def test01(): __cdbkernel__=create_scope() ex:=3x + x**2 + a x**2 + b x; q=SympyBridge(ex) q.from_sympy( str(sympy.collect(q.to_sympy(), $x$)) ) tst:= x**2 (a + 1) + x ( b + 3) - @(ex); assert(tst==0) print("Test 01 passed") test01() def test02(): __cdbkernel__=create_scope() {r,t}::Coordinate. f::Depends(r,t). ex:=f*A; \partial{#}::PartialDerivative. ex:= \partial_{r}{ f + (\sin(r)**2)**2 }; map_sympy(ex) tst:= \partial_{r}{f} + 4 \sin(r)**3 \cos(r) - @(ex); assert(tst==0) print("Test 02 passed") test02() def test03(): __cdbkernel__=create_scope() \tau::Coordinate. \partial{#}::Derivative(\tau). r::Depends(\tau). ex:=\partial{r}; q=SympyBridge(ex) q.from_sympy(str(q.to_sympy())) tst:= \partial{r} - @(ex); assert(tst==0) print("Test 03a passed") ex:=\partial{\partial{r}}; q=SympyBridge(ex) q.from_sympy(str(q.to_sympy())) tst:= \partial{\partial{r}} - @(ex); assert(tst==0) print("Test 03b passed") test03() def test04(): __cdbkernel__=create_scope() ex:= 1 - (-1)**2; simplify(_) assert(ex==0) print("Test 04 passed") test04() from cdb.sympy.calculus import integrate def test05(): __cdbkernel__=create_scope() ex:= \exp(-x); tst = integrate(ex, ($x$, 0, $\infty$)) assert(tst==1) print("Test 05 passed") test05() def test06(): # When acting on a super- or sub-script expression, # make sure that this parent_rel is not dropped. __cdbkernel__=create_scope() {r,\theta}::Coordinate. \partial{#}::PartialDerivative. # Evaluate works, but that looks explicity at # both sides separately and calls simplify on # it without 'deep=True'. ex:= \partial_{r}{\theta}; evaluate(ex, $$) assert(ex==0) print("Test 06a passed") # When using 'deep=True', simplify gets called # on the sub-script, and we need to be careful # not to turn this into '\partial{r}{\theta}', # as that is meaningless in sympy. ex:= \partial_{r}{\theta}; simplify(ex, deep=True) assert(ex==0) print("Test 06b passed") test06() def test07(): __cdbkernel__=create_scope() {r,\theta}::Coordinate. \partial{#}::PartialDerivative. f::Depends(r). ex:= \partial_{r}{3 f}; simplify(ex, deep=True) tst:= 3 \partial_{r}{f} - @(ex); assert(tst==0) print("Test 07 passed") test07()