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

edit retag close merge delete

Sort by » oldest newest most voted

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"

more

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

1

Yes, 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.