mdlbear: (technonerdmonster)

You may remember from my previous post about Hyperviewer that I’d been plagued by a mysterious bug. The second time the program tried to make a simplex (the N-dimensional version of a triangle (N=2) or tetrahedron (N=3), a whole batch of “ghost edges” appeared and the program (quite understandably) blew up. I didn’t realize it until somewhat later, but there were ghost vertices as well, and that was somewhat more fundamental. Basically, nVertices, the field that holds the number of vertices in the polytope, was wildly wrong.

Chasing ghosts

Eventually I narrowed things down to someplace around here, which is where things stood at the end of the previous post.

1        let vertices = [];
2        /* something goes massively wrong, right here. */
3        for (let i = 0; i < dim; ++i) {
4            vertices.push(new vector(dim).fill((j) => i === j? 1.0 : 0));
5        }

I found this by throwing an error, with a big data dump, right in the middle if nVertices was wrong (it’s supposed to be dim+), or if the length of the list of vertices was different from nVertices.

 1        let vertices = [];
 2        /* something goes massively wrong, right here. */
 3        if (this.nVertices !== (dim + 1) || this.nEdges !== ((dim + 1) * dim / 2) ||
 4            this.vertices.length !== 0 || this.edges.length !== 0 ) {
 5            throw new Error("nEdges = " + this.nEdges + " want " +  ((dim + 1) * dim / 2) +
 6                            "; nVertices = " + this.nVertices + " want " + dim +
 7                            "; vertices.length = " + this.vertices.length +
 8                            ' at this point in the initialization, where dim = ' + dim +
 9                            " in " + this.dimensions + '-D ' + 
10                           );
11        } 
12        for (let i = 0; i < dim; ++i) {

It appeared that nVertices was wildly wrong at that point. If I’d looked carefully and thought about what nVertices actually was, I would probably have found the bug at that point. Or even earlier. Instead, what clinched it was this:

 1        this.vertices = vertices;
 2        this.nVertices = vertices.length;  // setting this to dim+1 FAILS:
 3        // in other words, this.nVertices is getting changed between these two statements!
 4        if (this.vertices.length !== this.nVertices || this.edges.length !== 0) {
 5            throw new Error("expect " + this.nVertices + " verts, have " + this.vertices.length +
 6                            " in " + this.dimensions + '-D ' + +
 7                            "; want " + this.nEdges + " edges into " + this.edges.length
 8                           );
 9        }

The code that creates the list of vertices produces the right number of vertices. If I set nVertices equal to the length of that list, everything was fine.

If instead I set

1        this.nVertices = dim+1;

it was wrong. Huh? For example, in four dimensions, the number of vertices is supposed to be five, and that was the length of the list. When is 4+1 not equal to 5?

At this point a light bulb went off, because it was clear that dim+1 was coming out equal to 41. In three dimensions it was 31. When is 4+1 not equal to 5? When it’s actually "4"+1. In other words, dim was a string. JavaScript “helpfully” converts a string to a number when you do anything arithmetical to it, like multiply it by something or raise it to a power. But + isn’t always an arithmetic operation! In JavaScript (and many other languages) it’s also used for string concatenation.

What went wrong, and a rant

The problem was that, the second time I tried to create a simplex, the number of dimensions was coming from the user interface. From an <input element in a web form. And every value that you get from a web form is a string. HTML knows nothing about numbers, and it has no way to know what you’re going to do with the input you get.

So the fix was simple (and you can see it here on GitHub: convert the value from a string to a number right off before trying to use it as a number of dimensions. But… But… But cubes and octohedrons were right!

That’s because the number of vertices in a N-cube is 2**N, and in an N-orthoplex (octohedron in three dimensions) it’s N*2 (and multiplication is always an arithmetic operator in JavaScript). And it worked when I was creating the simplex’s vertices because it was being compared against in a for loop. And so on.

If I’d been using a strongly-typed language, the compiler would have found this two weeks ago.

There are two main ways of dealing with data in a programming language, called “strong typing” and “dynamic typing”. In a strongly-typed language, both values and variables (the boxes you put values into) have types (like “string” or “integer”), and the types have to match. You can’t put a string into a variable with a type of integer. Java is like that (mostly).

Some people find this burdensome, and they prefer dynamically-typed languages like JavaScript. In JavaScript, values have types, but variables don’t. It’s called “dynamic” typing because a variable can hold anything, and its type is that of the last thing that was put into it.

You can write code very quickly in a language where you don’t have to declare your variables and make sure they’re the right type for the kind of values you want to put into them. You can also shoot yourself in the foot much more easily.

There are a couple of strongly-typed variants on JavaScript, for example CoffeeScript and TypeScript, and a type-checker called “Flow”. I’m going to try one of those next.

There was one more problem with simplexes

(simplices?) … but that was purely geometrical, and just because I was trying to do all the geometry in my head instead of on paper, and wasn’t thinking things through.

If you’re in N dimensions, you can create an N-1 dimensional simplex by simply connecting the points with coordinates like [1,0,0], [0,1,0], and [0,0,1] (in three dimensions – it’s pretty easy to see that that gives you an equilateral triangle). Moreover, all the vertices are on the unit sphere, which is where we want them. The last vertex is a bit of a problem.

A fair amount of googling around (or DuckDuckGoing around, in my case) will eventually turn up this answer on, which says that in N dimensions, the last vertex has to be at [x,...,x] where x=-1/(1+sqrt(1+N)). Cool! And it works. Except that it’s not centered – that last vertex is a lot closer to the origin than the others. It took me longer than it should have to get this right, but the center of the simplex is its “center of mass”, which is simply the average of all the vertices. So that’s at y=(1+x)/(N+1) because there are N+1 vertices. Now we just have to subtract y from all the coordinates to shift it over until the center is at the origin.

Then of course we have to scale it so that all the vertices are back on the unit sphere. You can find the code here, on GitHub.

Another fine post from The Computer Curmudgeon.

mdlbear: (technonerdmonster)

(This will be something of an experiment. The original was written in markdown and posted on We'll see whether the process made a hash of it. I may have to do some cleaning up.

This post is about Hyperviewer, an update of a very old demo program of mine from 1988 that displays wireframe objects rotating in hyperspace. (Actually, anywhere between four and six dimensions.) Since this is 2018, I naturally decided to write it in JavaScript, using Inferno and SVG, and put it on the web. It was a learning experience, in more ways than one.

Getting started

I had been doing a little work with React, which is pretty good an very popular, and had recently read about Inferno, which is a lighter-weight, faster framework that's almost completely interchangeable with React. Sounded good, especially since I wanted high performance for something that's going to be doing thousands of floating-point matrix multiplies per second. (A hypercube in N dimensions has 2^N vertices, and a rotation matrix has N^2 entries -- do the math). (It turns out I really didn't have to worry -- Moore's Law over three decades gives a speedup by a factor of a million, give or take a few orders of magnitude, so even using an partially-interpreted language speed isn't a problem. Perhaps I'm showing my age.)

To keep things simple -- and make it possible to eventually save pictures -- I decided to use SVG: the web standard for Scalable Vector Graphics, rather than trying to draw them out using an HTML5 Canvas tag. It's a perfect match for something that's nothing but a bunch of vectors. SVG is XML-based, and you can simply drop it into the middle of an HTML page. SVG is also really easy to generate using the new JSX format, which is basically XML tags embedded in a JavaScript file.

Modern JavaScript uses a program called a "transpiler" -- the most common one is Babel -- that compiles shiny new JavaScript constructs (and even some new languages like TypeScript and CoffeeScript, which I want to learn soon) into the kind of plain old JavaScript that almost any browser can understand. (There are still some people using Microsoft Exploiter from the turn of the century millennium; if you're reading this blog it's safe for me to assume that you aren't one of them.)

Anyway, let's get started:

cut tag added to protect your sanity )

(Not too bad of a formatting job, though of course the color didn't come through. Cut tag added because it's over 2000 words.)

Another fine post from The Computer Curmudgeon.
Cross-posted on

mdlbear: the positively imaginary half of a cubic mandelbrot set (Default)

The only major news is that we have a firm date for when the previous owner of our house gets all his stuff moved out: June 30th. That's about three weeks sooner than the original worst-case plan, so Colleen and I will have the entire month to get moved in, rather than a week. Yay!

I don't seem to have done much this week. I did get the car charged, and deposited a bunch of checks (including some old enough that I'm not sure they're still good -- I need to get a lot better at that). Mostly I sat around the apartment exploring an assortment of math topics on Wikipedia and YouTube.

It turns out that, thanks to a paper I wrote back at Carleton with one of my math professors, it can easily be determined that my Erdős number is officially 7. Unofficially, if one includes patents as well as actual math papers, it's 4. That still probably exceeds the number of people reading this who knew what an Erdős number is before reading this. The official value almost certainly does.

I did some actual programming yesterday (which I made more progress on today), aimed at bringing my song formatting and typesetting into the 21st Century. Mostly that means switching from postscript files to PDFs everywhere, upgrading to LaTeX2e, and simplifying the build process. There are still a few formatting issues that need to be dealt with; I will be having some fun this week refactoring my horrible old style files into classes.

There was some discussion in comments elsewidth about finding a therapist; I did a little link chasing. Not going to do anything about it until after we move.

Notes & links, as usual )

mdlbear: (e8)

I'm really glad we got Colleen's medicare coverage straightened out (or mostly -- her Part D (drug) coverage is not fully functional yet, nor is her supplemental policy). Because she went in to Shoreline Clinic for lab work on Tuesday after her visit to the SSA office, and Wednesday we got a call telling her to go to the ER and get IV fluids, because her creatinine level was high. That's related to kidney function, and in this case indicated a problem with her catheter.

So she spent the rest of the week in Northwest Hospital; she was discharged Friday. And Medicare covers it. I spent much of the week doing medicare-related paperwork; being retired may be relaxing once you get to actually do it -- retiring sure isn't. I'm still not done with Colleen's.

Meanwhile, I've been reading. I finished Counterexamples in Analysis, which is a really fun read. It had been used as the textbook for Advanced Calculus up until the year I went to Carleton, so there were enough copies lying around for me to get intrigued by such perverse creatures as "a space-filling curve that's almost everywhere almost nowhere". In the process, supplementing it with Wikipedia dives, I've finally gotten a little more comfortable with ring theory.

Last night, between John Baez on the number 24 on YouTube and a bit of digging on Wikipedia, I also started getting the hang of the Monster Group and E8. They turn out to be related to the Binary Golay code, a 24-bit error-correcting code invented by Marcel Golay, who I knew of because he'd collaborated with my father on the Savitzky–Golay filter!

I've also been reading Operating Systems: Three Easy Pieces - it's mostly review for me, but it's a good presentation and there are a few good nuggets in there. The Codeless Code, a collection of software-development koans, is also worth of note, and of everything I've mentioned here is probably of the most interest to people casually interested in the sociology of software development. Or possibly Zen Buddhism.

I've also been looking around Don Knuth's home page -- Don was my favorite professor at Stanford -- which eventually led me back to Surreal Numbers. I see that I don't have a good set of links for those.

Notes & links, as usual )

mdlbear: the positively imaginary half of a cubic mandelbrot set (Default)
There's that moment when everything changes,
But really it's just you,
Seeing things differently.

When you realize that the solid bench you're sitting on
Is mostly empty space between particles.
When you learn that even the particles
Aren't really particles, and that light isn't entirely waves either.

When you see the way special relativity views velocity
As simple rotation in four-space, 
And you study general relativity and realize
That it's geometry all the way down.

When you suddenly get recursion,
Reading the Algol 60 Report, with its crystalline prose
And elegantly compact rules.
When Goedel blows the top of your head off,
And you understand that some things simply can't be proved.
When you see how elegantly Turing applies the same trick.

When you realize that a little of the Unknowable
Isn't part of the Unknown anymore,
Because now you know why you can't know it.

First published in a comment in the October 2014 Crowdfunding Creative Jam, on the theme "Paradigm Shifting Without a Clutch."

This is entirely autobiographical, though the sequence has been messed with a little to give artistic verisimilitude to an otherwise bald and unconvincing narrative.

Mirrored from My poetry there is in really rough shape; hopefully I'll get a little work done on it soon.

Also adopted by [personal profile] ysabetwordsmith as part of her Schrodinger's Heroes series, which makes it unintentionally canonical fanfic for an imaginary TV show. Talk about shifting without a clutch! At least it has synchromesh. Or was that synchrotron?

mdlbear: portrait of me holding a guitar, by Kelly Freas (freas)

Just a quickie today, since I'm traveling and away from my usual posting client, but this is way too good to leave on the shelf until it becomes seasonal. If you love mathematics, or are a fan of xkcd, you really need to go over to YouTube and watch/listen to The Gauss Christmath Special by the amazingly wacko Vi Hart. Then go check out Pachelbel's Music Box Canon in D. I could go on. And on.

mdlbear: (120-cell)

Today's xkcd is screamingly funny, at least to anyone who knows the Banach–Tarski Theorem.

mdlbear: the positively imaginary half of a cubic mandelbrot set (Default)
raw notes )

Family visits tend to center around food; Mom's visit this weekend is no exception. Lunch was lamb, onion, and chutney open-faced sandwitches (Mom's recipe); dinner was at Arya, our favorite Persian and Italian place. (The YD was the only one who took advantage of the Italian menu. Silly child.)

A drive after dinner, showing mom the lovely Victorian houses in Los Gatos and Saratoga.

Lots of links under the cut, mostly from an extended explore of non-computable functions on Wikipedia. Bears are easily amused.

mdlbear: (wtf)

This is just plain wrong.

picture behind cut for the preservation of your sanity )

... unless you're familiar with "A Planet Named Shayol". In which case it is very, very wrong.

mdlbear: (e8)

Bear went splat at about 11:00 last night, after noticing that I was falling asleep in my chair rather than actually typing anything. The fact that the [ profile] flower_cat, and hence I, had been sleeping particularly badly Monday night probably had something to do with it.

This morning we both felt much better.

Today is (2x103+23)/23/33. Be there or be, um, cubical.

mdlbear: (e8)

Just noticed that tomorrow is 23/33...

And that Thursday will be perfect...

mdlbear: the positively imaginary half of a cubic mandelbrot set (Default)

For some reason I'm feeling absolutely exhausted. It's also possible -- likely, even -- that I've had a little too much coffee. The fact that my current cup of it has a little Frangelico in it may help, but probably not enough.

Meanwhile the song I've been working on is threatening to become a rhymed sestina, and to turn from a song into poetry of the most intimate sort. I shall probably be forced to fork it. The form intrigues me greatly, though; the Wikipedia article points to a wonderful example[pdf] that expounds on its underlying group theory. (Aside: go check out today's xkcd. Not as far off-topic as one might think.)

My mind seems to make a fairly strong distinction between song lyrics and poems. Some poems can be set to music -- I've done it -- but they tend to remain recognizably poems.

Meanwhile, I'm about 2/3 of the way through The Dream of Scipio by Iain Pears, a book which presents its own fascinating difficulties for me. You see, it's historical fiction. In science fiction and fantasy, the genres that I'm comfortably familiar with, you can generally count on the author to give you all the information you need to make sense of the book. You are, after all, a guest in the author's private world: it's the author's job to make you feel at home there, at least by the time you get to the end.

The problem with historical fiction is that you're not in the author's private world: you're in this world's past. And history has been a subject I've mostly avoided, in my past. So there's always the question, when I run across a character or an incident in the book, of just how much is history and how much is fiction. And there's always the question of whether I'm missing something important by not knowing. As a result, I find myself spending a good deal more time in Wikipedia than I do with most of the novels I've read. Fascinating in its own right, if somewhat dangerous.

mdlbear: (120-cell)

Today is, among other things, Newton's Birthday, which makes the [ profile] flower_cat's gift to me of a copy of God Created the Integers: the Mathematical Breakthroughs that Changed History by Stephen Hawking particularly appropriate.

It's an anthology of some of the most important papers in mathematics, with Hawking's introductions, starting with extracts from Euclid's Elements and ending with Turing's On Computable Numbers. I'm planning to just read the introductions and skim the rest -- it's the sort of book in which I could easily lose myself for months.

Thank you, love!

mdlbear: (e8)

The exceptionally beautiful object in my userpic is a projection into two dimensions of an exceptionally weird, complex, and strangely symmetrical family of 8-dimensional mathematical object called E8. In particular, it's a Lie group that just happens to contain, as subgroups, all of the simpler Lie groups used in quantum physics and gravitation.

With me so far?

Last month, a physicist/surfer dude named Garrett Lisi (CV) posted a paper with the title An Exceptionally Simple Theory of Everything that manages to combine all of the above into something considerably simpler and more elegant than string theory. Well, simpler if you happen to have a graduate-level grasp of group theory, quantum physics, and general relativity.

The current flurry of Wikipedia articles was apparently set off by this article in The Telegraph; I found out about it during my lunch break, from this post by [ profile] wcg. Needless to say, I didn't get a whole lot of work done this afternoon. Although it also turns out that the E8 lattice is also closely related to the Haming code H(8,4), an 8-bit error-correcting code in which any two codewords differ by at least 4 bits. And that's something that I might be able to use. (Makes a good excuse, anyway.) (But be careful always to call it, please, research!)

update: Almost forgot to mention the connection between E8 and octonions. There's a good monograph by John Baez here. Yes, he's Joan's cousin.

mdlbear: (120-cell)
NPR: A Four-Dimensional Tribute to the Late Madeleine L'Engle
An actual tesseract is best described as a four dimensional cube...and is kind of confusing. So, in memory of L'Engle, we met up with Physicist David Morgan who took a little time out of his day to talk tesseracts with the BPP. Put your measley three-dimensional brains to work on this (Via Boing Boing)
mdlbear: (120-cell)

... if any were needed, that xkcd is cool beyond measure. (Feed at [ profile] xkcd_rss)

image behind cut )
mdlbear: (120-cell)

I was out walking a couple of days ago and the phrase "Moebius Bandsaw" popped into my head. Turns out you don't always need a double edge to cut both ways.

Math lust

2007-01-22 11:46 am
mdlbear: (120-cell)
Rapid Prototyping Models --- George W. Hart
As a sculptor I am necessarily interested in three-dimensional geometry. As a hobby I am also interested in the mathematics of four-dimensional geometry. From a 4D object, one can calculate 3D "shadows" which are often beautiful but very complex objects. RP machines can easily produce these structures, which are stunning to look at even if one doesn't understand the underlying higher-dimensional ideas behind them. Below are two examples of such models; I hope in the future to be able to provide models for some algebraic surfaces and other interesting mathematical forms.
(from this post by [ profile] wendyg.) I'm seriously lusting after the 120-cell (see userpic for a different view of the beast).

update: on order (the cheaper, mini version). My publishing company is HyperSpace Express -- it's a business expense.
mdlbear: (120-cell)

The adventure starts with this post by [ profile] jenkitty containing directions for knitting a Klein Bottle hat, ganked from this page on one-sided surfaces.

That, of course, immediately led me to remember this hat at the Acme Klein Bottle online store. Somewhere around here I recalled my friend Ted's amusing account of trying to commission a Klein Bottle from a glassblower in Germany. (He eventually succeeded.)

A few more links lead to the geometric topology section of the Geometry Junkyard, and an online book called Math That Makes You Go Wow: A Multi-Disciplinary Exploration of Non-Orientable Surfaces.

Finally, combining non-orientable surfaces with another of [ profile] jenkitty's interests, I tracked down this appendix to The Ultimate Science Fiction Poetry Guide, which contained the correct text and attribution for a limerick I remembered reading in the December 1968 issue of Martin Gardner's Mathematical Games column of Scientific American: it's by the late science fiction author Cyril Kornbluth:

 A burleycue dancer, a pip
 Named Virginia, could peel in a zip;
     But she read science fiction
     And died of constriction
 Attempting a Mobius strip.

(The icon, BTW, is a 120-cell ganked from this Wikipedia article

mdlbear: (hacker glider)

From [ profile] amethyst_dancer by way of this post by [ profile] folkmew comes the news that the classic A Million Random Digits with 100,000 Normal Deviates has recently been republished.

The Amazon customer reviews are well worth a read, and the "search inside" feature can provide hours of harmless amusement.

Personally, I found it a little dated. As the only work of its kind, the digits can hardly be considered random anymore, but must instead be regarded as parts of the largest well-known integer that does not have a simple closed-form expression in standard mathematical notation. (At least until ISBNs become accepted as standard mathematical notation, a prospect which purists can only contemplate with horror and disgust.)

mdlbear: the positively imaginary half of a cubic mandelbrot set (Default)

Just in case you thought needlework necessarily had anything to do with reality, take a look at the rochet Hyperbolic Coral reef Project at The Institute For Figuring. For a deeper look, check out their Hyperbolic Space online exhibit. (From Make: Blog)

And now, if you'll excuse me, I think I need to go re-read Mount Analogue: A Novel of Symbolically Authentic Non-Euclidean Adventures in Mountain Climbing.

Most Popular Tags


RSS Atom

Style Credit

Page generated 2019-04-22 02:45 pm
Powered by Dreamwidth Studios