
(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 8 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) (+ (* x y) (* z z)))) (* x (+ y (/ (/ (* z 3.0) x) (/ 1.0 z))))))
double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 1e+303) {
tmp = (z * z) + ((z * z) + ((x * y) + (z * z)));
} else {
tmp = x * (y + (((z * 3.0) / x) / (1.0 / 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) + ((x * y) + (z * z)))
else
tmp = x * (y + (((z * 3.0d0) / x) / (1.0d0 / 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) + ((x * y) + (z * z)));
} else {
tmp = x * (y + (((z * 3.0) / x) / (1.0 / z)));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z * z) <= 1e+303: tmp = (z * z) + ((z * z) + ((x * y) + (z * z))) else: tmp = x * (y + (((z * 3.0) / x) / (1.0 / 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(x * y) + Float64(z * z)))); else tmp = Float64(x * Float64(y + Float64(Float64(Float64(z * 3.0) / x) / Float64(1.0 / 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) + ((x * y) + (z * z))); else tmp = x * (y + (((z * 3.0) / x) / (1.0 / 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[(x * y), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + N[(N[(N[(z * 3.0), $MachinePrecision] / x), $MachinePrecision] / N[(1.0 / 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(x \cdot y + z \cdot z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + \frac{\frac{z \cdot 3}{x}}{\frac{1}{z}}\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1e303Initial program 99.8%
if 1e303 < (*.f64 z z) Initial program 90.0%
associate-+l+90.0%
associate-+l+90.0%
+-commutative90.0%
distribute-lft-out90.0%
distribute-lft-out90.0%
fma-define95.0%
remove-double-neg95.0%
unsub-neg95.0%
count-295.0%
neg-mul-195.0%
distribute-rgt-out--95.0%
metadata-eval95.0%
Simplified95.0%
Taylor expanded in x around inf 95.0%
unpow295.0%
associate-/l*100.0%
Applied egg-rr100.0%
clear-num100.0%
un-div-inv100.0%
Applied egg-rr100.0%
associate-*r/100.0%
div-inv100.0%
associate-/r*100.0%
Applied egg-rr100.0%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (fma z (* z 3.0) (* x y)))
double code(double x, double y, double z) {
return fma(z, (z * 3.0), (x * y));
}
function code(x, y, z) return fma(z, Float64(z * 3.0), Float64(x * y)) end
code[x_, y_, z_] := N[(z * N[(z * 3.0), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, z \cdot 3, x \cdot y\right)
\end{array}
Initial program 96.7%
associate-+l+96.8%
associate-+l+96.8%
+-commutative96.8%
distribute-lft-out96.8%
distribute-lft-out96.8%
fma-define98.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 (<= (* z z) 10000000000000.0) (+ (* x y) (* z z)) (* z (* z 3.0))))
double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 10000000000000.0) {
tmp = (x * y) + (z * z);
} else {
tmp = z * (z * 3.0);
}
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) <= 10000000000000.0d0) then
tmp = (x * y) + (z * z)
else
tmp = z * (z * 3.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 10000000000000.0) {
tmp = (x * y) + (z * z);
} else {
tmp = z * (z * 3.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z * z) <= 10000000000000.0: tmp = (x * y) + (z * z) else: tmp = z * (z * 3.0) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(z * z) <= 10000000000000.0) tmp = Float64(Float64(x * y) + Float64(z * z)); else tmp = Float64(z * Float64(z * 3.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z * z) <= 10000000000000.0) tmp = (x * y) + (z * z); else tmp = z * (z * 3.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 10000000000000.0], N[(N[(x * y), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision], N[(z * N[(z * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10000000000000:\\
\;\;\;\;x \cdot y + z \cdot z\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(z \cdot 3\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1e13Initial program 99.9%
Taylor expanded in x around inf 89.9%
Taylor expanded in x around inf 89.6%
if 1e13 < (*.f64 z z) Initial program 93.9%
Taylor expanded in x around 0 88.3%
distribute-lft1-in88.3%
metadata-eval88.3%
*-commutative88.3%
Simplified88.3%
*-commutative88.3%
unpow288.3%
associate-*r*88.2%
*-commutative88.2%
Applied egg-rr88.2%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (* x (+ y (/ (/ (* z 3.0) x) (/ 1.0 z)))))
double code(double x, double y, double z) {
return x * (y + (((z * 3.0) / x) / (1.0 / 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) / (1.0d0 / z)))
end function
public static double code(double x, double y, double z) {
return x * (y + (((z * 3.0) / x) / (1.0 / z)));
}
def code(x, y, z): return x * (y + (((z * 3.0) / x) / (1.0 / z)))
function code(x, y, z) return Float64(x * Float64(y + Float64(Float64(Float64(z * 3.0) / x) / Float64(1.0 / z)))) end
function tmp = code(x, y, z) tmp = x * (y + (((z * 3.0) / x) / (1.0 / z))); end
code[x_, y_, z_] := N[(x * N[(y + N[(N[(N[(z * 3.0), $MachinePrecision] / x), $MachinePrecision] / N[(1.0 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + \frac{\frac{z \cdot 3}{x}}{\frac{1}{z}}\right)
\end{array}
Initial program 96.7%
associate-+l+96.8%
associate-+l+96.8%
+-commutative96.8%
distribute-lft-out96.8%
distribute-lft-out96.8%
fma-define98.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%
Taylor expanded in x around inf 92.5%
unpow292.5%
associate-/l*94.1%
Applied egg-rr94.1%
clear-num94.0%
un-div-inv94.1%
Applied egg-rr94.1%
associate-*r/94.1%
div-inv94.1%
associate-/r*94.1%
Applied egg-rr94.1%
Final simplification94.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%
associate-+l+96.8%
associate-+l+96.8%
+-commutative96.8%
distribute-lft-out96.8%
distribute-lft-out96.8%
fma-define98.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%
Taylor expanded in x around inf 92.5%
unpow292.5%
associate-/l*94.1%
Applied egg-rr94.1%
clear-num94.0%
un-div-inv94.1%
Applied egg-rr94.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%
associate-+l+96.8%
associate-+l+96.8%
+-commutative96.8%
distribute-lft-out96.8%
distribute-lft-out96.8%
fma-define98.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%
Taylor expanded in x around inf 92.5%
unpow292.5%
associate-/l*94.1%
Applied egg-rr94.1%
(FPCore (x y z) :precision binary64 (if (<= z 1.42e-22) (* x y) (* z (* z 3.0))))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.42e-22) {
tmp = x * y;
} else {
tmp = z * (z * 3.0);
}
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 <= 1.42d-22) then
tmp = x * y
else
tmp = z * (z * 3.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 1.42e-22) {
tmp = x * y;
} else {
tmp = z * (z * 3.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.42e-22: tmp = x * y else: tmp = z * (z * 3.0) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.42e-22) tmp = Float64(x * y); else tmp = Float64(z * Float64(z * 3.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.42e-22) tmp = x * y; else tmp = z * (z * 3.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.42e-22], N[(x * y), $MachinePrecision], N[(z * N[(z * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.42 \cdot 10^{-22}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(z \cdot 3\right)\\
\end{array}
\end{array}
if z < 1.4200000000000001e-22Initial program 97.2%
associate-+l+97.2%
associate-+l+97.2%
+-commutative97.2%
distribute-lft-out97.2%
distribute-lft-out97.2%
fma-define97.7%
remove-double-neg97.7%
unsub-neg97.7%
count-297.7%
neg-mul-197.7%
distribute-rgt-out--97.7%
metadata-eval97.7%
Simplified97.7%
Taylor expanded in x around inf 95.9%
Taylor expanded in x around inf 60.3%
if 1.4200000000000001e-22 < z Initial program 95.7%
Taylor expanded in x around 0 77.6%
distribute-lft1-in77.6%
metadata-eval77.6%
*-commutative77.6%
Simplified77.6%
*-commutative77.6%
unpow277.6%
associate-*r*77.5%
*-commutative77.5%
Applied egg-rr77.5%
Final simplification65.2%
(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%
associate-+l+96.8%
associate-+l+96.8%
+-commutative96.8%
distribute-lft-out96.8%
distribute-lft-out96.8%
fma-define98.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%
Taylor expanded in x around inf 92.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)))