Re: Possreps - still trying to see the value

From: Bob Badour <bbadour_at_pei.sympatico.ca>
Date: Sun, 04 Mar 2007 22:19:21 GMT
Message-ID: <JBHGh.6249$PV3.54537_at_ursa-nb00s0.nbnet.nb.ca>


Marshall wrote:

> Okay, we mentioned possreps in passing in a recent thread.
> I'm still unclear on their value. Thought I'd try to talk it through
> and see what happens.
>
> The canonical example seems to be polar vs. cartesian.
> Bob used complex numbers the other day but I think
> 2D points is a bit more familiar.

Bob chose the complex number type and not a point type for a very good reason: complex number is a very specific type while a point type is an instance of a generic type.

To properly discuss a point type, one must start considering type generators for point types and matrix types.

As far as complex numbers go, real and imaginary are necessary and sufficient. We have no hyper-imaginary numbers to contend with. Plus, the complex number type has plenty of widely familiar operations like exponentiation.

> What operators are associated with 2D points?

The same operators we associate with n-D points.

  We
> would at least like to be able to get the x and y values.
> If we are thinking in polar terms, then the radius and
> angle also come immediately to mind. What else?

I suggest you are thinking in one direction and focusing on variables more than values. One would like to identify a value by both coordinate systems too. If a user has a magnitude and a phase, a good type system would let the user put them together into a literal as is and say: "Here, I have a complex number" without forcing the user to dig out sine and cosine.

Likewise, if the user has a real part and an imaginary part, a good type system would let the user put them together into a literal as is without forcing the user to dig out squares, square roots and arctangents.

Complex(0,1), Phaser(1,pi/2) and imaginary_unit might all represent valid literals for the same value.

> Probably we'd like to have some arithmetic of points:
> translate, rotate, scale. Dot product? Etc. (There's
> some question lurking nearby about the difference
> between a vector and a point; let's explicitly leave
> that out of this discussion, please.)

How many of the above does one get with matrix multiplication?

> So, are all these things present and accessible to
> client code in both forms? Is there any difference
> between the two possreps other than the performance
> characteristics of the associated functions?

There is no logical difference at all which is why both are equally valid representations at the logical level of discourse.

  If there
> isn't any other difference, it seems to me that means
> that possreps are part of the physical layer, and if
> that's the case, I don't see why they should be visible
> in the client code.

The whole point of possreps is to make the physical representation opaque to the client code. All complex numbers have a real part, an imaginary part, a magnitude and a phase.

Consider the following function:

Complex foo(Complex c) {

   Complex result = c
   RealPart(result) = 0
   return result
}

What would you expect for the result of foo(Phaser(1,pi/2)) ?

> If possreps are visible at the logical layer, then
> what do they provide that I wouldn't have otherwise?

The ability to change the real part of a complex number variable while holding the imaginary part invariant and the ability to change the phase of a complex number while holding the magnitude invariant, as examples.

> If instead of formalizing the point type, I instead
> used a tuple, either (x,y) or (t,r), and I had the
> full suite of functions I need defined on both forms,
> what don't I have that I would have with possreps?

Indeed. Why not just use a tuple type? After all, a tuple is a point in an n-ary space.

> Hot swap? Couldn't I get that, or almost that, with
> the tuple type? I could certainly modify existing
> relvars in place. There might be some adjustment
> necessary in client code, but I suspect even that
> could be automated. Perhaps *that* is the value
> of possreps?

I suggest you go back to the complex number type. Suppose e and pi are defined as real literals.

What would you expect for the value of the following expression?

Complex(e,0)^Phaser(pi,pi/2) - Real(e)^Imaginary(pi)

Doesn't logical independence require a type system that allows the user to express what the user wants any way the user wants to express it?

> The whole thing seems a lot like the ADTs of yore,

I had a highschool french teacher who frequently told me I have a fine grasp of the obvious. If not data types and abstractions, what sort of types did you think we were discussing here in a computer theory newsgroup?

> or even the idea of "value objects" that the OO world
> is starting to talk about now that the pendulum is
> swinging back in the direction of values.

Is that the one where the huge pendulum is sharpened to a razor edge and descends a little toward the bound protagonist on each massive swing?

> Any discussion or explanation is appreciated.
Received on Sun Mar 04 2007 - 23:19:21 CET

Original text of this message