login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Submitted by : (unknown) at: 2007-11-17T21:53:04-08:00 (17 years ago)
Name :
Axiom Version :
Category : Severity : Status :
Optional subject :  
Optional comment :

This following shows that functions in Axiom have types and a domain for functions may be associated with an identifier.

fricas
(1) -> dom:=(INT->INT)

\label{eq1}\left(\hbox{\axiomType{Integer}\ } \to \hbox{\axiomType{Integer}\ } \right)(1)
Type: Type
fricas
f:dom
Type: Void
fricas
f x == x-1
Type: Void

However, when the function is compiled, the returned type displayed may not agree with its declared type or even its apparent compiled type and depends on the input!

fricas
f 3
fricas
Compiling function f with type Integer -> Integer

\label{eq2}2(2)
Type: PositiveInteger?
fricas
f(-3)

\label{eq3}- 4(3)
Type: Integer

This has nothing to do with the declaration of f.

fricas
f(x:INT):INT==x-1
Function declaration f : Integer -> Integer has been added to workspace. Compiled code for f has been cleared. 1 old definition(s) deleted for function or rule f
Type: Void
fricas
f(3)
fricas
Compiling function f with type Integer -> Integer

\label{eq4}2(4)
Type: PositiveInteger?
fricas
f(-3)

\label{eq5}- 4(5)
Type: Integer

Not even:

fricas
f(x:INT):INT==(x-1)::INT
Function declaration f : Integer -> Integer has been added to workspace. Compiled code for f has been cleared. 1 old definition(s) deleted for function or rule f
Type: Void
fricas
f(3)
fricas
Compiling function f with type Integer -> Integer

\label{eq6}2(6)
Type: PositiveInteger?
fricas
f(-3)

\label{eq7}- 4(7)
Type: Integer

Or even:

fricas
g(x:INT):NNI == 2^(sign(x)*x)::NNI
Function declaration g : Integer -> NonNegativeInteger has been added to workspace.
Type: Void
fricas
g 3
fricas
Compiling function g with type Integer -> NonNegativeInteger
fricas
Compiling function G0 with type Integer -> Boolean

\label{eq8}8(8)
Type: PositiveInteger?

The following deliberate "error" shows the Interpreter always assumes 3 is of type PositiveInteger.

fricas
f 3

\label{eq9}2(9)
Type: PositiveInteger?
fricas
f -3
There are 9 exposed and 6 unexposed library operations named - having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op - to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation.
Cannot find a definition or applicable library operation named - with argument type(s) FunctionCalled(f) PositiveInteger
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

Compare the type returned below for g 1, the retraction to PositiveInteger is not done.

fricas
g(x:INT): FRAC INT == 1/x
Function declaration g : Integer -> Fraction(Integer) has been added to workspace. Compiled code for g has been cleared. 1 old definition(s) deleted for function or rule g
Type: Void
fricas
g 1
fricas
Compiling function g with type Integer -> Fraction(Integer)

\label{eq10}1(10)
Type: Fraction(Integer)

The difference may perhaps be due to the fact that the data structure of FRAC INT is very different from INT, whereas the data structure of INT is identical to that of PI. So the explanation that the reason 1/1 is not retracted because retract is not always possible is not the full story.

Status: open => rejected

The report is confused. There is a distinction between function's declared type (which does not change), and the type inferred by the interpreter for the value computed by a function. These are two separate processes.




  Subject:   Be Bold !!
  ( 15 subscribers )  
Please rate this page: