6

Very early on in Functional Differential Geometry, Sussman & Wisdom start using an "up structure"... but I haven't the slightest idea what this could be.

(print-expression
  ((compose P2-chi R2-chi-inverse)
  (up ’x0 ’y0)))

I cannot find the description of this structure anywhere in the text, and I cannot find it in a standard version of Scheme or the language documentation... so I'm wondering what exactly these "up structure" and "down structure" things are. I get that they correspond to the derivative and the integral in basic calculus. Just haven't the slightest idea how they're put together in Scheme.

1ijk
  • 1,417
  • 2
  • 19
  • 31
  • after learning a bit more multivariable calculus, I think the authors mean that an `up` structure is a column vector and a `down` structure is a row vector, hence, multiplying an `up` structure with `n` entries by a `down` structure with `m` entries should result in an `n`x`m` matrix. the text requires more advanced calculus (eg. multivariable) than I was prepared for when I first looked at it – 1ijk Feb 12 '16 at 20:38

2 Answers2

3

From the scmutils reference manual:1

We identify the Scheme vector data type with mathematical n-dimensional vectors. These are interpreted as up tuples when a distinction between up tuples and down tuples is made. We inherit from Scheme the constructors VECTOR and MAKE-VECTOR, the selectors VECTOR-LENGTH and VECTOR-REF, and zero-based indexing.

And, I think, the mathematical interpretation is: Covariance and contravariance of vectors.


1 (go to Up Tuples and Down Tuples section and scroll down to multiplication explanation, to see what it is all about).

Will Ness
  • 70,110
  • 9
  • 98
  • 181
usrtt1
  • 46
  • 2
2

See footnote 1 on Page 22:

In multiple dimensions the derivative Df(x) is a down tuple structure of the partial derivatives and the increment ∆x is an up tuple structure, so the indicated product is to be interpreted as a contraction. (See equation B.8.)

Scanning through the text for the appearance of up, it appears to be a two-place tuple holding real values. In Scheme two place tuple can be a simple dotted pair using cons:

 (define (up x y)
     (if (and (real? x)
              (real? y))
       (cons x y)
       (error "up: argument is not a Real"))))

 (define up? cons?)

 (define up-x car)

 (define up-y cdr)

Some Schemes bake a two place tuple in -- e.g. posn in Racket's Student Languages. On the other hand, in #lang racket we would probably use struct rather than cons and we would protect the struct with a contract:

#lang racket

(struct up (x y))

(provide (contract-out
          (struct up ((x real?)
                      (y real?)))))

Disclaimer

My impression from scanning the book is that the up structure holds two Real number values, but I don't claim to fully understand the maths. So a more complex data type may need to be specified or more extensive validation. Of course, a raw dynamically typed cons or list with no type validation is also an option for certain types of program.

ben rudgers
  • 3,647
  • 2
  • 20
  • 32
  • yes, but what is an "up tuple structure"? how is that defined in Scheme? – 1ijk Jan 15 '15 at 20:44
  • @haiqus Depending on the particular flavor of Scheme a tuple may be implemented as a pair, list, array, or a record type. At the simplest the two places of `up` could simply be a `cons` cell. See revised answer. – ben rudgers Jan 15 '15 at 21:37
  • The tuple can have more than two places, eg. a vector in R_3 space might be represented by (up 'x 'y 'z). It kind of makes sense that the authors may be leaving the precise data type unspecified and are just using the interface to illustrate the mathematics. In fact, rereading appendix B it looks like "up" is reserved for higher level vectors and "down" is reserved for the corresponding moments following derivation... I think we're getting very close to a complete explanation – 1ijk Jan 16 '15 at 04:34
  • 1
    Why the "memoize"? It's not a macro. – molbdnilo Jan 16 '15 at 10:10
  • I guess the memoize is for a type check on the inputs? – 1ijk Jan 16 '15 at 14:51
  • @haiqus Memoziation is the process of saving the results of a calculation. This allows the result to be looked up rather than having to be recalculated. In `(define (up x y) ...)` the variables `x` and `y` can be replaced by any expression. If `x` is a complex expression that takes one hour to calculate, then the `x` in `(real? x)` takes an hour and the `x` in `(cons x y)` takes another hour. On the other hand, though the `x` in `(let ((x1 x)...)...)` takes an hour, `(real? x1)` and `(cons x1 y1)` are as fast as a memory lookup. https://en.wikipedia.org/wiki/Memoization – ben rudgers Jan 16 '15 at 15:15
  • @benrudgers ah, I guess I didn't realize `x` would be evaluated more than once without the memoization – 1ijk Jan 16 '15 at 17:22
  • @benrudgers what you are describing in your above comment regarding the multiple substitution of a complex expression for `x` is not how Scheme evaluation works. Scheme is call by value with strict evaluation in an unspecified order. – GoZoner Jan 26 '15 at 05:27
  • 1
    @GoZoner Thanks. Memoziation removed. It is possible to express call by reference semantics into a Lisp, but it's a corner case and the confusion clearly outweighs it. See: http://docs.racket-lang.org/guide/pattern-macros.html?q=call%20by%20reference#%28part._pattern-macro-example%29 – ben rudgers Jan 27 '15 at 21:30
  • Sorry, didn't look at the link... because 'Racket is not Scheme' :-> – GoZoner Jan 28 '15 at 03:06
  • @GoZoner Racket isn't `#lang racket` either under any assumption that rules out R5RS as part of Racket. That's o.k. they say that Lisp is not an acceptable Lisp. – ben rudgers Jan 28 '15 at 04:29