Did you know ... | Search Documentation: |
![]() | Packs (add-ons) for SWI-Prolog |
Title: | unit and quantity arithmetic for swi-prolog |
---|---|
Rating: | Not rated. Create the first rating! |
Latest version: | 0.4 |
SHA1 sum: | 006ebf96f542bcd26605dc33b0b92b2a4af5f02a |
Author: | Kwon-Young Choi <kwon-young.choi@hotmail.fr> |
Maintainer: | Kwon-Young Choi <kwon-young.choi@hotmail.fr> |
Packager: | Kwon-Young Choi <kwon-young.choi@hotmail.fr> |
Home page: | https://github.com/kwon-young/units |
Download URL: | https://github.com/kwon-young/units/releases/*.zip |
Requires: | prolog>=9.3.15 |
Provides: | units |
No reviews. Create the first review!.
Version | SHA1 | #Downloads | URL |
---|---|---|---|
0.4 | 006ebf96f542bcd26605dc33b0b92b2a4af5f02a | 5 | https://github.com/kwon-young/units |
0.3 | 6205801eb7c3db36af683b73af6b3bcf96e89bd5 | 4 | https://github.com/kwon-young/units |
0.1 | 8fbf439a214a72b82623dfdc5d69782318c83860 | 1 | https://github.com/kwon-young/units |
Units is a quantity and units library modeled after mp-units
.
Here is a quick preview of what is possible:
:- use_module(library(units)). % simple numeric operations ?- qeval(10*km =:= 2*5*km). % conversions to common units ?- qeval(1 * h =:= 3600 * s). ?- qeval(1 * km + 1 * m =:= 1001 * m). % derived quantities ?- qeval(1 * km / (1 * s) =:= 1000 * m / s). ?- qeval(2 * km / h * (2 * h) =:= 4 * km). ?- qeval(2 * km / (2 * km / h) =:= 1 * h). ?- qeval(2 * m * (3 * m) =:= 6 * m^2). ?- qeval(10 * km / (5 * km) =:= 2). ?- qeval(1000 / (1 * s) =:= 1 * kHz). % assignement and comparison ?- qeval(A is 10*m), qeval(A < 20*km). A = 10 * kind(isq:length)[si:metre].
The library can be used through a single predicate qeval/1 which is a predicate that wraps any kind of arithmetic operations.
One of the specificity of the library is the combination of units and quantities.
Please read the excellent mp-units
documentation on the advantages of using quantities in addition to units.
Units and quantites can be used in multiple ways:
System:Unit
, example: si:metre
. Currently, the si
and international
system are implemented.System:UnitSymbol
, example: si:m
for si:metre
.metre
m
for si:metre
si:kilo(metre)
si:kilo(international:pound_force)
kilo(metre)
km
for kilo(metre)
kilogram
for si:kilo(gram)
or hectare
for si:hecto(are)
System:Quantity
, example: isq:length
. isq
is the only system of quantity implemented.
Here is a interesting use of the speed
quantity that can be use to generically describe the ratio of any type of length
by any type of time
:
:- use_module(library(units)). avg_speed(Distance, Time, Speed) :- qeval(S is Distance / Time), Speed = S.as(isq:speed). ?- avg_speed(220 * isq:distance[si:kilo(metre)], 2 * si:hour, Speed), qmust_be(isq:speed[si:kilo(metre)/si:hour], Speed). Speed = 110 * isq:speed[si:kilo(metre)/si:hour]. ?- avg_speed(220 * isq:height[inch], 2 * si:second, Speed). Speed = 110 * isq:speed[international:inch/si:second]. ?- avg_speed(220 * si:gram, 2 * si:second, Speed). ERROR: Domain error: `kind(isq:mass)/kind(isq:time)' expected, found `isq:speed'
The qmust_be/2 predicate can be used to check the quantity and unit of a result.
One peculiar feature is that this library also supports clpBNR arithmetic:
?- qeval({A*metre == B*inch}), A = 1. A = 1, B = 5000r127.
Pack contains 11 files holding a total of 74.7K bytes.