A computer algebra system written in pure Python http://sympy.org/ . To get started to with contributing https://github.com/sympy/sympy/wiki/Introduction-to-contributing
smichr on smichr-patch-2
Update sympy/core/tests/test_nu… (compare)
smichr on smichr-patch-2
Update test_numbers.py (compare)
smichr on smichr-patch-2
correct int(TribonacciConstant)… (compare)
>>> from sympy.parsing.sympy_parser import (parse_expr, standard_transformations, implicit_multiplication_application, convert_xor)
>>>
>>> def parse_plain_text(e, local_dict=None):
... return parse_expr(
... e,
... local_dict=local_dict,
... transformations=(standard_transformations + (implicit_multiplication_application, convert_xor)),
... evaluate=False)
...
>>> e = parse_plain_text("(49x^2 - 42xy + 9y^2) (7x + 3y) / (7x - 3y)")
>>> e
(7*x + 3*y)*(49*x**2 - 42*x*y + 9*y**2)/(7*x - 3*y)
>>> e.subs({x: 1, y: 2})
13
x1
or x_1
. Either seems to work in most cases, but only underscored subscripts seem to work in all cases (#19005)
1/3
with say 1000 digits, you can store it as a Rational
number and sympy will not convert it to a float in subsequent operations which means multiplying Rational(1, 3) * 3
gives you an integer 1 instead of a float 1.0
Float
refers to the specific way the numbers are represented, i.e., floating-point. Not all real numbers are represented that way. For instance, Rational(1, 3)
, sqrt(2)
and pi
are real numbers but not floating point, and in fact they can't be exactly represented as floating-point. A floating point number uses a very specific representation of $man\times 2^{exp}$ (see https://mpmath.org/doc/current/technical.html#representation-of-numbers).
Float(x) + Float(y) != Float(x + y)
in general.
x.is_real
will tell you if x is a real number. The Python classes are based on the implementation, which is why they are named after the representation. Calling Float
Real would be inaccurate because it is only one possible representation of real numbers, and one that can't even represent all possible ones at that.
>>> from sympy import *
>>> i = Symbol('i')
>>> a = 3 * i
>>> Sum(a, (i, 1, 5))
Sum(3*i, (i, 1, 5))
>>> Sum(a, (i, 1, 5)).doit()
45
>>> b = Sum(i, (i, 1, 10)) / Sum(i + 1, (i, 1, 10))
>>> b
Sum(i, (i, 1, 10))/Sum(i + 1, (i, 1, 10))
>>> b.doit()
11/13
>>> pprint(Sum(a, (i, 1, 5)))
5
___
╲
╲
╱ 3⋅i
╱
‾‾‾
i = 1
>>> pprint(b)
10
___
╲
╲
╱ i
╱
‾‾‾
i = 1
─────────────
10
___
╲
╲
╱ (i + 1)
╱
‾‾‾
i = 1
solve([x - 5], x)
simply return [5]
?