reaction_rules.pl 3.89 KB
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
:- module(
  reaction_rules,
  [
    reaction/1,
    basic_reaction/1,
    solution/1,
    patch_solution/2,
    kinetics/1,
    simple_kinetics/1,
    op(800, xfx, for),
    op(700, xfx, <=),
    op(750, xfx, =>),
    op(750, xfx, <=>),
    op(700, xfy, =)
  ]
).


:- grammar(reaction).


reaction(Kinetics for BasicReaction) :-
  kinetics(Kinetics),
  basic_reaction(BasicReaction).

reaction(Name : Kinetics for BasicReaction) :-
  name(Name),
  kinetics(Kinetics),
  basic_reaction(BasicReaction).

reaction(Name : BasicReaction) :-
  name(Name),
  basic_reaction(BasicReaction).

reaction(BasicReaction) :-
  basic_reaction(BasicReaction).


:- grammar(basic_reaction).


basic_reaction(Solution0 =[ Solution1 ]=> Solution2) :-
  solution(Solution0),
  solution(Solution1),
  solution(Solution2).

basic_reaction(Solution0 <=[ Solution1 ]=> Solution2) :-
  solution(Solution0),
  solution(Solution1),
  solution(Solution2).

basic_reaction(Solution0 => Solution1) :-
  solution(Solution0),
  solution(Solution1).

basic_reaction(Solution0 <=> Solution1) :-
  solution(Solution0),
  solution(Solution1).


:- grammar(solution).


solution('_').

solution(Solution0 + Solution1) :-
  solution(Solution0),
  solution(Solution1).

solution(Integer * Object) :-
  integer(Integer),
  object(Object).

solution(Object) :-
  object(Object).


patch_solution(Solution0 + Solution1, NewSolution0 + NewSolution1) :-
  !,
  patch_solution(Solution0, NewSolution0),
  patch_solution(Solution1, NewSolution1).

patch_solution(Solution0 - Solution1, NewSolution) :-
  !,
  patch_solution(Solution0, Solution1, NewSolution).

patch_solution(Solution, Solution).


patch_solution(Solution0 + Solution1, Solution2, Solution0 + NewSolution) :-
  !,
  patch_solution(Solution1, Solution2, NewSolution).

patch_solution(Solution0 * Solution1, Solution2, Solution0 * NewSolution) :-
  !,
  patch_solution(Solution1, Solution2, NewSolution).

patch_solution(Solution0 - Solution1, Solution2, NewSolution) :-
  !,
  patch_solution(Solution0, Solution1 - Solution2, NewSolution).

patch_solution(Solution0, Solution1, Solution0 - Solution1).


:- grammar(kinetics).


kinetics(SimpleKinetics) :-
  simple_kinetics(SimpleKinetics).

kinetics((SimpleKinetics0, SimpleKinetics1)) :-
  simple_kinetics(SimpleKinetics0),
  simple_kinetics(SimpleKinetics1).


:- grammar(simple_kinetics).


simple_kinetics(SimpleKinetics0 + SimpleKinetics1) :-
  simple_kinetics(SimpleKinetics0),
  simple_kinetics(SimpleKinetics1).

simple_kinetics(SimpleKinetics0 - SimpleKinetics1) :-
  simple_kinetics(SimpleKinetics0),
  simple_kinetics(SimpleKinetics1).

simple_kinetics(SimpleKinetics0 * SimpleKinetics1) :-
  simple_kinetics(SimpleKinetics0),
  simple_kinetics(SimpleKinetics1).

simple_kinetics(SimpleKinetics0 / SimpleKinetics1) :-
  simple_kinetics(SimpleKinetics0),
  simple_kinetics(SimpleKinetics1).

simple_kinetics(SimpleKinetics0 ^ SimpleKinetics1) :-
  simple_kinetics(SimpleKinetics0),
  simple_kinetics(SimpleKinetics1).

simple_kinetics(min(SimpleKinetics0, SimpleKinetics1)) :-
  simple_kinetics(SimpleKinetics0),
  simple_kinetics(SimpleKinetics1).

simple_kinetics(max(SimpleKinetics0, SimpleKinetics1)) :-
  simple_kinetics(SimpleKinetics0),
  simple_kinetics(SimpleKinetics1).

simple_kinetics(log(SimpleKinetics)) :-
  simple_kinetics(SimpleKinetics).

simple_kinetics(exp(SimpleKinetics)) :-
  simple_kinetics(SimpleKinetics).

simple_kinetics(cos(SimpleKinetics)) :-
  simple_kinetics(SimpleKinetics).

simple_kinetics(sin(SimpleKinetics)) :-
  simple_kinetics(SimpleKinetics).

simple_kinetics('MA'(SimpleKinetics)) :-
  simple_kinetics(SimpleKinetics).

simple_kinetics('MM'(SimpleKinetics)) :-
  simple_kinetics(SimpleKinetics).

simple_kinetics('H'(SimpleKinetics0, SimpleKinetics1)) :-
  simple_kinetics(SimpleKinetics0),
  simple_kinetics(SimpleKinetics1).

simple_kinetics([Object]) :-
  object(Object).

simple_kinetics(Number) :-
  number(Number).

simple_kinetics(Name) :-
  name(Name).