Solving
2x = 1with everything except common sense.
This repository is a tiny experimental playground where we ask an important question that nobody needed answered:
How many deep learning paradigms can we throw at a problem that elementary algebra solves in one line?
The answer is: more than society probably intended.
We compare a few wildly overqualified methods on simple linear equations of the form ax = b. Some methods solve the task. Some learn slowly. Some hallucinate politely. Some are here because once PyTorch is installed, human judgment apparently leaves the room.
Because simple problems are excellent microscopes.
When a model fails on a hard benchmark, everyone can hide behind complexity.
When a model fails on 2x = 1, there is nowhere to run.
This project is partly a joke, partly a teaching demo, and partly a small behavioral study of how different learning paradigms behave when forced into an absurdly simple symbolic/numeric task.
In other words:
- algebra solves the problem instantly;
- regression approximates the obvious;
- reinforcement learning turns division into a lifestyle;
- GANs attempt diplomacy with a single number;
- transformers may learn that
x =should be followed by some number, which is adorable in the way a toaster trying to write poetry is adorable.
.
├── train.py # Unified CLI entry point
├── configs/
│ └── default.json # Default experiment configuration
├── models/ # One module per method
├── utils/
│ ├── benchmark.py # Run multiple methods and save JSON records
│ ├── leaderboard.py # Rank saved runs by various questionable metrics
│ └── ... # Config loading, equation parsing, recording, helpers
└── outputs/runs/ # Default directory for generated run records
Install dependencies:
pip install -r requirements.txtRun one method:
python train.py --method algebra
python train.py --method linear
python train.py --method reinforce
python train.py --method gan
python train.py --method gan_point
python train.py --method dqn_discrete
python train.py --method dqn_general
python train.py --method transformer
python train.py --method customEach run writes a JSON record to outputs/runs/ by default.
For a throwaway run:
python train.py --method linear --no-saveThe project supports equations in the form:
ax=b
Examples:
python train.py --method algebra --equation "3x=7"
python train.py --method linear --equation "-2.5x=1"If the coefficient is negative, the safest CLI form is:
python train.py --method linear --equation=-2.5x=1Because command-line parsers, like neural networks, enjoy misinterpreting simple things.
The undefeated final boss.
It solves ax=b using division, as civilization intended.
A one-layer regression model trained to solve the equation numerically.
This is still overkill, but at least it is the kind of overkill that can be explained to a committee.
A policy-gradient method searching for the solution.
Useful if you have ever looked at 2x = 1 and thought:
This should be a sequential decision-making problem.
A GAN that learns a distribution centered around the solution.
Because apparently one number was not enough. We needed a generator, a discriminator, and a small philosophical crisis.
A GAN trained against a single solution point.
This method is included for scientific completeness and comedic density.
A DQN agent with discrete step actions for the original 2x = 1 environment.
It approaches algebra the way a person approaches a locked door by training a robot to slowly bump into it.
A DQN setup on random ax=b instances.
Slightly more general, still deeply unnecessary.
A tiny seq2seq transformer that maps equation strings to solution strings.
This is where things become interesting. Sometimes the model appears to learn the structure. Sometimes it appears to learn that after x =, a number should happen.
This is not symbolic reasoning. This is autocomplete wearing a lab coat.
A plug-in interface for your own method.
Because if you have another unreasonable way to solve elementary algebra, this project welcomes your contribution. Regrettably.
The default configuration lives at:
configs/default.jsonRun with a config file:
python train.py --config configs/default.json --method linearOverride config values from the command line:
python train.py --method linear --set methods.linear.epochs=20 --set methods.linear.lr=0.05This lets you tune the amount of computational drama applied to a problem with a closed-form solution.
Set methods.custom.entry_point to an import path in the format:
module.path:function
Examples:
models.custom_example:solve
myteam.solver:train
The driver passes all keys from methods.custom as keyword arguments, except:
entry_pointparams_countrunner_id
You can add hyperparameters in JSON or override them with --set.
Optional fields:
runner_id: short name used in saved records and leaderboards;params_count: parameter count used by the Reasoning / Comedy leaderboards, honor system, because apparently we still believe in society.
When using:
--equation "ax=b"the values a and b are injected into compatible methods, including:
algebralineargan_pointcustom
Security note:
entry_pointruns arbitrary importable code. Only use configs from people you trust.
If someone sends you a mysterious config and says “just run it,” maybe do not let natural selection win today.
See:
models/custom_example.py
for a minimal custom implementation.
Run multiple methods and save one result file per method:
python -m utils.benchmark --methods algebra linear gan_point
python -m utils.benchmark --methods algebra linear --set methods.linear.epochs=20
python -m utils.benchmark --methods algebra linear gan_point --equation "3x=7"Keep going even if one method explodes with dignity:
python -m utils.benchmark --methods algebra linear gan_point --continue-on-errorCustom equations are applied to methods with a stable single-equation interface:
algebra,linear,gan_point,custom: receiveaandb;gan: receives the target solution as its real-sample center;transformer: receives a formattedtest_eq.
The following methods still use their original tiny environments:
reinforcedqn_discretedqn_general
Their equation logic is baked into the environment, because even toy projects deserve legacy design debt.
Read saved JSON records and print rankings:
python -m utils.leaderboard
python -m utils.leaderboard --worst-per-methodThe leaderboard categories are named like serious benchmark metrics, then ranked in the least flattering direction:
| Leaderboard | Ranked by |
|---|---|
| Reasoning | Most parameters |
| Coding | Slowest convergence |
| Math | Largest absolute error |
| Comedy | Most overkill |
This is not because we hate deep learning.
It is because we respect algebra.
You can also run some modules directly:
python -m models.linear
python -m models.transformerUseful for quick experiments, debugging, or quietly confirming that a neural network has once again found a creative way to misunderstand a one-line equation.
This project is not about beating algebra. Algebra already won.
The interesting part is watching how different methods fail, converge, overfit, approximate, or accidentally reveal their inductive biases.
Possible things to inspect:
- final absolute error;
- convergence speed;
- parameter count;
- runtime;
- output format mistakes;
- whether the method learned the equation or merely learned the shape of an answer;
- how much machinery was required to rediscover division.
Contributions are welcome if they satisfy at least one of the following:
- they add a new unnecessarily powerful method;
- they improve the benchmark or leaderboard;
- they make the failure modes easier to inspect;
- they add visualization;
- they increase the scientific value;
- they increase the comedic value;
- ideally, both.
Possible future additions:
- LSTM / RNN solver;
- neural arithmetic units;
- symbolic regression baseline;
- chain-of-thought style solver;
- more equation families;
- visualizations of training dynamics;
- a Hall of Shame for especially cursed outputs.
There is no paper. Yet.
If this repository helps you teach, debug, laugh, or explain why next-token prediction is not the same thing as algebra, feel free to cite the repo.
If it convinces you to use algebra for 2x = 1, even better. Society heals one equation at a time.