This file is indexed.

/usr/include/polymake/group/action.h is in libpolymake-dev-common 3.2r2-3.

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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
/* Copyright (c) 1997-2018
   Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
   http://www.polymake.org

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version: http://www.gnu.org/licenses/gpl.txt.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
--------------------------------------------------------------------------------
*/

#ifndef __GROUP_ACTION_H
#define __GROUP_ACTION_H

#include "polymake/hash_map"
#include "polymake/Array.h"
#include <polymake/IncidenceMatrix.h>
#include <polymake/Polynomial.h>
#include <polymake/permutations.h>

namespace polymake { namespace group {


inline      
int degree(const Array<int>& a)
{
      return a.size();
}

template<typename Scalar>
int degree(const Matrix<Scalar>& a)
{
   assert(a.rows() == a.cols());
   return a.rows();
}

inline      
auto identity(int degree, const Array<int>&)
{
   return Array<int>(degree, entire(sequence(0, degree)));
}

template<typename Scalar>
auto identity(int degree, const Matrix<Scalar>&)
{
   return unit_matrix<Scalar>(degree);
}

inline      
auto inverse(const Array<int>& g)
{
   Array<int> inverse;
   inverse_permutation(g, inverse);
   return inverse;
}

template<typename Scalar>
auto inverse(const Matrix<Scalar>& g)
{
   return inv(g);
}

} }

namespace pm {
namespace operations {
namespace group {

struct on_container{};
struct on_nonhomog_container{};
struct on_elements{};
struct on_rows{};
struct on_cols{};
struct on_nonhomog_cols{};

template <typename OpRef, typename action_type, typename Perm, 
          typename op_tag=typename object_traits<typename deref<OpRef>::type>::generic_tag, 
          typename perm_tag=typename object_traits<Perm>::generic_tag,
          typename stores_ref=std::true_type,
          typename enabled=std::true_type>
struct action;

template <typename OpRef, typename action_type, typename Perm, 
          typename op_tag=typename object_traits<typename deref<OpRef>::type>::generic_tag, 
          typename perm_tag=typename object_traits<Perm>::generic_tag,
          typename stores_ref=std::true_type,
          typename enabled=std::true_type>
struct right_action;

template <typename OpRef, typename action_type, typename Perm, 
          typename op_tag=typename object_traits<typename deref<OpRef>::type>::generic_tag, 
          typename perm_tag=typename object_traits<Perm>::generic_tag,
          typename stores_ref=std::true_type>
struct conjugation_action;
   
// generic action on container with Array<int>
template <typename OpRef, typename Perm, typename op_tag, typename stores_ref>
struct action<OpRef, on_container, Perm, op_tag, is_container, stores_ref> {
   typedef OpRef argument_type;
   typedef typename deref<argument_type>::type result_type;

   typename std::conditional<stores_ref::value, const Perm&, const Perm>::type perm;
  
   action(const Perm& p)
      : perm(p) {}
  
   result_type operator() (typename function_argument<argument_type>::const_type x) const
   {
      return permuted(x,perm);
   }      
}; 

// generic action by conjugation
template <typename OpRef, typename action_type, typename Perm, typename op_tag, typename perm_tag, typename stores_ref>
struct conjugation_action {
   typedef OpRef argument_type;
   typedef typename deref<argument_type>::type result_type;

         action<OpRef, action_type, Perm, op_tag, perm_tag, stores_ref>  left;
   right_action<OpRef, action_type, Perm, op_tag, perm_tag, stores_ref> right;
  
   conjugation_action(const Perm& p)
      : left(p), right(polymake::group::inverse(p)) {}
  
   result_type operator() (typename function_argument<argument_type>::const_type x) const
   {
      return left(right(x));
   }      
}; 
   
// generic non-homogeneous action on container with Array<int>
template <typename OpRef, typename Perm, typename op_tag>
struct action<OpRef, on_nonhomog_container, Perm, op_tag, is_container> {
  typedef OpRef argument_type;
  typedef typename deref<argument_type>::type result_type;

  const Perm perm;
  
  action(const Perm& p)
   : perm(concatenate(pm::single_value_container<int>(0), translate(p, 1))) {}
  
  result_type operator() (typename function_argument<argument_type>::const_type x) const
  {
    return permuted(x,perm);
  }      
}; 

// action on integers (anchor of the on_elements recursion)
template <typename Perm, typename stores_ref>
struct action<int&, on_elements, Perm, is_scalar, is_container, stores_ref> {
   typedef int& argument_type;
   typedef typename deref<argument_type>::type result_type;
  
   typename std::conditional<stores_ref::value, const Perm&, const Perm>::type perm;

   action(const Perm& p)
      : perm(p) {}
  
   result_type operator() (typename function_argument<argument_type>::const_type x) const
   {
      return perm[x];
   }      
}; 

// generic action on elements in a container with Array<int>
template <typename OpRef, typename Perm, typename op_tag, typename stores_ref>
struct action<OpRef, on_elements, Perm, op_tag, is_container, stores_ref,
              typename std::enable_if<std::is_same<typename object_traits<typename deref<OpRef>::type>::model, is_container>::value
                                      && !std::is_same<op_tag, is_matrix>::value, std::true_type>::type
              > {
   typedef OpRef argument_type;
   typedef typename object_traits<typename deref<argument_type>::type>::persistent_type result_type;

   typename std::conditional<stores_ref::value, const Perm&, const Perm>::type perm;

   action(const Perm& p)
      : perm(p) {}

   result_type operator() (typename function_argument<argument_type>::const_type x) const
   {
      return result_type(attach_operation(x,action<typename deref<argument_type>::type::value_type&, on_elements, Perm>(perm)));
   }      
}; 

// generic action on elements in a matrix with Array<int>
template <typename OpRef, typename Perm, typename stores_ref>
struct action<OpRef, on_elements, Perm, is_matrix, is_container, stores_ref> {
   typedef OpRef argument_type;
   typedef typename object_traits<typename deref<argument_type>::type>::persistent_type result_type;

   typename std::conditional<stores_ref::value, const Perm&, const Perm>::type perm;

   action(const Perm& p)
      : perm(p) {}

   result_type operator() (typename function_argument<argument_type>::const_type x) const
   {
      return result_type(x.rows(),x.cols(),entire(attach_operation(concat_rows(x),action<typename deref<argument_type>::type::value_type&, on_elements, Perm>(perm))));
   }      
}; 

// action on rows of a matrix with Array<int>
template <typename OpRef, typename Perm, typename stores_ref>
struct action<OpRef, on_rows, Perm, is_matrix, is_container, stores_ref> {
   typedef OpRef argument_type;
   typedef typename deref<argument_type>::type result_type;

   typename std::conditional<stores_ref::value, const Perm&, const Perm>::type perm;

   action(const Perm& p)
      : perm(p) {}

   result_type operator() (typename function_argument< argument_type >::const_type x) const
   {
      return permuted_rows(x,perm);
   }
};

// action on cols of a matrix with Array<int>
template <typename OpRef, typename Perm, typename stores_ref>
struct action<OpRef, on_cols, Perm, is_matrix, is_container, stores_ref> {
   typedef OpRef argument_type;
   typedef typename deref<argument_type>::type result_type;
    
   typename std::conditional<stores_ref::value, const Perm&, const Perm>::type perm;

   action(const Perm& p)
      : perm(p) {}

   result_type operator() (typename function_argument< argument_type >::const_type x) const
   {
      return permuted_cols(x,perm);
   }      
}; 

// non-homogeneous action on the cols of a matrix with Array<int>
template <typename OpRef, typename Perm>
struct action<OpRef, on_nonhomog_cols, Perm, is_matrix, is_container> {
   typedef OpRef argument_type;
   typedef typename deref<argument_type>::type result_type;
    
   const Perm perm;

   action(const Perm& p)
      : perm(concatenate(pm::single_value_container<int>(0), translate(p, 1))) {}

   result_type operator() (typename function_argument< argument_type >::const_type x) const
   {
      return permuted_cols(x,perm);
   }      
}; 

// action on cols of an IncidenceMatrix with Array<int>
template <typename Perm, typename stores_ref>
struct action<IncidenceMatrix<>, on_container, Perm, is_incidence_matrix, is_container, stores_ref> {
   typedef IncidenceMatrix<> argument_type;
   typedef typename deref<argument_type>::type result_type;
    
   typename std::conditional<stores_ref::value, const Perm&, const Perm>::type perm;

   action(const Perm& p)
      : perm(p) {}

   result_type operator() (typename function_argument<argument_type>::const_type x) const
   {
      return permuted_cols(x,perm);
   }      
}; 

// action on a vector under a matrix group
template <typename OpRef, typename Perm, typename stores_ref>
struct action<OpRef, on_elements, Perm, is_vector, is_matrix, stores_ref> {
   typedef OpRef argument_type;
   typedef typename deref<argument_type>::type result_type;
    
   typename std::conditional<stores_ref::value, const Perm&, const Perm>::type mat;
    
   action(const Perm& m)
      : mat(m.top()) {}
    
   result_type operator() (typename function_argument<argument_type>::const_type x) const
   {
      return mat*x;
   }
};

// right action on a matrix under a matrix group
template <typename OpRef, typename Perm, typename stores_ref>
struct right_action<OpRef, on_elements, Perm, is_matrix, is_matrix, stores_ref> {
   typedef OpRef argument_type;
   typedef typename deref<argument_type>::type result_type;
    
   typename std::conditional<stores_ref::value, const Perm&, const Perm>::type mat;
    
   right_action(const Perm& m)
      : mat(m.top()) {}
    
   result_type operator() (typename function_argument<argument_type>::const_type x) const
   {
      return x*mat;
   }
};

// right action on a permutation under a permutation group
template <typename OpRef, typename Perm, typename stores_ref>
struct right_action<OpRef, on_container, Perm, is_container, is_container, stores_ref> {
   typedef OpRef argument_type;
   typedef typename deref<argument_type>::type result_type;
    
   typename std::conditional<stores_ref::value, const Perm&, const Perm>::type perm;
    
   right_action(const Perm& p)
      : perm(p) {}
    
   result_type operator() (typename function_argument<argument_type>::const_type x) const
   {
      return permuted(perm,x);
   }
};
   
// action on a matrix under a matrix group
template <typename OpRef, typename Perm, typename stores_ref>
struct action<OpRef, on_elements, Perm, is_matrix, is_matrix, stores_ref> {
   typedef OpRef argument_type;
   typedef typename deref<argument_type>::type result_type;
    
   typename std::conditional<stores_ref::value, const Perm&, const Perm>::type mat;
    
   action(const Perm& m)
      : mat(m.top()) {}
    
   result_type operator() (typename function_argument<argument_type>::const_type x) const
   {
      return mat*x;
   }
};
   
// action on the variables of a polyomial with Array<int>
template <typename Perm, typename Coefficient, typename Exponent, typename stores_ref>
struct action<Polynomial<Coefficient,Exponent>&, on_container, Perm, is_polynomial, is_container, stores_ref> {
   typedef Polynomial<Coefficient, Exponent>& argument_type;
   typedef typename deref<argument_type>::type result_type;

   typename std::conditional<stores_ref::value, const Perm&, const Perm>::type perm;

   action(const Perm& p)
      : perm(p) {}

   result_type operator() (typename function_argument<argument_type>::const_type x) const
   {
      return Polynomial<Coefficient, Exponent>(x.coefficients_as_vector(), action<Matrix<Exponent>, on_cols, Perm>(perm)(x.monomials_as_matrix()));
   }      
}; 

// generic action on both elements of a pair
template <typename E1, typename E2, typename action_type, typename Perm, typename perm_tag, typename stores_ref>
struct action<std::pair<E1,E2>&, action_type, Perm, is_composite, perm_tag, stores_ref> {
   typedef std::pair<E1,E2>& argument_type;
   typedef typename deref<argument_type>::type result_type;

   typename std::conditional<stores_ref::value, const Perm&, const Perm>::type perm;

   action(const Perm& p)
      : perm(p) {}

   result_type operator() (typename function_argument<argument_type>::const_type x) const
   {
      return std::make_pair<E1,E2>(action<E1&, action_type, Perm>(perm)(x.first),action<E2&, action_type, Perm>(perm)(x.second));
   }      
}; 

template<typename TMap, typename Perm, typename stores_ref>
struct action<TMap&, on_container, Perm, is_map, is_container, stores_ref> {
   typedef TMap& argument_type;
   typedef typename deref<argument_type>::type result_type;

   typename std::conditional<stores_ref::value, const Perm&, const Perm>::type perm;

   action(const Perm& p)
      : perm(p) {}

   result_type operator() (typename function_argument<argument_type>::const_type m) const
   {
      result_type img;
      const action<typename TMap::key_type, on_container, Perm> a(perm);
      for (const auto e : m)
         img[a(e.first)] = e.second;
      return img;
   }
};

} //end namespace group
} //end namespace operations

} //end namespace pm

namespace polymake { namespace group {

using pm::operations::group::on_container;
using pm::operations::group::on_nonhomog_container;
using pm::operations::group::on_elements;
using pm::operations::group::on_rows;
using pm::operations::group::on_cols;
using pm::operations::group::on_nonhomog_cols;

/*
 * computes the action on something under one permutation element
 */
template <typename action_type, typename Perm, typename Element>
typename pm::object_traits<Element>::persistent_type
action(const Perm& perm, const Element& element) 
{
  return pm::operations::group::action<Element&, action_type, Perm>(perm)(element);
}

// a memory-efficient version of the same
template <typename Iterator, typename Permutation, typename SetType> inline
void permute_to(Iterator in_it,          // deliberately no reference, so we can increment it inside the function
                const Permutation& perm,
                SetType& out)
{
   out.clear();
   while (!in_it.at_end()) {
      out += perm[*in_it];
      ++in_it;
   }
}

/*
 * computes the action on something under the inverse of a Array<int>
 */
template <typename action_type, typename Element>
typename pm::object_traits<Element>::persistent_type
action_inv(const Array<int>& perm, const Element& element) 
{
  Array<int> inv(perm.size());
  inverse_permutation(perm, inv);
  return pm::operations::group::action<Element&,action_type,Array<int> >(inv)(element);
}

} }

#endif // __GROUP_ACTION_H


// Local Variables:
// mode:C++
// c-basic-offset:3
// indent-tabs-mode:nil
// End: