SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Downloaden Sie, um offline zu lesen
A MuDDy Experience
ML Bindings to a BDD Library


       Ken Friis Larsen
     kflarsen@diku.dk

  Department of Computer Science
     University of Copenhagen


         July 15, 2009




                                   1 / 20
The Message




ML and BDDs hits a sweet spot




                            2 / 20
Background



   BuDDy
      C library for Binary Decision Diagrams by Jørn Lind-Nielsen
      State-of-art performance . . . 10 years ago
   MuDDy
      An ML interface to BuDDy
      Comes in Moscow ML, MLton, and O’Caml flavours
      Been used in many different projects over the years
   Domain Specific Embedded Language (DSEL)
      You embed a DSL in a general-purpose language




                                                                    3 / 20
Binary Decision Diagrams



   A BDD is:
       A canonical explicit directed acyclic graph representation of a
       boolean function
       A boolean expression on if-then-else normal form
   BDDs are mainly used for formal verification and hardware
   synthesis
   Excellent for representing large relations, for instance.




                                                                         4 / 20
Binary Decision Diagrams



   A BDD is:
       A canonical explicit directed acyclic graph representation of a
       boolean function
       A boolean expression on if-then-else normal form
   BDDs are mainly used for formal verification and hardware
   synthesis
   Excellent for representing large relations, for instance.
   Did I mention it is a canonical representation?




                                                                         4 / 20
An Example BDD

A BDD representing (x ⇔ y) ∧ ¬z


                                   x


                          y            y



                                   z



                         0             1


With variable ordering x < y < z


                                           5 / 20
MuDDy




MuDDy supports most features from BuDDy
   Structure bdd contains functions for manipulating BDDs
   Structure fdd contains functions for manipulating finite domain
   values, represented by a set of BDDs
   Structure bvec contains functions for representing and
   manipulating machine words represented by a set of BDDs.




                                                                6 / 20
Building BDDs from SML



Building a BDD representing the expression (x ⇒ y ∧ x) ⇒ y

 val (x, y) = (bdd.ithvar 0, bdd.ithvar 1)
 val b = (x ==> y / x) ==> y




                                                             7 / 20
Building BDDs from SML



Building a BDD representing the expression (x ⇒ y ∧ x) ⇒ y

 val (x, y) = (bdd.ithvar 0, bdd.ithvar 1)
 val b = (x ==> y / x) ==> y

Given the syntactic sugar:

 infix ==> /
 val(op /, op ==>) = (bdd.AND, bdd.IMP)




                                                             7 / 20
Using BDDs to Analyse a DS(E)L




 1. Design your language
 2. Declare types for representing abstract syntax trees
 3. Design a concrete syntax
 4. Use BDDs to model the semantics of your language
        Usually that means defining a (huge) transition predicate
 5. Use BDDs to find the set of reachable states and analyse all
    reachable states in one go.




                                                                   8 / 20
Simple Guarded Command Language




   e            ::=   true | false | x | e1 op e2 | ¬e
   assignment   ::=   x1 , . . . , xn := e1 , . . . , en
   command      ::=   e ? assignment
   program      ::=   assignment
                      command1 || . . . || commandn




                                                           9 / 20
Milner’s Scheduler


                                             h1
                                        c1          c2

                     start         h0                    h2

                                        c0          c3
                                             h3




    cycler i   =    ci ∧ ¬ti   ?   ti , ci , hi := true, ¬ci , true
               ||         hi   ?   ci+1 mod N , hi := true, false




                                                                      10 / 20
SGCL Embedded in SML, Abstract syntax




type var = string
datatype boolop = AND | OR | IMP | BIIMP
datatype bexp = BVar of var
              | BBin of bexp * boolop * bexp
              | NOT of bexp
              | TRUE | FALSE
datatype command = CMD of bexp * (var * bexp) list
datatype program = PRG of (var * bexp) list * command list




                                                       11 / 20
SGCL Embedded in SML, Syntactic Sugar

fun mkBBin opr (x, y) = BBin(x, opr, y)
infix / / ==> <==>
val (op /, op /, op ==>, op <==>) =
    (mkBBin AND, mkBBin OR, mkBBin IMP, mkBBin BIIMP)

infix ::=
val op ::= = ListPair.zip

infix ?
fun g ? ass = [CMD(g, ass)]

infix ||
val op|| = op@

val $ = BVar

                                                        12 / 20
