On Jun 27, 3:22 pm, Michael Orlitzky <mich...@orlitzky.com> wrote:
> I'll take a simple example. I'd like to integrate (or differentiate, or
> whatever) the following function,
>
>   x = var('x')
>
>   a = x
>   b = 2*x


Here you probably mean something else.  Are you getting a deprecation
warning?

It's better to define

a(x) = x
b(x) = 2*x

in which case you don't need to define x as a variable, it will be
done for you.  The difference is between function notation and
"symbolic expressions"; basically, one of them allows input nicely
because you said what the variable was, the other doesn't.  The
canonical example is

f = x + y - y

f(2) = ???

I don't actually quite agree with this, but it's a design decision
that's been made that in this case it's not clear whether x or y was
the input.  Doing

f(x) = x + y - y

makes it explicit (in accordance with Python style) that x is the
variable.

>
>   def f(x):
>     if (a(x) < b(x)):

in which case this would be fine

>       return 0
>     else:
>       return 1
>
> in Python code. Is there a way to make functions like these behave
> symbolically?

The easiest way to do this is to make them a class inheriting from
BuiltinFunction.  There are some very good examples in the functions/
folder.

I don't think that the Piecewise class can handle this sort of thing,
and in any case its capabilities are somewhat limited.

However, it might be nice to have something that was a wrapper

@symbolicfunction
def f(x):
   return some_expression_in_x(x)

Others have ideas whether this is good/feasible?

- kcrisman

-- 
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
URL: http://www.sagemath.org

Reply via email to