Consider the following scenario (which I tested at SageMathCloud), with an Ipython-Notebook:
%load_ext sage
import trans
def A():
""" Computes the factorial """
n, f = 1, 1
while True:
f = f*n
yield f
n += 1
def binomial_trans(seq):
""" Input : seq sequence generator """
S = []
n = 0
while True:
S.append(seq.next())
yield sum(binomial(n, k) * S[k] for k in (0..n))
n += 1
f = binomial_trans(A())
print [f.next() for _ in range(10)]
This works. Now I would like to outsource the function 'binomial_trans' in a file trans.py and compute
f = trans.binomial_trans(A())
print [f.next() for _ in range(10)]
This does not work. The error message is: AttributeError: 'float' object has no attribute 'n'
What can I do to make the import work together with Sage in an Ipython-Notebook?
Peter