
(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 3 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 (+ (* x y) (* z (* z 3.0))))
double code(double x, double y, double z) {
return (x * y) + (z * (z * 3.0));
}
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 * 3.0d0))
end function
public static double code(double x, double y, double z) {
return (x * y) + (z * (z * 3.0));
}
def code(x, y, z): return (x * y) + (z * (z * 3.0))
function code(x, y, z) return Float64(Float64(x * y) + Float64(z * Float64(z * 3.0))) end
function tmp = code(x, y, z) tmp = (x * y) + (z * (z * 3.0)); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(z * N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + z \cdot \left(z \cdot 3\right)
\end{array}
Initial program 98.7%
associate-+l+98.7%
associate-+l+98.7%
associate-+r+98.7%
distribute-lft-out98.7%
distribute-lft-out98.8%
remove-double-neg98.8%
unsub-neg98.8%
neg-mul-198.8%
count-298.8%
distribute-rgt-out--98.8%
metadata-eval98.8%
Simplified98.8%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (<= z 2.26e+21) (* x y) (* z (* z 3.0))))
double code(double x, double y, double z) {
double tmp;
if (z <= 2.26e+21) {
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 <= 2.26d+21) 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 <= 2.26e+21) {
tmp = x * y;
} else {
tmp = z * (z * 3.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 2.26e+21: tmp = x * y else: tmp = z * (z * 3.0) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 2.26e+21) 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 <= 2.26e+21) tmp = x * y; else tmp = z * (z * 3.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 2.26e+21], N[(x * y), $MachinePrecision], N[(z * N[(z * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.26 \cdot 10^{+21}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(z \cdot 3\right)\\
\end{array}
\end{array}
if z < 2.26e21Initial program 99.4%
associate-+l+99.4%
associate-+l+99.4%
associate-+r+99.4%
distribute-lft-out99.4%
distribute-lft-out99.4%
remove-double-neg99.4%
unsub-neg99.4%
neg-mul-199.4%
count-299.4%
distribute-rgt-out--99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in x around inf 68.7%
if 2.26e21 < z Initial program 97.0%
associate-+l+97.0%
associate-+l+97.0%
associate-+r+97.0%
distribute-lft-out97.0%
distribute-lft-out97.0%
remove-double-neg97.0%
unsub-neg97.0%
neg-mul-197.0%
count-297.0%
distribute-rgt-out--97.0%
metadata-eval97.0%
Simplified97.0%
Taylor expanded in x around 0 90.9%
metadata-eval90.9%
sqrt-pow170.2%
metadata-eval70.2%
sqrt-prod70.2%
*-commutative70.2%
Applied egg-rr70.2%
*-commutative70.2%
sqrt-prod70.2%
metadata-eval70.2%
sqrt-pow190.9%
metadata-eval90.9%
unpow290.9%
associate-*r*90.9%
Applied egg-rr90.9%
Final simplification74.7%
(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 98.7%
associate-+l+98.7%
associate-+l+98.7%
associate-+r+98.7%
distribute-lft-out98.7%
distribute-lft-out98.8%
remove-double-neg98.8%
unsub-neg98.8%
neg-mul-198.8%
count-298.8%
distribute-rgt-out--98.8%
metadata-eval98.8%
Simplified98.8%
Taylor expanded in x around inf 54.0%
Final simplification54.0%
(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 2024048
(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)))