Scientific Computing
Implemented — numerical-method examples in ordinary Karkain
arithmetic live under examples/12-scientific-computing/ and run
byte-identically on both engines.
Again with the honest caveat: there is no scientific-computing framework,
no tensor language surface and no arbitrary-precision type in Karkain. What
exists is IEEE double arithmetic through the generated C runtime plus the
implemented array/loop surface. These examples show iterative methods that
avoid the unreliable builtin float helpers where possible — which is both
correct and more instructive.
File |
Demonstrates |
|---|---|
|
Newton–Raphson square root iteration (√2 → 1.41421 …) |
|
Trapezoid rule converging to 1/3 on ∫₀¹ x² dx |
|
Mean, variance and standard deviation over a fixed sample |
|
3×3 integer matrix product |
Newton square root (excerpt)
func sqrt_newton(x) {
let guess = x
let i = 0
while (i < 10) {
guess = (guess + x / guess) / 2.0
i = i + 1
}
return guess
}
Run:
$ karkain run examples/12-scientific-computing/01_sqrt_newton.kark
Output format: floats print at 6 significant figures, identically on both
engines (1.41421, 0.333333, …).
See also
Machine Learning — gradient-descent shares these numeric idioms. Type Reference — the float type used by the runtime.