axiom-developer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Axiom-developer] Unit package question


From: Martin Rubey
Subject: Re: [Axiom-developer] Unit package question
Date: Tue, 23 Aug 2005 15:26:56 +0200

Dear all,

(I'm sending this also to Bertfried, since he was interested at some point)

C Y writes:

 > > (Well, that is Aldor syntax, but I hope in can be understood.)
 > 
 > Well, about as well as I understand Axiom's syntax... :-/.  I might as well
 > ask this up front, and I'm sorry in advance if I missed something obvious
 > and/or am proving myself as intelligent as your average rock:

Never ever say something like this. It is *good* to ask questions, and it is
also good to ask stupid questions. Moreover, it is impossible to tell
beforehand whether a question is stupid or not. In my opinion, there are no
stupid questions. (The reason for my saying that stupid questions are good
questions is that very likely 10 other people in the audience will secretely
hope that somebody else will be asking their "stupid" questions. But noone
dares.)

Elsewhere you wrote:

 > I'm quite aware these [questions] are an indicator I haven't read and
 > understood something I need to, so if someone can point me to the correct
 > "Axiom for Dummies" file I'll be only too glad to fade away until I
 > understand it properly.

PLEASE DON'T FADE AWAY. WE NEED YOU!

-------------------------------------------------------------------------------

 > Is there a tutorial or some such that takes a Category->Domains set of code
 > and dissects it essentially character by character, answering all the dumb
 > questions?

There is the Aldor user guide: http://www.aldor.org/docs/HTML/index.html which
is very thorough but maybe a little steep, so I think the following approach is
better for a beginning: 

 > Here are some of the ones floating around in my head which I don't know
 > quite how to answer at the moment. 

 > Taking this example:
 > 
 > Units(R: Field): Exports == Implementation where
 >   U == Fraction Polynomial Integer
 > 
 > 1) The syntax (R: Field) - what does this actually denote?  R I guess is all
 > Rings?

No. R is a identifier, a variable in the computer language sense. So the syntax
is

Name0(Name1: Type1, Name2: Type2, ...): NameA == NameB where

and Type1, Type2, ... are Types like 

* Field, Ring, ... which are categories, in this case Name1 will be taken by
  axiom to denote a domain of category Type1. Example:

------------------------------------------------
Units(R: Field): Exports == Implementation where
------------------------------------------------

R will be some Field from now on. I.e., you can multiply, add and take inverses
of the elements in R. 


* Integer, Polynomial Integer, PrimeField 5, ... which are domains, in which
  case Name1 will be taken by axiom to denote an element of Type1. Example:

-----------------------------------------------------
SquareMatrix(ndim,R): Exports == Implementation where
  ndim : NonNegativeInteger
  R    : Ring
-----------------------------------------------------

ndim will be a NonNegativeInteger and R a Ring. A valid call would be

0$SquareMatrix(5, Polynomial Integer)

which will give a 0 matrix of dimension 5 with entries (all zero) which are
Polynomials with Integer coefficients. Note that you are allowed to put the
type declaration also after the keyword "where".

Another example

------------------------------------------------
PrimeField(p:PositiveInteger): Exp == Impl where
------------------------------------------------

Here p will be a PositiveInteger. A valid call would be

characteristic()$PrimeField(5)

an invalid call would be

characteristic()$PrimeField(x)

unless x *is* an integer at the time of evaluation. 

 > 2) Exports == Implementation - what is actually being exported here, and
 > where is it being exported to?

"Exports" and "Implementation" are just two identifiers. If you read the
sources, you will sometimes also find

     Cat == Capsule

or 

     Cat == Definition

It seems that writing 

     Category ==

is reserved for categories.

So the complete syntax is (incomplete, but useful)

Name0(Name1: Type1, Name2: Type2, ...): NameA == NameB where

  NameA == with

    op1Declaration

    op2Declaration

    op3Declaration

  NameB == add

    op1Definition

    op2Definition

    op3Definition

The keyword 

* "==" means: here comes a macro definition 

* ":" means: here comes a type declaration

* ":=" means: here comes an assignment. 

So we could also write

Name0(Name1: Type1, Name2: Type2, ...): with

    op1Declaration

    op2Declaration

    op3Declaration

  == add

    op1Definition

    op2Definition

    op3Definition

except the indentation is then less clear.

The keyword "with" means: here come declarations the user will see. Note that
the with part may be missing. See below.

The keyword "add" means: here come definitions, declarations and assignments
the user will not see.

 > 4)  What is the significance of "%" within a domain definition?

It means: I am an element of this domain.

 > 5)  ...
 > 
 > If "Domains" are to be part of a "Category", what responsibilities do the
 > Domains have to a) label themselves as being part of a category 

This comes just before the "with" part. (If it is present...). An example is

PrimeField(p:PositiveInteger): Exp == Impl where
  Exp ==> Join(FiniteFieldCategory,FiniteAlgebraicExtensionField($),_
    ConvertibleTo(Integer))
  Impl ==>  InnerPrimeField(p) add
    if not prime?(p)$IntegerPrimesPackage(Integer) then
      error "Argument to prime field must be a prime"

Thus: PrimeField will be an element of the categories

FiniteFieldCategory, FiniteAlgebraicExtensionField($), and
ConvertibleTo(Integer)

(all quite reasonable, isn't it? "$" is the same as "%", as far as I know)

It does not have any additional operations exported -- apart from the
operations it inherits from FiniteFieldCategory, FiniteAlgebraicExtensionField
and ConvertibleTo(Integer).

 > b) ... Can a Category demand certain abilities or actions be defined for a
 > Domain in order for it to be a legal part of the Category?

Yes. ALL operations defined by the category must be implemented. However, you
can define a default implementation in the category itself. For example:

SemiGroup(): Category == SetCategory with
    --operations
      "*": (%,%) -> %                  ++ x*y returns the product of x and y.
      "**": (%,PositiveInteger) -> %   ++ x**n returns the repeated product
                                       ++ of x n times, i.e. exponentiation.
      "^": (%,PositiveInteger) -> %    ++ x^n returns the repeated product
                                       ++ of x n times, i.e. exponentiation.
    add
      import RepeatedSquaring(%)
      x:% ** n:PositiveInteger == expt(x,n)
      _^(x:%, n:PositiveInteger):% == x ** n

Here you find a default declaration of taking the n-th power that is valid for
SemiGroups. It will be overridden (i.e., implemented differently) by some
domains, of course.

 > > The full blown thing would then be 
 > > a category Units, that has as domains Mass, Time, Length, ... I
 > > suppose.
 > 
 > From what little I do understand, I like this idea the best of any so far.
 > I would call the category Dimensions, since that's what Mass, Time and
 > Length denote - they are not units until a specific quantity like 1 kg, 1
 > sec and 1 meter is defined.

To define

a * b

where a is of domain Mass and b of domain Time you probably need the Product
domain. The signature will be (I forgot to say: "++", "+++" and "--" are three
different kinds of comments...

)abb category DIM Dimension
Dimension(F: Field): Category == with

  "+": (%, %) -> %
  ++ elements of units can always be added

  "*": (F, %) -> %
  ++ elements of units can always be multiplied with a scalar

)abb package PRODDIM ProductDimension
ProductDimension(A: Dimension, B: Dimension): Exports == Implementation where

  "*": (A, B) -> Product(A, B)

But I'm not yet sure how you can define

a / b

where a is of domain Mass and b of domain Time...

Martin





reply via email to

[Prev in Thread] Current Thread [Next in Thread]