
(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 (<= x -1.2e+35) (* x (+ y (* 3.0 (* z (/ z x))))) (+ (* z z) (+ (* z z) (+ (* z z) (* x y))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= -1.2e+35) {
tmp = x * (y + (3.0 * (z * (z / x))));
} else {
tmp = (z * z) + ((z * z) + ((z * z) + (x * y)));
}
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 (x <= (-1.2d+35)) then
tmp = x * (y + (3.0d0 * (z * (z / x))))
else
tmp = (z * z) + ((z * z) + ((z * z) + (x * y)))
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.2e+35) {
tmp = x * (y + (3.0 * (z * (z / x))));
} else {
tmp = (z * z) + ((z * z) + ((z * z) + (x * y)));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if x <= -1.2e+35: tmp = x * (y + (3.0 * (z * (z / x)))) else: tmp = (z * z) + ((z * z) + ((z * z) + (x * y))) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= -1.2e+35) tmp = Float64(x * Float64(y + Float64(3.0 * Float64(z * Float64(z / x))))); else tmp = Float64(Float64(z * z) + Float64(Float64(z * z) + Float64(Float64(z * z) + Float64(x * y)))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if (x <= -1.2e+35)
tmp = x * (y + (3.0 * (z * (z / x))));
else
tmp = (z * z) + ((z * z) + ((z * z) + (x * y)));
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[x, -1.2e+35], N[(x * N[(y + N[(3.0 * N[(z * N[(z / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(z * z), $MachinePrecision] + N[(N[(z * z), $MachinePrecision] + N[(N[(z * z), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{+35}:\\
\;\;\;\;x \cdot \left(y + 3 \cdot \left(z \cdot \frac{z}{x}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot z + \left(z \cdot z + \left(z \cdot z + x \cdot y\right)\right)\\
\end{array}
\end{array}
if x < -1.20000000000000007e35Initial program 95.3%
Taylor expanded in x around inf 98.4%
Simplified98.4%
unpow298.4%
associate-/l*99.9%
Applied egg-rr99.9%
if -1.20000000000000007e35 < x Initial program 96.6%
Final simplification97.5%
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 96.3%
+-commutative96.3%
fma-define96.4%
associate-+l+96.4%
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 (fma x y (* z (* z 3.0))))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma(x, y, (z * (z * 3.0)));
}
x, y, z = sort([x, y, z]) function code(x, y, z) return fma(x, y, Float64(z * Float64(z * 3.0))) end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x * y + N[(z * N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(x, y, z \cdot \left(z \cdot 3\right)\right)
\end{array}
Initial program 96.3%
associate-+l+96.3%
associate-+l+96.3%
fma-define98.3%
associate-+r+98.3%
distribute-lft-out98.3%
distribute-lft-out98.3%
remove-double-neg98.3%
unsub-neg98.3%
count-298.3%
neg-mul-198.3%
distribute-rgt-out--98.3%
metadata-eval98.3%
Simplified98.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= (* z z) 5e+86) (not (<= (* z z) 1e+302))) (* x (+ y (* 3.0 (* z (/ z x))))) (* z (* z 3.0))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((z * z) <= 5e+86) || !((z * z) <= 1e+302)) {
tmp = x * (y + (3.0 * (z * (z / x))));
} 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) <= 5d+86) .or. (.not. ((z * z) <= 1d+302))) then
tmp = x * (y + (3.0d0 * (z * (z / x))))
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) <= 5e+86) || !((z * z) <= 1e+302)) {
tmp = x * (y + (3.0 * (z * (z / x))));
} 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) <= 5e+86) or not ((z * z) <= 1e+302): tmp = x * (y + (3.0 * (z * (z / x)))) 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) <= 5e+86) || !(Float64(z * z) <= 1e+302)) tmp = Float64(x * Float64(y + Float64(3.0 * Float64(z * Float64(z / x))))); else tmp = Float64(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 (((z * z) <= 5e+86) || ~(((z * z) <= 1e+302)))
tmp = x * (y + (3.0 * (z * (z / x))));
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[Or[LessEqual[N[(z * z), $MachinePrecision], 5e+86], N[Not[LessEqual[N[(z * z), $MachinePrecision], 1e+302]], $MachinePrecision]], N[(x * N[(y + N[(3.0 * N[(z * N[(z / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(z * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{+86} \lor \neg \left(z \cdot z \leq 10^{+302}\right):\\
\;\;\;\;x \cdot \left(y + 3 \cdot \left(z \cdot \frac{z}{x}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(z \cdot 3\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 4.9999999999999998e86 or 1.0000000000000001e302 < (*.f64 z z) Initial program 95.5%
Taylor expanded in x around inf 96.6%
Simplified96.6%
unpow296.6%
associate-/l*98.6%
Applied egg-rr98.6%
if 4.9999999999999998e86 < (*.f64 z z) < 1.0000000000000001e302Initial program 99.4%
associate-+l+99.4%
associate-+l+99.4%
fma-define99.4%
associate-+r+99.4%
distribute-lft-out99.4%
distribute-lft-out99.6%
remove-double-neg99.6%
unsub-neg99.6%
count-299.6%
neg-mul-199.6%
distribute-rgt-out--99.6%
metadata-eval99.6%
Simplified99.6%
add-sqr-sqrt99.3%
pow299.3%
associate-*r*99.1%
sqrt-prod99.1%
sqrt-prod45.4%
add-sqr-sqrt99.1%
Applied egg-rr99.1%
Taylor expanded in x around 0 87.1%
unpow287.1%
unpow287.1%
swap-sqr87.5%
unpow287.5%
Simplified87.5%
*-commutative87.5%
unpow-prod-down87.1%
pow287.1%
rem-square-sqrt87.9%
unpow287.8%
associate-*r*88.0%
Applied egg-rr88.0%
Final simplification96.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* z z) 2e+58) (+ (* z z) (* x y)) (* z (* z 3.0))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 2e+58) {
tmp = (z * z) + (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) <= 2d+58) then
tmp = (z * z) + (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) <= 2e+58) {
tmp = (z * z) + (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) <= 2e+58: tmp = (z * z) + (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) <= 2e+58) tmp = Float64(Float64(z * z) + Float64(x * y)); else tmp = Float64(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 ((z * z) <= 2e+58)
tmp = (z * z) + (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], 2e+58], N[(N[(z * z), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(z * N[(z * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+58}:\\
\;\;\;\;z \cdot z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(z \cdot 3\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1.99999999999999989e58Initial program 99.9%
Taylor expanded in x around inf 87.6%
Taylor expanded in x around inf 87.2%
if 1.99999999999999989e58 < (*.f64 z z) Initial program 92.3%
associate-+l+92.3%
associate-+l+92.3%
fma-define96.4%
associate-+r+96.4%
distribute-lft-out96.4%
distribute-lft-out96.5%
remove-double-neg96.5%
unsub-neg96.5%
count-296.5%
neg-mul-196.5%
distribute-rgt-out--96.5%
metadata-eval96.5%
Simplified96.5%
add-sqr-sqrt96.3%
pow296.3%
associate-*r*96.3%
sqrt-prod96.2%
sqrt-prod44.3%
add-sqr-sqrt96.2%
Applied egg-rr96.2%
Taylor expanded in x around 0 88.7%
unpow288.7%
unpow288.7%
swap-sqr88.9%
unpow288.9%
Simplified88.9%
*-commutative88.9%
unpow-prod-down88.7%
pow288.7%
rem-square-sqrt89.1%
unpow289.1%
associate-*r*89.2%
Applied egg-rr89.2%
Final simplification88.1%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* z z) 2e-95) (* x y) (* z (* z 3.0))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z * z) <= 2e-95) {
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) <= 2d-95) 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) <= 2e-95) {
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) <= 2e-95: 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) <= 2e-95) tmp = Float64(x * y); else tmp = Float64(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 ((z * z) <= 2e-95)
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], 2e-95], N[(x * y), $MachinePrecision], N[(z * N[(z * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 2 \cdot 10^{-95}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(z \cdot 3\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1.99999999999999998e-95Initial program 100.0%
associate-+l+100.0%
associate-+l+100.0%
fma-define100.0%
associate-+r+100.0%
distribute-lft-out100.0%
distribute-lft-out100.0%
remove-double-neg100.0%
unsub-neg100.0%
count-2100.0%
neg-mul-1100.0%
distribute-rgt-out--100.0%
metadata-eval100.0%
Simplified100.0%
add-sqr-sqrt99.9%
pow299.9%
associate-*r*99.9%
sqrt-prod99.9%
sqrt-prod58.1%
add-sqr-sqrt99.9%
Applied egg-rr99.9%
Taylor expanded in x around inf 93.2%
if 1.99999999999999998e-95 < (*.f64 z z) Initial program 93.5%
associate-+l+93.5%
associate-+l+93.5%
fma-define96.9%
associate-+r+96.9%
distribute-lft-out96.9%
distribute-lft-out97.1%
remove-double-neg97.1%
unsub-neg97.1%
count-297.1%
neg-mul-197.1%
distribute-rgt-out--97.1%
metadata-eval97.1%
Simplified97.1%
add-sqr-sqrt96.9%
pow296.9%
associate-*r*96.8%
sqrt-prod96.8%
sqrt-prod44.1%
add-sqr-sqrt96.8%
Applied egg-rr96.8%
Taylor expanded in x around 0 82.5%
unpow282.5%
unpow282.5%
swap-sqr82.7%
unpow282.7%
Simplified82.7%
*-commutative82.7%
unpow-prod-down82.5%
pow282.5%
rem-square-sqrt82.9%
unpow282.9%
associate-*r*83.0%
Applied egg-rr83.0%
Final simplification87.4%
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 96.3%
associate-+l+96.3%
associate-+l+96.3%
fma-define98.3%
associate-+r+98.3%
distribute-lft-out98.3%
distribute-lft-out98.3%
remove-double-neg98.3%
unsub-neg98.3%
count-298.3%
neg-mul-198.3%
distribute-rgt-out--98.3%
metadata-eval98.3%
Simplified98.3%
add-sqr-sqrt98.2%
pow298.2%
associate-*r*98.1%
sqrt-prod98.1%
sqrt-prod50.1%
add-sqr-sqrt98.1%
Applied egg-rr98.1%
Taylor expanded in x around inf 51.5%
(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 2024101
(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)))