Skip to content

symcalc/symcalc-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SymCalc C++

SymCalc Logo

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);
}

Contents

Example

#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;
}

Basic usage

  1. Include the SymCalc header:
#include <symcalc/symcalc.hpp>
using namespace symcalc;
  1. Define a variable:
Equation x("x");
  1. Define a function:
Equation fx = pow(x, 2);
  1. Evaluate:
double value = fx.eval({{x, 4}});
// or
value = fx({{x, 4}});
  1. Differentiate:
Equation dfdx = fx.derivative();
  1. 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);
  1. Display:
std::cout << fx << std::endl; // Prints the function
  1. Compile:
g++ main.cpp -o main -std=c++11 -lsymcalc
  1. See more on the website!

Install with make

  1. 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
  1. Build SymCalc with make
make
  1. Install SymCalc
make install

Or to a specific location with

make install PREFIX=/path/to/install

Learning SymCalc

You can learn more about SymCalc on these resources:

Authors

SymCalc is currently developed and maintaned by Kyryl Shyshko (@kyryloshy)