
(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}
(FPCore (x y z) :precision binary64 (if (<= (* y z) (- INFINITY)) (* z (* y (- x))) (* x (- 1.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -((double) INFINITY)) {
tmp = z * (y * -x);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -Double.POSITIVE_INFINITY) {
tmp = z * (y * -x);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -math.inf: tmp = z * (y * -x) else: tmp = x * (1.0 - (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= Float64(-Inf)) tmp = Float64(z * Float64(y * Float64(-x))); else tmp = Float64(x * Float64(1.0 - Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * z) <= -Inf) tmp = z * (y * -x); else tmp = x * (1.0 - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], (-Infinity)], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -\infty:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0Initial program 52.5%
Taylor expanded in z around inf 99.9%
Taylor expanded in y around inf 99.9%
neg-mul-199.9%
*-commutative99.9%
distribute-rgt-neg-in99.9%
Simplified99.9%
if -inf.0 < (*.f64 y z) Initial program 98.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.6e+130) (not (<= y 3e-101))) (* (* y z) (- x)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.6e+130) || !(y <= 3e-101)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
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.6d+130)) .or. (.not. (y <= 3d-101))) then
tmp = (y * z) * -x
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.6e+130) || !(y <= 3e-101)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.6e+130) or not (y <= 3e-101): tmp = (y * z) * -x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.6e+130) || !(y <= 3e-101)) tmp = Float64(Float64(y * z) * Float64(-x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.6e+130) || ~((y <= 3e-101))) tmp = (y * z) * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.6e+130], N[Not[LessEqual[y, 3e-101]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.6 \cdot 10^{+130} \lor \neg \left(y \leq 3 \cdot 10^{-101}\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.6000000000000001e130 or 3.0000000000000003e-101 < y Initial program 93.1%
Taylor expanded in y around inf 64.5%
mul-1-neg64.5%
distribute-rgt-neg-out64.5%
Simplified64.5%
if -3.6000000000000001e130 < y < 3.0000000000000003e-101Initial program 98.4%
Taylor expanded in y around 0 75.9%
Final simplification70.3%
(FPCore (x y z) :precision binary64 (if (<= y -3.45e+130) (* z (* y (- x))) (if (<= y 2.8e-101) x (* y (* z (- x))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.45e+130) {
tmp = z * (y * -x);
} else if (y <= 2.8e-101) {
tmp = x;
} else {
tmp = y * (z * -x);
}
return tmp;
}
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.45d+130)) then
tmp = z * (y * -x)
else if (y <= 2.8d-101) then
tmp = x
else
tmp = y * (z * -x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.45e+130) {
tmp = z * (y * -x);
} else if (y <= 2.8e-101) {
tmp = x;
} else {
tmp = y * (z * -x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.45e+130: tmp = z * (y * -x) elif y <= 2.8e-101: tmp = x else: tmp = y * (z * -x) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.45e+130) tmp = Float64(z * Float64(y * Float64(-x))); elseif (y <= 2.8e-101) tmp = x; else tmp = Float64(y * Float64(z * Float64(-x))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.45e+130) tmp = z * (y * -x); elseif (y <= 2.8e-101) tmp = x; else tmp = y * (z * -x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.45e+130], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.8e-101], x, N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.45 \cdot 10^{+130}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{-101}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\end{array}
\end{array}
if y < -3.4500000000000001e130Initial program 84.8%
Taylor expanded in z around inf 87.1%
Taylor expanded in y around inf 82.7%
neg-mul-182.7%
*-commutative82.7%
distribute-rgt-neg-in82.7%
Simplified82.7%
if -3.4500000000000001e130 < y < 2.79999999999999989e-101Initial program 98.4%
Taylor expanded in y around 0 75.9%
if 2.79999999999999989e-101 < y Initial program 96.6%
Taylor expanded in y around inf 58.9%
mul-1-neg58.9%
*-commutative58.9%
associate-*r*58.1%
distribute-rgt-neg-in58.1%
Simplified58.1%
Final simplification70.8%
(FPCore (x y z) :precision binary64 (if (<= y -3.45e+130) (* z (* y (- x))) (if (<= y 3e-101) x (* (* y z) (- x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.45e+130) {
tmp = z * (y * -x);
} else if (y <= 3e-101) {
tmp = x;
} else {
tmp = (y * z) * -x;
}
return tmp;
}
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.45d+130)) then
tmp = z * (y * -x)
else if (y <= 3d-101) then
tmp = x
else
tmp = (y * z) * -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.45e+130) {
tmp = z * (y * -x);
} else if (y <= 3e-101) {
tmp = x;
} else {
tmp = (y * z) * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.45e+130: tmp = z * (y * -x) elif y <= 3e-101: tmp = x else: tmp = (y * z) * -x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.45e+130) tmp = Float64(z * Float64(y * Float64(-x))); elseif (y <= 3e-101) tmp = x; else tmp = Float64(Float64(y * z) * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.45e+130) tmp = z * (y * -x); elseif (y <= 3e-101) tmp = x; else tmp = (y * z) * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.45e+130], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3e-101], x, N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.45 \cdot 10^{+130}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{elif}\;y \leq 3 \cdot 10^{-101}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\end{array}
\end{array}
if y < -3.4500000000000001e130Initial program 84.8%
Taylor expanded in z around inf 87.1%
Taylor expanded in y around inf 82.7%
neg-mul-182.7%
*-commutative82.7%
distribute-rgt-neg-in82.7%
Simplified82.7%
if -3.4500000000000001e130 < y < 3.0000000000000003e-101Initial program 98.4%
Taylor expanded in y around 0 75.9%
if 3.0000000000000003e-101 < y Initial program 96.6%
Taylor expanded in y around inf 58.9%
mul-1-neg58.9%
distribute-rgt-neg-out58.9%
Simplified58.9%
Final simplification71.1%
(FPCore (x y z) :precision binary64 (if (<= y -3.7e+131) (/ (* z x) z) x))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.7e+131) {
tmp = (z * x) / z;
} else {
tmp = x;
}
return tmp;
}
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.7d+131)) then
tmp = (z * x) / z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.7e+131) {
tmp = (z * x) / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.7e+131: tmp = (z * x) / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.7e+131) tmp = Float64(Float64(z * x) / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.7e+131) tmp = (z * x) / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.7e+131], N[(N[(z * x), $MachinePrecision] / z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.7 \cdot 10^{+131}:\\
\;\;\;\;\frac{z \cdot x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.69999999999999995e131Initial program 84.8%
Taylor expanded in z around inf 87.1%
Taylor expanded in y around 0 9.7%
associate-*r/9.7%
*-commutative9.7%
Applied egg-rr9.7%
if -3.69999999999999995e131 < y Initial program 97.7%
Taylor expanded in y around 0 61.2%
Final simplification53.6%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
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
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 95.8%
Taylor expanded in y around 0 53.6%
herbie shell --seed 2024180
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))