ctl.pl 1.48 KB
Newer Older
SOLIMAN Sylvain's avatar
SOLIMAN Sylvain 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
:- module(
  ctl,
  [
    % grammar
    ctl/1,
    % command
    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).


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].