
(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}
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y 2e+65) (fma x y (* z (* z 3.0))) (* y (+ x (* 3.0 (/ z (/ y z)))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= 2e+65) {
tmp = fma(x, y, (z * (z * 3.0)));
} else {
tmp = y * (x + (3.0 * (z / (y / z))));
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= 2e+65) tmp = fma(x, y, Float64(z * Float64(z * 3.0))); else tmp = Float64(y * Float64(x + Float64(3.0 * Float64(z / Float64(y / z))))); 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, 2e+65], N[(x * y + N[(z * N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(x + N[(3.0 * N[(z / N[(y / z), $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^{+65}:\\
\;\;\;\;\mathsf{fma}\left(x, y, z \cdot \left(z \cdot 3\right)\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 3 \cdot \frac{z}{\frac{y}{z}}\right)\\
\end{array}
\end{array}
if y < 2e65Initial program 97.9%
associate-+l+98.0%
associate-+l+98.0%
fma-define98.4%
associate-+r+98.4%
distribute-lft-out98.4%
distribute-lft-out98.5%
remove-double-neg98.5%
unsub-neg98.5%
count-298.5%
neg-mul-198.5%
distribute-rgt-out--98.5%
metadata-eval98.5%
Simplified98.5%
if 2e65 < y Initial program 95.6%
Taylor expanded in y around inf 97.8%
Simplified97.8%
unpow297.8%
associate-/l*99.9%
Applied egg-rr99.9%
clear-num100.0%
un-div-inv100.0%
Applied egg-rr100.0%
Final simplification98.7%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (fma z z (fma x y (* 2.0 (* z z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma(z, z, fma(x, y, (2.0 * (z * z))));
}
x, y, z = sort([x, y, z]) function code(x, y, z) return fma(z, z, fma(x, y, Float64(2.0 * Float64(z * z)))) end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(z * z + N[(x * y + N[(2.0 * N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, y, 2 \cdot \left(z \cdot z\right)\right)\right)
\end{array}
Initial program 97.5%
+-commutative97.5%
fma-define97.6%
associate-+l+97.6%
fma-define98.4%
count-298.4%
Simplified98.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= y 8e-135) (+ (* z z) (+ (* z z) (+ (* z z) (* x y)))) (* y (+ x (* 3.0 (/ z (/ y z)))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (y <= 8e-135) {
tmp = (z * z) + ((z * z) + ((z * z) + (x * y)));
} else {
tmp = y * (x + (3.0 * (z / (y / z))));
}
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 <= 8d-135) then
tmp = (z * z) + ((z * z) + ((z * z) + (x * y)))
else
tmp = y * (x + (3.0d0 * (z / (y / z))))
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 <= 8e-135) {
tmp = (z * z) + ((z * z) + ((z * z) + (x * y)));
} else {
tmp = y * (x + (3.0 * (z / (y / z))));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if y <= 8e-135: tmp = (z * z) + ((z * z) + ((z * z) + (x * y))) else: tmp = y * (x + (3.0 * (z / (y / z)))) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (y <= 8e-135) tmp = Float64(Float64(z * z) + Float64(Float64(z * z) + Float64(Float64(z * z) + Float64(x * y)))); else tmp = Float64(y * Float64(x + Float64(3.0 * Float64(z / Float64(y / 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 <= 8e-135)
tmp = (z * z) + ((z * z) + ((z * z) + (x * y)));
else
tmp = y * (x + (3.0 * (z / (y / 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[y, 8e-135], N[(N[(z * z), $MachinePrecision] + N[(N[(z * z), $MachinePrecision] + N[(N[(z * z), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(x + N[(3.0 * N[(z / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8 \cdot 10^{-135}:\\
\;\;\;\;z \cdot z + \left(z \cdot z + \left(z \cdot z + x \cdot y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 3 \cdot \frac{z}{\frac{y}{z}}\right)\\
\end{array}
\end{array}
if y < 8.0000000000000003e-135Initial program 97.5%
if 8.0000000000000003e-135 < y Initial program 97.5%
Taylor expanded in y around inf 98.7%
Simplified98.7%
unpow298.7%
associate-/l*99.9%
Applied egg-rr99.9%
clear-num99.9%
un-div-inv99.9%
Applied egg-rr99.9%
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 (<= (* z z) 16000000000.0) (* x y) (* (* z z) 3.0)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 16000000000.0) {
tmp = x * y;
} else {
tmp = (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 ((z * z) <= 16000000000.0d0) then
tmp = x * y
else
tmp = (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 ((z * z) <= 16000000000.0) {
tmp = x * y;
} else {
tmp = (z * z) * 3.0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z * z) <= 16000000000.0: tmp = x * y else: tmp = (z * z) * 3.0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(z * z) <= 16000000000.0) tmp = Float64(x * y); else tmp = Float64(Float64(z * 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 ((z * z) <= 16000000000.0)
tmp = x * y;
else
tmp = (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[N[(z * z), $MachinePrecision], 16000000000.0], N[(x * y), $MachinePrecision], N[(N[(z * z), $MachinePrecision] * 3.0), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 16000000000:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot z\right) \cdot 3\\
\end{array}
\end{array}
if (*.f64 z z) < 1.6e10Initial program 99.9%
Taylor expanded in x around inf 84.1%
if 1.6e10 < (*.f64 z z) Initial program 95.0%
Taylor expanded in x around 0 84.8%
Simplified84.8%
unpow284.8%
Applied egg-rr84.8%
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 (/ y z))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
return y * (x + (3.0 * (z / (y / z))));
}
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 / (y / z))))
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return y * (x + (3.0 * (z / (y / z))));
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return y * (x + (3.0 * (z / (y / z))))
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(y * Float64(x + Float64(3.0 * Float64(z / Float64(y / z))))) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = y * (x + (3.0 * (z / (y / z))));
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[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
y \cdot \left(x + 3 \cdot \frac{z}{\frac{y}{z}}\right)
\end{array}
Initial program 97.5%
Taylor expanded in y around inf 92.5%
Simplified92.5%
unpow292.5%
associate-/l*94.0%
Applied egg-rr94.0%
clear-num94.0%
un-div-inv94.0%
Applied egg-rr94.0%
Final simplification94.0%
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 97.5%
Taylor expanded in y around inf 92.5%
Simplified92.5%
unpow292.5%
associate-/l*94.0%
Applied egg-rr94.0%
Final simplification94.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* x y))
assert(x < y && y < z);
double code(double x, double y, double z) {
return x * 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 = x * y
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return x * y;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x * y
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(x * y) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x * y;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x \cdot y
\end{array}
Initial program 97.5%
Taylor expanded in x around inf 53.3%
(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 2024139
(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)))