
(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%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ 1.0 (/ (+ x -1.0) y))))
(if (<= y -3400000000.0)
t_0
(if (<= y -2.55e-54)
(/ y (+ y 1.0))
(if (<= y 34500000000000.0) (/ x (+ y 1.0)) t_0)))))
double code(double x, double y) {
double t_0 = 1.0 + ((x + -1.0) / y);
double tmp;
if (y <= -3400000000.0) {
tmp = t_0;
} else if (y <= -2.55e-54) {
tmp = y / (y + 1.0);
} else if (y <= 34500000000000.0) {
tmp = x / (y + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = 1.0d0 + ((x + (-1.0d0)) / y)
if (y <= (-3400000000.0d0)) then
tmp = t_0
else if (y <= (-2.55d-54)) then
tmp = y / (y + 1.0d0)
else if (y <= 34500000000000.0d0) then
tmp = x / (y + 1.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 + ((x + -1.0) / y);
double tmp;
if (y <= -3400000000.0) {
tmp = t_0;
} else if (y <= -2.55e-54) {
tmp = y / (y + 1.0);
} else if (y <= 34500000000000.0) {
tmp = x / (y + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 + ((x + -1.0) / y) tmp = 0 if y <= -3400000000.0: tmp = t_0 elif y <= -2.55e-54: tmp = y / (y + 1.0) elif y <= 34500000000000.0: tmp = x / (y + 1.0) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 + Float64(Float64(x + -1.0) / y)) tmp = 0.0 if (y <= -3400000000.0) tmp = t_0; elseif (y <= -2.55e-54) tmp = Float64(y / Float64(y + 1.0)); elseif (y <= 34500000000000.0) tmp = Float64(x / Float64(y + 1.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 + ((x + -1.0) / y); tmp = 0.0; if (y <= -3400000000.0) tmp = t_0; elseif (y <= -2.55e-54) tmp = y / (y + 1.0); elseif (y <= 34500000000000.0) tmp = x / (y + 1.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3400000000.0], t$95$0, If[LessEqual[y, -2.55e-54], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 34500000000000.0], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{x + -1}{y}\\
\mathbf{if}\;y \leq -3400000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -2.55 \cdot 10^{-54}:\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{elif}\;y \leq 34500000000000:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.4e9 or 3.45e13 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
associate--l+100.0%
div-sub100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
if -3.4e9 < y < -2.55000000000000005e-54Initial program 100.0%
Taylor expanded in x around 0 78.7%
+-commutative78.7%
Simplified78.7%
if -2.55000000000000005e-54 < y < 3.45e13Initial program 100.0%
Taylor expanded in x around inf 73.0%
+-commutative73.0%
Simplified73.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ 1.0 (/ -1.0 y))))
(if (<= y -1.0)
t_0
(if (<= y -2.7e-54) y (if (<= y 34500000000000.0) x t_0)))))
double code(double x, double y) {
double t_0 = 1.0 + (-1.0 / y);
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= -2.7e-54) {
tmp = y;
} else if (y <= 34500000000000.0) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = 1.0d0 + ((-1.0d0) / y)
if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= (-2.7d-54)) then
tmp = y
else if (y <= 34500000000000.0d0) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 + (-1.0 / y);
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= -2.7e-54) {
tmp = y;
} else if (y <= 34500000000000.0) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 + (-1.0 / y) tmp = 0 if y <= -1.0: tmp = t_0 elif y <= -2.7e-54: tmp = y elif y <= 34500000000000.0: tmp = x else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 + Float64(-1.0 / y)) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= -2.7e-54) tmp = y; elseif (y <= 34500000000000.0) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 + (-1.0 / y); tmp = 0.0; if (y <= -1.0) tmp = t_0; elseif (y <= -2.7e-54) tmp = y; elseif (y <= 34500000000000.0) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(-1.0 / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, -2.7e-54], y, If[LessEqual[y, 34500000000000.0], x, t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{-1}{y}\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -2.7 \cdot 10^{-54}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 34500000000000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 3.45e13 < y Initial program 100.0%
Taylor expanded in x around 0 73.5%
+-commutative73.5%
Simplified73.5%
Taylor expanded in y around inf 73.5%
if -1 < y < -2.70000000000000026e-54Initial program 100.0%
Taylor expanded in x around 0 76.6%
+-commutative76.6%
Simplified76.6%
Taylor expanded in y around 0 73.0%
if -2.70000000000000026e-54 < y < 3.45e13Initial program 100.0%
Taylor expanded in y around 0 71.5%
Final simplification72.5%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y -2.5e-60) y (if (<= y 34500000000000.0) x 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= -2.5e-60) {
tmp = y;
} else if (y <= 34500000000000.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 <= (-2.5d-60)) then
tmp = y
else if (y <= 34500000000000.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 <= -2.5e-60) {
tmp = y;
} else if (y <= 34500000000000.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= -2.5e-60: tmp = y elif y <= 34500000000000.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 <= -2.5e-60) tmp = y; elseif (y <= 34500000000000.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 <= -2.5e-60) tmp = y; elseif (y <= 34500000000000.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, -2.5e-60], y, If[LessEqual[y, 34500000000000.0], x, 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -2.5 \cdot 10^{-60}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 34500000000000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 3.45e13 < y Initial program 100.0%
Taylor expanded in y around inf 73.2%
if -1 < y < -2.5000000000000001e-60Initial program 100.0%
Taylor expanded in x around 0 76.6%
+-commutative76.6%
Simplified76.6%
Taylor expanded in y around 0 73.0%
if -2.5000000000000001e-60 < y < 3.45e13Initial program 100.0%
Taylor expanded in y around 0 71.5%
(FPCore (x y) :precision binary64 (if (or (<= x -7500000000.0) (not (<= x 3.9e+43))) (/ x (+ y 1.0)) (/ y (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -7500000000.0) || !(x <= 3.9e+43)) {
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 <= (-7500000000.0d0)) .or. (.not. (x <= 3.9d+43))) 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 <= -7500000000.0) || !(x <= 3.9e+43)) {
tmp = x / (y + 1.0);
} else {
tmp = y / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -7500000000.0) or not (x <= 3.9e+43): tmp = x / (y + 1.0) else: tmp = y / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -7500000000.0) || !(x <= 3.9e+43)) 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 <= -7500000000.0) || ~((x <= 3.9e+43))) tmp = x / (y + 1.0); else tmp = y / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -7500000000.0], N[Not[LessEqual[x, 3.9e+43]], $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 -7500000000 \lor \neg \left(x \leq 3.9 \cdot 10^{+43}\right):\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y + 1}\\
\end{array}
\end{array}
if x < -7.5e9 or 3.9000000000000001e43 < x Initial program 100.0%
Taylor expanded in x around inf 81.3%
+-commutative81.3%
Simplified81.3%
if -7.5e9 < x < 3.9000000000000001e43Initial program 100.0%
Taylor expanded in x around 0 74.6%
+-commutative74.6%
Simplified74.6%
Final simplification77.5%
(FPCore (x y) :precision binary64 (if (<= y -6.5e+53) 1.0 (if (<= y 2.8e+43) (/ x (+ y 1.0)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -6.5e+53) {
tmp = 1.0;
} else if (y <= 2.8e+43) {
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 <= (-6.5d+53)) then
tmp = 1.0d0
else if (y <= 2.8d+43) 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 <= -6.5e+53) {
tmp = 1.0;
} else if (y <= 2.8e+43) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6.5e+53: tmp = 1.0 elif y <= 2.8e+43: tmp = x / (y + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -6.5e+53) tmp = 1.0; elseif (y <= 2.8e+43) 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 <= -6.5e+53) tmp = 1.0; elseif (y <= 2.8e+43) tmp = x / (y + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6.5e+53], 1.0, If[LessEqual[y, 2.8e+43], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{+53}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{+43}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -6.50000000000000017e53 or 2.80000000000000019e43 < y Initial program 100.0%
Taylor expanded in y around inf 78.8%
if -6.50000000000000017e53 < y < 2.80000000000000019e43Initial program 100.0%
Taylor expanded in x around inf 68.6%
+-commutative68.6%
Simplified68.6%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 34500000000000.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 34500000000000.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 <= 34500000000000.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 <= 34500000000000.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 34500000000000.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 <= 34500000000000.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 <= 34500000000000.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, 34500000000000.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 34500000000000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 3.45e13 < y Initial program 100.0%
Taylor expanded in y around inf 73.2%
if -1 < y < 3.45e13Initial program 100.0%
Taylor expanded in y around 0 68.0%
(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 35.4%
herbie shell --seed 2024145
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))