
(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 7 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 (fma y x (* (* z z) 3.0)))
double code(double x, double y, double z) {
return fma(y, x, ((z * z) * 3.0));
}
function code(x, y, z) return fma(y, x, Float64(Float64(z * z) * 3.0)) end
code[x_, y_, z_] := N[(y * x + N[(N[(z * z), $MachinePrecision] * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, \left(z \cdot z\right) \cdot 3\right)
\end{array}
Initial program 99.1%
associate-+l+N/A
associate-+l+N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
count-2N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-eval99.1%
Simplified99.1%
*-commutativeN/A
fma-defineN/A
fma-lowering-fma.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.5%
Applied egg-rr99.5%
(FPCore (x y z) :precision binary64 (if (<= (* z z) 1e-51) (+ (* z z) (* y x)) (* z (* z 3.0))))
double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 1e-51) {
tmp = (z * z) + (y * x);
} 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) <= 1d-51) then
tmp = (z * z) + (y * x)
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) <= 1e-51) {
tmp = (z * z) + (y * x);
} else {
tmp = z * (z * 3.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z * z) <= 1e-51: tmp = (z * z) + (y * x) else: tmp = z * (z * 3.0) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(z * z) <= 1e-51) tmp = Float64(Float64(z * z) + Float64(y * x)); 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) <= 1e-51) tmp = (z * z) + (y * x); else tmp = z * (z * 3.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e-51], N[(N[(z * z), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(z * N[(z * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{-51}:\\
\;\;\;\;z \cdot z + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(z \cdot 3\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1e-51Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f6493.0%
Simplified93.0%
if 1e-51 < (*.f64 z z) Initial program 98.4%
associate-+l+N/A
associate-+l+N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
count-2N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-eval98.4%
Simplified98.4%
Taylor expanded in x around 0
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6486.9%
Simplified86.9%
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f6487.0%
Applied egg-rr87.0%
Final simplification89.5%
(FPCore (x y z) :precision binary64 (if (<= (* z z) 1e-51) (* y x) (* z (* z 3.0))))
double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 1e-51) {
tmp = y * x;
} 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) <= 1d-51) then
tmp = y * x
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) <= 1e-51) {
tmp = y * x;
} else {
tmp = z * (z * 3.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z * z) <= 1e-51: tmp = y * x else: tmp = z * (z * 3.0) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(z * z) <= 1e-51) tmp = Float64(y * x); 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) <= 1e-51) tmp = y * x; else tmp = z * (z * 3.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e-51], N[(y * x), $MachinePrecision], N[(z * N[(z * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{-51}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(z \cdot 3\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1e-51Initial program 100.0%
associate-+l+N/A
associate-+l+N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
count-2N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf
*-lowering-*.f6492.1%
Simplified92.1%
if 1e-51 < (*.f64 z z) Initial program 98.4%
associate-+l+N/A
associate-+l+N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
count-2N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-eval98.4%
Simplified98.4%
Taylor expanded in x around 0
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6486.9%
Simplified86.9%
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f6487.0%
Applied egg-rr87.0%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (<= (* z z) 2.4e-36) (* y x) (* (* z z) 3.0)))
double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 2.4e-36) {
tmp = y * x;
} 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) <= 2.4d-36) then
tmp = y * x
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) <= 2.4e-36) {
tmp = y * x;
} else {
tmp = (z * z) * 3.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z * z) <= 2.4e-36: tmp = y * x else: tmp = (z * z) * 3.0 return tmp
function code(x, y, z) tmp = 0.0 if (Float64(z * z) <= 2.4e-36) tmp = Float64(y * x); else tmp = Float64(Float64(z * z) * 3.0); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z * z) <= 2.4e-36) tmp = y * x; else tmp = (z * z) * 3.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 2.4e-36], N[(y * x), $MachinePrecision], N[(N[(z * z), $MachinePrecision] * 3.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 2.4 \cdot 10^{-36}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot z\right) \cdot 3\\
\end{array}
\end{array}
if (*.f64 z z) < 2.4e-36Initial program 100.0%
associate-+l+N/A
associate-+l+N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
count-2N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf
*-lowering-*.f6492.1%
Simplified92.1%
if 2.4e-36 < (*.f64 z z) Initial program 98.4%
associate-+l+N/A
associate-+l+N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
count-2N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-eval98.4%
Simplified98.4%
Taylor expanded in x around 0
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6486.9%
Simplified86.9%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (<= (* z z) 6.6e+295) (* y x) (* z z)))
double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 6.6e+295) {
tmp = y * x;
} else {
tmp = z * 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) <= 6.6d+295) then
tmp = y * x
else
tmp = z * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 6.6e+295) {
tmp = y * x;
} else {
tmp = z * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z * z) <= 6.6e+295: tmp = y * x else: tmp = z * z return tmp
function code(x, y, z) tmp = 0.0 if (Float64(z * z) <= 6.6e+295) tmp = Float64(y * x); else tmp = Float64(z * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z * z) <= 6.6e+295) tmp = y * x; else tmp = z * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 6.6e+295], N[(y * x), $MachinePrecision], N[(z * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 6.6 \cdot 10^{+295}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot z\\
\end{array}
\end{array}
if (*.f64 z z) < 6.60000000000000024e295Initial program 99.8%
associate-+l+N/A
associate-+l+N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
count-2N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around inf
*-lowering-*.f6462.5%
Simplified62.5%
if 6.60000000000000024e295 < (*.f64 z z) Initial program 97.0%
Taylor expanded in x around inf
*-lowering-*.f6495.8%
Simplified95.8%
Taylor expanded in x around 0
unpow2N/A
*-lowering-*.f6497.3%
Simplified97.3%
Final simplification71.8%
(FPCore (x y z) :precision binary64 (+ (* y x) (* z (* z 3.0))))
double code(double x, double y, double z) {
return (y * x) + (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 = (y * x) + (z * (z * 3.0d0))
end function
public static double code(double x, double y, double z) {
return (y * x) + (z * (z * 3.0));
}
def code(x, y, z): return (y * x) + (z * (z * 3.0))
function code(x, y, z) return Float64(Float64(y * x) + Float64(z * Float64(z * 3.0))) end
function tmp = code(x, y, z) tmp = (y * x) + (z * (z * 3.0)); end
code[x_, y_, z_] := N[(N[(y * x), $MachinePrecision] + N[(z * N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x + z \cdot \left(z \cdot 3\right)
\end{array}
Initial program 99.1%
associate-+l+N/A
associate-+l+N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
count-2N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-eval99.1%
Simplified99.1%
associate-*l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f6499.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (* y x))
double code(double x, double y, double z) {
return 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 = y * x
end function
public static double code(double x, double y, double z) {
return y * x;
}
def code(x, y, z): return y * x
function code(x, y, z) return Float64(y * x) end
function tmp = code(x, y, z) tmp = y * x; end
code[x_, y_, z_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 99.1%
associate-+l+N/A
associate-+l+N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
count-2N/A
distribute-rgt1-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-eval99.1%
Simplified99.1%
Taylor expanded in x around inf
*-lowering-*.f6448.0%
Simplified48.0%
Final simplification48.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 2024163
(FPCore (x y z)
:name "Linear.Quaternion:$c/ from linear-1.19.1.3, A"
:precision binary64
:alt
(! :herbie-platform default (+ (* (* 3 z) z) (* y x)))
(+ (+ (+ (* x y) (* z z)) (* z z)) (* z z)))