ArithmeticProgression
Describes an arithmetic progession of the form \((d n + s)_{n \in \mathbb{N}}\). Such an arithmetic progressions is defined by a shift \(s\) and the difference of two consecutive terms \(d\).
EXAMPLES:
sage: from rec_sequences.ArithmeticProgression import *
sage: prog = ArithmeticProgression(2, 3)
sage: print(prog)
Arithmetic progression (2*n+3)_n
sage: prog.get_diff(), prog.get_shift()
(2, 3)
sage: 5 in prog
True
sage: 6 in prog
False
sage: prog[2]
7
sage: prog[:5]
[3, 5, 7, 9, 11]
- class rec_sequences.ArithmeticProgression.ArithmeticProgression(diff=0, shift=0)
Bases:
sage.structure.sage_object.SageObject
Describes an arithmetic progession (diff*n+shift)_n for natural numbers diff, shift.
- __contains__(item)
Checks whether the arithmetic progression contains
item
provided it is a natural number.INPUT:
item
– a natural number
OUTPUT:
True
ifitem
is in the progression andFalse
otherwise.
- __eq__(prog)
Checks whether two arithmetic progressions are equal.
INPUT:
prog
– an arithmetic progression
OUTPUT:
True
if the two progressions are equal andFalse
otherwise.EXAMPLES:
sage: from rec_sequences.ArithmeticProgression import * sage: prog1 = ArithmeticProgression(2, 3) sage: prog2 = ArithmeticProgression(2, 3) sage: prog3 = ArithmeticProgression(2, 1) sage: prog1 == prog2 True sage: prog1 == prog3 False
- __getitem__(n)
INPUT:
n
– a natural number or a slice object
OUTPUT:
Returns the
n
-th term of the arithmetic progression.
- __init__(diff=0, shift=0)
Creates the arithmetic progression \((d n+s)_n\) where \(d\) is the given difference
diff
and \(s\) is the given shiftshift
.INPUT:
diff
– the difference of two consecutive values in the progression.shift
– the shift of the arithmetic progression.
OUTPUT:
The described arithmetic progression.
- _latex_()
OUTPUT:
A latex representation of the form
\[\{ d n + s : n \in \mathbb{N} \}\]where \(d\) is the difference of the progression and \(s\) is the shift of the progression.
- _repr_()
OUTPUT:
A string representation of the form “Arithmetic progression (d*n+s)_n” where
d
is the difference of the progression ands
is the shift of the progression.
- get_diff()
Returns the difference of the arithmetic progression.
- get_shift()
Returns the shift of the arithmetic progression.
- is_zero()
True if the arithmetic progression is constantly zero.
EXAMPLES:
sage: from rec_sequences.ArithmeticProgression import * sage: ArithmeticProgression(2, 3).is_zero() False sage: ArithmeticProgression(0, 0).is_zero() True