
Stargate Physics 101: A comedy about the importance of software testing - gwern
https://archiveofourown.org/works/3673335
======
jdaley
_We eventually tracked this down to some of the stabilisation algorithms –
they work fine within the intended time frames, but there 's an inefficiency
in them that gets worse the longer the wormhole is open and eventually they
can't keep up with the shifts._

An allusion to the accumulated rounding bug that caused the Patriot missile
incident in 1991? That system was likewise intended to operate for only short
periods.

From [https://autarkaw.wordpress.com/2008/06/02/round-off-
errors-a...](https://autarkaw.wordpress.com/2008/06/02/round-off-errors-and-
the-patriot-missile/)

In the Patriot missile, time was saved in a fixed point register that had a
length of 24 bits. Since the internal clock of the system is measured every
one-tenth of a second, 1/10 expressed in a 24 bit fixed point register is
0.0001100110011001100110011 (the exact value is 209715/2097152).

On the day of the mishap, the battery on the Patriot missile was left on for
100 consecutive hours, hence causing an inaccuracy of 9.5E-8x10x60x60x100=0.34
seconds.

The shift calculated in the range gate due to the error of 0.342 seconds was
calculated as 687m. The shift of larger than 137m resulted in the Scud not
being targeted and hence killing 28 Americans in the barracks of Saudi Arabia.

~~~
seiji
Nice comparison!

But, more likely, it's just a play on a reason a Stargate (when unaided by
some hostile energy source or time dilation field) just shuts off after 38
minutes with no explanation.

~~~
Someone1234
I agree that it is a play on that...

However in Stargate the actual 38 minutes thing isn't a computer limitation it
is a physical one. In the original show (i.e. SG1) Carter said it is
"impossible" due to physics for it to stay open longer, and they also
established that with enough raw power (e.g. blackhole, ancient device, etc)
it could be kept open longer or near indefinitely, it just wasn't possible
with the normal power the Stargate needs to operate.

Keep in mind they did exceed 38 minutes many times with different explanations
each time[0] none of which were computer related. It is also worth noting that
earth in the show built their own DHD which presumably would have different
computer limitations than the ancient built DHD (and as they established when
all DHDs in the universe died except theirs due to the malware).

[0]
[http://stargate.wikia.com/wiki/Stargate#Exceptions](http://stargate.wikia.com/wiki/Stargate#Exceptions)

~~~
SolarNet
> Carter said it is "impossible" due to physics for it to stay open longer

At the beginning of the story it's implied that things like that are why
Carter would be upset. Because the physics they had thought they had learned
from the stargate hardware turned out to be software limitations instead. It's
not like humans are ever capable of creating a wormhole to test for
themselves.

~~~
derefr
Later on, when Carter gives a lecture on wormhole physics at an Air Force
cadet academy, the teenage protagonist of that episode reacts in the same way,
and Carter gives an "I thought that way once, but then I saw enough compelling
evidence to change my mind about what's possible" speech.

------
Bluestrike2
That's hilarious. And damn, exploding planets sure do emphasize the sheer
random, uh, "creativity" of users. If there's a way, they'll find it. And if
there isn't, they'll make it. I wonder if Temit was an ascended being, because
surely near-omniscience is the only explanation for his ability to predict
some of the crazy things gate users would try.

Anyhow, one minor issue: the gates were thought of by a guy named Amelius the
night before they left the Alteran Home Galaxy, long before they ever reached
Earth. :)

~~~
DRMacIver
> Temit was an ascended being, because surely near-omniscience is the only
> explanation

Any sufficiently advanced QA department is indistinguishable from ascension.

> for his ability

Stop misgendering my werewolves. >:(

> Anyhow, one minor issue: the gates were thought of by a guy named Amelius
> the night before they left the Alteran Home Galaxy, long before they ever
> reached Earth. :)

Yeah, I had the timeline slightly wrong for how long it took them to get to
earth. In my defence there's no evidence of them making Stargates pre Milky
Way (he _came up_ with the idea in the Ori home galaxy but they then spent a
few thousand years looking for somewhere to settle), and we don't know how
long the Alterrans lived, so it's _just_ about plausible, but it's a bit of a
reach.

