On June 1, 2007 8:11 PM Sumant S.R. Oemrawsingh wrote: > > I filed a report on IssueTracker, but accidentally filed it > twice (n00bs...) Sorry for that.
No problem. I deleted the first one. Only this one remains: http://wiki.axiom-developer.org/358VariableIsApparentlyAlwaysAssumedToBePosi tive > The latter filing is more complete and correctly categorised. Good. Thanks for submitting the report! Normally I would add my comments directly to the report, but I think this one deserves a little discussion first because it is important to understand what Axiom is doing with your commands. First of all to make things clear I suggest you declare the function f as applying to an integer and yielding an integer, like this: (1) -> f:Integer->Integer Type: Void In fact in Axiom all functions have a specified domain and co-domain (signature), although sometimes the Axiom interpreter will make some assumptions about the domain and co-domain for you. Now you can define the body of the function as follows: (2) -> f(x|x<0)==-x**2 Type: Void (3) -> f(x|x>=0)==x**2 Type: Void And try evaluating it for some example values: (4) -> f(5) Compiling function f with type Integer -> Integer (4) 25 Type: PositiveInteger (5) -> f(-5) (5) - 25 Type: Integer But what happens if you just write 'f(x)'? (6) -> f(x) Conversion failed in the compiled user function f . Cannot convert from type Symbol to Integer for value x Do you see why this failed? x is not an Integer - it is a symbol! So what happened in your example in issue #358 ? You did not specify the signature of the function so the Axiom interpreter assigned one for you. E.g. (6) -> )cl all All user variables and function definitions have been cleared. (1) -> f(x|x<0)==-x**2 Type: Void (2) -> f(x|x>=0)==x**2 Type: Void So far we have only specified the body of the function. It has no signature. This is only a function prototype, not an actual function (yet). But as soon as Axiom has enough context it will make an assumption about the signature. In the next command Axiom first makes the reasonable assumption that the digit 5 represents a positive integer and then guesses the signature of the function f to be f: PositiveInteger -> Integer (3) -> f(5) Compiling function f with type PositiveInteger -> Integer (3) 25 Type: PositiveInteger Then Axiom retracts the result to positive integer again. But starting with -5, Axiom makes the assumption that by -5 you mean an integer, and so defines a new subtly function with signature f: Integer -> Integer (4) -> f(-5) Compiling function f with type Integer -> Integer (4) - 25 Type: Integer Now, suppose we try to call f with 'x'. 'x' is just a variable. Axiom needs to define yet another function based on the prototype that you provided. This time it guesses the following signature: f: Variable x -> Polynomial Integer (5) -> f(x) Compiling function f with type Variable x -> Polynomial Integer 2 (5) x Type: Polynomial Integer So why do we get the result 'x^2' and not '-x^2' ? The answer is that Axiom provides more that one meaning for <. In the case of polynomials, Axiom treats < as the lexical ordering. So we get the following result: (6) -> x>0 (6) true Type: Boolean (7) -> x<0 (7) false Type: Boolean Therefore Axiom takes the 2nd branch of the body of the definition of the function f. This is probably not at all what you expected, but this is implicitly exactly what you asked Axiom to do by omitting the signature of the function. (8) -> eval(f(x),x=-5) (8) 25 Type: Polynomial Integer Does not return -25 because you asked it to first evaluate f(x), which yields 'x^2' and then replace 'x' by -5 in that expression. Does this make sense to you? You said you expected the 'f(x)' would represent some kind of expression defined in a piecewise manner, but Axiom does not currently have any expressions of this kind. Regards, Bill Page. _______________________________________________ Axiom-mail mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/axiom-mail
