v erification des programmes d ordre sup erieur
play

V erification des programmes dordre sup erieur Charles Grellois - PowerPoint PPT Presentation

V erification des programmes dordre sup erieur Charles Grellois (travaux r ealis es avec Dal Lago et Melli` es) Aix-Marseille Universit e - LSIS Visite des etudiants de lENS Paris-Saclay 23 novembre 2017 Charles


  1. V´ erification des programmes d’ordre sup´ erieur Charles Grellois (travaux r´ ealis´ es avec Dal Lago et Melli` es) Aix-Marseille Universit´ e - LSIS Visite des ´ etudiants de l’ENS Paris-Saclay 23 novembre 2017 Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 1 / 42

  2. Functional programs, Higher-order models Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 2 / 42

  3. Imperative vs. functional programs Imperative programs: built on finite state machines (like Turing machines). Notion of state, global memory. Functional programs: built on functions that are composed together (like in Lambda-calculus). No state (except in impure languages), higher-order: functions can manipulate functions. (recall that Turing machines and λ -terms are equivalent in expressive power) Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 3 / 42

  4. Imperative vs. functional programs Imperative programs: built on finite state machines (like Turing machines). Notion of state, global memory. Functional programs: built on functions that are composed together (like in Lambda-calculus). No state (except in impure languages), higher-order: functions can manipulate functions. (recall that Turing machines and λ -terms are equivalent in expressive power) Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 3 / 42

  5. Example: imperative factorial int fact(int n) { int res = 1; for i from 1 to n do { res = res * i; } } return res; } Typical way of doing: using a variable (change the state). Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 4 / 42

  6. Example: functional factorial In OCaml: let rec factorial n = if n <= 1 then 1 else factorial (n-1) * n;; Typical way of doing: using a recursive function (don’t change the state). In practice, forbidding global variables reduces considerably the number of bugs, especially in a parallel setting (cf. Erlang). Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 5 / 42

  7. Advantages of functional programs Very mathematical: calculus of functions. . . . and thus very much studied from a mathematical point of view. This notably leads to strong typing, a marvellous feature. Much less error-prone: no manipulation of global state. More and more used, from Haskell and Caml to Scala, Javascript and even Java 8 nowadays. Also emerging for probabilistic programming. Price to pay: analysis of higher-order constructs. Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 6 / 42

  8. Advantages of functional programs Price to pay: analysis of higher-order constructs. Example of higher-order function: map . map ϕ [0 , 1 , 2] returns [ ϕ (0) , ϕ (1) , ϕ (2)]. Higher-order: map is a function taking a function ϕ as input. Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 7 / 42

  9. Advantages of functional programs Price to pay: analysis of higher-order constructs. Function calls + recursivity = deal with stacks of stacks. . . of calls Based on λ -calculus with recursion and types: we can use its semantics to do verification Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 7 / 42

  10. Probabilistic functional programs Probabilistic programming languages are more and more pervasive in computer science: modeling uncertainty, robotics, cryptography, machine learning, AI. . . What if we add probabilistic constructs? � M p , N 1 − p � In this talk: M ⊕ p N → v Allows to simulate some random distributions, not all. To be fully general: add the two roots of probabilistic programming, drawing values at random from more probability distributions (typically on the reals), and conditioning which allows among others to do machine learning. Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 8 / 42

  11. Using higher-order functions Bending a coin in the probabilistic functional language Church: var makeCoin = function(weight) { return function() { flip(weight) ? ’h’ : ’t’ } } var bend = function(coin) { return function() { (coin() == ’h’) ? makeCoin(0.7)() : makeCoin(0.1)() } } var fairCoin = makeCoin(0.5) var bentCoin = bend(fairCoin) viz(repeat(100,bentCoin)) Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 9 / 42

  12. Roadmap 1 Semantics of linear logic for verification of deterministic functional programs 2 A type system for termination of probabilistic functional programs Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 10 / 42

  13. Modeling functional programs using higher-order recursion schemes Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 11 / 42

  14. Model-checking Approximate the program − → build a model M . Then, formulate a logical specification ϕ over the model. Aim: design a program which checks whether M � ϕ. That is, whether the model M meets the specification ϕ . Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 12 / 42

  15. An example = Main Listen Nil Listen x = if end signal() then x else Listen received data() :: x Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 13 / 42

  16. An example = Listen Nil Main Listen x = if end signal() then x else Listen received data() :: x if Nil if data if . . A tree model: . Nil data data Nil We abstracted conditionals and datatypes. The approximation contains a non-terminating branch. Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 13 / 42

  17. Finite representations of infinite trees if Nil if data if . . Nil data . data Nil is not regular: it is not the unfolding of a finite graph as if Nil if data Nil Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 14 / 42

  18. Finite representations of infinite trees if Nil if data if . . Nil data . data Nil but it is represented by a higher-order recursion scheme (HORS). Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 14 / 42

  19. Higher-order recursion schemes = Listen Nil Main Listen x = if end signal() then x else Listen received data() :: x is abstracted as � S = L Nil G = L x = if x ( L ( data x ) ) which represents the higher-order tree of actions if Nil if . . . data Nil Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 15 / 42

  20. Higher-order recursion schemes � S = L Nil G = L x = if x ( L ( data x ) ) Rewriting starts from the start symbol S : L S → G Nil Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 16 / 42

  21. Higher-order recursion schemes � S = L Nil G = L x = if x ( L ( data x ) ) if L Nil L → G Nil data Nil Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 16 / 42

  22. Higher-order recursion schemes � S = L Nil G = L x = if x ( L ( data x ) ) if Nil if if data L Nil L Nil data → G data data Nil Nil Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 16 / 42

  23. Higher-order recursion schemes � S = L Nil G = L x = if x ( L ( data x ) ) if Nil if data if �G� = . . . Nil data data Nil Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 16 / 42

  24. Higher-order recursion schemes � S = L Nil G = L x = if x ( L ( data x ) ) HORS can alternatively be seen as simply-typed λ -terms with simply-typed recursion operators Y σ : ( σ → σ ) → σ . They are also equi-expressive to pushdown automata with stacks of stacks of stacks. . . and a collapse operation. Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 16 / 42

  25. Alternating parity tree automata Checking specifications over trees Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 17 / 42

  26. Monadic second order logic MSO is a common logic in verification, allowing to express properties as: “ all executions halt ” “ a given operation is executed infinitely often in some execution ” “ every time data is added to a buffer, it is eventually processed ” Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 18 / 42

  27. Alternating parity tree automata Checking whether a formula holds can be performed using an automaton. For an MSO formula ϕ , there exists an equivalent APT A ϕ s.t. �G� ϕ iff A ϕ has a run over �G� . � APT = alternating tree automata (ATA) + parity condition. Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 19 / 42

  28. Alternating tree automata ATA: non-deterministic tree automata whose transitions may duplicate or drop a subtree. Typically: δ ( q 0 , if ) = (2 , q 0 ) ∧ (2 , q 1 ). Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 20 / 42

  29. Alternating tree automata ATA: non-deterministic tree automata whose transitions may duplicate or drop a subtree. Typically: δ ( q 0 , if ) = (2 , q 0 ) ∧ (2 , q 1 ). if q 0 if q 0 q 0 q 1 Nil if if if data if data if data if − → A ϕ . . . . . . . . . Nil data Nil data Nil data data data data Nil Nil Nil Charles Grellois (AMU - LSIS) V´ erif. d’ordre sup. 23 novembre 2017 20 / 42

Recommend


More recommend