
(FPCore (x y z) :precision binary64 (+ (+ (+ (* x y) (* z z)) (* z z)) (* z z)))
double code(double x, double y, double z) {
return (((x * y) + (z * z)) + (z * z)) + (z * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (((x * y) + (z * z)) + (z * z)) + (z * z)
end function
public static double code(double x, double y, double z) {
return (((x * y) + (z * z)) + (z * z)) + (z * z);
}
def code(x, y, z): return (((x * y) + (z * z)) + (z * z)) + (z * z)
function code(x, y, z) return Float64(Float64(Float64(Float64(x * y) + Float64(z * z)) + Float64(z * z)) + Float64(z * z)) end
function tmp = code(x, y, z) tmp = (((x * y) + (z * z)) + (z * z)) + (z * z); end
code[x_, y_, z_] := N[(N[(N[(N[(x * y), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ (+ (* x y) (* z z)) (* z z)) (* z z)))
double code(double x, double y, double z) {
return (((x * y) + (z * z)) + (z * z)) + (z * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (((x * y) + (z * z)) + (z * z)) + (z * z)
end function
public static double code(double x, double y, double z) {
return (((x * y) + (z * z)) + (z * z)) + (z * z);
}
def code(x, y, z): return (((x * y) + (z * z)) + (z * z)) + (z * z)
function code(x, y, z) return Float64(Float64(Float64(Float64(x * y) + Float64(z * z)) + Float64(z * z)) + Float64(z * z)) end
function tmp = code(x, y, z) tmp = (((x * y) + (z * z)) + (z * z)) + (z * z); end
code[x_, y_, z_] := N[(N[(N[(N[(x * y), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (if (<= (* z z) 1e+303) (+ (* z z) (+ (* z z) (+ (* z z) (* x y)))) (* x (+ y (/ (* z 3.0) (/ x z))))))
double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 1e+303) {
tmp = (z * z) + ((z * z) + ((z * z) + (x * y)));
} else {
tmp = x * (y + ((z * 3.0) / (x / z)));
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z * z) <= 1d+303) then
tmp = (z * z) + ((z * z) + ((z * z) + (x * y)))
else
tmp = x * (y + ((z * 3.0d0) / (x / z)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 1e+303) {
tmp = (z * z) + ((z * z) + ((z * z) + (x * y)));
} else {
tmp = x * (y + ((z * 3.0) / (x / z)));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z * z) <= 1e+303: tmp = (z * z) + ((z * z) + ((z * z) + (x * y))) else: tmp = x * (y + ((z * 3.0) / (x / z))) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(z * z) <= 1e+303) tmp = Float64(Float64(z * z) + Float64(Float64(z * z) + Float64(Float64(z * z) + Float64(x * y)))); else tmp = Float64(x * Float64(y + Float64(Float64(z * 3.0) / Float64(x / z)))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z * z) <= 1e+303) tmp = (z * z) + ((z * z) + ((z * z) + (x * y))); else tmp = x * (y + ((z * 3.0) / (x / z))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+303], N[(N[(z * z), $MachinePrecision] + N[(N[(z * z), $MachinePrecision] + N[(N[(z * z), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + N[(N[(z * 3.0), $MachinePrecision] / N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+303}:\\
\;\;\;\;z \cdot z + \left(z \cdot z + \left(z \cdot z + x \cdot y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + \frac{z \cdot 3}{\frac{x}{z}}\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1e303Initial program 99.8%
if 1e303 < (*.f64 z z) Initial program 90.0%
Taylor expanded in x around inf 95.0%
Simplified95.0%
unpow295.0%
associate-/l*100.0%
Applied egg-rr100.0%
clear-num100.0%
un-div-inv100.0%
Applied egg-rr100.0%
associate-*l/100.0%
Applied egg-rr100.0%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (fma z z (fma x y (* 2.0 (* z z)))))
double code(double x, double y, double z) {
return fma(z, z, fma(x, y, (2.0 * (z * z))));
}
function code(x, y, z) return fma(z, z, fma(x, y, Float64(2.0 * Float64(z * z)))) end
code[x_, y_, z_] := N[(z * z + N[(x * y + N[(2.0 * N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, y, 2 \cdot \left(z \cdot z\right)\right)\right)
\end{array}
Initial program 96.7%
+-commutative96.7%
fma-define96.8%
associate-+l+96.8%
fma-define98.4%
count-298.4%
Simplified98.4%
(FPCore (x y z) :precision binary64 (fma x y (* (* z z) 3.0)))
double code(double x, double y, double z) {
return fma(x, y, ((z * z) * 3.0));
}
function code(x, y, z) return fma(x, y, Float64(Float64(z * z) * 3.0)) end
code[x_, y_, z_] := N[(x * y + N[(N[(z * z), $MachinePrecision] * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, \left(z \cdot z\right) \cdot 3\right)
\end{array}
Initial program 96.7%
associate-+l+96.8%
associate-+l+96.8%
fma-define98.3%
*-lft-identity98.3%
metadata-eval98.3%
count-298.3%
distribute-rgt-out98.3%
metadata-eval98.3%
metadata-eval98.3%
Simplified98.3%
(FPCore (x y z) :precision binary64 (fma x y (* z (* z 3.0))))
double code(double x, double y, double z) {
return fma(x, y, (z * (z * 3.0)));
}
function code(x, y, z) return fma(x, y, Float64(z * Float64(z * 3.0))) end
code[x_, y_, z_] := N[(x * y + N[(z * N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, z \cdot \left(z \cdot 3\right)\right)
\end{array}
Initial program 96.7%
associate-+l+96.8%
associate-+l+96.8%
fma-define98.3%
associate-+r+98.3%
distribute-lft-out98.3%
distribute-lft-out98.3%
remove-double-neg98.3%
unsub-neg98.3%
count-298.3%
neg-mul-198.3%
distribute-rgt-out--98.3%
metadata-eval98.3%
Simplified98.3%
(FPCore (x y z) :precision binary64 (if (<= (* x y) (- INFINITY)) (* x y) (+ (* z z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x * y) <= -((double) INFINITY)) {
tmp = x * y;
} else {
tmp = (z * z) + (x * y);
}
return tmp;
}
public static double code(double x, double y, double z) {
double tmp;
if ((x * y) <= -Double.POSITIVE_INFINITY) {
tmp = x * y;
} else {
tmp = (z * z) + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x * y) <= -math.inf: tmp = x * y else: tmp = (z * z) + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x * y) <= Float64(-Inf)) tmp = Float64(x * y); else tmp = Float64(Float64(z * z) + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x * y) <= -Inf) tmp = x * y; else tmp = (z * z) + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x * y), $MachinePrecision], (-Infinity)], N[(x * y), $MachinePrecision], N[(N[(z * z), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -\infty:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot z + x \cdot y\\
\end{array}
\end{array}
if (*.f64 x y) < -inf.0Initial program 55.6%
Taylor expanded in x around inf 77.8%
Simplified77.8%
Taylor expanded in x around inf 77.8%
if -inf.0 < (*.f64 x y) Initial program 99.9%
Taylor expanded in x around inf 79.5%
Taylor expanded in x around inf 79.0%
Final simplification78.9%
(FPCore (x y z) :precision binary64 (* x (+ y (/ (* z 3.0) (/ x z)))))
double code(double x, double y, double z) {
return x * (y + ((z * 3.0) / (x / z)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * (y + ((z * 3.0d0) / (x / z)))
end function
public static double code(double x, double y, double z) {
return x * (y + ((z * 3.0) / (x / z)));
}
def code(x, y, z): return x * (y + ((z * 3.0) / (x / z)))
function code(x, y, z) return Float64(x * Float64(y + Float64(Float64(z * 3.0) / Float64(x / z)))) end
function tmp = code(x, y, z) tmp = x * (y + ((z * 3.0) / (x / z))); end
code[x_, y_, z_] := N[(x * N[(y + N[(N[(z * 3.0), $MachinePrecision] / N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + \frac{z \cdot 3}{\frac{x}{z}}\right)
\end{array}
Initial program 96.7%
Taylor expanded in x around inf 92.5%
Simplified92.5%
unpow292.5%
associate-/l*94.1%
Applied egg-rr94.1%
clear-num94.0%
un-div-inv94.1%
Applied egg-rr94.1%
associate-*l/94.1%
Applied egg-rr94.1%
(FPCore (x y z) :precision binary64 (* x (+ y (* 3.0 (/ z (/ x z))))))
double code(double x, double y, double z) {
return x * (y + (3.0 * (z / (x / z))));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * (y + (3.0d0 * (z / (x / z))))
end function
public static double code(double x, double y, double z) {
return x * (y + (3.0 * (z / (x / z))));
}
def code(x, y, z): return x * (y + (3.0 * (z / (x / z))))
function code(x, y, z) return Float64(x * Float64(y + Float64(3.0 * Float64(z / Float64(x / z))))) end
function tmp = code(x, y, z) tmp = x * (y + (3.0 * (z / (x / z)))); end
code[x_, y_, z_] := N[(x * N[(y + N[(3.0 * N[(z / N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + 3 \cdot \frac{z}{\frac{x}{z}}\right)
\end{array}
Initial program 96.7%
Taylor expanded in x around inf 92.5%
Simplified92.5%
unpow292.5%
associate-/l*94.1%
Applied egg-rr94.1%
clear-num94.0%
un-div-inv94.1%
Applied egg-rr94.1%
Final simplification94.1%
(FPCore (x y z) :precision binary64 (* x (+ y (* 3.0 (* z (/ z x))))))
double code(double x, double y, double z) {
return x * (y + (3.0 * (z * (z / x))));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * (y + (3.0d0 * (z * (z / x))))
end function
public static double code(double x, double y, double z) {
return x * (y + (3.0 * (z * (z / x))));
}
def code(x, y, z): return x * (y + (3.0 * (z * (z / x))))
function code(x, y, z) return Float64(x * Float64(y + Float64(3.0 * Float64(z * Float64(z / x))))) end
function tmp = code(x, y, z) tmp = x * (y + (3.0 * (z * (z / x)))); end
code[x_, y_, z_] := N[(x * N[(y + N[(3.0 * N[(z * N[(z / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + 3 \cdot \left(z \cdot \frac{z}{x}\right)\right)
\end{array}
Initial program 96.7%
Taylor expanded in x around inf 92.5%
Simplified92.5%
unpow292.5%
associate-/l*94.1%
Applied egg-rr94.1%
Final simplification94.1%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return x * y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * y
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 96.7%
Taylor expanded in x around inf 92.5%
Simplified92.5%
Taylor expanded in x around inf 50.3%
(FPCore (x y z) :precision binary64 (+ (* (* 3.0 z) z) (* y x)))
double code(double x, double y, double z) {
return ((3.0 * z) * z) + (y * x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((3.0d0 * z) * z) + (y * x)
end function
public static double code(double x, double y, double z) {
return ((3.0 * z) * z) + (y * x);
}
def code(x, y, z): return ((3.0 * z) * z) + (y * x)
function code(x, y, z) return Float64(Float64(Float64(3.0 * z) * z) + Float64(y * x)) end
function tmp = code(x, y, z) tmp = ((3.0 * z) * z) + (y * x); end
code[x_, y_, z_] := N[(N[(N[(3.0 * z), $MachinePrecision] * z), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(3 \cdot z\right) \cdot z + y \cdot x
\end{array}
herbie shell --seed 2024096
(FPCore (x y z)
:name "Linear.Quaternion:$c/ from linear-1.19.1.3, A"
:precision binary64
:alt
(+ (* (* 3.0 z) z) (* y x))
(+ (+ (+ (* x y) (* z z)) (* z z)) (* z z)))