文章目录
- [Technical Documentation: `limsup_inf` -- Limit Superior and Limit Inferior of Set Sequences](#Technical Documentation:
limsup_inf– Limit Superior and Limit Inferior of Set Sequences) -
- Overview
- [Mathematical Background](#Mathematical Background)
- Dependencies
- [Module Functions](#Module Functions)
-
- `format_interval(obj)`
- [`get_approach(expr, var, L)`](#
get_approach(expr, var, L)) - [`subsequence_limset(expr, left, var, name="subsequence", verbose=True)`](#
subsequence_limset(expr, left, var, name="subsequence", verbose=True)) - [`analyze_general(expr_list, modulus, left=5, var=n, verbose=True)`](#
analyze_general(expr_list, modulus, left=5, var=n, verbose=True))
- [Usage Examples](#Usage Examples)
-
- [Example 1: Odd/Even Segmentation (m=2)](#Example 1: Odd/Even Segmentation (m=2))
- [Example 2: Three Subsequences (m=3)](#Example 2: Three Subsequences (m=3))
- [Example 3: Four Subsequences (m=4)](#Example 3: Four Subsequences (m=4))
- [Interpreting the Output](#Interpreting the Output)
- [Limitations and Assumptions](#Limitations and Assumptions)
- [How to Extend](#How to Extend)
- Source
Technical Documentation: limsup_inf -- Limit Superior and Limit Inferior of Set Sequences
Overview
limsup_inf is a Python module for computing the limit superior (limsup) and limit inferior (liminf) of a sequence of sets { A n } n = 1 ∞ \{A_n\}_{n=1}^\infty {An}n=1∞ that is defined by modular segmentation . It is particularly useful in real analysis and measure theory , where set sequences are often given by different formulas for different residue classes modulo m m m. The program handles:
- Arbitrary modulus m m m (number of subsequences).
- Left‑hand endpoint constant L L L (common to all sets).
- Right‑hand endpoints that are rational, algebraic, or simple transcendental functions of n n n.
- Automatic detection of convergence from above/below and correct interval openness.
- Empty sets and singleton limits.
Mathematical Background
For a sequence of sets { A n } n = 1 ∞ \{A_n\}_{n=1}^\infty {An}n=1∞, the upper limit and lower limit are defined as:
lim sup n → ∞ A n = ⋂ n = 1 ∞ ⋃ k = n ∞ A k , lim inf n → ∞ A n = ⋃ n = 1 ∞ ⋂ k = n ∞ A k . \limsup_{n\to\infty} A_n = \bigcap_{n=1}^\infty \bigcup_{k=n}^\infty A_k, \qquad \liminf_{n\to\infty} A_n = \bigcup_{n=1}^\infty \bigcap_{k=n}^\infty A_k. n→∞limsupAn=n=1⋂∞k=n⋃∞Ak,n→∞liminfAn=n=1⋃∞k=n⋂∞Ak.
If the sequence is segmented into m m m subsequences by the residue of the index modulo m m m:
A m n + r = L , f r ( n ) , r = 0 , 1 , ... , m − 1 , n = 1 , 2 , ... A_{m n + r} = L,\\ f_r(n), \quad r = 0,1,\dots,m-1, \quad n=1,2,\dots Amn+r=L, fr(n),r=0,1,...,m−1,n=1,2,...
then the limit set of each subsequence is:
lim n → ∞ A m n + r = { L , lim f r ( n ) if f r ( n ) → c from above , L , c ) if f r ( n ) → c from below , { L } if c = L and approached from above , ∅ if c \< L or ( c = L approached from below ) . \\lim_{n\\to\\infty} A_{m n + r} = \\begin{cases} \[L,\\ \\lim f_r(n) & \text{if } f_r(n) \to c \text{ from above},\\ L,\\ c) \& \\text{if } f_r(n) \\to c \\text{ from below},\\\\ \\{L\\} \& \\text{if } c = L \\text{ and approached from above},\\\\ \\emptyset \& \\text{if } c \< L \\text{ or } (c = L \\text{ approached from below}). \\end{cases} n→∞limAmn+r=⎩ ⎨ ⎧\[L, limfr(n)[L, c){L}∅if fr(n)→c from above,if fr(n)→c from below,if c=L and approached from above,if c<L or (c=L approached from below).
Finally:
lim inf A n = ⋂ r = 0 m − 1 ( lim n → ∞ A m n + r ) , lim sup A n = ⋃ r = 0 m − 1 ( lim n → ∞ A m n + r ) . \liminf A_n = \bigcap_{r=0}^{m-1} \left(\lim_{n\to\infty} A_{m n + r}\right), \qquad \limsup A_n = \bigcup_{r=0}^{m-1} \left(\lim_{n\to\infty} A_{m n + r}\right). liminfAn=r=0⋂m−1(n→∞limAmn+r),limsupAn=r=0⋃m−1(n→∞limAmn+r).
Dependencies
- Python 3.8 or higher
- SymPy (>= 1.9) -- symbolic computation
Install SymPy via pip if not already installed:
bash
pip install sympy
Module Functions
format_interval(obj)
Converts SymPy set objects (Interval, FiniteSet, EmptySet) to human‑readable strings like [a, b], [a, b), {c}, or ∅.
get_approach(expr, var, L)
Determines whether the expression expr(var) approaches the limit L from above ('above'), from below ('below'), equals L exactly ('equal'), or unknown ('unknown').
subsequence_limset(expr, left, var, name="subsequence", verbose=True)
Computes the limit set of a single subsequence whose right endpoint is expr(var) and left endpoint is left. Returns a SymPy set and prints detailed steps if verbose=True.
analyze_general(expr_list, modulus, left=5, var=n, verbose=True)
Main entry point.
Parameters:
expr_list: list of SymPy expressions of lengthmodulus;expr_list[r]corresponds to f r ( n ) f_r(n) fr(n) for A m n + r A_{m n + r} Amn+r.modulus: integer m ≥ 2 m \ge 2 m≥2.left: constant left endpoint L L L (default 5).var: symbolic variable (defaultnfromsympy.abc).verbose: ifTrue, prints the full calculation process for each subsequence and the final intersection/union.
Returns : a tuple (liminf_set, limsup_set) as SymPy objects.
Usage Examples
Example 1: Odd/Even Segmentation (m=2)
python
from sympy import symbols
from sympy.abc import n
from limsup_inf import analyze_general
expr_list = [
7 + n/(n+1) + n/(n**2), # A_{2n}
10 - 3*n/(n**2) - 1/n # A_{2n+1}
]
liminf, limsup = analyze_general(expr_list, modulus=2, left=5)
Output (abbreviated):
--- 汇总 ---
A_{2n + 0} 的极限集合: [5, 8]
A_{2n + 1} 的极限集合: [5, 10)
下限集 (liminf) = [5, 8] ∩ [5, 10) = [5, 8]
上限集 (limsup) = [5, 8] ∪ [5, 10) = [5, 10)
Example 2: Three Subsequences (m=3)
python
expr_list = [
5 + 1/n, # A_{3n} → {5}
6 + n**(-2), # A_{3n+1} → [5,6]
7 + 2/n # A_{3n+2} → [5,7)
]
liminf, limsup = analyze_general(expr_list, modulus=3, left=5)
Output:
下限集 (liminf) = {5} ∩ [5, 6] ∩ [5, 7) = {5}
上限集 (limsup) = {5} ∪ [5, 6] ∪ [5, 7) = [5, 7)
Example 3: Four Subsequences (m=4)
python
expr_list = [
5 + 1/n, # A_{4n} → {5}
6 + 1/(n**2), # A_{4n+1} → [5,6]
7 + 2/n, # A_{4n+2} → [5,7)
8 + 3/n # A_{4n+3} → [5,8)
]
liminf, limsup = analyze_general(expr_list, modulus=4, left=5)
Output:
下限集 (liminf) = {5} ∩ [5,6] ∩ [5,7) ∩ [5,8) = {5}
上限集 (limsup) = {5} ∪ [5,6] ∪ [5,7) ∪ [5,8) = [5,8)
Interpreting the Output
The program prints every step:
-
For each subsequence, it shows:
- Right‑hand expression.
- Limit value.
- Difference limit f r ( n ) − L f_r(n) - L fr(n)−L.
- Approach direction (above/below).
- Resulting limit set with proper openness.
-
The summary lists all subsequence limit sets.
-
Finally, the liminf and limsup are computed as the intersection and union of these sets, respectively, displayed with full symbolic notation.
Limitations and Assumptions
- The left endpoint L L L is assumed constant (not depending on n n n).
- The approach direction detection relies on multiplying the difference f r ( n ) − L f_r(n) - L fr(n)−L by n k n^k nk and taking limits. This works well for polynomials, rational functions, and combinations of rational functions with 1 / n 1/n 1/n or 1 / n 2 1/n^2 1/n2. For more exotic functions (e.g., exp ( − n ) \exp(-n) exp(−n), log ( n ) / n \log(n)/n log(n)/n), the detection may fall back to a conservative closed‑interval assumption; manual verification is advised.
- The sequence indices are assumed to start at n = 1 n=1 n=1 for all subsequences.
- Infinite limits ( ± ∞ \pm\infty ±∞) are treated as empty sets.
How to Extend
- Different starting index : If your sequence starts at n = 0 n=0 n=0, redefine
varaccordingly or shift the expressions. - Variable left endpoint : Modify
subsequence_limsetto accept a left expressionleft_exprand compute its limit. - More than one variable: The current design is for single‑variable sequences. For multivariate sequences, additional logic is needed.
Source
https://gitee.com/waterruby/ANNA.git
bash
============================================================
示例 1:模 2(奇偶分段)
============================================================
============================================================
集合序列定义(模 2 分段):
A_{2n + 0} = [5, n/(n + 1) + 7 + 1/n]
A_{2n + 1} = [5, 10 - 4/n]
============================================================
--- 分析 A_{2n + 0} ---
右端点表达式: n/(n + 1) + 7 + 1/n
左端点: 5
右端点极限: 8
右端点 - 左端点 的极限: 3
趋近方向: above
从上方趋近,极限区间为 闭区间: [5, 8]
--- 分析 A_{2n + 1} ---
右端点表达式: 10 - 4/n
左端点: 5
右端点极限: 10
右端点 - 左端点 的极限: 5
趋近方向: below
从下方趋近,极限区间为 右开区间: [5, 10)
--- 汇总 ---
A_{2n + 0} 的极限集合: [5, 8]
A_{2n + 1} 的极限集合: [5, 10)
下限集 (liminf) = [5, 8] ∩ [5, 10) = [5, 8]
上限集 (limsup) = [5, 8] ∪ [5, 10) = [5, 10)
============================================================
示例 2:模 3(三项分段)
============================================================
============================================================
集合序列定义(模 3 分段):
A_{3n + 0} = [5, 5 + 1/n]
A_{3n + 1} = [5, 6 + n**(-2)]
A_{3n + 2} = [5, 7 + 2/n]
============================================================
--- 分析 A_{3n + 0} ---
右端点表达式: 5 + 1/n
左端点: 5
右端点极限: 5
右端点 - 左端点 的极限: 0
趋近方向: above
从上方趋近,极限区间为 单点集: {5}
--- 分析 A_{3n + 1} ---
右端点表达式: 6 + n**(-2)
左端点: 5
右端点极限: 6
右端点 - 左端点 的极限: 1
趋近方向: above
从上方趋近,极限区间为 闭区间: [5, 6]
--- 分析 A_{3n + 2} ---
右端点表达式: 7 + 2/n
左端点: 5
右端点极限: 7
右端点 - 左端点 的极限: 2
趋近方向: above
从上方趋近,极限区间为 闭区间: [5, 7]
--- 汇总 ---
A_{3n + 0} 的极限集合: {5}
A_{3n + 1} 的极限集合: [5, 6]
A_{3n + 2} 的极限集合: [5, 7]
下限集 (liminf) = {5} ∩ [5, 6] ∩ [5, 7] = {5}
上限集 (limsup) = {5} ∪ [5, 6] ∪ [5, 7] = [5, 7]
============================================================
示例 3:模 4(四项分段)
============================================================
============================================================
集合序列定义(模 4 分段):
A_{4n + 0} = [5, 5 + 1/n]
A_{4n + 1} = [5, 6 + n**(-2)]
A_{4n + 2} = [5, 7 + 2/n]
A_{4n + 3} = [5, 8 + 3/n]
============================================================
--- 分析 A_{4n + 0} ---
右端点表达式: 5 + 1/n
左端点: 5
右端点极限: 5
右端点 - 左端点 的极限: 0
趋近方向: above
从上方趋近,极限区间为 单点集: {5}
--- 分析 A_{4n + 1} ---
右端点表达式: 6 + n**(-2)
左端点: 5
右端点极限: 6
右端点 - 左端点 的极限: 1
趋近方向: above
从上方趋近,极限区间为 闭区间: [5, 6]
--- 分析 A_{4n + 2} ---
右端点表达式: 7 + 2/n
左端点: 5
右端点极限: 7
右端点 - 左端点 的极限: 2
趋近方向: above
从上方趋近,极限区间为 闭区间: [5, 7]
--- 分析 A_{4n + 3} ---
右端点表达式: 8 + 3/n
左端点: 5
右端点极限: 8
右端点 - 左端点 的极限: 3
趋近方向: above
从上方趋近,极限区间为 闭区间: [5, 8]
--- 汇总 ---
A_{4n + 0} 的极限集合: {5}
A_{4n + 1} 的极限集合: [5, 6]
A_{4n + 2} 的极限集合: [5, 7]
A_{4n + 3} 的极限集合: [5, 8]
下限集 (liminf) = {5} ∩ [5, 6] ∩ [5, 7] ∩ [5, 8] = {5}
上限集 (limsup) = {5} ∪ [5, 6] ∪ [5, 7] ∪ [5, 8] = [5, 8]