Skip to content

Latest commit

ย 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Mathematics Engine - Calculus Toolkit

C++ License Platform SDL2

A Windows desktop application for symbolic calculus with step-by-step solutions and interactive features.

๐ŸŽ“ Comprehensive calculus toolkit supporting single and multivariate calculus operations with symbolic computation and real-time visualization.

๐ŸŽฏ Features

Seven Calculus Operations

  1. Differentiation (d/dx) - Find derivatives with step-by-step solutions
  2. Indefinite Integration (โˆซ f(x) dx) - Find antiderivatives + C
  3. Definite Integration (โˆซ[a,b] f(x) dx) - Calculate area under curve
  4. Limits (lim f(x)) - Calculate limits with step-by-step evaluation
  5. Matrix Multiplication - Multiply matrices with custom dimensions
  6. Partial Derivatives (โˆ‚f/โˆ‚x, โˆ‚f/โˆ‚y) - Compute partial derivatives for multivariate functions
  7. Double Integration (โˆซโˆซ f(x,y) dy dx) - Calculate double integrals over rectangular regions

Core Capabilities

  • Custom Equation Input: Type your own equations interactively
  • Step-by-Step Solutions: View detailed calculations with mathematical notation
  • UTF-8 Support: Full Unicode support for Greek letters (โˆ‚, ฯ€, ฮฑ) and math symbols (โ‹…, โˆš, โˆซ)
  • Interactive Menu: Choose operation at startup
  • Multiple Examples: Pre-loaded expressions for each mode
  • OpenGL Plotting: Real-time graphs for all modes:
    • Differentiation: f(x) and f'(x) curves
    • Indefinite: f(x) and F(x) antiderivative curves
    • Definite: f(x) with shaded area between bounds
  • Bounds Input: Set custom integration bounds for definite integrals

๐Ÿ› ๏ธ Technologies

  • C++17
  • SDL2 + SDL2_ttf for windowing and UTF-8 text rendering
  • OpenGL for plotting and graphics
  • GLEW for OpenGL extension loading
  • CMake for cross-platform building

๐Ÿ“ฆ Windows/MSYS2 Setup

1. Install MSYS2 MinGW64

Download and install MSYS2 from https://www.msys2.org/

2. Install Dependencies

Open MSYS2 MinGW64 terminal and run:

# Update package database
pacman -Syu

# Install compiler and build tools
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-make

# Install SDL2 and graphics libraries
pacman -S mingw-w64-x86_64-SDL2 mingw-w64-x86_64-SDL2_ttf
pacman -S mingw-w64-x86_64-glew mingw-w64-x86_64-glm

3. Build the Project

Option A: Using GCC Directly (Recommended)

cd Mathh
mkdir build
cd build

g++ -std=c++17     -I/mingw64/include -I../src     ../src/main.cpp     ../src/engine/parser.cpp     ../src/engine/differentiator.cpp     ../src/engine/integrator.cpp     ../src/engine/simplifier.cpp     ../src/engine/limit_calculator.cpp     ../src/engine/matrix_operations.cpp     ../src/engine/latex_exporter.cpp     ../src/engine/partial_derivative.cpp     ../src/engine/multivariate_integrator.cpp     ../src/ui/renderer.cpp     ../src/ui/text_renderer.cpp     ../src/ui/plotter.cpp     -L/mingw64/lib     -o MathEngineUTF8.exe     -lmingw32 -lSDL2main -lSDL2 -lSDL2_ttf     -lfreetype -lharfbuzz -lgraphite2 -ldwrite -lole32     -lbz2 -lz -lglew32 -lopengl32     -mconsole -O2 -Wall

Option B: Using CMake

cd Mathh
mkdir build
cd build

# Generate build files
cmake -G "MinGW Makefiles" ..

# Compile
cmake --build .

4. Run the Application

./math_engine.exe

๐Ÿง Linux Build Instructions

MathEngineUTF8 now supports native Linux builds ๐ŸŽ‰
Follow the steps below to compile and run it easily.


๐Ÿงฉ Prerequisites

Make sure you have all required development tools and libraries:

sudo apt update
sudo apt install build-essential pkg-config libsdl2-dev libsdl2-ttf-dev libglew-dev libgl1-mesa-dev

โš™๏ธ Building the Project

Clone the repository and switch into it:

git clone https://github.com/shubhu121/Mathh.git
cd Mathh

Run the included Linux build script:

./build/build_linux.sh

This script will:

  1. Compile all source files using g++ -std=c++17

  2. Use pkg-config to link against SDL2, SDL2_ttf, GLEW, and OpenGL

  3. Output the executable MathEngineUTF8 inside the build/ directory

Running the Program

./build/MathEngineUTF8

you should see output like :

+===================================+
|  Mathematics Engine - Calculus    |
+===================================+