Milner’s Scheduler in SML/SGCL
val (c0, t0,...,t3, h3) = ("c0", "t0",...,"t3", "h3")

fun cycler c t h c’ =
      ($c <==> TRUE / $t <==> FALSE) ?
                ([t, c, h] ::= [TRUE, NOT($c), TRUE])
   || (($h <==> TRUE) ? ([c’, h] ::= [TRUE, FALSE]))

fun task t = $t ? ([t] ::= [FALSE])

val milner4 =
    PRG( [(c0, TRUE),   (t0, FALSE), (h0, FALSE), ... ]
         cycler c0 t0   h0 c1
      || cycler c1 t1   h1 c2
      || cycler c2 t2   h2 c3
      || cycler c3 t3   h3 c0
      || task t0 ||     task t1 || task t2 || task t3)
                                                          13 / 20
Semantics of SGCL


The semantics of a command is a predicate describing a state change
by using a ordinary variables to describe the current state and primed
variables to describe the next state.
The semantics of a program is a predicate describing the initial state,
and conjunction of the semantics of the commands.

type bdd_vars = { var: int, primed: int}
type var_map = string * bdd_vars

val commandToBDD: var_map -> command -> bdd.bdd
val programToBDD: var_map -> program -> bdd.bdd * bdd.bdd




                                                                   14 / 20
Semantics of SGCL

fun commandToBDD allVars (CMD(guard, assignments)) =
    let val changed = List.map #1 assignments
        val unchanged =
            List.foldl (fn ((v, {var, primed}), res) =>
              if mem v changed then res
              else bdd.AND(bdd.BIIMP(bdd.ithvar primed,
                                     bdd.ithvar var),
                           res))
              bdd.TRUE allVars
        val assigns =
            conj (map (fn (v,be) =>
                            bdd.BIIMP(primed v, bexp be))
                  assignments)
    in bdd.IMP(bexp guard, assigns) end


                                                       15 / 20
Finding All Reachable States

fun reachable allVars I T =
    let val renames =
            List.map (fn(_,{var,primed}) => (var, primed))
                     allVars
        val pairset = bdd.makepairSet renames
        val unprimed = bdd.makeset(List.map #var allVars)

         open bdd infix OR
         fun loop R =
             let val post = appex T R And unprimed
                 val next = R OR replace next pairset
             in if equal R next then R else loop next end
    in   loop I end



                                                       16 / 20
Putting It All Together

To find all the reachable states of a SGCL program first call
programToBDD and then reachable:

  val   milner4 = ...
  val   allVars = ...
  val   (I, T) = programToBDD allVars milner4
  val   states = reachable allVars I T

We can now easily check some invariants. For example, that if
cycler 2 holds a token, no other cycler has a token:

  val c2inv = $c2 ==> NOT($c0) / NOT($c1) / NOT($c3)
  val check_c2inv = bdd.IMP (states, bexp allVars c2inv)




                                                                17 / 20
Keeping It Honest


The construction of the mapping between DSL variables and BDDs
variables is usually where things go sour. That is, it is hard to choose
a good BDD variable ordering.

No general algorithm, but the following heuristics gives good results:
    a variable and its primed version should be next to each other in
    the ordering
    if two variables are “close” to each other in the syntax tree, they
    should be close to each other in the ordering
    if a variable occurs with high frequency in the syntax tree, it
    should be in the beginning of the ordering




                                                                      18 / 20
What About Performance?
          No. of Schedulers:    50      100     150     200

          C                     1.63    4.69    13.66   31.20
          C++                   1.66    4.82    13.89   31.51
          O’Caml (native)       1.71    5.04    14.47   32.05
          O’Caml (bytecode)     1.74    5.15    14.58   32.91
          Moscow ML             1.76    5.15    15.12   33.42

Fresh runs on current laptop:

           No. of Schedulers:    50      100     150    200

           C                     0.38    1.07    3.18   7.25
           O’Caml (native)       0.35    1.21    3.42   7.64
           O’Caml (bytecode)     0.38    1.24    3.52   7.82
           Moscow ML             0.37    1.21    3.45   7.73
           MLton                 0.38    1.29    3.68   8.14

                                                                19 / 20
Summary




  ML and BDDs hits a sweet spot
      reasonably easy to embed DSLs in ML languages
      MLs gives few surprises with respect to space usage and execution
      BDDs can be used to represent many nice abstractions
      symbolically
  SGCL is a nice way to specify finite state machines




                                                                   20 / 20

Weitere ähnliche Inhalte

Was ist angesagt?

2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_papervandna123
 
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...Ruby Meditation
 
Logic Simplification Using SOP
Logic Simplification Using SOPLogic Simplification Using SOP
Logic Simplification Using SOPAbi Malik
 
Arduino based keyboard and display interfacing
Arduino based keyboard and display interfacingArduino based keyboard and display interfacing
Arduino based keyboard and display interfacingAkash1900
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 FeaturesJan Rüegg
 
C++ language basic
C++ language basicC++ language basic
C++ language basicWaqar Younis
 
Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programsharman kaur
 
Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Geeks Anonymes
 
Digital logic design lecture 07
Digital logic design   lecture 07 Digital logic design   lecture 07
Digital logic design lecture 07 FarhatUllah27
 
Switching theory and logic design.
Switching theory and logic design.Switching theory and logic design.
Switching theory and logic design.Anto Jose Moyalan
 
C++11 concurrency
C++11 concurrencyC++11 concurrency
C++11 concurrencyxu liwei
 
B sc3 unit 3 boolean algebra
B sc3 unit 3 boolean algebraB sc3 unit 3 boolean algebra
B sc3 unit 3 boolean algebraMahiboobAliMulla
 
08 logic simplification
08 logic simplification08 logic simplification
08 logic simplificationarunachalamr16
 
All VLSI programs
All VLSI programsAll VLSI programs
All VLSI programsGouthaman V
 

Was ist angesagt? (20)

B sc ii sem unit 2(b) ba
B sc ii sem unit 2(b) baB sc ii sem unit 2(b) ba
B sc ii sem unit 2(b) ba
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_paper
 
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...
 
Logic Simplification Using SOP
Logic Simplification Using SOPLogic Simplification Using SOP
Logic Simplification Using SOP
 
Arduino based keyboard and display interfacing
Arduino based keyboard and display interfacingArduino based keyboard and display interfacing
Arduino based keyboard and display interfacing
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
 
C++ language basic
C++ language basicC++ language basic
C++ language basic
 
C++11
C++11C++11
C++11
 
Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programs
 
Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)
 
