How to use the sympy.Eq 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 opesci / devito / tests / test_oi.py View on Github external
Equation = v1[i2][i1] = (v1[i2][i1] - 1.1F*v2[i2][i1])/(v3[i2][i1] +
                   7.0e-1F*v4[i2][i1]);
        '''
        load = 4.0
        store = 1.0
        add = 2.0
        mul = 3.0
        dtype = np.float32
        i1, i2 = symbols('i1 i2')
        data = np.arange(50, dtype=np.float32).reshape((10, 5))
        arr = np.empty_like(data)
        v1 = IndexedBase('v1')
        v2 = IndexedBase('v2')
        v3 = IndexedBase('v3')
        v4 = IndexedBase('v4')
        eq = Eq(v1[i2, i1], (v1[i2, i1] - 1.1*v2[i2, i1])/(0.7*v4[i2, i1] + v3[i2, i1]))

        propagator = Propagator("process", 10, (5,), 0, profile=True)
        propagator.stencils = (eq, )
        propagator.add_param("v1", data.shape, data.dtype)
        propagator.add_param("v2", data.shape, data.dtype)
        propagator.add_param("v3", data.shape, data.dtype)
        propagator.add_param("v4", data.shape, data.dtype)
        propagator.run([data, data, data, arr])

        propagator_oi = propagator.oi["main"]
        hand_oi = (mul+add)/((load+store)*np.dtype(dtype).itemsize)

        assert(propagator_oi == hand_oi)
github mph- / lcapy / lcapy / statespace.py View on Github external
def output_equations(self):
        """System of output equations:

        y = C x + D u

        where y is the output vector, x is the state vector and u is
        the input vector.

        """
        
        return tExpr(sym.Eq(self.y, sym.MatAdd(sym.MatMul(self.C, self.x),
                                               sym.MatMul(self.D, self.u)),
                            evaluate=False))
github wassgha / CalcTutor / main / question_factory / steps / diffsteps.py View on Github external
def print_Div(self, rule):
        with self.new_step():
            f, g = rule.numerator, rule.denominator
            fp, gp = f.diff(rule.symbol), g.diff(rule.symbol)
            x = rule.symbol
            ff = sympy.Function("f")(x)
            gg = sympy.Function("g")(x)
            qrule_left = sympy.Derivative(ff / gg, rule.symbol)
            qrule_right = sympy.ratsimp(sympy.diff(sympy.Function("f")(x) /
                                                   sympy.Function("g")(x)))
            qrule = sympy.Eq(qrule_left, qrule_right)
            self.append("Apply the quotient rule, which is:")
            self.append(self.format_math_display(qrule))
            self.append("{} and {}.".format(self.format_math(sympy.Eq(ff, f)),
                                            self.format_math(sympy.Eq(gg, g))))
            self.append("To find {}:".format(self.format_math(ff.diff(rule.symbol))))
            with self.new_level():
                self.print_rule(rule.numerstep)
            self.append("To find {}:".format(self.format_math(gg.diff(rule.symbol))))
            with self.new_level():
                self.print_rule(rule.denomstep)
            self.append("Now plug in to the quotient rule:")
            self.append(self.format_math(diff(rule)))
github thearn / examgen / examgen / lib / algebra.py View on Github external
integer = random.choice(integer)
    if integer:
        r1 = random.choice(digits_nozero)
        r2 = random.choice(digits_nozero)
        lhs = (var - r1) * (var - r2)
        lhs = lhs.expand()
        rhs = 0
    else:
        c1, c2, c3 = get_coefficients(3)
        lhs = c1*var**2 + c2*var + c3

    if rhs == None:
        c4, c5, c6 = get_coefficients(3, first_nonzero=False)
        rhs = c4*var**2 + c5*var + c6
    
    e = sympy.Eq(lhs, rhs)
    pvar = str(var)
    sols = ', '.join([pvar+" = " + sympy.latex(ex) for ex in sympy.solve(e, var)])
    sols = "$$" + sols + "$$"
    if len(sols) == 0:
        return make_quadratic_eq()
    return render(e), sols
github mdhiggins / sickbeard_mp4_automator / setup / subliminal / subliminal / score.py View on Github external
7. resolution = video_codec
    8. video_codec = 2 * audio_codec
    9. title = season + episode
    10. season = episode
    11. release_group = season
    12. audio_codec = 1

    :return: the score equations for an episode
    :rtype: list of :class:`sympy.Eq`

    """
    equations = []
    equations.append(Eq(hash, resolution + video_codec + audio_codec + series + season + episode + year + release_group))
    equations.append(Eq(series, resolution + video_codec + audio_codec + season + episode + release_group + 1))
    equations.append(Eq(series, year))
    equations.append(Eq(tvdb_id, series + year))
    equations.append(Eq(season, resolution + video_codec + audio_codec + 1))
    equations.append(Eq(imdb_id, series + season + episode + year))
    equations.append(Eq(resolution, video_codec))
    equations.append(Eq(video_codec, 2 * audio_codec))
    equations.append(Eq(title, season + episode))
    equations.append(Eq(season, episode))
    equations.append(Eq(release_group, season))
    equations.append(Eq(audio_codec, 1))
    return equations
github pymedusa / Medusa / lib / subliminal / score.py View on Github external
Eq(year, release_group + format + audio_codec + resolution + video_codec + 1),

        # release group is the next most wanted match
        Eq(release_group, format + audio_codec + resolution + video_codec + 1),

        # format counts as much as audio_codec, resolution and video_codec
        Eq(format, audio_codec + resolution + video_codec),

        # audio_codec is more valuable than video_codec
        Eq(audio_codec, video_codec + 1),

        # resolution counts as much as video_codec
        Eq(resolution,  video_codec),

        # hearing impaired is as much as resolution
        Eq(hearing_impaired, resolution),

        # video_codec counts more than the title
        Eq(video_codec,  1),
    ]

    return solve(equations, [hash, title, year, release_group, format, audio_codec, resolution, hearing_impaired,
                             video_codec])
github Knewton / Zoidberg / _old / solver.py View on Github external
def _solve_equivalence_statement(self, s):
		expressions = s.expressions
		self._think("Solving equivalence statement")
		a = self._solve_expression(expressions[0])
		b = self._solve_expression(expressions[1])
		self._think("I think a = {0}", a)
		self._think("I think b = {0}", b)
		soln = solve(Eq(a, b))

		# solution returned as an array of answers or an object
		if len(soln) == 1:
			try:
				return soln[0]
			except KeyError:
				return soln
		else:
			return soln
github sympy / sympy / sympy / physics / quantum / cg.py View on Github external
def _check_varsh_872_9(term_list):
    # Sum( CG(a,alpha,b,beta,c,gamma)*CG(a,alpha',b,beta',c,gamma), (gamma, -c, c), (c, abs(a-b), a+b))
    a, alpha, alphap, b, beta, betap, c, gamma, lt = map(Wild, (
        'a', 'alpha', 'alphap', 'b', 'beta', 'betap', 'c', 'gamma', 'lt'))
    # Case alpha==alphap, beta==betap

    # For numerical alpha,beta
    expr = lt*CG(a, alpha, b, beta, c, gamma)**2
    simp = 1
    sign = lt/abs(lt)
    x = abs(a - b)
    y = abs(alpha + beta)
    build_expr = a + b + 1 - Piecewise((x, x > y), (0, Eq(x, y)), (y, y > x))
    index_expr = a + b - c
    term_list, other1 = _check_cg_simp(expr, simp, sign, lt, term_list, (a, alpha, b, beta, c, gamma, lt), (a, alpha, b, beta), build_expr, index_expr)

    # For symbolic alpha,beta
    x = abs(a - b)
    y = a + b
    build_expr = (y + 1 - x)*(x + y + 1)
    index_expr = (c - x)*(x + c) + c + gamma
    term_list, other2 = _check_cg_simp(expr, simp, sign, lt, term_list, (a, alpha, b, beta, c, gamma, lt), (a, alpha, b, beta), build_expr, index_expr)

    # Case alpha!=alphap or beta!=betap
    # Note: this only works with leading term of 1, pattern matching is unable to match when there is a Wild leading term
    # For numerical alpha,alphap,beta,betap
    expr = CG(a, alpha, b, beta, c, gamma)*CG(a, alphap, b, betap, c, gamma)
    simp = KroneckerDelta(alpha, alphap)*KroneckerDelta(beta, betap)
    sign = sympify(1)
github Diaoul / subliminal / subliminal / score.py View on Github external
Eq(episode, season),

        # release group is the next most wanted match
        Eq(release_group, format + audio_codec + resolution + video_codec + 1),

        # format counts as much as audio_codec, resolution and video_codec
        Eq(format, audio_codec + resolution + video_codec),

        # audio_codec is more valuable than video_codec
        Eq(audio_codec, video_codec + 1),

        # resolution counts as much as video_codec
        Eq(resolution, video_codec),

        # video_codec is the least valuable match but counts more than the sum of all scoring increasing matches
        Eq(video_codec, hearing_impaired + 1),

        # hearing impaired is only used for score increasing, so put it to 1
        Eq(hearing_impaired, 1),
    ]

    return solve(equations, [hash, series, year, season, episode, release_group, format, audio_codec, resolution,
                             hearing_impaired, video_codec])
github wassgha / CalcTutor / main / question_factory / steps / intsteps.py View on Github external
def print_Power(self, rule):
        with self.new_step():
            self.append("The integral of {} is {} when {}:".format(
                self.format_math(rule.symbol ** sympy.Symbol('n')),
                self.format_math((rule.symbol ** (1 + sympy.Symbol('n'))) /
                                 (1 + sympy.Symbol('n'))),
                self.format_math(sympy.Ne(sympy.Symbol('n'), -1)),
            ))
            self.append(
                self.format_math_display(
                    sympy.Eq(sympy.Integral(rule.context, rule.symbol),
                           _manualintegrate(rule))))