Re: "Programming" in mathematica
- From: "Nena" <Nivea.Schwarzkopf@xxxxxx>
- Date: 7 Nov 2006 18:08:15 -0800
Jean-Marc, it's me again.
Maybe you can have a look on my new post ;-)
http://groups.google.com/group/sci.math.symbolic/browse_frm/thread/855bd2d000483ac1/e246a989e6a32c0f?lnk=raot&hl=de#e246a989e6a32c0f
Nena
Nena wrote:
Ups, it seems I'm writing rubbish all day long.
The expected answer to f[19] is 5.
Sorry, ignore what I've just posted.
I guess I'm too tired.
Nena
Nena wrote:
Hi Jean-Marc,
Thanks once again!
My formula is wrong!
It should be
Mod[p, c]
instead of
Mod[c, p].
But the function
f[p_Integer /; p > 3] :=
NestWhile[#1 + 1 &, 4, Mod[(Mod[p, #1]^((#1 - 1)/2)), #1] != 1 &]
still doesn't give me my expected answer.
Now I obtain
f[19] = 5
which is +1 too much! I suspect that c has been increased while
c = 4 passed the test Mod[(Mod[p, #1]^((#1 - 1)/2)), #1] != 1
Any ideas to fix that?
Many thanks,
Nena
Jean-Marc Gulliet wrote:
Nena wrote:
Hi Jean-Marc,----------------------------------------------------------------^^
Thanks for your answer!
Actually the condition I have it's a bit more
complicated then I first posted.
Instead of checking
Mod[c, p] == 1
I would like the program to check
Mod[Mod[c, p]^((c - 1)/2), c] == 1
So my change of your program would be
f[p_] := NestWhile[#1 + 1 & , 4, Mod[Mod[#1, p]^((#1 - 1)/2), 1#] != 1
Beware: slot numbers must be written the other way around, that is #1
(but this is not an issue here since Mathematica interpret it as one
times the first variable, 1*#1)
& ]
Then testing the program I get
f[19] = 20
The answer should be 4.
Where is my fault in changing your program?
I do not see anything wrong in the changes you made to the original
code. However, I suspect either the formula you use as stooping
criterion is not the correct one or your expected value for f[19] is
erroneous.
In[1]:=
f[p_Integer /; p > 3] :=
NestWhile[#1 + 1 & , 4, Mod[Mod[#1, p]^((#1 - 1)/2), #1] != 1 & ]
In[2]:=
f[19]
Out[2]=
20
The result above is in agreement with your formula
In[3]:=
Mod[Mod[c, p]^((c - 1)/2), c] == 1 /. {c -> 20, p -> 19}
Out[3]=
True
While the expected value of 4 for c failed the test
In[4]:=
Mod[Mod[c, p]^((c - 1)/2), c] == 1 /. {c -> 4, p -> 19}
Out[4]=
False
We can follow the process step by step,
In[5]:=
Mod[4, 19]
Out[5]=
4
In[6]:=
Mod[4, 19]^((4 - 1)/2)
Out[6]=
8
In[7]:=
Mod[Mod[4, 19]^((4 - 1)/2), 4]
Out[7]=
0
Regards,
Jean-Marc
.
- References:
- "Programming" in mathematica
- From: Nena
- Re: "Programming" in mathematica
- From: Jean-Marc Gulliet
- Re: "Programming" in mathematica
- From: Jean-Marc Gulliet
- Re: "Programming" in mathematica
- From: Nena
- Re: "Programming" in mathematica
- From: Jean-Marc Gulliet
- Re: "Programming" in mathematica
- From: Nena
- Re: "Programming" in mathematica
- From: Nena
- "Programming" in mathematica
- Prev by Date: Euclidean Algorithm in Mathematica
- Next by Date: Re: Euclidean Algorithm in Mathematica
- Previous by thread: Re: "Programming" in mathematica
- Next by thread: Euclidean Algorithm in Mathematica
- Index(es):