
(FPCore (x y) :precision binary64 (/ (+ x y) (+ y 1.0)))
double code(double x, double y) {
return (x + y) / (y + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) / (y + 1.0d0)
end function
public static double code(double x, double y) {
return (x + y) / (y + 1.0);
}
def code(x, y): return (x + y) / (y + 1.0)
function code(x, y) return Float64(Float64(x + y) / Float64(y + 1.0)) end
function tmp = code(x, y) tmp = (x + y) / (y + 1.0); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{y + 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (+ x y) (+ y 1.0)))
double code(double x, double y) {
return (x + y) / (y + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) / (y + 1.0d0)
end function
public static double code(double x, double y) {
return (x + y) / (y + 1.0);
}
def code(x, y): return (x + y) / (y + 1.0)
function code(x, y) return Float64(Float64(x + y) / Float64(y + 1.0)) end
function tmp = code(x, y) tmp = (x + y) / (y + 1.0); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{y + 1}
\end{array}
(FPCore (x y) :precision binary64 (/ (+ x y) (+ y 1.0)))
double code(double x, double y) {
return (x + y) / (y + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) / (y + 1.0d0)
end function
public static double code(double x, double y) {
return (x + y) / (y + 1.0);
}
def code(x, y): return (x + y) / (y + 1.0)
function code(x, y) return Float64(Float64(x + y) / Float64(y + 1.0)) end
function tmp = code(x, y) tmp = (x + y) / (y + 1.0); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{y + 1}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 0.86))) (+ 1.0 (/ x y)) (- x (* y (+ x -1.0)))))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 0.86)) {
tmp = 1.0 + (x / y);
} else {
tmp = x - (y * (x + -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.0d0)) .or. (.not. (y <= 0.86d0))) then
tmp = 1.0d0 + (x / y)
else
tmp = x - (y * (x + (-1.0d0)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 0.86)) {
tmp = 1.0 + (x / y);
} else {
tmp = x - (y * (x + -1.0));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 0.86): tmp = 1.0 + (x / y) else: tmp = x - (y * (x + -1.0)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 0.86)) tmp = Float64(1.0 + Float64(x / y)); else tmp = Float64(x - Float64(y * Float64(x + -1.0))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.0) || ~((y <= 0.86))) tmp = 1.0 + (x / y); else tmp = x - (y * (x + -1.0)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 0.86]], $MachinePrecision]], N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x - N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 0.86\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if y < -1 or 0.859999999999999987 < y Initial program 100.0%
Taylor expanded in y around inf 97.5%
+-commutative97.5%
associate--l+97.5%
+-commutative97.5%
associate--r-97.5%
div-sub97.5%
Simplified97.5%
Taylor expanded in x around inf 97.4%
neg-mul-197.4%
distribute-neg-frac97.4%
Simplified97.4%
div-inv97.3%
cancel-sign-sub97.3%
div-inv97.4%
+-commutative97.4%
Applied egg-rr97.4%
if -1 < y < 0.859999999999999987Initial program 100.0%
Taylor expanded in y around 0 98.9%
Final simplification98.2%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (+ 1.0 (/ (+ x -1.0) y)) (- x (* y (+ x -1.0)))))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = 1.0 + ((x + -1.0) / y);
} else {
tmp = x - (y * (x + -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.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = 1.0d0 + ((x + (-1.0d0)) / y)
else
tmp = x - (y * (x + (-1.0d0)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = 1.0 + ((x + -1.0) / y);
} else {
tmp = x - (y * (x + -1.0));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = 1.0 + ((x + -1.0) / y) else: tmp = x - (y * (x + -1.0)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(1.0 + Float64(Float64(x + -1.0) / y)); else tmp = Float64(x - Float64(y * Float64(x + -1.0))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.0))) tmp = 1.0 + ((x + -1.0) / y); else tmp = x - (y * (x + -1.0)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(1.0 + N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x - N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;1 + \frac{x + -1}{y}\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 97.5%
+-commutative97.5%
associate--l+97.5%
+-commutative97.5%
associate--r-97.5%
div-sub97.5%
Simplified97.5%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0 98.9%
Final simplification98.3%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 3.7e-16) x (if (<= y 2.4e+60) (/ x y) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 3.7e-16) {
tmp = x;
} else if (y <= 2.4e+60) {
tmp = 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.0d0)) then
tmp = 1.0d0
else if (y <= 3.7d-16) then
tmp = x
else if (y <= 2.4d+60) then
tmp = 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.0) {
tmp = 1.0;
} else if (y <= 3.7e-16) {
tmp = x;
} else if (y <= 2.4e+60) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 3.7e-16: tmp = x elif y <= 2.4e+60: tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 3.7e-16) tmp = x; elseif (y <= 2.4e+60) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = 1.0; elseif (y <= 3.7e-16) tmp = x; elseif (y <= 2.4e+60) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 3.7e-16], x, If[LessEqual[y, 2.4e+60], N[(x / y), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 3.7 \cdot 10^{-16}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{+60}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 2.4e60 < y Initial program 100.0%
Taylor expanded in y around inf 79.5%
if -1 < y < 3.7e-16Initial program 100.0%
Taylor expanded in y around 0 78.4%
if 3.7e-16 < y < 2.4e60Initial program 100.0%
Taylor expanded in y around inf 74.0%
+-commutative74.0%
associate--l+74.0%
+-commutative74.0%
associate--r-74.0%
div-sub74.0%
Simplified74.0%
Taylor expanded in x around inf 60.3%
Final simplification77.5%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 3.7e-16) (* x (- 1.0 y)) (if (<= y 7.5e+60) (/ x y) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 3.7e-16) {
tmp = x * (1.0 - y);
} else if (y <= 7.5e+60) {
tmp = 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.0d0)) then
tmp = 1.0d0
else if (y <= 3.7d-16) then
tmp = x * (1.0d0 - y)
else if (y <= 7.5d+60) then
tmp = 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.0) {
tmp = 1.0;
} else if (y <= 3.7e-16) {
tmp = x * (1.0 - y);
} else if (y <= 7.5e+60) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 3.7e-16: tmp = x * (1.0 - y) elif y <= 7.5e+60: tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 3.7e-16) tmp = Float64(x * Float64(1.0 - y)); elseif (y <= 7.5e+60) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = 1.0; elseif (y <= 3.7e-16) tmp = x * (1.0 - y); elseif (y <= 7.5e+60) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 3.7e-16], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.5e+60], N[(x / y), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 3.7 \cdot 10^{-16}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{+60}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 7.5e60 < y Initial program 100.0%
Taylor expanded in y around inf 79.5%
if -1 < y < 3.7e-16Initial program 100.0%
Taylor expanded in y around 0 99.3%
Taylor expanded in x around inf 78.9%
neg-mul-178.9%
unsub-neg78.9%
Simplified78.9%
if 3.7e-16 < y < 7.5e60Initial program 100.0%
Taylor expanded in y around inf 74.0%
+-commutative74.0%
associate--l+74.0%
+-commutative74.0%
associate--r-74.0%
div-sub74.0%
Simplified74.0%
Taylor expanded in x around inf 60.3%
Final simplification77.7%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 3.7e-16))) (+ 1.0 (/ x y)) (* x (- 1.0 y))))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 3.7e-16)) {
tmp = 1.0 + (x / y);
} else {
tmp = x * (1.0 - 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)) .or. (.not. (y <= 3.7d-16))) then
tmp = 1.0d0 + (x / y)
else
tmp = x * (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 3.7e-16)) {
tmp = 1.0 + (x / y);
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 3.7e-16): tmp = 1.0 + (x / y) else: tmp = x * (1.0 - y) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 3.7e-16)) tmp = Float64(1.0 + Float64(x / y)); else tmp = Float64(x * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.0) || ~((y <= 3.7e-16))) tmp = 1.0 + (x / y); else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 3.7e-16]], $MachinePrecision]], N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 3.7 \cdot 10^{-16}\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -1 or 3.7e-16 < y Initial program 100.0%
Taylor expanded in y around inf 95.0%
+-commutative95.0%
associate--l+95.0%
+-commutative95.0%
associate--r-95.0%
div-sub95.0%
Simplified95.0%
Taylor expanded in x around inf 95.1%
neg-mul-195.1%
distribute-neg-frac95.1%
Simplified95.1%
div-inv95.0%
cancel-sign-sub95.0%
div-inv95.1%
+-commutative95.1%
Applied egg-rr95.1%
if -1 < y < 3.7e-16Initial program 100.0%
Taylor expanded in y around 0 99.3%
Taylor expanded in x around inf 78.9%
neg-mul-178.9%
unsub-neg78.9%
Simplified78.9%
Final simplification86.1%
(FPCore (x y) :precision binary64 (if (or (<= y -4300000000.0) (not (<= y 1950000000.0))) (+ 1.0 (/ x y)) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -4300000000.0) || !(y <= 1950000000.0)) {
tmp = 1.0 + (x / y);
} else {
tmp = x / (y + 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 <= (-4300000000.0d0)) .or. (.not. (y <= 1950000000.0d0))) then
tmp = 1.0d0 + (x / y)
else
tmp = x / (y + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -4300000000.0) || !(y <= 1950000000.0)) {
tmp = 1.0 + (x / y);
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4300000000.0) or not (y <= 1950000000.0): tmp = 1.0 + (x / y) else: tmp = x / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -4300000000.0) || !(y <= 1950000000.0)) tmp = Float64(1.0 + Float64(x / y)); else tmp = Float64(x / Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -4300000000.0) || ~((y <= 1950000000.0))) tmp = 1.0 + (x / y); else tmp = x / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4300000000.0], N[Not[LessEqual[y, 1950000000.0]], $MachinePrecision]], N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4300000000 \lor \neg \left(y \leq 1950000000\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -4.3e9 or 1.95e9 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
+-commutative100.0%
associate--l+100.0%
+-commutative100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 99.8%
neg-mul-199.8%
distribute-neg-frac99.8%
Simplified99.8%
div-inv99.7%
cancel-sign-sub99.7%
div-inv99.8%
+-commutative99.8%
Applied egg-rr99.8%
if -4.3e9 < y < 1.95e9Initial program 100.0%
Taylor expanded in x around inf 78.8%
+-commutative78.8%
Simplified78.8%
Final simplification87.5%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 1950000000.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 1950000000.0) {
tmp = 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 <= (-1.0d0)) then
tmp = 1.0d0
else if (y <= 1950000000.0d0) then
tmp = x
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 1950000000.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 1950000000.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 1950000000.0) tmp = x; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = 1.0; elseif (y <= 1950000000.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 1950000000.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1950000000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 1.95e9 < y Initial program 100.0%
Taylor expanded in y around inf 72.9%
if -1 < y < 1.95e9Initial program 100.0%
Taylor expanded in y around 0 75.2%
Final simplification74.2%
(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 y around inf 32.7%
Final simplification32.7%
herbie shell --seed 2023322
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))