# Answers to the Exercises

Answer 3.1

> This does not really require to be answered. Just try it.

Answer 3.2

>   `proc {Donald Root}
>   sol(a:A b:B d:D e:E g:G l:L n:N o:O r:R t:T) = Root
>   in
>   Root ::: 0#9
>   {FD.distinct Root}
>   D\=:0 R\=:0 G\=:0
>   100000*D + 10000*O + 1000*N + 100*A + 10*L + D
>   + 100000*G + 10000*E + 1000*R + 100*A + 10*L + D
>   =: 100000*R + 10000*O + 1000*B + 100*E + 10*R + T
>   {FD.distribute split Root}
>   end`

Answer 7.1

> The first redundant constraint follows from the fact that the total number of occurrences in the sequence is , and that no numbers but those between 0 and occur in the sequence.

> The second redundant constraint follows from the fact that

> Here is a parametrized script for the Magic Sequence Puzzle:

>   `fun {MagicSequence N}
>   Cs = {List.number ~1 N-2 1}
>   in
>   proc {$ S}
>   {FD.tuple sequence N 0#N-1 S}
>   {For 0 N-1 1
>   proc {$ I} {FD.exactly S.(I+1) S I} end}
>   %% redundant constraints
>   {FD.sum S '=:' N}
>   {FD.sumC Cs S '=:' 0}
>   %%
>   {FD.distribute ff S}
>   end
>   end`

Answer 8.1

> > `{FD.impl X<:Y X+Y=:Z} = {FD.disj X*Y=:Z Z\=:5}`

Answer 8.2

> > `proc {Conj X Y Z}
> > X::0#1 Y::0#1
> > (X+Y=:2) = Z
> > end
> > proc {Equi X Y Z}
> > X::0#1 Y::0#1
> > (X=:Y) = Z
> > end
> > proc {Nega X Z}
> > X::0#1
> > (X=:0) = Z
> > end
> > proc {Disj X Y Z}
> > X::0#1 Y::0#1
> > (X+Y>:0) = Z
> > end
> > proc {Impl X Y Z}
> > X::0#1 Y::0#1
> > (X=:0) + (Y>:0) = Z
> > end`

Answer 8.3

> To minimize the value of `Satisfaction`, we modify the distributor for `Satisfaction` such that it tries smaller values first:

> > `{FD.distribute generic(order:naive value:min) [Satisfaction]}`

> It turns out that the persons can be aligned such that no preference is satisfied.

Answer 8.4

> > `local Aux in
> > {FD.decl Aux}
> > {FD.distance Q.7 Q.8 '=:' Aux}
> > {FD.element Q.7 [4 3 2 1 0] Aux}
> > end`

Answer 8.5

> > `thread
> > if A.type==B.type then
> > A.glass >=: B.glass
> > end
> > end`

Answer 11.1

> A possible solution is as follows.

> > `proc {CapacityConstraints TasksOnRes Start Dur}
> > {Record.forAll TasksOnRes
> > proc {$ Ts}
> > {ForAllTail Ts
> > proc {$ T1|Tr}
> > {ForAll Tr
> > proc {$ T2}
> > (Start.T1 + Dur.T1 =<: Start.T2) +
> > (Start.T2 + Dur.T2 =<: Start.T1) =: 1
> > end}
> > end}
> > end}
> > end`