i 1 / 61 Introduction and Context 2 / 61 3 / 61 3 / 61 3 / 61 - - PowerPoint PPT Presentation

i
SMART_READER_LITE
LIVE PREVIEW

i 1 / 61 Introduction and Context 2 / 61 3 / 61 3 / 61 3 / 61 - - PowerPoint PPT Presentation

Representing and Computing with Types in Dynamically Typed Languages Extending Dynamic Language Expressivity to Accommodate Rationally Typed Sequences Jim Edward Newton Thesis defense for the title: Doctorat de lUniversit e Sorbonne


slide-1
SLIDE 1

Representing and Computing with Types in Dynamically Typed Languages

Extending Dynamic Language Expressivity to Accommodate Rationally Typed Sequences

Jim Edward Newton

Thesis defense for the title: Doctorat de l’Universit´ e Sorbonne Universit´ e Directory: Pr. Thierry G´ eraud, EPITA/LRDE Advisor: Dr. Didier Verna, EPITA/LRDE November 20, 2018

i

1 / 61

slide-2
SLIDE 2

Introduction and Context

2 / 61

slide-3
SLIDE 3

3 / 61

slide-4
SLIDE 4

3 / 61

slide-5
SLIDE 5

3 / 61

slide-6
SLIDE 6

3 / 61

slide-7
SLIDE 7

Exotic design rules, fixed, optional, repeating

