You can define a function which takes a list or tuple as an argument,
and then you can iterate through its elements, with tests if you like.

sage: def sum_elements_whose_square_is_one(x):
....:     return sum(a for a in x if a^2 == 1)

Then for example:

sage: sum_elements_whose_square_is_one([1,2,3,4,-1,])
0

If that does not answer your question, please give
a concrete example of a function you want to define.

Or even wrong code that shows what you want.

[email protected] wrote:

I am a primitive sage user and I want to produce a function of n variables 
(x[1],x[2],...,x[n]), in nested 'for' loops. I've searched in sage's 
documentation, but I have still 2 problems:
1. How to define a list of variables, such that I can use its items, as 
independent variables, in loops. The loops are needed because the function 
is made up of sums of multiplications of clauses of these variables? 
2. How to simplify the result of loops according to some extra conditions, 
such as x[i]^2==1 ?

>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to