
(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}
(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%
(FPCore (x y) :precision binary64 (if (<= y -21.0) (* y (- x)) (if (<= y 3.35e-18) (+ y x) (- y (* y x)))))
double code(double x, double y) {
double tmp;
if (y <= -21.0) {
tmp = y * -x;
} else if (y <= 3.35e-18) {
tmp = y + x;
} else {
tmp = y - (y * x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-21.0d0)) then
tmp = y * -x
else if (y <= 3.35d-18) then
tmp = y + x
else
tmp = y - (y * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -21.0) {
tmp = y * -x;
} else if (y <= 3.35e-18) {
tmp = y + x;
} else {
tmp = y - (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -21.0: tmp = y * -x elif y <= 3.35e-18: tmp = y + x else: tmp = y - (y * x) return tmp
function code(x, y) tmp = 0.0 if (y <= -21.0) tmp = Float64(y * Float64(-x)); elseif (y <= 3.35e-18) tmp = Float64(y + x); else tmp = Float64(y - Float64(y * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -21.0) tmp = y * -x; elseif (y <= 3.35e-18) tmp = y + x; else tmp = y - (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -21.0], N[(y * (-x)), $MachinePrecision], If[LessEqual[y, 3.35e-18], N[(y + x), $MachinePrecision], N[(y - N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -21:\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{elif}\;y \leq 3.35 \cdot 10^{-18}:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;y - y \cdot x\\
\end{array}
\end{array}
if y < -21Initial 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 99.1%
neg-mul-199.1%
sub-neg99.1%
Simplified99.1%
Taylor expanded in x around inf 44.9%
mul-1-neg44.9%
*-commutative44.9%
distribute-rgt-neg-in44.9%
Simplified44.9%
if -21 < y < 3.3499999999999999e-18Initial 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 99.9%
if 3.3499999999999999e-18 < y 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 98.4%
neg-mul-198.4%
sub-neg98.4%
Simplified98.4%
Taylor expanded in x around 0 98.4%
mul-1-neg98.4%
*-commutative98.4%
sub-neg98.4%
Simplified98.4%
(FPCore (x y) :precision binary64 (if (<= y -21.0) (* y (- x)) (if (<= y 3.35e-18) (+ y x) (* y (- 1.0 x)))))
double code(double x, double y) {
double tmp;
if (y <= -21.0) {
tmp = y * -x;
} else if (y <= 3.35e-18) {
tmp = 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 (y <= (-21.0d0)) then
tmp = y * -x
else if (y <= 3.35d-18) then
tmp = 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 (y <= -21.0) {
tmp = y * -x;
} else if (y <= 3.35e-18) {
tmp = y + x;
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -21.0: tmp = y * -x elif y <= 3.35e-18: tmp = y + x else: tmp = y * (1.0 - x) return tmp
function code(x, y) tmp = 0.0 if (y <= -21.0) tmp = Float64(y * Float64(-x)); elseif (y <= 3.35e-18) tmp = 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 (y <= -21.0) tmp = y * -x; elseif (y <= 3.35e-18) tmp = y + x; else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -21.0], N[(y * (-x)), $MachinePrecision], If[LessEqual[y, 3.35e-18], N[(y + x), $MachinePrecision], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -21:\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{elif}\;y \leq 3.35 \cdot 10^{-18}:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if y < -21Initial 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 99.1%
neg-mul-199.1%
sub-neg99.1%
Simplified99.1%
Taylor expanded in x around inf 44.9%
mul-1-neg44.9%
*-commutative44.9%
distribute-rgt-neg-in44.9%
Simplified44.9%
if -21 < y < 3.3499999999999999e-18Initial 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 99.9%
if 3.3499999999999999e-18 < y 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 98.4%
neg-mul-198.4%
sub-neg98.4%
Simplified98.4%
(FPCore (x y) :precision binary64 (if (<= x 850.0) (+ y x) (* y (- x))))
double code(double x, double y) {
double tmp;
if (x <= 850.0) {
tmp = y + x;
} else {
tmp = y * -x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 850.0d0) then
tmp = y + x
else
tmp = y * -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 850.0) {
tmp = y + x;
} else {
tmp = y * -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 850.0: tmp = y + x else: tmp = y * -x return tmp
function code(x, y) tmp = 0.0 if (x <= 850.0) tmp = Float64(y + x); else tmp = Float64(y * Float64(-x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 850.0) tmp = y + x; else tmp = y * -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 850.0], N[(y + x), $MachinePrecision], N[(y * (-x)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 850:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\end{array}
\end{array}
if x < 850Initial 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 82.7%
if 850 < 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 48.7%
neg-mul-148.7%
sub-neg48.7%
Simplified48.7%
Taylor expanded in x around inf 46.8%
mul-1-neg46.8%
*-commutative46.8%
distribute-rgt-neg-in46.8%
Simplified46.8%
(FPCore (x y) :precision binary64 (if (<= x -1.6e-67) x y))
double code(double x, double y) {
double tmp;
if (x <= -1.6e-67) {
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 <= (-1.6d-67)) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.6e-67) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.6e-67: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (x <= -1.6e-67) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.6e-67) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.6e-67], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{-67}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.60000000000000011e-67Initial 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 58.3%
Taylor expanded in y around 0 49.2%
if -1.60000000000000011e-67 < 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 50.4%
(FPCore (x y) :precision binary64 (+ y x))
double code(double x, double y) {
return y + x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y + x
end function
public static double code(double x, double y) {
return y + x;
}
def code(x, y): return y + x
function code(x, y) return Float64(y + x) end
function tmp = code(x, y) tmp = y + x; end
code[x_, y_] := N[(y + x), $MachinePrecision]
\begin{array}{l}
\\
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 75.6%
(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 75.6%
Taylor expanded in y around 0 39.7%
herbie shell --seed 2024132
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))