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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2df402e
e9b611e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37dd2ef
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
---
license: mit
---

---

language:

* en
  library_name: pytorch
  license: mit
  tags:
* quadratic-equations
* mathematical-reasoning
* interpretability
* mechanistic-interpretability
* symbolic-reasoning
* synthetic-data
  pipeline_tag: text-generation

---

# SEAI: Learning Mathematical Representations for Quadratic Equation Solving

**SEAI (Square Equation AI)** is a research neural network designed to solve quadratic equations with real roots while enabling direct analysis of its learned internal representations.

The primary purpose of SEAI is not only numerical prediction. The project investigates whether a neural network trained to predict quadratic roots can develop internal representations correlated with mathematically meaningful quantities involved in the analytical solution.

A central observation of the current experiment is that hidden activations in deeper layers exhibit strong correlations with the normalized quadratic discriminant

$$
p^2-q
$$

and with its square-root transformation, despite neither quantity being explicitly provided as an input feature.

---

## Model Summary

SEAI receives a normalized representation of a quadratic equation

$$
ax^2+bx+c=0
$$

and predicts the two ordered real roots.

The model contains exactly:

**8,040,002 trainable parameters.**

The architecture consists of four custom quadratic layers followed by a linear output projection.

```text
Input (2)
    ↓
QuadraticLayer: 2 β†’ 1000
    ↓
LayerNorm
    ↓
GELU
    ↓
QuadraticLayer: 1000 β†’ 2000
    ↓
LayerNorm
    ↓
GELU
    ↓
QuadraticLayer: 2000 β†’ 2000
    ↓
LayerNorm
    ↓
GELU
    ↓
QuadraticLayer: 2000 β†’ 1000
    ↓
LayerNorm
    ↓
GELU
    ↓
Linear: 1000 β†’ 2
    ↓
Ordered normalized roots
```

---

## Mathematical Formulation

A quadratic equation is invariant under multiplication of all coefficients by the same non-zero scalar.

We therefore use the scale-invariant quantities

$$
P=\frac{b}{a},
\qquad
Q=\frac{c}{a}.
$$

The training distribution generated from roots in

$$
[-50,50]
$$

produces

$$
P\in[-100,100],
\qquad
Q\in[-2500,2500].
$$

The model receives the normalized variables

$$
p=\frac{P}{100},
\qquad
q=\frac{Q}{2500}.
$$

The target roots are normalized as

$$
x_n=\frac{x}{50}.
$$

Under this normalization, the exact solution for the normalized roots is

$$
\boxed{
x_{n,1/2}=-p\pm\sqrt{p^2-q}
}
$$

with the roots ordered so that

$$
x_{n,1}\leq x_{n,2}.
$$

The classical discriminant is

$$
\Delta=b^2-4ac.
$$

Under the SEAI normalization,

$$
\boxed{
\Delta=10000a^2(p^2-q)
}
$$

and therefore

$$
\boxed{
p^2-q=\frac{\Delta}{10000a^2}.
}
$$

Thus, \(p^2-q\) is exactly the discriminant normalized by the coefficient scale.

---

## Dataset

The dataset is entirely synthetic.

Two real roots are sampled from

$$
x_1,x_2\sim U(-50,50)
$$

and sorted so that

$$
x_1\leq x_2.
$$

A non-zero coefficient \(a\) is then selected and the remaining coefficients are constructed using

$$
b=-a(x_1+x_2)
$$

and

$$
c=ax_1x_2.
$$

This guarantees that the generated quadratic has the selected roots as its exact solutions.

The current training experiment uses:

```text
Training examples: 150,000
Root range:        [-50, 50]
Task:              real-root quadratic equations
```

The current experiment does not evaluate equations with complex roots.

---

## QuadraticLayer

The central custom component is:

