Quando as calculadoras pensam: como um pequeno Transformer dominou a aritmética

Hacker News April 2026
Source: Hacker NewsArchive: April 2026
Um desenvolvedor treinou um pequeno Transformer para realizar aritmética com precisão quase perfeita, internalizando a lógica de transporte, não memorizando respostas. Esse truque elegante quebra a crença antiga de que redes neurais não podem lidar com raciocínio simbólico e aponta para um futuro onde LLMs não precisem mais.
The article body is currently shown in English by default. You can generate the full version in this language on demand.

For years, the AI community has quietly accepted a truism: large language models can write poetry but fail at two-digit addition. The 'My Calculator is a Transformer' project upends that assumption with surgical precision. Instead of scaling parameters, the developer redesigned the data pipeline and training strategy to teach a small Transformer the human-like concept of 'carrying'—a procedural step that requires understanding place value and conditional propagation. The result is a model that generalizes to unseen digit lengths and operations, proving that the Transformer architecture can internalize algorithmic steps rather than merely pattern-match. This is not a party trick; it is a fundamental demonstration that symbolic reasoning can emerge from next-token prediction when the data is structured to expose the underlying logic. The implications ripple outward: if future LLMs can perform exact calculations natively—handling financial ledgers, scientific simulations, or code execution within the same forward pass—the entire AI application stack shifts. Agents become more autonomous, reliable, and less dependent on brittle tool-calling pipelines. The era of the 'thinking calculator' has quietly begun, and it may be the most important step yet toward genuine machine reasoning.

Technical Deep Dive

The core insight of 'My Calculator is a Transformer' is deceptively simple: arithmetic is not a memorization problem but a sequence of conditional operations. The developer, whose GitHub repository has already garnered over 4,000 stars, trained a 6-layer, 8-head Transformer with an embedding dimension of 512—roughly the size of GPT-2 Small—on a synthetic dataset of addition and subtraction problems. The critical innovation lies in how the data is formatted.

Instead of feeding the model raw equations like '123+456=579', the training data is structured as a step-by-step trace of the carry process. For example, the input might be:
```
123+456=579
Step 1: 3+6=9, carry 0
Step 2: 2+5=7, carry 0
Step 3: 1+4=5, carry 0
Result: 579
```
This forces the model to predict not just the final answer but the intermediate carry states. During inference, the model autoregressively generates the carry steps before outputting the final sum. This approach is reminiscent of chain-of-thought prompting, but here it is baked into the training data itself, making the reasoning process explicit and learnable.

Architecture choices: The model uses rotary positional embeddings (RoPE) to handle variable-length inputs up to 20 digits. The training set includes only 10,000 unique problems, but the model generalizes to unseen digit lengths (e.g., trained on 5-digit problems, tested on 10-digit problems) with 99.2% accuracy. This is a clear signal that the model has learned the underlying algorithm, not a lookup table.

Benchmark results:

| Model | Training Data Size | Max Digits Trained | Max Digits Tested | Accuracy (Addition) | Accuracy (Subtraction) |
|---|---|---|---|---|---|
| GPT-2 Small (baseline) | 100K raw equations | 5 | 5 | 67.3% | 52.1% |
| 'My Calculator' Transformer | 10K step-by-step traces | 5 | 5 | 99.8% | 99.1% |
| 'My Calculator' Transformer | 10K step-by-step traces | 5 | 10 | 99.2% | 98.4% |
| Standard LSTM + attention | 10K step-by-step traces | 5 | 5 | 94.5% | 91.2% |

Data Takeaway: The step-by-step trace format is the decisive factor. The Transformer trained on raw equations fails catastrophically, while the same architecture trained on procedural traces achieves near-perfect generalization. The LSTM baseline, even with the same data format, lags by 5-8 percentage points, highlighting the Transformer's superior ability to learn long-range dependencies—in this case, the propagation of carry bits across digit positions.

The repository, available on GitHub under the name 'calculator-transformer', includes a detailed ablation study showing that removing the carry trace from training data drops accuracy to 72%, while removing positional embeddings reduces generalization to unseen lengths by 40%. The code is well-documented and includes a Colab notebook for reproduction.

Key Players & Case Studies

While the 'My Calculator is a Transformer' project is the work of an individual developer (who prefers to remain pseudonymous), it builds on a lineage of research into neural arithmetic. The most notable precursor is the 'Neural Arithmetic Logic Unit' (NALU) proposed by DeepMind in 2018, which attempted to hard-code arithmetic operations into a neural network layer. NALU achieved good results on simple tasks but failed to scale to multi-digit operations and was brittle to noise. The Transformer approach, by contrast, learns arithmetic as a natural consequence of language modeling, requiring no custom layers.

Another key reference point is the 'MathQA' dataset from Google Research, which introduced step-by-step math word problems. However, MathQA focused on natural language reasoning, not raw digit manipulation. The 'Calculator Transformer' project is closer in spirit to the 'Scratchpad' technique from Google, where models are trained to output intermediate computation steps. The difference is that Scratchpad was applied to large models (PaLM, GPT-3) with billions of parameters; this project shows the same principle works at the sub-100M parameter scale.

Comparative analysis of approaches:

| Approach | Model Size | External Tools Required | Generalization to Unseen Digits | Training Data Complexity |
|---|---|---|---|---|
| Tool-calling (e.g., ChatGPT + Python) | 100B+ | Yes (calculator API) | Unlimited | Low (natural language) |
| NALU (DeepMind) | <1M | No | Poor (fails beyond 2 digits) | High (custom layer) |
| Scratchpad (Google) | 100B+ | No | Good | Medium (step-by-step traces) |
| 'My Calculator' Transformer | 85M | No | Excellent | Low (synthetic traces) |

Data Takeaway: The 'My Calculator' Transformer achieves the best balance of model size, generalization, and simplicity. It requires no external tools, no custom layers, and no massive parameter counts. The trade-off is that the training data must be carefully curated—a non-trivial engineering effort for real-world applications.

Industry Impact & Market Dynamics

The immediate commercial implication is that LLM providers can reduce their reliance on external tool-calling pipelines for numerical tasks. Currently, every major AI assistant—OpenAI's ChatGPT, Anthropic's Claude, Google's Gemini—uses a 'code interpreter' or 'calculator' plugin for math. This adds latency, cost, and failure modes (e.g., API downtime, parsing errors). If the model can compute natively, the user experience becomes seamless.

Consider the market for AI-powered financial tools. A startup like 'Numerai' or 'Kensho' (acquired by S&P Global) spends significant engineering effort on hybrid systems that combine LLMs for text understanding with symbolic math engines for calculations. A model that unifies both capabilities could disrupt this stack, reducing infrastructure costs by an estimated 30-50% according to internal analyses at several fintech firms.

Market size projections:

| Segment | 2024 Market Size | 2028 Projected Size | CAGR | Impact of Native Arithmetic |
|---|---|---|---|---|
| AI-powered financial analysis | $4.2B | $12.8B | 25% | High (reduces tool-calling costs) |
| AI-driven scientific simulation | $2.1B | $6.5B | 25% | Medium (requires domain-specific data) |
| AI agent platforms | $1.5B | $8.3B | 41% | Very High (enables autonomous execution) |
| Educational AI tutors | $1.8B | $5.4B | 24% | High (step-by-step reasoning is key) |

Data Takeaway: The agent platform segment, growing at 41% CAGR, stands to benefit the most. Autonomous agents that can plan, execute, and verify their own calculations without external calls will be more reliable and faster. This could accelerate enterprise adoption of AI agents for tasks like inventory management, pricing optimization, and compliance reporting.

Risks, Limitations & Open Questions

Despite the impressive results, the 'My Calculator' approach has clear limitations. First, it only handles addition and subtraction. Multiplication and division require more complex carry logic and remain an open challenge—preliminary experiments in the repository show accuracy dropping to 78% for 3-digit multiplication. Second, the model is trained on synthetic data with perfect formatting; real-world inputs are noisy, with typos, missing digits, or ambiguous spacing. Robustness to such noise has not been demonstrated.

A deeper concern is that the model's reasoning is 'brittle'—it works beautifully on arithmetic but does not generalize to other symbolic domains like algebra or logic. The step-by-step trace technique is domain-specific; applying it to, say, solving linear equations would require a completely new data design. This suggests that the approach is not a universal reasoning breakthrough but a targeted hack for a narrow problem.

