• No results found

Inthissetionweintroduethe1-dimensionalBin-Paking problem,asorigi-

nallyformulatedin[17℄.

Givenalistofboxesofdimensionsexpressedbythenaturals

p

1

, . . . , p

n

and binsofapaityexpressed bythe naturals

b

1

, . . . , b

m

,nd,ifit exists,avalid assignment oftheboxesintothebinsinsuhawaythatforeahbinthesum

ofthe dimensionsoftheboxesassignedtoitdoesnotexeedstheapaityof

thebinitself.

Wewillindiatetheinputlistofboxesby

X

,thelistofbinsby

B

,andthe outputassignment by

A

. Weindiatethe

i

-thelement of

l

,the lengthoflist

l

andthelist

l

wheretheposition

i

is dereasedby

a

respetivelyby

l[i]

,

|l|

and

l[i/a]

. Theoutputassignmentlist

A

hasthisproperty: foreahnatural

i

,the

i

-thbox hastobeputinthebin

A[i]

. It follows thatthe listof boxes andassignmentshavetohavethesamelength,thatis,theequality

(|X|=|A|)

holds. Nowweintroduesomenotationthatwillbeusefulfor ourproof. For

lists ofnaturals

A

and

X

and anatural

i

,wedeneSUM tobethe following funtion:

SUM

(A, X, i) =

X

j∈Q

X[j]

with

Q={j|A[j] =i}

WedeneaprediatePACKthatstatesunderwhihonditionsalistofnaturals

A

anbeonsideredavalidassignmentforthelistofboxes

X

andbins

B

,and theadditionalprediatePACKBthatstatestheexisteneofavalidassignment

forthelistofboxes

X

andbins

B

pulsanadditionalonstraintonthebinthe rstboxshouldbeassoiated,

(|X|=|A|)∧

(∀i.i <|B| →

SUM

(A, X, i)≤B[i])

PACKB

(n, A, X, B)

⇐⇒

X6= (:)∧

PACK

(A, X, B)∧

(|B| −n)≤A[0]

The1-dimensionalbinpakingproblemanbeformulatedasadeisionproblem

where,givenaninputelement

x

,wehavetostateifthereexistsan

y

suhthat a property

P(x, y)

holds or not. We an express this fat by the following formula:

∀x(∃yP(x, y))∨((∃yP(x, y))→ ⊥)

Asalreadyseen,inoursystemweexpresssuhformulasas:

∀x∃p(p→ ∃yP(x, y))∧((p→ ⊥)→((∃yP(x, y))→ ⊥))

thatis,foreahinput

x

thereexistsaboolean

p

suhthatif

p

holdsthenweare abletosupplyasolution,elsenosolutionexists. Wewillall

(p→ ∃yP(x, y))

and

((p

→ ⊥)

((∃yP(x, y))

→ ⊥))

the positive and negative part of the formula above. The proof-algorithm that we propose is a rst-t algorithm

beause, inthe ourseofthe searh, itattempts to plaeablok inthe rst

bininwhihittsasitsinitialtry.

Theorem3.3.1.

∀X, B∃p

(p→ ∃A

PACK

(A, X, B))∧

((p→ ⊥)→(∃A

PACK

(A, X, B))→ ⊥)

Proof. By indutionon

X

. Case

X

= (:)

. If there are noboxesto t, then foreahlistofbins

B

theemptylistisavalidassignment. Case

X

= (a::l)

. Assumetheindutionhypothesis(IH)andagenerilist

B

ofbins. Inorderto prove

∃p

(p→ ∃A

PACK

(A,(a::l), B))∧

((p→ff)(A

PACK

(A,(a::l), B))→ ⊥)

(3.5) weprovethefollowing assertion:

∀n.

(n≤ |B|)→ ∃p

(p→ ∃A(

PACKB

(n, A,(a::l), B))∧

((p→ ⊥)→(∃A

PACKB

(n, A,(a::l), B))→ ⊥

(3.6)

)

Obviouslyweanderive(3.5)instantiating(3.6) on

|B|

. Toprove(3.6) wego

byindutionon

n

. Case

n= 0

. Wefailndingavalidassignment for

(a::l)

in

B

beause itshouldholds

|B| ≤A[0]

and

A[0]<|B|

. Case

n+ 1

. Assume thenestedindutionhypothesis(NIH)and

(n+ 1≤ |B|)

. Weprove:

∃p

(p→ ∃A

PACKB

((n+ 1), A,(a::l), B))∧

((p→ff)→(∃A

PACKB

((n+ 1), A,(a::l), B))→ ⊥)

(3.7) Obviouslyif

(n+ 1≤ |B|)

then

(n≤ |B|)

. Thereareonlytwoases:

(a≤B[|B| −(n+ 1)])

: Thedimensionoftherstboxtsinthebinin position

(|B| −(n+ 1))

. Sowehekifavalidassignmentexistsforthe list

l

intothelistofbins

B

,where theposition

(|B| −(n+ 1))

(of

B

)is dereasedbythequantity

a

. Weinstantiate(IH)on

B[(|B| −(n+ 1))/a]

. Sothereexists aboolean

p

suhthat:

(p→ ∃A

PACK

(A, l, B[(|B| −(n+ 1))/a]))∧

(3.8)

((p→ ⊥)→(∃A

PACK

(A, l, B[(|B| −(n+ 1))/a]))→ ⊥)

Therearetwoases:

p

holdsoritdoesn'thold.

p

holds: Wearedone.From(3.8)weknow

A

suhthatPACK

(A, l, B[(|B|−

(n+ 1))/a])

,sothethesisisprovedintroduingttfor

p

and

((|B| −

(n+ 1)) ::A)

for

A

inthepositivepart of(3.7).

(p→ff)

holds : A valid assignment

A

, ifitdoes exists,has to assign

a

tothebin

i

with

|B| −n≤i <|B|

. Sothesearhedassignmentand theproofofitsexistene(ortheproofofitsnonexistene)isgiven

bythenestedindutionhypothesis(NIH)

(a

B[|B| −(n+ 1)])

: Also inthis ase, if asolutiondoesexists, itis givenby(NIH)

Theodeextratedfromthepreviousproofis:

(Re (list nat=> list nat=> (boole, list nat)))

([B℄ (#tt , (:)))

([a,l,f,B℄

[(Re (nat => (boole, list nat))

(#ff, (:))

[n, (p ,A)℄

if (a <= B[|B|-(n+1)℄)

let (p',A') = f B[(|B|-n)/a℄

if p' (#tt, (|B|-(n+1))::A') (p, A)

(p, A)℄ |B|

Theletonstrutorisobtainedusing insomestrategipointoftheproofthe

3.3.1 Experiment

Wespeializethebin-pakingproof ontheinputlistsofboxes

X

= (n::m:)

andbins

B= (a::a:)

. Theontentofthespeializedproofis:

if (n<=a)

if (m<=a--n)

(#tt, 0::(if (m<=a-n) (0:) (if (m<=a) (1:) (:))))

if (m<=a)

(#tt, 0::(if (m<=a-n) (0:) (if (m<=a) (1:) (:))))

if (n<=a)

if (m<=a)

(#tt, 1::(if (m<=a) (0:) (if (m<=a-n) (1:) (:))))

(m<=a-n

if (m<=a-n)

(1::(if (m<=a) (0:) (if (m<=a-n) (1:) (:))))

(:))

(#ff, (:))

if (n<=a)

if (m<=a)

(#tt, 1::(if (m<=a) (0:) (if (m<=a-n) (1:) (:))))

(m<=a-n,

if (m<=a-n) (1::(if (m<=a) (0:) (if (m<=a-n) (1:) (:))))) (:))

(#ff, (:))

Thepermutativeonversionrules areappliedto thespeialized proof. The

omputationalontentofthepermutedproofis:

if (n<=a) if (m<=a-n) (#tt, (0::0:)) if (m<=a) (#tt,(0::1:)) if (n<=a)

if (m<=a) (#tt, (1::0:)) (m<=a-n, (if (m<=a-n) (1::1:) (:)))

(#ff, (:))

if (n<=a)

if (m<=a) (#tt, (1::0:)) (m<=a-n, (if (m<=a-n) (1::1:) (:)))

(#ff, (:))

Finallypruning isappliedto thepermutedproof. Here we distinguishtwo

asesinextratingtheodefromtheprunedproof:

Noadditionalknowledgeon

n

,

m

isrequired:

P1= if (n<=a)

if (m<=a-n) (#tt, (0::0:)) (m<=a, (if (m<=a) (0::1:) (:)))

(#ff, (:))

P2 = (n<=a, if (n<=a) (0::1:) (:))

Intherstase(noknowledgeontheinputparameters)theeetofpruning

isthesimpliationofif-statementsthatourintheleft/rightbranhofan

outer if-statement with the sameboolean ondition. This proess ould be

performed with aprogram transformation tehniquessuh as partial evalua-

tion[21℄.

In the seondase (

m

≤n

) somethingdierent happens: there is noway to go from P1 to P2 with any program transformation tehnique. In fat,

the eliminationofthe if-statement ontheondition (m<=a-n) onlyrefersto

dependeny information available at proof level, and not at program level.

Finally weseethat theextensionalbehavior oftheextratedodeP1 andP2

hanges. WhileP1,ifn<=amayreturn(0::0:),P2willalwaysreturn(0::1:).

Butpruningkeepstheendformulaofthesub-proofs onwhihitis appliedso

boththeresultsevenifdierentwill satisfythesamelogialspeiation.

Related documents