Simple math symbolic manipulation library.
- C++17 compatible compiler
- CMake 3.13
Clone
https://github.com/rudlorenz/mathParserTo use Expressions in your project add src folder with add_subdirectory() command to your CmakeLists.txt file and
include Expressions.h and Parser.h in source files.
Alternatively you can use supplied main.cpp.
Parsing expression from string:
#include <Parser.h>
auto result = parser::parse("x + y");
if (result != nullptr) {
std::cout << "result : " << result->to_string();
}Parse expression from string and find derivative:
#include <Parser.h>
auto result = parser::parse("x * x + 2*x + 10");
if (result != nullptr)
{
auto derivative = result->diff("x");
std::cout << "expression : " << result->to_string() << "\n"
<< "derivative : " << derivative->to_string();
}Calls are chainable:
auto result = parser::parse("x*x*y + x*y*y");
auto as_string = result != nullptr
? result->diff(x)->diff(y)->to_string();You can create expressions directly, but it's highly discouraged:
#include "Expressions.h"
// x * x + y
auto var_x = std::make_shared<Variable>("x");
auto var_y = std::make_shared<Variable>("y");
auto result = std::make_shared<Sum>(
std::make_shared<Mul>(var_x, var_x),
var_y
);- Unit testing.
- Proper lexical and synax analysis i.e. input expression validation. Right now it works "garbage in --> garbage out".
- Expression simplification.
- Proper parser errors.