
(FPCore (x y z t) :precision binary64 :pre TRUE (+ (/ (* x x) (* y y)) (/ (* z z) (* t t))))
double code(double x, double y, double z, double t) {
return ((x * x) / (y * y)) + ((z * z) / (t * t));
}
real(8) function code(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = ((x * x) / (y * y)) + ((z * z) / (t * t))
end function
public static double code(double x, double y, double z, double t) {
return ((x * x) / (y * y)) + ((z * z) / (t * t));
}
def code(x, y, z, t): return ((x * x) / (y * y)) + ((z * z) / (t * t))
function code(x, y, z, t) return Float64(Float64(Float64(x * x) / Float64(y * y)) + Float64(Float64(z * z) / Float64(t * t))) end
function tmp = code(x, y, z, t) tmp = ((x * x) / (y * y)) + ((z * z) / (t * t)); end
code[x_, y_, z_, t_] := N[(N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(N[(z * z), $MachinePrecision] / N[(t * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x, y, z, t): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf], t in [-inf, +inf] code: THEORY BEGIN f(x, y, z, t: real): real = ((x * x) / (y * y)) + ((z * z) / (t * t)) END code
\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 :pre TRUE (+ (/ (* x x) (* y y)) (/ (* z z) (* t t))))
double code(double x, double y, double z, double t) {
return ((x * x) / (y * y)) + ((z * z) / (t * t));
}
real(8) function code(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = ((x * x) / (y * y)) + ((z * z) / (t * t))
end function
public static double code(double x, double y, double z, double t) {
return ((x * x) / (y * y)) + ((z * z) / (t * t));
}
def code(x, y, z, t): return ((x * x) / (y * y)) + ((z * z) / (t * t))
function code(x, y, z, t) return Float64(Float64(Float64(x * x) / Float64(y * y)) + Float64(Float64(z * z) / Float64(t * t))) end
function tmp = code(x, y, z, t) tmp = ((x * x) / (y * y)) + ((z * z) / (t * t)); end
code[x_, y_, z_, t_] := N[(N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(N[(z * z), $MachinePrecision] / N[(t * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x, y, z, t): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf], t in [-inf, +inf] code: THEORY BEGIN f(x, y, z, t: real): real = ((x * x) / (y * y)) + ((z * z) / (t * t)) END code
\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t}
(FPCore (x y z t) :precision binary64 :pre TRUE (fma (/ z t) (/ z t) (* (/ x y) (/ x y))))
double code(double x, double y, double z, double t) {
return fma((z / t), (z / t), ((x / y) * (x / y)));
}
function code(x, y, z, t) return fma(Float64(z / t), Float64(z / t), Float64(Float64(x / y) * Float64(x / y))) end
code[x_, y_, z_, t_] := N[(N[(z / t), $MachinePrecision] * N[(z / t), $MachinePrecision] + N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x, y, z, t): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf], t in [-inf, +inf] code: THEORY BEGIN f(x, y, z, t: real): real = ((z / t) * (z / t)) + ((x / y) * (x / y)) END code
\mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, \frac{x}{y} \cdot \frac{x}{y}\right)
Initial program 66.6%
Applied rewrites81.2%
Applied rewrites99.7%
(FPCore (x y z t) :precision binary64 :pre TRUE (fma (/ x y) (/ x y) (* z (/ (/ z t) t))))
double code(double x, double y, double z, double t) {
return fma((x / y), (x / y), (z * ((z / t) / t)));
}
function code(x, y, z, t) return fma(Float64(x / y), Float64(x / y), Float64(z * Float64(Float64(z / t) / t))) end
code[x_, y_, z_, t_] := N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision] + N[(z * N[(N[(z / t), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x, y, z, t): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf], t in [-inf, +inf] code: THEORY BEGIN f(x, y, z, t: real): real = ((x / y) * (x / y)) + (z * ((z / t) / t)) END code
\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, z \cdot \frac{\frac{z}{t}}{t}\right)
Initial program 66.6%
Applied rewrites90.1%
Applied rewrites90.1%
Applied rewrites97.0%
(FPCore (x y z t) :precision binary64 :pre TRUE (if (<= (/ (* z z) (* t t)) 5e+302) (fma (/ x y) (/ x y) (* z (/ z (* t t)))) (fma (/ z t) (/ z t) (* x (/ x (* y y))))))
double code(double x, double y, double z, double t) {
double tmp;
if (((z * z) / (t * t)) <= 5e+302) {
tmp = fma((x / y), (x / y), (z * (z / (t * t))));
} else {
tmp = fma((z / t), (z / t), (x * (x / (y * y))));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(Float64(z * z) / Float64(t * t)) <= 5e+302) tmp = fma(Float64(x / y), Float64(x / y), Float64(z * Float64(z / Float64(t * t)))); else tmp = fma(Float64(z / t), Float64(z / t), Float64(x * Float64(x / Float64(y * y)))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(N[(z * z), $MachinePrecision] / N[(t * t), $MachinePrecision]), $MachinePrecision], 5e+302], N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision] + N[(z * N[(z / N[(t * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(z / t), $MachinePrecision] * N[(z / t), $MachinePrecision] + N[(x * N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
f(x, y, z, t): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf], t in [-inf, +inf] code: THEORY BEGIN f(x, y, z, t: real): real = LET tmp = IF (((z * z) / (t * t)) <= (500000000000000000080882538393228219106334323115829719147747508550558749612869373932630121517106957626889886784090168708013722910283889599821695770803013034305575373061142488088628325022100263638403663533845231056330713750098525613244949130339381695724688044273646160407063978743165327734459561131638784)) THEN (((x / y) * (x / y)) + (z * (z / (t * t)))) ELSE (((z / t) * (z / t)) + (x * (x / (y * y)))) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{z \cdot z}{t \cdot t} \leq 5 \cdot 10^{+302}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, z \cdot \frac{z}{t \cdot t}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, \frac{z}{t}, x \cdot \frac{x}{y \cdot y}\right)\\
\end{array}
if (/.f64 (*.f64 z z) (*.f64 t t)) < 5e302Initial program 66.6%
Applied rewrites90.1%
Applied rewrites90.1%
if 5e302 < (/.f64 (*.f64 z z) (*.f64 t t)) Initial program 66.6%
Applied rewrites81.2%
Applied rewrites89.3%
(FPCore (x y z t) :precision binary64 :pre TRUE (if (<= (/ (* z z) (* t t)) INFINITY) (fma (/ x y) (/ x y) (* z (/ z (* t t)))) (fma z (/ (/ z t) t) (/ (* x x) (* y y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (((z * z) / (t * t)) <= ((double) INFINITY)) {
tmp = fma((x / y), (x / y), (z * (z / (t * t))));
} else {
tmp = fma(z, ((z / t) / t), ((x * x) / (y * y)));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(Float64(z * z) / Float64(t * t)) <= Inf) tmp = fma(Float64(x / y), Float64(x / y), Float64(z * Float64(z / Float64(t * t)))); else tmp = fma(z, Float64(Float64(z / t) / t), Float64(Float64(x * x) / Float64(y * y))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(N[(z * z), $MachinePrecision] / N[(t * t), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision] + N[(z * N[(z / N[(t * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(N[(z / t), $MachinePrecision] / t), $MachinePrecision] + N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\frac{z \cdot z}{t \cdot t} \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y}, \frac{x}{y}, z \cdot \frac{z}{t \cdot t}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, \frac{\frac{z}{t}}{t}, \frac{x \cdot x}{y \cdot y}\right)\\
\end{array}
if (/.f64 (*.f64 z z) (*.f64 t t)) < +inf.0Initial program 66.6%
Applied rewrites90.1%
Applied rewrites90.1%
if +inf.0 < (/.f64 (*.f64 z z) (*.f64 t t)) Initial program 66.6%
Applied rewrites73.4%
Applied rewrites79.0%
(FPCore (x y z t)
:precision binary64
:pre TRUE
(let* ((t_1 (/ (* x x) (* y y))))
(if (<= t_1 INFINITY)
(fma z (/ (/ z t) t) t_1)
(fma x (/ (/ x y) y) (/ (* z z) (* t t))))))double code(double x, double y, double z, double t) {
double t_1 = (x * x) / (y * y);
double tmp;
if (t_1 <= ((double) INFINITY)) {
tmp = fma(z, ((z / t) / t), t_1);
} else {
tmp = fma(x, ((x / y) / y), ((z * z) / (t * t)));
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(x * x) / Float64(y * y)) tmp = 0.0 if (t_1 <= Inf) tmp = fma(z, Float64(Float64(z / t) / t), t_1); else tmp = fma(x, Float64(Float64(x / y) / y), Float64(Float64(z * z) / Float64(t * t))); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], N[(z * N[(N[(z / t), $MachinePrecision] / t), $MachinePrecision] + t$95$1), $MachinePrecision], N[(x * N[(N[(x / y), $MachinePrecision] / y), $MachinePrecision] + N[(N[(z * z), $MachinePrecision] / N[(t * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
t_1 := \frac{x \cdot x}{y \cdot y}\\
\mathbf{if}\;t\_1 \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(z, \frac{\frac{z}{t}}{t}, t\_1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{\frac{x}{y}}{y}, \frac{z \cdot z}{t \cdot t}\right)\\
\end{array}
if (/.f64 (*.f64 x x) (*.f64 y y)) < +inf.0Initial program 66.6%
Applied rewrites73.4%
Applied rewrites79.0%
if +inf.0 < (/.f64 (*.f64 x x) (*.f64 y y)) Initial program 66.6%
Applied rewrites73.6%
Applied rewrites79.4%
(FPCore (x y z t) :precision binary64 :pre TRUE (if (<= (/ (* x x) (* y y)) INFINITY) (fma z (/ z (* t t)) (* x (/ x (* y y)))) (fma x (/ (/ x y) y) (/ (* z z) (* t t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (((x * x) / (y * y)) <= ((double) INFINITY)) {
tmp = fma(z, (z / (t * t)), (x * (x / (y * y))));
} else {
tmp = fma(x, ((x / y) / y), ((z * z) / (t * t)));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(Float64(x * x) / Float64(y * y)) <= Inf) tmp = fma(z, Float64(z / Float64(t * t)), Float64(x * Float64(x / Float64(y * y)))); else tmp = fma(x, Float64(Float64(x / y) / y), Float64(Float64(z * z) / Float64(t * t))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision], Infinity], N[(z * N[(z / N[(t * t), $MachinePrecision]), $MachinePrecision] + N[(x * N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(x / y), $MachinePrecision] / y), $MachinePrecision] + N[(N[(z * z), $MachinePrecision] / N[(t * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot x}{y \cdot y} \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(z, \frac{z}{t \cdot t}, x \cdot \frac{x}{y \cdot y}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{\frac{x}{y}}{y}, \frac{z \cdot z}{t \cdot t}\right)\\
\end{array}
if (/.f64 (*.f64 x x) (*.f64 y y)) < +inf.0Initial program 66.6%
Applied rewrites73.4%
Applied rewrites80.9%
if +inf.0 < (/.f64 (*.f64 x x) (*.f64 y y)) Initial program 66.6%
Applied rewrites73.6%
Applied rewrites79.4%
(FPCore (x y z t) :precision binary64 :pre TRUE (fma z (/ z (* t t)) (* x (/ x (* y y)))))
double code(double x, double y, double z, double t) {
return fma(z, (z / (t * t)), (x * (x / (y * y))));
}
function code(x, y, z, t) return fma(z, Float64(z / Float64(t * t)), Float64(x * Float64(x / Float64(y * y)))) end
code[x_, y_, z_, t_] := N[(z * N[(z / N[(t * t), $MachinePrecision]), $MachinePrecision] + N[(x * N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x, y, z, t): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf], t in [-inf, +inf] code: THEORY BEGIN f(x, y, z, t: real): real = (z * (z / (t * t))) + (x * (x / (y * y))) END code
\mathsf{fma}\left(z, \frac{z}{t \cdot t}, x \cdot \frac{x}{y \cdot y}\right)
Initial program 66.6%
Applied rewrites73.4%
Applied rewrites80.9%
(FPCore (x y z t) :precision binary64 :pre TRUE (fma x (/ x (* y y)) (/ (* z z) (* t t))))
double code(double x, double y, double z, double t) {
return fma(x, (x / (y * y)), ((z * z) / (t * t)));
}
function code(x, y, z, t) return fma(x, Float64(x / Float64(y * y)), Float64(Float64(z * z) / Float64(t * t))) end
code[x_, y_, z_, t_] := N[(x * N[(x / N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(N[(z * z), $MachinePrecision] / N[(t * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x, y, z, t): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf], t in [-inf, +inf] code: THEORY BEGIN f(x, y, z, t: real): real = (x * (x / (y * y))) + ((z * z) / (t * t)) END code
\mathsf{fma}\left(x, \frac{x}{y \cdot y}, \frac{z \cdot z}{t \cdot t}\right)
Initial program 66.6%
Applied rewrites73.6%
herbie shell --seed 2026092
(FPCore (x y z t)
:name "Graphics.Rasterific.Svg.PathConverter:arcToSegments from rasterific-svg-0.2.3.1"
:precision binary64
(+ (/ (* x x) (* y y)) (/ (* z z) (* t t))))