( s p a ci n g T a b le s ( minCutClassSpacing tx−cutLayer1 tx−cutLayer2 (( ” c u t C l a s s 1 ” ( g−index . . . ) n i l ” c u t C l a s s 2 ” ( g−index . . . ) n i l . . . ) [ sameNet | sameMetal ] [ paraOverlap [ g−overlap ] ] [ c u t C l a s s P r o f i l e ( ( ” c u t C l a s s 1 ” ( g−index . . . ) n i l ” c u t C l a s s 2 ” n i l | ( g−index . . . ) n i l . . . ) ( g−profileTable ) ] [ g−default ] ] ( g−table ) [ manhattan ] ) ) ( minViaSpacing tx−cutLayer1 tx−cutLayer2 (( ” c u t C l a s s 1 ” ( g−index . . . ) n i l ” c u t C l a s s 2 ” ( g−index . . . ) n i l . . . ) [ sameNet | sameMetal ] [ paraOverlap [ g−overlap ] ] [ c u t C l a s s P r o f i l e ( ( ” c u t C l a s s 1 ” ( g−index . . . ) n i l ” c u t C l a s s 2 ” n i l | ( g−index . . . ) n i l . . . ) ( g−profileTable ) ] [ g−default ] ] ( g−table ) [ manhattan ] ) ) ( minExoticEnclosure tx−cutLayer1 tx−cutLayer2 (( ” e x o t C l a s s 1 ” ( g−index . . . ) n i l ” e x o t C l a s s 2 ” ( g−index . . . ) n i l . . . ) [ sameNet | sameMetal ] [ paraOverlap [ g−overlap ] ] [ c u t C l a s s P r o f i l e ( ( . . . ) ) ] ) . . . )

Lots of types and optional elements, such as g-table, number, string, pair of string or fixnum.

3 / 61

slide-8
SLIDE 8

Code to create and analyze such a layout must: ◮ Parse the design rules ◮ Handle exceptions in erroneous input data ◮ Treat the data to process shapes in the layout ◮ Often fused together Can we express such patterns explicitly and declaratively, and let the system assure the run-time data is consistent? Can separate “application logic” from “error checking”?

3 / 61

slide-9
SLIDE 9

What is Common Lisp?

◮ Multi-paradigm: programming language ◮ ... allow the programmer to express himself. ◮ Functional, procedural, object-oriented. ◮ Meta-programming: Meta-object protocol, macros. ◮ Dynamic approach to typing and reflection

4 / 61

slide-10
SLIDE 10

Regular Sequences of Heterogeneous Types

◮ We can declare types of certain data.

◮ (declare (type integer X) (type list Y)) ; YES

5 / 61

slide-11
SLIDE 11

Regular Sequences of Heterogeneous Types

◮ We can declare types of certain data.

◮ (declare (type integer X) (type list Y)) ; YES

◮ We can use arbitrary, heterogeneous sequences.

◮ (:a 1 1.0 :b "a" "an" "the" :c 2 22 222 :d 2/3 ) ; YES

5 / 61

slide-12
SLIDE 12

Regular Sequences of Heterogeneous Types

◮ We can declare types of certain data.

◮ (declare (type integer X) (type list Y)) ; YES

◮ We can use arbitrary, heterogeneous sequences.

◮ (:a 1 1.0 :b "a" "an" "the" :c 2 22 222 :d 2/3 ) ; YES

◮ However, it is difficult to combine.

5 / 61

slide-13
SLIDE 13

Regular Sequences of Heterogeneous Types

◮ We can declare types of certain data.

◮ (declare (type integer X) (type list Y)) ; YES

◮ We can use arbitrary, heterogeneous sequences.

◮ (:a 1 1.0 :b "a" "an" "the" :c 2 22 222 :d 2/3 ) ; YES

◮ However, it is difficult to combine.

◮ (declare (type list[integer] X)) ; NO!

5 / 61

slide-14
SLIDE 14

Regular Sequences of Heterogeneous Types

◮ We can declare types of certain data.

◮ (declare (type integer X) (type list Y)) ; YES

◮ We can use arbitrary, heterogeneous sequences.

◮ (:a 1 1.0 :b "a" "an" "the" :c 2 22 222 :d 2/3 ) ; YES

◮ However, it is difficult to combine.

◮ (declare (type list[integer] X)) ; NO! ◮ (declare (type regular-pattern X)) ; NO!

5 / 61

slide-15
SLIDE 15

Regular Sequences of Heterogeneous Types

◮ We can declare types of certain data.

◮ (declare (type integer X) (type list Y)) ; YES

◮ We can use arbitrary, heterogeneous sequences.

◮ (:a 1 1.0 :b "a" "an" "the" :c 2 22 222 :d 2/3 ) ; YES

◮ However, it is difficult to combine.

◮ (declare (type list[integer] X)) ; NO! ◮ (declare (type regular-pattern X)) ; NO!

◮ We propose to extend the type system of Common Lisp.

5 / 61

slide-16
SLIDE 16

Regular Sequences of Heterogeneous Types

◮ We can declare types of certain data.

◮ (declare (type integer X) (type list Y)) ; YES

◮ We can use arbitrary, heterogeneous sequences.

◮ (:a 1 1.0 :b "a" "an" "the" :c 2 22 222 :d 2/3 ) ; YES

◮ However, it is difficult to combine.

◮ (declare (type list[integer] X)) ; NO! ◮ (declare (type regular-pattern X)) ; NO!

◮ We propose to extend the type system of Common Lisp. ◮ We introduce RTE, regular type expressions, specifying heterogeneous but regular sequences.

5 / 61

slide-17
SLIDE 17

Goal: Implement RTEs in Common Lisp

Vaguely: We want to efficiently detect whether a sequence of values matches a regular pattern of types. Precisely: Given a pattern, at compile-time, generate code, such that given a sequence of values at run-time, we can determine whether the sequence matches the pattern.

6 / 61

slide-18
SLIDE 18

Implementing RTE presents several challenges

  • 1. The representation problem:

Representing rational type expressions in Common Lisp.

  • 2. The decomposition problem:

Calculating the Maximal Disjoint Type Decomposition (MDTD).

  • 3. The serialization problem:

Generating code without redundant type checks.

7 / 61

slide-19
SLIDE 19

Overview

Intro Representation Problem Pattern Matching Decomposition Problem BDDs Serialization Problem Conclusion

8 / 61

slide-20
SLIDE 20

Types, Sequences, and Typed Sequences in Common Lisp

9 / 61

slide-21
SLIDE 21

Quick intro to the Common Lisp Type System A B

Type operations are set operations: membership, intersection, union, complement, empty-set.

10 / 61

slide-22
SLIDE 22

Quick intro to the Common Lisp Type System

unsigned-byte

fixnum integer float number

10 / 61

slide-23
SLIDE 23

Quick intro to the Common Lisp Type System

unsigned-byte

fixnum integer float number

(typep -1 ’(or float (and integer (not unsigned-byte)))) → true (subtypep ’(and integer fixnum) ’(not number)) → false (subtypep ’(and float fixnum) nil) → true

10 / 61

slide-24
SLIDE 24

We’d like to recognize sequences with regular patterns. ( 1 2.3 9.3 3 1.5 6.5 4.8 5 2 2.3)

11 / 61

slide-25
SLIDE 25

We’d like to recognize sequences with regular patterns. ( 1 2.3 9.3 3 1.5 6.5 4.8 5 2 2.3) ◮ We generalize string-based regular expressions to arbitrary sequences. ◮ To match a string like: "iFFiFFFiiF", ◮ ... we use a RE such as: (i · F ∗)+, ◮ ... which has surface syntax: "(iF*)+".

11 / 61

slide-26
SLIDE 26

We’d like to recognize sequences with regular patterns. ( 1 2.3 9.3 3 1.5 6.5 4.8 5 2 2.3) ◮ We generalize string-based regular expressions to arbitrary sequences. ◮ To match a string like: "iFFiFFFiiF", ◮ ... we use a RE such as: (i · F ∗)+, ◮ ... which has surface syntax: "(iF*)+".

We propose Rational Type Expressions (RTEs)

◮ Rational type expression: ( integer · float ∗)+ ◮ We need a surface syntax.

11 / 61

slide-27
SLIDE 27

We think this:

  • symbol ·number ?·(ratio∗∨float+)
  • ∧ t · number · number

And we write this:

( : and ( : cat symbol ( : ? number ) ( : or ( : ∗ r a t i o ) (:+ f l o a t ) ) ) ( : not ( : cat t number number ) ) )

Support for :and, :not, :?, and :+ is sometimes referred to as extended rational expressions. We don’t distinguish extended and ordinary RE.

12 / 61

slide-28
SLIDE 28

Using Surface Syntax

With the type definition (rte ...) we can use rational type expressions just like any other type in the language.

( defun s e t − a t t r i b u t e s ( o b j e c t a t t r ) ( d e c l a r e ( type ( r t e ( : ∗ ( : cat keyword number ) ) ) ; <−− RTE a t t r )) ( s e t f ( a t t r i b u t e s

  • b j e c t )

a t t r )) ( deftype p l i s t ( type ) `( r t e ( : ∗ ( : cat keyword , type ) ) ) ) ; <−− RTE ( d e f c l a s s polygon () (( c o l o r : type rgb ) ( p o i n t s : type ( r t e ( : ∗ ( : cat fixnum r e a l ) ) ) ) ) ) ; <−− RTE

13 / 61

slide-29
SLIDE 29

Efficient Pattern Matching Based on Types

14 / 61

slide-30
SLIDE 30

Does: (a 1 1.0 b "a" "an" "the" c 2 22 222 d 2/3) follow the pattern: (symbol · (number+ ∨ string+))+ ? I.e. , is the sequence an element of the specified type?

15 / 61

slide-31
SLIDE 31

Does: (a 1 1.0 b "a" "an" "the" c 2 22 222 d 2/3) follow the pattern: (symbol · (number+ ∨ string+))+ ? I.e. , is the sequence an element of the specified type? We construct a deterministic finite automaton (DFA). We want to support :not and :and in

  • ur DSL.

1 2 3 symbol number string symbol number symbol string

15 / 61

slide-32
SLIDE 32

(a 1 1.0 b "a" "an" "the" c 2 22 222 d 2/3) How does a DFA work as a type predicate?

1 2 3 symbol number string symbol number symbol string

15 / 61

slide-33
SLIDE 33

How does a DFA work as a type predicate? (a 1 1.0 b "a" "an" "the" c 2 22 222 d 2/3)

1 2 3 symbol number string symbol number symbol string

15 / 61

slide-34
SLIDE 34

How does a DFA work as a type predicate? ( a 1 1.0 b "a" "an" "the" c 2 22 222 d 2/3)

1 2 3 symbol number string symbol number symbol string

15 / 61

slide-35
SLIDE 35

How does a DFA work as a type predicate? (a

1 1.0 b "a"

"an" "the" c 2 22 222 d 2/3)

1 2 3 symbol number string symbol number symbol string

15 / 61

slide-36
SLIDE 36

How does a DFA work as a type predicate? (a 1

1.0 b "a"

"an" "the" c 2 22 222 d 2/3)

1 2 3 symbol number string symbol number symbol string

15 / 61

slide-37
SLIDE 37

How does a DFA work as a type predicate? (a 1 1.0

b "a"

"an" "the" c 2 22 222 d 2/3)

1 2 3 symbol number string symbol number symbol string

15 / 61

slide-38
SLIDE 38

How does a DFA work as a type predicate? (a 1 1.0 b

"a"

"an" "the" c 2 22 222 d 2/3)

1 2 3 symbol number string symbol number symbol string

15 / 61

slide-39
SLIDE 39

How does a DFA work as a type predicate? (a 1 1.0 b "a"

"an" "the" c 2

22 222 d 2/3)

1 2 3 symbol number string symbol number symbol string

15 / 61

slide-40
SLIDE 40

How does a DFA work as a type predicate? (a 1 1.0 b "a" "an"

"the"

c 2 22 222 d 2/3)

1 2 3 symbol number string symbol number symbol string

15 / 61

slide-41
SLIDE 41

How does a DFA work as a type predicate? (a 1 1.0 b "a" "an" "the"

c 2

22 222 d 2/3)

1 2 3 symbol number string symbol number symbol string

15 / 61

slide-42
SLIDE 42

How does a DFA work as a type predicate? (a 1 1.0 b "a" "an" "the" c

2

22 222 d 2/3)

1 2 3 symbol number string symbol number symbol string

15 / 61

slide-43
SLIDE 43

How does a DFA work as a type predicate? (a 1 1.0 b "a" "an" "the" c 2

22 222 d 2/3)

1 2 3 symbol number string symbol number symbol string

15 / 61

slide-44
SLIDE 44

How does a DFA work as a type predicate? (a 1 1.0 b "a" "an" "the" c 2 22

222 d 2/3)

1 2 3 symbol number string symbol number symbol string

15 / 61

slide-45
SLIDE 45

How does a DFA work as a type predicate? (a 1 1.0 b "a" "an" "the" c 2 22 222

d 2/3)

1 2 3 symbol number string symbol number symbol string

15 / 61

slide-46
SLIDE 46

How does a DFA work as a type predicate? (a 1 1.0 b "a" "an" "the" c 2 22 222 d

2/3 )

1 2 3 symbol number string symbol number symbol string

15 / 61

slide-47
SLIDE 47

How does a DFA work as a type predicate? Yes, it’s a match! (a 1 1.0 b "a" "an" "the" c 2 22 222 d 2/3)

1 2 3 symbol number string symbol number symbol string

15 / 61

slide-48
SLIDE 48

Code generated from (symbol · (number + ∨ string +))+

( tagbody ( u n l e s s seq ( r e t u r n n i l )) ( typecase ( pop seq ) ( symbol ( go 1)) ( t ( r e t u r n n i l ) ) ) 1 ( u n l e s s seq ( r e t u r n n i l )) ( typecase ( pop seq ) ( number ( go 2)) ( s t r i n g ( go 3)) ( t ( r e t u r n n i l ) ) ) 2 ( u n l e s s seq ( r e t u r n t )) ( typecase ( pop seq ) ( number ( go 2)) ( symbol ( go 1)) ( t ( r e t u r n n i l ) ) )

1 2 3 symbol number string symbol number symbol string

3 ( u n l e s s seq ( r e t u r n t )) ( typecase ( pop seq ) ( s t r i n g ( go 3)) ( symbol ( go 1)) ( t ( r e t u r n n i l ) ) ) ) )

16 / 61

slide-49
SLIDE 49

Lambda-lists characterized by RTEs

A lambda-list in Common Lisp has a fixed part (defun foo (a b) ...)

17 / 61

slide-50
SLIDE 50

Lambda-lists characterized by RTEs

A lambda-list in Common Lisp has a fixed part, an optional part (defun foo (a b &optional c) ...)

17 / 61

slide-51
SLIDE 51

Lambda-lists characterized by RTEs

A lambda-list in Common Lisp has a fixed part, an optional part, and a repeating part. (defun foo (a b &optional c &key x y) ...)

17 / 61

slide-52
SLIDE 52

Lambda-lists characterized by RTEs

A lambda-list in Common Lisp has a fixed part, an optional part, and a repeating part part. Any of the variables may be restricted by type declarations. (defun foo (a b &optional c &key x y) (declare (type integer a x) (type string b c y)) ...)

17 / 61

slide-53
SLIDE 53

Lambda-lists characterized by RTEs

A lambda-list in Common Lisp has a fixed part, an optional part, and a repeating part part. Any of the variables may be restricted by type declarations. (defun foo (a b &optional c &key x y) (declare (type integer a x) (type string b c y)) ...) The set of valid argument lists for a function may be characterized by an RTE.

17 / 61

slide-54
SLIDE 54

destructuring-bind is a different syntax for calling an anonymous function.

( destructuring−bind ( a (b c ) &key ( x t ) ( y ”” ) z ) DATA ( d e c l a r e ( type fixnum a b c z ) ( type symbol x ) ( type s t r i n g y )) . . . body . . . )

18 / 61

slide-55
SLIDE 55

destructuring-bind is a different syntax for calling an anonymous function.

( destructuring−bind ( a (b c ) &key ( x t ) ( y ”” ) z ) DATA ( d e c l a r e ( type fixnum a b c z ) ( type symbol x ) ( type s t r i n g y )) . . . body . . . )

For example: DATA = (2 (3 4) :y "a" :x ’b) ; YES

18 / 61

slide-56
SLIDE 56

destructuring-bind is a different syntax for calling an anonymous function.

( destructuring−bind ( a (b c ) &key ( x t ) ( y ”” ) z ) DATA ( d e c l a r e ( type fixnum a b c z ) ( type symbol x ) ( type s t r i n g y )) . . . body . . . )

For example: DATA = (2 (3 4) :y "a" :x ’b) ; YES DATA = (2 (3 4) :y "a" :x ’b :x 42 :y "hello" :y nil) ; YES

18 / 61

slide-57
SLIDE 57

destructuring-bind is a different syntax for calling an anonymous function.

( destructuring−bind ( a (b c ) &key ( x t ) ( y ”” ) z ) DATA ( d e c l a r e ( type fixnum a b c z ) ( type symbol x ) ( type s t r i n g y )) . . . body . . . )

For example: DATA = (2 (3 4) :y "a" :x ’b) ; YES DATA = (2 (3 4) :y "a" :x ’b :x 42 :y "hello" :y nil) ; YES DATA = (2 (3 4) :y "a" :x 42 :x ’b) ; NO An invalid argument list will signal an error at run-time.

18 / 61

slide-58
SLIDE 58

QUESTION: Can we select an appropriate lambda-list matching DATA, avoiding a run-time error? We propose destructuring-case.

( d e s t r u c t u r i n g − c a s e DATA ; ; Case−1 (( a b &o p t i o n a l ( c ”” )) ( d e c l a r e ( type i n t e g e r a ) ( type s t r i n g b c )) . . . body . . . ) ; ; Case−2 (( a ( b c ) &key ( x t ) ( y ”” ) z ) ( d e c l a r e ( type fixnum a b c ) ( type symbol x ) ( type s t r i n g y ) ( type l i s t z )) . . . body . . . ) )

19 / 61

slide-59
SLIDE 59

QUESTION: Can we select an appropriate lambda-list matching DATA, avoiding a run-time error? We propose destructuring-case.

( d e s t r u c t u r i n g − c a s e DATA ; ; Case−1 (( a b &o p t i o n a l ( c ”” )) ( d e c l a r e ( type i n t e g e r a ) ( type s t r i n g b c )) . . . body . . . ) ; ; Case−2 (( a ( b c ) &key ( x t ) ( y ”” ) z ) ( d e c l a r e ( type fixnum a b c ) ( type symbol x ) ( type s t r i n g y ) ( type l i s t z )) . . . body . . . ) )

◮ integer · string · string?

19 / 61

slide-60
SLIDE 60

QUESTION: Can we select an appropriate lambda-list matching DATA, avoiding a run-time error? We propose destructuring-case.

( d e s t r u c t u r i n g − c a s e DATA ; ; Case−1 (( a b &o p t i o n a l ( c ”” )) ( d e c l a r e ( type i n t e g e r a ) ( type s t r i n g b c )) . . . body . . . ) ; ; Case−2 (( a ( b c ) &key ( x t ) ( y ”” ) z ) ( d e c l a r e ( type fixnum a b c ) ( type symbol x ) ( type s t r i n g y ) ( type l i s t z )) . . . body . . . ) )

◮ integer · string · string?

1 integer 2 string 3 string

19 / 61

slide-61
SLIDE 61

QUESTION: Can we select an appropriate lambda-list matching DATA, avoiding a run-time error? We propose destructuring-case.

( d e s t r u c t u r i n g − c a s e DATA ; ; Case−1 (( a b &o p t i o n a l ( c ”” )) ( d e c l a r e ( type i n t e g e r a ) ( type s t r i n g b c )) . . . body . . . ) ; ; Case−2 (( a ( b c ) &key ( x t ) ( y ”” ) z ) ( d e c l a r e ( type fixnum a b c ) ( type symbol x ) ( type s t r i n g y ) ( type l i s t z )) . . . body . . . ) )

◮ integer · string · string?

1 integer 2 string 3 string

◮ What is the rational type expression?

19 / 61

slide-62
SLIDE 62

QUESTION: Can we select an appropriate lambda-list matching DATA, avoiding a run-time error? We propose destructuring-case.

( d e s t r u c t u r i n g − c a s e DATA ; ; Case−1 (( a b &o p t i o n a l ( c ”” )) ( d e c l a r e ( type i n t e g e r a ) ( type s t r i n g b c )) . . . body . . . ) ; ; Case−2 (( a ( b c ) &key ( x t ) ( y ”” ) z ) ( d e c l a r e ( type fixnum a b c ) ( type symbol x ) ( type s t r i n g y ) ( type l i s t z )) . . . body . . . ) )

◮ integer · string · string?

1 integer 2 string 3 string

◮ What is the rational type expression? ◮ What is the DFA?

19 / 61

slide-63
SLIDE 63

RTE auto-generated from destructuring lambda-list

( : cat ( : cat fixnum ( : and l i s t ( r t e ( : cat fixnum fixnum ) ) ) ) ( : and ( : ∗ ( : cat ( : or ( e q l : x ) ( e q l : y ) ( e q l : z )) t )) ( : cat ( : ∗ ( : cat ( not ( e q l : x )) t )) ( : ? ( : cat ( e q l : x ) symbol ( : ∗ t ) ) ) ) ( : cat ( : ∗ ( : cat ( not ( e q l : y )) t )) ( : ? ( : cat ( e q l : y ) s t r i n g ( : ∗ t ) ) ) ) ( : cat ( : ∗ ( : cat ( not ( e q l : z )) t )) ( : ? ( : cat ( e q l : z ) l i s t ( : ∗ t ) ) ) ) ) )

20 / 61

slide-64
SLIDE 64

DFA corresponding to auto-generated RTE

1 T1 2 T2 3 T3 24 T4 16 T5 4 T6 25 T8 17 T10 5 T3 6 T4 12 T5 T7 7 T8 13 T10 9 T5 8 T9 10 T10 T7 11 T11 T7 15 T4 14 T12 T8 T7 19 T3 20 T4 18 T5 T6 21 T8 T7 23 T3 22 T13 T6 T7 27 T3 26 T4 28 T5 T6 T7 T10

T1 = fixnum T2 = (and list (rte (:cat fixnum fixnum))) T3 = (eql :x) T4 = (eql :y) T5 = (eql :z) T6 = symbol T7 = t T8 = string T9 = (member :x :y) T10 = list T11 = (member :x :y :z) T12 = (member :x :z) T13 = (member :y :z) 21 / 61

slide-65
SLIDE 65

DFA corresponding to auto-generated RTE

1 T1 2 T2 3 T3 24 T4 16 T5 4 T6 25 T8 17 T10 5 T3 6 T4 12 T5 T7 7 T8 13 T10 9 T5 8 T9 10 T10 T7 11 T11 T7 15 T4 14 T12 T8 T7 19 T3 20 T4 18 T5 T6 21 T8 T7 23 T3 22 T13 T6 T7 27 T3 26 T4 28 T5 T6 T7 T10

Multiple transitions from states give rise to serialization problem.

21 / 61

slide-66
SLIDE 66

Rational Type Expressions (RTEs) with overlapping types (number · integer) ∨ (integer · number)

We have non-deterministic (NFA). integer ⊂ number

1 number 3 integer 2 integer number

integer number

22 / 61

slide-67
SLIDE 67

Rational Type Expressions (RTEs) with overlapping types (number · integer) ∨ (integer · number)

We want deterministic (DFA).

1 (and number (not integer)) 3 integer 2 integer number

22 / 61

slide-68
SLIDE 68

Maximal Disjoint Type Decomposition

23 / 61

slide-69
SLIDE 69

MDTD: decompose a set of types into disjoint types

◮ Given Ai as possibly overlapping regions,

A1 A2 A3 A4 A5 A6 A7 A8

24 / 61

slide-70
SLIDE 70

MDTD: decompose a set of types into disjoint types

◮ Given Ai as possibly overlapping regions, ◮ Calculate Xi as disjoint regions.

A1 A2 A3 A4 A5 A6 A7 A8 X1 X2 X13 X3 X11 X10 X12 X4 X5 X6 X7 X8 X9

24 / 61

slide-71
SLIDE 71

MDTD problem: Baseline algorithm

Are there any disjoint sets?

A1 A2 A3 A4 A5 A6 A7 A8

25 / 61

slide-72
SLIDE 72

MDTD problem: Baseline algorithm

Yes, A7 intersects no other set.

A1 A2 A3 A4 A5 A6 A7 A8

25 / 61

slide-73
SLIDE 73

MDTD problem: Baseline algorithm

So collect it into D : D = {A7}

A1 A2 A3 A4 A5 A6 A7 A8

25 / 61

slide-74
SLIDE 74

MDTD problem: Baseline algorithm

Select any intersecting pair of sets.

A1 A2 A3 A4 A5 A6 A7 A8

25 / 61

slide-75
SLIDE 75

MDTD problem: Baseline algorithm

E.g., A2. Does A2 intersect anything?

A1 A2 A3 A4 A5 A6 A7 A8

25 / 61

slide-76
SLIDE 76

MDTD problem: Baseline algorithm

  • Yes. A2 intersects A4.

A1 A2 A3 A4 A5 A6 A7 A8

25 / 61

slide-77
SLIDE 77

MDTD problem: Baseline algorithm

So calculate the standard partition of A2 and A4

A1 A2 A3 A4 A5 A6 A7 A8

25 / 61

slide-78
SLIDE 78

MDTD problem: Baseline algorithm

The standard partition is {A2 ∩ A4, ...}

A1 A2 A3 A4 A5 A6 A7 A8

25 / 61

slide-79
SLIDE 79

MDTD problem: Baseline algorithm

The standard partition is {A2 ∩ A4, A4 ∩ A2, ...}

A1 A2 A3 A4 A5 A6 A7 A8

25 / 61

slide-80
SLIDE 80

MDTD problem: Baseline algorithm

The standard partition is {A2 ∩ A4, A4 ∩ A2, A2 ∩ A4}

A1 A2 A3 A4 A5 A6 A7 A8

25 / 61

slide-81
SLIDE 81

MDTD problem: Baseline algorithm

So remove {A2, A4} and add {A2 ∩ A4, A4 ∩ A2, A2 ∩ A4}.

A1 A2 ∩ A4 A2 ∩ A4 A3 A4 ∩ A2 A5 A6 A7 A8

25 / 61

slide-82
SLIDE 82

MDTD problem: Baseline algorithm

Now, restart. Anything disjoint from everything else? No.

A1 A2 ∩ A4 A2 ∩ A4 A3 A4 ∩ A2 A5 A6 A7 A8

25 / 61

slide-83
SLIDE 83

MDTD problem: Baseline algorithm

So select any intersecting pair.

A1 A2 ∩ A4 A2 ∩ A4 A3 A4 ∩ A2 A5 A6 A7 A8

25 / 61

slide-84
SLIDE 84

MDTD problem: Baseline algorithm

E.g., A4 ∩ A2. Does it intersect anything?

A1 A2 ∩ A4 A2 ∩ A4 A3 A4 ∩ A2 A5 A6 A7 A8

25 / 61

slide-85
SLIDE 85

MDTD problem: Baseline algorithm

Yes, it intersects A5.

A1 A2 ∩ A4 A2 ∩ A4 A3 A4 ∩ A2 A5 A6 A7 A8

25 / 61

slide-86
SLIDE 86

MDTD problem: Baseline algorithm

So calculate the standard partition of A5 and A4 ∩ A2.

A1 A2 ∩ A4 A2 ∩ A4 A3 A4 ∩ A2 A5 A6 A7 A8

25 / 61

slide-87
SLIDE 87

MDTD problem: Baseline algorithm

The standard partition is {A5, ...}.

A1 A2 ∩ A4 A2 ∩ A4 A3 A4 ∩ A2 A5 A6 A7 A8

25 / 61

slide-88
SLIDE 88

MDTD problem: Baseline algorithm

The standard partition is {..., A4 ∩ A2 ∩ A5}.

A1 A2 ∩ A4 A2 ∩ A4 A3 A4 ∩ A2 A5 A6 A7 A8

25 / 61

slide-89
SLIDE 89

MDTD problem: Baseline algorithm

The standard partition is {A5, A4 ∩ A2 ∩ A5}.

A1 A2 ∩ A4 A2 ∩ A4 A3 A4 ∩ A2 A5 A6 A7 A8

25 / 61

slide-90
SLIDE 90

MDTD problem: Baseline algorithm

So remove {A5, A4 ∩ A2} and add {A5, A4 ∩ A2 ∩ A5}.

A1 A2 ∩ A4 A2 ∩ A4 A3 A4 ∩ A2 ∩ A5 A5 A6 A7 A8

25 / 61

slide-91
SLIDE 91

MDTD problem: Baseline algorithm

So remove {A5, A4 ∩ A2} and add {A5, A4 ∩ A2 ∩ A5}. A5 is in both sets. We can optimize, because A5 ⊂ A4 ∩ A2.

A1 A2 ∩ A4 A2 ∩ A4 A3 A4 ∩ A2 ∩ A5 A5 A6 A7 A8

25 / 61

slide-92
SLIDE 92

MDTD problem: Baseline algorithm

Continue the procedure until collecting all the pairwise disjoint sets.

X1 X2 X13 X3 X11 X10 X12 X4 X5 X6 X7 X8 X9

25 / 61

slide-93
SLIDE 93

MDTD problem: Baseline algorithm

Calculating all the colored regions as subsets of original overlapping sets.

X1 X2 X13 X3 X11 X10 X12 X4 X5 X6 X7 X8 X9

26 / 61

slide-94
SLIDE 94

List with set semantics

X3 X4 X6 X11 X5 =? =? =? =?

◮ Insertion into list with set semantics has linear complexity. ◮ Type equivalence check is Xi ⊂ Xj ∧ Xj ⊂ Xi ? ◮ And prevents us from using a hash table to implement sets. ◮ This equivalence function is SLOW!

27 / 61

slide-95
SLIDE 95

MDTD result: type specifiers are explosive in size

X2 : ( and ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ) X3 : ( and ( and ( and A1 ( not A2 )) A3) ( not A4 ) ) X10 : ( and ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) )

28 / 61

slide-96
SLIDE 96

Problems with baseline algorithm

◮ Explosive size of type specifiers ◮ O(n2) search on each iteration ◮ Set semantics for lists of types:

◮ To maintain uniqueness, O(n) list-insertion. ◮ Equivalent types may appear in many different forms. ... No canonical form ◮ Slow set-equivalence algorithm.

◮ Many redundant checks ◮ subtypep may return don’t-know

29 / 61

slide-97
SLIDE 97

Strategies to Improving MDTD algorithm

We can do better. ◮ Optimize current algorithm (caching etc). ◮ Change the algorithm. ◮ Change the data structure representing the sets (CL types).

30 / 61

slide-98
SLIDE 98

Graph-based MDTD

7 2 3 4 1 8 5 6

A1 A2 A3 A4 A5 A6 A7 A8

Topology graph representing type hierarchy and intersections. We find MDTD by controlled breaking and re-wiring of this graph.

31 / 61

slide-99
SLIDE 99

Step 0

Node Boolean Standard expression partition

6 1 2 3 4 8 5

1 A1 → A1 ∩ A6 2 A2 3 A3 4 A4 5 A5 6 A6 A6 collect into D 8 A8 X7 A7

32 / 61

slide-100
SLIDE 100

Step 1

Node Boolean Standard expression partition

5 4 8 1 2 3

1 A1 → A1 ∩ A6 ∩ A5 2 A2 3 A3 4 A4 → A4 ∩ A5 5 A5 A5 collect into D 8 A8 → A8 ∩ A5 X6 A6 X7 A7

33 / 61

slide-101
SLIDE 101

Step 2 using s-expressions

Node Boolean Standard expression partition

2 4 3 1 8

1 A1 ∩ A5 ∩ A6 2 A2 → A2 ∩ A4 ∩ A5 3 A3 4 A4 ∩ A5 → A4 ∩ A5 ∩ A2 8 A8 ∩ A5 9 A2 ∩ A4 ∩ A5 X5 A5 X6 A6 X7 A7

34 / 61

slide-102
SLIDE 102

Summary of MDTD algorithms

◮ Baseline algorithm suffers from several problems.

◮ Set semantics ◮ Slow loops ◮ Explosive size

◮ Graph algorithm fixes some of these problems.

◮ Better loops ◮ Fewer redundant checks

◮ Still a problem:

◮ Set semantics of type specifiers. ◮ Type equivalence ◮ Initial graph construction is Ω(n2)

◮ We can consider a smarter data structure to represent types.

35 / 61

slide-103
SLIDE 103

ROBDD: Reduced Ordered Binary Decision Diagrams

36 / 61

slide-104
SLIDE 104

What is an ROBDD?

An ROBDD is an EQ-canonical representation for a Boolean function ¬(¬Z1 ∧ Z3) ∨ (Z1 ∧ ¬Z2 ∧ ¬Z3) = (Z1 ∧ Z2) ∨ (Z1 ∧ ¬Z2 ∧ Z3) ∨ (¬Z1 ∧ ¬Z3) =

  • (Z1∨¬Z2)∧(Z1∨Z3)∧(¬Z1∨Z2)∧(Z2∨Z3)
  • ∨(¬Z1∧¬Z3)

Z1 Z2 Z3 Z3 T ⊥

37 / 61

slide-105
SLIDE 105

What is an ROBDD?

An ROBDD is an EQ-canonical representation for a Boolean function and an efficient evaluation procedure. ¬(¬Z1 ∧ Z3) ∨ (Z1 ∧ ¬Z2 ∧ ¬Z3) = (Z1 ∧ Z2) ∨ (Z1 ∧ ¬Z2 ∧ Z3) ∨ (¬Z1 ∧ ¬Z3) =

  • (Z1∨¬Z2)∧(Z1∨Z3)∧(¬Z1∨Z2)∧(Z2∨Z3)
  • ∨(¬Z1∧¬Z3)

Given assignments for the Boolean variables, trace through the BDD to obtain true or false.

Z1 Z2 Z3 Z3 T ⊥

37 / 61

slide-106
SLIDE 106

What is an ROBDD?

An ROBDD is an EQ-canonical representation for a Boolean function and an efficient evaluation procedure. To compute a DNF iteratively, follow all paths from Z1 to ⊤, noting the green and red arrows.

Z1→Z2→⊤

  • (¬Z1 ∧ ¬Z3) ∨(Z1 ∧ ¬Z2 ∧ Z3) ∨ (Z1 ∧ Z2)

Z1 Z2 Z3 Z3 T ⊥

37 / 61

slide-107
SLIDE 107

What is an ROBDD?

An ROBDD is an EQ-canonical representation for a Boolean function and an efficient evaluation procedure. To compute a DNF iteratively, follow all paths from Z1 to ⊤, noting the green and red arrows. (¬Z1 ∧ ¬Z3) ∨ (Z1 ∧ ¬Z2 ∧ Z3)

  • Z1→Z2→Z3→⊤

∨(Z1 ∧ Z2)

Z1 Z2 Z3 Z3 T ⊥

37 / 61

slide-108
SLIDE 108

What is an ROBDD?

An ROBDD is an EQ-canonical representation for a Boolean function and an efficient evaluation procedure. To compute a DNF iteratively, follow all paths from Z1 to ⊤, noting the green and red arrows. (¬Z1 ∧ ¬Z3) ∨ (Z1 ∧ ¬Z2 ∧ Z3) ∨

Z1→Z2→⊤

  • (Z1 ∧ Z2)

Z1 Z2 Z3 Z3 T ⊥

37 / 61

slide-109
SLIDE 109

Creative Commons Attribution ShareAlike, Author: Georg Mittenecker

The BDD is the Eierlegende Wollmilchsau of Boolean algebra. BDDs have many (many many..) surprising features and uses.

37 / 61

slide-110
SLIDE 110

The same ROBDD also represents the corresponding CL type specifier and type predicate procedure—no duplicate type checks. (Z1 ∧ Z2) ∨ (Z1 ∧ ¬Z2 ∧ Z3) ∨ (¬Z1 ∧ ¬Z3)

( or ( and Z1 Z2) ( and Z1 ( not Z2) Z3) ( and ( not Z1) ( not Z3 ) ) )

Z1 Z2 Z3 Z3 T ⊥

38 / 61

slide-111
SLIDE 111

How efficient is ROBDD compression

◮ What is the worst-case size of an n-variable ROBDD? ◮ What is expected size? We publish a journal article in ACM: Transactions on Computational Logic entitled: A Theoretical and Numerical Analysis of the Worst-Case Size of Reduced Ordered Binary Decision Diagrams.

39 / 61

slide-112
SLIDE 112

Shape of worst-case ROBDD of n Boolean variables?

Z1 Z2 Z2 Z3 Z3 Z3 Z3 Z4 Z4 Z4 Z4 Z4 Z4 Z4 Z4 Z5 Z5 Z5 Z5 Z5 Z5 Z5 Z5 Z5 Z5 Z5 Z5 Z5 Z5 Z5 Z5 Z6 Z6 Z6 Z6 Z6 Z6 Z6 Z6 Z6 Z6 Z6 Z6 T ⊥ Z7 Z7

Worst-case ROBDD has exponential 2i expansion from top to the belt, and double exponential 22i decay from the belt to bottom.

40 / 61

slide-113
SLIDE 113

Shape of worst-case ROBDD of n Boolean variables?

Z1 Z2 Z2 Z3 Z3 Z3 Z3 Z4 Z4 Z4 Z4 Z4 Z4 Z4 Z4 Z5 Z5 Z5 Z5 Z5 Z5 Z5 Z5 Z5 Z5 Z5 Z5 Z5 Z5 Z5 Z5 Z6 Z6 Z6 Z6 Z6 Z6 Z6 Z6 Z6 Z6 Z6 Z6 T ⊥ Z7 Z7

Worst-case ROBDD has exponential 2i expansion from top to the belt, and double exponential 22i decay from the belt to bottom. However, the worst-case size of the Common Lisp s-expression form of a type specifier has exponential size, but no double-exponential decay.

40 / 61

slide-114
SLIDE 114

We can revisit the graph-based MDTD algorithm using the ROBDD to represent type specifiers.

41 / 61

slide-115
SLIDE 115

We must break the green line joining nodes 4 and 8.

Node4 = A4 ∩ A5 ∩ A2 Node8 = A8 ∩ A5

A2 ⊥ A4 A5 T A5 ⊥ A8 T

We must calculate the standard partition: A4 ∩ A5 ∩ A2 ∩ A8 ∩ A5 (1) A4 ∩ A5 ∩ A2 ∩ A8 ∩ A5 (2) A4 ∩ A5 ∩ A2 ∩ A8 ∩ A5 (3)

42 / 61

slide-116
SLIDE 116

Extending ROBDDs for compatibility with CL type system

◮ Traditionally, ROBDDs assume the Boolean variables are independent. ◮ We propose extending ROBDDs to understand subtype relations.

43 / 61

slide-117
SLIDE 117

X8 = Node4 ∩ Node8 = A4 ∩ A5 ∩ A2 ∩ A8 ∩ A5

A2 A5 A4 ⊥ A8 T A4 ⊥ A8 T

Before After We propose simplifying ROBDDs in the presence of subtypes.

44 / 61

slide-118
SLIDE 118

The standard partition is sometimes simpler.

Node4 ∧ Node8 Node4 ∧ ¬Node8 ¬Node4 ∧ Node8 Before

A2 ⊥ A4 A5 A8 T A2 ⊥ A4 A5 A8 T A2 A5 A4 ⊥ A8 T

After

A4 A5 ⊥ A8 T A2 ⊥ A4 A8 T A4 ⊥ A8 T

45 / 61

slide-119
SLIDE 119

After Step 2 using ROBDDs Node type Node type

9 3 1 4 2

1

A1 A5 ⊥ A6 T

9

A2 A4 ⊥ T

2

A2 A4 ⊥ T

10

A4 A5 ⊥ A8 T

3

A3 T ⊥

X5

A5 T ⊥

4

A2 ⊥ A4 A8 T

X6

A6 T ⊥

8

A4 ⊥ A8 T

X7

A7 T ⊥

46 / 61

slide-120
SLIDE 120

Features of ROBDDs

◮ Refactor baseline and graph-based MDTD algorithms to use ROBDDs. ◮ ROBDDs are algorithmically easy to construct, ◮ ... especially in a language with garbage collection. ◮ Systematically manipulate Boolean operations: ∨, ∧, ⊕, ¬. ◮ Exponential in size, but simplify in presence of subtyping. ◮ Provide structural equivalence.

◮ ... insertion into a set becomes O(log n) rather than O(n).

◮ Serializable to if/then/else code; Will see shortly.

◮ Redundant checks optimized away.

47 / 61

slide-121
SLIDE 121

Optimizing type checking

48 / 61

slide-122
SLIDE 122

Recall the DFA problem?

RTE: (number · integer) ∨ (integer · number)

1 (and number (not integer)) 3 integer 2 integer number

DFA: leads to inefficient generated code; redundant type checks.

X0 ( u n l e s s seq ( r e t u r n n i l )) ( typecase ( pop seq ) ( i n t e g e r ( go X3 )) (( and number ( not i n t e g e r )) ; d u p l i c a t e type check :−( ( go X1 )) ( t ( r e t u r n n i l ) ) )

49 / 61

slide-123
SLIDE 123

We’d like to build an ROBDD to represent a typecase.

We know how to generate efficient code from an ROBDD. ◮ Convert typecase into Boolean expression (typecase

  • bj

(T.1 alternative-1 ) (T.2 alternative-2 ) ... (T.n alternative-n ))

50 / 61

slide-124
SLIDE 124

We’d like to build an ROBDD to represent a typecase.

We know how to generate efficient code from an ROBDD. ◮ Convert typecase into Boolean expression (typecase

  • bj

(T.1 alternative-1 ) (T.2 alternative-2 ) ... (T.n alternative-n )) ◮ Transform alternatives with side-effects into predicates pretending side-effect free. alternative-1 → Pseudo.type-1 alternative-2 → Pseudo.type-2 ... alternative-n → Pseudo.type-n

50 / 61

slide-125
SLIDE 125

Transform typecase into type specifier

(typecase

  • bj

(T.1 Pseudo.type .1) ; alternative-1 (T.2 Pseudo.type .2) ; alternative-2 ... (T.n Pseudo.type.n)) ; alternative-n Now this pure Boolean expression can be converted to DNF. (or (and T.1 Pseudo.type .1) (and T.2 (not T.1) Pseudo.type .2) ... (and T.n (not T.1) (not T.2) ... (not T.n-1) Pseudo.type.n))

51 / 61

slide-126
SLIDE 126

Another bdd-typecase example

( bdd−typecase

  • bj

(( and unsigned−byte ( not ( e q l 42))) ( d e l e t e − f i l e )) (( e q l 42) ( rename−file )) (( and number ( not ( e q l 42)) ( not fixnum )) ( d u p l i c a t e − f i l e )) (( and ( not fixnum ) unsigned−byte ) ( l a u n c h − m i s s i l e s ) ) ) number unsigned-byte fixnum (eql 42)

52 / 61

slide-127
SLIDE 127

Another bdd-typecase example

( bdd−typecase

  • bj

(( and unsigned−byte ( not ( e q l 42))) ( d e l e t e − f i l e )) (( e q l 42) ( rename−file )) (( and number ( not ( e q l 42)) ( not fixnum )) ( d u p l i c a t e − f i l e )) (( and ( not fixnum ) unsigned−byte ) ( l a u n c h − m i s s i l e s ) ) )

fixnum unsigned-byte number (eql 42) ⊥ unsigned-byte pt-rename pt-delete pt-duplicate T

52 / 61

slide-128
SLIDE 128

Properties of bdd-typecase

fixnum unsigned-byte number (eql 42) ⊥ unsigned-byte pt-rename pt-delete pt-duplicate T

◮ No duplicate type checks.

53 / 61

slide-129
SLIDE 129

Properties of bdd-typecase

fixnum unsigned-byte number (eql 42) ⊥ unsigned-byte pt-rename pt-delete pt-duplicate T

◮ No duplicate type checks. ◮ No super-type checks.

53 / 61

slide-130
SLIDE 130

Properties of bdd-typecase

fixnum unsigned-byte number (eql 42) ⊥ unsigned-byte pt-rename pt-delete pt-duplicate T

◮ No duplicate type checks. ◮ No super-type checks. ◮ Missing Pseudo... implies unreachable code.

53 / 61

slide-131
SLIDE 131

Properties of bdd-typecase

fixnum unsigned-byte number (eql 42) ⊥ unsigned-byte pt-rename pt-delete pt-duplicate T

◮ No duplicate type checks. ◮ No super-type checks. ◮ Missing Pseudo... implies unreachable code.

◮ No missiles launched!

53 / 61

slide-132
SLIDE 132

Properties of bdd-typecase

fixnum unsigned-byte number (eql 42) ⊥ unsigned-byte pt-rename pt-delete pt-duplicate T

◮ No duplicate type checks. ◮ No super-type checks. ◮ Missing Pseudo... implies unreachable code.

◮ No missiles launched!

◮ Serializable to efficient code.

53 / 61

slide-133
SLIDE 133

Machine generated code with tagbody/go.

( tagbody L1 ( i f ( typep

  • bj

' fixnum ) ( go L2 ) ( go L4 ) ) L2 ( i f ( typep

  • bj

' unsigned−byte ) ( go L3 ) ( r e t u r n n i l ) ) L3 ( i f ( typep

  • bj

'( e q l 42)) ( go P1) ( go P2 )) L4 ( i f ( typep

  • bj

' number ) ( go L5 ) ( r e t u r n n i l ) ) L5 ( i f ( typep

  • bj

' unsigned−byte ) ( go P2) ( go P3 )) P1 ( r e t u r n ( rename−file )) P2 ( r e t u r n ( d e l e t e − f i l e )) P3 ( r e t u r n ( d u p l i c a t e − f i l e ) ) )

fixnum unsigned-byte number (eql 42) ⊥ unsigned-byte pt-rename pt-delete pt-duplicate T

54 / 61

slide-134
SLIDE 134

Back to the deterministic state machine

1 (and number (not integer)) 3 integer 2 integer number

X0 ( u n l e s s seq ( r e t u r n n i l )) ( bdd−typecase ( pop seq ) ( i n t e g e r ( go X3 )) (( and number ( not i n t e g e r )) ( go X1 )) ( t ( r e t u r n n i l ) ) )

55 / 61

slide-135
SLIDE 135

Back to the deterministic state machine

1 (and number (not integer)) 3 integer 2 integer number

X0 ( u n l e s s seq ( r e t u r n n i l )) ( bdd−typecase ( pop seq ) ( i n t e g e r ( go X3 )) (( and number ( not i n t e g e r )) ( go X1 )) ( t ( r e t u r n n i l ) ) )

integer pt-go-x3 number T ⊥ pt-go-x2 pt-return

55 / 61

slide-136
SLIDE 136

Back to the deterministic state machine

1 (and number (not integer)) 3 integer 2 integer number

X0 ( u n l e s s seq ( r e t u r n n i l )) ( bdd−typecase ( pop seq ) ( i n t e g e r ( go X3 )) (( and number ( not i n t e g e r )) ( go X1 )) ( t ( r e t u r n n i l ) ) )

X0 ( u n l e s s seq ( r e t u r n n i l ) ) ( l e t ( ( obj ( pop seq ) ) ) ( tagbody L0 ( i f ( typep

  • bj

' i n t e g e r ) ( go P0) ( go L2 ) ) L2 ( i f ( typep

  • bj

' number ) ( go P1) ( go P2 )) P0 ( go X3) P1 ( go X1) P2 ( r e t u r n n i l ) ) )

55 / 61

slide-137
SLIDE 137

Results and Conclusions

56 / 61

slide-138
SLIDE 138

Performance comparison using various algorithms

101 102 103 104 10−4 10−3 10−2 10−1 100 CL types 101 102 103 10−4 10−3 10−2 10−1 100 Integer ranges 101 102 10−4 10−3 10−2 10−1 100 MEMBER types 101 102 103 104 10−4 10−3 10−2 10−1 100 Real number ranges 101 102 10−4 10−3 10−2 10−1 100 Object System types

mdtd-bdd mdtd-bdd-graph mdtd-graph mdtd-rtev2 parameterized-mdtd-bdd-graph

All plots show y = timecomputation vs. x = sizeinput × sizeoutput.

57 / 61

slide-139
SLIDE 139

ROBDD worst case size

N |ROBDDN| 1 3 2 5 3 7 4 11 5 19 6 31 7 47 8 79 9 143 10 271 11 511 12 767 13 1279 14 2303 15 4351 ◮ Number of labels is number of nodes in the ROBDD.

58 / 61

slide-140
SLIDE 140

ROBDD worst case size

N |ROBDDN| 1 3 2 5 3 7 4 11 5 19 6 31 7 47 8 79 9 143 10 271 11 511 12 767 13 1279 14 2303 15 4351 ◮ Number of labels is number of nodes in the ROBDD. ◮ Worst case code size for N type checks (including pseudo-predicates), proportional to full ROBDD size for N variables.

58 / 61

slide-141
SLIDE 141

ROBDD worst case size

N |ROBDDN| 1 3 2 5 3 7 4 11 5 19 6 31 7 47 8 79 9 143 10 271 11 511 12 767 13 1279 14 2303 15 4351 ◮ Number of labels is number of nodes in the ROBDD. ◮ Worst case code size for N type checks (including pseudo-predicates), proportional to full ROBDD size for N variables. ◮ But our ROBDD is never worst-case.

58 / 61

slide-142
SLIDE 142

Summary of Contributions

◮ Common Lisp types augmented to support regular type expressions

59 / 61

slide-143
SLIDE 143

Summary of Contributions

◮ Common Lisp types augmented to support regular type expressions

◮ ... extending rational language theory and ROBDDs ◮ ... to accommodate subtyping.

59 / 61

slide-144
SLIDE 144

Summary of Contributions

◮ Common Lisp types augmented to support regular type expressions

◮ ... extending rational language theory and ROBDDs ◮ ... to accommodate subtyping.

◮ Released open source versions of several Common Lisp packages developed for the thesis. Available on Quicklisp and LRDE GitLab.

59 / 61

slide-145
SLIDE 145

Summary of Contributions

◮ Common Lisp types augmented to support regular type expressions

◮ ... extending rational language theory and ROBDDs ◮ ... to accommodate subtyping.

◮ Released open source versions of several Common Lisp packages developed for the thesis. Available on Quicklisp and LRDE GitLab. ◮ Demonstrated use of BDDs to represent and compute with Common Lisp types.

59 / 61

slide-146
SLIDE 146

Summary of Contributions

◮ Common Lisp types augmented to support regular type expressions

◮ ... extending rational language theory and ROBDDs ◮ ... to accommodate subtyping.

◮ Released open source versions of several Common Lisp packages developed for the thesis. Available on Quicklisp and LRDE GitLab. ◮ Demonstrated use of BDDs to represent and compute with Common Lisp types. ◮ Journal publication: ACM Transactions on Computational Logic, A Theoretical and Numerical Analysis of the Worst-Case Size of Reduced Ordered Binary Decision Diagrams.

59 / 61

slide-147
SLIDE 147

Summary of Contributions

◮ Common Lisp types augmented to support regular type expressions

◮ ... extending rational language theory and ROBDDs ◮ ... to accommodate subtyping.

◮ Released open source versions of several Common Lisp packages developed for the thesis. Available on Quicklisp and LRDE GitLab. ◮ Demonstrated use of BDDs to represent and compute with Common Lisp types. ◮ Journal publication: ACM Transactions on Computational Logic, A Theoretical and Numerical Analysis of the Worst-Case Size of Reduced Ordered Binary Decision Diagrams. ◮ Published and particapted each year (3 times) in European Lisp Symposium

59 / 61

slide-148
SLIDE 148

Perspectives

◮ Better describe (or characterize) which MDTD algorithms are better for which kind of input. ◮ ... Performance tests with minimal sized ROBDD structures. ◮ Improve s-expression based manipulation. ◮ subtypep can almost be implemented in terms of ROBDD operations. ◮ Extend destructuring-case, remove duplication, detect vacuity. (ELS 2019?) ◮ Improve the decision procedure of PCL incorporating SICL technique of inlining constants. ◮ Extend to other dynamic languages? Possible?

60 / 61

slide-149
SLIDE 149

Q/A

Questions?

i

Code available at https://gitlab.lrde.epita.fr/jnewton/regular-type-expression and also (ql:quickload :regular-type-expression)

61 / 61

slide-150
SLIDE 150

Donald Knuth’s new toy.

Binary decision diagrams (ROBDDs) are wonderful, and the more I play with them the more I love them. For fifteen months I’ve been like a child with a new toy, being able now to solve problems that I never imagined would be tractable... I suspect that many readers will have the same experience ... there will always be more to learn about such a fertile subject. [Donald Knuth, Art of Computer Science, Volume 4]

1 / 26

slide-151
SLIDE 151

2 / 26

slide-152
SLIDE 152

Algebra of ROBDDs

(Z1 ∧ Z2 ∨ ¬Z1 ∧ ¬Z2) ∨ (Z1 ∧ ¬Z2 ∧ Z3) = Z1 ∧ Z2 ∨ ¬Z1 ∧ ¬Z2 ∨ Z1 ∧ ¬Z2 ∧ Z3

Z1 Z2 Z3 T ⊥

  • Z1

Z2 ⊥ Z3 T

=

Z1 Z2 Z3 T Z3 ⊥

3 / 26

slide-153
SLIDE 153

Algebra of ROBDDs

Negation is easy, just swap the true/false nodes. ¬(Z1 ∧ Z2 ∨ ¬Z1 ∧ ¬Z2 ∨ Z1 ∧ ¬Z2 ∧ Z3) = Z1 ∧ ¬Z2 ∧ ¬Z3 ∨ ¬Z1 ∧ Z3

¬

Z1 Z2 Z3 T Z3 ⊥

=

Z1 Z2 Z3 ⊥ Z3 T

3 / 26

slide-154
SLIDE 154

Programmatic treatment of an RTE

By homoiconicity we treat the surface syntax as the internal representation. (defun walk-rte (transform pattern) (typecase pattern (( cons (member :or :and :not :cat :* :+ :?)) (cons (first pattern) (mapcar (lambda (p) (walk-rte transform p)) (rest pattern )))) ... (t (funcall transform pattern ))))

4 / 26

slide-155
SLIDE 155

Use tail-call optimized local functions, if the target language does not support GOTO?

( l a b e l s (( L1 () ( i f ( typep

  • bj

' fixnum ) ( L2 ) ( L4 ) ) ) ( L2 () ( i f ( typep

  • bj

' unsigned−byte ) ( L3 ) n i l ) ) ( L3 () ( i f ( typep

  • bj

'( e q l 42)) (P1) (P2 ) ) ) ( L4 () ( i f ( typep

  • bj

' number ) ( L5 ) n i l ) ) ( L5 () ( i f ( typep

  • bj

' unsigned−byte ) (P2) (P3 ) ) ) (P1 ( ) ( rename−file ) ) (P2 ( ) ( d e l e t e − f i l e ) ) (P3 ( ) ( d u p l i c a t e − f i l e ) ) ) ( L1 ) )

5 / 26

slide-156
SLIDE 156

Common Lisp and types

◮ Type declarations in structured data and functions.

( d e f c l a s s c i r c l e () (( r a d i u s : type r e a l ) ; r e s t r i c t s l o t to c e r t a i n type ( c e n t e r : type cons ) ) ) ( defun cube−root ( x ) ( d e c l a r e ( type r e a l x )) ; promise to compiler ( expt x 1/3))

6 / 26

slide-157
SLIDE 157

Common Lisp and types

◮ Type declarations in structured data and functions. ◮ Arbitrary logic at run-time.

( defun s t r i n g i f y ( data ) ( typecase data ; p r i o r i t y based type t e s t ( s t r i n g data ) ( symbol ( symbol−name data )) ( l i s t ( mapcar #' s t r i n g i f y data ) ) ) )

6 / 26

slide-158
SLIDE 158

With the type definition (rte ...) we can use the surface syntax anywhere Common Lisp allows a type specifier. (defclass polygon () (( color) (points :type (rte (:* (:cat fixnum real )))))) (defun fun-42 (float-plist) (declare (type (rte (:+ (:cat keyword float ))) float-plist )) ...)

7 / 26

slide-159
SLIDE 159

With the type definition (rte ...) we can use the surface syntax anywhere Common Lisp allows a type specifier. (defclass polygon () (( color) (points :type (rte (:* (:cat fixnum real )))))) (defun fun-42 (float-plist) (declare (type (rte (:+ (:cat keyword float ))) float-plist )) ...) By homoiconicity we treat the surface syntax as the internal representation.

7 / 26

slide-160
SLIDE 160

Programmatic treatment of an RTE

By homoiconicity we treat the surface syntax as the internal representation. (defun walk-rte (transform pattern) (typecase pattern (( cons (member :or :and :not :cat :* :+ :?)) (cons (first pattern) (mapcar (lambda (p) (walk-rte transform p)) (rest pattern )))) ... (t (funcall transform pattern ))))

8 / 26

slide-161
SLIDE 161

Baseline Demo Step 1

We can observe the procedure execution textually as well. The explosive size of the type specifiers becomes evident.

found 1 d i s j o i n t : new−disjoint D1 D = ( 1 : A7 ) U = ( 1 : A1 2 : A2 3 : A3 4 : A4 5 : A5 6 : A6 7 : A8 ) i n t e r s e c t i n g : U1 U2

9 / 26

slide-162
SLIDE 162

Baseline Demo Step 2

found d i s j o i n t : new−disjoint ( ) D = ( 1 : A7 ) U = ( 1 : ( and A1 ( not A2 ) ) 2 : A2 3 : A3 4 : A4 5 : A5 6 : A6 7 : A8 ) i n t e r s e c t i n g : U1 U3

10 / 26

slide-163
SLIDE 163

Baseline Demo Step 3

found d i s j o i n t : new−disjoint ( ) D = ( 1 : A7 ) U = ( 1 : ( and ( and A1 ( not A2 )) A3) 2 : ( and A3 ( not ( and A1 ( not A2 ) ) ) ) 3 : ( and ( and A1 ( not A2 )) ( not A3 ) ) 4 : A2 5 : A4 6 : A5 7 : A6 8 : A8 ) i n t e r s e c t i n g : U1 U4

11 / 26

slide-164
SLIDE 164

Baseline Demo Step 4

found 2 new d i s j o i n t : D1 D2 D = ( 1 : ( and ( and ( and A1 ( not A2 )) A3) ( not A4 ) ) 2 : ( and ( and ( and A1 ( not A2 )) A3) A4) 3 : A7 ) U = ( 1 : ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) 2 : ( and A3 ( not ( and A1 ( not A2 ) ) ) ) 3 : ( and ( and A1 ( not A2 )) ( not A3 ) ) 4 : A2 5 : A5 6 : A6 7 : A8 ) i n t e r s e c t i n g : U1 U2

12 / 26

slide-165
SLIDE 165

Baseline Demo Step 5

found 0 new d i s j o i n t : D = ( 1 : ( and ( and ( and A1 ( not A2 )) A3) ( not A4 ) ) 2 : ( and ( and ( and A1 ( not A2 )) A3) A4) 3 : A7 ) U = ( 1 : ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) 2 : ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) 3 : ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) 4 : ( and ( and A1 ( not A2 )) ( not A3 ) ) 5 : A2 6 : A5 7 : A6 8 : A8 ) i n t e r s e c t i n g : U1 U5

13 / 26

slide-166
SLIDE 166

Baseline Demo Step 6

found 1 new d i s j o i n t : D1 D = ( 1: ( and ( and A4 ( not ( and ( and A1 ( not A2 )) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) 2 : ( and ( and ( and A1 ( not A2 )) A3) ( not A4 ) ) 3 : ( and ( and ( and A1 ( not A2 )) A3) A4) 4 : A7 ) U = ( 1: ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) 2 : ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) 3 : ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) 4 : ( and ( and A1 ( not A2 )) ( not A3 ) ) 5 : A5 6 : A6 7 : A8 ) i n t e r s e c t i n g : U1 U2

14 / 26

slide-167
SLIDE 167

Baseline Demo Step 7

found 1 d i s j o i n t : D1 D = ( 1: ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) 2: ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) 3: ( and ( and ( and A1 ( not A2 )) A3) ( not A4 ) ) 4: ( and ( and ( and A1 ( not A2 )) A3) A4) 5: A7 ) U = ( 1: ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) 2: ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) 3: ( and ( and A1 ( not A2 )) ( not A3 ) ) 4: A5 5: A6 6: A8 ) i n t e r s e c t i n g : U1 U2 15 / 26

slide-168
SLIDE 168

Baseline Demo Step 8

found 2 d i s j o i n t : new−disjoint D1 D2 D = ( 1: ( and ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ) 2: ( and ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) 3 : ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) 4 : ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) 5 : ( and ( and ( and A1 ( not A2 )) A3) ( not A4 ) ) 6 : ( and ( and ( and A1 ( not A2 )) A3) A4) 7 : A7 ) U = ( 1: ( and ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ( not ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ) ) 2 : ( and ( and A1 ( not A2 )) ( not A3 ) ) 3 : A5 4 : A6 5 : A8 ) i n t e r s e c t i n g : U1 U2

16 / 26

slide-169
SLIDE 169

Baseline Demo Step 9

found d i s j o i n t : D ( 1: ( and ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ) 2: ( and ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) 3: ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) 4 : ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) 5 : ( and ( and ( and A1 ( not A2 )) A3) ( not A4 ) ) 6 : ( and ( and ( and A1 ( not A2 )) A3) A4) 7 : A7 ) U ( 1 : ( and ( and ( and A1 ( not A2 )) ( not A3 )) ( not ( and ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ( not ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ) ) ) ) 2 : ( and ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ( not ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ) ) 3 : A5 4 : A6 5 : A8 ) i n t e r s e c t i n g : U1 U4

17 / 26

slide-170
SLIDE 170

Baseline Demo Step 10

found 1 d i s j o i n t : D1 D=8 U=4 D ( 1: A6 2: ( and ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ) 3: ( and ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) 4: ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) 5 : ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) 6 : ( and ( and ( and A1 ( not A2 )) A3) ( not A4 ) ) 7 : ( and ( and ( and A1 ( not A2 )) A3) A4) 8 : A7 ) U ( 1 : ( and ( and ( and ( and A1 ( not A2 )) ( not A3 ) ) ( not ( and ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ( not ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ) ) ) ) ( not A6 )) 2 : ( and ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ( not ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ) ) 3 : A5 4 : A8 ) i n t e r s e c t i n g : U1 U4

18 / 26

slide-171
SLIDE 171

Baseline Demo Step 11

found 2 d i s j o i n t : D1 D2 D=10 U=3 D ( 1 : ( and ( and ( and ( and ( and A1 ( not A2 )) ( not A3 ) ) ( not ( and ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ( not ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ) ) ) ) ( not A6 )) ( not A8 )) 2 : ( and ( and ( and ( and ( and A1 ( not A2 )) ( not A3 ) ) ( not ( and ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ( not ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ) ) ) ) ( not A6 )) A8) 3 : A6 4 : ( and ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ) 5: ( and ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) 6: ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) 7: ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) 8: ( and ( and ( and A1 ( not A2 ) ) A3) ( not A4 ) ) 9: ( and ( and ( and A1 ( not A2 ) ) A3) A4) 10: A7 ) U ( 1: ( and A8 ( not ( and ( and ( and ( and A1 ( not A2 )) ( not A3 ) ) ( not ( and ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ( not ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ) ) ) ) ( not A6 ) ) ) ) 2: ( and ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ( not ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ) ) 3: A5 ) i n t e r s e c t i n g : U1 U2

19 / 26

slide-172
SLIDE 172

Baseline Demo Step 12

found 1 d i s j o i n t : D1 D2 D ( 1 : ( and ( and ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ( not ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ) ) ( not ( and A8 ( not ( and ( and ( and ( and A1 ( not A2 )) ( not A3 ) ) ( not ( and ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ( not ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ) ) ) ) ( not A6 ) ) ) ) ) ) 2 : ( and ( and ( and ( and ( and A1 ( not A2 )) ( not A3 ) ) ( not ( and ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ( not ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ) ) ) ) ( not A6 ) ) ( not A8 )) 3 : ( and ( and ( and ( and ( and A1 ( not A2 )) ( not A3 ) ) ( not ( and ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ( not ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ) ) ) ) ( not A6 )) A8) 4: A6 5: ( and ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ) 6: ( and ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) 7: ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) 8: ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) 9: ( and ( and ( and A1 ( not A2 ) ) A3) ( not A4 ) ) 10: ( and ( and ( and A1 ( not A2 )) A3) A4) 11: A7 ) U ( 1: ( and A8 ( not ( and ( and ( and ( and A1 ( not A2 )) ( not A3 ) ) ( not ( and ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ( not ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ) ) ) ) ( not A6 ) ) ) ) 2: A5 ) i n t e r s e c t i n g : U1 U2

20 / 26

slide-173
SLIDE 173

Baseline Demo Step 13

found 2 d i s j o i n t : D1 D2 D ( 1 : A5 2 : ( and ( and A8 ( not ( and ( and ( and ( and A1 ( not A2 )) ( not A3 ) ) ( not ( and ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ( not ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 )) A3 ) ) ) ) ) ) ) ) ) ) ) ( not A6 ) ) ) ) ( not A5 )) 3 : ( and ( and ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ( not ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ) ) ( not ( and A8 ( not ( and ( and ( and ( and A1 ( not A2 )) ( not A3 ) ) ( not ( and ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ( not ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ) ) ) ) ( not A6 ) ) ) ) ) ) 4 : ( and ( and ( and ( and ( and A1 ( not A2 )) ( not A3 ) ) ( not ( and ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ( not ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ) ) ) ) ( not A6 )) ( not A8 )) 5: ( and ( and ( and ( and ( and A1 ( not A2 )) ( not A3 ) ) ( not ( and ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ( not ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ) ) ) ) ( not A6 )) A8) 6: A6 7: ( and ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ) 8: ( and ( and ( and A2 ( not ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) ( not ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) ) ) ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( not ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) ) ) 9: ( and ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ( not ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ) ) 10: ( and ( and A4 ( not ( and ( and A1 ( not A2 ) ) A3 ) ) ) ( and A3 ( not ( and A1 ( not A2 ) ) ) ) ) 11: ( and ( and ( and A1 ( not A2 )) A3) ( not A4 ) ) 12: ( and ( and ( and A1 ( not A2 )) A3) A4) 13: A7 ) U ( )

21 / 26

slide-174
SLIDE 174

Baseline MDTD algorithm

Algorithm 1: Finds the maximal disjoint type decomposition Input: A finite non-empty set U of sets Output: A finite set D of disjoint sets

1 D ← ∅ 2 while true do 3

D′ ← {u ∈ U | u′ ∈ U \ {u} = ⇒ u ∩ u′ = ∅}

4

D ← D ∪ D′

5

U ← U \ D′

6

if U = ∅ then

7

return D

8

else

9

Find α ∈ U and β ∈ U such that α ∩ β = ∅

10

U ← U \ {α, β} ∪ standard-partition

22 / 26

slide-175
SLIDE 175

Step 3 using s-expressions

Node Boolean Standard expression partition

4 8 1 2 3 9

1 A1 ∩ A5 ∩ A6 2 A2 ∩ A4 ∩ A5 3 A3 4 A4 ∩ A5 ∩ A2 → A4 ∩ A5 ∩ A2 ∩ A8 ∩ A5 8 A8 ∩ A5 → A8 ∩ A5 ∩ A4 ∩ A5 ∩ A2 9 A2 ∩ A4 ∩ A5 10 A4 ∩ A5 ∩ A2 ∩ A8 ∩ A5 X5 A5 X6 A6 X7 A7

23 / 26

slide-176
SLIDE 176

Step 4 using s-expressions

Node

Boolean Standard expression partition

8 1 10 4 3 9 2

1 A1 ∩ A5 ∩ A6

→ A1 ∩ A5 ∩ A6 ∩ A8 ∩ A5 ∩ A4 ∩ A5 ∩ A2

2 A2 ∩ A4 ∩ A5 3 A3 4

A4 ∩ A5 ∩ A2 ∩ A8 ∩ A5

8

A8 ∩ A5 ∩ A4 ∩ A5 ∩ A2

collect 9 A2 ∩ A4 ∩ A5 10

A4 ∩ A5 ∩ A2 ∩ A8 ∩ A5

X5 A5 X6 A6 X7 A7

24 / 26

slide-177
SLIDE 177

Step 5 using s-expressions

Node

Boolean Standard expression partition

10 1 4 9 3 2

1

A1 ∩ A5 ∩ A6 → A1 ∩ A5 ∩ A6 ∩ A8 ∩ A5 ∩ A4 ∩ A5 ∩ A2 ∩ A8 ∩ A5 ∩ A4 ∩ A5 ∩ A2 ∩ A4 ∩ A5 ∩ A2 ∩ A8 ∩ A5

2 A2 ∩ A4 ∩ A5 3 A3 4 A4 ∩ A5 ∩ A2 ∩ A8 ∩ A5 9 A2 ∩ A4 ∩ A5 10 A4 ∩ A5 ∩ A2 ∩ A8 ∩ A5 collect X5 A5 X6 A6 X7 A7 X8 A8 ∩ A5 ∩ A4 ∩ A5 ∩ A2

25 / 26

slide-178
SLIDE 178

Step 6 using s-expressions

Node Boolean expression

9 3 1 4 2

1 A1 ∩ A6 ∩A8 ∩ A5 ∩ A4 ∩ A5 ∩ A2 ∩A4 ∩ A5 ∩ A2 ∩ A8 ∩ A5 2 A2 ∩ A4 ∩ A5 3 A3 4 A4 ∩ A5 ∩ A2 ∩ A8 ∩ A5 9 A2 ∩ A4 ∩ A5 X5 A5 X6 A6 X7 A7 X8 A8 ∩ A5 ∩ A4 ∩ A5 ∩ A2 X10 A4 ∩ A5 ∩ A2 ∩ A8 ∩ A5

26 / 26