This file is indexed.

/usr/include/gecode/int/arithmetic/sqr.hpp is in libgecode-dev 3.7.3-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
 *  Main authors:
 *     Christian Schulte <schulte@gecode.org>
 *
 *  Copyright:
 *     Christian Schulte, 2008
 *
 *  Last modified:
 *     $Date: 2011-08-09 02:04:53 +1000 (Tue, 09 Aug 2011) $ by $Author: schulte $
 *     $Revision: 12253 $
 *
 *  This file is part of Gecode, the generic constraint
 *  development environment:
 *     http://www.gecode.org
 *
 *  Permission is hereby granted, free of charge, to any person obtaining
 *  a copy of this software and associated documentation files (the
 *  "Software"), to deal in the Software without restriction, including
 *  without limitation the rights to use, copy, modify, merge, publish,
 *  distribute, sublicense, and/or sell copies of the Software, and to
 *  permit persons to whom the Software is furnished to do so, subject to
 *  the following conditions:
 *
 *  The above copyright notice and this permission notice shall be
 *  included in all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */

#include <cmath>

namespace Gecode { namespace Int { namespace Arithmetic {

  /*
   * Positive bounds consistent squaring
   *
   */
  template<class VA, class VB>
  forceinline ExecStatus
  prop_sqr_plus_bnd(Space& home, VA x0, VB x1) {
    bool mod;
    do {
      mod = false;
      {
        ModEvent me = x0.lq(home,floor(::sqrt(static_cast<double>(x1.max()))));
        if (me_failed(me)) return ES_FAILED;
        mod |= me_modified(me);
      }
      {
        ModEvent me = x0.gq(home,ceil(::sqrt(static_cast<double>(x1.min()))));
        if (me_failed(me)) return ES_FAILED;
        mod |= me_modified(me);
      }
      {
        ModEvent me = x1.lq(home,x0.max()*x0.max());
        if (me_failed(me)) return ES_FAILED;
        mod |= me_modified(me);
      }
      {
        ModEvent me = x1.gq(home,x0.min()*x0.min());
        if (me_failed(me)) return ES_FAILED;
        mod |= me_modified(me);
      }
    } while (mod);
    return ES_OK;
  }

  template<class VA, class VB>
  forceinline
  SqrPlusBnd<VA,VB>::SqrPlusBnd(Home home, VA x0, VB x1)
    : MixBinaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND>(home,x0,x1) {}

  template<class VA, class VB>
  forceinline ExecStatus
  SqrPlusBnd<VA,VB>::post(Home home, VA x0, VB x1) {
    GECODE_ES_CHECK(prop_sqr_plus_bnd(home,x0,x1));
    (void) new (home) SqrPlusBnd<VA,VB>(home,x0,x1);
    return ES_OK;
  }

  template<class VA, class VB>
  forceinline
  SqrPlusBnd<VA,VB>::SqrPlusBnd(Space& home, bool share, SqrPlusBnd<VA,VB>& p)
    : MixBinaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND>(home,share,p) {}

  template<class VA, class VB>
  Actor*
  SqrPlusBnd<VA,VB>::copy(Space& home, bool share) {
    return new (home) SqrPlusBnd<VA,VB>(home,share,*this);
  }

  template<class VA, class VB>
  ExecStatus
  SqrPlusBnd<VA,VB>::propagate(Space& home, const ModEventDelta&) {
    GECODE_ES_CHECK(prop_sqr_plus_bnd(home,x0,x1));
    return x0.assigned() ? home.ES_SUBSUMED(*this) : ES_FIX;
  }



  /*
   * Bounds consistent squaring
   *
   */

  template<class View>
  forceinline
  SqrBnd<View>::SqrBnd(Home home, View x0, View x1)
    : BinaryPropagator<View,PC_INT_BND>(home,x0,x1) {}

  template<class View>
  forceinline ExecStatus
  SqrBnd<View>::post(Home home, View x0, View x1) {
    GECODE_ME_CHECK(x1.gq(home,0));
    if (same(x0,x1)) {
      GECODE_ME_CHECK(x1.lq(home,1));
    } else {
      GECODE_ME_CHECK(x0.lq(home,floor(::sqrt(static_cast<double>
                                              (Limits::max)))));
      GECODE_ME_CHECK(x0.gq(home,-floor(::sqrt(static_cast<double>
                                               (-Limits::min)))));
      if (x0.min() >= 0)
        return SqrPlusBnd<IntView,IntView>::post(home,x0,x1);
      if (x0.max() <= 0)
        return SqrPlusBnd<MinusView,IntView>::post(home,MinusView(x0),x1);
      GECODE_ME_CHECK(x1.lq(home,
                            std::max(x0.min()*x0.min(),x0.max()*x0.max())));
      (void) new (home) SqrBnd<View>(home,x0,x1);
    }
    return ES_OK;
  }

  template<class View>
  forceinline
  SqrBnd<View>::SqrBnd(Space& home, bool share, SqrBnd<View>& p)
    : BinaryPropagator<View,PC_INT_BND>(home,share,p) {}

  template<class View>
  Actor*
  SqrBnd<View>::copy(Space& home, bool share) {
    return new (home) SqrBnd<View>(home,share,*this);
  }

  template<class View>
  ExecStatus
  SqrBnd<View>::propagate(Space& home, const ModEventDelta&) {
    assert(x1.min() >= 0);
    if (x0.min() >= 0)
      GECODE_REWRITE(*this,(SqrPlusBnd<IntView,IntView>::post(home(*this),x0,x1)));
    if (x0.max() <= 0)
      GECODE_REWRITE(*this,(SqrPlusBnd<MinusView,IntView>::post(home(*this),
        MinusView(x0),x1)));

    GECODE_ME_CHECK(x1.lq(home,std::max(x0.min()*x0.min(),
                                        x0.max()*x0.max())));

    int s = static_cast<int>(floor(::sqrt(static_cast<double>(x1.max()))));

    GECODE_ME_CHECK(x0.gq(home,-s));
    GECODE_ME_CHECK(x0.lq(home,s));

    if (x0.assigned() && x1.assigned())
      return (x0.val()*x0.val() == x1.val()) ?
        home.ES_SUBSUMED(*this) : ES_FAILED;

    return ES_NOFIX;
  }

  /*
   * Value mappings for squaring and square root
   *
   */

  /// Mapping integer to square
  class ValuesMapSqr {
  public:
    /// Perform mapping
    forceinline int val(int n) const {
      return n*n;
    }
  };

  /// Mapping integer to square root
  class ValuesMapSqrt {
  public:
    /// Perform mapping
    forceinline int val(int n) const {
      return static_cast<int>(floor(::sqrt(static_cast<double>(n))));
    }
  };


  /*
   * Positive domain consistent squaring
   *
   */
  template<class VA, class VB>
  forceinline
  SqrPlusDom<VA,VB>::SqrPlusDom(Home home, VA x0, VB x1)
    : MixBinaryPropagator<VA,PC_INT_DOM,VB,PC_INT_DOM>(home,x0,x1) {}

  template<class VA, class VB>
  forceinline ExecStatus
  SqrPlusDom<VA,VB>::post(Home home, VA x0, VB x1) {
    GECODE_ES_CHECK(prop_sqr_plus_bnd(home,x0,x1));
    (void) new (home) SqrPlusDom<VA,VB>(home,x0,x1);
    return ES_OK;
  }

  template<class VA, class VB>
  forceinline
  SqrPlusDom<VA,VB>::SqrPlusDom(Space& home, bool share, SqrPlusDom<VA,VB>& p)
    : MixBinaryPropagator<VA,PC_INT_DOM,VB,PC_INT_DOM>(home,share,p) {}

  template<class VA, class VB>
  Actor*
  SqrPlusDom<VA,VB>::copy(Space& home, bool share) {
    return new (home) SqrPlusDom<VA,VB>(home,share,*this);
  }

  template<class VA, class VB>
  PropCost
  SqrPlusDom<VA,VB>::cost(const Space&, const ModEventDelta& med) const {
    if (VA::me(med) == ME_INT_VAL)
      return PropCost::unary(PropCost::LO);
    else if (VA::me(med) == ME_INT_DOM)
      return PropCost::binary(PropCost::HI);
    else
      return PropCost::binary(PropCost::LO);
  }

  template<class VA, class VB>
  ExecStatus
  SqrPlusDom<VA,VB>::propagate(Space& home, const ModEventDelta& med) {
    if (VA::me(med) != ME_INT_DOM) {
      GECODE_ES_CHECK(prop_sqr_plus_bnd(home,x0,x1));
      return x0.assigned() ?
        home.ES_SUBSUMED(*this)
        : home.ES_NOFIX_PARTIAL(*this,VA::med(ME_INT_DOM));
    }

    {
      ViewValues<VA> v0(x0);
      Iter::Values::Map<ViewValues<VA>,ValuesMapSqr> s0(v0);
      GECODE_ME_CHECK(x1.inter_v(home,s0,false));
    }

    {
      ViewValues<VB> v1(x1);
      Iter::Values::Map<ViewValues<VB>,ValuesMapSqrt> s1(v1);
      GECODE_ME_CHECK(x0.inter_v(home,s1,false));
    }

    return x0.assigned() ? home.ES_SUBSUMED(*this) : ES_FIX;
  }


  /*
   * Domain consistent squaring
   *
   */

  template<class View>
  forceinline
  SqrDom<View>::SqrDom(Home home, View x0, View x1)
    : BinaryPropagator<View,PC_INT_DOM>(home,x0,x1) {}

  template<class View>
  forceinline ExecStatus
  SqrDom<View>::post(Home home, View x0, View x1) {
    GECODE_ME_CHECK(x1.gq(home,0));
    if (same(x0,x1)) {
      GECODE_ME_CHECK(x1.lq(home,1));
    } else {
      GECODE_ME_CHECK(x0.lq(home,floor(::sqrt(static_cast<double>
                                              (Limits::max)))));
      GECODE_ME_CHECK(x0.gq(home,-floor(::sqrt(static_cast<double>
                                               (-Limits::min)))));
      if (x0.min() >= 0)
        return SqrPlusDom<IntView,IntView>::post(home,x0,x1);
      if (x0.max() <= 0)
        return SqrPlusDom<MinusView,IntView>::post(home,MinusView(x0),x1);
      GECODE_ME_CHECK(x1.lq(home,
                            std::max(x0.min()*x0.min(),x0.max()*x0.max())));
      (void) new (home) SqrDom<View>(home,x0,x1);
    }
    return ES_OK;
  }

  template<class View>
  forceinline
  SqrDom<View>::SqrDom(Space& home, bool share, SqrDom<View>& p)
    : BinaryPropagator<View,PC_INT_DOM>(home,share,p) {}

  template<class View>
  Actor*
  SqrDom<View>::copy(Space& home, bool share) {
    return new (home) SqrDom<View>(home,share,*this);
  }

  template<class View>
  PropCost
  SqrDom<View>::cost(const Space&, const ModEventDelta& med) const {
    if (View::me(med) == ME_INT_VAL)
      return PropCost::unary(PropCost::LO);
    else if (View::me(med) == ME_INT_DOM)
      return PropCost::binary(PropCost::HI);
    else
      return PropCost::binary(PropCost::LO);
  }

  template<class View>
  ExecStatus
  SqrDom<View>::propagate(Space& home, const ModEventDelta& med) {
    assert(x1.min() >= 0);
    if (View::me(med) != ME_INT_DOM) {
      if (x0.min() >= 0)
        GECODE_REWRITE(*this,(SqrPlusDom<IntView,IntView>::post(home(*this),x0,x1)));
      if (x0.max() <= 0)
        GECODE_REWRITE(*this,(SqrPlusDom<MinusView,IntView>::post(home(*this),
          MinusView(x0),x1)));

      GECODE_ME_CHECK(x1.lq(home,std::max(x0.min()*x0.min(),
                                          x0.max()*x0.max())));

      int s = static_cast<int>(floor(::sqrt(static_cast<double>(x1.max()))));

      GECODE_ME_CHECK(x0.gq(home,-s));
      GECODE_ME_CHECK(x0.lq(home,s));

      if (x0.assigned() && x1.assigned())
        return (x0.val()*x0.val() == x1.val()) ?
          home.ES_SUBSUMED(*this) : ES_FAILED;
      return home.ES_NOFIX_PARTIAL(*this,View::med(ME_INT_DOM));

    }

    Region r(home);
    {
      ViewValues<View> i(x0), j(x0);
      using namespace Iter::Values;
      Positive<ViewValues<View> > p(i);
      Negative<ViewValues<View> > n(j);
      Minus m(r,n);

      Map<Positive<ViewValues<View> >,ValuesMapSqr,true> sp(p);
      Map<Minus,ValuesMapSqr,true> sm(m);
      Union<Map<Positive<ViewValues<View> >,ValuesMapSqr,true>,
        Map<Minus,ValuesMapSqr,true> > u(sp,sm);
      GECODE_ME_CHECK(x1.inter_v(home,u,false));
    }

    {
      ViewValues<View> i(x1), j(x1);
      using namespace Iter::Values;
      Map<ViewValues<View>,ValuesMapSqrt,true> si(i), sj(j);
      Minus mi(r,si);
      Union<Minus,
        Map<ViewValues<View>,ValuesMapSqrt,true> > u(mi,sj);
      GECODE_ME_CHECK(x0.inter_v(home,u,false));
    }

    return x0.assigned() ? home.ES_SUBSUMED(*this) : ES_FIX;
  }

}}}

// STATISTICS: int-prop