2023-01-30

Developing independence

The child is five.

Recently she's started closing her door when she goes in her room, and sometime issues the instruction "leave me alone". All of which I expected, though I didn't really know when to expect it.

The bit where she locked her door behind her is what surprised me.

Can you use fixed-point?

I do scientific computing. Mostly in c++ which offers a host of places to have problems, but that isn't what I want to talk about today. Instead I want to talk about language-independent issues with math.

From a science or engineering point of view, the formulae that we look up and equations we write down and manipulate all assume we're working with real or complex values (or at least with integers). Notably all those fields are infinite and we represent a working sub-set of them with not-very-big sets of bits. And that's where the trouble sets in.

Now, many language provide types that offer a "floating-point" representation of some of the reals. Think about a binary version of scientific notation: $1.xyz \times 2^{abc}$. In modern times this stuff is actually well standardized with most hardware implementing IEEE754.

A not-at-all exhaustive list of the common problems for floating-point representations include

  • Easy to write down fractions like $\frac{1}{3}$ don't have exact representations in floating point because the format is finite.
  • Worse, even fractions like $\frac{1}{5}$ that have finite representations in decimal notation don't have one in binary notation and so are also inexactly represented.
  • The Commutative and Associative rules for basic operations like addition and multiplication are lost in some circumstances.
  • It takes special care to insure that you can accurately round-trip a in-memory value through a textual representation.
  • As a result of the above, it is very easy to write down an expression that has an equal sign in the middle on paper, but when you compute the two sides in code and compare them with == it returns false.
  • As a result of library differences in IO routines and some functions even if you get it right on one machine/compiler combination it can break if ported to a different machine/compiler combination even if they both implement the same standard!
As a result of these and other details floating-point math is notoriously hard to use correctly. The more so if you worry about unreasonable inputs (as you must).

We use floating-point math anyway because it supports values over a huge range of magnitude (for the number of bits used in the representation) and often has a fast, hardware-supported implementation. Still, sometimes, if you know the use domain well enough you can select a more limited range of necessary values and use fixed-point math to avoid some of the problems with floating-point.

Recently at work we dealt with "it's not comparing right" problems for angles on the sphere by coding azimuth and elevation in terms of a integer numbers of arc-minutes which provided more than sufficient precision for our needs, gets along nicely with the domain practice of describing angles in degrees, means that each value fits into a 16-bit field, and can be reliably round-tripped through a customer-specified text format.

Alas, many languages (most that are promoted for scientific computing) don't have bulit-in types or library support for fixed point so it isn't always practical: you have to ask how you will implement any special functions you need before you make that choice.

But it is worth asking right at the start.

2023-01-26

Unanticipated milestone

It's like a coming of age ritual, except not as fun.

There will come a time when your doctors describes your situation in reference to "a [wo]man of your age".

2023-01-07

Uhm...

I got a Kindle Scribe for Christmas. Yeah, now I hav an e-reader I can actually read papers on! Cool.

Of course, this just means I've been sucked into Amazon's ecosystem. You can only use a few formats on it, but that includes PDF. Except...

  • Annotation support on most PDFs is limited.
  • To get full annotation support you have to submit the file through "Send to Kindle"1 where I suppose it is pre-processed in some way and them made available for downloading to your machine.

Fine. I'll pretend I don't think they're spying on my content, and I'll even try to believe that they are spying responsibly. But honestly they already know a lot about me.

But that doesn't mean that there aren't any surprises here. You see, the machine has a web browser. It's not very good, but it's there. That browser won't save PDFs directly to the machine, which is a little weird, but the big oddity is that it also has no facility to route them through Send to Kindle. To somehow manage to make matters worse, the "Send to Kindle" page has a link for a "Send to Kindle" browser extension!

Seems like a no-brainer to me. Perhaps I should send them a note, but they make that weird, too.2


1 More "Send to Kindle" breakage: it will convert ebook files to a Kindle friendly format for you, but will silently drop on the floor any files already in Kindle preferred format (that perhaps, you downloaded from a DRM-free source like Standard EBooks).

2 The device supports a "Contact Us" feature, which lets you send missives into the void, but they specifically disavow any intention to hold a conversation as a result (or even just telling you what they are doing about it). There doesn't seem to be a customer facing issue tracker where you can see that your suggestion is already in progress or follow deliberations on how to handle an issue. I'm spoiled by the culture of the open-source world.

2023-01-04

This, too, will pass

For most of my politically aware life it was possible to count on the Replublicans being disciplined team-players, while you never knew when the Democrats were going to suffer a flash resurgance of the feud between the dreamy idealists, the hard-core misguided utopians, and the just trying to get something to work pragmatists.

That's not the look we've been seeing for the last decade or so, culminating in the chaos around this year's Speaker of the House election.

Of course, falling at the last hurdle on the way to his lifelong dream couldn't happen to a better guy than Mr. McCarthy, but wishes for a centrist coalition aside I worry about the alternative.