(Lec 4) Binary Decision Diagrams: Manipulation

Similar documents
Lecture 11 Binary Decision Diagrams (BDDs)

CSE 332. Sorting. Data Abstractions. CSE 332: Data Abstractions. QuickSort Cutoff 1. Where We Are 2. Bounding The MAXIMUM Problem 4

Factorising FACTORISING.

CS 573 Automata Theory and Formal Languages

Lecture 6: Coding theory

Logic Synthesis and Verification

1 PYTHAGORAS THEOREM 1. Given a right angled triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides.

Project 6: Minigoals Towards Simplifying and Rewriting Expressions

For a, b, c, d positive if a b and. ac bd. Reciprocal relations for a and b positive. If a > b then a ab > b. then

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

Improper Integrals. The First Fundamental Theorem of Calculus, as we ve discussed in class, goes as follows:

18.06 Problem Set 4 Due Wednesday, Oct. 11, 2006 at 4:00 p.m. in 2-106

Designing finite automata II

Counting Paths Between Vertices. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

(Lec 9) Multi-Level Min III: Role of Don t Cares

Convert the NFA into DFA

CS 360 Exam 2 Fall 2014 Name

Review of Gaussian Quadrature method

22: Union Find. CS 473u - Algorithms - Spring April 14, We want to maintain a collection of sets, under the operations of:

How do we solve these things, especially when they get complicated? How do we know when a system has a solution, and when is it unique?

Logic Synthesis and Verification

CARLETON UNIVERSITY. 1.0 Problems and Most Solutions, Sect B, 2005

Unit 4. Combinational Circuits

Chapter 4 State-Space Planning

expression simply by forming an OR of the ANDs of all input variables for which the output is

CS 2204 DIGITAL LOGIC & STATE MACHINE DESIGN SPRING 2014

Now we must transform the original model so we can use the new parameters. = S max. Recruits

CS 491G Combinatorial Optimization Lecture Notes

Bases for Vector Spaces

Regular expressions, Finite Automata, transition graphs are all the same!!

p-adic Egyptian Fractions

6.5 Improper integrals

I1 = I2 I1 = I2 + I3 I1 + I2 = I3 + I4 I 3

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.

10. AREAS BETWEEN CURVES

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2

Parse trees, ambiguity, and Chomsky normal form

Properties of Integrals, Indefinite Integrals. Goals: Definition of the Definite Integral Integral Calculations using Antiderivatives

Homework 3 Solutions

EE 108A Lecture 2 (c) W. J. Dally and P. Levis 2

CMSC 330: Organization of Programming Languages

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

Exam Review. John Knight Electronics Department, Carleton University March 2, 2009 ELEC 2607 A MIDTERM

Lecture 3. In this lecture, we will discuss algorithms for solving systems of linear equations.

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9.

Outline Data Structures and Algorithms. Data compression. Data compression. Lossy vs. Lossless. Data Compression

Lecture 3: Equivalence Relations

How do we solve these things, especially when they get complicated? How do we know when a system has a solution, and when is it unique?

Propositional models. Historical models of computation. Application: binary addition. Boolean functions. Implementation using switches.

Proportions: A ratio is the quotient of two numbers. For example, 2 3

2.4 Theoretical Foundations

1. Logic verification

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

Common intervals of genomes. Mathieu Raffinot CNRS LIAFA

Numbers and indices. 1.1 Fractions. GCSE C Example 1. Handy hint. Key point

Lecture 3. XML Into RDBMS. XML and Databases. Memory Representations. Memory Representations. Traversals and Pre/Post-Encoding. Memory Representations

Designing Information Devices and Systems I Spring 2018 Homework 7

I 3 2 = I I 4 = 2A

Data Structures LECTURE 10. Huffman coding. Example. Coding: problem definition

x dx does exist, what does the answer look like? What does the answer to

Surds and Indices. Surds and Indices. Curriculum Ready ACMNA: 233,

Polynomials. Polynomials. Curriculum Ready ACMNA:

Designing Information Devices and Systems I Discussion 8B

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

