
(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 6 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}
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y 2.35e-23) (fma x y (* z (* z 3.0))) (* y (+ x (/ 1.0 (/ (/ y z) (* z 3.0)))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= 2.35e-23) {
tmp = fma(x, y, (z * (z * 3.0)));
} else {
tmp = y * (x + (1.0 / ((y / z) / (z * 3.0))));
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= 2.35e-23) tmp = fma(x, y, Float64(z * Float64(z * 3.0))); else tmp = Float64(y * Float64(x + Float64(1.0 / Float64(Float64(y / z) / Float64(z * 3.0))))); end return tmp end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[y, 2.35e-23], N[(x * y + N[(z * N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(x + N[(1.0 / N[(N[(y / z), $MachinePrecision] / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.35 \cdot 10^{-23}:\\
\;\;\;\;\mathsf{fma}\left(x, y, z \cdot \left(z \cdot 3\right)\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + \frac{1}{\frac{\frac{y}{z}}{z \cdot 3}}\right)\\
\end{array}
\end{array}
if y < 2.35e-23Initial program 97.8%
associate-+l+97.8%
associate-+l+97.8%
fma-define98.8%
associate-+r+98.8%
distribute-lft-out98.8%
distribute-lft-out98.9%
remove-double-neg98.9%
unsub-neg98.9%
count-298.9%
neg-mul-198.9%
distribute-rgt-out--98.9%
metadata-eval98.9%
Simplified98.9%
if 2.35e-23 < y Initial program 93.5%
Taylor expanded in y around inf 96.7%
Simplified96.7%
unpow296.7%
associate-/l*100.0%
Applied egg-rr100.0%
clear-num100.0%
un-div-inv99.9%
Applied egg-rr99.9%
associate-*l/99.9%
clear-num100.0%
Applied egg-rr100.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y 2e-21) (+ (* z z) (+ (* z z) (+ (* y x) (* z z)))) (* y (+ x (/ 1.0 (/ (/ y z) (* z 3.0)))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= 2e-21) {
tmp = (z * z) + ((z * z) + ((y * x) + (z * z)));
} else {
tmp = y * (x + (1.0 / ((y / z) / (z * 3.0))));
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 (y <= 2d-21) then
tmp = (z * z) + ((z * z) + ((y * x) + (z * z)))
else
tmp = y * (x + (1.0d0 / ((y / z) / (z * 3.0d0))))
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (y <= 2e-21) {
tmp = (z * z) + ((z * z) + ((y * x) + (z * z)));
} else {
tmp = y * (x + (1.0 / ((y / z) / (z * 3.0))));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if y <= 2e-21: tmp = (z * z) + ((z * z) + ((y * x) + (z * z))) else: tmp = y * (x + (1.0 / ((y / z) / (z * 3.0)))) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= 2e-21) tmp = Float64(Float64(z * z) + Float64(Float64(z * z) + Float64(Float64(y * x) + Float64(z * z)))); else tmp = Float64(y * Float64(x + Float64(1.0 / Float64(Float64(y / z) / Float64(z * 3.0))))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (y <= 2e-21)
tmp = (z * z) + ((z * z) + ((y * x) + (z * z)));
else
tmp = y * (x + (1.0 / ((y / z) / (z * 3.0))));
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[y, 2e-21], N[(N[(z * z), $MachinePrecision] + N[(N[(z * z), $MachinePrecision] + N[(N[(y * x), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(x + N[(1.0 / N[(N[(y / z), $MachinePrecision] / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2 \cdot 10^{-21}:\\
\;\;\;\;z \cdot z + \left(z \cdot z + \left(y \cdot x + z \cdot z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + \frac{1}{\frac{\frac{y}{z}}{z \cdot 3}}\right)\\
\end{array}
\end{array}
if y < 1.99999999999999982e-21Initial program 97.8%
if 1.99999999999999982e-21 < y Initial program 93.5%
Taylor expanded in y around inf 96.7%
Simplified96.7%
unpow296.7%
associate-/l*100.0%
Applied egg-rr100.0%
clear-num100.0%
un-div-inv99.9%
Applied egg-rr99.9%
associate-*l/99.9%
clear-num100.0%
Applied egg-rr100.0%
Final simplification98.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y x) (- INFINITY)) (* y x) (+ (* y x) (* z z))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * x) <= -((double) INFINITY)) {
tmp = y * x;
} else {
tmp = (y * x) + (z * z);
}
return tmp;
}
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * x) <= -Double.POSITIVE_INFINITY) {
tmp = y * x;
} else {
tmp = (y * x) + (z * z);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * x) <= -math.inf: tmp = y * x else: tmp = (y * x) + (z * z) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * x) <= Float64(-Inf)) tmp = Float64(y * x); else tmp = Float64(Float64(y * x) + Float64(z * z)); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * x) <= -Inf)
tmp = y * x;
else
tmp = (y * x) + (z * z);
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(y * x), $MachinePrecision], (-Infinity)], N[(y * x), $MachinePrecision], N[(N[(y * x), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot x \leq -\infty:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x + z \cdot z\\
\end{array}
\end{array}
if (*.f64 x y) < -inf.0Initial program 46.7%
Taylor expanded in y around inf 73.3%
Simplified73.3%
Taylor expanded in y around inf 73.3%
if -inf.0 < (*.f64 x y) Initial program 99.8%
Taylor expanded in x around inf 77.7%
Taylor expanded in x around inf 77.1%
Final simplification76.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* y (+ x (/ 1.0 (/ (/ y z) (* z 3.0))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
return y * (x + (1.0 / ((y / z) / (z * 3.0))));
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 + (1.0d0 / ((y / z) / (z * 3.0d0))))
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return y * (x + (1.0 / ((y / z) / (z * 3.0))));
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return y * (x + (1.0 / ((y / z) / (z * 3.0))))
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(y * Float64(x + Float64(1.0 / Float64(Float64(y / z) / Float64(z * 3.0))))) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = y * (x + (1.0 / ((y / z) / (z * 3.0))));
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(y * N[(x + N[(1.0 / N[(N[(y / z), $MachinePrecision] / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
y \cdot \left(x + \frac{1}{\frac{\frac{y}{z}}{z \cdot 3}}\right)
\end{array}
Initial program 96.7%
Taylor expanded in y around inf 93.5%
Simplified93.5%
unpow293.5%
associate-/l*95.1%
Applied egg-rr95.1%
clear-num95.1%
un-div-inv95.1%
Applied egg-rr95.1%
associate-*l/95.1%
clear-num95.1%
Applied egg-rr95.1%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* y (+ x (* 3.0 (* z (/ z y))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
return y * (x + (3.0 * (z * (z / y))));
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 / y))))
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return y * (x + (3.0 * (z * (z / y))));
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return y * (x + (3.0 * (z * (z / y))))
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(y * Float64(x + Float64(3.0 * Float64(z * Float64(z / y))))) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = y * (x + (3.0 * (z * (z / y))));
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(y * N[(x + N[(3.0 * N[(z * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
y \cdot \left(x + 3 \cdot \left(z \cdot \frac{z}{y}\right)\right)
\end{array}
Initial program 96.7%
Taylor expanded in y around inf 93.5%
Simplified93.5%
unpow293.5%
associate-/l*95.1%
Applied egg-rr95.1%
Final simplification95.1%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* y x))
assert(x < y && y < z);
double code(double x, double y, double z) {
return y * x;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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
assert x < y && y < z;
public static double code(double x, double y, double z) {
return y * x;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return y * x
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(y * x) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = y * x;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
y \cdot x
\end{array}
Initial program 96.7%
Taylor expanded in y around inf 93.5%
Simplified93.5%
Taylor expanded in y around inf 51.4%
Final simplification51.4%
(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 2024106
(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)))