[sage-support] enumerating vectors in Z^d

2010-05-06 Thread Eva
Problem background: I want to find the smallest (in l_2 norm) vectors
that satisfy a certain condition - creating a minimal set of coset
representatives for Z^d/A(Z^d) for a dilation matrix A.  My idea is to
start with 0 and enumerate vectors in Z^d one at a time.  For each new
vector that I consider, I can test whether it is in a new coset, or in
a coset that I already have a representative for.  I know the number
of cosets in advance, so can stop when I reach the right number of
coset representatives.

My question: what is the best way to enumerate vectors in Z^d (for an
arbitrary d that my function will be passed as a parameter, so I don't
know its value in advance) starting with 0, then going through all
vectors with just a single 1 and all other entries 0, then going
through all vectors with a single -1 and all other entries 0, then
going through all vectors with two 1's or -1's and all other entries
0, etc.?  Ideally I could find the next vector in my sequence of
vectors to consider one-at-a-time, so that I don't generate more
vectors than I need to, but I suspect it will be easier to generate
vectors in the sequence in batches, such as all vectors with a single
1 entry, then all vectors with a single -1 entry, and so on.

-- 
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


Re: [sage-support] enumerating vectors in Z^d

2010-05-06 Thread Dan Drake
On Wed, 05 May 2010 at 05:38PM -0700, Eva wrote:
 My question: what is the best way to enumerate vectors in Z^d (for an
 arbitrary d that my function will be passed as a parameter, so I don't
 know its value in advance) starting with 0, then going through all
 vectors with just a single 1 and all other entries 0, then going
 through all vectors with a single -1 and all other entries 0, then
 going through all vectors with two 1's or -1's and all other entries
 0, etc.?  Ideally I could find the next vector in my sequence of
 vectors to consider one-at-a-time, so that I don't generate more
 vectors than I need to, but I suspect it will be easier to generate
 vectors in the sequence in batches, such as all vectors with a single
 1 entry, then all vectors with a single -1 entry, and so on.

One starting point is IntegerVectors -- try IntegerVectors? in a Sage
session. You can do IntegerVectors(5,3) to get an iterator for all
vectors of nonnegative integers of length 3 that sum to 5.

Others may have better ideas, but my first guess is that you'll work with
IntegerVectors(n,d) (for n = 1, 2, 3...) and for each vector, look at
all the nonzero entries and flip the signs in all possible ways. For a
integer vector v, you can find the nonzero entries with something like

[i for i, val in enumerate(v) if val != 0]

and then call Subsets on that list and flip signs:

for indices in Subsets([i for i, val in enumerate(v) if val != 0]):
   w = v[:]
   for index in indices:
   w[index] *= -1
   # now do your coset test stuff

There are probably much better ways to do this, but the above will work,
I think. You can also ask your question in the sage-combinat-devel
group.

Dan

--
---  Dan Drake
-  http://mathsci.kaist.ac.kr/~drake
---


signature.asc
Description: Digital signature


[sage-support] Re: enumerating vectors in Z^d

2010-05-06 Thread Eva


On May 6, 5:21 am, Dan Drake dr...@kaist.edu wrote:
 One starting point is IntegerVectors -- try IntegerVectors? in a Sage
 session. You can do IntegerVectors(5,3) to get an iterator for all
 vectors of nonnegative integers of length 3 that sum to 5.

 Others may have better ideas, but my first guess is that you'll work with
 IntegerVectors(n,d) (for n = 1, 2, 3...) and for each vector, look at
 all the nonzero entries and flip the signs in all possible ways. For a
 integer vector v, you can find the nonzero entries with something like

     [i for i, val in enumerate(v) if val != 0]

 and then call Subsets on that list and flip signs:

     for indices in Subsets([i for i, val in enumerate(v) if val != 0]):
        w = v[:]
        for index in indices:
            w[index] *= -1
        # now do your coset test stuff

 There are probably much better ways to do this, but the above will work,
 I think. You can also ask your question in the sage-combinat-devel
 group.

 Dan

 --
 ---  Dan Drake
 -  http://mathsci.kaist.ac.kr/~drake
 ---

  signature.asc
  1KViewDownload

Hmmm, that will give me vectors ordered by l_1 norm, which would get
me off to a good start!  Is there anything to test/find the l_2 norm
of a vector?

Thanks,
Eva

-- 
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: rational function arithmetic

2010-05-06 Thread JamesHDavenport
On May 5, 10:09 am, Mike Hansen mhan...@gmail.com wrote:
 Hello,

 On Wed, May 5, 2010 at 5:03 AM, Matt Bainbridge

 bainbridge.m...@gmail.com wrote:
  I wrote a sage program which does a lot of arithmetic in the field of
  rational functions Frac(Q[x,y,z]).  The problem is that sage doesn't
  check for common divisors of the numerator and denominator, so after
  doing a lot of arithmetic operations, I end up with rational functions
  whose numerator and denominator are divisible by huge integers (on the
  order of 2^3000).  Is there a reasonable way to get sage to eliminate
  common factors after each arithmetic operation?

 Currently, the easiest way to do this is just to work over
 Frac(ZZ[x,y,z]) which is equivalent.
Yes indeed. The basic problem is that QQ is, morally Frac(ZZ), so you
are nesting Frac constructors.
This is, generally speaking, a bad idea, as we found in Axiom, but
hard to prevent.

 --
 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

-- 
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] Making a movie or animation with 3d plotting of sage: animate() fails with 3D

2010-05-06 Thread isurug
Hello there,
First of all, a very big thank you for this piece of gold: sagemath.
Im loving it!
I could get it to do all i wanted so far without much less fuss! I
have now tried to make an animation or movie with it of some 3d plot i
have.  I want to capture the changes occur in the plot with one
variable. I used animate() but it failed. I'd really appreciate if
anyone can shine some light regarding how this is possible in
Sagemath?

Thank you,
Isuru

-- 
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


Re: [sage-support] Making a movie or animation with 3d plotting of sage: animate() fails with 3D

2010-05-06 Thread Ajay Rawat
use :
@interact

On Thu, May 6, 2010 at 4:04 PM, isurug isurugod...@gmail.com wrote:

 Hello there,
 First of all, a very big thank you for this piece of gold: sagemath.
 Im loving it!
 I could get it to do all i wanted so far without much less fuss! I
 have now tried to make an animation or movie with it of some 3d plot i
 have.  I want to capture the changes occur in the plot with one
 variable. I used animate() but it failed. I'd really appreciate if
 anyone can shine some light regarding how this is possible in
 Sagemath?

 Thank you,
 Isuru

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




-- 
Ajay Rawat
Kalpakkam, IGCAR

-
Save Himalayas
-

-- 
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: Making a movie or animation with 3d plotting of sage: animate() fails with 3D