Discrete Structures, Test 2 Monday, March 28, 2016 SOLUTIONS, VERSION α

Bridging the gap: GCSE AS Level

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

Basic Derivative Properties

Implication Graphs and Logic Testing

Tutorial Worksheet. 1. Find all solutions to the linear system by following the given steps. x + 2y + 3z = 2 2x + 3y + z = 4.

Linear Algebra Introduction

Handout: Natural deduction for first order logic

Nondeterminism and Nodeterministic Automata

3 Regular expressions

Lecture 2e Orthogonal Complement (pages )

Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem 2/16/15

The graphs of Rational Functions

CSC2542 State-Space Planning

Mathematics Number: Logarithms

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science

Coalgebra, Lecture 15: Equations for Deterministic Automata

Unit #9 : Definite Integral Properties; Fundamental Theorem of Calculus

Let s divide up the interval [ ab, ] into n subintervals with the same length, so we have

1 Nondeterministic Finite Automata

GRUPOS NANTEL BERGERON

Project 3: Using Identities to Rewrite Expressions

Surface maps into free groups

If we have a function f(x) which is well-defined for some a x b, its integral over those two values is defined as

Lecture 2 : Propositions DRAFT

The Regulated and Riemann Integrals

Lecture 1. Functional series. Pointwise and uniform convergence.

Interpreting Integrals and the Fundamental Theorem

First Midterm Examination

AP Calculus BC Chapter 8: Integration Techniques, L Hopital s Rule and Improper Integrals

Quadratic Forms. Quadratic Forms

NON-DETERMINISTIC FSA

Global alignment. Genome Rearrangements Finding preserved genes. Lecture 18

Algorithms & Data Structures Homework 8 HS 18 Exercise Class (Room & TA): Submitted by: Peer Feedback by: Points:

2.4 Linear Inequalities and Interval Notation

Transcription:

(Le 4) Binry Deision Digrms: Mnipultion Wht you know Bsi BDD t struture DAG representtion How vrile orering + reution = nonil A few immeite pplitions eg, trivil tutology heking Wht you on t know Algorithms to uil one effiiently Most useful implementtion triks for effiieny (Thnks to Rny Brynt & Krl Bre for nie BDD pis+slies) R. Rutenr 2, CMU 8-76, Fll 2 Copyright Notie Ro A. Rutenr, 2 All rights reserve. You my not mke opies of this mteril in ny form without my express permission. R. Rutenr 2, CMU 8-76, Fll 2 2 Pge

Pge 2 Where Are We? More BDDs -- now how to tully implement them M T W Th F Aug 27 28 29 3 3 Sep 3 4 5 6 7 2 2 3 4 3 7 8 9 2 2 4 24 25 26 27 28 5 Ot 2 3 4 5 6 8 9 2 7 5 6 7 8 9 8 22 23 24 25 26 9 29 3 3 2 Nov 5 6 7 8 9 2 3 4 5 6 2 Thnxgive 9 2 2 22 23 3 26 27 28 29 3 4 De 3 4 5 6 7 5 2 3 4 6 Introution Avne Boolen lger JAVA Review Forml verifition 2-Level logi synthesis Multi-level logi synthesis Tehnology mpping Plement Routing Stti timing nlysis Eletril timing nlysis Geometri t struts & pps R. Rutenr 2, CMU 8-76, Fll 2 3 Hnouts Physil Leture 4 -- BDD Mnipultion Eletroni HW2 is out on the we site. (Also, note ll TA/Prof offie hours re on we site, in Aout Clss ) Assignments Proj3 out lte toy or tomorrow: Builing simple BDD pkge in JAVA, then using it for some exmple verifition tsks R. Rutenr 2, CMU 8-76, Fll 2 4

