def test_var_accepts_comma(): v1 = var('x y z') v2 = var('x,y,z') v3 = var('x,y z') assert v1 == v2 assert v1 == v3
def test_var(): var("a") assert a == Symbol("a") var("b bb cc zz _x") assert b == Symbol("b") assert bb == Symbol("bb") assert cc == Symbol("cc") assert zz == Symbol("zz") assert _x == Symbol("_x") v = var(['d', 'e', 'fg']) assert d == Symbol('d') assert e == Symbol('e') assert fg == Symbol('fg') # check return value assert v == [d, e, fg] # see if var() really injects into global namespace raises(NameError, lambda: z1) _make_z1() assert z1 == Symbol("z1") raises(NameError, lambda: z2) _make_z2() assert z2 == Symbol("z2")
def test_var_return(): raises(ValueError, lambda: var('')) v2 = var('q') v3 = var('q p') assert v2 == Symbol('q') assert v3 == (Symbol('q'), Symbol('p'))
def _make_z1(): var("z1")
def __make_z2(): var("z2")
import sys sys.path.append("..") from timeit import default_timer as clock from csympy import var var("x y z") f = (x**y + y**z + z**x)**100 print f t1 = clock() g = f.expand() t2 = clock() print "Total time:", t2-t1, "s"
import sys sys.path.append("..") from timeit import default_timer as clock from csympy import var var("x y z") e = (x + y + z + 1)**15 f = e * (e + 1) print f t1 = clock() g = f.expand() t2 = clock() print "Total time:", t2 - t1, "s"
import sys sys.path.append("..") from timeit import default_timer as clock from csympy import var var("x y z w") e = (x+y+z+w)**15 f = e*(e+w) print f t1 = clock() g = f.expand() t2 = clock() print "Total time:", t2-t1, "s"
import sys sys.path.append("..") from timeit import default_timer as clock from csympy import var, Integer def fact(n): if n in [0, 1]: return 1 else: return n*fact(n-1) def diff(e, x, n): for i in range(n): e = e.diff(x) return e def legendre(n, x): e = Integer(1)/(Integer(2)**n * fact(Integer(n))) * diff((x**2-1)**n, x, n) return e.expand() var("x") for n in range(10): print n, legendre(n, x) t1 = clock() e = legendre(500, x) t2 = clock() print "Total time for legendre(500, x):", t2-t1, "s"
def test_var(): var("z") assert z == Symbol("z")
import sys sys.path.append("..") from timeit import default_timer as clock from csympy import var var("x y z w") e = (x + y + z + w)**60 t1 = clock() g = e.expand() t2 = clock() print "Total time:", t2 - t1, "s"