2010-05-06 Thread Marshall Hampton
If you search this group for animate or animation you can see a
lot of other responses.  One approach is to using ffmpeg to make a
movie out of a sequence of frames you save somewhere (e.g. the DATA
directory).  Another is to use Jmol, but that requires learning a bit
more about Jmol since the functionality isn't wrapped in Sage well
yet.  There has also been some recent progress in including the Theora
codec in Sage, which can be used with html5 (see
http://trac.sagemath.org/sage_trac/ticket/7298).  Eventually the
animate command should be able to use that last option for 3d objects
but I'm not sure how long that's going to take.

-M. Hampton

On May 6, 5:34 am, isurug isurugod...@gmail.com wrote:
 Hello there,
 First of all, a very big thank you for this piece of gold: sagemath.
 Im loving it!
 I could get it to do all i wanted so far without much less fuss! I
 have now tried to make an animation or movie with it of some 3d plot i
 have.  I want to capture the changes occur in the plot with one
 variable. I used animate() but it failed. I'd really appreciate if
 anyone can shine some light regarding how this is possible in
 Sagemath?

 Thank you,
 Isuru

 --
 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 
 athttp://groups.google.com/group/sage-support
 URL:http://www.sagemath.org

-- 
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: Making a movie or animation with 3d plotting of sage: animate() fails with 3D

2010-05-06 Thread Marshall Hampton
I just noticed that saving 3d objects to a file has finally been
fixed: http://trac.sagemath.org/sage_trac/ticket/2872
That means we are one step closer to handling 3d animations.  I can't
find a trac ticket that explicitly targets that but maybe I'm just
missing it.

-M. Hampton

On May 6, 7:10 am, Marshall Hampton hampto...@gmail.com wrote:
 If you search this group for animate or animation you can see a
 lot of other responses.  One approach is to using ffmpeg to make a
 movie out of a sequence of frames you save somewhere (e.g. the DATA
 directory).  Another is to use Jmol, but that requires learning a bit
 more about Jmol since the functionality isn't wrapped in Sage well
 yet.  There has also been some recent progress in including the Theora
 codec in Sage, which can be used with html5 
 (seehttp://trac.sagemath.org/sage_trac/ticket/7298).  Eventually the
 animate command should be able to use that last option for 3d objects
 but I'm not sure how long that's going to take.

 -M. Hampton

 On May 6, 5:34 am, isurug isurugod...@gmail.com wrote:



  Hello there,
  First of all, a very big thank you for this piece of gold: sagemath.
  Im loving it!
  I could get it to do all i wanted so far without much less fuss! I
  have now tried to make an animation or movie with it of some 3d plot i
  have.  I want to capture the changes occur in the plot with one
  variable. I used animate() but it failed. I'd really appreciate if
  anyone can shine some light regarding how this is possible in
  Sagemath?

  Thank you,
  Isuru

  --
  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 
  athttp://groups.google.com/group/sage-support
  URL:http://www.sagemath.org

 --
 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 
 athttp://groups.google.com/group/sage-support
 URL:http://www.sagemath.org

-- 
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


Re: [sage-support] enumerating vectors in Z^d

2010-05-06 Thread Mike Hansen
On Wed, May 5, 2010 at 8:38 PM, Eva eva.cu...@acadiau.ca wrote:
 Problem background: I want to find the smallest (in l_2 norm) vectors
 that satisfy a certain condition - creating a minimal set of coset
 representatives for Z^d/A(Z^d) for a dilation matrix A.  My idea is to
 start with 0 and enumerate vectors in Z^d one at a time.  For each new
 vector that I consider, I can test whether it is in a new coset, or in
 a coset that I already have a representative for.  I know the number
 of cosets in advance, so can stop when I reach the right number of
 coset representatives.

Do you require that the L2 norm is weakly increasing for the order in
which they're produced?

There are a number of ways to get the norm:

sage: v = vector([1,2,3])
sage: v.norm()
sqrt(14)

sage: def l2norm(v):
: return sqrt(sum([i^2 for i in v]))
:
sage: l2norm([0,1,2])
sqrt(5)

--Mike

-- 
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


Re: [sage-support] Re: converting strings to latex

2010-05-06 Thread Georg Damm
Hi Alex,

 If I understand correctly your question, you would like to
  convert arithmetical expressions directly into Latex.

I would like to convert a string into a sage-Latex-expression (in 
sagetex).

 I don't know if it is possible to do it in Sage, but you could
  always write your own function. I've written a small one that
  should do the trick.
[...]
 sage: sarrus(matrix)
 '[1 \\cdot 0 \\cdot 1 + 1 \\cdot (-1) \\cdot (-1) + 1 \\cdot 1
  \\cdot 0] - [1 \\cdot 0 \\cdot (-1) + 1 \\cdot 1 \\cdot 1 + 1
  \\cdot (-1) \ \cdot 0]'
 sage: print sarrus(matrix)
 [1 \cdot 0 \cdot 1 + 1 \cdot (-1) \cdot (-1) + 1 \cdot 1 \cdot 0]
  - [1 \cdot 0 \cdot (-1) + 1 \cdot 1 \cdot 1 + 1 \cdot (-1) \cdot
  0]
 
 Does that answer your problem ?

Thank you for the code (it's more elegant than my first try :) ). It 
doesn't work too, because the problem is that sagetex is putting the 
string in some kind of (typewriter-)enviroment. After some 
experimentation i found a possible solution is to replace \cdot 
with $\cdot$. It doesn't look nice, but better than before.  

Georg

 On 5 mai, 11:28, Dr. Georg Damm georg.d...@web.de wrote:
  Hi all,
 
  i've written a function to explain the rule of sarrus. Is there
  a possibility to return latex code insted of a text? I'd like
  to use something like $\sage{sarrus(A)}$ in sagetex.
 
  Thanks a lot,
 
  Georg
 
  P.S.: I expirimented with JSMathExpr from sage.misc.latex, but
  i couldn't improve the output.
 
  def sarrus(A):
  res=
  for i in range(3):
 
  if (A[0,i]=0):
  res+=++latex(A[0,i])  
  else:
  res+=+(+latex(A[0,i])+)  
  if (A[1,(i+1)%3]=0):
  res+=*+latex(A[1,(i+1)%3])  
  else:
  res+=*(+latex(A[1,(i+1)%3])+)
  if (A[2,(i+2)%3]=0):
  res+=*+latex(A[2,(i+2)%3])  
  else:
  res+=*(+latex(A[2,(i+2)%3])+)
 
  for i in range(2,5):
  if (A[0,i%3]=0):
  res+=-+latex(A[0,i%3])  
  else:
  res+=-(+latex(A[0,i%3])+)  
  if (A[1,(i-1)%3] = 0):
  res+=*+latex(A[1,(i-1)%3])  
  else:
  res+=*(+latex(A[1,(i-1)%3])+)
  if (A[2,(i-2)%3]=0):
  res+=*+latex(A[2,(i-2)%3])  
  else:
  res+=*(+latex(A[2,(i-2)%3])+)
  return res
 
  --
  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
  athttp://groups.google.com/group/sage-support
  URL:http://www.sagemath.org
 

-- 
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: Sagetex wont plot

2010-05-06 Thread Oscar
I tried export PATH=/Applications/sage/:$PATH  in Terminal and got
this:

export: Command not found.

I'm running Mac OS 10.5.8.

Oscar Chavez

On May 5, 7:54 pm, Dan Drake dr...@kaist.edu wrote:
 On Wed, 05 May 2010 at 07:38AM -0600, jrodri1...@gmail.com wrote:
  Thanks!!! I got that working. But, I stumbled onto something else...

  I tried copying my file into the same directory as the sage file and
  running it from there. The interesting thing is that I can only run
  sage if I type sage\sage (when in the Applications folder) or
  /Applications/sage/sage. I can't actually cd into the sage folder
  itself and simply type in sage. Is that normal?

 It's normal if you haven't added the right directory to your $PATH.
 While in a terminal, you can do

       export PATH=/Applications/sage/:$PATH

 and after that, you should be able to just type sage and get Sage to
 run. If you run Sage from inside TeXShop, you don't need to do anything
 because (IIRC) it automatically looks for Sage in /Applications/sage.

 Dan

 --
 ---  Dan Drake
 -  http://mathsci.kaist.ac.kr/~drake
 ---

  signature.asc
  1KViewDownload

-- 
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] How to add grid lines to plot?

2010-05-06 Thread Eugene Goldberg
Hello!

There is plot:
p=plot(sin,0,2*pi)
How to add grid lines to this plot?

-- 
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


Re: [sage-support] How to add grid lines to plot?

2010-05-06 Thread Mike Hansen
Hello,

On Thu, May 6, 2010 at 2:14 PM, Eugene Goldberg omegat...@gmail.com wrote:
 There is plot:
 p=plot(sin,0,2*pi)
 How to add grid lines to this plot?

plot(sin,0,2*pi,gridlines=True)

You can look at the documentation of plot for more examples.

--Mike

-- 
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: converting strings to latex

2010-05-06 Thread ablondin
Ok, I think I understand your problem. I had something similar before.
The problem is that the object returned by the function sarrus is a
'str',
which sagetex format so that it replaces every underscore, etc. with
\_ to make it work in Latex. If you don't want the output to be
modified,
you have to use LatexExpr object

def sarrus(A):
bracket_neg = lambda i:str(i) if i = 0 else '(' + str(i) + ')'
res = '['

for i in range(3):
for j in range(3):
a_ij = A[j, (i+j)%3]
if j  0: res += ' \\cdot '
res += bracket_neg(a_ij)
if i  2: res += ' + '

res += '] - ['

for i in range(3):
for j in range(3):
a_ij = A[j, (2-i-j)%3]
if j  0: res += ' \\cdot '
res += bracket_neg(a_ij)
if i  2: res += ' + '

res += ']'

from sage.misc.latex import LatexExpr
return LatexExpr(res)

and when you call \sage{sarrus(A)}, you must put in between dollar
signs. Feel free to ask further if it doesn't solve your problem !

Alex

On 6 mai, 10:29, Georg Damm georg.d...@web.de wrote:
 Hi Alex,

  If I understand correctly your question, you would like to
   convert arithmetical expressions directly into Latex.

 I would like to convert a string into a sage-Latex-expression (in
 sagetex).



  I don't know if it is possible to do it in Sage, but you could
   always write your own function. I've written a small one that
   should do the trick.
 [...]
  sage: sarrus(matrix)
  '[1 \\cdot 0 \\cdot 1 + 1 \\cdot (-1) \\cdot (-1) + 1 \\cdot 1
   \\cdot 0] - [1 \\cdot 0 \\cdot (-1) + 1 \\cdot 1 \\cdot 1 + 1
   \\cdot (-1) \ \cdot 0]'
  sage: print sarrus(matrix)
  [1 \cdot 0 \cdot 1 + 1 \cdot (-1) \cdot (-1) + 1 \cdot 1 \cdot 0]
   - [1 \cdot 0 \cdot (-1) + 1 \cdot 1 \cdot 1 + 1 \cdot (-1) \cdot
   0]

  Does that answer your problem ?

 Thank you for the code (it's more elegant than my first try :) ). It
 doesn't work too, because the problem is that sagetex is putting the
 string in some kind of (typewriter-)enviroment. After some
 experimentation i found a possible solution is to replace \cdot
 with $\cdot$. It doesn't look nice, but better than before.  

 Georg



  On 5 mai, 11:28, Dr. Georg Damm georg.d...@web.de wrote:
   Hi all,

   i've written a function to explain the rule of sarrus. Is there
   a possibility to return latex code insted of a text? I'd like
   to use something like $\sage{sarrus(A)}$ in sagetex.

   Thanks a lot,

   Georg

   P.S.: I expirimented with JSMathExpr from sage.misc.latex, but
   i couldn't improve the output.

   def sarrus(A):
       res=
       for i in range(3):

           if (A[0,i]=0):
               res+=++latex(A[0,i])  
           else:
               res+=+(+latex(A[0,i])+)  
           if (A[1,(i+1)%3]=0):
               res+=*+latex(A[1,(i+1)%3])  
           else:
               res+=*(+latex(A[1,(i+1)%3])+)
           if (A[2,(i+2)%3]=0):
               res+=*+latex(A[2,(i+2)%3])  
           else:
               res+=*(+latex(A[2,(i+2)%3])+)

       for i in range(2,5):
           if (A[0,i%3]=0):
               res+=-+latex(A[0,i%3])  
           else:
               res+=-(+latex(A[0,i%3])+)  
           if (A[1,(i-1)%3] = 0):
               res+=*+latex(A[1,(i-1)%3])  
           else:
               res+=*(+latex(A[1,(i-1)%3])+)
           if (A[2,(i-2)%3]=0):
               res+=*+latex(A[2,(i-2)%3])  
           else:
               res+=*(+latex(A[2,(i-2)%3])+)
       return res

   --
   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
   athttp://groups.google.com/group/sage-support
   URL:http://www.sagemath.org

 --
 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 
 athttp://groups.google.com/group/sage-support
 URL:http://www.sagemath.org

-- 
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