
(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 6 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 (<= y -1.05e+28)
1.0
(if (<= y 160000000000.0)
(/ x (+ y 1.0))
(if (<= y 4.8e+52) 1.0 (if (<= y 1.06e+83) (/ x y) 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -1.05e+28) {
tmp = 1.0;
} else if (y <= 160000000000.0) {
tmp = x / (y + 1.0);
} else if (y <= 4.8e+52) {
tmp = 1.0;
} else if (y <= 1.06e+83) {
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.05d+28)) then
tmp = 1.0d0
else if (y <= 160000000000.0d0) then
tmp = x / (y + 1.0d0)
else if (y <= 4.8d+52) then
tmp = 1.0d0
else if (y <= 1.06d+83) 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.05e+28) {
tmp = 1.0;
} else if (y <= 160000000000.0) {
tmp = x / (y + 1.0);
} else if (y <= 4.8e+52) {
tmp = 1.0;
} else if (y <= 1.06e+83) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.05e+28: tmp = 1.0 elif y <= 160000000000.0: tmp = x / (y + 1.0) elif y <= 4.8e+52: tmp = 1.0 elif y <= 1.06e+83: tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.05e+28) tmp = 1.0; elseif (y <= 160000000000.0) tmp = Float64(x / Float64(y + 1.0)); elseif (y <= 4.8e+52) tmp = 1.0; elseif (y <= 1.06e+83) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.05e+28) tmp = 1.0; elseif (y <= 160000000000.0) tmp = x / (y + 1.0); elseif (y <= 4.8e+52) tmp = 1.0; elseif (y <= 1.06e+83) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.05e+28], 1.0, If[LessEqual[y, 160000000000.0], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.8e+52], 1.0, If[LessEqual[y, 1.06e+83], N[(x / y), $MachinePrecision], 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.05 \cdot 10^{+28}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 160000000000:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{elif}\;y \leq 4.8 \cdot 10^{+52}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.06 \cdot 10^{+83}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.04999999999999995e28 or 1.6e11 < y < 4.8e52 or 1.05999999999999995e83 < y Initial program 100.0%
Taylor expanded in y around inf 82.7%
if -1.04999999999999995e28 < y < 1.6e11Initial program 100.0%
Taylor expanded in x around inf 85.2%
+-commutative85.2%
Simplified85.2%
if 4.8e52 < y < 1.05999999999999995e83Initial program 100.0%
Taylor expanded in x around inf 74.2%
+-commutative74.2%
Simplified74.2%
Taylor expanded in y around inf 74.2%
Final simplification83.5%
(FPCore (x y)
:precision binary64
(if (<= y -4.2e+29)
1.0
(if (<= y 1.45e-54)
(/ x (+ y 1.0))
(if (<= y 3e+52) (/ y (+ y 1.0)) (if (<= y 9.5e+82) (/ x y) 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -4.2e+29) {
tmp = 1.0;
} else if (y <= 1.45e-54) {
tmp = x / (y + 1.0);
} else if (y <= 3e+52) {
tmp = y / (y + 1.0);
} else if (y <= 9.5e+82) {
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 <= (-4.2d+29)) then
tmp = 1.0d0
else if (y <= 1.45d-54) then
tmp = x / (y + 1.0d0)
else if (y <= 3d+52) then
tmp = y / (y + 1.0d0)
else if (y <= 9.5d+82) 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 <= -4.2e+29) {
tmp = 1.0;
} else if (y <= 1.45e-54) {
tmp = x / (y + 1.0);
} else if (y <= 3e+52) {
tmp = y / (y + 1.0);
} else if (y <= 9.5e+82) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.2e+29: tmp = 1.0 elif y <= 1.45e-54: tmp = x / (y + 1.0) elif y <= 3e+52: tmp = y / (y + 1.0) elif y <= 9.5e+82: tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -4.2e+29) tmp = 1.0; elseif (y <= 1.45e-54) tmp = Float64(x / Float64(y + 1.0)); elseif (y <= 3e+52) tmp = Float64(y / Float64(y + 1.0)); elseif (y <= 9.5e+82) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.2e+29) tmp = 1.0; elseif (y <= 1.45e-54) tmp = x / (y + 1.0); elseif (y <= 3e+52) tmp = y / (y + 1.0); elseif (y <= 9.5e+82) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.2e+29], 1.0, If[LessEqual[y, 1.45e-54], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3e+52], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 9.5e+82], N[(x / y), $MachinePrecision], 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{+29}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{-54}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{elif}\;y \leq 3 \cdot 10^{+52}:\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{+82}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -4.2000000000000003e29 or 9.50000000000000049e82 < y Initial program 100.0%
Taylor expanded in y around inf 82.7%
if -4.2000000000000003e29 < y < 1.45000000000000007e-54Initial program 100.0%
Taylor expanded in x around inf 88.6%
+-commutative88.6%
Simplified88.6%
if 1.45000000000000007e-54 < y < 3e52Initial program 100.0%
Taylor expanded in x around 0 68.0%
+-commutative68.0%
Simplified68.0%
if 3e52 < y < 9.50000000000000049e82Initial program 100.0%
Taylor expanded in x around inf 74.2%
+-commutative74.2%
Simplified74.2%
Taylor expanded in y around inf 74.2%
Final simplification84.0%
(FPCore (x y) :precision binary64 (if (or (<= y -2.5e+25) (not (<= y 3700000000.0))) (+ 1.0 (/ (+ x -1.0) y)) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -2.5e+25) || !(y <= 3700000000.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 <= (-2.5d+25)) .or. (.not. (y <= 3700000000.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 <= -2.5e+25) || !(y <= 3700000000.0)) {
tmp = 1.0 + ((x + -1.0) / y);
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.5e+25) or not (y <= 3700000000.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 <= -2.5e+25) || !(y <= 3700000000.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 <= -2.5e+25) || ~((y <= 3700000000.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, -2.5e+25], N[Not[LessEqual[y, 3700000000.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 -2.5 \cdot 10^{+25} \lor \neg \left(y \leq 3700000000\right):\\
\;\;\;\;1 + \frac{x + -1}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -2.50000000000000012e25 or 3.7e9 < y Initial program 100.0%
Taylor expanded in y around inf 99.8%
associate--l+99.8%
div-sub99.8%
sub-neg99.8%
metadata-eval99.8%
Simplified99.8%
if -2.50000000000000012e25 < y < 3.7e9Initial program 100.0%
Taylor expanded in x around inf 85.6%
+-commutative85.6%
Simplified85.6%
Final simplification92.6%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 0.21) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 0.21) {
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 <= 0.21d0) 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 <= 0.21) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 0.21: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 0.21) 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 <= 0.21) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 0.21], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 0.21:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 0.209999999999999992 < y Initial program 100.0%
Taylor expanded in y around inf 72.3%
if -1 < y < 0.209999999999999992Initial program 100.0%
Taylor expanded in y around 0 85.4%
Final simplification78.6%
(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 39.4%
Final simplification39.4%
herbie shell --seed 2024077
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))