How to use the sympy.S function in sympy

To help you get started, we’ve selected a few sympy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dotnet / infer / src / Tools / PythonScripts / GenerateSeries.py View on Github external
def print_error_bound(name, indent, variable_name, series_length, coefficients, nextc):
    is_alternating = sign(coefficients[-1]) != sign(coefficients[-2])
    if is_alternating:
        nextc = abs(nextc)
        print(f"{indent}// Error is at most {format_real_coefficient(nextc)}*{variable_name}**{series_length} when {variable_name} >= 0")
        ulp1 = 2.220446049250313e-16
        if name == "2: Digamma at 1":
            offset = S(1e6)
        elif name == "3: Digamma at 2":
            offset = 1 + digamma(1)
        elif name == "4: Digamma asymptotic":
            offset = S(1)
        elif name == "5: Trigamma at 1":
            offset = S(1e8)
        elif name == "7: Tetragamma at 1":
            offset = S(2e12)
        elif name == "6: Trigamma asymptotic":
            offset = S(1)
        elif name == "8: Tetragamma asymptotic":
            offset = S(12**-3)
        elif name == "15: log(exp(x) - 1) / x":
            offset = S(-log(1e-3))
        else:
            offset = abs(coefficients[0])
        if offset == 0:
            offset = abs(coefficients[1])
            if offset == 0:
                offset = abs(coefficients[2])
github zholos / qml / test / libm.py View on Github external
def test_hyper():
    for x in sorted(exparg):
        test("erf", x, N(sp.erf(x)))
    for x in sorted(exparg):
        test("erfc", x, N(sp.erfc(x)))

    gamarg = FiniteSet(*(x+S(1)/12 for x in exparg))
    betarg = ProductSet(gamarg, gamarg)
    for x in sorted(gamarg):
        test("lgamma", x, N(sp.log(abs(sp.gamma(x)))))
    for x in sorted(gamarg):
        test("gamma", x, N(sp.gamma(x)))
    for x, y in sorted(betarg, key=lambda (x, y): (y, x)):
        test("beta", x, y, N(sp.beta(x, y)))

    pgamarg = FiniteSet(S(1)/12, S(1)/3, S(3)/2, 5)
    pgamargp = ProductSet(gamarg & Interval(0, oo, True), pgamarg)
    for a, x in sorted(pgamargp):
        test("pgamma", a, x, N(sp.lowergamma(a, x)))
    for a, x in sorted(pgamargp):
        test("pgammac", a, x, N(sp.uppergamma(a, x)))
    for a, x in sorted(pgamargp):
        test("pgammar", a, x, N(sp.lowergamma(a, x)/sp.gamma(a)))
    for a, x in sorted(pgamargp):
        test("pgammarc", a, x, N(sp.uppergamma(a, x)/sp.gamma(a)))
    for a, x in sorted(pgamargp):
        test("ipgammarc", a, N(sp.uppergamma(a, x)/sp.gamma(a)), x)

    pbetargp = [(a, b, x) for a, b, x in ProductSet(betarg, pgamarg)
                if a > 0 and b > 0 and x < 1]
    pbetargp.sort(key=lambda (a, b, x): (b, a, x))
    for a, b, x in pbetargp:
github sympy / sympy / sympy / integrals / rubi / rules / logarithms.py View on Github external
def replacement2131(p, f, g, b, d, a, c, n, x, e):
        rubi.append(2131)
        return -Dist(b*e*n*p/(d*g), Subst(Int((a + b*log(c*(d + e*x)**p))**(n + S(-1))/x, x), x, S(1)/(f + g*x)), x) + Simp((a + b*log(c*(d + e/(f + g*x))**p))**n*(d*(f + g*x) + e)/(d*g), x)
    rule2131 = ReplacementRule(pattern2131, replacement2131)
github SheffieldML / GPy / GPy / util / symbolic.py View on Github external
def eval(cls, t, tprime, d_i, d_j, l):
        if (t.is_Number
            and tprime.is_Number
            and d_i.is_Number
            and d_j.is_Number
            and l.is_Number):
            if (t is S.NaN
                or tprime is S.NaN
                or d_i is S.NaN
                or d_j is S.NaN
                or l is S.NaN):
                return S.NaN
            else:
                half_l_di = 0.5*l*d_i
                arg_1 = half_l_di + tprime/l
                arg_2 = half_l_di - (t-tprime)/l
                ln_part_1 = ln_diff_erf(arg_1, arg_2)
                arg_1 = half_l_di 
                arg_2 = half_l_di - t/l
                sign_val = sign(t/l)
                ln_part_2 = ln_diff_erf(half_l_di, half_l_di - t/l)
github sympy / sympy / sympy / integrals / rubi / constraints.py View on Github external
def cons_f1025(a, A, c, e, C, d, B):
    return ZeroQ(-S(4)*A*B*C*d + S(4)*A*e*(S(2)*A*C + B**S(2)) - B**S(3)*d + S(2)*B**S(2)*C*c - S(8)*C**S(3)*a)
github sympy / sympy / sympy / integrals / rubi / constraints.py View on Github external
def cons_f870(a, b, B, C):
    return ZeroQ(B*a**(S(1)/3)*b**(S(1)/3) + S(2)*C*a**(S(2)/3))
github MiroK / fenics_ii / demo / emi_mortar_2d.py View on Github external
def setup_mms(eps):
    '''Simple MMS problem for UnitSquareMesh'''
    from common import as_expression
    import sympy as sp
    pi = sp.pi
    x, y, EPS = sp.symbols('x[0] x[1] EPS')
    
    u1 = sp.cos(4*pi*x)*sp.cos(4*pi*y)
    u2 = 2*u1

    f1 = -u1.diff(x, 2) - u1.diff(y, 2) + u1
    f2 = -u2.diff(x, 2) - u2.diff(y, 2) + u2
    g = (u1 - u2)*EPS  
    # NOTE: the multiplier is grad(u).n and with the chosen data this
    # means that it's zero on the interface
    up = map(as_expression, (u1, u2, sp.S(0)))  # The flux
    f = map(as_expression, (f1, f2))
    g = as_expression(g, EPS=eps)  # Prevent recompilation

    return up, f+[g]
github brian-team / brian2modelfitting / brian2modelfitting / fitter.py View on Github external
sensitivity_names.append(names)

    new_eqs = []
    for names, sensitivity_eqs, param in zip(sensitivity_names, sensitivity, parameters):
        for name, eq, orig_var in zip(names, sensitivity_eqs, diff_eq_names):
            if param in namespace:
                unit = eqs[orig_var].dim / namespace[param].dim
            elif param in group.variables:
                unit = eqs[orig_var].dim / group.variables[param].dim
            else:
                raise AssertionError(f'Parameter {param} neither in namespace nor variables')
            unit = repr(unit) if not unit.is_dimensionless else '1'
            if optimize:
                # Check if the equation stays at zero if initialized at zero
                zeroed = eq.subs(name, sympy.S.Zero)
                if zeroed == sympy.S.Zero:
                    # No need to include equation as differential equation
                    if unit == '1':
                        new_eqs.append(f'{sympy_to_str(name)} = 0 : {unit}')
                    else:
                        new_eqs.append(f'{sympy_to_str(name)} = 0*{unit} : {unit}')
                    continue
            rhs = sympy_to_str(eq)
            if rhs == '0':  # avoid unit mismatch
                rhs = f'0*{unit}/second'
            new_eqs.append('d{lhs}/dt = {rhs} : {unit}'.format(lhs=sympy_to_str(name),
                                                               rhs=rhs,
                                                               unit=unit))
    new_eqs = Equations('\n'.join(new_eqs))
    return new_eqs