๐Ÿ’ก Notes

  • The Linux build script is located at: build/build_linux.sh
  • You can edit it if you use a different compiler or custom flags.
  • The script wonโ€™t affect Windows or other build systems.

๐ŸŽฎ Controls

Main Menu

Key Action
1-7 Select operation (1=Diff, 2=Indefinite, 3=Definite, 4=Limits, 5=Matrix, 6=Partial, 7=Double)
UP/DOWN Navigate menu
ENTER Confirm selection
ESC Quit

Calculus Modes (All)

Key Action
ENTER Type custom equation
SPACE Next example
UP/DOWN Scroll steps
ESC Return to menu

Definite Integration

Key Action
B Change bounds
TAB Switch between bounds

Limits

Key Action
L or P Open limit configuration
T Quick toggle limit type (finite/+โˆž/-โˆž)
TAB Switch fields in config

Matrix Multiplication

Key Action
TAB Switch between dimension fields
ENTER Confirm and enter matrix values

Partial Derivatives

Key Action
ENTER Type custom equation f(x,y)
SPACE Next example
X Export to LaTeX

Double Integration

Key Action
B Set integration bounds (x and y)
TAB Switch between bound fields
SPACE Next example

How to Use

  1. Launch: See main menu with 7 operations
  2. Select Mode: Press 1-7 or use UP/DOWN arrows + ENTER
  3. Custom Input: Press ENTER and type equation
  4. View Results: See step-by-step solution
  5. Advanced Features: Press B for bounds, L/P for limit config, X for LaTeX export
  6. Return: Press ESC to go back to menu

๐Ÿ“š Supported Functions

Basic Operations

  • Addition: x + 2
  • Subtraction: x - 3
  • Multiplication: x * 5 or 5x
  • Division: x / 2
  • Exponentiation: x^3

Trigonometric Functions

  • sin(x), cos(x), tan(x)

Other Functions

  • exp(x) - Exponential
  • ln(x) - Natural logarithm
  • sqrt(x) - Square root

Example Expressions

Differentiation:

sin(x^2)            โ†’ Chain rule
x^3 + 2*x           โ†’ Power rule
(x^3 + 2*x)*cos(x)  โ†’ Product rule

Integration:

x^2                 โ†’ Power rule (first/second degree)
sin(x)              โ†’ Trigonometric
exp(x)              โ†’ Exponential

Definite Integration:

x^2 from [0, 3]     โ†’ Area = 9.0
sin(x) from [0, ฯ€]  โ†’ Area = 2.0

Partial Derivatives:

x^2 + y^2           โ†’ โˆ‚f/โˆ‚x = 2*x, โˆ‚f/โˆ‚y = 2*y
x*y                 โ†’ โˆ‚f/โˆ‚x = y, โˆ‚f/โˆ‚y = x
sin(x)*cos(y)       โ†’ โˆ‚f/โˆ‚x = cos(x)*cos(y), โˆ‚f/โˆ‚y = -sin(x)*sin(y)

Double Integration:

x*y over [0,1]ร—[0,1]      โ†’ Result = 0.25
x^2 + y^2 over [0,2]ร—[0,2] โ†’ Numerical result

๐Ÿ—๏ธ Project Structure

MathEngine/
โ”œโ”€โ”€ CMakeLists.txt           # Build configuration
โ”œโ”€โ”€ README.md                # This file
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main.cpp            # Application entry point
โ”‚   โ”œโ”€โ”€ engine/
โ”‚   โ”‚   โ”œโ”€โ”€ ast.h/.cpp                    # Abstract Syntax Tree definitions
โ”‚   โ”‚   โ”œโ”€โ”€ parser.h/.cpp                 # Expression parser
โ”‚   โ”‚   โ”œโ”€โ”€ differentiator.h/.cpp         # Symbolic differentiation
โ”‚   โ”‚   โ”œโ”€โ”€ integrator.h/.cpp             # Symbolic integration
โ”‚   โ”‚   โ”œโ”€โ”€ simplifier.h/.cpp             # Expression simplification
โ”‚   โ”‚   โ”œโ”€โ”€ limit_calculator.h/.cpp       # Limit evaluation
โ”‚   โ”‚   โ”œโ”€โ”€ matrix_operations.h/.cpp      # Matrix operations
โ”‚   โ”‚   โ”œโ”€โ”€ latex_exporter.h/.cpp         # LaTeX export
โ”‚   โ”‚   โ”œโ”€โ”€ partial_derivative.h/.cpp     # Partial derivatives
โ”‚   โ”‚   โ””โ”€โ”€ multivariate_integrator.h/.cpp # Double integration
โ”‚   โ””โ”€โ”€ ui/
โ”‚       โ”œโ”€โ”€ renderer.h/.cpp        # SDL2/OpenGL renderer
โ”‚       โ”œโ”€โ”€ text_renderer.h/.cpp   # UTF-8 text rendering
โ”‚       โ””โ”€โ”€ plotter.h/.cpp         # Function plotting
โ””โ”€โ”€ assets/
    โ””โ”€โ”€ fonts/
        โ””โ”€โ”€ NotoSans-Regular.ttf   # UTF-8 compatible font

