# Re: OT Why Am I doing this?

Frank Goenninger DG1SBG wrote:
Ken Tilton <kennytilton@xxxxxxxxxxxxx> writes:

This thread is about, gosh, what is the structure isomorphic to --4
in its mathematical abstractitude? We know 3-2-1 is (3-2)-1
mathematically, so ((- 3 2) 1) is a nice representation of that for
the math engine. And I had gone with (- (- 4)) for --4 (which is
right, it seems) but the thread started because I scared myself with a
false commandment "Thine trees shalt always descend to the
left". Rubbish, thine trees shalt always reflect what they are
modelling.

Right. So why not model

x - -4

as

"Variable x minus the number -4. This means substracting a negative
number. We calculate this as adding the absolute value of the number
-4, which equals to 4. So we get

x + 4."

OK, so -4 is atomic, in the class <number> (using anglys to denote class). Super.

as it *should* be interpreted by the kids in any case? Translating
that into a data representation then would for me look like

(- x y) with y being bound to -4. This requires recognizing the token
-4 as a number.

Parsing

-4^2

then is

"We see the power operator here. This binds stronger than the minus
sign. Hence we get

- 4^2

which is the number -16."

OK, so now the minus sign is separate from the four, and -4 is either (a) of class <minus-sign> a subclass of <sign> a subclass of <operator> and has a slot <operands> populate by 4, a <number>, or (b) the silliness I have, the operator signed applied to two operands, a minus sign and a number 4.

What happened to atomic -4?

Representing this is, of course, requires analyzing the token "-4^2"
as a two-step operation itself. So, it ends up into a the requirement
of having a two-phase analysis approach: Operators/operations and
token

So they hit - and I have a sign instance, then they hit 4 and the minus instance goes away and I have a number instance (value -4) and then they hit the ^ key to start an exponent and I suddenly have three instances (-, 4, and a ^ awaiting its exponent), then they hit backspace and whoops there it is, back to one instance, -4 <number>?

Methinks the components of -4 and -4^2 need to be the same in re the minus sign and the 4, God does not play change-class with the universe.

Of course you all know this yourself. So, I just wrote this to check
if I understood your problem and your coding approach correctly - I
will have to deal with something similar down my own project...

The code will tell you if you have taken a wrong turn, it will be hard to write.

kt

--
http://www.theoryyalgebra.com/

"Career highlights? I had two. I got an intentional walk
from Sandy Koufax and I got out of a rundown against the Mets."."
- Bob Uecker
.