NeuroMath

A custom mathematical and symbolic computation language built from scratch using Python.

NeuroMath is a mini computer algebra system (CAS) that supports:

✅ Variable assignments

✅ User-defined functions

✅ Symbolic differentiation

✅ Symbolic integration

✅ Mathematical built-in functions

✅ Notebook-style Streamlit interface

✅ Clean interpreter architecture (Lexer → Parser → AST → Interpreter)

🚀 Demo
x = 5
f(x) = 3*x^2 + 5*x

print(f(2))
print(diff(f(x), x))

Output:

22
6*x + 5
📌 Features
🔹 Core Language Features

Arithmetic operations: +, -, *, /, ^

Variable assignment

Function definition

Function calls

Nested expressions

Multi-line programs

Print function

typeof() support

🔹 Symbolic Computation

Powered internally via SymPy conversion layer.

Supported symbolic operations:

diff(expression, variable)

integrate(expression, variable)

Symbolic simplification

Mixed numeric + symbolic expressions

Example:

f(x) = x^3 + 2*x
diff(f(x), x)

Output:

3*x^2 + 2
🏗️ Architecture

NeuroMath is built using a traditional interpreter pipeline:

Source Code
    ↓
Lexer (Tokenization)
    ↓
Parser (AST Construction)
    ↓
Interpreter (Execution Engine)
    ↓
Symbolic Conversion Layer (SymPy)
Components
Module	Responsibility
lexer/	Converts source code into tokens
parser/	Builds Abstract Syntax Tree
ast/	AST node definitions
interpreter/	Executes AST
symbolic engine	Converts AST to SymPy expressions
streamlit app	Notebook-style GUI
📚 Language Syntax
Variables
x = 10
y = x + 5

Rules:

Must start with a letter

Case-sensitive

Cannot start with a number

Function Definition
f(x) = x^2 + 3*x

Call:

f(2)
Symbolic Operations
diff(x^2, x)
integrate(x^2, x)
Print
print(x)
Built-in Mathematical Functions

sin(x)

cos(x)

tan(x)

sqrt(x)

log(x)

exp(x)

pi

e

Example:

sin(pi/2)
🖥️ Notebook Interface

NeuroMath includes a Streamlit-powered notebook UI that mimics Wolfram / Jupyter-style execution:

Cell-based execution

Persistent environment

Reset kernel

Execution history

Run:

streamlit run app.py
⚙️ Installation

Clone repository:

git clone https://github.com/yourusername/neuromath.git
cd neuromath

Install dependencies:

pip install -r requirements.txt

Run CLI:

python main.py

Run GUI:

streamlit run app.py
🧪 Example Programs
Numeric Evaluation
x = 5
y = 7
z = x*y + 3
print(z)
Symbolic + Numeric Mixed
x = 10
diff(x^2, x)

Output:

2*x

(Symbolic mode correctly ignores numeric memory.)

🔬 Design Highlights

Clean separation of numeric and symbolic evaluation modes

Context-aware AST to SymPy transformation

Local function scope isolation

Session-state safe Streamlit architecture

Modular and extensible design

📁 Project Structure
neuromath/
│
├── lexer/
├── parser/
├── ast/
├── interpreter/
├── app.py
├── main.py
├── requirements.txt
└── README.md