verification of a brick wang tiling algorithm

28
Verification of a brick Wang tiling algorithm Verification of a brick Wang tiling algorithm Toshiaki Matsushima 1 Yoshihiro Mizoguchi 2 Alexandre Derouet-Jourdan 3 1 Graduate School of Mathematics, Kyushu University 2 Institute of Mathematics for Industry, Kyushu University 3 OLM Digital Inc. March 31, 2016 SCSS2016 at Ochanomizu University, Tokyo

Upload: yoshihiro-mizoguchi

Post on 21-Feb-2017

214 views

Category:

Software


2 download

TRANSCRIPT

Verification of a brick Wang tiling algorithm

Verification of a brick Wang tiling algorithm

Toshiaki Matsushima1 Yoshihiro Mizoguchi2

Alexandre Derouet-Jourdan3

1 Graduate School of Mathematics, Kyushu University

2 Institute of Mathematics for Industry, Kyushu University

3OLM Digital Inc.

March 31, 2016SCSS2016 at Ochanomizu University, Tokyo

Verification of a brick Wang tiling algorithm

Wang Tiling (Hao Wang 1961)

A tile set is a finite set of Wang tiles, unit square tiles withcolored edges.In general, Wang tiling problem is a problem to tile the(infinite) Euclidean plane using arbitrarily many copies of thetiles in the given tile set.Tiles are arranged side by side with matching colors.

Example of Wang tessellation with 13 tiles (cf. Wikipedia)

Verification of a brick Wang tiling algorithm

Wang Tiling for Theoreticians

DecidabilityThe existence of an algorithm to decide whether a given finite set ofWang tiles can tile the plane.Answer: NO! (Robert Berger 1966)It is equivalent to the halting problem of the Turing machine.

Periodic tilingIf a finite set of Wang tiles can tile the plane, then there exists also aperiodic tiling.Answer: NO!

(Counter examples,20426 tiles (Berger 1966),14 tiles (Kari 1996) ,

13 tiles (Culik 1996),11 tiles (Jeandel & Rao 2015)∗).

Verification of a brick Wang tiling algorithm

Wang Tiling for Computer Graphics

Aperiodic texture mapping (by J. Stam), European ResearchConsortium for Informatics and Mathematics (ERCIM), 1997.[The first use of Wang Tiles for texture synthesis.]

Tilings and Patterns (by B. Grunbaum, et.al.), H.Freeman andCompany, 1987. [Deterministic algorithm using 16 tiles.]

Wang Tiles for Image and Texture Generation (by M.F.Cohen,et.al.), ACM. Trans. Graph. 22(3),287-294, 2003.[Deterministic (sequential) algorithm using 8 tiles for 4 colors.]

Recursive Wang Tiles for Real-Time Blue Noise (by J. Kopf,et.al.) SIGGRAPH 2006. [Stochastic algorithm using 2K2 tilesfor K colors.]

Verification of a brick Wang tiling algorithm

Wang Tiling Method

ProsA very efficient simple method to produce complex structures such asaperiodic tiling.A control parameter is a choice of a tile set, this gives intuitional operationsto control result tilings.

ConsIt is undecidable to check a given tile set can tile the plane.It is decidable to check a given tile set can tile a bounded region with agiven boundary condition. But it is hard to check it for any boundarycondition.

Our ApproachWe introduce a class of tile sets and we show that any tile sets in our classcan always tile a rectangular region for any boundary condition.

Verification of a brick Wang tiling algorithm

Abstract

A brick Wang tiles set is a tile set introduced to model wall patternsin computer graphics [A.D-Jourdan 2015].

We implemented a tiling algorithm with a proof of its correctness.

We also show a formal proof of an existence of a tiling of any givenbrick Wang tile set for any rectangular region larger than 2 × 2.

We reduce the problem into a tiling problem of a 2 × 2 region.

We divide the boundary colorings into finite classes and give asolution for each class.

