I went to the opening workshops of CAV 2019 in New York this year (on my own dime mind you!) after getting back from joining Ben on the long trail for a bit. The tutorials on Rosette and Liquid Haskell were really fun. Very interesting technology. Also got some good ramen and mochi pudding, so it’s all good. Big Gay Ice Cream was dece.

## Day 1 workshops

Calin Belta http://sites.bu.edu/hyness/calin/.Has a new book. Control of Temporal logic systems. Automata. Optimized. Partition space into abstraction. Bisimulation https://www.springer.com/gp/book/9783319507620

Control Lyapunov Function (CLF) – guarantees you are going where you want to go

Control Barrier Function – Somehow controls regions you don’t want to go to.

Lyapunov function based trajectory optimization. You somehow have (Ames 2014) http://ames.gatech.edu/CLF_QP_ACC_final.pdf Is this it?

Differential flatness , input output linearization

Sadradiini worked there.

Temproal logic with

#### Rise of Temporal Logic

Linear Temporal Logic vs CTL

Fixpoint logic,

Buchi automata – visit accepting state infinite times

equivalency to first order logic

monadic logic, propositions only take 1 agrument. Decidable. Lowenheim. Quantifier elimination. Bounded Mondel property

Languages: ForSpec, SVA, LDL, PSL, Sugar

Monadic second order logic (MSO).

method of tableau

#### Sadraddini

Polytopic regions. Can push forward the dynmaics around a trajectory and the polytope that you lie in. RRT/LQR polytopic tree. pick random poitn. Run.

Evauating branching heuristics

branch and prune icp. dreal.

branch and prune. Take set. Propagate constraints until none fire.

branching heuristics on variables

largest first, smearing, lookahead. Try different options see who has the most pruning. Non clear that helped that muhc

QF_NRA. dreal benchmarks. flyspeck, control, robotics, SMT-lib

http://capd.sourceforge.net/capdDynSys/docs/html/index.html

#### Rosette

commands: saolver adied programming

verify – find an input on which the assertions fail. exists x. not safe

debug – Minimal unsat core if you give an unsat query. x=42/\ safe(s,P(x))$ we know thia is unsat because of previous step

solve – exists v si.t safe(v)

synthesis – exists e forall x safe(x,P(x))

define-symbolic, assert, verify, debug, solve, sythesis

Rosette. Alloy is also connected to her. Z Method. Is related to relational logic?

https://homes.cs.washington.edu/~emina/media/cav19-tutorial/index.html

http://emina.github.io/rosette/

Building solver aided programming tool.

symbolic compiler. reduce program all possible paths to a constraint

Cling – symbolic execution engine for llvm

implement intepreter in rosette

Symbolic virtual machine

layering of languages. DSL. library (shallow) embedding. interpreter (deep) embedding.

deep embedding for sythesis.

I can extract coq to rosette?

how does it work?

reverse and filter keeping only positive queries.

symbolic execution vs bounded model checking

symbolic checks every possible branch of the program. Cost is expoentntial

CBMC.

type driven state merging. Merge instances of primitiv types. (like BMC), value types structurally ()

instance Merge Int, Bool, Real — collect up SMT context

vs. Traversable f => Merge (f c) – do using Traversable

symbolic union a set of guarded values with diskoint guard.

merging union. at most one of any shape. bounded by number of possible shapes.

puts some branching in rosette and some branch (on primitives) in SMT.

symbolic propfiling. Repair the encdoing.

tools people have built.

veify radiation

strategy generation. That’s interesting. builds good rewrite rules.

serval.

certikso komodo keystone. fintie programss

IS rosette going to be useful for my work? coooooould be

### Liquid Haskell

https://ranjitjhala.github.io/

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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 |
{-# LANGUAGE GADTs, DataKinds, PolyKinds #-} {-@ LIQUID "--reflection" @-} {-@ LIQUID "--short-names" @-} {-@ LIQUID "--ple" @-} {-@ type TRUE = {v: Bool | v = True }@-} {-@ type NonEmpty a = {v : [a] | len v > 0} @-} {-@ head :: NonEmpty a -> a @-} head (x : _) = x {-@ measure f :: Int -> Int @-} f x = 2 * x {-@ true :: TRUE @-} true = True -- impl x y = x ==> y -- {-@ congruence :: Int -> Int -> TRUE @-} -- congruence x y = (x == y) ==> (f x == f y) -- {-@ (==>) :: {x : Bool |} -> {y : Bool |} -> {z : Bool | z = x ==> y} @-} -- x ==> y = (not x) || y -- aws automated reaosning group {- nullaway uber. sadowski google static anaylis infer faecobook give programmer early refinement types why and how to use how to implement refinement types mostly like floyd hoare logic types + predicates = refinement type t := {x:b | p} erefinemed b x : t -> t -- refined function type linear arithemtic congruence axioms emit a bunch of verification conditions (VC) p1 => p2 => p3 ... SMT can tell if VC is alwasy true -} {-@ type Zero = {v : Int | v == 0} @-} {-@ zero :: Zero @-} zero = (0 :: Int) -- why? {-@ type NAT = {v: Int | v >= 0} @-} {-@ nats :: [Nat] @-} nats = [0,1,1,1] :: [Int] {- subtype in an environemnt Gamma, t1 is a subtype of t2 x are vairables are in scope. /\x |- {v | q} <= {v | r} True => -} {-@ plus :: x : Int -> y : Int -> {v : Int | v = x + y} @-} plus :: Int -> Int -> Int plus x y = x + y -- measure. uninterpeteyd function called measure. -- {-@ measure vlen :: Vector a -> Int @-} -- {-@ at :: vec :Vector a -> {i : Nat | i < vlen vec} -> @-} -- {-@ size :: vec : Vector a -> {n : Nat | n == vlen vec} @-} {- horn contrints infer Collections and Higher and order fucntions reduce :: (a -> b -> a) -> a -> [b] -> a type a is an invaraint that holds on initial acc and indictively on f Huh. That is true. -- Huh. I could prove sum formulas this way. sum'' = vec = let is = range 0 (size vec) add = \tot i -> ot + at vec i properties of data structures size of of a list allow uninterpetyed functions inside refinements { measre length} LISTNE a = {v : [a] | 0 < length v} measure yields refined constructions [] :: {v : [a] | legnth v = 0} --} {- Q: measure? Q : environment? Q : where is standard libraru? no foralls anywhere? All in decidable fragment p : ([a],[a]) | (fst p) + (snd p) == lenght xs measures fst and snd interpeter impossible :: {v : String | false} -> a imperative language interpolation /inlcude folder has prelude basic values {v : Int | lo <= v && v < hi } invaraint properties of structures encoe invraints in constructor data OrdPair = OP {opX :: Int, opY :: Int} {-@ data OrdPair = OP {opX :: Int, opY :: {v : Int | opX < v}@-} class Liquid Int class Liquid Bool class Liquid ... Real? {-@ @-} Liquid Relations? { } data OList {-@data OList a LB = Empt | :< {oHd :: {v : a | LB = v} oTl :: OList a oHd } @-} {-@ {oHd :: a, oTl :: OList {v : a | oHd < v} }@-} GADTs? -} data MyList a where Nil :: MyList a {-@ Cons :: v : a -> MyList {x : a | x < v} -> MyList a @-} Cons :: a -> MyList a -> MyList a test :: MyList Int test = Cons 2 (Cons 1 Nil) {- abstracting the invaraint from the data structure parametrzie by relations data [a]<rel :: a -> a -> Bool> where = [] | (:) {hd :: } rel != is unique list {\x y -> x >= y} type level lambdas!? .... uh.... maybe. reflecting singletons into liquid? termination metrics / [length xs + len ys] -- merge sort {-@ Half a s = }@-} Oncey ou have temrination proofs you have proofs of correctness Propositions as Types Plus commutes is trivial {n = n + n} -} {-@ easyProof :: {True} @-} easyProof = () -- hot damn. I mean this is in it's legerdomain. But prettttty sweet. {-@ commute :: x : Int -> y : Int -> {x + y = y + x} @-} commute :: Int -> Int -> () commute x y = () {-@ reflect mysum @-} {-@ mysum :: Nat -> Nat @-} mysum :: Int -> Int mysum 0 = 0 -- if n <= 0 then 0 else 2 * n + (mysum (n - 1)) mysum n = 2 * n + (mysum (n - 1)) -- what is going on here? why do I need _? {-@ mysumpf :: _ -> {mysum 0 = 0 } @-} -- mysumpf :: Proof mysumpf _ = let x = mysum 0 in x {-@ mysumpf' :: {mysum 3 = 12 } @-} -- mysumpf :: Proof mysumpf' = () {-@ reflect fastsum @-} {-@ fastsum :: Nat -> Nat @-} fastsum :: Int -> Int fastsum n = n * (n + 1) type Proof = () {- {-@ pfsum :: x : Nat -> {fastsum x = mysum x} @-} pfsum :: Int -> Proof pfsum 0 = () -- let _ = fastsum 0 in let _ = mysum 0 in () pfsum n = pfsum (n-1) -} {-@ pfsum :: x : Nat -> {fastsum x = mysum x} @-} pfsum :: Int -> Proof pfsum 0 = () -- let _ = fastsum 0 in let _ = mysum 0 in () pfsum n = pfsum (n-1) {- reflection reflect takes the prcondition of sum and dumps it as the poscondition sum3 _ = let s0 =sum 0 s1 = sum 1 s2 = sum 3 -- all are going to be in scope. z3 will connect the dots. using proof combinatos from Proof Combinators long chains of claculations reflection of singletons data SS s where {-@ SZero :: {v : Int | v = 0} -> SS 'Zero @-} SZero :: Int -> SS 'Zero {-@ SZero :: {v : Int | v = 0} -> SS 'S a @-} SZero :: Int -> SS 'Zero proof by induction sum n = n * (n + 1)/2 2 * sum n = n * (n + 1) point free liquid types (.) :: (a -> b) -> (a -> ) ? Can I abstract over predicates like this? ({v:a | p} -> {s:}) -> Vectors cauchy schwartz -} data V2 a = V2 a a {-@ reflect dot @-} dot (V2 x y) (V2 x' y') = x * x' + y * y' {-@ reflect vplus @-} vplus (V2 x y) (V2 x' y') = V2 (x + x') (y + y') {-@ reflect smul @-} smul s (V2 x' y') = V2 (s * x') (s * y') {- {-@ cauchy :: x : V2 Int -> y : V2 Int -> {(dot x y) * (dot x y) <= (dot x x) * (dot y y) } @-} cauchy :: V2 Int -> V2 Int -> Proof cauchy x y = let q = dotpos (vplus x y) in let r = dotpos (vplus x (smul (-1 :: Int) y)) in (\_ _ -> ()) q r -} -- {-@ square :: Int -> Nat @-} -- basiclly the same thing {-@ reflect square @-} square :: Int -> Int square x = x * x {-@ sqpos :: x: Int -> {square x >= 0} @-} sqpos :: Int -> () sqpos x = () {-@ dotpos :: x: V2 Int -> {dot x x >= 0} @-} dotpos :: V2 Int -> () dotpos x = () {-@ dotsym :: x: V2 Int -> y : V2 Int -> {dot x y = dot y x} @-} dotsym :: V2 Int -> V2 Int -> () dotsym x y = () {-@ vpluscomm :: x: V2 Int -> y : V2 Int -> {vplus x y = vplus y x} @-} vpluscomm :: V2 Int -> V2 Int -> () vpluscomm x y = () {-@ dotlin :: x: V2 Int -> y : V2 Int -> z : V2 Int -> {dot (vplus x y) z = dot x z + dot y z} @-} dotlin :: V2 Int -> V2 Int -> V2 Int -> () dotlin x y z = () {- What else is interesting to prove? verify stuff about ODEs? fold [1 .. t] where t = 10 could give little spiel about how dynamical systems are like imperative programming get some rationals. profunctor p a b a -> b are refined functions I should learn how to abstract over typeclasses. Verified typeclasses? SMT has built in rationals prob? -} data Rat = Rat Int Int {-@ reflect rplus @-} rplus :: Rat -> Rat -> Rat rplus (Rat x y) (Rat x' y') = Rat (x*y' + x'*y) (y * y') {-@ reflect rmul @-} rmul :: Rat -> Rat -> Rat rmul (Rat x y) (Rat x' y') = Rat (x*x') (y * y') data Nat' = S Nat' | Z {-@ measure nlen @-} {-@ nlen :: Nat' -> Nat @-} nlen :: Nat' -> Int nlen Z = 0 nlen (S x) = 1 + (nlen x) {- -- failing? -- crash: SMTLIB2 respSat = Error "line 31 column 169: unknown sort 'Main.SNat'" data SNat a where SZ :: SNat 'Z SS :: SNat x -> SNat ('S x) -} {-@ reflect conv @-} {-@ conv :: x : Nat -> {v : Nat' | nlen v = x} @-} conv :: Int -> Nat' conv 0 = Z conv x = S (conv (x-1)) -- It's an isomorphism {-@ pfconv :: x : Nat -> {nlen (conv x) = x} @-} pfconv :: Int -> Proof pfconv 0 = () pfconv x = pfconv (x - 1) {-@ pfconv' :: x : Nat' -> {conv (nlen x) = x} @-} pfconv' :: Nat' -> Proof pfconv' Z = () pfconv' (S x) = pfconv' x {-@ reflect plus' @-} plus' :: Nat' -> Nat' -> Nat' plus' Z x = x plus' (S x) y = S (plus' x y) {-@ plusz' :: x : Nat' -> {plus' x Z = plus' Z x} @-} plusz' :: Nat' -> Proof plusz' Z = () plusz' (S x) = plusz' x {-@ pluscomm' :: x : Nat' -> y : Nat' -> {plus' x y = plus' y x} / [nlen x, nlen y] @-} pluscomm' :: Nat' -> Nat' -> Proof pluscomm' Z y = plusz' y pluscomm' (S x) (S y) = const (pluscomm' (S x) y) $ const (pluscomm' x (S y)) $ pluscomm' x y -- const () $ const (plus' (S x) (S y)) $ const (plus' x (S y)) (plus' x y) -- const (pluscomm' (S x) y) $ const (pluscomm' x (S y)) $ pluscomm' x y -- flip const is proof combinator .== {-let q = pluscomm' x (S y) in let w = pluscomm' (S x) y in let r = pluscomm' x y in (\b n m -> ()) q w r -- ? Was this necessary? -} pluscomm' x Z = plusz' x -- {-@ data Iso = @-} data Iso a b = Iso { to :: a -> b, from :: b -> a, p1 :: Proof, p2 :: Proof} {- We also have type level lambdas. refinement polymorphism LH is somewhat like singletons in the sense there is a manual reflection step. In singletons the manual reflection is in the Sing type in LH it is kind of all over the place. (+) has a type. Where is it defined? How does it know that the Haskell function + is the same as the SMT solver function? Coq and Agda and Idris type checking is powered quite a bit by an internal unification engine explicit annotation may lessen the burden somewhat SMT solvers as a unification engine structure unification vs uninterpeted functions. f a ~ Int is not a valid Haskell constraint. Maybe with the unmatchable arrow it is? In a funny sense, there is a difference between Just and (+ 1). One being a constructor means we can match out of it Just :: a ->> b (+ 1) :: Int -> Int -} -- test' :: (f a ~ Int) => () -- test' = () |

Liquid Haskell – What is?

another thing we could do is galois connections between refinements. Pos, Zero, Neg <-> Int

Liquid Haskell uses SMT solvers to resolve it’s type checking requirements.

Agda et al also work very much via unification. Unification is a broad term but it’s true.

It also has a horn clause solver for inference. Every language needs some kind of inference or you’d go insane. Also it is piggybacking on haskell

It’s not as magical as I thought? Like seeing the magicians trick. It really does understand haskell code. Like it isn’t interpretting it. When it knows facts about how (+) works, that is because the refined type was put in by hand in the prelude connecting it to SMT facts. What is imported by liquid haskell?

The typing environment is clutch. You need to realize what variables are in scope and what their types are, because that is all the SMT can use to push through type checking requirements.

Installing the stack build worked for me. It takes a while . I couldn’t get cabal install to work, because I am not l33t.

Uninterpeted functions. Unmatchability?

It wouldn’t be haskell without a bunch of compiler directives. It is somewhat difficult to find in a single cohesive place what all the syntax, and directives are from liquid haskell. Poking around it best.

- ple
- reflection
- no-termination
- higherorder – what is this?

https://github.com/ucsd-progsys/230-wi19-web course notes

https://github.com/ucsd-progsys/liquid-sf some of software foundations

https://nikivazou.github.io/publications.html niki vazou’s pubs. Check out refinement reflection

https://nikivazou.github.io/static/Haskell17/law-abiding-instances.pdf draft work? Shows stuff about typeclasses. This is a haskell 2017 paper though

https://arxiv.org/pdf/1701.03320 intro to liquid haskell. Interesting to a see a different author’s take

http://goto.ucsd.edu/~nvazou/presentations/ presentations. They are fairly similar to one another.

Liquid haskell gives us the ability to put types on stuff that wasn’t possible before.

Linearity :: f :: {a -> b | f (s ^* a) == s ^* (f a) }

Pullback. {(a,b) | f a == g b}

Equalizer

Many things in categoruy theory rely on the exists unique. Do we have functiona extensionality in Liquid haskell?

product : {(a,b) | f q = x, g q = y, => }

Pushing the boundaries on what liquid haskell can do sounds fun.

Equalizer. The eqaulizer seems prominents in sheaves. Pre-sheaves are basically functors. Sheaves require extra conditions. Restriction maps have to work? Open covers seem important

type Equalizer f g a b = {(e :: a , eq :: a -> b) | f (eq e) = g (eq e) }

I think both the type a and eq are special. e is like an explcit parametrization.

type Eq f g a = {e :: a | f e = g e} I think this is more in the spirit. Use f and g both as measures.

presheaf is functor. But then sheaf is functor that

(a, Eq (F a) (G a)). typelevel equalizer? All types a that F and G agree on.

https://ncatlab.org/nlab/show/equalizer

https://blog.functorial.com/posts/2012-02-19-What-If-Haskell-Had-Equalizers.html

Records are sheaves – Jon Sterling. Records have subtyping. This gives you a toplogy feeling thing.

https://www.slideshare.net/jonsterling/galois-tech-talk-vinyl-records-in-haskell-and-type-theory

What about purescript records?

{foo | a} {bar | a} -> intersection = {foo bar | b} can inhabit either

union is

or do you want closed records? union is union of fields. intersection is intersection of fields.

In this case a cover would be a set of records with possibly overlapping fields whose combined labels cover the whle space we want to talk about. consistency condition of sheaf/equalizer is that overlapping records fields have to match. I guess { q.foo = r.foo } ?There is a way to combine all the stuff up. This is exactly what Ghrist was getting at with tables. Tables with shared columns.

data R1 = R1 {foo :: Int, bar :: Int}

{ (r1 :: R1, r2 :: R2) | (foo r1) = (foo r2) } — we manitain duplicates across records.

{. }

if you have a “cover” {foo bar |} {bar fred} {gary larry} whose in

https://www.sciencedirect.com/science/article/pii/S1571066108005264

Sheaves. As a model of concurrency? Gaguen paper.

sheaves as constraint satisfcation? sheafifcation. Constraint solving as a way of fusing the local constraints to be globally consistent.

sheaves as records

sheaves as data fusion

http://www.cs.bham.ac.uk/~mhe/papers/barbados.pdf

Escardo. Compact data types are those finitely searchable

Continuous funcitons are ~computable? Productive?

http://www.paultaylor.eu/ASD/foufct/

http://www.paultaylor.eu/~pt/prafm/

typed recursion theory toplogy

typed computatabiltity theory

Topological notions in computation. Dictionary of terms realted decidable, searchable, semi decidablee

cs.ioc.ee/ewscs/2012/escardo/slides.pdf

https://en.wikipedia.org/wiki/Computable_topology

Through NDArray overloading, a significant fragment of numpy code is probably verifiable.

Start with functional arithmetic programs.

Need to inspect function annotations to know how to build input type.

@verify() tag

Use (Writer a) style monad.

If statements are branching. We are again approaching inspecting functions via probing. But what if we lazily probe. At every __bool__ point, we run a z3 program to determine if there is an avaiable bool left possible (we don’t need to inspect dead code regions. Also would be cool to mention it is a dead region). Curious. We’re reflecting via Z3.

Loops present a problem. Fixed loops are fine. but what about loops that depend on the execution? for i in range(n). I guess again we can hack it…? Maybe. range only takes an integer. we don’t have overload access.

Maybe we need to go into a full eval loop. utterly deconstructing the function and evaluating it statelemnt by statement.

(compare :: a -> a -> Comparison). We could select a choice based on if there is a new one avaialable. Requires access to external store. We lose the thread. How can we know a choice was made? How can we know what the choice was? Did it ask var1 or var2? We can probably do it in python via access to a global store. But in haskell?

while loops take invariant annotations.

It would be cool to have a program that takes

pre conditions. Post ocnditions, but then also a Parameter keyword to declare const variables as deriveable. exists parameter. forall x precondition x => post condition.

Parameter could be of a type to take a dsl of reasonable computations. Perhaps with complexity predicates. and then interpretting the parameter defines the computation.

Or simpler case is parameter is an integer. a magic number.

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 |
@pre(lambda x: None) @post(lambda r: r >= 0) def square(x): return x**2 @verify(pre, post) # Easier. because now we can also verify the individual function. Call Z3 at function definition time. def pre(f,cond): if(VERIFCAIOTN_ON) return fnew def fnew(x): if(VERIFICATION_ON): if(x == VerificationEnv): newenv = x.copy new.add_pre(cond(x.var)) newVar = Z3.variable() newenv.add(newVar == f(x.var)) else: return f(x) def post(f, cond): def fnew(x): if x == VerifcationEnv: Z3.findmodel(not cond(x.var), x.env) if can't find one: we're good. x.env.append(cond(x.var)) return x else: assert(False, model, function name, function postcondition code.) #overloading assignment. isn't a problem. class VerifyArray(): #numpy Z3 shim. #termination requires measure decreasing at every recursive call. #arbaitrary loops? How to deal with those? #maybe a hierarchy of envs to make it easier on z3. Like it doesn't need to give the whole program history if the local use is good enough. class VerificationEnv(): self.var = [] self.pre = [] self.post = [] |