ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 30 Jun 2011 05:15:47 -0500Running PARI/GP and Sagehttp://ask.sagemath.org/question/7839/running-parigp-and-sage/Suppose I have a function a(i) in PARI/GP code. To evaluate something like a(5) in sage code I write pari('a[5]'). However, running the for loop on pari('a[i]') doesn't seem to work. Is there a work around for this?Wed, 29 Jun 2011 21:35:14 -0500http://ask.sagemath.org/question/7839/running-parigp-and-sage/Answer by cswiercz for <p>Suppose I have a function a(i) in PARI/GP code. To evaluate something like a(5) in sage code I write pari('a[5]'). However, running the for loop on pari('a[i]') doesn't seem to work. Is there a work around for this?</p>
http://ask.sagemath.org/question/7839/running-parigp-and-sage/?answer=12477#post-id-12477Running
for i in range(n):
pari('a[i]')
won't work since `'a[i]'` is a string. Try something like this instead:
for i in range(n):
pari('a[%d]' %(i))
This will actually substitute the values `i` takes on into the string expressions you want to evaluate.Thu, 30 Jun 2011 05:15:47 -0500http://ask.sagemath.org/question/7839/running-parigp-and-sage/?answer=12477#post-id-12477