Digital logic design lecture 07
Digital logic design   lecture 07 Digital logic design   lecture 07
Digital logic design lecture 07
 
Switching theory and logic design.
Switching theory and logic design.Switching theory and logic design.
Switching theory and logic design.
 
C++ book
C++ bookC++ book
C++ book
 
Labsheet1stud
Labsheet1studLabsheet1stud
Labsheet1stud
 
C++11 concurrency
C++11 concurrencyC++11 concurrency
C++11 concurrency
 
B sc3 unit 3 boolean algebra
B sc3 unit 3 boolean algebraB sc3 unit 3 boolean algebra
B sc3 unit 3 boolean algebra
 
C++11 & C++14
C++11 & C++14C++11 & C++14
C++11 & C++14
 
08 logic simplification
08 logic simplification08 logic simplification
08 logic simplification
 
Digital logic circuits
Digital  logic  circuitsDigital  logic  circuits
Digital logic circuits
 
All VLSI programs
All VLSI programsAll VLSI programs
All VLSI programs
 

Andere mochten auch

Mining Relationships for Gold
Mining Relationships for GoldMining Relationships for Gold
Mining Relationships for Goldlmilesw
 
A MuDDy Experience - ML Bindings to a BDD Library
A MuDDy Experience - ML Bindings to a BDD LibraryA MuDDy Experience - ML Bindings to a BDD Library
A MuDDy Experience - ML Bindings to a BDD LibraryKen Friis Larsen
 
Ears, feet and injuries: The development of project based learning materials ...
Ears, feet and injuries: The development of project based learning materials ...Ears, feet and injuries: The development of project based learning materials ...
Ears, feet and injuries: The development of project based learning materials ...University of Derby
 
Sasa Nesic - PhD Dissertation Defense
Sasa Nesic - PhD Dissertation DefenseSasa Nesic - PhD Dissertation Defense
Sasa Nesic - PhD Dissertation DefenseSasa Nesic
 
Denver Marketing Mediation 1
Denver Marketing Mediation 1Denver Marketing Mediation 1
Denver Marketing Mediation 1Frank Salvatore
 
