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, 30 Jun 2011 12:15:47 +0200Running PARI/GP and Sagehttps://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?Thu, 30 Jun 2011 04:35:14 +0200https://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>
https://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 12:15:47 +0200https://ask.sagemath.org/question/7839/running-parigp-and-sage/?answer=12477#post-id-12477