Inthissetionweintroduethe1-dimensionalBin-Paking problem,asorigi-
nallyformulatedin[17℄.
Givenalistofboxesofdimensionsexpressedbythenaturals
p
1
, . . . , p
n
and binsofapaityexpressed bythe naturalsb
1
, . . . , b
m
,nd,ifit exists,avalid assignment oftheboxesintothebinsinsuhawaythatforeahbinthesumofthe dimensionsoftheboxesassignedtoitdoesnotexeedstheapaityof
thebinitself.
Wewillindiatetheinputlistofboxesby
X
,thelistofbinsbyB
,andthe outputassignment byA
. Weindiatethei
-thelement ofl
,the lengthoflistl
andthelistl
wherethepositioni
is dereasedbya
respetivelybyl[i]
,|l|
andl[i/a]
. TheoutputassignmentlistA
hasthisproperty: foreahnaturali
,thei
-thbox hastobeputinthebinA[i]
. It follows thatthe listof boxes andassignmentshavetohavethesamelength,thatis,theequality(|X|=|A|)
holds. Nowweintroduesomenotationthatwillbeusefulfor ourproof. Forlists ofnaturals
A
andX
and anaturali
,wedeneSUM tobethe following funtion:SUM
(A, X, i) =
X
j∈Q
X[j]
withQ={j|A[j] =i}
WedeneaprediatePACKthatstatesunderwhihonditionsalistofnaturals
A
anbeonsideredavalidassignmentforthelistofboxesX
andbinsB
,and theadditionalprediatePACKBthatstatestheexisteneofavalidassignmentforthelistofboxes
X
andbinsB
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
,wehavetostateifthereexistsany
suhthat a propertyP(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
thereexistsabooleanp
suhthatifp
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 algorithmbeause, 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
. CaseX
= (:)
. If there are noboxesto t, then foreahlistofbinsB
theemptylistisavalidassignment. CaseX
= (a::l)
. Assumetheindutionhypothesis(IH)andagenerilistB
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) wegobyindutionon
n
. Casen= 0
. Wefailndingavalidassignment for(a::l)
inB
beause itshouldholds|B| ≤A[0]
andA[0]<|B|
. Casen+ 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 listl
intothelistofbinsB
,where theposition(|B| −(n+ 1))
(ofB
)is dereasedbythequantitya
. Weinstantiate(IH)onB[(|B| −(n+ 1))/a]
. Sothereexists abooleanp
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)weknowA
suhthatPACK(A, l, B[(|B|−
(n+ 1))/a])
,sothethesisisprovedintroduingttforp
and((|B| −
(n+ 1)) ::A)
forA
inthepositivepart of(3.7).(p→ff)
holds : A valid assignmentA
, ifitdoes exists,has to assigna
tothebini
with|B| −n≤i <|B|
. Sothesearhedassignmentand theproofofitsexistene(ortheproofofitsnonexistene)isgivenbythenestedindutionhypothesis(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:)
andbinsB= (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.