
(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 7 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 (fma x (- 1.0 y) y))
assert(x < y);
double code(double x, double y) {
return fma(x, (1.0 - y), y);
}
x, y = sort([x, y]) function code(x, y) return fma(x, Float64(1.0 - y), y) end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(x * N[(1.0 - y), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\mathsf{fma}\left(x, 1 - y, y\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
associate-+r-100.0%
*-commutative100.0%
+-commutative100.0%
*-lft-identity100.0%
metadata-eval100.0%
distribute-rgt-out--100.0%
fma-define100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.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 -61.0)
t_0
(if (<= y 7.5e+126)
(+ x y)
(if (or (<= y 2.95e+153) (not (<= y 4e+272))) t_0 y)))))assert(x < y);
double code(double x, double y) {
double t_0 = y * -x;
double tmp;
if (y <= -61.0) {
tmp = t_0;
} else if (y <= 7.5e+126) {
tmp = x + y;
} else if ((y <= 2.95e+153) || !(y <= 4e+272)) {
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 <= (-61.0d0)) then
tmp = t_0
else if (y <= 7.5d+126) then
tmp = x + y
else if ((y <= 2.95d+153) .or. (.not. (y <= 4d+272))) 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 <= -61.0) {
tmp = t_0;
} else if (y <= 7.5e+126) {
tmp = x + y;
} else if ((y <= 2.95e+153) || !(y <= 4e+272)) {
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 <= -61.0: tmp = t_0 elif y <= 7.5e+126: tmp = x + y elif (y <= 2.95e+153) or not (y <= 4e+272): 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 <= -61.0) tmp = t_0; elseif (y <= 7.5e+126) tmp = Float64(x + y); elseif ((y <= 2.95e+153) || !(y <= 4e+272)) 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 <= -61.0)
tmp = t_0;
elseif (y <= 7.5e+126)
tmp = x + y;
elseif ((y <= 2.95e+153) || ~((y <= 4e+272)))
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, -61.0], t$95$0, If[LessEqual[y, 7.5e+126], N[(x + y), $MachinePrecision], If[Or[LessEqual[y, 2.95e+153], N[Not[LessEqual[y, 4e+272]], $MachinePrecision]], 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 -61:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{+126}:\\
\;\;\;\;x + y\\
\mathbf{elif}\;y \leq 2.95 \cdot 10^{+153} \lor \neg \left(y \leq 4 \cdot 10^{+272}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -61 or 7.5000000000000006e126 < y < 2.9500000000000001e153 or 4.0000000000000003e272 < y Initial program 100.0%
+-commutative100.0%
associate-+r-100.0%
cancel-sign-sub-inv100.0%
*-commutative100.0%
cancel-sign-sub100.0%
remove-double-neg100.0%
neg-mul-1100.0%
distribute-rgt-out--100.0%
distribute-lft-out--100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
remove-double-neg100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
distribute-lft-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 97.2%
neg-mul-197.2%
sub-neg97.2%
Simplified97.2%
Taylor expanded in x around inf 59.0%
mul-1-neg59.0%
*-commutative59.0%
distribute-rgt-neg-in59.0%
Simplified59.0%
if -61 < y < 7.5000000000000006e126Initial program 100.0%
+-commutative100.0%
associate-+r-100.0%
cancel-sign-sub-inv100.0%
*-commutative100.0%
cancel-sign-sub100.0%
remove-double-neg100.0%
neg-mul-1100.0%
distribute-rgt-out--100.0%
distribute-lft-out--100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
remove-double-neg100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
distribute-lft-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 90.8%
if 2.9500000000000001e153 < y < 4.0000000000000003e272Initial program 100.0%
+-commutative100.0%
associate-+r-100.0%
cancel-sign-sub-inv100.0%
*-commutative100.0%
cancel-sign-sub100.0%
remove-double-neg100.0%
neg-mul-1100.0%
distribute-rgt-out--100.0%
distribute-lft-out--100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
remove-double-neg100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
distribute-lft-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 54.8%
Final simplification78.5%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 6.5e-7))) (* y (- 1.0 x)) (+ x y)))
assert(x < y);
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 6.5e-7)) {
tmp = y * (1.0 - x);
} else {
tmp = x + 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) :: tmp
if ((y <= (-1.0d0)) .or. (.not. (y <= 6.5d-7))) then
tmp = y * (1.0d0 - x)
else
tmp = x + y
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 6.5e-7)) {
tmp = y * (1.0 - x);
} else {
tmp = x + y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 6.5e-7): tmp = y * (1.0 - x) else: tmp = x + y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 6.5e-7)) tmp = Float64(y * Float64(1.0 - x)); else tmp = Float64(x + y); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if ((y <= -1.0) || ~((y <= 6.5e-7)))
tmp = y * (1.0 - x);
else
tmp = x + y;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 6.5e-7]], $MachinePrecision]], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 6.5 \cdot 10^{-7}\right):\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if y < -1 or 6.50000000000000024e-7 < y Initial program 100.0%
+-commutative100.0%
associate-+r-100.0%
cancel-sign-sub-inv100.0%
*-commutative100.0%
cancel-sign-sub100.0%
remove-double-neg100.0%
neg-mul-1100.0%
distribute-rgt-out--100.0%
distribute-lft-out--100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
remove-double-neg100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
distribute-lft-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 95.9%
neg-mul-195.9%
sub-neg95.9%
Simplified95.9%
if -1 < y < 6.50000000000000024e-7Initial program 100.0%
+-commutative100.0%
associate-+r-100.0%
cancel-sign-sub-inv100.0%
*-commutative100.0%
cancel-sign-sub100.0%
remove-double-neg100.0%
neg-mul-1100.0%
distribute-rgt-out--100.0%
distribute-lft-out--100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
remove-double-neg100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
distribute-lft-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 98.4%
Final simplification97.2%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y -1.0) (* y (- 1.0 x)) (if (<= y 6.5e-7) (+ x y) (- y (* x y)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = y * (1.0 - x);
} else if (y <= 6.5e-7) {
tmp = x + y;
} else {
tmp = y - (x * 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) :: tmp
if (y <= (-1.0d0)) then
tmp = y * (1.0d0 - x)
else if (y <= 6.5d-7) then
tmp = x + y
else
tmp = y - (x * y)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = y * (1.0 - x);
} else if (y <= 6.5e-7) {
tmp = x + y;
} else {
tmp = y - (x * y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= -1.0: tmp = y * (1.0 - x) elif y <= 6.5e-7: tmp = x + y else: tmp = y - (x * y) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(y * Float64(1.0 - x)); elseif (y <= 6.5e-7) tmp = Float64(x + y); else tmp = Float64(y - Float64(x * y)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (y <= -1.0)
tmp = y * (1.0 - x);
elseif (y <= 6.5e-7)
tmp = x + y;
else
tmp = y - (x * y);
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, -1.0], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6.5e-7], N[(x + y), $MachinePrecision], N[(y - N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{-7}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y - x \cdot y\\
\end{array}
\end{array}
if y < -1Initial program 100.0%
+-commutative100.0%
associate-+r-100.0%
cancel-sign-sub-inv100.0%
*-commutative100.0%
cancel-sign-sub100.0%
remove-double-neg100.0%
neg-mul-1100.0%
distribute-rgt-out--100.0%
distribute-lft-out--100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
remove-double-neg100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
distribute-lft-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 95.4%
neg-mul-195.4%
sub-neg95.4%
Simplified95.4%
if -1 < y < 6.50000000000000024e-7Initial program 100.0%
+-commutative100.0%
associate-+r-100.0%
cancel-sign-sub-inv100.0%
*-commutative100.0%
cancel-sign-sub100.0%
remove-double-neg100.0%
neg-mul-1100.0%
distribute-rgt-out--100.0%
distribute-lft-out--100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
remove-double-neg100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
distribute-lft-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 98.4%
if 6.50000000000000024e-7 < y Initial program 100.0%
+-commutative100.0%
associate-+r-100.0%
cancel-sign-sub-inv100.0%
*-commutative100.0%
cancel-sign-sub100.0%
remove-double-neg100.0%
neg-mul-1100.0%
distribute-rgt-out--100.0%
distribute-lft-out--100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
remove-double-neg100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
distribute-lft-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around inf 96.5%
neg-mul-196.5%
sub-neg96.5%
Simplified96.5%
Taylor expanded in x around 0 96.5%
mul-1-neg96.5%
*-commutative96.5%
sub-neg96.5%
Simplified96.5%
Final simplification97.2%
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%
+-commutative100.0%
associate-+r-100.0%
cancel-sign-sub-inv100.0%
*-commutative100.0%
cancel-sign-sub100.0%
remove-double-neg100.0%
neg-mul-1100.0%
distribute-rgt-out--100.0%
distribute-lft-out--100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
remove-double-neg100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
distribute-lft-out--100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (+ x y))
assert(x < y);
double code(double x, double y) {
return x + 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 = x + y
end function
assert x < y;
public static double code(double x, double y) {
return x + y;
}
[x, y] = sort([x, y]) def code(x, y): return x + y
x, y = sort([x, y]) function code(x, y) return Float64(x + y) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = x + y;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(x + y), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
x + y
\end{array}
Initial program 100.0%
+-commutative100.0%
associate-+r-100.0%
cancel-sign-sub-inv100.0%
*-commutative100.0%
cancel-sign-sub100.0%
remove-double-neg100.0%
neg-mul-1100.0%
distribute-rgt-out--100.0%
distribute-lft-out--100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
remove-double-neg100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
distribute-lft-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 73.0%
Final simplification73.0%
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%
+-commutative100.0%
associate-+r-100.0%
cancel-sign-sub-inv100.0%
*-commutative100.0%
cancel-sign-sub100.0%
remove-double-neg100.0%
neg-mul-1100.0%
distribute-rgt-out--100.0%
distribute-lft-out--100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-out100.0%
remove-double-neg100.0%
distribute-lft-neg-in100.0%
distribute-rgt-neg-in100.0%
distribute-lft-out--100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 33.7%
Final simplification33.7%
herbie shell --seed 2024034
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))