Pge 3 BDDs: Cretion First gol Input: gte-level logi network Output: BDD tht represents Boolen funtion of the network Question: how? Cnnot ffor to o it the wy we evelope the BDD ie......nnot uil the full eision igrm from the truth tle n then o the reution to nonil form x x 2 x 3 f x 3 x 2 x 3 x x 3 x 2 x 3 R. Rutenr 2, CMU 8-76, Fll 2 5 BDDs: Cretion So, how o we o it? Buil up BDD inrementlly, y wlking the gte network Eh input is BDD Eh gte eomes n opertor tht proues new BDD A T B Out C T2 A B C T T2 Out R. Rutenr 2, CMU 8-76, Fll 2 6

Pge 4 BDDs: Cretion Strtegy Represent t s set of OBDDs, ll with ientil vrile orerings Express solution metho s sequene of symoli opertions Implement eh opertion y OBDD mnipultion Wht extly is symoli opertion? Think of it like C lnguge suroutine tht works on BDDs... *OPERATOR( *Input, *Input2)... ie, it s routine tht tkes 2 pointers to BDD strutures, uils new BDD struture, n returns you pointer to it Algorithmi properties Arguments re OBDDs with ientil vrile orerings. Result is OBDD with sme orering. Clle the Closure Property : OBDDs go in, OBDDs ome out R. Rutenr 2, CMU 8-76, Fll 2 7 BDDs: Cretion How o we o it? Option (The ovious pproh) Buil BDD opertors for ll the things you n o iretly on logi gte networks, or Boolen funtions themselves Simple opertors: NOT(), AND(,) OR(,), EXOR(,), et Complex opertors: COFACTOR(F,x), CONSENSUS(F,x), et To uil the BDD for Out... might wnt something like this: A B C T T2 Out A = new_vr(""); B = new_vr(""); C = new_vr(""); T = AND(A, B); T2 = AND(B, C); Out = OR(T, T2); R. Rutenr 2, CMU 8-76, Fll 2 8

BDDs: Cretion Wht s wrong with this? Nothing, tully. Perfetly workle......ut not the most elegnt wy of oing it An not the wy people tully o it these ys Option 2: (Sutle pproh) Buil few, ritil, ore opertors on BDDs Buil up ALL the other opertors you like using ONLY this smll set of uiling-lok opertors Avntge Atully less progrmming work, sine you only hve to uil few omplite routines Mkes it muh esier to new opertors lter R. Rutenr 2, CMU 8-76, Fll 2 9 BDDs: RESTRICT Opertor So, wht re the ore opertors we nee? Surprisingly, there re only 2: RESTRICT, ITE RESTRICT(funtion F, vrile v, onstnt k) This is just the Shnnon oftor of F wrt vrile v Exmple: RESTRICT(F, v, ) == F v RESTRICT(F, v, ) == F v Rememer: F is represente s BDD, result of RESTRICT is nother BDD ie, we re relly implementing something like this: *RESTRICT( *F, vrile v, int k) R. Rutenr 2, CMU 8-76, Fll 2 Pge 5

Pge 6 BDDs: ITE If_Then_Else Opertor ITE(funtion F, funtion G, funtion H) Clle the IF-THEN-ELSE opertor ITE(F,G, H) is itself nother Boolen funtion Couple of ifferent wys to esrie just wht ITE is... In pseuo-c... ITE(F,G,H)(x,...,xn) { if ( F(x,..., xn)== ) then return ( G(x,..., xn) ) else return ( H(x,..., xn) ) } In Boolen lger... Let X = x,x2,...xn, just for onveniene of nottion ITE(F,G,H)(X) = F(X) G(X) + F(X) H(X) R. Rutenr 2, CMU 8-76, Fll 2 BDDs: ITE As hrwre... X F G H selet MUX ITE(F,G,H)(X) This one is lso pretty esy to rememer ITE is like n IF-THEN-ELSE in softwre, or MUX in hrwre Critil things to rememer re: ITE(F,G,H) IS A NEW FUNCTION F,G,H re inputs to ITE opertor, represente s BDDs ITE(F,G,H) retes (is) new BDD R. Rutenr 2, CMU 8-76, Fll 2 2

BDDs: ITE Conventions Usully see the input funtions to ITE written like this: ITE( I, T, E)...just for onveniene in rememering tht the first is the IF funtion, the seon is the THEN funtion, lst is ELSE funtion Bk to BDD ore opertors Sort of esy to see why you nee RESTRICT - Lots of useful things you n uil out of oftors Wht goo is ITE? Wht n you o with it? Atully, lmost everything... R. Rutenr 2, CMU 8-76, Fll 2 3 BDDs: Uses of ITE Cn mke ny si 2-input gte out of ITE Not F F MUX An F F G G MUX Or F F G G MUX R. Rutenr 2, CMU 8-76, Fll 2 4 Pge 7

BDDs: Uses of ITE Let s e preise ut how we inten to use ITE An F F G Hve BDD t strutures for funtions F(X), G(X) We wnt to rete the BDD for the funtion (F G)(X) G MUX ITE(F,G,) We o this y lling the ITE routine on the BDD t strutures for funtion F, for funtion G, n for onstnt BDD== ITE returns s vlue pointer to new BDD, whih == (F G) R. Rutenr 2, CMU 8-76, Fll 2 5 BDDs: Cretion If you n implement RESTRICT, ITE... You n uil up silly nything useful you nee to mnipulte Boolen funtions, or uil BDDs of tul gte networks New question How o we tully implement RESTRICT n ITE s lgorithms? Answers Shnnon oftoring to the resue, gin! Reursive ivie n onquer, gin! Nee ouple of speil t strutures to mke it effiient Strt y looking t ITE R. Rutenr 2, CMU 8-76, Fll 2 6 Pge 8

BDDs: Implementing ITE Assumptions There is glol vrile orering: x < x2 < x3 <... < xn If I give you few vriles, you n tell me whih is smllest Exmple: Input: x2, x7 smller(x2, x7) == x2 We will use multi-roote DAGs (MRDAGs) for the BDDs Amzingly enough, it s simpler to implement Newly rete BDDs lwys try to shre noes in existing BDDs Exmple: wht is MRDAG BDD for funtions F(,)=+, G(,)=? R. Rutenr 2, CMU 8-76, Fll 2 7 BDDs: Implementing ITE Key implementtion ie: Use Shnnon expnsion Suppose X=x, x2,... x,... xn Suppose we hve 3 funtions I(X), T(X), E(X), then... ITE(I, T, E) = x ITE( I x,t x, E x ) + x ITE( I x,t x, E x )...ie, ITE n itself e eompose reursively! An, if you wnt to think BDDs... ITE( I, T, E) = x BDD for I BDD for T BDD for E ITE( I x,t x, E x ) ITE( I x,t x, E x ) R. Rutenr 2, CMU 8-76, Fll 2 8 Pge 9

BDDs: Implementing ITE So, wht o we nee to o reursive ITE? Termintion onitions: when n we reognize nswer n quit? Splitting riterion: whih vrile (x?) o you pik to split on? Coftoring: how hr is it to get I x,t x, E x, et. from their BDDs? Effiieny onerns: how fst is this, how ig is the reursion? Reution: how o we gurntee the BDD we proue is reue? Solutions Turns these thing re tully ll interepenent Let s strt wlking thru these issues n see wht we get... R. Rutenr 2, CMU 8-76, Fll 2 9 BDDs: Implementing ITE Generl lgorithm ITE( I, T, E ) { if (terminl se) { return ompute result ; } else { let x e splitting vrile; PosFtor = ITE( I x, T x, E x ) ; NegFtor = ITE( I x,t x, E x ) ; R = new noe for vr x ; R.loson = NegFtor ; R.hison = Posftor ; Do reutions; return( R ); } } R. Rutenr 2, CMU 8-76, Fll 2 2 Pge

Pge BDDs: ITE Implementtion ITE( I, T, E) terminl ses If I = => Return T if I = => Return E If T = && E = => Return I If T = E => Return E Exmples T E I selet ITE(I,T,E) ITE(,, ) = BDD for E ITE(,, ) = ITE(,, ) = BDD for T BDD for E BDD for E BDD for I BDD for T BDD for T R. Rutenr 2, CMU 8-76, Fll 2 2 BDDs: ITE Implementtion Some sutlety out termintion A onern rise erlier ws: how o we keep nswer reue? At lest for the termintion onitions, esy in multi-roote DAG When you terminte, you just return pointer to something tht lrey exists in the MRDAG Sine the MRDAG is BDD, it s lrey reue ie, No extr work Note: so, when ITE is lle n termintes, it relly looks like this... ITE(,, ) = MRDAG for ll our BDDs Eh of the inputs I, T, E re relly represente y ptr to some root noe in this ig MRDAG. Result ITE(I,T,E) ultimtely ens up nother noe in here. For termintion onitions, the result is lwys n existing noe. R. Rutenr 2, CMU 8-76, Fll 2 22

Pge 2 BDDs: ITE Implementtion Splitting vrile seletion There s tully only one right hoie Split on smllest vr mong roots of I, T, E ITE( I, T, E) => if x < y < z, pik x to split on y x z BDD for I BDD for T BDD for E Why? Beuse it mkes the oftoring trivil to implement! Rememer, we now hve to ompute I x,t x, E x, I x,t x, E x R. Rutenr 2, CMU 8-76, Fll 2 23 BDDs: ITE Implementtion RESTRICT(F,v,k) Rememer, this is the opertor tht oes the oftor on BDDs In generl, it s it omplite Troule is when you oftor wrt vr own eep insie the BDD Exmple: Restrit vrile to Restrit ( F, vr x, onst k ): Bypss ny noes for vrile x /* set to onst */ Choose Hi hil for k = Choose Lo hil for k = Reue result Fin noes Bypss Reue R. Rutenr 2, CMU 8-76, Fll 2 24

BDDs: ITE Implementtion..ut there s some useful speil ses here If we lwys pik splitting vr s: smllest(roots of I, T, E)......then we re lwys oing one of these 2 ses Cse : Restrit on root noe vrile Restrit(, x, ) hison Restrit(, x, ) loson x x L H H L H L Cse 2: Restrit on vrile less thn root noe vrile E.g., x < y Restrit(, x, ) originl funtion y L H R. Rutenr 2, CMU 8-76, Fll 2 25 BDDs: ITE Implementtion OK -- tht lst one ws sutle... Let s look t onrete exmple to see the ie here. Restrit( F,, ) ==? vr orer is: < < 2 < 2 < 3 < 3 Funtion F 2 2 3 3 R. Rutenr 2, CMU 8-76, Fll 2 26 Pge 3

Pge 4 BDDs: ITE Implementtion Why tht works Alwys pik vrile t or ove the root of I, T, E Never then hve to oftor own eep in BDD Result is lwys pointer to some noe tht lrey exists in the multiroote DAG of our BDDs So, gin, the reution step tkes re of itself here ie, the MRDAG is reue t ll times, we just return pointer to sudag insie it, whih is lso reue RESTRICT(, vr x, onstnt ) = MRDAG for ll our BDDs In multiroote DAG, these speil ses of RESTRICT will lwys return pointer to some noe tht is lrey in DAG R. Rutenr 2, CMU 8-76, Fll 2 27 BDDs: ITE Exmple Let s try little ITE exmple Cpitl letters = funtions, smll letters = vriles Vr orer is < < < We wnt to ompute ITE ( I(,,,), T(,,,), E(,,,) ) Assume it s MRDAG, we use funtion nmes to ID noes... nottion is E for this noe, ie, we will lel the Boolen funtion for eh noe E = + D = T = B = C = I = + R. Rutenr 2, CMU 8-76, Fll 2 28

Pge 5 BDD: ITE Exmple E = + D = T = B = C = I = + ITE(I, T, E) =? smllest vr mong roots is ITE(I,T,E) lo hi ITE(I, T, E ) ITE(I, T, E ) lo ITE(B,, E) ITE(,, ) ITE(I,T,E) hi ITE(, ITE(B, C, E), E) ITE(,, ) R. Rutenr 2, CMU 8-76, Fll 2 29 Cn we terminte these new ITEs right wy? ie, will we reurse more, or o we know the nswers now? Let s rememer the speil ses for ITE termintion ITE(I,T,E) lo hi ITE( ITE(B,,,, E) ) ITE(, ITE(B, C,, E),, E) ) I I T E selet ITE(I,T,E) T E selet ITE(I,T,E) R. Rutenr 2, CMU 8-76, Fll 2 3

Pge 6 BDD: ITE Exmple E = + D = T = B = C = I = + lo ITE(B,, E) ITE(I,T,E) hi C ITE(I,T,E) lo hi lo hi C ITE(B,,E ) = ITE(,, D) = D ITE(B,,E ) = ITE(,, ) = R. Rutenr 2, CMU 8-76, Fll 2 3 BDD: ITE Exmple E = + D = T = B = C = I = + lo ITE(I,T,E) = hi lo hi C D An we re one! Reursion tree nturlly tres out the resulting BDD for ITE(I,T,E) We set up termintion onitions so tht leves re lwys noes tht lrey exist in the originl multi-roote DAG for So, we n just plug our result k into our MRDAG... R. Rutenr 2, CMU 8-76, Fll 2 32

Pge 7 BDD: ITE Exmple E = + D = T = B = C = I = + lo lo hi ITE(I,T,E) hi C D Atul resulting MRDAG tht we get ITE(I,T,E) E = + D = T = B = C = I = + R. Rutenr 2, CMU 8-76, Fll 2 33 BDD: ITE Implementtion Reution, revisite In our little exmple, the resulting funtion ITE ws new, not lrey existing in the MRDAG, n ll the lef noes were lrey there. Wht hppens if the resulting funtion is NOT new, if it lrey exists in the MRDAG? Exmple Suppose tht, for whtever reson, ITE returns the B = funtion E = + D = T = B = C = I = + lo ITE(I,T,E) hi R. Rutenr 2, CMU 8-76, Fll 2 34

Pge 8 BDDs: ITE Implementtion Following prior exmples, we uil MRDAG s... E = + D = T = B = C = I = + lo ITE(I,T,E) hi E = + D = T = B = C = I = + ITE(I,T,E) TROUBLE!! It s not reue nymore!! R. Rutenr 2, CMU 8-76, Fll 2 35 BDDs: ITE Implementtion Esy to rete new BDD tht s not reue In our B= exmple, we me reunnt vr noe How to fix? Clever trik: The Unique Tle New nottion: mke key for eh noe s (vr, lo, hi) Mke hsh tle (lle the Unique tle) tht mps (vr, lo, hi) for eh noe into tul pointer ress of the noe in the MRDAG T = I = + E = + B = 3 C = 4 D = 6 7 2 Ptr ress 5 Unique Tle Hsh Inex Aress (,7,) 4 R. Rutenr 2, CMU 8-76, Fll 2 36

BDDs: ITE Implementtion Trik Never, ever just rete noe, like B= noe, without heking to see if the noe you wnt to rete lrey exists in the Unique tle This is the ig ie for how we voi reunny Nee new funtion, lle FinOrCreteNoe FinOrCreteNoe heks to see if the noe you wnt to mke lrey exists in the MRDAG. If so, it just returns pointer to tht noe, inste of mking new noe FinOrCreteNoe lso n hek to mke sure you on t o something stupi to mke n unreue DAG Helpful to see piture of wht FinOrCreteNoe oes... R. Rutenr 2, CMU 8-76, Fll 2 37 BDDs: ITE Reution Cse : Trying to mke onstnt noe If you invoke FinOrCrete(onstnt, null, null) n the MRDAG lrey hs tht onstnt, you return pointer to it Ex: FinOrCreteNoe(, null, null) = BDDs Note: this hnles the first reution rule we gve... R. Rutenr 2, CMU 8-76, Fll 2 38 Pge 9

Pge 2 BDDs: ITE Reution Cse 2: Trying to uplite n existing vr noe If you invoke FinOrCrete(vr, loson, hison) n the MRDAG lrey hs this noe, you just return pointer to it Ex: FinOrCreteNoe(,, 6) = Note: this hnles the seon reution rule we gve... T = I = + E = + B = 3 C = 4 D = 6 7 2 5 x x x y z y z R. Rutenr 2, CMU 8-76, Fll 2 39 BDDs: ITE Reution Cse 3: Trying to mke n unneessry test noe If you invoke FinOrCrete(vr, loson, hison) n loson = = hison, then you just return loson, n on t even try to look in DAG Ex: FinOrCreteNoe(, 5, 5) = Note: this hnles the lst reution rule we gve... T = I = + E = + B = 3 C = 4 D = 6 7 2 5 x y y R. Rutenr 2, CMU 8-76, Fll 2 4

Pge 2 BDDs: ITE Reution Cse 4: None of the ove Well, you n t fin it in the existing MRDAG, n it s not stupi to rete it, so go he n rete the noe, n then rememer to insert it in the unique tle Ex: FinOrCreteNoe(, 5, 6) =? T = I = + E = + B = 3 C = 4 D = 6 7 2 5 T = I = + E = + B = 3 C = 4 D = 6 7 2 5 Unique Tle Hsh inex Aress (, 5, 6) 2 R. Rutenr 2, CMU 8-76, Fll 2 4 ITE: FinOrCreteNoe Algorithm looks like this FinOrCreteNoe(vr v, loson, hison) { if (v is tully onstnt ) { if( this onstnt NOT lrey in Unique tle ) instll this onstnt in UNIQUE tle; return ( pointer to onstnt ); } else if (loson == hison) return (loson) ; else if ( (v, loson, hison) lrey in Unique tle ) return ( pointer to (v, loson, hison) from Unique tle); else { rete new noe = (v, loson, hison); instll this noe in Unique tle; return (pointer to (v, loson, hison) ); } } R. Rutenr 2, CMU 8-76, Fll 2 42

BDDs: Reution Wht s relly going on here? Inste of uiling nonreue BDD, then going k to reue it......inste, we hek eh noe s we try to rete it uring reursive ivie&onquer......if it woul rete reunnt noe, we on t llow it to hppen. Inste, we return n existing noe of the BDD whenever we n. This is tully how ALL reutions get one on BDDs All lgorithms tht mnipulte or rete BDDs ll FinOrCreteNoe, to ensure things lwys sty reue Never, ever rete n unreue DAG R. Rutenr 2, CMU 8-76, Fll 2 43 ITE: Implementtion One more essentil trik for effiieny Turns out tht on igger prolems, it s very esy for the reursion to try to reompute the sme intermeite result ITE(,, ) lle on intermeite funtions mny times In ft, n e exponentil numer of lls to ITE in the reursion, ut not ll of them re unique omputtions Turns out there is relly esy fix... But let s onvine ourselves tht this is rel prolem, first... R. Rutenr 2, CMU 8-76, Fll 2 44 Pge 22

Pge 23 ITE: Reursive Clls Compute ITE( I, T, E) for BDDs elow (lphet vr orer) Argument I Argument T Argument E q s p r z x y ITE Reursive Clls ITE(p,, x) = = ITE(q,, z) = = ITE(r,, z) ITE(r,, y) = = = = ITE(s,, z) ITE(,, z) ITE(s,, ) = = ITE(,, ) ITE(,, ) R. Rutenr 2, CMU 8-76, Fll 2 45 BDDs: ITE Reursive Clls Reursive ll tree tells us lot... ITE(p,, x) = = ITE(q,, z) = = ITE(r,, z) ITE(r,, y) = = = = ITE(s,, z) ITE(,, z) ITE(s,, ) = = ITE(,, ) ITE(,, ) These hve 2 rrows going INTO them, so these ITE results will get reompute twie uring reursion R. Rutenr 2, CMU 8-76, Fll 2 46

Pge 24 Asie: Rememer Wht ITE Is Doing... Eh ll to ITE strts with 3 BDDs, returns BDD ITE(p,, x) = ITE(q,, z) = = = ITE(r,, z) ITE(r,, y) = = = = ITE(s,, z) ITE(,, z) ITE(s,, ) = = ITE(,, ) ITE(,, ) ITE( s,, z ) = ptr to some s z MRDAG for ll our BDDs R. Rutenr 2, CMU 8-76, Fll 2 47 BDDs: Reution Revisite Also, n see tht reution is importnt Reursive lls to ITE nturlly tre out n unreue BDD Reution on the fly vi FinOrCreteNoe prevents this Reursion ITE(p,, x) = ITE(q,, z) = = = ITE(r,, z) ITE(r,, y) = = = = ITE(s,, z) ITE(,, z) ITE(s,, ) = = ITE(,, ) ITE(,, ) Nturl BDD tre out uring ITE reursion Reue BDD R. Rutenr 2, CMU 8-76, Fll 2 48

Pge 25 BDDs: ITE Opertion Tle How to prevent reomputtion uring ITE reursion? Every time you return from ITE, you store your ompute nswer in tle, lle the Opertion Tle. Key is (I,T,E), vlue is ress of ompute noe in BDD returne Every time you enter ITE, you look in the tle first to see if the nswer hs lrey een ompute erlier in reursion Nie, simple solution, tres some memory (tle) for time Reursion ITE(p,, x) = ITE(q,, z) = = = ITE(r,, z) ITE(r,, y) = = = = ITE(s,, z) ITE(,, z) ITE(s,, ) = = ITE(,, ) ITE(,, ) Opertion Tle Hsh Vlue (p,,r) (q,,) (s,,z) Aress NoeI NoeJ NoeK R. Rutenr 2, CMU 8-76, Fll 2 49 BDDs: ITE Complexity Effiieny Without Opertion Tle Exponentil Complexity Effetively expn out eision trees With Opertion Tle Worst se = prout of grph sizes for I, T, n E At worst, will fill tle with ll possile keys Intertion with multi-root DAG ssumption If ll BDDs use shre noes... Mintin glol Opertion Tle, ross ALL BDDs More possiilities for quik termintion R. Rutenr 2, CMU 8-76, Fll 2 5

BDDs: ITE Finl ITE lgorithm ITE( I, T, E ) { if (terminl se pplies to I, T, E) { return( immeite ompute result ) ; } else if ( Opertion Tle hs entry for (I,T,E) ) { return( result noe from opertion tle ); } else { let x e smllest vr from mong roots of I, T, E ; PosFtor = ITE( I x,t x, E x ); Negftor = ITE( I x,t x, E x ); R = FinOrCreteNoe(x, NegFtor, PosFtor); InsertIntoOpertionTle( hsh vlue (I, T, E), ress R) ; return( R ) ; } } R. Rutenr 2, CMU 8-76, Fll 2 5 BDDs: Mnipultion There is similr lgorithm for generl RESTRICT Another reursive esent, uses FinOrCreteNoe gin Trik is to reple ll the noes tht hve the vrile you re oftoring out, n get the loson, hison pointers right We won t look t this in etil If you n implement ITE, n RESTRICT... You n silly implement everything interesting Severl useful properties too Closure: if you strt with ROBDDs with prtiulr vr orer, results of ITE n RESTRICT (properly implemente) re gin ROBDDs with sme vr orer Complexity: polynomil in size of input BDDs R. Rutenr 2, CMU 8-76, Fll 2 52 Pge 26

BDDs: Mnipultion Summry Implement 2 ore opertors on BDD t strutures RESTRICT( F, vr x, onstnt k) = Shnnon oftor ITE( I, T, E) = IF-THEN-ELSE opertor Eh of these tkes BDDs s inputs, returns new BDD From ITE & RESTRICT,you n implement lots of stuff Coftoring, quntifition, erivtives All the si gte types: NOT, AND, OR, EXOR, et Other more exoti stuff (see homework) Given n effiient BDD softwre pkge, n o lots of nie prtil engineering pplitions Stisfiility: tre BDD from root to noe to fin inputs tht mke the funtion == Equivlene: if 2 funtions re sme over ALL inputs, their BDDs en up itentil, ie, 2 pointers to sme noe in the MRDAG R. Rutenr 2, CMU 8-76, Fll 2 53 Pge 27