Discussion:
[Axiom-math] BasicOperator's %eval property
Igor Khavkine
2007-05-29 00:35:46 UTC
Permalink
Greetings Axiom gurus! Here's some more weirdness that I'd like to
understand better. I snipped all the "Loading ..." messages. Any
hints?

Thanks.

Igor


(3) -> feval1(x:INT):INT == x^2
Function declaration feval1 : Integer -> Integer has been added to
workspace.
Type: Void
(4) -> feval1(10)
Compiling function feval1 with type Integer -> Integer

(4) 100
Type: PositiveInteger
(5) -> feval2(x:EXPR INT):EXPR INT == x^2
Function declaration feval2 : Expression Integer -> Expression
Integer has been added to workspace.
Type: Void
(6) -> feval2(10)

(6) 100
Type: Expression Integer
(7) -> f := operator 'f
(7) ->
(7) f
Type: BasicOperator
(8) -> evaluate(f,feval2) -- from BOP1, assigns the %eval property
(8) ->
(8) f
Type: BasicOperator
(9) -> f(10)
(9) ->
(9) 100
Type: Expression Integer
(10) -> evaluate(f,feval1)
(10) ->
(10) f
Type: BasicOperator
(11) -> f(10)
11) ->
((0 . 10) 0 . 1) is not of type NUMBER.
Martin Rubey
2007-05-29 13:06:20 UTC
Permalink
Post by Igor Khavkine
Greetings Axiom gurus! Here's some more weirdness that I'd like to
understand better. I snipped all the "Loading ..." messages. Any
hints?
Yes. It's not a weirdness, it's a bug.
Post by Igor Khavkine
(3) -> feval1(x:INT):INT == x^2
(10) -> evaluate(f,feval1)
(10) ->
(10) f
Type: BasicOperator
(11) -> f(10)
11) ->
((0 . 10) 0 . 1) is not of type NUMBER.
If you say )se me bo on, you'll see that axiom applies elt(f, 10) from
Expression Integer: it coerces 10 to EXPR INT and succeeds.

The function elt is in fact implemented in ExpressionSpace:

elt(op:OP, args:List %) ==
not belong? op => error "Unknown operator"
((u := arity op) case N) and (#args ^= u::N)
=> error "Wrong number of arguments"
(v := evaluate(op,args)$BasicOperatorFunctions1(%)) case % => v::%
okkernel(op, args)

Here comes, what I believe is a bug: belong? is defined in EXPR to give true
always. It really should check whether the %eval property is from EXPR to
EXPR, if it is set. Well, there are other possibilities, too, for example, we
could leave the operator unevaluated if the %eval property does not match. In
any case, currently evaluate(op,args)$BasicOperatorFunctions1(%) blows op.

Could you add it to IssueTracker, please?

Many thanks,

Martin

Loading...