def test_ei(): pos = Symbol('p', positive=True) neg = Symbol('n', negative=True) assert Ei(-pos) == Ei(polar_lift(-1)*pos) - I*pi assert Ei(neg) == Ei(polar_lift(neg)) - I*pi assert tn_branch(Ei) assert mytd(Ei(x), exp(x)/x, x) assert mytn(Ei(x), Ei(x).rewrite(uppergamma), -uppergamma(0, x*polar_lift(-1)) - I*pi, x) assert mytn(Ei(x), Ei(x).rewrite(expint), -expint(1, x*polar_lift(-1)) - I*pi, x) assert Ei(x).rewrite(expint).rewrite(Ei) == Ei(x) assert Ei(x*exp_polar(2*I*pi)) == Ei(x) + 2*I*pi assert Ei(x*exp_polar(-2*I*pi)) == Ei(x) - 2*I*pi assert mytn(Ei(x), Ei(x).rewrite(Shi), Chi(x) + Shi(x), x) assert mytn(Ei(x*polar_lift(I)), Ei(x*polar_lift(I)).rewrite(Si), Ci(x) + I*Si(x) + I*pi/2, x) assert Ei(log(x)).rewrite(li) == li(x) assert Ei(2*log(x)).rewrite(li) == li(x**2) assert gruntz(Ei(x+exp(-x))*exp(-x)*x, x, oo) == 1 assert Ei(x).series(x) == EulerGamma + log(x) + x + x**2/4 + \ x**3/18 + x**4/96 + x**5/600 + O(x**6)
def test_ei(): assert Ei(0) == S.NegativeInfinity assert Ei(oo) == S.Infinity assert Ei(-oo) == S.Zero assert tn_branch(Ei) assert mytd(Ei(x), exp(x) / x, x) assert mytn(Ei(x), Ei(x).rewrite(uppergamma), -uppergamma(0, x * polar_lift(-1)) - I * pi, x) assert mytn(Ei(x), Ei(x).rewrite(expint), -expint(1, x * polar_lift(-1)) - I * pi, x) assert Ei(x).rewrite(expint).rewrite(Ei) == Ei(x) assert Ei(x * exp_polar(2 * I * pi)) == Ei(x) + 2 * I * pi assert Ei(x * exp_polar(-2 * I * pi)) == Ei(x) - 2 * I * pi assert mytn(Ei(x), Ei(x).rewrite(Shi), Chi(x) + Shi(x), x) assert mytn(Ei(x * polar_lift(I)), Ei(x * polar_lift(I)).rewrite(Si), Ci(x) + I * Si(x) + I * pi / 2, x) assert Ei(log(x)).rewrite(li) == li(x) assert Ei(2 * log(x)).rewrite(li) == li(x**2) assert gruntz(Ei(x + exp(-x)) * exp(-x) * x, x, oo) == 1 assert Ei(x).series(x) == EulerGamma + log(x) + x + x**2/4 + \ x**3/18 + x**4/96 + x**5/600 + O(x**6) assert Ei(x).series(x, 1, 3) == Ei(1) + E * (x - 1) + O((x - 1)**3, (x, 1)) assert str(Ei(cos(2)).evalf(n=10)) == '-0.6760647401' raises(ArgumentIndexError, lambda: Ei(x).fdiff(2))
def test_ei(): assert tn_branch(Ei) assert mytd(Ei(x), exp(x) / x, x) assert mytn(Ei(x), Ei(x).rewrite(uppergamma), -uppergamma(0, x * polar_lift(-1)) - I * pi, x) assert mytn(Ei(x), Ei(x).rewrite(expint), -expint(1, x * polar_lift(-1)) - I * pi, x) assert Ei(x).rewrite(expint).rewrite(Ei) == Ei(x) assert Ei(x * exp_polar(2 * I * pi)) == Ei(x) + 2 * I * pi assert Ei(x * exp_polar(-2 * I * pi)) == Ei(x) - 2 * I * pi assert mytn(Ei(x), Ei(x).rewrite(Shi), Chi(x) + Shi(x), x) assert mytn(Ei(x * polar_lift(I)), Ei(x * polar_lift(I)).rewrite(Si), Ci(x) + I * Si(x) + I * pi / 2, x) assert Ei(log(x)).rewrite(li) == li(x) assert Ei(2 * log(x)).rewrite(li) == li(x**2) assert gruntz(Ei(x + exp(-x)) * exp(-x) * x, x, oo) == 1 assert Ei(x).series(x) == EulerGamma + log(x) + x + x**2/4 + \ x**3/18 + x**4/96 + x**5/600 + O(x**6) assert str(Ei(cos(2)).evalf(n=10)) == '-0.6760647401'
def test_Li(): assert Li(2) == 0 assert Li(oo) == oo assert isinstance(Li(z), Li) assert diff(Li(z), z) == 1/log(z) assert gruntz(1/Li(z), z, oo) == 0 assert Li(z).rewrite(li) == li(z) - li(2)
def test_Li(): assert Li(2) == 0 assert Li(oo) == oo assert isinstance(Li(z), Li) assert diff(Li(z), z) == 1 / log(z) assert gruntz(1 / Li(z), z, oo) == 0 assert Li(z).rewrite(li) == li(z) - li(2) raises(ArgumentIndexError, lambda: Li(z).fdiff(2))
def multiply_epsilon(self): """Looks for epsilon in the denominator of the equation. If found, multiplies that equation by epsilon to remove instabilities. """ for i, eq in enumerate(self.dae.model_eqs['res'].eqs.sym_list): if eq['eq'].has(Symbol("epsilon")): g_limit = gruntz(eq['eq'], Symbol("epsilon"), 0) if len( set([ sympy.numbers.Infinity(), sympy.numbers.NegativeInfinity() ]) & g_limit.atoms()) != 0: self.dae.model_eqs['res'].eqs.multiply_epsilon(i) for i, eq in enumerate(self.dae.model_eqs['icd'].eqs.sym_list): g_limit = gruntz(eq['eq'], Symbol("epsilon"), 0) if len( set([ sympy.numbers.Infinity(), sympy.numbers.NegativeInfinity() ]) & g_limit.atoms()) != 0: self.dae.model_eqs['icd'].eqs.multiply_epsilon(i)
def test_Li(): assert Li(2) == 0 assert Li(oo) is oo assert isinstance(Li(z), Li) assert diff(Li(z), z) == 1 / log(z) assert gruntz(1 / Li(z), z, oo) == 0 assert Li(z).rewrite(li) == li(z) - li(2) assert Li(z).series(z) == \ log(z)**5/600 + log(z)**4/96 + log(z)**3/18 + log(z)**2/4 + log(z) + log(log(z)) - li(2) + EulerGamma raises(ArgumentIndexError, lambda: Li(z).fdiff(2))
def eval_epsilon(self, eq): """Evaluates the limit as epsilon goes to zero in the given equation. Parameters ---------- eq : ``str`` The equation to be evaluated. Returns ------- ``dict`` The dictionary containing the equation evaluated as epsilon goes to zero. """ eps = gruntz(simplify(sympify(eq)), Symbol("epsilon"), 0) to_send = {'type': "epsilon", 'eq': str(eps), 'latex': latex(eps)} return json.dumps(to_send)
def test_li(): z = Symbol("z") zr = Symbol("z", real=True) zp = Symbol("z", positive=True) zn = Symbol("z", negative=True) assert li(0) == 0 assert li(1) is -oo assert li(oo) is oo assert isinstance(li(z), li) assert unchanged(li, -zp) assert unchanged(li, zn) assert diff(li(z), z) == 1 / log(z) assert conjugate(li(z)) == li(conjugate(z)) assert conjugate(li(-zr)) == li(-zr) assert unchanged(conjugate, li(-zp)) assert unchanged(conjugate, li(zn)) assert li(z).rewrite(Li) == Li(z) + li(2) assert li(z).rewrite(Ei) == Ei(log(z)) assert li(z).rewrite(uppergamma) == (-log(1 / log(z)) / 2 - log(-log(z)) + log(log(z)) / 2 - expint(1, -log(z))) assert li(z).rewrite(Si) == (-log(I * log(z)) - log(1 / log(z)) / 2 + log(log(z)) / 2 + Ci(I * log(z)) + Shi(log(z))) assert li(z).rewrite(Ci) == (-log(I * log(z)) - log(1 / log(z)) / 2 + log(log(z)) / 2 + Ci(I * log(z)) + Shi(log(z))) assert li(z).rewrite(Shi) == (-log(1 / log(z)) / 2 + log(log(z)) / 2 + Chi(log(z)) - Shi(log(z))) assert li(z).rewrite(Chi) == (-log(1 / log(z)) / 2 + log(log(z)) / 2 + Chi(log(z)) - Shi(log(z))) assert li(z).rewrite(hyper) == (log(z) * hyper( (1, 1), (2, 2), log(z)) - log(1 / log(z)) / 2 + log(log(z)) / 2 + EulerGamma) assert li(z).rewrite(meijerg) == (-log(1 / log(z)) / 2 - log(-log(z)) + log(log(z)) / 2 - meijerg( ((), (1, )), ((0, 0), ()), -log(z))) assert gruntz(1 / li(z), z, oo) == 0 assert li(z).series(z) == log(z)**5/600 + log(z)**4/96 + log(z)**3/18 + log(z)**2/4 + \ log(z) + log(log(z)) + EulerGamma raises(ArgumentIndexError, lambda: li(z).fdiff(2))
def test_li(): z = Symbol("z") zr = Symbol("z", real=True) zp = Symbol("z", positive=True) zn = Symbol("z", negative=True) assert li(0) == 0 assert li(1) == -oo assert li(oo) == oo assert isinstance(li(z), li) assert diff(li(z), z) == 1 / log(z) assert conjugate(li(z)) == li(conjugate(z)) assert conjugate(li(-zr)) == li(-zr) assert conjugate(li(-zp)) == conjugate(li(-zp)) assert conjugate(li(zn)) == conjugate(li(zn)) assert li(z).rewrite(Li) == Li(z) + li(2) assert li(z).rewrite(Ei) == Ei(log(z)) assert li(z).rewrite(uppergamma) == (-log(1 / log(z)) / 2 - log(-log(z)) + log(log(z)) / 2 - expint(1, -log(z))) assert li(z).rewrite(Si) == (-log(I * log(z)) - log(1 / log(z)) / 2 + log(log(z)) / 2 + Ci(I * log(z)) + Shi(log(z))) assert li(z).rewrite(Ci) == (-log(I * log(z)) - log(1 / log(z)) / 2 + log(log(z)) / 2 + Ci(I * log(z)) + Shi(log(z))) assert li(z).rewrite(Shi) == (-log(1 / log(z)) / 2 + log(log(z)) / 2 + Chi(log(z)) - Shi(log(z))) assert li(z).rewrite(Chi) == (-log(1 / log(z)) / 2 + log(log(z)) / 2 + Chi(log(z)) - Shi(log(z))) assert li(z).rewrite(hyper) == (log(z) * hyper( (1, 1), (2, 2), log(z)) - log(1 / log(z)) / 2 + log(log(z)) / 2 + EulerGamma) assert li(z).rewrite(meijerg) == (-log(1 / log(z)) / 2 - log(-log(z)) + log(log(z)) / 2 - meijerg( ((), (1, )), ((0, 0), ()), -log(z))) assert gruntz(1 / li(z), z, oo) == 0
def test_li(): z = Symbol("z") zr = Symbol("z", real=True) zp = Symbol("z", positive=True) zn = Symbol("z", negative=True) assert li(0) == 0 assert li(1) == -oo assert li(oo) == oo assert isinstance(li(z), li) assert diff(li(z), z) == 1/log(z) assert conjugate(li(z)) == li(conjugate(z)) assert conjugate(li(-zr)) == li(-zr) assert conjugate(li(-zp)) == conjugate(li(-zp)) assert conjugate(li(zn)) == conjugate(li(zn)) assert li(z).rewrite(Li) == Li(z) + li(2) assert li(z).rewrite(Ei) == Ei(log(z)) assert li(z).rewrite(uppergamma) == (-log(1/log(z))/2 - log(-log(z)) + log(log(z))/2 - expint(1, -log(z))) assert li(z).rewrite(Si) == (-log(I*log(z)) - log(1/log(z))/2 + log(log(z))/2 + Ci(I*log(z)) + Shi(log(z))) assert li(z).rewrite(Ci) == (-log(I*log(z)) - log(1/log(z))/2 + log(log(z))/2 + Ci(I*log(z)) + Shi(log(z))) assert li(z).rewrite(Shi) == (-log(1/log(z))/2 + log(log(z))/2 + Chi(log(z)) - Shi(log(z))) assert li(z).rewrite(Chi) == (-log(1/log(z))/2 + log(log(z))/2 + Chi(log(z)) - Shi(log(z))) assert li(z).rewrite(hyper) ==(log(z)*hyper((1, 1), (2, 2), log(z)) - log(1/log(z))/2 + log(log(z))/2 + EulerGamma) assert li(z).rewrite(meijerg) == (-log(1/log(z))/2 - log(-log(z)) + log(log(z))/2 - meijerg(((), (1,)), ((0, 0), ()), -log(z))) assert gruntz(1/li(z), z, oo) == 0
def test_ei(): assert tn_branch(Ei) assert mytd(Ei(x), exp(x)/x, x) assert mytn(Ei(x), Ei(x).rewrite(uppergamma), -uppergamma(0, x*polar_lift(-1)) - I*pi, x) assert mytn(Ei(x), Ei(x).rewrite(expint), -expint(1, x*polar_lift(-1)) - I*pi, x) assert Ei(x).rewrite(expint).rewrite(Ei) == Ei(x) assert Ei(x*exp_polar(2*I*pi)) == Ei(x) + 2*I*pi assert Ei(x*exp_polar(-2*I*pi)) == Ei(x) - 2*I*pi assert mytn(Ei(x), Ei(x).rewrite(Shi), Chi(x) + Shi(x), x) assert mytn(Ei(x*polar_lift(I)), Ei(x*polar_lift(I)).rewrite(Si), Ci(x) + I*Si(x) + I*pi/2, x) assert Ei(log(x)).rewrite(li) == li(x) assert Ei(2*log(x)).rewrite(li) == li(x**2) assert gruntz(Ei(x+exp(-x))*exp(-x)*x, x, oo) == 1 assert Ei(x).series(x) == EulerGamma + log(x) + x + x**2/4 + \ x**3/18 + x**4/96 + x**5/600 + O(x**6) assert str(Ei(cos(2)).evalf(n=10)) == '-0.6760647401'
def eval_epsilon(self): """Take the limit as the parameter epsilon goes to zero. """ if self.symbol: self.symbol = gruntz(sympify(self.symbol).simplify(), Symbol("epsilon"), 0) self.eq = gruntz(sympify(self.eq).simplify(), Symbol("epsilon"), 0)