```python
class QuadraticLayer(nn.Module):
    def __init__(self, in_features, out_features):
        super().__init__()

        self.linear = nn.Linear(in_features, out_features)

        self.A = nn.Parameter(torch.ones(out_features) * 0.01)
        self.B = nn.Parameter(torch.ones(out_features))
        self.C = nn.Parameter(torch.zeros(out_features))

    def forward(self, x):
        z = self.linear(x)
        return self.A * z**2 + self.B * z + self.C
```

Each output channel therefore computes

$$
y_i=A_i z_i^2+B_i z_i+C_i
$$

where

$$
z=Wx+b.
$$

This gives the model an explicit mechanism for constructing quadratic nonlinear transformations of learned linear projections.

---

## Training Configuration

```text
Dataset size:       150,000
Batch size:         256
Epochs:             125

Optimizer:          AdamW
Learning rate:      3e-4
Weight decay:       1e-4

Loss:               SmoothL1Loss
Gradient clipping:  max_norm = 1.0

Activation:         GELU
Normalization:      LayerNorm
```

---

## Evaluation

One recent independent evaluation run produced the following results:

| Metric                 |   Result |
| ---------------------- | -------: |
| MAE                    | 0.084864 |
| RMSE                   | 0.137898 |
| Maximum observed error | 1.652145 |
| Error < 0.1            |   69.34% |
| Error < 0.01           |    0.27% |

These metrics are reported in the normalized root representation unless otherwise specified.

The current evaluation results should be considered preliminary. Earlier experiments used independently generated evaluation sets, so future releases will use fixed train/validation/test splits and fixed random seeds for reproducible comparisons.

The model tends to perform worse when the two roots become very close.

---

## Interpretability Analysis

One of the main purposes of SEAI is to investigate whether mathematically meaningful structures emerge inside the network.

Forward hooks are used to record hidden activations from each `QuadraticLayer`.

Neuron activations are compared against candidate mathematical features including

$$
p,\quad q,\quad p^2,\quad q^2,\quad pq,
$$

$$
p^2-q,\qquad p^2+q,
$$

and

$$
\sqrt{|p^2-q|}.
$$

Because the current dataset contains real-root equations, the discriminant-related quantity satisfies

$$
p^2-q\geq0
$$

up to numerical precision.

The analysis investigates which candidate mathematical quantities are most strongly correlated with individual hidden activations.

---

## Observed Representation Structure

The current experiment shows a qualitative progression across layers.

### First Quadratic Layer

Hidden activations primarily show strong correlations with the original variables

$$
p
$$

and

$$
q.
$$

### Second Quadratic Layer

Nonlinear mathematical combinations become more prominent, including

$$
p^2+q
$$

and

$$
p^2-q.
$$

### Third and Fourth Quadratic Layers

The strongest recurring candidate features include

$$
p^2-q
$$

and

$$
\sqrt{p^2-q}.
$$

This produces an experimentally observed progression consistent with the algebraic structure required by the analytical solution:

$$
\boxed{
p,q
\rightarrow
\text{quadratic combinations}
\rightarrow
p^2-q
\rightarrow
\sqrt{p^2-q}
\rightarrow
x_1,x_2
}
$$

The interpretation of this progression remains exploratory.

---

## Main Interpretability Finding

The central observation of the current study is:

> **An 8.04-million-parameter neural network developed hidden representations strongly correlated with the normalized quadratic discriminant and its square-root transformation, despite not receiving either quantity explicitly as an input.**

This does **not** establish that an individual neuron literally performs symbolic discriminant or square-root computation.

Instead, it provides evidence that the trained network contains internal representations that are statistically aligned with mathematically meaningful quantities involved in the classical solution.

---

## Error Behaviour Near Repeated Roots

The largest errors tend to occur when

$$
x_1\approx x_2.
$$

For the normalized representation this corresponds to

$$
p^2-q\approx0.
$$

This is the regime in which the square-root term in the analytical solution approaches zero.

A future systematic analysis will measure prediction error as a function of

$$
|x_2-x_1|
$$

and

$$
p^2-q.
$$

---

## Limitations

The following limitations are important.

### Correlation is not proof of symbolic computation

A high correlation between a neuron and a mathematical expression does not prove that the neuron explicitly computes that expression.

### Preliminary evaluation protocol

The current reported metrics include experiments performed with independently generated evaluation sets. Fixed evaluation data and fixed seeds are required for rigorous model comparison.

### Restricted data distribution

The model is currently trained on real-root quadratic equations generated from roots in

$$
[-50,50].
$$

Generalization outside this range has not yet been established.

### No complex-root regime

The current training and evaluation setup does not investigate equations with

$$
p^2-q<0.
$$

### Interpretability is exploratory

The current analysis is primarily based on neuron-level correlations. Stronger evidence would require symbolic regression, reproducibility across independent runs, and causal interventions on candidate neurons or representations.

---

## Future Research

Planned experiments include:

* fixed reproducible train/validation/test splits;
* multiple random seeds;
* standard MLP baselines;
* ablations of the quadratic transformation;
* systematic neuron-level symbolic regression;
* causal interventions on neurons correlated with \(p^2-q\);
* out-of-distribution evaluation;
* larger root and coefficient ranges;
* analysis of representation stability across independently trained models;
* comparison with conventional polynomial architectures;
* extension to higher-degree polynomial equations.

A key research question is whether the observed discriminant-related representations arise systematically from the quadratic architecture or can be reproduced equally well by standard neural networks of comparable size.

---

## Intended Use

SEAI is intended primarily as a research prototype for:

* mechanistic interpretability;
* mathematical representation learning;
* neural symbolic reasoning;
* analysis of learned algebraic structure;
* controlled studies of neural networks on mathematically defined tasks.

It is not intended to replace conventional numerical solvers in production environments.

For arbitrary quadratic equations, a conventional analytical or numerical solver remains preferable.

---

## Repository Structure

```text
SEAI/
β”œβ”€β”€ train.py
β”œβ”€β”€ model.py
β”œβ”€β”€ interpretability.py
β”œβ”€β”€ evaluation.py
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ README.md
└── weights/
    └── model_weights_SEAI.pth
```

The final reproducible release should additionally contain:

```text
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ train.pt
β”‚   β”œβ”€β”€ validation.pt
β”‚   └── test.pt
β”œβ”€β”€ configs/
β”‚   └── seai_config.json
└── results/
    β”œβ”€β”€ metrics.json
    └── interpretability/
```

---

## Citation

```bibtex
@misc{seai2026,
      title={SEAI: Learning Mathematical Representations for Quadratic Equation Solving},
      author={ALEXFLR},
      year={2026},
      note={Research prototype}
}
```

The corresponding research paper is intended for publication on arXiv.

---

## Project Status

**Research prototype β€” experimental**

SEAI is primarily a research project investigating whether neural networks can develop internal representations aligned with known mathematical structures.


πŸ€–AI

class QuadraticLayer(nn.Module):
    def __init__(self, in_features, out_features):
        super().__init__()
        self.linear = nn.Linear(
            in_features,
            out_features
        )
        self.A = nn.Parameter(
            t.ones(out_features) * 0.01
        )

        self.B = nn.Parameter(
            t.ones(out_features)
        )

        self.C = nn.Parameter(
            t.zeros(out_features)
        )

    def forward(self, x):

        z = self.linear(x)

        return (
            self.A * z**2
            + self.B * z
            + self.C
        )

class SEAI(nn.Module):
    def __init__(self):
        super().__init__()

        self.net = nn.Sequential(

            QuadraticLayer(2, 1000),
            nn.LayerNorm(1000),
            nn.GELU(),

            QuadraticLayer(1000, 2000),
            nn.LayerNorm(2000),
            nn.GELU(),

            QuadraticLayer(2000, 2000),
            nn.LayerNorm(2000),
            nn.GELU(),

            QuadraticLayer(2000, 1000),
            nn.LayerNorm(1000),
            nn.GELU(),

            nn.Linear(1000, 2)
        )

    def forward(self, x):
        return self.net(x)


model = SEAI().to(device)

model.eval()

with t.no_grad():
  ...
weights in another file.