Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move private doctests to pytests in mathics.builtin.numeric #916

Merged
merged 4 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 0 additions & 117 deletions mathics/builtin/numbers/algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,6 @@ class Apart(Builtin):
But it does not touch other expressions:
>> Sin[1 / (x ^ 2 - y ^ 2)] // Apart
= Sin[1 / (x ^ 2 - y ^ 2)]

#> Attributes[f] = {HoldAll}; Apart[f[x + x]]
= f[x + x]

#> Attributes[f] = {}; Apart[f[x + x]]
= f[2 x]
"""

attributes = A_LISTABLE | A_PROTECTED
Expand Down Expand Up @@ -504,25 +498,9 @@ class Coefficient(Builtin):
>> Coefficient[a x^2 + b y^3 + c x + d y + 5, x, 0]
= 5 + b y ^ 3 + d y

## Errors:
#> Coefficient[x + y + 3]
: Coefficient called with 1 argument; 2 or 3 arguments are expected.
= Coefficient[3 + x + y]
#> Coefficient[x + y + 3, 5]
: 5 is not a valid variable.
= Coefficient[3 + x + y, 5]

## This is known bug of Sympy 1.0, next Sympy version will fix it by this commit
## https://github.com/sympy/sympy/commit/25bf64b64d4d9a2dc563022818d29d06bc740d47
## #> Coefficient[x * y, z, 0]
## = x y
## ## Sympy 1.0 retuns 0

## ## TODO: Support Modulus
## >> Coefficient[(x + 2)^3 + (x + 3)^2, x, 0, Modulus -> 3]
## = 2
## #> Coefficient[(x + 2)^3 + (x + 3)^2, x, 0, {Modulus -> 3, Modulus -> 2, Modulus -> 10}]
## = {2, 1, 7}
"""

attributes = A_LISTABLE | A_PROTECTED
Expand Down Expand Up @@ -910,21 +888,11 @@ class CoefficientList(Builtin):
= {2 / (-3 + y), 1 / (-3 + y) + 1 / (-2 + y)}
>> CoefficientList[(x + y)^3, z]
= {(x + y) ^ 3}
#> CoefficientList[x + y, 5]
: 5 is not a valid variable.
= CoefficientList[x + y, 5]

## Form 2 CoefficientList[poly, {var1, var2, ...}]
>> CoefficientList[a x^2 + b y^3 + c x + d y + 5, {x, y}]
= {{5, d, 0, b}, {c, 0, 0, 0}, {a, 0, 0, 0}}
>> CoefficientList[(x - 2 y + 3 z)^3, {x, y, z}]
= {{{0, 0, 0, 27}, {0, 0, -54, 0}, {0, 36, 0, 0}, {-8, 0, 0, 0}}, {{0, 0, 27, 0}, {0, -36, 0, 0}, {12, 0, 0, 0}, {0, 0, 0, 0}}, {{0, 9, 0, 0}, {-6, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, {{1, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}}
#> CoefficientList[(x - 2 y)^4, {x, 2}]
: 2 is not a valid variable.
= CoefficientList[(x - 2 y) ^ 4, {x, 2}]
#> CoefficientList[x / y, {x, y}]
: x / y is not a polynomial.
= CoefficientList[x / y, {x, y}]
"""

messages = {
Expand Down Expand Up @@ -1182,22 +1150,6 @@ class Expand(_Expand):

>> Expand[(1 + a)^12, Modulus -> 4]
= 1 + 2 a ^ 2 + 3 a ^ 4 + 3 a ^ 8 + 2 a ^ 10 + a ^ 12

#> Expand[x, Modulus -> -1] (* copy odd MMA behaviour *)
= 0
#> Expand[x, Modulus -> x]
: Value of option Modulus -> x should be an integer.
= Expand[x, Modulus -> x]

#> a(b(c+d)+e) // Expand
= a b c + a b d + a e

#> (y^2)^(1/2)/(2x+2y)//Expand
= Sqrt[y ^ 2] / (2 x + 2 y)


#> 2(3+2x)^2/(5+x^2+3x)^3 // Expand
= 24 x / (5 + 3 x + x ^ 2) ^ 3 + 8 x ^ 2 / (5 + 3 x + x ^ 2) ^ 3 + 18 / (5 + 3 x + x ^ 2) ^ 3
"""

summary_text = "expand out products and powers"
Expand Down Expand Up @@ -1303,15 +1255,6 @@ class ExpandDenominator(_Expand):

>> ExpandDenominator[(a + b) ^ 2 / ((c + d)^2 (e + f))]
= (a + b) ^ 2 / (c ^ 2 e + c ^ 2 f + 2 c d e + 2 c d f + d ^ 2 e + d ^ 2 f)

## Modulus option
#> ExpandDenominator[1 / (x + y)^3, Modulus -> 3]
= 1 / (x ^ 3 + y ^ 3)
#> ExpandDenominator[1 / (x + y)^6, Modulus -> 4]
= 1 / (x ^ 6 + 2 x ^ 5 y + 3 x ^ 4 y ^ 2 + 3 x ^ 2 y ^ 4 + 2 x y ^ 5 + y ^ 6)

#> ExpandDenominator[2(3+2x)^2/(5+x^2+3x)^3]
= 2 (3 + 2 x) ^ 2 / (125 + 225 x + 210 x ^ 2 + 117 x ^ 3 + 42 x ^ 4 + 9 x ^ 5 + x ^ 6)
"""

summary_text = "expand just the denominator of a rational expression"
Expand Down Expand Up @@ -1354,11 +1297,6 @@ class Exponent(Builtin):
= -Infinity
>> Exponent[1, x]
= 0

## errors:
#> Exponent[x^2]
: Exponent called with 1 argument; 2 or 3 arguments are expected.
= Exponent[x ^ 2]
"""

attributes = A_LISTABLE | A_PROTECTED
Expand Down Expand Up @@ -1422,10 +1360,6 @@ class Factor(Builtin):
You can use Factor to find when a polynomial is zero:
>> x^2 - x == 0 // Factor
= x (-1 + x) == 0

## Issue659
#> Factor[{x+x^2}]
= {x (1 + x)}
"""

attributes = A_LISTABLE | A_PROTECTED
Expand Down Expand Up @@ -1467,9 +1401,6 @@ class FactorTermsList(Builtin):
= {2, -1 + x ^ 2}
>> FactorTermsList[x^2 - 2 x + 1]
= {1, 1 - 2 x + x ^ 2}
#> FactorTermsList[2 x^2 - 2, x]
= {2, 1, -1 + x ^ 2}

>> f = 3 (-1 + 2 x) (-1 + y) (1 - a)
= 3 (-1 + 2 x) (-1 + y) (1 - a)
>> FactorTermsList[f]
Expand Down Expand Up @@ -1775,17 +1706,6 @@ class MinimalPolynomial(Builtin):
= -2 - 2 x ^ 2 + x ^ 4
>> MinimalPolynomial[Sqrt[I + Sqrt[6]], x]
= 49 - 10 x ^ 4 + x ^ 8

#> MinimalPolynomial[7a, x]
: 7 a is not an explicit algebraic number.
= MinimalPolynomial[7 a, x]
#> MinimalPolynomial[3x^3 + 2x^2 + y^2 + ab, x]
: ab + 2 x ^ 2 + 3 x ^ 3 + y ^ 2 is not an explicit algebraic number.
= MinimalPolynomial[ab + 2 x ^ 2 + 3 x ^ 3 + y ^ 2, x]

## PurePoly
#> MinimalPolynomial[Sqrt[2 + Sqrt[3]]]
= 1 - 4 #1 ^ 2 + #1 ^ 4
"""

attributes = A_LISTABLE | A_PROTECTED
Expand Down Expand Up @@ -1874,37 +1794,6 @@ class PolynomialQ(Builtin):
= True
>> PolynomialQ[x^2 + axy^2 - bSin[c], {a, b, c}]
= False

#> PolynomialQ[x, x, y]
: PolynomialQ called with 3 arguments; 1 or 2 arguments are expected.
= PolynomialQ[x, x, y]

## Always return True if argument is Null
#> PolynomialQ[x^3 - 2 x/y + 3xz,]
: Warning: comma encountered with no adjacent expression. The expression will be treated as Null (line 1 of "<test>").
= True
#> PolynomialQ[, {x, y, z}]
: Warning: comma encountered with no adjacent expression. The expression will be treated as Null (line 1 of "<test>").
= True
#> PolynomialQ[, ]
: Warning: comma encountered with no adjacent expression. The expression will be treated as Null (line 1 of "<test>").
: Warning: comma encountered with no adjacent expression. The expression will be treated as Null (line 1 of "<test>").
= True

## TODO: MMA and Sympy handle these cases differently
## #> PolynomialQ[x^(1/2) + 6xyz]
## : No variable is not supported in PolynomialQ.
## = True
## #> PolynomialQ[x^(1/2) + 6xyz, {}]
## : No variable is not supported in PolynomialQ.
## = True

## #> PolynomialQ[x^3 - 2 x/y + 3xz]
## : No variable is not supported in PolynomialQ.
## = False
## #> PolynomialQ[x^3 - 2 x/y + 3xz, {}]
## : No variable is not supported in PolynomialQ.
## = False
"""

messages = {
Expand Down Expand Up @@ -1994,9 +1883,6 @@ class Together(Builtin):
But it does not touch other functions:
>> Together[f[a / c + b / c]]
= f[a / c + b / c]

#> f[x]/x+f[x]/x^2//Together
= f[x] (1 + x) / x ^ 2
"""

attributes = A_LISTABLE | A_PROTECTED
Expand Down Expand Up @@ -2030,9 +1916,6 @@ class Variables(Builtin):
= {a, b, c, x, y}
>> Variables[x + Sin[y]]
= {x, Sin[y]}
## failing test case from MMA docs
#> Variables[E^x]
= {}
"""
summary_text = "list of variables in a polynomial"

Expand Down
60 changes: 0 additions & 60 deletions mathics/builtin/numbers/calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,24 +172,6 @@ class D(SympyFunction):
Hesse matrix:
>> D[Sin[x] * Cos[y], {{x,y}, 2}]
= {{-Cos[y] Sin[x], -Cos[x] Sin[y]}, {-Cos[x] Sin[y], -Cos[y] Sin[x]}}

#> D[2/3 Cos[x] - 1/3 x Cos[x] Sin[x] ^ 2,x]//Expand
= -2 x Cos[x] ^ 2 Sin[x] / 3 + x Sin[x] ^ 3 / 3 - 2 Sin[x] / 3 - Cos[x] Sin[x] ^ 2 / 3

#> D[f[#1], {#1,2}]
= f''[#1]
#> D[(#1&)[t],{t,4}]
= 0

#> Attributes[f] ={HoldAll}; Apart[f''[x + x]]
= f''[2 x]

#> Attributes[f] = {}; Apart[f''[x + x]]
= f''[2 x]

## Issue #375
#> D[{#^2}, #]
= {2 #1}
"""

# TODO
Expand Down Expand Up @@ -416,16 +398,6 @@ class Derivative(PostfixOperator, SympyFunction):
= Derivative[2, 1][h]
>> Derivative[2, 0, 1, 0][h[g]]
= Derivative[2, 0, 1, 0][h[g]]

## Parser Tests
#> Hold[f''] // FullForm
= Hold[Derivative[2][f]]
#> Hold[f ' '] // FullForm
= Hold[Derivative[2][f]]
#> Hold[f '' ''] // FullForm
= Hold[Derivative[4][f]]
#> Hold[Derivative[x][4] '] // FullForm
= Hold[Derivative[1][Derivative[x][4]]]
"""

attributes = A_N_HOLD_ALL
Expand Down Expand Up @@ -866,12 +838,8 @@ class FindRoot(_BaseFinder):
= FindRoot[Sin[x] - x, {x, 0}]


#> FindRoot[2.5==x,{x,0}]
= {x -> 2.5}

>> FindRoot[x^2 - 2, {x, 1,3}, Method->"Secant"]
= {x -> 1.41421}

"""

rules = {
Expand Down Expand Up @@ -972,20 +940,6 @@ class Integrate(SympyFunction):
>> Integrate[f[x], {x, a, b}] // TeXForm
= \int_a^b f\left[x\right] \, dx

#> DownValues[Integrate]
= {}
#> Definition[Integrate]
= Attributes[Integrate] = {Protected, ReadProtected}
.
. Options[Integrate] = {Assumptions -> $Assumptions, GenerateConditions -> Automatic, PrincipalValue -> False}
#> Integrate[Hold[x + x], {x, a, b}]
= Integrate[Hold[x + x], {x, a, b}]
#> Integrate[sin[x], x]
= Integrate[sin[x], x]

#> Integrate[x ^ 3.5 + x, x]
= x ^ 2 / 2 + 0.222222 x ^ 4.5

Sometimes there is a loss of precision during integration.
You can check the precision of your result with the following sequence
of commands.
Expand All @@ -994,20 +948,6 @@ class Integrate(SympyFunction):
>> % // Precision
= MachinePrecision

#> Integrate[1/(x^5+1), x]
= RootSum[1 + 5 #1 + 25 #1 ^ 2 + 125 #1 ^ 3 + 625 #1 ^ 4&, Log[x + 5 #1] #1&] + Log[1 + x] / 5

#> Integrate[ArcTan(x), x]
= x ^ 2 ArcTan / 2
#> Integrate[E[x], x]
= Integrate[E[x], x]

#> Integrate[Exp[-(x/2)^2],{x,-Infinity,+Infinity}]
= 2 Sqrt[Pi]

#> Integrate[Exp[-1/(x^2)], x]
= x E ^ (-1 / x ^ 2) + Sqrt[Pi] Erf[1 / x]

>> Integrate[ArcSin[x / 3], x]
= x ArcSin[x / 3] + Sqrt[9 - x ^ 2]

Expand Down
42 changes: 0 additions & 42 deletions mathics/builtin/numbers/diffeqns.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,48 +42,6 @@ class DSolve(Builtin):

>> DSolve[D[y[x, t], t] + 2 D[y[x, t], x] == 0, y[x, t], {x, t}]
= {{y[x, t] -> C[1][x - 2 t]}}

## FIXME: sympy solves this as `Function[{x}, C[1] + Integrate[ArcSin[f[2 x]], x]]`
## #> Attributes[f] = {HoldAll};
## #> DSolve[f[x + x] == Sin[f'[x]], f, x]
## : To avoid possible ambiguity, the arguments of the dependent variable in f[x + x] == Sin[f'[x]] should literally match the independent variables.
## = DSolve[f[x + x] == Sin[f'[x]], f, x]

## #> Attributes[f] = {};
## #> DSolve[f[x + x] == Sin[f'[x]], f, x]
## : To avoid possible ambiguity, the arguments of the dependent variable in f[2 x] == Sin[f'[x]] should literally match the independent variables.
## = DSolve[f[2 x] == Sin[f'[x]], f, x]

#> DSolve[f'[x] == f[x], f, x] // FullForm
= {{Rule[f, Function[{x}, Times[C[1], Power[E, x]]]]}}

#> DSolve[f'[x] == f[x], f, x] /. {C[1] -> 1}
= {{f -> (Function[{x}, 1 E ^ x])}}

#> DSolve[f'[x] == f[x], f, x] /. {C -> D}
= {{f -> (Function[{x}, D[1] E ^ x])}}

#> DSolve[f'[x] == f[x], f, x] /. {C[1] -> C[0]}
= {{f -> (Function[{x}, C[0] E ^ x])}}

#> DSolve[f[x] == 0, f, {}]
: {} cannot be used as a variable.
= DSolve[f[x] == 0, f, {}]

## Order of arguments shoudn't matter
#> DSolve[D[f[x, y], x] == D[f[x, y], y], f, {x, y}]
= {{f -> (Function[{x, y}, C[1][-x - y]])}}
#> DSolve[D[f[x, y], x] == D[f[x, y], y], f[x, y], {x, y}]
= {{f[x, y] -> C[1][-x - y]}}
#> DSolve[D[f[x, y], x] == D[f[x, y], y], f[x, y], {y, x}]
= {{f[x, y] -> C[1][-x - y]}}
"""

# XXX sympy #11669 test
"""
#> DSolve[\\[Gamma]'[x] == 0, \\[Gamma], x]
: Hit sympy bug #11669.
= ...
"""

# TODO: GeneratedParameters option
Expand Down
21 changes: 0 additions & 21 deletions mathics/builtin/numbers/exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@ class Exp(MPMathFunction):

>> Plot[Exp[x], {x, 0, 3}]
= -Graphics-
#> Exp[1.*^20]
: Overflow occurred in computation.
= Overflow[]
"""

rules = {
Expand Down Expand Up @@ -206,21 +203,6 @@ class Log(MPMathFunction):
= Indeterminate
>> Plot[Log[x], {x, 0, 5}]
= -Graphics-

#> Log[1000] / Log[10] // Simplify
= 3

#> Log[1.4]
= 0.336472

#> Log[Exp[1.4]]
= 1.4

#> Log[-1.4]
= 0.336472 + 3.14159 I

#> N[Log[10], 30]
= 2.30258509299404568401799145468
"""

summary_text = "logarithm function"
Expand Down Expand Up @@ -316,9 +298,6 @@ class LogisticSigmoid(Builtin):

>> LogisticSigmoid[{-0.2, 0.1, 0.3}]
= {0.450166, 0.524979, 0.574443}

#> LogisticSigmoid[I Pi]
= LogisticSigmoid[I Pi]
"""

summary_text = "logistic function"
Expand Down
Loading