
(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 (let* ((t_0 (* x (- 1.0 (* y z))))) (if (<= t_0 (- INFINITY)) (* (- y) (* x z)) 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 = -y * (x * z);
} 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 = -y * (x * z);
} 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 = -y * (x * z) 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(Float64(-y) * Float64(x * z)); 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 = -y * (x * z); 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[((-y) * N[(x * z), $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:\\
\;\;\;\;\left(-y\right) \cdot \left(x \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (*.f64 x (-.f64 1 (*.f64 y z))) < -inf.0Initial program 76.9%
Taylor expanded in y around inf 76.9%
mul-1-neg76.9%
*-commutative76.9%
associate-*r*99.9%
distribute-rgt-neg-out99.9%
*-commutative99.9%
Simplified99.9%
if -inf.0 < (*.f64 x (-.f64 1 (*.f64 y z))) Initial program 98.6%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.4e-59) (not (<= z 2.7e+70))) (* x (* y (- z))) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.4e-59) || !(z <= 2.7e+70)) {
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 <= (-1.4d-59)) .or. (.not. (z <= 2.7d+70))) 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 <= -1.4e-59) || !(z <= 2.7e+70)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.4e-59) or not (z <= 2.7e+70): tmp = x * (y * -z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.4e-59) || !(z <= 2.7e+70)) 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 <= -1.4e-59) || ~((z <= 2.7e+70))) tmp = x * (y * -z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.4e-59], N[Not[LessEqual[z, 2.7e+70]], $MachinePrecision]], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.4 \cdot 10^{-59} \lor \neg \left(z \leq 2.7 \cdot 10^{+70}\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.3999999999999999e-59 or 2.7e70 < z Initial program 93.1%
Taylor expanded in y around inf 66.9%
mul-1-neg66.9%
distribute-rgt-neg-out66.9%
distribute-rgt-neg-in66.9%
Simplified66.9%
if -1.3999999999999999e-59 < z < 2.7e70Initial program 99.9%
Taylor expanded in y around 0 72.5%
Final simplification69.8%
(FPCore (x y z) :precision binary64 (if (<= z -1.28e-49) (* (- y) (* x z)) (if (<= z 2.9e+72) x (* x (* y (- z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.28e-49) {
tmp = -y * (x * z);
} else if (z <= 2.9e+72) {
tmp = x;
} else {
tmp = x * (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 (z <= (-1.28d-49)) then
tmp = -y * (x * z)
else if (z <= 2.9d+72) then
tmp = x
else
tmp = x * (y * -z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.28e-49) {
tmp = -y * (x * z);
} else if (z <= 2.9e+72) {
tmp = x;
} else {
tmp = x * (y * -z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.28e-49: tmp = -y * (x * z) elif z <= 2.9e+72: tmp = x else: tmp = x * (y * -z) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.28e-49) tmp = Float64(Float64(-y) * Float64(x * z)); elseif (z <= 2.9e+72) tmp = x; else tmp = Float64(x * Float64(y * Float64(-z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.28e-49) tmp = -y * (x * z); elseif (z <= 2.9e+72) tmp = x; else tmp = x * (y * -z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.28e-49], N[((-y) * N[(x * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.9e+72], x, N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.28 \cdot 10^{-49}:\\
\;\;\;\;\left(-y\right) \cdot \left(x \cdot z\right)\\
\mathbf{elif}\;z \leq 2.9 \cdot 10^{+72}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\end{array}
\end{array}
if z < -1.28e-49Initial program 92.5%
Taylor expanded in y around inf 61.6%
mul-1-neg61.6%
*-commutative61.6%
associate-*r*67.8%
distribute-rgt-neg-out67.8%
*-commutative67.8%
Simplified67.8%
if -1.28e-49 < z < 2.90000000000000017e72Initial program 99.9%
Taylor expanded in y around 0 72.5%
if 2.90000000000000017e72 < z Initial program 94.1%
Taylor expanded in y around inf 75.4%
mul-1-neg75.4%
distribute-rgt-neg-out75.4%
distribute-rgt-neg-in75.4%
Simplified75.4%
Final simplification71.6%
(FPCore (x y z) :precision binary64 (if (<= z -3e-58) (* z (- (* x y))) (if (<= z 3.5e+67) x (* x (* y (- z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3e-58) {
tmp = z * -(x * y);
} else if (z <= 3.5e+67) {
tmp = x;
} else {
tmp = x * (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 (z <= (-3d-58)) then
tmp = z * -(x * y)
else if (z <= 3.5d+67) then
tmp = x
else
tmp = x * (y * -z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -3e-58) {
tmp = z * -(x * y);
} else if (z <= 3.5e+67) {
tmp = x;
} else {
tmp = x * (y * -z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3e-58: tmp = z * -(x * y) elif z <= 3.5e+67: tmp = x else: tmp = x * (y * -z) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3e-58) tmp = Float64(z * Float64(-Float64(x * y))); elseif (z <= 3.5e+67) tmp = x; else tmp = Float64(x * Float64(y * Float64(-z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3e-58) tmp = z * -(x * y); elseif (z <= 3.5e+67) tmp = x; else tmp = x * (y * -z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3e-58], N[(z * (-N[(x * y), $MachinePrecision])), $MachinePrecision], If[LessEqual[z, 3.5e+67], x, N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3 \cdot 10^{-58}:\\
\;\;\;\;z \cdot \left(-x \cdot y\right)\\
\mathbf{elif}\;z \leq 3.5 \cdot 10^{+67}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\end{array}
\end{array}
if z < -3.00000000000000008e-58Initial program 92.5%
flip--54.0%
clear-num53.9%
un-div-inv54.0%
clear-num53.9%
flip--92.4%
Applied egg-rr92.4%
Taylor expanded in y around inf 61.6%
div-inv61.6%
frac-2neg61.6%
metadata-eval61.6%
remove-double-div61.6%
distribute-lft-neg-in61.6%
associate-*r*67.7%
Applied egg-rr67.7%
if -3.00000000000000008e-58 < z < 3.5e67Initial program 99.9%
Taylor expanded in y around 0 73.0%
if 3.5e67 < z Initial program 94.2%
Taylor expanded in y around inf 75.9%
mul-1-neg75.9%
distribute-rgt-neg-out75.9%
distribute-rgt-neg-in75.9%
Simplified75.9%
Final simplification72.0%
(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 50.7%
Final simplification50.7%
herbie shell --seed 2023297
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))