
(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}
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (+ y (* x (- 1.0 y))))
assert(x < y);
double code(double x, double y) {
return y + (x * (1.0 - y));
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y + (x * (1.0d0 - y))
end function
assert x < y;
public static double code(double x, double y) {
return y + (x * (1.0 - y));
}
[x, y] = sort([x, y]) def code(x, y): return y + (x * (1.0 - y))
x, y = sort([x, y]) function code(x, y) return Float64(y + Float64(x * Float64(1.0 - y))) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = y + (x * (1.0 - y));
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(y + N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
y + x \cdot \left(1 - y\right)
\end{array}
Initial program 100.0%
associate--l+100.0%
+-commutative100.0%
remove-double-neg100.0%
unsub-neg100.0%
cancel-sign-sub-inv100.0%
associate--l+100.0%
neg-mul-1100.0%
cancel-sign-sub-inv100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-out100.0%
*-commutative100.0%
distribute-rgt-out100.0%
+-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= y -1.1e+16)
t_0
(if (<= y 7.2e+19) (+ y x) (if (<= y 1.15e+41) t_0 y)))))assert(x < y);
double code(double x, double y) {
double t_0 = y * -x;
double tmp;
if (y <= -1.1e+16) {
tmp = t_0;
} else if (y <= 7.2e+19) {
tmp = y + x;
} else if (y <= 1.15e+41) {
tmp = t_0;
} else {
tmp = y;
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
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 (y <= (-1.1d+16)) then
tmp = t_0
else if (y <= 7.2d+19) then
tmp = y + x
else if (y <= 1.15d+41) then
tmp = t_0
else
tmp = y
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double t_0 = y * -x;
double tmp;
if (y <= -1.1e+16) {
tmp = t_0;
} else if (y <= 7.2e+19) {
tmp = y + x;
} else if (y <= 1.15e+41) {
tmp = t_0;
} else {
tmp = y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): t_0 = y * -x tmp = 0 if y <= -1.1e+16: tmp = t_0 elif y <= 7.2e+19: tmp = y + x elif y <= 1.15e+41: tmp = t_0 else: tmp = y return tmp
x, y = sort([x, y]) function code(x, y) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (y <= -1.1e+16) tmp = t_0; elseif (y <= 7.2e+19) tmp = Float64(y + x); elseif (y <= 1.15e+41) tmp = t_0; else tmp = y; end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
t_0 = y * -x;
tmp = 0.0;
if (y <= -1.1e+16)
tmp = t_0;
elseif (y <= 7.2e+19)
tmp = y + x;
elseif (y <= 1.15e+41)
tmp = t_0;
else
tmp = y;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[y, -1.1e+16], t$95$0, If[LessEqual[y, 7.2e+19], N[(y + x), $MachinePrecision], If[LessEqual[y, 1.15e+41], t$95$0, y]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -1.1 \cdot 10^{+16}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 7.2 \cdot 10^{+19}:\\
\;\;\;\;y + x\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{+41}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1.1e16 or 7.2e19 < y < 1.1499999999999999e41Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 54.6%
mul-1-neg54.6%
distribute-rgt-neg-in54.6%
Simplified54.6%
if -1.1e16 < y < 7.2e19Initial program 100.0%
associate--l+100.0%
+-commutative100.0%
remove-double-neg100.0%
unsub-neg100.0%
cancel-sign-sub-inv100.0%
associate--l+100.0%
neg-mul-1100.0%
cancel-sign-sub-inv100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-out100.0%
*-commutative100.0%
distribute-rgt-out100.0%
+-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 97.3%
if 1.1499999999999999e41 < y Initial program 100.0%
Taylor expanded in x around 0 53.3%
Final simplification75.7%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y -540000000000.0) (* y (- x)) (if (<= y 0.45) (+ y x) (- y (* y x)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= -540000000000.0) {
tmp = y * -x;
} else if (y <= 0.45) {
tmp = y + x;
} else {
tmp = y - (y * x);
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-540000000000.0d0)) then
tmp = y * -x
else if (y <= 0.45d0) then
tmp = y + x
else
tmp = y - (y * x)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (y <= -540000000000.0) {
tmp = y * -x;
} else if (y <= 0.45) {
tmp = y + x;
} else {
tmp = y - (y * x);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= -540000000000.0: tmp = y * -x elif y <= 0.45: tmp = y + x else: tmp = y - (y * x) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= -540000000000.0) tmp = Float64(y * Float64(-x)); elseif (y <= 0.45) tmp = Float64(y + x); else tmp = Float64(y - Float64(y * x)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (y <= -540000000000.0)
tmp = y * -x;
elseif (y <= 0.45)
tmp = y + x;
else
tmp = y - (y * x);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[y, -540000000000.0], N[(y * (-x)), $MachinePrecision], If[LessEqual[y, 0.45], N[(y + x), $MachinePrecision], N[(y - N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -540000000000:\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{elif}\;y \leq 0.45:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;y - y \cdot x\\
\end{array}
\end{array}
if y < -5.4e11Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 54.1%
mul-1-neg54.1%
distribute-rgt-neg-in54.1%
Simplified54.1%
if -5.4e11 < y < 0.450000000000000011Initial program 100.0%
associate--l+100.0%
+-commutative100.0%
remove-double-neg100.0%
unsub-neg100.0%
cancel-sign-sub-inv100.0%
associate--l+100.0%
neg-mul-1100.0%
cancel-sign-sub-inv100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-out100.0%
*-commutative100.0%
distribute-rgt-out100.0%
+-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 98.0%
if 0.450000000000000011 < y Initial program 100.0%
Taylor expanded in y around inf 99.4%
Taylor expanded in x around 0 99.4%
mul-1-neg99.4%
*-commutative99.4%
sub-neg99.4%
Simplified99.4%
Final simplification87.2%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y -2050000000000.0) (* y (- x)) (if (<= y 0.45) (+ y x) (* y (- 1.0 x)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= -2050000000000.0) {
tmp = y * -x;
} else if (y <= 0.45) {
tmp = y + x;
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-2050000000000.0d0)) then
tmp = y * -x
else if (y <= 0.45d0) then
tmp = y + x
else
tmp = y * (1.0d0 - x)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (y <= -2050000000000.0) {
tmp = y * -x;
} else if (y <= 0.45) {
tmp = y + x;
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= -2050000000000.0: tmp = y * -x elif y <= 0.45: tmp = y + x else: tmp = y * (1.0 - x) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= -2050000000000.0) tmp = Float64(y * Float64(-x)); elseif (y <= 0.45) tmp = Float64(y + x); else tmp = Float64(y * Float64(1.0 - x)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (y <= -2050000000000.0)
tmp = y * -x;
elseif (y <= 0.45)
tmp = y + x;
else
tmp = y * (1.0 - x);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[y, -2050000000000.0], N[(y * (-x)), $MachinePrecision], If[LessEqual[y, 0.45], N[(y + x), $MachinePrecision], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2050000000000:\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{elif}\;y \leq 0.45:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if y < -2.05e12Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 54.1%
mul-1-neg54.1%
distribute-rgt-neg-in54.1%
Simplified54.1%
if -2.05e12 < y < 0.450000000000000011Initial program 100.0%
associate--l+100.0%
+-commutative100.0%
remove-double-neg100.0%
unsub-neg100.0%
cancel-sign-sub-inv100.0%
associate--l+100.0%
neg-mul-1100.0%
cancel-sign-sub-inv100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-out100.0%
*-commutative100.0%
distribute-rgt-out100.0%
+-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 98.0%
if 0.450000000000000011 < y Initial program 100.0%
Taylor expanded in y around inf 99.4%
Final simplification87.2%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (+ y x))
assert(x < y);
double code(double x, double y) {
return y + x;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y + x
end function
assert x < y;
public static double code(double x, double y) {
return y + x;
}
[x, y] = sort([x, y]) def code(x, y): return y + x
x, y = sort([x, y]) function code(x, y) return Float64(y + x) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = y + x;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(y + x), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
y + x
\end{array}
Initial program 100.0%
associate--l+100.0%
+-commutative100.0%
remove-double-neg100.0%
unsub-neg100.0%
cancel-sign-sub-inv100.0%
associate--l+100.0%
neg-mul-1100.0%
cancel-sign-sub-inv100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-out100.0%
*-commutative100.0%
distribute-rgt-out100.0%
+-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 74.4%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 y)
assert(x < y);
double code(double x, double y) {
return y;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y
end function
assert x < y;
public static double code(double x, double y) {
return y;
}
[x, y] = sort([x, y]) def code(x, y): return y
x, y = sort([x, y]) function code(x, y) return y end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = y;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := y
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 39.7%
herbie shell --seed 2024091
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))