ctl.pl 2.26 KB
Newer Older
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
1 2 3 4 5 6
:- module(
  ctl,
  [
    % grammar
    ctl/1,
    % command
7 8 9 10 11
    add_ctl/1,
    delete_ctl/1,
    delete_ctl/0,
    list_ctl/0,
    % API
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
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
    normalize_query/3
  ]
).

:- grammar(ctl).

ctl('EX'(E)) :-
  ctl(E).

ctl('EF'(E)) :-
  ctl(E).

ctl('EG'(E)) :-
  ctl(E).

ctl('EU'(E, F)) :-
  ctl(E),
  ctl(F).

ctl('AX'(E)) :-
  ctl(E).

ctl('AF'(E)) :-
  ctl(E).

ctl('AG'(E)) :-
  ctl(E).

ctl('AU'(E, F)) :-
  ctl(E),
  ctl(F).

ctl(not(E)) :-
  ctl(E).

ctl(E /\ F) :-
  ctl(E),
  ctl(F).

ctl(E \/ F) :-
  ctl(E),
  ctl(F).

ctl(E -> F) :-
  ctl(E),
  ctl(F).

ctl(reachable(E)) :-
  ctl(E).
:- doc('reachable(φ) is equivalent to EF(φ)').

ctl(oscil(E)) :-
  ctl(E).
:- doc('oscil(φ) is equivalent to AG((φ -> EF(not φ)) /\\\\ (not φ -> EF(φ))),
        i.e. AG(EF(φ) /\\\\ EF(not φ))').

ctl(checkpoint(E, F)) :-
  ctl(E),
  ctl(F).
:- doc('checkpoint(φ, ψ) is equivalent to not EU(not φ, ψ)').

ctl(E) :-
  object(E).


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
add_ctl(Formula) :-
  biocham_command,
  type(Formula, ctl),
  doc('Adds a CTL formula to the currently declared CTL specification.'),
  add_item([kind: ctl_spec, item: Formula]).


delete_ctl(Formula) :-
  biocham_command,
  type(Formula, ctl),
  doc('Removes a CTL formula to the currently declared CTL specification.'),
  find_item([id: Id, type: ctl_spec, item: Formula]),
  delete_item(Id).


delete_ctl :-
  biocham_command,
  doc('Removes all formulae from the current CTL specification.'),
  % model: current_model?
  delete_items([kind: ctl_spec]).


list_ctl :-
  biocham_command,
  doc('Prints out all formulae from the current CTL specification.'),
  % model: current_model?
  list_items([kind: ctl_spec]).


SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
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
normalize_query(Query, NQuery, SLeaves) :-
  normalize_query(Query, NQuery, [], Leaves),
  sort(Leaves, SLeaves).


normalize_query(reachable(Q), QQ, L1, L2) :-
  !,
  normalize_query('EF'(Q), QQ, L1, L2).

normalize_query(oscil(Q), QQ, L1, L2) :-
  !,
  normalize_query('AG'('EF'(Q) /\ 'EF'(not(Q))), QQ, L1, L2).

normalize_query(checkpoint(A, B), QQ, L1, L2) :-
  !,
  normalize_query(not('EU'(not(A), B)), QQ, L1, L2).

normalize_query(Q, Q, L, [Q | L]) :-
  atomic(Q),
  !.

normalize_query(Q, QQ, L1, L2) :-
  Q =.. [Functor | Args],
  % maplist(normalize_query, Args, QArgs),
  foldl(normalize_query, Args, QArgs, L1, L2),
  QQ =.. [Functor | QArgs].