
(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 (if (<= (* y z) 2e+177) (* x (- 1.0 (* y z))) (* y (* x (- z)))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 2e+177) {
tmp = x * (1.0 - (y * z));
} else {
tmp = y * (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 ((y * z) <= 2d+177) then
tmp = x * (1.0d0 - (y * z))
else
tmp = y * (x * -z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= 2e+177) {
tmp = x * (1.0 - (y * z));
} else {
tmp = y * (x * -z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= 2e+177: tmp = x * (1.0 - (y * z)) else: tmp = y * (x * -z) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= 2e+177) tmp = Float64(x * Float64(1.0 - Float64(y * z))); else tmp = Float64(y * Float64(x * Float64(-z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * z) <= 2e+177) tmp = x * (1.0 - (y * z)); else tmp = y * (x * -z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], 2e+177], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq 2 \cdot 10^{+177}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < 2e177Initial program 98.2%
if 2e177 < (*.f64 y z) Initial program 71.6%
Taylor expanded in y around inf 99.9%
mul-1-neg99.9%
distribute-rgt-neg-in99.9%
distribute-lft-neg-out99.9%
*-commutative99.9%
Simplified99.9%
Final simplification98.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (* x (- z)))))
(if (<= (* y z) -2000000000.0)
t_0
(if (<= (* y z) 0.005)
x
(if (<= (* y z) 2e+177) (* (* y z) (- x)) t_0)))))
double code(double x, double y, double z) {
double t_0 = y * (x * -z);
double tmp;
if ((y * z) <= -2000000000.0) {
tmp = t_0;
} else if ((y * z) <= 0.005) {
tmp = x;
} else if ((y * z) <= 2e+177) {
tmp = (y * z) * -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 = y * (x * -z)
if ((y * z) <= (-2000000000.0d0)) then
tmp = t_0
else if ((y * z) <= 0.005d0) then
tmp = x
else if ((y * z) <= 2d+177) then
tmp = (y * z) * -x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (x * -z);
double tmp;
if ((y * z) <= -2000000000.0) {
tmp = t_0;
} else if ((y * z) <= 0.005) {
tmp = x;
} else if ((y * z) <= 2e+177) {
tmp = (y * z) * -x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x * -z) tmp = 0 if (y * z) <= -2000000000.0: tmp = t_0 elif (y * z) <= 0.005: tmp = x elif (y * z) <= 2e+177: tmp = (y * z) * -x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x * Float64(-z))) tmp = 0.0 if (Float64(y * z) <= -2000000000.0) tmp = t_0; elseif (Float64(y * z) <= 0.005) tmp = x; elseif (Float64(y * z) <= 2e+177) tmp = Float64(Float64(y * z) * Float64(-x)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x * -z); tmp = 0.0; if ((y * z) <= -2000000000.0) tmp = t_0; elseif ((y * z) <= 0.005) tmp = x; elseif ((y * z) <= 2e+177) tmp = (y * z) * -x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(y * z), $MachinePrecision], -2000000000.0], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], 0.005], x, If[LessEqual[N[(y * z), $MachinePrecision], 2e+177], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{if}\;y \cdot z \leq -2000000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \cdot z \leq 0.005:\\
\;\;\;\;x\\
\mathbf{elif}\;y \cdot z \leq 2 \cdot 10^{+177}:\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (*.f64 y z) < -2e9 or 2e177 < (*.f64 y z) Initial program 86.9%
Taylor expanded in y around inf 95.9%
mul-1-neg95.9%
distribute-rgt-neg-in95.9%
distribute-lft-neg-out95.9%
*-commutative95.9%
Simplified95.9%
if -2e9 < (*.f64 y z) < 0.0050000000000000001Initial program 100.0%
Taylor expanded in y around 0 98.5%
if 0.0050000000000000001 < (*.f64 y z) < 2e177Initial program 99.5%
Taylor expanded in y around inf 75.7%
mul-1-neg75.7%
associate-*r*93.3%
distribute-lft-neg-in93.3%
distribute-rgt-neg-out93.3%
*-commutative93.3%
Simplified93.3%
Final simplification97.0%
(FPCore (x y z) :precision binary64 (if (or (<= (* y z) -2000000000.0) (not (<= (* y z) 0.005))) (* (* y z) (- x)) x))
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -2000000000.0) || !((y * z) <= 0.005)) {
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 * z) <= (-2000000000.0d0)) .or. (.not. ((y * z) <= 0.005d0))) 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 * z) <= -2000000000.0) || !((y * z) <= 0.005)) {
tmp = (y * z) * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((y * z) <= -2000000000.0) or not ((y * z) <= 0.005): tmp = (y * z) * -x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -2000000000.0) || !(Float64(y * z) <= 0.005)) 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 * z) <= -2000000000.0) || ~(((y * z) <= 0.005))) tmp = (y * z) * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], -2000000000.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.005]], $MachinePrecision]], N[(N[(y * z), $MachinePrecision] * (-x)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -2000000000 \lor \neg \left(y \cdot z \leq 0.005\right):\\
\;\;\;\;\left(y \cdot z\right) \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -2e9 or 0.0050000000000000001 < (*.f64 y z) Initial program 90.2%
Taylor expanded in y around inf 90.7%
mul-1-neg90.7%
associate-*r*88.1%
distribute-lft-neg-in88.1%
distribute-rgt-neg-out88.1%
*-commutative88.1%
Simplified88.1%
if -2e9 < (*.f64 y z) < 0.0050000000000000001Initial program 100.0%
Taylor expanded in y around 0 98.5%
Final simplification93.7%
(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.4%
Taylor expanded in y around 0 54.4%
Final simplification54.4%
herbie shell --seed 2023257
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))