File: action.rules

package info (click to toggle)
polymake 4.14-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,888 kB
  • sloc: cpp: 168,933; perl: 43,407; javascript: 31,575; ansic: 3,007; java: 2,654; python: 632; sh: 268; xml: 117; makefile: 61
file content (743 lines) | stat: -rw-r--r-- 34,131 bytes parent folder | download | duplicates (2)
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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
#  Copyright (c) 1997-2024
#  Ewgenij Gawrilow, Michael Joswig, and the polymake team
#  Technische Universität Berlin, Germany
#  https://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.
#-------------------------------------------------------------------------------

function induced_orbits<Scalar>(fan::PolyhedralFan<Scalar> $$ { homog_action=>0, return_matrix=>1 }) {
    my ($c, $action_name, $generator_name, $options) = @_;
    return group::induced_orbits_impl<Scalar>($c, $action_name, $generator_name, (new Scalar()), $options);
}

object PolyhedralFan {

   # @category Symmetry
   property GROUP : group::Group : multiple {

      # @category Symmetry
      property MATRIX_ACTION : group::MatrixActionOnVectors<Scalar>;

      # @category Symmetry
      # One representative from every orbit of the [[RAYS]] under the group action.
      property REPRESENTATIVE_RAYS : Matrix<Scalar>;

      # @category Symmetry
      # One representative from every orbit of the [[MAXIMAL_CONES]] under the group action.
      property REPRESENTATIVE_MAXIMAL_CONES : IncidenceMatrix;

      # @category Symmetry
      # List of all cones of all dimensions of the fan, one from each orbit,
      # sorted by dimension.
      # Indices in the IncidenceMatrix's refer to [[RAYS]].
      property REPRESENTATIVE_CONES : Array<IncidenceMatrix>;


      #
      # some shortcuts
      #

      # @category Symmetry
      # explicit representatives of equivalence classes of [[fan::INPUT_RAYS]] under a group action
      user_method REPRESENTATIVE_INPUT_RAYS = INPUT_RAYS_ACTION.EXPLICIT_ORBIT_REPRESENTATIVE_MATRIX;

      # @category Symmetry
      # explicit representatives of equivalence classes of [[fan::INPUT_CONES]] under a group action
      user_method REPRESENTATIVE_INPUT_CONES = INPUT_CONES_ACTION.EXPLICIT_ORBIT_REPRESENTATIVES;

      rule REPRESENTATIVE_RAYS = RAYS_ACTION.EXPLICIT_ORBIT_REPRESENTATIVE_MATRIX;

      rule REPRESENTATIVE_MAXIMAL_CONES = MAXIMAL_CONES_ACTION.EXPLICIT_ORBIT_REPRESENTATIVES;

      property MAXIMAL_CONES_ACTION {

           # @category Symmetry
           # dimensions of representatives of maximal cones
           property REPRESENTATIVE_COMBINATORIAL_DIMS : Array<Int>;

           # @category Symmetry
           # counts how many representatives of maximal cones there are in each dimension
           property REPRESENTATIVE_F_VECTOR : Array<Int>;
      }
                                     
   } # end property GROUP

      # First, some rules that apply to all actions

   rule GROUP.ORDER : GROUP.RAYS_ACTION.TRANSVERSAL_SIZES | GROUP.MAXIMAL_CONES_ACTION.TRANSVERSAL_SIZES | GROUP.HOMOGENEOUS_COORDINATE_ACTION.TRANSVERSAL_SIZES {
       my $arr = $this->give("GROUP.RAYS_ACTION.TRANSVERSAL_SIZES | GROUP.MAXIMAL_CONES_ACTION.TRANSVERSAL_SIZES | GROUP.HOMOGENEOUS_COORDINATE_ACTION.TRANSVERSAL_SIZES");
       my $i = new Integer(1);
       $i *= $_ foreach(@{$arr});
       $this->GROUP->ORDER = $i;
   }
   weight 1.10;

   rule GROUP.CONJUGACY_CLASS_SIZES : GROUP.RAYS_ACTION.CONJUGACY_CLASSES | GROUP.MAXIMAL_CONES_ACTION.CONJUGACY_CLASSES | \
       GROUP.HOMOGENEOUS_COORDINATE_ACTION.CONJUGACY_CLASSES | GROUP.SET_ACTION.CONJUGACY_CLASSES  | GROUP.MATRIX_ACTION.CONJUGACY_CLASSES {
           my $arr = $this->give("GROUP.RAYS_ACTION.CONJUGACY_CLASSES | GROUP.MAXIMAL_CONES_ACTION.CONJUGACY_CLASSES | GROUP.HOMOGENEOUS_COORDINATE_ACTION.CONJUGACY_CLASSES | GROUP.SET_ACTION.CONJUGACY_CLASSES | GROUP.MATRIX_ACTION.CONJUGACY_CLASSES");
           $this->GROUP->CONJUGACY_CLASS_SIZES = [ map {$_->size} @{$arr} ];
   }
   weight 1.10;

   # *_ACTION->IRREDUCIBLE_DECOMPOSITION, in alphabetical order
   rule GROUP.HOMOGENEOUS_COORDINATE_ACTION.IRREDUCIBLE_DECOMPOSITION : GROUP.HOMOGENEOUS_COORDINATE_ACTION.CHARACTER, GROUP.CHARACTER_TABLE, GROUP.CONJUGACY_CLASS_SIZES, GROUP.ORDER {
       $this->GROUP->HOMOGENEOUS_COORDINATE_ACTION->IRREDUCIBLE_DECOMPOSITION = group::irreducible_decomposition($this->GROUP->HOMOGENEOUS_COORDINATE_ACTION->CHARACTER, $this->GROUP);
   }
   weight 1.10;

   rule GROUP.MATRIX_ACTION.IRREDUCIBLE_DECOMPOSITION : GROUP.MATRIX_ACTION.CHARACTER, GROUP.CHARACTER_TABLE, GROUP.CONJUGACY_CLASS_SIZES, GROUP.ORDER {
       $this->GROUP->MATRIX_ACTION->IRREDUCIBLE_DECOMPOSITION = group::irreducible_decomposition($this->GROUP->MATRIX_ACTION->CHARACTER, $this->GROUP);
   }
   weight 1.10;

   rule GROUP.MAXIMAL_CONES_ACTION.IRREDUCIBLE_DECOMPOSITION : GROUP.MAXIMAL_CONES_ACTION.CHARACTER, GROUP.CHARACTER_TABLE, GROUP.CONJUGACY_CLASS_SIZES, GROUP.ORDER {
       $this->GROUP->MAXIMAL_CONES_ACTION->IRREDUCIBLE_DECOMPOSITION = group::irreducible_decomposition($this->GROUP->MAXIMAL_CONES_ACTION->CHARACTER, $this->GROUP);
   }
   weight 1.10;

   rule GROUP.RAYS_ACTION.IRREDUCIBLE_DECOMPOSITION : GROUP.RAYS_ACTION.CHARACTER, GROUP.CHARACTER_TABLE, GROUP.CONJUGACY_CLASS_SIZES, GROUP.ORDER {
       $this->GROUP->RAYS_ACTION->IRREDUCIBLE_DECOMPOSITION = group::irreducible_decomposition($this->GROUP->RAYS_ACTION->CHARACTER, $this->GROUP);
   }
   weight 1.10;

   rule GROUP.MAXIMAL_CONES_ACTION.REPRESENTATIVE_COMBINATORIAL_DIMS : MAXIMAL_CONES_COMBINATORIAL_DIMS, GROUP.MAXIMAL_CONES_ACTION.ORBIT_REPRESENTATIVES {
       my @dims;
       foreach (@{$this->GROUP->MAXIMAL_CONES_ACTION->ORBIT_REPRESENTATIVES}) {
           push @dims, $this->MAXIMAL_CONES_COMBINATORIAL_DIMS->[$_];
       }
       $this->GROUP->MAXIMAL_CONES_ACTION->REPRESENTATIVE_COMBINATORIAL_DIMS = \@dims;
   }

   rule GROUP.MAXIMAL_CONES_ACTION.REPRESENTATIVE_F_VECTOR : COMBINATORIAL_DIM, GROUP.MAXIMAL_CONES_ACTION.REPRESENTATIVE_COMBINATORIAL_DIMS {
       my $fvect = new Array<Int>(1 + $this->COMBINATORIAL_DIM);
       foreach (@{$this->GROUP->MAXIMAL_CONES_ACTION->REPRESENTATIVE_COMBINATORIAL_DIMS}) {
           $fvect->[$_]++;
       }
       $this->GROUP->MAXIMAL_CONES_ACTION->REPRESENTATIVE_F_VECTOR = $fvect;
   }
   
   #
   # explicit representatives
   #

   # rule GROUP.SET_ACTION.EXPLICIT_ORBIT_REPRESENTATIVES : GROUP.SET_ACTION.DOMAIN_NAME, GROUP.SET_ACTION.ORBIT_REPRESENTATIVES, MAX_INTERIOR_SIMPLICES | INTERIOR_RIDGE_SIMPLICES {
   #    my $domain_name = $this->GROUP->SET_ACTION->DOMAIN_NAME;
   #    my @reps = map { $this->$domain_name->[$_] } @{$this->GROUP->SET_ACTION->ORBIT_REPRESENTATIVES};
   #    $this->GROUP->SET_ACTION->EXPLICIT_ORBIT_REPRESENTATIVES = \@reps;
   # }
   # weight 1.10;

   rule GROUP.INPUT_RAYS_ACTION.EXPLICIT_ORBIT_REPRESENTATIVE_MATRIX : GROUP.INPUT_RAYS_ACTION.ORBIT_REPRESENTATIVES, INPUT_RAYS {
      $this->GROUP->INPUT_RAYS_ACTION->EXPLICIT_ORBIT_REPRESENTATIVE_MATRIX = $this->INPUT_RAYS->minor($this->GROUP->INPUT_RAYS_ACTION->ORBIT_REPRESENTATIVES, All);
   }
   weight 1.10;

   rule GROUP.RAYS_ACTION.EXPLICIT_ORBIT_REPRESENTATIVE_MATRIX : GROUP.RAYS_ACTION.ORBIT_REPRESENTATIVES, RAYS {
      $this->GROUP->RAYS_ACTION->EXPLICIT_ORBIT_REPRESENTATIVE_MATRIX = $this->RAYS->minor($this->GROUP->RAYS_ACTION->ORBIT_REPRESENTATIVES, All);
   }
   weight 1.10;

   #
   # induce actions from others
   #

   #
   # induce RAYS_ACTION
   #
   rule GROUP.INPUT_RAYS_ACTION.GENERATORS : GROUP.HOMOGENEOUS_COORDINATE_ACTION.GENERATORS, INPUT_RAYS {
      $this->GROUP->INPUT_RAYS_ACTION = group::induce_permutation_action($this, "HOMOGENEOUS_COORDINATE_ACTION", "INPUT_RAYS", "input_ray_action", "induced from coordinate action", 1);
   }
   weight 1.10;

   rule GROUP.INPUT_RAYS_ACTION.CONJUGACY_CLASS_REPRESENTATIVES: GROUP.HOMOGENEOUS_COORDINATE_ACTION.CONJUGACY_CLASS_REPRESENTATIVES, INPUT_RAYS {
      $this->GROUP->INPUT_RAYS_ACTION->CONJUGACY_CLASS_REPRESENTATIVES = group::induced_permutations($this->GROUP->HOMOGENEOUS_COORDINATE_ACTION->CONJUGACY_CLASS_REPRESENTATIVES, $this->INPUT_RAYS, homogeneous_action=>1);
   }
   weight 1.10;

   rule GROUP.RAYS_ACTION.GENERATORS : GROUP.MAXIMAL_CONES_ACTION.GENERATORS, MAXIMAL_CONES_THRU_RAYS {
      $this->GROUP->RAYS_ACTION->GENERATORS = group::induce_permutation_action($this, "MAXIMAL_CONES_ACTION", "MAXIMAL_CONES_THRU_RAYS", "ray_action", "induced from maximal cones action", 0)->GENERATORS;
   }
   weight 1.10;

   rule GROUP.RAYS_ACTION.CONJUGACY_CLASS_REPRESENTATIVES: GROUP.MAXIMAL_CONES_ACTION.CONJUGACY_CLASS_REPRESENTATIVES, MAXIMAL_CONES_THRU_RAYS {
      $this->GROUP->RAYS_ACTION->CONJUGACY_CLASS_REPRESENTATIVES = group::induced_permutations($this->GROUP->MAXIMAL_CONES_ACTION->CONJUGACY_CLASS_REPRESENTATIVES, $this->MAXIMAL_CONES_THRU_RAYS, homogeneous_action=>0);
   }
   weight 1.10;

   rule GROUP.RAYS_ACTION.GENERATORS : GROUP.HOMOGENEOUS_COORDINATE_ACTION.GENERATORS, RAYS {
      $this->GROUP->RAYS_ACTION->GENERATORS = group::induce_permutation_action($this, "HOMOGENEOUS_COORDINATE_ACTION", "RAYS", "ray_action", "induced from homogeneous coordinate action", 1)->GENERATORS;
   }
   weight 1.10;

   rule GROUP.RAYS_ACTION.CONJUGACY_CLASS_REPRESENTATIVES: GROUP.HOMOGENEOUS_COORDINATE_ACTION.CONJUGACY_CLASS_REPRESENTATIVES, RAYS {
      $this->GROUP->RAYS_ACTION->CONJUGACY_CLASS_REPRESENTATIVES = group::induced_permutations($this->GROUP->HOMOGENEOUS_COORDINATE_ACTION->CONJUGACY_CLASS_REPRESENTATIVES, $this->RAYS, homogeneous_action=>1);
   }
   weight 1.10;

   #
   # induce MAXIMAL_CONES_ACTION
   #

   rule GROUP.MAXIMAL_CONES_ACTION.GENERATORS : GROUP.RAYS_ACTION.GENERATORS, MAXIMAL_CONES {
      $this->GROUP->MAXIMAL_CONES_ACTION->GENERATORS = group::induce_permutation_action($this, "RAYS_ACTION", "MAXIMAL_CONES", "maximal_cones_action", "induced from ray action", 0)->GENERATORS;
   }
   weight 1.10;

   rule GROUP.MAXIMAL_CONES_ACTION.CONJUGACY_CLASS_REPRESENTATIVES: GROUP.RAYS_ACTION.CONJUGACY_CLASS_REPRESENTATIVES, MAXIMAL_CONES {
      $this->GROUP->MAXIMAL_CONES_ACTION->CONJUGACY_CLASS_REPRESENTATIVES = group::induced_permutations($this->GROUP->RAYS_ACTION->CONJUGACY_CLASS_REPRESENTATIVES, $this->MAXIMAL_CONES, homogeneous_action=>0);
   }
   weight 1.10;

   #
   # induce MATRIX_ACTION
   #

   rule GROUP.MATRIX_ACTION.GENERATORS : GROUP.INPUT_RAYS_ACTION.GENERATORS, INPUT_RAYS {
       group::induce_matrix_action_generators($this, "MATRIX_ACTION", "INPUT_RAYS_ACTION", "INPUT_RAYS", new Matrix<Scalar>());
   }

   rule GROUP.MATRIX_ACTION.CONJUGACY_CLASS_REPRESENTATIVES : GROUP.INPUT_RAYS_ACTION.CONJUGACY_CLASS_REPRESENTATIVES, INPUT_RAYS {
       group::induce_matrix_action_conjugacy_class_representatives($this, "MATRIX_ACTION", "INPUT_RAYS_ACTION", "INPUT_RAYS", new Matrix<Scalar>());
   }

   rule GROUP.MATRIX_ACTION.GENERATORS : GROUP.RAYS_ACTION.GENERATORS, RAYS {
       group::induce_matrix_action_generators($this, "MATRIX_ACTION", "RAYS_ACTION", "RAYS", new Matrix<Scalar>());
   }

   rule GROUP.MATRIX_ACTION.CONJUGACY_CLASS_REPRESENTATIVES : GROUP.RAYS_ACTION.CONJUGACY_CLASS_REPRESENTATIVES, RAYS {
       group::induce_matrix_action_conjugacy_class_representatives($this, "MATRIX_ACTION", "RAYS_ACTION", "RAYS", new Matrix<Scalar>());
   }

   #
   # Others
   #

   rule GROUP.FACET_NORMALS_ACTION.GENERATORS : GROUP.HOMOGENEOUS_COORDINATE_ACTION.GENERATORS, FACET_NORMALS {
      $this->GROUP->FACET_NORMALS_ACTION->GENERATORS = group::induce_permutation_action($this, "HOMOGENEOUS_COORDINATE_ACTION", "FACET_NORMALS", "facet_normals_action", "induced from homogeneous_coordinate_action", 1, \&canonicalize_facets)->GENERATORS;
   }
   weight 1.10;

   rule GROUP.FACET_NORMALS_ACTION.CONJUGACY_CLASS_REPRESENTATIVES: GROUP.HOMOGENEOUS_COORDINATE_ACTION.CONJUGACY_CLASS_REPRESENTATIVES, FACET_NORMALS {
      $this->GROUP->FACET_NORMALS_ACTION->CONJUGACY_CLASS_REPRESENTATIVES = group::induced_permutations($this->GROUP->HOMOGENEOUS_COORDINATE_ACTION->CONJUGACY_CLASS_REPRESENTATIVES, $this->FACET_NORMALS, homogeneous_action=>1);
   }
   weight 1.10;
   
   #
   # Orbits induced by coordinate actions
   #

   rule INPUT_RAYS, GROUP.INPUT_RAYS_ACTION.EXPLICIT_ORBIT_REPRESENTATIVE_MATRIX : GROUP.HOMOGENEOUS_COORDINATE_ACTION.GENERATORS, GROUP.HOMOGENEOUS_COORDINATE_ACTION.INPUT_RAYS_GENERATORS {
      my ($pts, $a) = induced_orbits($this, "HOMOGENEOUS_COORDINATE_ACTION", "INPUT_RAYS_GENERATORS", homog_action => 1);
      $this->INPUT_RAYS = $pts;
      $this->GROUP->INPUT_RAYS_ACTION = $a;
   }
   weight 2.10;
#    incurs PointsPerm;

   method rays_from_action($) {
       my ($this, $action_type) = @_;
       my $is_homogeneous = ($action_type eq "HOMOGENEOUS_COORDINATE_ACTION");
       my ($pts, $a) = induced_orbits($this, $action_type, "RAYS_GENERATORS", homog_action => $is_homogeneous, return_matrix => 0);
       
       # make the given RAYS_GENERATORS come first in the list of RAYS
       my $rep_set = new HashSet<Vector<Scalar>>;
       my @pts_in_order;
       foreach (@{$this->GROUP->$action_type->RAYS_GENERATORS}) {
           $rep_set += $_;
           push @pts_in_order, $_;
       }

       foreach (@{$pts}) {
           if ( ! $rep_set->contains($_) ) {
               push @pts_in_order, $_;
           }
       }

       my $all_rays = new Matrix<Scalar>(\@pts_in_order);
       # we find the induced permutation action on the rows of this matrix
       # before assigning it to RAYS
       # because that assignment homogenizes the first column and sabotages
       # the attempt to find the induced permutation
       my $ia = group::induce_permutation_action($this, $action_type, $all_rays, "induced RAYS_ACTION", "induced from $action_type", $is_homogeneous);

       $this->RAYS = $all_rays;
       $a->GENERATORS = $ia->GENERATORS;
       if (defined $ia->lookup("CONJUGACY_CLASS_REPRESENTATIVES")) {
           $a->CONJUGACY_CLASS_REPRESENTATIVES = $ia->CONJUGACY_CLASS_REPRESENTATIVES;
       }
       $this->GROUP->RAYS_ACTION = $a;
   }
                           
   rule RAYS, GROUP.RAYS_ACTION.GENERATORS, GROUP.RAYS_ACTION.EXPLICIT_ORBIT_REPRESENTATIVE_MATRIX : GROUP.HOMOGENEOUS_COORDINATE_ACTION.GENERATORS, GROUP.HOMOGENEOUS_COORDINATE_ACTION.RAYS_GENERATORS {
       $this->rays_from_action("HOMOGENEOUS_COORDINATE_ACTION");
   }
   weight 2.10;
   incurs RaysPerm;

   rule RAYS, GROUP.RAYS_ACTION.GENERATORS, GROUP.RAYS_ACTION.EXPLICIT_ORBIT_REPRESENTATIVE_MATRIX : GROUP.MATRIX_ACTION.GENERATORS, GROUP.MATRIX_ACTION.RAYS_GENERATORS {
       $this->rays_from_action("MATRIX_ACTION");
   }
   weight 2.10;
   incurs RaysPerm;
                           
   rule MAXIMAL_CONES : RAYS, GROUP.RAYS_ACTION.GENERATORS, GROUP.MAXIMAL_CONES_ACTION.MAXIMAL_CONES_GENERATORS {
       my $gens = $this->GROUP->RAYS_ACTION->GENERATORS;
       my $all_cones = new HashSet<Set<Int>>;
       foreach (@{$this->GROUP->MAXIMAL_CONES_ACTION->MAXIMAL_CONES_GENERATORS}) {
           foreach(@{group::orbit($gens, new Set($_))}) {
               $all_cones += $_;
           }
       }
       my $max_cones = new IncidenceMatrix($all_cones->size(), $gens->[0]->size());
       my $i=0;
       foreach (@{$all_cones}) {
           $max_cones->row($i++) += $_;
       }
       $this->MAXIMAL_CONES = $max_cones;
   }
   weight 2.10;
   incurs ConesPerm;

} # end PolyhedralFan


object PolyhedralComplex {

    property GROUP {

        # @category Symmetry
        property VERTICES_ACTION = override RAYS_ACTION;

        # @category Symmetry
        property COORDINATE_ACTION = override HOMOGENEOUS_COORDINATE_ACTION {

            # @category Symmetry
            property POINTS_GENERATORS = override INPUT_RAYS_GENERATORS;

            # @category Symmetry
            property N_POINTS_GENERATORS = override N_INPUT_RAYS_GENERATORS;

            # @category Symmetry
            property VERTICES_GENERATORS = override RAYS_GENERATORS;

            # @category Symmetry
            property N_VERTICES_GENERATORS = override N_RAYS_GENERATORS;
        }

        # @category Symmetry
        property POINTS_ACTION = override INPUT_RAYS_ACTION;

        # @category Symmetry
        property MAXIMAL_POLYTOPES_ACTION = override MAXIMAL_CONES_ACTION {

            # @category Symmetry
            property POINTS_GENERATORS = override INPUT_RAYS_GENERATORS;

            # @category Symmetry
            property N_POINTS_GENERATORS = override N_INPUT_RAYS_GENERATORS;

            # @category Symmetry
            property VERTICES_GENERATORS = override RAYS_GENERATORS;

            # @category Symmetry
            property N_VERTICES_GENERATORS = override N_RAYS_GENERATORS;

            # @category Symmetry
            property MAXIMAL_POLYTOPES_GENERATORS = override MAXIMAL_CONES_GENERATORS;
        }

        # @category Symmetry
        property MATRIX_ACTION_ON_COMPLEX = override MATRIX_ACTION { 
            # overriding this name is silly, but if the name of the action is not overridden, assigning to GENERATORS breaks.
            # to test this, delete the "override" and execute the example for 
            # orbit_complex<Scalar>(fan::PolyhedralComplex<Scalar>, group::MatrixActionOnVectors<Scalar>)
            
            # @category Symmetry
            property VERTICES_GENERATORS = override RAYS_GENERATORS;

        }
            
        # @category Symmetry
        property REPRESENTATIVE_VERTICES = override REPRESENTATIVE_RAYS;

        # @category Symmetry
        property REPRESENTATIVE_MAXIMAL_POLYTOPES = override REPRESENTATIVE_MAXIMAL_CONES;

   }

   # induced actions

   rule GROUP.POINTS_ACTION.GENERATORS : GROUP.COORDINATE_ACTION.GENERATORS , POINTS {
      $this->GROUP->POINTS_ACTION->GENERATORS = group::induce_permutation_action($this, "COORDINATE_ACTION", "POINTS", "points_action", "induced from coordinate_action")->GENERATORS;
   }
   weight 1.10;

   rule GROUP.POINTS_ACTION.CONJUGACY_CLASS_REPRESENTATIVES: GROUP.COORDINATE_ACTION.CONJUGACY_CLASS_REPRESENTATIVES, POINTS {
      $this->GROUP->POINTS_ACTION->CONJUGACY_CLASS_REPRESENTATIVES = group::induced_permutations($this->GROUP->COORDINATE_ACTION->CONJUGACY_CLASS_REPRESENTATIVES, $this->POINTS, homogeneous_action=>0);
   }
   weight 1.10;

   rule GROUP.POINTS_ACTION.GENERATORS, GROUP.POINTS_ACTION.DEGREE : GROUP.PERMUTATION_ACTION.GENERATORS, GROUP.PERMUTATION_ACTION.DEGREE {
       $this->GROUP->POINTS_ACTION->GENERATORS = $this->GROUP->PERMUTATION_ACTION->GENERATORS;
       $this->GROUP->POINTS_ACTION->DEGREE = $this->GROUP->PERMUTATION_ACTION->DEGREE;
   }
   weight 0.10;
   precondition : GROUP.PERMUTATION_ACTION.DEGREE, N_POINTS { $this->GROUP->PERMUTATION_ACTION->DEGREE == $this->N_POINTS }

   rule GROUP.VERTICES_ACTION.GENERATORS : GROUP.COORDINATE_ACTION.GENERATORS, VERTICES {
      $this->GROUP->VERTICES_ACTION->GENERATORS = group::induce_permutation_action($this, "COORDINATE_ACTION", "VERTICES", "vertices_action", "induced from coordinate_action")->GENERATORS;
   }
   weight 1.10;

   rule GROUP.VERTICES_ACTION.CONJUGACY_CLASS_REPRESENTATIVES: GROUP.COORDINATE_ACTION.CONJUGACY_CLASS_REPRESENTATIVES, VERTICES {
      $this->GROUP->VERTICES_ACTION->CONJUGACY_CLASS_REPRESENTATIVES = group::induced_permutations($this->GROUP->COORDINATE_ACTION->CONJUGACY_CLASS_REPRESENTATIVES, $this->VERTICES, homogeneous_action=>0);
   }
   weight 1.10;

   rule GROUP.VERTICES_ACTION.GENERATORS, GROUP.VERTICES_ACTION.DEGREE : GROUP.PERMUTATION_ACTION.GENERATORS, GROUP.PERMUTATION_ACTION.DEGREE {
      $this->GROUP->VERTICES_ACTION->GENERATORS = $this->GROUP->PERMUTATION_ACTION->GENERATORS;
      $this->GROUP->VERTICES_ACTION->DEGREE = $this->GROUP->PERMUTATION_ACTION->DEGREE;
   }
   weight 0.10;
   precondition : GROUP.PERMUTATION_ACTION.DEGREE, N_VERTICES { $this->GROUP->PERMUTATION_ACTION->DEGREE == $this->N_VERTICES }


   # induced orbits
   
   rule POINTS, GROUP.POINTS_ACTION.EXPLICIT_ORBIT_REPRESENTATIVE_MATRIX : GROUP.COORDINATE_ACTION.GENERATORS, GROUP.COORDINATE_ACTION.POINTS_GENERATORS {
      my ($pts, $a) = induced_orbits($this, "COORDINATE_ACTION", "POINTS_GENERATORS", homog_action => 0);
      $this->POINTS = $pts;
      $this->GROUP->POINTS_ACTION = $a;
   }
   weight 2.10;
#   incurs PointsPerm;

   rule VERTICES, GROUP.VERTICES_ACTION.GENERATORS, GROUP.VERTICES_ACTION.EXPLICIT_ORBIT_REPRESENTATIVE_MATRIX : GROUP.COORDINATE_ACTION.GENERATORS, GROUP.COORDINATE_ACTION.VERTICES_GENERATORS {
       $this->rays_from_action("COORDINATE_ACTION");
   }
   weight 2.10;
   incurs RaysPerm;

   rule GROUP.POINTS_ACTION.EXPLICIT_ORBIT_REPRESENTATIVE_MATRIX : GROUP.POINTS_ACTION.ORBIT_REPRESENTATIVES, POINTS {
       $this->GROUP->POINTS_ACTION->EXPLICIT_ORBIT_REPRESENTATIVE_MATRIX = $this->POINTS->minor($this->GROUP->POINTS_ACTION->ORBIT_REPRESENTATIVES, All);
   }
   weight 1.10;

   # Generates an array with a specified number of different colors.
   # @param Int number      the number of colors
   # @return array          the colors as strings
   sub generateColors {
       my $number=$_[0];
   # not really implemented yet!
       my @FIFTEEN_COLORS=("chocolate1","salmon1","plum1","LightGreen","azure","LightSlateGrey","MidnightBlue","DarkOliveGreen","IndianRed","LavenderBlush","orange","green","red","blue","yellow");
       my @colors=();
       for(my $i=0;$i<$number;$i++) {
           if($i<15) {
               $colors[$i]=$FIFTEEN_COLORS[14-$i];
           } else {
               $colors[$i]="black";
           }
       }
       return @colors;
   }

   # @category Visualization
   # Visualizes the graph of a symmetric cone:
   # All nodes belonging to one orbit get the same color.
   # @return Visual::PolytopeGraph
   user_method VISUAL_ORBIT_COLORED_GRAPH(%Visual::Graph::decorations, { seed => undef }) {
       my ($this, $decor, $seed)=@_;
       my @colors=generateColors($this->GROUP->RAYS_ACTION->N_ORBITS);
       my @nodeColors;
       for(my $i=0; $i<$this->GROUP->RAYS_ACTION->N_ORBITS; $i++){
           foreach my $ray_index(@{$this->GROUP->RAYS_ACTION->ORBITS->[$i]}){
               $nodeColors[$ray_index]=$colors[$i]; #each ray gets the color(=number) of its orbit
           }
       }
       my $VG=$this->GRAPH->VISUAL( Name => $this->name,
                                    (exists $decor->{NodeBorderColor} || exists $decor->{VertexColor} ? () : (NodeColor => \@nodeColors)),
                                    $decor, $seed );
       visualize( new Visual::PolytopeGraph( Name => "ORBIT_COLORED_GRAPH of " . $this->name,
                                             Polytope => $this,
                                             $VG ));
   }

} # end PolyhedralComplex


# @category Symmetry
# Constructs the orbit fan of a given fan //input_fan//
# with respect to a given set of generators //gens//.
# @param fan::PolyhedralFan input_fan the generating fan of the orbit fan
# @param Array<Array<Int>> gens the generators of a permutation group that acts on the coordinates of the ambient space
# @return fan::PolyhedralFan the orbit fan of //input_fan// w.r.t. the coordinate action generated by //gens//
# @example [prefer ppl] To calculate an orbit fan, follow these steps:
# First specify a seed fan:
# > $f=new PolyhedralFan(RAYS=>[[1,1],[1,0],[-1,-1]], MAXIMAL_CONES=>[[0,1],[1,2]]);
# Then define the orbit fan by specifying coordinate permutations:
# > $of = orbit_fan($f,[[1,0]]);
# The only properties of $of defined so far reside in GROUP:
# > print $of->GROUP->properties();
# | name: unnamed#0
# | type: Group as PolyhedralFan<Rational>::GROUP
# | 
# | HOMOGENEOUS_COORDINATE_ACTION
# | type: PermutationAction<Int, Rational>
# | 
# | MAXIMAL_CONES_ACTION
# | type: PermutationAction<Int, Rational> as PolyhedralFan<Rational>::GROUP::MAXIMAL_CONES_ACTION
# |
# Now you can calculate the [[RAYS]] and [[MAXIMAL_CONES]] of the orbit fan.
# > print $of->RAYS;
# | 1 1
# | 1 0
# | -1 -1
# | 0 1
# > print $of->N_MAXIMAL_CONES;
# | 4

user_function orbit_fan(fan::PolyhedralFan, can_convert_to<Array<Array<Int>>>) {
    my ($input_fan, $gens) = @_;
    my $ra = new group::PermutationAction(GENERATORS=>$gens, RAYS_GENERATORS=>$input_fan->give("RAYS | INPUT_RAYS"));
    my $ca = new group::PermutationAction(MAXIMAL_CONES_GENERATORS=>$input_fan->MAXIMAL_CONES);
    my $g = new group::Group;
    my $p = new fan::PolyhedralFan;
    $p->add("GROUP", $g, HOMOGENEOUS_COORDINATE_ACTION=>$ra, MAXIMAL_CONES_ACTION=>$ca);
    return $p;
}


# @category Symmetry
# Constructs the orbit fan of a given fan //input_fan//
# with respect to a given set of matrix group generators //gens//.
# @param fan::PolyhedralFan input_fan the generating fan of the orbit fan
# @param Array<Matrix<Scalar>> gens the generators of a matrix group that acts on the ambient space
# @tparam Scalar underlying number type
# @return fan::PolyhedralFan the orbit fan of //input_fan// w.r.t. the matrix action generated by //gens//
# @example To calculate an orbit fan, follow these steps:
# First specify a seed fan:
# > $f=new PolyhedralFan(RAYS=>[[1,1,1],[1,1,0],[1,1/2,1/4]],MAXIMAL_CONES=>[[0,2],[1,2]]);
# Then define the orbit fan by specifying a matrix group action:
# > $of = orbit_fan($f,polytope::cube(2,group=>1)->GROUP->MATRIX_ACTION);
# The only properties of $of defined so far reside in GROUP:
# > print $of->GROUP->properties();
# | name: unnamed#0
# | type: Group as PolyhedralFan<Rational>::GROUP
# | 
# | MATRIX_ACTION
# | type: MatrixActionOnVectors<Rational>
# | 
# | MAXIMAL_CONES_ACTION
# | type: PermutationAction<Int, Rational> as PolyhedralFan<Rational>::GROUP::MAXIMAL_CONES_ACTION
# |
# Now you can calculate the [[RAYS]] and [[MAXIMAL_CONES]] of the orbit fan.
# > print $of->RAYS;
# | 1 1 1
# | 1 1 0
# | 1 1/2 1/4
# | 1 -1 -1
# | 1 -1 1
# | 1 1 -1
# | 1 -1 0
# | 1 0 -1
# | 1 0 1
# | 1 -1/2 -1/4
# | 1 -1/2 1/4
# | 1 -1/4 -1/2
# | 1 -1/4 1/2
# | 1 1/4 -1/2
# | 1 1/4 1/2
# | 1 1/2 -1/4
# > print $of->N_MAXIMAL_CONES;
# | 16
   
user_function orbit_fan<Scalar>(fan::PolyhedralFan<Scalar>, group::MatrixActionOnVectors<Scalar>) {
    my ($input_fan, $a) = @_;
    my $ra = new group::MatrixActionOnVectors<Scalar>(GENERATORS=>$a->GENERATORS, RAYS_GENERATORS=>$input_fan->give("RAYS | INPUT_RAYS"));
    my $ca = new group::MatrixActionOnVectors<Scalar>(MAXIMAL_CONES_GENERATORS=>$input_fan->MAXIMAL_CONES);
    my $g = new group::Group;
    my $p = new fan::PolyhedralFan;
    $p->add("GROUP", $g, MATRIX_ACTION=>$ra, MAXIMAL_CONES_ACTION=>$ca);
    return $p;
}

# @category Symmetry
# Constructs the orbit complex of a given polyhedral complex //input_complex//
# with respect to a given set of generators //gens//.
# @param fan::PolyhedralComplex input_complex the generating complex of the orbit complex
# @param Array<Array<Int>> gens the generators of a permutation group that acts on the coordinates of the ambient space
# @return fan::PolyhedralComplex the orbit complex of //input_complex// w.r.t. the coordinate action generated by //gens//
# @example [prefer ppl] To calculate an orbit complex with respect to a group of coordinate permutations, follow these steps:
# First specify a seed complex:
# > $f=new PolyhedralComplex(VERTICES=>[[1,1,1],[1,1,0],[1,-1,-1]], MAXIMAL_POLYTOPES=>[[0,1],[1,2]]);
# Then define the orbit complex by specifying a permutation action on coordinates:
# > $oc = orbit_complex($f, [[1,0]]);
# The only properties of $oc defined so far reside in GROUP:
# > print $oc->GROUP->properties();
# | type: Group as PolyhedralComplex<Rational>::GROUP
# | 
# | COORDINATE_ACTION
# | type: PermutationAction<Int, Rational> as PolyhedralComplex<Rational>::GROUP::COORDINATE_ACTION
# | 
# | MAXIMAL_POLYTOPES_ACTION
# | type: PermutationAction<Int, Rational> as PolyhedralComplex<Rational>::GROUP::MAXIMAL_POLYTOPES_ACTION
#
# Now you can calculate the [[VERTICES]] and [[MAXIMAL_POLYTOPES]] of the orbit fan.
# > print $oc->VERTICES;
# | 1 1 1
# | 1 1 0
# | 1 -1 -1
# | 1 0 1
# > print $oc->N_MAXIMAL_POLYTOPES;
# | 4

user_function orbit_complex(fan::PolyhedralComplex, can_convert_to<Array<Array<Int>>>) {
    my ($input, $gens) = @_;
    return new fan::PolyhedralComplex(GROUP => new group::Group,
                                      "GROUP.COORDINATE_ACTION" => new group::PermutationAction(), 
                                      "GROUP.COORDINATE_ACTION.GENERATORS" => $gens,
                                      "GROUP.COORDINATE_ACTION.VERTICES_GENERATORS" => $input->give("VERTICES | POINTS"),
                                      "GROUP.MAXIMAL_POLYTOPES_ACTION" => new group::PermutationAction(),
                                      "GROUP.MAXIMAL_POLYTOPES_ACTION.MAXIMAL_POLYTOPES_GENERATORS" => $input->MAXIMAL_POLYTOPES);
}

# @category Symmetry
# Constructs the orbit complex of a given polyhedral complex //input_complex//
# with respect to a given group action //a//.
# @param fan::PolyhedralComplex input_complex the generating complex of the orbit complex
# @param group::PermutationAction a the action of a permutation group on the coordinates of the ambient space
# @return fan::PolyhedralComplex the orbit complex of //input_complex// w.r.t. the action //a//
# @example To calculate an orbit complex with respect to a group of coordinate permutations, follow these steps:
# First specify a seed complex:
# > $f=new PolyhedralComplex(VERTICES=>[[1,1,1],[1,1,0],[1,1/2,1/4]], MAXIMAL_POLYTOPES=>[[0,2],[1,2]]);
# Then define the orbit complex by specifying a matrix group action on the coordinates:
# > $oc = orbit_complex($f, polytope::cube(2,group=>1)->GROUP->MATRIX_ACTION);
# The only properties of $oc defined so far reside in GROUP:
# | type: Group as PolyhedralComplex<Rational>::GROUP
# | 
# | MATRIX_ACTION_ON_COMPLEX
# | type: MatrixActionOnVectors<Rational> as PolyhedralComplex<Rational>::GROUP::MATRIX_ACTION_ON_COMPLEX
# | 
# | MAXIMAL_POLYTOPES_ACTION
# | type: PermutationAction<Int, Rational> as PolyhedralComplex<Rational>::GROUP::MAXIMAL_POLYTOPES_ACTION
# 
# Now you can calculate the [[VERTICES]] and [[MAXIMAL_POLYTOPES]] of the orbit fan.
# > print $oc->VERTICES;
# | 1 1 1
# | 1 1 0
# | 1 1/2 1/4
# | 1 -1 -1
# | 1 -1 1
# | 1 1 -1
# | 1 -1 0
# | 1 0 -1
# | 1 0 1
# | 1 -1/2 -1/4
# | 1 -1/2 1/4
# | 1 -1/4 -1/2
# | 1 -1/4 1/2
# | 1 1/4 -1/2
# | 1 1/4 1/2
# | 1 1/2 -1/4
# > print $oc->N_MAXIMAL_POLYTOPES;
# | 16

user_function orbit_complex<Scalar>(fan::PolyhedralComplex<Scalar>, group::MatrixActionOnVectors<Scalar>) {
    my ($input, $a) = @_;
    my $ma = new group::MatrixActionOnVectors<Scalar>();
    return new fan::PolyhedralComplex(GROUP => new group::Group,
                                      "GROUP.MATRIX_ACTION_ON_COMPLEX" => $ma,
                                      "GROUP.MATRIX_ACTION_ON_COMPLEX.GENERATORS" => $a->GENERATORS,
                                      "GROUP.MATRIX_ACTION_ON_COMPLEX.VERTICES_GENERATORS" => $input->give("VERTICES | POINTS"),
                                      "GROUP.MAXIMAL_POLYTOPES_ACTION" => new group::PermutationAction(),
                                      "GROUP.MAXIMAL_POLYTOPES_ACTION.MAXIMAL_POLYTOPES_GENERATORS" => $input->MAXIMAL_POLYTOPES);
}


# @category Symmetry
# Returns the permutation action induced by the symmetry group of the fan //f// on the set of //k//-dimensional cones.
# This action is not stored as a property of //f//, because polymake doesn't support dynamic names of properties.
# Be aware that the set of //k//-dimensional cones itself is ''%% $f->CONES->[$k-1] %%''.
# @param fan::PolyhedralFan f the input fan
# @param Int k the dimension of the cones to induce the action on
# @return group::PermutationAction a the action induced by //Aut//(//f//) on the set of //k//-dimensional cones
# @example Consider a 3-cube //c//. To calculate the induced action of //Aut//(//c//) on the set of 2-dimensional cones of the normal fan, type
# > $f = fan::normal_fan(polytope::cube(3, group=>1));
# > print fan::cones_action($f,2)->properties();
# | name: CONES_ACTION(2)
# | type: PermutationAction<Int, Rational>
# | description: action induced on 2-dimensional cones
# | 
# | GENERATORS
# | 0 3 4 1 2 5 7 6 8 10 9 11
# | 1 0 2 5 6 3 4 7 9 8 11 10
# | 0 2 1 4 3 8 9 10 5 6 7 11
# > print $f->CONES->[1];
# | {2 4}
# | {0 4}
# | {0 2}
# | {1 4}
# | {1 2}
# | {3 4}
# | {0 3}
# | {1 3}
# | {2 5}
# | {0 5}
# | {1 5}
# | {3 5}

user_function cones_action(fan::PolyhedralFan, $) {
    my ($this, $k) = @_;
    my $a = new group::PermutationAction("CONES_ACTION($k)");
    my $cones = $this->HASSE_DIAGRAM->cones_of_dim($k);
    $a->GENERATORS = group::induced_permutations($this->GROUP->RAYS_ACTION->GENERATORS, $cones);
    if (defined(my $cc = $this->lookup("GROUP.RAYS_ACTION.CONJUGACY_CLASS_REPRESENTATIVES"))) {
        $a->CONJUGACY_CLASS_REPRESENTATIVES = group::induced_permutations($cc, $cones);
    }
    $a->description = "action induced on $k-dimensional cones";
    return $a;
}



# @category Symmetry
# Compute the combinatorial symmetries (i.e., automorphisms of the face lattice) of
# a given fan //f//. They are stored in terms of a GROUP.RAYS_ACTION and a GROUP.MAXIMAL_CONES_ACTION
# property in //f//, and the GROUP.MAXIMAL_CONES_ACTION is also returned.
# @param PolyhedralFan f
# @return group::PermutationAction the action of the combinatorial symmetry group on the rays
# @example To get the ray symmetry group of the square and print its generators, type the following:
# > print combinatorial_symmetries(normal_fan(polytope::cube(2)))->GENERATORS;
# | 2 3 0 1
# | 1 0 3 2
# | 0 2 1 3
# > $f = normal_fan(polytope::cube(2)); combinatorial_symmetries($f);
# > print $f->GROUP->RAYS_ACTION->GENERATORS;
# | 0 1 3 2
# | 1 0 2 3
# | 2 3 0 1
# > print $f->GROUP->MAXIMAL_CONES_ACTION->GENERATORS;
# | 2 3 0 1
# | 1 0 3 2
# | 0 2 1 3

user_function combinatorial_symmetries(fan::PolyhedralFan) {
    my ($f) = @_;
    return group::combinatorial_symmetries_impl($f, $f->MAXIMAL_CONES, "MAXIMAL_CONES_ACTION", "RAYS_ACTION");
}

# Local Variables:
# mode: perl
# cperl-indent-level: 3
# indent-tabs-mode:nil
# End: