We propose to extend the Method plugin's calculation with measurement unit tracking, checking, formatting and some implicit conversions. Unit nomenclature and allowed conversions will be written explicitly on nearby pages. See Method Unit Coding

### Unit Labels

We've already seen units appear in labels as a convenience. We will systematize these conventions as our primary interface.

166 Recovered Area (Acres) 32.67 Annual Consumption (Metric Tons) 0.02 Consumption (Tonne / Year / Person)

We will interpret the contents of parentheses as units. However, our interpretation will depend on a series of conventions applied quite literally.

Unit names may be singular or plural, but not both interchangeably. That is **Acre** and **Acres** are different.

Unit names must be identical if they are to name the same unit. That is **foot**, **Foot** and **Feet** are three different units.

Unit names won't contain spaces if they name an individual unit. Thus metric tons must be spelt **MetricTons**

Unit names combine when measurements involve multiple scales. The combination is independent of the order. That is **Foot Pound** and **Pound Foot** are the same internally.

Unit names for ratios may be composed of a numerator and denominator represented by a single slash. Units to the right of the slash are all in the denominator. That is tonne per year per person would be **Tonne / Year Person**.

### Sums

When conversion factors have been provided they can be applied automatically to sum measurements in different units.

12 (inches) per (feet)

A running sum will be in the units last used. A measurement without units will sum as the prevailing unit.

5 Coarse Height (feet) 6 And Then Some (inches) SUM Actual Height

*when implemented, sum of 66 expected*

When the preferred unit of a result is specified then provided conversion factors will be applied.

5 Coarse Height (feet) 6 And Then Some (inches) SUM Actual Height (feet)

*when implemented, sum of 5.5 expected*

When units are specified they will be checked and conversions applied if available.

When units aren't specified they will be inferred and visible by hovering over the result.

When units aren't specified for SHOW they will be inferred and added to the visible caption on a line by itself.

### Products

Multiplying numbers yields quantities with composed units. For example, height x width in inches yields area in square inches.

12 Height (Inches) 24 Width (Inches) PRODUCT Area (Inches Inches)

We anticipate the use of superscript powers as an output formatting embellishment. Area would report as (Inches²). This could be reported in (Feet²) given appropriate conversions. The unit (Feet²) is written in input as (Feet Feet) and stored as such internally.

Alternatively, the Google calculator is happy to report inches x inches as inches squared or square inches.

### Ratios

First observe that numbers may come directly from a measurement or be the result of comparing two measurements as a ratio.

150 Distance Traveled (Miles) 2.5 Elapsed Time (Hours) RATIO Average Speed (Miles / Hours)

While we might find it convenient to name ratios, it doesn't make sense to sum them.

18.7 City Traffic (MPG) 23.5 Open Road (MPG) SUM Total Fuel Efficency

*not a reasonable computation, prefer weighted average*

A product of ratios will yield unit numerators and denominators composed independently.

A ratio of ratios will yield unit numerators and denominators composed independently after units of the divisor have been inverted.

Like units in the numerator and denominator will be canceled.

A ratio can yield a unit-less quantity which is not the same as a quantity for which units have not been specified. The two have different default behavior in sums.

### Conversions

Conversion factors specified quantities of a destination unit that comes from each 1.0 of a source unit. Conversions are recognized by two sets of parenthesis.

12 (Inches) from (Feet) 144 (Square Inches) from (Square Feet) 1728 (Cubic Inches) from (Cubic Feet)

Conversions may assume additional physical properties such as what is being measured and/or converted. These appear outside the parenthesis. Additional assumptions are not checked but can be viewed by hovering over converted quantities.

7.48052 (Gallons) from (Cubic Feet) Water 8.34 (Pounds) from (Gallons) Water 0.44548 (kg) CO2 from (kW Hr) Grid Electricity

See Conversion factors from the Carbon Trust. pdf

Some conversion factors may need explanation that exceeds that possible in the label. Consider the example of these historic exchange rates averaged over the month of June, 2000. source

106.1092 Japanese (Yen) from US (Dollars) 1.5084 US (Dollars) from GB (Pounds)

Only one conversion will be applied at a time. One must have the source units and want the destination units for a forward conversion (multiply) or the exact opposite for a reverse conversion (divide).

Consider an 8 x 10 foot holding tank filled to 9 inches with water. We can compute the water's weight using conversions above.

8 Wide (Feet) 10 Long (Feet) PRODUCT (Square Inches) 9 Deep (Inches) PRODUCT (Cubic Feet) SUM (Gallons) SUM (Pounds)

*not yet implemented, expected 60 cubic feet, 448 gallons, 3745 pounds.*

We switch from feet to inches and back and then from gallons to pounds to match the available conversions.

Implicit conversions are retrieved based on source and destination units alone. Should there be multiple conversions that might apply, the closest conversion will be chosen.

Conversion factors can be explicitly applied by recalling exactly the factor desired and applying it with PRODUCT.

2400 Annual per Capita Lighting (kW Hr) (kg) CO2 from (kW Hr) Grid Electricity PRODUCT Annual CO2 per Capita Lighting (kg)

Conversions are themselves ratios that have been labeled such that they are clearly intended for implicit application. A ratio and its inverse are equivalent conversions.

88 (Feet / Seconds) 60 (Miles / Hours) RATIO (Feet / Seconds) from (Miles / Hours)

60 (Miles / Hours) 88 (Feet / Seconds) RATIO (Miles / Hours) from (Feet / Seconds)

### Errors

It is an error to convert a result with units to other units for which there is not a direct conversion factor.

It is not an error to convert a result without units to any units desired. (But this conversion simply asserts the units of the current result.)

It is an error to sum quantities that cannot be converted to the prevailing unit

It is an error to sum quantities that are ratios (have a unit denominator.) A ratio who's units have canceled is still considered to have a denominator.

It is not an error to multiply quantities that cannot be converted to the prevailing unit. (However, this may lead to unwanted units that won't convert later.)

It is not yet possible to convert Centigrade to Fahrenheit with this conversion mechanism.

One can check that variables are being defined with the expected units by setting "debug" to non-zero. Refresh whole pages to see debug output.

0 debug

### Representation

A feature of this scheme is that it almost works with no more representation than that squeezed into value labels themselves. However, there are a few additional needs that will drive us to attach units directly to values.

We need for units to travel with values even when the values leave their labeled locations. We have asValue() to extract a number from a more complex value.

We need to know if units given in labels have been interpreted and how they have been interpreted if there is any ambiguity.

We need to know what units have been assumed when units have not been provided.

We need a normalized and easily interpreted form for units that is independent of any formatting fashion, say between square inches, inches squared and inches^{2}.

A value with units will be represented by an object that we will informally call a measurement.

value = number | measure measure = { value: number, units: terms | ratio } ratio = { units: terms, per: terms } terms = [ words ]

Terms are alphabetized arrays of single unit names. Square feet would be [ "Feet", "Feet" ].

A measurement has units which may be terms or a ratio of terms. When units cancel a denominator may become empty but it won't revert from a ratio.

A conversion factors are measurements that add source units in a from field, *from: terms | ratio*.

{ "value": 144, "units": [ "Inches", "Inches" ], "from": [ "Feet", "Feet" ] }