
(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 7 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
(let* ((t_0 (- 1.0 (/ (- 1.0 x) y))) (t_1 (/ x (+ y 1.0))))
(if (<= y -2.6e+40)
t_0
(if (<= y 1.25e-123)
t_1
(if (<= y 1.9e-67) (/ y (+ y 1.0)) (if (<= y 21000000.0) t_1 t_0))))))
double code(double x, double y) {
double t_0 = 1.0 - ((1.0 - x) / y);
double t_1 = x / (y + 1.0);
double tmp;
if (y <= -2.6e+40) {
tmp = t_0;
} else if (y <= 1.25e-123) {
tmp = t_1;
} else if (y <= 1.9e-67) {
tmp = y / (y + 1.0);
} else if (y <= 21000000.0) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = 1.0d0 - ((1.0d0 - x) / y)
t_1 = x / (y + 1.0d0)
if (y <= (-2.6d+40)) then
tmp = t_0
else if (y <= 1.25d-123) then
tmp = t_1
else if (y <= 1.9d-67) then
tmp = y / (y + 1.0d0)
else if (y <= 21000000.0d0) then
tmp = t_1
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 - x) / y);
double t_1 = x / (y + 1.0);
double tmp;
if (y <= -2.6e+40) {
tmp = t_0;
} else if (y <= 1.25e-123) {
tmp = t_1;
} else if (y <= 1.9e-67) {
tmp = y / (y + 1.0);
} else if (y <= 21000000.0) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 - ((1.0 - x) / y) t_1 = x / (y + 1.0) tmp = 0 if y <= -2.6e+40: tmp = t_0 elif y <= 1.25e-123: tmp = t_1 elif y <= 1.9e-67: tmp = y / (y + 1.0) elif y <= 21000000.0: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 - Float64(Float64(1.0 - x) / y)) t_1 = Float64(x / Float64(y + 1.0)) tmp = 0.0 if (y <= -2.6e+40) tmp = t_0; elseif (y <= 1.25e-123) tmp = t_1; elseif (y <= 1.9e-67) tmp = Float64(y / Float64(y + 1.0)); elseif (y <= 21000000.0) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 - ((1.0 - x) / y); t_1 = x / (y + 1.0); tmp = 0.0; if (y <= -2.6e+40) tmp = t_0; elseif (y <= 1.25e-123) tmp = t_1; elseif (y <= 1.9e-67) tmp = y / (y + 1.0); elseif (y <= 21000000.0) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 - N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.6e+40], t$95$0, If[LessEqual[y, 1.25e-123], t$95$1, If[LessEqual[y, 1.9e-67], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 21000000.0], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \frac{1 - x}{y}\\
t_1 := \frac{x}{y + 1}\\
\mathbf{if}\;y \leq -2.6 \cdot 10^{+40}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{-123}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{-67}:\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{elif}\;y \leq 21000000:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -2.6000000000000001e40 or 2.1e7 < y Initial program 99.9%
Taylor expanded in y around -inf 100.0%
mul-1-neg100.0%
unsub-neg100.0%
mul-1-neg100.0%
sub-neg100.0%
Simplified100.0%
if -2.6000000000000001e40 < y < 1.25000000000000007e-123 or 1.89999999999999994e-67 < y < 2.1e7Initial program 100.0%
Taylor expanded in x around inf 80.9%
+-commutative80.9%
Simplified80.9%
if 1.25000000000000007e-123 < y < 1.89999999999999994e-67Initial program 100.0%
Taylor expanded in x around 0 70.8%
+-commutative70.8%
Simplified70.8%
Final simplification90.2%
(FPCore (x y)
:precision binary64
(if (<= y -1.02e+49)
1.0
(if (<= y -1.0)
(/ x y)
(if (<= y 5.6e-7)
x
(if (<= y 6.2e+42) 1.0 (if (<= y 2e+58) (/ x y) 1.0))))))
double code(double x, double y) {
double tmp;
if (y <= -1.02e+49) {
tmp = 1.0;
} else if (y <= -1.0) {
tmp = x / y;
} else if (y <= 5.6e-7) {
tmp = x;
} else if (y <= 6.2e+42) {
tmp = 1.0;
} else if (y <= 2e+58) {
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.02d+49)) then
tmp = 1.0d0
else if (y <= (-1.0d0)) then
tmp = x / y
else if (y <= 5.6d-7) then
tmp = x
else if (y <= 6.2d+42) then
tmp = 1.0d0
else if (y <= 2d+58) 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.02e+49) {
tmp = 1.0;
} else if (y <= -1.0) {
tmp = x / y;
} else if (y <= 5.6e-7) {
tmp = x;
} else if (y <= 6.2e+42) {
tmp = 1.0;
} else if (y <= 2e+58) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.02e+49: tmp = 1.0 elif y <= -1.0: tmp = x / y elif y <= 5.6e-7: tmp = x elif y <= 6.2e+42: tmp = 1.0 elif y <= 2e+58: tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.02e+49) tmp = 1.0; elseif (y <= -1.0) tmp = Float64(x / y); elseif (y <= 5.6e-7) tmp = x; elseif (y <= 6.2e+42) tmp = 1.0; elseif (y <= 2e+58) tmp = Float64(x / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.02e+49) tmp = 1.0; elseif (y <= -1.0) tmp = x / y; elseif (y <= 5.6e-7) tmp = x; elseif (y <= 6.2e+42) tmp = 1.0; elseif (y <= 2e+58) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.02e+49], 1.0, If[LessEqual[y, -1.0], N[(x / y), $MachinePrecision], If[LessEqual[y, 5.6e-7], x, If[LessEqual[y, 6.2e+42], 1.0, If[LessEqual[y, 2e+58], N[(x / y), $MachinePrecision], 1.0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.02 \cdot 10^{+49}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -1:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 5.6 \cdot 10^{-7}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{+42}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2 \cdot 10^{+58}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.02e49 or 5.60000000000000038e-7 < y < 6.2000000000000003e42 or 1.99999999999999989e58 < y Initial program 99.9%
Taylor expanded in y around inf 81.2%
if -1.02e49 < y < -1 or 6.2000000000000003e42 < y < 1.99999999999999989e58Initial program 99.8%
Taylor expanded in x around inf 83.7%
+-commutative83.7%
Simplified83.7%
Taylor expanded in y around inf 77.5%
if -1 < y < 5.60000000000000038e-7Initial program 100.0%
Taylor expanded in y around 0 74.9%
Final simplification78.1%
(FPCore (x y)
:precision binary64
(if (<= y -1.1e+50)
1.0
(if (or (<= y 5.6e-7) (and (not (<= y 2.6e+43)) (<= y 1.35e+58)))
(/ x (+ y 1.0))
1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.1e+50) {
tmp = 1.0;
} else if ((y <= 5.6e-7) || (!(y <= 2.6e+43) && (y <= 1.35e+58))) {
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.1d+50)) then
tmp = 1.0d0
else if ((y <= 5.6d-7) .or. (.not. (y <= 2.6d+43)) .and. (y <= 1.35d+58)) 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.1e+50) {
tmp = 1.0;
} else if ((y <= 5.6e-7) || (!(y <= 2.6e+43) && (y <= 1.35e+58))) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.1e+50: tmp = 1.0 elif (y <= 5.6e-7) or (not (y <= 2.6e+43) and (y <= 1.35e+58)): tmp = x / (y + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.1e+50) tmp = 1.0; elseif ((y <= 5.6e-7) || (!(y <= 2.6e+43) && (y <= 1.35e+58))) 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.1e+50) tmp = 1.0; elseif ((y <= 5.6e-7) || (~((y <= 2.6e+43)) && (y <= 1.35e+58))) tmp = x / (y + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.1e+50], 1.0, If[Or[LessEqual[y, 5.6e-7], And[N[Not[LessEqual[y, 2.6e+43]], $MachinePrecision], LessEqual[y, 1.35e+58]]], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{+50}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 5.6 \cdot 10^{-7} \lor \neg \left(y \leq 2.6 \cdot 10^{+43}\right) \land y \leq 1.35 \cdot 10^{+58}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.10000000000000008e50 or 5.60000000000000038e-7 < y < 2.60000000000000021e43 or 1.3500000000000001e58 < y Initial program 99.9%
Taylor expanded in y around inf 81.2%
if -1.10000000000000008e50 < y < 5.60000000000000038e-7 or 2.60000000000000021e43 < y < 1.3500000000000001e58Initial program 100.0%
Taylor expanded in x around inf 76.7%
+-commutative76.7%
Simplified76.7%
Final simplification78.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ x (+ y 1.0))))
(if (<= x -4.4e-35)
t_0
(if (<= x 4.5e-23)
(/ y (+ y 1.0))
(if (<= x 2e+20) x (if (<= x 7.5e+87) 1.0 t_0))))))
double code(double x, double y) {
double t_0 = x / (y + 1.0);
double tmp;
if (x <= -4.4e-35) {
tmp = t_0;
} else if (x <= 4.5e-23) {
tmp = y / (y + 1.0);
} else if (x <= 2e+20) {
tmp = x;
} else if (x <= 7.5e+87) {
tmp = 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 = x / (y + 1.0d0)
if (x <= (-4.4d-35)) then
tmp = t_0
else if (x <= 4.5d-23) then
tmp = y / (y + 1.0d0)
else if (x <= 2d+20) then
tmp = x
else if (x <= 7.5d+87) then
tmp = 1.0d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x / (y + 1.0);
double tmp;
if (x <= -4.4e-35) {
tmp = t_0;
} else if (x <= 4.5e-23) {
tmp = y / (y + 1.0);
} else if (x <= 2e+20) {
tmp = x;
} else if (x <= 7.5e+87) {
tmp = 1.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x / (y + 1.0) tmp = 0 if x <= -4.4e-35: tmp = t_0 elif x <= 4.5e-23: tmp = y / (y + 1.0) elif x <= 2e+20: tmp = x elif x <= 7.5e+87: tmp = 1.0 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x / Float64(y + 1.0)) tmp = 0.0 if (x <= -4.4e-35) tmp = t_0; elseif (x <= 4.5e-23) tmp = Float64(y / Float64(y + 1.0)); elseif (x <= 2e+20) tmp = x; elseif (x <= 7.5e+87) tmp = 1.0; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x / (y + 1.0); tmp = 0.0; if (x <= -4.4e-35) tmp = t_0; elseif (x <= 4.5e-23) tmp = y / (y + 1.0); elseif (x <= 2e+20) tmp = x; elseif (x <= 7.5e+87) tmp = 1.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -4.4e-35], t$95$0, If[LessEqual[x, 4.5e-23], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2e+20], x, If[LessEqual[x, 7.5e+87], 1.0, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{y + 1}\\
\mathbf{if}\;x \leq -4.4 \cdot 10^{-35}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 4.5 \cdot 10^{-23}:\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{elif}\;x \leq 2 \cdot 10^{+20}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{+87}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -4.39999999999999987e-35 or 7.50000000000000014e87 < x Initial program 99.9%
Taylor expanded in x around inf 80.5%
+-commutative80.5%
Simplified80.5%
if -4.39999999999999987e-35 < x < 4.49999999999999975e-23Initial program 100.0%
Taylor expanded in x around 0 83.3%
+-commutative83.3%
Simplified83.3%
if 4.49999999999999975e-23 < x < 2e20Initial program 100.0%
Taylor expanded in y around 0 88.7%
if 2e20 < x < 7.50000000000000014e87Initial program 99.9%
Taylor expanded in y around inf 66.5%
Final simplification81.1%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 5.6e-7) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 5.6e-7) {
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.6d-7) 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.6e-7) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 5.6e-7: 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.6e-7) 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.6e-7) 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.6e-7], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 5.6 \cdot 10^{-7}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 5.60000000000000038e-7 < y Initial program 99.9%
Taylor expanded in y around inf 72.8%
if -1 < y < 5.60000000000000038e-7Initial program 100.0%
Taylor expanded in y around 0 74.9%
Final simplification73.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 41.9%
Final simplification41.9%
herbie shell --seed 2023274
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))