home *** CD-ROM | disk | FTP | other *** search
-
- <HTML>
- <HEAD>
- <TITLE>Math::MatrixBool - Matrix of Booleans</TITLE>
- <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
- <LINK REV="made" HREF="mailto:">
- </HEAD>
-
- <BODY>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> Math::MatrixBool - Matrix of Booleans</P></STRONG>
- </TD></TR>
- </TABLE>
-
- <A NAME="__index__"></A>
- <!-- INDEX BEGIN -->
-
- <UL>
-
- <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
-
- <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
- <LI><A HREF="#description">DESCRIPTION</A></LI>
- <LI><A HREF="#overloaded operators">OVERLOADED OPERATORS</A></LI>
- <LI><A HREF="#see also">SEE ALSO</A></LI>
- <LI><A HREF="#version">VERSION</A></LI>
- <LI><A HREF="#author">AUTHOR</A></LI>
- <LI><A HREF="#copyright">COPYRIGHT</A></LI>
- <LI><A HREF="#license agreement">LICENSE AGREEMENT</A></LI>
- </UL>
- <!-- INDEX END -->
-
- <HR>
- <P>
- <H1><A NAME="name">NAME</A></H1>
- <P>Math::MatrixBool - Matrix of Booleans</P>
- <P>Easy manipulation of matrices of booleans (Boolean Algebra)</P>
- <P>
- <HR>
- <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
- <UL>
- <LI>Linux</LI>
- <LI>Solaris</LI>
- <LI>Windows</LI>
- </UL>
- <HR>
- <H1><A NAME="synopsis">SYNOPSIS</A></H1>
- <UL>
- <LI>
- <CODE>use Math::MatrixBool;</CODE>
- <P></P>
- <LI>
- <CODE>$new_matrix = new Math::MatrixBool($rows,$columns);</CODE>
- <P>the matrix object constructor method</P>
- <P>An exception is raised if the necessary memory cannot be allocated.</P>
- <P></P>
- <LI>
- <CODE>$new_matrix = Math::MatrixBool->new($rows,$columns);</CODE>
- <P>alternate way of calling the matrix object constructor method</P>
- <P></P>
- <LI>
- <CODE>$new_matrix = $some_matrix-></CODE><CODE>new($rows,$columns);</CODE>
- <P>still another way of calling the matrix object constructor method
- ($some_matrix is not affected by this)</P>
- <P></P>
- <LI>
- <CODE>$new_matrix = Math::MatrixBool-></CODE><CODE>new_from_string($string);</CODE>
- <P>This method allows you to read in a matrix from a string (for
- instance, from the keyboard, from a file or from your code).</P>
- <P>The syntax is simple: each row must start with ``<CODE>[ </CODE>'' and end with
- ``<CODE> ]\n</CODE>'' (``<CODE>\n</CODE>'' being the newline character and ``<CODE> </CODE>'' a space or
- tab) and contain one or more numbers, all separated from each other
- by spaces or tabs.</P>
- <P>Additional spaces or tabs can be added at will, but no comments.</P>
- <P>Numbers are either ``0'' or ``1''.</P>
- <P>Examples:</P>
- <PRE>
- $string = "[ 1 0 0 ]\n[ 1 1 0 ]\n[ 1 1 1 ]\n";
- $matrix = Math::MatrixBool->new_from_string($string);
- print "$matrix";</PRE>
- <P>By the way, this prints</P>
- <PRE>
- [ 1 0 0 ]
- [ 1 1 0 ]
- [ 1 1 1 ]</PRE>
- <P>But you can also do this in a much more comfortable way using the
- shell-like ``here-document'' syntax:</P>
- <PRE>
- $matrix = Math::MatrixBool->new_from_string(<<'MATRIX');
- [ 1 0 0 0 0 0 1 ]
- [ 0 1 0 0 0 0 0 ]
- [ 0 0 1 0 0 0 0 ]
- [ 0 0 0 1 0 0 0 ]
- [ 0 0 0 0 1 0 0 ]
- [ 0 0 0 0 0 1 0 ]
- [ 1 0 0 0 0 0 1 ]
- MATRIX</PRE>
- <P>You can even use variables in the matrix:</P>
- <PRE>
- $c1 = $A1 * $x1 - $b1 >= 0 ?"1":"0";
- $c1 = $A2 * $x2 - $b2 >= 0 ?"1":"0";
- $c1 = $A3 * $x3 - $b3 >= 0 ?"1":"0";</PRE>
- <PRE>
- $matrix = Math::MatrixBool->new_from_string(<<"MATRIX");</PRE>
- <PRE>
- [ 1 0 0 ]
- [ 0 1 0 ]
- [ $c1 $c2 $c3 ]</PRE>
- <PRE>
- MATRIX</PRE>
- <P>(Remember that you may use spaces and tabs to format the matrix to
- your taste)</P>
- <P>Note that this method uses exactly the same representation for a
- matrix as the ``stringify'' operator ``'': this means that you can convert
- any matrix into a string with <CODE>$string = "$matrix";</CODE> and read it back
- in later (for instance from a file!).</P>
- <P>If the string you supply (or someone else supplies) does not obey
- the syntax mentioned above, an exception is raised, which can be
- caught by ``eval'' as follows:</P>
- <PRE>
- print "Please enter your matrix (in one line): ";
- $string = <STDIN>;
- $string =~ s/\\n/\n/g;
- eval { $matrix = Math::MatrixBool->new_from_string($string); };
- if ($@)
- {
- print "$@";
- # ...
- # (error handling)
- }
- else
- {
- # continue...
- }</PRE>
- <P>or as follows:</P>
- <PRE>
- eval { $matrix = Math::MatrixBool->new_from_string(<<"MATRIX"); };
- [ 1 0 0 ]
- [ 0 1 0 ]
- [ $c1 $c2 $c3 ]
- MATRIX
- if ($@)
- # ...</PRE>
- <P>Actually, the method shown above for reading a matrix from the keyboard
- is a little awkward, since you have to enter a lot of ``\n'''s for the
- newlines.</P>
- <P>A better way is shown in this piece of code:</P>
- <PRE>
- while (1)
- {
- print "\nPlease enter your matrix ";
- print "(multiple lines, <ctrl-D> = done):\n";
- eval { $new_matrix =
- Math::MatrixBool->new_from_string(join('',<STDIN>)); };
- if ($@)
- {
- $@ =~ s/\s+at\b.*?$//;
- print "${@}Please try again.\n";
- }
- else { last; }
- }</PRE>
- <P>Possible error messages of the ``new_from_string()'' method are:</P>
- <PRE>
- Math::MatrixBool::new_from_string(): syntax error in input string
- Math::MatrixBool::new_from_string(): empty input string</PRE>
- <P>If the input string has rows with varying numbers of columns,
- the following warning will be printed to STDERR:</P>
- <PRE>
- Math::MatrixBool::new_from_string(): missing elements will be set to zero!</PRE>
- <P>If everything is okay, the method returns an object reference to the
- (newly allocated) matrix containing the elements you specified.</P>
- <P></P>
- <LI>
- <CODE>($rows,$columns) = $matrix->Dim();</CODE>
- <P>returns the dimensions (= number of rows and columns) of the given matrix</P>
- <P></P>
- <LI>
- <CODE>$matrix->Empty();</CODE>
- <P>sets all elements in the matrix to ``0''</P>
- <P></P>
- <LI>
- <CODE>$matrix->Fill();</CODE>
- <P>sets all elements in the matrix to ``1''</P>
- <P></P>
- <LI>
- <CODE>$matrix->Flip();</CODE>
- <P>flips (i.e., complements) all elements in the given matrix</P>
- <P></P>
- <LI>
- <CODE>$matrix->Zero();</CODE>
- <P>sets all elements in the matrix to ``0''</P>
- <P></P>
- <LI>
- <CODE>$matrix->One();</CODE>
- <P>fills the matrix with one's in the main diagonal and zero's elsewhere</P>
- <P>Note that multiplying this matrix with itself yields the same matrix again
- (provided it is a square matrix)!</P>
- <P></P>
- <LI>
- <CODE>$matrix->Bit_On($row,$column);</CODE>
- <P>sets a given element to ``1''</P>
- <P></P>
- <LI>
- <CODE>$matrix->Insert($row,$column);</CODE>
- <P>alias for ``Bit_On()'', deprecated</P>
- <P></P>
- <LI>
- <CODE>$matrix->Bit_Off($row,$column);</CODE>
- <P>sets a given element to ``0''</P>
- <P></P>
- <LI>
- <CODE>$matrix->Delete($row,$column);</CODE>
- <P>alias for ``Bit_Off()'', deprecated</P>
- <P></P>
- <LI>
- <CODE>$boolean = $matrix-></CODE><CODE>bit_flip($row,$column);</CODE>
- <P>flips (i.e., complements) a given element and returns its new value</P>
- <P></P>
- <LI>
- <CODE>$boolean = $matrix-></CODE><CODE>flip($row,$column);</CODE>
- <P>alias for ``bit_flip()'', deprecated</P>
- <P></P>
- <LI>
- <CODE>$boolean = $matrix-></CODE><CODE>bit_test($row,$column);</CODE>
- <P>tests wether a given element is set</P>
- <P></P>
- <LI>
- <CODE>$boolean = $matrix-></CODE><CODE>contains($row,$column);</CODE>
- <P>tests wether a given element is set (alias for ``bit_test()'')</P>
- <P></P>
- <LI>
- <CODE>$boolean = $matrix-></CODE><CODE>in($row,$column);</CODE>
- <P>alias for ``bit_test()'', deprecated</P>
- <P></P>
- <LI>
- <CODE>$elements = $matrix->Number_of_elements();</CODE>
- <P>calculates the number of elements contained in the given matrix</P>
- <P></P>
- <LI>
- <CODE>$norm_max = $matrix->Norm_max();</CODE>
- <P>calculates the ``maximum''-norm of the given matrix</P>
- <P></P>
- <LI>
- <CODE>$norm_one = $matrix->Norm_one();</CODE>
- <P>calculates the ``1''-norm of the given matrix</P>
- <P></P>
- <LI>
- <CODE>$matrix1->Addition($matrix2,$matrix3);</CODE>
- <P>calculates the sum of matrix2 and matrix3 and stores the result in matrix1
- (in-place is also possible)</P>
- <P></P>
- <LI>
- <CODE>$product_matrix = $matrix1->Multiplication($matrix2);</CODE>
- <P>calculates the product of matrix1 and matrix2 and returns an object reference
- to a new matrix where the result is stored; uses ``<CODE>^</CODE>'' as boolean addition
- operator internally</P>
- <P></P>
- <LI>
- <CODE>$product_matrix = $matrix1->Product($matrix2);</CODE>
- <P>calculates the product of matrix1 and matrix2 and returns an object reference
- to a new matrix where the result is stored; uses ``<CODE>|</CODE>'' as boolean addition
- operator internally</P>
- <P></P>
- <LI>
- <CODE>$closure = $matrix->Kleene();</CODE>
- <P>computes the reflexive transitive closure of the given matrix and returns
- a new matrix containing the result. (The original matrix is not changed by
- this in any way!)</P>
- <P>Uses a variant of Kleene's algorithm. See <A HREF="../../../Math/Kleene(3).html">the Math::Kleene(3) manpage</A> for more details
- about this algorithm!</P>
- <P>This algorithm is mainly used in graph theory: Each position in the matrix
- corresponds to a (directed!) possible connection (``edge'') between two points
- (``vortices'') of a graph. Each position in the matrix contains a ``1'' if the
- corresponding edge is part of the graph and a ``0'' if not.</P>
- <P>Computing the closure of this matrix means to find out if there is a path
- from any vortice of the graph to any other (a path consisting of one or more
- edges).</P>
- <P>Note that there are more applications of Kleene's algorithm in other fields
- as well (see also Math::MatrixReal(3), DFA::Kleene(3), Math::Kleene(3)).</P>
- <P></P>
- <LI>
- <CODE>$matrix1->Union($matrix2,$matrix3);</CODE>
- <P>calculates the union of matrix2 and matrix3 and stores the result in matrix1
- (in-place is also possible)</P>
- <P></P>
- <LI>
- <CODE>$matrix1->Intersection($matrix2,$matrix3);</CODE>
- <P>calculates the intersection of matrix2 and matrix3 and stores the result in
- matrix1 (in-place is also possible)</P>
- <P></P>
- <LI>
- <CODE>$matrix1->Difference($matrix2,$matrix3);</CODE>
- <P>calculates matrix2 ``minus'' matrix3 ( = matrix2 \ matrix3 ) and stores the
- result in matrix1 (in-place is also possible)</P>
- <P>Note that this is set difference, not matrix difference! Matrix difference
- degenerates to (= is the same as) matrix addition in a Boolean Algebra!!</P>
- <P></P>
- <LI>
- <CODE>$matrix1->ExclusiveOr($matrix2,$matrix3);</CODE>
- <P>calculates the exclusive-or (which in the case of a Boolean Algebra happens
- to be the same as the addition) of matrix2 and matrix3 and stores the
- result in matrix1 (in-place is also possible)</P>
- <P></P>
- <LI>
- <CODE>$matrix1->Complement($matrix2);</CODE>
- <P>calculates the complement of matrix2 and stores the result in matrix1
- (in-place is also possible)</P>
- <P></P>
- <LI>
- <CODE>$matrix1->Transpose($matrix2);</CODE>
- <P>calculates the transpose of matrix2 and stores the result in matrix1
- (in-place is also possible if and only if the matrix is a square matrix!);
- in general, matrix1 must have reversed numbers of rows and columns
- in relation to matrix2</P>
- <P></P>
- <LI>
- <CODE>$boolean = $matrix1->equal($matrix2);</CODE>
- <P>tests if matrix1 is the same as matrix2</P>
- <P></P>
- <LI>
- <CODE>$boolean = $matrix1->subset($matrix2);</CODE>
- <P>tests if matrix1 is a subset of matrix2</P>
- <P></P>
- <LI>
- <CODE>$boolean = $matrix1->inclusion($matrix2);</CODE>
- <P>alias for ``subset()'', deprecated</P>
- <P></P>
- <LI>
- <CODE>$boolean = $matrix1->lexorder($matrix2);</CODE>
- <P>tests if matrix1 comes lexically before matrix2, i.e., if (matrix1 <= matrix2)
- holds, as though the two bit vectors used to represent the two matrices were
- two large numbers in binary representation</P>
- <P>(Note that this is an <STRONG>arbitrary</STRONG> order relationship!)</P>
- <P></P>
- <LI>
- <CODE>$result = $matrix1->Compare($matrix2);</CODE>
- <P>lexically compares matrix1 and matrix2 and returns -1, 0 or 1 if
- (matrix1 < matrix2), (matrix1 == matrix2) or (matrix1 > matrix2) holds,
- respectively</P>
- <P>(Again, the two bit vectors representing the two matrices are compared as
- though they were two large numbers in binary representation)</P>
- <P></P>
- <LI>
- <CODE>$matrix1->Copy($matrix2);</CODE>
- <P>copies the contents of matrix2 to an <STRONG>ALREADY EXISTING</STRONG> matrix1</P>
- <P></P>
- <LI>
- <CODE>$new_matrix = $some_matrix->Shadow();</CODE>
- <P>returns an object reference to a <STRONG>NEW</STRONG> but <STRONG>EMPTY</STRONG> matrix of
- the <STRONG>SAME SIZE</STRONG> as some_matrix</P>
- <P></P>
- <LI>
- <CODE>$twin_matrix = $some_matrix->Clone();</CODE>
- <P>returns an object reference to a <STRONG>NEW</STRONG> matrix of the <STRONG>SAME SIZE</STRONG> as
- some_matrix; the contents of some_matrix have <STRONG>ALREADY BEEN COPIED</STRONG>
- to the new matrix</P>
- <P></P>
- <LI>
- <STRONG>Hint: method names all in lower case indicate a boolean return value!</STRONG>
- <P>(Except for ``<CODE>new()</CODE>'' and ``<CODE>new_from_string()</CODE>'', of course!)</P>
- <P></P></UL>
- <P>Please refer to <A HREF="#overloaded operators">OVERLOADED OPERATORS</A> below for ways of using
- overloaded operators instead of explicit method calls in order to
- facilitate calculations with matrices!</P>
- <P>
- <HR>
- <H1><A NAME="description">DESCRIPTION</A></H1>
- <P>This class lets you dynamically create boolean matrices of arbitrary
- size and perform all the basic operations for matrices on them, like</P>
- <DL>
- <DT><STRONG><A NAME="item_%2D">-</A></STRONG><BR>
- <DD>
- setting or deleting elements,
- <P></P>
- <DT><STRONG>-</STRONG><BR>
- <DD>
- testing wether a certain element is set,
- <P></P>
- <DT><STRONG>-</STRONG><BR>
- <DD>
- computing the sum, difference, product, closure and complement of matrices,
- <P>(you can also compute the union, intersection, difference and exclusive-or
- of the underlying bit vector)</P>
- <P></P>
- <DT><STRONG>-</STRONG><BR>
- <DD>
- copying matrices,
- <P></P>
- <DT><STRONG>-</STRONG><BR>
- <DD>
- testing two matrices for equality or inclusion (subset relationship), and
- <P></P>
- <DT><STRONG>-</STRONG><BR>
- <DD>
- computing the number of elements and the norm of a matrix.
- <P></P></DL>
- <P>Please refer to <A HREF="#overloaded operators">OVERLOADED OPERATORS</A> below for ways of using
- overloaded operators instead of explicit method calls in order to
- facilitate calculations with matrices!</P>
- <P>
- <HR>
- <H1><A NAME="overloaded operators">OVERLOADED OPERATORS</A></H1>
- <P>Calculations with matrices can not only be performed with explicit method
- calls using this module, but also through ``magical'' overloaded arithmetic
- and relational operators.</P>
- <P>For instance, instead of writing</P>
- <PRE>
- $matrix1 = Math::MatrixBool->new($rows,$columns);
- $matrix2 = Math::MatrixBool->new($rows,$columns);
- $matrix3 = Math::MatrixBool->new($rows,$columns);</PRE>
- <PRE>
- [...]</PRE>
- <PRE>
- $matrix3->Multiplication($matrix1,$matrix2);</PRE>
- <P>you can just say</P>
- <PRE>
- $matrix1 = Math::MatrixBool->new($rows,$columns);
- $matrix2 = Math::MatrixBool->new($rows,$columns);</PRE>
- <PRE>
- [...]</PRE>
- <PRE>
- $matrix3 = $matrix1 * $matrix2;</PRE>
- <P>That's all!</P>
- <P>Here is the list of all ``magical'' overloaded operators and their
- semantics (meaning):</P>
- <P>Unary operators: '-', '~', 'abs', testing, '!', '``'''</P>
- <P>Binary (arithmetic) operators: '+', '*', '|', '-', '&', '^'</P>
- <P>Binary (relational) operators: '==', '!=', '<', '<=', '>', '>='</P>
- <P>Binary (relational) operators: 'cmp', 'eq', 'ne', 'lt', 'le', 'gt', 'ge'</P>
- <P>Note that both arguments to a binary operator from the list above must
- be matrices; numbers or other types of data are not permitted as arguments
- and will produce an error message.</P>
- <DL>
- <DT><STRONG><A NAME="item_%27%2D%27">'-'</A></STRONG><BR>
- <DD>
- Unary Minus / Complement ( <CODE>$matrix2 = -$matrix1;</CODE> )
- <P>The unary operator '-' computes the complement of the given matrix.</P>
- <P></P>
- <DT><STRONG><A NAME="item_%27%7E%27">'~'</A></STRONG><BR>
- <DD>
- Transpose ( <CODE>$matrix2 = ~$matrix1;</CODE> )
- <P>The operator '~' computes the transpose of the given matrix.</P>
- <P></P>
- <DT><STRONG><A NAME="item_abs">abs</A></STRONG><BR>
- <DD>
- Absolute Value ( <A HREF="#item_abs"><CODE>$no_of_elem = abs($matrix);</CODE></A> )
- <P>Here, the absolute value of a matrix has been defined as the number
- of elements the given matrix contains. This is <STRONG>NOT</STRONG> the same as the
- ``norm'' of a matrix!</P>
- <P></P>
- <DT><STRONG><A NAME="item_test">test</A></STRONG><BR>
- <DD>
- Boolean Test ( <CODE>if ($matrix) { ... }</CODE> )
- <P>You can actually test a matrix as though it were a boolean value.</P>
- <P>No special operator is needed for this; Perl automatically calls the
- appropriate method in this package if ``$matrix'' is a blessed reference
- to an object of the ``Math::MatrixBool'' class or one of its derived
- classes.</P>
- <P>This operation returns ``true'' (1) if the given matrix is not empty and
- ``false'' ('') otherwise.</P>
- <P></P>
- <DT><STRONG><A NAME="item_%27%21%27">'!'</A></STRONG><BR>
- <DD>
- Negated Boolean Test ( <CODE>if (! $matrix) { ... }</CODE> )
- <P>You can also perform a negated test on a matrix as though it were a boolean
- value. For example:</P>
- <PRE>
- if (! $matrix) { ... }</PRE>
- <PRE>
- unless ($matrix) { ... } # internally, same as above!</PRE>
- <P>This operation returns ``true'' (1) if the given matrix is empty and ``false''
- ('') otherwise.</P>
- <P></P>
- <DT><STRONG><A NAME="item_%27%22%22%22%22%27">'``''``'''</A></STRONG><BR>
- <DD>
- ``Stringification'' ( <CODE>print "$matrix";</CODE> )
- <P>It is possible to get a string representation of a given matrix by just
- putting the matrix object reference between double quotes.</P>
- <P>Note that in general the string representation of a matrix will span over
- multiple lines (i.e., the string which is generated contains ``\n'' characters,
- one at the end of each row of the matrix).</P>
- <P>Example:</P>
- <PRE>
- $matrix = new Math::MatrixBool(5,6);
- $matrix->One();
- print "$matrix";</PRE>
- <P>This will print:</P>
- <PRE>
- [ 1 0 0 0 0 0 ]
- [ 0 1 0 0 0 0 ]
- [ 0 0 1 0 0 0 ]
- [ 0 0 0 1 0 0 ]
- [ 0 0 0 0 1 0 ]</PRE>
- <P></P>
- <DT><STRONG><A NAME="item_%27%2B%27">'+'</A></STRONG><BR>
- <DD>
- Addition ( <CODE>$matrix3 = $matrix1 + $matrix2;</CODE> )
- <P>The '+' operator calculates the sum of two matrices.</P>
- <P>Examples:</P>
- <PRE>
- $all = $odd + $even;</PRE>
- <PRE>
- $all += $odd;
- $all += $even;</PRE>
- <P>Note that the '++' operator will produce an error message if applied
- to an object of this class because adding a number to a matrix makes
- no sense.</P>
- <P></P>
- <DT><STRONG><A NAME="item_%27%2A%27">'*'</A></STRONG><BR>
- <DD>
- Multiplication ( <CODE>$matrix3 = $matrix1 * $matrix2;</CODE> )
- <P>The '*' operator calculates the matrix product of two matrices.</P>
- <P>Examples:</P>
- <PRE>
- $test = $one * $one;</PRE>
- <PRE>
- $test *= $one;
- $test *= $test;</PRE>
- <P>Note that you can use matrices of any size as long as their numbers of
- rows and columns correspond in the following way (example):</P>
- <PRE>
- $matrix_3 = $matrix_1 * $matrix_2;</PRE>
- <PRE>
- [ 2 2 ]
- [ 2 2 ]
- [ 2 2 ]</PRE>
- <PRE>
- [ 1 1 1 ] [ 3 3 ]
- [ 1 1 1 ] [ 3 3 ]
- [ 1 1 1 ] [ 3 3 ]
- [ 1 1 1 ] [ 3 3 ]</PRE>
- <P>I.e., the number of columns of matrix #1 is the same as the number of
- rows of matrix #2, and the number of rows and columns of the resulting
- matrix #3 is determined by the number of rows of matrix #1 and the
- number of columns of matrix #2, respectively.</P>
- <P>This way you can also perform the multiplication of a matrix with a
- vector, since a vector is just a degenerated matrix with several rows
- but only one column, or just one row and several columns.</P>
- <P></P>
- <DT><STRONG><A NAME="item_%27%7C%27">'|'</A></STRONG><BR>
- <DD>
- Union ( <CODE>$matrix3 = $matrix1 | $matrix2;</CODE> )
- <P>The '|' operator is used to calculate the union of two matrices
- (of corresponding elements).</P>
- <P>Examples:</P>
- <PRE>
- $all = $odd | $even;</PRE>
- <PRE>
- $all |= $odd;
- $all |= $even;</PRE>
- <P></P>
- <DT><STRONG>'-'</STRONG><BR>
- <DD>
- Difference ( <CODE>$matrix3 = $matrix1 - $matrix2;</CODE> )
- <P>The operator '-' calculates the (dotted) difference of two matrices, i.e.,</P>
- <PRE>
- 0 - 0 == 0
- 0 - 1 == 0
- 1 - 0 == 1
- 1 - 1 == 0</PRE>
- <P>for each corresponding element.</P>
- <P>Examples:</P>
- <PRE>
- $odd = $all - $even;</PRE>
- <PRE>
- $all -= $even;</PRE>
- <P>Note that the '--' operator will produce an error message if applied
- to an object of this class because subtracting a number from a matrix
- makes no sense.</P>
- <P></P>
- <DT><STRONG><A NAME="item_%27%26%27">'&'</A></STRONG><BR>
- <DD>
- Intersection ( <CODE>$matrix3 = $matrix1 & $matrix2;</CODE> )
- <P>The '&' operator is used to calculate the intersection of two matrices
- (of the corresponding elements).</P>
- <P>Examples:</P>
- <PRE>
- $rest = $all & $even;</PRE>
- <PRE>
- $all &= $even;</PRE>
- <P></P>
- <DT><STRONG><A NAME="item_%27%5E%27">'^'</A></STRONG><BR>
- <DD>
- ExclusiveOr ( <CODE>$matrix3 = $matrix1 ^ $matrix2;</CODE> )
- <P>The '^' operator is used to calculate the exclusive-or of two matrices
- (of their corresponding elements).</P>
- <P>In fact this operation is identical with the addition of two matrices
- in this case of a Boolean Algebra.</P>
- <P>Examples:</P>
- <PRE>
- $odd = $all ^ $even;</PRE>
- <PRE>
- $all ^= $even;</PRE>
- <P></P>
- <DT><STRONG><A NAME="item_%27%3D%3D%27">'=='</A></STRONG><BR>
- <DD>
- Test For Equality ( <CODE>if ($matrix1 == $matrix2) { ... }</CODE> )
- <P>This operator tests two matrices for equality.</P>
- <P>Note that <STRONG>without</STRONG> operator overloading, <CODE>( $matrix1 == $matrix2 )</CODE> would
- test wether the two references <STRONG>pointed to</STRONG> the <STRONG>same object</STRONG>! (!)</P>
- <P><STRONG>With</STRONG> operator overloading in effect, <CODE>( $matrix1 == $matrix2 )</CODE> tests
- wether the two matrix objects <STRONG>contain</STRONG> exactly the <STRONG>same elements</STRONG>!</P>
- <P></P>
- <DT><STRONG><A NAME="item_%27%21%3D%27">'!='</A></STRONG><BR>
- <DD>
- Test For Non-Equality ( <CODE>if ($matrix1 != $matrix2) { ... }</CODE> )
- <P>This operator tests wether two matrices are different.</P>
- <P>Note again that this tests wether the <STRONG>contents</STRONG> of the two matrices are
- not the same, and <STRONG>not</STRONG> wether the two <STRONG>references</STRONG> are different!</P>
- <P></P>
- <DT><STRONG><A NAME="item_%27%3C%27">'<'</A></STRONG><BR>
- <DD>
- Test For True Subset ( <CODE>if ($matrix1 < $matrix2) { ... }</CODE> )
- <P>This operator tests wether $matrix1 is a true subset of $matrix2, i.e.
- wether the elements contained in $matrix1 are also contained in $matrix2,
- but not all elements contained in $matrix2 are contained in $matrix1.</P>
- <P>Example:</P>
- <PRE>
- [ 1 0 0 0 0 ] [ 1 0 0 0 1 ]
- [ 0 1 0 0 0 ] [ 0 1 0 0 0 ]
- [ 0 0 1 0 0 ] is a true subset of [ 0 0 1 0 0 ]
- [ 0 0 0 1 0 ] [ 0 0 0 1 0 ]
- [ 1 0 0 0 1 ] [ 1 0 0 0 1 ]</PRE>
- <PRE>
- [ 1 0 0 0 0 ] [ 1 0 0 0 1 ]
- [ 0 1 0 0 0 ] [ 0 1 0 0 0 ]
- but [ 0 0 1 0 0 ] is not a subset of [ 0 0 1 0 0 ]
- [ 0 0 0 1 0 ] [ 0 0 0 1 0 ]
- [ 1 0 0 0 1 ] [ 0 0 0 0 1 ]</PRE>
- <P>(nor vice-versa!)</P>
- <PRE>
- [ 1 0 0 0 1 ] [ 1 0 0 0 1 ]
- [ 0 1 0 0 0 ] [ 0 1 0 0 0 ]
- and [ 0 0 1 0 0 ] is a subset of [ 0 0 1 0 0 ]
- [ 0 0 0 1 0 ] [ 0 0 0 1 0 ]
- [ 1 0 0 0 1 ] [ 1 0 0 0 1 ]</PRE>
- <P>but not a true subset because the two matrices are identical.</P>
- <P></P>
- <DT><STRONG><A NAME="item_%27%3C%3D%27">'<='</A></STRONG><BR>
- <DD>
- Test For Subset ( <CODE>if ($matrix1 <= $matrix2) { ... }</CODE> )
- <P>This operator tests wether $matrix1 is a subset of $matrix2, i.e.
- wether all elements contained in $matrix1 are also contained in $matrix2.</P>
- <P>This also evaluates to ``true'' when the two matrices are the same.</P>
- <P></P>
- <DT><STRONG><A NAME="item_%27%3E%27">'>'</A></STRONG><BR>
- <DD>
- Test For True Superset ( <CODE>if ($matrix1 > $matrix2) { ... }</CODE> )
- <P>This operator tests wether $matrix1 is a true superset of $matrix2, i.e.
- wether all elements contained in $matrix2 are also contained in $matrix1,
- but not all elements contained in $matrix1 are contained in $matrix2.</P>
- <P>Note that <CODE>($matrix1 > $matrix2)</CODE> is exactly the same as
- <CODE>($matrix2 < $matrix1)</CODE>.</P>
- <P></P>
- <DT><STRONG><A NAME="item_%27%3E%3D%27">'>='</A></STRONG><BR>
- <DD>
- Test For Superset ( <CODE>if ($matrix1 >= $matrix2) { ... }</CODE> )
- <P>This operator tests wether $matrix1 is a superset of $matrix2, i.e.
- wether all elements contained in $matrix2 are also contained in $matrix1.</P>
- <P>This also evaluates to ``true'' when the two matrices are equal.</P>
- <P>Note that <CODE>($matrix1 >= $matrix2)</CODE> is exactly the same as
- <CODE>($matrix2 <= $matrix1)</CODE>.</P>
- <P></P>
- <DT><STRONG><A NAME="item_cmp">cmp</A></STRONG><BR>
- <DD>
- Compare ( <CODE>$result = $matrix1 cmp $matrix2;</CODE> )
- <P>This operator compares the two matrices lexically, i.e. it regards the
- two bit vectors representing the two matrices as two large (unsigned)
- numbers in binary representation and returns ``-1'' if the number for
- $matrix1 is smaller than that for $matrix2, ``0'' if the two numbers are
- the same (i.e., when the two matrices are equal!) or ``1'' if the number
- representing $matrix1 is larger than the number representing $matrix2.</P>
- <P>Note that this comparison has nothing to do whatsoever with algebra,
- it is just an <STRONG>arbitrary</STRONG> order relationship!</P>
- <P>It is only intended to provide an (arbitrary) order by which (for example)
- an array of matrices can be sorted, for instance to find out quickly (using
- binary search) if a specific matrix has already been produced before in some
- matrix-producing process or not.</P>
- <P></P>
- <DT><STRONG><A NAME="item_eq">eq</A></STRONG><BR>
- <DD>
- ``equal''
- <P></P>
- <DT><STRONG><A NAME="item_ne">ne</A></STRONG><BR>
- <DD>
- ``not equal''
- <P></P>
- <DT><STRONG><A NAME="item_lt">lt</A></STRONG><BR>
- <DD>
- ``less than''
- <P></P>
- <DT><STRONG><A NAME="item_le">le</A></STRONG><BR>
- <DD>
- ``less than or equal''
- <P></P>
- <DT><STRONG><A NAME="item_gt">gt</A></STRONG><BR>
- <DD>
- ``greater than''
- <P></P>
- <DT><STRONG><A NAME="item_ge">ge</A></STRONG><BR>
- <DD>
- ``greater than or equal''
- <P>These are all operators derived from the ``cmp'' operator (see above).</P>
- <P>They can be used instead of the ``cmp'' operator to make the intended
- type of comparison more obvious in your code.</P>
- <P>For instance, <CODE>($matrix1 le $matrix2)</CODE> is much more readable and clearer
- than <CODE>(($matrix1 cmp $matrix2) <= 0)</CODE>!</P>
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="see also">SEE ALSO</A></H1>
- <P>Bit::Vector(3), Math::MatrixReal(3), DFA::Kleene(3),
- Math::Kleene(3), Set::IntegerFast(3), Set::IntegerRange(3).</P>
- <P>
- <HR>
- <H1><A NAME="version">VERSION</A></H1>
- <P>This man page documents ``Math::MatrixBool'' version 5.7.</P>
- <P>
- <HR>
- <H1><A NAME="author">AUTHOR</A></H1>
- <P>Steffen Beyer <<A HREF="mailto:sb@sdm.de">sb@sdm.de</A>>.</P>
- <P>
- <HR>
- <H1><A NAME="copyright">COPYRIGHT</A></H1>
- <P>Copyright (c) 1995, 1996, 1997, 1998, 1999 by Steffen Beyer.
- All rights reserved.</P>
- <P>
- <HR>
- <H1><A NAME="license agreement">LICENSE AGREEMENT</A></H1>
- <P>This package is free software; you can redistribute it and/or
- modify it under the same terms as Perl itself.</P>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> Math::MatrixBool - Matrix of Booleans</P></STRONG>
- </TD></TR>
- </TABLE>
-
- </BODY>
-
- </HTML>
-