
(FPCore (x y) :precision binary64 (- (+ x y) (* x y)))
double code(double x, double y) {
return (x + y) - (x * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) - (x * y)
end function
public static double code(double x, double y) {
return (x + y) - (x * y);
}
def code(x, y): return (x + y) - (x * y)
function code(x, y) return Float64(Float64(x + y) - Float64(x * y)) end
function tmp = code(x, y) tmp = (x + y) - (x * y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) - x \cdot y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- (+ x y) (* x y)))
double code(double x, double y) {
return (x + y) - (x * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) - (x * y)
end function
public static double code(double x, double y) {
return (x + y) - (x * y);
}
def code(x, y): return (x + y) - (x * y)
function code(x, y) return Float64(Float64(x + y) - Float64(x * y)) end
function tmp = code(x, y) tmp = (x + y) - (x * y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) - x \cdot y
\end{array}
(FPCore (x y) :precision binary64 (+ y (- x (* y x))))
double code(double x, double y) {
return y + (x - (y * x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y + (x - (y * x))
end function
public static double code(double x, double y) {
return y + (x - (y * x));
}
def code(x, y): return y + (x - (y * x))
function code(x, y) return Float64(y + Float64(x - Float64(y * x))) end
function tmp = code(x, y) tmp = y + (x - (y * x)); end
code[x_, y_] := N[(y + N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + \left(x - y \cdot x\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
associate--l+100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (* y (- x)))) (if (<= x -4e+228) t_0 (if (<= x -2.2e-91) x (if (<= x 1.0) y t_0)))))
double code(double x, double y) {
double t_0 = y * -x;
double tmp;
if (x <= -4e+228) {
tmp = t_0;
} else if (x <= -2.2e-91) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = y * -x
if (x <= (-4d+228)) then
tmp = t_0
else if (x <= (-2.2d-91)) then
tmp = x
else if (x <= 1.0d0) then
tmp = y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = y * -x;
double tmp;
if (x <= -4e+228) {
tmp = t_0;
} else if (x <= -2.2e-91) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = y * -x tmp = 0 if x <= -4e+228: tmp = t_0 elif x <= -2.2e-91: tmp = x elif x <= 1.0: tmp = y else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (x <= -4e+228) tmp = t_0; elseif (x <= -2.2e-91) tmp = x; elseif (x <= 1.0) tmp = y; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = y * -x; tmp = 0.0; if (x <= -4e+228) tmp = t_0; elseif (x <= -2.2e-91) tmp = x; elseif (x <= 1.0) tmp = y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[x, -4e+228], t$95$0, If[LessEqual[x, -2.2e-91], x, If[LessEqual[x, 1.0], y, t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;x \leq -4 \cdot 10^{+228}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -2.2 \cdot 10^{-91}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -3.9999999999999997e228 or 1 < x Initial program 100.0%
+-commutative100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in y around inf 54.7%
Taylor expanded in x around inf 54.0%
mul-1-neg54.0%
distribute-rgt-neg-out54.0%
Simplified54.0%
if -3.9999999999999997e228 < x < -2.2000000000000001e-91Initial program 99.9%
+-commutative99.9%
associate--l+100.0%
Simplified100.0%
Taylor expanded in y around 0 59.4%
if -2.2000000000000001e-91 < x < 1Initial program 100.0%
+-commutative100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in x around 0 78.2%
Final simplification67.0%
(FPCore (x y) :precision binary64 (if (or (<= y -0.029) (not (<= y 4.9e-197))) (* y (- 1.0 x)) x))
double code(double x, double y) {
double tmp;
if ((y <= -0.029) || !(y <= 4.9e-197)) {
tmp = y * (1.0 - x);
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-0.029d0)) .or. (.not. (y <= 4.9d-197))) then
tmp = y * (1.0d0 - x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -0.029) || !(y <= 4.9e-197)) {
tmp = y * (1.0 - x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -0.029) or not (y <= 4.9e-197): tmp = y * (1.0 - x) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -0.029) || !(y <= 4.9e-197)) tmp = Float64(y * Float64(1.0 - x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -0.029) || ~((y <= 4.9e-197))) tmp = y * (1.0 - x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -0.029], N[Not[LessEqual[y, 4.9e-197]], $MachinePrecision]], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.029 \lor \neg \left(y \leq 4.9 \cdot 10^{-197}\right):\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -0.0290000000000000015 or 4.9000000000000002e-197 < y Initial program 100.0%
+-commutative100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in y around inf 83.0%
if -0.0290000000000000015 < y < 4.9000000000000002e-197Initial program 100.0%
+-commutative100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in y around 0 74.3%
Final simplification80.0%
(FPCore (x y) :precision binary64 (if (<= x -2.1e-91) (- x (* y x)) (* y (- 1.0 x))))
double code(double x, double y) {
double tmp;
if (x <= -2.1e-91) {
tmp = x - (y * x);
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-2.1d-91)) then
tmp = x - (y * x)
else
tmp = y * (1.0d0 - x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -2.1e-91) {
tmp = x - (y * x);
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.1e-91: tmp = x - (y * x) else: tmp = y * (1.0 - x) return tmp
function code(x, y) tmp = 0.0 if (x <= -2.1e-91) tmp = Float64(x - Float64(y * x)); else tmp = Float64(y * Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.1e-91) tmp = x - (y * x); else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.1e-91], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \cdot 10^{-91}:\\
\;\;\;\;x - y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -2.0999999999999999e-91Initial program 100.0%
+-commutative100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in x around inf 89.9%
*-commutative89.9%
distribute-lft-out--89.9%
*-rgt-identity89.9%
Simplified89.9%
if -2.0999999999999999e-91 < x Initial program 100.0%
+-commutative100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in y around inf 70.4%
Final simplification76.0%
(FPCore (x y) :precision binary64 (if (<= x -2.8e-91) x y))
double code(double x, double y) {
double tmp;
if (x <= -2.8e-91) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-2.8d-91)) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -2.8e-91) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.8e-91: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (x <= -2.8e-91) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.8e-91) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.8e-91], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{-91}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -2.8e-91Initial program 100.0%
+-commutative100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in y around 0 52.3%
if -2.8e-91 < x Initial program 100.0%
+-commutative100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in x around 0 54.3%
Final simplification53.7%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
+-commutative100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in y around 0 37.6%
Final simplification37.6%
herbie shell --seed 2023221
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))