On Thu, Sep 22, 2011 at 1:37 PM, Anna Haensch <annahaen...@gmail.com> wrote: > Is there any way in sage, or rather python, to define a function which > takes as its input n variables, rather than assigning a fixed > number? > > I've just written a piece of code for the Quadratic Forms module, > which takes as input a Quadratic Lattice, Q, and three vectors, so > (Q,v_1,v_2,v_3), and it generates the lattice L which is on the same > underlying quadratic space as Q but with basis v_1,v_2,v_3.
You can do something like the following: sage: def f(*args): ....: return sum(args) ....: sage: f(1,2,3) 6 sage: f(2,3,5,8) 18 For more info, you can look at http://www.saltycrane.com/blog/2008/01/how-to-use-args-and-kwargs-in-python/ or in more detail at http://docs.python.org/tutorial/controlflow.html#defining-functions --Mike > Now, at the moment this is only for ternary forms, but I'd like to > extend it to forms of any finite dimension. The problem is that I > can't see how to input vectors v_1,...,v_n. > > Any tips would be greatly appreciated! > > Thanks, > Anna > > -- > To post to this group, send an email to sage-devel@googlegroups.com > To unsubscribe from this group, send an email to > sage-devel+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/sage-devel > URL: http://www.sagemath.org > -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org