forked from debrouxl/gcc4ti
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtsymb.html
188 lines (171 loc) · 8.38 KB
/
htsymb.html
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Using Symbolic Mathematics</TITLE>
<STYLE TYPE="TEXT/CSS">
<!--
.IE3-DUMMY { CONT-SIZE: 100%; }
BODY { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; BACKGROUND-COLOR: #E0E0E0; }
P { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
H1 { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
H2 { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
H3 { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
H4 { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
H5 { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
H6 { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
UL { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; }
TD { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; BACKGROUND-COLOR: #FFFFFF; }
.NOBORDER { BACKGROUND-COLOR: #E0E0E0; PADDING: 0pt; }
.NOBORDER TD { FONT-FAMILY: Verdana,Arial,Helvetica,Sans-Serif; BACKGROUND-COLOR: #E0E0E0; PADDING: 0pt; }
.CODE { FONT-FAMILY: Courier New; }
-->
</STYLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#E0E0E0">
<FONT SIZE="5"><B>Using Symbolic Mathematics</B></FONT>
<HR>
<P>Using this library you can use even complex calculations which include algebraic
manipulations, calculus, etc. Everything you need is to build up the expression on
the expression stack in RPN (Reverse Polish Notation) form using various functions
from <A HREF="estack.html">estack.h</A> header file, then to evaluate the expression
using functions <A HREF="estack.html#NG_approxESI">NG_approxESI</A> or
<A HREF="estack.html#NG_rationalESI">NG_rationalESI</A>.
You need to know what is RPN (also known as Postfix Notation) to do this (see
<A HREF="estack.html">estack.h</A> for a list of RPN tokens). Symbolic
mathematics will be ilustrated through various examples. First example will be a simple
program which takes two polynoms (or more general expressions) as arguments, multiplies them,
then returns a new polynom as the result. In TI-Basic, you can perform such calculations using
TI-Basic function</P>
<PRE>expand (<I>arg1</I> * <I>arg2</I>)</PRE>
<P>where <I>arg1</I> and <I>arg2</I> are arguments. This may be represented in RPN form as</P>
<PRE><I>arg2</I> <I>arg1</I> * expand</PRE>
<P>So, here is a program (called "Multiply Polynoms"; note that <I>arg2</I> and <I>arg1</I> are already on the stack before
entering the program):</P>
<PRE>// Multiply and expand the two polynoms passed to the program
#define USE_TI89 // Compile for TI-89
#define USE_TI92PLUS // Compile for TI-92 Plus
#define USE_V200 // Compile for V200
#define OPTIMIZE_ROM_CALLS // Use ROM Call Optimization
#define RETURN_VALUE // Return a value
#define ENABLE_ERROR_RETURN // Enable returning errors
#define MIN_AMS 101 // Compile for AMS 1.01 or higher
#define SAVE_SCREEN // Save/Restore LCD Contents
#include <tigcclib.h> // Include All Header Files
// Main Function
void _main(void)
{
push_quantum_pair (MUL_TAG, EXPAND_TAG);
NG_rationalESI (top_estack);
}
</PRE>
<P>It is highly recommended to <A HREF="htretval.html#reterr">pass errors on to the AMS</A>.
After compiling this program (assuming that its name is "polymul.c") try this from TI-Basic:</P>
<PRE>polymul (x+y, x-y)</PRE>
<P>But note that returning values from ASM programs to TI-Basic is not without severe limitations.
See the section about <A HREF="htretval.html">returning values to TI-Basic</A>.
<BR><BR>
<A HREF="estack.html">estack.h</A> contains two very useful functions which convert ordinary
algebraic expressions (given in a string) to tokenized RPN form and vice-versa, named
<A HREF="estack.html#push_parse_text">push_parse_text</A> and <A HREF="estack.html#display_statements">display_statements</A>
(although they are somewhat slow, so if you want fast calculations, force RPN as much as possible).
They are very useful if you want to process algebraic data accepted from the keyboard, or to display
algebraic data on the screen. Also, a function <A HREF="estack.html#Print2DExpr">Print2DExpr</A>
is implemented, which "pretty prints" the expression in a window. Here is an example of a program (called "Pretty Print")
which calculates the ingegral of 1/((x-3)(x^2+4)) with respect to x and "pretty prints" the result
on the screen:</P>
<PRE>// Calculate an integral and pretty print it
#define USE_TI89 // Compile for TI-89
#define USE_TI92PLUS // Compile for TI-92 Plus
#define USE_V200 // Compile for V200
#define MIN_AMS 101 // Compile for AMS 1.01 or higher
#define SAVE_SCREEN // Save/Restore LCD Contents
#include <tigcclib.h> // Include All Header Files
// Main Function
void _main(void)
{
TRY
push_END_TAG ();
push_quantum (VAR_X_TAG);
push_parse_text ("1/((x-3)(x^2+4))");
push_quantum (INTEGRATE_TAG);
NG_rationalESI (top_estack);
WinClr (DeskTop);
Print2DExpr (Parse2DExpr (top_estack, FALSE), DeskTop, 0, 50);
ONERR
DrawStr (20, 20, "Error!", A_NORMAL);
ENDTRY
ngetchx ();
}
</PRE>
<P>As already mentioned above, powerful applications should avoid <A HREF="estack.html#push_parse_text">push_parse_text</A>
as much as possible, and use RPN as much as possible. This will be ilustrated through an example.
The expression</P>
<PRE>Integral (1/((x-3)(x^2+4)), x)
</PRE>
<P>may be expressed in the RPN form (see <A HREF="estack.html">estack.h</A>) as shown below:</P>
<PRE>x 1 x 3 - 2 x ^ 4 + * / Integral
</PRE>
<P>According to this representation, the previous program may be rewritten as ("Static Expression"):</P>
<PRE>// Evaluate and print a static expression
#define USE_TI89 // Compile for TI-89
#define USE_TI92PLUS // Compile for TI-92 Plus
#define USE_V200 // Compile for V200
#define OPTIMIZE_ROM_CALLS // Use ROM Call Optimization
#define MIN_AMS 100 // Compile for AMS 1.00 or higher
#define SAVE_SCREEN // Save/Restore LCD Contents
#include <tigcclib.h> // Include All Header Files
// Main Function
void _main(void)
{
static unsigned char rpn[] = {END_TAG, VAR_X_TAG, 1, 1, POSINT_TAG,
VAR_X_TAG, 3, 1, POSINT_TAG, SUB_TAG, 2, 1, POSINT_TAG, VAR_X_TAG,
POW_TAG, 4, 1, POSINT_TAG, ADD_TAG, MUL_TAG, DIV_TAG, INTEGRATE_TAG};
NG_rationalESI (rpn + sizeof (rpn) - 1);
WinClr (DeskTop);
Print2DExpr (Parse2DExpr (top_estack, FALSE), DeskTop, 0, 50);
ngetchx ();
}
</PRE>
<P>Maybe you want to find an integral of the function which is passed as the argument
of the program in respect to x, and to print the result using the ordinary
<A HREF="stdio.html#printf">printf</A> function (i.e. without "pretty printing")? OK, why not?
Here is an example (called "Integrate"):</P>
<PRE>// Integrate the argument with respect to x and display it
#define USE_TI89 // Compile for TI-89
#define USE_TI92PLUS // Compile for TI-92 Plus
#define USE_V200 // Compile for V200
#define OPTIMIZE_ROM_CALLS // Use ROM Call Optimization
#define MIN_AMS 101 // Compile for AMS 1.00 or higher
#define SAVE_SCREEN // Save/Restore LCD Contents
#include <tigcclib.h> // Include All Header Files
// Main Function
void _main(void)
{
ESI argptr = top_estack;
HANDLE h;
clrscr ();
TRY
push_END_TAG ();
push_quantum (VAR_X_TAG);
push_expr_quantum (argptr, INTEGRATE_TAG);
NG_rationalESI (top_estack);
h = display_statements (top_estack, 1, FALSE);
printf ("The integral is: %s", (const char*) (HeapDeref (h)));
HeapFree (h);
ONERR
printf ("Error!");
ENDTRY
ngetchx();
}
</PRE>
<P>A lot of extremely powerful math functions are implemented in the <A HREF="estack.html">estack.h</A>
header file, which are never seen in TI-Basic: accessing various parts of expressions, extracting
factors, terms, etc. Of course, don't try to make any program for symbolic math before studying
the <A HREF="estack.html">estack.h</A> header file carefully. Anyway,
<A HREF="bascmd.html">bascmd.h</A>, <A HREF="basfunc.html">basfunc.h</A>,
and <A HREF="basop.html">basop.h</A> are useful for symbolic mathematics as well.</P>
<P>See also: <A HREF="estack.html">estack.h</A>, <A HREF="basfunc.html">basfunc.h</A>, <A HREF="basop.html">basop.h</A>, <A HREF="bascmd.html">bascmd.h</A></P>
<HR>
<H3><A HREF="index.html">Return to the main index</A></H3>
</BODY>
</HTML>