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:
Equation fx = 5 * pow(x, 2) + sin(x);
Instead of hard-coded functions like this:
#include <cmath>
double fx(double x){
return 5 * pow(x, 2) + sin(x);
}
#include <symcalc/symcalc.hpp>
using namespace symcalc;
int main(){
// SymCalc variable
Equation x ("x");
// SymCalc function
Equation fx = pow(x, 2) * 5 - 4 * sin(exp(x));
// SymCalc derivative
Equation dfdx = fx.derivative();
// SymCalc evaluate
double value = dfdx.eval({{x, 5}});
std::cout << value << std::endl;
return 0;
}
- Include the SymCalc header:
#include <symcalc/symcalc.hpp>
using namespace symcalc;
- Define a variable:
Equation x("x");
- Define a function:
Equation fx = pow(x, 2);
- Evaluate:
double value = fx.eval({{x, 4}});
// or
value = fx({{x, 4}});
- Differentiate:
Equation dfdx = fx.derivative();
- Multi-variable!:
Equation x("x");
Equation y("y");
Equation fxy = pow(x, 2) - 4 * abs(y);
Equation dfdx = fxy.derivative(x);
Equation dfdy = fxy.derivative(y);
- Display:
std::cout << fx << std::endl; // Prints the function
- Compile:
g++ main.cpp -o main -std=c++11 -lsymcalc
- See more on the website!
- Download the source code with git or wget:
git clone https://github.com/symcalc/symcalc-cpp; cd symcalc-cpp
or
wget https://symcalc.site/cpp/source_latest.zip; unzip source_latest.zip; cd symcalc_cpp_source
- Build SymCalc with make
make
- Install SymCalc
make install
Or to a specific location with
make install PREFIX=/path/to/install
You can learn more about SymCalc on these resources:
SymCalc is currently developed and maintaned by Kyryl Shyshko (@kyryloshy)