[sage-support] Re: Comment in python code [[cloud.sagemath.com]]

2013-11-03 Thread Andrew Mathas
This is not a bug. Rather it is a consequence of the syntax require by 
python. To quote from the python 
documentationhttp://docs.python.org/release/2.5.1/ref/indentation.html
:

Leading whitespace (spaces and tabs) at the beginning of a logical line is 
used to compute the indentation level of the line, which in turn is used to 
determine the grouping of statements. 
The reason why you are getting an error here is that in python code, 
including comment, in for-loops must be indented. The rationale for this is 
that it makes the code easier to read. I tend to agree because I used to 
indent my code before I started using python. I even indent in tex files:)

Andrew


On Sunday, 3 November 2013 11:29:20 UTC+1, projetmbc wrote:

 Hello.

 I think that is not good to have an error with the following code.

 
 for i in range(10):
 # Here is a basic comment...
 print i, --, i**2
 

 The error due to the comment is the following one.

 Error in lines 1-1 Traceback (most recent call last): File 
 /mnt/home/pjXx5pJx/.sagemathcloud/sage_server.py, line 633, in execute 
 exec compile(block+'\n', '', 'single') in namespace, locals File 
 string, line 1 for i in range(Integer(10)): ^ SyntaxError: unexpected 
 EOF while parsing


 Just add a space before # and everything is ok... Too weird...
 This should be fixed.

 Best regards.
 C.


-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/groups/opt_out.


[sage-support] Re: Problems with multivariate Laurent polynomial subtitution

2013-09-19 Thread Andrew Mathas
As I posted in sage-dev the problem actually is with the coefficients and I 
found a somewhat heavy handed solution:

sage: R.u,v=LaurentPolynomialRing(ZZ,2)
sage: p=2*u**-1*v**-1+u*v
sage: sum( R(c)*u**-exp[0]*v**-exp[1] for (exp,c) in p.dict().iteritems() )
2*u*v + u^-1*v^-1

Andrew

-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/groups/opt_out.


[sage-support] Problems with multivariate Laurent polynomial subtitution

2013-09-18 Thread Andrew Mathas
Hello All,

I have some polynomials in two varaibles, say u and v, and I want to apply 
the map which u to u^-1 and v to v^-1. Sadly, I run to problems insude sage:

With one variable it is OK:

sage: R.u=LaurentPolynomialRing(ZZ)
sage: p=u**-1  
sage: p.substitute(u=u^-1)
u

but when I go to two variables then it breaks:

sage: R.u,v=LaurentPolynomialRing(ZZ,2)
sage: p=u**-1
sage: p.substitute(u=u^-2)
---
TypeError Traceback (most recent call last)
ipython-input-32-d9f8f61b1503 in module()
 1 p.substitute(u=u**-Integer(2))

/usr/local/src/sage/sage-5.11/local/lib/python2.7/site-packages/sage/structure/element.so
 
in sage.structure.element.Element.substitute 
(sage/structure/element.c:6349)()

/usr/local/src/sage/sage-5.11/local/lib/python2.7/site-packages/sage/rings/polynomial/laurent_polynomial.so
 
in sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_mpair.subs 
(sage/rings/polynomial/laurent_polynomial.c:10778)()

/usr/local/src/sage/sage-5.11/local/lib/python2.7/site-packages/sage/structure/element.so
 
in sage.structure.element.RingElement.__imul__ 
(sage/structure/element.c:14780)()

/usr/local/src/sage/sage-5.11/local/lib/python2.7/site-packages/sage/structure/coerce.so
 
in sage.structure.coerce.CoercionModel_cache_maps.bin_op 
(sage/structure/coerce.c:8169)()

TypeError: unsupported operand parent(s) for '*': 'Multivariate Laurent 
Polynomial Ring in u, v over Rational Field' and 'Multivariate Laurent 
Polynomial Ring in u, v over Integer Ring'

If p=u then this is fine, so it is the u^-1 that is causing the problem.
Of course what I really want to do is p.substitute({u:u**-1, v:v**-1}) 
where o is computed on the fly but if I can even do this then I am stuck.

Does ayone know if I am doing something wrong here or if there is a way 
around this?

Cheers,
Andrew

-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/groups/opt_out.


[sage-support] Re: Constructing subsapces of vector spaces

2012-12-04 Thread Andrew Mathas
Thanks Nils. I this is similar to, but more elegant than, what I tried 
earlier. I went back to the solution above, however, I thought that there 
was probably a lot of overhead in creating the space ZZ^3 and the 
homomorphism. Indeed,

%timeit V.hom([(ZZ^3)(v) for v in [[1,2,3],[2,1,4],[3,3,7]]]).kernel()
125 loops, best of 3: 2.15 ms per loop

sage: %timeit 
V.submodule_with_basis([V.linear_combination_of_basis(b.list())  for b in 
mat.kernel().basis()])
625 loops, best of 3: 1.39 ms per loop

so it does seem to be slower, although one example is hardly definitive.

Andrew

-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To post to this group, send email to sage-support@googlegroups.com.
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support?hl=en.




[sage-support] Re: Constructing subsapces of vector spaces

2012-12-03 Thread Andrew Mathas
Hi John,

Thanks for the reply, but you have my problem upside down as I don't need 
to restrict from the ambient space to the subspace but rather to extend 
from the subspace to the ambient space. 

For example, I could have:

sage: V
Free module of degree 4 and rank 3 over Integer Ring
User basis matrix:
[0 1 2 3]
[2 3 1 4]
[1 3 2 1]
sage: mat=matrix([[1,2,3],[2,1,4],[3,3,7]]); mat.kernel()
Free module of degree 3 and rank 1 over Integer Ring
Echelon basis matrix:
[ 1  1 -1]

The problem that is V is isomorphic to Z^3, but it is represented as a 
subspace of Z^4, whereas the kernel is a subspace of Z^3. As I mentioned, 

sage: V.submodule_with_basis([V.linear_combination_of_basis(b.list())  for 
b in mat.kernel().basis()])
Free module of degree 4 and rank 1 over Integer Ring
User basis matrix:
[1 1 1 6]

does give the kernel as a subspace of V. I was just wondering if there was 
a better way of doing this.

Cheers,
Andrew

-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To post to this group, send email to sage-support@googlegroups.com.
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support?hl=en.




[sage-support] Constructing subsapces of vector spaces

2012-12-02 Thread Andrew Mathas
Hi All,

I have been playing with some code where I want to find a submodule of a 
module V which is annihilated by a bunch of maps. What I want to do 
something like the following:

V= some free submodule of rank v inside a space of rank d\ge v.
mat=[[0 for col in range(w)] for row in range(v)]  # fairly sparse matrix 
which describes the map f on bases of V and W
...compute non-zero entries of the matrix ``mat``
V = V.intersection( matrix(mat).kernel() )

where v=dim V,  w=dim W where f is a map from V to W. Of course, this 
doesn't quite work because matrix(mat).kernel() returns a submodule of ZZ^v 
with respect to its standard basis whereas the space V has a very different 
basis in general. To get around this I found myself writing

kernel=V.submodule_with_basis([V.linear_combination_of_basis(b.list())  for 
b in matrix(pmat).kernel().basis()])
V=V.intersection(kernel)

This strikes me as being a very convoluted way of writing something is 
presumably quite common: writing the standard basis elements as linear 
combinations of another basis. My question is: is there a better way to do 
this?

For a little while, I tried defining W=FreeModule(ZZ,w) and then 
constructing the map f explicitly as a homomorphism from V to W. Doing it 
this way does make f.kernel() into a submodule of V, but this approach just 
seems to create a lot of extra overhead with very little benefit as I 
essentially still had to construct the matrix ``mat`` above and used it to 
define ``f`` with respect to the bases of ``V`` and ``W``. In fact, all 
this really did was shift my problem above of writing the basis of the 
kernel in terms of the basis of V to the problem of writing the images of f 
in terms of the standard basis of W. (Even though I imagine that this 
second approach is much slower I really should have  checked by doing some 
profiling before rewriting as above, but I didn't...)

Any thoughts?

Cheers,
Andrew



-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To post to this group, send email to sage-support@googlegroups.com.
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support?hl=en.




[sage-support] Re: Monoid algebra

2012-11-12 Thread Andrew Mathas
I think that this does want you want and it's just the absence of 
documentation that is letting you down. Try:

sage: M = FreeMonoid(3,['a','b','c'])
sage: a,b,c=M.gens()  # or use M.inject_variables()
sage: A=M.algebra(QQ)
sage: A(a)*A(b)+ A(c)
B[c] + B[a*b]

Andrew

-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To post to this group, send email to sage-support@googlegroups.com.
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support?hl=en.




[sage-support] Re: swtich Gap to Sage

2012-11-02 Thread Andrew Mathas
I think that this does the same as your code, although it seems to me that 
this is not want you really want because the pairs (A,B) of subgroups that 
you return will not in general have the property that G=A x B. I have not 
played at all with groups in sage before so this may be far from optimal:

def direct_summands(G):
r
Return the direct summands of the abelian group ``G``.

EXAMPLES::

sage: direct_summands( CyclicPermutationGroup(4) )
[(Permutation Group with generators [()], Permutation Group with 
generators [(1,2,3,4)]), 
 (Permutation Group with generators [(1,3)(2,4)], Permutation Group 
with generators [(1,3)(2,4)])]

if not (G in Groups and G.is_finite() and G.is_abelian() ):
raise ValueError, '%s must be a finite abelian group' % G

# will create a dictionary of the subgroups in G up to isomorphism 
indexed by size
subgroups_by_size={}
for H in G.subgroups():  # loop over *all* subgroups of G
h=H.cardinality()
if h in subgroups_by_size:
if not all(H.is_isomorphic(K) for K in subgroups[h]):
subgroups_by_size[h].append(H)
else:
subgroups_by_size[h]=[H]

# n is the number of divisors of |G|
g=G.cardinality()
divisors = [(d, g/d) for d in  g.divisors() if 2*d=g]

return [(A,B) for (d,e) in divisors if d in subgroups_by_size and e in 
subgroups_by_size
  for A in subgroups_by_size[d] for B in 
subgroups_by_size[e] ]


Put this into a file, say, summands,py, and then type
sage: attach summands,py
inside sage.

As a general rule, you can find out what to do using tab-completion. For 
example, if you type
sage: G=CyclicPermutationGroup(4)
sage: G.tab
then you will get a list of the methods that apply to the group G.

Andrew

-- 
You received this message because you are subscribed to the Google Groups 
sage-support group.
To post to this group, send email to sage-support@googlegroups.com.
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support?hl=en.




[sage-support] Localising at a prime ideal

2012-05-02 Thread Andrew Mathas
Hi All,

Is there any way in sage to construct the localisation (or localization if 
you prefer) of a ring at a prime ideal? For example, I would like to do the 
following:

sage: R=ZZ.extension(cyclotomic_polynomial(6),'xi')
sage: xi=R.gen(1)
sage: I=R.ideal(7,xi+4)
sage: RI = R.localise(I)

Andrew

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: Calculating with primitive roots of unity in sage

2012-04-15 Thread Andrew Mathas
Thanks for the replies!

Over other fields it's no good just extending by a root of the n'th 
 cyclotomic polynomial, since that need not be irreducible!  The example you 
 gave was particularly unfortunate since over GF(5) the 5th cyclotomic poly 
 has only 1 root with multiplicity 4.  So it's quite right to say that the 
 resulting algebra is not a field.  (The question about Sage not being able 
 to tell that the result is finite is unfortunate, and should be logged as a 
 feature to be implemented., but is not particularly relevant to the current 
 discussion).


I clearly shouldn't post these things late at night! In the context that I 
am working with a primitive pth root of unity in characteristic p is an 
important special case, but this corresponds to xi=1 so I can simply work 
with  GF(p). 

For fields of characteristic p0, I need to work in GF(p^a) for some a so I 
guess that my question really is: does anyone know how to construct the 
smallest extension of GF(p) which contains a primitive eth root of unity 
when gcd(e,p)=1?

Andrew

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org