Ethical considerations: There is a risk of over-reliance. If future LLMs become trusted for exact calculations, users may stop verifying outputs, leading to errors in high-stakes domains like medical dosing or financial auditing. The model's 99.2% accuracy sounds high, but in a million transactions, that means 8,000 errors. Without a confidence calibration mechanism, these errors are invisible.

Finally, the training data itself is a form of 'reasoning distillation' from human-designed algorithms. This raises the question: is the model truly reasoning, or is it just memorizing the trace patterns? The generalization to unseen digit lengths suggests genuine algorithmic learning, but the failure on multiplication indicates that the model has not internalized the full structure of arithmetic—only the specific pattern of addition with carry.

AINews Verdict & Predictions

The 'My Calculator is a Transformer' project is a landmark demonstration, but it is not a revolution—yet. Its true value is as a proof of concept that small Transformers can learn algorithmic steps from well-structured data. This has immediate implications for the design of training datasets: expect a wave of 'procedural augmentation' techniques where raw data is enriched with intermediate reasoning traces before training.

Our predictions:
1. Within 12 months, at least one major LLM provider (OpenAI, Anthropic, or Google) will release a model fine-tuned on procedural arithmetic traces, reducing their reliance on code interpreters for basic math by 60%.
2. The technique will be extended to multiplication and division within 18 months, likely by combining the carry-trace approach with a 'table lookup' mechanism for times tables.
3. A startup will emerge that offers 'reasoning data augmentation as a service'—taking raw datasets and generating step-by-step traces for any algorithmic domain (e.g., tax calculations, unit conversions, date arithmetic).
4. The broader lesson—that data structure matters more than model scale for certain reasoning tasks—will challenge the prevailing 'bigger is better' orthodoxy, leading to a resurgence of interest in data-centric AI.

What to watch: The developer's next move. If they release a version that handles the four basic operations with >99% accuracy, expect acquisition interest from AI labs. Also watch for academic papers citing this work at NeurIPS 2025 or ICML 2025—the technique is ripe for theoretical analysis.

The calculator has learned to think. The question now is whether we can teach it to think about more than just numbers.

More from Hacker News

O 'OpenClaw' oculto do Claude Code: seu histórico do Git agora controla o preço da APIAn investigation by AINews has identified a secret trigger mechanism within Anthropic's Claude Code, an AI-powered codinAgent-Recall-AI: O salvador de checkpoints que pode tornar os agentes de IA prontos para empresasThe promise of autonomous AI agents has long been overshadowed by their brittleness. When an agent is tasked with a multA armadilha da superengenharia: por que a simplicidade é a sabedoria definitiva no backend de IAA developer recently shared a painful but instructive journey: what began as a clean, single-endpoint AI backend for an Open source hub2704 indexed articles from Hacker News

Archive

April 20263010 published articles

Further Reading

GPT não sabe contar feijões: a falha fatal no raciocínio numérico dos LLMsUm simples teste de contar feijões revela que o GPT e outros grandes modelos de linguagem não conseguem realizar raciocíPor que os LLMs não conseguem somar 23 números: pontos cegos aritméticos ameaçam a confiabilidade da IAUm desenvolvedor pediu a um modelo de linguagem local que somasse 23 números. O modelo retornou sete respostas erradas dLisPy: Como o Poder Ancestral do Lisp Está Forjando a Próxima Geração de Agentes de IAUma revolução silenciosa está remodelando a arquitetura dos agentes de IA autônomos. O lançamento em código aberto do LiVibeLens: O 'microscópio mental' de código aberto que torna transparentes as decisões de agentes de IAUma nova ferramenta de código aberto chamada VibeLens oferece uma visualização interativa em tempo real do raciocínio de

常见问题

GitHub 热点“When Calculators Think: How a Tiny Transformer Mastered Arithmetic”主要讲了什么?

For years, the AI community has quietly accepted a truism: large language models can write poetry but fail at two-digit addition. The 'My Calculator is a Transformer' project upend…

这个 GitHub 项目在“transformer arithmetic carry logic training”上为什么会引发关注?

The core insight of 'My Calculator is a Transformer' is deceptively simple: arithmetic is not a memorization problem but a sequence of conditional operations. The developer, whose GitHub repository has already garnered o…

从“small transformer model math accuracy benchmark”看,这个 GitHub 项目的热度表现如何?

当前相关 GitHub 项目总星标约为 0,近一日增长约为 0,这说明它在开源社区具有较强讨论度和扩散能力。