
(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 (<= (* x (- 1.0 (* y z))) (- INFINITY)) (* z (* x (- y))) (- x (* x (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((x * (1.0 - (y * z))) <= -((double) INFINITY)) {
tmp = z * (x * -y);
} else {
tmp = x - (x * (y * z));
}
return tmp;
}
public static double code(double x, double y, double z) {
double tmp;
if ((x * (1.0 - (y * z))) <= -Double.POSITIVE_INFINITY) {
tmp = z * (x * -y);
} else {
tmp = x - (x * (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x * (1.0 - (y * z))) <= -math.inf: tmp = z * (x * -y) else: tmp = x - (x * (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x * Float64(1.0 - Float64(y * z))) <= Float64(-Inf)) tmp = Float64(z * Float64(x * Float64(-y))); else tmp = Float64(x - Float64(x * Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x * (1.0 - (y * z))) <= -Inf) tmp = z * (x * -y); else tmp = x - (x * (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-Infinity)], N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], N[(x - N[(x * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot \left(1 - y \cdot z\right) \leq -\infty:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot \left(y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 x (-.f64 1 (*.f64 y z))) < -inf.0Initial program 79.9%
Taylor expanded in y around 0 79.9%
mul-1-neg79.9%
unsub-neg79.9%
Simplified79.9%
Taylor expanded in y around inf 79.9%
associate-*r*100.0%
*-commutative100.0%
neg-mul-1100.0%
distribute-rgt-neg-in100.0%
distribute-rgt-neg-in100.0%
Simplified100.0%
if -inf.0 < (*.f64 x (-.f64 1 (*.f64 y z))) Initial program 99.0%
Taylor expanded in y around 0 99.1%
mul-1-neg99.1%
unsub-neg99.1%
Simplified99.1%
Final simplification99.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (* x (- y)))))
(if (<= z -2.8e-125)
t_0
(if (<= z 2.5e-5)
x
(if (<= z 4e+27)
(* (- y) (* x z))
(if (<= z 1.95e+46)
x
(if (<= z 1.8e+125)
(* x (* y (- z)))
(if (<= z 2.8e+127) x t_0))))))))
double code(double x, double y, double z) {
double t_0 = z * (x * -y);
double tmp;
if (z <= -2.8e-125) {
tmp = t_0;
} else if (z <= 2.5e-5) {
tmp = x;
} else if (z <= 4e+27) {
tmp = -y * (x * z);
} else if (z <= 1.95e+46) {
tmp = x;
} else if (z <= 1.8e+125) {
tmp = x * (y * -z);
} else if (z <= 2.8e+127) {
tmp = x;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = z * (x * -y)
if (z <= (-2.8d-125)) then
tmp = t_0
else if (z <= 2.5d-5) then
tmp = x
else if (z <= 4d+27) then
tmp = -y * (x * z)
else if (z <= 1.95d+46) then
tmp = x
else if (z <= 1.8d+125) then
tmp = x * (y * -z)
else if (z <= 2.8d+127) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * (x * -y);
double tmp;
if (z <= -2.8e-125) {
tmp = t_0;
} else if (z <= 2.5e-5) {
tmp = x;
} else if (z <= 4e+27) {
tmp = -y * (x * z);
} else if (z <= 1.95e+46) {
tmp = x;
} else if (z <= 1.8e+125) {
tmp = x * (y * -z);
} else if (z <= 2.8e+127) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * (x * -y) tmp = 0 if z <= -2.8e-125: tmp = t_0 elif z <= 2.5e-5: tmp = x elif z <= 4e+27: tmp = -y * (x * z) elif z <= 1.95e+46: tmp = x elif z <= 1.8e+125: tmp = x * (y * -z) elif z <= 2.8e+127: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(x * Float64(-y))) tmp = 0.0 if (z <= -2.8e-125) tmp = t_0; elseif (z <= 2.5e-5) tmp = x; elseif (z <= 4e+27) tmp = Float64(Float64(-y) * Float64(x * z)); elseif (z <= 1.95e+46) tmp = x; elseif (z <= 1.8e+125) tmp = Float64(x * Float64(y * Float64(-z))); elseif (z <= 2.8e+127) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * (x * -y); tmp = 0.0; if (z <= -2.8e-125) tmp = t_0; elseif (z <= 2.5e-5) tmp = x; elseif (z <= 4e+27) tmp = -y * (x * z); elseif (z <= 1.95e+46) tmp = x; elseif (z <= 1.8e+125) tmp = x * (y * -z); elseif (z <= 2.8e+127) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.8e-125], t$95$0, If[LessEqual[z, 2.5e-5], x, If[LessEqual[z, 4e+27], N[((-y) * N[(x * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.95e+46], x, If[LessEqual[z, 1.8e+125], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.8e+127], x, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{if}\;z \leq -2.8 \cdot 10^{-125}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 2.5 \cdot 10^{-5}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4 \cdot 10^{+27}:\\
\;\;\;\;\left(-y\right) \cdot \left(x \cdot z\right)\\
\mathbf{elif}\;z \leq 1.95 \cdot 10^{+46}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.8 \cdot 10^{+125}:\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{elif}\;z \leq 2.8 \cdot 10^{+127}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -2.8e-125 or 2.8000000000000002e127 < z Initial program 93.3%
Taylor expanded in y around 0 93.4%
mul-1-neg93.4%
unsub-neg93.4%
Simplified93.4%
Taylor expanded in y around inf 59.3%
associate-*r*63.6%
*-commutative63.6%
neg-mul-163.6%
distribute-rgt-neg-in63.6%
distribute-rgt-neg-in63.6%
Simplified63.6%
if -2.8e-125 < z < 2.50000000000000012e-5 or 4.0000000000000001e27 < z < 1.94999999999999997e46 or 1.8000000000000002e125 < z < 2.8000000000000002e127Initial program 99.9%
Taylor expanded in y around 0 79.8%
if 2.50000000000000012e-5 < z < 4.0000000000000001e27Initial program 99.5%
flip--70.4%
associate-*r/71.0%
metadata-eval71.0%
pow271.0%
Applied egg-rr71.0%
associate-/l*71.0%
+-commutative71.0%
Simplified71.0%
Taylor expanded in y around inf 76.7%
associate-/r/76.7%
associate-*r*48.2%
div-inv48.2%
metadata-eval48.2%
associate-*r*48.2%
neg-mul-148.2%
*-commutative48.2%
associate-*r*77.2%
neg-mul-177.2%
associate-*r*77.2%
Applied egg-rr77.2%
Taylor expanded in z around 0 76.7%
mul-1-neg76.7%
*-commutative76.7%
associate-*r*77.2%
distribute-rgt-neg-in77.2%
Simplified77.2%
if 1.94999999999999997e46 < z < 1.8000000000000002e125Initial program 99.9%
Taylor expanded in y around inf 56.0%
mul-1-neg56.0%
distribute-rgt-neg-in56.0%
distribute-rgt-neg-out56.0%
Simplified56.0%
Final simplification70.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- 1.0 (* y z))))) (if (<= t_0 (- INFINITY)) (* z (* x (- y))) t_0)))
double code(double x, double y, double z) {
double t_0 = x * (1.0 - (y * z));
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = z * (x * -y);
} else {
tmp = t_0;
}
return tmp;
}
public static double code(double x, double y, double z) {
double t_0 = x * (1.0 - (y * z));
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = z * (x * -y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (1.0 - (y * z)) tmp = 0 if t_0 <= -math.inf: tmp = z * (x * -y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(1.0 - Float64(y * z))) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = Float64(z * Float64(x * Float64(-y))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (1.0 - (y * z)); tmp = 0.0; if (t_0 <= -Inf) tmp = z * (x * -y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - y \cdot z\right)\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;z \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (*.f64 x (-.f64 1 (*.f64 y z))) < -inf.0Initial program 79.9%
Taylor expanded in y around 0 79.9%
mul-1-neg79.9%
unsub-neg79.9%
Simplified79.9%
Taylor expanded in y around inf 79.9%
associate-*r*100.0%
*-commutative100.0%
neg-mul-1100.0%
distribute-rgt-neg-in100.0%
distribute-rgt-neg-in100.0%
Simplified100.0%
if -inf.0 < (*.f64 x (-.f64 1 (*.f64 y z))) Initial program 99.0%
Final simplification99.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (* x (- y)))))
(if (<= z -2.8e-125)
t_0
(if (<= z 9e+45)
x
(if (<= z 3e+125) (* x (* y (- z))) (if (<= z 2.1e+127) x t_0))))))
double code(double x, double y, double z) {
double t_0 = z * (x * -y);
double tmp;
if (z <= -2.8e-125) {
tmp = t_0;
} else if (z <= 9e+45) {
tmp = x;
} else if (z <= 3e+125) {
tmp = x * (y * -z);
} else if (z <= 2.1e+127) {
tmp = x;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = z * (x * -y)
if (z <= (-2.8d-125)) then
tmp = t_0
else if (z <= 9d+45) then
tmp = x
else if (z <= 3d+125) then
tmp = x * (y * -z)
else if (z <= 2.1d+127) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * (x * -y);
double tmp;
if (z <= -2.8e-125) {
tmp = t_0;
} else if (z <= 9e+45) {
tmp = x;
} else if (z <= 3e+125) {
tmp = x * (y * -z);
} else if (z <= 2.1e+127) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * (x * -y) tmp = 0 if z <= -2.8e-125: tmp = t_0 elif z <= 9e+45: tmp = x elif z <= 3e+125: tmp = x * (y * -z) elif z <= 2.1e+127: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(x * Float64(-y))) tmp = 0.0 if (z <= -2.8e-125) tmp = t_0; elseif (z <= 9e+45) tmp = x; elseif (z <= 3e+125) tmp = Float64(x * Float64(y * Float64(-z))); elseif (z <= 2.1e+127) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * (x * -y); tmp = 0.0; if (z <= -2.8e-125) tmp = t_0; elseif (z <= 9e+45) tmp = x; elseif (z <= 3e+125) tmp = x * (y * -z); elseif (z <= 2.1e+127) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(x * (-y)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.8e-125], t$95$0, If[LessEqual[z, 9e+45], x, If[LessEqual[z, 3e+125], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.1e+127], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{if}\;z \leq -2.8 \cdot 10^{-125}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 9 \cdot 10^{+45}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3 \cdot 10^{+125}:\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{+127}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -2.8e-125 or 2.09999999999999992e127 < z Initial program 93.3%
Taylor expanded in y around 0 93.4%
mul-1-neg93.4%
unsub-neg93.4%
Simplified93.4%
Taylor expanded in y around inf 59.3%
associate-*r*63.6%
*-commutative63.6%
neg-mul-163.6%
distribute-rgt-neg-in63.6%
distribute-rgt-neg-in63.6%
Simplified63.6%
if -2.8e-125 < z < 8.9999999999999997e45 or 3.00000000000000015e125 < z < 2.09999999999999992e127Initial program 99.9%
Taylor expanded in y around 0 77.8%
if 8.9999999999999997e45 < z < 3.00000000000000015e125Initial program 99.9%
Taylor expanded in y around inf 56.0%
mul-1-neg56.0%
distribute-rgt-neg-in56.0%
distribute-rgt-neg-out56.0%
Simplified56.0%
Final simplification69.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.4e-188) (not (<= z 2.5e+46))) (* x (* y (- z))) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.4e-188) || !(z <= 2.5e+46)) {
tmp = x * (y * -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 ((z <= (-5.4d-188)) .or. (.not. (z <= 2.5d+46))) then
tmp = x * (y * -z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -5.4e-188) || !(z <= 2.5e+46)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.4e-188) or not (z <= 2.5e+46): tmp = x * (y * -z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.4e-188) || !(z <= 2.5e+46)) tmp = Float64(x * Float64(y * Float64(-z))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5.4e-188) || ~((z <= 2.5e+46))) tmp = x * (y * -z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.4e-188], N[Not[LessEqual[z, 2.5e+46]], $MachinePrecision]], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.4 \cdot 10^{-188} \lor \neg \left(z \leq 2.5 \cdot 10^{+46}\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.4000000000000002e-188 or 2.5000000000000001e46 < z Initial program 94.7%
Taylor expanded in y around inf 55.5%
mul-1-neg55.5%
distribute-rgt-neg-in55.5%
distribute-rgt-neg-out55.5%
Simplified55.5%
if -5.4000000000000002e-188 < z < 2.5000000000000001e46Initial program 99.9%
Taylor expanded in y around 0 78.5%
Final simplification63.8%
(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 96.6%
Taylor expanded in y around 0 54.4%
Final simplification54.4%
herbie shell --seed 2023293
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))