
(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 (- 1.0 y))))
double code(double x, double y) {
return y + (x * (1.0 - y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y + (x * (1.0d0 - y))
end function
public static double code(double x, double y) {
return y + (x * (1.0 - y));
}
def code(x, y): return y + (x * (1.0 - y))
function code(x, y) return Float64(y + Float64(x * Float64(1.0 - y))) end
function tmp = code(x, y) tmp = y + (x * (1.0 - y)); end
code[x_, y_] := N[(y + N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
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%
Final simplification100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (* y (- x)))) (if (<= x -5.5e+297) t_0 (if (<= x -7.5e-33) x (if (<= x 1.0) y t_0)))))
double code(double x, double y) {
double t_0 = y * -x;
double tmp;
if (x <= -5.5e+297) {
tmp = t_0;
} else if (x <= -7.5e-33) {
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 <= (-5.5d+297)) then
tmp = t_0
else if (x <= (-7.5d-33)) 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 <= -5.5e+297) {
tmp = t_0;
} else if (x <= -7.5e-33) {
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 <= -5.5e+297: tmp = t_0 elif x <= -7.5e-33: 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 <= -5.5e+297) tmp = t_0; elseif (x <= -7.5e-33) 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 <= -5.5e+297) tmp = t_0; elseif (x <= -7.5e-33) 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, -5.5e+297], t$95$0, If[LessEqual[x, -7.5e-33], 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 -5.5 \cdot 10^{+297}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -7.5 \cdot 10^{-33}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -5.50000000000000024e297 or 1 < x 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 inf 55.4%
mul-1-neg55.4%
unsub-neg55.4%
Simplified55.4%
Taylor expanded in x around inf 53.9%
mul-1-neg53.9%
distribute-rgt-neg-in53.9%
Simplified53.9%
if -5.50000000000000024e297 < x < -7.5000000000000001e-33Initial 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 68.3%
if -7.5000000000000001e-33 < x < 1Initial 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 x around 0 72.1%
Final simplification66.2%
(FPCore (x y) :precision binary64 (if (or (<= x -6.4e-130) (not (<= x 2e-11))) (* x (- 1.0 y)) y))
double code(double x, double y) {
double tmp;
if ((x <= -6.4e-130) || !(x <= 2e-11)) {
tmp = x * (1.0 - y);
} 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 <= (-6.4d-130)) .or. (.not. (x <= 2d-11))) then
tmp = x * (1.0d0 - y)
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -6.4e-130) || !(x <= 2e-11)) {
tmp = x * (1.0 - y);
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -6.4e-130) or not (x <= 2e-11): tmp = x * (1.0 - y) else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -6.4e-130) || !(x <= 2e-11)) tmp = Float64(x * Float64(1.0 - y)); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -6.4e-130) || ~((x <= 2e-11))) tmp = x * (1.0 - y); else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -6.4e-130], N[Not[LessEqual[x, 2e-11]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.4 \cdot 10^{-130} \lor \neg \left(x \leq 2 \cdot 10^{-11}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -6.3999999999999999e-130 or 1.99999999999999988e-11 < x 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 x around inf 91.6%
if -6.3999999999999999e-130 < x < 1.99999999999999988e-11Initial 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 x around 0 75.5%
Final simplification85.5%
(FPCore (x y) :precision binary64 (if (<= x -3.4e-129) (* x (- 1.0 y)) (* y (- 1.0 x))))
double code(double x, double y) {
double tmp;
if (x <= -3.4e-129) {
tmp = x * (1.0 - y);
} 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 <= (-3.4d-129)) then
tmp = x * (1.0d0 - y)
else
tmp = y * (1.0d0 - x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3.4e-129) {
tmp = x * (1.0 - y);
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.4e-129: tmp = x * (1.0 - y) else: tmp = y * (1.0 - x) return tmp
function code(x, y) tmp = 0.0 if (x <= -3.4e-129) tmp = Float64(x * Float64(1.0 - y)); else tmp = Float64(y * Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.4e-129) tmp = x * (1.0 - y); else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.4e-129], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \cdot 10^{-129}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -3.40000000000000013e-129Initial 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 x around inf 87.8%
if -3.40000000000000013e-129 < x 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 inf 65.8%
mul-1-neg65.8%
unsub-neg65.8%
Simplified65.8%
Final simplification73.7%
(FPCore (x y) :precision binary64 (if (<= x -3.3e-33) x y))
double code(double x, double y) {
double tmp;
if (x <= -3.3e-33) {
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 <= (-3.3d-33)) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3.3e-33) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.3e-33: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (x <= -3.3e-33) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.3e-33) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.3e-33], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.3 \cdot 10^{-33}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -3.3000000000000003e-33Initial 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 63.9%
if -3.3000000000000003e-33 < x 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 x around 0 47.5%
Final simplification52.3%
(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%
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 44.0%
Final simplification44.0%
herbie shell --seed 2024017
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))