
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
double code(double x, double y, double z) {
return x * (1.0 - (y * 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 * (1.0d0 - (y * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
def code(x, y, z): return x * (1.0 - (y * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(y * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - (y * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - y \cdot z\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
double code(double x, double y, double z) {
return x * (1.0 - (y * 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 * (1.0d0 - (y * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
def code(x, y, z): return x * (1.0 - (y * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(y * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - (y * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - y \cdot z\right)
\end{array}
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* z y) -1e+146) (* z (* y (- x))) (if (<= (* z y) 1e+260) (* x (- 1.0 (* z y))) (* y (* x (- z))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z * y) <= -1e+146) {
tmp = z * (y * -x);
} else if ((z * y) <= 1e+260) {
tmp = x * (1.0 - (z * y));
} else {
tmp = y * (x * -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 ((z * y) <= (-1d+146)) then
tmp = z * (y * -x)
else if ((z * y) <= 1d+260) then
tmp = x * (1.0d0 - (z * y))
else
tmp = y * (x * -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 ((z * y) <= -1e+146) {
tmp = z * (y * -x);
} else if ((z * y) <= 1e+260) {
tmp = x * (1.0 - (z * y));
} else {
tmp = y * (x * -z);
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z * y) <= -1e+146: tmp = z * (y * -x) elif (z * y) <= 1e+260: tmp = x * (1.0 - (z * y)) else: tmp = y * (x * -z) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(z * y) <= -1e+146) tmp = Float64(z * Float64(y * Float64(-x))); elseif (Float64(z * y) <= 1e+260) tmp = Float64(x * Float64(1.0 - Float64(z * y))); else tmp = Float64(y * Float64(x * Float64(-z))); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z * y) <= -1e+146)
tmp = z * (y * -x);
elseif ((z * y) <= 1e+260)
tmp = x * (1.0 - (z * y));
else
tmp = y * (x * -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[(z * y), $MachinePrecision], -1e+146], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * y), $MachinePrecision], 1e+260], N[(x * N[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot y \leq -1 \cdot 10^{+146}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{elif}\;z \cdot y \leq 10^{+260}:\\
\;\;\;\;x \cdot \left(1 - z \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -9.99999999999999934e145Initial program 84.9%
flip--27.8%
associate-*r/27.8%
metadata-eval27.8%
pow227.8%
+-commutative27.8%
fma-def27.8%
Applied egg-rr27.8%
associate-/l*27.8%
Simplified27.8%
Taylor expanded in y around inf 84.9%
div-inv84.8%
frac-2neg84.8%
metadata-eval84.8%
remove-double-div84.9%
distribute-rgt-neg-in84.9%
associate-*r*97.7%
*-commutative97.7%
distribute-rgt-neg-in97.7%
*-commutative97.7%
Applied egg-rr97.7%
if -9.99999999999999934e145 < (*.f64 y z) < 1.00000000000000007e260Initial program 99.9%
if 1.00000000000000007e260 < (*.f64 y z) Initial program 78.0%
Taylor expanded in y around inf 78.0%
mul-1-neg78.0%
associate-*r*99.9%
distribute-rgt-neg-in99.9%
*-commutative99.9%
associate-*r*99.9%
distribute-rgt-neg-out99.9%
Simplified99.9%
Final simplification99.6%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y -3.1e+56) (not (<= y 2.15e-101))) (* x (* z (- y))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.1e+56) || !(y <= 2.15e-101)) {
tmp = x * (z * -y);
} else {
tmp = x;
}
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 <= (-3.1d+56)) .or. (.not. (y <= 2.15d-101))) then
tmp = x * (z * -y)
else
tmp = x
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 <= -3.1e+56) || !(y <= 2.15e-101)) {
tmp = x * (z * -y);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y <= -3.1e+56) or not (y <= 2.15e-101): tmp = x * (z * -y) else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -3.1e+56) || !(y <= 2.15e-101)) tmp = Float64(x * Float64(z * Float64(-y))); else tmp = x; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y <= -3.1e+56) || ~((y <= 2.15e-101)))
tmp = x * (z * -y);
else
tmp = x;
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[y, -3.1e+56], N[Not[LessEqual[y, 2.15e-101]], $MachinePrecision]], N[(x * N[(z * (-y)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.1 \cdot 10^{+56} \lor \neg \left(y \leq 2.15 \cdot 10^{-101}\right):\\
\;\;\;\;x \cdot \left(z \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.10000000000000005e56 or 2.1499999999999999e-101 < y Initial program 91.5%
Taylor expanded in y around inf 68.2%
mul-1-neg68.2%
distribute-rgt-neg-in68.2%
distribute-rgt-neg-out68.2%
Simplified68.2%
if -3.10000000000000005e56 < y < 2.1499999999999999e-101Initial program 99.9%
Taylor expanded in y around 0 76.2%
Final simplification72.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y -3.5e+56) (not (<= y 6e-70))) (* y (* x (- z))) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.5e+56) || !(y <= 6e-70)) {
tmp = y * (x * -z);
} else {
tmp = x;
}
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 <= (-3.5d+56)) .or. (.not. (y <= 6d-70))) then
tmp = y * (x * -z)
else
tmp = x
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 <= -3.5e+56) || !(y <= 6e-70)) {
tmp = y * (x * -z);
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y <= -3.5e+56) or not (y <= 6e-70): tmp = y * (x * -z) else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -3.5e+56) || !(y <= 6e-70)) tmp = Float64(y * Float64(x * Float64(-z))); else tmp = x; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y <= -3.5e+56) || ~((y <= 6e-70)))
tmp = y * (x * -z);
else
tmp = x;
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[y, -3.5e+56], N[Not[LessEqual[y, 6e-70]], $MachinePrecision]], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \cdot 10^{+56} \lor \neg \left(y \leq 6 \cdot 10^{-70}\right):\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.49999999999999999e56 or 6.0000000000000003e-70 < y Initial program 91.0%
Taylor expanded in y around inf 69.5%
mul-1-neg69.5%
associate-*r*75.4%
distribute-rgt-neg-in75.4%
*-commutative75.4%
associate-*r*75.3%
distribute-rgt-neg-out75.3%
Simplified75.3%
if -3.49999999999999999e56 < y < 6.0000000000000003e-70Initial program 99.9%
Taylor expanded in y around 0 75.3%
Final simplification75.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= x 2.15e-160) (- x (* z (* x y))) (* x (- 1.0 (* z y)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (x <= 2.15e-160) {
tmp = x - (z * (x * y));
} else {
tmp = x * (1.0 - (z * 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 <= 2.15d-160) then
tmp = x - (z * (x * y))
else
tmp = x * (1.0d0 - (z * 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 <= 2.15e-160) {
tmp = x - (z * (x * y));
} else {
tmp = x * (1.0 - (z * y));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if x <= 2.15e-160: tmp = x - (z * (x * y)) else: tmp = x * (1.0 - (z * y)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (x <= 2.15e-160) tmp = Float64(x - Float64(z * Float64(x * y))); else tmp = Float64(x * Float64(1.0 - Float64(z * 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 <= 2.15e-160)
tmp = x - (z * (x * y));
else
tmp = x * (1.0 - (z * 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, 2.15e-160], N[(x - N[(z * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.15 \cdot 10^{-160}:\\
\;\;\;\;x - z \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z \cdot y\right)\\
\end{array}
\end{array}
if x < 2.15000000000000007e-160Initial program 93.0%
sub-neg93.0%
distribute-rgt-in92.9%
*-un-lft-identity92.9%
distribute-rgt-neg-in92.9%
Applied egg-rr92.9%
*-commutative92.9%
*-commutative92.9%
associate-*r*93.9%
distribute-rgt-neg-in93.9%
distribute-lft-neg-in93.9%
associate-*l*92.9%
*-commutative92.9%
add-sqr-sqrt53.3%
sqrt-prod68.8%
sqr-neg68.8%
distribute-rgt-neg-out68.8%
distribute-rgt-neg-out68.8%
sqrt-unprod32.2%
add-sqr-sqrt50.7%
cancel-sign-sub-inv50.7%
add-sqr-sqrt32.2%
sqrt-unprod68.8%
distribute-rgt-neg-out68.8%
distribute-rgt-neg-out68.8%
sqr-neg68.8%
Applied egg-rr92.9%
expm1-log1p-u71.5%
expm1-udef60.6%
Applied egg-rr60.6%
expm1-def71.5%
expm1-log1p92.9%
associate-*r*96.4%
*-commutative96.4%
Simplified96.4%
if 2.15000000000000007e-160 < x Initial program 100.0%
Final simplification97.7%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 x)
assert(x < y && y < z);
double code(double x, double y, double z) {
return 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 = x
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return x;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x
x, y, z = sort([x, y, z]) function code(x, y, z) return x end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := x
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x
\end{array}
Initial program 95.4%
Taylor expanded in y around 0 49.2%
Final simplification49.2%
herbie shell --seed 2024020
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))