• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python printing.sstr函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sympy.printing.sstr函数的典型用法代码示例。如果您正苦于以下问题:Python sstr函数的具体用法?Python sstr怎么用?Python sstr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了sstr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_sstrrepr

def test_sstrrepr():
    assert sstr('abc') == 'abc'
    assert sstrrepr('abc') == "'abc'"

    e = ['a', 'b', 'c', x]
    assert sstr(e) == "[a, b, c, x]"
    assert sstrrepr(e) == "['a', 'b', 'c', x]"
开发者ID:Lenqth,项目名称:sympy,代码行数:7,代码来源:test_str.py


示例2: test_Matrix

def test_Matrix():
    M = Matrix([[x**+1, 1], [y, x + y]])
    assert str(M) == sstr(M) == "[x,     1]\n[y, x + y]"
    M = Matrix()
    assert str(M) == sstr(M) == "[]"
    M = Matrix(0, 1, lambda i, j: 0)
    assert str(M) == sstr(M) == "[]"
开发者ID:FireJade,项目名称:sympy,代码行数:7,代码来源:test_str.py


示例3: test_set

def test_set():
    assert sstr(set()) == 'set()'
    assert sstr(frozenset()) == 'frozenset()'

    assert sstr(set([1, 2, 3])) == 'set([1, 2, 3])'
    assert sstr(
        set([1, x, x**2, x**3, x**4])) == 'set([1, x, x**2, x**3, x**4])'
开发者ID:FireJade,项目名称:sympy,代码行数:7,代码来源:test_str.py


示例4: replaceWith

def replaceWith(s, symbols, i):
    '''
    Replaces `With` and `Module by python functions`
    '''
    if type(s) == Function('With') or type(s) == Function('Module'):
        constraints = ', '
        result = '    def With{}({}):'.format(i, ', '.join(symbols))
        if type(s.args[0]) == Function('List'): # get all local varibles of With and Module
            L = list(s.args[0].args)
        else:
            L = [s.args[0]]

        for i in L: # define local variables
            if isinstance(i, Set):
                result += '\n        {} = {}'.format(i.args[0], sstr(i.args[1], sympy_integers=True))
            elif isinstance(i, Symbol):
                result += "\n        {} = Symbol('{}')".format(i, i)

        if type(s.args[1]) == Function('CompoundExpression'): # Expand CompoundExpression
            C = s.args[1]
            if isinstance(C.args[0], Set):
                result += '\n        {} = {}'.format(C.args[0].args[0], C.args[0].args[1])
            result += '\n        return {}'.format(sstr(C.args[1], sympy_integers=True))
            return result, constraints
        elif type(s.args[1]) == Function('Condition'):
            C = s.args[1]
            if len(C.args) == 2:
                constraints += 'CustomConstraint(lambda {}: {})'.format(', '.join([str(i) for i in C.free_symbols]), sstr(C.args[1], sympy_integers=True))
            result += '\n        return {}'.format(sstr(C.args[0], sympy_integers=True))
            return result, constraints

        result += '\n        return {}'.format(sstr(s.args[1], sympy_integers=True))
        return result, constraints
    else:
        return sstr(s, sympy_integers=True), ''
开发者ID:tclose,项目名称:sympy,代码行数:35,代码来源:parse.py


示例5: test_PrettyPoly

def test_PrettyPoly():
    from sympy.polys.domains import QQ

    F = QQ.frac_field(x, y)
    R = QQ[x, y]
    assert sstr(F.convert(x / (x + y))) == sstr(x / (x + y))
    assert sstr(R.convert(x + y)) == sstr(x + y)
开发者ID:Ryzh,项目名称:sympy,代码行数:7,代码来源:test_str.py


示例6: test_noncommutative

def test_noncommutative():
    A, B, C = symbols('A,B,C', commutative=False)

    assert sstr(A*B*C**-1) == "A*B*C**(-1)"
    assert sstr(C**-1*A*B) == "C**(-1)*A*B"
    assert sstr(A*C**-1*B) == "A*C**(-1)*B"
    assert sstr(sqrt(A)) == "sqrt(A)"
    assert sstr(1/sqrt(A)) == "A**(-1/2)"
开发者ID:Lenqth,项目名称:sympy,代码行数:8,代码来源:test_str.py


示例7: test_printmethod

def test_printmethod():
    class R(abs):
        def _sympystr(self, printer):
            return "foo(%s)" % printer._print(self.args[0])
    assert sstr(R(x)) == "foo(x)"
    class R(abs):
        def _sympystr(self, printer):
            return "foo"
    assert sstr(R(x)) == "foo"
开发者ID:bibile,项目名称:sympy,代码行数:9,代码来源:test_str.py


示例8: test_Rational

def test_Rational():
    n1 = Rational(1, 4)
    n2 = Rational(1, 3)
    n3 = Rational(2, 4)
    n4 = Rational(2, -4)
    n5 = Rational(0)
    n7 = Rational(3)
    n8 = Rational(-3)
    assert str(n1*n2) == "1/12"
    assert str(n1*n2) == "1/12"
    assert str(n3) == "1/2"
    assert str(n1*n3) == "1/8"
    assert str(n1 + n3) == "3/4"
    assert str(n1 + n2) == "7/12"
    assert str(n1 + n4) == "-1/4"
    assert str(n4*n4) == "1/4"
    assert str(n4 + n2) == "-1/6"
    assert str(n4 + n5) == "-1/2"
    assert str(n4*n5) == "0"
    assert str(n3 + n4) == "0"
    assert str(n1**n7) == "1/64"
    assert str(n2**n7) == "1/27"
    assert str(n2**n8) == "27"
    assert str(n7**n8) == "1/27"
    assert str(Rational("-25")) == "-25"
    assert str(Rational("1.25")) == "5/4"
    assert str(Rational("-2.6e-2")) == "-13/500"
    assert str(S("25/7")) == "25/7"
    assert str(S("-123/569")) == "-123/569"
    assert str(S("0.1[23]", rational=1)) == "61/495"
    assert str(S("5.1[666]", rational=1)) == "31/6"
    assert str(S("-5.1[666]", rational=1)) == "-31/6"
    assert str(S("0.[9]", rational=1)) == "1"
    assert str(S("-0.[9]", rational=1)) == "-1"

    assert str(sqrt(Rational(1, 4))) == "1/2"
    assert str(sqrt(Rational(1, 36))) == "1/6"

    assert str((123**25) ** Rational(1, 25)) == "123"
    assert str((123**25 + 1)**Rational(1, 25)) != "123"
    assert str((123**25 - 1)**Rational(1, 25)) != "123"
    assert str((123**25 - 1)**Rational(1, 25)) != "122"

    assert str(sqrt(Rational(81, 36))**3) == "27/8"
    assert str(1/sqrt(Rational(81, 36))**3) == "8/27"

    assert str(sqrt(-4)) == str(2*I)
    assert str(2**Rational(1, 10**10)) == "2**(1/10000000000)"

    assert sstr(Rational(2, 3), sympy_integers=True) == "S(2)/3"
    x = Symbol("x")
    assert sstr(x**Rational(2, 3), sympy_integers=True) == "x**(S(2)/3)"
    assert sstr(Eq(x, Rational(2, 3)), sympy_integers=True) == "Eq(x, S(2)/3)"
    assert sstr(Limit(x, x, Rational(7, 2)), sympy_integers=True) == \
        "Limit(x, x, S(7)/2)"
开发者ID:Lenqth,项目名称:sympy,代码行数:55,代码来源:test_str.py


示例9: test_Matrix_str

