
(FPCore (x y z) :precision binary64 :pre TRUE (+ x (/ (* y y) z)))
double code(double x, double y, double z) {
return x + ((y * y) / z);
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + ((y * y) / z)
end function
public static double code(double x, double y, double z) {
return x + ((y * y) / z);
}
def code(x, y, z): return x + ((y * y) / z)
function code(x, y, z) return Float64(x + Float64(Float64(y * y) / z)) end
function tmp = code(x, y, z) tmp = x + ((y * y) / z); end
code[x_, y_, z_] := N[(x + N[(N[(y * y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = x + ((y * y) / z) END code
x + \frac{y \cdot y}{z}
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 :pre TRUE (+ x (/ (* y y) z)))
double code(double x, double y, double z) {
return x + ((y * y) / z);
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + ((y * y) / z)
end function
public static double code(double x, double y, double z) {
return x + ((y * y) / z);
}
def code(x, y, z): return x + ((y * y) / z)
function code(x, y, z) return Float64(x + Float64(Float64(y * y) / z)) end
function tmp = code(x, y, z) tmp = x + ((y * y) / z); end
code[x_, y_, z_] := N[(x + N[(N[(y * y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = x + ((y * y) / z) END code
x + \frac{y \cdot y}{z}
(FPCore (x y z) :precision binary64 :pre TRUE (fma 0.5 (/ (+ y y) (/ z y)) x))
double code(double x, double y, double z) {
return fma(0.5, ((y + y) / (z / y)), x);
}
function code(x, y, z) return fma(0.5, Float64(Float64(y + y) / Float64(z / y)), x) end
code[x_, y_, z_] := N[(0.5 * N[(N[(y + y), $MachinePrecision] / N[(z / y), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = ((5e-1) * ((y + y) / (z / y))) + x END code
\mathsf{fma}\left(0.5, \frac{y + y}{\frac{z}{y}}, x\right)
Initial program 92.9%
Applied rewrites99.8%
Applied rewrites96.9%
Applied rewrites99.8%
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 :pre TRUE (fma y (* y (/ 1.0 z)) x))
double code(double x, double y, double z) {
return fma(y, (y * (1.0 / z)), x);
}
function code(x, y, z) return fma(y, Float64(y * Float64(1.0 / z)), x) end
code[x_, y_, z_] := N[(y * N[(y * N[(1.0 / z), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (y * (y * ((1) / z))) + x END code
\mathsf{fma}\left(y, y \cdot \frac{1}{z}, x\right)
Initial program 92.9%
Applied rewrites99.9%
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 :pre TRUE (fma y (/ y z) x))
double code(double x, double y, double z) {
return fma(y, (y / z), x);
}
function code(x, y, z) return fma(y, Float64(y / z), x) end
code[x_, y_, z_] := N[(y * N[(y / z), $MachinePrecision] + x), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (y * (y / z)) + x END code
\mathsf{fma}\left(y, \frac{y}{z}, x\right)
Initial program 92.9%
Applied rewrites99.9%
herbie shell --seed 2026092
(FPCore (x y z)
:name "Crypto.Random.Test:calculate from crypto-random-0.0.9"
:precision binary64
(+ x (/ (* y y) z)))