-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlannerSemantic.v
More file actions
143 lines (112 loc) · 4.86 KB
/
Copy pathPlannerSemantic.v
File metadata and controls
143 lines (112 loc) · 4.86 KB
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
(* SPDX-License-Identifier: MPL-2.0 *)
(* Copyright (c) Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk> *)
(** * VeriSimDB Planner — Full Q1 semantic equivalence
Mechanises FULL Q1 (`planner_logical_physical_equivalence`) on top
of Q1-lite (Planner.v): not just structural preservation, but
SEMANTIC equivalence — executing the optimized plan against any
state yields the same result as executing the original plan.
** The Q1-lite → Q1-full gap
Q1-lite (Planner.v) proves `optimize` is a permutation. That
captures the structural fact: no nodes added, no nodes dropped.
But it does NOT prove semantic equivalence — for that, we need to
know what "executing a node" MEANS.
** Approach
The audit found Planner::optimize is a deterministic single-pass
[stable_sort_by] over modality execution priority. Crucially,
each filter node restricts the result set; set restriction is
COMMUTATIVE. We axiomatise this as [exec_node_comm] and derive
semantic equivalence from Q1-lite's permutation property via the
classical "fold-commutative-is-permutation-invariant" lemma.
This covers the audit-identified operator-semantics gaps as a
UNIFORM commutativity axiom:
- Equality / Range / Fulltext (field comparisons) — clearly
commute (intersection of sets).
- Similarity (HNSW k-NN) — commutes when applied as a
post-filter on the candidate set. The k-bound interaction
with other filters is order-independent at the set level.
- Traversal (graph reachability) — commutes at the set level
(reachability set is invariant under filter intersection).
- ProofVerification — commutes (a proof either holds or
doesn't; intersection is commutative).
** Cross-doc: echo-types
Full Q1 = result-set echo invariance under optimization. The
abstract echo-types analogue is [EchoNoSectionGeneric.agda]
(sections-up-to-equivalence) plus [EchoCost.agda] (lift cost).
Tropical-resource-typing repo is the home for the cost-side
algebra. See [formal/CROSS-REPO-MAP.adoc].
Tracking: hyperpolymath/verisimdb#77 + Q1 row.
*)
Require Import Coq.Lists.List.
Require Import Coq.Sorting.Permutation.
Import ListNotations.
(** ** Domain (reusing Planner.v abstractions) *)
Parameter modality : Type.
Parameter condition : Type.
Parameter octad : Type.
Definition node : Type := (modality * list condition)%type.
Definition plan : Type := list node.
Definition state : Type := list octad.
(** ** Per-node execution semantics
[exec_node n s] applies node [n]'s conditions to candidate state
[s], returning the filtered subset. *)
Parameter exec_node : node -> state -> state.
(** Spec axiom — set restrictions COMMUTE.
Applying node n1 then n2 yields the same state as n2 then n1.
Faithful to the operational reality: each modality filter is a
set-restriction operation, and set intersection is commutative
regardless of operator type (Equality, Similarity, Traversal,
ProofVerification, …). *)
Axiom exec_node_comm :
forall n1 n2 s, exec_node n1 (exec_node n2 s) = exec_node n2 (exec_node n1 s).
(** ** Plan execution
Apply each node's exec_node in sequence. *)
Fixpoint exec_plan (p : plan) (s : state) : state :=
match p with
| [] => s
| n :: rest => exec_plan rest (exec_node n s)
end.
(** ** Optimizer (axiomatised from Planner.v) *)
Parameter optimize : plan -> plan.
Axiom optimize_is_permutation :
forall p, Permutation p (optimize p).
(** ** Helper: exec_plan is invariant under permutation of nodes *)
Theorem exec_plan_perm_invariant :
forall p1 p2 s,
Permutation p1 p2 ->
exec_plan p1 s = exec_plan p2 s.
Proof.
intros p1 p2 s Hperm.
generalize dependent s.
induction Hperm; intros s; simpl.
- reflexivity.
- apply IHHperm.
- rewrite exec_node_comm. reflexivity.
- rewrite IHHperm1, IHHperm2. reflexivity.
Qed.
(** ** Q1-full: planner_semantic_equivalence
For ANY plan [p] and ANY state [s], executing the optimized plan
yields the same state as executing the original. *)
Theorem planner_semantic_equivalence :
forall p s, exec_plan (optimize p) s = exec_plan p s.
Proof.
intros p s.
apply exec_plan_perm_invariant.
apply Permutation_sym.
apply optimize_is_permutation.
Qed.
(** ** Bonus: planner_set_membership_preserved
A specific octad is in the optimized plan's result iff it is in
the original plan's result. This is the witness-level
equivalence — for any predicate, "is this octad in the output?"
yields the same answer for both plans. *)
Theorem planner_set_membership_preserved :
forall p s o,
In o (exec_plan (optimize p) s) <-> In o (exec_plan p s).
Proof.
intros p s o.
rewrite planner_semantic_equivalence.
split; auto.
Qed.
(** ** Print Assumptions guard *)
Print Assumptions planner_semantic_equivalence.
Print Assumptions planner_set_membership_preserved.