def test_Matrix_str():
    M = Matrix([[x**+1, 1], [y, x + y]])
    assert str(M) == "Matrix([[x, 1], [y, x + y]])"
    assert sstr(M) == "Matrix([\n[x,     1],\n[y, x + y]])"
    M = Matrix([[1]])
    assert str(M) == sstr(M) == "Matrix([[1]])"
    M = Matrix([[1, 2]])
    assert str(M) == sstr(M) ==  "Matrix([[1, 2]])"
    M = Matrix()
    assert str(M) == sstr(M) == "Matrix(0, 0, [])"
    M = Matrix(0, 1, lambda i, j: 0)
    assert str(M) == sstr(M) == "Matrix(0, 1, [])"
开发者ID:Lenqth,项目名称:sympy,代码行数:12,代码来源:test_str.py


示例10: __repr__

    def __repr__(self):
        str_sol = 'HolonomicFunction(%s, %s)' % ((self.annihilator).__repr__(), sstr(self.x))
        if not self._have_init_cond:
            return str_sol
        else:
            cond_str = ''
            diff_str = ''
            for i in self.y0:
                cond_str += ', f%s(%s) = %s' % (diff_str, sstr(self.x0), sstr(i))
                diff_str += "'"

            sol = str_sol + cond_str
            return sol
开发者ID:Carreau,项目名称:sympy,代码行数:13,代码来源:holonomic.py


示例11: __repr__

    def __repr__(self):
        str_sol = 'HolonomicSequence(%s, %s)' % ((self.recurrence).__repr__(), sstr(self.n))
        if not self._have_init_cond:
            return str_sol
        else:
            cond_str = ''
            seq_str = 0
            for i in self.u0:
                cond_str += ', u(%s) = %s' % (sstr(seq_str), sstr(i))
                seq_str += 1

            sol = str_sol + cond_str
            return sol
开发者ID:cklb,项目名称:sympy,代码行数:13,代码来源:recurrence.py


示例12: downvalues_rules

def downvalues_rules(r, parsed):
    '''
    Function which generates parsed rules by substituting all possible
    combinations of default values.
    '''
    res = []
    index = 0
    for i in r:
        print('parsing rule {}'.format(r.index(i) + 1))
        # Parse Pattern
        if i[1][1][0] == 'Condition':
            p = i[1][1][1].copy()
        else:
            p = i[1][1].copy()

        optional = get_default_values(p, {})
        pattern = generate_sympy_from_parsed(p.copy(), replace_Int=True)
        pattern, free_symbols = add_wildcards(pattern, optional=optional)
        free_symbols = list(set(free_symbols)) #remove common symbols

        # Parse Transformed Expression and Constraints
        if i[2][0] == 'Condition': # parse rules without constraints seperately
            constriant = divide_constraint(i[2][2], free_symbols) # seperate And constraints into indivdual constraints
            FreeQ_vars, FreeQ_x = seperate_freeq(i[2][2].copy()) # seperate FreeQ into indivdual constraints
            transformed = generate_sympy_from_parsed(i[2][1].copy(), symbols=free_symbols)
        else:
            constriant = ''
            FreeQ_vars, FreeQ_x = [], []
            transformed = generate_sympy_from_parsed(i[2].copy(), symbols=free_symbols)

        FreeQ_constraint = parse_freeq(FreeQ_vars, FreeQ_x, free_symbols)
        pattern = sympify(pattern)
        pattern = sstr(pattern, sympy_integers=True)
        pattern = setWC(pattern)
        transformed = sympify(transformed)

        index += 1
        if type(transformed) == Function('With') or type(transformed) == Function('Module'): # define seperate function when With appears
            transformed, With_constraints = replaceWith(transformed, free_symbols, index)
            parsed += '    pattern' + str(index) +' = Pattern(' + pattern + '' + FreeQ_constraint + '' + constriant + With_constraints + ')'
            parsed += '\n{}'.format(transformed)
            parsed += '\n    ' + 'rule' + str(index) +' = ReplacementRule(' + 'pattern' + sstr(index, sympy_integers=True) + ', lambda ' + ', '.join(free_symbols) + ' : ' + 'With{}({})'.format(index, ', '.join(free_symbols)) + ')\n    '
        else:
            transformed = sstr(transformed, sympy_integers=True)
            parsed += '    pattern' + str(index) +' = Pattern(' + pattern + '' + FreeQ_constraint + '' + constriant + ')'
            parsed += '\n    ' + 'rule' + str(index) +' = ReplacementRule(' + 'pattern' + sstr(index, sympy_integers=True) + ', lambda ' + ', '.join(free_symbols) + ' : ' + transformed + ')\n    '
        parsed += 'rubi.add(rule'+ str(index) +')\n\n'

    parsed += '    return rubi\n'

    return parsed
