ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 18 Aug 2018 01:21:34 -0500How can I find the sum of fibonacci (1) + (2) + (4) + (7) + (11) + (16) + ... ?https://ask.sagemath.org/question/43408/how-can-i-find-the-sum-of-fibonacci-1-2-4-7-11-16/ How can I find the sum of fibonacci (1) + (2) + (4) + (7) + (11) + (16) + ... ?
* The numbers in () means the terms of fibonacci sequencepizzaSat, 18 Aug 2018 01:21:34 -0500https://ask.sagemath.org/question/43408/Factorization sequence to enumerated sequence in Sagehttps://ask.sagemath.org/question/39678/factorization-sequence-to-enumerated-sequence-in-sage/I have the following Magma code that I want to rewrite in Sage:
Eltseq(Random(FiniteField(2^8)));
This basically produces the following result: `[ 0, 1, 0, 1, 1, 1, 0, 1 ]`. The function `Eltseq` is defined as this in the documentation (https://magma.maths.usyd.edu.au/magma/handbook/text/166):
> Given a factorization sequence f,
> create the enumerated sequence
> containing the same pairs of primes
> and exponents.
Any ideas how can I rewrite this line in Sage?whateverMon, 20 Nov 2017 12:22:19 -0600https://ask.sagemath.org/question/39678/Problem with Sequence commandhttps://ask.sagemath.org/question/34956/problem-with-sequence-command/ Computation of gcd of objects of a class a created fails. I investigated the case and traced down that the problem lies in Sequence command. Consider the following example class:
class foo(object) :
def __init__(self, L_) :
self.L = deepcopy(L_)
def __getitem__(self, j) :
return self.L[j]
def size(self) :
return len(self.L)
Create and example object:
a = foo( [1,2,3] )
print a.size()
>> 3
Build a nested object:
A = foo([ foo([1,2,3]), foo([2,4,8]), foo([1,1]), foo([1]) ])
print A.size()
>> 4
Everything works as expected. So let's iterate over A:
for a in A :
print a.size()
>> 3
>> 3
>> 2
>> 1
So far so good. Let's use Sequence as gcd internally does:
S = Sequence(A)
for s in S :
print s.size()
>> `TypeError: object of type 'foo' has no len()`
And boom! Something went wrong. Try to call len explicitly:
for s in S :
print len(s.L)
>> `TypeError: object of type 'foo' has no len()`
The same error! Surprisingly the following code actually works (but IMHO it should not):
for s in S :
print len(s.L.L)
>> 3
>> 3
>> 2
>> 1
It seems like something strange happens in initialization. When creating a sequence, all objects get initialized by themselves.
Ok. So here is my question: what's up? Do I do something wrong or is this a bug in `Sequence`? I know that Python does not provide copy constructors, hence how to initialize objects to avoid this kind of problems?
Thanks in advance,
Przemek
_pkMon, 26 Sep 2016 11:24:23 -0500https://ask.sagemath.org/question/34956/Symbolic function that sums over variable sequencehttps://ask.sagemath.org/question/31674/symbolic-function-that-sums-over-variable-sequence/How do I define a symbolic function that takes a sum of variables as value?
I have tried the following:
k=var('k')
f(x)=sum(x[k], k, 1, 5)
But I get the following error:
TypeError: unable to convert k to an integer
I want to be able to symbolically differentiate `f` with regards to e.g. `x[3]`.jonatanFri, 18 Dec 2015 04:16:12 -0600https://ask.sagemath.org/question/31674/Series 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.LRMMon, 02 Feb 2015 21:50:47 -0600https://ask.sagemath.org/question/25685/Plotting Sequence of Pointshttps://ask.sagemath.org/question/10475/plotting-sequence-of-points/How do I plot the sequence {1/n} for n = 1 to 100 in Sage? I browsed plot?, but didn't see it as an option, or I didn't know what it was called. david8381Tue, 27 Aug 2013 06:43:54 -0500https://ask.sagemath.org/question/10475/Plot a function involving lowest termshttps://ask.sagemath.org/question/10372/plot-a-function-involving-lowest-terms/Hi,
How do I use sage to plot the following function?
$$ f(x)= \left[ \begin {array} {cc} 0, & x \text{ irrational, } 0 \lt x \lt 1 \\\\
\frac{1}{q},& x = \frac{p}{q} \text{ in lowest term, } 0 < x < 1.\end{array} \right.$$
I actually wrote a function that would generate the following sequence:
$$ \frac{1}{n}, \dots , \frac{n-1}{n}$$ for a given $n$.
Then I created a list of lists that contains the above sequence for each n. After flattening that list, I call the set function on it to remove duplicates. Then I use that to creat a list (x,y) tuple to plot the function using scatter plot.
I was wondering if there is a simpler way of doing this.
ensabaMon, 22 Jul 2013 00:33:41 -0500https://ask.sagemath.org/question/10372/How to find limit of a recursive sequence?https://ask.sagemath.org/question/9562/how-to-find-limit-of-a-recursive-sequence/For example, I have this sequence:
f(0) = 1
f(n) = 1/5 * (f(n-1)^2 + f(n-1) + 3)
How do I find the limit of this sequence? I have been searching for how to do this for a while, but I can't find the answer.ZombifierSat, 24 Nov 2012 16:57:16 -0600https://ask.sagemath.org/question/9562/