
(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 97.9%
associate-+l+97.9%
associate-+l+97.9%
fma-def99.5%
count-299.5%
distribute-rgt1-in99.5%
*-commutative99.5%
associate-*l*99.5%
metadata-eval99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (* z 3.0)))) (if (<= (* z z) 4e+289) (+ t_0 (* x y)) t_0)))
double code(double x, double y, double z) {
double t_0 = z * (z * 3.0);
double tmp;
if ((z * z) <= 4e+289) {
tmp = t_0 + (x * y);
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = z * (z * 3.0d0)
if ((z * z) <= 4d+289) then
tmp = t_0 + (x * y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * (z * 3.0);
double tmp;
if ((z * z) <= 4e+289) {
tmp = t_0 + (x * y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * (z * 3.0) tmp = 0 if (z * z) <= 4e+289: tmp = t_0 + (x * y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(z * 3.0)) tmp = 0.0 if (Float64(z * z) <= 4e+289) tmp = Float64(t_0 + Float64(x * y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * (z * 3.0); tmp = 0.0; if ((z * z) <= 4e+289) tmp = t_0 + (x * y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(z * 3.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * z), $MachinePrecision], 4e+289], N[(t$95$0 + N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(z \cdot 3\right)\\
\mathbf{if}\;z \cdot z \leq 4 \cdot 10^{+289}:\\
\;\;\;\;t_0 + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (*.f64 z z) < 4.0000000000000002e289Initial program 99.8%
associate-+l+99.8%
associate-+l+99.8%
fma-def99.9%
count-299.9%
distribute-rgt1-in99.9%
*-commutative99.9%
associate-*l*99.9%
metadata-eval99.9%
Simplified99.9%
fma-udef99.9%
+-commutative99.9%
Applied egg-rr99.9%
if 4.0000000000000002e289 < (*.f64 z z) Initial program 93.9%
Taylor expanded in x around 0 98.8%
unpow298.8%
unpow298.8%
distribute-rgt1-in98.8%
metadata-eval98.8%
*-commutative98.8%
associate-*r*98.8%
Simplified98.8%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (* z (* z 3.0)))
double code(double x, double y, double z) {
return 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 = z * (z * 3.0d0)
end function
public static double code(double x, double y, double z) {
return z * (z * 3.0);
}
def code(x, y, z): return z * (z * 3.0)
function code(x, y, z) return Float64(z * Float64(z * 3.0)) end
function tmp = code(x, y, z) tmp = z * (z * 3.0); end
code[x_, y_, z_] := N[(z * N[(z * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \left(z \cdot 3\right)
\end{array}
Initial program 97.9%
Taylor expanded in x around 0 56.7%
unpow256.7%
unpow256.7%
distribute-rgt1-in56.7%
metadata-eval56.7%
*-commutative56.7%
associate-*r*56.7%
Simplified56.7%
Final simplification56.7%
(FPCore (x y z) :precision binary64 (* z 2.0))
double code(double x, double y, double z) {
return z * 2.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z * 2.0d0
end function
public static double code(double x, double y, double z) {
return z * 2.0;
}
def code(x, y, z): return z * 2.0
function code(x, y, z) return Float64(z * 2.0) end
function tmp = code(x, y, z) tmp = z * 2.0; end
code[x_, y_, z_] := N[(z * 2.0), $MachinePrecision]
\begin{array}{l}
\\
z \cdot 2
\end{array}
Initial program 97.9%
Taylor expanded in x around 0 56.7%
unpow256.7%
*-commutative56.7%
associate-*l*56.7%
*-commutative56.7%
count-256.7%
Simplified56.7%
+-commutative56.7%
fma-def56.7%
flip-+0.0%
+-inverses0.0%
+-inverses0.0%
associate-*r/0.0%
+-inverses0.0%
+-inverses0.0%
distribute-lft-out--0.0%
+-inverses0.0%
+-inverses0.0%
flip-+33.7%
Applied egg-rr33.7%
fma-udef33.7%
+-commutative33.7%
count-233.7%
distribute-rgt-out34.1%
Simplified34.1%
Taylor expanded in z around 0 3.4%
Simplified3.4%
Final simplification3.4%
(FPCore (x y z) :precision binary64 (* z z))
double code(double x, double y, double z) {
return 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 = z * z
end function
public static double code(double x, double y, double z) {
return z * z;
}
def code(x, y, z): return z * z
function code(x, y, z) return Float64(z * z) end
function tmp = code(x, y, z) tmp = z * z; end
code[x_, y_, z_] := N[(z * z), $MachinePrecision]
\begin{array}{l}
\\
z \cdot z
\end{array}
Initial program 97.9%
Taylor expanded in x around 0 56.7%
unpow256.7%
*-commutative56.7%
associate-*l*56.7%
*-commutative56.7%
count-256.7%
Simplified56.7%
+-commutative56.7%
fma-def56.7%
flip-+0.0%
+-inverses0.0%
+-inverses0.0%
associate-*r/0.0%
+-inverses0.0%
+-inverses0.0%
distribute-lft-out--0.0%
+-inverses0.0%
+-inverses0.0%
flip-+33.7%
Applied egg-rr33.7%
fma-udef33.7%
+-commutative33.7%
count-233.7%
distribute-rgt-out34.1%
Simplified34.1%
Taylor expanded in z around inf 38.2%
Simplified38.2%
Final simplification38.2%
(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 2023224
(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)))