Exemple #1
0
def vpprint(expr, **settings):
    r"""Function for pretty printing of expressions generated in the
    sympy.physics vector package.

    Mainly used for expressions not inside a vector; the output of running
    scripts and generating equations of motion. Takes the same options as
    SymPy's pretty_print(); see that function for more information.

    Parameters
    ==========

    expr : valid SymPy object
        SymPy expression to pretty print
    settings : args
        Same as those accepted by SymPy's pretty_print.


    """

    pp = VectorPrettyPrinter(settings)

    # Note that this is copied from sympy.printing.pretty.pretty_print:

    # XXX: this is an ugly hack, but at least it works
    use_unicode = pp._settings['use_unicode']
    from sympy.printing.pretty.pretty_symbology import pretty_use_unicode
    uflag = pretty_use_unicode(use_unicode)

    try:
        return pp.doprint(expr)
    finally:
        pretty_use_unicode(uflag)
Exemple #2
0
def vpprint(expr, **settings):
    r"""Function for pretty printing of expressions generated in the
    sympy.physics vector package.

    Mainly used for expressions not inside a vector; the output of running
    scripts and generating equations of motion. Takes the same options as
    SymPy's pretty_print(); see that function for more information.

    Parameters
    ==========

    expr : valid SymPy object
        SymPy expression to pretty print
    settings : args
        Same as those accepted by SymPy's pretty_print.


    """

    pp = VectorPrettyPrinter(settings)

    # Note that this is copied from sympy.printing.pretty.pretty_print:

    # XXX: this is an ugly hack, but at least it works
    use_unicode = pp._settings['use_unicode']
    from sympy.printing.pretty.pretty_symbology import pretty_use_unicode
    uflag = pretty_use_unicode(use_unicode)

    try:
        return pp.doprint(expr)
    finally:
        pretty_use_unicode(uflag)
Exemple #3
0
def print_caracas(expr, **settings):   
    settings['use_unicode'] = False
    
    pp = CaracasPrettyPrinter(settings)
    #    breakpoint()
    # XXX: this is an ugly hack, but at least it works
    use_unicode = pp._settings['use_unicode']
    uflag = pretty_use_unicode(use_unicode)

    try:
        return print(pp.doprint(expr))
    finally:
        pretty_use_unicode(uflag)
Exemple #4
0
            def render(self, *args, **kwargs):
                ar = e.args  # just to shorten things
                settings = printer._settings if printer else {}
                if printer:
                    use_unicode = printer._use_unicode
                else:
                    from sympy.printing.pretty.pretty_symbology import (
                        pretty_use_unicode, )

                    use_unicode = pretty_use_unicode()
                mpp = printer if printer else VectorPrettyPrinter(settings)
                if len(ar) == 0:
                    return unicode(0)
                bar = u"\N{CIRCLED TIMES}" if use_unicode else "|"
                ol = []  # output list, to be concatenated to a string
                for i, v in enumerate(ar):
                    # if the coef of the dyadic is 1, we skip the 1
                    if ar[i][0] == 1:
                        ol.extend([
                            u" + ",
                            mpp.doprint(ar[i][1]), bar,
                            mpp.doprint(ar[i][2])
                        ])

                    # if the coef of the dyadic is -1, we skip the 1
                    elif ar[i][0] == -1:
                        ol.extend([
                            u" - ",
                            mpp.doprint(ar[i][1]), bar,
                            mpp.doprint(ar[i][2])
                        ])

                    # If the coefficient of the dyadic is not 1 or -1,
                    # we might wrap it in parentheses, for readability.
                    elif ar[i][0] != 0:
                        if isinstance(ar[i][0], Add):
                            arg_str = mpp._print(ar[i][0]).parens()[0]
                        else:
                            arg_str = mpp.doprint(ar[i][0])
                        if arg_str.startswith(u"-"):
                            arg_str = arg_str[1:]
                            str_start = u" - "
                        else:
                            str_start = u" + "
                        ol.extend([
                            str_start,
                            arg_str,
                            u" ",
                            mpp.doprint(ar[i][1]),
                            bar,
                            mpp.doprint(ar[i][2]),
                        ])

                outstr = u"".join(ol)
                if outstr.startswith(u" + "):
                    outstr = outstr[3:]
                elif outstr.startswith(" "):
                    outstr = outstr[1:]
                return outstr
Exemple #5
0
            def render(self, *args, **kwargs):
                ar = e.args  # just to shorten things
                settings = printer._settings if printer else {}
                if printer:
                    use_unicode = printer._use_unicode
                else:
                    from sympy.printing.pretty.pretty_symbology import (
                        pretty_use_unicode)
                    use_unicode = pretty_use_unicode()
                mpp = printer if printer else VectorPrettyPrinter(settings)
                if len(ar) == 0:
                    return unicode(0)
                bar = u"\N{CIRCLED TIMES}" if use_unicode else "|"
                ol = []  # output list, to be concatenated to a string
                for i, v in enumerate(ar):
                    # if the coef of the dyadic is 1, we skip the 1
                    if ar[i][0] == 1:
                        ol.extend([u" + ",
                                  mpp.doprint(ar[i][1]),
                                  bar,
                                  mpp.doprint(ar[i][2])])

                    # if the coef of the dyadic is -1, we skip the 1
                    elif ar[i][0] == -1:
                        ol.extend([u" - ",
                                  mpp.doprint(ar[i][1]),
                                  bar,
                                  mpp.doprint(ar[i][2])])

                    # If the coefficient of the dyadic is not 1 or -1,
                    # we might wrap it in parentheses, for readability.
                    elif ar[i][0] != 0:
                        if isinstance(ar[i][0], Add):
                            arg_str = mpp._print(
                                ar[i][0]).parens()[0]
                        else:
                            arg_str = mpp.doprint(ar[i][0])
                        if arg_str.startswith(u"-"):
                            arg_str = arg_str[1:]
                            str_start = u" - "
                        else:
                            str_start = u" + "
                        ol.extend([str_start, arg_str, u" ",
                                  mpp.doprint(ar[i][1]),
                                  bar,
                                  mpp.doprint(ar[i][2])])

                outstr = u"".join(ol)
                if outstr.startswith(u" + "):
                    outstr = outstr[3:]
                elif outstr.startswith(" "):
                    outstr = outstr[1:]
                return outstr