On Dec 9, 2009, at 5:40 AM, Pablo De Napoli wrote:

> Many thanks to everybody for your help.
>
> some questions/remarks:
>
> 1) ¿Does every function needs to have two versions: a symbolic one and
> a numerical one?

Somewhat. The situation arises because one often only defines the  
function numerically (i.e. it's an algorithm that takes numerical  
input and returns numerical output), but wants to use it in symbolic  
contexts.

> 2) the current implementation treats f(x)=sin(x) as a symbolic  
> expression
>
> sage: f(x)=sin(x)
> sage: f
> x |--> sin(x)
> sage: type(f)
> <type 'sage.symbolic.expression.Expression'>
>
> However, mathematically a function is something different: for  
> instance it
> has a domain and a range (say: this function takes one real number as
> argument, and returns another real number).
>
> ¿is there some way to express this in Sage? (I know this might be  
> difficult as
> python is dynamically typed).
>
> This might be important for instance, when applying some operator to
> the function. For instance: the results of one operation can be
> different if the function is considered as one of a real variable, or
> as one of a complex variable (say).
>
> I think it would be important to have some unified framework for
> functions, so that users
> don't see that one function acts in one way and some other in a  
> different way.

Right now functions do act differently depending on their input:

sage: log(2.0, 5.0)
0.430676558073393

sage: log(mod(2, 17), mod(5, 17))
6

If one looks at the source of log(a,b), the first thing it tries to do  
is call a.log(b), which may do entirely different things depending on  
what a is. I see this as a good thing--otherwise one would have to  
have a whole bunch of log functions (log_real, log_complex,  
descrete_log, ... (Actually, this last one would be an infinite  
collection of log functions with distinct domains.)) That would  
clutter the namespace and also make choosing the right one hard to  
remember. Rather than view log as a function, I view it as a symbol  
whose meaning is context sensitive.

Of course, there are situations where one would want to specify the  
domain and range of a function, especially for user-defined functions.

- Robert


-- 
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

Reply via email to