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.Thu, 09 Dec 2010 23:19:01 +0100Abstract Algebra Questionhttps://ask.sagemath.org/question/7797/abstract-algebra-question/My teacher gave us an extra credit problem using sage, I am having soo much trouble just trying to get started and was hoping for any sort of help possible. Heres the question: An element a in Z mod n is a square if there is some b element of Z mod n such that a^2 = b. Find the number of squares in Z mod p^(n).
Would the code look something like this:
for p^2 = b, let p be prime:
print modulo(Integer(Z):
....
This is my first time ever using a computer program. Sage seems very powerful and I expect to use it more during my school break, but if anyone can help me now, I would greatly appreciate it!!!!!
`Wed, 08 Dec 2010 01:00:40 +0100https://ask.sagemath.org/question/7797/abstract-algebra-question/Answer by kcrisman for <p>My teacher gave us an extra credit problem using sage, I am having soo much trouble just trying to get started and was hoping for any sort of help possible. Heres the question: An element a in Z mod n is a square if there is some b element of Z mod n such that a^2 = b. Find the number of squares in Z mod p^(n).
Would the code look something like this:</p>
<pre><code>for p^2 = b, let p be prime:
</code></pre>
<p>print modulo(Integer(Z):
....
This is my first time ever using a computer program. Sage seems very powerful and I expect to use it more during my school break, but if anyone can help me now, I would greatly appreciate it!!!!!</p>
<p>`</p>
https://ask.sagemath.org/question/7797/abstract-algebra-question/?answer=11832#post-id-11832The earlier comments I believe we made to you in Question 195 still hold! This isn't a homework tutorial. So, once again, I'll give you some hints as to where to find this information, and what the issues are, but no more.
Your syntax is not quite right. You may wish to check out a Python tutorial, such as the [official one](http://docs.python.org/tutorial/), [Dive into Python](http://diveintopython.org/) (for more experienced programmers), or [Think Python](http://greenteapress.com/thinkpython/thinkpython.html), which is truly excellent and truly for beginners, and truly free in that form :)
More specifically, since you haven't defined `b`, you can't say anything about it. Second, the `for` statement needs some sort of iterable as its object. The `prime_range` function, which you can learn more about with
sage: prime_range?
would be useful for getting a set of primes to iterate over; you can use `[1..5]` to get the set of integers from 1 to 5. Third, you probably want some kind of conditional statement if you are testing whether an element is a square; usually this has the syntax
if b>25:
print 'yay!'
else:
print 'boo!'
This would be if you were checking whether `b` was greater than 25.
Incidentally, the statement of the problem also looks strange; see if you can figure out what seems wrong mathematically with what you wrote.Wed, 08 Dec 2010 08:11:45 +0100https://ask.sagemath.org/question/7797/abstract-algebra-question/?answer=11832#post-id-11832Comment by kcrisman for <p>The earlier comments I believe we made to you in Question 195 still hold! This isn't a homework tutorial. So, once again, I'll give you some hints as to where to find this information, and what the issues are, but no more.</p>
<p>Your syntax is not quite right. You may wish to check out a Python tutorial, such as the <a href="http://docs.python.org/tutorial/">official one</a>, <a href="http://diveintopython.org/">Dive into Python</a> (for more experienced programmers), or <a href="http://greenteapress.com/thinkpython/thinkpython.html">Think Python</a>, which is truly excellent and truly for beginners, and truly free in that form :) </p>
<p>More specifically, since you haven't defined <code>b</code>, you can't say anything about it. Second, the <code>for</code> statement needs some sort of iterable as its object. The <code>prime_range</code> function, which you can learn more about with</p>
<pre><code>sage: prime_range?
</code></pre>
<p>would be useful for getting a set of primes to iterate over; you can use <code>[1..5]</code> to get the set of integers from 1 to 5. Third, you probably want some kind of conditional statement if you are testing whether an element is a square; usually this has the syntax</p>
<pre><code>if b>25:
print 'yay!'
else:
print 'boo!'
</code></pre>
<p>This would be if you were checking whether <code>b</code> was greater than 25.</p>
<p>Incidentally, the statement of the problem also looks strange; see if you can figure out what seems wrong mathematically with what you wrote.</p>
https://ask.sagemath.org/question/7797/abstract-algebra-question/?comment=22432#post-id-22432Well, I don't think I did anything more than give you references to some pretty general Sage stuff. Learning Python will help you a lot. By the way, you should mention to your teacher that you used ask.sagemath.org as a resource; not doing so would be called improper citation of references.Thu, 09 Dec 2010 23:19:01 +0100https://ask.sagemath.org/question/7797/abstract-algebra-question/?comment=22432#post-id-22432Comment by Mathstudent2010 for <p>The earlier comments I believe we made to you in Question 195 still hold! This isn't a homework tutorial. So, once again, I'll give you some hints as to where to find this information, and what the issues are, but no more.</p>
<p>Your syntax is not quite right. You may wish to check out a Python tutorial, such as the <a href="http://docs.python.org/tutorial/">official one</a>, <a href="http://diveintopython.org/">Dive into Python</a> (for more experienced programmers), or <a href="http://greenteapress.com/thinkpython/thinkpython.html">Think Python</a>, which is truly excellent and truly for beginners, and truly free in that form :) </p>
<p>More specifically, since you haven't defined <code>b</code>, you can't say anything about it. Second, the <code>for</code> statement needs some sort of iterable as its object. The <code>prime_range</code> function, which you can learn more about with</p>
<pre><code>sage: prime_range?
</code></pre>
<p>would be useful for getting a set of primes to iterate over; you can use <code>[1..5]</code> to get the set of integers from 1 to 5. Third, you probably want some kind of conditional statement if you are testing whether an element is a square; usually this has the syntax</p>
<pre><code>if b>25:
print 'yay!'
else:
print 'boo!'
</code></pre>
<p>This would be if you were checking whether <code>b</code> was greater than 25.</p>
<p>Incidentally, the statement of the problem also looks strange; see if you can figure out what seems wrong mathematically with what you wrote.</p>
https://ask.sagemath.org/question/7797/abstract-algebra-question/?comment=22433#post-id-22433coming in clutch kcrisman! Ty man. I think I figured it out now!Thu, 09 Dec 2010 20:07:36 +0100https://ask.sagemath.org/question/7797/abstract-algebra-question/?comment=22433#post-id-22433