utility
Some utility functions for sequences.
- exception rec_sequences.utility.TimeoutError(time)
Bases:
ExceptionException raised if computations did not finish in given
time.Attributes:
time– number indicating the seconds used for the computationmessage– given by “Timeout after s seconds” where s istime.
- rec_sequences.utility.ceil_SR(a)
Computes an integer approximation of
a.INPUT:
a– a number
OUTPUT:
The smallest integer
bwitha <= b.
- rec_sequences.utility.ceil_SR_bound(a, bound)
Computes a rational approximation of
a.INPUT:
a– a real numberbound– a number
OUTPUT:
A rational number
bwitha <= b < bound.
- rec_sequences.utility.decode_exceptions(ret)
Checks whether the given value is an exception. If it is, it raises this exception. Otherwise the given value is just returned.
- rec_sequences.utility.encode_exceptions(func, *args, **kwargs)
Encodes the exception raised by a function as an object.
INPUT:
func– a functiontime(default:10) – a number; if positive, it specifies the timefuncshould be run; if not positive it will be ignored*args– additional arguments passed tofunc**kwargs– additional arguments passed tofunc
OUTPUT:
Calls the given function
funcwith the given parameters. If the function raises an exception, this exception is returned as an object. Otherwise the usual return value is returned.
- rec_sequences.utility.eval_matrix(matrix_sequence, n=1)
Returns the matrix evaluated at an index.
INPUT:
matrix_sequence– a matrix over a sequence ringn(default:1) – a natural number
OUTPUT:
If the matrix \((c_{i,j})_{i,j}\) is given, the matrix \((c_{i,j}(n))_{i,j}\) is returned.
- rec_sequences.utility.eval_vector(vector_sequence, n)
Returns the vector evaluated at an index.
INPUT:
vector_sequence– a vector over a sequence ringn(default:1) – a natural number
OUTPUT:
If the vector \((c_{i})_{i}\) is given, the vector \((c_{i}(n))_{i}\) is returned.
- rec_sequences.utility.is_root_of_unity(a)
INPUT:
a– a number
OUTPUT:
Returns
Trueifais a root of unity andFalseotherwise.
- rec_sequences.utility.log(cls, msg, level=0, time=- 1, time2=- 1)
Assumes that the given class has a logger object called
log. Tries to output the given messagemsgas info using this logger.These messages can be displayed using:
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
INPUT:
cls– a class having a logger object calledlogmsg– a string; the message that is shown by the loggerlevel– a natural number, indicating the indentation of the messagetime– iftime2is not given, this is a specific timetime2– used to compute the time-span fromtimetotime2to indicate how long a computation took.
OUTPUT:
A string which contains leading whitespaces (the amount depends on
level), the specified messagemsgand the given time.
- rec_sequences.utility.matrix_subsequence(matrix_sequence, u, v=0)
Returns the matrix subsequence.
INPUT:
matrix_sequence– a matrix over a sequence ringu– a rational numberv(optional) – a rational number
OUTPUT:
If the matrix \((c_{i,j}(n))_{i,j}\) is given, the matrix \((c_{i,j}(\operatorname{floor}(u n + v)))_{i,j}\) is returned.
- rec_sequences.utility.shift_matrix(matrix_sequence, n=1)
Returns the matrix shifted.
INPUT:
matrix_sequence– a matrix over a sequence ringn(default:1) – a natural number
OUTPUT:
If the matrix \((c_{i,j})_{i,j}\) is given, the matrix \((\sigma^n c_{i,j})_{i,j}\) is returned.
- rec_sequences.utility.shift_rat_vector(vector_sequence, n=1)
Returns the vector shifted.
INPUT:
vector_sequence– a vector over a rational function ringn(default:1) – a natural number
OUTPUT:
If the vector \((c_{i})_{i}\) is given, the vector \((\sigma^n c_{i})_{i}\) is returned.
- rec_sequences.utility.shift_vector(vector_sequence, n=1)
Returns the vector shifted.
INPUT:
vector_sequence– a vector over a sequence ringn(default:1) – a natural number
OUTPUT:
If the vector \((c_{i})_{i}\) is given, the vector \((\sigma^n c_{i})_{i}\) is returned.
- rec_sequences.utility.split_list(l, r)
Splits a list into lists of equal size.
INPUT:
l– a listr– a natural number which divideslen(l).
OUTPUT:
The list
lsplit intorlists of equal size
- rec_sequences.utility.split_list_rec(l, r)
Splits a list recursively into lists of equal size.
INPUT:
l– a listr– a list of natural numbers such that the product of these is preciselylen(l).
OUTPUT:
The list
lsplit intor[0]lists of equal size which itself are split intor[1]lists of equal size, etc.
- rec_sequences.utility.timeout(func, time=10, *args, **kwargs)
Run a method
funcin a forked subprocess for the given time and with the the given arguments. Iftimeis not positive, the method is might run indefinitely if the function does not return.INPUT:
func– a functiontime(default:10) – a number; if positive, it specifies the timefuncshould be run; if not positive it will be ignored*args– additional arguments passed tofunc**kwargs– additional arguments passed tofunc
OUTPUT:
Returns
func(*args, **kwargs). If the function does not finish in the given time, aTimeoutErroris raised. Exceptions raised byfuncare raised again.
- rec_sequences.utility.vector_interlace(vector_sequences, initial_values=[])
Returns the interlacing of the given vectors of sequences.
INPUT:
vector_sequences– container of vectors of sequences over a common ring.initial_values– list of vectors in the ground field.
OUTPUT:
Interlacing of
vector_sequenceswith the prepended valuesinitial_valuesat the beginning.
- rec_sequences.utility.vector_subsequence(vector_sequence, u, v=0)
Returns the vector subsequence.
INPUT:
vector_sequence– a vector over a sequence ringu– a rational numberv(optional) – a rational number
OUTPUT:
If the vector \((c_{i}(n))_{i}\) is given, the vector \((c_{i}(\operatorname{floor}(u n + v)))_{i}\) is returned.