~~~
poopchute
The show Stargate Universe is set on a alterran Galaxy seeding ship. The
stargates in that show are definitely an earlier design than the milky way
ones, demonstrated by their ability to only dial other gates within a few
dozen light years instead of across the galaxy

~~~
DRMacIver
Technically they're an earlier design than the ones found in the Milky Way by
the time of the show.

But, um, honestly I hated Universe and didn't watch much of it, so it's not
very surprising that this doesn't manage to be compliant with it.

------
saurik
I read this and do not consider it to be about "the importance of software
testing"... it reads more like a demonstration of the hubris that one can fix
a fundamentally flawed system by trying to dream up test cases and then fixing
them one by one as if they were in isolation of each other. One can imagine
someone writing something like this about a sorting algorithm, slowly
discovering corner cases of large numbers, negative numbers, 2s compliment
wraparound situations, custom comparators that violate invariants, values that
are being mutated while sorting... the more of these issues you find the more
you should question that you really have defined the problem correctly, not
patting yourself on the back for having good testing.

------
nbevans
Haven't read the article in full but as a Stargate SG-1 fanatic, I can tell
you there were numerous episodes where the plot played upon the number of bugs
and design flaws in the reverse-engineered software that powered the gate on
Earth. Almost every season Dr Carter would speak of the improvements she had
made to the "dialling computer" and other such things. There was an episode
called "Time", my favourite, where they inadvertently dialled a planet next to
a black hole and the worm hole could not shut down. It was subsequently learnt
that this would never have been possible had it not been for design flaws in
the dialling computer program.

~~~
kefka
Ah. "Error code 23, extreme gravity present"

It's OK, we don't know what this error means. We'll override it.

------
kchoudhu
Each item in the list of untested edge-cases at the end corresponds to an
_excellent_ episode.

Hilarious stuff.

~~~
Tuna-Fish
What episode does the "2\. Rotating gate" refer to? I don't remember seeing
that one...

~~~
DRMacIver
About a third of them aren't from any episode, including that one.

------
david-given
It's funny because it's true. Every word.

...well, not the bits about planets exploding. I've never written code which
did that. Yet. I did once write a program which summoned demons, but never
made it work.

~~~
jamstruth
Do you work in the High Energy Magic building of the Unseen University? Giving
Hex[1] the keys to summon demons sounds like a bad idea.

