Skip to content

Commit 38dcb3f

Browse files
lemmyclaude
andcommitted
ewd998/EWD998_proof: reuse CommunityModules FunctionTheorems
Drop the local Functions.tla (it was the older copy without SumFunctionOnSet) so EXTENDS Functions resolves to the CommunityModules version, which lets EWD998_proof EXTEND the proven FunctionTheorems module. Remove the locally-restated, unproven FoldFunctionOnSet* lemmas (FoldFunctionIsFoldFunctionOnSet, ...Empty, ...Iterate, ...Union, ...Equal, ...Type) -- they were effectively axioms and are now obtained from FunctionTheorems. Keep IsAssociativeOn / IsCommutativeOn / IsIdentityOn and PlusACI as named-operator wrappers, and add a small PlusOnIntAC lemma that bundles ACI + closure + base in the shape the CM theorems' premises expect (mirrors the IntegersAC helper inside FunctionTheorems_proofs.tla). Rewrite each Sum* lemma as a short structured proof citing the CM theorem; this also closes SumIterate, SumUnion and SumEqual, whose previous proofs were commented out as failing or missing. tlapm verifies all 835 obligations in EWD998_proof.tla. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com> Signed-off-by: Markus Alexander Kuppe <github.com@lemmster.de>
1 parent e743a0a commit 38dcb3f

3 files changed

Lines changed: 50 additions & 232 deletions

File tree

specifications/ewd998/EWD998_proof.tla

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(***************************************************************************)
33
(* Proofs checked by TLAPS about the EWD998 specification. *)
44
(***************************************************************************)
5-
EXTENDS EWD998, FiniteSetTheorems, TLAPS
5+
EXTENDS EWD998, FunctionTheorems, FiniteSetTheorems, TLAPS
66

77
USE NAssumption
88

@@ -43,7 +43,10 @@ THEOREM TypeCorrect == Init /\ [][Next]_vars => []TypeOK
4343
<1>. QED BY <1>1, <1>2, PTL
4444

4545
(***************************************************************************)
46-
(* Lemmas about FoldFunction that should go to a library. *)
46+
(* Names for the algebraic properties of a binary operator over a domain. *)
47+
(* The CommunityModules theorems below (FoldFunctionOnSetAC, *)
48+
(* FoldFunctionOnSetDisjointUnion, etc.) state these premises inline; the *)
49+
(* named-operator wrappers let us cite them more readably via PlusACI. *)
4750
(***************************************************************************)
4851
IsAssociativeOn(op(_,_), S) ==
4952
\A x,y,z \in S : op(x, op(y,z)) = op(op(x,y), z)
@@ -54,52 +57,11 @@ IsCommutativeOn(op(_,_), S) ==
5457
IsIdentityOn(op(_,_), e, S) ==
5558
\A x \in S : op(e,x) = x
5659

57-
LEMMA FoldFunctionIsFoldFunctionOnSet ==
58-
ASSUME NEW op(_,_), NEW base, NEW fun
59-
PROVE FoldFunction(op, base, fun) = FoldFunctionOnSet(op, base, fun, DOMAIN fun)
60-
61-
LEMMA FoldFunctionOnSetEmpty ==
62-
ASSUME NEW op(_,_), NEW base, NEW fun
63-
PROVE FoldFunctionOnSet(op, base, fun, {}) = base
64-
65-
LEMMA FoldFunctionOnSetIterate ==
66-
ASSUME NEW op(_,_),
67-
NEW S, IsFiniteSet(S), NEW T,
68-
NEW base \in T, NEW fun \in [S -> T],
69-
NEW inds \in SUBSET S, NEW e \in inds,
70-
IsAssociativeOn(op, T), IsCommutativeOn(op, T), IsIdentityOn(op, base, T)
71-
PROVE FoldFunctionOnSet(op, base, fun, inds)
72-
= op(fun[e], FoldFunctionOnSet(op, base, fun, inds \ {e}))
73-
74-
LEMMA FoldFunctionOnSetUnion ==
75-
ASSUME NEW op(_,_),
76-
NEW S, IsFiniteSet(S), NEW T,
77-
NEW base \in T, NEW fun \in [S -> T],
78-
NEW inds1 \in SUBSET S, NEW inds2 \in SUBSET S, inds1 \cap inds2 = {},
79-
IsAssociativeOn(op, T), IsCommutativeOn(op, T), IsIdentityOn(op, base, T)
80-
PROVE FoldFunctionOnSet(op, base, fun, inds1 \cup inds2)
81-
= op(FoldFunctionOnSet(op, base, fun, inds1), FoldFunctionOnSet(op, base, fun, inds2))
82-
83-
LEMMA FoldFunctionOnSetEqual ==
84-
ASSUME NEW op(_,_),
85-
NEW S, IsFiniteSet(S), NEW T, NEW base \in T,
86-
NEW f \in [S -> T], NEW g \in [S -> T],
87-
NEW inds \in SUBSET S,
88-
\A x \in inds : f[x] = g[x]
89-
PROVE FoldFunctionOnSet(op, base, f, inds) = FoldFunctionOnSet(op, base, g, inds)
90-
91-
LEMMA FoldFunctionOnSetType ==
92-
ASSUME NEW op(_,_),
93-
NEW S, NEW T, IsFiniteSet(S),
94-
NEW base \in T, NEW fun \in [S -> T],
95-
NEW inds \in SUBSET S,
96-
\A x,y \in T : op(x,y) \in T
97-
PROVE FoldFunctionOnSet(op, base, fun, inds) \in T
98-
9960
(***************************************************************************)
100-
(* The provers have trouble applying these generic lemmas to the specific *)
101-
(* instances required for the spec so we restate them for the operators *)
102-
(* that appear in the definition of the inductive invariant. *)
61+
(* Specializations of FunctionTheorems' generic FoldFunctionOnSet* *)
62+
(* theorems to the (+, 0) monoid on Int/Nat that underlies the spec's *)
63+
(* Sum operator. Restating them as Sum* lemmas avoids dragging the AC *)
64+
(* premises through every call site of the inductive invariant proof. *)
10365
(***************************************************************************)
10466
LEMMA NodeIsFinite == IsFiniteSet(Node)
10567
BY FS_Interval DEF Node
@@ -113,6 +75,24 @@ LEMMA PlusACI ==
11375
/\ IsIdentityOn(+, 0, Int)
11476
BY DEF IsAssociativeOn, IsCommutativeOn, IsIdentityOn
11577

78+
(***************************************************************************)
79+
(* Closure + ACI + neutral element of (+, 0) on Nat and Int, in the form *)
80+
(* expected by the FoldFunctionOnSet* theorem premises. (FunctionTheorems *)
81+
(* uses an analogous local lemma in its own proofs.) *)
82+
(***************************************************************************)
83+
LEMMA PlusOnIntAC ==
84+
/\ 0 \in Int
85+
/\ \A x,y \in Int : x+y \in Int
86+
/\ \A x,y \in Int : x+y = y+x
87+
/\ \A x,y,z \in Int : x + (y+z) = (x+y) + z
88+
/\ \A x \in Int : 0 + x = x
89+
BY PlusACI DEF IsAssociativeOn, IsCommutativeOn, IsIdentityOn
90+
91+
LEMMA PlusOnNatClosure ==
92+
/\ 0 \in Nat
93+
/\ \A x,y \in Nat : x+y \in Nat
94+
OBVIOUS
95+
11696
LEMMA SumEmpty ==
11797
ASSUME NEW fun
11898
PROVE Sum(fun, {}) = 0
@@ -122,7 +102,11 @@ LEMMA SumIterate ==
122102
ASSUME NEW fun \in [Node -> Int],
123103
NEW inds \in SUBSET Node, NEW e \in inds
124104
PROVE Sum(fun, inds) = fun[e] + Sum(fun, inds \ {e})
125-
\* BY FoldFunctionOnSetIterate, NodeIsFinite, PlusACI DEF Sum (* fails *)
105+
<1>1. IsFiniteSet(inds)
106+
BY NodeIsFinite, FS_Subset
107+
<1>2. \A j \in inds : fun[j] \in Int
108+
OBVIOUS
109+
<1>. QED BY <1>1, <1>2, FoldFunctionOnSetAC, PlusOnIntAC, IsaM("iprover") DEF Sum
126110

127111
LEMMA SumSingleton ==
128112
ASSUME NEW fun \in [Node -> Int], NEW x \in Node
@@ -133,25 +117,40 @@ LEMMA SumUnion ==
133117
ASSUME NEW fun \in [Node -> Int],
134118
NEW inds1 \in SUBSET Node, NEW inds2 \in SUBSET Node, inds1 \cap inds2 = {}
135119
PROVE Sum(fun, inds1 \cup inds2) = Sum(fun, inds1) + Sum(fun, inds2)
120+
<1>1. IsFiniteSet(inds1) /\ IsFiniteSet(inds2)
121+
BY NodeIsFinite, FS_Subset
122+
<1>2. \A j \in inds1 \cup inds2 : fun[j] \in Int
123+
OBVIOUS
124+
<1>. QED BY <1>1, <1>2, FoldFunctionOnSetDisjointUnion, PlusOnIntAC, IsaM("iprover") DEF Sum
136125

137126
LEMMA SumEqual ==
138127
ASSUME NEW f \in [Node -> Int], NEW g \in [Node -> Int],
139128
NEW inds \in SUBSET Node,
140129
\A x \in inds : f[x] = g[x]
141130
PROVE Sum(f, inds) = Sum(g, inds)
142-
\* BY FoldFunctionOnSetEqual, NodeIsFinite DEF Sum (* fails *)
131+
<1>1. IsFiniteSet(inds)
132+
BY NodeIsFinite, FS_Subset
133+
<1>. QED BY <1>1, FoldFunctionOnSetEqual, Zenon DEF Sum
143134

144135
LEMMA SumIsInt ==
145136
ASSUME NEW fun \in [Node -> Int],
146137
NEW inds \in SUBSET Node
147138
PROVE Sum(fun, inds) \in Int
148-
BY FoldFunctionOnSetType, NodeIsFinite, Isa DEF Sum
139+
<1>1. IsFiniteSet(inds)
140+
BY NodeIsFinite, FS_Subset
141+
<1>2. \A j \in inds : fun[j] \in Int
142+
OBVIOUS
143+
<1>. QED BY <1>1, <1>2, FoldFunctionOnSetType, PlusOnIntAC, IsaM("iprover") DEF Sum
149144

150145
LEMMA SumIsNat ==
151146
ASSUME NEW fun \in [Node -> Nat],
152147
NEW inds \in SUBSET Node
153148
PROVE Sum(fun, inds) \in Nat
154-
BY FoldFunctionOnSetType, NodeIsFinite, \A x,y \in Nat: x+y \in Nat, IsaM("blast") DEF Sum
149+
<1>1. IsFiniteSet(inds)
150+
BY NodeIsFinite, FS_Subset
151+
<1>2. \A j \in inds : fun[j] \in Nat
152+
OBVIOUS
153+
<1>. QED BY <1>1, <1>2, FoldFunctionOnSetType, PlusOnNatClosure, IsaM("iprover") DEF Sum
155154

156155
LEMMA SumZero ==
157156
ASSUME NEW fun \in [Node -> Int], NEW inds \in SUBSET Node,

specifications/ewd998/Functions.tla

Lines changed: 0 additions & 176 deletions
This file was deleted.

specifications/ewd998/manifest.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,6 @@
170170
"features": [],
171171
"models": []
172172
},
173-
{
174-
"path": "specifications/ewd998/Functions.tla",
175-
"features": [],
176-
"models": []
177-
},
178173
{
179174
"path": "specifications/ewd998/SmokeEWD998.tla",
180175
"features": [],

0 commit comments

Comments
 (0)