Skip to content

Improve reachability / exhaustive checks for pattern matches for class#4379

Closed
gbasler wants to merge 1 commit intoscala:2.11.xfrom
gbasler:topic/patmat-exclusive-cases
Closed

Improve reachability / exhaustive checks for pattern matches for class#4379
gbasler wants to merge 1 commit intoscala:2.11.xfrom
gbasler:topic/patmat-exclusive-cases

Conversation

@gbasler
Copy link
Contributor

@gbasler gbasler commented Mar 12, 2015

hierarchies (relatively flat) with a lot of children.

The CNF encoding for mutually exclusive symbols of a domain that was used so
far, adds a quadratic number of clauses to the formula to check.

E.g. if a domain has the symbols a, b and c then
the clauses

!a \/ !b  /\
!a \/ !c  /\
!b \/ !c

are added.

The first line prevents that a and b are both true at the same time and so
on.

There's a simple, more efficient encoding that can be used instead: consider a
comparator circuit in hardware, that checks that out of n signals, at most 1
is true. Such a circuit can be built in the form of a sequential counter and
thus requires only 3n-4 additional clauses 1. A comprehensible comparison of
different encodings can be found in 2.

Review by @adriaanm or @retronym

@scala-jenkins scala-jenkins added this to the 2.11.7 milestone Mar 12, 2015
@retronym
Copy link
Member

👏

@gbasler gbasler force-pushed the topic/patmat-exclusive-cases branch from 3b6f1e1 to eb80879 Compare March 12, 2015 20:51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/map/foreach/

@adriaanm
Copy link
Contributor

Super! Very elegant.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ops.lengthCompare(5) > 0 is a little more efficient here.

@gbasler
Copy link
Contributor Author

gbasler commented Mar 14, 2015

I've changed a few things due to the review, can squash it, when you are fine with the changes. I'll also have a quick look with the profiler and check how the extreme cases perform...

@lrytz
Copy link
Member

lrytz commented Mar 27, 2015

/rebuild

hierarchies (relatively flat) with a lot of children.

The CNF encoding for mutually exclusive symbols of a domain that was used so
far, adds a quadratic number of clauses to the formula to check.

E.g. if a domain has the symbols `a`, `b` and `c` then
the clauses
```
!a \/ !b  /\
!a \/ !c  /\
!b \/ !c
```
are added.

The first line prevents that `a` and `b` are both true at the same time and so
on.

There's a simple, more efficient encoding that can be used instead: consider a
comparator circuit in hardware, that checks that out of `n` signals, at most 1
is true. Such a circuit can be built in the form of a sequential counter and
thus requires only 3n-4 additional clauses [1]. A comprehensible comparison of
different encodings can be found in [2].

[1]: http://www.carstensinz.de/papers/CP-2005.pdf
[2]: http://www.wv.inf.tu-dresden.de/Publications/2013/report-13-04.pdf
@gbasler gbasler force-pushed the topic/patmat-exclusive-cases branch from cbc52ce to 2822f5c Compare March 29, 2015 12:33
@adriaanm
Copy link
Contributor

adriaanm commented Apr 6, 2015

I think this can be merged as is, with potential performance tuning in a later PR. I dropped the ball on getting this merged in a timely fashion (in my defense, we had a pretty packed end of the quarter). Thanks again!

@adriaanm
Copy link
Contributor

adriaanm commented Apr 6, 2015

Rebasing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants