So it seems there are (at least!) two classes of functions; those which accept symbolic input, like sin:
m(x)=sin(x/2) and those which don't, such as mod. I had not realized there was such a distinction. Thank you all. -Alasdair On Jul 2, 5:15 am, William Stein <wst...@gmail.com> wrote: > On Wed, Jul 1, 2009 at 8:52 PM, Simon King<simon.k...@uni-jena.de> wrote: > > > Hi Alasdair, > > > On 1 Jul., 13:00, David Joyner <wdjoy...@gmail.com> wrote: > >> I think the first tries to use Sage's symbolic expression machinery > >> but the second does not. > > > Yes, it seems so. > > > Using Sage, one should always be aware that some very handy/fancy > > syntax is only available due to the Sage preparser. > > > E.g., some definitions such as f(x) = sin(x) or R.<x>=QQ[] are not > > valid Python. But when you do this in Sage, it internally becomes > > sage: preparse('m(x)=sin(x)') > > '__tmp__=var("x"); m = symbolic_expression(sin(x)).function(x)' > > > In your first approach, you get '__tmp__=var("x"); m = > > symbolic_expression(mod(x,Integer(10))).function(x)' > > > But mod(x,Integer(10)) gives an error, since x is a symbolic variable > > and not an integer, and since "mod" is not symbolic, in contrast to > > "sin": > > sage: type(sin) > > <class 'sage.functions.trig.Function_sin'> > > sage: type(mod) > > <type 'builtin_function_or_method'> > > For the record, at some point we may want to make "mod" work with > symbolic input. > I.e., I don't see any reason why at some point in the future we could > make the following make sense: > > sage: x = var('x') > sage: f = mod(x, 3) > sage: f > Mod(x, 3) > sage: f.subs(x=5) > 2 > > This is already how Mathematica works: > > f := Mod[x,3]; f > Mod[x, 3] > > f /. x -> 5 > 2 > > William --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---