kinetics.pl 562 Bytes
Newer Older
Thierry Martinez's avatar
Thierry Martinez committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
:- module(
  kinetics,
  [
    kinetics/3
  ]
).

kinetics(Kinetics, Reactants, Expression) :-
  (
    Kinetics = 'MA'(Coefficient)
  ->
    mass_action(Coefficient, Reactants, Expression)
  ).


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


concentration_product([], 1).

concentration_product([Coefficient * Reactant | Reactants], Product) :-
  Product = Coefficient * [Reactant] * ProductTail,
  concentration_product(Reactants, ProductTail).