XIVAI/Stupid-Equation-Solver
<div align="center">
🤖 Stupid-Equation-Solver
Solving 1st–4th Degree Polynomials from Raw Text
No CAS. No symbolic engine. Just a neural network that learned algebra from scratch.
![Params]() ![Hardware]() ![OS]()
📜 License
Weights: Released under CC-BY-NC-4.0 for non-commercial use.
Training code & data: Not publicly available. All rights reserved.
</div>
<a id="english"></a>
🇬🇧 English
📖 Description
A lightweight neural network that solves algebraic polynomial equations of 1st to 4th degree (both complete and incomplete) — directly from raw character text.
The model infers real roots without any external CAS or symbolic algebra engine. It learned polynomial factorization, discriminant calculation, sign switching, and root extraction directly from ASCII strings.
💡 Think of it as a tiny neural calculator that reads equations like a human would — and just knows the answer.
🏗️ Architecture & Training
🎯 Benchmark Results (100 Unseen Test Equations)
<a id="polski"></a>
🇵🇱 Polski
📖 Opis
Lekki model neuronowy rozwiązujący równania algebraiczne wielomianowe od 1. do 4. stopnia (zarówno zupełne, jak i niezupełne) bezpośrednio z surowego tekstu znakowego.
Model wyznacza pierwiastki rzeczywiste bez użycia zewnętrznych silników symbolicznych (CAS) — uczy się wyznaczania wyróżnika (delty), rozkładu na czynniki, reguły znaków i pierwiastkowania wprost z ciągów znaków ASCII.
💡 Wyobraź sobie mały neuronowy kalkulator, który czyta równania jak człowiek — i po prostu zna odpowiedź.
🏗️ Architektura i Trening
🎯 Wyniki testowe (100 równań)
<a id="russian"></a>
🇷🇺 Русский
📖 Описание
Лёгкая нейросеть, решающая алгебраические полиномиальные уравнения 1–4 степени (полные и неполные) прямо из сырого текста.
Модель находит действительные корни без сторонних систем компьютерной алгебры (CAS) — она выучила формулы Виета, дискриминант, смену знаков и извлечение корней напрямую из ASCII-строк.
💡 Представьте крошечный нейронный калькулятор, который читает уравнение как человек — и просто знает ответ.
🏗️ Архитектура и обучение
🎯 Метрики качества (бенчмарк на 100 уравнениях)
💻 Quick Start
Install dependencies
pip install onnxruntime numpySolve equations in Python
import json
import numpy as np
import onnxruntime as ort
# 1. Load ONNX model and metadata
# Исправлено: используем equation_embedded.onnx вместо model.onnx
session = ort.InferenceSession("equation_embedded.onnx")
with open("config.json", "r", encoding="utf-8") as f:
config = json.load(f)
vocab = config["vocab"]
max_len = config["max_len"]
# 2. Inference function
def solve(equation: str):
equation = equation.strip()
if "=" not in equation:
equation += " = 0"
# Determine polynomial degree
if "^4" in equation: deg = 4
elif "^3" in equation: deg = 3
elif "^2" in equation: deg = 2
else: deg = 1
tokens = [vocab.get(ch, 1) for ch in equation]
tokens = tokens[:max_len] + [0] * max(0, max_len - len(tokens))
input_data = np.array([tokens], dtype=np.int64)
# Run inference (проверь, что имена входов и выходов в ONNX совпадают)
preds = session.run(["roots"], {"tokens": input_data})[0][0]
return [round(float(r), 2) for r in preds[:deg]]
# 3. Test examples
print(solve("3x^2 - 4x - 15 = 0")) # -> [2.96, -1.59] (Exact: 3.0, -1.67)
print(solve("x^2 - 2x - 1 = 0")) # -> [2.03, -0.41] (Exact: 2.41, -0.41)
print(solve("x^2 - 16 = 0")) # -> [3.85, -4.02] (Exact: 4.0, -4.0)
print(solve("a^3 - 3a^2 + 2a = 0")) # -> [2.09, 0.84, -0.14] (Exact: 2.0, 1.0, 0.0)⚠️ Limitations
· Regression, not symbolic. Outputs are continuous approximations, not exact fractions. Values like 2.96 instead of 3.0 are expected.
· Degree cap. Trained exclusively on 1st–4th degree polynomials. Fifth-degree and higher are out of scope for this version.
· Real roots only. Complex roots are not modeled.
· Root range. Best performance within [-20, 20].
· No repeat roots detection. Multiplicity is not reported — only the value.
🚀 Roadmap
☐ v2: Token-classification head for exact integer roots
☐ v2: Variable-length output (no fixed max_roots)
☐ v3: Extend to 5th+ degree polynomials
☐ v3: Complex root support
<div align="center">
⚡ Part of XIV AI
A startup from Poland, building AI models from scratch.
License: MIT · Trained on: Intel Arc A770 · Framework: PyTorch XPU
</div>
