home *** CD-ROM | disk | FTP | other *** search
- " basic polynomial types "
- "
- * poly.self,v
- * Revision 1.13 1993/07/22 00:15:19 richards
- * Moved back to having event handlers per operation.
- * eventHandler/buttons now support substitution.
- * poly.self has primitive substitution handler, except that it has
- * no concept of context.
- *
- * Revision 1.12 1993/07/18 20:22:31 richards
- * Added substitution of polynomials (not quite working properly yet).
- * Some tests for this added to test4.
- * Buttons work, selections work, and eventHandling is coming along.
- *
- * Revision 1.11 1993/07/13 21:47:02 richards
- * July 13 checkin.
- *
- * Revision 1.10 1993/06/18 21:25:39 richards
- * Moved font support into viewManager.
- * Starting to add selection stuff into window and boite.
- * Boites refer properly back to the polynomial structures.
- *
- * Revision 1.9 1993/06/03 21:33:14 richards
- * Fixed up the redrawing of the subviews. Turned out they were being drawn off the screen
- * due to faulty thinking about where the areas really were.
- *
- * Revision 1.8 1993/05/31 20:27:53 richards
- * symbols has the whole greek alphabet, but some letters are not named right.
- * window.self noww uses two sub-classes of compoundView, one inside the other.
- * (Still have problem identifying them...)
- * test7 obsolete.
- * Fixed some problems with font positioning in boites and poly.
- *
- * Revision 1.7 1993/05/31 00:12:14 richards
- * May 30 checkin. Font support is nearly debugged.
- * Make use of glue now.
- * Added rational (fraction) types.
- *
- * Revision 1.6 1993/05/30 21:41:14 richards
- * Add rational type.
- *
- * Revision 1.5 1993/05/23 23:16:47 richards
- * No longer puts polynomials under globals, but rather aa.
- *
- * Revision 1.4 1992/08/19 02:42:21 richards
- * Added makeBoite to start the polynomial -> boite conversion. No font support yet.
- *
- * Revision 1.3 1992/07/05 22:38:37 richards
- * Added support for properly parenthesizing infix operators.
- * Each infix operator has an infixPriority, and if a lower priority
- * operation is printed as part of a higher priority binding (e.g. an
- * addition in the middle of a multiplication) then parenthesis are
- * added.
- *
- * Revision 1.2 1992/07/05 22:08:05 richards
- * Added and testing scalars and the plus operator.
- * The slot `thisObjectPrints' must be on the actual object --- it can't
- * be inherited. (This makes sense though...)
- *
- * Revision 1.1 1992/06/28 15:07:43 richards
- * Initial revision
- *
- *
- * /home/2user2/richards/cvs/491/aa/poly.self,v 1.13 1993/07/22 00:15:19 richards Exp
- *
- "
-
- aa traits _AddSlotsIfAbsent: ( |
- vector = ().
- scalar = ().
- addition = ().
- product = ().
- rational = ().
- exponent = ().
- differentiation = ().
- integration = ().
- operator = ().
- unaryop = ().
- binop = ().
- naryop = ()
- |)
-
- aa mixins _AddSlotsIfAbsent: ( |
- infixop = ().
- poly = ().
- |)
-
- aa traits operator _Define: (|
- ^ parent* = traits clonable.
- |)
-
- aa traits vector _Define: (|
- ^ parent* = traits clonable.
- |)
-
- aa mixins infixop _Define: (|
- printString: n = ( |output|
- output: ''.
- ( n > infixPriority ) ifTrue: [ output: '(' ].
- doFirst: [ |:firstArg| output: output,
- (firstArg printString: infixPriority) ]
- Middle: [ |:anArg| output: (output,' ',infixSymbol,' ',
- (anArg printString: infixPriority))]
- Last: [ |:lastArg| output: (output,' ',infixSymbol,' ',
- (lastArg printString: infixPriority))]
- IfEmpty: [ error: infixSymbol,
- ' requires at least two arguments'].
- ( n > infixPriority) ifTrue: [ output: output,')'].
- output).
- printString = ( printString: infixPriority ).
-
- makeBoite: n = ( | myHBoite. |
- myHBoite: aa boites hboite copy.
- myHBoite polyObject: self.
- ( n > infixPriority ) ifTrue: [ myHBoite addEnd: (aa boites htext make: '('). ].
-
- doFirst: [| :firstArg |
- myHBoite addEnd: firstArg makeBoite: infixPriority.
- myHBoite addEnd: (aa boites htext make: infixSymbol).
- ]
- Middle: [| :anArg |
- myHBoite addEnd: anArg makeBoite: infixPriority.
- myHBoite addEnd: (aa boites htext make: infixSymbol).
- ]
- Last: [| :lastArg|
- myHBoite addEnd: lastArg makeBoite: infixPriority.
- ]
- IfEmpty: [ error: infixSymbol,
- ' requires at least two arguments'].
-
- ( n > infixPriority ) ifTrue: [
- myHBoite addEnd: (aa boites htext make: ')').
- ].
- myHBoite
- ).
- makeBoite = ( makeBoite: infixPriority ).
-
- |)
-
- aa mixins poly _Define: (|
- ^ + aVar = ( |new|
- new: aa prototypes addition copy.
- new buildAddition: self.
- new buildAddition: aVar.
- new
- ).
- ^ * aVar = ( |new|
- new: aa prototypes product copy.
- new buildProduct: self.
- new buildProduct: aVar.
- new
- ).
- ^ / aVar = (| new |
- new: aa prototypes rational copy.
- new numerator: self.
- new denominator: aVar.
- new
- ).
-
- |)
-
-
- aa traits binop _Define: (|
- ^ parent* = aa traits operator.
- size = 2.
- doFirst: firstBlock Middle: middleBlock Last: lastBlock IfEmpty: emptyBlock = (
- firstBlock value: leftTerm.
- lastBlock value: rightTerm.
- ).
- substitute: eqn1 For: eqn2 = (| nb. |
- 'substitute: ' print. printLine. eqn1 printLine. eqn2 printLine.
- (equals: eqn2) ifTrue: [ ^(eqn1 copy) ].
- nb: copy.
- nb leftTerm: leftTerm substitute: eqn1 For: eqn2.
- nb rightTerm: rightTerm substitute: eqn1 For: eqn2.
- nb
- ).
- equals: eqn = (
- ((parent = eqn parent) && " MUST BE SAME TYPE "
- [(leftTerm equals: eqn leftTerm) &&
- (rightTerm equals: eqn rightTerm)])
- ).
-
- |)
-
- aa traits naryop _Define: (|
- ^ parent* = aa traits operator.
- doFirst: firstBlock Middle: middleBlock Last: lastBlock IfEmpty: emptyBlock = (
- ^(arguments doFirst: firstBlock
- Middle: middleBlock
- Last: lastBlock
- IfEmpty: emptyBlock)
- ).
- substitute: eqn1 For: eqn2 = (| n. |
- 'substitute: ' print. printLine. eqn1 printLine. eqn2 printLine.
- (equals: eqn2) ifTrue: [ ^eqn1 copy ].
- n: copy.
- n arguments removeAll.
- arguments do: [|:arg |
- n arguments addLast: (arg substitute: eqn1 For: eqn2).
- ].
- n
- ).
- equals: eqn = (| res. |
- res: (parent = eqn parent) && [arguments size = eqn arguments size].
- res ifTrue: [
- 0 to: (arguments size - 1) Do: [|:pos|
- res: res && [(arguments at: pos) equals: (eqn arguments at: pos)].
- ].
- ].
- res
- ).
- |)
-
- aa traits addition _Define: (|
- ^ parent** = aa traits naryop.
- ^ infixparent* = aa mixins infixop.
- ^ varparent* = aa mixins poly.
- infixSymbol = '+'.
- infixPriority = 16.
- arguments = ( terms ).
- copy = ( |new|
- new: clone.
- new terms: terms copy.
- new
- ).
- ^ buildAddition: var = (
- terms addLast: var.
- self
- )
- |)
-
- aa traits product _Define: (|
- ^ parent** = aa traits naryop.
- ^ infixparent* = aa mixins infixop.
- ^ varparent* = aa mixins poly.
- infixSymbol = '*'.
- infixPriority = 32.
- arguments = ( terms ).
- copy = ( |new|
- new: clone.
- new terms: terms copy.
- new
- ).
- ^ buildProduct: var = (
- terms addLast: var.
- self
- )
- |)
-
- aa traits rational _Define: (|
- ^ parent** = aa traits binop.
- ^ infixparent* = aa mixins infixop.
- ^ varparent* = aa mixins poly.
- infixSymbol = '/'.
- infixPriority = 20.
- leftTerm = ( numerator ).
- leftTerm: n = ( numerator: n ).
- rightTerm = ( denominator ).
- rightTerm: n = ( denominator: n ).
- copy = (| new |
- new: clone.
- new
- ).
- makeBoite: n = ( | vb. hb. line. |
- vb: aa boites vboite copy. vb polyObject: self.
- hb: aa boites hboite copy. hb polyObject: numerator.
-
- hb addEnd: aa boites hglue copy.
- hb addEnd: (numerator makeBoite: infixPriority).
- hb addEnd: aa boites hglue copy.
- vb addEnd: hb.
-
- line: aa boites hline copy.
- vb addEnd: line.
- vb baseLineBoite: line.
-
- hb: aa boites hboite copy. hb polyObject: denominator.
- hb addEnd: aa boites hglue copy.
- hb addEnd: (denominator makeBoite: infixPriority).
- hb addEnd: aa boites hglue copy.
- vb addEnd: hb.
-
- vb
- ).
- |)
-
-
- aa traits scalar _Define: (|
- ^ parent** = aa traits vector.
- ^ varparent* = aa mixins poly.
- printString = ( asciiRepresentation ).
- printString: n = ( asciiRepresentation ).
- makeBoite: n = (| nb. |
- nb: boiteRepresentation copy.
- nb polyObject: self.
- nb
- ).
- makeBoite = ( makeBoite: infixPriority ).
- commutes = true.
- associates = true.
- distributes = true.
- infixPriority = 64. " () never needed "
- create: name = ( |new|
- new: clone.
- new asciiRepresentation: name.
- new boiteRepresentation: (aa boites htext make: name).
- new
- ).
- create: name Boite: b = ( |new|
- new: clone.
- new asciiRepresentation: name.
- new boiteRepresentation: b.
- new
- ).
- equals: eqn = (
- = eqn
- ).
- substitute: eqn1 For: eqn2 = (
- 'substitute: ' print. printLine. eqn1 printLine. eqn2 printLine.
- (equals: eqn2) ifTrue: [ ^eqn1 ]. " SCALARs aren't copied "
- self
- ).
- |)
-
- " -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- "
- " PROTOTYPES FOR ABOVE OBJECTS "
- " -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- "
-
- aa prototypes _AddSlotsIfAbsent: (|
- addition = ().
- product = ().
- rational = ().
- scalar = ().
- |)
-
- aa prototypes addition _Define: (|
- ^ parent* = aa traits addition.
- thisObjectPrints = true.
- _^ terms <- list copy.
- |)
-
- aa prototypes product _Define: (|
- ^ parent* = aa traits product.
- thisObjectPrints = true.
- _^ terms <- list copy.
- |)
-
- aa prototypes rational _Define: (|
- ^ parent* = aa traits rational.
- thisObjectPrints = true.
- ^ numerator <- nil.
- ^ denominator <- nil.
- |)
-
- aa prototypes scalar _Define: (|
- ^ parent* = aa traits scalar.
- thisObjectPrints = true.
- _ asciiRepresentation.
- _ boiteRepresentation.
- |)
-
-
-
-
-