def test_specfun(): for f in [besselj, bessely, besseli, besselk]: assert mcode(f(n, x)) == f.__name__ + '(n, x)' assert mcode(hankel1(n, x)) == 'besselh(n, 1, x)' assert mcode(hankel2(n, x)) == 'besselh(n, 2, x)' assert mcode(airyai(x)) == 'airy(0, x)' assert mcode(airyaiprime(x)) == 'airy(1, x)' assert mcode(airybi(x)) == 'airy(2, x)' assert mcode(airybiprime(x)) == 'airy(3, x)' assert mcode(uppergamma(n, x)) == 'gammainc(x, n, \'upper\')' assert mcode(lowergamma(n, x)) == 'gammainc(x, n, \'lower\')' assert mcode(jn(n, x)) == 'sqrt(2)*sqrt(pi)*sqrt(1./x).*besselj(n + 1/2, x)/2' assert mcode(yn(n, x)) == 'sqrt(2)*sqrt(pi)*sqrt(1./x).*bessely(n + 1/2, x)/2' assert mcode(Chi(x)) == 'coshint(x)' assert mcode(Ci(x)) == 'cosint(x)' assert mcode(laguerre(n, x)) == 'laguerreL(n, x)' assert mcode(li(x)) == 'logint(x)' assert mcode(loggamma(x)) == 'gammaln(x)' assert mcode(polygamma(n, x)) == 'psi(n, x)' assert mcode(Shi(x)) == 'sinhint(x)' assert mcode(Si(x)) == 'sinint(x)' assert mcode(LambertW(x)) == 'lambertw(x)' assert mcode(LambertW(x, n)) == 'lambertw(n, x)' assert mcode(zeta(x)) == 'zeta(x)' assert mcode(zeta(x, y)) == '% Not supported in Octave:\n% zeta\nzeta(x, y)'
def test_harmonic(): n = Symbol("n") assert harmonic(n, 0) == n assert harmonic(n).evalf() == harmonic(n) assert harmonic(n, 1) == harmonic(n) assert harmonic(1, n).evalf() == harmonic(1, n) assert harmonic(0, 1) == 0 assert harmonic(1, 1) == 1 assert harmonic(2, 1) == Rational(3, 2) assert harmonic(3, 1) == Rational(11, 6) assert harmonic(4, 1) == Rational(25, 12) assert harmonic(0, 2) == 0 assert harmonic(1, 2) == 1 assert harmonic(2, 2) == Rational(5, 4) assert harmonic(3, 2) == Rational(49, 36) assert harmonic(4, 2) == Rational(205, 144) assert harmonic(0, 3) == 0 assert harmonic(1, 3) == 1 assert harmonic(2, 3) == Rational(9, 8) assert harmonic(3, 3) == Rational(251, 216) assert harmonic(4, 3) == Rational(2035, 1728) assert harmonic(oo, -1) == S.NaN assert harmonic(oo, 0) == oo assert harmonic(oo, S.Half) == oo assert harmonic(oo, 1) == oo assert harmonic(oo, 2) == (pi**2) / 6 assert harmonic(oo, 3) == zeta(3)
def test_harmonic_limit(): n = Symbol("n") m = Symbol("m", positive=True) assert limit(harmonic(n, m + 1), n, oo) == zeta(m + 1) assert limit(harmonic(n, 2), n, oo) == pi**2/6 assert limit(harmonic(n, 3), n, oo) == -polygamma(2, 1)/2
def test_harmonic(): n = Symbol("n") assert harmonic(n, 0) == n assert harmonic(n).evalf() == harmonic(n) assert harmonic(n, 1) == harmonic(n) assert harmonic(1, n).evalf() == harmonic(1, n) assert harmonic(0, 1) == 0 assert harmonic(1, 1) == 1 assert harmonic(2, 1) == Rational(3, 2) assert harmonic(3, 1) == Rational(11, 6) assert harmonic(4, 1) == Rational(25, 12) assert harmonic(0, 2) == 0 assert harmonic(1, 2) == 1 assert harmonic(2, 2) == Rational(5, 4) assert harmonic(3, 2) == Rational(49, 36) assert harmonic(4, 2) == Rational(205, 144) assert harmonic(0, 3) == 0 assert harmonic(1, 3) == 1 assert harmonic(2, 3) == Rational(9, 8) assert harmonic(3, 3) == Rational(251, 216) assert harmonic(4, 3) == Rational(2035, 1728) assert harmonic(oo, -1) == nan assert harmonic(oo, 0) == oo assert harmonic(oo, Rational(1, 2)) == oo assert harmonic(oo, 1) == oo assert harmonic(oo, 2) == (pi**2)/6 assert harmonic(oo, 3) == zeta(3) assert harmonic(oo, x) == harmonic(oo, x, evaluate=False)
def test_harmonic_limit(): n = Symbol("n") m = Symbol("m", positive=True) assert limit(harmonic(n, m + 1), n, oo) == zeta(m + 1) assert limit(harmonic(n, 2), n, oo) == pi**2 / 6 assert limit(harmonic(n, 3), n, oo) == -polygamma(2, 1) / 2
def test_Function(): assert mcode(f(x, y, z)) == "f[x, y, z]" assert mcode(sin(x) ** cos(x)) == "Sin[x]^Cos[x]" assert mcode(sign(x)) == "Sign[x]" assert mcode(atanh(x), user_functions={"atanh": "ArcTanh"}) == "ArcTanh[x]" assert (mcode(meijerg(((1, 1), (3, 4)), ((1,), ()), x)) == "MeijerG[{{1, 1}, {3, 4}}, {{1}, {}}, x]") assert (mcode(hyper((1, 2, 3), (3, 4), x)) == "HypergeometricPFQ[{1, 2, 3}, {3, 4}, x]") assert mcode(Min(x, y)) == "Min[x, y]" assert mcode(Max(x, y)) == "Max[x, y]" assert mcode(Max(x, 2)) == "Max[2, x]" # issue sympy/sympy#15344 assert mcode(binomial(x, y)) == "Binomial[x, y]" assert mcode(log(x)) == "Log[x]" assert mcode(tan(x)) == "Tan[x]" assert mcode(cot(x)) == "Cot[x]" assert mcode(asin(x)) == "ArcSin[x]" assert mcode(acos(x)) == "ArcCos[x]" assert mcode(atan(x)) == "ArcTan[x]" assert mcode(acot(x)) == "ArcCot[x]" assert mcode(sinh(x)) == "Sinh[x]" assert mcode(cosh(x)) == "Cosh[x]" assert mcode(tanh(x)) == "Tanh[x]" assert mcode(coth(x)) == "Coth[x]" assert mcode(asinh(x)) == "ArcSinh[x]" assert mcode(acosh(x)) == "ArcCosh[x]" assert mcode(atanh(x)) == "ArcTanh[x]" assert mcode(acoth(x)) == "ArcCoth[x]" assert mcode(sech(x)) == "Sech[x]" assert mcode(csch(x)) == "Csch[x]" assert mcode(erfc(x)) == "Erfc[x]" assert mcode(conjugate(x)) == "Conjugate[x]" assert mcode(re(x)) == "Re[x]" assert mcode(im(x)) == "Im[x]" assert mcode(polygamma(x, y)) == "PolyGamma[x, y]" assert mcode(factorial(x)) == "Factorial[x]" assert mcode(factorial2(x)) == "Factorial2[x]" assert mcode(rf(x, y)) == "Pochhammer[x, y]" assert mcode(gamma(x)) == "Gamma[x]" assert mcode(zeta(x)) == "Zeta[x]" assert mcode(Heaviside(x)) == "UnitStep[x]" assert mcode(fibonacci(x)) == "Fibonacci[x]" assert mcode(polylog(x, y)) == "PolyLog[x, y]" class myfunc1(Function): @classmethod def eval(cls, x): pass class myfunc2(Function): @classmethod def eval(cls, x, y): pass pytest.raises(ValueError, lambda: mcode(myfunc1(x), user_functions={"myfunc1": ["Myfunc1"]})) assert mcode(myfunc1(x), user_functions={"myfunc1": "Myfunc1"}) == "Myfunc1[x]" assert mcode(myfunc2(x, y), user_functions={"myfunc2": [(lambda *x: False, "Myfunc2")]}) == "myfunc2[x, y]"
def test_harmonic_limit_fail(): n = Symbol("n") m = Symbol("m") # For m > 1: assert limit(harmonic(n, m), n, oo) == zeta(m)
def test_Function(): assert mcode(f(x, y, z)) == "f[x, y, z]" assert mcode(sin(x) ** cos(x)) == "Sin[x]^Cos[x]" assert mcode(sign(x)) == "Sign[x]" assert mcode(atanh(x), user_functions={"atanh": "ArcTanh"}) == "ArcTanh[x]" assert (mcode(meijerg(((1, 1), (3, 4)), ((1,), ()), x)) == "MeijerG[{{1, 1}, {3, 4}}, {{1}, {}}, x]") assert (mcode(hyper((1, 2, 3), (3, 4), x)) == "HypergeometricPFQ[{1, 2, 3}, {3, 4}, x]") assert mcode(Min(x, y)) == "Min[x, y]" assert mcode(Max(x, y)) == "Max[x, y]" assert mcode(Max(x, 2)) == "Max[2, x]" # issue sympy/sympy#15344 assert mcode(binomial(x, y)) == "Binomial[x, y]" assert mcode(log(x)) == "Log[x]" assert mcode(tan(x)) == "Tan[x]" assert mcode(cot(x)) == "Cot[x]" assert mcode(asin(x)) == "ArcSin[x]" assert mcode(acos(x)) == "ArcCos[x]" assert mcode(atan(x)) == "ArcTan[x]" assert mcode(sinh(x)) == "Sinh[x]" assert mcode(cosh(x)) == "Cosh[x]" assert mcode(tanh(x)) == "Tanh[x]" assert mcode(coth(x)) == "Coth[x]" assert mcode(sech(x)) == "Sech[x]" assert mcode(csch(x)) == "Csch[x]" assert mcode(erfc(x)) == "Erfc[x]" assert mcode(conjugate(x)) == "Conjugate[x]" assert mcode(re(x)) == "Re[x]" assert mcode(im(x)) == "Im[x]" assert mcode(polygamma(x, y)) == "PolyGamma[x, y]" assert mcode(factorial(x)) == "Factorial[x]" assert mcode(factorial2(x)) == "Factorial2[x]" assert mcode(rf(x, y)) == "Pochhammer[x, y]" assert mcode(gamma(x)) == "Gamma[x]" assert mcode(zeta(x)) == "Zeta[x]" assert mcode(asinh(x)) == "ArcSinh[x]" assert mcode(Heaviside(x)) == "UnitStep[x]" assert mcode(fibonacci(x)) == "Fibonacci[x]" assert mcode(polylog(x, y)) == "PolyLog[x, y]" assert mcode(atanh(x)) == "ArcTanh[x]" class myfunc1(Function): @classmethod def eval(cls, x): pass class myfunc2(Function): @classmethod def eval(cls, x, y): pass pytest.raises(ValueError, lambda: mcode(myfunc1(x), user_functions={"myfunc1": ["Myfunc1"]})) assert mcode(myfunc1(x), user_functions={"myfunc1": "Myfunc1"}) == "Myfunc1[x]" assert mcode(myfunc2(x, y), user_functions={"myfunc2": [(lambda *x: False, "Myfunc2")]}) == "myfunc2[x, y]"