Neumathwork (NMN) v4.0: Neuro-Symbolic Mathematical Reasoning Engine

Author: Christopher Alberto Hamonangan

Neumathwork (NMN) is an advanced hybrid Neuro-Symbolic Artificial Intelligence architecture designed to solve formal mathematical problems (ranging from elementary arithmetic and K-12 algebra to undergraduate calculus and linear algebra) with 100% exact rational soundness and zero hallucination.

Unlike pure autoregressive Large Language Models (LLMs) that struggle with arithmetic drift and complex algebraic precedence, NMN strictly separates responsibilities:

  • Neural Network (GAT + GRU): Provides heuristic intuition, operator selection, and search guidance.
  • Symbolic Universal Engine: Executes formal mathematical laws and step reductions using exact rational arithmetic (Fraction), guaranteeing absolute correctness.

Training Corpus

The active checkpoint (nmn_checkpoint.pth) was trained on 8.27 Million pure training samples (train_shards), with validation datasets (val_shards) strictly isolated. The dataset was generated using a grammar-guided syntactic pipeline with domain boundary constraints across 8 academic fields:

Dataset Domain Code #Train Samples Proportion Scope & Mathematical Invariants
Elementary Arithmetic ARI 1.04 M 12.58% Multi-level deep arithmetic, nested parentheses, PEMDAS hierarchy
Linear Equations & Balancing LIN 2.23 M 26.96% Single/multi-step transposition, variable isolation, fractions, two-sided variable balance
Algebraic Systems (2-Var) SYS 0.20 M 2.45% Simultaneous linear systems (SPLDV) via Cramer elimination (x, y)
Quadratic Equations QAD 0.20 M 2.44% Polynomial roots via symbolic Discriminant (D = b^2 - 4ac) & ABC formula
Differential Calculus DIF 0.20 M 2.45% Symbolic differentiation d/dx, polynomial power rule, linearity
Integral Calculus INT 0.20 M 2.44% Indefinite integration integral f(x)dx, polynomial antiderivative rule
Continuity & Limits LIM 0.20 M 2.44% Limit evaluation lim x to c f(x), rational continuity substitution
Matrix & Linear Algebra MAT 0.60 M 7.31% Matrix determinant 2 x 2 (ad - bc), transpose, non-commutative matrix multiplication
Special & Discrete Functions SPC 3.39 M 40.93% Trigonometry (sin, cos, tan), logs (ln), exp, Pythagoras (hypot), FPB (gcd), faktorial (fact)
TOTAL CORPUS ALL 8.27 M 100.00% Comprehensive K-12 to Undergraduate Pure Mathematics

Supported Operations & Syntax

Neumathwork natively parses and reduces 24+ mathematical operations. Below are the supported operations and how to write them:

1. Basic Arithmetic & Powers

  • Addition / Subtraction: a + b, a - b (e.g., (12 + 8) - 5)
  • Multiplication / Division: a * b, a / b (Exact rational evaluation: 22 / 4 β†’ 11/2)
  • Powers & Roots: pow(base, exp) (e.g., pow(2, 5)), pow2(x) (e.g., pow2(9)), sqrt(x) (e.g., sqrt(144))
  • Absolute Value: abs(x) (e.g., abs(0 - 25))

2. Trigonometry & Transcendental Functions

  • Trigonometric Ratios: sin(deg), cos(deg), tan(deg) (Exact angles: sin(30) β†’ 1/2)
  • Exponential & Logarithms: exp(x) (e.g., exp(0) β†’ 1), ln(x) (Natural log, e.g., ln(1) β†’ 0)

3. Geometry & Discrete Mathematics

  • Pythagoras / Euclidean Norm: hypot(a, b) (e.g., hypot(9, 40) β†’ 41)
  • Circle Geometry: circle_area(r) (Exact Ο€ * r^2, e.g., circle_area(7) β†’ 154)
  • Number Theory (GCD / FPB): gcd(a, b) (e.g., gcd(48, 72) β†’ 24)
  • Combinatorics (Factorial): fact(n) (e.g., fact(5) β†’ 120)

4. Advanced Algebra, Matrices, & Calculus

  • Linear Equations: ax + b = c, (ax + b) / k = c (e.g., (4*x + 8) / 2 = 18 β†’ x = 7)
  • Quadratic Equations: a*x^2 + b*x + c = 0 (e.g., 1*x^2 - 11*x + 24 = 0 β†’ HP = { 8, 3 })
  • Matrix Determinant (2x2): det([[a, b], [c, d]]) (e.g., det([[-15, 8], [4, -3]]) β†’ 13)
  • Matrix Transpose & Multiplication: trans(...), matmul(...)
  • Calculus Derivative: diff(expr) (e.g., diff(3*x^2 + 4*x))
  • Calculus Antiderivative / Integral: int(expr) (e.g., int(4*x^3))

Architecture Design

Neumathwork uses an optimized parameter-efficient neuro-symbolic design (~2.5M parameters total):

  1. 8D Typed Expression Graph (8D-TEG): Tokenizes equations into an Abstract Syntax Tree (AST) with 8 structural node features (depth, degree, is_left, is_right, in_lhs, etc.).
  2. 4-Layer Relation-Aware Residual GAT: Graph Attention layers with LayerNorm to capture non-local mathematical operator precedence.
  3. 2-Layer GRU Controller + Cross-Attention: Sequentially navigates candidate nodes to identify reducible sub-expressions (redexes).
  4. Dual-Head Policy (NOP & NMC):
    • Neural Operator Prediction (NOP): Discrete 16-class classification head with learned temperature scaling (T β‰ˆ 1.05).
    • Neural Matrix Computation (NMC): Continuous latent magnitude heuristic trained with Signed-Log Smooth L1 Loss.
  5. Symbolic Sovereign Verifier: Deterministic rule engine ensuring strict mathematical invariants (Zero-division prevention, negative root rejection).

Validation

  • NOP Exact-Op Accuracy: 100.00% on 1.625M validation samples.
  • Continuous Latent Precision: Median MAE = 0.0338 in signed-log space.
  • Inference Speed: 0.018 ms / step (~54,000 problems/second on a single CUDA GPU).
  • Symbolic Safety: 0.00% violation rate on division by zero or domain boundaries.
  • Production Assessment: AAA+ (Zero-Dummy Real Empirical) tested across 30 formal metrics.

Quickstart: How to Run

To run Neumathwork locally using the weights from this repository:

import torch
from train_nmn import NeumathworkModel
from symbolic_engine import MathTextParser, evaluate_expression_tree

# 1. Instantiate architecture and load weights
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = NeumathworkModel(in_features=8, hidden_dim=256, num_heads=4, num_classes=16).to(device)
model.load_state_dict(torch.load('nmn_checkpoint.pth', map_location=device))
model.eval()

# 2. Parse and solve any complex expression
query = "(fact(5) / gcd(48, 72)) + (pow(3, 3) * hypot(9, 40)) - abs(-150)"
ast_root = MathTextParser.parse(query)
history, final_result, status = evaluate_expression_tree(ast_root)

print("Exact Final Result:", final_result)  # Output: 962
---
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support