Bug ? Wilson's Theorem

Doug Stewart dastew at sympatico.ca
Thu Dec 18 21:34:59 CST 2008


Okubok Kenjiro wrote:
> Doug Stewart ????????:
>> Okubok Kenjiro wrote:
>>> Sir
>>>
>>> I know octave is not a tool for number theory, but when I taught
>>> Wilson's theorem in a high-school I found a bug?
>>> Wilsons theorem says, for any prime number p, (p-1)!+1 is divisible 
>>> by p;
>>> with octave
>>> rem(prod(1:(p-1)),p) must be zero, my students checked this for all
>>> primes less than 100. There was an exception for p=29,
>>> rem(prod(1:28),29), ans=3.514e+13.
>>> I am a retired mathematician worked in ODE, and am helping highschool
>>> boys after regular
>>> classes. To deal with large integers, I teach them to factorize into
>>> residual classes and their products. I guess octave changes its 
>>> strategy
>>> at 29, resulting in this case.
>>>
>>> Kenjiro Okubo
>>> Prof. Emeritus UEC,Tokyo Japan
>>> _______________________________________________
>>> Bug-octave mailing list
>>> Bug-octave at octave.org
>>> https://www-old.cae.wisc.edu/mailman/listinfo/bug-octave
>>>
>> I took a look at your prog. and I don't think Octave will do that 
>> question.
>>
>>
>> try the following change and you will see what I meen.
>>
>> #wilson's theorem says for any prime p (p-1)!+1 is divisible by p.
>> format long
>> plist=[2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 
>> 83 89 97];
>> for k=1:25
>> p=plist(k);
>> r=rem(prod(1:(p-1))+3,p);
>> printf("%d , %d\n",p,r)
>> endfor
>>
>> If you look you will see that I added 3 instead of 1
>> Now it should not give zero as an answer but it does.
>> This is because octave cannot produce the big numbers exactly that 
>> come from the prod() command.
>>
>> I hope this helps.
>>
>> Doug Stewart
>>
>>
>>
>>
> Thankyou for your comment,to extend the ability of octave's "prod()",I 
> taught residue
> classes and their arithmetics.

Sir,
Thanks for your comment.What I did for my boys was the following:


octave:12> rem(prod(1:10),29)*rem(prod(11:20),29)*rem(prod(21:28),29)
ans =  260
octave:13> rem(260,29)+1
ans =  29

they do not know how to code a program, but do interactive actions.Residue
calculations may improve factorial or factorization process in programs like
octave, but these are for pari-gp,GMP,MAXIMA etc.
          K.Okubo

This is an excellent solution!!!    :-)


Doug




More information about the Bug-octave mailing list