Challenge
Given a list of SI base units, a list of equations and a target, you must derive the units of the target using only the base units.
Derived Units
From Wikipedia:
The International System of Units (SI) specifies a set of seven base units from which all other SI units of measurement are derived. Each of these other units (SI derived units) is either dimensionless or can be expressed as a product of powers of one or more of the base units.
For example, the SI derived unit of area is the square metre (m2), and the SI derived unit of density is the kilogram per cubic metre (kg/m3 or kg m−3).
The seven SI base units are:
- Ampere, A
- Candela, cd
- Kelvin, K
- Kilogram, kg
- Metre, m
- Mole, mol
- Second, s
Example
Input
Base units:
d [m]
m [kg]
t [s]
Equations:
v = d/t
a = v/t
F = m*a
E = F*d
Target:
E
Output
E [kg*m*m/s/s]
Input
Base units:
G [cd]
L [m]
y [A]
a [K]
Equations:
T = y*y/L
A = T*G
Target:
A
Output
A [cd*A*A/m]
Rules
The units will be always be given in the form
a [b]
Where a
will be a single uppercase or lowercase alphabetical letter and b
will be a unit (one or more characters).
The equation will be in the form
a = c
Where c
will be an expression which will only ever use previously defined units and the operators *
and /
.
Powers must be expanded. For example, the unit of area is officially m^2
, but you should represent this as m*m
. The same applies to negative powers such as speed (m*s^-1
) which should be represented as a division: m/s
. Similarly, the units for acceleration, m/s^2
or m*s^-2
, should be represented as m/s/s
.
You do not have to do any cancelling out. For example, an output C*s/kg/s
is valid even though it can be cancelled down to C/kg
.
There is no specific order for the multiplication: kg*s/m
, s/m*kg
, s*kg/m
are all valid (but /m*s*kg
is invalid).
Note: You will never have to divide by a derived unit.
Winning
The shortest code in bytes wins