Re: if-expression and variables
Ralf Hemmecke <[email protected]> Tue, 03 May 2011 11:21:12 +0200
| Newsgroups | gmane.comp.mathematics.axiom.general |
|---|---|
| Message-ID | <[email protected]> |
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 > 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. >