CaminoRealDoc.tioga
Dennis Arnon, December 15, 1986 10:26:03 am PST
CaminoReal
CEDAR 6.0 — FOR INTERNAL XEROX USE ONLY
CaminoReal
Dennis Arnon and Carl Waldspurger
© Copyright 1986 Xerox Corporation. All rights reserved.
Abstract: CaminoReal is an environment for several kinds of manipulations of mathematical expressions: (1) interactive, syntax-directed, two-dimensional, WYSIWYG editing, (2) insertion into a Tioga document, and (3) algebraic manipulation.
Created by: Dennis Arnon and Carl Waldspurger
Maintained by: Dennis Arnon <Arnon.pa>
Keywords: Math Editor, Mathematical Expressions, WYSIWYG, Computer Algebra, Algebra, MEDDLE, Polynomials, Matrices, Generic Procedures, Object-Oriented Programming, BigRats, BigCardinals, Algebraic Numbers, Complex Numbers
XEROX  Xerox Corporation
   Palo Alto Research Center
   3333 Coyote Hill Road
   Palo Alto, California 94304

For Internal Xerox Use Only
There is no 'royal road' to geometry.
Euclid, said to Ptolemy I
0. Prefatory Note
To see the mathematical expressions in this document, begin by carrying out the instructions in Section 2.
Double-starred items (**) can be ignored by the general user.
1. Introduction
There are computer algebra systems (Macsyma, Maple, Reduce, Scratchpad, SMP), and there are high quality document formatting systems that support mathematical expressions (Eqn-Troff, TEX, INFOR, VORTEX). There is still no adequate support for the working scientist who may have databases of math to browse, and who needs "living" notebooks and technical papers. Such a worker typically wants to examine a document or database, edit or algebraically manipulate expressions therein, and save new expressions. Not only should editing and algebra serve databases and documents, but conversely: one would like high-quality logs of algebra sessions.
CaminoReal is a prototype system for integration of documents, editing, and algebra. It supports interactive, syntax-directed, two-dimensional, WYSIWYG editing of mathematical expressions, placing/fetching such expressions in/from Tioga documents, and algebraic manipulation of expressions. The algebraic manipulation is based on an object-oriented paradigm that supports generic procedures (the AlgebraStructures package). Thus CaminoReal also provides client interfaces for generic operations in structured domains (e.g. vectors, matrices, polynomials) over such ground domains as Mesa INTs, Mesa REALs, Complexes, and BigRats. For example, with either the user environment or the interfaces, one can easily read and do simple arithmetic on matrices of polynomials with complex number coefficients, or matrices of such matrices, etc.
The expression editor is essentially Carl Waldspurger's MEDDLE package, extended to dovetail with the algebraic manipulation facilities (MEDDLE remains available as a separate CedarChest package).
It is perhaps most natural to view the algebra system as resident in the editor, i.e. algebraic manipulation of expressions is just a kind of editing of expressions. The current algebra functionality is a small Cedar package. [In the future we hope to offer access to other algebra systems running in either Unix or Lisp. This may be done either by extending the current user interface paradigm to incorporate functionality provided by the foreign system, or by providing new user interfaces for algebraic manipulation that allow the (necessarily knowledgeable) user to work with the foreign system in some facsimile of its own user interface paradigm] .
The new user should get some acquaintance with the terminology of Section 3. Sections 4-8 deal with editing of expressions, and moving expressions back and forth between CaminoReal and Tioga documents. Sections 9-12 deal with doing algebra. Section 14 pertains to some rather esoteric data structures pertaining to algebraic curves and surfaces. Section 15 describes how a client would use the algebra interfaces.
2. Getting Started
Bringover -p /Cyan/Imaging/Top/CaminoReal.df. Type "CaminoReal" to a command tool. You will get a viewer named "CaminoRealItem" opened in the left column [and in the future another iconified viewer named "Cad2DViewer"].
3. Items, Expressions, Domains, Objects
A Item is just another name for a CaminoReal viewer tool. An Item has a name, displayed in the viewer banner. You can change an items name by typing a new one in the ScratchPad and clicking the SetName menu button. You can get a new Item at any time by bugging the "NewItem" button in an existing Item, or typing "Camino" to a command tool.
An Expression can be displayed and edited, but is not capable of having algebraic manipulations performed on it. Every Expression is attached to some Item; every Item has one and only one (possibly null) Current Expression, which, at any moment, is what you see.
Strictly speaking, a Domain is just a set. Typically the Domains of interest are also algebraic structures, e.g. the integers, 2 x 2 matrices of complex numbers. Associated with any Domain is a certain collection of operations, such as conversion of Domain elements from Ropes or elements of other Domains, and arithmetic.
Abstractly, an Object is an element of a Domain. CaminoReal Objects possess Display Expressions, which we look at to see what Object we've got. Given an arbitrary Expression and an arbitrary Domain, the Expression may or may not be interpretable as an element of that Domain (obviously a Display Expression can always be interpreted as an element of its Object's Domain). In other words, from a given (Expression, Domain) pair we may or may not be able to construct an Object.
Every Object is attached to some Item, and every Item has one and only one (possibly empty) Current Object. The Domain to which an Item's Object belongs is the Item's Object Domain. Items also have a Working Domain, which can be edited at will. A common action is to set an Item's Current Object by interpreting its Current Expression as an element of its Working Domain; this is done by bugging SetObject with the Current Expression being the primary selection ("primary selection" is defined below).
When an Item has a nontrivial Object, it will usually be the case that the Item's Current Expression is the Object's Display Expression, but this is not necessarily so. We may edit the Current Expression, and the changes have no affect on the Current Object until we explicitly request that a new Current Object be established (e.g. by bugging SetObject with the appropriate primary selection (see below) in effect).
4. Terminology for Editing Expressions
PlaceHolder:
A placeholder is an empty Expression which needs to be filled in.
It is similar in appearance and function to placeholders () in Tioga, with
the exception that CaminoReal placeholders are never optional.
Replace:
"Replace old with new" means to delete old and insert new in its place.
Wrap:
"Wrap template foo around bar" means to use bar to fill in a placeholder in
template foo. After the wrap, bar is a subExpression of foo.
5. Selecting Expressions
What can you select?
You can select any Expression or subExpression.
You cannot select individual symbols in an Expression.
Example:
If you are editing a template for a summation, you can select any of the summation's
subExpressions (lowerlimit, upperlimit, summand) or the entire summation Expression.
You cannot, however, select the sigma symbol by itself in the summation (clicking on the
sigma will actually select the entire summation Expression).
Since Expressions can be thought of as trees (with operators at nodes and atoms at leaves),
CaminoReal provides ways to move through the Expression tree with a minimum of fuss.
Operations are available which allow you to: extend a selection to include its parent
Expression (moving up the tree), narrow a selection to a child Expression (moving down
the tree), and change a selection to select a sibling Expression (same level in tree).
Thus, both CaminoReal and Tioga have hierarchical tree-like structures and commands for
selecting subtrees and leaves.
There are three (well, really four) selection types, again similar in appearance and
function to Tioga selections:
Primary selection:
Selected Expression is highlighted by rendering it white on black, which is
inverted from the normal black on white (just like Tioga).
Copy selection:
Selected Expression is highlighted in dark gray.
Move selection:
Selected Expression is highlighted in light gray.
Active keyboard selection (KB Selection):
This selection type cannot be applied by the user. The selected Expression
highlighted using horizontal gray lines. This selection type is automatically
invoked when there is an active keyboard entry for an atom (e.g. a number or
variable). Its purpose is mostly as an indicator. However, when template
wrapping is invoked from the keyboard, an active keyboard selection is used
like a primary selection. (yes, I know this isn't so great and should be made more uniform,
but I have a plane to catch - It wouldn't be too hard to fix).
How can you select?
You can select Expressions using either the mouse or keyboard (mostly the mouse).
To select an Expression with the mouse, simply point at the Expression you wish to
select and click the appropriate button. The selected Expression will be the smallest
Expression (greatest depth in tree) which contains the point specified by the mouse. If you
think of each Expression as being enclosed by a bounding box, this is the Expression
enclosed by the smallest box which contains the point specified by the mouse.
The following mappings are currently used:
Single Clicks:
Red => Primary Select
Shift Red => Copy Select
Ctrl Red => Move Select
Blue => Primary Sibling Select
Shift Blue => Primary Child Select
Double Clicks:
Red => Extend Primary Selection to Parent
Shift Red => Extend Copy Selection to Parent
Ctrl Red => Extend Move Selection to Parent
Other:
DEL => Delete Primary Selection
Ctrl-P => Primary Select Parent of current Primary or KB selection
Ctrl-K => Primary Select Child (das Kind) of current Primary or KB selection
Ctrl-L => Primary Select Sibling (Lateral movement) of current Primary or KB selection
6. Entering Expressions
Using Menus:
ReplaceWithMatrix:
Replaces the primary selection with a matrix Expression.
The dimensions for the matrix are chosen from pop-up menus.
(note: CaminoReal can support arbitrarily big matrices, but the current user interface restricts
the maximum dimension to be 10 x 10.)
The matrix is initialized by setting all elements = 0.
This is useful when entering sparse matrices, and isn't really a hindarance when
you aren't.
ReplaceWithVector:
Replaces the primary selection with a vector Expression.
The type (row or column) and dimension for the vector are chosen from pop-up menus.
(note: CaminoReal can support arbitrarily big vectors, but the current user interface restricts
the maximum dimension to be 10.)
The vector is initialized by setting all elements = 0.
Vectors are really just special cases of matrices, but for some applications (e.g. CaminoReal)
it is desirable to maintain a distinction between vectors and matrices.
ReplaceWithExpr:
Replaces the primary selection with a template for a compound Expression.
The template (operation) is chosen from a pop-up menu.
ReplaceWithAtom:
Replaces the primary selection with an atomic Expression. The type of atom is chosen from a pop-up menu. Depending on the type of atom selected, the atom value is either obtained from additional pop-up menus or from a Tioga viewer selection. For example, "ReplaceWithAtom Integer" tries to get an integer from an active text selection, and "ReplaceWithAtom GreekVariable" provides a pop-up menu of choices for the variable.
"ReplaceWithAtom Variable" may allow you to get characters you want into an Expression when no other way seems available. Whatever is in the active text selection, i.e. any valid rope, will be picked up and stuffed when you bug the "Variable" entry of the pop-up menu.
WrapWithExpr:
Wraps a template around the primary selection. In other words, the primary selection
is used to fill in a placeholder in the template. This placeholder is usually the first
(e.g. "a" in "a + b") or most important (e.g. integrand in integration) argument to the
template. (Yes, of course the "hot" argument should be highlighted in the pop-up menu, but unfortunately
the pop-up menus package can't switch fonts between chars or even selections. Other alternatives
looked bad.) The template (operation) is chosen from a pop-up menu.
Using the keyboard:
CaminoReal allows keyboard input for some of the most common expression types.
Integer, Real, and Variable atoms can be typed directly into a (Primary- or Keyboard-)selected Expression. As mentioned in the section on selections, the active Keyboard selection will be selected and highlighted using horizontal gray lines. This selection is terminated as soon as a Primary selection is made or any editing function is invoked (you can always select outside of an Expression to get rid of the Keyboard selection). A Real number must begin with a digit (e.g. 0), and not just a decimal point
Typing operator characters into a selected Expression performs a template wrap around the currently active Keyboard or Primary selection. Currently supported keys, with their semantics, include:
'+ => binary sum
'— => binary difference
'- => unary negation
'* => binary product
'/ => binary fraction
'^ => binary pow
'← => binary subscript
', => binary list
'? => binary function
'( => unary parentheses
'{ => unary curlyBrackets
'[ => unary squareBrackets
'! => unary factorial
'$ => unary exists
'@ => unary forAll
'& => binary and
'| => binary or
'~ => unary not
'= => binary eqFormula
'> => binary gtFormula
'< => binary ltFormula
'# => binary notEqFormula
Ctrl-P => "select parent"
Ctrl-K => "select child (das Kind)"
Ctrl-L => "select sibling (Lateral movement)"
Ctrl-H => undo previous keystroke
Ctrl-X => swap Primary and Move selections (can't really use in keyboard input, since mouse required to make Move selection)
For the binary operators, this gives "pseudo-infix" input. For example, to enter "a + b", simply select a placeholder, then type "a", "+", "b". What is really going on is that the operation "+" is wrapped around the Expression "a", and the placeholder for the augend is auto-selected. Typing the "b" fills in the augend placeholder. The ctrl-P "select parent" operation is very useful for keyboard input to avoid switching beteen the keyboard and the mouse. For example, to enter X, use the keystrokes "x", "^", "2", ctrl—P, "+", "1", ctrl-P, "=", "0".
For the unary operators, the input paradigm is "prefix". E.g. to enter X, type the keystrokes "x", "$", "(".
(Note: This method is far from ideal. The user should be able to type "soft" parentheses which would elminate the need for most ctrl-P's. This also opens up the can of worms called "operator precedences" and "automatic parentheses generation" which should be considered in the future).
7. Editing Expressions
Copy
Make a Primary selection, hold down the Shift key, make a Copy selection, release Shift, and the Primary selection will be replaced by the Copy selection. The Copy selection is unchanged.
Can be done within a single Camino viewer or between two viewers.
Move
Make a Primary selection, hold down the Control key, make a Move selection, release Control, and the Primary selection will be replaced by the Move selection. The Move selection is replaced by a Placeholder.
Can be done within a single Camino viewer or between two viewers.
Swap
Intended to mimic Tioga's swap. Make a Primary selection, hold down Control, hit and release the "X" key (continue holding down Control) make a Move selection, release the Control key, and the Primary and Move selections will be interchanged.
Can be done within a single Camino viewer or between two viewers.
8. Expressions and Tioga Documents
ToTioga button
To put an expression into a Tioga doc, make a primary selection in the Camino viewer, make a selection in the Tioga doc, and bug "ToTioga". The expression will be placed in the document immediately preceding the Tioga selection. The value in the ScratchPad will become its PointSize in the document. 20.0 is a good initial choice.
The ScratchPad must either contain a REAL constant, or be empty, when you do this. If nonempty, the value it contains will become the PointSize of the expression in the document. 20.0 is the default if the ScratchPad is empty, and in general is a good initial choice.
Note that scaling an expression in a Camino viewer (with the Scale button) has no bearing on the PointSize an expression gets when put into a Tioga document; only the value in the ScratchPad controls that.
FromTioga button
To fetch an expression from a Tioga doc, make a primary selection in the Camino viewer, (character) select the expression in the Tioga doc, and bug "FromTioga". The ScratchPad will get set to the PointSize.
SetPtSize button
To adjust the PointSize of an expression in a document, put the value you want in the ScratchPad, (character) select the expr in the doc, and bug "SetPtSize".
Examples
Here are some sample paragraphs containing Expressions.
This is a plain line of text which happens to be above a Expression:
This line contains a Expression: X.
This is a plain line of text which happens to be below a Expression.
The following is a large Expression:
      Y
This line is immediately below the large Expression.
Here are some various sizes of Expressions (30 pt, 20 pt, 15 pt), obtained by setting the Expression's PointSize to the appropriate value (i.e. 30, 20, 15):
A
B
C
Note that Expressions can easily be moved or copied around in text with Tioga character copy.
Printing the document
Create an interpress file with the command "TiogaToInterpress <doc>.tioga", followed by an InterpressToPD command (e.g. "InterpressToPD <doc>.interpress raven384" for Stinger); print the resulting pd file. Be sure MeddleArtwork on is in effect when you do the TiogaToInterpress.
This sequence of steps is bundled up in the command file StingerPrint.cm
Further details on expressions in documents **
This discussion assumes that in the "Properties" box of the Edit Tool, you have toggled the "For selected nodes" box so that it becomes "For selected characters".
An Expression in a Tioga document is a character with Properties (see TiogaDoc). Thus if you select an Expression and list its properties, you'll see that it has the Artwork, MeddleExpr, and MeddlePtSize, properties. The way things work is that the value of the Artwork property for each Expression is "MeddleExpr", and the value of its MeddleExpr property is its "Meddle-format rope". The current modus operandi is to move Meddle-format ropes back and forth between the CaminoReal viewer and the characters in the document to which they are attached, with the FromTioga and ToTioga buttons of the Camino viewer
To see one of these Meddle-format rope's, fill in the "Property name" field of the Edit Tool with value "MeddleExpr", select an Expression in a document (e.g. this document), and hit the Get button for Property values.
9. The Basic User Interface Paradigm for Algebra
In terms of the definitions given above, we can state the basic fact of life for users doing algebraic manipulation: one Object, one Viewer. Every time an operation (e.g. addition of two Objects) that creates a new Object is performed, a new Item is created to which that Object is attached. Thus during a typical algebra session, Viewers accumulate quickly. A better way, e.g. logging new Objects in a continuously growing Tioga document, will come.
Before doing any algebra, we first have to have Domains to do it in, which is the subject of the next section.
10. Creating Domains
Bug the
Working Domain
button in the control panel. You'll get a pop-up menu of choices. Some of these are Ground Domains, and others are Domain Structuring Operations. The current Ground Domains likely to be of interest to the general user are:
Bools, Colors, FormulaOperators, Integers, Rationals, Reals, Complexes
You must initially select one of these; a short name for it (e.g. Z for Integers) will appear in the text viewer next to the Working Domain button.
Polynomials
For any polynomial, we need to keep track of 'what variables it's a polynomial in'. This is accomplished by associating a variable sequence with the polynomial. This is a sequence of Ropes (the variables). In order for scanning to work, variables should be Cedar identifiers. A variable sequence should be written as comma-separated variables enclosed in parentheses (whitespace ok anywhere except within a variable). For example, "(x,y,z)".
What you do is enter the variable sequence into the ScratchPad, then bug WorkingDomain, and bug Polynomials in the menu. The coefficient domain is what was previously in the "WorkingDomain".
Matrices
These are rings of square matrices of specified size, whose entries are elements of the current Working Domain. When you select Matrices, you get a pop-up menu to select the size.
11. Creating and Manipulating Objects
Creating an Object can be done in two ways: with the SetObject button described above, and by reading an Algebra-format Rope format rope for an object, as described in the next section.
Once you have a Current Object, bug the OperateObject button to get a list of available operations. The Current Object is the implicit first operand to any of these.
12. Algebra-format Ropes for Objects
The reader may find it a useful exercise, for each of these examples, to create an Item, set its WorkingDomain appropriately, Tioga-select the Algebra-format Rope given below for a sample element of that Domain, bug the OperateWorkingDomain button, and choose the FromLinearRope operation. In each instance, you should get a new Current Object and corresponding Display Expression.
You can always see what CaminoReal thinks is an appropriate Algebra-format Rope for the Primary Selection by bugging the "ToASRope" button.
1. Complex Numbers
Algebra-format Rope: (-38368.0 + 22976.0 i )
Display Expression:
i
At present, CaminoReal insists that anything that is to be considered a complex number must be created with the complex template from the menu, and hence be displayed in the form X. Thus for example, complex zero must be dealt with as X (or X; the presence or absence of decimal points doesn't matter) and complex one asX. Also, complex numbers with negative imaginary part will appear as in this example: X. Given this rigidity, one can perhaps live with the fact that complex numbers are not enclosed in parenthesis, e.g. here's an example of how CaminoReal currently prints a polynomial in x with complex coefficients: X
2. Polynomials
A polynomial is written as a sequence of terms in the variables of that list. Order of terms doesn't matter. Multiplication is implicit (whitespace between coefficients and variables). Exponentiation is indicated by either "^" or "**". Order of occurrence of variables in a term doesn't matter (no duplicate monomials allowed, however). Error if a variable not in the variable sequence occurs, but not all variables in the list need occur in any given polynomial. Case matters in variables. Order of occurrence of variables in a term doesn't matter.
No simplification currently supported in input, e.g. (x + y)^2 is illegal.
For example, suppose Domain is Polynomials in (x, y, z) over the Rationals.
Algebra-format Rope: x z^33 - 92837498279872983749734 / 33 y**23 + x y z - 1
Display Expression: i
3. Matrices
Domain is 2 x 2 Matrices over Polynomials in (x) over the Complexes.
Algebra-format Rope: [ [ x , (1.0 + 1.0 i ) x^12 + (0.0 - 1.0 i ) ] , [ x^3 , x ] ]
Display Expression: X
4. Algebraic Numbers (see Section 14)
Suppose the domain is extension of Rationals by the unique real root of X between -2 and -1.
Algebra-format Rope: [ x^3 + 647364/19 x^2 - 3 x + 1/8 ]
Display Expression: X
13. Other Menu Buttons
Scale
Scales the contents of the viewer.
red => scale by factor of 1.5 (zoom)
yellow => remove all scaling and return to default size (normal)
blue => scale by factor of 1/1.5 (shrink)
Home
Moves the Expression to its default location at the lower left-hand corner of the
viewer. This is useful if you used the bi-scrollers and "lost" the Expression somewhere
on the infinite plane.
Undo
Undoes the last operation which changed the contents of the viewer. Undo in CaminoReal, unlike Tioga, undoes the last change to an individual viewer, not to the global collection of active viewers (There are pros and cons to this approach). Undo sets the primary selection to the entire Current Expression. Note that Undo can also be done from the keyboard with either Control-H or Backspace.
SetName
Sets the name of this Item to the contents of the ScratchPad.
NewItem
Get a new CaminoRealTool. Copies Working Domain but not the Current Object (if any)
RestoreObject
Reset the Current Expression to be the Display Expression of the Current Object.
CopyObject
Like NewItem except copies Current Object also.
ToASRope **
This operation is similar to the ToRope operation, except that the linear form generated
is in a format which is readable by the "FromLinearRope" operation of many Domains.
Debug **
Bugging (no pun intended) Debug raises a resumable Break SIGNAL.
The state of the viewer and the currently displayed Expression can be
examined in the symbolic debugger.
14. Domains and Objects for Algebraic Numbers, Curves and Surfaces
The RealAlgebraicNumbers constructor is applied to a domain of univariate polynomials over the Rationals, e.g. Q[x]. Having set the Working Domain of an Item to this Domain, a particular real algebraic number can be created from two Objects (which must be attached to other Items): an element of the appropriate domain of univariate polynomials (this should be an irreducible polynomial), and an isolating interval for a particular real root of that polynomial. For example, the polynomial might be:
X
and the isolating interval
X
The latter can be constructed as an element of the domain of Points of length 2 over the Rationals. Primary select the polynomial and secondary select the interval. Then in the Viewer whose Working Domain is Real Algebraic Numbers, bug OperateWorkingDomain, and you will see the algebraic number displayed. For the above example, the result would be:
X
The ExtensionField constructor can only be applied in an Item whose Current Object is a Real Algebraic Number, constructed as just described. Just select ExtensionField from the Working Domain menu, and the domain constructed is the extension of the Rationals by that Algebraic Number. Elements of this domain are now univariate polynomials in the appropriate variable reduced mod the minimal polynomial. Thus in the above example, if we create a Current Expression of
X
primary select it, and bug SetObject, after reduction mod the minimal polynomial of X, we will get:
X
[The FormulaOperators and Cads ground Domains, and the Formulas, RealAlgebraicNumbers, ExtensionField, SamplePoints, CoveringSets, and Cells structuring operations are used, for algebraic curves and surfaces. Cad2DViewer is used for displaying algebraic curves. Exercising this stuff involves a detour through the Vax currently; consult Arnon if interested.]
15. Client Interfaces
To seek out the interfaces you want, look at AlgebraStructures.df. The class record slots, which are the same for all Domains, are defined in AlgebraClasses.mesa.
Client's method of Creating Domains
Ground Domains are provided as public variables in the appropriate interface, e.g.:
Ints.Ints
BigRats.BigRats
Structuring Operations have obvious names in the appropriate interface, e.g.:
domain ← Polynomials.MakePolynomialStructure[coeffRing, V]
Client's method of Creating Objects
Use the FromRope operation of the Domain's class record, or constructors (e.g. Matrices.DiagonalMatrix).
Displaying Objects
Use the ToRope operation of the Domain's class record.
Using Domain-specific operations
E.g. Polynomials.Differentiate[domain][arg].

or Polynomials.Diff[arg]
16. Acknowledgements
Thanks to Rick Beach and Michael Plass for enlightenment on Tioga and other matters. Thanks to Ken Pier for the "point and stuff" part of the CaminoReal-Tioga interface.