
(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 6 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 (if (<= (* y z) 5e+257) (- x (* (* y z) x)) (* y (* z (- x)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 5e+257) {
tmp = x - ((y * z) * x);
} else {
tmp = y * (z * -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 * z) <= 5d+257) then
tmp = x - ((y * z) * x)
else
tmp = y * (z * -x)
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 5e+257) {
tmp = x - ((y * z) * x);
} else {
tmp = y * (z * -x);
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y * z) <= 5e+257: tmp = x - ((y * z) * x) else: tmp = y * (z * -x) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 5e+257) tmp = Float64(x - Float64(Float64(y * z) * x)); else tmp = Float64(y * Float64(z * Float64(-x))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= 5e+257)
tmp = x - ((y * z) * x);
else
tmp = y * (z * -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[LessEqual[N[(y * z), $MachinePrecision], 5e+257], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 5 \cdot 10^{+257}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 5.00000000000000028e257Initial program 98.3%
sub-neg98.3%
distribute-rgt-in98.3%
*-un-lft-identity98.3%
distribute-rgt-neg-in98.3%
Applied egg-rr98.3%
if 5.00000000000000028e257 < (*.f64 y z) Initial program 73.3%
Taylor expanded in y around inf 99.7%
mul-1-neg99.7%
distribute-rgt-neg-in99.7%
distribute-lft-neg-out99.7%
*-commutative99.7%
Simplified99.7%
Final simplification98.4%
NOTE: y and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (or (<= z -2.4e-115)
(not (or (<= z 1.75e-11) (and (not (<= z 4.9e+17)) (<= z 6e+38)))))
(* (* y z) (- x))
x))assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.4e-115) || !((z <= 1.75e-11) || (!(z <= 4.9e+17) && (z <= 6e+38)))) {
tmp = (y * z) * -x;
} 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 ((z <= (-2.4d-115)) .or. (.not. (z <= 1.75d-11) .or. (.not. (z <= 4.9d+17)) .and. (z <= 6d+38))) then
tmp = (y * z) * -x
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 ((z <= -2.4e-115) || !((z <= 1.75e-11) || (!(z <= 4.9e+17) && (z <= 6e+38)))) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (z <= -2.4e-115) or not ((z <= 1.75e-11) or (not (z <= 4.9e+17) and (z <= 6e+38))): tmp = (y * z) * -x else: tmp = x return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -2.4e-115) || !((z <= 1.75e-11) || (!(z <= 4.9e+17) && (z <= 6e+38)))) tmp = Float64(Float64(y * z) * Float64(-x)); else tmp = x; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -2.4e-115) || ~(((z <= 1.75e-11) || (~((z <= 4.9e+17)) && (z <= 6e+38)))))
tmp = (y * z) * -x;
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[z, -2.4e-115], N[Not[Or[LessEqual[z, 1.75e-11], And[N[Not[LessEqual[z, 4.9e+17]], $MachinePrecision], LessEqual[z, 6e+38]]]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{-115} \lor \neg \left(z \leq 1.75 \cdot 10^{-11} \lor \neg \left(z \leq 4.9 \cdot 10^{+17}\right) \land z \leq 6 \cdot 10^{+38}\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.40000000000000021e-115 or 1.7500000000000001e-11 < z < 4.9e17 or 6.0000000000000002e38 < z Initial program 94.1%
Taylor expanded in y around inf 66.1%
mul-1-neg66.1%
associate-*r*66.7%
distribute-lft-neg-in66.7%
distribute-rgt-neg-out66.7%
*-commutative66.7%
Simplified66.7%
if -2.40000000000000021e-115 < z < 1.7500000000000001e-11 or 4.9e17 < z < 6.0000000000000002e38Initial program 99.9%
Taylor expanded in y around 0 86.8%
Final simplification74.0%
NOTE: y and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (* z (- x)))))
(if (<= z -2.4e-115)
t_0
(if (<= z 5.9e-12)
x
(if (<= z 8.2e+17) (* (* y z) (- x)) (if (<= z 5.5e+38) x t_0))))))assert(y < z);
double code(double x, double y, double z) {
double t_0 = y * (z * -x);
double tmp;
if (z <= -2.4e-115) {
tmp = t_0;
} else if (z <= 5.9e-12) {
tmp = x;
} else if (z <= 8.2e+17) {
tmp = (y * z) * -x;
} else if (z <= 5.5e+38) {
tmp = x;
} else {
tmp = t_0;
}
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 = y * (z * -x)
if (z <= (-2.4d-115)) then
tmp = t_0
else if (z <= 5.9d-12) then
tmp = x
else if (z <= 8.2d+17) then
tmp = (y * z) * -x
else if (z <= 5.5d+38) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double t_0 = y * (z * -x);
double tmp;
if (z <= -2.4e-115) {
tmp = t_0;
} else if (z <= 5.9e-12) {
tmp = x;
} else if (z <= 8.2e+17) {
tmp = (y * z) * -x;
} else if (z <= 5.5e+38) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): t_0 = y * (z * -x) tmp = 0 if z <= -2.4e-115: tmp = t_0 elif z <= 5.9e-12: tmp = x elif z <= 8.2e+17: tmp = (y * z) * -x elif z <= 5.5e+38: tmp = x else: tmp = t_0 return tmp
y, z = sort([y, z]) function code(x, y, z) t_0 = Float64(y * Float64(z * Float64(-x))) tmp = 0.0 if (z <= -2.4e-115) tmp = t_0; elseif (z <= 5.9e-12) tmp = x; elseif (z <= 8.2e+17) tmp = Float64(Float64(y * z) * Float64(-x)); elseif (z <= 5.5e+38) tmp = x; else tmp = t_0; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = y * (z * -x);
tmp = 0.0;
if (z <= -2.4e-115)
tmp = t_0;
elseif (z <= 5.9e-12)
tmp = x;
elseif (z <= 8.2e+17)
tmp = (y * z) * -x;
elseif (z <= 5.5e+38)
tmp = x;
else
tmp = t_0;
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[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.4e-115], t$95$0, If[LessEqual[z, 5.9e-12], x, If[LessEqual[z, 8.2e+17], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], If[LessEqual[z, 5.5e+38], x, t$95$0]]]]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
t_0 := y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{if}\;z \leq -2.4 \cdot 10^{-115}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 5.9 \cdot 10^{-12}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 8.2 \cdot 10^{+17}:\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{+38}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -2.40000000000000021e-115 or 5.5000000000000003e38 < z Initial program 93.7%
Taylor expanded in y around inf 64.3%
mul-1-neg64.3%
distribute-rgt-neg-in64.3%
distribute-lft-neg-out64.3%
*-commutative64.3%
Simplified64.3%
if -2.40000000000000021e-115 < z < 5.9e-12 or 8.2e17 < z < 5.5000000000000003e38Initial program 99.9%
Taylor expanded in y around 0 86.8%
if 5.9e-12 < z < 8.2e17Initial program 99.9%
Taylor expanded in y around inf 91.0%
mul-1-neg91.0%
associate-*r*91.1%
distribute-lft-neg-in91.1%
distribute-rgt-neg-out91.1%
*-commutative91.1%
Simplified91.1%
Final simplification73.6%
NOTE: y and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (* y (- x)))))
(if (<= z -7.8e-82)
t_0
(if (<= z 9.8e-11)
x
(if (<= z 7.6e+16) (* (* y z) (- x)) (if (<= z 4.8e+38) x t_0))))))assert(y < z);
double code(double x, double y, double z) {
double t_0 = z * (y * -x);
double tmp;
if (z <= -7.8e-82) {
tmp = t_0;
} else if (z <= 9.8e-11) {
tmp = x;
} else if (z <= 7.6e+16) {
tmp = (y * z) * -x;
} else if (z <= 4.8e+38) {
tmp = x;
} else {
tmp = t_0;
}
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 = z * (y * -x)
if (z <= (-7.8d-82)) then
tmp = t_0
else if (z <= 9.8d-11) then
tmp = x
else if (z <= 7.6d+16) then
tmp = (y * z) * -x
else if (z <= 4.8d+38) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double t_0 = z * (y * -x);
double tmp;
if (z <= -7.8e-82) {
tmp = t_0;
} else if (z <= 9.8e-11) {
tmp = x;
} else if (z <= 7.6e+16) {
tmp = (y * z) * -x;
} else if (z <= 4.8e+38) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): t_0 = z * (y * -x) tmp = 0 if z <= -7.8e-82: tmp = t_0 elif z <= 9.8e-11: tmp = x elif z <= 7.6e+16: tmp = (y * z) * -x elif z <= 4.8e+38: tmp = x else: tmp = t_0 return tmp
y, z = sort([y, z]) function code(x, y, z) t_0 = Float64(z * Float64(y * Float64(-x))) tmp = 0.0 if (z <= -7.8e-82) tmp = t_0; elseif (z <= 9.8e-11) tmp = x; elseif (z <= 7.6e+16) tmp = Float64(Float64(y * z) * Float64(-x)); elseif (z <= 4.8e+38) tmp = x; else tmp = t_0; end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = z * (y * -x);
tmp = 0.0;
if (z <= -7.8e-82)
tmp = t_0;
elseif (z <= 9.8e-11)
tmp = x;
elseif (z <= 7.6e+16)
tmp = (y * z) * -x;
elseif (z <= 4.8e+38)
tmp = x;
else
tmp = t_0;
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[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -7.8e-82], t$95$0, If[LessEqual[z, 9.8e-11], x, If[LessEqual[z, 7.6e+16], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], If[LessEqual[z, 4.8e+38], x, t$95$0]]]]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
t_0 := z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{if}\;z \leq -7.8 \cdot 10^{-82}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 9.8 \cdot 10^{-11}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 7.6 \cdot 10^{+16}:\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{elif}\;z \leq 4.8 \cdot 10^{+38}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -7.79999999999999947e-82 or 4.80000000000000035e38 < z Initial program 93.4%
*-commutative93.4%
flip--64.4%
associate-*l/60.6%
metadata-eval60.6%
pow260.6%
Applied egg-rr60.6%
unpow260.6%
*-commutative60.6%
associate-*r*56.6%
Applied egg-rr56.6%
Taylor expanded in y around 0 44.0%
unpow244.0%
Simplified44.0%
Taylor expanded in y around inf 66.3%
mul-1-neg66.3%
*-commutative66.3%
*-commutative66.3%
*-commutative66.3%
associate-*l*70.8%
distribute-rgt-neg-in70.8%
*-commutative70.8%
distribute-lft-neg-out70.8%
Simplified70.8%
if -7.79999999999999947e-82 < z < 9.7999999999999998e-11 or 7.6e16 < z < 4.80000000000000035e38Initial program 99.9%
Taylor expanded in y around 0 87.5%
if 9.7999999999999998e-11 < z < 7.6e16Initial program 99.9%
Taylor expanded in y around inf 91.0%
mul-1-neg91.0%
associate-*r*91.1%
distribute-lft-neg-in91.1%
distribute-rgt-neg-out91.1%
*-commutative91.1%
Simplified91.1%
Final simplification78.1%
NOTE: y and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) 5e+257) (* x (- 1.0 (* y z))) (* y (* z (- x)))))
assert(y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 5e+257) {
tmp = x * (1.0 - (y * z));
} else {
tmp = y * (z * -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 * z) <= 5d+257) then
tmp = x * (1.0d0 - (y * z))
else
tmp = y * (z * -x)
end if
code = tmp
end function
assert y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 5e+257) {
tmp = x * (1.0 - (y * z));
} else {
tmp = y * (z * -x);
}
return tmp;
}
[y, z] = sort([y, z]) def code(x, y, z): tmp = 0 if (y * z) <= 5e+257: tmp = x * (1.0 - (y * z)) else: tmp = y * (z * -x) return tmp
y, z = sort([y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 5e+257) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(y * Float64(z * Float64(-x))); end return tmp end
y, z = num2cell(sort([y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((y * z) <= 5e+257)
tmp = x * (1.0 - (y * z));
else
tmp = y * (z * -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[LessEqual[N[(y * z), $MachinePrecision], 5e+257], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, z] = \mathsf{sort}([y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 5 \cdot 10^{+257}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 5.00000000000000028e257Initial program 98.3%
if 5.00000000000000028e257 < (*.f64 y z) Initial program 73.3%
Taylor expanded in y around inf 99.7%
mul-1-neg99.7%
distribute-rgt-neg-in99.7%
distribute-lft-neg-out99.7%
*-commutative99.7%
Simplified99.7%
Final simplification98.4%
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.2%
Taylor expanded in y around 0 49.7%
Final simplification49.7%
herbie shell --seed 2023221
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))