| 1 | {-# LANGUAGE NoMonomorphismRestriction, MultiParamTypeClasses, FlexibleContexts, FlexibleInstances, UndecidableInstances, Rank2Types, EmptyDataDecls, FunctionalDependencies #-} |
|---|
| 2 | {-# OPTIONS_GHC -fno-warn-missing-methods -fno-warn-overlapping-patterns #-} |
|---|
| 3 | |
|---|
| 4 | module Proof_default where |
|---|
| 5 | import Prelude hiding (($),(/)) |
|---|
| 6 | import Data.List |
|---|
| 7 | {- # LINE 212 "E:\\Neil\\thesis\\proof.tex" # -} |
|---|
| 8 | -- !defines ["eval"] |
|---|
| 9 | -- !typesigFunction [] |
|---|
| 10 | -- !implementsFunction ["eval","|"] |
|---|
| 11 | |
|---|
| 12 | eval (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 | |
|---|
| 21 | e''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 | |
|---|
| 29 | isBottom :: Val -> Bool |
|---|
| 30 | isBottom Bottom = True |
|---|
| 31 | isBottom (Val c xs) = any isBottom xs |
|---|
| 32 | |
|---|
| 33 | valCtor :: Val -> Maybe CtorName |
|---|
| 34 | valCtor (Val c xs) = Just c |
|---|
| 35 | valCtor Bottom = Nothing |
|---|
| 36 | |
|---|
| 37 | propTaut :: (alpha -> Bool) -> Prop alpha -> Bool |
|---|
| 38 | propTaut f x = (propTrue :: Prop ()) == propMap (propBool . f) x |
|---|
| 39 | |
|---|
| 40 | satE' :: Prop (Sat Expr) -> Bool |
|---|
| 41 | satE' = propTaut satE |
|---|
| 42 | |
|---|
| 43 | satE :: Sat Expr -> Bool |
|---|
| 44 | satE (Sat x k) = sat (eval x) k |
|---|
| 45 | |
|---|
| 46 | satV' :: Prop (Sat Val) -> Bool |
|---|
| 47 | satV' = propTaut satV |
|---|
| 48 | |
|---|
| 49 | satV :: Sat Val -> Bool |
|---|
| 50 | satV (Sat v k) = sat v k |
|---|
| 51 | |
|---|
| 52 | sat :: Val -> Constraint -> Bool |
|---|
| 53 | |
|---|
| 54 | sat = 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 | |
|---|
| 61 | data Val = Val CtorName [Val] |
|---|
| 62 | | Bottom |
|---|
| 63 | |
|---|
| 64 | data Expr = Make CtorName [Expr] |
|---|
| 65 | | Call FuncName [Expr] |
|---|
| 66 | | Var VarName |
|---|
| 67 | | Case Expr [Alt] |
|---|
| 68 | |
|---|
| 69 | data Alt = Alt CtorName [VarName] Expr |
|---|
| 70 | |
|---|
| 71 | e''3 :: Expr -> Val |
|---|
| 72 | e''3 (Make c xs ) = Val c (map e''3 xs) |
|---|
| 73 | e''3 (Call f xs) | f == "error" = Bottom |
|---|
| 74 | | otherwise = e''3 $ body f / (args f, xs) |
|---|
| 75 | e''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 | |
|---|
| 79 | uneval :: Val -> Expr |
|---|
| 80 | uneval (Val c xs) = Make c (map uneval xs) |
|---|
| 81 | uneval 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 | |
|---|
| 92 | infixr 1 $ |
|---|
| 93 | infixr 0 ==> |
|---|
| 94 | class Implies a where (==>) :: a -> a -> Bool |
|---|
| 95 | ($) :: (a -> b) -> a -> b |
|---|
| 96 | |
|---|
| 97 | instance Implies Bool |
|---|
| 98 | instance Implies (Prop a) |
|---|
| 99 | |
|---|
| 100 | type FuncName = String |
|---|
| 101 | type CtorName = String |
|---|
| 102 | type VarName = String |
|---|
| 103 | |
|---|
| 104 | freeVars :: Expr -> [String] |
|---|
| 105 | body :: FuncName -> Expr |
|---|
| 106 | args :: FuncName -> [VarName] |
|---|
| 107 | var :: VarName -> Maybe (Expr, Selector) |
|---|
| 108 | ctors :: CtorName -> [CtorName] |
|---|
| 109 | type Selector = (CtorName, Int) |
|---|
| 110 | |
|---|
| 111 | precond :: FuncName -> Prop (Sat VarName) |
|---|
| 112 | prePost :: FuncName -> Constraint -> Prop (Sat VarName) |
|---|
| 113 | pre :: Expr -> Prop (Sat Expr) |
|---|
| 114 | reduce :: Prop (Sat Expr) -> Prop (Sat VarName) |
|---|
| 115 | red :: Expr -> Constraint -> Prop (Sat VarName) |
|---|
| 116 | substP :: Eq alpha => [(alpha,beta)] -> Prop (Sat alpha) -> Prop (Sat beta) |
|---|
| 117 | |
|---|
| 118 | data Sat alpha = Sat alpha Constraint |
|---|
| 119 | instance Eq a => Eq (Sat a) |
|---|
| 120 | |
|---|
| 121 | (-<) :: alpha -> [CtorName] -> Prop (Sat alpha) |
|---|
| 122 | (|>) :: Selector -> Constraint -> Constraint |
|---|
| 123 | (<|) :: CtorName -> Constraint -> Prop (Sat Int) |
|---|
| 124 | |
|---|
| 125 | data Prop alpha |
|---|
| 126 | instance Eq a => Eq (Prop a) |
|---|
| 127 | |
|---|
| 128 | propAnd, propOr :: Prop alpha -> Prop alpha -> Prop alpha |
|---|
| 129 | propAnds, propOrs :: [Prop alpha] -> Prop alpha |
|---|
| 130 | propMap :: (alpha -> Prop beta) -> Prop alpha -> Prop beta |
|---|
| 131 | propTrue, propFalse :: Prop alpha |
|---|
| 132 | propBool :: Bool -> Prop alpha |
|---|
| 133 | propLit :: alpha -> Prop alpha |
|---|
| 134 | |
|---|
| 135 | data Constraint = Constraint |
|---|
| 136 | |
|---|
| 137 | class Subst a b c | c -> b, c -> a, a -> b where (/) :: a -> b -> c |
|---|
| 138 | instance Subst Expr ([VarName], [Expr]) Expr |
|---|
| 139 | instance Subst a b c => Subst (Prop a) b (Prop c) |
|---|
| 140 | instance (Eq a, Eq b) => Subst (Sat a) ([a], [b]) (Sat b) |
|---|
| 141 | |
|---|
| 142 | instance Eq Val |
|---|
| 143 | instance Eq Expr |
|---|
| 144 | |
|---|
| 145 | ($) = undefined -- stub |
|---|
| 146 | freeVars = undefined -- stub |
|---|
| 147 | body = undefined -- stub |
|---|
| 148 | args = undefined -- stub |
|---|
| 149 | var = undefined -- stub |
|---|
| 150 | ctors = undefined -- stub |
|---|
| 151 | precond = undefined -- stub |
|---|
| 152 | prePost = undefined -- stub |
|---|
| 153 | pre = undefined -- stub |
|---|
| 154 | reduce = undefined -- stub |
|---|
| 155 | red = undefined -- stub |
|---|
| 156 | substP = undefined -- stub |
|---|
| 157 | (-<) = undefined -- stub |
|---|
| 158 | (|>) = undefined -- stub |
|---|
| 159 | (<|) = undefined -- stub |
|---|
| 160 | propOr = undefined -- stub |
|---|
| 161 | propAnd = undefined -- stub |
|---|
| 162 | propOrs = undefined -- stub |
|---|
| 163 | propAnds = undefined -- stub |
|---|
| 164 | propMap = undefined -- stub |
|---|
| 165 | propFalse = undefined -- stub |
|---|
| 166 | propTrue = undefined -- stub |
|---|
| 167 | propBool = undefined -- stub |
|---|
| 168 | propLit = undefined -- stub |
|---|
| 169 | |
|---|
| 170 | {- # LINE 76 "E:\\Neil\\thesis\\proof.tex" # -} |
|---|
| 171 | -- !defines ["auto_1"] |
|---|
| 172 | auto_1 = error |
|---|
| 173 | where |
|---|
| 174 | |
|---|
| 175 | {- # LINE 108 "E:\\Neil\\thesis\\proof.tex" # -} |
|---|
| 176 | -- !defines ["auto_7"] |
|---|
| 177 | auto_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"] |
|---|
| 185 | auto_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"] |
|---|
| 191 | auto_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"] |
|---|
| 198 | auto_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"] |
|---|
| 207 | auto_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"] |
|---|
| 215 | auto_22 = precond "error" == propFalse |
|---|
| 216 | where |
|---|
| 217 | |
|---|
| 218 | {- # LINE 165 "E:\\Neil\\thesis\\proof.tex" # -} |
|---|
| 219 | -- !defines ["auto_23"] |
|---|
| 220 | auto_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"] |
|---|
| 226 | auto_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"] |
|---|
| 234 | auto_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"] |
|---|
| 240 | auto_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"] |
|---|
| 248 | auto_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"] |
|---|
| 255 | auto_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"] |
|---|
| 262 | auto_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"] |
|---|
| 269 | auto_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"] |
|---|
| 276 | auto_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"] |
|---|
| 284 | auto_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"] |
|---|
| 292 | auto_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"] |
|---|
| 300 | auto_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"] |
|---|
| 307 | auto_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"] |
|---|
| 315 | auto_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"] |
|---|
| 323 | auto_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"] |
|---|
| 331 | auto_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"] |
|---|
| 339 | auto_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"] |
|---|
| 347 | auto_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"] |
|---|
| 355 | auto_48 = not $ satE' propFalse |
|---|
| 356 | -- inline |satE'| |
|---|
| 357 | where |
|---|
| 358 | |
|---|
| 359 | {- # LINE 239 "E:\\Neil\\thesis\\proof.tex" # -} |
|---|
| 360 | -- !defines ["auto_49"] |
|---|
| 361 | auto_49 = not $ False |
|---|
| 362 | -- inline |not| |
|---|
| 363 | where |
|---|
| 364 | |
|---|
| 365 | {- # LINE 257 "E:\\Neil\\thesis\\proof.tex" # -} |
|---|
| 366 | -- !defines ["auto_50"] |
|---|
| 367 | auto_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"] |
|---|
| 375 | auto_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"] |
|---|
| 383 | auto_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"] |
|---|
| 391 | auto_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"] |
|---|
| 399 | auto_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 |
|---|