
(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%
(FPCore (x y) :precision binary64 (if (<= y -0.000135) (/ y (+ y 1.0)) (if (<= y 550.0) (+ x y) (if (<= y 5.5e+45) (/ x (+ y 1.0)) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -0.000135) {
tmp = y / (y + 1.0);
} else if (y <= 550.0) {
tmp = x + y;
} else if (y <= 5.5e+45) {
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 <= (-0.000135d0)) then
tmp = y / (y + 1.0d0)
else if (y <= 550.0d0) then
tmp = x + y
else if (y <= 5.5d+45) 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 <= -0.000135) {
tmp = y / (y + 1.0);
} else if (y <= 550.0) {
tmp = x + y;
} else if (y <= 5.5e+45) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -0.000135: tmp = y / (y + 1.0) elif y <= 550.0: tmp = x + y elif y <= 5.5e+45: tmp = x / (y + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -0.000135) tmp = Float64(y / Float64(y + 1.0)); elseif (y <= 550.0) tmp = Float64(x + y); elseif (y <= 5.5e+45) 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 <= -0.000135) tmp = y / (y + 1.0); elseif (y <= 550.0) tmp = x + y; elseif (y <= 5.5e+45) tmp = x / (y + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -0.000135], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 550.0], N[(x + y), $MachinePrecision], If[LessEqual[y, 5.5e+45], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.000135:\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{elif}\;y \leq 550:\\
\;\;\;\;x + y\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{+45}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.35000000000000002e-4Initial program 100.0%
Taylor expanded in x around 0 76.3%
+-commutative76.3%
Simplified76.3%
if -1.35000000000000002e-4 < y < 550Initial program 100.0%
Taylor expanded in y around inf 99.8%
Taylor expanded in y around 0 97.2%
Taylor expanded in x around 0 97.2%
+-commutative97.2%
Simplified97.2%
if 550 < y < 5.5000000000000001e45Initial program 100.0%
Taylor expanded in x around inf 84.1%
+-commutative84.1%
Simplified84.1%
if 5.5000000000000001e45 < y Initial program 100.0%
Taylor expanded in y around inf 75.8%
Final simplification86.0%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 550.0) (+ x y) (if (<= y 1.75e+46) (/ x (+ y 1.0)) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 550.0) {
tmp = x + y;
} else if (y <= 1.75e+46) {
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.0d0)) then
tmp = 1.0d0
else if (y <= 550.0d0) then
tmp = x + y
else if (y <= 1.75d+46) 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.0) {
tmp = 1.0;
} else if (y <= 550.0) {
tmp = x + y;
} else if (y <= 1.75e+46) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 550.0: tmp = x + y elif y <= 1.75e+46: tmp = x / (y + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 550.0) tmp = Float64(x + y); elseif (y <= 1.75e+46) 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.0) tmp = 1.0; elseif (y <= 550.0) tmp = x + y; elseif (y <= 1.75e+46) tmp = x / (y + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 550.0], N[(x + y), $MachinePrecision], If[LessEqual[y, 1.75e+46], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 550:\\
\;\;\;\;x + y\\
\mathbf{elif}\;y \leq 1.75 \cdot 10^{+46}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 1.74999999999999992e46 < y Initial program 100.0%
Taylor expanded in y around inf 75.8%
if -1 < y < 550Initial program 100.0%
Taylor expanded in y around inf 99.8%
Taylor expanded in y around 0 97.2%
Taylor expanded in x around 0 97.2%
+-commutative97.2%
Simplified97.2%
if 550 < y < 1.74999999999999992e46Initial program 100.0%
Taylor expanded in x around inf 84.1%
+-commutative84.1%
Simplified84.1%
Final simplification85.9%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 550.0) (+ x y) (if (<= y 4.6e+45) (/ x y) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 550.0) {
tmp = x + y;
} else if (y <= 4.6e+45) {
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 <= 550.0d0) then
tmp = x + y
else if (y <= 4.6d+45) 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 <= 550.0) {
tmp = x + y;
} else if (y <= 4.6e+45) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 550.0: tmp = x + y elif y <= 4.6e+45: 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 <= 550.0) tmp = Float64(x + y); elseif (y <= 4.6e+45) 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 <= 550.0) tmp = x + y; elseif (y <= 4.6e+45) 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, 550.0], N[(x + y), $MachinePrecision], If[LessEqual[y, 4.6e+45], N[(x / y), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 550:\\
\;\;\;\;x + y\\
\mathbf{elif}\;y \leq 4.6 \cdot 10^{+45}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 4.60000000000000025e45 < y Initial program 100.0%
Taylor expanded in y around inf 75.8%
if -1 < y < 550Initial program 100.0%
Taylor expanded in y around inf 99.8%
Taylor expanded in y around 0 97.2%
Taylor expanded in x around 0 97.2%
+-commutative97.2%
Simplified97.2%
if 550 < y < 4.60000000000000025e45Initial program 100.0%
Taylor expanded in x around inf 84.1%
+-commutative84.1%
Simplified84.1%
Taylor expanded in y around inf 79.4%
Final simplification85.7%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 7.4e-56) x (if (<= y 1.0) y 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 7.4e-56) {
tmp = x;
} else if (y <= 1.0) {
tmp = 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 <= 7.4d-56) then
tmp = x
else if (y <= 1.0d0) then
tmp = 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 <= 7.4e-56) {
tmp = x;
} else if (y <= 1.0) {
tmp = y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 7.4e-56: tmp = x elif y <= 1.0: tmp = y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 7.4e-56) tmp = x; elseif (y <= 1.0) tmp = 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 <= 7.4e-56) tmp = x; elseif (y <= 1.0) tmp = y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 7.4e-56], x, If[LessEqual[y, 1.0], y, 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 7.4 \cdot 10^{-56}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 70.5%
if -1 < y < 7.4000000000000004e-56Initial program 100.0%
Taylor expanded in y around 0 71.8%
if 7.4000000000000004e-56 < y < 1Initial program 99.9%
Taylor expanded in y around inf 99.9%
Taylor expanded in y around 0 88.3%
Taylor expanded in x around 0 67.6%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (/ (+ x y) y) (+ x y)))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = (x + y) / y;
} else {
tmp = 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.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = (x + y) / y
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = (x + y) / y;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = (x + y) / y else: tmp = x + y return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(Float64(x + y) / y); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.0))) tmp = (x + y) / y; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(N[(x + y), $MachinePrecision] / y), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;\frac{x + y}{y}\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in y around inf 98.7%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around inf 99.8%
Taylor expanded in y around 0 97.9%
Taylor expanded in x around 0 97.9%
+-commutative97.9%
Simplified97.9%
Final simplification98.4%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 50.0) (+ x y) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 50.0) {
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 <= 50.0d0) 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 <= 50.0) {
tmp = x + y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 50.0: 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 <= 50.0) 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 <= 50.0) 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, 50.0], N[(x + y), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 50:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 50 < y Initial program 100.0%
Taylor expanded in y around inf 70.5%
if -1 < y < 50Initial program 100.0%
Taylor expanded in y around inf 99.8%
Taylor expanded in y around 0 97.9%
Taylor expanded in x around 0 97.9%
+-commutative97.9%
Simplified97.9%
Final simplification82.8%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 5.5e-10) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 5.5e-10) {
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 <= 5.5d-10) 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 <= 5.5e-10) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 5.5e-10: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 5.5e-10) 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 <= 5.5e-10) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 5.5e-10], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{-10}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 5.4999999999999996e-10 < y Initial program 100.0%
Taylor expanded in y around inf 69.3%
if -1 < y < 5.4999999999999996e-10Initial program 100.0%
Taylor expanded in y around 0 67.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 40.7%
herbie shell --seed 2024137
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))