Skip to content

chaotic-society/theoretica

Repository files navigation

Theoretica

GitHub last commit GitHub Workflow Status Codacy Badge Documentation License

A C++ math library for scientific computing with a simple and elegant interface.

Theoretica provides methods for scientific computing, statistical analysis of experimental data and numerical approximation. The aim of the project is to give simple and immediate access to powerful algorithms for scientific and engineering software. The library is tested using Chebyshev, a unit testing framework specifically developed for scientific and numerical software.

A short example

The following code solves the Lorenz attractor and writes the solution to a file:

vec3 f(real t, vec3 v) {

    const real a = 13, b = 20, c = 8./3.;
    const real x = v[0], y = v[1], z = v[2];

    return {
        y * a - x * a,
        x * b - x * z,
        x * y - c * z
    };
}

int main() {

    // Initial conditions
    vec3 x0 = {0.0, 0.1, 0.0};

    // Use Runge-Kutta between t=0 and 50
    auto sol = ode::solve_rk4(f, x0, 0.0, 50.0);

    std::ofstream file ("lorenz.dat");
    file << sol;
}

Features

Some features of the library include:

  • Cross-platform with x86 and OpenMP enhancements
  • Common real and complex functions
  • Numerical Linear Algebra
  • Complex numbers (algebraic & exponential form) and quaternions
  • Numerical calculus, from integrals to ODEs
  • Multivariate Automatic Differentiation with differential operators
  • Univariate and multivariate optimization and root-finding
  • Descriptive and inferential statistics and Monte Carlo methods
  • Bezier curves and spline interpolation

Theoretica is constantly developed and improved with new ideas!

Setup

Theoretica is a header-only library and has no dependencies, so you can include it in your projects straight-away! You can build all tests and example programs by running make all in the main folder, ensuring that it works on your machine. When using the library, you can include single headers or use theoretica.h which includes all library headers (you can define THEORETICA_INCLUDE_BASE to make it include only fundamental headers).

Quickstart

You can compile this simple code to check your setup:

#include "theoretica.h"
using namespace th;

int main() {
    
    // Declare a 3D vector
    vec3 v = {1, 2, 3};

    // Create a 3x3 identity matrix
    mat3 A = mat3::identity();

    // Transform v by A
    vec3 w = A * v;
}

Examples

The examples folder contains simple programs that showcase usage of the library:

Documentation

The documentation for the project is available at this link. The documentation is written using Doxygen syntax alongside the source code and the website is automatically updated on each commit. The HTML documentation is also available for download in the gh-pages branch. The bibliography used during research for the library is listed in BIBLIOGRAPHY.md. You may learn more about the design choices behind the library reading the Software Specification.

Contributing

Contributions are welcome and appreciated! Have a look at the Contributing Guide to learn more about how you can help. Contributions include writing code and documentation, testing and researching algorithms.

Workflow

Test on Linux Test on Windows Test on MacOS

Theoretica uses automated workflows for recurring tasks. On each commit to master, tests are run on Linux, Windows and MacOS, benchmarks are launched and documentation is built and deployed to the online website. This ensures that the library works correctly and the documentation is always up-to-date.

License

The project is currently under the GNU Lesser General Public License 3.0. You may learn more about it here.