Skip to content

Commit d810880

Browse files
committed
Remove unit tests from algebra module
Also start adding module docstring for some other unit tests.
1 parent ee072c8 commit d810880

3 files changed

Lines changed: 13 additions & 95 deletions

File tree

mathics/builtin/numbers/algebra.py

Lines changed: 6 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,6 @@ class Simplify(Builtin):
384384
# = Undefined
385385
# >> Simplify[ConditionalExpression[1, a > 0], { a > 0 }]
386386
# = 1
387-
388-
#> Simplify[a*x^2+b*x^2]
389-
= x ^ 2 (a + b)
390-
391-
## triggers TypeError in sympy.simplify
392-
#> x f[{y}] // Simplify
393-
= x f[{y}]
394387
"""
395388

396389
rules = {
@@ -1271,7 +1264,7 @@ class Coefficient(Builtin):
12711264
<dd>return the coefficient of $form$^$n$ in $expr$.
12721265
</dl>
12731266
1274-
## Form 1
1267+
## Form 1: Coefficent[expr, form]
12751268
>> Coefficient[(x + y)^4, (x^2) * (y^2)]
12761269
= 6
12771270
>> Coefficient[a x^2 + b y^3 + c x + d y + 5, x]
@@ -1282,31 +1275,16 @@ class Coefficient(Builtin):
12821275
= 405
12831276
>> Coefficient[(x + 2)/(y - 3) + (x + 3)/(y - 2), x]
12841277
= 1 / (-3 + y) + 1 / (-2 + y)
1285-
#> Coefficient[(x + 2)/(y - 3) + (x + 3)/(y - 2), z, 0]
1286-
= (2 + x) / (-3 + y) + (3 + x) / (-2 + y)
1287-
#> Coefficient[y (x - 2)/((y^2 - 9)) + (x + 5)/(y + 2), x]
1288-
= y / (-9 + y ^ 2) + 1 / (2 + y)
1289-
#> Coefficient[y (x - 2)/((y^2 - 9)) + (x + 5)/(y + 2), y]
1290-
= x / (-9 + y ^ 2) - 2 / (-9 + y ^ 2)
1291-
## MMA returns better one: (-2 + x) / (-9 + y ^ 2)
1292-
#> Coefficient[y (x - 2)/((y - 3)(y + 3)) + (x + 5)/(y + 2), x]
1293-
= y / (-9 + y ^ 2) + 1 / (2 + y)
1294-
#> Coefficient[y (x - 2)/((y - 3)(y + 3)) + (x + 5)/(y + 2), y]
1295-
= x / (-9 + y ^ 2) - 2 / (-9 + y ^ 2)
1296-
## MMA returns better one: (-2 + x) / ((-3 + y) (3 + y))
1297-
#> Coefficient[x^3 - 2 x/y + 3 x z, y]
1298-
= 0
1299-
#> Coefficient[x^2 + axy^2 - bSin[c], c]
1300-
= 0
13011278
>> Coefficient[x*Cos[x + 3] + 6*y, x]
13021279
= Cos[3 + x]
13031280
1304-
## Form 2
1281+
## Form 2: Coefficent[expr, form, n]
13051282
>> Coefficient[(x + 1)^3, x, 2]
13061283
= 3
13071284
>> Coefficient[a x^2 + b y^3 + c x + d y + 5, y, 3]
13081285
= b
1309-
## Find the free term in a polynomial
1286+
1287+
Find the free term in a polynomial:
13101288
>> Coefficient[(x + 2)^3 + (x + 3)^2, x, 0]
13111289
= 17
13121290
>> Coefficient[(x + 2)^3 + (x + 3)^2, y, 0]
@@ -1364,7 +1342,7 @@ class CoefficientList(Builtin):
13641342
<dd>returns an array of coefficients of the $vari$.
13651343
</dl>
13661344
1367-
## Form 1
1345+
## Form 1 CoefficientList[poly, var]
13681346
>> CoefficientList[(x + 3)^5, x]
13691347
= {243, 405, 270, 90, 15, 1}
13701348
>> CoefficientList[(x + y)^4, x]
@@ -1375,37 +1353,13 @@ class CoefficientList(Builtin):
13751353
= {2 / (-3 + y), 1 / (-3 + y) + 1 / (-2 + y)}
13761354
>> CoefficientList[(x + y)^3, z]
13771355
= {(x + y) ^ 3}
1378-
#> CoefficientList[x + y]
1379-
: CoefficientList called with 1 argument; 2 or 3 arguments are expected.
1380-
= CoefficientList[x + y]
1381-
#> CoefficientList[x^2 + a x y^2 - b Sin[c], y]
1382-
= {-b Sin[c] + x ^ 2, 0, a x}
1383-
#> CoefficientList[1/y, y]
1384-
: 1 / y is not a polynomial.
1385-
= CoefficientList[1 / y, y]
1386-
#> CoefficientList[0, x]
1387-
= {}
1388-
#> CoefficientList[1, x]
1389-
= {1}
13901356
#> CoefficientList[x + y, 5]
13911357
: 5 is not a valid variable.
13921358
= CoefficientList[x + y, 5]
1393-
#> CoefficientList[x + 1, {}]
1394-
= 1 + x
13951359
1396-
## Form 2
1360+
## Form 2 CoefficientList[poly, {var1, var2, ...}]
13971361
>> CoefficientList[a x^2 + b y^3 + c x + d y + 5, {x, y}]
13981362
= {{5, d, 0, b}, {c, 0, 0, 0}, {a, 0, 0, 0}}
1399-
#> CoefficientList[a x^2 + b y^3 + c x + d y + 5, {x}]
1400-
= {5 + b y ^ 3 + d y, c, a}
1401-
#> CoefficientList[a x^2 + b y^3 + c x + d y + 5, {}]
1402-
= 5 + a x ^ 2 + b y ^ 3 + c x + d y
1403-
#> CoefficientList[a x^2 + b y^3 + c x + d y + 5, {x, y + 1}]
1404-
= {{5 + b y ^ 3 + d y}, {c}, {a}}
1405-
#> CoefficientList[a x^2 + b y^3 + c x + d y + 5, {x + 1, y}]
1406-
= {{5 + a x ^ 2 + c x, d, 0, b}}
1407-
#> CoefficientList[a x^2 + b y^3 + c x + d y + 5, {x + 1, y + 1}]
1408-
= {{5 + a x ^ 2 + b y ^ 3 + c x + d y}}
14091363
>> CoefficientList[(x - 2 y + 3 z)^3, {x, y, z}]
14101364
= {{{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}}}
14111365
#> CoefficientList[(x - 2 y)^4, {x, 2}]
@@ -1414,12 +1368,6 @@ class CoefficientList(Builtin):
14141368
#> CoefficientList[x / y, {x, y}]
14151369
: x / y is not a polynomial.
14161370
= CoefficientList[x / y, {x, y}]
1417-
#> CoefficientList[y (x - 2)/((z - 3) (z + 3)) + (x + 5)/(z + 2), {x, y}]
1418-
= {{5 / (2 + z), -2 / (-9 + z ^ 2)}, {1 / (2 + z), 1 / (-9 + z ^ 2)}}
1419-
#> CoefficientList[0, {x, y}]
1420-
= {}
1421-
#> CoefficientList[1, {x, y}]
1422-
= {{1}}
14231371
"""
14241372

14251373
messages = {
@@ -1521,52 +1469,15 @@ class Exponent(Builtin):
15211469
15221470
>> Exponent[5 x^2 - 3 x + 7, x]
15231471
= 2
1524-
#> Exponent[5 x^2 - 3 x + 7, x, List]
1525-
= {0, 1, 2}
15261472
>> Exponent[(x^3 + 1)^2 + 1, x]
15271473
= 6
1528-
#> Exponent[(x^3 + 1)^2 + 1, x, List]
1529-
= {0, 3, 6}
1530-
#> Exponent[Sqrt[I + Sqrt[6]], x]
1531-
= 0
15321474
>> Exponent[x^(n + 1) + Sqrt[x] + 1, x]
15331475
= Max[1 / 2, 1 + n]
1534-
#> Exponent[x^(n + 1) + Sqrt[x] + 1, x, List]
1535-
= {0, 1 / 2, 1 + n}
1536-
#> Exponent[(x + y)^n - 1, x, List]
1537-
= {0}
1538-
#> Exponent[(x + 3 y)^5, x*y^4]
1539-
= 0
15401476
>> Exponent[x / y, y]
15411477
= -1
15421478
15431479
>> Exponent[(x^2 + 1)^3 - 1, x, Min]
15441480
= 2
1545-
#> Exponent[(x^2 + 1)^3 - 1, x, List]
1546-
= {2, 4, 6}
1547-
>> Exponent[1 - 2 x^2 + a x^3, x, List]
1548-
= {0, 2, 3}
1549-
#> Exponent[(x + 1) + (x + 1)^2, x, List]
1550-
= {0, 1, 2}
1551-
1552-
#> Exponent[(x + 3 y - 2 z)^3 * (5 y + z), {x, y}, List]
1553-
= {{0, 1, 2, 3}, {0, 1, 2, 3, 4}}
1554-
#> Exponent[(x + 3 y - 2 z)^3*(5 y + z), {"x", "y"}, List]
1555-
= {{0}, {0}}
1556-
#> Exponent[(x + 3 y - 2 z)^3*(5 y + z), {}]
1557-
= {}
1558-
#> Exponent[x^a + b y^3 + c x + 2 y^e + 5, {x, y}, List]
1559-
= {{0, 1, a}, {0, 3, e}}
1560-
#> Exponent[x^2 / y^3, {x, y}]
1561-
= {2, -3}
1562-
#> Exponent[(x + 2)/(y - 3) + (x + 3)/(y - 2), {x, y, z}, List]
1563-
= {{0, 1}, {0}, {0}}
1564-
#> Exponent[x + 6 x^3 y^2 - 3/((x^2) (y^2)), {x, y}, List]
1565-
= {{-2, 1, 3}, {-2, 0, 2}}
1566-
#> Exponent[x^5 Sin[x^2] + x * x^3 Cos[x], x, List]
1567-
= {4, 5}
1568-
#> Exponent[x^5 Sin[x^2] + y Cos[y^2] + Log[x^3] + 6 y^4, {x, y}, List]
1569-
= {{0, 5}, {0, 1, 4}}
15701481
15711482
>> Exponent[0, x]
15721483
= -Infinity

test/test_calculus.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# -*- coding: utf-8 -*-
2+
"""
3+
Unit tests from builtins ... calculus.py
4+
"""
5+
26
from .helper import check_evaluation
37

48

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
3+
"""
4+
Unit tests from builtins ... colors.py
5+
"""
36

47

58
import unittest

0 commit comments

Comments
 (0)