
(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 7 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) -5e+118) (* z (* y (- x))) (- x (* (* y z) x))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+118) {
tmp = z * (y * -x);
} else {
tmp = x - ((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 * z) <= (-5d+118)) then
tmp = z * (y * -x)
else
tmp = x - ((y * z) * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+118) {
tmp = z * (y * -x);
} else {
tmp = x - ((y * z) * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -5e+118: tmp = z * (y * -x) else: tmp = x - ((y * z) * x) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -5e+118) tmp = Float64(z * Float64(y * Float64(-x))); else tmp = Float64(x - Float64(Float64(y * z) * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * z) <= -5e+118) tmp = z * (y * -x); else tmp = x - ((y * z) * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -5e+118], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(y * z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+118}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x - \left(y \cdot z\right) \cdot x\\
\end{array}
\end{array}
if (*.f64 y z) < -4.99999999999999972e118Initial program 84.1%
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 -4.99999999999999972e118 < (*.f64 y z) Initial program 98.1%
sub-neg98.1%
distribute-rgt-in98.2%
*-un-lft-identity98.2%
distribute-rgt-neg-in98.2%
Applied egg-rr98.2%
associate-*l*92.5%
add-sqr-sqrt45.0%
sqrt-unprod63.1%
sqr-neg63.1%
sqrt-unprod23.5%
add-sqr-sqrt52.4%
cancel-sign-sub-inv52.4%
associate-*l*55.1%
*-commutative55.1%
*-commutative55.1%
distribute-lft-neg-out55.1%
distribute-rgt-neg-out55.1%
associate-*l*52.4%
add-sqr-sqrt23.5%
sqrt-unprod63.1%
sqr-neg63.1%
sqrt-unprod45.0%
add-sqr-sqrt92.5%
associate-*l*98.2%
*-commutative98.2%
Applied egg-rr98.2%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.6e+39) (not (<= y 2.65e-120))) (* (* y z) (- x)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.6e+39) || !(y <= 2.65e-120)) {
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 <= (-1.6d+39)) .or. (.not. (y <= 2.65d-120))) 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 <= -1.6e+39) || !(y <= 2.65e-120)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.6e+39) or not (y <= 2.65e-120): tmp = (y * z) * -x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.6e+39) || !(y <= 2.65e-120)) 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 <= -1.6e+39) || ~((y <= 2.65e-120))) tmp = (y * z) * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.6e+39], N[Not[LessEqual[y, 2.65e-120]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{+39} \lor \neg \left(y \leq 2.65 \cdot 10^{-120}\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.59999999999999996e39 or 2.64999999999999999e-120 < y Initial program 93.0%
Taylor expanded in y around inf 65.9%
mul-1-neg65.9%
distribute-rgt-neg-out65.9%
Simplified65.9%
if -1.59999999999999996e39 < y < 2.64999999999999999e-120Initial program 99.9%
Taylor expanded in y around 0 74.7%
Final simplification69.5%
(FPCore (x y z) :precision binary64 (if (<= y -1.5e+39) (* (* z x) (- y)) (if (<= y 2.65e-120) x (* (* y z) (- x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.5e+39) {
tmp = (z * x) * -y;
} else if (y <= 2.65e-120) {
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 <= (-1.5d+39)) then
tmp = (z * x) * -y
else if (y <= 2.65d-120) 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 <= -1.5e+39) {
tmp = (z * x) * -y;
} else if (y <= 2.65e-120) {
tmp = x;
} else {
tmp = (y * z) * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.5e+39: tmp = (z * x) * -y elif y <= 2.65e-120: tmp = x else: tmp = (y * z) * -x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.5e+39) tmp = Float64(Float64(z * x) * Float64(-y)); elseif (y <= 2.65e-120) 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 <= -1.5e+39) tmp = (z * x) * -y; elseif (y <= 2.65e-120) tmp = x; else tmp = (y * z) * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.5e+39], N[(N[(z * x), $MachinePrecision] * (-y)), $MachinePrecision], If[LessEqual[y, 2.65e-120], x, N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{+39}:\\
\;\;\;\;\left(z \cdot x\right) \cdot \left(-y\right)\\
\mathbf{elif}\;y \leq 2.65 \cdot 10^{-120}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\end{array}
\end{array}
if y < -1.5e39Initial program 84.9%
Taylor expanded in y around inf 74.0%
mul-1-neg74.0%
*-commutative74.0%
associate-*r*87.1%
distribute-rgt-neg-in87.1%
Simplified87.1%
if -1.5e39 < y < 2.64999999999999999e-120Initial program 99.9%
Taylor expanded in y around 0 74.7%
if 2.64999999999999999e-120 < y Initial program 99.9%
Taylor expanded in y around inf 59.0%
mul-1-neg59.0%
distribute-rgt-neg-out59.0%
Simplified59.0%
Final simplification73.1%
(FPCore (x y z) :precision binary64 (if (<= y -7.6e+37) (* z (* y (- x))) (if (<= y 2.65e-120) x (* (* y z) (- x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7.6e+37) {
tmp = z * (y * -x);
} else if (y <= 2.65e-120) {
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 <= (-7.6d+37)) then
tmp = z * (y * -x)
else if (y <= 2.65d-120) 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 <= -7.6e+37) {
tmp = z * (y * -x);
} else if (y <= 2.65e-120) {
tmp = x;
} else {
tmp = (y * z) * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7.6e+37: tmp = z * (y * -x) elif y <= 2.65e-120: tmp = x else: tmp = (y * z) * -x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7.6e+37) tmp = Float64(z * Float64(y * Float64(-x))); elseif (y <= 2.65e-120) 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 <= -7.6e+37) tmp = z * (y * -x); elseif (y <= 2.65e-120) tmp = x; else tmp = (y * z) * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7.6e+37], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.65e-120], x, N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.6 \cdot 10^{+37}:\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{elif}\;y \leq 2.65 \cdot 10^{-120}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\end{array}
\end{array}
if y < -7.59999999999999979e37Initial program 84.9%
Taylor expanded in z around inf 90.3%
Taylor expanded in y around inf 82.2%
neg-mul-182.2%
*-commutative82.2%
distribute-rgt-neg-in82.2%
Simplified82.2%
if -7.59999999999999979e37 < y < 2.64999999999999999e-120Initial program 99.9%
Taylor expanded in y around 0 74.7%
if 2.64999999999999999e-120 < y Initial program 99.9%
Taylor expanded in y around inf 59.0%
mul-1-neg59.0%
distribute-rgt-neg-out59.0%
Simplified59.0%
Final simplification71.8%
(FPCore (x y z) :precision binary64 (if (<= (* y z) -5e+118) (* z (* y (- x))) (* x (- 1.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+118) {
tmp = z * (y * -x);
} else {
tmp = x * (1.0 - (y * z));
}
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 * z) <= (-5d+118)) then
tmp = z * (y * -x)
else
tmp = x * (1.0d0 - (y * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -5e+118) {
tmp = z * (y * -x);
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -5e+118: 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) <= -5e+118) 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) <= -5e+118) 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], -5e+118], 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 -5 \cdot 10^{+118}:\\
\;\;\;\;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) < -4.99999999999999972e118Initial program 84.1%
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 -4.99999999999999972e118 < (*.f64 y z) Initial program 98.1%
(FPCore (x y z) :precision binary64 (if (<= z 1.8e+234) x (/ (* z x) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.8e+234) {
tmp = x;
} else {
tmp = (z * x) / z;
}
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 (z <= 1.8d+234) then
tmp = x
else
tmp = (z * x) / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 1.8e+234) {
tmp = x;
} else {
tmp = (z * x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.8e+234: tmp = x else: tmp = (z * x) / z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.8e+234) tmp = x; else tmp = Float64(Float64(z * x) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.8e+234) tmp = x; else tmp = (z * x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.8e+234], x, N[(N[(z * x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.8 \cdot 10^{+234}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{z \cdot x}{z}\\
\end{array}
\end{array}
if z < 1.8e234Initial program 96.7%
Taylor expanded in y around 0 50.3%
if 1.8e234 < z Initial program 82.0%
Taylor expanded in z around inf 93.6%
Taylor expanded in y around 0 2.5%
associate-*r/23.0%
*-commutative23.0%
Applied egg-rr23.0%
Final simplification48.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 47.5%
herbie shell --seed 2024170
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))