Debian Codegraph @

help/pt_BR/html/ch05s07.html

raw
1 <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>List of GEL Operators</title><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot"><link rel="home" href="index.html" title="Manual do Genius"><link rel="up" href="ch05.html" title="Chapter 5. GEL Basics"><link rel="prev" href="ch05s06.html" title="Modular Evaluation"><link rel="next" href="ch06.html" title="Chapter 6. Programming with GEL"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">List of GEL Operators</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch05s06.html">Prev</a> </td><th width="60%" align="center">Chapter 5. GEL Basics</th><td width="20%" align="right"> <a accesskey="n" href="ch06.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="genius-gel-operator-list"></a>List of GEL Operators</h2></div></div></div><p lang="en">
2 Everything in GEL is really just an expression. Expressions are stringed together with
3 different operators. As we have seen, even the separator is simply a binary operator
4 in GEL. Here is a list of the operators in GEL.
5 </p><div class="variablelist"><dl class="variablelist"><dt><span lang="en" class="term"><strong class="userinput"><code>a;b</code></strong></span></dt><dd><p lang="en">
6 The separator, just evaluates both
7 <code class="varname">a</code> and
8 <code class="varname">b</code>,
9 but returns only the result of
10 <code class="varname">b</code>.
11 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a=b</code></strong></span></dt><dd><p lang="en">
12 The assignment operator. This assigns <code class="varname">b</code> to
13 <code class="varname">a</code> (<code class="varname">a</code> must be a valid <a class="link" href="ch06s09.html" title="Lvalues">lvalue</a>) (note however that this operator
14 may be translated to <code class="literal">==</code> if used in a place where boolean
15 expression is expected)
16 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a:=b</code></strong></span></dt><dd><p lang="en">
17 The assignment operator. Assigns <code class="varname">b</code> to
18 <code class="varname">a</code> (<code class="varname">a</code> must be a valid <a class="link" href="ch06s09.html" title="Lvalues">lvalue</a>). This is
19 different from <code class="literal">=</code> because it never gets translated to a
20 <code class="literal">==</code>.
21 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>|a|</code></strong></span></dt><dd><p lang="en">
22 Absolute value.
23 In case the expression is a complex number the result will be the modulus
24 (distance from the origin). For example:
25 <strong class="userinput"><code>|3 * e^(1i*pi)|</code></strong>
26 returns 3.
27 </p><p lang="en">
28 See
29 <a class="ulink" href="http://mathworld.wolfram.com/AbsoluteValue.html" target="_top">Mathworld</a> for more information.
30 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a^b</code></strong></span></dt><dd><p lang="en">
31 Exponentiation, raises <code class="varname">a</code> to the <code class="varname">b</code>th power.
32 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a.^b</code></strong></span></dt><dd><p lang="en">
33 Element by element exponentiation. Raise each element of a matrix
34 <code class="varname">a</code> to the <code class="varname">b</code>th power. Or if
35 <code class="varname">b</code> is a matrix of the same size as
36 <code class="varname">a</code>, then do the operation element by element.
37 If <code class="varname">a</code> is a number and <code class="varname">b</code> is a
38 matrix then it creates matrix of the same size as
39 <code class="varname">b</code> with <code class="varname">a</code> raised to all the
40 different powers in <code class="varname">b</code>.
41 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a+b</code></strong></span></dt><dd><p lang="en">
42 Addition. Adds two numbers, matrices, functions or strings. If
43 you add a string to anything the result will just be a string. If one is
44 a square matrix and the other a number, then the number is multiplied by
45 the identity matrix.
46 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a-b</code></strong></span></dt><dd><p lang="en">
47 Subtraction. Subtract two numbers, matrices or functions.
48 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a*b</code></strong></span></dt><dd><p lang="en">
49 Multiplication. This is the normal matrix multiplication.
50 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a.*b</code></strong></span></dt><dd><p lang="en">
51 Element by element multiplication if <code class="varname">a</code> and
52 <code class="varname">b</code> are matrices.
53 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a/b</code></strong></span></dt><dd><p lang="en">
54 Division. When <code class="varname">a</code> and <code class="varname">b</code> are just numbers
55 this is the normal division. When they are matrices, then this is
56 equivalent to <strong class="userinput"><code>a*b^-1</code></strong>.
57 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a./b</code></strong></span></dt><dd><p lang="en">
58 Element by element division. Same as <strong class="userinput"><code>a/b</code></strong> for
59 numbers, but operates element by element on matrices.
60 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a\b</code></strong></span></dt><dd><p lang="en">
61 Back division. That is this is the same as <strong class="userinput"><code>b/a</code></strong>.
62 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a.\b</code></strong></span></dt><dd><p lang="en">
63 Element by element back division.
64 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a%b</code></strong></span></dt><dd><p lang="en">
65 The mod operator. This does not turn on the <a class="link" href="ch05s06.html" title="Modular Evaluation">modular mode</a>, but
66 just returns the remainder of integer division
67 <strong class="userinput"><code>a/b</code></strong>.
68 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a.%b</code></strong></span></dt><dd><p lang="en">
69 Element by element mod operator. Returns the remainder
70 after element by element integer division
71 <strong class="userinput"><code>a./b</code></strong>.
72 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a mod b</code></strong></span></dt><dd><p lang="en">
73 Modular evaluation operator. The expression <code class="varname">a</code>
74 is evaluated modulo <code class="varname">b</code>. See <a class="xref" href="ch05s06.html" title="Modular Evaluation">the section called “Modular Evaluation”</a>.
75 Some functions and operators behave differently modulo an integer.
76 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a!</code></strong></span></dt><dd><p lang="en">
77 Factorial operator. This is like
78 <strong class="userinput"><code>1*...*(n-2)*(n-1)*n</code></strong>.
79 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a!!</code></strong></span></dt><dd><p lang="en">
80 Double factorial operator. This is like
81 <strong class="userinput"><code>1*...*(n-4)*(n-2)*n</code></strong>.
82 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a==b</code></strong></span></dt><dd><p lang="en">
83 Equality operator.
84 Returns <code class="constant">true</code> or <code class="constant">false</code>
85 depending on <code class="varname">a</code> and <code class="varname">b</code> being equal or not.
86 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a!=b</code></strong></span></dt><dd><p lang="en">
87 Inequality operator,
88 returns <code class="constant">true</code> if <code class="varname">a</code> does not
89 equal <code class="varname">b</code> else returns <code class="constant">false</code>.
90 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a&lt;&gt;b</code></strong></span></dt><dd><p lang="en">
91 Alternative inequality operator,
92 returns <code class="constant">true</code> if <code class="varname">a</code> does not
93 equal <code class="varname">b</code> else returns <code class="constant">false</code>.
94 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a&lt;=b</code></strong></span></dt><dd><p lang="en">
95 Less than or equal operator,
96 returns <code class="constant">true</code> if <code class="varname">a</code> is
97 less than or equal to
98 <code class="varname">b</code> else returns <code class="constant">false</code>.
99 These can be chained as in <strong class="userinput"><code>a &lt;= b &lt;= c</code></strong> (can
100 also be combined with the less than operator).
101 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a&gt;=b</code></strong></span></dt><dd><p lang="en">
102 Greater than or equal operator,
103 returns <code class="constant">true</code> if <code class="varname">a</code> is
104 greater than or equal to
105 <code class="varname">b</code> else returns <code class="constant">false</code>.
106 These can be chained as in <strong class="userinput"><code>a &gt;= b &gt;= c</code></strong>
107 (and they can also be combined with the greater than operator).
108 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a&lt;b</code></strong></span></dt><dd><p lang="en">
109 Less than operator,
110 returns <code class="constant">true</code> if <code class="varname">a</code> is
111 less than
112 <code class="varname">b</code> else returns <code class="constant">false</code>.
113 These can be chained as in <strong class="userinput"><code>a &lt; b &lt; c</code></strong>
114 (they can also be combined with the less than or equal to operator).
115 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a&gt;b</code></strong></span></dt><dd><p lang="en">
116 Greater than operator,
117 returns <code class="constant">true</code> if <code class="varname">a</code> is
118 greater than
119 <code class="varname">b</code> else returns <code class="constant">false</code>.
120 These can be chained as in <strong class="userinput"><code>a &gt; b &gt; c</code></strong>
121 (they can also be combined with the greater than or equal to operator).
122 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a&lt;=&gt;b</code></strong></span></dt><dd><p lang="en">
123 Comparison operator. If <code class="varname">a</code> is equal to
124 <code class="varname">b</code> it returns 0, if <code class="varname">a</code> is less
125 than <code class="varname">b</code> it returns -1 and if
126 <code class="varname">a</code> is greater than <code class="varname">b</code> it
127 returns 1.
128 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a and b</code></strong></span></dt><dd><p lang="en">
129 Logical and. Returns true if both
130 <code class="varname">a</code> and <code class="varname">b</code> are true,
131 else returns false. If given numbers, nonzero numbers
132 are treated as true.
133 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a or b</code></strong></span></dt><dd><p lang="en">
134 Logical or.
135 Returns true if either
136 <code class="varname">a</code> or <code class="varname">b</code> is true,
137 else returns false. If given numbers, nonzero numbers
138 are treated as true.
139 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a xor b</code></strong></span></dt><dd><p lang="en">
140 Logical xor.
141 Returns true if exactly one of
142 <code class="varname">a</code> or <code class="varname">b</code> is true,
143 else returns false. If given numbers, nonzero numbers
144 are treated as true.
145 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>not a</code></strong></span></dt><dd><p lang="en">
146 Logical not. Returns the logical negation of <code class="varname">a</code>.
147 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>-a</code></strong></span></dt><dd><p lang="en">
148 Negation operator. Returns the negative of a number or a matrix (works element-wise on a matrix).
149 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>&amp;a</code></strong></span></dt><dd><p lang="en">
150 Variable referencing (to pass a reference to a variable).
151 See <a class="xref" href="ch06s08.html" title="References">the section called “References”</a>.
152 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>*a</code></strong></span></dt><dd><p lang="en">
153 Variable dereferencing (to access a referenced variable).
154 See <a class="xref" href="ch06s08.html" title="References">the section called “References”</a>.
155 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a'</code></strong></span></dt><dd><p lang="en">
156 Matrix conjugate transpose. That is, rows and columns get swapped and we take complex conjugate of all entries. That is
157 if the i,j element of <code class="varname">a</code> is x+iy, then the j,i element of <strong class="userinput"><code>a'</code></strong> is x-iy.
158 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a.'</code></strong></span></dt><dd><p lang="en">
159 Matrix transpose, does not conjugate the entries. That is,
160 the i,j element of <code class="varname">a</code> becomes the j,i element of <strong class="userinput"><code>a.'</code></strong>.
161 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a@(b,c)</code></strong></span></dt><dd><p lang="en">
162 Get element of a matrix in row <code class="varname">b</code> and column
163 <code class="varname">c</code>. If <code class="varname">b</code>,
164 <code class="varname">c</code> are vectors, then this gets the corresponding
165 rows, columns or submatrices.
166 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a@(b,)</code></strong></span></dt><dd><p lang="en">
167 Get row of a matrix (or multiple rows if <code class="varname">b</code> is a vector).
168 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a@(b,:)</code></strong></span></dt><dd><p lang="en">
169 Same as above.
170 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a@(,c)</code></strong></span></dt><dd><p lang="en">
171 Get column of a matrix (or columns if <code class="varname">c</code> is a
172 vector).
173 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a@(:,c)</code></strong></span></dt><dd><p lang="en">
174 Same as above.
175 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a@(b)</code></strong></span></dt><dd><p lang="en">
176 Get an element from a matrix treating it as a vector. This will
177 traverse the matrix row-wise.
178 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a:b</code></strong></span></dt><dd><p lang="en">
179 Build a vector from <code class="varname">a</code> to <code class="varname">b</code> (or specify a row, column region for the <code class="literal">@</code> operator). For example to get rows 2 to 4 of matrix <code class="varname">A</code> we could do
180 </p><pre lang="en" class="programlisting">A@(2:4,)
181 </pre><p lang="en">
182 as <strong class="userinput"><code>2:4</code></strong> will return a vector
183 <strong class="userinput"><code>[2,3,4]</code></strong>.
184 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a:b:c</code></strong></span></dt><dd><p lang="en">
185 Build a vector from <code class="varname">a</code> to <code class="varname">c</code>
186 with <code class="varname">b</code> as a step. That is for example
187 </p><pre lang="en" class="programlisting">genius&gt; 1:2:9
188 =
189 `[1, 3, 5, 7, 9]
190 </pre><p lang="en">
191 </p><p lang="en">
192 When the numbers involved are floating point numbers, for example
193 <strong class="userinput"><code>1.0:0.4:3.0</code></strong>, the output is what is expected
194 even though adding 0.4 to 1.0 five times is actually just slightly
195 more than 3.0 due to the way that floating point numbers are
196 stored in base 2 (there is no 0.4, the actual number stored is
197 just ever so slightly bigger). The way this is handled is the
198 same as in the for, sum, and prod loops. If the end is within
199 <strong class="userinput"><code>2^-20</code></strong> times the step size of the endpoint,
200 the endpoint is used and we assume there were roundoff errors.
201 This is not perfect, but it handles the majority of the cases.
202 This check is done only from version 1.0.18 onwards, so execution
203 of your code may differ on older versions. If you want to avoid
204 dealing with this issue, use actual rational numbers, possibly
205 using the <code class="function">float</code> if you wish to get floating
206 point numbers in the end. For example
207 <strong class="userinput"><code>1:2/5:3</code></strong> does the right thing and
208 <strong class="userinput"><code>float(1:2/5:3)</code></strong> even gives you floating
209 point numbers and is ever so slightly more precise than
210 <strong class="userinput"><code>1.0:0.4:3.0</code></strong>.
211 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>(a)i</code></strong></span></dt><dd><p lang="en">
212 Make <code class="varname">a</code> into an imaginary number (multiply <code class="varname">a</code> by the
213 imaginary). Normally the imaginary number <code class="varname">i</code> is
214 written as <strong class="userinput"><code>1i</code></strong>. So the above is equal to
215 </p><pre lang="en" class="programlisting">(a)*1i
216 </pre><p lang="en">
217 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>`a</code></strong></span></dt><dd><p lang="en">
218 Quote an identifier so that it doesn't get evaluated. Or
219 quote a matrix so that it doesn't get expanded.
220 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>a swapwith b</code></strong></span></dt><dd><p lang="en">
221 Swap value of <code class="varname">a</code> with the value
222 of <code class="varname">b</code>. Currently does not operate
223 on ranges of matrix elements.
224 It returns <code class="constant">null</code>.
225 Available from version 1.0.13.
226 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>increment a</code></strong></span></dt><dd><p lang="en">
227 Increment the variable <code class="varname">a</code> by 1. If
228 <code class="varname">a</code> is a matrix, then increment each element.
229 This is equivalent to <strong class="userinput"><code>a=a+1</code></strong>, but
230 it is somewhat faster. It returns <code class="constant">null</code>.
231 Available from version 1.0.13.
232 </p></dd><dt><span lang="en" class="term"><strong class="userinput"><code>increment a by b</code></strong></span></dt><dd><p lang="en">
233 Increment the variable <code class="varname">a</code> by <code class="varname">b</code>. If
234 <code class="varname">a</code> is a matrix, then increment each element.
235 This is equivalent to <strong class="userinput"><code>a=a+b</code></strong>, but
236 it is somewhat faster. It returns <code class="constant">null</code>.
237 Available from version 1.0.13.
238 </p></dd></dl></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p lang="en">
239 The @() operator makes the : operator most useful. With this you can specify regions of a matrix. So that a@(2:4,6) is the rows 2,3,4 of the column 6. Or a@(,1:2) will get you the first two columns of a matrix. You can also assign to the @() operator, as long as the right value is a matrix that matches the region in size, or if it is any other type of value.
240 </p></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p lang="en">
241 The comparison operators (except for the &lt;=&gt; operator, which behaves normally), are not strictly binary operators, they can in fact be grouped in the normal mathematical way, e.g.: (1&lt;x&lt;=y&lt;5) is a legal boolean expression and means just what it should, that is (1&lt;x and x≤y and y&lt;5)
242 </p></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p lang="en">
243 The unitary minus operates in a different fashion depending on where it
244 appears. If it appears before a number it binds very closely, if it appears in
245 front of an expression it binds less than the power and factorial operators.
246 So for example <strong class="userinput"><code>-1^k</code></strong> is really <strong class="userinput"><code>(-1)^k</code></strong>,
247 but <strong class="userinput"><code>-foo(1)^k</code></strong> is really <strong class="userinput"><code>-(foo(1)^k)</code></strong>. So
248 be careful how you use it and if in doubt, add parentheses.
249 </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch05s06.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch05.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch06.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Modular Evaluation </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 6. Programming with GEL</td></tr></table></div></body></html>