= symbolic
This is a proof-of-concept experiment to handle symbolic expressions in Ruby, inspired by Sage.
Symbolic expressions can be built with Ruby syntax in a +symbolic+ block, by declaring variables with +var+:
symbolic do var :x expr = 2+x # now expr contains a symbolic expression puts expr # -> (2 + x) puts eval(expr) # -> (2 + x) self.x = 1.5 puts eval(expr) # -> 3.5 puts eval(expr/7) # -> 0.5 var :y poly = 3x3 - x2 - yx + 7 puts eval(poly) # -> ((7.875 - (y * 1.5)) + 7) puts eval(poly, :y=>5.0) # -> 7.375 end
Functions can be defined with +fun+:
symbolic do fun(:sqr){|x| x*x} var :x expr = sqr(sin(x)) puts expr # -> sqr(sin(x)) self.x = 1.5 puts eval(expr) # -> 0.994996248300223 end
== Similar project
http://github.com/brainopia/symbolic is a similar, more complete project. Because of this the gem released by this project has been renamed to symbolic-math. Note that this project's pretensions are more limited than brainopia's; I only intend to play with syntax to do symbolic Math in Ruby, not to implement any relevant symbolic math functionality.
== Note on Patches/Pull Requests
== Copyright
Copyright (c) 2009 Javier Goizueta. See LICENSE for details.