# The physical-quantities Reference Manual

Next: , Previous: , Up: (dir)   [Contents][Index]

# The physical-quantities Reference Manual

This is the physical-quantities Reference Manual, version 0.1, generated automatically by Declt version 3.0 "Montgomery Scott" on Fri Jun 26 11:57:31 2020 GMT+0.

Next: , Previous: , Up: Top   [Contents][Index]

# Physical Quantities

This lisp library handles physical quantities which consist of

• Value/Magnitude
• Uncertainty/Error
• Unit

where the type of the value can be any subtype of `real`. For the uncertainty, both absolute and relative values are possible. Combinations of lisp symbols or strings are used to describe units. User defined units including abbreviations and prefixes are supported. Error propagation and unit checking is performed for all defined operations.

## Example usage

The following example illustrates the use of the library:

``````(require :asdf)
(use-package :physical-quantities}
(define-si-units)

(let (m c m)
;; Define the mass
(setf m #q(1.00 +/- 0.01 kg))
;; The speed of light
(setf c #q(299792458 m / s))
;; e = m * c^2
(setf e (q* m (qpow c 2)))
;; Print e, converted to petajoule
(print #q(e -> PJ)))
``````

This will print

``````#<QUANTITY 89.87552 +/- 1.0 % petajoule {...}>
``````

## Defining quantities

To define a quantity, either the macro `(quantity ...)` or the read macro `#q(...)` can be used. For the latter, the function `(define-read-macros)` must be called first.

The following lines of code are equivalent:

``````(quantity 1 "kilogram")
(quantity 1 "kg")

#q(1 kilogram)
#q(1 kg)
``````

This creates an object of type `quantity`. Its value is the integer `1` and its unit is `kilogram`. The uncertainty/error of this quantity is zero because it was not specified. To define it, the symbol `+/-` (or `+-`), followed by a number, can be inserted into the macro call after the value:

``````#q(1 +/- 0.2 kg)
``````

This sets the absolute error to 0.2 kg. To define a relative error, the `%` sign has to be appended:

``````#q(1 +/- 20 % kg)
``````

Note that there must be space between numbers and symbols.

It is permitted to use variables or even lisp forms instead of numbers for both the value/magnitude or the uncertainty/error.

### Specifying units

Units are specified as a sequence of unit factors. A unit factor is essentially a unit and a power. The power defaults to 1 when only naming the unit (e.g. `metre`). If a power of -1 is desired, either the symbol `/` or `per` can be inserted before the unit (e.g `/ metre` or `per metre`). Powers other than 1 or -1 are specified in any of the following ways:

``````metre ^ 2
metre ** 2
metre to the 2
/ metre ^ 2
/ metre ** 2
/ metre to the 2
``````

Note that `/ metre` is equivalent to `metre ^ -1`.

For the powers 2 and 3, there are special keywords:

``````square metre
cubic metre
metre squared
metre cubed
/ square metre
/ cubic metre
/ metre squared
/ metre cubed
``````

As pointed out above, the full unit is a sequence of such unit factors:

``````kilogram metre ^ 2 / second ^ 2 / kelvin / mole
kg m ^ 2 / s ^ 2 / K / mol
``````

Please note that separating symbols with spaces is compulsory.

### Unit abbreviations

Units can be abbreviated. This means that `kilometre` is interpreted in the same way as `km`. Note that both the unit `metre` and the prefix `kilo` is abbreviated. Mixing abbreviation (e.g. `kmetre` or `kilom`) is not supported.

### Standalone units

Units without value can be obtained by using one of these methods:

``````(mkunit "metre" / "second")
(mkunit "m" / "s")
#u(metre / second)
#u(m / s)
``````

These will all create the same unit. Note that the representation of the result may change in the future.

### Upper- and lowercase

Lisp by default converts all symbols that it reads to uppercase. This default setting is disabled and case is preserved for units within the `#q(...)` and `#u(...)` read macros, therefore `#q(1 Pa)` has different units from `#q(1 pA)`. When using the `(quantity ...)` or `(mkunit ...)` macros, this is not possible and therefore you would have to specify `(quantity 1 "Pa")` or `(quantity 1 "pA")`. The macros `(quantity ...)` and `(mkunit ...)` do accept symbols, but these will be converted to uppercase by the reader (usually causing a unit lookup error) unless they are escaped by using the `|...|` syntax for example.

Note that the `#q(...)` read macro makes the usual case conversion for the value/magnitude and uncertainty/error. Therefore, it is possible to write

``````(let ((val 1.0) (err 0.1))
#q(val +/- err m / s))
``````

which will result in `#<QUANTITY 1.0 +/- 0.1 metre / second {...}>`. The symbols are converted to uppercase in the `let` form as well as in the `#q(...)` read macro.

## Operations

Common Lisp does not easily allow the redefinition/overloading of standard operators such as `+` or `*`. For this reason, a number of operators are provided to work with both types `real` and `quantity`. These are prefixed with the letter `q`, e.g. `q+` or `q*`. Example:

``````(q* a (q+ b (qsqrt c)))
``````

The result of such an operation is always a quantity, even if all arguments passed to the function are of type `real`.

When using these operations, error propagation will be performed automatically. The error propagation is first-order only and correlations are not taken into account.

### Defining new operations

Apart from the predefined operations, new options can be defined as normal functions or methods. See section Accessing value, error and unit for relevant information.

There is a convenience macro `defqop` that automatically converts arguments to values of type `quantity` if a `real` number is passed:

``````(defqop factorial (number!u)
(unless (errorlessp number)
(error "The error propagation of FACTORIAL is undefined."))
;; Insert more tests here ...
(make-quantity :value (loop for n from 1 upto (value number) for result = 1 then (* result n) finally (return result))))
``````

The list of arguments (here only `number!u`) is not a lambda list and things like `&optional` or `&key` are not allowed. Furthermore, all arguments are expected to be either of type `real` or `quantity`. The ending `!u` in `number!u` means that the argument `number` should automatically be checked for unitlessness. Otherwise an error will be signaled. The suffix must only appear in the argument list.

## Converting units

Units can be converted by calling the `(quantity ...)` or `#q(...)` macro and specifying `->` and a new unit:

``````(let ((v #q(20 m / s)))
(setf v #q(v -> km / h))
(print v))
``````

This would print

``````#<QUANTITY 72 kilometre / hour {...}>
``````

Instead of using a variable as the first form in the macro call, one could specify any other form such as

``````#q((q* 1/2 m (qpow v 2)) -> joule)
``````

or even a quantity definition

``````#q(20 +/- 1 % m / s -> km / h)
``````

Note that it is an error if the units are not convertible.

### Limitations

The unit conversion only considers the conversion factor. This means that linear conversions with offset (not to speak of nonlinear conversions) may not work as expected. For example

``````#q(1 celsius -> kelvin)
``````

will produce 1 kelvin. The offset of 273.15 is ignored. This is fine for conversion of temperature differences, but not for absolute temperatures.

## Accessing value, error and unit

To retrieve value/magnitude, uncertainty/error and unit of an object of type `quantity`, one can use the functions

• `(value <quantity>)` to retrieve the value/magnitude
• `(unit <quantity>)` to retrieve the unit
• `(absolute-error <quantity>)` or `(aerr <quantity>)` to retrieve the absolute uncertainty/error
• `(relative-error <quantity>)` or `(rerr <quantity>` to retrieve the relative uncertainty/error

These are all places, so they are `setf`able. Note that setting the absolute uncertainty will affect the relative uncertainty and vice versa. Also note that it is an error accessing the relative error when the value/magnitude is zero.

## Machine interface

The macros `(quantity ...)` and `#q(...)` are intended as convenience for humans. They are not very lispy. To create quantities in a manner that is suitable for machines, the function `(make-quantity ...)` is defined:

``````(make-quantity :value 1 :error 0.1 :error-type :absolute :unit '(("m" 1) ("s" -1)))
``````

This is equivalent to `#q(1 +/- 0.1 m / s)`. Note that the unit is a list of unit factors with each unit factor being a symbol or string that stands for a unit and an integer for the power. Being a function, the arguments are evaluated before the `quantity` is created. This allows the unit to be a variable. Units can be created with the `(make-unit ...)` function:

``````(make-unit '("m" 1) '("s" -1))
``````

Units can be converted using the `(convert-unit ...)` function. It accepts either a unit object or a list of unit factors:

``````(convert-unit v (make-unit '("km" 1) '("h" -1)))
(convert-unit v '(("km" 1) ("h" -1)))
``````

## Defining new units

New units can be defined using the `(define-unit ...)` macro:

``````(define-unit "metre" :abbrev "m" :alias "meter")
(define-unit "watthour" :def (1 "watt" "hour") :abbrev "Wh")
(define-unit "mile" :def (1609344/1000 "metre") :abbrev "mi")
(define-unit "gravity" :def (981/100 "metre" / "second" ^ 2) :abbrev "g")
``````

There are a number of keywords that may appear in the definition:

• `:def` Specifies the unit in terms of another unit. Complex dependencies can be given such as `(0.3048 "metre" / "second" ^ 2)`. If this keyword is missing, the newly defined unit will be considered a base unit.
• `:alias` Allows multiple (non-abbreviated) names for a unit, given as a single symbol or a list of symbols. This is helpful if there are different spellings (e.g. metre, meter).
• `:abbrev` Abbreviations for the unit can be specified here, given as a single symbol or a list of symbols. Be careful about name conflicts (see above).
• `:prefix-test` A function of two arguments, the base and the power, which decides whether a unit prefix is admissible for use with this unit. For more details, see below.
• `:overwrite` A flag to suppress errors that occur when a naming conflict is detected.

For all defined units and abbreviations, more units with all permissible prefixes such as `kilowatthour` or `kWh` will automatically be defined. This may cause naming conflicts which will raise an error. It is possible to define which prefixes are admissible.

For some units, certain prefixes make no sense. For example: For the unit `tonne`, the prefix `kilo` is widely used (`kilotonne`). It makes little sense, however, to use `millitonne`. To specify, which prefixes are admissible, the keyword parameter `:prefix-test` can be used in the call to `define-unit`. It accepts a function of two arguments, the base and the power of a prefix. The function can then decide, whether such a prefix is admissible by returning `T` or `NIL`. Here is an example:

``````(define-unit "tonne" :def (1000 "kilogram") :prefix-test (lambda (base power) (and (= base 10) (>= power 3))))
``````

This will only allow the units `tonne`, `kilotonne`, `megatonne`, etc.

To facilitate the prefix test specification, some functions are provided:

• `(prefix-base base &optional mod)` Will return a function that accepts only the given base and powers divisible by `mod` (defaulting to 1).
• `(prefix-range base from to)` Will return a function that accepts only the given base and powers in the range between `from` and `to` (inclusive). To leave the range open on either side, `NIL` can be supplied.
• `(prefix-list base &rest powers)` Will return a function that accepts only the given base and the given powers.

To combine such tests, the following composing functions are provided:

• `(prefix-and &rest functions)` This will acccept a prefix if all functions accept it.
• `(prefix-or &rest functions)` This will accept a prefix if a single function accepts it.

You can use the standard composing function `complement` where necessary.

The above example could be rewritten to read

``````(define-unit "tonne" :def (1000 "kilogram") :prefix-test (prefix-range 10 3 nil))
``````

## Defining prefixes

Prefixes can be defined by using the `(define-unit-prefix ...)` macro:

``````(define-unit-prefix "giga" 9 :abbrev "G")
(define-unit-prefix "gibi" 3 :abbrev "Gi" :base 1024)
``````

The full name is specified first, followed by the power. Keyword parameters allow the definition of the base (defaults to 10) and abbreviation. In this example, `giga` is equivalent to 10^9 and `gibi` to 1024^3.

You must define prefixes before defining the units that use them.

## Standard units and prefixes

When calling the function `(define-si-units &optional clear-existing-units)`, the SI units will be automatically defined. More sets may be available in the future.

## Local namespaces

Several unit and prefix definitions can be used in a program by locally defining them. This can be done with the `(with-local-units ...)` and `(with-saved-units ...`) macros. The former completely clears the outside units and prefixes until control leaves the form. The latter makes a copy of all the unit definitions such that they can be changed within the body of the form without affecting the outisde definitions.

Please note that the unit definitions use dynamic scope an not lexical scope. This means that the unit definitions are only local during the time spent within the macro call. It is therefore not possible to close over the unit definitions. While quantities with local unit can be returned from this macro call, the unit may be undefined after the time of the call or may have a different meaning.

## Errors/Conditions

The errors/conditions signaled by the library are all subtypes of `physical-quantities-error` which itself is a subtype of `standard-error`. However, no event triggers the `physical-quantities-error` directly. Instead, the most specific error is signaled. Here is the complete hierarcy of conditions:

• `quantity-definition-error`

• `quantity-definition-syntax-error`: There is a syntax error in one of the following forms: `#q(...)`, `(quantity ...)`, `(make-quantity ...)`, `#u(...)`, `(make-unit ...)` or `(mkunit ...)`.
• `quantity-definition-semantic-error`: There is a semantic error in one of the following forms: `#q(...)`, `(quantity ...)`, `(make-quantity ...)`, `#u(...)`, `(make-unit ...)` or `(mkunit ...)`.
• `invalid-unit-error`

• `invalid-unit-operation-error`: The mathematical operation can not be performed on the input quantity with the given unit.
• `invalid-unit-conversion-error`: The units can not be converted into each other.
• `invalid-unit-reference-error`: The unit is undefined or the prefix unit combination does not exist.
• `operation-undefined-error`: The mathematical operation is undefined for the given input parameters.

• `error-propagation-error`: The propagation of uncertainty can not be performed with the given parameters.

• `unit-definition-error`

• `unit-definition-syntax-error`: A syntactic problem exists with a `(define-unit ...)` or `(define-prefix ...)` form.
• `unit-definition-semantic-error`: There is a semantic error with a `(define-unit ...)` or `(define-prefix ...)` form.
• `unit-definition-conflict-error`: The unit or prefix is already defined or a combination of prefix and unit conflicts with another unit.

Physical Quantities: Lisp Library

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Next: , Previous: , Up: Top   [Contents][Index]

## 2 Systems

The main system appears first, followed by any subsystem dependency.

Previous: , Up: Systems   [Contents][Index]

### 2.1 physical-quantities

Author

Marco Rossini

GPLv2

Description

A library that provides a numeric type with optional unit and/or uncertainty for computations with automatic error propagation.

Version

0.1

Dependency

parseq

Source

physical-quantities.asd (file)

Components

Next: , Previous: , Up: Top   [Contents][Index]

## 3 Files

Files are sorted by type and then listed depth-first from the systems components trees.

Previous: , Up: Files   [Contents][Index]

### 3.1 Lisp

Next: , Previous: , Up: Lisp files   [Contents][Index]

#### 3.1.1 physical-quantities.asd

Location

physical-quantities.asd

Systems

physical-quantities (system)

Next: , Previous: , Up: Lisp files   [Contents][Index]

#### 3.1.2 physical-quantities/package.lisp

Parent

physical-quantities (system)

Location

package.lisp

Packages

#### 3.1.3 physical-quantities/utils.lisp

Dependency

package.lisp (file)

Parent

physical-quantities (system)

Location

utils.lisp

Internal Definitions

#### 3.1.4 physical-quantities/conditions.lisp

Dependency

utils.lisp (file)

Parent

physical-quantities (system)

Location

conditions.lisp

Exported Definitions
Internal Definitions

#### 3.1.5 physical-quantities/unit-factor.lisp

Dependency

conditions.lisp (file)

Parent

physical-quantities (system)

Location

unit-factor.lisp

Exported Definitions
Internal Definitions

#### 3.1.6 physical-quantities/unit-database.lisp

Dependency

unit-factor.lisp (file)

Parent

physical-quantities (system)

Location

unit-database.lisp

Exported Definitions
Internal Definitions

#### 3.1.7 physical-quantities/units.lisp

Dependency

unit-database.lisp (file)

Parent

physical-quantities (system)

Location

units.lisp

Exported Definitions
Internal Definitions

#### 3.1.8 physical-quantities/quantity.lisp

Dependency

units.lisp (file)

Parent

physical-quantities (system)

Location

quantity.lisp

Exported Definitions
Internal Definitions

#### 3.1.9 physical-quantities/numeric.lisp

Dependency

quantity.lisp (file)

Parent

physical-quantities (system)

Location

numeric.lisp

Exported Definitions
Internal Definitions

#### 3.1.10 physical-quantities/parse-rules.lisp

Dependency

numeric.lisp (file)

Parent

physical-quantities (system)

Location

parse-rules.lisp

Dependency

parse-rules.lisp (file)

Parent

physical-quantities (system)

Location

Exported Definitions

Internal Definitions

Previous: , Up: Lisp files   [Contents][Index]

#### 3.1.12 physical-quantities/si-units.lisp

Dependency

Parent

physical-quantities (system)

Location

si-units.lisp

Exported Definitions

define-si-units (function)

Next: , Previous: , Up: Top   [Contents][Index]

## 4 Packages

Packages are listed by definition order.

Previous: , Up: Packages   [Contents][Index]

### 4.1 physical-quantities

Source

package.lisp (file)

Nicknames
• pq
• pquant
• physq
Use List
• parseq
• common-lisp
Exported Definitions
Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

## 5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.

Next: , Previous: , Up: Definitions   [Contents][Index]

### 5.1 Exported definitions

Next: , Previous: , Up: Exported definitions   [Contents][Index]

#### 5.1.1 Macros

Macro: define-unit NAME &key DEF ALIAS ABBREV PREFIX-TEST OVERWRITE
Package
Source

unit-database.lisp (file)

Macro: define-unit-prefix NAME POWER &key ABBREV BASE
Package
Source

unit-database.lisp (file)

Macro: defqop NAME ARG-LIST &body BODY
Package
Source

numeric.lisp (file)

Macro: mkunit &rest EXPR

Human interface to make a unit.

Package
Source

units.lisp (file)

Macro: qop QFORM
Package
Source

numeric.lisp (file)

Macro: quantity &rest EXPR

Function to define quantities without the reader macro.

Package
Source

quantity.lisp (file)

Macro: with-local-units &body BODY

Shadow the global unit table with a new rule table.

Package
Source

unit-database.lisp (file)

Macro: with-saved-units &body BODY

Shadow the global unit table with a copy of the unit table. When returninng from the body the original units are restored.

Package
Source

unit-database.lisp (file)

Next: , Previous: , Up: Exported definitions   [Contents][Index]

#### 5.1.2 Functions

Function: convert-to-base-units QUANTITY
Package
Source

quantity.lisp (file)

Function: convert-unit QUANTITY UNIT
Package
Source

quantity.lisp (file)

Lets the user define the #q(...) and #u(...) read macros.

Package
Source

Function: define-si-units &key CLEAR-EXISTING-UNITS
Package
Source

si-units.lisp (file)

Function: make-quantity &key VALUE ERROR ERROR-TYPE UNIT
Package
Source

quantity.lisp (file)

Function: make-unit &rest UNIT-FACTORS

Machine interface for making a unit.

Package
Source

units.lisp (file)

Function: q* &rest NUMBERS
Package
Source

numeric.lisp (file)

Function: q+ &rest NUMBERS
Package
Source

numeric.lisp (file)

Function: q- NUMBER &rest MORE-NUMBERS
Package
Source

numeric.lisp (file)

Function: q/ NUMBER &rest MORE-NUMBERS
Package
Source

numeric.lisp (file)

Function: q/= X Y &optional P-VALUE
Package
Source

numeric.lisp (file)

Function: qabs NUMBER
Package
Source

numeric.lisp (file)

Function: qacos NUMBER
Package
Source

numeric.lisp (file)

Function: qacosh NUMBER
Package
Source

numeric.lisp (file)

Function: qasin NUMBER
Package
Source

numeric.lisp (file)

Function: qasinh NUMBER
Package
Source

numeric.lisp (file)

Function: qatan NUMBER
Package
Source

numeric.lisp (file)

Function: qatanh NUMBER
Package
Source

numeric.lisp (file)

Function: qcos NUMBER
Package
Source

numeric.lisp (file)

Function: qcosh NUMBER
Package
Source

numeric.lisp (file)

Function: qequal X Y
Package
Source

numeric.lisp (file)

Function: qequalp X Y
Package
Source

numeric.lisp (file)

Function: qexp EXPONENT
Package
Source

numeric.lisp (file)

Function: qexpt BASE EXPONENT
Package
Source

numeric.lisp (file)

Function: qln NUMBER
Package
Source

numeric.lisp (file)

Function: qlog NUMBER BASE
Package
Source

numeric.lisp (file)

Function: qpow BASE POWER
Package
Source

numeric.lisp (file)

Package
Source

numeric.lisp (file)

Function: qround QUANTITY &key DIGITS PLACE
Package
Source

numeric.lisp (file)

Function: qsin NUMBER
Package
Source

numeric.lisp (file)

Function: qsinh NUMBER
Package
Source

numeric.lisp (file)

Function: qsqrt QUANTITY

Computes the square root of a given quantity. Result must always be real.

Package
Source

numeric.lisp (file)

Function: qtan NUMBER
Package
Source

numeric.lisp (file)

Function: qtanh NUMBER
Package
Source

numeric.lisp (file)

Function: quantityp OBJECT
Package
Source

quantity.lisp (file)

Function: str-unit OBJ

Prints the given unit in human readable form

Package
Source

units.lisp (file)

Function: uf-power INSTANCE
Function: (setf uf-power) VALUE INSTANCE
Package
Source

unit-factor.lisp (file)

Function: uf-unit INSTANCE
Function: (setf uf-unit) VALUE INSTANCE
Package
Source

unit-factor.lisp (file)

Function: unitp OBJECT

Checks whether an object is a unit.

Package
Source

units.lisp (file)

Function: units-convertible UNIT-A UNIT-B

Expands and reduces both units and compares the unit factors for equality (in unit and power)

Package
Source

units.lisp (file)

Function: units-equal UNIT-A UNIT-B

Reduces both units (without converting to base units) and compares the unit factors for equality (in unit and power)

Package
Source

units.lisp (file)

Function: units-equalp UNIT-A UNIT-B

Reduces both units (converting to base units) and compares the unit factors for equality (in unit and power)

Package
Source

units.lisp (file)

Next: , Previous: , Up: Exported definitions   [Contents][Index]

#### 5.1.3 Generic functions

Generic Function: absolute-error QUANTITY
Generic Function: (setf absolute-error) ERROR QUANTITY
Package
Source

quantity.lisp (file)

Methods
Method: absolute-error (QUANTITY quantity)
Method: (setf absolute-error) ERROR (QUANTITY quantity)
Generic Function: aerr QUANTITY
Generic Function: (setf aerr) ERROR QUANTITY
Package
Source

quantity.lisp (file)

Methods
Method: aerr (QUANTITY quantity)
Method: (setf aerr) ERROR (QUANTITY quantity)
Generic Function: q< X Y &optional P-VALUE

Determines whether the one quantity is less than another quantity

Package
Source

numeric.lisp (file)

Methods
Method: q< (X quantity) (Y quantity) &optional P-VALUE
Method: q< (X real) (Y quantity) &optional P-VALUE
Method: q< (X quantity) (Y real) &optional P-VALUE
Method: q< (X real) (Y real) &optional P-VALUE
Generic Function: q<= X Y &optional P-VALUE

Determines whether the one quantity is less or equal to another quantity

Package
Source

numeric.lisp (file)

Methods
Method: q<= (X quantity) (Y quantity) &optional P-VALUE
Method: q<= (X real) (Y quantity) &optional P-VALUE
Method: q<= (X quantity) (Y real) &optional P-VALUE
Method: q<= (X real) (Y real) &optional P-VALUE
Generic Function: q= X Y &optional P-VALUE

Determines whether the value of two quantities are equal.

Package
Source

numeric.lisp (file)

Methods
Method: q= (X quantity) (Y quantity) &optional P-VALUE
Method: q= (X real) (Y quantity) &optional P-VALUE
Method: q= (X quantity) (Y real) &optional P-VALUE
Method: q= (X real) (Y real) &optional P-VALUE
Generic Function: q> X Y &optional P-VALUE

Determines whether the one quantity is greater than another quantity

Package
Source

numeric.lisp (file)

Methods
Method: q> (X quantity) (Y quantity) &optional P-VALUE
Method: q> (X real) (Y quantity) &optional P-VALUE
Method: q> (X quantity) (Y real) &optional P-VALUE
Method: q> (X real) (Y real) &optional P-VALUE
Generic Function: q>= X Y &optional P-VALUE

Determines whether the one quantity is greater or equal to another quantity

Package
Source

numeric.lisp (file)

Methods
Method: q>= (X quantity) (Y quantity) &optional P-VALUE
Method: q>= (X real) (Y quantity) &optional P-VALUE
Method: q>= (X quantity) (Y real) &optional P-VALUE
Method: q>= (X real) (Y real) &optional P-VALUE
Generic Function: relative-error QUANTITY
Generic Function: (setf relative-error) ERROR QUANTITY
Package
Source

quantity.lisp (file)

Methods
Method: relative-error (QUANTITY quantity)
Method: (setf relative-error) ERROR (QUANTITY quantity)
Generic Function: rerr QUANTITY
Generic Function: (setf rerr) ERROR QUANTITY
Package
Source

quantity.lisp (file)

Methods
Method: rerr (QUANTITY quantity)
Method: (setf rerr) ERROR (QUANTITY quantity)
Generic Function: unit OBJECT
Generic Function: (setf unit) NEW-VALUE OBJECT
Package
Methods
Method: unit (QUANTITY quantity)

Source

quantity.lisp (file)

Method: (setf unit) NEW-VALUE (QUANTITY quantity)

automatically generated writer method

Source

quantity.lisp (file)

Generic Function: value OBJECT
Generic Function: (setf value) NEW-VALUE OBJECT
Package
Methods
Method: value (QUANTITY quantity)

Source

quantity.lisp (file)

Method: (setf value) NEW-VALUE (QUANTITY quantity)

automatically generated writer method

Source

quantity.lisp (file)

Next: , Previous: , Up: Exported definitions   [Contents][Index]

#### 5.1.4 Conditions

Condition: error-propagation-error ()

Error for situations in which the propagation of uncertainty is undefined

Package
Source

conditions.lisp (file)

Direct superclasses

physical-quantities-error (condition)

Condition: invalid-unit-conversion-error ()

Error when converting between incompatible units

Package
Source

conditions.lisp (file)

Direct superclasses

invalid-unit-error (condition)

Condition: invalid-unit-error ()

Generic unit error

Package
Source

conditions.lisp (file)

Direct superclasses

physical-quantities-error (condition)

Direct subclasses
Condition: invalid-unit-operation-error ()

Error for situations in which the unit is invalid in a given operation

Package
Source

conditions.lisp (file)

Direct superclasses

invalid-unit-error (condition)

Condition: invalid-unit-reference-error ()

Unit lookup error

Package
Source

conditions.lisp (file)

Direct superclasses

invalid-unit-error (condition)

Condition: operation-undefined-error ()

Error for situations in which an operation is undefined

Package
Source

conditions.lisp (file)

Direct superclasses

physical-quantities-error (condition)

Condition: physical-quantities-error ()

Generic error for the physical quantities library.

Package
Source

conditions.lisp (file)

Direct superclasses

simple-error (condition)

Direct subclasses
Condition: unit-definition-conflict-error ()

Name conflict for the definition of a unit/prefix

Package
Source

conditions.lisp (file)

Direct superclasses

unit-definition-error (condition)

Condition: unit-definition-error ()

Generic error for unit/prefix definitions.

Package
Source

conditions.lisp (file)

Direct superclasses

physical-quantities-error (condition)

Direct subclasses
Condition: unit-definition-semantic-error ()

Semantic error in the definition of a unit/prefix

Package
Source

conditions.lisp (file)

Direct superclasses

unit-definition-error (condition)

Condition: unit-definition-syntax-error ()

Syntax error in the definition of a unit/prefix

Package
Source

conditions.lisp (file)

Direct superclasses

unit-definition-error (condition)

Previous: , Up: Exported definitions   [Contents][Index]

#### 5.1.5 Classes

Class: quantity ()
Package
Source

quantity.lisp (file)

Direct superclasses

standard-object (class)

Direct methods
Direct slots
Slot: value
Initargs

:value

Initform

0

value (generic function)

Writers

(setf value) (generic function)

Slot: error
Initargs

:error

Initform

0

error-direct (generic function)

Writers

(setf error-direct) (generic function)

Slot: unit
Initargs

:unit

unit (generic function)

Writers

(setf unit) (generic function)

Previous: , Up: Definitions   [Contents][Index]

### 5.2 Internal definitions

Next: , Previous: , Up: Internal definitions   [Contents][Index]

#### 5.2.1 Special variables

Special Variable: *unit-abbreviation-table*
Package
Source

unit-database.lisp (file)

Special Variable: *unit-alias-table*
Package
Source

unit-database.lisp (file)

Special Variable: *unit-prefix-table*
Package
Source

unit-database.lisp (file)

Special Variable: *unit-translation-table*
Package
Source

unit-database.lisp (file)

Next: , Previous: , Up: Internal definitions   [Contents][Index]

#### 5.2.2 Macros

Macro: dup-quantity Q &key V E U
Package
Source

numeric.lisp (file)

Macro: error-propagation &rest VAR-DERIVATIVE-PAIRS
Package
Source

numeric.lisp (file)

Macro: f-error TYPE (&rest INITARGS) CONTROL &rest ARGS

Like (error ...), but allows the condition type to be specified (which is required to inherit from simple-condition).

Package
Source

conditions.lisp (file)

Macro: nand &rest FORMS
Package
Source

utils.lisp (file)

Macro: with-gensyms (&rest NAMES) &body BODY
Package
Source

utils.lisp (file)

Macro: with-unit-lookup (BASE-UNIT TRANSLATION UNIT) &body BODY
Package
Source

unit-database.lisp (file)

Next: , Previous: , Up: Internal definitions   [Contents][Index]

#### 5.2.3 Functions

Function: ae VAL ERR
Package
Source

quantity.lisp (file)

Function: beta X

Helper for the inverf function.

Package
Source

utils.lisp (file)

Function: chebyshev-polynomial N X

Evaluates the nth Chebyshev polynomial.

Package
Source

utils.lisp (file)

Function: chebyshev-polynomial% N X A B

Recursion function for the Chebyshev polynomial evaluation.

Package
Source

utils.lisp (file)

Function: clear-units ()
Package
Source

unit-database.lisp (file)

Function: collect-factors F &rest EXPANDED-UNIT-FACTORS
Package
Source

units.lisp (file)

Function: confidence-interval CONFIDENCE-VALUE &key TWO-SIDED
Package
Source

utils.lisp (file)

Function: convert-unit% VALUE UNIT-A UNIT-B

Applies the conversion factor between unit-a and unit-b to the given value.

Package
Source

units.lisp (file)

Function: copy-hash-table HASH-TABLE

Creates a copy of the given hash table.

Package
Source

utils.lisp (file)

Function: copy-unit UNIT

Creates a copy of the given unit.

Package
Source

units.lisp (file)

Function: copy-unit-factor INSTANCE
Package
Source

unit-factor.lisp (file)

Function: define-unit% NAME &key DEF ALIASES ABBREVIATIONS PREFIX-TEST OVERWRITE

Defines a new unit with the identifier name. A list of aliases and a list of abbreviations are permitted which - when encountered - are internally converted to the primary identifier. The definition allows the unit to be defined in terms of other units, e.g :def (1.602 kilometre). Prefixes is must be a function of two parameters, the base and the power, with which it decides whether a prefix is allowed for the unit. It defaults to allowing all defined prefixes.

Package
Source

unit-database.lisp (file)

Function: define-unit-prefix% NAME POWER &key ABBREV BASE

Defines a unit prefix such as kilo in kilometre. Apart from the name the power is required (3 for kilo) together with the base that defaults to 10. An abbreviation for the prefix is also allowed which will be used in combination with abbreviated units.

Package
Source

unit-database.lisp (file)

Function: dereference-unit UNIT

Takes a unit and looks up aliases and abbreviations of unit factors and replaces them with the main unit designators.

Package
Source

units.lisp (file)

Function: divide-units &rest UNITS

Divides the given units with each, reducing the result.

Package
Source

units.lisp (file)

Function: erf X

Calculates the error function.

Package
Source

utils.lisp (file)

Function: errorlessp QUANTITY

Checks whether a quantity is without uncertainty/error.

Package
Source

quantity.lisp (file)

Function: expand-unit UNIT

Expands the given unit into base units and reduces them

Package
Source

units.lisp (file)

Function: expand-unit-factor FACTOR

Converts a single unit factor into its expansion of base units, together with a conversion factor

Package
Source

units.lisp (file)

Function: has-error-p QUANTITY

Checks whether a quantity has uncertainty/error.

Package
Source

quantity.lisp (file)

Function: has-key KEY HASH-TABLE
Package
Source

utils.lisp (file)

Function: has-unit-p QUANTITY

Checks whether the given quantity has a unit.

Package
Source

quantity.lisp (file)

Function: have ITEM SEQUENCE &key TEST KEY
Package
Source

utils.lisp (file)

Function: inverf X

Inverse error function.

Package
Source

utils.lisp (file)

Function: l= LIST LENGTH

Tests efficiently whether the length of the list is equal to the given length.

Package
Source

utils.lisp (file)

Function: l> LIST LENGTH

Tests efficiently whether the length of the list is greater than the given length.

Package
Source

utils.lisp (file)

Function: ll= LIST-A LIST-B

Tests efficiently whether the length of list-a is equal to the length of list-b.

Package
Source

utils.lisp (file)

Function: lookup-unit UNIT
Package
Source

unit-database.lisp (file)

Function: make-quantity% &key VALUE ERROR UNIT
Package
Source

quantity.lisp (file)

Function: make-uf UNIT POWER
Package
Source

unit-factor.lisp (file)

Function: mklist OBJ

Makes a list out of the given object unless it already is a list.

Package
Source

utils.lisp (file)

Function: mkstr &rest ARGS
Package
Source

utils.lisp (file)

Function: multiply-units &rest UNITS

Multiplies units with each other and reduces the result.

Package
Source

units.lisp (file)

Function: p-value X
Package
Source

utils.lisp (file)

Function: power-unit UNIT POWER

Raises the unit to the given power.

Package
Source

units.lisp (file)

Function: prefix-and &rest FUNCTIONS
Package
Source

unit-database.lisp (file)

Function: prefix-base BASE &optional MOD
Package
Source

unit-database.lisp (file)

Function: prefix-list BASE &rest POWERS
Package
Source

unit-database.lisp (file)

Function: prefix-or &rest FUNCTIONS
Package
Source

unit-database.lisp (file)

Function: prefix-range BASE POWER-MIN POWER-MAX
Package
Source

unit-database.lisp (file)

Function: py+ &rest NUMBERS

Package
Source

utils.lisp (file)

Function: q-op-insert TREE
Package
Source

numeric.lisp (file)

Function: quantile P

Calculates the quantile for the normal distribution.

Package
Source

utils.lisp (file)

Function: r-function-a X

Helper for the inverf function.

Package
Source

utils.lisp (file)

Function: r-function-b X

Helper for the inverf function.

Package
Source

utils.lisp (file)

Function: re VAL ERR
Package
Source

quantity.lisp (file)

The read macro #q(...) is an abbreviation for (quantity ...) which does not transform lowercase symbols to uppercase for unit factors.

Package
Source

The read macro #u(...) is an abbreviation for (mkunit ...) which does not transform lowercase symbols to uppercase.

Package
Source

Function: reduce-unit UNIT

Reduces the powers of duplicate unit factors in a given unit, e.g. km^2 / km -> km, but m / km -> m / km. No unit lookup is made.

Package
Source

units.lisp (file)

Function: root-unit UNIT INDEX

Extracts the root from the given unit if possible. Converts to base units if necessary.

Package
Source

units.lisp (file)

Function: round-to NUMBER DIGITS &optional PLACE
Package
Source

numeric.lisp (file)

Function: sort-unit UNIT

Sorts the unit by positive and negative powers.

Package
Source

units.lisp (file)

Function: split TEST SEQUENCE &key KEY
Package
Source

utils.lisp (file)

Function: symb &rest ARGS
Package
Source

utils.lisp (file)

Function: symbol-prefix PREFIX SYMBOLS
Package
Source

unit-database.lisp (file)

Function: table-check NAME ALIASES ABBREVS
Package
Source

unit-database.lisp (file)

Function: table-insert NAME ALIASES ABBREVS DEF
Package
Source

unit-database.lisp (file)

Function: uf-equal A B
Package
Source

unit-factor.lisp (file)

Function: uf-pow UNIT-FACTOR POWER
Package
Source

unit-factor.lisp (file)

Function: unit-factor-p OBJECT
Package
Source

unit-factor.lisp (file)

Function: unit-has-unit-p UNIT
Package
Source

units.lisp (file)

Function: unit-hash-key-check KEY
Package
Source

unit-database.lisp (file)

Function: unitlessp QUANTITY

Checks whether the given quantity is unitless.

Package
Source

quantity.lisp (file)

Function: unzip LIST
Package
Source

utils.lisp (file)

Function: xnor &rest FORMS
Package
Source

utils.lisp (file)

Next: , Previous: , Up: Internal definitions   [Contents][Index]

#### 5.2.4 Generic functions

Generic Function: error-direct OBJECT
Generic Function: (setf error-direct) NEW-VALUE OBJECT
Package
Methods
Method: error-direct (QUANTITY quantity)

Source

quantity.lisp (file)

Method: (setf error-direct) NEW-VALUE (QUANTITY quantity)

automatically generated writer method

Source

quantity.lisp (file)

Generic Function: eval-quantity VALUE ERROR UNIT-A UNIT-B
Package
Source

quantity.lisp (file)

Methods
Method: eval-quantity (Q quantity) (ERROR (eql 0)) (UNIT-A (eql nil)) UNIT-B
Method: eval-quantity (Q quantity) (ERROR (eql 0)) UNIT-A (UNIT-B (eql nil))
Method: eval-quantity (VALUE quantity) (ERROR (eql 0)) (UNIT-A (eql nil)) (UNIT-B (eql nil))
Method: eval-quantity (VALUE number) (ERROR number) UNIT-A UNIT-B
Method: eval-quantity (VALUE number) (ERROR number) UNIT-A (UNIT-B (eql nil))

Next: , Previous: , Up: Internal definitions   [Contents][Index]

#### 5.2.5 Conditions

Condition: quantity-definition-error ()

Generic error for quantity definitions.

Package
Source

conditions.lisp (file)

Direct superclasses

physical-quantities-error (condition)

Direct subclasses
Condition: quantity-definition-semantic-error ()

Semantic error in the definition of a quantity/unit

Package
Source

conditions.lisp (file)

Direct superclasses

quantity-definition-error (condition)

Condition: quantity-definition-syntax-error ()

Syntax error in the definition of a quantity/unit

Package
Source

conditions.lisp (file)

Direct superclasses

quantity-definition-error (condition)

Previous: , Up: Internal definitions   [Contents][Index]

#### 5.2.6 Structures

Structure: unit-factor ()
Package
Source

unit-factor.lisp (file)

Direct superclasses

structure-object (structure)

Direct slots
Slot: unit
Type

string

Initform

""

uf-unit (function)

Writers

(setf uf-unit) (function)

Slot: power
Type

integer

Initform

0

uf-power (function)

Writers

(setf uf-power) (function)

Previous: , Up: Top   [Contents][Index]

## Appendix A Indexes

Next: , Previous: , Up: Indexes   [Contents][Index]

### A.1 Concepts

Next: , Previous: , Up: Indexes   [Contents][Index]

### A.2 Functions

Jump to: (   A   B   C   D   E   F   G   H   I   L   M   N   P   Q   R   S   T   U   V   W   X
Jump to: (   A   B   C   D   E   F   G   H   I   L   M   N   P   Q   R   S   T   U   V   W   X

Next: , Previous: , Up: Indexes   [Contents][Index]