
(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 (fma (* (- y) x) z x)))
(if (<= (* y z) (- INFINITY))
t_0
(if (<= (* y z) 2e+142) (* (- 1.0 (* y z)) x) t_0))))
double code(double x, double y, double z) {
double t_0 = fma((-y * x), z, x);
double tmp;
if ((y * z) <= -((double) INFINITY)) {
tmp = t_0;
} else if ((y * z) <= 2e+142) {
tmp = (1.0 - (y * z)) * x;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(Float64(Float64(-y) * x), z, x) tmp = 0.0 if (Float64(y * z) <= Float64(-Inf)) tmp = t_0; elseif (Float64(y * z) <= 2e+142) tmp = Float64(Float64(1.0 - Float64(y * z)) * x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[((-y) * x), $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[N[(y * z), $MachinePrecision], (-Infinity)], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], 2e+142], N[(N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\left(-y\right) \cdot x, z, x\right)\\
\mathbf{if}\;y \cdot z \leq -\infty:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \cdot z \leq 2 \cdot 10^{+142}:\\
\;\;\;\;\left(1 - y \cdot z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 y z) < -inf.0 or 2.0000000000000001e142 < (*.f64 y z) Initial program 80.6%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6499.8
Applied rewrites99.8%
if -inf.0 < (*.f64 y z) < 2.0000000000000001e142Initial program 99.9%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (* (- y) z) x))) (if (<= (* y z) -2.0) t_0 (if (<= (* y z) 0.2) (* 1.0 x) t_0))))
double code(double x, double y, double z) {
double t_0 = (-y * z) * x;
double tmp;
if ((y * z) <= -2.0) {
tmp = t_0;
} else if ((y * z) <= 0.2) {
tmp = 1.0 * 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 * z) * x
if ((y * z) <= (-2.0d0)) then
tmp = t_0
else if ((y * z) <= 0.2d0) then
tmp = 1.0d0 * 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 * z) * x;
double tmp;
if ((y * z) <= -2.0) {
tmp = t_0;
} else if ((y * z) <= 0.2) {
tmp = 1.0 * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (-y * z) * x tmp = 0 if (y * z) <= -2.0: tmp = t_0 elif (y * z) <= 0.2: tmp = 1.0 * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(Float64(-y) * z) * x) tmp = 0.0 if (Float64(y * z) <= -2.0) tmp = t_0; elseif (Float64(y * z) <= 0.2) tmp = Float64(1.0 * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (-y * z) * x; tmp = 0.0; if ((y * z) <= -2.0) tmp = t_0; elseif ((y * z) <= 0.2) tmp = 1.0 * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[((-y) * z), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[N[(y * z), $MachinePrecision], -2.0], t$95$0, If[LessEqual[N[(y * z), $MachinePrecision], 0.2], N[(1.0 * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(-y\right) \cdot z\right) \cdot x\\
\mathbf{if}\;y \cdot z \leq -2:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \cdot z \leq 0.2:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 y z) < -2 or 0.20000000000000001 < (*.f64 y z) Initial program 90.5%
Taylor expanded in y around inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6486.0
Applied rewrites86.0%
if -2 < (*.f64 y z) < 0.20000000000000001Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites98.2%
Final simplification92.4%
(FPCore (x y z) :precision binary64 (if (<= x 1.9e+20) (fma (* (- z) x) y x) (* (- 1.0 (* y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= 1.9e+20) {
tmp = fma((-z * x), y, x);
} else {
tmp = (1.0 - (y * z)) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= 1.9e+20) tmp = fma(Float64(Float64(-z) * x), y, x); else tmp = Float64(Float64(1.0 - Float64(y * z)) * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, 1.9e+20], N[(N[((-z) * x), $MachinePrecision] * y + x), $MachinePrecision], N[(N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.9 \cdot 10^{+20}:\\
\;\;\;\;\mathsf{fma}\left(\left(-z\right) \cdot x, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - y \cdot z\right) \cdot x\\
\end{array}
\end{array}
if x < 1.9e20Initial program 94.2%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6493.7
Applied rewrites93.7%
if 1.9e20 < x Initial program 99.9%
Final simplification95.1%
(FPCore (x y z) :precision binary64 (* (- 1.0 (* y z)) x))
double code(double x, double y, double z) {
return (1.0 - (y * z)) * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (1.0d0 - (y * z)) * x
end function
public static double code(double x, double y, double z) {
return (1.0 - (y * z)) * x;
}
def code(x, y, z): return (1.0 - (y * z)) * x
function code(x, y, z) return Float64(Float64(1.0 - Float64(y * z)) * x) end
function tmp = code(x, y, z) tmp = (1.0 - (y * z)) * x; end
code[x_, y_, z_] := N[(N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - y \cdot z\right) \cdot x
\end{array}
Initial program 95.5%
Final simplification95.5%
(FPCore (x y z) :precision binary64 (* 1.0 x))
double code(double x, double y, double z) {
return 1.0 * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 * x
end function
public static double code(double x, double y, double z) {
return 1.0 * x;
}
def code(x, y, z): return 1.0 * x
function code(x, y, z) return Float64(1.0 * x) end
function tmp = code(x, y, z) tmp = 1.0 * x; end
code[x_, y_, z_] := N[(1.0 * x), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot x
\end{array}
Initial program 95.5%
Taylor expanded in y around 0
Applied rewrites53.4%
Final simplification53.4%
herbie shell --seed 2024308
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))