Modulo calculations consider the remainder of a division. One simple example is the clock. 17 o'clock is equal to 5 o'clock.
In sagemath, modulo computation is available via the % operator:
17 % 12
Another way is the use of the mod function:
mod(21, 12)
It is also possible to create an object which contains all remainders of divisions by 12:
clock = Integers(12)
Using the clock instance, we can instantiate member 21. Its representation reveals number 21 reduced modulo 12:
print(clock(21))
A field is a set where you can add, substract, multiply and divide the elements and the solution is also in this set.
Such a finite field can be created using the following commands. Be aware that the order has to be a prime power.
F.<a> = GF(5)
F.<a> = FiniteField(9)
show(F)
If we want to see if a number is prime, we can use Primes
:
13 in Primes()
2019 in Primes()
2019 is not a prime number? Then it must have some interesting prime factorisation:
2019.factor()
Which elements are in F?
print(list(F))
What are the elements in our clock?
print(list(clock))
Sagemath can even display the operation table. But some import
is needed:
from sage.matrix.operation_table import OperationTable
OperationTable(clock, operation=operator.add)
For better readability we can use digits instead of letters:
OperationTable(clock, operation=operator.add, names='digits')
In our case, it's the best to use the original elements of the clock:
OperationTable(clock, operation=operator.add, names='elements')
Take a list and search for a sequence containing these numbers
search = oeis([1, 1, 2, 3], max_results=4)
print(search)
Take the Fibonacci numbers and calculate the first 15 terms
c = search[0]
c.first_terms(15)
We can also search by the name of a sequence
search = oeis.find_by_description('catalan')
print(search)
search[0].first_terms(4)