
(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 5 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 (* y (- x))) (- x (* x (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((x * (1.0 - (y * z))) <= -((double) INFINITY)) {
tmp = z * (y * -x);
} 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 * (y * -x);
} 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 * (y * -x) 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(y * Float64(-x))); 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 * (y * -x); 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[(y * (-x)), $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(y \cdot \left(-x\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 74.0%
Taylor expanded in y around inf 74.0%
mul-1-neg74.0%
associate-*r*100.0%
Simplified100.0%
if -inf.0 < (*.f64 x (-.f64 1 (*.f64 y z))) Initial program 98.2%
sub-neg98.2%
distribute-rgt-in98.2%
*-un-lft-identity98.2%
distribute-rgt-neg-in98.2%
Applied egg-rr98.2%
associate-*l*91.5%
distribute-lft-neg-in91.5%
*-commutative91.5%
distribute-rgt-neg-out91.5%
distribute-lft-neg-in91.5%
add-sqr-sqrt51.5%
sqrt-unprod60.5%
sqr-neg60.5%
sqrt-unprod29.3%
add-sqr-sqrt50.9%
*-commutative50.9%
distribute-lft-neg-in50.9%
cancel-sign-sub-inv50.9%
associate-*l*54.4%
*-commutative54.4%
associate-*r*53.7%
*-commutative53.7%
associate-*r*50.9%
distribute-rgt-neg-in50.9%
add-sqr-sqrt29.3%
sqrt-unprod60.5%
sqr-neg60.5%
Applied egg-rr91.5%
Taylor expanded in y around 0 98.2%
Final simplification98.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (* y (- x)))))
(if (<= (* y z) (- INFINITY))
t_0
(if (<= (* y z) -4e+15)
(* x (* y (- z)))
(if (<= (* y z) 5e-10) x t_0)))))
double code(double x, double y, double z) {
double t_0 = z * (y * -x);
double tmp;
if ((y * z) <= -((double) INFINITY)) {
tmp = t_0;
} else if ((y * z) <= -4e+15) {
tmp = x * (y * -z);
} else if ((y * z) <= 5e-10) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
public static double code(double x, double y, double z) {
double t_0 = z * (y * -x);
double tmp;
if ((y * z) <= -Double.POSITIVE_INFINITY) {
tmp = t_0;
} else if ((y * z) <= -4e+15) {
tmp = x * (y * -z);
} else if ((y * z) <= 5e-10) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * (y * -x) tmp = 0 if (y * z) <= -math.inf: tmp = t_0 elif (y * z) <= -4e+15: tmp = x * (y * -z) elif (y * z) <= 5e-10: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(y * Float64(-x))) tmp = 0.0 if (Float64(y * z) <= Float64(-Inf)) tmp = t_0; elseif (Float64(y * z) <= -4e+15) tmp = Float64(x * Float64(y * Float64(-z))); elseif (Float64(y * z) <= 5e-10) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * (y * -x); tmp = 0.0; if ((y * z) <= -Inf) tmp = t_0; elseif ((y * z) <= -4e+15) tmp = x * (y * -z); elseif ((y * z) <= 5e-10) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(y * z), $MachinePrecision], (-Infinity)], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], -4e+15], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 5e-10], x, t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{if}\;y \cdot z \leq -\infty:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \cdot z \leq -4 \cdot 10^{+15}:\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{elif}\;y \cdot z \leq 5 \cdot 10^{-10}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0 or 5.00000000000000031e-10 < (*.f64 y z) Initial program 86.0%
Taylor expanded in y around inf 85.2%
mul-1-neg85.2%
associate-*r*94.3%
Simplified94.3%
if -inf.0 < (*.f64 y z) < -4e15Initial program 99.7%
Taylor expanded in y around inf 99.7%
mul-1-neg99.7%
distribute-rgt-neg-in99.7%
distribute-rgt-neg-out99.7%
Simplified99.7%
if -4e15 < (*.f64 y z) < 5.00000000000000031e-10Initial program 100.0%
Taylor expanded in y around 0 98.0%
Final simplification97.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- 1.0 (* y z))))) (if (<= t_0 (- INFINITY)) (* z (* y (- x))) 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 * (y * -x);
} 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 * (y * -x);
} 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 * (y * -x) 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(y * Float64(-x))); 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 * (y * -x); 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[(y * (-x)), $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(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (*.f64 x (-.f64 1 (*.f64 y z))) < -inf.0Initial program 74.0%
Taylor expanded in y around inf 74.0%
mul-1-neg74.0%
associate-*r*100.0%
Simplified100.0%
if -inf.0 < (*.f64 x (-.f64 1 (*.f64 y z))) Initial program 98.2%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (if (or (<= (* y z) -4e+15) (not (<= (* y z) 5e-10))) (* z (* y (- x))) x))
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -4e+15) || !((y * z) <= 5e-10)) {
tmp = z * (y * -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 * z) <= (-4d+15)) .or. (.not. ((y * z) <= 5d-10))) then
tmp = z * (y * -x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -4e+15) || !((y * z) <= 5e-10)) {
tmp = z * (y * -x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((y * z) <= -4e+15) or not ((y * z) <= 5e-10): tmp = z * (y * -x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -4e+15) || !(Float64(y * z) <= 5e-10)) tmp = Float64(z * Float64(y * Float64(-x))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((y * z) <= -4e+15) || ~(((y * z) <= 5e-10))) tmp = z * (y * -x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], -4e+15], N[Not[LessEqual[N[(y * z), $MachinePrecision], 5e-10]], $MachinePrecision]], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -4 \cdot 10^{+15} \lor \neg \left(y \cdot z \leq 5 \cdot 10^{-10}\right):\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -4e15 or 5.00000000000000031e-10 < (*.f64 y z) Initial program 90.7%
Taylor expanded in y around inf 90.2%
mul-1-neg90.2%
associate-*r*92.4%
Simplified92.4%
if -4e15 < (*.f64 y z) < 5.00000000000000031e-10Initial program 100.0%
Taylor expanded in y around 0 98.0%
Final simplification95.1%
(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.2%
Taylor expanded in y around 0 48.8%
Final simplification48.8%
herbie shell --seed 2023320
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))