[Tutor] Python and Symbolic Math for beginners

Steven D'Aprano steve at pearwood.info
Mon Jun 17 04:14:12 CEST 2013


On 17/06/13 11:25, bob gailer wrote:
> On 6/15/2013 5:53 AM, Amit Saha wrote:
>>   Symbolic math?
> What is that?

Algebra, calculus and similar.


py> import sympy
py> x = sympy.Symbol('x')
py> ((x + 2)**3).expand()
x**3 + 6*x**2 + 12*x + 8


Where possible, it calculates exact mathematical results:

py> sympy.sin(3*sympy.pi/4)
2**(1/2)/2


compared to floating point approximations:

py> import math
py> math.sin(3*math.pi/4)
0.7071067811865476



-- 
Steven


More information about the Tutor mailing list