
(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: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- 1.0 (* y z))))) (if (<= t_0 5e+305) t_0 (* z (* x (- y))))))
assert(y < z);
double code(double x, double y, double z) {
double t_0 = x * (1.0 - (y * z));
double tmp;
if (t_0 <= 5e+305) {
tmp = t_0;
} else {
tmp = z * (x * -y);
}
return tmp;
}
NOTE: 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) :: t_0
real(8) :: tmp
t_0 = x * (1.0d0 - (y * z))
if (t_0 <= 5d+305) then
tmp = t_0
else
tmp = z * (x * -y)
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double t_0 = x * (1.0 - (y * z));
double tmp;
if (t_0 <= 5e+305) {
tmp = t_0;
} else {
tmp = z * (x * -y);
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): t_0 = x * (1.0 - (y * z)) tmp = 0 if t_0 <= 5e+305: tmp = t_0 else: tmp = z * (x * -y) return tmp
y, z = sort([y, z]) function code(x, y, z) t_0 = Float64(x * Float64(1.0 - Float64(y * z))) tmp = 0.0 if (t_0 <= 5e+305) tmp = t_0; else tmp = Float64(z * Float64(x * Float64(-y))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = x * (1.0 - (y * z));
tmp = 0.0;
if (t_0 <= 5e+305)
tmp = t_0;
else
tmp = z * (x * -y);
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 5e+305], t$95$0, N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - y \cdot z\right)\\
\mathbf{if}\;t_0 \leq 5 \cdot 10^{+305}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\end{array}
\end{array}
if (*.f64 x (-.f64 1 (*.f64 y z))) < 5.00000000000000009e305Initial program 98.6%
if 5.00000000000000009e305 < (*.f64 x (-.f64 1 (*.f64 y z))) Initial program 82.0%
add-cube-cbrt82.0%
pow382.0%
Applied egg-rr82.0%
Taylor expanded in y around inf 99.6%
mul-1-neg99.6%
distribute-rgt-neg-in99.6%
distribute-lft-neg-out99.6%
*-commutative99.6%
Simplified99.6%
rem-cube-cbrt100.0%
associate-*r*99.9%
neg-mul-199.9%
associate-*r*99.9%
Applied egg-rr99.9%
Final simplification98.8%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- 1.0 (* y z))))) (if (<= t_0 5e+305) t_0 (* y (* x (- z))))))
assert(y < z);
double code(double x, double y, double z) {
double t_0 = x * (1.0 - (y * z));
double tmp;
if (t_0 <= 5e+305) {
tmp = t_0;
} else {
tmp = y * (x * -z);
}
return tmp;
}
NOTE: 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) :: t_0
real(8) :: tmp
t_0 = x * (1.0d0 - (y * z))
if (t_0 <= 5d+305) then
tmp = t_0
else
tmp = y * (x * -z)
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double t_0 = x * (1.0 - (y * z));
double tmp;
if (t_0 <= 5e+305) {
tmp = t_0;
} else {
tmp = y * (x * -z);
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): t_0 = x * (1.0 - (y * z)) tmp = 0 if t_0 <= 5e+305: tmp = t_0 else: tmp = y * (x * -z) return tmp
y, z = sort([y, z]) function code(x, y, z) t_0 = Float64(x * Float64(1.0 - Float64(y * z))) tmp = 0.0 if (t_0 <= 5e+305) tmp = t_0; else tmp = Float64(y * Float64(x * Float64(-z))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = x * (1.0 - (y * z));
tmp = 0.0;
if (t_0 <= 5e+305)
tmp = t_0;
else
tmp = y * (x * -z);
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 5e+305], t$95$0, N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - y \cdot z\right)\\
\mathbf{if}\;t_0 \leq 5 \cdot 10^{+305}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\end{array}
\end{array}
if (*.f64 x (-.f64 1 (*.f64 y z))) < 5.00000000000000009e305Initial program 98.6%
if 5.00000000000000009e305 < (*.f64 x (-.f64 1 (*.f64 y z))) Initial program 82.0%
Taylor expanded in y around inf 100.0%
mul-1-neg99.6%
distribute-rgt-neg-in99.6%
distribute-lft-neg-out99.6%
*-commutative99.6%
Simplified100.0%
Final simplification98.8%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y -2.2e+81) (not (<= y 1.02e-44))) (* x (* y (- z))) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.2e+81) || !(y <= 1.02e-44)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
NOTE: 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 <= (-2.2d+81)) .or. (.not. (y <= 1.02d-44))) then
tmp = x * (y * -z)
else
tmp = x
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.2e+81) || !(y <= 1.02e-44)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y <= -2.2e+81) or not (y <= 1.02e-44): tmp = x * (y * -z) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -2.2e+81) || !(y <= 1.02e-44)) tmp = Float64(x * Float64(y * Float64(-z))); else tmp = x; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y <= -2.2e+81) || ~((y <= 1.02e-44)))
tmp = x * (y * -z);
else
tmp = x;
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[y, -2.2e+81], N[Not[LessEqual[y, 1.02e-44]], $MachinePrecision]], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.2 \cdot 10^{+81} \lor \neg \left(y \leq 1.02 \cdot 10^{-44}\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.19999999999999987e81 or 1.0199999999999999e-44 < y Initial program 92.4%
Taylor expanded in y around inf 78.2%
mul-1-neg78.2%
associate-*r*74.2%
distribute-lft-neg-in74.2%
distribute-rgt-neg-out74.2%
*-commutative74.2%
Simplified74.2%
if -2.19999999999999987e81 < y < 1.0199999999999999e-44Initial program 99.9%
Taylor expanded in y around 0 78.3%
Final simplification76.4%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= y -1.02e+77) (not (<= y 1.05e-39))) (* y (* x (- z))) x))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.02e+77) || !(y <= 1.05e-39)) {
tmp = y * (x * -z);
} else {
tmp = x;
}
return tmp;
}
NOTE: 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 <= (-1.02d+77)) .or. (.not. (y <= 1.05d-39))) then
tmp = y * (x * -z)
else
tmp = x
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.02e+77) || !(y <= 1.05e-39)) {
tmp = y * (x * -z);
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y <= -1.02e+77) or not (y <= 1.05e-39): tmp = y * (x * -z) else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((y <= -1.02e+77) || !(y <= 1.05e-39)) tmp = Float64(y * Float64(x * Float64(-z))); else tmp = x; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y <= -1.02e+77) || ~((y <= 1.05e-39)))
tmp = y * (x * -z);
else
tmp = x;
end
tmp_2 = tmp;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[y, -1.02e+77], N[Not[LessEqual[y, 1.05e-39]], $MachinePrecision]], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.02 \cdot 10^{+77} \lor \neg \left(y \leq 1.05 \cdot 10^{-39}\right):\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.02e77 or 1.04999999999999997e-39 < y Initial program 92.4%
Taylor expanded in y around inf 78.8%
mul-1-neg78.2%
distribute-rgt-neg-in78.2%
distribute-lft-neg-out78.2%
*-commutative78.2%
Simplified78.8%
if -1.02e77 < y < 1.04999999999999997e-39Initial program 99.9%
Taylor expanded in y around 0 78.4%
Final simplification78.6%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 x)
assert(y < z);
double code(double x, double y, double z) {
return x;
}
NOTE: 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 y < z;
public static double code(double x, double y, double z) {
return x;
}
[y, z] = sort([y, z]) def code(x, y, z): return x
y, z = sort([y, z]) function code(x, y, z) return x end
y, z = num2cell(sort([y, z])){:}
function tmp = code(x, y, z)
tmp = x;
end
NOTE: y and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := x
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
x
\end{array}
Initial program 96.6%
Taylor expanded in y around 0 52.4%
Final simplification52.4%
herbie shell --seed 2023224
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))