I also need to represent types in computation related domains such as λ-calculus and combinators (as explained here). It would be good to upgrade the very simplistic representation of types that exists there at the moment.

In order to use the SPAD Rewrite rules and pattern matching capabilities (as explained here) we need to make this domain a ring.

As shown in the table (right) there is a potential correspondence between type constructs and ring operations:

I suspect that, from a theoretical point of view, we want the type system to implement a Closed Cartesian Category (CCC) but due to the practical issue above it might be best to make it a ring for now.

Type

Ring

UNION(A,B)

A+B

RECORD(A,B)

A*B

NONE

0

ANY

1

A->B

BA

?

-A

On issue with the table above is that I can't see a meaning in a type which corresponds to a minus operation. However, I see no reason why we cant implement minus even though it does not correspond to any actual types.

Also, I'm not sure about exponent to represent function types. For instance: A point in3D space might be represented by Float3, however its hard to see this as 3->Float except in a very theoretical sense.

This is a sort of 'lifting', that is, values in this domain represent
types.

Type Expressions

Because this is a ring (also needs to inherit a few other categories) then Axiom/FriCAS allows us to define expressions over it. This gives the possibility of having variables that represent types and to use SPAD rewrite rules to express type identities, for instance, we might define simplification rules for types like these:

There is a problem with this, so far, it is not clear what should be a type constant and what needs to be in an expression. In the above rules, I have used a convention that lower case letters are variables which can be replaced by any types. Its not as simple as numbers where operations on the numbers just produce another number, here operations on types produce a tree structure:

Integer * Float = Record(Integer,Float)

Although the above is a tree structure, I would say that it is still a 'Type' and not a 'TypeExpression' because it does not contain any variables.

MType

MType is a domain I have written which stands for 'matchable type'. The intention is to be
able to represent types in a way that is more powerful than
the existing FriCAS types.

I want to be able to have type variables and to use
type constructors in a more flexible way.

The original reason for writing this is that I needed to
represent types in a SPAD version of the interpreter that I
am working on (see page here). In this interpreter it is used by TypeMatcher to hold type information.

We then need to pattern match this. There is a mechanism in SPAD for pattern matching, in ordinary expressions, which is used in specifying rewrite rules. Is there an way that we can use that mechanism, not for an expression on ordinary functions, but for a 'type expression'? that is an expression where all the 'values' are 'types'.

There is more information about this SPAD pattern matching mechanism on page here.

I have therefore written a domain 'MatchableType' which implements:

ConvertibleTo(Pattern(MatchableType))

PatternMatchable(MatchableType)

The code I have written to experiment with these things is on github here.

To try the code download 'Interpret.spad' from github and compile it like this:

Note: we need to compile first in 'bootStrapMode' and then again normally, this is because the code has circular references.

(7) -> R1:RewriteRule(MType,MType,Expression(MType)) := rule a+0 == a
RewriteRule(MType,MType,Expression(MType)) is not a valid type.
(7) -> R1:RewriteRule(MType,MType,MTypeExpression(MType)) := rule a+0 == a
There are 1 exposed and 0 unexposed library operations named rule
having 2 argument(s) but none was determined to be applicable.
Use HyperDoc Browse, or issue
)display op rule
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 rule
with argument type(s)
Polynomial(Integer)
Variable(a)
Perhaps you should use "@" to indicate the required return type,
or "$" to specify which version of the function you need.
(7) -> RR := RewriteRule(MType,MType,MTypeExpression(MType))
(7) RewriteRule(MType,MType,MTypeExpression(MType))
Type: Type
(8) -> R2:RewriteRule(Integer,Integer,Expression(Integer)) := rule a+1 == a
(8) a + 1 == a
Type: RewriteRule(Integer,Integer,Expression(Integer))
(9) ->

This page discusses implementing type theory as a mathematical structure using Axiom/FriCAS which is a Computer Algebra System.

Computer Algebra Systems

On this page I have put some information about computer algebra systems and in particular Axiom/FriCAS.

Other Code

This is one of a series of pages describing code that I have written for FriCAS. Some of this code has already been included with the FriCAS library and so can be used as soon as FriCAS is installed (as described here). Other code on these pages is not yet included with FriCAS and so would have to be compiled from within FriCAS. For an overview of all the code I have written, on various topics, see page here.