Discussion:
[Axiom-math] missing exports in Finite DirectProduct and Product
Bill Page
2007-10-18 03:19:27 UTC
Permalink
Axiom Developers;

If the components of the cartesian product Product or DirectProduct
are domains in the category Finite then the product domain has Finite.
Unfortunately the current Axiom library code does not define all of
the required exports of Finite. For example:

(1) -> index(1)$DirectProduct(2,IntegerMod(3))
Internal Error
The function index with signature hashcode is missing from domain
DirectProduct2(IntegerMod 3)

(1) -> index(1)$Product(OVAR [a,b],IntegerMod(3))
Internal Error
The function index with signature hashcode is missing from domain
Product(OrderedVariableList (a b))(IntegerMod 3)

(1) -> DirectProduct(2,IntegerMod(3)) has Finite

(1) true
Type: Boolean

The attached file contains a patch against FriCAS Revision: 112 that
adds the missing operations 'index', 'lookup', and 'hash'. The
operation 'size' is already available as a default.

Having 'index' available for products allows one to iterate over the
elements of a cross product like this:

X:=Product(OVAR [a,b],IntegerMod(3))
[index(i::PI)$X for i in 1..size()$X]

Note: Coercion to PositiveInteger (PI) is required because 'size'
returns an NonNegativeInteger (NNI) so i is of type NNI but index
expects an argument >= 1. Since the products export operations allow
acces to the components it is easy to write functions that map over
such lists.

Writing this made me think that it was also desirable the domains in
Finite also enumerate there members in a more functional manner so
because FriCAS now allows us to easily make fairly deep changes in the
algebra code, as an exercise I decided to define the following new
export of Finite

expand: () -> List %

expand() == [index(i::PositiveInteger) for i in 1..size()]

So with this patch one can write for example:

(1) -> map(x+->(selectsecond(x)::Symbol)^(selectfirst(x)::Integer), _
expand()$Product(ZMOD(3),OVAR [a,b]))

2 2
(1) [a,b,a ,b ,1,1]
Type: List Expression Integer

------

I would be interested in your opinions about this approach to
providing Cartesian products for the Axiom library.

I think it is interesting to see how domains in the category Finite
able to participate like "sets" in the language. Of course it is also
possible to represent countably infinite sets in Axiom via the Stream
domain. This suggests the that the category constructor StepThrough
could also usefully be provided with an export that expands to such
Stream. Perhaps the underlying Spad language should support this sort
of expansion of Finite and countably infinite domains as a standard
form of iterator in the [ ... for i in ... ] construction?

Of course Aldor already has implemented some basic abstractions of
this kind but it is not entirely obvious to me how best to extend
Axiom's library and still stay within the limitations of the current
Spad language.

Regards,
Bill Page.
Martin Rubey
2007-10-18 06:39:06 UTC
Permalink
Post by Bill Page
I would be interested in your opinions about this approach to
providing Cartesian products for the Axiom library.
I think you did something quite interesting. Unfortunately, I'm very busy
right now, but you might be interested in digging up a proposal of mine I made
a year ago or so, concerning StepThrough. It was rejected back then (for good
theoretic reasons), but I still have the feeling that the behaviour I
Post by Bill Page
I think it is interesting to see how domains in the category Finite able to
participate like "sets" in the language. Of course it is also possible to
represent countably infinite sets in Axiom via the Stream domain. This
suggests the that the category constructor StepThrough could also usefully be
provided with an export that expands to such Stream. Perhaps the underlying
Spad language should support this sort of expansion of Finite and countably
infinite domains as a standard form of iterator in the [ ... for i in ... ]
construction?
Of course Aldor already has implemented some basic abstractions of this kind
but it is not entirely obvious to me how best to extend Axiom's library and
still stay within the limitations of the current Spad language.
Really, what is missing are generators. I do not think that adding them to
SPAD in a naive manner would be too difficult, but I never tried.


Many thanks for your effort,

Martin
Francois Maltey
2007-10-18 13:30:06 UTC
Permalink
Dear Bill, and others.

About Product (i.e. cartesian product) and DirectProduct over finite domains.

You add 'index', 'lookup', and 'hash'.
The operation 'size' is already available as a default.
Having 'index' available for products allows one to iterate over the
X:=Product(OVAR [a,b],IntegerMod(3))
[index(i::PI)$X for i in 1..size()$X]
Right, axiom searchs for the congruent integer with index and lookup.

But is it possible to have an intrinsic loop than an integer loop ?

Dom := OVAR [aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,ll]
[i for i in dd..ee]
Writing this made me think that it was also desirable the domains in
Finite also enumerate there members in a more functional manner so
because FriCAS now allows us to easily make fairly deep changes in the
algebra code, as an exercise I decided to define the following new
export of Finite
expand: () -> List %
expand() == [index(i::PositiveInteger) for i in 1..size()]
A good primitive. The expand name looks as expand (100..110).

For finite domains you enumerate all the cases, not a subset of cases.
I don't find any expand functions in others finite domain.
Others systems uses expand for expanding calculus only.

So I prefer an enumerate function to an expand function,
and add an enumerate in all the finite structure
***@OVAR[aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,ll] responds
[aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,ll]

So I see 2 functions :

enumerate without arguments for all the cases.
and expand with a interval for subset.
Is it possible to get this after an expand (5..7, aa..cc) ?

[[5,aa],[6,aa],[7,aa],[5,bb],[6,bb],[7,bb],[5,cc],[6,cc],[7,cc]]

I don't see how to type this expand.
(1) -> map(x+->(selectsecond(x)::Symbol)^(selectfirst(x)::Integer), _
expand()$Product(ZMOD(3),OVAR [a,b]))
2 2
(1) [a,b,a ,b ,1,1]
It's a progress to allow this map, but it isn't too serviceable.

Why not a
map (x +-> x.1::Symbol^x.2::Integer
for x in enumerate()$Product(ZMOD(3),OVAR [a,b]))
map (x +-> x.1::Symbol^x.2::Integer
for x in expand(1..2,a..b)$Product(ZMOD(3),OVAR [a,b]))

So axiom has record and cartesian products,
but the must use of makeprod(,)@... or news(,)@.... isn't friendly.

Mathematics use so often cartesian product it's penalizing to
have to declare a cartesian product with new or makeprod.
Other languages allow lists for this uses because they aren't typed.

A new constructor as [|...,...|] should be a great progress in the
interface. By example caml uses [1;2;3] for lists and [|1;2;3|] for array.
I would be interested in your opinions about this approach to
providing Cartesian products for the Axiom library.
A really good idea for finite domains.
I think it is interesting to see how domains in the category Finite
able to participate like "sets" in the language.
What are the commom functions in this cases ?

index, lookup, hash, are they present in all finite domains ?

Enumerate in a list all the elements is a good idea.
It may be interesting to expand? a sub-interval.

For cartesian product in general a short constructor will be a
serious avantage. output [|n, (X-1)^n|] will work.
Of course Aldor already has implemented some basic abstractions of
this kind but it is not entirely obvious to me how best to extend
Axiom's library and still stay within the limitations of the current
Spad language.
Will axiom interpreter include aldor or not in the future ?

F.
Ralf Hemmecke
2007-10-18 16:16:16 UTC
Permalink
Hi Francois,
Post by Francois Maltey
But is it possible to have an intrinsic loop than an integer loop ?
Dom := OVAR [aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,ll]
[i for i in dd..ee]
What a question...

Your problem is only because you are struggeling with Axiom.
In Aldor there is only *one* "for" construction and that looks like

for x in g

where g is of type Generator(Something).
Don't be misled if you see something like

for x in 1..10

in Aldor. If the object after "in" is not a Generator(?) then the
compiler throws in the function "generator". So the above is actually
the same as

for x in generator(1..10)

Voila, again a Generator(Integer). The question now is whether there is
a function

generator: Segment(Integer) -> Generator(Integer)

Of course there is. (OK, in LibAldor, it is actually IntegerSegment.)

So what you see here is that you would have to implement something of
that provides a function

..

Right. "Two dots" is a library *function* and not a built-in thing.
This now equally applies to SPAD and the Axiom library. You find the
definition of ".." in seg.spad.pamphlet.

Well, maybe that doesn't help you too much.

Ralf

Loading...