
(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 4 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 (* z (- 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 = y * (z * -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 = y * (z * -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 = y * (z * -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(y * Float64(z * 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 = y * (z * -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[(y * N[(z * (-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:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (*.f64 x (-.f64 1 (*.f64 y z))) < -inf.0Initial program 78.3%
flip--42.3%
associate-*r/42.3%
metadata-eval42.3%
pow242.3%
Applied egg-rr42.3%
associate-/l*42.3%
+-commutative42.3%
Simplified42.3%
Taylor expanded in y around inf 78.3%
mul-1-neg78.3%
*-commutative78.3%
associate-*l*99.9%
distribute-rgt-neg-in99.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 -5.2e-65) (not (<= z 1.9e+80))) (* x (* z (- y))) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.2e-65) || !(z <= 1.9e+80)) {
tmp = x * (z * -y);
} 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.2d-65)) .or. (.not. (z <= 1.9d+80))) then
tmp = x * (z * -y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -5.2e-65) || !(z <= 1.9e+80)) {
tmp = x * (z * -y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.2e-65) or not (z <= 1.9e+80): tmp = x * (z * -y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.2e-65) || !(z <= 1.9e+80)) tmp = Float64(x * Float64(z * Float64(-y))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5.2e-65) || ~((z <= 1.9e+80))) tmp = x * (z * -y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.2e-65], N[Not[LessEqual[z, 1.9e+80]], $MachinePrecision]], N[(x * N[(z * (-y)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.2 \cdot 10^{-65} \lor \neg \left(z \leq 1.9 \cdot 10^{+80}\right):\\
\;\;\;\;x \cdot \left(z \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.20000000000000019e-65 or 1.89999999999999999e80 < z Initial program 92.1%
Taylor expanded in y around inf 72.7%
mul-1-neg72.7%
distribute-rgt-neg-in72.7%
distribute-rgt-neg-out72.7%
Simplified72.7%
if -5.20000000000000019e-65 < z < 1.89999999999999999e80Initial program 99.9%
Taylor expanded in y around 0 79.1%
Final simplification76.4%
(FPCore (x y z) :precision binary64 (if (<= z -2.9e-69) (* y (* z (- x))) (if (<= z 1.7e+80) x (* x (* z (- y))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.9e-69) {
tmp = y * (z * -x);
} else if (z <= 1.7e+80) {
tmp = x;
} else {
tmp = x * (z * -y);
}
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 <= (-2.9d-69)) then
tmp = y * (z * -x)
else if (z <= 1.7d+80) then
tmp = x
else
tmp = x * (z * -y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.9e-69) {
tmp = y * (z * -x);
} else if (z <= 1.7e+80) {
tmp = x;
} else {
tmp = x * (z * -y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.9e-69: tmp = y * (z * -x) elif z <= 1.7e+80: tmp = x else: tmp = x * (z * -y) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.9e-69) tmp = Float64(y * Float64(z * Float64(-x))); elseif (z <= 1.7e+80) tmp = x; else tmp = Float64(x * Float64(z * Float64(-y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.9e-69) tmp = y * (z * -x); elseif (z <= 1.7e+80) tmp = x; else tmp = x * (z * -y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.9e-69], N[(y * N[(z * (-x)), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.7e+80], x, N[(x * N[(z * (-y)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.9 \cdot 10^{-69}:\\
\;\;\;\;y \cdot \left(z \cdot \left(-x\right)\right)\\
\mathbf{elif}\;z \leq 1.7 \cdot 10^{+80}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(z \cdot \left(-y\right)\right)\\
\end{array}
\end{array}
if z < -2.8999999999999998e-69Initial program 95.3%
flip--59.7%
associate-*r/55.5%
metadata-eval55.5%
pow255.5%
Applied egg-rr55.5%
associate-/l*59.6%
+-commutative59.6%
Simplified59.6%
Taylor expanded in y around inf 70.6%
mul-1-neg70.6%
*-commutative70.6%
associate-*l*68.8%
distribute-rgt-neg-in68.8%
Simplified68.8%
if -2.8999999999999998e-69 < z < 1.69999999999999996e80Initial program 99.9%
Taylor expanded in y around 0 79.1%
if 1.69999999999999996e80 < z Initial program 87.8%
Taylor expanded in y around inf 75.7%
mul-1-neg75.7%
distribute-rgt-neg-in75.7%
distribute-rgt-neg-out75.7%
Simplified75.7%
Final simplification75.9%
(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.1%
Final simplification54.1%
herbie shell --seed 2023271
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))