Denver Marketing Mediation 2
Denver Marketing Mediation 2Denver Marketing Mediation 2
Denver Marketing Mediation 2Frank Salvatore
 
Denver Marketing Mediation 3
Denver Marketing Mediation 3Denver Marketing Mediation 3
Denver Marketing Mediation 3Frank Salvatore
 
Prezentacja Jabber
Prezentacja JabberPrezentacja Jabber
Prezentacja Jabberbm9ib2r5
 
Toontown Slideshow
Toontown SlideshowToontown Slideshow
Toontown Slideshowguest02a449
 
Designing Effective Power Point Presentations
Designing Effective Power Point PresentationsDesigning Effective Power Point Presentations
Designing Effective Power Point PresentationsVinh Ha Nguyen Thi
 
Serwer internetowy w systemie Linux
Serwer internetowy w systemie LinuxSerwer internetowy w systemie Linux
Serwer internetowy w systemie Linuxbm9ib2r5
 

Andere mochten auch (17)

Mining Relationships for Gold
Mining Relationships for GoldMining Relationships for Gold
Mining Relationships for Gold
 
A MuDDy Experience - ML Bindings to a BDD Library
A MuDDy Experience - ML Bindings to a BDD LibraryA MuDDy Experience - ML Bindings to a BDD Library
A MuDDy Experience - ML Bindings to a BDD Library
 
Ears, feet and injuries: The development of project based learning materials ...
Ears, feet and injuries: The development of project based learning materials ...Ears, feet and injuries: The development of project based learning materials ...
Ears, feet and injuries: The development of project based learning materials ...
 
Sasa Nesic - PhD Dissertation Defense
Sasa Nesic - PhD Dissertation DefenseSasa Nesic - PhD Dissertation Defense
Sasa Nesic - PhD Dissertation Defense
 
Tagzania
TagzaniaTagzania
Tagzania
 
Denver Marketing Mediation 1
Denver Marketing Mediation 1Denver Marketing Mediation 1
Denver Marketing Mediation 1
 
Denver Marketing Mediation 2
Denver Marketing Mediation 2Denver Marketing Mediation 2
Denver Marketing Mediation 2
 
Denver Marketing Mediation 3
Denver Marketing Mediation 3Denver Marketing Mediation 3
Denver Marketing Mediation 3
 
Genealogy Marketing
Genealogy MarketingGenealogy Marketing
Genealogy Marketing
 
Landscaping Marketing 4
Landscaping Marketing 4Landscaping Marketing 4
Landscaping Marketing 4
 
Landscaping Marketing 2
Landscaping Marketing 2Landscaping Marketing 2
Landscaping Marketing 2
 
Landscaping Marketing 1
Landscaping Marketing 1Landscaping Marketing 1
Landscaping Marketing 1
 
Prezentacja Jabber
Prezentacja JabberPrezentacja Jabber
Prezentacja Jabber
 
Toontown Slideshow
Toontown SlideshowToontown Slideshow
Toontown Slideshow
 
Designing Effective Power Point Presentations
Designing Effective Power Point PresentationsDesigning Effective Power Point Presentations
Designing Effective Power Point Presentations
 
DNS
DNSDNS
DNS
 
Serwer internetowy w systemie Linux
Serwer internetowy w systemie LinuxSerwer internetowy w systemie Linux
Serwer internetowy w systemie Linux
 

Ähnlich wie A MuDDy Experience - ML Bindings to a BDD Library

Modeling An Rational Integral With Saber State Ams
Modeling An Rational Integral With Saber State AmsModeling An Rational Integral With Saber State Ams
Modeling An Rational Integral With Saber State Amsdomnitei
 
20101017 program analysis_for_security_livshits_lecture02_compilers
20101017 program analysis_for_security_livshits_lecture02_compilers20101017 program analysis_for_security_livshits_lecture02_compilers
20101017 program analysis_for_security_livshits_lecture02_compilersComputer Science Club
 
ROBDD&Charecteristics
ROBDD&CharecteristicsROBDD&Charecteristics
ROBDD&CharecteristicsIffat Anjum
 
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionEelco Visser
 
FPGA based BCH Decoder
FPGA based BCH DecoderFPGA based BCH Decoder
FPGA based BCH Decoderijsrd.com
 
Planning Under Uncertainty With Markov Decision Processes
Planning Under Uncertainty With Markov Decision ProcessesPlanning Under Uncertainty With Markov Decision Processes
Planning Under Uncertainty With Markov Decision Processesahmad bassiouny
 
Java Keeps Throttling Up!
Java Keeps Throttling Up!Java Keeps Throttling Up!
Java Keeps Throttling Up!José Paumard
 
Box2D with SIMD in JavaScript
Box2D with SIMD in JavaScriptBox2D with SIMD in JavaScript
Box2D with SIMD in JavaScriptIntel® Software
 
Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...
Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...
Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...CloudxLab
 
Low-level Shader Optimization for Next-Gen and DX11 by Emil Persson
Low-level Shader Optimization for Next-Gen and DX11 by Emil PerssonLow-level Shader Optimization for Next-Gen and DX11 by Emil Persson
Low-level Shader Optimization for Next-Gen and DX11 by Emil PerssonAMD Developer Central
 
Class 11: Deeper List Procedures
Class 11: Deeper List ProceduresClass 11: Deeper List Procedures
Class 11: Deeper List ProceduresDavid Evans
 
Parallel Evaluation of Multi-Semi-Joins
Parallel Evaluation of Multi-Semi-JoinsParallel Evaluation of Multi-Semi-Joins
Parallel Evaluation of Multi-Semi-JoinsJonny Daenen
 
Constraint Programming in Haskell
Constraint Programming in HaskellConstraint Programming in Haskell
Constraint Programming in HaskellDavid Overton
 
The TclQuadcode Compiler
The TclQuadcode CompilerThe TclQuadcode Compiler
The TclQuadcode CompilerDonal Fellows
 
Ur Domain Haz Monoids DDDx NYC 2014
Ur Domain Haz Monoids DDDx NYC 2014Ur Domain Haz Monoids DDDx NYC 2014
Ur Domain Haz Monoids DDDx NYC 2014Cyrille Martraire
 

Ähnlich wie A MuDDy Experience - ML Bindings to a BDD Library (20)

Modeling An Rational Integral With Saber State Ams
Modeling An Rational Integral With Saber State AmsModeling An Rational Integral With Saber State Ams
Modeling An Rational Integral With Saber State Ams
 
20101017 program analysis_for_security_livshits_lecture02_compilers
20101017 program analysis_for_security_livshits_lecture02_compilers20101017 program analysis_for_security_livshits_lecture02_compilers
20101017 program analysis_for_security_livshits_lecture02_compilers
 
Binary decision diagrams
Binary decision diagramsBinary decision diagrams
Binary decision diagrams
 
ROBDD&Charecteristics
ROBDD&CharecteristicsROBDD&Charecteristics
ROBDD&Charecteristics
 
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint Resolution
 
Digital Logic
Digital LogicDigital Logic
Digital Logic
 
FPGA based BCH Decoder
FPGA based BCH DecoderFPGA based BCH Decoder
FPGA based BCH Decoder
 
Planning Under Uncertainty With Markov Decision Processes
Planning Under Uncertainty With Markov Decision ProcessesPlanning Under Uncertainty With Markov Decision Processes
Planning Under Uncertainty With Markov Decision Processes
 
Compiling fµn language
Compiling fµn languageCompiling fµn language
Compiling fµn language
 
Java Keeps Throttling Up!
Java Keeps Throttling Up!Java Keeps Throttling Up!
Java Keeps Throttling Up!
 
Box2D with SIMD in JavaScript
Box2D with SIMD in JavaScriptBox2D with SIMD in JavaScript
Box2D with SIMD in JavaScript
 
Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...
Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...
Apache Spark - Basics of RDD & RDD Operations | Big Data Hadoop Spark Tutoria...
 
Low-level Shader Optimization for Next-Gen and DX11 by Emil Persson
Low-level Shader Optimization for Next-Gen and DX11 by Emil PerssonLow-level Shader Optimization for Next-Gen and DX11 by Emil Persson
Low-level Shader Optimization for Next-Gen and DX11 by Emil Persson
 
Class 11: Deeper List Procedures
Class 11: Deeper List ProceduresClass 11: Deeper List Procedures
Class 11: Deeper List Procedures
 
Parallel Evaluation of Multi-Semi-Joins
Parallel Evaluation of Multi-Semi-JoinsParallel Evaluation of Multi-Semi-Joins
Parallel Evaluation of Multi-Semi-Joins
 
Constraint Programming in Haskell
Constraint Programming in HaskellConstraint Programming in Haskell
Constraint Programming in Haskell
 
The TclQuadcode Compiler
The TclQuadcode CompilerThe TclQuadcode Compiler
The TclQuadcode Compiler
 
PECCS 2014
PECCS 2014PECCS 2014
PECCS 2014
 
Ur Domain Haz Monoids DDDx NYC 2014
Ur Domain Haz Monoids DDDx NYC 2014Ur Domain Haz Monoids DDDx NYC 2014
Ur Domain Haz Monoids DDDx NYC 2014
 
Programming Hp33s talk v3
Programming Hp33s talk v3Programming Hp33s talk v3
Programming Hp33s talk v3
 

Kürzlich hochgeladen

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 

A MuDDy Experience - ML Bindings to a BDD Library

  • 1. A MuDDy Experience ML Bindings to a BDD Library Ken Friis Larsen kflarsen@diku.dk Department of Computer Science University of Copenhagen July 15, 2009 1 / 20
  • 2. The Message ML and BDDs hits a sweet spot 2 / 20
  • 3. Background BuDDy C library for Binary Decision Diagrams by Jørn Lind-Nielsen State-of-art performance . . . 10 years ago MuDDy An ML interface to BuDDy Comes in Moscow ML, MLton, and O’Caml flavours Been used in many different projects over the years Domain Specific Embedded Language (DSEL) You embed a DSL in a general-purpose language 3 / 20
  • 4. Binary Decision Diagrams A BDD is: A canonical explicit directed acyclic graph representation of a boolean function A boolean expression on if-then-else normal form BDDs are mainly used for formal verification and hardware synthesis Excellent for representing large relations, for instance. 4 / 20
  • 5. Binary Decision Diagrams A BDD is: A canonical explicit directed acyclic graph representation of a boolean function A boolean expression on if-then-else normal form BDDs are mainly used for formal verification and hardware synthesis Excellent for representing large relations, for instance. Did I mention it is a canonical representation? 4 / 20
  • 6. An Example BDD A BDD representing (x ⇔ y) ∧ ¬z x y y z 0 1 With variable ordering x < y < z 5 / 20
  • 7. MuDDy MuDDy supports most features from BuDDy Structure bdd contains functions for manipulating BDDs Structure fdd contains functions for manipulating finite domain values, represented by a set of BDDs Structure bvec contains functions for representing and manipulating machine words represented by a set of BDDs. 6 / 20
  • 8. Building BDDs from SML Building a BDD representing the expression (x ⇒ y ∧ x) ⇒ y val (x, y) = (bdd.ithvar 0, bdd.ithvar 1) val b = (x ==> y / x) ==> y 7 / 20
  • 9. Building BDDs from SML Building a BDD representing the expression (x ⇒ y ∧ x) ⇒ y val (x, y) = (bdd.ithvar 0, bdd.ithvar 1) val b = (x ==> y / x) ==> y Given the syntactic sugar: infix ==> / val(op /, op ==>) = (bdd.AND, bdd.IMP) 7 / 20
  • 10. Using BDDs to Analyse a DS(E)L 1. Design your language 2. Declare types for representing abstract syntax trees 3. Design a concrete syntax 4. Use BDDs to model the semantics of your language Usually that means defining a (huge) transition predicate 5. Use BDDs to find the set of reachable states and analyse all reachable states in one go. 8 / 20
  • 11. Simple Guarded Command Language e ::= true | false | x | e1 op e2 | ¬e assignment ::= x1 , . . . , xn := e1 , . . . , en command ::= e ? assignment program ::= assignment command1 || . . . || commandn 9 / 20
  • 12. Milner’s Scheduler h1 c1 c2 start h0 h2 c0 c3 h3 cycler i = ci ∧ ¬ti ? ti , ci , hi := true, ¬ci , true || hi ? ci+1 mod N , hi := true, false 10 / 20
  • 13. SGCL Embedded in SML, Abstract syntax type var = string datatype boolop = AND | OR | IMP | BIIMP datatype bexp = BVar of var | BBin of bexp * boolop * bexp | NOT of bexp | TRUE | FALSE datatype command = CMD of bexp * (var * bexp) list datatype program = PRG of (var * bexp) list * command list 11 / 20
  • 14. SGCL Embedded in SML, Syntactic Sugar fun mkBBin opr (x, y) = BBin(x, opr, y) infix / / ==> <==> val (op /, op /, op ==>, op <==>) = (mkBBin AND, mkBBin OR, mkBBin IMP, mkBBin BIIMP) infix ::= val op ::= = ListPair.zip infix ? fun g ? ass = [CMD(g, ass)] infix || val op|| = op@ val $ = BVar 12 / 20
  • 15. Milner’s Scheduler in SML/SGCL val (c0, t0,...,t3, h3) = ("c0", "t0",...,"t3", "h3") fun cycler c t h c’ = ($c <==> TRUE / $t <==> FALSE) ? ([t, c, h] ::= [TRUE, NOT($c), TRUE]) || (($h <==> TRUE) ? ([c’, h] ::= [TRUE, FALSE])) fun task t = $t ? ([t] ::= [FALSE]) val milner4 = PRG( [(c0, TRUE), (t0, FALSE), (h0, FALSE), ... ] cycler c0 t0 h0 c1 || cycler c1 t1 h1 c2 || cycler c2 t2 h2 c3 || cycler c3 t3 h3 c0 || task t0 || task t1 || task t2 || task t3) 13 / 20
  • 16. Semantics of SGCL The semantics of a command is a predicate describing a state change by using a ordinary variables to describe the current state and primed variables to describe the next state. The semantics of a program is a predicate describing the initial state, and conjunction of the semantics of the commands. type bdd_vars = { var: int, primed: int} type var_map = string * bdd_vars val commandToBDD: var_map -> command -> bdd.bdd val programToBDD: var_map -> program -> bdd.bdd * bdd.bdd 14 / 20
  • 17. Semantics of SGCL fun commandToBDD allVars (CMD(guard, assignments)) = let val changed = List.map #1 assignments val unchanged = List.foldl (fn ((v, {var, primed}), res) => if mem v changed then res else bdd.AND(bdd.BIIMP(bdd.ithvar primed, bdd.ithvar var), res)) bdd.TRUE allVars val assigns = conj (map (fn (v,be) => bdd.BIIMP(primed v, bexp be)) assignments) in bdd.IMP(bexp guard, assigns) end 15 / 20
  • 18. Finding All Reachable States fun reachable allVars I T = let val renames = List.map (fn(_,{var,primed}) => (var, primed)) allVars val pairset = bdd.makepairSet renames val unprimed = bdd.makeset(List.map #var allVars) open bdd infix OR fun loop R = let val post = appex T R And unprimed val next = R OR replace next pairset in if equal R next then R else loop next end in loop I end 16 / 20
  • 19. Putting It All Together To find all the reachable states of a SGCL program first call programToBDD and then reachable: val milner4 = ... val allVars = ... val (I, T) = programToBDD allVars milner4 val states = reachable allVars I T We can now easily check some invariants. For example, that if cycler 2 holds a token, no other cycler has a token: val c2inv = $c2 ==> NOT($c0) / NOT($c1) / NOT($c3) val check_c2inv = bdd.IMP (states, bexp allVars c2inv) 17 / 20
  • 20. Keeping It Honest The construction of the mapping between DSL variables and BDDs variables is usually where things go sour. That is, it is hard to choose a good BDD variable ordering. No general algorithm, but the following heuristics gives good results: a variable and its primed version should be next to each other in the ordering if two variables are “close” to each other in the syntax tree, they should be close to each other in the ordering if a variable occurs with high frequency in the syntax tree, it should be in the beginning of the ordering 18 / 20
  • 21. What About Performance? No. of Schedulers: 50 100 150 200 C 1.63 4.69 13.66 31.20 C++ 1.66 4.82 13.89 31.51 O’Caml (native) 1.71 5.04 14.47 32.05 O’Caml (bytecode) 1.74 5.15 14.58 32.91 Moscow ML 1.76 5.15 15.12 33.42 Fresh runs on current laptop: No. of Schedulers: 50 100 150 200 C 0.38 1.07 3.18 7.25 O’Caml (native) 0.35 1.21 3.42 7.64 O’Caml (bytecode) 0.38 1.24 3.52 7.82 Moscow ML 0.37 1.21 3.45 7.73 MLton 0.38 1.29 3.68 8.14 19 / 20
  • 22. Summary ML and BDDs hits a sweet spot reasonably easy to embed DSLs in ML languages MLs gives few surprises with respect to space usage and execution BDDs can be used to represent many nice abstractions symbolically SGCL is a nice way to specify finite state machines 20 / 20