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.Tue, 03 Feb 2015 15:17:58 +0100Series and Sequences (Sage x Mathematica)https://ask.sagemath.org/question/25685/series-and-sequences-sage-x-mathematica/Hello, all.
I am trying to move from Mathematica to Sage Math but I'm facing basic issues. I had read the manual and searched for the answer in many results from google and found no answer to things like this:
In Mathematica, if I want to generate a sequence of integers I do the following (just an example):
Table[4*n^2 + 3, {n, 0, 50}] **or** Array[4 #^2 + 3 &, 44, 0]
and it will output the following:
{3, 7, 19, 39, 67, 103, 147, 199, 259, 327, 403, 487, 579, 679, 787, 903, 1027, 1159, 1299, 1447, 1603, 1767, 1939, 2119, 2307, 2503, 2707, 2919, 3139, 3367, 3603, 3847, 4099, 4359, 4627, 4903, 5187, 5479, 5779, 6087, 6403, 6727, 7059, 7399}
I saw the command range() but it doesn't accept a formula. Also, there is a mix of commands between Maxima and Python ... I'm really lost.
How can I generate the same list using Sage?
Thank you.Tue, 03 Feb 2015 04:50:47 +0100https://ask.sagemath.org/question/25685/series-and-sequences-sage-x-mathematica/Answer by LRM for <p>Hello, all.</p>
<p>I am trying to move from Mathematica to Sage Math but I'm facing basic issues. I had read the manual and searched for the answer in many results from google and found no answer to things like this:</p>
<p>In Mathematica, if I want to generate a sequence of integers I do the following (just an example):</p>
<pre><code>Table[4*n^2 + 3, {n, 0, 50}] **or** Array[4 #^2 + 3 &, 44, 0]
</code></pre>
<p>and it will output the following:</p>
<pre><code>{3, 7, 19, 39, 67, 103, 147, 199, 259, 327, 403, 487, 579, 679, 787, 903, 1027, 1159, 1299, 1447, 1603, 1767, 1939, 2119, 2307, 2503, 2707, 2919, 3139, 3367, 3603, 3847, 4099, 4359, 4627, 4903, 5187, 5479, 5779, 6087, 6403, 6727, 7059, 7399}
</code></pre>
<p>I saw the command range() but it doesn't accept a formula. Also, there is a mix of commands between Maxima and Python ... I'm really lost.</p>
<p>How can I generate the same list using Sage?</p>
<p>Thank you.</p>
https://ask.sagemath.org/question/25685/series-and-sequences-sage-x-mathematica/?answer=25686#post-id-25686 I found my own answer based on a related question, here is how I can do the same:
[(n,4*n^2 + 3) for n in range(51)]
Maybe I can find more ways to generate such sequences, maybe using lambda / "pure functions"
Tue, 03 Feb 2015 04:56:59 +0100https://ask.sagemath.org/question/25685/series-and-sequences-sage-x-mathematica/?answer=25686#post-id-25686Comment by kcrisman for <p>I found my own answer based on a related question, here is how I can do the same:</p>
<p>[(n,4*n^2 + 3) for n in range(51)] </p>
<p>Maybe I can find more ways to generate such sequences, maybe using lambda / "pure functions"</p>
https://ask.sagemath.org/question/25685/series-and-sequences-sage-x-mathematica/?comment=25693#post-id-25693Yes, many such things are automatically available in Python, which is a powerful general-purpose programming language. You may also find the `table` command quite useful - just type `table?` and read the documentation for it.Tue, 03 Feb 2015 15:17:58 +0100https://ask.sagemath.org/question/25685/series-and-sequences-sage-x-mathematica/?comment=25693#post-id-25693Comment by vdelecroix for <p>I found my own answer based on a related question, here is how I can do the same:</p>
<p>[(n,4*n^2 + 3) for n in range(51)] </p>
<p>Maybe I can find more ways to generate such sequences, maybe using lambda / "pure functions"</p>
https://ask.sagemath.org/question/25685/series-and-sequences-sage-x-mathematica/?comment=25690#post-id-25690List comprehension as you did is the most common way. But as you wrote it, the output is a list of pairs and not {3, 7, ..., }. There is also the possibility of using: filter(lambda n: 4*n^2+3, range(51)) which I found less useful.Tue, 03 Feb 2015 11:34:49 +0100https://ask.sagemath.org/question/25685/series-and-sequences-sage-x-mathematica/?comment=25690#post-id-25690