[1]
[https://en.wikipedia.org/wiki/Hex_(Discworld)](https://en.wikipedia.org/wiki/Hex_\(Discworld\))

~~~
NoGravitas
Or possibly at the Laundry[0]?

[0]:
[https://en.wikipedia.org/wiki/The_Atrocity_Archives](https://en.wikipedia.org/wiki/The_Atrocity_Archives)

------
jperras
> The coordinate calculations were pretty hairy, so we just hard-coded each
> location into the Stargates for now. It shouldn't be hard to extend properly
> later.

Ha! Gold.

~~~
TeMPOraL
Yeah, this is the most plausible explanation I've ever heard of the utter
insanity of DHD design.

~~~
heavenlyhash
Some friends and I were chatting about this last night while watching the
heinous MacGuffins and Deus ex Machina moments in the final episode of
Atlantis, oddly enough, backpedalling furiously trying to come up with
alternative excuses for the coordinate system.

Our best stab was handwaving frantically and uttering something about a
Hilbert curve [1][2].

But that still doesn't really explain anything about why the ancients would
pull the equivalent of going from IPv6 to _v4_ by dropping the number of
coordinates in the Milky Way gates.... or, anything else, really.

[1] [https://en.wikipedia.org/wiki/Space-
filling_curve](https://en.wikipedia.org/wiki/Space-filling_curve) [2] a la
[https://xkcd.com/195/](https://xkcd.com/195/)

------
CharlesMerriam2
Kudos for the language section. We use strange words like "bug" and "error"
when we really mean more complex ideas. Where are the words for "flawed by
virtue of being untested", "acceptable flaw because the chain of causality is
too long in the physical world", "failure to map possible external states (as
opposed to internal states)". Language design for spoken technical language
should be a 'thing'.

------
DiabloD3
Ahh, Stargate.

Never gets old, and I wish we'd find out how Universe ends already.

~~~
hias
I hope there will be a new series someday.

Looking forward for the reboot triology of the original movie though :)

~~~
Noughmad
I just hope O'Neill will be spelled with two L's.

~~~
kchoudhu
Indeed.

(Apologies in advance for the shitpost)

------
guard-of-terra
The kind of people who design things like this tend to think about such issues
defensively, from the start.

Much of our fundamental problems with software seciruty stems from the fact
that people don't think of software as of something particularily dangerous.

~~~
DRMacIver
One would certainly hope this to be the case, but it's hard to watch SG1 and
get the impression that the ancients had much of a concept of defensive
design.

~~~
mjevans
On the contrary, my view is that the Ancients knew defensive design is a
/hard/ problem, for higher level languages. The lower level parts (like the
actual Stargates) had smart companion interfaces where the safety features
exist. The fact that you can over-ride a safety, presumably if you know what
it exists for and have a use case for ignoring it, is a good engineering
feature for a device that might be used in more extreme circumstances. (Such
as evacuating from an Ori invasion.)

------
TeMPOraL
That kind of explains the attitude of ascendent beings towards our universe:
they treat it all as one big pile of legacy code - not to touch under any
circumstances!

------
TheGuyWhoCodes
If you think about it the entire show was actually "Testing in Production"

~~~
noir_lord
That was even mentioned in some of the episodes, I vaguely recall some
scientist been horrified because they'd only decoded 97 of the over 200 error
codes/status codes.

Probably McKay.

There was a strong technical slant in that show.

EDIT:

> For instance, he knew that when Carter got the Stargate working with three
> supercomputers, they ignored 220 of the 400 feedback signals the Stargate
> can emit during any given dialing sequence.

[http://stargate.wikia.com/wiki/Meredith_Rodney_McKay](http://stargate.wikia.com/wiki/Meredith_Rodney_McKay)

I miss stargate so much.

~~~
Zardoz84
McKay becomes a really nerd genius on Atlantis... I hope that at least write
some books about what happens on Destiny before they got to sleep.

~~~
ajford
I always wondered why he suddenly becomes allergic to citrus.

In one of his first appearances on SG1, he invites Carter to the cafeteria,
mentioning that they have lemon chicken, with excitement. If I'm not mistaken,
it's not until the SGA fork that he seems to be allergic to citrus.

~~~
DRMacIver
I think you're confusing episodes. In his first appearance he mentions that
he's allergic to citrus. The "I love lemon chicken" incident comes from
Carter's visit to a parallel universe when she's experimenting with the merlin
device in a later season.

...I'm really embarrassed that I know that from memory.

------
onetimePete
Oh, Stargate- man i remember that- i got that idea for that city-traint
wriggling itself through the gate from one wormhole to another from this.
Great Inspiration.

[https://springrts.com/phpbb/download/file.php?id=9695](https://springrts.com/phpbb/download/file.php?id=9695)

Brilliant show. Strong science attitude of anything goes, if you put your mind
to it. Also actual c++ code when "Hacking" was done.

------
jerf
Half-expected the ending to be "So, anyway, we've been reassigned to this
Ascension project, because the brass want that working _yesterday_ and they've
decided to add every available engineer to speed it up."

------
yincrash
I enjoyed the part where the author implied that the asteroid belt was the
result of a stargate crashing into Tellus.

------
outworlder
> We shipped one of them off to the nearest inhabited planet in another star
> system – horrible hellhole of a place called Abydos.

That is only going to be correct if you disregard the whole "Universe" series.
Otherwise, the chronology is wrong. And can't be just about the movie,
otherwise there are no "ancients".

All in all, an excellent read. This was almost certainly written by a software
engineer, or two.

------
cowpewter
Wow, never thought I'd ever see an AoO link on HN. I usually mentally
associate that domain with slash fic.

~~~
adiabatty
It used to be on someone's blog. It got moved to AoOO for posterity, I guess.

------
tnecniv
He forgot the part about how you get cold when you go through the stargate...

I need to watch this show again.

~~~
ajford
They resolve this in the show. Carter mentions the rough ride and cold was due
to their home-grown dialing program and instabilities in the wormhole. Further
tweaks result in the improved travel comfort.