๐Ÿงฎ How It Works

1. Parsing

  • Input expression is tokenized and converted to Abstract Syntax Tree (AST)
  • Supports operator precedence and parentheses
  • Handles implicit multiplication (e.g., 2x โ†’ 2 * x)

2. Differentiation

  • Applies calculus rules:
    • Power Rule: d/dx(xโฟ) = nยทxโฟโปยน
    • Chain Rule: d/dx(f(g(x))) = f'(g(x))ยทg'(x)
    • Product Rule: d/dx(fยทg) = f'ยทg + fยทg'
    • Quotient Rule: d/dx(f/g) = (f'ยทg - fยทg')/gยฒ
  • Records each step with description and expression

3. Integration

  • Applies integration rules:
    • Power Rule: โˆซ xโฟ dx = xโฟโบยน/(n+1) + C
    • Constant Multiple: โˆซ cยทf(x) dx = cยทโˆซ f(x) dx
    • Sum Rule: โˆซ (f + g) dx = โˆซ f dx + โˆซ g dx
    • Trigonometric: โˆซ sin(x) dx = -cos(x) + C
  • For definite: applies Fundamental Theorem (F(b) - F(a))
  • Records each step with description

4. Simplification

  • Eliminates redundant operations:
    • x + 0 โ†’ x
    • x * 1 โ†’ x
    • x * 0 โ†’ 0
    • x^1 โ†’ x
  • Constant folding: evaluates numeric expressions

5. Rendering

  • Text: SDL2_ttf renders UTF-8 strings to OpenGL textures
  • Plotting: OpenGL draws function graphs by sampling x values
  • UI: Orthographic projection for 2D interface
  • Menu System: Interactive mode selection

๐Ÿ”ง Customization

Change Font Size

Edit src/main.cpp:

textRenderer.init("assets/fonts/NotoSans-Regular.ttf", 24); // Change 24 to desired size

Add New Functions

  1. Add function to UnaryFunc enum in src/engine/ast.h
  2. Implement derivative in src/engine/differentiator.cpp
  3. Add parser support in src/engine/parser.cpp

Adjust Plot Range

Edit src/main.cpp:

plotter.setViewport(-5, 5, -5, 5); // xMin, xMax, yMin, yMax

๐Ÿ› Troubleshooting

Font Not Found

Ensure NotoSans-Regular.ttf is in build/assets/fonts/

Missing DLLs on Windows

Copy these from MinGW64 bin to build directory:

  • SDL2.dll
  • SDL2_ttf.dll
  • libfreetype-6.dll
  • glew32.dll
  • libgcc_s_seh-1.dll
  • libstdc++-6.dll
  • libwinpthread-1.dll

OpenGL Errors

Update graphics drivers to support OpenGL 2.1+

๐Ÿš€ Future Enhancements

  • Multiple variable support (partial derivatives, double integration)
  • Limits with L'Hรดpital's rule
  • Matrix operations
  • LaTeX export
  • Triple integration
  • Gradient and divergence
  • Taylor series expansion
  • Visual AST tree representation
  • ImGui-based UI for expression input
  • Syntax highlighting in input field
  • Symbol palette (โˆซ, ฯ€, โˆ‘, etc.)
  • Equation solver

๐Ÿค Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Quick Start for Contributors

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/your-feature
  3. Make your changes and test thoroughly
  4. Commit with clear messages: git commit -m "feat: add new feature"
  5. Push and create a pull request

Areas We Need Help

  • ๐Ÿ› Bug fixes and testing
  • ๐Ÿ“š Documentation improvements
  • โœจ New mathematical operations
  • ๐ŸŽจ UI/UX enhancements
  • โšก Performance optimizations

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

TL;DR: Feel free to use, modify, and distribute this software. Attribution is appreciated but not required.

๐Ÿ‘ฅ Authors & Contributors

Created by: Shubh (@positronx_)

Twitter Follow

Contributors: See contributors list

Built with โค๏ธ using SDL2, OpenGL, and C++17 for Windows 10/11 (MSYS2 MinGW64)

โ˜• Support My Work

If you find this project helpful, consider supporting its development!

Buy Me A Coffee

Your support helps me:

  • ๐Ÿš€ Build more open-source tools
  • ๐Ÿ“š Create educational content
  • ๐Ÿ”ง Maintain and improve existing projects
  • โ˜• Stay caffeinated while coding!

Buy me a coffee โ˜•


โญ Star this repository if you find it helpful!
๐Ÿ› Report issues to help us improve
๐Ÿ”ง Contribute to make it even better!

About

No description, website, or topics provided.

Resources

Contributing

Stars

27 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages