summaryrefslogtreecommitdiffstats
path: root/doc/en/index.docbook
blob: ed37e23ad219643e036cc780f20da0066ca9bda6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<?xml version="1.0" ?>
<!DOCTYPE book PUBLIC "-//KDE//DTD DocBook XML V4.2-Based Variant V1.1//EN" "dtd/kdex.dtd" [
<!ENTITY mathemagics "Mathemagics" > 
<!ENTITY package "kdenonbeta">
<!ENTITY % addindex "IGNORE">
<!ENTITY % English "INCLUDE" > <!-- change language only here -->
]>

<book lang="&language;">
<bookinfo>
<title>The &mathemagics; Handbook</title>

<authorgroup>
<author>
<firstname>Jason</firstname>
<surname>Katz-Brown</surname>
<affiliation>
<address><email>jason@katzbrown.com</email></address>
</affiliation>
</author>
</authorgroup>

<copyright>
<year>2002</year>
<holder>Jason Katz-Brown</holder>
</copyright>

<legalnotice>&FDLNotice;</legalnotice>

<date>2002-05-25</date>
<releaseinfo>1.0</releaseinfo>

<abstract><para>&mathemagics; is a scientific RPN calculator for &tde;.</para></abstract>

<keywordset>
<keyword>KDE</keyword>
<keyword>Mathemagics</keyword>
<keyword>calculator</keyword>
<keyword>RPN</keyword>
</keywordset>
</bookinfo>

<chapter id="introduction">
<title>Introduction</title>

<para>This document describes &mathemagics; version 1.0.</para>

<para>&mathemagics; is a full-featured scientific calculator. It uses Reverse Polish Notation, or RPN. &mathemagics; can store and use user-defined functions and variables, and comes with large number of built-in functions.</para>

<para>Have fun with &mathemagics;!</para>

</chapter>


<chapter id="usage">
<title>Usage</title>

<para>This chapter describes usage of &mathemagics;'s features.</para>

<sect1 id="rpn">
<title>Reverse Polish Notation (RPN)</title>

<para>Most calculators use an algebraic system of input. In this system, one enters arguments to a function after entering the function itself. For example, to add 2 and 2, one would enter <userinput>2 + 2</userinput>.</para>

<para>&mathemagics; uses the <emphasis>Reverse Polish Notation</emphasis> system for input. With RPN, arguments are entered before the function. So to add 2 and 2, one would enter "2 2 +".</para>

<para>RPN is based around the <emphasis>stack</emphasis>. The stack stores numbers. When you execute a function, like <guibutton>x^y</guibutton>, the operation takes its arguments from the stack. If there are not enough numbers on the stack, &mathemagics; will tell you. In &mathemagics;, the stack is shown as a pile of line-entries. The first stack level is on the very bottom.</para>
</sect1>

<sect1 id="stack">
<title>Modifying the Stack</title>

<para>To enter something onto the stack, type it into the line-entry on the main toolbar. Then press the Return key. The number you entered will be pushed onto the stack. You can enter multiple numbers onto the stack at once by separating them with spaces. </para>

<para>To modify numbers already on the stack, click in the line-entry that represents the stack level. Then modify the displayed number by typing the new number you want into the line-entry. Finally, press return and the number will be saved onto that stack level. If you ever want to get rid of any stack changes you've made in this way, Choose the <guimenu>Edit</guimenu>-><guimenuitem>Revert Stack Changes</guimenuitem>.</para>

<para>To drop a stack level, replace the text in its line-entry with nothing. Then press return as you normall would in that line-entry.</para>

<para>To roll values on the stack upwards from a level, click the button to the right of the stack level you want to roll from. If the <guilabel>Inv</guilabel> button is checked, this will roll the values down; otherwise, it will roll them up.</para>
</sect1>

<sect1 id="functions">
<title>Using Functions</title>

<para>&mathemagics; comes with many built-in functions. You can access most of them from the <guilabel>Operations</guilabel> menu. The functions take their arguments from the numbers on the stack.</para>

<para>Alternatively, you can type the name of the function directly into the main line-entry.</para>

</sect1>

<sect1 id="variables">
<title>Variables</title>

<para>Variable syntax in &mathemagics; are slightly tricky to use.</para>

<variablelist>
<varlistentry>
<term>Assigning Variables</term>
<listitem>
<para><userinput>2 $example=</userinput> will create the variable <emphasis>example</emphasis> and assign the value <emphasis>2</emphasis> to it.</para>
<para><userinput>2 level $example=</userinput> will create the variable <emphasis>example</emphasis> and assign the value of the second stack level to it.</para>
<para>So, to assign the value on stack level 1 to a variable, write the variable name (prefaced by '$') followed immediately by '='.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Using Variables</term>
<listitem>
<para>To push the variable example on the stack, simply enter <userinput>$example</userinput>. In this way, using variables is the same as using any other number in equations. If you enter a variable that has no value assigned to it, nothing is pushed onto the stack.</para>
</listitem>
</varlistentry>
</variablelist>

</sect1>
</chapter>

<chapter id="scripting">
<title>Scripting</title>

<para>&mathemagics; can be scripted by defining your own functions.</para>

<sect1 id="user-functions">
<title>Defining Your Own Functions</title>

<para>You can define your own functions in &mathemagics;.</para>

<variablelist>
<varlistentry>
<term>Creating Functions</term>
<listitem>
<para><userinput>example=2 *</userinput> will create the function <emphasis>example</emphasis>. As defined, this function multiplies the bottom stack level by two. Functions can use any variables, and even call other functions</para>
</listitem>
</varlistentry>
<varlistentry>
<term>Using Functions</term>
<listitem>
<para>To use the function example, simply enter <userinput>example</userinput>. The function will be evaluated.</para>
</listitem>
</varlistentry>
</variablelist>

</sect1>

<sect1 id="useful">
<title>Useful Functions for Scripting</title>

<para>There are a few useful built-in functions that you can use when scripting &mathemagics;. Of course, all other built-in functions are also available for use.</para>

<informaltable><tgroup cols="3">
<thead>
<row><entry>Function</entry><entry>Arguments</entry><entry>Result</entry></row></thead>

<tbody>

<row><entry><userinput>reqargs</userinput></entry>
<entry>1: number of required arguments</entry>
<entry>stops function execution if stack does not have enough arguments</entry></row>

<row><entry><userinput>stopif</userinput></entry>
<entry>1: whether or not to stop (1 for true ($true), anything else for false ($false))</entry>
<entry>stop function execution if specified</entry></row>

<row><entry><userinput>at</userinput></entry>
<entry>1: level number (0-indexed)</entry>
<entry>drops stack level 1; pushes value of stack level onto stack</entry></row>

<row><entry><userinput>level</userinput></entry>
<entry>1: level number (1-indexed)</entry>
<entry>drops stack level 1; pushes value of stack level onto stack</entry></row>

</tbody></tgroup></informaltable>

</sect1>

</chapter>

<chapter id="specific-functions">

<title>Notes on Specific Functions</title>

<para>Some built-in functions in &mathemagics; require extra explanation. This follows.</para>

<sect1 id="lsh-rsh">
<title>Left Shift (lsh) and Right Shift (rsh)</title>
<variablelist>
<varlistentry>
<term><userinput>lsh</userinput> left shifts the integer part of the displayed value (multiplies it by 2) n times, where n is the next input number, and gives an integer result:</term>
<listitem><para><userinput>10 3 lsh</userinput> gives <emphasis>80</emphasis> (10 multiplied by 2 three times).</para>
<para><userinput>10.345 3 lsh</userinput> also gives <emphasis>80</emphasis>.</para></listitem>
</varlistentry>

