Approximate Metric Units by Graham Nelson

Extension built in to Inform


(Note: This extension uses integer arithmetic for its calculations, which was the best that could be done until June 2012. The new version of "Metric Units" uses floating-point calculations and is much more accurate, though it only works on versions of the Glulx virtual machine dating from 2011. This is a renamed copy of the old "Metric Units", and is preserved in case people need it to keep older works running.)

The metric system provides a consistent set of units for scientific measurement of the world. Though often associated with the French Revolution or with Napoleon, the system of metric units only really began to displace existing units in May 1875, when it was made official by an international treaty. In 1960, it was renamed the "Système international d'unités", which is usually abbreviated "SI".

This extension is a kit for writers who want to make realistic simulations, backed up by some quantitative physics. It defines kinds of values for the 25 or so SI units in common usage, and more than 100 notations for them. It also makes sure they multiply correctly. For instance, a mass times an acceleration produces a force, so

say "You feel a force of [2kg times 5 m/ss]."

will produce the text "You feel a force of 10N." The easiest way to see how all these units combine is to run one of the examples below and look at the Kinds index which results.

For each unit, both names and notations are allowed. Thus '2 kilograms' is equivalent to '2kg'. Both English and French spellings of 'meter'/'metre' and 'liter'/'litre' are allowed, but we insist on 'gram' not 'gramme' and 'tonne' not 'ton'. ('Ton' is too easily confused with the Imperial measure, which is not quite the same.) We can print back the same value in a variety of ways. For instance:

say "[m0 in metric units]";
say "[m0 in kg]";
say "[m0 in g]";
say "[m0 in kilograms]";

might produce: '2.04kg', '2.04kg', '2040g', '2.04 kilograms'. The text expansion '... in metric units' prints any value of any of these units in its most natural notation: 2.04kg is thought to be better than 2040g, but 981g would be better than 0.981kg. Or in the case of our variant spellings:

say "[C in metric units]";
say "[C in milliliters]";
say "[C in millilitres]";

might produce '47 ml', '47 milliliters', '47 millilitres'. It's also worth remembering that any value can be rounded:

say "[C to the nearest 5 ml]";

would produce '45 ml', for instance.

For detailed notes on each of the units, consult the Kinds index for any project using this extension.

There are three main restrictions. First, Inform can only represent numbers within a certain range. Each kind of value is set up on the assumption that writers will want it to model human-scale situations - length, for instance, varies from 1mm, the smallest conscious movement a human can make, up to 2150km or so, the length of a continent-spanning footpath. 'Approximate Metric Units' is an extension to help with real-world physics questions like how long a plate dropped off the roof takes to hit the ground, or when a rope will break, or how long a saucepan of water will take to boil. It won't be much use for celestial events like lightning strikes, where enormous energies are released for fleeting periods of time, or for tiny subatomic events.

Secondly, calculations are done with fixed-point arithmetic and will inevitably involve small rounding errors. Working out the same quantity by two different methods, which ought to have the same result according to physics, will often produce slightly different answers because these errors accumulate differently. 'Approximate Metric Units' aspires to help the writer to get physical answers which are about right, not to be a precision tool.

Thirdly, we haven't included every SI unit. There are hundreds of kinds of value which turn up in physics, and we only include the commonest 25 or so. The missing ones which have named SI units are:

solid angle (measured in steradians), luminous flux (lux), electric capacitance (Farads), electric resistance (Ohms), electric conductance (Siemens), magnetic flux (Webers), magnetic field (Teslas), inductance (Henries), radioactivity (Becquerels), absorbed radioactive dose (Grays), equivalent radioactive dose (Sieverts), chemical quantity (mole), catalytic activity (katals).

As can be seen, we've missed out units for chemistry, electromagnetic effects beyond the basic ones, and radioactivity. It would be easy to add any of these which might be needed:

Electric resistance is a kind of value.

1 Ohm (in metric units, in Ohms, singular) or 2 Ohms (in metric units, in Ohms, plural) specifies an electric resistance scaled at 1000.

Electric resistance times electric current specifies a voltage.

Similarly, there are many kinds of value which don't have named SI units, but where physicists write them down as compounds. These are also easy to add as needed:

