Ticket #2296: Proof_default.hs

File Proof_default.hs, 11.4 KB (added by NeilMitchell, 5 years ago)
Line 
1{-# LANGUAGE NoMonomorphismRestriction, MultiParamTypeClasses, FlexibleContexts, FlexibleInstances, UndecidableInstances, Rank2Types, EmptyDataDecls, FunctionalDependencies #-}
2{-# OPTIONS_GHC -fno-warn-missing-methods -fno-warn-overlapping-patterns #-}
3
4module Proof_default where
5import Prelude hiding (($),(/))
6import Data.List
7{- # LINE 212 "E:\\Neil\\thesis\\proof.tex" # -}
8-- !defines ["eval"]
9-- !typesigFunction []
10-- !implementsFunction ["eval","|"]
11
12eval (Call f xs)  | f == "error" = Bottom
13                   | otherwise = eval $ body f / (args f, xs)
14
15
16{- # LINE 188 "E:\\Neil\\thesis\\proof.tex" # -}
17-- !defines ["eval"]
18 -- !typesigFunction []
19 -- !implementsFunction ["eval"]
20
21e''1 (Make c xs) = Val c (map e''1 xs)
22
23
24{- # LINE 112 "E:\\Neil\\thesis\\proof.tex" # -}
25-- !defines ["isBottom","valCtor","propTaut","satE'","satE","satV'","satV","sat"]
26-- !typesigFunction ["isBottom","valCtor","propTaut","satE'","satE","satV'","satV","sat"]
27-- !implementsFunction ["isBottom","valCtor","propTaut","satE'","satE","satV'","satV"]
28
29isBottom :: Val -> Bool
30isBottom Bottom = True
31isBottom (Val c xs) = any isBottom xs
32
33valCtor :: Val -> Maybe CtorName
34valCtor (Val c xs) = Just c
35valCtor Bottom = Nothing
36
37propTaut :: (alpha -> Bool) -> Prop alpha -> Bool
38propTaut f x = (propTrue :: Prop ()) == propMap (propBool . f) x
39
40satE' :: Prop (Sat Expr) -> Bool
41satE' = propTaut satE
42
43satE :: Sat Expr -> Bool
44satE (Sat x k) = sat (eval x) k
45
46satV' :: Prop (Sat Val) -> Bool
47satV' = propTaut satV
48
49satV :: Sat Val -> Bool
50satV (Sat v k) = sat v k
51
52sat :: Val -> Constraint -> Bool
53
54sat = undefined -- stub
55
56{- # LINE 84 "E:\\Neil\\thesis\\proof.tex" # -}
57-- !defines ["eval","uneval"]
58 -- !typesigFunction ["eval","uneval"]
59 -- !implementsFunction ["data","|","eval","Val","->","uneval"]
60
61data Val  =  Val CtorName [Val]
62          |  Bottom
63
64data Expr  =  Make CtorName [Expr]
65           |  Call FuncName [Expr]
66           |  Var  VarName
67           |  Case Expr [Alt]
68
69data Alt = Alt CtorName [VarName] Expr
70
71e''3 :: Expr -> Val
72e''3 (Make c xs   ) = Val c (map e''3 xs)
73e''3 (Call f xs)  | f == "error" = Bottom
74                  | otherwise = e''3 $ body f / (args f, xs)
75e''3 (Case x as   ) = case e''3 x of
76    Val c xs -> e''3 $ head [y / (vs, map uneval xs) | Alt c' vs y <- as, c == c']
77    Bottom -> Bottom
78
79uneval :: Val -> Expr
80uneval (Val c xs)  = Make c (map uneval xs)
81uneval Bottom      = Call "error" []
82
83
84{- # LINE 9 "E:\\Neil\\thesis\\proof.tex" # -}
85-- !defines ["infixr","freeVars","body","args","var","ctors","precond","prePost","pre","reduce","red","substP","-<","|>","<|","propAnd","propAnds","propMap","propTrue","propBool","propLit","propOr","propOrs","propFalse"]
86-- !typesigFunction ["$","freeVars","body","args","var","ctors","precond","prePost","pre","reduce","red","substP","-<","|>","<|","propOr","propAnd","propOrs","propAnds","propMap","propFalse","propTrue","propBool","propLit"]
87-- !implementsFunction ["import","infixr","class","instance","type","data"]
88
89-- HIDE import Prelude hiding (($),(/))
90-- HIDE import Data.List
91
92infixr 1  $
93infixr 0  ==>
94class Implies a where (==>) :: a -> a -> Bool
95($) :: (a -> b) -> a -> b
96
97instance Implies Bool
98instance Implies (Prop a)
99
100type FuncName = String
101type CtorName = String
102type VarName = String
103
104freeVars :: Expr -> [String]
105body   :: FuncName  -> Expr
106args   :: FuncName  -> [VarName]
107var    :: VarName   -> Maybe (Expr, Selector)
108ctors  :: CtorName  -> [CtorName]
109type Selector  =  (CtorName, Int)
110
111precond   :: FuncName -> Prop (Sat VarName)
112prePost   :: FuncName -> Constraint -> Prop (Sat VarName)
113pre ::  Expr -> Prop (Sat Expr)
114reduce    :: Prop (Sat Expr) -> Prop (Sat VarName)
115red :: Expr -> Constraint -> Prop (Sat VarName)
116substP :: Eq alpha => [(alpha,beta)] -> Prop (Sat alpha) -> Prop (Sat beta)
117
118data Sat alpha = Sat alpha Constraint
119instance Eq a => Eq (Sat a)
120
121(-<)  :: alpha -> [CtorName] -> Prop (Sat alpha)
122(|>)  :: Selector -> Constraint -> Constraint
123(<|)  :: CtorName -> Constraint -> Prop (Sat Int)
124
125data Prop alpha
126instance Eq a => Eq (Prop a)
127
128propAnd, propOr           :: Prop alpha -> Prop alpha -> Prop alpha
129propAnds, propOrs         :: [Prop alpha] -> Prop alpha
130propMap                   :: (alpha -> Prop beta) -> Prop alpha -> Prop beta
131propTrue, propFalse       :: Prop alpha
132propBool                  :: Bool -> Prop alpha
133propLit                   :: alpha -> Prop alpha
134
135data Constraint = Constraint
136
137class Subst a b c | c -> b, c -> a, a -> b where (/) :: a -> b -> c
138instance Subst Expr ([VarName], [Expr]) Expr
139instance Subst a b c => Subst (Prop a) b (Prop c)
140instance (Eq a, Eq b) => Subst (Sat a) ([a], [b]) (Sat b)
141
142instance Eq Val
143instance Eq Expr
144
145($) = undefined -- stub
146freeVars = undefined -- stub
147body = undefined -- stub
148args = undefined -- stub
149var = undefined -- stub
150ctors = undefined -- stub
151precond = undefined -- stub
152prePost = undefined -- stub
153pre = undefined -- stub
154reduce = undefined -- stub
155red = undefined -- stub
156substP = undefined -- stub
157(-<) = undefined -- stub
158(|>) = undefined -- stub
159(<|) = undefined -- stub
160propOr = undefined -- stub
161propAnd = undefined -- stub
162propOrs = undefined -- stub
163propAnds = undefined -- stub
164propMap = undefined -- stub
165propFalse = undefined -- stub
166propTrue = undefined -- stub
167propBool = undefined -- stub
168propLit = undefined -- stub
169
170{- # LINE 76 "E:\\Neil\\thesis\\proof.tex" # -}
171-- !defines ["auto_1"]
172auto_1 = error
173 where
174
175{- # LINE 108 "E:\\Neil\\thesis\\proof.tex" # -}
176-- !defines ["auto_7"]
177auto_7 = x / (vs,ys)
178 where
179 x = undefined
180 vs = undefined
181 ys = undefined
182
183{- # LINE 146 "E:\\Neil\\thesis\\proof.tex" # -}
184-- !defines ["auto_16"]
185auto_16 = satE' $ pre x ==> not $ isBottom $ eval x
186 where
187 x = undefined
188
189{- # LINE 151 "E:\\Neil\\thesis\\proof.tex" # -}
190-- !defines ["auto_17"]
191auto_17 = satV' $ x -< cs ==> maybe True (`elem` cs) (valCtor x)
192 where
193 x = undefined
194 cs = undefined
195
196{- # LINE 154 "E:\\Neil\\thesis\\proof.tex" # -}
197-- !defines ["auto_19"]
198auto_19 = sat (Val c xs) ((c,i) |> k) ==> sat (xs !! i) k
199 where
200 k = undefined
201 c = undefined
202 i = undefined
203 xs = undefined
204
205{- # LINE 157 "E:\\Neil\\thesis\\proof.tex" # -}
206-- !defines ["auto_21"]
207auto_21 = satV' $ (c <| k) / ([1..],xs) ==> sat (Val c xs) k
208 where
209 k = undefined
210 c = undefined
211 xs = undefined
212
213{- # LINE 162 "E:\\Neil\\thesis\\proof.tex" # -}
214-- !defines ["auto_22"]
215auto_22 = precond "error" == propFalse
216 where
217
218{- # LINE 165 "E:\\Neil\\thesis\\proof.tex" # -}
219-- !defines ["auto_23"]
220auto_23 = precond f ==> reduce $ pre $ body f
221 where
222 f = undefined
223
224{- # LINE 168 "E:\\Neil\\thesis\\proof.tex" # -}
225-- !defines ["auto_24"]
226auto_24 = satE' $ reduce x / (vs,xs) ==> satE' $ x / (vs, xs)
227 where
228 x = undefined
229 vs = undefined
230 xs = undefined
231
232{- # LINE 174 "E:\\Neil\\thesis\\proof.tex" # -}
233-- !defines ["auto_25"]
234auto_25 = not $ isBottom x ==> satE' $ pre $ uneval x
235 where
236 x = undefined
237
238{- # LINE 194 "E:\\Neil\\thesis\\proof.tex" # -}
239-- !defines ["auto_29"]
240auto_29 = satE' $ pre $ Make c xs  ==> all (satE' . pre) xs
241    -- inline |pre|
242 where
243 c = undefined
244 xs = undefined
245
246{- # LINE 194 "E:\\Neil\\thesis\\proof.tex" # -}
247-- !defines ["auto_30"]
248auto_30 = satE' $ propAnds $ map pre xs ==> all (satE' . pre) xs
249    -- inline |satE'|
250 where
251 xs = undefined
252
253{- # LINE 194 "E:\\Neil\\thesis\\proof.tex" # -}
254-- !defines ["auto_31"]
255auto_31 = and $ map satE' $ map pre xs  ==> all (satE' . pre) xs
256    -- |map f . map g == map (f . g)|
257 where
258 xs = undefined
259
260{- # LINE 194 "E:\\Neil\\thesis\\proof.tex" # -}
261-- !defines ["auto_32"]
262auto_32 = and $ map (satE' . pre) xs ==> all (satE' . pre) xs
263    -- |and . map f == all f|
264 where
265 xs = undefined
266
267{- # LINE 194 "E:\\Neil\\thesis\\proof.tex" # -}
268-- !defines ["auto_33"]
269auto_33 = all (satE' . pre) xs ==> all (satE' . pre) xs
270    -- equal
271 where
272 xs = undefined
273
274{- # LINE 219 "E:\\Neil\\thesis\\proof.tex" # -}
275-- !defines ["auto_36"]
276auto_36 = satE' $ pre $ Call f xs ==> f /= "error"
277    -- inline |pre|
278 where
279 f = undefined
280 xs = undefined
281
282{- # LINE 219 "E:\\Neil\\thesis\\proof.tex" # -}
283-- !defines ["auto_37"]
284auto_37 = satE' $ (precond f / (args f, xs)) `propAnd` propAnds (map pre xs) ==> f /= "error"
285    -- inline |satE'|
286 where
287 f = undefined
288 xs = undefined
289
290{- # LINE 219 "E:\\Neil\\thesis\\proof.tex" # -}
291-- !defines ["auto_38"]
292auto_38 = satE' (precond f / (args f, xs)) && all (satE' . pre) xs ==> f /= "error"
293    -- weaken implication
294 where
295 f = undefined
296 xs = undefined
297
298{- # LINE 219 "E:\\Neil\\thesis\\proof.tex" # -}
299-- !defines ["auto_39"]
300auto_39 = satE' (precond f / (args f, xs)) ==> f /= "error"
301 where
302 f = undefined
303 xs = undefined
304
305{- # LINE 231 "E:\\Neil\\thesis\\proof.tex" # -}
306-- !defines ["auto_42"]
307auto_42 = satE' (precond f / (args f, xs)) ==> f /= "error"
308    -- assume |f /= "error"|
309 where
310 f = undefined
311 xs = undefined
312
313{- # LINE 231 "E:\\Neil\\thesis\\proof.tex" # -}
314-- !defines ["auto_43"]
315auto_43 = satE' (precond f / (args f, xs)) ==> True
316    -- implication
317 where
318 f = undefined
319 xs = undefined
320
321{- # LINE 239 "E:\\Neil\\thesis\\proof.tex" # -}
322-- !defines ["auto_44"]
323auto_44 = satE' (precond f / (args f, xs)) ==> f /= "error"
324    -- assume |f == "error"|
325 where
326 f = undefined
327 xs = undefined
328
329{- # LINE 239 "E:\\Neil\\thesis\\proof.tex" # -}
330-- !defines ["auto_45"]
331auto_45 = satE' (precond f / (args f, xs)) ==> False
332    -- implication
333 where
334 f = undefined
335 xs = undefined
336
337{- # LINE 239 "E:\\Neil\\thesis\\proof.tex" # -}
338-- !defines ["auto_46"]
339auto_46 = not $ satE' (precond "error" / (args f, xs))
340    -- \lemma{precond/error}
341 where
342 f = undefined
343 xs = undefined
344
345{- # LINE 239 "E:\\Neil\\thesis\\proof.tex" # -}
346-- !defines ["auto_47"]
347auto_47 = not $ satE' $ (propFalse / (args f, xs))
348    -- inline |(/)|
349 where
350 f = undefined
351 xs = undefined
352
353{- # LINE 239 "E:\\Neil\\thesis\\proof.tex" # -}
354-- !defines ["auto_48"]
355auto_48 = not $ satE' propFalse
356    -- inline |satE'|
357 where
358
359{- # LINE 239 "E:\\Neil\\thesis\\proof.tex" # -}
360-- !defines ["auto_49"]
361auto_49 = not $ False
362    -- inline |not|
363 where
364
365{- # LINE 257 "E:\\Neil\\thesis\\proof.tex" # -}
366-- !defines ["auto_50"]
367auto_50 = satE' $ pre $ Call f xs ==> satE' $ pre $ body f / (args f, xs)
368    -- inline pre on LHS
369 where
370 f = undefined
371 xs = undefined
372
373{- # LINE 257 "E:\\Neil\\thesis\\proof.tex" # -}
374-- !defines ["auto_51"]
375auto_51 = satE' $ (precond f / (args f, xs)) `propAnd` propAnds (map pre xs) ==> satE' $ pre $ body f / (args f, xs)
376    -- inline |satE'|
377 where
378 f = undefined
379 xs = undefined
380
381{- # LINE 257 "E:\\Neil\\thesis\\proof.tex" # -}
382-- !defines ["auto_52"]
383auto_52 = satE' (precond f / (args f, xs)) && all (satE' . pre) xs ==> satE' $ pre $ body f / (args f, xs)
384    -- \lemma{precond}
385 where
386 f = undefined
387 xs = undefined
388
389{- # LINE 257 "E:\\Neil\\thesis\\proof.tex" # -}
390-- !defines ["auto_53"]
391auto_53 = satE' ((reduce $ pre $ body f) / (args f, xs)) && all (satE' . pre) xs ==> satE' $ pre $ body f / (args f, xs)
392    -- \lemma{reduce}
393 where
394 f = undefined
395 xs = undefined
396
397{- # LINE 257 "E:\\Neil\\thesis\\proof.tex" # -}
398-- !defines ["auto_54"]
399auto_54 = satE' (pre (body f) / (args f / xs)) && all (satE' . pre) xs ==> satE' $ pre $ body f / (args f, xs)
400    -- \lemma{pre/subst}
401 where
402 f = undefined
403 xs = undefined