ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 17 Nov 2010 12:40:55 +0100Modular Arithmetic Question using Sagehttps://ask.sagemath.org/question/7758/modular-arithmetic-question-using-sage/Hey forumgoers, just have a question using Sage. I am having trouble with a few questions asked to me, heres the questions, how do can you compute (n-1)! mod n for n < 100. Find a formula relating the number of idempotents in Zsubn with the number of distinct prime factors that n has.
An element a in Z(subn) is a square if there is some b element of Z(subn) such that a^2=b. Find the number of squares in Z(sub p^n). Tue, 09 Nov 2010 15:58:58 +0100https://ask.sagemath.org/question/7758/modular-arithmetic-question-using-sage/Comment by Jason Grout for <p>Hey forumgoers, just have a question using Sage. I am having trouble with a few questions asked to me, heres the questions, how do can you compute (n-1)! mod n for n < 100. Find a formula relating the number of idempotents in Zsubn with the number of distinct prime factors that n has. </p>
<p>An element a in Z(subn) is a square if there is some b element of Z(subn) such that a^2=b. Find the number of squares in Z(sub p^n). </p>
https://ask.sagemath.org/question/7758/modular-arithmetic-question-using-sage/?comment=22508#post-id-22508Please post what you have tried and maybe a specific question about what you have tried. Some helpful resources are in the tutorial, for example, http://sagemath.org/doc/tutorial/tour_assignment.html
This sounds like it might be a homework problem. We'd be doing you a huge disservice if it is and we just handed you the answer.
Wed, 10 Nov 2010 00:01:47 +0100https://ask.sagemath.org/question/7758/modular-arithmetic-question-using-sage/?comment=22508#post-id-22508Answer by kcrisman for <p>Hey forumgoers, just have a question using Sage. I am having trouble with a few questions asked to me, heres the questions, how do can you compute (n-1)! mod n for n < 100. Find a formula relating the number of idempotents in Zsubn with the number of distinct prime factors that n has. </p>
<p>An element a in Z(subn) is a square if there is some b element of Z(subn) such that a^2=b. Find the number of squares in Z(sub p^n). </p>
https://ask.sagemath.org/question/7758/modular-arithmetic-question-using-sage/?answer=11778#post-id-11778I agree with Jason on most of these. The only one of these which is worthy is the (n-1)! one. I feel like it's ok for me to give Sage commands to do this, though not in one fell swoop - s/he'll still have to put it together.
Keep in mind, though, Mathstudent2010, that your instructor is almost certainly NOT looking for this! Instead a more theoretical result is probably in mind. In particular, although your instructor *might* find it okay to find a pattern using a computer program, they almost certainly will not appreciate a 'proof' of it using the program. You'll have to discover that part for yourself.
In general, if you want to just see the output of something for a certain number of integers, I recommend
for n in [1..100]:
print do_this_thing(n)
This isn't the best longterm, but it provides immediate feedback. This is called a loop.
Secondly, the factorial function is easy - for instance, 10! is `factorial(10)`.
Finally, you can get modular arithmetic as well. For instance, 25 modulo 7 is `mod(25,7)`. Put it all together and you should be able to get an answer, possibly showing you a pattern - but not a proof.Wed, 10 Nov 2010 11:00:11 +0100https://ask.sagemath.org/question/7758/modular-arithmetic-question-using-sage/?answer=11778#post-id-11778Comment by Mathstudent2010 for <p>I agree with Jason on most of these. The only one of these which is worthy is the (n-1)! one. I feel like it's ok for me to give Sage commands to do this, though not in one fell swoop - s/he'll still have to put it together.</p>
<p>Keep in mind, though, Mathstudent2010, that your instructor is almost certainly NOT looking for this! Instead a more theoretical result is probably in mind. In particular, although your instructor <em>might</em> find it okay to find a pattern using a computer program, they almost certainly will not appreciate a 'proof' of it using the program. You'll have to discover that part for yourself. </p>
<p>In general, if you want to just see the output of something for a certain number of integers, I recommend</p>
<pre><code>for n in [1..100]:
print do_this_thing(n)
</code></pre>
<p>This isn't the best longterm, but it provides immediate feedback. This is called a loop.</p>
<p>Secondly, the factorial function is easy - for instance, 10! is <code>factorial(10)</code>.</p>
<p>Finally, you can get modular arithmetic as well. For instance, 25 modulo 7 is <code>mod(25,7)</code>. Put it all together and you should be able to get an answer, possibly showing you a pattern - but not a proof.</p>
https://ask.sagemath.org/question/7758/modular-arithmetic-question-using-sage/?comment=22496#post-id-22496I think I am going down the right path. Any input would be nice. Tue, 16 Nov 2010 13:33:11 +0100https://ask.sagemath.org/question/7758/modular-arithmetic-question-using-sage/?comment=22496#post-id-22496Comment by kcrisman for <p>I agree with Jason on most of these. The only one of these which is worthy is the (n-1)! one. I feel like it's ok for me to give Sage commands to do this, though not in one fell swoop - s/he'll still have to put it together.</p>
<p>Keep in mind, though, Mathstudent2010, that your instructor is almost certainly NOT looking for this! Instead a more theoretical result is probably in mind. In particular, although your instructor <em>might</em> find it okay to find a pattern using a computer program, they almost certainly will not appreciate a 'proof' of it using the program. You'll have to discover that part for yourself. </p>
<p>In general, if you want to just see the output of something for a certain number of integers, I recommend</p>
<pre><code>for n in [1..100]:
print do_this_thing(n)
</code></pre>
<p>This isn't the best longterm, but it provides immediate feedback. This is called a loop.</p>
<p>Secondly, the factorial function is easy - for instance, 10! is <code>factorial(10)</code>.</p>
<p>Finally, you can get modular arithmetic as well. For instance, 25 modulo 7 is <code>mod(25,7)</code>. Put it all together and you should be able to get an answer, possibly showing you a pattern - but not a proof.</p>
https://ask.sagemath.org/question/7758/modular-arithmetic-question-using-sage/?comment=22490#post-id-22490Yup, you figured out how to get Sage to do this for you - congratulations! The rest is mathematics - observing patterns, verifying them, proving them. Good luck!Wed, 17 Nov 2010 12:40:55 +0100https://ask.sagemath.org/question/7758/modular-arithmetic-question-using-sage/?comment=22490#post-id-22490Comment by Mathstudent2010 for <p>I agree with Jason on most of these. The only one of these which is worthy is the (n-1)! one. I feel like it's ok for me to give Sage commands to do this, though not in one fell swoop - s/he'll still have to put it together.</p>
<p>Keep in mind, though, Mathstudent2010, that your instructor is almost certainly NOT looking for this! Instead a more theoretical result is probably in mind. In particular, although your instructor <em>might</em> find it okay to find a pattern using a computer program, they almost certainly will not appreciate a 'proof' of it using the program. You'll have to discover that part for yourself. </p>
<p>In general, if you want to just see the output of something for a certain number of integers, I recommend</p>
<pre><code>for n in [1..100]:
print do_this_thing(n)
</code></pre>
<p>This isn't the best longterm, but it provides immediate feedback. This is called a loop.</p>
<p>Secondly, the factorial function is easy - for instance, 10! is <code>factorial(10)</code>.</p>
<p>Finally, you can get modular arithmetic as well. For instance, 25 modulo 7 is <code>mod(25,7)</code>. Put it all together and you should be able to get an answer, possibly showing you a pattern - but not a proof.</p>
https://ask.sagemath.org/question/7758/modular-arithmetic-question-using-sage/?comment=22497#post-id-22497Jason and Kcrisman, thank you for your reply, help and suggestions.
Here is what I have been doing:
sage: for n in [1..100]:
....: print mod(factorial(n-1), n)
....:
0
1
2
2
4
0
6
0
0
0
10
0
12
0
0
0
16
0
18
0
0
0
22
0
0
0
0
0
28
0
30
0
0
0
0
0
36
0
0
0
40
0
42
0
0
0
46
0
0
0
0
0
52
0
0
0
0
0
58
0
60
0
0
0
0
0
66
0
0
0
70
0
72
0
0
0
0
0
78
0
0
0
82
0
0
0
0
0
88
0
0
0
0
0
0
0
96
0
0
0
Tue, 16 Nov 2010 13:26:38 +0100https://ask.sagemath.org/question/7758/modular-arithmetic-question-using-sage/?comment=22497#post-id-22497