Zend - The PHP Company




Miscellaneous

Add Code


Which binary Functions satisfy Semigroupoid  

Type: application
Added by: mike_chimirev
Entered: 15/09/2003
Last modified: 09/12/2002
Rating: - (fewer than 3 votes)
Views: 2877
Calculation to determine which of 16 binary functions satisfy the associative law of SEMIGROUPOID and which ones don't


<?php

$functions 
= array( 
    
"0"=>"0000",
    
"&"=>"0001",
    
"x & ~y"=>"0010",
    
"x"=>"0011",
    
"~x & y"=>"0100",
    
"y"=>"0101",
    
"xor"=>"0110",
    
"or"=>"0111",    
    
"nor"=>"1000",
    
"~nor"=>"1001",
    
"~y"=>"1010",
    
"x | ~y"=>"1011",
    
"~x"=>"1100",
    
"~x | y"=>"1101",
    
"nand"=>"1110",
    
"1"=>"1111");

foreach (
$functions as $key=>$function)
{
    echo 
"<br><table border=1 cellpadding=3 cellspacing=0>";
    echo 
"<tr><td colspan=8 align=center bgcolor=silver><font color=blue><b>$key</b></font></b></td></tr>";
    echo 
"<tr><td align=center>x</td><td align=center>y</td><td align=center>z</td><td align=center>(y+z)</td><td align=center>x+(y+z)</td><td align=center>(x+y)</td><td align=center>(x+y)+z</td><td>x+(y+z)=(x+y)+z</td>";
    foreach(
$xarr=array(false,true) as $x)
    {    
        foreach(
$yarr=array(false,true) as $y)
        {
            foreach(
$zarr=array(false,true) as $z)
            {

                if(
$x){$displayX "T";}
                else  {
$displayX "F";}

                if(
$y){$displayY "T";}
                else  {
$displayY "F";}

                if(
$z){$displayZ "T";}
                else  {
$displayZ "F";}

                echo 
"<tr>";
                echo 
"<td> &nbsp $displayX &nbsp </td><td> &nbsp $displayY &nbsp </td><td> &nbsp $displayZ &nbsp </td>";    
                
                
$leftside operation($x,operation ($y,$z,$function),$function);
                
$rightside operation(operation($x,$y,$function),$z,$function);
        
                echo 
"<td align=center>".operation ($y,$z,$function)."</td>";
                echo 
"<td align=center>".$leftside."</td>";

                echo 
"<td align=center>".operation($x,$y,$function)."</td>";
                echo 
"<td align=center>".$rightside."</td>";    

        
                if(
$leftside == $rightside)
                {
                    echo 
"<td align=center>";                
                    echo 
"<font color=green>";
                }     
                else
                {
                    echo 
"<td bgcolor=silver align=center>";                
                    echo 
"<font color=red>";
                }     

                echo 
"$leftside = $rightside";

                echo 
"</font></b>";
                
                echo 
"</td>";
    
                echo 
"</tr>";
            }
        }
    }
    echo 
"</table>";
}

    echo 
"<br><br>";

    echo
"<table bgcolor=silver width=80%>";
    echo 
"<tr><td>";
    
$source 'semigroupoid.php';
    
highlight_file($source);
    echo 
"</td></tr>";
    echo 
"<table>";


function 
operation($firstValue,$secondValue,$functionID)
{
    
#$functionResults = array ($functionID[0],$functionID[1],$functionID[2],$functionID[3]);

    
if( (!$firstValue) && (!$secondValue) )
    {
        return 
$functionID[0];
    }

    if( (!
$firstValue) && ($secondValue) )
    {
        return 
$functionID[1];
    }

    if( (
$firstValue) && (!$secondValue) )
    {
        return 
$functionID[2];
    }

    if( (
$firstValue) && ($secondValue) )
    {
        return 
$functionID[3];
    }

}

?>


Usage Example




Rate This Script





Search



This Category All Categories