
(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 9 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 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 99.9%
(FPCore (x y) :precision binary64 (if (or (<= y -2.9e+50) (not (<= y 5.3e+16))) (+ (* 2.0 (/ x y)) -1.0) (+ 1.0 (* -2.0 (/ y x)))))
double code(double x, double y) {
double tmp;
if ((y <= -2.9e+50) || !(y <= 5.3e+16)) {
tmp = (2.0 * (x / y)) + -1.0;
} else {
tmp = 1.0 + (-2.0 * (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 <= (-2.9d+50)) .or. (.not. (y <= 5.3d+16))) then
tmp = (2.0d0 * (x / y)) + (-1.0d0)
else
tmp = 1.0d0 + ((-2.0d0) * (y / x))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -2.9e+50) || !(y <= 5.3e+16)) {
tmp = (2.0 * (x / y)) + -1.0;
} else {
tmp = 1.0 + (-2.0 * (y / x));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.9e+50) or not (y <= 5.3e+16): tmp = (2.0 * (x / y)) + -1.0 else: tmp = 1.0 + (-2.0 * (y / x)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.9e+50) || !(y <= 5.3e+16)) tmp = Float64(Float64(2.0 * Float64(x / y)) + -1.0); else tmp = Float64(1.0 + Float64(-2.0 * Float64(y / x))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2.9e+50) || ~((y <= 5.3e+16))) tmp = (2.0 * (x / y)) + -1.0; else tmp = 1.0 + (-2.0 * (y / x)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.9e+50], N[Not[LessEqual[y, 5.3e+16]], $MachinePrecision]], N[(N[(2.0 * N[(x / y), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(1.0 + N[(-2.0 * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.9 \cdot 10^{+50} \lor \neg \left(y \leq 5.3 \cdot 10^{+16}\right):\\
\;\;\;\;2 \cdot \frac{x}{y} + -1\\
\mathbf{else}:\\
\;\;\;\;1 + -2 \cdot \frac{y}{x}\\
\end{array}
\end{array}
if y < -2.9e50 or 5.3e16 < y Initial program 99.9%
Taylor expanded in x around 0 78.8%
if -2.9e50 < y < 5.3e16Initial program 100.0%
Taylor expanded in y around 0 75.3%
Final simplification77.0%
(FPCore (x y) :precision binary64 (if (<= y -1.75e+50) (/ (- x y) y) (if (<= y 4.5e+55) (+ 1.0 (* -2.0 (/ y x))) (/ y (- (- x) y)))))
double code(double x, double y) {
double tmp;
if (y <= -1.75e+50) {
tmp = (x - y) / y;
} else if (y <= 4.5e+55) {
tmp = 1.0 + (-2.0 * (y / x));
} 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.75d+50)) then
tmp = (x - y) / y
else if (y <= 4.5d+55) then
tmp = 1.0d0 + ((-2.0d0) * (y / x))
else
tmp = y / (-x - y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.75e+50) {
tmp = (x - y) / y;
} else if (y <= 4.5e+55) {
tmp = 1.0 + (-2.0 * (y / x));
} else {
tmp = y / (-x - y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.75e+50: tmp = (x - y) / y elif y <= 4.5e+55: tmp = 1.0 + (-2.0 * (y / x)) else: tmp = y / (-x - y) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.75e+50) tmp = Float64(Float64(x - y) / y); elseif (y <= 4.5e+55) tmp = Float64(1.0 + Float64(-2.0 * Float64(y / x))); else tmp = Float64(y / Float64(Float64(-x) - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.75e+50) tmp = (x - y) / y; elseif (y <= 4.5e+55) tmp = 1.0 + (-2.0 * (y / x)); else tmp = y / (-x - y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.75e+50], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, 4.5e+55], N[(1.0 + N[(-2.0 * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y / N[((-x) - y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.75 \cdot 10^{+50}:\\
\;\;\;\;\frac{x - y}{y}\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{+55}:\\
\;\;\;\;1 + -2 \cdot \frac{y}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\left(-x\right) - y}\\
\end{array}
\end{array}
if y < -1.75000000000000003e50Initial program 99.9%
Taylor expanded in x around 0 83.9%
if -1.75000000000000003e50 < y < 4.49999999999999998e55Initial program 99.9%
Taylor expanded in y around 0 72.9%
if 4.49999999999999998e55 < y Initial program 99.9%
Taylor expanded in x around 0 79.0%
neg-mul-179.0%
Simplified79.0%
Final simplification76.6%
(FPCore (x y) :precision binary64 (if (<= y -1.1e+49) (/ (- x y) y) (if (<= y 4.7e+17) (/ x (+ x y)) (/ y (- (- x) y)))))
double code(double x, double y) {
double tmp;
if (y <= -1.1e+49) {
tmp = (x - y) / y;
} else if (y <= 4.7e+17) {
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 <= (-1.1d+49)) then
tmp = (x - y) / y
else if (y <= 4.7d+17) 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 <= -1.1e+49) {
tmp = (x - y) / y;
} else if (y <= 4.7e+17) {
tmp = x / (x + y);
} else {
tmp = y / (-x - y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.1e+49: tmp = (x - y) / y elif y <= 4.7e+17: tmp = x / (x + y) else: tmp = y / (-x - y) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.1e+49) tmp = Float64(Float64(x - y) / y); elseif (y <= 4.7e+17) tmp = Float64(x / Float64(x + y)); else tmp = Float64(y / Float64(Float64(-x) - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.1e+49) tmp = (x - y) / y; elseif (y <= 4.7e+17) tmp = x / (x + y); else tmp = y / (-x - y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.1e+49], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, 4.7e+17], N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision], N[(y / N[((-x) - y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{+49}:\\
\;\;\;\;\frac{x - y}{y}\\
\mathbf{elif}\;y \leq 4.7 \cdot 10^{+17}:\\
\;\;\;\;\frac{x}{x + y}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\left(-x\right) - y}\\
\end{array}
\end{array}
if y < -1.1e49Initial program 99.9%
Taylor expanded in x around 0 83.9%
if -1.1e49 < y < 4.7e17Initial program 100.0%
Taylor expanded in x around inf 74.7%
if 4.7e17 < y Initial program 99.9%
Taylor expanded in x around 0 73.6%
neg-mul-173.6%
Simplified73.6%
Final simplification76.3%
(FPCore (x y) :precision binary64 (if (or (<= y -1.5e+49) (not (<= y 1.45e+17))) (/ (- x y) y) (/ x (+ x y))))
double code(double x, double y) {
double tmp;
if ((y <= -1.5e+49) || !(y <= 1.45e+17)) {
tmp = (x - y) / y;
} 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.5d+49)) .or. (.not. (y <= 1.45d+17))) then
tmp = (x - y) / y
else
tmp = x / (x + y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.5e+49) || !(y <= 1.45e+17)) {
tmp = (x - y) / y;
} else {
tmp = x / (x + y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.5e+49) or not (y <= 1.45e+17): tmp = (x - y) / y else: tmp = x / (x + y) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.5e+49) || !(y <= 1.45e+17)) tmp = Float64(Float64(x - y) / y); else tmp = Float64(x / Float64(x + y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.5e+49) || ~((y <= 1.45e+17))) tmp = (x - y) / y; else tmp = x / (x + y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.5e+49], N[Not[LessEqual[y, 1.45e+17]], $MachinePrecision]], N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision], N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{+49} \lor \neg \left(y \leq 1.45 \cdot 10^{+17}\right):\\
\;\;\;\;\frac{x - y}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x + y}\\
\end{array}
\end{array}
if y < -1.5000000000000001e49 or 1.45e17 < y Initial program 99.9%
Taylor expanded in x around 0 77.8%
if -1.5000000000000001e49 < y < 1.45e17Initial program 100.0%
Taylor expanded in x around inf 74.7%
Final simplification76.3%
(FPCore (x y) :precision binary64 (if (<= y -1.4e+51) -1.0 (if (<= y 4.6e+55) (/ x (+ x y)) -1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.4e+51) {
tmp = -1.0;
} else if (y <= 4.6e+55) {
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 (y <= (-1.4d+51)) then
tmp = -1.0d0
else if (y <= 4.6d+55) 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 (y <= -1.4e+51) {
tmp = -1.0;
} else if (y <= 4.6e+55) {
tmp = x / (x + y);
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.4e+51: tmp = -1.0 elif y <= 4.6e+55: tmp = x / (x + y) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.4e+51) tmp = -1.0; elseif (y <= 4.6e+55) tmp = Float64(x / Float64(x + y)); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.4e+51) tmp = -1.0; elseif (y <= 4.6e+55) tmp = x / (x + y); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.4e+51], -1.0, If[LessEqual[y, 4.6e+55], N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision], -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{+51}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 4.6 \cdot 10^{+55}:\\
\;\;\;\;\frac{x}{x + y}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < -1.40000000000000002e51 or 4.59999999999999975e55 < y Initial program 99.9%
Taylor expanded in x around 0 80.5%
if -1.40000000000000002e51 < y < 4.59999999999999975e55Initial program 99.9%
Taylor expanded in x around inf 72.1%
(FPCore (x y) :precision binary64 (if (<= y -2e+50) -1.0 (if (<= y 4.1e+54) (- 1.0 (/ y x)) -1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2e+50) {
tmp = -1.0;
} else if (y <= 4.1e+54) {
tmp = 1.0 - (y / x);
} 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 <= (-2d+50)) then
tmp = -1.0d0
else if (y <= 4.1d+54) then
tmp = 1.0d0 - (y / x)
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2e+50) {
tmp = -1.0;
} else if (y <= 4.1e+54) {
tmp = 1.0 - (y / x);
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2e+50: tmp = -1.0 elif y <= 4.1e+54: tmp = 1.0 - (y / x) else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2e+50) tmp = -1.0; elseif (y <= 4.1e+54) tmp = Float64(1.0 - Float64(y / x)); else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2e+50) tmp = -1.0; elseif (y <= 4.1e+54) tmp = 1.0 - (y / x); else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2e+50], -1.0, If[LessEqual[y, 4.1e+54], N[(1.0 - N[(y / x), $MachinePrecision]), $MachinePrecision], -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{+50}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 4.1 \cdot 10^{+54}:\\
\;\;\;\;1 - \frac{y}{x}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < -2.0000000000000002e50 or 4.09999999999999967e54 < y Initial program 99.9%
Taylor expanded in x around 0 80.5%
if -2.0000000000000002e50 < y < 4.09999999999999967e54Initial program 99.9%
Taylor expanded in x around inf 72.1%
Taylor expanded in x around inf 72.0%
mul-1-neg72.0%
unsub-neg72.0%
Simplified72.0%
(FPCore (x y) :precision binary64 (if (<= y -6e+49) -1.0 (if (<= y 200000000000.0) 1.0 -1.0)))
double code(double x, double y) {
double tmp;
if (y <= -6e+49) {
tmp = -1.0;
} else if (y <= 200000000000.0) {
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 <= (-6d+49)) then
tmp = -1.0d0
else if (y <= 200000000000.0d0) 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 <= -6e+49) {
tmp = -1.0;
} else if (y <= 200000000000.0) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6e+49: tmp = -1.0 elif y <= 200000000000.0: tmp = 1.0 else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -6e+49) tmp = -1.0; elseif (y <= 200000000000.0) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -6e+49) tmp = -1.0; elseif (y <= 200000000000.0) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6e+49], -1.0, If[LessEqual[y, 200000000000.0], 1.0, -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{+49}:\\
\;\;\;\;-1\\
\mathbf{elif}\;y \leq 200000000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if y < -6.0000000000000005e49 or 2e11 < y Initial program 99.9%
Taylor expanded in x around 0 77.1%
if -6.0000000000000005e49 < y < 2e11Initial program 100.0%
Taylor expanded in x around inf 73.8%
(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 99.9%
Taylor expanded in x around 0 50.5%
(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 2024165
(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)))