test-symbols.lua
require 'pl'
app.require_here()
require 'symbols'
local MT = getmetatable(_1)
add = MT.__add
mul = MT.__mul
pow = MT.__pow
function testeq (e1,e2)
if not equals(e1,e2) then
print ('Not equal',repr(e1),repr(e2))
end
end
sin = register(math.sin,'sin')
f = register(function(x,y,z) end)
function testexpand (e)
print(repr(fold(expand(e)))) end
function testfold (e)
print(repr(fold(e)))
end
a,b,c,x,y = Var 'a,b,c,x,y'
function testdiff (e)
balance(e)
e = diff(e,x)
balance(e)
print('+ ',e)
e = fold(e)
print('- ',e)
end
testdiff(x^2+1)
testdiff(3*x^2)
testdiff(x^2 + 2*x^3)
testdiff(x^2 + 2*a*x^3 + x^4)
testdiff(2*a*x^3)
testdiff(x*x*x)