
(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 8 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 -7800.0) (not (<= y 29000000.0))) (+ 1.0 (/ (+ x -1.0) y)) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -7800.0) || !(y <= 29000000.0)) {
tmp = 1.0 + ((x + -1.0) / 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 <= (-7800.0d0)) .or. (.not. (y <= 29000000.0d0))) then
tmp = 1.0d0 + ((x + (-1.0d0)) / 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 <= -7800.0) || !(y <= 29000000.0)) {
tmp = 1.0 + ((x + -1.0) / y);
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -7800.0) or not (y <= 29000000.0): tmp = 1.0 + ((x + -1.0) / y) else: tmp = x / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -7800.0) || !(y <= 29000000.0)) tmp = Float64(1.0 + Float64(Float64(x + -1.0) / y)); else tmp = Float64(x / Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -7800.0) || ~((y <= 29000000.0))) tmp = 1.0 + ((x + -1.0) / y); else tmp = x / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -7800.0], N[Not[LessEqual[y, 29000000.0]], $MachinePrecision]], N[(1.0 + N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7800 \lor \neg \left(y \leq 29000000\right):\\
\;\;\;\;1 + \frac{x + -1}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -7800 or 2.9e7 < y Initial program 100.0%
Taylor expanded in y around -inf 99.9%
mul-1-neg99.9%
unsub-neg99.9%
mul-1-neg99.9%
sub-neg99.9%
Simplified99.9%
if -7800 < y < 2.9e7Initial program 100.0%
Taylor expanded in x around inf 78.0%
+-commutative78.0%
Simplified78.0%
Final simplification88.8%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 29000000.0))) (+ 1.0 (/ -1.0 y)) x))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 29000000.0)) {
tmp = 1.0 + (-1.0 / y);
} else {
tmp = 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)) .or. (.not. (y <= 29000000.0d0))) then
tmp = 1.0d0 + ((-1.0d0) / y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 29000000.0)) {
tmp = 1.0 + (-1.0 / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 29000000.0): tmp = 1.0 + (-1.0 / y) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 29000000.0)) tmp = Float64(1.0 + Float64(-1.0 / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.0) || ~((y <= 29000000.0))) tmp = 1.0 + (-1.0 / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 29000000.0]], $MachinePrecision]], N[(1.0 + N[(-1.0 / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 29000000\right):\\
\;\;\;\;1 + \frac{-1}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1 or 2.9e7 < y Initial program 100.0%
Taylor expanded in x around 0 79.3%
+-commutative79.3%
Simplified79.3%
Taylor expanded in y around inf 79.3%
if -1 < y < 2.9e7Initial program 100.0%
Taylor expanded in y around 0 76.3%
Final simplification77.8%
(FPCore (x y) :precision binary64 (if (or (<= y -420000.0) (not (<= y 57000000.0))) (+ 1.0 (/ x y)) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -420000.0) || !(y <= 57000000.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 <= (-420000.0d0)) .or. (.not. (y <= 57000000.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 <= -420000.0) || !(y <= 57000000.0)) {
tmp = 1.0 + (x / y);
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -420000.0) or not (y <= 57000000.0): tmp = 1.0 + (x / y) else: tmp = x / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -420000.0) || !(y <= 57000000.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 <= -420000.0) || ~((y <= 57000000.0))) tmp = 1.0 + (x / y); else tmp = x / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -420000.0], N[Not[LessEqual[y, 57000000.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 -420000 \lor \neg \left(y \leq 57000000\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -4.2e5 or 5.7e7 < y Initial program 100.0%
Taylor expanded in y around -inf 99.9%
mul-1-neg99.9%
unsub-neg99.9%
mul-1-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in x around inf 99.5%
neg-mul-199.5%
Simplified99.5%
if -4.2e5 < y < 5.7e7Initial program 100.0%
Taylor expanded in x around inf 78.0%
+-commutative78.0%
Simplified78.0%
Final simplification88.7%
(FPCore (x y) :precision binary64 (if (<= y -4e+30) 1.0 (if (<= y 100000000.0) (/ x (+ y 1.0)) (+ 1.0 (/ -1.0 y)))))
double code(double x, double y) {
double tmp;
if (y <= -4e+30) {
tmp = 1.0;
} else if (y <= 100000000.0) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0 + (-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 <= (-4d+30)) then
tmp = 1.0d0
else if (y <= 100000000.0d0) then
tmp = x / (y + 1.0d0)
else
tmp = 1.0d0 + ((-1.0d0) / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -4e+30) {
tmp = 1.0;
} else if (y <= 100000000.0) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0 + (-1.0 / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4e+30: tmp = 1.0 elif y <= 100000000.0: tmp = x / (y + 1.0) else: tmp = 1.0 + (-1.0 / y) return tmp
function code(x, y) tmp = 0.0 if (y <= -4e+30) tmp = 1.0; elseif (y <= 100000000.0) tmp = Float64(x / Float64(y + 1.0)); else tmp = Float64(1.0 + Float64(-1.0 / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4e+30) tmp = 1.0; elseif (y <= 100000000.0) tmp = x / (y + 1.0); else tmp = 1.0 + (-1.0 / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4e+30], 1.0, If[LessEqual[y, 100000000.0], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-1.0 / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{+30}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 100000000:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{-1}{y}\\
\end{array}
\end{array}
if y < -4.0000000000000001e30Initial program 100.0%
Taylor expanded in y around inf 85.0%
if -4.0000000000000001e30 < y < 1e8Initial program 100.0%
Taylor expanded in x around inf 76.4%
+-commutative76.4%
Simplified76.4%
if 1e8 < y Initial program 100.0%
Taylor expanded in x around 0 78.5%
+-commutative78.5%
Simplified78.5%
Taylor expanded in y around inf 78.6%
Final simplification79.1%
(FPCore (x y) :precision binary64 (if (<= y -2.45e+30) 1.0 (if (<= y 6.2e-73) (/ x (+ y 1.0)) (/ y (+ y 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -2.45e+30) {
tmp = 1.0;
} else if (y <= 6.2e-73) {
tmp = x / (y + 1.0);
} else {
tmp = y / (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 <= (-2.45d+30)) then
tmp = 1.0d0
else if (y <= 6.2d-73) then
tmp = x / (y + 1.0d0)
else
tmp = y / (y + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.45e+30) {
tmp = 1.0;
} else if (y <= 6.2e-73) {
tmp = x / (y + 1.0);
} else {
tmp = y / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.45e+30: tmp = 1.0 elif y <= 6.2e-73: tmp = x / (y + 1.0) else: tmp = y / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if (y <= -2.45e+30) tmp = 1.0; elseif (y <= 6.2e-73) tmp = Float64(x / Float64(y + 1.0)); else tmp = Float64(y / Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.45e+30) tmp = 1.0; elseif (y <= 6.2e-73) tmp = x / (y + 1.0); else tmp = y / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.45e+30], 1.0, If[LessEqual[y, 6.2e-73], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.45 \cdot 10^{+30}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{-73}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y + 1}\\
\end{array}
\end{array}
if y < -2.44999999999999992e30Initial program 100.0%
Taylor expanded in y around inf 85.0%
if -2.44999999999999992e30 < y < 6.19999999999999938e-73Initial program 100.0%
Taylor expanded in x around inf 79.9%
+-commutative79.9%
Simplified79.9%
if 6.19999999999999938e-73 < y Initial program 100.0%
Taylor expanded in x around 0 73.2%
+-commutative73.2%
Simplified73.2%
Final simplification79.4%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 29000000.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 29000000.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 <= 29000000.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 <= 29000000.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 29000000.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 <= 29000000.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 <= 29000000.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, 29000000.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 29000000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 2.9e7 < y Initial program 100.0%
Taylor expanded in y around inf 79.1%
if -1 < y < 2.9e7Initial program 100.0%
Taylor expanded in y around 0 76.3%
Final simplification77.7%
(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 41.2%
Final simplification41.2%
herbie shell --seed 2023192
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))