Angular momentum is a kind of value.

1 Nms specifies an angular momentum scaled at 1000.

Momentum times length specifies an angular momentum.

Besides angular momentum, 'Approximate Metric Units' also leaves out:

volumetric flow (cu m/s), jerk (m/sss), snap (m/ssss), angular velocity (rad/s, though Inform would probably use degrees/s), torque (Nm), wavenumber (1/m), specific volume (cu m/kg), molar volume (cu m/mole), molar heat capacity (J/K/mol), molar energy (J/mol), specific energy (J/kg), energy density (J/cu m), surface tension (J/sq m), thermal conductivity (W/m/C), viscosity (sq m/s), conductivity (S/m), permittivity (F/m), permeability (H/m), electric field strength (V/m), magnetic field strength (A/m), resistivity (Ohm metre).

This extension is pretty faithful to SI conventions. It chooses degrees rather than radians for angle, and centigrade rather than Kelvin for temperature, because these are more useful for humans and easier to represent in text. But otherwise it's strictly metric, and does not define Imperial measures. See the example below for how to add these.

Example: ** Galileo, Galileo - Dropping a cannonball or a feather from a variety of heights.

This experiment was first proposed in Pisa in the 1630s, but more definitively carried out by the crew of Apollo 15 in 1971, using a geological hammer and the feather of a falcon. Galileo's point was that heavy objects and light objects fall at the same speed because of gravity, and that only air resistance makes us think feathers fall more slowly than cannonballs. (Of course, heavy objects do land harder; the hammer kicked up a lot more lunar dust than the feather did.)

"Galileo, Galileo"

Include Approximate Metric Units by Graham Nelson.

The acceleration due to gravity is an acceleration that varies.

Laboratory is a room. "An elegant Pisan room, with fine Renaissance panels, except for the teleport corridor to the east." A cannon ball and a feather are in the Laboratory.

Martian Outpost is east of the Laboratory. "A reddish-lit room with steel walls, whose only exit is the teleport corridor to west."

A room has an acceleration called gravitational field. The gravitational field of a room is usually 9.807 m/ss. The gravitational field of the Martian Outpost is 3.69 m/ss.

A thing has a mass. The mass of a thing is usually 10g. The mass of the cannon ball is 2kg.

Dropping it from is an action applying to one thing and one length.

Understand "drop [thing] from [length]" as dropping it from.

Check dropping it from:
     if the player is not holding the noun:
         say "You would need to be holding that first." instead.

Check dropping it from:
     if the length understood is greater than 3m:
         say "Just how tall are you, exactly?" instead.

Check dropping it from:
     if the length understood is 0m:
         try dropping the noun instead.

Equation - Newton's Second Law
         F=ma
where F is a force, m is a mass, a is an acceleration.

Equation - Principle of Conservation of Energy
         mgh = mv^2/2
where m is a mass, h is a length, v is a velocity, and g is the acceleration due to gravity.

Equation - Galilean Equation for a Falling Body
         v = gt
where g is the acceleration due to gravity, v is a velocity, and t is an elapsed time.

Carry out dropping something (called the falling body) from:
     now the acceleration due to gravity is the gravitational field of the location;
     let m be the mass of the falling body;
     let h be the length understood;
     let F be given by Newton's Second Law where a is the acceleration due to gravity;
     say "You let go [the falling body] from a height of [the length understood], and, subject to a downward force of [F], it falls. ";
     now the noun is in the location;
     let v be given by the Principle of Conservation of Energy;
     let t be given by the Galilean Equation for a Falling Body;
     let KE be given by KE = mv^2/2 where KE is an energy;
     say "[t to the nearest 0.01s] later, this mass of [m] hits the floor at [v] with a kinetic energy of [KE].";
     if the KE is greater than 50J:
         say "[line break]This is not doing either the floor or your ears any favours."

Test me with "get ball / drop it from 1m / get ball / drop it from 2m / get ball / drop it from 3m / get ball / drop it from 3.2m / get ball / drop it from 0m / get all / east / drop ball from 3m / drop feather from 3m".

