
(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 (fma y x (* 3.0 (* z z))))
double code(double x, double y, double z) {
return fma(y, x, (3.0 * (z * z)));
}
function code(x, y, z) return fma(y, x, Float64(3.0 * Float64(z * z))) end
code[x_, y_, z_] := N[(y * x + N[(3.0 * N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, 3 \cdot \left(z \cdot z\right)\right)
\end{array}
Initial program 98.3%
associate-+l+N/A
associate-+l+N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
count-2N/A
distribute-lft1-inN/A
metadata-evalN/A
*-lowering-*.f64N/A
*-lowering-*.f6499.1%
Applied egg-rr99.1%
(FPCore (x y z) :precision binary64 (if (<= (* z z) 1e-31) (+ (* z z) (* y x)) (* z (/ 3.0 (/ 1.0 z)))))
double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 1e-31) {
tmp = (z * z) + (y * x);
} else {
tmp = z * (3.0 / (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-31) then
tmp = (z * z) + (y * x)
else
tmp = z * (3.0d0 / (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-31) {
tmp = (z * z) + (y * x);
} else {
tmp = z * (3.0 / (1.0 / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z * z) <= 1e-31: tmp = (z * z) + (y * x) else: tmp = z * (3.0 / (1.0 / z)) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(z * z) <= 1e-31) tmp = Float64(Float64(z * z) + Float64(y * x)); else tmp = Float64(z * Float64(3.0 / Float64(1.0 / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z * z) <= 1e-31) tmp = (z * z) + (y * x); else tmp = z * (3.0 / (1.0 / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e-31], N[(N[(z * z), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(z * N[(3.0 / N[(1.0 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{-31}:\\
\;\;\;\;z \cdot z + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{3}{\frac{1}{z}}\\
\end{array}
\end{array}
if (*.f64 z z) < 1e-31Initial program 99.9%
Taylor expanded in x around inf
*-lowering-*.f6491.5%
Simplified91.5%
if 1e-31 < (*.f64 z z) Initial program 96.9%
Taylor expanded in x around 0
distribute-lft1-inN/A
metadata-evalN/A
*-commutativeN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6483.4%
Simplified83.4%
metadata-evalN/A
div-invN/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6483.3%
Applied egg-rr83.3%
clear-numN/A
div-invN/A
associate-/r*N/A
metadata-evalN/A
/-lowering-/.f64N/A
/-lowering-/.f6483.4%
Applied egg-rr83.4%
Final simplification87.0%
(FPCore (x y z) :precision binary64 (if (<= (* z z) 1e-31) (* y x) (* z (/ 3.0 (/ 1.0 z)))))
double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 1e-31) {
tmp = y * x;
} else {
tmp = z * (3.0 / (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-31) then
tmp = y * x
else
tmp = z * (3.0d0 / (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-31) {
tmp = y * x;
} else {
tmp = z * (3.0 / (1.0 / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z * z) <= 1e-31: tmp = y * x else: tmp = z * (3.0 / (1.0 / z)) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(z * z) <= 1e-31) tmp = Float64(y * x); else tmp = Float64(z * Float64(3.0 / Float64(1.0 / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z * z) <= 1e-31) tmp = y * x; else tmp = z * (3.0 / (1.0 / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e-31], N[(y * x), $MachinePrecision], N[(z * N[(3.0 / N[(1.0 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{-31}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{3}{\frac{1}{z}}\\
\end{array}
\end{array}
if (*.f64 z z) < 1e-31Initial program 99.9%
Taylor expanded in x around inf
*-lowering-*.f6490.4%
Simplified90.4%
if 1e-31 < (*.f64 z z) Initial program 96.9%
Taylor expanded in x around 0
distribute-lft1-inN/A
metadata-evalN/A
*-commutativeN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6483.4%
Simplified83.4%
metadata-evalN/A
div-invN/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6483.3%
Applied egg-rr83.3%
clear-numN/A
div-invN/A
associate-/r*N/A
metadata-evalN/A
/-lowering-/.f64N/A
/-lowering-/.f6483.4%
Applied egg-rr83.4%
Final simplification86.5%
(FPCore (x y z) :precision binary64 (if (<= (* z z) 1e-31) (* y x) (* 3.0 (* z z))))
double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 1e-31) {
tmp = y * x;
} else {
tmp = 3.0 * (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) <= 1d-31) then
tmp = y * x
else
tmp = 3.0d0 * (z * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 1e-31) {
tmp = y * x;
} else {
tmp = 3.0 * (z * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z * z) <= 1e-31: tmp = y * x else: tmp = 3.0 * (z * z) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(z * z) <= 1e-31) tmp = Float64(y * x); else tmp = Float64(3.0 * Float64(z * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z * z) <= 1e-31) tmp = y * x; else tmp = 3.0 * (z * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e-31], N[(y * x), $MachinePrecision], N[(3.0 * N[(z * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{-31}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(z \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1e-31Initial program 99.9%
Taylor expanded in x around inf
*-lowering-*.f6490.4%
Simplified90.4%
if 1e-31 < (*.f64 z z) Initial program 96.9%
Taylor expanded in x around 0
distribute-lft1-inN/A
metadata-evalN/A
*-commutativeN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6483.4%
Simplified83.4%
Final simplification86.5%
(FPCore (x y z) :precision binary64 (if (<= z 1.05e-15) (* y x) (* z (* 3.0 z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.05e-15) {
tmp = y * x;
} else {
tmp = z * (3.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 <= 1.05d-15) then
tmp = y * x
else
tmp = z * (3.0d0 * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 1.05e-15) {
tmp = y * x;
} else {
tmp = z * (3.0 * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.05e-15: tmp = y * x else: tmp = z * (3.0 * z) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.05e-15) tmp = Float64(y * x); else tmp = Float64(z * Float64(3.0 * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.05e-15) tmp = y * x; else tmp = z * (3.0 * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.05e-15], N[(y * x), $MachinePrecision], N[(z * N[(3.0 * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.05 \cdot 10^{-15}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(3 \cdot z\right)\\
\end{array}
\end{array}
if z < 1.0499999999999999e-15Initial program 99.3%
Taylor expanded in x around inf
*-lowering-*.f6464.3%
Simplified64.3%
if 1.0499999999999999e-15 < z Initial program 95.9%
Taylor expanded in x around 0
distribute-lft1-inN/A
metadata-evalN/A
*-commutativeN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6480.7%
Simplified80.7%
associate-*l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f6480.6%
Applied egg-rr80.6%
Final simplification69.3%
(FPCore (x y z) :precision binary64 (if (<= z 6e-16) (* y x) (* z (/ z 0.3333333333333333))))
double code(double x, double y, double z) {
double tmp;
if (z <= 6e-16) {
tmp = y * x;
} else {
tmp = z * (z / 0.3333333333333333);
}
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 <= 6d-16) then
tmp = y * x
else
tmp = z * (z / 0.3333333333333333d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 6e-16) {
tmp = y * x;
} else {
tmp = z * (z / 0.3333333333333333);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 6e-16: tmp = y * x else: tmp = z * (z / 0.3333333333333333) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 6e-16) tmp = Float64(y * x); else tmp = Float64(z * Float64(z / 0.3333333333333333)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 6e-16) tmp = y * x; else tmp = z * (z / 0.3333333333333333); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 6e-16], N[(y * x), $MachinePrecision], N[(z * N[(z / 0.3333333333333333), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 6 \cdot 10^{-16}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \frac{z}{0.3333333333333333}\\
\end{array}
\end{array}
if z < 5.99999999999999987e-16Initial program 99.3%
Taylor expanded in x around inf
*-lowering-*.f6464.3%
Simplified64.3%
if 5.99999999999999987e-16 < z Initial program 95.9%
Taylor expanded in x around 0
distribute-lft1-inN/A
metadata-evalN/A
*-commutativeN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6480.7%
Simplified80.7%
metadata-evalN/A
div-invN/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6480.7%
Applied egg-rr80.7%
Final simplification69.3%
(FPCore (x y z) :precision binary64 (+ (* y x) (* 3.0 (* z z))))
double code(double x, double y, double z) {
return (y * x) + (3.0 * (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 = (y * x) + (3.0d0 * (z * z))
end function
public static double code(double x, double y, double z) {
return (y * x) + (3.0 * (z * z));
}
def code(x, y, z): return (y * x) + (3.0 * (z * z))
function code(x, y, z) return Float64(Float64(y * x) + Float64(3.0 * Float64(z * z))) end
function tmp = code(x, y, z) tmp = (y * x) + (3.0 * (z * z)); end
code[x_, y_, z_] := N[(N[(y * x), $MachinePrecision] + N[(3.0 * N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x + 3 \cdot \left(z \cdot z\right)
\end{array}
Initial program 98.3%
Taylor expanded in x around 0
+-commutativeN/A
associate-+r+N/A
+-commutativeN/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
*-lft-identityN/A
distribute-rgt-outN/A
metadata-evalN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6498.3%
Simplified98.3%
Final simplification98.3%
(FPCore (x y z) :precision binary64 (+ (* y x) (* z (* 3.0 z))))
double code(double x, double y, double z) {
return (y * x) + (z * (3.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 = (y * x) + (z * (3.0d0 * z))
end function
public static double code(double x, double y, double z) {
return (y * x) + (z * (3.0 * z));
}
def code(x, y, z): return (y * x) + (z * (3.0 * z))
function code(x, y, z) return Float64(Float64(y * x) + Float64(z * Float64(3.0 * z))) end
function tmp = code(x, y, z) tmp = (y * x) + (z * (3.0 * z)); end
code[x_, y_, z_] := N[(N[(y * x), $MachinePrecision] + N[(z * N[(3.0 * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x + z \cdot \left(3 \cdot z\right)
\end{array}
Initial program 98.3%
Taylor expanded in x around 0
+-commutativeN/A
associate-+r+N/A
+-commutativeN/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
*-rgt-identityN/A
*-lft-identityN/A
distribute-rgt-outN/A
metadata-evalN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6498.3%
Simplified98.3%
associate-*l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f6498.3%
Applied egg-rr98.3%
Final simplification98.3%
(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 98.3%
Taylor expanded in x around inf
*-lowering-*.f6451.0%
Simplified51.0%
Final simplification51.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 2024191
(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)))