Math::Logic

Math::Logic is a Perl module that provides pure 2, 3 or multi-value logic.
Download

Math::Logic Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Mark Summerfield
  • Publisher web site:
  • http://search.cpan.org/~summer/

Math::Logic Tags


Math::Logic Description

Math::Logic is a Perl module that provides pure 2, 3 or multi-value logic. Math::Logic is a Perl module that provides pure 2, 3 or multi-value logic.SYNOPSIS use Math::Logic qw( $TRUE $FALSE $UNDEF $STR_TRUE $STR_FALSE $STR_UNDEF ) ; # 1 0 -1 'TRUE' 'FALSE' 'UNDEF' use Math::Logic ':NUM' ; # $TRUE $FALSE $UNDEF -- what you normally want use Math::Logic ':ALL' ; # All the constants use Math::Logic ':STR' ; # $STR_TRUE $STR_FALSE $STR_UNDEF # 2-degree logic my $true = Math::Logic->new( -value => $TRUE, -degree => 2 ) ; my $false = Math::Logic->new( -value => $FALSE, -degree => 2 ) ; my $x = Math::Logic->new_from_string( 'TRUE,2' ) ; print "true" if $true ; # 3-degree logic (non-propagating) my $true = Math::Logic->new( -value => $TRUE, -degree => 3 ) ; my $false = Math::Logic->new( -value => $FALSE, -degree => 3 ) ; my $undef = Math::Logic->new( -value => $UNDEF, -degree => 3 ) ; my $x = Math::Logic->new_from_string( 'FALSE,3' ) ; print "true" if ( $true | $undef ) == $TRUE ; # 3-degree logic (propagating) my $true = Math::Logic->new( -value => $TRUE, -degree => 3, -propagate => 1 ) ; my $false = Math::Logic->new( -value => $FALSE, -degree => 3, -propagate => 1 ) ; my $undef = Math::Logic->new( -value => $UNDEF, -degree => 3, -propagate => 1 ) ; my $x = Math::Logic->new_from_string( '( UNDEF, 3, -propagate )' ) ; print "undef" if ( $true | $undef ) == $UNDEF ; # multi-degree logic my $True = 100 ; # Define our own true my $False = $FALSE ; my $true = Math::Logic->new( -value => $True, -degree => $True ) ; my $very = Math::Logic->new( -value => 67, -degree => $True ) ; my $fairly = Math::Logic->new( -value => 33, -degree => $True ) ; my $false = Math::Logic->new( -value => $False, -degree => $True ) ; my $x = Math::Logic->new_from_string( "25,$True" ) ; print "maybe" if ( $very | $fairly ) > 50 ; # We can have arbitrarily complex expressions; the result is a Math::Logic # object; all arguments must be Math::Logic objects or things which can be # promoted into such and must all be compatible. The outcome depends on # which kind of logic is being used. my $xor = ( $x | $y ) & ( ! ( $x & $y ) ) ; # This is identical to: my $xor = $x ^ $y ;Perl's built-in logical operators, and, or, xor and not support 2-value logic. This means that they always produce a result which is either true or false. In fact perl sometimes returns 0 and sometimes returns undef for false depending on the operator and the order of the arguments. For "true" Perl generally returns the first value that evaluated to true which turns out to be extremely useful in practice. Given the choice Perl's built-in logical operators are to be preferred -- but when you really want pure 2-degree logic or 3-degree logic or multi-degree logic they are available through this module.The only 2-degree logic values are 1 (TRUE) and 0 (FALSE).The only 3-degree logic values are 1 (TRUE), 0 (FALSE) and -1 (UNDEF). Note that UNDEF is -1 not undef!The only multi-degree logic values are 0 (FALSE)..-degree -- the value of TRUE is equal to the degree, usually 100.The -degree is the maximum value (except for 2 and 3-degree logic); i.e. logic of n-degree is n+1-value logic, e.g. 100-degree logic has 101 values, 0..100.Although some useful constants may be exported, this is an object module and the results of logical comparisons are Math::Logic objects.Requirements:· Perl Requirements: · Perl


Math::Logic Related Software