
% Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
%     - Redistributions of source code must retain the above copyright
%       notice, this list of conditions and the following disclaimer.
%
%     - Redistributions in binary form must reproduce the above copyright
%       notice, this list of conditions and the following disclaimer in
%       the documentation and/or other materials provided with the
%       distribution.
%
%     - Neither the name of The Numerical ALgorithms Group Ltd. nor the
%       names of its contributors may be used to endorse or promote products
%       derived from this software without specific prior written permission.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
% IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
% TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
% PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
% OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
% EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
% PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES-- LOSS OF USE, DATA, OR
% PROFITS-- OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
% LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
% NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



% card.htex
The \spadtype{CardinalNumber} domain can be used for values indicating
the cardinality of sets, both finite and infinite.
For example, the \spadfunFrom{dimension}{VectorSpace} operation in the
category \spadtype{VectorSpace} returns a cardinal number.

The non-negative integers have a natural construction as cardinals
\begin{verbatim}
0 = #{ }, 1 = {0}, 2 = {0, 1}, ..., n = {i | 0 <= i < n}.
\end{verbatim}
The fact that \spad{0} acts as a zero for the multiplication of cardinals is
equivalent to the axiom of choice.

\xtc{
Cardinal numbers can be created by conversion from non-negative integers.
}{
\spadcommand{c0 := 0 :: CardinalNumber \bound{c0}}
}
\xtc{
}{
\spadcommand{c1 := 1 :: CardinalNumber \bound{c1}}
}
\xtc{
}{
\spadcommand{c2 := 2 :: CardinalNumber \bound{c2}}
}
\xtc{
}{
\spadcommand{c3 := 3 :: CardinalNumber \bound{c3}}
}
\xtc{
They can also be obtained as the named cardinal \spad{Aleph(n)}.
}{
\spadcommand{A0 := Aleph 0 \bound{A0}}
}
\xtc{
}{
\spadcommand{A1 := Aleph 1 \bound{A1}}
}
\xtc{
The \spadfunFrom{finite?}{CardinalNumber} operation tests whether a value is a
finite cardinal, that is, a non-negative integer.
}{
\spadcommand{finite? c2 \free{c2}}
}
\xtc{
}{
\spadcommand{finite? A0 \free{A0}}
}
\xtc{
Similarly, the \spadfunFrom{countable?}{CardinalNumber}
operation determines whether a value is
a countable cardinal, that is, finite or \spad{Aleph(0)}.
}{
\spadcommand{countable? c2 \free{c2}}
}
\xtc{
}{
\spadcommand{countable? A0 \free{A0}}
}
\xtc{
}{
\spadcommand{countable? A1 \free{A1}}
}
Arithmetic operations are defined on cardinal numbers as follows:
If \spad{x = \#X}  and  \spad{y = \#Y} then

\begin{texonly}
\begin{tabular}{@{}lcll}
\tt x+y  &\tt =&\tt  \#(X+Y)  & cardinality of the disjoint union \\
\tt x-y  &\tt =&\tt  \#(X-Y)  & cardinality of the relative complement \\
\tt x*y  &\tt =&\tt  \#(X*Y)  & cardinality of the Cartesian product \\
\tt x^y &\tt =&\tt  \#(X^Y) & cardinality of the set of maps from \spad{Y} to \spad{X}
\end{tabular}
\end{texonly}
\htonly
\indent{0}
\spad{x+y  = \#(X+Y)} \tab{20} cardinality of the disjoint union \newline
\spad{x-y  = \#(X-Y)} \tab{20} cardinality of the relative complement \newline
\spad{x*y  = \#(X*Y)} \tab{20} cardinality of the Cartesian product \newline
\spad{x^y = \#(X^Y)}\tab{20} cardinality of the set of maps from \spad{Y} to \spad{X} \newline
\endhtonly

\xtc{
Here are some arithmetic examples.
}{
\spadcommand{[c2 + c2, c2 + A1] \free{c2 A1}}
}
\xtc{
}{
\spadcommand{[c0*c2, c1*c2, c2*c2, c0*A1, c1*A1, c2*A1, A0*A1] \free{c0,c1,c2,A0,A1}}
}
\xtc{
}{
\spadcommand{[c2^c0, c2^c1, c2^c2, A1^c0, A1^c1, A1^c2] \free{c0,c1,c2,A1}}
}
\xtc{
Subtraction is a partial operation: it is not defined
when subtracting a larger cardinal from a smaller one, nor
when subtracting two equal infinite cardinals.
}{
\spadcommand{[c2-c1, c2-c2, c2-c3, A1-c2, A1-A0, A1-A1] \free{c1,c2,c3,A0,A1}}
}
\index{generalized continuum hypothesis}
The generalized continuum hypothesis asserts that
\begin{verbatim}
2^Aleph i = Aleph(i+1)
\end{verbatim}
and is independent of the axioms of set theory.\footnote{Goedel,
{\it The consistency of the continuum hypothesis,}
Ann. Math. Studies, Princeton Univ. Press, 1940.}
\xtc{
The \spadtype{CardinalNumber} domain provides an operation to assert
whether the hypothesis is to be assumed.
}{
\spadcommand{generalizedContinuumHypothesisAssumed true \bound{GCH}}
}
\xtc{
When the generalized continuum hypothesis
is assumed, exponentiation to a transfinite power is allowed.
}{
\spadcommand{[c0^A0, c1^A0, c2^A0, A0^A0, A0^A1, A1^A0, A1^A1] \free{c0,c1,c2,A0,A1,GCH}}
}

Three commonly encountered cardinal numbers are

\begin{texonly}
\begin{tabular}{@{}ll}
$a = \#{\bf Z}$ & countable infinity \\
$c = \#{\bf R}$ & the continuum      \\
$f = \#\{g | g: [0,1] \rightarrow {\bf R}\}$
\end{tabular}
\end{texonly}
\htonly
\indent{0}
\spad{a = \#}{\bf Z} \tab{20}       countable infinity \newline
\spad{c = \#}{\bf R} \tab{20}      the continuum       \newline
\spad{f = \#\{g| g: [0,1] -> {\bf R}\}}                \newline
\endhtonly

\xtc{
In this domain, these values are obtained under the
generalized continuum hypothesis in this way.
}{
\spadcommand{a := Aleph 0 \free{GCH}\bound{a}}
}
\xtc{
}{
\spadcommand{c := 2^a    \free{a}  \bound{c}}
}
\xtc{
}{
\spadcommand{f := 2^c    \free{c}  \bound{f}}
}
