
(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 (+ (/ y (+ y 1.0)) (/ x (+ y 1.0))))
double code(double x, double y) {
return (y / (y + 1.0)) + (x / (y + 1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y / (y + 1.0d0)) + (x / (y + 1.0d0))
end function
public static double code(double x, double y) {
return (y / (y + 1.0)) + (x / (y + 1.0));
}
def code(x, y): return (y / (y + 1.0)) + (x / (y + 1.0))
function code(x, y) return Float64(Float64(y / Float64(y + 1.0)) + Float64(x / Float64(y + 1.0))) end
function tmp = code(x, y) tmp = (y / (y + 1.0)) + (x / (y + 1.0)); end
code[x_, y_] := N[(N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision] + N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{y}{y + 1} + \frac{x}{y + 1}
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 100.0%
+-commutative100.0%
+-commutative100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ 1.0 (/ (+ x -1.0) y))))
(if (<= y -80000.0)
t_0
(if (<= y 7.5e-92)
(/ x (+ y 1.0))
(if (<= y 0.0036) (/ y (+ y 1.0)) t_0)))))
double code(double x, double y) {
double t_0 = 1.0 + ((x + -1.0) / y);
double tmp;
if (y <= -80000.0) {
tmp = t_0;
} else if (y <= 7.5e-92) {
tmp = x / (y + 1.0);
} else if (y <= 0.0036) {
tmp = y / (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 <= (-80000.0d0)) then
tmp = t_0
else if (y <= 7.5d-92) then
tmp = x / (y + 1.0d0)
else if (y <= 0.0036d0) then
tmp = y / (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 <= -80000.0) {
tmp = t_0;
} else if (y <= 7.5e-92) {
tmp = x / (y + 1.0);
} else if (y <= 0.0036) {
tmp = y / (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 <= -80000.0: tmp = t_0 elif y <= 7.5e-92: tmp = x / (y + 1.0) elif y <= 0.0036: tmp = y / (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 <= -80000.0) tmp = t_0; elseif (y <= 7.5e-92) tmp = Float64(x / Float64(y + 1.0)); elseif (y <= 0.0036) tmp = Float64(y / 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 <= -80000.0) tmp = t_0; elseif (y <= 7.5e-92) tmp = x / (y + 1.0); elseif (y <= 0.0036) tmp = y / (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, -80000.0], t$95$0, If[LessEqual[y, 7.5e-92], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.0036], N[(y / 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 -80000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{-92}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{elif}\;y \leq 0.0036:\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -8e4 or 0.0035999999999999999 < y Initial program 100.0%
Taylor expanded in y around inf 98.5%
+-commutative98.5%
associate--l+98.5%
+-commutative98.5%
associate--r-98.5%
div-sub98.5%
Simplified98.5%
if -8e4 < y < 7.5000000000000005e-92Initial program 100.0%
Taylor expanded in x around inf 79.8%
+-commutative79.8%
Simplified79.8%
if 7.5000000000000005e-92 < y < 0.0035999999999999999Initial program 100.0%
Taylor expanded in x around 0 68.1%
+-commutative68.1%
Simplified68.1%
Final simplification88.3%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ 1.0 (/ x y))))
(if (<= y -8200000.0)
t_0
(if (<= y 5e-93)
(/ x (+ y 1.0))
(if (<= y 0.0036) (/ y (+ y 1.0)) t_0)))))
double code(double x, double y) {
double t_0 = 1.0 + (x / y);
double tmp;
if (y <= -8200000.0) {
tmp = t_0;
} else if (y <= 5e-93) {
tmp = x / (y + 1.0);
} else if (y <= 0.0036) {
tmp = y / (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 / y)
if (y <= (-8200000.0d0)) then
tmp = t_0
else if (y <= 5d-93) then
tmp = x / (y + 1.0d0)
else if (y <= 0.0036d0) then
tmp = y / (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 / y);
double tmp;
if (y <= -8200000.0) {
tmp = t_0;
} else if (y <= 5e-93) {
tmp = x / (y + 1.0);
} else if (y <= 0.0036) {
tmp = y / (y + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 + (x / y) tmp = 0 if y <= -8200000.0: tmp = t_0 elif y <= 5e-93: tmp = x / (y + 1.0) elif y <= 0.0036: tmp = y / (y + 1.0) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 + Float64(x / y)) tmp = 0.0 if (y <= -8200000.0) tmp = t_0; elseif (y <= 5e-93) tmp = Float64(x / Float64(y + 1.0)); elseif (y <= 0.0036) tmp = Float64(y / Float64(y + 1.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 + (x / y); tmp = 0.0; if (y <= -8200000.0) tmp = t_0; elseif (y <= 5e-93) tmp = x / (y + 1.0); elseif (y <= 0.0036) tmp = y / (y + 1.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -8200000.0], t$95$0, If[LessEqual[y, 5e-93], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.0036], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{x}{y}\\
\mathbf{if}\;y \leq -8200000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-93}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{elif}\;y \leq 0.0036:\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -8.2e6 or 0.0035999999999999999 < y Initial program 100.0%
Taylor expanded in y around inf 98.5%
+-commutative98.5%
associate--l+98.5%
+-commutative98.5%
associate--r-98.5%
div-sub98.5%
Simplified98.5%
Taylor expanded in x around inf 98.0%
neg-mul-198.0%
distribute-neg-frac98.0%
Simplified98.0%
sub-neg98.0%
distribute-frac-neg98.0%
remove-double-neg98.0%
+-commutative98.0%
Applied egg-rr98.0%
if -8.2e6 < y < 4.99999999999999994e-93Initial program 100.0%
Taylor expanded in x around inf 79.8%
+-commutative79.8%
Simplified79.8%
if 4.99999999999999994e-93 < y < 0.0035999999999999999Initial program 100.0%
Taylor expanded in x around 0 68.1%
+-commutative68.1%
Simplified68.1%
Final simplification88.1%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.75e-9))) (+ 1.0 (/ x y)) x))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.75e-9)) {
tmp = 1.0 + (x / 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 <= 1.75d-9))) then
tmp = 1.0d0 + (x / 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 <= 1.75e-9)) {
tmp = 1.0 + (x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 1.75e-9): tmp = 1.0 + (x / y) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.75e-9)) tmp = Float64(1.0 + Float64(x / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.75e-9))) tmp = 1.0 + (x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.75e-9]], $MachinePrecision]], N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1.75 \cdot 10^{-9}\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1 or 1.75e-9 < y Initial program 100.0%
Taylor expanded in y around inf 95.6%
+-commutative95.6%
associate--l+95.6%
+-commutative95.6%
associate--r-95.6%
div-sub95.6%
Simplified95.6%
Taylor expanded in x around inf 95.4%
neg-mul-195.4%
distribute-neg-frac95.4%
Simplified95.4%
sub-neg95.4%
distribute-frac-neg95.4%
remove-double-neg95.4%
+-commutative95.4%
Applied egg-rr95.4%
if -1 < y < 1.75e-9Initial program 100.0%
Taylor expanded in y around 0 74.6%
Final simplification85.3%
(FPCore (x y) :precision binary64 (if (or (<= y -35000.0) (not (<= y 4300000.0))) (+ 1.0 (/ x y)) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -35000.0) || !(y <= 4300000.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 <= (-35000.0d0)) .or. (.not. (y <= 4300000.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 <= -35000.0) || !(y <= 4300000.0)) {
tmp = 1.0 + (x / y);
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -35000.0) or not (y <= 4300000.0): tmp = 1.0 + (x / y) else: tmp = x / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -35000.0) || !(y <= 4300000.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 <= -35000.0) || ~((y <= 4300000.0))) tmp = 1.0 + (x / y); else tmp = x / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -35000.0], N[Not[LessEqual[y, 4300000.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 -35000 \lor \neg \left(y \leq 4300000\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -35000 or 4.3e6 < y Initial program 100.0%
Taylor expanded in y around inf 99.7%
+-commutative99.7%
associate--l+99.7%
+-commutative99.7%
associate--r-99.7%
div-sub99.7%
Simplified99.7%
Taylor expanded in x around inf 99.2%
neg-mul-199.2%
distribute-neg-frac99.2%
Simplified99.2%
sub-neg99.2%
distribute-frac-neg99.2%
remove-double-neg99.2%
+-commutative99.2%
Applied egg-rr99.2%
if -35000 < y < 4.3e6Initial program 100.0%
Taylor expanded in x around inf 73.9%
+-commutative73.9%
Simplified73.9%
Final simplification86.4%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 1.75e-9) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 1.75e-9) {
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 <= 1.75d-9) 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 <= 1.75e-9) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 1.75e-9: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 1.75e-9) 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 <= 1.75e-9) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 1.75e-9], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.75 \cdot 10^{-9}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 1.75e-9 < y Initial program 100.0%
Taylor expanded in y around inf 73.5%
if -1 < y < 1.75e-9Initial program 100.0%
Taylor expanded in y around 0 74.6%
Final simplification74.1%
(FPCore (x y) :precision binary64 (/ (+ y x) (+ y 1.0)))
double code(double x, double y) {
return (y + x) / (y + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y + x) / (y + 1.0d0)
end function
public static double code(double x, double y) {
return (y + x) / (y + 1.0);
}
def code(x, y): return (y + x) / (y + 1.0)
function code(x, y) return Float64(Float64(y + x) / Float64(y + 1.0)) end
function tmp = code(x, y) tmp = (y + x) / (y + 1.0); end
code[x_, y_] := N[(N[(y + x), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{y + x}{y + 1}
\end{array}
Initial program 100.0%
Final simplification100.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 39.7%
Final simplification39.7%
herbie shell --seed 2024018
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))