SignPattern

The class describes a cyclic sign pattern from some term on. I.e., the class describes a finite set of initial values where the sign need not be cyclic and than a description of the signs from the point on where they are cyclic. However, there are also C-finite sequences which do not have cyclic sign pattern, cf. Example 2.3 in [AKKOW21].

The initial values and elements from the cycle are saved as 1,-1 and 0 describing positive, negative and zero values, respectively.

EXAMPLES:

sage: from rec_sequences.SignPattern import *
sage: pattern = SignPattern([0,1,-1], [1,0,-1])
sage: pattern
Sign pattern: initial values <0+-> cycle <+0->
sage: pattern[:10]
[0, 1, -1, 1, 0, -1, 1, 0, -1, 1]
sage: pattern.get_initial_values()
[0, 1, -1]
sage: pattern.get_cycle()
[1, 0, -1]
sage: pattern.get_positive_progressions()
{Arithmetic progression (3*n+3)_n}
class rec_sequences.SignPattern.SignPattern(initial_values=[], cycle=[])

Bases: sage.structure.sage_object.SageObject

Describes the cyclic sign pattern of a sequence.

__eq__(pattern)

Checks whether two zero patterns are equal.

INPUT:

  • pattern – a sign pattern

OUTPUT:

True if the two patterns are equal and False otherwise.

EXAMPLES:

sage: from rec_sequences.SignPattern import *
sage: pattern1 = SignPattern([1,0,-1], [1,0,-1])
sage: pattern2 = SignPattern([], [1,0,-1])
sage: pattern3 = SignPattern([1,0,1], [1,0,-1])
sage: pattern1 == pattern2 
True
sage: pattern2 == pattern3
False
__getitem__(n)

INPUT:

  • n – a natural number or a slice object (specifying only finitely many values)

OUTPUT:

Returns -1 if the n-th value is negative +1 if it is positive and 0 if it is zero. If n is a slice object, a list with these values is returned.

EXAMPLES:

sage: from rec_sequences.SignPattern import *
sage: pattern = SignPattern([0,1,-1], [1,0,-1])
sage: pattern[3]
1
sage: pattern[:10]
[0, 1, -1, 1, 0, -1, 1, 0, -1, 1]
__init__(initial_values=[], cycle=[])

Creates a sign pattern with the given data.

INPUT:

  • initial_values – a list of exceptional signs not covered by the cycle.

  • cycle – the list of cyclic signs which holds after the initial_values (has to be non-empty)

OUTPUT:

The described sign pattern.

EXAMPLES:

sage: from rec_sequences.SignPattern import *
sage: pattern = SignPattern([0,1,-1], [1,0,-1])
sage: print(pattern)
Sign pattern: initial values <0+-> cycle <+0->
_latex_()

OUTPUT:

A latex representation of the form

\[\langle a \underbrace{b}_{} \cdots \rangle\]

where a is a string representation of the signs of the initial values and b is a string representation of the signs of the cycle (built by the characters +,0,-).

EXAMPLES:

sage: from rec_sequences.SignPattern import *
sage: print(latex(SignPattern([0,1,-1], [1,0,-1])))
\langle0+-\underbrace{+0-}_{}\cdots\rangle
sage: print(latex(SignPattern([], [1,-1])))
\langle\underbrace{+-}_{}\cdots\rangle
get_cycle()

OUTPUT:

Returns the cycle of the pattern.

EXAMPLES:

sage: from rec_sequences.SignPattern import *
sage: SignPattern([0,1,-1], [1,0,-1]).get_cycle()
[1, 0, -1]
sage: SignPattern([0,1,-1], [1]).get_cycle()
[1]
get_cycle_length()

OUTPUT:

Returns the length of the cycle. This might be a multiple of the minimal length.

EXAMPLES:

sage: from rec_sequences.SignPattern import *
sage: SignPattern([0,1,-1], [1,0,-1]).get_cycle_length()
3
sage: SignPattern([], [1,0,-1]).get_cycle_length()
3
sage: SignPattern([], [1,0]).get_cycle_length()
2
sage: SignPattern([], [1,0,1,0]).get_cycle_length()
4
get_cycle_start()

OUTPUT:

Returns the index from which the sign-pattern is guaranteed to be cyclic. This index might not be minimal.

EXAMPLES:

sage: from rec_sequences.SignPattern import *
sage: SignPattern([0,1,-1], [1,0,-1]).get_cycle_start()
3
sage: SignPattern([1,0,-1], [1,0,-1]).get_cycle_start()
3
sage: SignPattern([], [1,0,-1]).get_cycle_start()
0
get_initial_values()

