Space habitats more expensive than terraforming Mars? You're having to import large quantities of volatiles in either case, Mars needs more imported per person supported (since you'll be using lots of them in the upper atmosphere where they only provide radiation shielding and pressure, instead of smaller quantities to directly support biologically active processes), Mars outgasses the hydrogen you import thanks to photodisassociation of water molecules, and Mars has half the available solar power of a 1 AU orbit (and while you can possibly power a habitat with nuclear power, good luck using anything but solar for a terraforming project).
Now, if you're dealing with habitats, yes, Mars gives you the advantage that by reasonably good placement you can have all the CHONSP you need for your habitat right at your doorstep, and an atmosphere that unmodified already shields reasonable amounts of radiation on its own, et cetera. Mars habitats will be cheaper than orbitals (or sealed habitats anywhere but Earth). But you were talking terraforming. Orbitals vastly outperform terraforming Mars in cost effectiveness per person supported (and Mars outperforms any other solar system body other than Earth).
Now, fragility. Yes, orbitals are relatively fragile. But they are also more numerous. If an orbital faces an independent one-in-a-hundred chance of a local catastrophic total failure leading to death of all inhabitants in a decade, and Earth faces a one-in-a-trillion chance of a local catastrophic total failure leading to death of all inhabitants in a decade, then ten orbitals are a hundred million times less fragile collectively than Earth despite being ten billion times more fragile individually. When you consider the raw number of orbitals you can make for the cost of terraforming Mars, orbitals as a group vastly outclass terraforming Mars in their ability to avoid existential risk, over all classes of risk where a terraformed Mars would actually reduce existential risk.
Space habitats more expensive than terraforming Mars?
No, more expensive than Mars habitats, for the reasons you mentioned. When I said "and easier to terraform," I meant that as a bonus, not as a requirement. Closed habitats seem like a reasonable norm for small societies in hostile conditions.
independent one-in-a-hundred chance
Sure; but there must also be dependent chances (like gamma ray bursts or ubiquitous design faults or so on). It seems difficult to have the baseline dependent fragility of orbital habitats at lower than the baselin...
Can anyone recommend some resources, or provide actual examples, of any relevant evolutionary-biology-style equations which could describe what factors would most likely predominate to allow for the survival of sapience, given such factors as the ease which any given individual can acquire the means of killing large numbers of people, the scale of those means, the willingness o people to use those means, the ability of small groups to travel away from other groups, and so on?
Or, put another way - is there any way I can quantitatively check my intuition that a valuable way to avoid certain existential risks is to flee Earth?