
(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 1e+305) t_0 (* y (* x (- z))))))
double code(double x, double y, double z) {
double t_0 = x * (1.0 - (y * z));
double tmp;
if (t_0 <= 1e+305) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = x * (1.0d0 - (y * z))
if (t_0 <= 1d+305) then
tmp = t_0
else
tmp = y * (x * -z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (1.0 - (y * z));
double tmp;
if (t_0 <= 1e+305) {
tmp = t_0;
} else {
tmp = y * (x * -z);
}
return tmp;
}
def code(x, y, z): t_0 = x * (1.0 - (y * z)) tmp = 0 if t_0 <= 1e+305: tmp = t_0 else: tmp = y * (x * -z) return tmp
function code(x, y, z) t_0 = Float64(x * Float64(1.0 - Float64(y * z))) tmp = 0.0 if (t_0 <= 1e+305) tmp = t_0; else tmp = Float64(y * Float64(x * Float64(-z))); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (1.0 - (y * z)); tmp = 0.0; if (t_0 <= 1e+305) tmp = t_0; else tmp = y * (x * -z); 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, 1e+305], t$95$0, N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - y \cdot z\right)\\
\mathbf{if}\;t_0 \leq 10^{+305}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\end{array}
\end{array}
if (*.f64 x (-.f64 1 (*.f64 y z))) < 9.9999999999999994e304Initial program 99.9%
if 9.9999999999999994e304 < (*.f64 x (-.f64 1 (*.f64 y z))) Initial program 79.9%
Taylor expanded in y around inf 100.0%
mul-1-neg100.0%
distribute-rgt-neg-in100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
Simplified100.0%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= (* y z) -20000.0) (not (<= (* y z) 4e-6))) (* x (* y (- z))) x))
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -20000.0) || !((y * z) <= 4e-6)) {
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 (((y * z) <= (-20000.0d0)) .or. (.not. ((y * z) <= 4d-6))) 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 (((y * z) <= -20000.0) || !((y * z) <= 4e-6)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((y * z) <= -20000.0) or not ((y * z) <= 4e-6): tmp = x * (y * -z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -20000.0) || !(Float64(y * z) <= 4e-6)) 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 (((y * z) <= -20000.0) || ~(((y * z) <= 4e-6))) tmp = x * (y * -z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], -20000.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 4e-6]], $MachinePrecision]], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -20000 \lor \neg \left(y \cdot z \leq 4 \cdot 10^{-6}\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -2e4 or 3.99999999999999982e-6 < (*.f64 y z) Initial program 94.1%
Taylor expanded in y around inf 91.8%
mul-1-neg91.8%
associate-*r*92.3%
distribute-lft-neg-in92.3%
distribute-rgt-neg-out92.3%
*-commutative92.3%
Simplified92.3%
if -2e4 < (*.f64 y z) < 3.99999999999999982e-6Initial program 100.0%
Taylor expanded in y around 0 98.5%
Final simplification95.7%
(FPCore (x y z) :precision binary64 (if (<= (* y z) -20000000.0) (* y (* x (- z))) (if (<= (* y z) 4e-6) x (* x (* y (- z))))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -20000000.0) {
tmp = y * (x * -z);
} else if ((y * z) <= 4e-6) {
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 ((y * z) <= (-20000000.0d0)) then
tmp = y * (x * -z)
else if ((y * z) <= 4d-6) 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 ((y * z) <= -20000000.0) {
tmp = y * (x * -z);
} else if ((y * z) <= 4e-6) {
tmp = x;
} else {
tmp = x * (y * -z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -20000000.0: tmp = y * (x * -z) elif (y * z) <= 4e-6: tmp = x else: tmp = x * (y * -z) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -20000000.0) tmp = Float64(y * Float64(x * Float64(-z))); elseif (Float64(y * z) <= 4e-6) 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 ((y * z) <= -20000000.0) tmp = y * (x * -z); elseif ((y * z) <= 4e-6) tmp = x; else tmp = x * (y * -z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -20000000.0], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 4e-6], x, N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -20000000:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{elif}\;y \cdot z \leq 4 \cdot 10^{-6}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -2e7Initial program 92.9%
Taylor expanded in y around inf 95.0%
mul-1-neg95.0%
distribute-rgt-neg-in95.0%
distribute-lft-neg-out95.0%
*-commutative95.0%
Simplified95.0%
if -2e7 < (*.f64 y z) < 3.99999999999999982e-6Initial program 100.0%
Taylor expanded in y around 0 97.9%
if 3.99999999999999982e-6 < (*.f64 y z) Initial program 95.1%
Taylor expanded in y around inf 90.3%
mul-1-neg90.3%
associate-*r*93.3%
distribute-lft-neg-in93.3%
distribute-rgt-neg-out93.3%
*-commutative93.3%
Simplified93.3%
Final simplification96.2%
(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 97.3%
Taylor expanded in y around 0 55.1%
Final simplification55.1%
herbie shell --seed 2023185
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))