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, 10 Jun 2020 21:06:35 +0200How do I get that sage prints me out some itemhttps://ask.sagemath.org/question/51872/how-do-i-get-that-sage-prints-me-out-some-item/ I have the following code:
sage:R.<x>=QQ[]
f=x^2-x+6
K.<a>=NumberField(f)
cl = K.class_group()
L=K.ideal(23)
S=ideal(4,a+1)
S.is_integral()
sage: for norm, ideals in K.ideals_of_bdd_norm(50).items():
for J in ideals:
for N in range(5):
if (J.is_coprime(L*N)):
if(J!=cl.one()):
if(4*J.norm()-1 in L*N):
print norm,J,N
The output is :
True
6 Fractional ideal (6, a + 2) 1
6 Fractional ideal (a - 1) 1
6 Fractional ideal (a) 1
6 Fractional ideal (6, a + 3) 1
29 Fractional ideal (29, a + 18) 1
29 Fractional ideal (29, a + 10) 1
What do I have to do to only get the item 29 Fractional ideal (29, a + 18) 1 ?Tue, 09 Jun 2020 18:56:10 +0200https://ask.sagemath.org/question/51872/how-do-i-get-that-sage-prints-me-out-some-item/Comment by John Palmieri for <p>I have the following code:</p>
<pre><code> sage:R.<x>=QQ[]
f=x^2-x+6
K.<a>=NumberField(f)
cl = K.class_group()
L=K.ideal(23)
S=ideal(4,a+1)
S.is_integral()
sage: for norm, ideals in K.ideals_of_bdd_norm(50).items():
for J in ideals:
for N in range(5):
if (J.is_coprime(L*N)):
if(J!=cl.one()):
if(4*J.norm()-1 in L*N):
print norm,J,N
</code></pre>
<p>The output is :</p>
<pre><code>True
6 Fractional ideal (6, a + 2) 1
6 Fractional ideal (a - 1) 1
6 Fractional ideal (a) 1
6 Fractional ideal (6, a + 3) 1
29 Fractional ideal (29, a + 18) 1
29 Fractional ideal (29, a + 10) 1
</code></pre>
<p>What do I have to do to only get the item 29 Fractional ideal (29, a + 18) 1 ?</p>
https://ask.sagemath.org/question/51872/how-do-i-get-that-sage-prints-me-out-some-item/?comment=51876#post-id-51876Can you provide more information? How, computationally or programmatically or mathematically, do you want to choose which item to print/return?Tue, 09 Jun 2020 23:13:35 +0200https://ask.sagemath.org/question/51872/how-do-i-get-that-sage-prints-me-out-some-item/?comment=51876#post-id-51876Comment by Moondoggy for <p>I have the following code:</p>
<pre><code> sage:R.<x>=QQ[]
f=x^2-x+6
K.<a>=NumberField(f)
cl = K.class_group()
L=K.ideal(23)
S=ideal(4,a+1)
S.is_integral()
sage: for norm, ideals in K.ideals_of_bdd_norm(50).items():
for J in ideals:
for N in range(5):
if (J.is_coprime(L*N)):
if(J!=cl.one()):
if(4*J.norm()-1 in L*N):
print norm,J,N
</code></pre>
<p>The output is :</p>
<pre><code>True
6 Fractional ideal (6, a + 2) 1
6 Fractional ideal (a - 1) 1
6 Fractional ideal (a) 1
6 Fractional ideal (6, a + 3) 1
29 Fractional ideal (29, a + 18) 1
29 Fractional ideal (29, a + 10) 1
</code></pre>
<p>What do I have to do to only get the item 29 Fractional ideal (29, a + 18) 1 ?</p>
https://ask.sagemath.org/question/51872/how-do-i-get-that-sage-prints-me-out-some-item/?comment=51878#post-id-51878I only want to know whether there is a command to select a specific item for example 29 Fractional ideal (29, a + 18) 1.Wed, 10 Jun 2020 00:14:20 +0200https://ask.sagemath.org/question/51872/how-do-i-get-that-sage-prints-me-out-some-item/?comment=51878#post-id-51878Answer by John Palmieri for <p>I have the following code:</p>
<pre><code> sage:R.<x>=QQ[]
f=x^2-x+6
K.<a>=NumberField(f)
cl = K.class_group()
L=K.ideal(23)
S=ideal(4,a+1)
S.is_integral()
sage: for norm, ideals in K.ideals_of_bdd_norm(50).items():
for J in ideals:
for N in range(5):
if (J.is_coprime(L*N)):
if(J!=cl.one()):
if(4*J.norm()-1 in L*N):
print norm,J,N
</code></pre>
<p>The output is :</p>
<pre><code>True
6 Fractional ideal (6, a + 2) 1
6 Fractional ideal (a - 1) 1
6 Fractional ideal (a) 1
6 Fractional ideal (6, a + 3) 1
29 Fractional ideal (29, a + 18) 1
29 Fractional ideal (29, a + 10) 1
</code></pre>
<p>What do I have to do to only get the item 29 Fractional ideal (29, a + 18) 1 ?</p>
https://ask.sagemath.org/question/51872/how-do-i-get-that-sage-prints-me-out-some-item/?answer=51899#post-id-51899Instead of:
sage: for a in [0,1,2]:
....: print(a**2)
....:
0
1
4
do
sage: L = []
sage: for a in [0,1,2]:
....: L.append(a**2)
....:
sage: L
[0, 1, 4]
Then you have access to the list L, you can pick and choose elements from it, etc. For example:
sage: L[2]
4
Wed, 10 Jun 2020 21:06:35 +0200https://ask.sagemath.org/question/51872/how-do-i-get-that-sage-prints-me-out-some-item/?answer=51899#post-id-51899