We proved formally that the enumeration of classes are sufficientand the solution is correct for each class.

Verification of a brick Wang tiling algorithm

Brick Wang tiling

Let C = {i | 0 ≤ i ≤ k } (k > 0) be a finite set of colors.

Definition (Wang Tile)

A Wang tile is a function w : {t , l, b , r} → C .

Definition (Brick Wang Tile)

A Wang tile w is said to be a brick Wang tile ifw(t) , w(b) ∧ w(l) = w(r) or w(t) = w(b) ∧ w(l) , w(r).We define the set WC of all brick Wang tiles for a given color set C .

Values w(t), w(l), w(b), and w(r) denote the colors of the top,left, bottom, and right edges, respectively, of a tile w.

brick: not brick:

where C = {�,�,�,�,�,�}.

Verification of a brick Wang tiling algorithm

Example

Let the color set C = {0.2, 0.4, 0.6, 0.8}. Consider a brick Wang tile in theleft Figure, where w(l) = w(r) = 0.6, w(t) = 0.8, and w(b) = 0.4.We draw three lines on a square tile, the vertices of which are{(0, 0), (0, 1), (1, 1), (1, 0)} according to the values of w(l), w(r), w(t),and w(b). Since w(l) = w(r), we draw a line from left to right. For thiscase, we draw a line from (0, 0.6) to (1, 0.6). Since w(t) , w(b), wedraw two perpendicular lines from (0.8, 1) and (0.4, 0) to the horizontalline. By tiling these brick Wang tiles, a brick wall pattern texture havingdifferent size of bricks can be created.

Verification of a brick Wang tiling algorithm

Tiling algorithm (1)

Let C = {i | 0 ≤ i ≤ k } and |C | ≥ 3.We use a notation ¬c to indicate a color different from c ∈ C .

¬c = min{c′ | c′ , c}

¬c1 ∧ ¬c2 = min{c′ | c′ , c1 ∧ c′ , c2}

Since we use an extracted function as a function over the typeintegers, we consider the domain of an every function as nat inCoq. To describe properties over a finite set C and a finite regionPnm, we use some bounding conditions for a variable in nat. Wedo not care about a values of functions b , e and e′ outside of theregion Pnm.

Verification of a brick Wang tiling algorithm

Brick Wang tiling

Definition

A rectangular region {(i, j) ∈ N × N | 1 ≤ i ≤ n, 1 ≤ j ≤ m} isdenoted by Pnm. A tiling is a function T : Pnm → WC , and wedenote T (i, j) by Ti,j . A boundary (coloring) over Pnm is afunctionbnm : {0, n+1}×{j | 1 ≤ j ≤ m}∪{i | 1 ≤ i ≤ n}×{0,m+1} → C .

Verification of a brick Wang tiling algorithm

Valid tiling

Definition

Let Pnm be a rectangular region, and let bnm be a boundary coloring overPnm. A tiling T is valid for bnm if

Ti,j(t) =

bnm(0, j) (i = 1, 1 ≤ j ≤ m)

Ti−1,j(b) (2 ≤ i ≤ n, 1 ≤ j ≤ m),

Tn,j(b) = bnm(n + 1, j) (1 ≤ j ≤ m),

Ti,j(l) =

bnm(i, 0) (1 ≤ i ≤ n, j = 1)Ti,j−1(r) (1 ≤ i ≤ n, 2 ≤ j ≤ m), and

Ti,m(r) = bnm(i,m + 1) (1 ≤ i ≤ n).

Ti−1,j

Ti,j−1 Ti,j Ti,j+1

Ti+1,j

Verification of a brick Wang tiling algorithm

Edge functions

Definition

For a valid tiling T for bnm over Pnm, we define horizontal edgefunction eT : N → N → C and vertical edge functione′T: N → N → C as follows:

eT (i, j) =

Ti+1,j(t) (0 ≤ i ≤ n − 1, 1 ≤ j ≤ m)

Tn,j(b) (i = n, 1 ≤ j ≤ m)

0 (otherwise)

e′T(i, j) =

Ti,j+1(l) (1 ≤ i ≤ n, 0 ≤ j ≤ m − 1)Ti,m(r) (1 ≤ i ≤ n, j = m)

0 (otherwise)

Verification of a brick Wang tiling algorithm

Valid edge functions

Lemma

Let T be a valid tiling for a boundary coloring bnm over a rectangularregion Pnm.

1 eT (0, j) = b(0, j) (1 ≤ j ≤ m),eT (n, j) = b(n + 1, j) (1 ≤ j ≤ m).

2 e′T(i, 0) = b(i, 0) (1 ≤ i ≤ n),

e′T(i,m) = b(i,m + 1) (1 ≤ i ≤ n).

Verification of a brick Wang tiling algorithm

Brick Pair

Definition

Let Pnm be a rectangular region, e : N → N → C and e′ : N → N → C .A pair (e, e′) is a brick pair over Pnm, if(e(i − 1, j) = e(i, j) ∧ e′(i, j − 1) , e′(i, j)), or(e(i − 1, j) , e(i, j) ∧ e′(i, j − 1) = e′(i, j)) for 1 ≤ i ≤ n, 1 ≤ j ≤ m.

brick: not brick:

Proposition

Let Pnm be a rectangular region, and let (e, e′) be a brick pair over Pnm.Then, there exists a boundary coloring bnm over Pnm and a valid tiling Tover Pnm for bnm such that (eT , e′

T) = (e, e′). �

We denote a boundary coloring bnm and a tiling T in Proposition bybnm(e, e′) and T (e, e′), respectively.

Verification of a brick Wang tiling algorithm

Tileable(1)

Definition (Tileable)

Let n and m be natural numbers. Then, Pnm is tileable if thereexists a valid tiling for any boundary coloring bnm over Pnm.

Lemma (Three boundary condition)

Let WC be the set of all brick Wang tiles for a given color set C .Then we have {(w(l),w(t),w(r)) |w ∈ WC}

= {(w(t),w(r),w(b)) |w ∈ WC}

= {(w(r),w(b),w(l)) |w ∈ WC}

= {(w(b),w(l),w(t)) |w ∈ WC} = C3. �

Verification of a brick Wang tiling algorithm

Tileable(2)

Proposition (A.D-Jourdan 2015)

1 P12 is not tileable (i.e., there exists a boundary coloring suchthat there is no valid tiling).

2 P22 is not tileable if |C | = 2.

Theorem (A.D-Jourdan 2015)

If |C | ≥ 3, then a rectangular region Pnm is tileable for any n ≥ 2and m ≥ 2.

Verification of a brick Wang tiling algorithm

Tiling algorithm (2)

Our algorithm solve a problem over a region Pnm for a givenboundary condition bnm. That is it finds a brick pair (e, e′) from agiven boundary coloring bnm over a region Pnm such that T (e, e′)is valid. Our algorithm consists of three parts:

(Step1) To reduce a tiling problem over Pnm to P2m,(Step2) To reduce a tiling problem over P2m to P22, and(Step3) To solve a tiling problem over P22.

!"# !$# !$$

%&'()*+ , , , , , , %&'()$+  , , , , ,%&'()-+

Verification of a brick Wang tiling algorithm

Tiling algorithm (Step1)

Cosider Pnm and bnm (n,m > 2). We divide it into two tiling problemsover P1m for b1m and P(n−1)m for b(n−1)m, where

b1m(i, j) =

bnm(i, j) (i = 0, 1),bnm(0, j) (i = 2, j = 1, 2),¬ bnm(0, j) (i = 2, 3 ≤ j ≤ m),

b(n−1)m(i, j) =

b1m(2, j) (i = 0),bnm(i + 1, j) (i > 0).

For a tiling over P1m, we solve it by

e(i, j) =

b1m(0, j) (i = 0),b1m(2, j) (i = 1),

e′(1, j) =

bnm(1, 0) (j = 0),¬ bnm(1, 0) ∧ ¬ bnm(1,m + 1) (j = 1),bnm(1,m + 1) (2 ≤ j ≤ m + 1).

Verification of a brick Wang tiling algorithm

Step1: Pnm → P(n−1)m → · · · → P2m

We abbreviate bij = bnm(i, j).

P(n−1)m

b0,1 b0,2 b0,3 b0,m

b0,1 b0,2 ¬b0,3 ¬b0,m

b1,0

b2,0

...

bn,0

b1,m+1

b2,m+1

...

bn,m+1

m m ⇔ ⇔♥ ♦ ♦ ♦

♥= ¬b1,0 ∧ ¬b1,m+1

♦= b1,m+1

!"# !$# !$$

%&'()*+ , , , , , , %&'()$+  , , , , ,%&'()-+

Verification of a brick Wang tiling algorithm

Tiling algorithm (Step2)

Consider P2m and b2m (m > 2). We divide it into two tiling problemover P21 for b21 and P2(m−1) for b2(m−1), where

b21(i, j) =

b2m(i, j) (j = 0, 1),b2m(i, 0) (j = 2),

b2(m−1)(i, j) =

b21(i, 2) (j = 0),b2m(i, j + 1) (j > 0),

For a tiling over P21, we solve it by

e(i, 1) =

b2m(0, 1) (i = 0),¬ b2m(0, 1) ∧ ¬ b2m(3, 1) (i = 1),b2m(3, 1) (i = 2),

e′(i, j) =

b21(i, 0) (j = 0),b21(i, 2) (j = 1).

Verification of a brick Wang tiling algorithm

Step2: P2m → P2(m−1) → · · · → P22

We abbreviate bij = b2m(i, j).

P2(m−1)

b1,0

b2,0

b1,0

b2,0

b1,m+1

b2,m+1

b0,1 b0,2 · · · b0,m

b3,1 b3,2· · · b3,m

♥ ♥= ¬b0,1 ∧ ¬b3,1

!"# !$# !$$

%&'()*+ , , , , , , %&'()$+  , , , , ,%&'()-+

Verification of a brick Wang tiling algorithm

Tiling algorithm (Step3)

Consider P22 and b . We abbreviate bij = b(i, j), eij = e(i, j) ande′

ij= e(i, j). Since it satisfies boundary conditions, we have

e0j = b0j , e2j = b3j , e′i0= bi0 and e′

i2= bi3 (i = 0, 1, j = 0, 1).

So all we need is defining colors e11, e12, e′11

and e′21

. Accordingto the equality conditions of b10 = b13, b20 = b23, b01 = b31 andb02 = b32, we define those values for e and e′. We summarizethem in the Table.

Verification of a brick Wang tiling algorithm

Tiling algorithm (implementation)

A Coq implementation of (e, e′) is a pair of functions e_nm ande’_nm, as shown in the followings:

Fixpoint e_nm (n m : nat) : boundary -> edge :=

fun b : boundary =>

match n with

| 0 | 1 => e_1m b

| 2 => enm_to_emn (fun b’ => e’_n2 m b’) b

| S n’ => fun (i j : nat) =>

match i with

| 0 => (bSnm_to_b1m m b) 0 j

| S i’ => e_nm n’ m (bSnm_to_bnm m b) i’ j

end

end.

Fixpoint e’_nm (n m : nat) : boundary -> edge

.... Similar to e_nm ....

end.

Verification of a brick Wang tiling algorithm

Verification using Coq (1)

We verify conditions, Boundary_i, Boundary_j, and Brick.

Definition Boundary_i (n m : nat)(b : boundary)(e’ : edge) :=

forall i : nat,

e’ i 0 == b i 0 /\ e’ i m == b i (S m) \/ i = 0 \/ n < i.

Definition Boundary_j (n m : nat)(b : boundary)(e : edge) :=

forall j : nat,

e 0 j == b 0 j /\ e n j == b (S n) j \/ j = 0 \/ m < j.

Definition Brick (n m : nat)(e e’ : edge) :=

forall i j : nat,

(e i (S j) == e (S i) (S j) /\ e’ (S i) j != e’ (S i) (S j)) \/

(e i (S j) != e (S i) (S j) /\ e’ (S i) j == e’ (S i) (S j)) \/

n <= i \/ m <= j.

Verification of a brick Wang tiling algorithm

Verification using Coq (2)

The validities of our algorithm (Step 3), (Step 2) and (Step 1) areshowed in P22_Valid_nm, P2m_Valid_nm and e_nm_Valid,respectively.Definition Valid_nm (n m : nat)(b : boundary) :=

Boundary_i n m b (e’_nm n m b)

/\ Boundary_j n m b (e_nm n m b)

/\ Brick n m (e_nm n m b) (e’_nm n m b).

Lemma P22_Valid_nm : forall b : boundary, Valid_nm 2 2 b.

Lemma Valid_nm_ind_2m : forall (b : boundary)(m : nat),

2 <= m -> (forall b’ : boundary, Valid_nm 2 m b’)

-> Valid_nm 2 (S m) b.

Lemma P2m_Valid_nm : forall (b : boundary)(m : nat), 2 <= m

-> Valid_nm 2 m b.

Lemma Valid_nm_ind_nm : forall (b : boundary)(n m : nat),

2 <= n -> 2 <= m -> (forall b’ : boundary, Valid_nm n m b’)

-> Valid_nm (S n) m b.

Theorem e_nm_Valid : forall (b : boundary)(n m : nat),

2 <= n -> 2 <= m -> Valid_nm n m b.

Verification of a brick Wang tiling algorithm

Verification using Coq (3)

Main theorem about the tileablity is translated into a theoremPnm_Tileable in Coq.

Theorem (A.D-Jourdan 2015)

If |C | ≥ 3, then a rectangular region Pnm is tileable for any n ≥ 2and m ≥ 2.

Theorem Pnm_Tileable : forall (b : boundary)(n m : nat),

2 <= n -> 2 <= m

-> exists (e e’ : edge), Valid n m b e e’.

Proof.

move => b n m H0 H1.

exists (e_nm n m b).

exists (e’_nm n m b).

apply (e_nm_Valid b n m H0 H1).

Qed.

Verification of a brick Wang tiling algorithm

Conclusion

A brick Wang tiles set is a tile set introduced to model the texture ofwall patterns in computer graphics [A.D-Jourdan 2015].

We implemented a tiling algorithm with a proof of its correctness.

We also show a formal proof of an existence of a tiling of any givenbrick Wang tile set for any rectangular region larger than 2 × 2.

We reduce the problem into a tiling problem of a 2 × 2 region.

We divide the boundary colorings into finite classes and give asolution for each class.

We proved formally that the enumeration of classes are sufficientand the solution is correct for each class.

Verification of a brick Wang tiling algorithm

Appendix

All source codes and proofs are in the github repository

https://github.com/KyushuUniversityMathematics/BrickCornerWangTiling.

To check examples following instructions.1 To extract functions e_nm and e’_nm.coqc TilingProgram.v

There exists an OCaml file TilingProgam.ml that contains examples ofboundary colorings, such as boundary44a and boundary44c.

2 To execute rendering example file.ocamlc TilingProgram.ml Tilingrender.ml -o TilingRender

There exist rendered images such as b44a.svg and b44c.svg.3 Some external program such as rsvg-convert may be used to convert the

image format from svg to png.eg. svg-convert b44a.svg > b44a.png