Website / License: Apache-2.0 / Changelog / Ruby , C++
SymCalc (which stands for Symbolic Calculus) is a library that introduces mathematics to code, where you can declare, evaluate, and differentiate any possible maths function with a single call.
SymCalc allows to write readable and flexible code, adding a lot of functionality along the way, like this:
fx = 5 * x ** 2 + sin(x)
Instead of hard-coded functions like this:
def fx(x)
5 * x ** 2 + Math.sin(x)
end
require 'symcalc'
include SymCalc
# SymCalc variable
x = var("x")
# SymCalc function
fx = x ** 2 * 5 - 4 * sin(exp(x))
# SymCalc derivative
dfdx = fx.derivative()
# SymCalc evaluate
value = dfdx.eval x: 5
puts value
- Require SymCalc:
require 'symcalc'
include SymCalc
- Define a variable:
x = var("x")
- Define a function:
fx = x ** 2
- Evaluate:
value = fx.eval(x: 4)
# or
value = fx(x: 4)
- Differentiate:
dfdx = fx.derivative
- Multi-variable!:
x = var("x")
y = var("y")
fxy = x ** 2 - 4 * abs(y)
dfdx = fxy.derivative(variable: x)
dfdy = fxy.derivative(variable: y)
- Display:
puts fx # Prints the function
- Run:
ruby main.rb
- See more on the website!
Run:
gem install symcalc
You can learn more about SymCalc on these resources:
SymCalc is currently developed and maintaned by Kyryl Shyshko (@kyryloshy)