-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRewriting.lp
88 lines (54 loc) · 2.11 KB
/
Rewriting.lp
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
require open lisa2dedukti.FOL;
require open lisa2dedukti.prelude;
constant symbol RedForm : TYPE;
constant symbol redForm : Set;
rule τ redForm ↪ RedForm;
symbol norm : Formula → RedForm;
constant symbol RedTop : RedForm;
constant symbol RedBot : RedForm;
constant symbol RedOr : (List redForm) → RedForm;
constant symbol RedNeg : RedForm → RedForm;
constant symbol RedForall : (Term → RedForm) → RedForm;
constant symbol RedExists : (Term → RedForm) → RedForm;
// ≔ λ x, prf (seq (ϕ x) (ψ x)) → prf (seq (ϕ t) (ψ t)) ;
// Builtin
// Syntactic sugar - And, Iff, Implies, ExistsOne
rule And $l ↪ Neg (Or (map Neg $l));
rule Iff $ϕ $ψ ↪ And ((Implies $ϕ $ψ) ⸬ (Implies $ψ $ϕ) ⸬ Nil);
rule Implies $ϕ $ψ ↪ Or ((Neg $ϕ) ⸬ $ψ ⸬ Nil) ;
rule ExistsOne $f ↪ Forall (λ y, (Exists (λ x, Iff (Equality x y) ($f x))));
// Rewriting rules
rule Or Nil ↪ Top;
// A1 - Commutativité
// A2 - Associativité
symbol flatFormula : Formula → RedForm;
symbol flatten : List formula → List redForm ;
rule flatFormula (Or $l) ↪ (RedOr (flatten $l));
rule flatFormula (Neg $x) ↪ (RedNeg (flatFormula $x));
rule flatFormula Top ↪ RedTop;
rule flatFormula Bot ↪ RedBot;
rule flatten Nil ↪ Nil;
rule flatten ((Or $l1) ⸬ $l2) ↪ append (flatten $l1) (flatten $l2);
rule flatten ($x ⸬ $l) ↪ (flatFormula $x) ⸬ (flatten $l);
/*
rule flatten ((Neg $x) ⸬ $l) ↪ (RedNeg (flatFormula $x)) ⸬ (flatten $l);
rule flatten (Bot ⸬ $l) ↪ RedBot ⸬ (flatten $l);
rule flatten (Top ⸬ $l) ↪ RedTop ⸬ (flatten $l);
*/
rule norm $f ↪ flatFormula $f;
compute norm (Or (Or (Top ⸬ (Or ((Neg Top) ⸬ Top ⸬ Nil) ) ⸬ Nil) ⸬ Bot ⸬ (Or (Bot ⸬ (Neg Bot) ⸬ Nil)) ⸬ Nil));
compute λ (x:Formula), (norm (Or (x ⸬ (Or (Top ⸬ Bot ⸬ Nil)) ⸬ Nil)));
compute λ (x:Formula), (norm (Or (x ⸬ Top ⸬ Bot ⸬ Nil)));
symbol RemoveDuplicate : RedForm → RedForm;
symbol RemoveX (x:RedForm) (l: List redForm): RedForm;
//rule RemoveX $x ($y ⸬ $l) ↪
// A3 -
// rule Or
/*
// A4 -
// rule
// A5
rule Neg (Neg $x) ↪ $x;
rule Neg Bot ↪ Top;
rule Neg Top ↪ Bot;
*/