
(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 8 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%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (* x (- y)) (if (<= y 8.5e-51) x (* y (- 1.0 x)))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * -y;
} else if (y <= 8.5e-51) {
tmp = 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 <= (-1.0d0)) then
tmp = x * -y
else if (y <= 8.5d-51) then
tmp = 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 <= -1.0) {
tmp = x * -y;
} else if (y <= 8.5e-51) {
tmp = x;
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = x * -y elif y <= 8.5e-51: tmp = x else: tmp = y * (1.0 - x) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(x * Float64(-y)); elseif (y <= 8.5e-51) tmp = x; else tmp = Float64(y * Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = x * -y; elseif (y <= 8.5e-51) tmp = x; else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], N[(x * (-y)), $MachinePrecision], If[LessEqual[y, 8.5e-51], x, N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{-51}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if y < -1Initial program 100.0%
Taylor expanded in y around inf 96.7%
Taylor expanded in x around inf 55.8%
associate-*r*55.8%
neg-mul-155.8%
*-commutative55.8%
Simplified55.8%
if -1 < y < 8.50000000000000036e-51Initial program 100.0%
Taylor expanded in x around inf 84.5%
Taylor expanded in y around 0 84.2%
if 8.50000000000000036e-51 < y Initial program 100.0%
Taylor expanded in y around inf 92.8%
Final simplification80.7%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (* x (- y)) (if (<= y 3.6e-50) x y)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * -y;
} else if (y <= 3.6e-50) {
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.0d0)) then
tmp = x * -y
else if (y <= 3.6d-50) 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.0) {
tmp = x * -y;
} else if (y <= 3.6e-50) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = x * -y elif y <= 3.6e-50: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(x * Float64(-y)); elseif (y <= 3.6e-50) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = x * -y; elseif (y <= 3.6e-50) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], N[(x * (-y)), $MachinePrecision], If[LessEqual[y, 3.6e-50], x, y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{-50}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1Initial program 100.0%
Taylor expanded in y around inf 96.7%
Taylor expanded in x around inf 55.8%
associate-*r*55.8%
neg-mul-155.8%
*-commutative55.8%
Simplified55.8%
if -1 < y < 3.59999999999999979e-50Initial program 100.0%
Taylor expanded in x around inf 84.5%
Taylor expanded in y around 0 84.2%
if 3.59999999999999979e-50 < y Initial program 100.0%
Taylor expanded in y around inf 92.8%
Taylor expanded in x around 0 48.4%
Final simplification68.0%
(FPCore (x y) :precision binary64 (if (<= y 8.8e-54) (- x (* x y)) (- y (* x y))))
double code(double x, double y) {
double tmp;
if (y <= 8.8e-54) {
tmp = x - (x * 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 <= 8.8d-54) then
tmp = x - (x * y)
else
tmp = y - (x * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 8.8e-54) {
tmp = x - (x * y);
} else {
tmp = y - (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 8.8e-54: tmp = x - (x * y) else: tmp = y - (x * y) return tmp
function code(x, y) tmp = 0.0 if (y <= 8.8e-54) tmp = Float64(x - Float64(x * y)); else tmp = Float64(y - Float64(x * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 8.8e-54) tmp = x - (x * y); else tmp = y - (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 8.8e-54], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], N[(y - N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.8 \cdot 10^{-54}:\\
\;\;\;\;x - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x \cdot y\\
\end{array}
\end{array}
if y < 8.7999999999999998e-54Initial program 100.0%
Taylor expanded in x around inf 77.0%
if 8.7999999999999998e-54 < y Initial program 100.0%
Taylor expanded in x around 0 92.8%
(FPCore (x y) :precision binary64 (if (<= y 5.5e-50) (- x (* x y)) (* y (- 1.0 x))))
double code(double x, double y) {
double tmp;
if (y <= 5.5e-50) {
tmp = x - (x * 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 <= 5.5d-50) then
tmp = x - (x * 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 <= 5.5e-50) {
tmp = x - (x * y);
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 5.5e-50: tmp = x - (x * y) else: tmp = y * (1.0 - x) return tmp
function code(x, y) tmp = 0.0 if (y <= 5.5e-50) tmp = Float64(x - Float64(x * y)); else tmp = Float64(y * Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 5.5e-50) tmp = x - (x * y); else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 5.5e-50], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5.5 \cdot 10^{-50}:\\
\;\;\;\;x - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if y < 5.49999999999999975e-50Initial program 100.0%
Taylor expanded in x around inf 77.0%
if 5.49999999999999975e-50 < y Initial program 100.0%
Taylor expanded in y around inf 92.8%
(FPCore (x y) :precision binary64 (if (<= y 4.3e-50) x y))
double code(double x, double y) {
double tmp;
if (y <= 4.3e-50) {
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 <= 4.3d-50) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 4.3e-50) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 4.3e-50: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= 4.3e-50) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 4.3e-50) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 4.3e-50], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.3 \cdot 10^{-50}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 4.29999999999999997e-50Initial program 100.0%
Taylor expanded in x around inf 77.0%
Taylor expanded in y around 0 60.9%
if 4.29999999999999997e-50 < y Initial program 100.0%
Taylor expanded in y around inf 92.8%
Taylor expanded in x around 0 48.4%
(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 x around inf 70.2%
Taylor expanded in y around 0 45.8%
(FPCore (x y) :precision binary64 0.0)
double code(double x, double y) {
return 0.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.0d0
end function
public static double code(double x, double y) {
return 0.0;
}
def code(x, y): return 0.0
function code(x, y) return 0.0 end
function tmp = code(x, y) tmp = 0.0; end
code[x_, y_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 100.0%
Taylor expanded in y around inf 56.6%
Taylor expanded in x around inf 26.9%
associate-*r*26.9%
neg-mul-126.9%
*-commutative26.9%
Simplified26.9%
add-log-exp15.2%
add-sqr-sqrt15.2%
sqrt-unprod15.1%
exp-prod15.1%
add-sqr-sqrt6.6%
sqrt-unprod6.9%
sqr-neg6.9%
sqrt-unprod1.8%
add-sqr-sqrt2.0%
pow-flip2.0%
exp-prod1.6%
rgt-mult-inverse2.6%
metadata-eval2.6%
metadata-eval2.6%
Applied egg-rr2.6%
herbie shell --seed 2024137
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))