
(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 5 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 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 99.0%
associate-+l+99.0%
associate-+l+99.1%
fma-def99.5%
count-299.5%
distribute-rgt1-in99.5%
metadata-eval99.5%
metadata-eval99.5%
metadata-eval99.5%
*-commutative99.5%
associate-*l*99.6%
metadata-eval99.6%
metadata-eval99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x y z)
:precision binary64
(if (or (<= (* z z) 8.6e-89)
(and (not (<= (* z z) 1.75e-74)) (<= (* z z) 8e-12)))
(* x y)
(* 3.0 (* z z))))
double code(double x, double y, double z) {
double tmp;
if (((z * z) <= 8.6e-89) || (!((z * z) <= 1.75e-74) && ((z * z) <= 8e-12))) {
tmp = x * y;
} 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) <= 8.6d-89) .or. (.not. ((z * z) <= 1.75d-74)) .and. ((z * z) <= 8d-12)) then
tmp = x * y
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) <= 8.6e-89) || (!((z * z) <= 1.75e-74) && ((z * z) <= 8e-12))) {
tmp = x * y;
} else {
tmp = 3.0 * (z * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((z * z) <= 8.6e-89) or (not ((z * z) <= 1.75e-74) and ((z * z) <= 8e-12)): tmp = x * y else: tmp = 3.0 * (z * z) return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(z * z) <= 8.6e-89) || (!(Float64(z * z) <= 1.75e-74) && (Float64(z * z) <= 8e-12))) tmp = Float64(x * y); 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) <= 8.6e-89) || (~(((z * z) <= 1.75e-74)) && ((z * z) <= 8e-12))) tmp = x * y; else tmp = 3.0 * (z * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(z * z), $MachinePrecision], 8.6e-89], And[N[Not[LessEqual[N[(z * z), $MachinePrecision], 1.75e-74]], $MachinePrecision], LessEqual[N[(z * z), $MachinePrecision], 8e-12]]], N[(x * y), $MachinePrecision], N[(3.0 * N[(z * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 8.6 \cdot 10^{-89} \lor \neg \left(z \cdot z \leq 1.75 \cdot 10^{-74}\right) \land z \cdot z \leq 8 \cdot 10^{-12}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;3 \cdot \left(z \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 8.59999999999999974e-89 or 1.75000000000000007e-74 < (*.f64 z z) < 7.99999999999999984e-12Initial program 99.9%
Taylor expanded in x around 0 99.9%
unpow299.9%
+-commutative99.9%
unpow299.9%
*-commutative99.9%
associate-*r*99.9%
*-commutative99.9%
associate-+r+99.9%
distribute-lft-out100.0%
fma-def100.0%
*-commutative100.0%
distribute-rgt1-in100.0%
metadata-eval100.0%
*-commutative100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in z around 0 87.3%
if 8.59999999999999974e-89 < (*.f64 z z) < 1.75000000000000007e-74 or 7.99999999999999984e-12 < (*.f64 z z) Initial program 98.3%
Taylor expanded in x around 0 86.4%
unpow286.4%
unpow286.4%
distribute-rgt1-in86.4%
metadata-eval86.4%
Simplified86.4%
Final simplification86.8%
(FPCore (x y z) :precision binary64 (if (or (<= (* z z) 5e-91) (and (not (<= (* z z) 2e-74)) (<= (* z z) 4e-15))) (* x y) (* z (* z 3.0))))
double code(double x, double y, double z) {
double tmp;
if (((z * z) <= 5e-91) || (!((z * z) <= 2e-74) && ((z * z) <= 4e-15))) {
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 * z) <= 5d-91) .or. (.not. ((z * z) <= 2d-74)) .and. ((z * z) <= 4d-15)) 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 * z) <= 5e-91) || (!((z * z) <= 2e-74) && ((z * z) <= 4e-15))) {
tmp = x * y;
} else {
tmp = z * (z * 3.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((z * z) <= 5e-91) or (not ((z * z) <= 2e-74) and ((z * z) <= 4e-15)): tmp = x * y else: tmp = z * (z * 3.0) return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(z * z) <= 5e-91) || (!(Float64(z * z) <= 2e-74) && (Float64(z * z) <= 4e-15))) 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 * z) <= 5e-91) || (~(((z * z) <= 2e-74)) && ((z * z) <= 4e-15))) tmp = x * y; else tmp = z * (z * 3.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(z * z), $MachinePrecision], 5e-91], And[N[Not[LessEqual[N[(z * z), $MachinePrecision], 2e-74]], $MachinePrecision], LessEqual[N[(z * z), $MachinePrecision], 4e-15]]], N[(x * y), $MachinePrecision], N[(z * N[(z * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-91} \lor \neg \left(z \cdot z \leq 2 \cdot 10^{-74}\right) \land z \cdot z \leq 4 \cdot 10^{-15}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(z \cdot 3\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 4.99999999999999997e-91 or 1.99999999999999992e-74 < (*.f64 z z) < 4.0000000000000003e-15Initial program 99.9%
Taylor expanded in x around 0 99.9%
unpow299.9%
+-commutative99.9%
unpow299.9%
*-commutative99.9%
associate-*r*99.9%
*-commutative99.9%
associate-+r+99.9%
distribute-lft-out100.0%
fma-def100.0%
*-commutative100.0%
distribute-rgt1-in100.0%
metadata-eval100.0%
*-commutative100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in z around 0 87.3%
if 4.99999999999999997e-91 < (*.f64 z z) < 1.99999999999999992e-74 or 4.0000000000000003e-15 < (*.f64 z z) Initial program 98.3%
Taylor expanded in x around 0 86.4%
unpow286.4%
unpow286.4%
distribute-rgt1-in86.4%
metadata-eval86.4%
*-commutative86.4%
associate-*r*86.5%
Simplified86.5%
Final simplification86.9%
(FPCore (x y z) :precision binary64 (+ (* z (* z 3.0)) (* x y)))
double code(double x, double y, double z) {
return (z * (z * 3.0)) + (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 = (z * (z * 3.0d0)) + (x * y)
end function
public static double code(double x, double y, double z) {
return (z * (z * 3.0)) + (x * y);
}
def code(x, y, z): return (z * (z * 3.0)) + (x * y)
function code(x, y, z) return Float64(Float64(z * Float64(z * 3.0)) + Float64(x * y)) end
function tmp = code(x, y, z) tmp = (z * (z * 3.0)) + (x * y); end
code[x_, y_, z_] := N[(N[(z * N[(z * 3.0), $MachinePrecision]), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \left(z \cdot 3\right) + x \cdot y
\end{array}
Initial program 99.0%
associate-+l+99.0%
associate-+l+99.1%
fma-def99.5%
count-299.5%
distribute-rgt1-in99.5%
metadata-eval99.5%
metadata-eval99.5%
metadata-eval99.5%
*-commutative99.5%
associate-*l*99.6%
metadata-eval99.6%
metadata-eval99.6%
Simplified99.6%
fma-udef99.2%
+-commutative99.2%
Applied egg-rr99.2%
Final simplification99.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 99.0%
Taylor expanded in x around 0 99.0%
unpow299.0%
+-commutative99.0%
unpow299.0%
*-commutative99.0%
associate-*r*99.0%
*-commutative99.0%
associate-+r+99.1%
distribute-lft-out99.2%
fma-def99.6%
*-commutative99.6%
distribute-rgt1-in99.6%
metadata-eval99.6%
*-commutative99.6%
*-commutative99.6%
Simplified99.6%
Taylor expanded in z around 0 50.6%
Final simplification50.6%
(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 2023268
(FPCore (x y z)
:name "Linear.Quaternion:$c/ from linear-1.19.1.3, A"
:precision binary64
:herbie-target
(+ (* (* 3.0 z) z) (* y x))
(+ (+ (+ (* x y) (* z z)) (* z z)) (* z z)))