
(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 (- (+ 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}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= y -1.0)
t_0
(if (<= y 3.6e-102)
x
(if (<= y 1.86e+208) y (if (<= y 2.5e+237) t_0 y))))))
double code(double x, double y) {
double t_0 = y * -x;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 3.6e-102) {
tmp = x;
} else if (y <= 1.86e+208) {
tmp = y;
} else if (y <= 2.5e+237) {
tmp = t_0;
} else {
tmp = y;
}
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 (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 3.6d-102) then
tmp = x
else if (y <= 1.86d+208) then
tmp = y
else if (y <= 2.5d+237) then
tmp = t_0
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = y * -x;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 3.6e-102) {
tmp = x;
} else if (y <= 1.86e+208) {
tmp = y;
} else if (y <= 2.5e+237) {
tmp = t_0;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): t_0 = y * -x tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 3.6e-102: tmp = x elif y <= 1.86e+208: tmp = y elif y <= 2.5e+237: tmp = t_0 else: tmp = y return tmp
function code(x, y) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 3.6e-102) tmp = x; elseif (y <= 1.86e+208) tmp = y; elseif (y <= 2.5e+237) tmp = t_0; else tmp = y; end return tmp end
function tmp_2 = code(x, y) t_0 = y * -x; tmp = 0.0; if (y <= -1.0) tmp = t_0; elseif (y <= 3.6e-102) tmp = x; elseif (y <= 1.86e+208) tmp = y; elseif (y <= 2.5e+237) tmp = t_0; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 3.6e-102], x, If[LessEqual[y, 1.86e+208], y, If[LessEqual[y, 2.5e+237], t$95$0, y]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{-102}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.86 \cdot 10^{+208}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 2.5 \cdot 10^{+237}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1 or 1.85999999999999993e208 < y < 2.5000000000000001e237Initial program 100.0%
Taylor expanded in x around inf 54.9%
Taylor expanded in y around inf 54.0%
mul-1-neg54.0%
distribute-lft-neg-out54.0%
*-commutative54.0%
Simplified54.0%
if -1 < y < 3.6e-102Initial program 100.0%
Taylor expanded in y around 0 81.9%
if 3.6e-102 < y < 1.85999999999999993e208 or 2.5000000000000001e237 < y Initial program 100.0%
Taylor expanded in x around 0 60.6%
Final simplification68.4%
(FPCore (x y) :precision binary64 (if (<= x -1.6e-85) (* x (- 1.0 y)) (if (<= x 1.0) y (* y (- x)))))
double code(double x, double y) {
double tmp;
if (x <= -1.6e-85) {
tmp = x * (1.0 - y);
} else if (x <= 1.0) {
tmp = y;
} 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 <= (-1.6d-85)) then
tmp = x * (1.0d0 - y)
else if (x <= 1.0d0) then
tmp = y
else
tmp = y * -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.6e-85) {
tmp = x * (1.0 - y);
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = y * -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.6e-85: tmp = x * (1.0 - y) elif x <= 1.0: tmp = y else: tmp = y * -x return tmp
function code(x, y) tmp = 0.0 if (x <= -1.6e-85) tmp = Float64(x * Float64(1.0 - y)); elseif (x <= 1.0) tmp = y; else tmp = Float64(y * Float64(-x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.6e-85) tmp = x * (1.0 - y); elseif (x <= 1.0) tmp = y; else tmp = y * -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.6e-85], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], y, N[(y * (-x)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{-85}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\end{array}
\end{array}
if x < -1.60000000000000014e-85Initial program 100.0%
Taylor expanded in x around inf 88.5%
if -1.60000000000000014e-85 < x < 1Initial program 100.0%
Taylor expanded in x around 0 79.5%
if 1 < x Initial program 100.0%
Taylor expanded in x around inf 99.5%
Taylor expanded in y around inf 46.4%
mul-1-neg46.4%
distribute-lft-neg-out46.4%
*-commutative46.4%
Simplified46.4%
Final simplification73.5%
(FPCore (x y) :precision binary64 (if (<= y 8.7e-103) (* x (- 1.0 y)) (* y (- 1.0 x))))
double code(double x, double y) {
double tmp;
if (y <= 8.7e-103) {
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 (y <= 8.7d-103) 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 (y <= 8.7e-103) {
tmp = x * (1.0 - y);
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 8.7e-103: tmp = x * (1.0 - y) else: tmp = y * (1.0 - x) return tmp
function code(x, y) tmp = 0.0 if (y <= 8.7e-103) 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 (y <= 8.7e-103) tmp = x * (1.0 - y); else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 8.7e-103], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.7 \cdot 10^{-103}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if y < 8.6999999999999996e-103Initial program 100.0%
Taylor expanded in x around inf 71.8%
if 8.6999999999999996e-103 < y Initial program 100.0%
Taylor expanded in y around inf 91.6%
Final simplification77.5%
(FPCore (x y) :precision binary64 (if (<= y 1.15e-102) (* x (- 1.0 y)) (- y (* x y))))
double code(double x, double y) {
double tmp;
if (y <= 1.15e-102) {
tmp = x * (1.0 - y);
} else {
tmp = y - (x * y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 1.15d-102) then
tmp = x * (1.0d0 - y)
else
tmp = y - (x * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.15e-102) {
tmp = x * (1.0 - y);
} else {
tmp = y - (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.15e-102: tmp = x * (1.0 - y) else: tmp = y - (x * y) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.15e-102) tmp = Float64(x * Float64(1.0 - y)); else tmp = Float64(y - Float64(x * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.15e-102) tmp = x * (1.0 - y); else tmp = y - (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.15e-102], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y - N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.15 \cdot 10^{-102}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y - x \cdot y\\
\end{array}
\end{array}
if y < 1.14999999999999993e-102Initial program 100.0%
Taylor expanded in x around inf 71.8%
if 1.14999999999999993e-102 < y Initial program 100.0%
Taylor expanded in y around inf 91.6%
sub-neg91.6%
distribute-rgt-in91.6%
*-un-lft-identity91.6%
Applied egg-rr91.6%
distribute-lft-neg-out91.6%
unsub-neg91.6%
*-commutative91.6%
Applied egg-rr91.6%
Final simplification77.5%
(FPCore (x y) :precision binary64 (if (<= y 1.15e-102) x y))
double code(double x, double y) {
double tmp;
if (y <= 1.15e-102) {
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 (y <= 1.15d-102) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.15e-102) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.15e-102: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= 1.15e-102) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.15e-102) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.15e-102], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.15 \cdot 10^{-102}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 1.14999999999999993e-102Initial program 100.0%
Taylor expanded in y around 0 53.6%
if 1.14999999999999993e-102 < y Initial program 100.0%
Taylor expanded in x around 0 58.3%
Final simplification54.9%
(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%
Taylor expanded in y around 0 40.6%
Final simplification40.6%
herbie shell --seed 2024082
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))