kinetics.pl 592 Bytes
Newer Older
Thierry Martinez's avatar
Thierry Martinez committed
1 2 3 4 5 6 7 8 9 10 11 12
:- module(
  kinetics,
  [
    kinetics/3
  ]
).

kinetics(Kinetics, Reactants, Expression) :-
  (
    Kinetics = 'MA'(Coefficient)
  ->
    mass_action(Coefficient, Reactants, Expression)
13 14
  ;
    Expression = Kinetics
Thierry Martinez's avatar
Thierry Martinez committed
15 16 17 18 19 20 21 22 23 24 25
  ).


mass_action(Coefficient, Reactants, Expression) :-
  concentration_product(Reactants, ConcentrationProduct),
  Expression = Coefficient * ConcentrationProduct.


concentration_product([], 1).

concentration_product([Coefficient * Reactant | Reactants], Product) :-
26
  Product = [Reactant] ^ Coefficient * ProductTail,
Thierry Martinez's avatar
Thierry Martinez committed
27
  concentration_product(Reactants, ProductTail).