# Re: [eclipse-clp-users] How to expand domain of a variable

From: Sergey Dymchenko <kit1980_at_...6...>
Date: Sun, 6 Nov 2011 15:16:49 +0200
```Great, thank you!

On Sun, Nov 6, 2011 at 11:00 AM, Joachim Schimpf <jschimpf@...311...> wrote:
> The right hand side of ::/2 is also just a list, only in a slightly
> different format from what you have as input.
>
> So you just translate your input list [[10, 20], [15, 30], [40, 50]]
> to the kind of list that the ::/2 predicate expects, i.e.
>
> input_to_intervals(In, Out) :-
>        ( foreach([Min,Max],In), foreach(Min..Max,Out) do true ).
>
>
> ?- input_to_intervals([[10, 20], [15, 30], [40, 50]], Intervals),
>    X :: Intervals.
>
> Intervals = [10 .. 20, 15 .. 30, 40 .. 50]
> X = X{[10 .. 30, 40 .. 50]}
> Yes (0.00s cpu)
>
>
>
>
> Sergey Dymchenko wrote:
>> Thank you, but the main question how to construct that domain X ::
>> [10..20, 15..30, 40..50] if I have a list of interval boundaries [[10,
>> 20], [15, 30], [40, 50]] (I read them from a file, number of intervals
>> can be different).
>> I can't see how do this simpler than in my model/2
>>
>> Sergey.
>>
>> On Sun, Nov 6, 2011 at 2:18 AM, Joachim Schimpf <jschimpf@...311...> wrote:
>>> Sergey Dymchenko wrote:
>>>> [eclipse 1]: model([[10, 20], [15, 30], [40, 50]], Domain),
>>>> query(Domain, 1, A1), query(Domain, 10, A2), query(Domain, 35, A3).
>>>>
>>>> Domain = [10 .. 30, 40 .. 50]
>>>> A1 = "No"
>>>> A2 = "Yes"
>>>> A3 = "No"
>>>> Yes (0.00s cpu)
>>> Hi Sergey,
>>>
>>> you can achieve that simply via
>>>
>>> ?- X :: [10..20, 15..30, 40..50], is_in_domain(1, X, B1), is_in_domain(10, X, B2).
>>> X = X{[10 .. 30, 40 .. 50]}
>>> B1 = no
>>> B2 = yes
>>> Yes (0.00s cpu)
>>>
>>>
>>> -- Joachim
>
> ------------------------------------------------------------------------------
> RSA(R) Conference 2012
> Save \$700 by Nov 18
> Register now
> http://p.sf.net/sfu/rsa-sfdev2dev1
> _______________________________________________
> ECLiPSe-CLP-Users mailing list
> ECLiPSe-CLP-Users_at_lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/eclipse-clp-users
>
```
Received on Sun Nov 06 2011 - 13:16:55 CET

This archive was generated by hypermail 2.2.0 : Mon Jul 09 2018 - 02:05:29 CEST