Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def substitute(self, expression: sympy.Expr, substitutions: dict):
for key, value in substitutions.items():
if not isinstance(value, sympy.Expr):
substitutions[key] = sympy.sympify(value)
return expression.subs(substitutions, simultaneous=True).doit()
def sympify(x):
if x == -sympy.oo:
sx = -sympy.oo
elif x == sympy.oo:
sx = sympy.oo
else:
sx = sympy.sympify(x)
return sx
def __truediv__(self, other):
return self * sympify(other)**-1
def safe_sympify(value):
_check_input(value)
return sympify(value)
for nested_rule in rules:
nested_formula = sp.sympify(
sbml.formulaToL3String(nested_rule.getMath()),
locals=self.local_symbols)
nested_formula = \
nested_formula.subs(variable, formula)
nested_rule.setFormula(str(nested_formula))
for variable in assignments:
assignments[variable].subs(variable, formula)
# do this at the very end to ensure we have flattened all recursive
# rules
for variable in assignments.keys():
self.replaceInAllExpressions(
sp.sympify(variable, locals=self.local_symbols),
assignments[variable]
)
for comp, vol in zip(self.compartmentSymbols, self.compartmentVolume):
self.replaceInAllExpressions(
comp, vol
)
def __new__(cls, a=0, b=0, c=0, d=0, real_field=True):
a = sympify(a)
b = sympify(b)
c = sympify(c)
d = sympify(d)
if any(i.is_commutative is False for i in [a, b, c, d]):
raise ValueError("arguments have to be commutative")
else:
obj = Expr.__new__(cls, a, b, c, d)
obj._a = a
obj._b = b
obj._c = c
obj._d = d
obj._real_field = real_field
return obj
def _zp2tf(zeros, poles, K=1, var=s):
"""Create a transfer function from lists of zeros and poles,
and from a constant gain."""
zeros = sym.sympify(zeros)
poles = sym.sympify(poles)
if isinstance(zeros, (tuple, list)):
zz = [(var - z) for z in zeros]
else:
zz = [(var - z) ** zeros[z] for z in zeros]
if isinstance(zeros, (tuple, list)):
pp = [1 / (var - p) for p in poles]
else:
pp = [1 / (var - p) ** poles[p] for p in poles]
return sym.Mul(K, *(zz + pp))
assert isinstance(past,CubicHermiteSpline)
super().__init__(anchors=past)
self.t, self.y, self.diff = self[-1]
self.old_new_y = None
self.parameters = []
from jitcdde._jitcdde import t, y, past_y, past_dy, anchors
from sympy import DeferredVector, sympify, lambdify
Y = DeferredVector("Y")
substitutions = list(reversed(helpers)) + [(y(i),Y[i]) for i in range(self.n)]
past_calls = 0
f_wc = []
for entry in f():
new_entry = sympify(entry).subs(substitutions).simplify(ratio=1.0)
past_calls += new_entry.count(anchors)
f_wc.append(new_entry)
F = lambdify(
[t, Y] + list(control_pars),
f_wc,
[
{
anchors.name: self.get_anchors_with_mem,
past_y .name: interpolate,
past_dy.name: interpolate_diff,
},
"math"
]
)
Examples
========
>>> from sympy.stats import P, Die
>>> from sympy import Eq
>>> X, Y = Die('X', 6), Die('Y', 6)
>>> P(X > 3)
1/2
>>> P(Eq(X, 5), X > 2) # Probability that X == 5 given that X > 2
1/4
>>> P(X > Y)
5/12
"""
condition = sympify(condition)
given_condition = sympify(given_condition)
if condition.has(RandomIndexedSymbol):
return pspace(condition).probability(condition, given_condition, evaluate, **kwargs)
if isinstance(given_condition, RandomSymbol):
condrv = random_symbols(condition)
if len(condrv) == 1 and condrv[0] == given_condition:
from sympy.stats.frv_types import BernoulliDistribution
return BernoulliDistribution(probability(condition), 0, 1)
if any([dependent(rv, given_condition) for rv in condrv]):
from sympy.stats.symbolic_probability import Probability
return Probability(condition, given_condition)
else:
return probability(condition)
if given_condition is not None and \
def m_values(j):
j = sympify(j)
size = 2*j + 1
if not size.is_Integer or not size > 0:
raise ValueError(
'Only integer or half-integer values allowed for j, got: : %r' % j
)
return size, [j - i for i in range(int(2*j + 1))]