<varlistentry>
<term><userinput>rsh</userinput> right shifts the value (performs an integer divide by 2) n times.</term> <listitem><para><userinput>16 2 rsh</userinput> gives <emphasis>4</emphasis> (16 divided by 2 twice).</para> <para><userinput>16.999 2 rsh</userinput> also gives <emphasis>4</emphasis>.</para>
</listitem>
</varlistentry>
</variablelist>

</sect1>

<sect1 id="and-or-xor">
<title>And, Or and XOr</title>

<para>The <userinput>and</userinput>, <userinput>or</userinput> and <userinput>xor</userinput> functions perform bitwise logical operations and therefore appear more meaningful if the <guilabel>Base</guilabel> is set to <guilabel>Hexadecimal</guilabel>, <guilabel>Octal</guilabel> or <guilabel>Binary</guilabel> rather than <guilabel>Decmal</guilabel>. In the following examples <guilabel>Base</guilabel> is set to <guilabel>Binary</guilabel>.</para>

<variablelist>
<varlistentry>
<term><userinput>and</userinput> does a logical AND.</term>
<listitem><para><userinput>101 110 and</userinput> gives
<emphasis>100</emphasis></para> </listitem>
</varlistentry>

<varlistentry>
<term><userinput>or</userinput> does the logical OR.</term>
<listitem><para><userinput>101 110 or</userinput> gives
<emphasis>111</emphasis></para> </listitem>
</varlistentry>

<varlistentry>
<term><userinput>xor</userinput> performs the logical
XOR (exclusive OR) operation.</term>
<listitem><para><userinput>101 110 xor</userinput> gives
<emphasis>11</emphasis></para> </listitem>
</varlistentry>

</variablelist>
</sect1>

</chapter>


<chapter id="questions-and-answers">
<title>Questions and Answers</title>

<qandaset>

<qandaentry>
<question><para>How do I get pi=3.1415926...?</para></question>
<answer><para>There is a predefined variable pi. To use it, enter <userinput>$pi</userinput>.</para></answer>
</qandaentry>

<qandaentry>
<question><para>How do I get e, the Euler number?</para></question>
<answer><para>There is a predefined variable e. To use it, enter <userinput>$e</userinput>.</para></answer>
</qandaentry>

</qandaset>
</chapter>

<chapter id="copyright">
<title>Credits and License</title>

<para>&mathemagics; Program copyright 2001-2002 Jason Katz-Brown <email>jason@katzbrown.com</email>.</para>

<para>Documentation copyright 2002:</para>
<itemizedlist>
<listitem><para>Jason Katz-Brown <email>jason@katzbrown.com</email></para></listitem>
</itemizedlist>

&underFDL;
<!-- &underBSDLicence; -->

</chapter>

<appendix id="installation">
<title>Installation</title>

<para>&mathemagics; is part of the &tde; project. For more details about &tde; visit <ulink url="http://trinitydesktop.org">http://trinitydesktop.org</ulink>.</para>

<para>&mathemagics;'s website is <ulink
url="https://mirror.git.trinitydesktop.org/gitea/TDE/mathemagics">
https://mirror.git.trinitydesktop.org/gitea/TDE/mathemagics</ulink></para>

<sect1 id="compilation-and-installation">
<title>Compilation and Installation</title>

<para>
In order to compile and install &mathemagics; on your system, type the following in the base directory; distribution:
<screen width="40">
<prompt>%</prompt> <userinput>mkdir -p build</userinput>
<prompt>%</prompt> <userinput>cd build</userinput>
<prompt>%</prompt> <userinput>cmake ../</userinput>
<prompt>%</prompt> <userinput>make</userinput>
<prompt>%</prompt> <userinput>make install</userinput>
</screen>
</para>

<para>Since &mathemagics; uses cmake you should have not trouble compiling it. Default options for cmake build are available in the INSTALL file.</para>

</sect1>
</appendix>

</book>