Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168733
Image: ubuntu2004
First step. Goal: to know using Sage if a number is an integer . The idea is to introduce the set on integers ( let us name is "N" )
N=IntegerRing
3.7 in N()
False
4 in N()
True
Now we can easily ask Sage if (n^x-n) is multiple of x ( here with n=12 and x=13 )
n=12;x=13
(n^x-n)/x in N()
True
Second step. Goal : to know using Sage if a number x is prime. The idea is to use the fuction " x in Primes()"
3 in Primes()
True
How to test if (n^x-n) is multiple of a given x for some different values n ? The idea is to use pour x the set of integers n ( between two values ) such that (n^x-n)/x is integer for example: for x=8
x=8;w = [n for n in range(1,10) if (n^x-n)/x in N()]
w
[1, 8, 9]
Set(w).cardinality()
3
That means for x=13 we have only 3 numbers between 1 and 10 having the property (n^x-n) divisible by x
By this way you can easily find a criteria for the property of divisibility for all integer n between 1 and some "max" value...
def divisib(x,max): return Set([n for n in range(1,max) if (n^x-n)/x in N()]).cardinality()==max-1
divisib(14,10)
False
divisib(17,10)
True
exeptions=Set([k for k in range(1,20) if divisib(k+0,20) and k not in Primes() ])
exeptions
{1}
This last result means : for x between 1 and 20 we have only one number (x=1) not prime having the property... Now you can see if they are some more exeptions ...