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

moving private doctests to pytest in mathics.builtin.specialfns, #915

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
69 changes: 0 additions & 69 deletions mathics/builtin/numbers/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ class Eigenvalues(Builtin):

>> Eigenvalues[{{7, 1}, {-4, 3}}]
= {5, 5}

#> Eigenvalues[{{1, 0}, {0}}]
: Argument {{1, 0}, {0}} at position 1 is not a non-empty rectangular matrix.
= Eigenvalues[{{1, 0}, {0}}]
"""

messages = {
Expand Down Expand Up @@ -221,9 +217,6 @@ class Eigenvectors(Builtin):
>> Eigenvectors[{{0.1, 0.2}, {0.8, 0.5}}]
= ...
### = {{-0.355518, -1.15048}, {-0.62896, 0.777438}}

#> Eigenvectors[{{-2, 1, -1}, {-3, 2, 1}, {-1, 1, 0}}]
= {{1, 7, 3}, {1, 1, 0}, {0, 0, 0}}
"""

messages = {
Expand Down Expand Up @@ -365,18 +358,6 @@ class LeastSquares(Builtin):
>> LeastSquares[{{1, 1, 1}, {1, 1, 2}}, {1, 3}]
: Solving for underdetermined system not implemented.
= LeastSquares[{{1, 1, 1}, {1, 1, 2}}, {1, 3}]

## Inconsistent system - ideally we'd print a different message
#> LeastSquares[{{1, 1, 1}, {1, 1, 1}}, {1, 0}]
: Solving for underdetermined system not implemented.
= LeastSquares[{{1, 1, 1}, {1, 1, 1}}, {1, 0}]

#> LeastSquares[{1, {2}}, {1, 2}]
: Argument {1, {2}} at position 1 is not a non-empty rectangular matrix.
= LeastSquares[{1, {2}}, {1, 2}]
#> LeastSquares[{{1, 2}, {3, 4}}, {1, {2}}]
: Argument {1, {2}} at position 2 is not a non-empty rectangular matrix.
= LeastSquares[{{1, 2}, {3, 4}}, {1, {2}}]
"""

messages = {
Expand Down Expand Up @@ -510,13 +491,6 @@ class LinearSolve(Builtin):
>> LinearSolve[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, {1, -2, 3}]
: Linear equation encountered that has no solution.
= LinearSolve[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, {1, -2, 3}]

#> LinearSolve[{1, {2}}, {1, 2}]
: Argument {1, {2}} at position 1 is not a non-empty rectangular matrix.
= LinearSolve[{1, {2}}, {1, 2}]
#> LinearSolve[{{1, 2}, {3, 4}}, {1, {2}}]
: Argument {1, {2}} at position 2 is not a non-empty rectangular matrix.
= LinearSolve[{{1, 2}, {3, 4}}, {1, {2}}]
"""

messages = {
Expand Down Expand Up @@ -582,13 +556,6 @@ class MatrixExp(Builtin):

>> MatrixExp[{{1.5, 0.5}, {0.5, 2.0}}]
= {{5.16266, 3.02952}, {3.02952, 8.19218}}

#> MatrixExp[{{a, 0}, {0, b}}]
= {{E ^ a, 0}, {0, E ^ b}}

#> MatrixExp[{{1, 0}, {0}}]
: Argument {{1, 0}, {0}} at position 1 is not a non-empty rectangular matrix.
= MatrixExp[{{1, 0}, {0}}]
"""

messages = {
Expand Down Expand Up @@ -628,13 +595,6 @@ class MatrixPower(Builtin):

>> MatrixPower[{{1, 2}, {2, 5}}, -3]
= {{169, -70}, {-70, 29}}

#> MatrixPower[{{0, x}, {0, 0}}, n]
= MatrixPower[{{0, x}, {0, 0}}, n]

#> MatrixPower[{{1, 0}, {0}}, 2]
: Argument {{1, 0}, {0}} at position 1 is not a non-empty rectangular matrix.
= MatrixPower[{{1, 0}, {0}}, 2]
"""

messages = {
Expand Down Expand Up @@ -681,10 +641,6 @@ class MatrixRank(Builtin):
= 3
>> MatrixRank[{{a, b}, {3 a, 3 b}}]
= 1

#> MatrixRank[{{1, 0}, {0}}]
: Argument {{1, 0}, {0}} at position 1 is not a non-empty rectangular matrix.
= MatrixRank[{{1, 0}, {0}}]
"""

messages = {
Expand Down Expand Up @@ -721,10 +677,6 @@ class NullSpace(Builtin):
= {}
>> MatrixRank[A]
= 3

#> NullSpace[{1, {2}}]
: Argument {1, {2}} at position 1 is not a non-empty rectangular matrix.
= NullSpace[{1, {2}}]
"""

messages = {
Expand Down Expand Up @@ -764,10 +716,6 @@ class PseudoInverse(Builtin):

>> PseudoInverse[{{1.0, 2.5}, {2.5, 1.0}}]
= {{-0.190476, 0.47619}, {0.47619, -0.190476}}

#> PseudoInverse[{1, {2}}]
: Argument {1, {2}} at position 1 is not a non-empty rectangular matrix.
= PseudoInverse[{1, {2}}]
"""

messages = {
Expand Down Expand Up @@ -798,10 +746,6 @@ class QRDecomposition(Builtin):

>> QRDecomposition[{{1, 2}, {3, 4}, {5, 6}}]
= {{{Sqrt[35] / 35, 3 Sqrt[35] / 35, Sqrt[35] / 7}, {13 Sqrt[210] / 210, 2 Sqrt[210] / 105, -Sqrt[210] / 42}}, {{Sqrt[35], 44 Sqrt[35] / 35}, {0, 2 Sqrt[210] / 35}}}

#> QRDecomposition[{1, {2}}]
: Argument {1, {2}} at position 1 is not a non-empty rectangular matrix.
= QRDecomposition[{1, {2}}]
"""

messages = {
Expand Down Expand Up @@ -844,10 +788,6 @@ class RowReduce(Builtin):
. 0 1 2
.
. 0 0 0

#> RowReduce[{{1, 0}, {0}}]
: Argument {{1, 0}, {0}} at position 1 is not a non-empty rectangular matrix.
= RowReduce[{{1, 0}, {0}}]
"""

messages = {
Expand Down Expand Up @@ -881,15 +821,6 @@ class SingularValueDecomposition(Builtin):

>> SingularValueDecomposition[{{1.5, 2.0}, {2.5, 3.0}}]
= {{{0.538954, 0.842335}, {0.842335, -0.538954}}, {{4.63555, 0.}, {0., 0.107862}}, {{0.628678, 0.777666}, {-0.777666, 0.628678}}}


#> SingularValueDecomposition[{{3/2, 2}, {5/2, 3}}]
: Symbolic SVD is not implemented, performing numerically.
= {{{0.538954, 0.842335}, {0.842335, -0.538954}}, {{4.63555, 0.}, {0., 0.107862}}, {{0.628678, 0.777666}, {-0.777666, 0.628678}}}

#> SingularValueDecomposition[{1, {2}}]
: Argument {1, {2}} at position 1 is not a non-empty rectangular matrix.
= SingularValueDecomposition[{1, {2}}]
"""

# Sympy lacks symbolic SVD
Expand Down
79 changes: 3 additions & 76 deletions mathics/builtin/numbers/numbertheory.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ class Divisors(Builtin):
= {1, 2, 4, 8, 11, 16, 22, 32, 44, 64, 88, 176, 352, 704}
>> Divisors[{87, 106, 202, 305}]
= {{1, 3, 29, 87}, {1, 2, 53, 106}, {1, 2, 101, 202}, {1, 5, 61, 305}}
#> Divisors[0]
= Divisors[0]
#> Divisors[{-206, -502, -1702, 9}]
= {{1, 2, 103, 206}, {1, 2, 251, 502}, {1, 2, 23, 37, 46, 74, 851, 1702}, {1, 3, 9}}
#> Length[Divisors[1000*369]]
= 96
#> Length[Divisors[305*176*369*100]]
= 672
"""

# TODO: support GaussianIntegers
Expand Down Expand Up @@ -275,21 +267,6 @@ class FractionalPart(Builtin):

>> FractionalPart[-5.25]
= -0.25

#> FractionalPart[b]
= FractionalPart[b]

#> FractionalPart[{-2.4, -2.5, -3.0}]
= {-0.4, -0.5, 0.}

#> FractionalPart[14/32]
= 7 / 16

#> FractionalPart[4/(1 + 3 I)]
= 2 / 5 - I / 5

#> FractionalPart[Pi^20]
= -8769956796 + Pi ^ 20
"""

attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_READ_PROTECTED | A_PROTECTED
Expand Down Expand Up @@ -370,47 +347,6 @@ class MantissaExponent(Builtin):

>> MantissaExponent[10, b]
= MantissaExponent[10, b]

#> MantissaExponent[E, Pi]
= {E / Pi, 1}

#> MantissaExponent[Pi, Pi]
= {1 / Pi, 2}

#> MantissaExponent[5/2 + 3, Pi]
= {11 / (2 Pi ^ 2), 2}

#> MantissaExponent[b]
= MantissaExponent[b]

#> MantissaExponent[17, E]
= {17 / E ^ 3, 3}

#> MantissaExponent[17., E]
= {0.84638, 3}

#> MantissaExponent[Exp[Pi], 2]
= {E ^ Pi / 32, 5}

#> MantissaExponent[3 + 2 I, 2]
: The value 3 + 2 I is not a real number
= MantissaExponent[3 + 2 I, 2]

#> MantissaExponent[25, 0.4]
: Base 0.4 is not a real number greater than 1.
= MantissaExponent[25, 0.4]

#> MantissaExponent[0.0000124]
= {0.124, -4}

#> MantissaExponent[0.0000124, 2]
= {0.812646, -16}

#> MantissaExponent[0]
= {0, 0}

#> MantissaExponent[0, 2]
= {0, 0}
"""

attributes = A_LISTABLE | A_PROTECTED
Expand Down Expand Up @@ -674,9 +610,6 @@ class PrimePowerQ(Builtin):

>> PrimePowerQ[371293]
= True

#> PrimePowerQ[1]
= False
"""

attributes = A_LISTABLE | A_PROTECTED | A_READ_PROTECTED
Expand All @@ -687,19 +620,19 @@ class PrimePowerQ(Builtin):

# TODO: GaussianIntegers option
"""
#> PrimePowerQ[5, GaussianIntegers -> True]
##> PrimePowerQ[5, GaussianIntegers -> True]
= False
"""

# TODO: Complex args
"""
#> PrimePowerQ[{3 + I, 3 - 2 I, 3 + 4 I, 9 + 7 I}]
##> PrimePowerQ[{3 + I, 3 - 2 I, 3 + 4 I, 9 + 7 I}]
= {False, True, True, False}
"""

# TODO: Gaussian rationals
"""
#> PrimePowerQ[2/125 - 11 I/125]
##> PrimePowerQ[2/125 - 11 I/125]
= True
"""

Expand Down Expand Up @@ -740,12 +673,6 @@ class RandomPrime(Builtin):

>> RandomPrime[{10,30}, {2,5}]
= ...

#> RandomPrime[{10,12}, {2,2}]
= {{11, 11}, {11, 11}}

#> RandomPrime[2, {3,2}]
= {{2, 2}, {2, 2}, {2, 2}}
"""

messages = {
Expand Down
28 changes: 0 additions & 28 deletions mathics/builtin/specialfns/bessel.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@


class _Bessel(MPMathFunction):

attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_PROTECTED | A_READ_PROTECTED

nargs = {2}
Expand Down Expand Up @@ -109,18 +108,6 @@ class AiryAiZero(Builtin):

>> N[AiryAiZero[1]]
= -2.33811

#> AiryAiZero[1]
= AiryAiZero[1]

#> AiryAiZero[1.]
= AiryAiZero[1.]

#> AiryAi[AiryAiZero[1]]
= 0

#> N[AiryAiZero[2], 100]
= -4.087949444130970616636988701457391060224764699108529754984160876025121946836047394331169160758270562
"""

# TODO: 'AiryAiZero[$k$, $x0$]' - $k$th zero less than x0
Expand Down Expand Up @@ -235,18 +222,6 @@ class AiryBiZero(Builtin):

>> N[AiryBiZero[1]]
= -1.17371

#> AiryBiZero[1]
= AiryBiZero[1]

#> AiryBiZero[1.]
= AiryBiZero[1.]

#> AiryBi[AiryBiZero[1]]
= 0

#> N[AiryBiZero[2], 100]
= -3.271093302836352715680228240166413806300935969100284801485032396261130864238742879252000673830055014
"""

# TODO: 'AiryBiZero[$k$, $x0$]' - $k$th zero less than x0
Expand Down Expand Up @@ -380,9 +355,6 @@ class BesselJ(_Bessel):
>> BesselJ[0, 5.2]
= -0.11029

#> BesselJ[2.5, 1]
= 0.0494968

>> D[BesselJ[n, z], z]
= -BesselJ[1 + n, z] / 2 + BesselJ[-1 + n, z] / 2

Expand Down
18 changes: 0 additions & 18 deletions mathics/builtin/specialfns/gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ class Factorial(PostfixOperator, MPMathFunction):
>> !a! //FullForm
= Not[Factorial[a]]

#> 0!
= 1
"""

attributes = A_NUMERIC_FUNCTION | A_PROTECTED
Expand Down Expand Up @@ -301,22 +299,6 @@ class Gamma(MPMathMultiFunction):
Both 'Gamma' and 'Factorial' functions are continuous:
>> Plot[{Gamma[x], x!}, {x, 0, 4}]
= -Graphics-

## Issue 203
#> N[Gamma[24/10], 100]
= 1.242169344504305404913070252268300492431517240992022966055507541481863694148882652446155342679460339
#> N[N[Gamma[24/10],100]/N[Gamma[14/10],100],100]
= 1.400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
#> % // Precision
= 100.

#> Gamma[1.*^20]
: Overflow occurred in computation.
= Overflow[]

## Needs mpmath support for lowergamma
#> Gamma[1., 2.]
= Gamma[1., 2.]
"""

mpmath_names = {
Expand Down
3 changes: 0 additions & 3 deletions mathics/builtin/specialfns/orthogonal.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,6 @@ class SphericalHarmonicY(MPMathFunction):
## Results depend on sympy version
>> SphericalHarmonicY[3, 1, theta, phi]
= ...

#> SphericalHarmonicY[1,1,x,y]
= -Sqrt[6] E ^ (I y) Sin[x] / (4 Sqrt[Pi])
"""

nargs = {4}
Expand Down
Loading
Loading