Librărie pentru secvențe numerice
Project description
NumSeq - Python Library 🧮
NumSeq is a Python library that generates well-known number sequences.
It provides simple and efficient functions for creating sequences like natural numbers, odd numbers, and many classical mathematical sequences. Some of the sequences you can generate include:
- Perfect squares and perfect cubes
- Triangular numbers and tetrahedral numbers
- Fibonacci and Tribonacci numbers
- Lucas numbers
- Catalan numbers
- Padovan and Perrin numbers
- Motzkin numbers
- Armstrong numbers
- Perfect numbers
- Collatz sequence
- Harshad numbers
- Hamming numbers
- Mersenne and Fermat numbers
- Pell numbers
Each function is designed to be intuitive, with clear parameters and return values, allowing you to quickly generate sequences for learning, testing, or computational purposes.
You can find the library and install it from PyPI.
Available Functions
1. naturals0(n) 🌱
- Description: Returns the first
n+1natural numbers starting from 0. - Parameter:
n(int) – the number up to which the sequence is generated (inclusive). Must be a positive number.
- Returns:
- List of integers
[0, 1, 2, ..., n].
- List of integers
- Example:
naturals0(5) # returns [0, 1, 2, 3, 4, 5]
2. naturals(n) 🌿
- Description: Returns the first
nnatural numbers starting from 1. - Parameter:
n(int) – the number of natural numbers to generate. Must be a positive number.
- Returns:
- List of integers
[1, 2, 3, ..., n].
- List of integers
- Example:
naturals(5) # returns [1, 2, 3, 4, 5]
3. odd_numbers_up_to(n) 🔢
- Description: Returns all odd numbers from 1 up to
n(inclusive ifnis odd). - Parameter:
n(int) – the upper limit for generating odd numbers. Must be a positive number.
- Returns:
- List of odd numbers
[1, 3, 5, ..., ≤ n].
- List of odd numbers
- Example:
odd_numbers_up_to(10) # returns [1, 3, 5, 7, 9]
4. first_odd_numbers(n) 🌟
- Description: Returns the first
nodd numbers. - Parameter:
n(int) – the number of odd numbers to generate. Must be a positive number.
- Returns:
- List of the first
nodd numbers[1, 3, 5, ..., (2*n-1)].
- List of the first
- Example:
first_odd_numbers(5) # returns [1, 3, 5, 7, 9]
5. even_numbers_up_to(n) ⚡
- Description: Returns all even numbers from 0 up to
n(exclusive). - Parameter:
n(int) – the upper limit for generating even numbers. Must be a positive number.
- Returns:
- List of even numbers
[0, 2, 4, ..., < n].
- List of even numbers
- Example:
even_numbers_up_to(10) # returns [0, 2, 4, 6, 8]
6. first_even_numbers(n) 💧
- Description: Returns the first
neven numbers starting from 0. - Parameter:
n(int) – the number of even numbers to generate. Must be a positive number.
- Returns:
- List of the first
neven numbers[0, 2, 4, ..., 2*(n-1)].
- List of the first
- Example:
first_even_numbers(5) # returns [0, 2, 4, 6, 8]
7. perfect_squares_up_to(n) 🔲
- Description: Returns all perfect square numbers less than or equal to
n. - Parameter:
n(int) – the upper limit for generating perfect squares. Must be a positive number.
- Returns:
- List of perfect squares
[0, 1, 4, 9, ..., ≤ n].
- List of perfect squares
- Example:
perfect_squares_up_to(10) # returns [0, 1, 4, 9]
8. first_perfect_square_numbers(n) ✨
- Description: Returns the first
nperfect square numbers starting from 0. - Parameter:
n(int) – the number of perfect squares to generate. Must be a positive number.
- Returns:
- List of the first
nperfect squares[0, 1, 4, 9, ..., (n-1)^2].
- List of the first
- Example:
first_perfect_square_numbers(5) # returns [0, 1, 4, 9, 16]
9. perfect_cubes_up_to(n) 🟫
- Description: Returns all perfect cube numbers less than or equal to
n. - Parameter:
n(int) – the upper limit for generating perfect cubes. Must be a positive number.
- Returns:
- List of perfect cubes
[0, 1, 8, 27, ..., ≤ n].
- List of perfect cubes
- Example:
perfect_cubes_up_to(30) # returns [0, 1, 8, 27]
10. first_perfect_cube_numbers(n) 🔹
- Description: Returns the first
nperfect cube numbers starting from 0. - Parameter:
n(int) – the number of perfect cubes to generate. Must be a positive number.
- Returns:
- List of the first
nperfect cubes[0, 1, 8, 27, ..., (n-1)^3].
- List of the first
- Example:
first_perfect_cube_numbers(5) # returns [0, 1, 8, 27, 64]
11. triangular_numbers_up_to(n) 🔺
- Description: Returns all triangular numbers less than or equal to
n. - Formula:
T_k = k * (k + 1) / 2, whereT_kis the k-th triangular number. - Parameter:
n(int) – the upper limit for generating triangular numbers. Must be a positive number.
- Returns:
- List of triangular numbers
[1, 3, 6, 10, ..., ≤ n].
- List of triangular numbers
- Example:
triangular_numbers_up_to(15) # returns [1, 3, 6, 10, 15]
12. first_triangular_numbers(n) 🔹
- Description: Returns the first
ntriangular numbers starting from 1. - Formula:
T_k = k * (k + 1) / 2 - Parameter:
n(int) – the number of triangular numbers to generate. Must be a positive number.
- Returns:
- List of the first
ntriangular numbers[1, 3, 6, 10, ..., T_n].
- List of the first
- Example:
first_triangular_numbers(5) # returns [1, 3, 6, 10, 15]
13. tetrahedral_numbers_up_to(n) 🔷
- Description: Returns all tetrahedral numbers less than or equal to
n. - Formula:
Te_k = k * (k + 1) * (k + 2) / 6, whereTe_kis the k-th tetrahedral number. - Parameter:
n(int) – the upper limit for generating tetrahedral numbers. Must be a positive number.
- Returns:
- List of tetrahedral numbers
[1, 4, 10, 20, ..., ≤ n].
- List of tetrahedral numbers
- Example:
tetrahedral_numbers_up_to(20) # returns [1, 4, 10, 20]
14. first_tetrahedral_numbers(n) 🔹
- Description: Returns the first
ntetrahedral numbers starting from 1. - Formula:
Te_k = k * (k + 1) * (k + 2) / 6 - Parameter:
n(int) – the number of tetrahedral numbers to generate. Must be a positive number.
- Returns:
- List of the first
ntetrahedral numbers[1, 4, 10, 20, ..., Te_n].
- List of the first
- Example:
first_tetrahedral_numbers(5) # returns [1, 4, 10, 20, 35]
15. prime_numbers_up_to(n) 🥇
- Description: Returns all prime numbers less than or equal to
n. - Parameter:
n(int) – the upper limit for generating prime numbers. Must be a positive number.
- Returns:
- List of prime numbers
[2, 3, 5, 7, ..., ≤ n].
- List of prime numbers
- Example:
prime_numbers_up_to(10) # returns [2, 3, 5, 7]
16. first_prime_numbers(n) 🔢
- Description: Returns the first
nprime numbers starting from 2. - Parameter:
n(int) – the number of prime numbers to generate. Must be a positive number.
- Returns:
- List of the first
nprime numbers[2, 3, 5, 7, ..., P_n].
- List of the first
- Example:
first_prime_numbers(5) # returns [2, 3, 5, 7, 11]
17. fibonacci_numbers_up_to(n) 🌊
- Description: Returns all Fibonacci numbers less than or equal to
n. - Parameter:
n(int) – the upper limit for generating Fibonacci numbers. Must be a positive number.
- Returns:
- List of Fibonacci numbers
[0, 1, 1, 2, 3, 5, 8, ..., ≤ n].
- List of Fibonacci numbers
- Fibonacci numbers formula:
$$ F_0 = 0, \quad F_1 = 1, \quad F_n = F_{n-1} + F_{n-2}, \quad n \ge 2 $$
- Example:
fibonacci_numbers_up_to(10) # returns [0, 1, 1, 2, 3, 5, 8]
18. first_fibonacci_numbers(n) 🔢
- Description: Returns the first
nFibonacci numbers. - Parameter:
n(int) – the number of Fibonacci numbers to generate. Must be greater than 1.
- Returns:
- List of the first
nFibonacci numbers[0, 1, 1, 2, 3, 5, ...].
- List of the first
- Fibonacci numbers formula:
$$ F_0 = 0, \quad F_1 = 1, \quad F_n = F_{n-1} + F_{n-2}, \quad n \ge 2 $$
- Example:
first_fibonacci_numbers(7) # returns [0, 1, 1, 2, 3, 5, 8]
19. lucas_numbers_up_to(n) 🌟
- Description: Returns all Lucas numbers less than or equal to
n. - Parameter:
n(int) – the upper limit for generating Lucas numbers. Must be a positive number.
- Returns:
- List of Lucas numbers
[2, 1, 3, 4, 7, 11, 18, ..., ≤ n].
- List of Lucas numbers
- Lucas numbers formula:
$$ L_0 = 2, \quad L_1 = 1, \quad L_n = L_{n-1} + L_{n-2}, \quad n \ge 2 $$
- Example:
lucas_numbers_up_to(20) # returns [2, 1, 3, 4, 7, 11, 18]
20. first_lucas_numbers(n) 🔢
- Description: Returns the first
nLucas numbers. - Parameter:
n(int) – the number of Lucas numbers to generate. Must be greater than 1.
- Returns:
- List of the first
nLucas numbers[2, 1, 3, 4, 7, 11, ...].
- List of the first
- Lucas numbers formula:
$$ L_0 = 2, \quad L_1 = 1, \quad L_n = L_{n-1} + L_{n-2}, \quad n \ge 2 $$
- Example:
first_lucas_numbers(7) # returns [2, 1, 3, 4, 7, 11, 18]
21. catalan_numbers_up_to(n) 🧮
- Description: Returns all Catalan numbers less than or equal to
n. - Parameter:
n(int) – the upper limit for generating Catalan numbers. Must be a positive number.
- Returns:
- List of Catalan numbers
[1, 1, 2, 5, 14, 42, ..., ≤ n].
- List of Catalan numbers
- Catalan numbers formula:
$$ C_n = \frac{(2n)!}{(n+1)! * n!}, \quad n \ge 0 $$
- Example:
catalan_numbers_up_to(20) # returns [1, 1, 2, 5, 14]
22. first_catalan_numbers(n) 🔢
- Description: Returns the first
nCatalan numbers. - Parameter:
n(int) – the number of Catalan numbers to generate. Must be a positive number.
- Returns:
- List of the first
nCatalan numbers[1, 1, 2, 5, 14, ...].
- List of the first
- Catalan numbers formula:
$$ C_n = \frac{(2n)!}{(n+1)! * n!}, \quad n \ge 0 $$
- Example:
first_catalan_numbers(7) # returns [1, 1, 2, 5, 14, 42, 132]
23. factorial_numbers_up_to(n) 🔢
- Description: Returns all factorial numbers less than or equal to
n. - Parameter:
n(int) – the maximum value up to which factorial numbers are generated. Must be a positive number.
- Returns:
- List of factorial numbers
[1, 2, 6, 24, ...]that are less than or equal ton.
- List of factorial numbers
- Example:
factorial_numbers_up_to(30) # returns [1, 2, 6, 24]
24. first_factorial_numbers(n) 🔢
- Description: Returns the first
nfactorial numbers. - Parameter:
n(int) – the number of factorial numbers to generate. Must be a positive number.
- Returns:
- List of the first
nfactorial numbers[1, 1, 2, 6, 24, ...].
- List of the first
- Factorial numbers formula:
$$ n! = 1 \cdot 2 \cdot 3 \cdot \dots \cdot n, \quad n \ge 0 $$
- Example:
first_factorial_numbers(7) # returns [1, 1, 2, 6, 24, 120, 720]
25.padovan_numbers_up_to(n) 🔢
- Description: Returns all Padovan numbers less than or equal to
n. - Parameter:
n(int) – the maximum value for Padovan numbers. Must be a positive number greater than 0.
- Returns:
- List of Padovan numbers
[1, 1, 1, 2, 2, 3, 4, 5, 7, ...]up ton.
- List of Padovan numbers
- Padovan numbers formula (recurrence relation):
$$ P(n) = P(n-2) + P(n-3), \quad P(0)=P(1)=P(2)=1, \quad n \ge 0 $$
- Example:
padovan_numbers_up_to(10) # returns [1, 1, 1, 2, 2, 3, 4, 5, 7, 9]
26.first_padovan_numbers(n) 🔢
- Description: Returns the first
nPadovan numbers. - Parameter:
n(int) – the number of Padovan numbers to generate. Must be a positive number.
- Returns:
- List of the first
nPadovan numbers[1, 1, 1, 2, 2, 3, 4, 5, 7, ...].
- List of the first
- Padovan numbers formula (recurrence relation):
$$ P(n) = P(n-2) + P(n-3), \quad P(0)=P(1)=P(2)=1, \quad n \ge 0 $$
- Example:
first_padovan_numbers(10) # returns [1, 1, 1, 2, 2, 3, 4, 5, 7, 9]
27. perrin_numbers_up_to(n) 🔢
- Description: Returns all Perrin numbers less than or equal to
n. - Parameter:
n(int) – the maximum value for Perrin numbers. Must be a positive number greater than 0.
- Returns:
- List of Perrin numbers
[3, 0, 2, 3, 2, 5, 5, 7, 10, ...]up ton.
- List of Perrin numbers
- Perrin numbers formula (recurrence relation):
$$ P(n) = P(n-2) + P(n-3), \quad P(0)=3, P(1)=0, P(2)=2, \quad n \ge 0 $$
- Example:
perrin_numbers_up_to(10) # returns [3, 0, 2, 3, 2, 5, 5, 7, 10]
28. first_perrin_numbers(n) 🔢
- Description: Returns the first
nPerrin numbers. - Parameter:
n(int) – the number of Perrin numbers to generate. Must be a positive number.
- Returns:
- List of the first
nPerrin numbers[3, 0, 2, 3, 2, 5, 5, 7, 10, ...].
- List of the first
- Perrin numbers formula (recurrence relation):
$$ P(n) = P(n-2) + P(n-3), \quad P(0)=3, P(1)=0, P(2)=2, \quad n \ge 0 $$
- Example:
first_perrin_numbers(10) # returns [3, 0, 2, 3, 2, 5, 5, 7, 10, 12]
29. motzkin_numbers_up_to(n) 🔢
- Description: Returns all Motzkin numbers less than or equal to
n. - Parameter:
n(int) – the upper limit for Motzkin numbers. Must be a positive number.
- Returns:
- List of all Motzkin numbers ≤
n[1, 1, 2, 4, 9, ...].
- List of all Motzkin numbers ≤
- Motzkin numbers formula (recurrence relation):
$$ M(n) = M(n-1) + \sum_{k=0}^{n-2} M(k) \cdot M(n-2-k), \quad M(0)=1, M(1)=1, \quad n \ge 2 $$
- Example:
motzkin_numbers_up_to(20) # returns [1, 1, 2, 4, 9]
30. first_motzkin_numbers(n) 🔢
- Description: Returns the first
nMotzkin numbers. - Parameter:
n(int) – the number of Motzkin numbers to generate. Must be a positive number.
- Returns:
- List of the first
nMotzkin numbers[1, 1, 2, 4, 9, 21, ...].
- List of the first
- Motzkin numbers formula (recurrence relation):
$$ M(n) = M(n-1) + \sum_{k=0}^{n-2} M(k) \cdot M(n-2-k), \quad M(0)=1, M(1)=1, \quad n \ge 2 $$
- Example:
first_motzkin_numbers(7) # returns [1, 1, 2, 4, 9, 21, 51]
31. tribonacci_numbers_up_to(n) 🔢
- Description: Returns all Tribonacci numbers less than or equal to
n. - Parameter:
n(int) – the upper limit for Tribonacci numbers. Must be a positive number.
- Returns:
- List of Tribonacci numbers
[0, 1, 1, 2, 4, 7, ...]that do not exceedn.
- List of Tribonacci numbers
- Tribonacci numbers formula (recurrence relation):
$$ T(n) = T(n-1) + T(n-2) + T(n-3), \quad T(0)=0, T(1)=1, T(2)=1, \quad n \ge 3 $$
- Example:
tribonacci_numbers_up_to(20) # returns [0, 1, 1, 2, 4, 7, 13]
32. first_tribonacci_numbers(n) 🔢
- Description: Returns the first
nTribonacci numbers. - Parameter:
n(int) – the number of Tribonacci numbers to generate. Must be a positive number.
- Returns:
- List of the first
nTribonacci numbers[0, 1, 1, 2, 4, 7, ...].
- List of the first
- Tribonacci numbers formula (recurrence relation):
$$ T(n) = T(n-1) + T(n-2) + T(n-3), \quad T(0)=0, T(1)=1, T(2)=1, \quad n \ge 3 $$
- Example:
first_tribonacci_numbers(7) # returns [0, 1, 1, 2, 4, 7, 13]
33. armstrong_numbers_up_to(n) 🔢
- Description: Returns all Armstrong numbers less than or equal to
n. - Parameter:
n(int) – the upper limit for Armstrong numbers. Must be a positive number.
- Returns:
- List of Armstrong numbers
[1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, ...]that do not exceedn.
- List of Armstrong numbers
- Armstrong number formula:
A number is an Armstrong number if:
$$ N = \sum_{i=1}^{k} d_i^k $$
where (d_i) are the digits of (N) and (k) is the number of digits in (N).
- Example:
armstrong_numbers_up_to(500) # returns [1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407]
34. first_armstrong_numbers(n) 🔢
- Description: Returns the first
nArmstrong numbers in order. - Parameter:
n(int) – the number of Armstrong numbers to generate. Must be a positive number.
- Returns:
- List of the first
nArmstrong numbers[1, 2, 3, 4, 5, ...].
- List of the first
- Armstrong number formula:
A number is an Armstrong number if:
$$ N = \sum_{i=1}^{k} d_i^k $$
where (d_i) are the digits of (N) and (k) is the number of digits in (N).
- Example:
first_armstrong_numbers(10) # returns [1, 2, 3, 4, 5, 6, 7, 8, 9, 153]
35. perfect_numbers_up_to(n) 🔢
- Description: Returns all perfect numbers less than or equal to
n. - Parameter:
n(int) – the upper limit to generate perfect numbers. Must be a positive number.
- Returns:
- List of perfect numbers
≤ n[6, 28, 496, ...].
- List of perfect numbers
- Perfect number formula:
A number (N) is perfect if:
$$ N = \sum_{d | N, d < N} d $$
i.e., the sum of its proper divisors equals the number itself.
- Example:
perfect_numbers_up_to(500) # returns [6, 28, 496]
36. first_perfect_numbers(n) 🔢
- Description: Returns the first
nperfect numbers in order. - Parameter:
n(int) – the number of perfect numbers to generate. Must be a positive number.
- Returns:
- List of the first
nperfect numbers[6, 28, 496, ...].
- List of the first
- Perfect number formula:
A number (N) is perfect if:
$$ N = \sum_{d | N, d < N} d $$
i.e., the sum of its proper divisors equals the number itself.
- Example:
first_perfect_numbers(4) # returns [6, 28, 496, 8128]
37. collatz_sequence(n) 🔢
-
Description: Generates the Collatz sequence starting from a positive integer
n. -
Parameter:
n(int) – the starting number of the sequence. Must be a positive integer.
-
Returns:
- List of integers representing the Collatz sequence until it reaches 1.
-
Collatz rules:
- Start with any positive integer
n. - If
nis even, divide it by 2. - If
nis odd, multiply by 3 and add 1. - Repeat until
nbecomes 1.
- Start with any positive integer
-
Example:
collatz_sequence(6) # returns [6, 3, 10, 5, 16, 8, 4, 2, 1]
38. harshad_numbers_up_to(n) 🔢
- Description: Returns all Harshad (Niven) numbers less than or equal to
n. A number is Harshad if it is divisible by the sum of its digits. - Parameter:
n(int) – the upper limit to generate Harshad numbers. Must be a positive number.
- Returns:
- List of Harshad numbers
≤ n[1, 2, 3, 4, 5, ...].
- List of Harshad numbers
- Definition:
A number (N) is a Harshad number if:
$$ N \bmod S(N) = 0 $$
where (S(N)) is the sum of the digits of (N).
- Example:
harshad_numbers_up_to(20) # returns [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18]
39. first_harshad_numbers(n) 🔢
- Description: Returns the first
nHarshad (Niven) numbers in order. A number is Harshad if it is divisible by the sum of its digits. - Parameter:
n(int) – the number of Harshad numbers to generate. Must be a positive number.
- Returns:
- List of the first
nHarshad numbers[1, 2, 3, 4, 5, ...].
- List of the first
- Definition:
A number (N) is a Harshad number if:
$$ N \bmod S(N) = 0 $$
where (S(N)) is the sum of the digits of (N).
- Example:
first_harshad_numbers(15) # returns [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24]
40. hamming_numbers_up_to(n) 🔢
- Description: Returns all Hamming numbers less than or equal to
n. A Hamming number is a number whose only prime factors are 2, 3, or 5. - Parameter:
n(int) – the upper limit to generate Hamming numbers. Must be a positive number greater than 0.
- Returns:
- List of Hamming numbers
≤ n[1, 2, 3, 4, 5, 6, 8, ...].
- List of Hamming numbers
- Definition:
A number (N) is a Hamming number if it can be expressed as:
$$ N = 2^i \cdot 3^j \cdot 5^k $$
for non-negative integers (i, j, k).
- Example:
hamming_numbers_up_to(20) # returns [1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16]
41. first_hamming_numbers(n) 🔢
- Description: Returns the first
nHamming numbers in order. A Hamming number is a number whose only prime factors are 2, 3, or 5. - Parameter:
n(int) – the number of Hamming numbers to generate. Must be a positive number greater than 0.
- Returns:
- List of the first
nHamming numbers[1, 2, 3, 4, 5, 6, 8, ...].
- List of the first
- Definition:
A number (N) is a Hamming number if it can be expressed as:
$$ N = 2^i \cdot 3^j \cdot 5^k $$
for non-negative integers (i, j, k).
- Example:
first_hamming_numbers(15) # returns [1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24]
42. mersenne_numbers_up_to(n) 🔢
- Description: Returns all Mersenne numbers less than or equal to
n. A Mersenne number is a number of the form (2^p - 1) where (p) is a prime number. - Parameter:
n(int) – the upper limit to generate Mersenne numbers. Must be a positive number greater than 0.
- Returns:
- List of Mersenne numbers
≤ n[3, 7, 31, ...].
- List of Mersenne numbers
- Definition:
A number (M) is a Mersenne number if it can be expressed as:
$$ M = 2^p - 1 $$
where (p) is prime.
- Example:
mersenne_numbers_up_to(100) # returns [3, 7, 31, 127]
43. first_mersenne_numbers(count) 🔢
- Description: Returns the first
countMersenne numbers in order. A Mersenne number is a number of the form (2^p - 1) where (p) is a prime number. - Parameter:
count(int) – the number of Mersenne numbers to generate. Must be a positive number greater than 0.
- Returns:
- List of the first
countMersenne numbers[3, 7, 31, ...].
- List of the first
- Definition:
A number (M) is a Mersenne number if it can be expressed as:
$$ M = 2^p - 1 $$
where (p) is prime.
- Example:
first_mersenne_numbers(5) # returns [3, 7, 31, 127, 8191]
44. fermat_numbers_up_to(n) 🔢
- Description: Returns all Fermat numbers less than or equal to
n. A Fermat number is a number of the form (2^{2^k} + 1). - Parameter:
n(int) – the upper limit to generate Fermat numbers. Must be a positive number greater than 0.
- Returns:
- List of Fermat numbers
≤ n[3, 5, 17, ...].
- List of Fermat numbers
- Definition:
A number (F) is a Fermat number if it can be expressed as:
$$ F = 2^{2^k} + 1 $$
where (k) is a non-negative integer.
- Example:
fermat_numbers_up_to(100) # returns [3, 5, 17, 257]
45. first_fermat_numbers(count) 🔢
- Description: Returns the first
countFermat numbers in order. A Fermat number is a number of the form (2^{2^k} + 1). - Parameter:
count(int) – the number of Fermat numbers to generate. Must be a positive number greater than 0.
- Returns:
- List of the first
countFermat numbers[3, 5, 17, ...].
- List of the first
- Definition:
A number (F) is a Fermat number if it can be expressed as:
$$ F = 2^{2^k} + 1 $$
where (k) is a non-negative integer.
- Example:
first_fermat_numbers(5) # returns [3, 5, 17, 257, 65537]
46. pell_numbers_up_to(n) 🔢
- Description: Returns all Pell numbers less than or equal to
n. Pell numbers follow the recurrence (P_n = 2P_{n-1} + P_{n-2}) with initial values (P_0 = 0) and (P_1 = 1). - Parameter:
n(int) – the upper limit. Must be a non-negative number.
- Returns:
- List of all Pell numbers
≤ n[0, 1, 2, 5, 12, ...].
- List of all Pell numbers
- Definition:
A number (P_n) is a Pell number if it satisfies:
$$ P_0 = 0, \quad P_1 = 1, \quad P_n = 2 \cdot P_{n-1} + P_{n-2} \quad \text{for } n \ge 2 $$
- Example:
pell_numbers_up_to(20) # returns [0, 1, 2, 5, 12]
47. first_pell_numbers(count) 🔢
- Description: Returns the first
countPell numbers in order. A Pell number is defined by the recurrence relation (P_n = 2P_{n-1} + P_{n-2}) with initial values (P_0 = 0) and (P_1 = 1). - Parameter:
count(int) – the number of Pell numbers to generate. Must be a positive number greater than 0.
- Returns:
- List of the first
countPell numbers[0, 1, 2, 5, 12, ...].
- List of the first
- Definition:
A number (P_n) is a Pell number if it satisfies:
$$ P_0 = 0, \quad P_1 = 1, \quad P_n = 2 \cdot P_{n-1} + P_{n-2} \quad \text{for } n \ge 2 $$
- Example:
first_pell_numbers(6) # returns [0, 1, 2, 5, 12, 29]
48. add_sequences(seq1, seq2) ➕
- Description: Returns a new sequence that is the element-wise sum of two sequences of equal length.
- Parameters:
seq1(list of numbers) – the first sequence.seq2(list of numbers) – the second sequence. Must have the same length asseq1.
- Returns:
- List of numbers representing the element-wise sum of
seq1andseq2.
- List of numbers representing the element-wise sum of
- Raises:
ValueErrorif the sequences are not of the same length.
- Example:
add_sequences([1, 2, 3], [4, 5, 6]) # returns [5, 7, 9]
49. subtract_sequences(seq1, seq2) ➖
- Description: Returns a new sequence that is the element-wise difference of two sequences of equal length.
- Parameters:
seq1(list of numbers) – the first sequence.seq2(list of numbers) – the second sequence. Must have the same length asseq1.
- Returns:
- List of numbers representing the element-wise difference
seq1[i] - seq2[i].
- List of numbers representing the element-wise difference
- Raises:
ValueErrorif the sequences are not of the same length.
- Example:
subtract_sequences([5, 7, 9], [1, 2, 3]) # returns [4, 5, 6]
50. multiply_sequences(seq1, seq2) ✖️
- Description: Returns a new sequence that is the element-wise product of two sequences of equal length.
- Parameters:
seq1(list of numbers) – the first sequence.seq2(list of numbers) – the second sequence. Must have the same length asseq1.
- Returns:
- List of numbers representing the element-wise product
seq1[i] * seq2[i].
- List of numbers representing the element-wise product
- Raises:
ValueErrorif the sequences are not of the same length.
- Example:
multiply_sequences([1, 2, 3], [4, 5, 6]) # returns [4, 10, 18]
51. divide_sequences(seq1, seq2) ➗
- Description: Returns a new sequence that is the element-wise division of two sequences of equal length.
- Parameters:
seq1(list of numbers) – the numerator sequence.seq2(list of numbers) – the denominator sequence. Must have the same length asseq1.
- Returns:
- List of numbers representing the element-wise division
seq1[i] / seq2[i].
- List of numbers representing the element-wise division
- Raises:
ValueErrorif the sequences are not of the same length.ZeroDivisionErrorif any element inseq2is zero.
- Example:
divide_sequences([4, 10, 18], [2, 5, 3]) # returns [2.0, 2.0, 6.0]
52. modulo_sequences(seq1, seq2) 🟰
- Description: Returns a new sequence that is the element-wise modulo of two sequences of equal length.
- Parameters:
seq1(list of numbers) – the dividend sequence.seq2(list of numbers) – the divisor sequence. Must have the same length asseq1.
- Returns:
- List of numbers representing the element-wise modulo
seq1[i] % seq2[i].
- List of numbers representing the element-wise modulo
- Raises:
ValueErrorif the sequences are not of the same length.ZeroDivisionErrorif any element inseq2is zero.
- Example:
modulo_sequences([5, 7, 10], [2, 3, 4]) # returns [1, 1, 2]
53. power_sequences(seq1, seq2) 🔺
- Description: Returns a new sequence that is the element-wise exponentiation of two sequences of equal length.
- Parameters:
seq1(list of numbers) – the base sequence.seq2(list of numbers) – the exponent sequence. Must have the same length asseq1.
- Returns:
- List of numbers representing the element-wise power
seq1[i] ** seq2[i].
- List of numbers representing the element-wise power
- Raises:
ValueErrorif the sequences are not of the same length.
- Example:
power_sequences([2, 3, 4], [3, 2, 1]) # returns [8, 9, 4]
54. absolute_difference_sequences(seq1, seq2) 🔹
- Description: Returns a new sequence containing the element-wise absolute differences between two sequences of equal length.
- Parameters:
seq1(list of numbers) – the first sequence.seq2(list of numbers) – the second sequence. Must have the same length asseq1.
- Returns:
- List of numbers representing the absolute differences
|seq1[i] - seq2[i]|.
- List of numbers representing the absolute differences
- Raises:
ValueErrorif the sequences are not of the same length.
- Example:
absolute_difference_sequences([5, 7, 2], [3, 10, 2]) # returns [2, 3, 0]
55. concat_sequences(seq1, seq2) 🔗
- Description: Returns a new sequence by concatenating two sequences end-to-end.
- Parameters:
seq1(list) – the first sequence.seq2(list) – the second sequence.
- Returns:
- List containing all elements of
seq1followed by all elements ofseq2.
- List containing all elements of
- Example:
concat_sequences([1, 2, 3], [4, 5, 6]) # returns [1, 2, 3, 4, 5, 6]
56. logic_AND_on_sequences(seq1, seq2) 🔒
- Description: Returns a new sequence containing the element-wise logical AND of two boolean sequences of equal length.
- Parameters:
seq1(list of 0 or 1) – the first boolean sequence.seq2(list of 0 or 1) – the second boolean sequence. Must have the same length asseq1.
- Returns:
- List of numbers representing the logical AND of corresponding elements
seq1[i] and seq2[i].
- List of numbers representing the logical AND of corresponding elements
- Raises:
ValueErrorif the sequences are not of the same length or contain non-boolean values.
- Example:
logic_AND_on_sequences([1, 0, 1], [0, 1, 1]) # returns [0, 0, 1]
57. logic_OR_on_sequences(seq1, seq2) 🔓
- Description: Returns a new sequence containing the element-wise logical OR of two boolean sequences of equal length.
- Parameters:
seq1(list of 0 or 1) – the first boolean sequence.seq2(list of 0 or 1) – the second boolean sequence. Must have the same length asseq1.
- Returns:
- List of numbers representing the logical OR of corresponding elements
seq1[i] or seq2[i].
- List of numbers representing the logical OR of corresponding elements
- Raises:
ValueErrorif the sequences are not of the same length or contain non-boolean values.
- Example:
logic_OR_on_sequences([1, 0, 1], [0, 1, 1]) # returns [1, 1, 1]
58. logic_XOR_on_sequences(seq1, seq2) ✖️
- Description: Returns a new sequence containing the element-wise logical XOR of two boolean sequences of equal length.
- Parameters:
seq1(list of 0 or 1) – the first boolean sequence.seq2(list of 0 or 1) – the second boolean sequence. Must have the same length asseq1.
- Returns:
- List of numbers representing the logical XOR of corresponding elements
seq1[i] != seq2[i].
- List of numbers representing the logical XOR of corresponding elements
- Raises:
ValueErrorif the sequences are not of the same length or contain non-boolean values.
- Example:
logic_XOR_on_sequences([1, 0, 1], [0, 1, 1]) # returns [1, 1, 0]
59. sum_elements_of_sequence(seq) ➕
- Description: Returns the sum of all elements in a sequence.
- Parameter:
seq(list of numbers) – the sequence to sum.
- Returns:
- Sum of all elements in the sequence.
- Example:
sum_elements_of_sequence([1, 2, 3, 4]) # returns 10
60. max_from_sequence(seq) 📈
- Description: Returns the maximum value from a sequence.
- Parameter:
seq(list of numbers) – the sequence to evaluate.
- Returns:
- The largest number in the sequence.
- Example:
max_from_sequence([1, 2, 3, 4]) # returns 4
61. min_from_sequence(seq) 📉
- Description: Returns the minimum value from a sequence.
- Parameter:
seq(list of numbers) – the sequence to evaluate.
- Returns:
- The smallest number in the sequence.
- Example:
min_from_sequence([1, 2, 3, 4]) # returns 1
62. arithmetic_mean(seq) ➗
- Description: Returns the arithmetic mean (average) of the elements in a sequence.
- Parameter:
seq(list of numbers) – the sequence to evaluate. Must contain at least one element.
- Returns:
- The arithmetic mean of the sequence.
- Example:
arithmetic_mean([2, 4, 6, 8]) # returns 5.0
Enjoy generating number sequences with NumSeq! 🎉
Contributions and suggestions are welcome. 🚀
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file numseq-0.1.1.tar.gz.
File metadata
- Download URL: numseq-0.1.1.tar.gz
- Upload date:
- Size: 18.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ecdd8a7687b2655a8e1514e2c2f35c2d3a921129c207226820adac3caa8c9c0
|
|
| MD5 |
c3bb1e52c0dfeb6c62d3cac2714397df
|
|
| BLAKE2b-256 |
234cdb423e63f7760edf8761242034b200205698e6e72a4d0e10ceb57a67d791
|
File details
Details for the file numseq-0.1.1-py3-none-any.whl.
File metadata
- Download URL: numseq-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
563acf614264ce2e961d00a5404778ee7ce737de8643686c239769dc055f1d4b
|
|
| MD5 |
4ee6b2761535ee82344885fe8fd8d216
|
|
| BLAKE2b-256 |
574178b220ce8dd643f8d4ba32dafb032a50c5a0a23a5015d9944a35c4696763
|