I like magic with rules. I like fantasy stories in which magic isn't "magic"- it's just the way the world works, part of physics that just happens to be different from ours. As a programmer myself, I'm also fond of fantasy stories with computers in them- things like The Silicon Mage and parts of the Castle Perilous books. The astute reader may recognize the title as a play on Structure and Interpretation of Computer Programs. And I'm certainly not the first to invent a magic system based on computer programming, but I think I've got a pretty fun personal take on the concept.
Several years ago, Eliezer Yudkowsky published a short story called Initiation Ceremony, a followup to the essay "To Spread Science, Keep it Secret"; the central idea here is that people like knowing secrets and being part of conspiracies- so if we want to increase scientific literacy and respect for science, maybe the best route would actually be to keep it secret! Or, put on a show of doing so, at least.
That got me thinking- what if there was a real practical reason why some particular science had to be kept secret?
Maybe the universe itself is programmable, and that fact needs to be hidden from malicious hackers (not terribly unique yet).
Maybe the universe is programmable, and it's ridiculously easy to do, if you know the trick. So easy that literally anybody can access the super-user interface with 5 minutes instruction to tell them how; but if you don't know what you're doing, an improperly educated person could accidentally destroy the world....
That's something worth keeping as a very carefully controlled secret. Plausibly, that would be very difficult to do indefinitely. So perhaps we're looking at a world that has undergone multiple cycles of civilization and destruction, whenever the secret gets into the wrong hands.
So, how does the programming interface work? Why, by giving instructions to demons of course! Humans acquiring magical powers by making deals with supernatural creatures- demons, angels, or what-have-you- is an old and respectable fantasy trope; we just need to set up some rules that make it more like computer programming, and less like Dr. Faustus. If demons are really good at following directions, but natively really stupid, like computers....
In more detail: Presume that the universe is animist, down to the very lowest levels. Basically, it works like our world, but the thing that "breathes fire into the equations and makes a universe for them to describe" is that every particle is actually an animist intelligence which has been instructed in the rules of physics that it is meant to follow (by whom!?). Additional intelligences exercise hierarchical control over various higher levels of organization- most notably, there's a primordial intelligence, or spirit, behind every living organism, including every human, and a lot of inanimate objects too, a fact which would be objectively, scientifically verifiable to a properly-trained thaumatologist. If you could talk to the intelligence behind an electron, or anything else, and tell it to behave differently, it would, just like you can talk to a person and convince them to do things- but how do you talk to an electron? You need some kind of intermediary, someone or something that can communicate directly with the fundamental intelligences of the animist world, but which can also understand you, the magician.
Now we get into some theology- an empirical science in this world, even if not everyone believes in precisely the same religion! Clearly, someone had to give the electrons and such their initial instructions; the world was formed out of a chaos of primordial intelligences at all levels of advancement by a Creator, who picked the simplest intelligences for the jobs of being fundamental particles, and also instructed them to obey certain kinds of commands under certain circumstances from more advanced intelligences, thus providing a mechanism for the intelligences selected to serve as human spirits (and those of other animals) to exercise free will over their bodies. This implies two things: first, that even really simple primordial intelligences must be aware of each other and capable of communicating with each other, and also capable of solving fairly complicated mathematical problems extremely rapidly; and second, that, given the finite number of animals in the world, that there is still an infinite number of advanced intelligences left in the primordial chaos outside the world.
Some of that infinite sea of left-out intelligences would probably like very much to have the chance to interact with Creation.
Since there is a Creator who told the world how to work in the first place, miracles are easily performed if that Creator just decides to give some updated instructions every once in a while; or, alternatively to instruct the animist world to understand and obey commands from certain delegated servants- priests of the one true religion. That's one kind of "magic" that would exist in this world, but so far it just looks like a monotheistic religion in a world indistinguishable from our own. In order to turn "magic" into a reproducible, objective science, we presume that, having set up humans as lords over his Creation, this Creator has also given every human the authority to allow additional intelligences from the infinite chaos permission to interact with the world, and give them delegated authority over some material domain to serve as their "body".
The only requirements are that a human
a) be "sane" (another fiddly concept which would suddenly have an objective, verifiable test in this world!)
b) genuinely want such an intelligence to enter the world.
c) genuinely believe that it will work
That gets you the most basic, simplest possible "magic spell"- the equivalent of "uum" from Sam Hughes's serial novel Ra, a spell that "works" but does nothing, as no instructions are provided to the summoned intelligence.
Once you add the intention that the summoned intelligence have permission to interact with the material world in any way, however, that's when things get dangerous! Before you meet them (and remember, they exist in the infinite chaos outside the world- where are you going to get the chance?), there's no way to select a specific intelligence to summon; whichever random one you get might be fairly smart, or insufferably stupid; and it might be naturally benevolent, or excessively malevolent, or simply ignorant- a state often indistinguishable for malevolence! If your instructions are either impossible to carry out, or insufficiently precise, you might get lucky with having summoned an "angel"- a benevolent, reasonably smart intelligence- but much more likely, the results will be some level of disastrous. Hence, the common name for summoned intelligences: Demons. It's just safer to assume that they're all dangerous and malevolent, and make sure you know how to control them properly.
The requirements for doing magic- believe that it will work, and wish for a demon to show up with a particular set of instructions- are so simple that they could be easily rediscovered by just about anyone with a sufficiently open mind. "Fortunately", much like the sparks from Girl Genius, most people who independently rediscover demon summoning without proper training are likely to accidentally kill themselves, or at least get scared off it, well before they can do any large-scale damage. But, to really maintain a stable society would require a massive over-arching conspiracy and disinformation campaign about the true nature of magic, such that people do not actually believe that they are capable of it, rather like the situation in Shin Sekai Yori, where all humans possess powerful telekinesis.
And, if initiates to the conspiracy want to be able to actually use magic at all safely, it would be necessary for them to develop something very like our computer science, in order to ensure that they can provide absolutely precise instructions to obviate any possible differences in the personality or intelligence level of any summoned demon, and ensure that they will all behave precisely the same, predictably and reproducibly- and safely- for any given spell.
If demons can be used to re-instruct any matter arbitrarily, as the Creator of the World could do, that's a little over-powered- not to mention difficult for humans to practically figure out how to use. Magic systems are made interesting not so much by what they can do, but what they can't do- and how characters manage to exercise their creativity to get around those restrictions anyway.
First, the low-level limitations: demons can produce effects equivalent to applying arbitrary forces, or manipulating statistical outcomes, but they are not permitted to violate certain fundamental invariants of the universe, such as:
- No effects that would violate conservation of energy or momentum.
- No transmission of information faster than light.
- No exact cloning of quantum information.
Additionally, the source of magic (essentially, delegation of creative power to humans by divine fiat) suggests a few other higher-level rules:
- A demon cannot directly alter any part of a human's body without explicit consent of that human.
- A demon acting on its own cannot intentionally kill a human.
A Specific Magical Society
Under this framework, there are still all kinds of different societies that could develop. That's part of what makes for an interesting world, in which all kinds of different stories could be told about different people in different places. Here's one that I find interesting:
As previously noted, this world has probably gone through several catastrophes, where some rogue magician has had the power to "destroy the world". The last disaster left behind a slew of magical artifacts from the previous civilization- things which, on a purely physical level, are unremarkable, but which have demons attached to them running complicated "software" and just waiting around for someone to activate the programmed user interface appropriately. These provide for a rich source of ad-hoc folk magic beliefs, given that they don't behave according to any necessary logical rules- merely according to the whim of the ancient magician who created them, and whatever they thought "made sense". They would also be intriguing objects of study for specialists in reverse-engineering, attempting to use the ancient objects to advance the state of modern thaumatology.
The conspiracy and practice of magic is controlled by a Guild of Magicians, who do not publicly reveal the source of magical power, but are very clear on the fact that it's extremely difficult to explain or make use of, certainly not something that just anybody can do, although they are happy to welcome anyone willing to go through the necessary many years of preliminary training. In order to create a supply of adepts who are appropriately trained in the mental discipline of composing precise and unambiguous instructions, they accredit and control Colleges of Thaumaturgy in universities through the country, one of whose departments is of course Algorithmics- of which the basic reference work is, of course, The Structure and Interpretation of Demonic Incantations. Demons, of course, are purely theoretical constructs- oracles that one may assume have no real intelligence but will follow any instructions given them quickly and precisely, and whose operation can be approximated by certain useful algorithmic devices studied in the College of Engineering. Unlike most CS programs in our world, however, courses in Algorithmics would focus heavily on formal provability of incantation (program) correctness and security.
An accredited degree in algorithmics, plus some study of physics, qualify a student to apply for entrance to the Guild, to assist a practical magician. Those who prove sufficiently skilled and trustworthy are eventually advanced to the rank of Licensed Magician via a private initiation ceremony in which the secret is revealed- that demons are real, and your incantations will become effective (i.e., your programs will run) if you believe it, and wish it. After that point, they may begin to work as practical magicians in some field of engineering, or as academic researchers.
Occasionally, of course- every couple of years or so- someone rediscovers the secret anew anyway, or some disgruntled magician really does leak it to their friends despite their extensive training, and a little bit of havoc ensues. When that happens, the Guild must spring into action to effect containment of the disaster, and construct a cover story about how the secret of magic was leaked, and reiterating to the public just how dangerous it is outside of the hands of the Guild, and only the Guild.
Of course, there are other countries in the world, not all of which are under control of the Guild of Magicians, but that's no worry- all of the ones that still exist clearly have their own effective means of keeping the secret under control, and if they don't tip off their own citizens, they certainly won't tip off ours....