
(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}
\\
\frac{x - y}{x + 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}
\\
\frac{x - y}{x + y}
\end{array}
(FPCore (x y) :precision binary64 (- (/ x (+ x y)) (/ y (+ x y))))
double code(double x, double y) {
return (x / (x + y)) - (y / (x + y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x / (x + y)) - (y / (x + y))
end function
public static double code(double x, double y) {
return (x / (x + y)) - (y / (x + y));
}
def code(x, y): return (x / (x + y)) - (y / (x + y))
function code(x, y) return Float64(Float64(x / Float64(x + y)) - Float64(y / Float64(x + y))) end
function tmp = code(x, y) tmp = (x / (x + y)) - (y / (x + y)); end
code[x_, y_] := N[(N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision] - N[(y / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{x + y} - \frac{y}{x + y}
\end{array}
Initial program 100.0%
div-sub100.0%
Applied egg-rr100.0%
(FPCore (x y) :precision binary64 (if (or (<= y -1.05e-68) (not (<= y 3.2e-23))) (/ y (- (- y) x)) (/ x (+ x y))))
double code(double x, double y) {
double tmp;
if ((y <= -1.05e-68) || !(y <= 3.2e-23)) {
tmp = y / (-y - x);
} else {
tmp = x / (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.05d-68)) .or. (.not. (y <= 3.2d-23))) then
tmp = y / (-y - x)
else
tmp = x / (x + y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.05e-68) || !(y <= 3.2e-23)) {
tmp = y / (-y - x);
} else {
tmp = x / (x + y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.05e-68) or not (y <= 3.2e-23): tmp = y / (-y - x) else: tmp = x / (x + y) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.05e-68) || !(y <= 3.2e-23)) tmp = Float64(y / Float64(Float64(-y) - x)); else tmp = Float64(x / Float64(x + y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.05e-68) || ~((y <= 3.2e-23))) tmp = y / (-y - x); else tmp = x / (x + y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.05e-68], N[Not[LessEqual[y, 3.2e-23]], $MachinePrecision]], N[(y / N[((-y) - x), $MachinePrecision]), $MachinePrecision], N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.05 \cdot 10^{-68} \lor \neg \left(y \leq 3.2 \cdot 10^{-23}\right):\\
\;\;\;\;\frac{y}{\left(-y\right) - x}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x + y}\\
\end{array}
\end{array}
if y < -1.05000000000000004e-68 or 3.19999999999999976e-23 < y Initial program 100.0%
Taylor expanded in x around 0 75.1%
neg-mul-175.1%
Simplified75.1%
if -1.05000000000000004e-68 < y < 3.19999999999999976e-23Initial program 100.0%
Taylor expanded in y around inf 74.2%
Taylor expanded in y around 0 80.4%
Final simplification77.3%
(FPCore (x y) :precision binary64 (if (or (<= x -2.85e+25) (not (<= x 2.1e-29))) (/ x (+ x y)) (/ (- x y) y)))
double code(double x, double y) {
double tmp;
if ((x <= -2.85e+25) || !(x <= 2.1e-29)) {
tmp = x / (x + y);
} else {
tmp = (x - y) / y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-2.85d+25)) .or. (.not. (x <= 2.1d-29))) then
tmp = x / (x + y)
else
tmp = (x - y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -2.85e+25) || !(x <= 2.1e-29)) {
tmp = x / (x + y);
} else {
tmp = (x - y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.85e+25) or not (x <= 2.1e-29): tmp = x / (x + y) else: tmp = (x - y) / y return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.85e+25) || !(x <= 2.1e-29)) tmp = Float64(x / Float64(x + y)); else tmp = Float64(Float64(x - y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -2.85e+25) || ~((x <= 2.1e-29))) tmp = x / (x + y); else tmp = (x - y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.85e+25], N[Not[LessEqual[x, 2.1e-29]], $MachinePrecision]], N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.85 \cdot 10^{+25} \lor \neg \left(x \leq 2.1 \cdot 10^{-29}\right):\\
\;\;\;\;\frac{x}{x + y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x - y}{y}\\
\end{array}
\end{array}
if x < -2.8499999999999998e25 or 2.09999999999999989e-29 < x Initial program 100.0%
Taylor expanded in y around inf 78.5%
Taylor expanded in y around 0 75.1%
if -2.8499999999999998e25 < x < 2.09999999999999989e-29Initial program 100.0%
Taylor expanded in x around 0 79.2%
Final simplification77.1%
(FPCore (x y) :precision binary64 (if (or (<= x -4.5e+25) (not (<= x 1.5e-32))) (/ x (+ x y)) -1.0))
double code(double x, double y) {
double tmp;
if ((x <= -4.5e+25) || !(x <= 1.5e-32)) {
tmp = x / (x + y);
} else {
tmp = -1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-4.5d+25)) .or. (.not. (x <= 1.5d-32))) then
tmp = x / (x + y)
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -4.5e+25) || !(x <= 1.5e-32)) {
tmp = x / (x + y);
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -4.5e+25) or not (x <= 1.5e-32): tmp = x / (x + y) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -4.5e+25) || !(x <= 1.5e-32)) tmp = Float64(x / Float64(x + y)); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -4.5e+25) || ~((x <= 1.5e-32))) tmp = x / (x + y); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -4.5e+25], N[Not[LessEqual[x, 1.5e-32]], $MachinePrecision]], N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision], -1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{+25} \lor \neg \left(x \leq 1.5 \cdot 10^{-32}\right):\\
\;\;\;\;\frac{x}{x + y}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if x < -4.5000000000000003e25 or 1.5e-32 < x Initial program 100.0%
Taylor expanded in y around inf 78.5%
Taylor expanded in y around 0 75.1%
if -4.5000000000000003e25 < x < 1.5e-32Initial program 100.0%
Taylor expanded in x around 0 78.6%
Final simplification76.8%
(FPCore (x y) :precision binary64 (if (<= y -3.8e-65) -1.0 (if (<= y 5e-35) 1.0 -1.0)))
double code(double x, double y) {
double tmp;
if (y <= -3.8e-65) {
tmp = -1.0;
} else if (y <= 5e-35) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-3.8d-65)) then
tmp = -1.0d0
else if (y <= 5d-35) then
tmp = 1.0d0
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3.8e-65) {
tmp = -1.0;
} else if (y <= 5e-35) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.8e-65: tmp = -1.0 elif y <= 5e-35: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -3.8e-65) tmp = -1.0; elseif (y <= 5e-35) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.8e-65) tmp = -1.0; elseif (y <= 5e-35) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.8e-65], -1.0, If[LessEqual[y, 5e-35], 1.0, -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{-65}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-35}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < -3.8000000000000002e-65 or 4.99999999999999964e-35 < y Initial program 100.0%
Taylor expanded in x around 0 74.3%
if -3.8000000000000002e-65 < y < 4.99999999999999964e-35Initial program 100.0%
Taylor expanded in x around inf 79.7%
(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}
\\
\frac{x - y}{x + y}
\end{array}
Initial program 100.0%
(FPCore (x y) :precision binary64 -1.0)
double code(double x, double y) {
return -1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -1.0d0
end function
public static double code(double x, double y) {
return -1.0;
}
def code(x, y): return -1.0
function code(x, y) return -1.0 end
function tmp = code(x, y) tmp = -1.0; end
code[x_, y_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 51.8%
(FPCore (x y) :precision binary64 (- (/ x (+ x y)) (/ y (+ x y))))
double code(double x, double y) {
return (x / (x + y)) - (y / (x + y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x / (x + y)) - (y / (x + y))
end function
public static double code(double x, double y) {
return (x / (x + y)) - (y / (x + y));
}
def code(x, y): return (x / (x + y)) - (y / (x + y))
function code(x, y) return Float64(Float64(x / Float64(x + y)) - Float64(y / Float64(x + y))) end
function tmp = code(x, y) tmp = (x / (x + y)) - (y / (x + y)); end
code[x_, y_] := N[(N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision] - N[(y / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{x + y} - \frac{y}{x + y}
\end{array}
herbie shell --seed 2024116
(FPCore (x y)
:name "Data.Colour.RGB:hslsv from colour-2.3.3, D"
:precision binary64
:alt
(! :herbie-platform default (- (/ x (+ x y)) (/ y (+ x y))))
(/ (- x y) (+ x y)))