Skip to content

Commit 494f99b

Browse files
Design document for combining priority axioms (#1937)
* Design document for combining priority axioms * Fix lost term * Fix formulas and ending Co-authored-by: Virgil Serbanuta <virgil.serbanuta>
1 parent c31693a commit 494f99b

File tree

2 files changed

+103
-1
lines changed

2 files changed

+103
-1
lines changed

docs/2020-06-22-Rewrite-Rule-Priorities.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ and we encode the rule as:
168168
∧ ¬ (∃ X₁ . φ₁(X₁) ∧ P₁(X₁))
169169
...
170170
∧ ¬ (∃ Xn . φn(Xn) ∧ Pn(Xn))
171-
psi(X)
171+
ψ(X)
172172
```
173173
Strictly speaking, we should have the left hand side of the encoding of the
174174
respective rules under `∃ Xᵢ` above, but the two forms should be
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
Combining priority axioms
2+
=========================
3+
4+
Background
5+
----------
6+
7+
If we have this chain of axioms: `α₁(X₁)⇒β₁(X₁)``αₙ(Xₙ)⇒βₙ(Xₙ)` in which
8+
all the LHS are *function-like* and *injection-based*, and all the RHS
9+
except `βₙ(Xₙ)` are *function-like*, then their combined transition is
10+
11+
```
12+
(⌈β₁(X₁)∧α₂(X₂)⌉ ∧ ⌈β₂(X₂)∧α₃(X₃)⌉ ∧ … ∧ ⌈βₙ₋₁(Xₙ₋₁)∧αₙ(Xₙ)⌉ ∧ α₁(X₁)) → ••…•βₙ(Xₙ)
13+
```
14+
15+
Also see the [Combining Rewrite Axioms](2019-09-09-Combining-Rewrite-Axioms.md)
16+
document.
17+
18+
Priorities allow writing case-based `K` code that closer resembles functional
19+
languages, i.e. it allows saying things like "Apply this rule first,
20+
if that doesn't work try this other one, if that also doesn't work try
21+
this, and so on". The `owise` attribute is a special case of this.
22+
23+
For a rule `φ(X) ⇒ ψ(X) requires P(X) [priority p]` we take the all
24+
rules at previous priorities:
25+
```
26+
φ₁(X) ⇒ ψ₁(X) requires P₁(X)
27+
...
28+
φn(X) ⇒ ψn(X) requires Pn(X)
29+
```
30+
and we encode the rule as:
31+
```
32+
φ(X) ∧ P(X)
33+
∧ ¬ (∃ X₁ . φ₁(X₁) ∧ P₁(X₁))
34+
...
35+
∧ ¬ (∃ Xn . φn(Xn) ∧ Pn(Xn))
36+
⇒ ψ(X)
37+
```
38+
39+
Also see the [Rewrite Rule Priorities](2020-06-22-Rewrite-Rule-Priorities.md)
40+
document.
41+
42+
Applying the rules
43+
------------------
44+
45+
We will examine how to compute `⌈β(X₁)∧α(X₂)⌉` where `β(X₁)` is the right
46+
hand side of a random rewrite rule and `α(X₂)` is the left hand sight of
47+
priority rewrite rule.
48+
49+
```
50+
⌈β(X₁)∧α(X₂)⌉
51+
= ⌈ β(X₁) ∧ φ(X) ∧ P(X)
52+
∧ ¬ (∃ X₁ . φ₁(X₁) ∧ P₁(X₁))
53+
...
54+
∧ ¬ (∃ Xn . φn(Xn) ∧ Pn(Xn))
55+
56+
// If β(X₁) is functional then β(X₁)∧ φ(X) = β(X₁) ∧ ⌈β(X₁)∧ φ(X)⌉
57+
= ⌈ β(X₁) ∧ ⌈β(X₁)∧ φ(X)⌉ ∧ P(X)
58+
∧ ¬ (∃ X₁ . φ₁(X₁) ∧ P₁(X₁))
59+
...
60+
∧ ¬ (∃ Xn . φn(Xn) ∧ Pn(Xn))
61+
62+
// If P is a predicate then ⌈φ∧P⌉=⌈φ⌉∧P
63+
= ⌈ β(X₁)
64+
∧ ¬ (∃ X₁ . φ₁(X₁) ∧ P₁(X₁))
65+
...
66+
∧ ¬ (∃ Xn . φn(Xn) ∧ Pn(Xn))
67+
68+
∧ ⌈β(X₁) ∧ φ(X)⌉ ∧ P(X)
69+
// φ(X) ∧ (¬ ∃ Z. α(Z)) = φ(X) ∧ (¬ ∃ Z. ⌈φ(X) ∧ α(Z)⌉)
70+
// See the Justification section in
71+
// 2018-11-08-Configuration-Splitting-Simplification.md
72+
= ⌈β(X₁)
73+
∧ ¬ (∃ X₁ . ⌈ β(X₁) ∧ φ₁(X₁) ∧ P₁(X₁) ⌉)
74+
...
75+
∧ ¬ (∃ Xn . ⌈ β(X₁) ∧ φn(Xn) ∧ Pn(Xn) ⌉)
76+
77+
∧ ⌈β(X₁) ∧ φ(X)⌉ ∧ P(X)
78+
// If P is a predicate then ⌈φ∧P⌉=⌈φ⌉∧P
79+
= ⌈β(X₁)
80+
∧ ¬ (∃ X₁ . ⌈ β(X₁) ∧ φ₁(X₁) ⌉ ∧ P₁(X₁))
81+
...
82+
∧ ¬ (∃ Xn . ⌈ β(X₁) ∧ φn(Xn) ⌉ ∧ Pn(Xn))
83+
84+
∧ ⌈β(X₁) ∧ φ(X)⌉ ∧ P(X)
85+
// If P is a predicate then ∃ X . P is a predicate
86+
// If P is a predicate then ⌈φ∧P⌉=⌈φ⌉∧P
87+
= ⌈β(X₁)⌉
88+
∧ ¬ (∃ X₁ . ⌈ β(X₁) ∧ φ₁(X₁) ⌉ ∧ P₁(X₁))
89+
...
90+
∧ ¬ (∃ Xn . ⌈ β(X₁) ∧ φn(Xn) ⌉ ∧ Pn(Xn))
91+
∧ ⌈β(X₁) ∧ φ(X)⌉ ∧ P(X)
92+
// ⌈t⌉ ∧ ⌈ t ∧ s ⌉ = ⌈ t ∧ s ⌉
93+
= ⌈β(X₁) ∧ φ(X)⌉ ∧ P(X)
94+
∧ ¬ (∃ X₁ . ⌈ β(X₁) ∧ φ₁(X₁) ⌉ ∧ P₁(X₁))
95+
...
96+
∧ ¬ (∃ Xn . ⌈ β(X₁) ∧ φn(Xn) ⌉ ∧ Pn(Xn))
97+
```
98+
99+
Usually, at least some of the existential clauses should disappear, because
100+
unification, i.e. the `⌈ β(Xi) ∧ φi(Xi) ⌉` part, will probably either succeed
101+
with a full substitution, or will fail. Of course, since we are using symbolic
102+
inputs, this is not guaranteed.

0 commit comments

Comments
 (0)