<?xml version="1.0" encoding="utf-8" ?> <!-- for emacs: -*- coding: utf-8 -*- --> <!-- Apache may like this line in the file .htaccess: AddCharset utf-8 .html --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd" > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head><title>two dimensional formatting</title> <link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/> </head> <body> <table class="buttons"> <tr> <td><div><a href="_file_spmanipulation.html">next</a> | <a href="_saving_sppolynomials_spand_spmatrices_spin_spfiles.html">previous</a> | <a href="_file_spmanipulation.html">forward</a> | <a href="_saving_sppolynomials_spand_spmatrices_spin_spfiles.html">backward</a> | <a href="___The_sp__Macaulay2_splanguage.html">up</a> | <a href="index.html">top</a> | <a href="master.html">index</a> | <a href="toc.html">toc</a> | <a href="http://www.math.uiuc.edu/Macaulay2/">Macaulay2 web site</a></div> </td> </tr> </table> <div><a href="index.html" title="">Macaulay2Doc</a> > <a href="___The_sp__Macaulay2_splanguage.html" title="">The Macaulay2 language</a> > <a href="_two_spdimensional_spformatting.html" title="">two dimensional formatting</a></div> <hr/> <div><h1>two dimensional formatting</h1> <div>We have seen that nets (see <a href="___Net.html" title="the class of all nets and strings">Net</a>) are potentially useful for two dimesional formatting of output to an ascii terminal with limited graphical ability. We present now a few more hints about putting this idea into practice. Nets are used extensively in Macaulay2 for formatting, for example, for formatting of polynomials and matrices.<table class="examples"><tr><td><pre>i1 : R = ZZ/101[x,y,z];</pre> </td></tr> <tr><td><pre>i2 : f = random(R^1,R^{5:-3}) o2 = | -41x3-28x2y+5xy2-9y3-50x2z-34xyz+28y2z+7yz2+43z3 ------------------------------------------------------------------------ -40x3+18x2y-10xy2-15y3-47x2z+4xyz-2y2z-27xz2+47yz2-4z3 ------------------------------------------------------------------------ -40x3-11x2y+37xy2-47y3+50xyz+39y2z-17xz2-12yz2-9z3 ------------------------------------------------------------------------ 11x3+34x2y-31xy2+50y3-4x2z-6xyz-6y2z-35xz2-46yz2+40z3 ------------------------------------------------------------------------ 41x3-16x2y-19xy2+38y3+34x2z-45xyz-7y2z+32xz2-13yz2+26z3 | 1 5 o2 : Matrix R <--- R</pre> </td></tr> </table> Output of routines such as <a href="_betti.html" title="display degrees">betti</a> and <a href="_net.html" title="format for printing, as a net">net</a> that return nets can be easily incorporated into more complex displays using standard operations on nets (see <a href="___Net.html" title="the class of all nets and strings">Net</a>).<table class="examples"><tr><td><pre>i3 : C = resolution cokernel f 1 5 9 5 o3 = R <-- R <-- R <-- R <-- 0 0 1 2 3 4 o3 : ChainComplex</pre> </td></tr> <tr><td><pre>i4 : be = betti C 0 1 2 3 o4 = total: 1 5 9 5 0: 1 . . . 1: . . . . 2: . 5 . . 3: . . 9 5 o4 : BettiTally</pre> </td></tr> <tr><td><pre>i5 : "Betti numbers of " | net C | " are " | (net be)^2 0 1 2 3 total: 1 5 9 5 1 5 9 5 0: 1 . . . o5 = Betti numbers of R <-- R <-- R <-- R <-- 0 are 1: . . . . 2: . 5 . . 0 1 2 3 4 3: . . 9 5</pre> </td></tr> </table> You could even learn how to display algebraic expressions with nets.<table class="examples"><tr><td><pre>i6 : "x" | "2"^1 2 o6 = x</pre> </td></tr> </table> There is an easier way to display algebraic expressions, using a type of thing called an <a href="___Expression.html" title="the class of all expressions">Expression</a>. It allows you to set up things that print out as powers, sums, products, matrices, and so on. There are various types of expression, such as <a href="___Power.html" title="the class of all power expressions">Power</a>, <a href="___Sum.html" title="the class of all sum expressions">Sum</a>, <a href="___Divide.html" title="the class of all divide expressions">Divide</a>, <a href="___Minus.html" title="the class of all minus expressions">Minus</a>, and <a href="___Product.html" title="the class of all product expressions">Product</a> that we can use for this.<table class="examples"><tr><td><pre>i7 : Divide(Minus a,b) -a o7 = -- b o7 : Expression of class Divide</pre> </td></tr> <tr><td><pre>i8 : Power(Sum(3,4,5),7) 7 o8 = (3 + 4 + 5) o8 : Expression of class Power</pre> </td></tr> <tr><td><pre>i9 : Sum(1,2, Minus 3, 4,5) o9 = 1 + 2 - 3 + 4 + 5 o9 : Expression of class Sum</pre> </td></tr> </table> Actually, the formation of such expressions is contagious, in the sense that the basic algebraic operations will construct expressions for you if one of their two operands is already an expression.<table class="examples"><tr><td><pre>i10 : Minus a / b -a o10 = -- b o10 : Expression of class Divide</pre> </td></tr> <tr><td><pre>i11 : (Sum(3,4,5))^7 7 o11 = (3 + 4 + 5) o11 : Expression of class Power</pre> </td></tr> <tr><td><pre>i12 : 1 + 2 + Minus 3 + 4 + 5 o12 = 3 - 3 + 4 + 5 o12 : Expression of class Sum</pre> </td></tr> </table> In the last example above, <tt>1 + 2</tt> was evaluated first, so it yielded <tt>3</tt> but after that the contagion set in.<p/> The function <a href="_expression.html" title="convert to an expression">expression</a> can be used to prepare things such as polynomials for formatting using the mechanism introduced above.<table class="examples"><tr><td><pre>i13 : g = (x+y)^2 2 2 o13 = x + 2x*y + y o13 : R</pre> </td></tr> <tr><td><pre>i14 : e = expression g 2 2 o14 = x + 2x*y + y o14 : Expression of class Sum</pre> </td></tr> <tr><td><pre>i15 : peek e 2 2 o15 = Sum{x , 2x*y, y }</pre> </td></tr> </table> In the example above, we see that <a href="_peek.html" title="examine contents of an object">peek</a> extracts only one level of the structure. We may use <a href="_peek_sq_lp__Z__Z_cm__Thing_rp.html" title="examine contents of an object">peek'</a> to display the structure of <tt>e</tt> to depth 2.<table class="examples"><tr><td><pre>i16 : peek'(2,e) 2 2 o16 = Sum{Product{x }, Product{2, x, y}, Product{y }}</pre> </td></tr> </table> Other types of <a href="___Expression.html" title="the class of all expressions">Expression</a> that can be used for formatting nested lists as two dimensional arrays are <a href="___Matrix__Expression.html" title="the class of all matrix expressions">MatrixExpression</a> and <a href="___Table.html" title="the class of all table expressions">Table</a>.<table class="examples"><tr><td><pre>i17 : Table{{1,2,3},{a,bb,ccc}} o17 = 1 2 3 a bb ccc o17 : Expression of class Table</pre> </td></tr> <tr><td><pre>i18 : MatrixExpression{{1,2,3},{a,bb,ccc}} o18 = | 1 2 3 | | | | a bb ccc | o18 : Expression of class MatrixExpression</pre> </td></tr> <tr><td><pre>i19 : Table{{"Example 1","Example 2"}, {Table{{1,2},{3,4}},Table{{11,22},{3,444}}}} o19 = Example 1 Example 2 1 2 11 22 3 4 3 444 o19 : Expression of class Table</pre> </td></tr> </table> </div> </div> </body> </html>