
(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 (<= x -2.6e+50)
(and (not (<= x -1.55e-68))
(or (<= x -1.65e-121) (not (<= x 2.05e+106)))))
(/ x (+ y 1.0))
(/ y (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -2.6e+50) || (!(x <= -1.55e-68) && ((x <= -1.65e-121) || !(x <= 2.05e+106)))) {
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 ((x <= (-2.6d+50)) .or. (.not. (x <= (-1.55d-68))) .and. (x <= (-1.65d-121)) .or. (.not. (x <= 2.05d+106))) 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 ((x <= -2.6e+50) || (!(x <= -1.55e-68) && ((x <= -1.65e-121) || !(x <= 2.05e+106)))) {
tmp = x / (y + 1.0);
} else {
tmp = y / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.6e+50) or (not (x <= -1.55e-68) and ((x <= -1.65e-121) or not (x <= 2.05e+106))): tmp = x / (y + 1.0) else: tmp = y / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.6e+50) || (!(x <= -1.55e-68) && ((x <= -1.65e-121) || !(x <= 2.05e+106)))) 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 ((x <= -2.6e+50) || (~((x <= -1.55e-68)) && ((x <= -1.65e-121) || ~((x <= 2.05e+106))))) tmp = x / (y + 1.0); else tmp = y / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.6e+50], And[N[Not[LessEqual[x, -1.55e-68]], $MachinePrecision], Or[LessEqual[x, -1.65e-121], N[Not[LessEqual[x, 2.05e+106]], $MachinePrecision]]]], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{+50} \lor \neg \left(x \leq -1.55 \cdot 10^{-68}\right) \land \left(x \leq -1.65 \cdot 10^{-121} \lor \neg \left(x \leq 2.05 \cdot 10^{+106}\right)\right):\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y + 1}\\
\end{array}
\end{array}
if x < -2.6000000000000002e50 or -1.55e-68 < x < -1.65000000000000005e-121 or 2.0500000000000001e106 < x Initial program 100.0%
Taylor expanded in x around inf 88.3%
+-commutative88.3%
Simplified88.3%
if -2.6000000000000002e50 < x < -1.55e-68 or -1.65000000000000005e-121 < x < 2.0500000000000001e106Initial program 100.0%
Taylor expanded in x around 0 77.2%
+-commutative77.2%
Simplified77.2%
Final simplification82.0%
(FPCore (x y) :precision binary64 (if (or (<= y -27500000.0) (not (<= y 42000.0))) (- 1.0 (/ (- 1.0 x) y)) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -27500000.0) || !(y <= 42000.0)) {
tmp = 1.0 - ((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 <= (-27500000.0d0)) .or. (.not. (y <= 42000.0d0))) then
tmp = 1.0d0 - ((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 <= -27500000.0) || !(y <= 42000.0)) {
tmp = 1.0 - ((1.0 - x) / y);
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -27500000.0) or not (y <= 42000.0): tmp = 1.0 - ((1.0 - x) / y) else: tmp = x / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -27500000.0) || !(y <= 42000.0)) tmp = Float64(1.0 - Float64(Float64(1.0 - 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 <= -27500000.0) || ~((y <= 42000.0))) tmp = 1.0 - ((1.0 - x) / y); else tmp = x / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -27500000.0], N[Not[LessEqual[y, 42000.0]], $MachinePrecision]], N[(1.0 - N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -27500000 \lor \neg \left(y \leq 42000\right):\\
\;\;\;\;1 - \frac{1 - x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -2.75e7 or 42000 < y Initial program 100.0%
Taylor expanded in y around -inf 99.7%
mul-1-neg99.7%
unsub-neg99.7%
mul-1-neg99.7%
sub-neg99.7%
Simplified99.7%
if -2.75e7 < y < 42000Initial program 100.0%
Taylor expanded in x around inf 74.9%
+-commutative74.9%
Simplified74.9%
Final simplification87.0%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 2.55e-18) x (if (<= y 4.5e+65) (/ x y) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 2.55e-18) {
tmp = x;
} else if (y <= 4.5e+65) {
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 <= 2.55d-18) then
tmp = x
else if (y <= 4.5d+65) 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 <= 2.55e-18) {
tmp = x;
} else if (y <= 4.5e+65) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 2.55e-18: tmp = x elif y <= 4.5e+65: 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 <= 2.55e-18) tmp = x; elseif (y <= 4.5e+65) 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 <= 2.55e-18) tmp = x; elseif (y <= 4.5e+65) 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, 2.55e-18], x, If[LessEqual[y, 4.5e+65], N[(x / y), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.55 \cdot 10^{-18}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{+65}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 4.5e65 < y Initial program 100.0%
Taylor expanded in y around inf 78.5%
if -1 < y < 2.54999999999999991e-18Initial program 100.0%
Taylor expanded in y around 0 76.3%
if 2.54999999999999991e-18 < y < 4.5e65Initial program 99.9%
Taylor expanded in x around inf 59.8%
+-commutative59.8%
Simplified59.8%
Taylor expanded in y around inf 51.4%
Final simplification75.4%
(FPCore (x y) :precision binary64 (if (or (<= y -12200000.0) (not (<= y 2000000.0))) (+ 1.0 (/ x y)) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -12200000.0) || !(y <= 2000000.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 <= (-12200000.0d0)) .or. (.not. (y <= 2000000.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 <= -12200000.0) || !(y <= 2000000.0)) {
tmp = 1.0 + (x / y);
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -12200000.0) or not (y <= 2000000.0): tmp = 1.0 + (x / y) else: tmp = x / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -12200000.0) || !(y <= 2000000.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 <= -12200000.0) || ~((y <= 2000000.0))) tmp = 1.0 + (x / y); else tmp = x / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -12200000.0], N[Not[LessEqual[y, 2000000.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 -12200000 \lor \neg \left(y \leq 2000000\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -1.22e7 or 2e6 < y Initial program 100.0%
Taylor expanded in y around -inf 99.7%
mul-1-neg99.7%
unsub-neg99.7%
mul-1-neg99.7%
sub-neg99.7%
Simplified99.7%
Taylor expanded in x around inf 99.1%
neg-mul-199.1%
distribute-neg-frac99.1%
Simplified99.1%
if -1.22e7 < y < 2e6Initial program 100.0%
Taylor expanded in x around inf 74.9%
+-commutative74.9%
Simplified74.9%
Final simplification86.7%
(FPCore (x y) :precision binary64 (if (<= y -1.6e+60) 1.0 (if (<= y 5.2e+65) (/ x (+ y 1.0)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.6e+60) {
tmp = 1.0;
} else if (y <= 5.2e+65) {
tmp = x / (y + 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 <= (-1.6d+60)) then
tmp = 1.0d0
else if (y <= 5.2d+65) then
tmp = x / (y + 1.0d0)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.6e+60) {
tmp = 1.0;
} else if (y <= 5.2e+65) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.6e+60: tmp = 1.0 elif y <= 5.2e+65: tmp = x / (y + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.6e+60) tmp = 1.0; elseif (y <= 5.2e+65) tmp = Float64(x / Float64(y + 1.0)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.6e+60) tmp = 1.0; elseif (y <= 5.2e+65) tmp = x / (y + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.6e+60], 1.0, If[LessEqual[y, 5.2e+65], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{+60}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{+65}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.59999999999999995e60 or 5.20000000000000005e65 < y Initial program 100.0%
Taylor expanded in y around inf 83.8%
if -1.59999999999999995e60 < y < 5.20000000000000005e65Initial program 100.0%
Taylor expanded in x around inf 73.5%
+-commutative73.5%
Simplified73.5%
Final simplification77.4%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 2.55e-18) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 2.55e-18) {
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 <= 2.55d-18) 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 <= 2.55e-18) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 2.55e-18: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 2.55e-18) 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 <= 2.55e-18) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 2.55e-18], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.55 \cdot 10^{-18}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 2.54999999999999991e-18 < y Initial program 100.0%
Taylor expanded in y around inf 70.2%
if -1 < y < 2.54999999999999991e-18Initial program 100.0%
Taylor expanded in y around 0 76.3%
Final simplification73.1%
(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 37.8%
Final simplification37.8%
herbie shell --seed 2023230
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))