OUTPUT:

Returns the initial values of the pattern.

EXAMPLES:

sage: from rec_sequences.SignPattern import *
sage: SignPattern([0,1,-1], [1,0,-1]).get_initial_values()
[0, 1, -1]
sage: SignPattern([], [1,-1]).get_initial_values()
[]
get_negative_progressions()

OUTPUT:

Returns a set of the arithmetic progressions (rec_sequences.ArithmeticProgression) where the pattern is negative.

EXAMPLES:

sage: from rec_sequences.SignPattern import *
sage: SignPattern([0,1,-1], [1,0,-1]).get_negative_progressions()
{Arithmetic progression (3*n+5)_n}
get_positive_progressions()

OUTPUT:

Returns a set of the arithmetic progressions (rec_sequences.ArithmeticProgression) where the pattern is positive.

EXAMPLES:

sage: from rec_sequences.SignPattern import *
sage: SignPattern([0,1,-1], [1,0,-1]).get_positive_progressions()
{Arithmetic progression (3*n+3)_n}
get_zero_progressions()

OUTPUT:

Returns a set of the arithmetic progressions (rec_sequences.ArithmeticProgression) where the pattern is zero.

EXAMPLES:

sage: from rec_sequences.SignPattern import *
sage: SignPattern([0,1,-1], [1,0,-1]).get_zero_progressions()
{Arithmetic progression (3*n+4)_n}
classmethod guess(data, cycles=3)

Computes the sign pattern of the given data.

INPUT:

  • data – a list of numbers

  • cycles – the number of cycles that need to be detected to conclude whether we indeed have a period. Assume cycles>1.

OUTPUT:

The sign-pattern satisfied by data. If no pattern could be found, a ValueError is raised.

ALGORITHM:

We assume that the periodic behavior starts at least at the half-point of the given data. The algorithm is not particularly efficient and runs in O(len(data)^3) in the worst case. However, in the usual case, if data is cyclic almost from the beginning it is essentially O(len(data))

EXAMPLES:

sage: from rec_sequences.SignPattern import *

sage: SignPattern.guess([0,2] + 10*[1,-1])
Sign pattern: initial values <0+> cycle <+->
sage: SignPattern.guess([1,0,0,1,0,-2,0,3,0,-4,0,5,0,-6,0])
Traceback (most recent call last):
...
ValueError: No sign pattern found, you can try with more data.
sage: SignPattern.guess([1,0,0,1,0,-2,0,3,0,-4,0,5,0,-6,0], \
....:                   cycles=2)
Sign pattern: initial values <+0> cycle <0+0->
is_negative()

OUTPUT:

Returns True if the pattern has only negative values, i.e. no zeros or positive values.

EXAMPLES:

sage: from rec_sequences.SignPattern import *
sage: SignPattern([0,1,-1], [1,0,-1]).is_negative()
False
sage: SignPattern([-1], [-1]).is_negative()
True
is_positive()

OUTPUT:

Returns True if the pattern has only positive values, i.e. no zeros or negative values.

EXAMPLES:

sage: from rec_sequences.SignPattern import *
sage: SignPattern([0,1,-1], [1,0,-1]).is_positive()
False
sage: SignPattern([1], [1]).is_positive()
True
is_zero()

OUTPUT:

Returns True if the pattern is constantly zero.

EXAMPLES:

sage: from rec_sequences.SignPattern import *
sage: SignPattern([0,1,-1], [1,0,-1]).is_zero()
False
sage: SignPattern([1,-1], [1,-1]).is_zero()
False
sage: SignPattern([0], [0]).is_zero()
True
sage: SignPattern([], [0]).is_zero()
True
non_zero()

OUTPUT:

Returns True if the pattern has no zeros at all.

EXAMPLES:

sage: from rec_sequences.SignPattern import *
sage: SignPattern([0,1,-1], [1,0,-1]).non_zero()
False
sage: SignPattern([1,-1], [1,-1]).non_zero()
True
sage: SignPattern([0,1], [0]).non_zero()
False
repr_cycle()

OUTPUT:

Returns a string representation of the cycle only containing +, -, 0 for positive, negative and zero entries.

EXAMPLES:

sage: from rec_sequences.SignPattern import *
sage: print(SignPattern([0,1,-1], [1,0,-1]).repr_cycle())
+0-
repr_initial_values()

OUTPUT:

Returns a string representation of the initial values only containing +, -, 0 for positive, negative and zero entries.

EXAMPLES:

sage: from rec_sequences.SignPattern import *
sage: print(SignPattern([0,1,-1], [1,0,-1]).repr_initial_values())
0+-