# raku-Physics-Measure

Provides Measure objects that have value, units and error(tbd) and can be used in common physics calculations. Uses raku Physics::Unit.

# Instructions

`zef --verbose install https://github.com/p6steve/raku-Physics-Measure.git`

and, conversely, `zef uninstall Physics::Measure`

# Synopsis

This example shows some key features of Physics::Measure...

- support for SI prefixes, base and derived units (cm, kg, ml and so on)
- imported as raku postfix operators for convenience and clarity
- custom math operators
`(+-*/)`

for easy inclusion in calculations - inference of type class (Length, Time, Mass, etc.) from units
- derivation of type class of results (Speed, Acceleration, etc.)

# Use Cases

The Physics::Measure and Physics::Unit modules were designed with the following use cases in mind:

- convenient use for practical science - lab calculations and interactive presentation of data sets
- a framework for educators and students to interactively explore basic physics via a modern OO language
- an everyday unit conversion and calculation tool (not much point if it can't convert miles to km and so on)

Some other use cases - use for physical chemistry calculations (eg. environmental) and for historic data ingestion - have also been seen on the horizon and the author would be happy to work with you to help adapt to meet a wider set of needs.

# Design Model

To address the Use Cases, the following consistent functional parts have been created:

- a raku Class and Object model to represent Units and Measurements
- methods for Measure math operations, output, comparison, conversion, normalisation and rebasing
- a Unit Grammar to parse unit expressions and cope with textual variants such as ‘miles per hour’ or ‘mph’, or ‘m/s’, ‘ms^-1’, ‘m.s-1’
- an extensible library of about 800 built in unit types covering SI base, derived, US and imperial
- a set of "API" options to meet a variety of consumption needs

Together Physics::Measure and Physics::Unit follow this high level class design model:

Type classes represent physical measurement such as (Length), (Time), (Speed), etc. They are child classes of the (Measure) parent class.

You can do math operations on (Measure) objects - (Length) can add/subtract to (Length), (Time) can add/subtract to (Time), and so on. A mismatch like adding a (Length) to a (Time) gives a raku Type error *cannot convert in to different type Length*. You can, however, divide e.g. (Length) by (Time) and then get a (Speed) type back. (Length) ** 2 => (Area). (Length) ** 3 => (Volume). And so on. There are 36 pre-defined types provided. Methods are provided to create custom units and types.

Therefore, in the normal course, please make your objects as instances of the Child type classes.

# Three Consumer Options

## Option 1: Postfix Operator Syntax (SI Units)

As seen above, if you just want SI prefixes, base and derived units (cm, kg, ml and so on), the :ALL export label provides them as raku postfix:<> custom operators. This option is intended for scientist / coders who want fast and concise access to a modern Unit library. Here is another example, basic wave mechanics, bringing in the Physics::Constants module:

The following SI units are provided in all Prefix-Unit combinations:

SI Base Unit (7) | SI Derived Unit (20) | SI Prefix (20) |
---|---|---|

'm', 'metre', | 'Hz', 'hertz', | 'da', 'deka', |

'g', 'gram', | 'N', 'newton', | 'h', 'hecto', |

's', 'second', | 'Pa', 'pascal', | 'k', 'kilo', |

'A', 'amp', | 'J', 'joule', | 'M', 'mega', |

'K', 'kelvin', | 'W', 'watt', | 'G', 'giga', |

'mol', 'mol', | 'C', 'coulomb', | 'T', 'tera', |

'cd', 'candela', | 'V', 'volt', | 'P', 'peta', |

'F', 'farad', | 'E', 'exa', | |

'Ω', 'ohm', | 'Z', 'zetta', | |

'S', 'siemens', | 'Y', 'yotta', | |

'Wb', 'weber', | 'd', 'deci', | |

'T', 'tesla', | 'c', 'centi', | |

'H', 'henry', | 'm', 'milli', | |

'lm', 'lumen', | 'μ', 'micro', | |

'lx', 'lux', | 'n', 'nano', | |

'Bq', 'becquerel', | 'p', 'pico', | |

'Gy', 'gray', | 'f', 'femto', | |

'Sv', 'sievert', | 'a', 'atto', | |

'kat', 'katal', | 'z', 'zepto', | |

'l', 'litre', | 'y', 'yocto', |

#litre included due to common use of ml, dl, etc.

## Option 2: Object Constructor Syntax

In addition to the SI units listed above, Physics::Measure (and Physics::Unit) offers a comprehensive library of non-metric units. US units and Imperial units include feet, miles, knots, hours, chains, tons and over 200 more. The non-metric units are not exposed as postfix operators.

A flexible unit expression parser is included to cope with textual variants such as ‘miles per hour’ or ‘mph’; or ‘m/s’, ‘ms^-1’, ‘m.s-1’ (the SI derived unit representation) or ‘m⋅s⁻¹’ (the SI recommended string representation, with superscript powers). The unit expression parser decodes a valid unit string into its roots, extracting unit dimensions and inferring the appropriate type.

Of course, the standard raku object constructor syntax may be used for SI units too:

This syntax option is the most structured and raku native. For example, it helps educators to use units and basic physics exercises as a way to introduce students to formal raku Object Orientation principles.

## Option 3: Libra Shorthand Syntax

In many cases, coders will want the flexibility of the unit expression parser and the wider range of non-metric units but they also want a concise notation. In this case, the unicode libra emoji ♎️ is provided as shorthand for object construction:

*Use the emoji editor provided on your system (or just cut and paste)*

# Special Measure Types

## Angles

## Time

# Unit Conversion

# Rounding & Normalisation

# Comparison Methods

# Output Methods

To see what you have got, then go:

# Custom Measures

To make a custom Measure, you can use this incantation:

# Summary

The family of Physics::Measure, Physics::Unit and Physics::Constants raku modules is a consistent and extensible toolkit intended for science and education. It provides a comprehensive library of both metric (SI) and non-metric units, it is built on a Type Object foundation, it has a unit expression Grammar and implements math, conversion and comparison methods.

Any feedback is welcome to p6steve / via the github Issues above.