Advertisement
apexsquirt

[PHP-CLI] Checking if a finite structure is a group

Jul 15th, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.73 KB | None | 0 0
  1. <?php
  2.  
  3. //Vérifie si <$array,rel> est un groupe
  4.  
  5. function rel($x,$y) {   // relation
  6.     return ($x+$y)%6;
  7. }
  8. $array = [0,1,2,3,4,5]; // array
  9.  
  10. $neutres = [];
  11. $inv = [];
  12. $fail = 0;
  13. $nonass = 0;
  14. $noncom = 0;
  15. $noninv = 0;
  16. $nonclt = 0;
  17. $associativite = "Oui";
  18. $commutativite = "Oui";
  19. $cloture = "Oui";
  20. for ($i = 0; $i < count($array); $i++) {
  21.     $candidat = true;
  22.     for ($j = 0; $j < count($array); $j++) {
  23.         if (rel($array[$i],$array[$j]) == $array[$j] && rel($array[$j],$array[$i]) == $array[$j] && $candidat == true) {
  24.             $candidat = true;
  25.         } else {
  26.             if ($candidat == false) { $fail++; }
  27.             $candidat = false;
  28.         }
  29.     }
  30.     if ($candidat == true) {
  31.         $neutres[count($neutres)] = $array[$i];
  32.     }
  33. }
  34. $fail /= count($array)**2;
  35. for ($i = 0; $i < count($array); $i++) {
  36.     for ($j = 0; $j < count($array); $j++) {
  37.         if (rel($array[$i],$array[$j]) != rel($array[$j],$array[$i])) {
  38.             $commutativite = "Non";
  39.             $noncom++;
  40.         }
  41.         if (!in_array(rel($array[$i],$array[$j]),$array) || !in_array(rel($array[$j],$array[$i]),$array)) {
  42.             $cloture = "Non";
  43.             $nonclt++;
  44.         }
  45.         if (in_array(rel($array[$i],$array[$j]),$neutres)) {
  46.             $inv[2*$i] = "Existe";
  47.         }
  48.         if (in_array(rel($array[$i],$array[$j]),$neutres)) {
  49.             $inv[2*$i+1] = "Existe";
  50.         }
  51.         for ($k = 0; $k < count($array); $k++) {
  52.             if  (( rel(rel($array[$i],$array[$j]),$array[$k]) != rel($array[$i],rel($array[$j],$array[$k]))
  53.                 || rel(rel($array[$i],$array[$k]),$array[$j]) != rel($array[$i],rel($array[$k],$array[$j]))
  54.                 || rel(rel($array[$j],$array[$i]),$array[$k]) != rel($array[$j],rel($array[$i],$array[$k]))
  55.                 || rel(rel($array[$j],$array[$k]),$array[$i]) != rel($array[$j],rel($array[$k],$array[$i]))
  56.                 || rel(rel($array[$k],$array[$i]),$array[$j]) != rel($array[$k],rel($array[$i],$array[$j]))
  57.                 || rel(rel($array[$k],$array[$j]),$array[$i]) != rel($array[$k],rel($array[$j],$array[$i])))) {
  58.                 $associativite = "Non";
  59.                 $nonass++;
  60.             }
  61.         }
  62.     }
  63. }
  64. print "Nb. neutres : ".count($neutres)." (Plage de réussite moyenne : ".round(100*$fail,1)."%)\n";
  65. print "Nb. inverses : ".count($inv)."/".(2*count($array))." (Échecs : ".(2*count($array)-count($inv))."/".(2*count($array)).")\n";
  66. print "Commutativité : ".$commutativite." ($noncom/".(count($array)**2)." contrexemples)\n";
  67. print "Associativité : ".$associativite." ($nonass/".(count($array)**3)." contrexemples)\n";
  68. print "Clotûre : ".$cloture." (Échecs : $nonclt/".(count($array)**2).")\n";
  69. if (count($neutres) > 0 && count($inv) == 2*count($array) && $associativite == "Oui" && $cloture == "Oui") {
  70.     print "C'est un groupe";
  71.     if ($commutativite == "Oui") {
  72.         print " abélien";
  73.     } else {
  74.         print " non-abélien";
  75.     }
  76. } else {
  77.     print "Ce n'est pas un groupe";
  78. }
  79. echo `pause>nul`;
  80.  
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement