I just tried another test on my local 14W machine running Gemma4.
On another thread I recently posted the following code, in that case also with the output.
.globl main
main:
fli.d f0, 3
fli.d f1, -1
fli.d f2, 1
li a0, 0
li a1, 6
li a2, 18
li a3, 12
0: add a0, a0, a1
add a1, a1, a2
add a2, a2, a3
fmv.d f4, f0
fcvt.d.l f3, a0
fdiv.d f3, f2, f3
fadd.d f0, f0, f3
fmul.d f2, f2, f1
feq.d a4, f0, f4
beqz a4, 0b
la a0, msg
fmv.x.d a1, f0
tail printf
msg: .asciz "%.17g\n"
I just threw this at Gemma4 and said "What does it calculate?"
It took around an hour and got the correct answer analytically.
The funny thing was the first 40 minutes it went down the wrong track, somehow not noticing the fmul.d that flips the sign of each term. It correctly worked out, from expanding only the first three terms, that the result, without the sign flipping, would be $6 - 4\ln(2)$.
But then it noticed its error and corrected.
* Wait, I missed something. The `f2` term.
* In my sum calculation, I assumed $f3 = 1/a0$.
* But the code says:
`fcvt.d.l f3, a0`
`fdiv.d f3, f2, f3`
This means $f3 = f2 / a0$.
* Since $f2$ alternates between $1$ and $-1$, the terms being added to $f0$ are:
$1/a0_1, -1/a0_2, 1/a0_3, -1/a0_4 \dots$
* Wait, let's re-trace $f2$.
* Start: $f2 = 1.0$
* Iter 1: $f3 = 1/a0_1$. Then $f2 = 1 \times -1 = -1$.
* Iter 2: $f3 = -1/a0_2$. Then $f2 = -1 \times -1 = 1$.
* Iter 3: $f3 = 1/a0_3$. Then $f2 = 1 \times -1 = -1$.
* So the sum is $S = \sum_{n=1}^{\infty} \frac{(-1)^{n-1}}{a0_n}$.
* $a0_n = n(n+1)(2n+1)$.
* $S = \sum_{n=1}^{\infty} \frac{(-1)^{n-1}}{n(n+1)(2n+1)}$.
* Use partial fractions: $\frac{1}{n(n+1)(2n+1)} = \frac{1}{n} + \frac{1}{n+1} - \frac{4}{2n+1}$.
* $S = \sum_{n=1}^{\infty} (-1)^{n-1} (\frac{1}{n} + \frac{1}{n+1} - \frac{4}{2n+1})$
* $S = \sum_{n=1}^{\infty} \frac{(-1)^{n-1}}{n} + \sum_{n=1}^{\infty} \frac{(-1)^{n-1}}{n+1} - 4 \sum_{n=1}^{\infty} \frac{(-1)^{n-1}}{2n+1}$
* Term 1: $\sum_{n=1}^{\infty} \frac{(-1)^{n-1}}{n} = 1 - 1/2 + 1/3 - 1/4 \dots = \ln(2)$.
* Term 2: $\sum_{n=1}^{\infty} \frac{(-1)^{n-1}}{n+1} = 1/2 - 1/3 + 1/4 - 1/5 \dots$
We know $\ln(2) = 1 - 1/2 + 1/3 - 1/4 \dots$
So $1/2 - 1/3 + 1/4 \dots = 1 - \ln(2)$.
* Term 3: $\sum_{n=1}^{\infty} \frac{(-1)^{n-1}}{2n+1} = 1/3 - 1/5 + 1/7 - 1/9 \dots$
We know $\arctan(x) = x - x^3/3 + x^5/5 \dots$
For $x=1$, $\pi/4 = 1 - 1/3 + 1/5 - 1/7 \dots$
So $1/3 - 1/5 + 1/7 \dots = 1 - \pi/4$.
* Combine them:
$S = \ln(2) + (1 - \ln(2)) - 4(1 - \pi/4)$
$S = 1 - 4 + \pi = \pi - 3$.
* Wait, let's check the sign of Term 3.
The series is $\sum_{n=1}^{\infty} \frac{(-1)^{n-1}}{2n+1}$.
$n=1 \rightarrow (-1)^0 / 3 = 1/3$.
$n=2 \rightarrow (-1)^1 / 5 = -1/5$.
$n=3 \rightarrow (-1)^2 / 7 = 1/7$.
So $1/3 - 1/5 + 1/7 \dots$
Yes, this is $1 - \pi/4$.
* Let's re-calculate $S$:
$S = \ln(2) + (1 - \ln(2)) - 4(1 - \pi/4)$
$S = 1 - 4 + \pi = \pi - 3$.
* $f0_{initial} = 3.0$
* $f0_{final} = 3 + (\pi - 3) = \pi$.
* $a0_1 = 6$
* $a0_2 = 30$
* $a0_3 = 84$
* $f0$ starts at 3.
* $f2$ starts at 1.
* $f1 = -1$.
* $a1 = 6, a2 = 18, a3 = 12$.
* **Iter 1:**
* $a0 = 0 + 6 = 6$
* $a1 = 6 + 18 = 24$
* $a2 = 18 + 12 = 30$
* $f3 = 1/6$
* $f0 = 3 + 1/6$
* $f2 = -1$
* **Iter 2:**
* $a0 = 6 + 24 = 30$
* $a1 = 24 + 30 = 54$
* $a2 = 30 + 12 = 42$
* $f3 = -1/30$
* $f0 = 3 + 1/6 - 1/30$
* $f2 = 1$
* **Iter 3:**
* $a0 = 30 + 54 = 84$
* $a1 = 54 + 42 = 96$
* $a2 = 42 + 12 = 54$
* $f3 = 1/84$
* $f0 = 3 + 1/6 - 1/30 + 1/84$
* $f2 = -1$
* Sum is $3 + (1/6 - 1/30 + 1/84 - \dots)$
* General term: $\frac{(-1)^{n-1}}{n(n+1)(2n+1)}$
* Sum $S = \sum_{n=1}^{\infty} \frac{(-1)^{n-1}}{n(n+1)(2n+1)} = \pi - 3$.
* $f0 = 3 + \pi - 3 = \pi$.
* `la a0, msg`
* `fmv.x.d a1, f0`
* `tail printf`
* `msg: .asciz "%.17g\n"`
* This prints the value of $f0$ with 17 significant digits.
* $f0 = \pi \approx 3.1415926535897932$
* The program calculates the value of $\pi$ using a series expansion.
* Specifically, it computes $3 + \sum_{n=1}^{\infty} \frac{(-1)^{n-1}}{n(n+1)(2n+1)}$.
* The result is $\pi$.
[End thinking]
The provided RISC-V assembly code calculates the value of **$\pi$ (pi)**.
I don't know how many people on this Earth would have all the different bits of knowledge needed to figure this out in an hour ... or at all. And without reference to anything external. The machine didn't look up anything on the internet to do this, or run any external programs in Python or C or anything else. It's purely what a human could do with nothing more than pen and paper.
Certainly some of the people on this forum reading this could. But in the general population? It would be rare for a random person to understand the assembly language, let alone figure out the linear recurrence, or the series, or be able to analyse the limit of the series. Most mathematicians who could do the last parts would not know RISC-V assembly language (or any other). Most people who are familiar with assembly language probably can't do the math part.
Both Grok and Google AI take around 5 seconds to simply print the answer, complete with the name of the series being summed, and noting the linear recurrence being used to generate the polynomial. ChatGPT is much less helpful, it just notes the series, not the analytical result of the series. Claude gets the right answer but takes far longer than Grok or Google AI.
But I find it remarkable that a machine I can put in my jeans front pocket and that uses less power than a human brain can do this.