Note the way Inform is able to solve the conservation equation, which says the potential energy at the start equals the kinetic energy at the end, to find the velocity v: this involves taking a square root, but it all happens automatically. Square roots tend to cause rounding errors - so on Mars the cannon ball and feather actually land 0.02s apart, in the calculation above, despite Galileo. But no human observer would notice that discrepancy.

Example: ** The Empire Strikes Back - Using good old Imperial measures of length and area alongside these Frenchified metric ones.

Imperial measures, often going back to obscure customs in Anglo-Saxon England, were inflicted across much of the world in the heyday of the British Empire. Some are still very much alive in England and its former colonies (Australia, India, New Zealand, Canada, Ireland, the USA and so on) - miles and feet, for instance. Others continue only in unscientific social customs, like sport: horse-races are measured in furlongs; the running distance between the two wickets of a cricket pitch is 22 yards, which is 1 chain exactly; and even in France, a football goal must be 8 feet high and 8 yards wide.

"The Empire Strikes Back"

Include Approximate Metric Units by Graham Nelson.

Steeple Aston Cricket Pitch is a room.

1 inch (in imperial units, in inches, singular) or 2 inches (in imperial units, in inches, plural) specifies a length equivalent to 2.5cm.
1 foot (in imperial units, in feet, singular) or 2 feet (in imperial units, in feet, plural) specifies a length equivalent to 12 inches.
1 yard (in imperial units, in yards, singular) or 2 yards (in imperial units, in yards, plural) specifies a length equivalent to 3 feet.
1 chain (in imperial units, in chains, singular) or 2 chains (in imperial units, in chains, plural) specifies a length equivalent to 22 yards.
1 furlong (in imperial units, in furlongs, singular) or 2 furlongs (in imperial units, in furlongs, plural) specifies a length equivalent to 10 chains.
1 mile (in imperial units, in miles, singular) or 2 miles (in imperial units, in miles, plural) specifies a length equivalent to 8 furlongs.
1 league (in imperial units, in leagues, singular) or 2 leagues (in imperial units, in leagues, plural) specifies a length equivalent to 3 miles.

1 square foot (in imperial units, in square feet, singular) or 2 square feet (in imperial units, in square feet, plural) specifies an area equivalent to 900 sq cm.
1 square yard (in imperial units, in square yards, singular) or 2 square yards (in imperial units, in square yards, plural) specifies an area equivalent to 9 square feet.
1 acre (in imperial units, in acres, singular) or 2 acres (in imperial units, in acres, plural) specifies an area equivalent to 4840 square yards.

Understand "convert [a length]" as converting. Converting is an action applying to one length.

Carry out converting:
     let A be the length understood;
     say "Measuring A = [A], which ";
     say "= [A in millimetres] ";
     say "= [A in centimetres] ";
     say "= [A in metres] ";
     say "= [A in kilometres] ";
     say "= [A in inches] ";
     say "= [A in feet] ";
     say "= [A in yards] ";
     say "= [A in chains] ";
     say "= [A in furlongs] ";
     say "= [A in miles] ";
     say "= [A in leagues].";
     say "Metric: [A in metric units].";
     say "Imperial: [A in Imperial units].[paragraph break]";

Test me with "convert 1.2m / convert 2m / convert 30cm / convert 20 chains".

The above conversions are based on 1 inch equals 2.5cm, which is not very accurate: 2.54cm would be closer. But to get that accuracy we would need to represent lengths down to 0.4mm, which is below the 1mm cutoff imposed by 'Metric Units'. We'll accept this 2% error in lengths (or 4% error in areas) as harmless, given that we're not going to be doing any serious calculations in Imperial units; if we were, we'd do better to make a fresh extension for them.

Confusions still cause spectacular failures, as when an Air Canada ground crew mixed up pounds and kilograms and fuelled a Boeing 767 so lightly in 1983 that it ran dry at 41,000 feet, losing all engines, avionics and electricity. The captain, by great good luck also an amateur glider pilot, made a now-legendary landing at an obscure airstrip which the first officer by great good luck had once flown from. The USA's Mars Climate Orbiter spacecraft, whose navigation software confused pounds and newtons, was not so lucky and burned up in the Martian atmosphere in 1998 at a cost of $330 million.