On Sat, Sep 19, 2009 at 12:18 PM, Francois Maltey <fmal...@nerim.fr> wrote:
>
> Hello,
>
> Is it possible to compose/iterate functions in sage by a functional way
> without any loop for or while.
>
> When I used mupad I could get the u(100) term of this sequence by :
>
> (sin@@100) (1) # u(0)=1 and u(n+1)=sin (u(n))
>
> What does sage propose ? (without any loop)

Python proposes... legible code?  I can't even tell what the above does.

> An other question :
>
> How can I insert a test in a map(anonymous function) or [calculus for x
> in list].
> I can do it when I declare a external new function, but I can't inside
> the map or the [calculus in list]
> if...then...else in Maple, Mupad or Axiom send a result. Even with a
> return I can't do it in lambda.
>
> This mupad-command creates a tridiagonal matrix :
> matrix (4,4, (i,j)->if abs (i-j) <= 1 then 1 else 0 end_if)
>
> How can I do with sage.

sage: matrix(4,4, [ 1 if abs(i-j) <= 1 else 0  for i in [1..4] for j in [1..4]])
[1 1 0 0]
[1 1 1 0]
[0 1 1 1]
[0 0 1 1]

Python has conditional expressions, e.g.,

     X if <condition> else Y

means "if <condition> is true evaluate to X, otherwise evaluate to Y".

See http://docs.python.org/whatsnew/2.5.html#pep-308

William



>
> F.
>
>
>
>
> >
>



-- 
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to