A compile-time symbolic algebra library implemented in modern C++20 using template metaprogramming. This project provides a zero-overhead symbolic math DSL that models algebraic expressions with full compile-time evaluation, formatting, and simplification support. Designed with extensibility and clarity in mind, it is inspired by expression template techniques in libraries like Eigen.
- Compile-Time Evaluation: Symbolic expressions are evaluated entirely at compile time using
constexprtechniques. - Expression Simplification: Includes simplification rules such as: (Have to be implemented)
x + x → 2 * xa * x + b * x → (a + b) * x(already implemented)
- CRTP-Based Expression Hierarchy: All expressions inherit from
ExpressionBase<Derived>for zero-cost polymorphism. - Uniform Representation: All expressions normalized as
Scaled<Coeff, Expr>to simplify folding, evaluation, and transformation. - Algebraic Operators: Natural support for
+,-,*, variadicAdd, andMultiplicationwith correct operator precedence. - Tuple-Based Internal Storage: Variadic expressions internally stored in
std::tupleand manipulated viastd::apply. - Fully Header-Only: Just include the headers and use the DSL in your project.
Symbolic_Math_DSL_with_Cpp20/
├── include/
│ ├── expressions.hpp # Core DSL types and operators
│ ├── concepts.hpp # Concepts for constraining symbolic types
│ └── utility.hpp # Formatting and type utilities
├── tests/
│ └── test.cpp # Catch2 unit tests
├── CMakeLists.txt # Build file for tests (Catch2)
└── README.md # This file
#include "expressions.hpp"
using namespace math_dsl;
constexpr Variable<'x'> x;
constexpr Variable<'y'> y;
constexpr Scalar<2> two;
constexpr auto expr = x * (y + two);
static_assert(expr.eval(Input<InputPair<'x', 3>, InputPair<'y', 5>>{}) == 21);
std::cout << expr.expr(); // prints: (x*y + 2x)This project uses Catch2 for unit testing.
git clone https://github.com/basava70/Symbolic_Math_DSL_with_Cpp20.git
cd Symbolic_Math_DSL_with_Cpp20
mkdir build && cd build
cmake ..
make
./check.sh
./run.sh- Division operator
/support - Exponentiation (e.g.,
x^n) - Symbolic logarithms (e.g.,
log(x)) - Symbolic differentiation (
d/dxsupport)
This project is licensed under the MIT License. See the LICENSE file for details.