Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 7ebd25ac536d248d499a3ce2acda963a > files > 4978

Macaulay2-1.3.1-8.fc15.i686.rpm

<?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>ranges and repetitions</title>
<link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/>
</head>
<body>
<table class="buttons">
  <tr>
    <td><div><a href="__sh_sp__Basic__List.html">next</a> | <a href="_lists_spand_spsequences.html">previous</a> | <a href="__sh_sp__Basic__List.html">forward</a> | backward | <a href="_lists_spand_spsequences.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="_lists_spand_spsequences.html" title="">lists and sequences</a> > <a href="_ranges_spand_sprepetitions.html" title="">ranges and repetitions</a></div>
<hr/>
<div><h1>ranges and repetitions</h1>
<div><p>In this section we discuss the use of ranges and repetitions.</p>
<h2>ranges</h2>
The operator <a href="_...html" title="a binary operator, used for sequences of consecutive items">..</a> can be used to create sequences of numbers, sequences of subscripted variables, or sequences of those particular symbols that are known to <a href="_vars.html" title="variables">vars</a>, and so on.<table class="examples"><tr><td><pre>i1 : 1 .. 5, y_1 .. y_5, a .. e

o1 = ((1, 2, 3, 4, 5), (y , y , y , y , y ), (a, b, c, d, e))
                         1   2   3   4   5

o1 : Sequence</pre>
</td></tr>
</table>
<h2>repetitions</h2>
The operator <a href="___Z__Z_sp_co_sp__Thing.html" title="repeat an item">ZZ : Thing</a> is used to create sequences by replicating something a certain number of times.<table class="examples"><tr><td><pre>i2 : 12:a

o2 = (a, a, a, a, a, a, a, a, a, a, a, a)

o2 : Sequence</pre>
</td></tr>
</table>
Replicating something once results in a sequence of length 1, which cannot be entered by simply typing parentheses.<table class="examples"><tr><td><pre>i3 : 1:a

o3 = 1 : (a)

o3 : Sequence</pre>
</td></tr>
<tr><td><pre>i4 : (a)

o4 = a

o4 : Symbol</pre>
</td></tr>
</table>
<h2>ranges and repetitions in lists</h2>
Notice what happens when we try to construct a list using <a href="_...html" title="a binary operator, used for sequences of consecutive items">..</a> or <a href="__co.html" title="a binary operator, uses include repetition; ideal quotients">:</a>.<table class="examples"><tr><td><pre>i5 : z = {3 .. 6, 9, 3:12}

o5 = {(3, 4, 5, 6), 9, (12, 12, 12)}

o5 : List</pre>
</td></tr>
</table>
The result above is a list of length 3 some of whose elements are sequences.  This may be a problem if the user intended to produce the list <tt>{3, 4, 5, 6, 9, 12, 12, 12}</tt>.  The function <a href="_splice.html" title="remove subsequences">splice</a> can be used to flatten out one level of nesting - think of it as removing those pairs of parentheses that are one level inward.<table class="examples"><tr><td><pre>i6 : splice z

o6 = {3, 4, 5, 6, 9, 12, 12, 12}

o6 : List</pre>
</td></tr>
</table>
The difference between <a href="_splice.html" title="remove subsequences">splice</a> and <a href="_flatten.html" title="flatten a list by unnesting lists">flatten</a> is, essentially, that <a href="_flatten.html" title="flatten a list by unnesting lists">flatten</a> removes braces one level inward.<table class="examples"><tr><td><pre>i7 : flatten {a,{b,c}}

o7 = {a, b, c}

o7 : List</pre>
</td></tr>
<tr><td><pre>i8 : splice {a,(b,c)}

o8 = {a, b, c}

o8 : List</pre>
</td></tr>
</table>
The function <a href="_to__List.html" title="list of elements">toList</a> converts sequences to lists.<table class="examples"><tr><td><pre>i9 : 1..6

o9 = (1, 2, 3, 4, 5, 6)

o9 : Sequence</pre>
</td></tr>
<tr><td><pre>i10 : toList(1..6)

o10 = {1, 2, 3, 4, 5, 6}

o10 : List</pre>
</td></tr>
</table>
Many operators and functions will splice lists presented to them.  For example, when creating a polynomial ring, the array of variables and the list of degrees are spliced for you.<table class="examples"><tr><td><pre>i11 : QQ[a..c,x_1..x_4, Degrees => { 3:1, 4:2 }]

o11 = QQ[a, b, c, x , x , x , x ]
                   1   2   3   4

o11 : PolynomialRing</pre>
</td></tr>
<tr><td><pre>i12 : degrees oo

o12 = {{1}, {1}, {1}, {2}, {2}, {2}, {2}}

o12 : List</pre>
</td></tr>
</table>
</div>
</div>
</body>
</html>