Origin for each line in Lesson_1.red from check-in f2c04ccdad:

f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c:                   REDUCE INTERACTIVE LESSON NUMBER 1
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c:                          David R. Stoutemyer
f2c04ccdad 2021-03-03 trnsz@pobox.c:                          University of Hawaii
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT This is lesson 1 of 7 interactive lessons about the REDUCE
f2c04ccdad 2021-03-03 trnsz@pobox.c: system for computer symbolic mathematics.  These lessons presume an
f2c04ccdad 2021-03-03 trnsz@pobox.c: acquaintance with elementary calculus, together with a previous
f2c04ccdad 2021-03-03 trnsz@pobox.c: exposure to some computer programming language.
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: In REDUCE, any sequence of characters from the word "COMMENT" through
f2c04ccdad 2021-03-03 trnsz@pobox.c: the next semicolon or dollar-sign statement separator is an
f2c04ccdad 2021-03-03 trnsz@pobox.c: explanatory remark ignored by the system.  In general, either
f2c04ccdad 2021-03-03 trnsz@pobox.c: separator signals the end of a statement, with the dollar sign
f2c04ccdad 2021-03-03 trnsz@pobox.c: suppressing any output that might otherwise automatically be produced
f2c04ccdad 2021-03-03 trnsz@pobox.c: by the statement.  The typing of a carriage return initiates the
f2c04ccdad 2021-03-03 trnsz@pobox.c: immediate sequential execution of all statements which have been
f2c04ccdad 2021-03-03 trnsz@pobox.c: terminated on that line.  When REDUCE is ready for more input, it will
f2c04ccdad 2021-03-03 trnsz@pobox.c: prompt you with a prompt number followed by a colon and a space at the
f2c04ccdad 2021-03-03 trnsz@pobox.c: left margin.
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: Expressions can be formed using "^", "*", "/", "+", and "-" to
f2c04ccdad 2021-03-03 trnsz@pobox.c: indicate exponentiation, multiplication, division, addition, and
f2c04ccdad 2021-03-03 trnsz@pobox.c: subtraction or negation respectively.  Assignments to variables can be
f2c04ccdad 2021-03-03 trnsz@pobox.c: done using the operator ":=".  For example:;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: r2d2 := (987654321/15)^3;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT The immediately preceding line, without a semicolon, is the
f2c04ccdad 2021-03-03 trnsz@pobox.c: computed output generated by the line with a semicolon which precedes
f2c04ccdad 2021-03-03 trnsz@pobox.c: it.  Note that exact indefinite-precision rational arithmetic was
f2c04ccdad 2021-03-03 trnsz@pobox.c: used, in contrast to the limited-precision arithmetic of traditional
f2c04ccdad 2021-03-03 trnsz@pobox.c: programming languages.
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: We can use the name R2D2 to represent its value in subsequent
f2c04ccdad 2021-03-03 trnsz@pobox.c: expressions such as;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: r2d2 := -r2d2/25 + 3*(13-5);
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT We could equally well write the name of this variable as R2D2,
f2c04ccdad 2021-03-03 trnsz@pobox.c: r2D2 or R2d2 since REDUCE is case-insensitive.  Using this
f2c04ccdad 2021-03-03 trnsz@pobox.c: flexibility, in these lessons code discussed within the text will be
f2c04ccdad 2021-03-03 trnsz@pobox.c: written in upper case to make it stand out, but code to be actually
f2c04ccdad 2021-03-03 trnsz@pobox.c: executed by REDUCE will be written in lower case.
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: Now I will give you an opportunity to try some analogous computations.
f2c04ccdad 2021-03-03 trnsz@pobox.c: To do so, type the letter n or N followed by a carriage return in
f2c04ccdad 2021-03-03 trnsz@pobox.c: response to the question "Cont?".  (You could type y or Y if you wish
f2c04ccdad 2021-03-03 trnsz@pobox.c: to relinquish this opportunity, but I strongly recommend reinforced
f2c04ccdad 2021-03-03 trnsz@pobox.c: learning through active participation.)  After trying an example or
f2c04ccdad 2021-03-03 trnsz@pobox.c: two, type the command "cont" (with any capitalization) terminated by a
f2c04ccdad 2021-03-03 trnsz@pobox.c: semicolon and carriage return when you wish to proceed with the rest
f2c04ccdad 2021-03-03 trnsz@pobox.c: of the lesson.  To avoid interference with our examples, please don't
f2c04ccdad 2021-03-03 trnsz@pobox.c: assign anything to any variable names beginning with the letters E
f2c04ccdad 2021-03-03 trnsz@pobox.c: through I.  To avoid lengthy delays, I recommend keeping all of your
f2c04ccdad 2021-03-03 trnsz@pobox.c: examples approximately as trivial as ours, saving your more ambitious
f2c04ccdad 2021-03-03 trnsz@pobox.c: experiments until after the lesson.  If you happen to initiate a
f2c04ccdad 2021-03-03 trnsz@pobox.c: calculation requiring an undue amount of time to evaluate or display,
f2c04ccdad 2021-03-03 trnsz@pobox.c: you can abort that computation with an interrupt (Ctrl-C) to terminate
f2c04ccdad 2021-03-03 trnsz@pobox.c: REDUCE.  Restart REDUCE, followed by the statement "in less1.red",
f2c04ccdad 2021-03-03 trnsz@pobox.c: followed by a semicolon and return, to restart the lesson at the
f2c04ccdad 2021-03-03 trnsz@pobox.c: beginning.;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: pause;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT Now watch this example illustrating some more dramatic
f2c04ccdad 2021-03-03 trnsz@pobox.c: differences from traditional scientific programming systems:;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: e1 := 2*g + 3*g + h^3/h;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT Note how we are allowed to use variables to which we have
f2c04ccdad 2021-03-03 trnsz@pobox.c: assigned no values!  Note too how similar terms and similar factors
f2c04ccdad 2021-03-03 trnsz@pobox.c: are combined automatically.  REDUCE also automatically expands
f2c04ccdad 2021-03-03 trnsz@pobox.c: products and powers of sums, together with placing expressions over
f2c04ccdad 2021-03-03 trnsz@pobox.c: common denominators, as illustrated by the examples:;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: e2 := e1*(f+g);
f2c04ccdad 2021-03-03 trnsz@pobox.c: e2 := e1^2;
f2c04ccdad 2021-03-03 trnsz@pobox.c: e1+1/e1;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT Our last example also illustrates that there is no need to
f2c04ccdad 2021-03-03 trnsz@pobox.c: assign an expression if we do not plan to use its value later.  Try
f2c04ccdad 2021-03-03 trnsz@pobox.c: some similar examples.;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: pause;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT It is not always desirable to expand expressions over a common
f2c04ccdad 2021-03-03 trnsz@pobox.c: denominator, and we can use the OFF statement to turn off either or
f2c04ccdad 2021-03-03 trnsz@pobox.c: both computational switches which control these transformations.  The
f2c04ccdad 2021-03-03 trnsz@pobox.c: switch named EXP controls EXPansion, and the switch named MCD controls
f2c04ccdad 2021-03-03 trnsz@pobox.c: the Making of Common Denominators;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: off exp, mcd;
f2c04ccdad 2021-03-03 trnsz@pobox.c: e2 := e1^2$
f2c04ccdad 2021-03-03 trnsz@pobox.c: e2 := e2*(f+g) + 1/e1;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT To turn these switches back on, we type:;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: on exp, mcd;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT Try a few relevant examples with these switches turned off
f2c04ccdad 2021-03-03 trnsz@pobox.c: individually and jointly;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: pause;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: on exp;  % Just in case you turned it off!
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT The "%" character is another way to introduce a comment that
f2c04ccdad 2021-03-03 trnsz@pobox.c: extends as far as the end of the line.
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: Now consider the example:;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: e2 := (2*(f*h)^2 - f^2*g*h - (f*g)^2 - f*h^3 + f*h*g^2 - h^4
f2c04ccdad 2021-03-03 trnsz@pobox.c:        + g*h^3)/(f^2*h - f^2*g - f*h^2 + 2*f*g*h - f*g^2
f2c04ccdad 2021-03-03 trnsz@pobox.c:        - g*h^2 + g^2*h);
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT It is not obvious, but the numerator and denominator of this
f2c04ccdad 2021-03-03 trnsz@pobox.c: expression share a nontrivial common divisor which can be canceled.
f2c04ccdad 2021-03-03 trnsz@pobox.c: To make REDUCE automatically cancel greatest common divisors, we turn
f2c04ccdad 2021-03-03 trnsz@pobox.c: on the computational switch named GCD:;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: on gcd;
f2c04ccdad 2021-03-03 trnsz@pobox.c: e2;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT The switch is not on by default because
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c:     1.  It can consume a lot of time.
f2c04ccdad 2021-03-03 trnsz@pobox.c:     2.  Often we know in advance the few places where a nontrivial
f2c04ccdad 2021-03-03 trnsz@pobox.c:         GCD can occur in our problem.
f2c04ccdad 2021-03-03 trnsz@pobox.c:     3.  Even without GCD cancellation, expansion and common
f2c04ccdad 2021-03-03 trnsz@pobox.c:         denominators guarantee that any rational expression which is
f2c04ccdad 2021-03-03 trnsz@pobox.c:         equivalent to zero simplifies to zero.
f2c04ccdad 2021-03-03 trnsz@pobox.c:     4.  When the denominator is the greatest common divisor, such
f2c04ccdad 2021-03-03 trnsz@pobox.c:         as for  (X^2 - 2*X + 1)/(X - 1),  REDUCE cancels the
f2c04ccdad 2021-03-03 trnsz@pobox.c:         greatest common divisor even when GCD is OFF.
f2c04ccdad 2021-03-03 trnsz@pobox.c:     5.  GCD cancellation sometimes makes expressions more
f2c04ccdad 2021-03-03 trnsz@pobox.c:         complicated, such as with  (F^10 - G^10)/(F^2 + F*G - 2*G^2).
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: Try the examples mentioned in this comment, together with one or two
f2c04ccdad 2021-03-03 trnsz@pobox.c: other relevant ones.;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: pause;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT Exact rational arithmetic can consume an alarming amount of
f2c04ccdad 2021-03-03 trnsz@pobox.c: computer time when the constituent integers have quite large
f2c04ccdad 2021-03-03 trnsz@pobox.c: magnitudes, and the results become awkward to interpret qualitatively.
f2c04ccdad 2021-03-03 trnsz@pobox.c: When this is the case and somewhat inexact numerical coefficients are
f2c04ccdad 2021-03-03 trnsz@pobox.c: acceptable, we can have the arithmetic done using floating point by
f2c04ccdad 2021-03-03 trnsz@pobox.c: turning on the computational switch ROUNDED.  With this switch on, any
f2c04ccdad 2021-03-03 trnsz@pobox.c: non-integer rational numbers are approximated by floating-point
f2c04ccdad 2021-03-03 trnsz@pobox.c: numbers, and the result of any arithmetic operation is floating-point
f2c04ccdad 2021-03-03 trnsz@pobox.c: when any of its operands is floating point.  For example:;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: on rounded;
f2c04ccdad 2021-03-03 trnsz@pobox.c: e1 := (12.3456789e3*f + 3*g)^2 + 1/2;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT With ROUNDED off, any floating-point constants are
f2c04ccdad 2021-03-03 trnsz@pobox.c: automatically represented as explicit rational numbers:;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: off rounded;
f2c04ccdad 2021-03-03 trnsz@pobox.c: e1 := 12.35*g;
f2c04ccdad 2021-03-03 trnsz@pobox.c: pause;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT A number of elementary functions, such as SIN, COS and LOG,
f2c04ccdad 2021-03-03 trnsz@pobox.c: are built into REDUCE.  Moreover, the letter E represents the base of
f2c04ccdad 2021-03-03 trnsz@pobox.c: the natural logarithms, so the exponentiation operator enables us to
f2c04ccdad 2021-03-03 trnsz@pobox.c: represent the exponential function as well as fractional powers.  For
f2c04ccdad 2021-03-03 trnsz@pobox.c: example:;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: e1:= sin(-f*g) + log(e) + (3*g^2*cos(-1))^(1/2);
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT What automatic simplifications can you identify in this
f2c04ccdad 2021-03-03 trnsz@pobox.c: example?
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: Note that REDUCE never approximates the values of these functions,
f2c04ccdad 2021-03-03 trnsz@pobox.c: even for numerical arguments, and exact computations are generally
f2c04ccdad 2021-03-03 trnsz@pobox.c: impossible for non-trivial numerical arguments.
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: Experimentally determine some other built-in simplifications for these
f2c04ccdad 2021-03-03 trnsz@pobox.c: functions.;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: pause;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT Later you will learn how to introduce additional
f2c04ccdad 2021-03-03 trnsz@pobox.c: simplifications and additional functions.  To compute numerical
f2c04ccdad 2021-03-03 trnsz@pobox.c: approximations for examples such as COS(1) simply turn on ROUNDED.
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: Differentiation is also built-into REDUCE.  For example, to
f2c04ccdad 2021-03-03 trnsz@pobox.c: differentiate E1 with respect to F:;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: e2 := df(e1,f);
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT To compute the second derivative of E2 with respect to G, we
f2c04ccdad 2021-03-03 trnsz@pobox.c: can type either DF(E2,G,2) or DF(E1,F,1,G,2) or DF(E1,F,G,2) or
f2c04ccdad 2021-03-03 trnsz@pobox.c: DF(E1,G,2,F,1) or;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: df(e1,g,2,f);
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT Surely you can't resist trying a few derivatives of your own!
f2c04ccdad 2021-03-03 trnsz@pobox.c: (Careful, high-order derivatives can be alarmingly complicated.);
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: pause;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT REDUCE uses the name I to represent (-1)^(1/2), incorporating
f2c04ccdad 2021-03-03 trnsz@pobox.c: some simplification rules such as replacing I^2 by -1.  Here is an
f2c04ccdad 2021-03-03 trnsz@pobox.c: opportunity to experimentally determine other simplifications such as
f2c04ccdad 2021-03-03 trnsz@pobox.c: for I^3, 1/I^23, and (I^2-1)/(I-1).;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: pause;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT Clearly it is inadvisable to use E or I as a variable.  T is
f2c04ccdad 2021-03-03 trnsz@pobox.c: also inadvisable for reasons that will become clear later.
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: The value of a variable is said to be "bound" to the variable.  Any
f2c04ccdad 2021-03-03 trnsz@pobox.c: variable to which we have assigned a value is called a bound variable,
f2c04ccdad 2021-03-03 trnsz@pobox.c: and any variable to which we have not assigned a value is called an
f2c04ccdad 2021-03-03 trnsz@pobox.c: indeterminate.  Occasionally it is desirable to make a bound variable
f2c04ccdad 2021-03-03 trnsz@pobox.c: into an indeterminate, and this can be done using the CLEAR command.
f2c04ccdad 2021-03-03 trnsz@pobox.c: For example:;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: clear r2d2, e1, e2;
f2c04ccdad 2021-03-03 trnsz@pobox.c: e2;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT If you suspect that a degenerate assignment, such as E1:=E1,
f2c04ccdad 2021-03-03 trnsz@pobox.c: would suffice to clear a bound variable, try it on one of your own
f2c04ccdad 2021-03-03 trnsz@pobox.c: bound variables.;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: pause;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT REDUCE also supports matrix algebra, as illustrated by the
f2c04ccdad 2021-03-03 trnsz@pobox.c: following:;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: matrix e1(4,1), f;
f2c04ccdad 2021-03-03 trnsz@pobox.c: e1;  f;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT This declaration establishes E1 as a matrix with 4 rows and 1
f2c04ccdad 2021-03-03 trnsz@pobox.c: column, while establishing F as a matrix of unspecified size.  To
f2c04ccdad 2021-03-03 trnsz@pobox.c: establish element values (and sizes if not already established in the
f2c04ccdad 2021-03-03 trnsz@pobox.c: MATRIX declaration), we can use the MAT function, as illustrated by
f2c04ccdad 2021-03-03 trnsz@pobox.c: the following example:;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: h := mat((log(g), g+3), (g, 5/7));
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT Only after establishing the size of a matrix by declaring it
f2c04ccdad 2021-03-03 trnsz@pobox.c: or executing a matrix assignment can we refer to an individual element
f2c04ccdad 2021-03-03 trnsz@pobox.c: or to the matrix as a whole.  For example to increase the last element
f2c04ccdad 2021-03-03 trnsz@pobox.c: of H by 1 then form twice the transpose of H, we can type:;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: h(2,2) := h(2,2) + 1;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 2*tp(h);
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT To compute the determinant of H:;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: det(h);
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT To compute the trace of H:;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: trace(h);
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT To compute the inverse of H, we can use H^(-1) or 1/H.  To
f2c04ccdad 2021-03-03 trnsz@pobox.c: compute the solution to the equation H*F = MAT((G),(2)), we can
f2c04ccdad 2021-03-03 trnsz@pobox.c: left-multiply the right-hand side by the inverse of H:;
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: f := 1/h*mat((g),(2));
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: COMMENT Notes:
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c:    1.  MAT((G),(2))/H would denote right-multiplication by the
f2c04ccdad 2021-03-03 trnsz@pobox.c:        inverse, which is not what we want.
f2c04ccdad 2021-03-03 trnsz@pobox.c:    2.  Solutions for a set of right-hand-side vectors are most
f2c04ccdad 2021-03-03 trnsz@pobox.c:        efficiently computed simultaneously by collecting the right-
f2c04ccdad 2021-03-03 trnsz@pobox.c:        hand sides together as the columns of a single multiple-column
f2c04ccdad 2021-03-03 trnsz@pobox.c:        matrix.
f2c04ccdad 2021-03-03 trnsz@pobox.c:    3.  Sub-expressions of the form 1/H*... or H^(-1)*... are computed
f2c04ccdad 2021-03-03 trnsz@pobox.c:        more efficiently than if the inverse is computed separately in
f2c04ccdad 2021-03-03 trnsz@pobox.c:        a previous statement, so separate computation of the inverse
f2c04ccdad 2021-03-03 trnsz@pobox.c:        is advisable only if several solutions are desired and if
f2c04ccdad 2021-03-03 trnsz@pobox.c:        they cannot be computed simultaneously.
f2c04ccdad 2021-03-03 trnsz@pobox.c:    4.  MAT must have parentheses around each row of elements even if
f2c04ccdad 2021-03-03 trnsz@pobox.c:        there is only one row or only one element per row.
f2c04ccdad 2021-03-03 trnsz@pobox.c:    5.  References to individual matrix elements must have exactly two
f2c04ccdad 2021-03-03 trnsz@pobox.c:        subscripts, even if the matrix has only one row or one column.
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: Congratulations on completing lesson 1!  I urge you to try a sequence
f2c04ccdad 2021-03-03 trnsz@pobox.c: of more ambitious examples for the various features that have been
f2c04ccdad 2021-03-03 trnsz@pobox.c: introduced, in order to gain some familiarity with the relationship
f2c04ccdad 2021-03-03 trnsz@pobox.c: between problem size and computing time for various operations.  (The
f2c04ccdad 2021-03-03 trnsz@pobox.c: command "ON TIME" causes computing time to be output.)  I also urge
f2c04ccdad 2021-03-03 trnsz@pobox.c: you to bring to the next lesson appropriate examples from textbooks,
f2c04ccdad 2021-03-03 trnsz@pobox.c: articles, or elsewhere, in order to experience the decisive learning
f2c04ccdad 2021-03-03 trnsz@pobox.c: reinforcement afforded by meaningful personal examples that are not
f2c04ccdad 2021-03-03 trnsz@pobox.c: arbitrarily contrived.
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: To avoid the possibility of interference from assignments and
f2c04ccdad 2021-03-03 trnsz@pobox.c: declarations in lesson 1, it is wise to execute lesson 2 in a fresh
f2c04ccdad 2021-03-03 trnsz@pobox.c: REDUCE session, when you are ready.
f2c04ccdad 2021-03-03 trnsz@pobox.c: 
f2c04ccdad 2021-03-03 trnsz@pobox.c: ;end;

iCAS Bundled REDUCE Scripts
Homepage | GitHub Mirror | SourceHut Mirror | NotABug Mirror | Chisel Mirror | Chisel RSS ]