Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Vérifie si <$array,rel> est un groupe
- function rel($x,$y) { // relation
- return ($x+$y)%6;
- }
- $array = [0,1,2,3,4,5]; // array
- $neutres = [];
- $inv = [];
- $fail = 0;
- $nonass = 0;
- $noncom = 0;
- $noninv = 0;
- $nonclt = 0;
- $associativite = "Oui";
- $commutativite = "Oui";
- $cloture = "Oui";
- for ($i = 0; $i < count($array); $i++) {
- $candidat = true;
- for ($j = 0; $j < count($array); $j++) {
- if (rel($array[$i],$array[$j]) == $array[$j] && rel($array[$j],$array[$i]) == $array[$j] && $candidat == true) {
- $candidat = true;
- } else {
- if ($candidat == false) { $fail++; }
- $candidat = false;
- }
- }
- if ($candidat == true) {
- $neutres[count($neutres)] = $array[$i];
- }
- }
- $fail /= count($array)**2;
- for ($i = 0; $i < count($array); $i++) {
- for ($j = 0; $j < count($array); $j++) {
- if (rel($array[$i],$array[$j]) != rel($array[$j],$array[$i])) {
- $commutativite = "Non";
- $noncom++;
- }
- if (!in_array(rel($array[$i],$array[$j]),$array) || !in_array(rel($array[$j],$array[$i]),$array)) {
- $cloture = "Non";
- $nonclt++;
- }
- if (in_array(rel($array[$i],$array[$j]),$neutres)) {
- $inv[2*$i] = "Existe";
- }
- if (in_array(rel($array[$i],$array[$j]),$neutres)) {
- $inv[2*$i+1] = "Existe";
- }
- for ($k = 0; $k < count($array); $k++) {
- if (( rel(rel($array[$i],$array[$j]),$array[$k]) != rel($array[$i],rel($array[$j],$array[$k]))
- || rel(rel($array[$i],$array[$k]),$array[$j]) != rel($array[$i],rel($array[$k],$array[$j]))
- || rel(rel($array[$j],$array[$i]),$array[$k]) != rel($array[$j],rel($array[$i],$array[$k]))
- || rel(rel($array[$j],$array[$k]),$array[$i]) != rel($array[$j],rel($array[$k],$array[$i]))
- || rel(rel($array[$k],$array[$i]),$array[$j]) != rel($array[$k],rel($array[$i],$array[$j]))
- || rel(rel($array[$k],$array[$j]),$array[$i]) != rel($array[$k],rel($array[$j],$array[$i])))) {
- $associativite = "Non";
- $nonass++;
- }
- }
- }
- }
- print "Nb. neutres : ".count($neutres)." (Plage de réussite moyenne : ".round(100*$fail,1)."%)\n";
- print "Nb. inverses : ".count($inv)."/".(2*count($array))." (Échecs : ".(2*count($array)-count($inv))."/".(2*count($array)).")\n";
- print "Commutativité : ".$commutativite." ($noncom/".(count($array)**2)." contrexemples)\n";
- print "Associativité : ".$associativite." ($nonass/".(count($array)**3)." contrexemples)\n";
- print "Clotûre : ".$cloture." (Échecs : $nonclt/".(count($array)**2).")\n";
- if (count($neutres) > 0 && count($inv) == 2*count($array) && $associativite == "Oui" && $cloture == "Oui") {
- print "C'est un groupe";
- if ($commutativite == "Oui") {
- print " abélien";
- } else {
- print " non-abélien";
- }
- } else {
- print "Ce n'est pas un groupe";
- }
- echo `pause>nul`;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement