File: list_suspicious_rules

package info (click to toggle)
polymake 4.12-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 35,992 kB
  • sloc: cpp: 168,768; perl: 43,375; javascript: 31,575; ansic: 3,007; java: 2,654; python: 633; sh: 268; xml: 117; makefile: 61
file content (84 lines) | stat: -rw-r--r-- 3,155 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
#  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.
#-------------------------------------------------------------------------------
#
#  Find all rules in an application that could trigger a permutation but don't declare this
#

if (@ARGV != 1) {
   warn "usage: polymake --script list_suspicious_rules APPLICATION_NAME\n";
   exit(1);
}

application($ARGV[0]);

my %unique;
my @perms=map { grep { $_->flags & Core::Property::Flags::is_permutation and !$unique{$_}++ } values %{$_->properties} }
              @{$application->object_types};

foreach my $rule (@{$application->rules}) {
   next if !defined($rule->code)                # skip shortcut rules and user methods
        or $rule->flags & Core::Rule::Flags::is_function
        or (grep { Core::get_array_flags($_) & Core::Property::Flags::is_permutation } @{$rule->input});   # skip rules dealing with some permutation

   my (%seen_in, %seen_out);
   foreach (@{$rule->input}) {
      possible_permutations($_, \%seen_in) for @$_;
   }
   possible_permutations($_, \%seen_out) for @{$rule->output};
   delete @seen_out{keys %seen_in};
   delete $seen_out{$rule->with_permutation->perm_path->[-1]} if defined $rule->with_permutation;

   if (keys %seen_out) {
      print '"', sub_file($rule->code), '", line ', sub_firstline($rule->code), ": rule ", $rule->header, "\n";
      while (my ($perm, $list)=each %seen_out) {
         print "   ", $perm->name, " : ", join(", ", map { is_object($_) ? $_->name : join(".", map { $_->name } @$_) } @$list), "\n";
      }
      print "\n";
   }
}


sub possible_permutations {
   my ($path, $seen) = @_;
   if (@$path == 1) {
      my $prop = $path->[0];
      foreach my $permutation (@perms) {
         if (defined($permutation->sensitive_props->{$prop->key})) {
            push @{$seen->{$permutation}}, $prop;
         }
      }
   } else {
      foreach my $permutation (@perms) {
         if (defined($permutation->find_sensitive_sub_property(@$path))) {
            push @{$seen->{$permutation}}, $path;
         } else {
            for (my $depth=0; $depth < $#$path; ++$depth) {
               if (defined(my $sub_permutation = $permutation->find_sub_permutation(@$path[0..$depth]))) {
                  if (defined($sub_permutation->find_sensitive_sub_property(@$path[$depth+1..$#$path]))) {
                     push @{$seen->{$permutation}}, $path;
                  }
               }
            }
         }
      }
   }
}

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