home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _b74bbaa692e8f38983d10aeb171a3f77 < prev    next >
Text File  |  2000-03-23  |  29KB  |  742 lines

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>Math::MatrixBool - Matrix of Booleans</TITLE>
  5. <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
  6. <LINK REV="made" HREF="mailto:">
  7. </HEAD>
  8.  
  9. <BODY>
  10. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  11. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  12. <STRONG><P CLASS=block> Math::MatrixBool - Matrix of Booleans</P></STRONG>
  13. </TD></TR>
  14. </TABLE>
  15.  
  16. <A NAME="__index__"></A>
  17. <!-- INDEX BEGIN -->
  18.  
  19. <UL>
  20.  
  21.     <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
  22.  
  23.     <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
  24.     <LI><A HREF="#description">DESCRIPTION</A></LI>
  25.     <LI><A HREF="#overloaded operators">OVERLOADED OPERATORS</A></LI>
  26.     <LI><A HREF="#see also">SEE ALSO</A></LI>
  27.     <LI><A HREF="#version">VERSION</A></LI>
  28.     <LI><A HREF="#author">AUTHOR</A></LI>
  29.     <LI><A HREF="#copyright">COPYRIGHT</A></LI>
  30.     <LI><A HREF="#license agreement">LICENSE AGREEMENT</A></LI>
  31. </UL>
  32. <!-- INDEX END -->
  33.  
  34. <HR>
  35. <P>
  36. <H1><A NAME="name">NAME</A></H1>
  37. <P>Math::MatrixBool - Matrix of Booleans</P>
  38. <P>Easy manipulation of matrices of booleans (Boolean Algebra)</P>
  39. <P>
  40. <HR>
  41. <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
  42. <UL>
  43. <LI>Linux</LI>
  44. <LI>Solaris</LI>
  45. <LI>Windows</LI>
  46. </UL>
  47. <HR>
  48. <H1><A NAME="synopsis">SYNOPSIS</A></H1>
  49. <UL>
  50. <LI>
  51. <CODE>use Math::MatrixBool;</CODE>
  52. <P></P>
  53. <LI>
  54. <CODE>$new_matrix = new Math::MatrixBool($rows,$columns);</CODE>
  55. <P>the matrix object constructor method</P>
  56. <P>An exception is raised if the necessary memory cannot be allocated.</P>
  57. <P></P>
  58. <LI>
  59. <CODE>$new_matrix = Math::MatrixBool->new($rows,$columns);</CODE>
  60. <P>alternate way of calling the matrix object constructor method</P>
  61. <P></P>
  62. <LI>
  63. <CODE>$new_matrix = $some_matrix-></CODE><CODE>new($rows,$columns);</CODE>
  64. <P>still another way of calling the matrix object constructor method
  65. ($some_matrix is not affected by this)</P>
  66. <P></P>
  67. <LI>
  68. <CODE>$new_matrix = Math::MatrixBool-></CODE><CODE>new_from_string($string);</CODE>
  69. <P>This method allows you to read in a matrix from a string (for
  70. instance, from the keyboard, from a file or from your code).</P>
  71. <P>The syntax is simple: each row must start with ``<CODE>[ </CODE>'' and end with
  72. ``<CODE> ]\n</CODE>'' (``<CODE>\n</CODE>'' being the newline character and ``<CODE> </CODE>'' a space or
  73. tab) and contain one or more numbers, all separated from each other
  74. by spaces or tabs.</P>
  75. <P>Additional spaces or tabs can be added at will, but no comments.</P>
  76. <P>Numbers are either ``0'' or ``1''.</P>
  77. <P>Examples:</P>
  78. <PRE>
  79.     $string = "[ 1 0 0 ]\n[ 1 1 0 ]\n[ 1 1 1 ]\n";
  80.     $matrix = Math::MatrixBool->new_from_string($string);
  81.     print "$matrix";</PRE>
  82. <P>By the way, this prints</P>
  83. <PRE>
  84.     [ 1 0 0 ]
  85.     [ 1 1 0 ]
  86.     [ 1 1 1 ]</PRE>
  87. <P>But you can also do this in a much more comfortable way using the
  88. shell-like ``here-document'' syntax:</P>
  89. <PRE>
  90.     $matrix = Math::MatrixBool->new_from_string(<<'MATRIX');
  91.     [  1  0  0  0  0  0  1  ]
  92.     [  0  1  0  0  0  0  0  ]
  93.     [  0  0  1  0  0  0  0  ]
  94.     [  0  0  0  1  0  0  0  ]
  95.     [  0  0  0  0  1  0  0  ]
  96.     [  0  0  0  0  0  1  0  ]
  97.     [  1  0  0  0  0  0  1  ]
  98.     MATRIX</PRE>
  99. <P>You can even use variables in the matrix:</P>
  100. <PRE>
  101.     $c1  =  $A1 * $x1 - $b1 >= 0  ?"1":"0";
  102.     $c1  =  $A2 * $x2 - $b2 >= 0  ?"1":"0";
  103.     $c1  =  $A3 * $x3 - $b3 >= 0  ?"1":"0";</PRE>
  104. <PRE>
  105.     $matrix = Math::MatrixBool->new_from_string(<<"MATRIX");</PRE>
  106. <PRE>
  107.         [   1    0    0   ]
  108.         [   0    1    0   ]
  109.         [  $c1  $c2  $c3  ]</PRE>
  110. <PRE>
  111.     MATRIX</PRE>
  112. <P>(Remember that you may use spaces and tabs to format the matrix to
  113. your taste)</P>
  114. <P>Note that this method uses exactly the same representation for a
  115. matrix as the ``stringify'' operator ``'': this means that you can convert
  116. any matrix into a string with <CODE>$string = "$matrix";</CODE> and read it back
  117. in later (for instance from a file!).</P>
  118. <P>If the string you supply (or someone else supplies) does not obey
  119. the syntax mentioned above, an exception is raised, which can be
  120. caught by ``eval'' as follows:</P>
  121. <PRE>
  122.     print "Please enter your matrix (in one line): ";
  123.     $string = <STDIN>;
  124.     $string =~ s/\\n/\n/g;
  125.     eval { $matrix = Math::MatrixBool->new_from_string($string); };
  126.     if ($@)
  127.     {
  128.         print "$@";
  129.         # ...
  130.         # (error handling)
  131.     }
  132.     else
  133.     {
  134.         # continue...
  135.     }</PRE>
  136. <P>or as follows:</P>
  137. <PRE>
  138.     eval { $matrix = Math::MatrixBool->new_from_string(<<"MATRIX"); };
  139.     [   1    0    0   ]
  140.     [   0    1    0   ]
  141.     [  $c1  $c2  $c3  ]
  142.     MATRIX
  143.     if ($@)
  144.     # ...</PRE>
  145. <P>Actually, the method shown above for reading a matrix from the keyboard
  146. is a little awkward, since you have to enter a lot of ``\n'''s for the
  147. newlines.</P>
  148. <P>A better way is shown in this piece of code:</P>
  149. <PRE>
  150.   while (1)
  151.   {
  152.       print "\nPlease enter your matrix ";
  153.       print "(multiple lines, <ctrl-D> = done):\n";
  154.       eval { $new_matrix =
  155.           Math::MatrixBool->new_from_string(join('',<STDIN>)); };
  156.       if ($@)
  157.       {
  158.           $@ =~ s/\s+at\b.*?$//;
  159.           print "${@}Please try again.\n";
  160.       }
  161.       else { last; }
  162.   }</PRE>
  163. <P>Possible error messages of the ``new_from_string()'' method are:</P>
  164. <PRE>
  165.     Math::MatrixBool::new_from_string(): syntax error in input string
  166.     Math::MatrixBool::new_from_string(): empty input string</PRE>
  167. <P>If the input string has rows with varying numbers of columns,
  168. the following warning will be printed to STDERR:</P>
  169. <PRE>
  170.     Math::MatrixBool::new_from_string(): missing elements will be set to zero!</PRE>
  171. <P>If everything is okay, the method returns an object reference to the
  172. (newly allocated) matrix containing the elements you specified.</P>
  173. <P></P>
  174. <LI>
  175. <CODE>($rows,$columns) = $matrix->Dim();</CODE>
  176. <P>returns the dimensions (= number of rows and columns) of the given matrix</P>
  177. <P></P>
  178. <LI>
  179. <CODE>$matrix->Empty();</CODE>
  180. <P>sets all elements in the matrix to ``0''</P>
  181. <P></P>
  182. <LI>
  183. <CODE>$matrix->Fill();</CODE>
  184. <P>sets all elements in the matrix to ``1''</P>
  185. <P></P>
  186. <LI>
  187. <CODE>$matrix->Flip();</CODE>
  188. <P>flips (i.e., complements) all elements in the given matrix</P>
  189. <P></P>
  190. <LI>
  191. <CODE>$matrix->Zero();</CODE>
  192. <P>sets all elements in the matrix to ``0''</P>
  193. <P></P>
  194. <LI>
  195. <CODE>$matrix->One();</CODE>
  196. <P>fills the matrix with one's in the main diagonal and zero's elsewhere</P>
  197. <P>Note that multiplying this matrix with itself yields the same matrix again
  198. (provided it is a square matrix)!</P>
  199. <P></P>
  200. <LI>
  201. <CODE>$matrix->Bit_On($row,$column);</CODE>
  202. <P>sets a given element to ``1''</P>
  203. <P></P>
  204. <LI>
  205. <CODE>$matrix->Insert($row,$column);</CODE>
  206. <P>alias for ``Bit_On()'', deprecated</P>
  207. <P></P>
  208. <LI>
  209. <CODE>$matrix->Bit_Off($row,$column);</CODE>
  210. <P>sets a given element to ``0''</P>
  211. <P></P>
  212. <LI>
  213. <CODE>$matrix->Delete($row,$column);</CODE>
  214. <P>alias for ``Bit_Off()'', deprecated</P>
  215. <P></P>
  216. <LI>
  217. <CODE>$boolean = $matrix-></CODE><CODE>bit_flip($row,$column);</CODE>
  218. <P>flips (i.e., complements) a given element and returns its new value</P>
  219. <P></P>
  220. <LI>
  221. <CODE>$boolean = $matrix-></CODE><CODE>flip($row,$column);</CODE>
  222. <P>alias for ``bit_flip()'', deprecated</P>
  223. <P></P>
  224. <LI>
  225. <CODE>$boolean = $matrix-></CODE><CODE>bit_test($row,$column);</CODE>
  226. <P>tests wether a given element is set</P>
  227. <P></P>
  228. <LI>
  229. <CODE>$boolean = $matrix-></CODE><CODE>contains($row,$column);</CODE>
  230. <P>tests wether a given element is set (alias for ``bit_test()'')</P>
  231. <P></P>
  232. <LI>
  233. <CODE>$boolean = $matrix-></CODE><CODE>in($row,$column);</CODE>
  234. <P>alias for ``bit_test()'', deprecated</P>
  235. <P></P>
  236. <LI>
  237. <CODE>$elements = $matrix->Number_of_elements();</CODE>
  238. <P>calculates the number of elements contained in the given matrix</P>
  239. <P></P>
  240. <LI>
  241. <CODE>$norm_max = $matrix->Norm_max();</CODE>
  242. <P>calculates the ``maximum''-norm of the given matrix</P>
  243. <P></P>
  244. <LI>
  245. <CODE>$norm_one = $matrix->Norm_one();</CODE>
  246. <P>calculates the ``1''-norm of the given matrix</P>
  247. <P></P>
  248. <LI>
  249. <CODE>$matrix1->Addition($matrix2,$matrix3);</CODE>
  250. <P>calculates the sum of matrix2 and matrix3 and stores the result in matrix1
  251. (in-place is also possible)</P>
  252. <P></P>
  253. <LI>
  254. <CODE>$product_matrix = $matrix1->Multiplication($matrix2);</CODE>
  255. <P>calculates the product of matrix1 and matrix2 and returns an object reference
  256. to a new matrix where the result is stored; uses ``<CODE>^</CODE>'' as boolean addition
  257. operator internally</P>
  258. <P></P>
  259. <LI>
  260. <CODE>$product_matrix = $matrix1->Product($matrix2);</CODE>
  261. <P>calculates the product of matrix1 and matrix2 and returns an object reference
  262. to a new matrix where the result is stored; uses ``<CODE>|</CODE>'' as boolean addition
  263. operator internally</P>
  264. <P></P>
  265. <LI>
  266. <CODE>$closure = $matrix->Kleene();</CODE>
  267. <P>computes the reflexive transitive closure of the given matrix and returns
  268. a new matrix containing the result. (The original matrix is not changed by
  269. this in any way!)</P>
  270. <P>Uses a variant of Kleene's algorithm. See <A HREF="../../../Math/Kleene(3).html">the Math::Kleene(3) manpage</A> for more details
  271. about this algorithm!</P>
  272. <P>This algorithm is mainly used in graph theory: Each position in the matrix
  273. corresponds to a (directed!) possible connection (``edge'') between two points
  274. (``vortices'') of a graph. Each position in the matrix contains a ``1'' if the
  275. corresponding edge is part of the graph and a ``0'' if not.</P>
  276. <P>Computing the closure of this matrix means to find out if there is a path
  277. from any vortice of the graph to any other (a path consisting of one or more
  278. edges).</P>
  279. <P>Note that there are more applications of Kleene's algorithm in other fields
  280. as well (see also Math::MatrixReal(3), DFA::Kleene(3), Math::Kleene(3)).</P>
  281. <P></P>
  282. <LI>
  283. <CODE>$matrix1->Union($matrix2,$matrix3);</CODE>
  284. <P>calculates the union of matrix2 and matrix3 and stores the result in matrix1
  285. (in-place is also possible)</P>
  286. <P></P>
  287. <LI>
  288. <CODE>$matrix1->Intersection($matrix2,$matrix3);</CODE>
  289. <P>calculates the intersection of matrix2 and matrix3 and stores the result in
  290. matrix1 (in-place is also possible)</P>
  291. <P></P>
  292. <LI>
  293. <CODE>$matrix1->Difference($matrix2,$matrix3);</CODE>
  294. <P>calculates matrix2 ``minus'' matrix3 ( = matrix2 \ matrix3 ) and stores the
  295. result in matrix1 (in-place is also possible)</P>
  296. <P>Note that this is set difference, not matrix difference! Matrix difference
  297. degenerates to (= is the same as) matrix addition in a Boolean Algebra!!</P>
  298. <P></P>
  299. <LI>
  300. <CODE>$matrix1->ExclusiveOr($matrix2,$matrix3);</CODE>
  301. <P>calculates the exclusive-or (which in the case of a Boolean Algebra happens
  302. to be the same as the addition) of matrix2 and matrix3 and stores the
  303. result in matrix1 (in-place is also possible)</P>
  304. <P></P>
  305. <LI>
  306. <CODE>$matrix1->Complement($matrix2);</CODE>
  307. <P>calculates the complement of matrix2 and stores the result in matrix1
  308. (in-place is also possible)</P>
  309. <P></P>
  310. <LI>
  311. <CODE>$matrix1->Transpose($matrix2);</CODE>
  312. <P>calculates the transpose of matrix2 and stores the result in matrix1
  313. (in-place is also possible if and only if the matrix is a square matrix!);
  314. in general, matrix1 must have reversed numbers of rows and columns
  315. in relation to matrix2</P>
  316. <P></P>
  317. <LI>
  318. <CODE>$boolean = $matrix1->equal($matrix2);</CODE>
  319. <P>tests if matrix1 is the same as matrix2</P>
  320. <P></P>
  321. <LI>
  322. <CODE>$boolean = $matrix1->subset($matrix2);</CODE>
  323. <P>tests if matrix1 is a subset of matrix2</P>
  324. <P></P>
  325. <LI>
  326. <CODE>$boolean = $matrix1->inclusion($matrix2);</CODE>
  327. <P>alias for ``subset()'', deprecated</P>
  328. <P></P>
  329. <LI>
  330. <CODE>$boolean = $matrix1->lexorder($matrix2);</CODE>
  331. <P>tests if matrix1 comes lexically before matrix2, i.e., if (matrix1 <= matrix2)
  332. holds, as though the two bit vectors used to represent the two matrices were
  333. two large numbers in binary representation</P>
  334. <P>(Note that this is an <STRONG>arbitrary</STRONG> order relationship!)</P>
  335. <P></P>
  336. <LI>
  337. <CODE>$result = $matrix1->Compare($matrix2);</CODE>
  338. <P>lexically compares matrix1 and matrix2 and returns -1, 0 or 1 if
  339. (matrix1 < matrix2), (matrix1 == matrix2) or (matrix1 > matrix2) holds,
  340. respectively</P>
  341. <P>(Again, the two bit vectors representing the two matrices are compared as
  342. though they were two large numbers in binary representation)</P>
  343. <P></P>
  344. <LI>
  345. <CODE>$matrix1->Copy($matrix2);</CODE>
  346. <P>copies the contents of matrix2 to an <STRONG>ALREADY EXISTING</STRONG> matrix1</P>
  347. <P></P>
  348. <LI>
  349. <CODE>$new_matrix = $some_matrix->Shadow();</CODE>
  350. <P>returns an object reference to a <STRONG>NEW</STRONG> but <STRONG>EMPTY</STRONG> matrix of
  351. the <STRONG>SAME SIZE</STRONG> as some_matrix</P>
  352. <P></P>
  353. <LI>
  354. <CODE>$twin_matrix = $some_matrix->Clone();</CODE>
  355. <P>returns an object reference to a <STRONG>NEW</STRONG> matrix of the <STRONG>SAME SIZE</STRONG> as
  356. some_matrix; the contents of some_matrix have <STRONG>ALREADY BEEN COPIED</STRONG>
  357. to the new matrix</P>
  358. <P></P>
  359. <LI>
  360. <STRONG>Hint: method names all in lower case indicate a boolean return value!</STRONG>
  361. <P>(Except for ``<CODE>new()</CODE>'' and ``<CODE>new_from_string()</CODE>'', of course!)</P>
  362. <P></P></UL>
  363. <P>Please refer to <A HREF="#overloaded operators">OVERLOADED OPERATORS</A> below for ways of using
  364. overloaded operators instead of explicit method calls in order to
  365. facilitate calculations with matrices!</P>
  366. <P>
  367. <HR>
  368. <H1><A NAME="description">DESCRIPTION</A></H1>
  369. <P>This class lets you dynamically create boolean matrices of arbitrary
  370. size and perform all the basic operations for matrices on them, like</P>
  371. <DL>
  372. <DT><STRONG><A NAME="item_%2D">-</A></STRONG><BR>
  373. <DD>
  374. setting or deleting elements,
  375. <P></P>
  376. <DT><STRONG>-</STRONG><BR>
  377. <DD>
  378. testing wether a certain element is set,
  379. <P></P>
  380. <DT><STRONG>-</STRONG><BR>
  381. <DD>
  382. computing the sum, difference, product, closure and complement of matrices,
  383. <P>(you can also compute the union, intersection, difference and exclusive-or
  384. of the underlying bit vector)</P>
  385. <P></P>
  386. <DT><STRONG>-</STRONG><BR>
  387. <DD>
  388. copying matrices,
  389. <P></P>
  390. <DT><STRONG>-</STRONG><BR>
  391. <DD>
  392. testing two matrices for equality or inclusion (subset relationship), and
  393. <P></P>
  394. <DT><STRONG>-</STRONG><BR>
  395. <DD>
  396. computing the number of elements and the norm of a matrix.
  397. <P></P></DL>
  398. <P>Please refer to <A HREF="#overloaded operators">OVERLOADED OPERATORS</A> below for ways of using
  399. overloaded operators instead of explicit method calls in order to
  400. facilitate calculations with matrices!</P>
  401. <P>
  402. <HR>
  403. <H1><A NAME="overloaded operators">OVERLOADED OPERATORS</A></H1>
  404. <P>Calculations with matrices can not only be performed with explicit method
  405. calls using this module, but also through ``magical'' overloaded arithmetic
  406. and relational operators.</P>
  407. <P>For instance, instead of writing</P>
  408. <PRE>
  409.     $matrix1 = Math::MatrixBool->new($rows,$columns);
  410.     $matrix2 = Math::MatrixBool->new($rows,$columns);
  411.     $matrix3 = Math::MatrixBool->new($rows,$columns);</PRE>
  412. <PRE>
  413.     [...]</PRE>
  414. <PRE>
  415.     $matrix3->Multiplication($matrix1,$matrix2);</PRE>
  416. <P>you can just say</P>
  417. <PRE>
  418.     $matrix1 = Math::MatrixBool->new($rows,$columns);
  419.     $matrix2 = Math::MatrixBool->new($rows,$columns);</PRE>
  420. <PRE>
  421.     [...]</PRE>
  422. <PRE>
  423.     $matrix3 = $matrix1 * $matrix2;</PRE>
  424. <P>That's all!</P>
  425. <P>Here is the list of all ``magical'' overloaded operators and their
  426. semantics (meaning):</P>
  427. <P>Unary operators: '-', '~', 'abs', testing, '!', '``'''</P>
  428. <P>Binary (arithmetic) operators: '+', '*', '|', '-', '&', '^'</P>
  429. <P>Binary (relational) operators: '==', '!=', '<', '<=', '>', '>='</P>
  430. <P>Binary (relational) operators: 'cmp', 'eq', 'ne', 'lt', 'le', 'gt', 'ge'</P>
  431. <P>Note that both arguments to a binary operator from the list above must
  432. be matrices; numbers or other types of data are not permitted as arguments
  433. and will produce an error message.</P>
  434. <DL>
  435. <DT><STRONG><A NAME="item_%27%2D%27">'-'</A></STRONG><BR>
  436. <DD>
  437. Unary Minus / Complement ( <CODE>$matrix2 = -$matrix1;</CODE> )
  438. <P>The unary operator '-' computes the complement of the given matrix.</P>
  439. <P></P>
  440. <DT><STRONG><A NAME="item_%27%7E%27">'~'</A></STRONG><BR>
  441. <DD>
  442. Transpose ( <CODE>$matrix2 = ~$matrix1;</CODE> )
  443. <P>The operator '~' computes the transpose of the given matrix.</P>
  444. <P></P>
  445. <DT><STRONG><A NAME="item_abs">abs</A></STRONG><BR>
  446. <DD>
  447. Absolute Value ( <A HREF="#item_abs"><CODE>$no_of_elem = abs($matrix);</CODE></A> )
  448. <P>Here, the absolute value of a matrix has been defined as the number
  449. of elements the given matrix contains. This is <STRONG>NOT</STRONG> the same as the
  450. ``norm'' of a matrix!</P>
  451. <P></P>
  452. <DT><STRONG><A NAME="item_test">test</A></STRONG><BR>
  453. <DD>
  454. Boolean Test ( <CODE>if ($matrix) { ... }</CODE> )
  455. <P>You can actually test a matrix as though it were a boolean value.</P>
  456. <P>No special operator is needed for this; Perl automatically calls the
  457. appropriate method in this package if ``$matrix'' is a blessed reference
  458. to an object of the ``Math::MatrixBool'' class or one of its derived
  459. classes.</P>
  460. <P>This operation returns ``true'' (1) if the given matrix is not empty and
  461. ``false'' ('') otherwise.</P>
  462. <P></P>
  463. <DT><STRONG><A NAME="item_%27%21%27">'!'</A></STRONG><BR>
  464. <DD>
  465. Negated Boolean Test ( <CODE>if (! $matrix) { ... }</CODE> )
  466. <P>You can also perform a negated test on a matrix as though it were a boolean
  467. value. For example:</P>
  468. <PRE>
  469.     if (! $matrix) { ... }</PRE>
  470. <PRE>
  471.     unless ($matrix) { ... }     #  internally, same as above!</PRE>
  472. <P>This operation returns ``true'' (1) if the given matrix is empty and ``false''
  473. ('') otherwise.</P>
  474. <P></P>
  475. <DT><STRONG><A NAME="item_%27%22%22%22%22%27">'``''``'''</A></STRONG><BR>
  476. <DD>
  477. ``Stringification'' ( <CODE>print "$matrix";</CODE> )
  478. <P>It is possible to get a string representation of a given matrix by just
  479. putting the matrix object reference between double quotes.</P>
  480. <P>Note that in general the string representation of a matrix will span over
  481. multiple lines (i.e., the string which is generated contains ``\n'' characters,
  482. one at the end of each row of the matrix).</P>
  483. <P>Example:</P>
  484. <PRE>
  485.     $matrix = new Math::MatrixBool(5,6);
  486.     $matrix->One();
  487.     print "$matrix";</PRE>
  488. <P>This will print:</P>
  489. <PRE>
  490.     [ 1 0 0 0 0 0 ]
  491.     [ 0 1 0 0 0 0 ]
  492.     [ 0 0 1 0 0 0 ]
  493.     [ 0 0 0 1 0 0 ]
  494.     [ 0 0 0 0 1 0 ]</PRE>
  495. <P></P>
  496. <DT><STRONG><A NAME="item_%27%2B%27">'+'</A></STRONG><BR>
  497. <DD>
  498. Addition ( <CODE>$matrix3 = $matrix1 + $matrix2;</CODE> )
  499. <P>The '+' operator calculates the sum of two matrices.</P>
  500. <P>Examples:</P>
  501. <PRE>
  502.     $all   =  $odd + $even;</PRE>
  503. <PRE>
  504.     $all  +=  $odd;
  505.     $all  +=  $even;</PRE>
  506. <P>Note that the '++' operator will produce an error message if applied
  507. to an object of this class because adding a number to a matrix makes
  508. no sense.</P>
  509. <P></P>
  510. <DT><STRONG><A NAME="item_%27%2A%27">'*'</A></STRONG><BR>
  511. <DD>
  512. Multiplication ( <CODE>$matrix3 = $matrix1 * $matrix2;</CODE> )
  513. <P>The '*' operator calculates the matrix product of two matrices.</P>
  514. <P>Examples:</P>
  515. <PRE>
  516.     $test   =  $one * $one;</PRE>
  517. <PRE>
  518.     $test  *=  $one;
  519.     $test  *=  $test;</PRE>
  520. <P>Note that you can use matrices of any size as long as their numbers of
  521. rows and columns correspond in the following way (example):</P>
  522. <PRE>
  523.         $matrix_3 = $matrix_1 * $matrix_2;</PRE>
  524. <PRE>
  525.                           [ 2 2 ]
  526.                           [ 2 2 ]
  527.                           [ 2 2 ]</PRE>
  528. <PRE>
  529.               [ 1 1 1 ]   [ 3 3 ]
  530.               [ 1 1 1 ]   [ 3 3 ]
  531.               [ 1 1 1 ]   [ 3 3 ]
  532.               [ 1 1 1 ]   [ 3 3 ]</PRE>
  533. <P>I.e., the number of columns of matrix #1 is the same as the number of
  534. rows of matrix #2, and the number of rows and columns of the resulting
  535. matrix #3 is determined by the number of rows of matrix #1 and the
  536. number of columns of matrix #2, respectively.</P>
  537. <P>This way you can also perform the multiplication of a matrix with a
  538. vector, since a vector is just a degenerated matrix with several rows
  539. but only one column, or just one row and several columns.</P>
  540. <P></P>
  541. <DT><STRONG><A NAME="item_%27%7C%27">'|'</A></STRONG><BR>
  542. <DD>
  543. Union ( <CODE>$matrix3 = $matrix1 | $matrix2;</CODE> )
  544. <P>The '|' operator is used to calculate the union of two matrices
  545. (of corresponding elements).</P>
  546. <P>Examples:</P>
  547. <PRE>
  548.     $all   =  $odd | $even;</PRE>
  549. <PRE>
  550.     $all  |=  $odd;
  551.     $all  |=  $even;</PRE>
  552. <P></P>
  553. <DT><STRONG>'-'</STRONG><BR>
  554. <DD>
  555. Difference ( <CODE>$matrix3 = $matrix1 - $matrix2;</CODE> )
  556. <P>The operator '-' calculates the (dotted) difference of two matrices, i.e.,</P>
  557. <PRE>
  558.     0 - 0 == 0
  559.     0 - 1 == 0
  560.     1 - 0 == 1
  561.     1 - 1 == 0</PRE>
  562. <P>for each corresponding element.</P>
  563. <P>Examples:</P>
  564. <PRE>
  565.     $odd   =  $all  - $even;</PRE>
  566. <PRE>
  567.     $all  -=  $even;</PRE>
  568. <P>Note that the '--' operator will produce an error message if applied
  569. to an object of this class because subtracting a number from a matrix
  570. makes no sense.</P>
  571. <P></P>
  572. <DT><STRONG><A NAME="item_%27%26%27">'&'</A></STRONG><BR>
  573. <DD>
  574. Intersection ( <CODE>$matrix3 = $matrix1 & $matrix2;</CODE> )
  575. <P>The '&' operator is used to calculate the intersection of two matrices
  576. (of the corresponding elements).</P>
  577. <P>Examples:</P>
  578. <PRE>
  579.     $rest  =  $all & $even;</PRE>
  580. <PRE>
  581.     $all  &=  $even;</PRE>
  582. <P></P>
  583. <DT><STRONG><A NAME="item_%27%5E%27">'^'</A></STRONG><BR>
  584. <DD>
  585. ExclusiveOr ( <CODE>$matrix3 = $matrix1 ^ $matrix2;</CODE> )
  586. <P>The '^' operator is used to calculate the exclusive-or of two matrices
  587. (of their corresponding elements).</P>
  588. <P>In fact this operation is identical with the addition of two matrices
  589. in this case of a Boolean Algebra.</P>
  590. <P>Examples:</P>
  591. <PRE>
  592.     $odd   =  $all  ^ $even;</PRE>
  593. <PRE>
  594.     $all  ^=  $even;</PRE>
  595. <P></P>
  596. <DT><STRONG><A NAME="item_%27%3D%3D%27">'=='</A></STRONG><BR>
  597. <DD>
  598. Test For Equality ( <CODE>if ($matrix1 == $matrix2) { ... }</CODE> )
  599. <P>This operator tests two matrices for equality.</P>
  600. <P>Note that <STRONG>without</STRONG> operator overloading, <CODE>( $matrix1 == $matrix2 )</CODE> would
  601. test wether the two references <STRONG>pointed to</STRONG> the <STRONG>same object</STRONG>! (!)</P>
  602. <P><STRONG>With</STRONG> operator overloading in effect, <CODE>( $matrix1 == $matrix2 )</CODE> tests
  603. wether the two matrix objects <STRONG>contain</STRONG> exactly the <STRONG>same elements</STRONG>!</P>
  604. <P></P>
  605. <DT><STRONG><A NAME="item_%27%21%3D%27">'!='</A></STRONG><BR>
  606. <DD>
  607. Test For Non-Equality ( <CODE>if ($matrix1 != $matrix2) { ... }</CODE> )
  608. <P>This operator tests wether two matrices are different.</P>
  609. <P>Note again that this tests wether the <STRONG>contents</STRONG> of the two matrices are
  610. not the same, and <STRONG>not</STRONG> wether the two <STRONG>references</STRONG> are different!</P>
  611. <P></P>
  612. <DT><STRONG><A NAME="item_%27%3C%27">'<'</A></STRONG><BR>
  613. <DD>
  614. Test For True Subset ( <CODE>if ($matrix1 < $matrix2) { ... }</CODE> )
  615. <P>This operator tests wether $matrix1 is a true subset of $matrix2, i.e.
  616. wether the elements contained in $matrix1 are also contained in $matrix2,
  617. but not all elements contained in $matrix2 are contained in $matrix1.</P>
  618. <P>Example:</P>
  619. <PRE>
  620.         [ 1 0 0 0 0 ]                       [ 1 0 0 0 1 ]
  621.         [ 0 1 0 0 0 ]                       [ 0 1 0 0 0 ]
  622.         [ 0 0 1 0 0 ]  is a true subset of  [ 0 0 1 0 0 ]
  623.         [ 0 0 0 1 0 ]                       [ 0 0 0 1 0 ]
  624.         [ 1 0 0 0 1 ]                       [ 1 0 0 0 1 ]</PRE>
  625. <PRE>
  626.         [ 1 0 0 0 0 ]                       [ 1 0 0 0 1 ]
  627.         [ 0 1 0 0 0 ]                       [ 0 1 0 0 0 ]
  628.    but  [ 0 0 1 0 0 ]   is not a subset of  [ 0 0 1 0 0 ]
  629.         [ 0 0 0 1 0 ]                       [ 0 0 0 1 0 ]
  630.         [ 1 0 0 0 1 ]                       [ 0 0 0 0 1 ]</PRE>
  631. <P>(nor vice-versa!)</P>
  632. <PRE>
  633.         [ 1 0 0 0 1 ]                       [ 1 0 0 0 1 ]
  634.         [ 0 1 0 0 0 ]                       [ 0 1 0 0 0 ]
  635.    and  [ 0 0 1 0 0 ]     is a subset of    [ 0 0 1 0 0 ]
  636.         [ 0 0 0 1 0 ]                       [ 0 0 0 1 0 ]
  637.         [ 1 0 0 0 1 ]                       [ 1 0 0 0 1 ]</PRE>
  638. <P>but not a true subset because the two matrices are identical.</P>
  639. <P></P>
  640. <DT><STRONG><A NAME="item_%27%3C%3D%27">'<='</A></STRONG><BR>
  641. <DD>
  642. Test For Subset ( <CODE>if ($matrix1 <= $matrix2) { ... }</CODE> )
  643. <P>This operator tests wether $matrix1 is a subset of $matrix2, i.e.
  644. wether all elements contained in $matrix1 are also contained in $matrix2.</P>
  645. <P>This also evaluates to ``true'' when the two matrices are the same.</P>
  646. <P></P>
  647. <DT><STRONG><A NAME="item_%27%3E%27">'>'</A></STRONG><BR>
  648. <DD>
  649. Test For True Superset ( <CODE>if ($matrix1 > $matrix2) { ... }</CODE> )
  650. <P>This operator tests wether $matrix1 is a true superset of $matrix2, i.e.
  651. wether all elements contained in $matrix2 are also contained in $matrix1,
  652. but not all elements contained in $matrix1 are contained in $matrix2.</P>
  653. <P>Note that <CODE>($matrix1 > $matrix2)</CODE> is exactly the same as
  654. <CODE>($matrix2 < $matrix1)</CODE>.</P>
  655. <P></P>
  656. <DT><STRONG><A NAME="item_%27%3E%3D%27">'>='</A></STRONG><BR>
  657. <DD>
  658. Test For Superset ( <CODE>if ($matrix1 >= $matrix2) { ... }</CODE> )
  659. <P>This operator tests wether $matrix1 is a superset of $matrix2, i.e.
  660. wether all elements contained in $matrix2 are also contained in $matrix1.</P>
  661. <P>This also evaluates to ``true'' when the two matrices are equal.</P>
  662. <P>Note that <CODE>($matrix1 >= $matrix2)</CODE> is exactly the same as
  663. <CODE>($matrix2 <= $matrix1)</CODE>.</P>
  664. <P></P>
  665. <DT><STRONG><A NAME="item_cmp">cmp</A></STRONG><BR>
  666. <DD>
  667. Compare ( <CODE>$result = $matrix1 cmp $matrix2;</CODE> )
  668. <P>This operator compares the two matrices lexically, i.e. it regards the
  669. two bit vectors representing the two matrices as two large (unsigned)
  670. numbers in binary representation and returns ``-1'' if the number for
  671. $matrix1 is smaller than that for $matrix2, ``0'' if the two numbers are
  672. the same (i.e., when the two matrices are equal!) or ``1'' if the number
  673. representing $matrix1 is larger than the number representing $matrix2.</P>
  674. <P>Note that this comparison has nothing to do whatsoever with algebra,
  675. it is just an <STRONG>arbitrary</STRONG> order relationship!</P>
  676. <P>It is only intended to provide an (arbitrary) order by which (for example)
  677. an array of matrices can be sorted, for instance to find out quickly (using
  678. binary search) if a specific matrix has already been produced before in some
  679. matrix-producing process or not.</P>
  680. <P></P>
  681. <DT><STRONG><A NAME="item_eq">eq</A></STRONG><BR>
  682. <DD>
  683. ``equal''
  684. <P></P>
  685. <DT><STRONG><A NAME="item_ne">ne</A></STRONG><BR>
  686. <DD>
  687. ``not equal''
  688. <P></P>
  689. <DT><STRONG><A NAME="item_lt">lt</A></STRONG><BR>
  690. <DD>
  691. ``less than''
  692. <P></P>
  693. <DT><STRONG><A NAME="item_le">le</A></STRONG><BR>
  694. <DD>
  695. ``less than or equal''
  696. <P></P>
  697. <DT><STRONG><A NAME="item_gt">gt</A></STRONG><BR>
  698. <DD>
  699. ``greater than''
  700. <P></P>
  701. <DT><STRONG><A NAME="item_ge">ge</A></STRONG><BR>
  702. <DD>
  703. ``greater than or equal''
  704. <P>These are all operators derived from the ``cmp'' operator (see above).</P>
  705. <P>They can be used instead of the ``cmp'' operator to make the intended
  706. type of comparison more obvious in your code.</P>
  707. <P>For instance, <CODE>($matrix1 le $matrix2)</CODE> is much more readable and clearer
  708. than <CODE>(($matrix1 cmp $matrix2) <= 0)</CODE>!</P>
  709. <P></P></DL>
  710. <P>
  711. <HR>
  712. <H1><A NAME="see also">SEE ALSO</A></H1>
  713. <P>Bit::Vector(3), Math::MatrixReal(3), DFA::Kleene(3),
  714. Math::Kleene(3), Set::IntegerFast(3), Set::IntegerRange(3).</P>
  715. <P>
  716. <HR>
  717. <H1><A NAME="version">VERSION</A></H1>
  718. <P>This man page documents ``Math::MatrixBool'' version 5.7.</P>
  719. <P>
  720. <HR>
  721. <H1><A NAME="author">AUTHOR</A></H1>
  722. <P>Steffen Beyer <<A HREF="mailto:sb@sdm.de">sb@sdm.de</A>>.</P>
  723. <P>
  724. <HR>
  725. <H1><A NAME="copyright">COPYRIGHT</A></H1>
  726. <P>Copyright (c) 1995, 1996, 1997, 1998, 1999 by Steffen Beyer.
  727. All rights reserved.</P>
  728. <P>
  729. <HR>
  730. <H1><A NAME="license agreement">LICENSE AGREEMENT</A></H1>
  731. <P>This package is free software; you can redistribute it and/or
  732. modify it under the same terms as Perl itself.</P>
  733. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  734. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  735. <STRONG><P CLASS=block> Math::MatrixBool - Matrix of Booleans</P></STRONG>
  736. </TD></TR>
  737. </TABLE>
  738.  
  739. </BODY>
  740.  
  741. </HTML>
  742.