def test_factorial(): n = Symbol('n', integer=True) assert str(factorial(-2)) == "zoo" assert str(factorial(0)) == "1" assert str(factorial(7)) == "5040" assert str(factorial(n)) == "factorial(n)" assert str(factorial(2 * n)) == "factorial(2*n)" assert str(factorial(factorial(n))) == 'factorial(factorial(n))' assert str(factorial(factorial2(n))) == 'factorial(factorial2(n))' assert str(factorial2(factorial(n))) == 'factorial2(factorial(n))' assert str(factorial2(factorial2(n))) == 'factorial2(factorial2(n))' assert str(subfactorial(3)) == "2" assert str(subfactorial(n)) == "subfactorial(n)" assert str(subfactorial(2 * n)) == "subfactorial(2*n)"
def test_factorial(): n = Symbol('n', integer=True) assert str(factorial(-2)) == 'zoo' assert str(factorial(0)) == '1' assert str(factorial(7)) == '5040' assert str(factorial(n)) == 'factorial(n)' assert str(factorial(2 * n)) == 'factorial(2*n)' assert str(factorial(factorial(n))) == 'factorial(factorial(n))' assert str(factorial(factorial2(n))) == 'factorial(factorial2(n))' assert str(factorial2(factorial(n))) == 'factorial2(factorial(n))' assert str(factorial2(factorial2(n))) == 'factorial2(factorial2(n))' assert str(subfactorial(3)) == '2' assert str(subfactorial(n)) == 'subfactorial(n)' assert str(subfactorial(2 * n)) == 'subfactorial(2*n)'
def test_factorial(): n = Symbol('n', integer=True) assert str(factorial(-2)) == "zoo" assert str(factorial(0)) == "1" assert str(factorial(7)) == "5040" assert str(factorial(n)) == "factorial(n)" assert str(factorial(2*n)) == "factorial(2*n)" assert str(factorial(factorial(n))) == 'factorial(factorial(n))' assert str(factorial(factorial2(n))) == 'factorial(factorial2(n))' assert str(factorial2(factorial(n))) == 'factorial2(factorial(n))' assert str(factorial2(factorial2(n))) == 'factorial2(factorial2(n))' assert str(subfactorial(3)) == "2" assert str(subfactorial(n)) == "subfactorial(n)" assert str(subfactorial(2*n)) == "subfactorial(2*n)"
def test_factorial2(): n = Symbol('n', integer=True) assert factorial2(-1) == 1 assert factorial2(0) == 1 assert factorial2(7) == 105 assert factorial2(8) == 384 assert factorial2(n).func == factorial2 factorial2(Rational(1, 2)) # issue sympy/sympy#10388 assert isinstance(factorial2(oo), factorial2) pytest.raises(ValueError, lambda: factorial2(-2)) nn = Symbol('nn', negative=True) assert isinstance(factorial2(Rational(-1, 2)), factorial2) # The following is exhaustive tt = Symbol('tt', integer=True, nonnegative=True) tte = Symbol('tte', even=True, nonnegative=True) tpe = Symbol('tpe', even=True, positive=True) tto = Symbol('tto', odd=True, nonnegative=True) tf = Symbol('tf', integer=True, nonnegative=False) tfe = Symbol('tfe', even=True, nonnegative=False) tfo = Symbol('tfo', odd=True, nonnegative=False) ft = Symbol('ft', integer=False, nonnegative=True) ff = Symbol('ff', integer=False, nonnegative=False) fn = Symbol('fn', integer=False) nt = Symbol('nt', nonnegative=True) nf = Symbol('nf', nonnegative=False) nn = Symbol('nn') assert factorial2(n).is_integer is None assert factorial2(tt - 1).is_integer assert factorial2(tte - 1).is_integer assert factorial2(tpe - 3).is_integer # This should work, but it doesn't due to ... # assert factorial2(tto - 4).is_integer assert factorial2(tto - 2).is_integer assert factorial2(tf).is_integer is None assert factorial2(tfe).is_integer is None assert factorial2(tfo).is_integer is None assert factorial2(ft).is_integer is None assert factorial2(ff).is_integer is None assert factorial2(fn).is_integer is None assert factorial2(nt).is_integer is None assert factorial2(nf).is_integer is None assert factorial2(nn).is_integer is None assert factorial2(n).is_positive is None assert factorial2(tt - 1).is_positive is True assert factorial2(tte - 1).is_positive is True # This should work, but it doesn't due to ... # assert factorial2(tpe - 3).is_positive is True assert factorial2(tpe - 1).is_positive is True # This should work, but it doesn't due to ... # assert factorial2(tto - 2).is_positive is True assert factorial2(tto - 1).is_positive is True assert factorial2(tf).is_positive is None assert factorial2(tfe).is_positive is None assert factorial2(tfo).is_positive is None assert factorial2(ft).is_positive is None assert factorial2(ff).is_positive is None assert factorial2(fn).is_positive is None assert factorial2(nt).is_positive is None assert factorial2(nf).is_positive is None assert factorial2(nn).is_positive is None assert factorial2(0, evaluate=False).is_even is False assert factorial2(0, evaluate=False).is_odd is True assert factorial2(tt).is_even is None assert factorial2(tt).is_odd is None assert factorial2(tte).is_even is None assert factorial2(tte).is_odd is None assert factorial2(tte + 2).is_even is True assert factorial2(tpe).is_even is True assert factorial2(tpe).is_odd is False assert factorial2(tto).is_odd is True assert factorial2(tf).is_even is None assert factorial2(tf).is_odd is None assert factorial2(tfe).is_even is None assert factorial2(tfe).is_odd is None assert factorial2(tfo).is_even is False assert factorial2(tfo).is_odd is None
def test_Function(): assert mathematica_code(f(x, y, z)) == 'f[x, y, z]' assert mathematica_code(sin(x)**cos(x)) == 'Sin[x]^Cos[x]' assert mathematica_code(sign(x)) == 'Sign[x]' assert mathematica_code(atanh(x), user_functions={'atanh': 'ArcTanh'}) == 'ArcTanh[x]' assert (mathematica_code(meijerg( ((1, 1), (3, 4)), ((1, ), ()), x)) == 'MeijerG[{{1, 1}, {3, 4}}, {{1}, {}}, x]') assert (mathematica_code(hyper( (1, 2, 3), (3, 4), x)) == 'HypergeometricPFQ[{1, 2, 3}, {3, 4}, x]') assert mathematica_code(Min(x, y)) == 'Min[x, y]' assert mathematica_code(Max(x, y)) == 'Max[x, y]' assert mathematica_code(Max(x, 2)) == 'Max[2, x]' # issue sympy/sympy#15344 assert mathematica_code(binomial(x, y)) == 'Binomial[x, y]' assert mathematica_code(log(x)) == 'Log[x]' assert mathematica_code(tan(x)) == 'Tan[x]' assert mathematica_code(cot(x)) == 'Cot[x]' assert mathematica_code(asin(x)) == 'ArcSin[x]' assert mathematica_code(acos(x)) == 'ArcCos[x]' assert mathematica_code(atan(x)) == 'ArcTan[x]' assert mathematica_code(acot(x)) == 'ArcCot[x]' assert mathematica_code(sinh(x)) == 'Sinh[x]' assert mathematica_code(cosh(x)) == 'Cosh[x]' assert mathematica_code(tanh(x)) == 'Tanh[x]' assert mathematica_code(coth(x)) == 'Coth[x]' assert mathematica_code(asinh(x)) == 'ArcSinh[x]' assert mathematica_code(acosh(x)) == 'ArcCosh[x]' assert mathematica_code(atanh(x)) == 'ArcTanh[x]' assert mathematica_code(acoth(x)) == 'ArcCoth[x]' assert mathematica_code(sech(x)) == 'Sech[x]' assert mathematica_code(csch(x)) == 'Csch[x]' assert mathematica_code(erf(x)) == 'Erf[x]' assert mathematica_code(erfi(x)) == 'Erfi[x]' assert mathematica_code(erfc(x)) == 'Erfc[x]' assert mathematica_code(conjugate(x)) == 'Conjugate[x]' assert mathematica_code(re(x)) == 'Re[x]' assert mathematica_code(im(x)) == 'Im[x]' assert mathematica_code(polygamma(x, y)) == 'PolyGamma[x, y]' assert mathematica_code(factorial(x)) == 'Factorial[x]' assert mathematica_code(factorial2(x)) == 'Factorial2[x]' assert mathematica_code(rf(x, y)) == 'Pochhammer[x, y]' assert mathematica_code(gamma(x)) == 'Gamma[x]' assert mathematica_code(zeta(x)) == 'Zeta[x]' assert mathematica_code(Heaviside(x)) == 'UnitStep[x]' assert mathematica_code(fibonacci(x)) == 'Fibonacci[x]' assert mathematica_code(polylog(x, y)) == 'PolyLog[x, y]' assert mathematica_code(loggamma(x)) == 'LogGamma[x]' assert mathematica_code(uppergamma(x, y)) == 'Gamma[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: mathematica_code(MyFunc1(x), user_functions={'MyFunc1': ['Myfunc1']})) assert mathematica_code(MyFunc1(x), user_functions={'MyFunc1': 'Myfunc1'}) == 'Myfunc1[x]' assert mathematica_code( MyFunc2(x, y), user_functions={'MyFunc2': [(lambda *x: False, 'Myfunc2')]}) == 'MyFunc2[x, y]'