In Axiom, we can implement a characteristic function for a
given set, in the category of sets, which would avoid
division by zero. This can take care of the provisos. If
I am not mistaken, the step(a,b,x) is the characteristic
function for the interval set [a,b], but the
implementation below, as pointed out, may cause division
by zero. We can use "if-then-else" to implement it
instead.
William
On Fri, 10 Jun 2011 19:56:18 +0200
Stefan Karrmann <[email protected]> wrote:
Dear all,
we can help ourselves in some cases by:
sign x == (abs x)/x
H x == (1 + sign x)/2
step (a,b,x) == (H(x-a)) * (H(b-x))
The drawback is that we get a 'Division by zero'.
Kind regards,
Stefan
Am Donnerstag, den 05.05.2011, 00:23 -0400 schrieb
William Sit:
Dear Stefan:
You posed a legitimate problem: how should symbolic
computation handle piecewise defined functions, and in
particular, how to integrate such a function.
Maple and Mathematica both can handle piecewise
functions.
Look up "piecewise" from Maple Help. You can easily
define
a piecewise function, and differentiate or integrate it.
Indeed, Maple says:
The piecewise function can be differentiated,
integrated,
simplified, plotted, and used in the following types of
differential equations: constant coefficients and
discontinuous perturbation function, general first-order
linear, Riccati, and some other classes which are
handled
by integration or variation of parameter. See
dsolve[piecewise] for more details. series, limit, abs,
and signum can handle the piecewise function.
As example, the desired solution the problem of
integrating f(x) from 0 to t, where f(x) is 2x if x < 10
and 5x^2 otherwise, should be the function g(t), defined
as t^2 if t < 10 and -4000/3 +(5 t^3)/3 otherwise. Maple
does exactly that. In fact, I even tried to integrate
f(f(x)) and f(f(x+1)) and Maple does it with no problems
with all the cases covered.
Mathematica has a similar function called Piecewise to
construct piecewise functions, and like Maple, Piecewise
can be used in such functions as Integrate, Minimize,
Reduce, DSolve and Simplify, as well as their numeric
analogs.
This may be an uncovered domain in Axiom. A search for
"piecewise" shows no hits. I think piecewise functions
have to be separately handled, particularly in case
analysis (possibly involving semi-algebraic sets and
CAD)
if there is any indefiniteness in the answer (like an
indefinite integral). There is some evidence that if the
user does not use the built-in "piecewise" or
"Piecewise"
function, but uses an if-then-else construction, neither
Maple nor Mathematica can handle subsequent mathematical
calculations. For example, the system would not do the
case analysis, much less the "simplification"
automatically, but would present the result as the
integral of If[x < 10, 2 x, 5 x^2] (in Mathematica; I
did
not try Maple). Even when the case analysis is done, it
would still not simplify or evaluate the integrals:
h[x_] := If[x < 10, Integrate[2 y, {y, 0, x}],
Integrate[2 y, {y, 0, 10}] + Integrate[5 y^2, {y, 10,
x}]]
when h[x] is called. It will evaluate on numerical
inputs.
In our earlier discussions, we were "lured" into using
"if-the-else" constructions and thus got the feeling
that
this is difficult to handle. The confusion is that we
interpret "x < 10" as an binary relation, whereas it
should be handled as a semi-algebraic set (in one
dimension, this is just an interval)!
However, the algorithms seem to be there, and someone
should implement them in Axiom if it is not already done
but hidden in some obscure packages.
William
On Wed, 04 May 2011 22:37:48 +0200
Stefan Karrmann <[email protected]> wrote:
> Dear all,
>
> thanks for your answers. They clears a lot.
>
> I actually want to integrate test1 and solve an
>differential equation
> with it.
>
> E.g.
> test2 x == rho * test1 x
> y = operator 'y
> odeq := D(y x) = test2 x
> solve(odeq, y, x)
>
> Obviously, the solution is "formally"
>
> y_sol x == integrate(test2 x,x)
>
> Kind regards,
> Stefan
>
> Am Dienstag, den 03.05.2011, 11:21 +0200 schrieb Ralf
>Hemmecke:
>> Dear Stefan,
>>
>> as others already have pointed out, for Axiom, your
>>question is not
>> really well posed.
>>
>> In Axiom
>>
>> if x<10 then 2*x else 5*x^2
>>
>> is *not* an expression (as you might know it from
other
>>untyped CAS like
>> Mathematica or Maple), but rather a programming
language
>>construct. In
>> other words, if Axiom sees this, it is evaluated. So
the
>>result is
>> either 2*x or 5*x^2 depending on the (boolean)
outcome
>>of the evaluation
>> of x<10.
>>
>> I think, Bill suggested to use something like
InputForm.
>>There it would
>> be possible to represent an if-expression
unevaluated.
>>
>> But you should rather say what you actually want
(it's
>>not the same what
>> you expect).
>>
>> In order for us to suggest you a proper way to handle
>>your use case, you
>> should tell us why you want a piecewise function and
>>(more important)
>> what you later want to do with that function.
>>
>> Until we have that information, everything would be
just
>>digging in the
>> dark.
>>
>> Ralf
>>
>> On 04/30/2011 08:40 PM, Stefan Karrmann wrote:
>> > Dear all,
>> >
>> > I'm new to axiom and have a problem with piecewise
>>functions.
>> >
>> > test1 (x | x< 10) == 2*x
>> > test1 (x | x >= 10) == 5*x^2
>> > [was typo: test1 (x | x< 10) == 5*x^2]
>> > test1
>> > ->
>> > test1 (x | x< 10) == 2x
>> > test1 (x | ^ x< 10) == 5x
>> >
>>
Type:
>>FunctionCalled
>> > test1 y
>> > ->
>> > 2
>> > 5y
>> >
>> > I expected something like (if y< 10 then 2*y else
>>5*y**2).
>> >
>> > How is it possible to pass a Variable to a
piecewise
>>function respecting
>> > the pieces?
>> >
>> > PS: Using a block and => or explicit if-then-else
>>does not help.
>
>
> _______________________________________________
> Axiom-math mailing list
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/axiom-math
William Sit, Professor Emeritus
Mathematics, City College of New York
Office: R6/291D Tel: 212-650-5179
Home Page: http://scisun.sci.ccny.cuny.edu/~wyscc/
William Sit, Professor Emeritus
Mathematics, City College of New York
Office: R6/291D Tel: 212-650-5179
Home Page: http://scisun.sci.ccny.cuny.edu/~wyscc/
_______________________________________________
Axiom-math mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/axiom-math