Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class phlegmClass
- {
- public $bogus="bogus";
- public function __construct()
- {
- $this->bogus="bogus";
- }
- public function math($mnemonic="",&$q=0,$p=0,$T=true,$F=false)
- {
- global $pretty, $stats;
- foreach(
- [
- "inequalityGates" => false,
- "arithmeticOp" => false,
- "vennGates" => true
- ] as $instructionSet => $truths
- )
- {
- switch(true)
- {
- case $truths:
- $ret = $this->$instructionSet($mnemonic,$q,$p,$T,$F);
- default:
- $ret = $this->$instructionSet($mnemonic,$q,$p);
- }
- if($ret !== $this->bogus){return $ret;}
- }
- return $this->bogus;
- }
- public function inequalityGates($mnemonic="",&$q=0,$p=0)
- {
- global $pretty, $stats;
- if(is_string($mnemonic))
- {
- $mnemonic=strtoupper($mnemonic);
- }
- switch($mnemonic)
- {
- case "EQU":
- case "==":
- case "===":
- return ($q==$p);
- case "NEQ":
- case "<>":
- case "!=":
- case "!==":
- return ($q!==$p);
- case "GTR":
- case ">":
- return ($q>$p);
- case "LSS":
- case "<":
- return ($q<$p);
- case "GEQ":
- case ">=":
- return ($q>=$p);
- case "LEQ":
- case "<=":
- return ($q<=$p);
- }
- return $this->bogus;
- }
- public function arithmeticOp($mnemonic="",&$q=0,$p=0)
- {
- global $pretty, $stats;
- if(is_string($mnemonic))
- {
- $mnemonic=strtoupper($mnemonic);
- }
- switch($mnemonic)
- {
- case "=":
- $q=$p;
- return $q;
- case "&=":
- case ".=":
- $q.=$p;
- return $q;
- case "+=":
- $q+=$p;
- return $q;
- case "-=":
- $q-=$p;
- return $q;
- case "*=":
- $q=$q*$p;
- return $q;
- case "/=":
- $q=$q/$p;
- return $q;
- case "++":
- $q++;
- return $q;
- case "--":
- $q--;
- return $q;
- }
- return $this->bogus;
- }
- // 64bit x 20input floating gate emulator
- // 1280 total bits input, 64 total bits output
- // copyright 2002 01/26, 2024 03/20 Timothy Robert Keal alias jargon
- public function Gate16
- (
- $a = 0, $b = 0, $c = 0, $d = 0,
- $g0000 = 0,
- $g0001 = 0,
- $g0010 = 0,
- $g0011 = 0,
- $g0100 = 0,
- $g0101 = 0,
- $g0110 = 0,
- $g0111 = 0,
- $g1000 = 0,
- $g1001 = 0,
- $g1010 = 0,
- $g1011 = 0,
- $g1100 = 0,
- $g1101 = 0,
- $g1110 = 0,
- $g1111 = 0
- )
- {
- $tmp = 0;
- $tmp = $tmp | ($g0000 & ~($a | $b | $c | $d));
- $tmp = $tmp | ($g0001 & ~($this->IMP ( $d,($a | $b | $c))));
- $tmp = $tmp | ($g0010 & ~($this->IMP ( $c, ($a | $b | $d))));
- $tmp = $tmp | ($g0011 & ~($this->IMP ( ($c & $d), ($a | $b))));
- $tmp = $tmp | ($g0100 & ~($this->IMP ( $b, ($a | $c | $d))));
- $tmp = $tmp | ($g0101 & ~($this->IMP ( ($b & $d), ($a | $c))));
- $tmp = $tmp | ($g0110 & ~($this->IMP ( ($b & $c), ($a | $d))));
- $tmp = $tmp | ($g0111 & ~($this->IMP ( ($b & $c & $d), $a)));
- $tmp = $tmp | ($g1000 & ~($this->IMP ( $a, ($b | $c | $d))));
- $tmp = $tmp | ($g1001 & ~($this->IMP ( ($a & $d), ($b | $c))));
- $tmp = $tmp | ($g1010 & ~($this->IMP ( ($a & $c), ($b | $d))));
- $tmp = $tmp | ($g1011 & ~($this->IMP ( ($a & $c & $d), $b)));
- $tmp = $tmp | ($g1100 & ~($this->IMP ( ($a & $b), ($c | $d))));
- $tmp = $tmp | ($g1101 & ~($this->IMP ( ($a & $b & $d), $c)));
- $tmp = $tmp | ($g1110 & ~($this->IMP ( ($a & $b & $c), $d)));
- $tmp = $tmp | ($g1111 & ($a & $b & $c & $d));
- return $tmp;
- }
- public function IMP ($q,$p)
- {
- return ~$q | $p;
- }
- // 64bit x 6input floating gate emulator
- // 384 total bits input, 64 total bits output
- // copyright 2002 01/23, 2024 03/20 Timothy Robert Keal alias jargon
- public function Gate4
- (
- $a = 0, $b = 0,
- $g00 = 0,
- $g01 = 0,
- $g10 = 0,
- $g11 = 0
- )
- {
- $a=intval($a);
- $b=intval($b);
- $tmp = 0;
- $tmp = $tmp | ($g00 & ~($a | $b));
- $tmp = $tmp | ($g01 & ~($this->IMP ( $b, $a)));
- $tmp = $tmp | ($g10 & ~($this->IMP ( $a, $b)));
- $tmp = $tmp | ($g11 & ($a & $b));
- return $tmp;
- }
- public function vennGates
- (
- $gate = true,
- $q = 0,
- $p = 0,
- $T = true,
- $F = false
- )
- {
- if(!is_bool($gate))
- {
- if(!is_numeric($gate))
- {
- if(is_string($gate))
- {
- $gate=strtolower($gate);
- if(explode(":",$gate)[0] == "bitwise")
- {
- $float=explode(":",$gate);
- $gate=str_replace("_"," ",$float[0]);
- unset($float[0]);
- $float=explode(",",implode(",",$float));
- $float=array_map('intval', $float);
- }
- }
- }else{
- $gate=intval($gate);
- }
- }else{
- $gate=boolval($gate);
- }
- switch($gate)
- {
- case 0:
- case false:
- case "false":
- case "f":
- return $this->Gate4($q,$p,$F,$F,$F,$F);
- case 1:
- case "q nor p":
- return $this->Gate4($q,$p,$T,$F,$F,$F);
- case 2:
- case "p nimp q":
- case "p not implying q":
- return $this->Gate4($q,$p,$F,$T,$F,$F);
- case 3:
- case "not q":
- return $this->Gate4($q,$p,$T,$T,$F,$F);
- case 4:
- case "q nimp p":
- case "q not implying p":
- return $this->Gate4($q,$p,$F,$F,$T,$F);
- case 5:
- case "not p":
- return $this->Gate4($q,$p,$T,$F,$T,$F);
- case 6:
- case "q neqv p":
- case "q xor p":
- case "q not equivalent p":
- return $this->Gate4($q,$p,$F,$T,$T,$F);
- case 7:
- case "q nand p":
- return $this->Gate4($q,$p,$T,$T,$T,$F);
- case 8:
- case "q and p":
- return $this->Gate4($q,$p,$F,$F,$F,$T);
- case 9:
- case "q eqv p":
- case "q xnor p":
- case "q equivalent p":
- return $this->Gate4($q,$p,$T,$F,$F,$T);
- case 10:
- case "p":
- return $this->Gate4($q,$p,$F,$T,$F,$T);
- case 11:
- case "q imp p":
- case "q implying p":
- return $this->Gate4($q,$p,$T,$T,$F,$T);
- case 12:
- case "p":
- return $this->Gate4($q,$p,$F,$F,$T,$T);
- case 13:
- case "p imp q":
- case "p implying q":
- return $this->Gate4($q,$p,$T,$F,$T,$T);
- case 14:
- case "q or p":
- return $this->Gate4($q,$p,$F,$T,$T,$T);
- case 15:
- case true:
- case "truth":
- case "true":
- case "t":
- return $this->Gate4($q,$p,$T,$T,$T,$T);
- case "bitwise":
- return $this->Gate4($q,$p,$float[0],$float[1],$float[2],$float[3]);
- }
- return $this->bogus;
- }
- public function diceRoll($mnemonic,&$q,&$p)
- {
- global $pretty, $stats;
- $tally=1;
- $Pattern="/([1-9][0-9]*[0-9]*|)d([1-9][0-9]*[0-9]*)/mi";
- if(preg_match_all($Pattern,$mnemonic,$matches,PREG_SET_ORDER)==0){return $this->bogus;}
- $exD=explode("d",$mnemonic);
- if(count($exD)<2)
- {
- return $this->bogus;
- }
- if($exD[0]==""){$exD[0]=1;}
- $q=$exD[0];
- $p=$exD[1];
- $tally=0;
- for($multi=1;$multi<=$exD[0];$multi++)
- {
- $tally+=rand(1,$exD[1]);
- }
- return $tally;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement