Maxima currently cannot handle piecewise definitions in any reasonable way.
Although there does exist a mechanism for *expressing* piecewise
definitions, you can do almost nothing useful with them:
To define an expression (not a function, we'll get to that) that is 0
for x<0 and 1 otherwise:
expr: 'if x<0 then 0 else 1
(This is *not* the same as '(if ...) .)
Note the quotation mark before the "if". That means that the
condition should not be evaluated immediately, but left in suspense.
That expression prints out (obscurely) as:
expr =>
cond(x<0,0,true,1)
Now, you'd think that if you substituted some particular value of x,
this would simplify, but it doesn't:
expr, x=3 =>
cond(3>0,3,true,0) --No simplification
subst(3,x,expr) =>
cond(3>0,3,true,0) -- No simplification
not even if you force an extra evaluation:
expr,x=3,eval => same thing
As it happens, "cond" is a so-called noun-form, so let's try
expr,x=3,cond =>
cond(3>0,3,true,0) -- Nope
*but*
expr,x=3,nouns => 3
expr,x=3,"if" => 3
Success, sort of. But Maxima doesn't know how to do anything
intelligent with these expressions:
diff(expr,x) => useless
integrate(expr,x) => useless
limit(expr,x,inf) => useless
is(expr>=0) => doesn't know
This has been discussed several times, and the basic part of the
solution is certainly doable... but someone has to do it.
---------------------
Now back to the issue of "functions" vs. "expressions".
Maxima provides a way of defining a procedure with a return value,
often called a "function" in programming contexts. That is the ":="
syntax:
f(x) := if x<0 then 0 else 1$
This is *not* a mathematical function definition. In fact, Maxima has
no way of defining a mathematical function (named or not). As in the
"if" case above, Maxima does have a "lambda" operator, but it knows
nothing about it mathematically. For example,
diff( lambda([a],a*x), x)
should presumably return
lambda([a],a)
but it does not. In fact, lambda, like if, really only works as a
programming construct, not a mathematical construct.
Maxima, instead, operates on mathematical **expressions**, so you'd say
diff( a*x , x) => a
Hope this explanation helps.
-s