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

Edit detail for SandBox Direct Product revision 1 of 2

1 2
Editor:
Time: 2007/11/18 17:58:19 GMT-8
Note: Product is exactly what I was looking for!

changed:
-
The direct product of two functions over the same domain is
another function over that domain whose co-domain is the product
of the co-domains their co-domains.

Axiom makes this a little awkward because it currently does not
properly support non-homogeneous tuples (Tuple ANY) as the output
of functions (i.e. co-domains that are general products). We use
Axiom's Record type below. It is also possible to write this
using non-homogeneous Lists or DirectProducts.

\begin{axiom}
)abbrev package MAPHAC3X MapPackInternalHac3x
++ Description: Mapping hack for Addition
++ The function \spad{fDirPrd(f,g,x)} is \spad{(fx,gx)} which is needed below
MapPackInternalHac3x(A: SetCategory, B: SetCategory, C: SetCategory):
   with fDirPrd:  (A->B, A->C,A) -> Record(a:B,b:C) ==
      add
         fDirPrd(g,h,x)  == [(g x), (h x)]

\end{axiom}



\begin{axiom}
)abbrev package MAPPK3X MappingPackage3x
++ Description: Functional Direct Product
++ Given functions f:A->B and g:A->C, X returns the function ++ \spad{(fx,gx):A->BxC}
++ \spad{f &X g} is the function \spad{h} such that \spad{h x = (f x , g x)}.
MappingPackage3x(A:SetCategory, B:SetCategory, C:SetCategory):
   with X: (A->B, A->C) -> (A->Record(a:B,b:C)) ==
      add
         MapPackInternalHac3x(A, B, C)
         fab:  A -> B
         fac:  A -> C
         X(fab,fac) == fDirPrd(fab,fac,#1)

\end{axiom}

Test the product with two functions f and g.
\begin{axiom}
f := (x:INT):INT +-> 3*x
g := (x:INT):INT +-> x^3
fg:=(f &X g)
fg(3)
\end{axiom}

Since the result of the functional direct product is a function whose
co-domain is a Record, for functional composition we need to write 
a function whose domain is a Record, i.e. so that it takes as input
the data output output by another function.
\begin{axiom}
s := (x:Record(a:INT,b:INT)):INT+->(x.a+x.b)
sX := (s * (f &X g))
sX(9)
\end{axiom}


<hr>
From William Sit, July 1, 2005 7:46:00 -5:00<br>

The Cartesian Product of two domains is implemented in 'Product'. The 'DirectProduct' domain is when the component domains are all the same. You worked too hard. The "product" of two functions can be defined on the fly naturally:

\begin{axiom}
h(x:INT):Product(INT,INT)== makeprod(f x,g x)
h(3)
\end{axiom}

Or, if you really want to make a package out of this:

\begin{axiom}
)abbrev package FUNCPROD FunctionalProduct
++ Description: Allows making one function out of two components
++ The function \spad{product(f,g)} is the function whose components are f and g
FunctionalProduct(A: SetCategory, B: SetCategory, C: SetCategory): Package == Code where
   D ==> Product(B,C)
   Package ==> with 
      product:  (A->B, A->C) -> (A->D)
   Code ==> add
      product(g,h) == makeprod(g #1, h #1)$D
\end{axiom}

\begin{axiom}
k:=product(f,g)
k(3)
\end{axiom}

From BillPage Fri Jul 1 11:10:11 -0500 2005
From: Bill Page
Date: Fri, 01 Jul 2005 11:10:11 -0500
Subject: Product is exactly what I was looking for!
Message-ID: <20050701111011-0500@page.axiom-developer.org>

William Sit wrote:

> The Cartesian Product of two domains is implemented in Product.
> The DirectProduct domain is when the component domains are all
> the same. You worked too hard. The "product" of two functions
> can be defined on the fly naturally ...

I have not been able to find any documentation about this
domain in the Axiom Book. Did I just miss it?

So now I want to know how the domain Product relates to
tuples. Really from the point of view of category theory
we want a tuple to be a member of an n-ary Product.

Still the use of Product for 2-tuples is quite straightforward.
For example:
\begin{axiom}
)expose Product
g:Product(INT,Float)->Product(Float,INT)
g(x)==makeprod(selectsecond(x),selectfirst(x))
g(makeprod(1,1.1))
\end{axiom}


The direct product of two functions over the same domain is another function over that domain whose co-domain is the product of the co-domains their co-domains.

Axiom makes this a little awkward because it currently does not properly support non-homogeneous tuples (Tuple ANY) as the output of functions (i.e. co-domains that are general products). We use Axiom's Record type below. It is also possible to write this using non-homogeneous Lists or DirectProducts?.

axiom
)abbrev package MAPHAC3X MapPackInternalHac3x
++ Description: Mapping hack for Addition
++ The function \spad{fDirPrd(f,g,x)} is \spad{(fx,gx)} which is needed below
MapPackInternalHac3x(A: SetCategory, B: SetCategory, C: SetCategory):
   with fDirPrd:  (A->B, A->C,A) -> Record(a:B,b:C) ==
      add
         fDirPrd(g,h,x)  == [(g x), (h x)]
axiom
Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/5523093780900071215-25px.001.spad using 
      old system compiler.
   MAPHAC3X abbreviates package MapPackInternalHac3x 
------------------------------------------------------------------------
   initializing NRLIB MAPHAC3X for MapPackInternalHac3x 
   compiling into NRLIB MAPHAC3X 
   compiling exported fDirPrd : (A -> B,A -> C,A) -> Record(a: B,b: C)
Time: 0.06 SEC.
(time taken in buildFunctor: 0)
;;; *** |MapPackInternalHac3x| REDEFINED
;;; *** |MapPackInternalHac3x| REDEFINED Time: 0.02 SEC.
Cumulative Statistics for Constructor MapPackInternalHac3x Time: 0.08 seconds
finalizing NRLIB MAPHAC3X Processing MapPackInternalHac3x for Browser database: --->-->MapPackInternalHac3x((fDirPrd ((Record (: a B) (: b C)) (Mapping B A) (Mapping C A) A))): Not documented!!!! --------constructor--------- ; compiling file "/var/zope2/var/LatexWiki/MAPHAC3X.NRLIB/MAPHAC3X.lsp" (written 11 MAY 2011 04:33:22 AM):
; /var/zope2/var/LatexWiki/MAPHAC3X.NRLIB/MAPHAC3X.fasl written ; compilation finished in 0:00:00.123 ------------------------------------------------------------------------ MapPackInternalHac3x is now explicitly exposed in frame initial MapPackInternalHac3x will be automatically loaded when needed from /var/zope2/var/LatexWiki/MAPHAC3X.NRLIB/MAPHAC3X
>> System error: The bounding indices 163 and 162 are bad for a sequence of length 162. See also: The ANSI Standard, Glossary entry for "bounding index designator" The ANSI Standard, writeup for Issue SUBSEQ-OUT-OF-BOUNDS:IS-AN-ERROR

axiom
)abbrev package MAPPK3X MappingPackage3x
++ Description: Functional Direct Product
++ Given functions f:A->B and g:A->C, X returns the function ++ \spad{(fx,gx):A->BxC}
++ \spad<b>&X g</b> is the function \spad{h} such that \spad{h x = (f x , g x)}.
MappingPackage3x(A:SetCategory, B:SetCategory, C:SetCategory):
   with X: (A->B, A->C) -> (A->Record(a:B,b:C)) ==
      add
         MapPackInternalHac3x(A, B, C)
         fab:  A -> B
         fac:  A -> C
         X(fab,fac) == fDirPrd(fab,fac,#1)
axiom
Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/5456321546929993926-25px.002.spad using 
      old system compiler.
   MAPPK3X abbreviates package MappingPackage3x 
------------------------------------------------------------------------
   initializing NRLIB MAPPK3X for MappingPackage3x 
   compiling into NRLIB MAPPK3X 
>> Apparent user error: Use: import (MapPackInternalHac3x A B C)

Test the product with two functions f and g.

axiom
f := (x:INT):INT +-> 3*x

\label{eq1}\mbox{theMap (...)}(1)
Type: (Integer -> Integer)
axiom
g := (x:INT):INT +-> x^3

\label{eq2}\mbox{theMap (...)}(2)
Type: (Integer -> Integer)
axiom
fg:=(f &X g)
There are no library operations named X Use HyperDoc Browse or issue )what op X to learn if there is any operation containing " X " in its name.
Cannot find a definition or applicable library operation named X with argument type(s) (Integer -> Integer) (Integer -> Integer)
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need. fg(3)
There are no library operations named fg Use HyperDoc Browse or issue )what op fg to learn if there is any operation containing " fg " in its name.
Cannot find a definition or applicable library operation named fg with argument type(s) PositiveInteger
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

Since the result of the functional direct product is a function whose co-domain is a Record, for functional composition we need to write a function whose domain is a Record, i.e. so that it takes as input the data output output by another function.

axiom
s := (x:Record(a:INT,b:INT)):INT+->(x.a+x.b)

\label{eq3}\mbox{theMap (...)}(3)
Type: (Record(a: Integer,b: Integer) -> Integer)
axiom
sX := (s * (f &X g))
There are no library operations named X Use HyperDoc Browse or issue )what op X to learn if there is any operation containing " X " in its name.
Cannot find a definition or applicable library operation named X with argument type(s) (Integer -> Integer) (Integer -> Integer)
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need. sX(9)
There are no library operations named sX Use HyperDoc Browse or issue )what op sX to learn if there is any operation containing " sX " in its name.
Cannot find a definition or applicable library operation named sX with argument type(s) PositiveInteger
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.


From William Sit, July 1, 2005 7:46:00 -5:00

The Cartesian Product of two domains is implemented in Product. The DirectProduct domain is when the component domains are all the same. You worked too hard. The "product" of two functions can be defined on the fly naturally:

axiom
h(x:INT):Product(INT,INT)== makeprod(f x,g x)
Function declaration h : Integer -> Product(Integer,Integer) has been added to workspace.
Type: Void
axiom
h(3)
axiom
Compiling function h with type Integer -> Product(Integer,Integer)

\label{eq4}\left(9, \:{27}\right)(4)
Type: Product(Integer,Integer)

Or, if you really want to make a package out of this:

axiom
)abbrev package FUNCPROD FunctionalProduct
++ Description: Allows making one function out of two components
++ The function \spad{product(f,g)} is the function whose components are f and g
FunctionalProduct(A: SetCategory, B: SetCategory, C: SetCategory): Package == Code where
   D ==> Product(B,C)
   Package ==> with 
      product:  (A->B, A->C) -> (A->D)
   Code ==> add
      product(g,h) == makeprod(g #1, h #1)$D
axiom
Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/3438835739696712844-25px.006.spad using 
      old system compiler.
   FUNCPROD abbreviates package FunctionalProduct 
------------------------------------------------------------------------
   initializing NRLIB FUNCPROD for FunctionalProduct 
   compiling into NRLIB FUNCPROD 
   compiling exported product : (A -> B,A -> C) -> A -> Product(B,C)
Time: 0.02 SEC.
(time taken in buildFunctor: 0)
;;; *** |FunctionalProduct| REDEFINED
;;; *** |FunctionalProduct| REDEFINED Time: 0.01 SEC.
Cumulative Statistics for Constructor FunctionalProduct Time: 0.03 seconds
finalizing NRLIB FUNCPROD Processing FunctionalProduct for Browser database: --->-->FunctionalProduct((product ((Mapping D A) (Mapping B A) (Mapping C A)))): Not documented!!!! --------constructor--------- ; compiling file "/var/zope2/var/LatexWiki/FUNCPROD.NRLIB/FUNCPROD.lsp" (written 11 MAY 2011 04:33:24 AM):
; /var/zope2/var/LatexWiki/FUNCPROD.NRLIB/FUNCPROD.fasl written ; compilation finished in 0:00:00.090 ------------------------------------------------------------------------ FunctionalProduct is now explicitly exposed in frame initial FunctionalProduct will be automatically loaded when needed from /var/zope2/var/LatexWiki/FUNCPROD.NRLIB/FUNCPROD
>> System error: The bounding indices 163 and 162 are bad for a sequence of length 162. See also: The ANSI Standard, Glossary entry for "bounding index designator" The ANSI Standard, writeup for Issue SUBSEQ-OUT-OF-BOUNDS:IS-AN-ERROR

axiom
k:=product(f,g)

\label{eq5}\mbox{theMap (...)}(5)
Type: (Integer -> Product(Integer,Integer))
axiom
k(3)

\label{eq6}\left(9, \:{27}\right)(6)
Type: Product(Integer,Integer)

Product is exactly what I was looking for! --Bill Page, Fri, 01 Jul 2005 11:10:11 -0500 reply
William Sit wrote:
The Cartesian Product of two domains is implemented in Product. The DirectProduct? domain is when the component domains are all the same. You worked too hard. The "product" of two functions can be defined on the fly naturally ...

I have not been able to find any documentation about this domain in the Axiom Book. Did I just miss it?

So now I want to know how the domain Product relates to tuples. Really from the point of view of category theory we want a tuple to be a member of an n-ary Product.

Still the use of Product for 2-tuples is quite straightforward. For example:

axiom
)expose Product
Product is now explicitly exposed in frame initial g:Product(INT,Float)->Product(Float,INT)
Compiled code for h has been cleared.
Cannot process mapping declaration on g since it already has a value. g(x)==makeprod(selectsecond(x),selectfirst(x))
Type: Void
axiom
g(makeprod(1,1.1))
axiom
Compiling function g with type Product(PositiveInteger,Float) -> 
      Product(Float,PositiveInteger)

\label{eq7}\left({1.1}, \: 1 \right)(7)
Type: Product(Float,PositiveInteger?)