开发者ID:tclose,项目名称:sympy,代码行数:51,代码来源:parse.py


示例13: downvalues_rules

def downvalues_rules(r, parsed):
    '''
    Function which generates parsed rules by substituting all possible
    combinations of default values.
    '''
    res = []

    index = 0
    for i in r:
        #print('parsing rule {}'.format(r.index(i) + 1)) # uncomment to display number of rules parsed

        # Parse Pattern
        if i[1][1][0] == 'Condition':
            p = i[1][1][1].copy()
        else:
            p = i[1][1].copy()

        optional = get_default_values(p, {})
        pattern = generate_sympy_from_parsed(p.copy(), replace_Int=True)
        pattern, free_symbols = add_wildcards(pattern, optional=optional)
        free_symbols = list(set(free_symbols)) #remove common symbols

        # Parse Transformed Expression and Constraints
        if i[2][0] == 'Condition': # parse rules without constraints seperately
            constriant = divide_constraint(i[2][2], free_symbols) # seperate And constraints into indivdual constraints
            FreeQ_vars, FreeQ_x = seperate_freeq(i[2][2].copy()) # seperate FreeQ into indivdual constraints
            transformed = generate_sympy_from_parsed(i[2][1].copy(), symbols=free_symbols)
        else:
            constriant = ''
            FreeQ_vars, FreeQ_x = [], []
            transformed = generate_sympy_from_parsed(i[2].copy(), symbols=free_symbols)

        FreeQ_constraint = parse_freeq(FreeQ_vars, FreeQ_x)
        pattern = sympify(pattern)
        pattern = sstr(pattern, sympy_integers=True)
        pattern = setWC(pattern)
        transformed = sympify(transformed)
        transformed = sstr(transformed, sympy_integers=True)

        index += 1
        parsed = parsed + '    pattern' + str(index) +' = Pattern(' + pattern + '' + FreeQ_constraint + '' + constriant + ')'
        parsed = parsed + '\n    ' + 'rule' + str(index) +' = ReplacementRule(' + 'pattern' + sstr(index, sympy_integers=True) + ', lambda ' + ', '.join(free_symbols) + ' : ' + transformed + ')\n    '
        parsed = parsed + 'rubi.add(rule'+ str(index) +')\n\n'

    parsed = parsed + '    return rubi\n'

    # Replace modified functions such as `_Sum`
    parsed = parsed.replace('_Sum', 'Sum')

    return parsed
开发者ID:tachycline,项目名称:sympy,代码行数:50,代码来源:parse.py


示例14: __str__

    def __str__(self):

        string = 'Univariate Differential Operator Algebra in intermediate '\
            + sstr(self.gen_symbol) + ' over the base ring ' + \
            (self.base).__str__()

        return string
开发者ID:gamer496,项目名称:sympy,代码行数:7,代码来源:holonomic.py


示例15: __str__

    def __str__(self):
        """
        Return latex version of expression as string
        Use symbol_name_dict from create_symbol_name_dict to convert
        some symbols into their corresponding latex expressions.

        In addition, if expression is a LinearEntity, then display as equation
        of line set to zero.
        """

        from sympy.geometry.line import LinearEntity

        expression = self._expression
        symbol_name_dict = create_symbol_name_dict()

        if isinstance(expression, LinearEntity):
            xvar = self._parameters.get("xvar", "x")
            yvar = self._parameters.get("yvar", "y")
            output = "%s = 0" % latex(expression.equation(x=xvar, y=yvar), symbol_names=symbol_name_dict)
        else:
            try:
                output = latex(expression, symbol_names=symbol_name_dict)
            except RuntimeError:
                # for now, since dividing by one creates infinite recursion
                # in latex printer, use sstr print
                from sympy.printing import sstr

                output = sstr(expression)
            except:
                output = "[error]"

        return output
开发者ID:dqnykamp,项目名称:mathinsight,代码行数:32,代码来源:math_objects.py


示例16: test_set

def test_set():
    assert sstr(set()) == 'set()'
    assert sstr(frozenset()) == 'frozenset()'

    assert sstr(set([1])) == '{1}'
    assert sstr(frozenset([1])) == 'frozenset({1})'
    assert sstr(set([1, 2, 3])) == '{1, 2, 3}'
    assert sstr(frozenset([1, 2, 3])) == 'frozenset({1, 2, 3})'

    assert sstr(
        set([1, x, x**2, x**3, x**4])) == '{1, x, x**2, x**3, x**4}'
    assert sstr(
        frozenset([1, x, x**2, x**3, x**4])) == 'frozenset({1, x, x**2, x**3, x**4})'
开发者ID:Lenqth,项目名称:sympy,代码行数:13,代码来源:test_str.py


示例17: test_full_prec

def test_full_prec():
    assert sstr(S("0.3"), full_prec=True) == "0.300000000000000"
    assert sstr(S("0.3"), full_prec="auto") == "0.300000000000000"
    assert sstr(S("0.3"), full_prec=False) == "0.3"
    assert sstr(S("0.3") * x, full_prec=True) in ["0.300000000000000*x", "x*0.300000000000000"]
    assert sstr(S("0.3") * x, full_prec="auto") in ["0.3*x", "x*0.3"]
    assert sstr(S("0.3") * x, full_prec=False) in ["0.3*x", "x*0.3"]
开发者ID:abhishek070193,项目名称:sympy,代码行数:7,代码来源:test_str.py


示例18: __str__

    def __str__(self):
        listofpoly = self.listofpoly
        print_str = ''

        for i, j in enumerate(listofpoly):
            if j == self.parent.base.zero:
                continue

            if i == 0:
                print_str += '(' + sstr(j) + ')'
                continue

            if print_str:
                print_str += ' + '

            if i == 1:
                print_str += '(' + sstr(j) + ')Dx'
                continue

            print_str += '(' + sstr(j) + ')' + 'Dx**' + sstr(i)

        return print_str
开发者ID:Carreau,项目名称:sympy,代码行数:22,代码来源:holonomic.py


示例19: __str__

 def __str__(self):
     str_sol = 'Beam({}, {}, {})'.format(sstr(self._length), sstr(self._elastic_modulus), sstr(self._second_moment))
     return str_sol
开发者ID:wxgeo,项目名称:geophar,代码行数:3,代码来源:beam.py


示例20: _divide_constriant

def _divide_constriant(s, symbols):
    # Creates a CustomConstraint of the form `CustomConstraint(lambda a, x: FreeQ(a, x))`
    if s[0] == 'FreeQ':
        return ''
    lambda_symbols = list(set(get_free_symbols(s, symbols, [])))
    return 'CustomConstraint(lambda {}: {})'.format(', '.join(lambda_symbols), sstr(sympify(generate_sympy_from_parsed(s)), sympy_integers=True))
开发者ID:tachycline,项目名称:sympy,代码行数:6,代码来源:parse.py



注:本文中的sympy.printing.sstr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python printing.sstrrepr函数代码示例发布时间:2022-05-27
下一篇:
Python printing.srepr函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap