Skip to content

Commit 907e241

Browse files
committed
Bump min sympy version to 1.7
1 parent 07c94c7 commit 907e241

4 files changed

Lines changed: 54 additions & 55 deletions

File tree

mathics/builtin/arithmetic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1874,7 +1874,7 @@ class Sum(_IterationFunction, SympyFunction):
18741874
= 0
18751875
18761876
>> (-1 + a^n) Sum[a^(k n), {k, 0, m-1}] // Simplify
1877-
= Piecewise[{{m (-1 + a ^ n), a ^ n == 1}, {-1 + (a ^ n) ^ m, True}}]
1877+
= -1 + (a ^ n) ^ m
18781878
18791879
Infinite sums:
18801880
>> Sum[1 / 2 ^ i, {i, 1, Infinity}]

mathics/builtin/linalg.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,24 @@ class Tr(Builtin):
5858
<dt>'Tr[$m$]'
5959
<dd>computes the trace of the matrix $m$.
6060
</dl>
61-
61+
6262
>> Tr[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}]
6363
= 15
64-
64+
6565
Symbolic trace:
6666
>> Tr[{{a, b, c}, {d, e, f}, {g, h, i}}]
6767
= a + e + i
6868
"""
69-
69+
7070
messages = {
7171
'matsq': "The matrix `1` is not square."
7272
}
73-
73+
7474
#TODO: generalize to vectors and higher-rank tensors, and allow function arguments for application
75-
75+
7676
def apply(self, m, evaluation):
7777
'Tr[m_]'
78-
78+
7979
matrix = to_sympy_matrix(m)
8080
if matrix is None or matrix.cols != matrix.rows or matrix.cols == 0:
8181
return evaluation.message('Tr', 'matsq', m)
@@ -701,7 +701,7 @@ class Eigenvalues(Builtin):
701701
= {-1, 1, 2}
702702
703703
>> Eigenvalues[{{Cos[theta],Sin[theta],0},{-Sin[theta],Cos[theta],0},{0,0,1}}] // Sort
704-
= {1, Cos[theta] + Sqrt[-1 + Cos[theta] ^ 2], Cos[theta] - Sqrt[-1 + Cos[theta] ^ 2]}
704+
= {1, Cos[theta] + Sqrt[(-1 + Cos[theta]) (1 + Cos[theta])], Cos[theta] - Sqrt[(-1 + Cos[theta]) (1 + Cos[theta])]}
705705
706706
>> Eigenvalues[{{7, 1}, {-4, 3}}]
707707
= {5, 5}
@@ -731,7 +731,7 @@ def apply(self, m, evaluation):
731731
eigenvalues.sort(key=lambda v: (abs(v[0]), - re(v[0]), - im(v[0])),
732732
reverse=True)
733733

734-
eigenvalues = [from_sympy(v) for (v, c) in eigenvalues
734+
eigenvalues = [from_sympy(v) for (v, c) in eigenvalues
735735
for _ in range(c)]
736736
# Sort the eigenvalues in an arbitrary yet deterministic order
737737
else:

mathics/builtin/numbertheory.py

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class Divisors(Builtin):
294294

295295
# TODO: support GaussianIntegers
296296
# e.g. Divisors[2, GaussianIntegers -> True]
297-
297+
298298
attributes = ('Listable',)
299299

300300
def apply(self, n, evaluation):
@@ -369,102 +369,102 @@ class MantissaExponent(Builtin):
369369
370370
>> MantissaExponent[125., 2]
371371
= {0.976563, 7}
372-
372+
373373
>> MantissaExponent[10, b]
374374
= MantissaExponent[10, b]
375-
375+
376376
#> MantissaExponent[E, Pi]
377377
= {E / Pi, 1}
378-
378+
379379
#> MantissaExponent[Pi, Pi]
380380
= {1 / Pi, 2}
381-
381+
382382
#> MantissaExponent[5/2 + 3, Pi]
383383
= {11 / (2 Pi ^ 2), 2}
384-
384+
385385
#> MantissaExponent[b]
386386
= MantissaExponent[b]
387-
387+
388388
#> MantissaExponent[17, E]
389389
= {17 / E ^ 3, 3}
390-
390+
391391
#> MantissaExponent[17., E]
392392
= {0.84638, 3}
393-
393+
394394
#> MantissaExponent[Exp[Pi], 2]
395395
= {E ^ Pi / 32, 5}
396-
396+
397397
#> MantissaExponent[3 + 2 I, 2]
398398
: The value 3 + 2 I is not a real number
399399
= MantissaExponent[3 + 2 I, 2]
400-
400+
401401
#> MantissaExponent[25, 0.4]
402402
: Base 0.4 is not a real number greater than 1.
403403
= MantissaExponent[25, 0.4]
404-
404+
405405
#> MantissaExponent[0.0000124]
406406
= {0.124, -4}
407-
407+
408408
#> MantissaExponent[0.0000124, 2]
409409
= {0.812646, -16}
410-
410+
411411
#> MantissaExponent[0]
412412
= {0, 0}
413-
413+
414414
#> MantissaExponent[0, 2]
415415
= {0, 0}
416416
"""
417-
417+
418418
attributes = ('Listable',)
419-
419+
420420
rules = {
421421
'MantissaExponent[0]': '{0, 0}',
422422
'MantissaExponent[0, n_]': '{0, 0}',
423423
}
424-
424+
425425
messages = {
426426
'realx': 'The value `1` is not a real number',
427427
'rbase': 'Base `1` is not a real number greater than 1.',
428428
}
429-
429+
430430
def apply(self, n, b, evaluation):
431431
'MantissaExponent[n_, b_]'
432432
# Handle Input with special cases such as PI and E
433433
n_sympy, b_sympy = n.to_sympy(), b.to_sympy()
434-
434+
435435
expr = Expression('MantissaExponent', n, b)
436-
436+
437437
if isinstance(n.to_python(), complex):
438438
evaluation.message('MantissaExponent', 'realx', n)
439439
return expr
440-
440+
441441
if n_sympy.is_constant():
442442
temp_n = Expression('N', n).evaluate(evaluation)
443443
py_n = temp_n.to_python()
444444
else:
445445
return expr
446-
446+
447447
if b_sympy.is_constant():
448448
temp_b = Expression('N', b).evaluate(evaluation)
449449
py_b = temp_b.to_python()
450450
else:
451451
return expr
452-
452+
453453
if not py_b > 1:
454454
evaluation.message('MantissaExponent', 'rbase', b)
455455
return expr
456-
456+
457457
base_exp = int(mpmath.log(py_n, py_b))
458-
458+
459459
exp = (base_exp + 1) if base_exp >= 0 else base_exp
460460

461461
return Expression('List', Expression('Divide', n , b ** exp), exp)
462-
462+
463463
def apply_2(self, n, evaluation):
464464
'MantissaExponent[n_]'
465465
n_sympy = n.to_sympy()
466466
expr = Expression('MantissaExponent', n)
467-
467+
468468
if isinstance(n.to_python(), complex):
469469
evaluation.message('MantissaExponent', 'realx', n)
470470
return expr
@@ -474,12 +474,12 @@ def apply_2(self, n, evaluation):
474474
py_n = temp_n.to_python()
475475
else:
476476
return expr
477-
478-
base_exp = int(mpmath.log10(py_n))
477+
478+
base_exp = int(mpmath.log10(py_n))
479479
exp = (base_exp + 1) if base_exp >= 0 else base_exp
480-
480+
481481
return Expression('List', Expression('Divide', n , (10 ** exp)), exp)
482-
482+
483483
def _fractional_part(self, n, expr, evaluation):
484484
n_sympy = n.to_sympy()
485485
if n_sympy.is_constant():
@@ -491,9 +491,9 @@ def _fractional_part(self, n, expr, evaluation):
491491
result = n - negative_integer_part
492492
else:
493493
return expr
494-
494+
495495
return from_python(result)
496-
496+
497497
class FractionalPart(Builtin):
498498
"""
499499
<dl>
@@ -509,34 +509,34 @@ class FractionalPart(Builtin):
509509
510510
#> FractionalPart[b]
511511
= FractionalPart[b]
512-
512+
513513
#> FractionalPart[{-2.4, -2.5, -3.0}]
514514
= {-0.4, -0.5, 0.}
515-
515+
516516
#> FractionalPart[14/32]
517517
= 7 / 16
518-
518+
519519
#> FractionalPart[4/(1 + 3 I)]
520520
= 2 / 5 - I / 5
521-
521+
522522
#> FractionalPart[Pi^20]
523523
= -8769956796 + Pi ^ 20
524524
"""
525-
525+
526526
attributes = ('Listable', 'NumericFunction', 'ReadProtected')
527-
527+
528528
def apply(self, n, evaluation):
529529
'FractionalPart[n_]'
530530
expr = Expression('FractionalPart', n)
531531
return _fractional_part(self.__class__.__name__, n, expr, evaluation)
532-
532+
533533
def apply_2(self, n, evaluation):
534534
'FractionalPart[n_Complex]'
535535
expr = Expression('FractionalPart', n)
536536
n_real = Expression("Re", n).evaluate(evaluation)
537537
n_image = Expression("Im", n).evaluate(evaluation)
538-
539-
real_fractional_part = _fractional_part(self.__class__.__name__, n_real, expr, evaluation)
538+
539+
real_fractional_part = _fractional_part(self.__class__.__name__, n_real, expr, evaluation)
540540
image_fractional_part = _fractional_part(self.__class__.__name__, n_image, expr, evaluation)
541541
return Expression('Complex', real_fractional_part, image_fractional_part)
542542

@@ -634,7 +634,7 @@ class CoprimeQ(Builtin):
634634
= True
635635
636636
>> CoprimeQ[4+2I, 6+3I]
637-
= False
637+
= True
638638
639639
>> CoprimeQ[2, 3, 5]
640640
= True
@@ -964,4 +964,3 @@ def apply(self, m, n, evaluation):
964964
return Expression('List', Integer(py_m // py_n), (py_m % py_n))
965965
else:
966966
return Expression('QuotientRemainder', m, n)
967-

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def read(*rnames):
8080

8181
# General Requirements
8282
INSTALL_REQUIRES += [
83-
"sympy>=1.6, < 1.7",
83+
"sympy>=1.7, <= 1.8dev",
8484
"django >= 3.0, < 3.2",
8585
"mpmath>=1.1.0",
8686
"numpy",

0 commit comments

Comments
 (0)