
(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: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) -2e+179) (- (* z (* y x))) (* x (- 1.0 (* y z)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -2e+179) {
tmp = -(z * (y * x));
} else {
tmp = x * (1.0 - (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 * z) <= (-2d+179)) then
tmp = -(z * (y * x))
else
tmp = x * (1.0d0 - (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 * z) <= -2e+179) {
tmp = -(z * (y * x));
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -2e+179: tmp = -(z * (y * x)) else: tmp = x * (1.0 - (y * z)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -2e+179) tmp = Float64(-Float64(z * Float64(y * x))); else tmp = Float64(x * Float64(1.0 - 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 * z) <= -2e+179)
tmp = -(z * (y * x));
else
tmp = x * (1.0 - (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[N[(y * z), $MachinePrecision], -2e+179], (-N[(z * N[(y * x), $MachinePrecision]), $MachinePrecision]), N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -2 \cdot 10^{+179}:\\
\;\;\;\;-z \cdot \left(y \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -1.99999999999999996e179Initial program 76.7%
Taylor expanded in y around inf 76.7%
mul-1-neg76.7%
associate-*r*99.8%
Simplified99.8%
if -1.99999999999999996e179 < (*.f64 y z) Initial program 98.2%
Final simplification98.4%
NOTE: x, 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 (<= (* y z) -2e+179)
t_0
(if (<= (* y z) -200.0) (* (* y z) (- x)) (if (<= (* y z) 0.02) x t_0)))))assert(x < y && y < z);
double code(double x, double y, double z) {
double t_0 = -(z * (y * x));
double tmp;
if ((y * z) <= -2e+179) {
tmp = t_0;
} else if ((y * z) <= -200.0) {
tmp = (y * z) * -x;
} else if ((y * z) <= 0.02) {
tmp = x;
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = -(z * (y * x))
if ((y * z) <= (-2d+179)) then
tmp = t_0
else if ((y * z) <= (-200.0d0)) then
tmp = (y * z) * -x
else if ((y * z) <= 0.02d0) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double t_0 = -(z * (y * x));
double tmp;
if ((y * z) <= -2e+179) {
tmp = t_0;
} else if ((y * z) <= -200.0) {
tmp = (y * z) * -x;
} else if ((y * z) <= 0.02) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): t_0 = -(z * (y * x)) tmp = 0 if (y * z) <= -2e+179: tmp = t_0 elif (y * z) <= -200.0: tmp = (y * z) * -x elif (y * z) <= 0.02: tmp = x else: tmp = t_0 return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) t_0 = Float64(-Float64(z * Float64(y * x))) tmp = 0.0 if (Float64(y * z) <= -2e+179) tmp = t_0; elseif (Float64(y * z) <= -200.0) tmp = Float64(Float64(y * z) * Float64(-x)); elseif (Float64(y * z) <= 0.02) tmp = x; else tmp = t_0; end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
t_0 = -(z * (y * x));
tmp = 0.0;
if ((y * z) <= -2e+179)
tmp = t_0;
elseif ((y * z) <= -200.0)
tmp = (y * z) * -x;
elseif ((y * z) <= 0.02)
tmp = x;
else
tmp = t_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_] := Block[{t$95$0 = (-N[(z * N[(y * x), $MachinePrecision]), $MachinePrecision])}, If[LessEqual[N[(y * z), $MachinePrecision], -2e+179], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], -200.0], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 0.02], x, t$95$0]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := -z \cdot \left(y \cdot x\right)\\
\mathbf{if}\;y \cdot z \leq -2 \cdot 10^{+179}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \cdot z \leq -200:\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{elif}\;y \cdot z \leq 0.02:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 y z) < -1.99999999999999996e179 or 0.0200000000000000004 < (*.f64 y z) Initial program 88.0%
Taylor expanded in y around inf 86.6%
mul-1-neg86.6%
associate-*r*91.7%
Simplified91.7%
if -1.99999999999999996e179 < (*.f64 y z) < -200Initial program 99.8%
Taylor expanded in y around inf 95.9%
mul-1-neg95.9%
associate-*r*87.3%
Simplified87.3%
Taylor expanded in x around 0 95.9%
if -200 < (*.f64 y z) < 0.0200000000000000004Initial program 100.0%
Taylor expanded in y around 0 97.9%
Final simplification95.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 z) -200.0) (not (<= (* y z) 0.02))) (* (* y z) (- x)) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -200.0) || !((y * z) <= 0.02)) {
tmp = (y * z) * -x;
} 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 * z) <= (-200.0d0)) .or. (.not. ((y * z) <= 0.02d0))) then
tmp = (y * z) * -x
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 * z) <= -200.0) || !((y * z) <= 0.02)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if ((y * z) <= -200.0) or not ((y * z) <= 0.02): tmp = (y * z) * -x else: tmp = x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -200.0) || !(Float64(y * z) <= 0.02)) tmp = Float64(Float64(y * z) * Float64(-x)); 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 * z) <= -200.0) || ~(((y * z) <= 0.02)))
tmp = (y * z) * -x;
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[N[(y * z), $MachinePrecision], -200.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.02]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -200 \lor \neg \left(y \cdot z \leq 0.02\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -200 or 0.0200000000000000004 < (*.f64 y z) Initial program 91.1%
Taylor expanded in y around inf 89.1%
mul-1-neg89.1%
associate-*r*90.5%
Simplified90.5%
Taylor expanded in x around 0 89.1%
if -200 < (*.f64 y z) < 0.0200000000000000004Initial program 100.0%
Taylor expanded in y around 0 97.9%
Final simplification93.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (* y z) -200.0) (* y (* z (- x))) (if (<= (* y z) 0.02) x (- (* z (* y x))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -200.0) {
tmp = y * (z * -x);
} else if ((y * z) <= 0.02) {
tmp = x;
} else {
tmp = -(z * (y * 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 * z) <= (-200.0d0)) then
tmp = y * (z * -x)
else if ((y * z) <= 0.02d0) then
tmp = x
else
tmp = -(z * (y * 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 * z) <= -200.0) {
tmp = y * (z * -x);
} else if ((y * z) <= 0.02) {
tmp = x;
} else {
tmp = -(z * (y * x));
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (y * z) <= -200.0: tmp = y * (z * -x) elif (y * z) <= 0.02: tmp = x else: tmp = -(z * (y * x)) return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -200.0) tmp = Float64(y * Float64(z * Float64(-x))); elseif (Float64(y * z) <= 0.02) tmp = x; else tmp = Float64(-Float64(z * Float64(y * 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 * z) <= -200.0)
tmp = y * (z * -x);
elseif ((y * z) <= 0.02)
tmp = x;
else
tmp = -(z * (y * 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[LessEqual[N[(y * z), $MachinePrecision], -200.0], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 0.02], x, (-N[(z * N[(y * x), $MachinePrecision]), $MachinePrecision])]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -200:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{elif}\;y \cdot z \leq 0.02:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;-z \cdot \left(y \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -200Initial program 89.0%
Taylor expanded in y around inf 86.9%
mul-1-neg86.9%
associate-*r*93.1%
distribute-rgt-neg-in93.1%
*-commutative93.1%
associate-*l*89.9%
Simplified89.9%
if -200 < (*.f64 y z) < 0.0200000000000000004Initial program 100.0%
Taylor expanded in y around 0 97.9%
if 0.0200000000000000004 < (*.f64 y z) Initial program 93.3%
Taylor expanded in y around inf 91.2%
mul-1-neg91.2%
associate-*r*87.8%
Simplified87.8%
Final simplification93.7%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= z 2.3e+188) x (/ (* z x) z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (z <= 2.3e+188) {
tmp = x;
} else {
tmp = (z * 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 <= 2.3d+188) then
tmp = x
else
tmp = (z * 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 <= 2.3e+188) {
tmp = x;
} else {
tmp = (z * x) / z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if z <= 2.3e+188: tmp = x else: tmp = (z * x) / z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (z <= 2.3e+188) tmp = x; else tmp = Float64(Float64(z * x) / 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 <= 2.3e+188)
tmp = x;
else
tmp = (z * 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[z, 2.3e+188], x, N[(N[(z * x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.3 \cdot 10^{+188}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{z \cdot x}{z}\\
\end{array}
\end{array}
if z < 2.30000000000000011e188Initial program 96.7%
Taylor expanded in y around 0 58.1%
if 2.30000000000000011e188 < z Initial program 85.0%
Taylor expanded in z around inf 89.7%
Taylor expanded in y around 0 3.1%
associate-*r/27.8%
Applied egg-rr27.8%
Final simplification55.9%
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.9%
Taylor expanded in y around 0 54.0%
Final simplification54.0%
herbie shell --seed 2024115
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))