logic_tools 0.3.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/logic_tools/logictree.rb +17 -3
- data/lib/logic_tools/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 050637aebd4a23cf2fad66977655693b4bfec213
|
4
|
+
data.tar.gz: 633b3b494230e852f4bb4f5b41bf6cfc445de661
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a61b43345ddf05b11fbf9dd01a19bd4c8570e8d609e4a5d4da58a2bd786eb19c2ec028489cdaed9b4801f76681bb97e18c321d39e52dfd91463801324e9659d6
|
7
|
+
data.tar.gz: 017c29e9181dc2421f4260a5852d515de011088a9e495e55f21c6d511246435460ee54ef1079a89350b1d654120e9f00fa5e3656046ba4c6f92b0421a389bcf1
|
data/README.md
CHANGED
@@ -4,9 +4,12 @@ LogicTools is a set of command-line tools for processing logic expressions.
|
|
4
4
|
The tools include:
|
5
5
|
|
6
6
|
* __simplify\_qm__: for simplifying a logic expression.
|
7
|
+
* __simplify\_es__: for simplifying a logic expression (much more efficient than simplify_qm).
|
7
8
|
* __std\_conj__: for computing the conjunctive normal form of a logic expression.
|
8
9
|
* __std\_dij__: for computing the disjunctive normal form a of logic expression.
|
9
10
|
* __truth\_tbl__: for generating the truth table of a logic expression.
|
11
|
+
* __is\_tautolofy__: for checking if a logic expression is a tautology or not.
|
12
|
+
* __complement__: for computing the complement of a logic expression.
|
10
13
|
|
11
14
|
|
12
15
|
## Installation
|
@@ -37,7 +40,7 @@ Multiple expressions stored into a file can also be processed as follows:
|
|
37
40
|
|
38
41
|
The logical expression is an expression where:
|
39
42
|
|
40
|
-
* a logical variable is represented by a single alphabetical character (hence there is in total 56 possible variables)
|
43
|
+
* a logical variable is represented by a single alphabetical character (hence there is in total 56 possible variables), or a string of alphabetical characters enclosed by curly brackets.
|
41
44
|
* a logical OR is represented by a '+' character;
|
42
45
|
* a logical AND is represented by a '.' character (but it can be omitted);
|
43
46
|
* a logical NOT is represented by a '~' or a '!' character;
|
@@ -54,6 +57,7 @@ For instance the followings are valid logical expression using the a,b and c var
|
|
54
57
|
"a.b.c"
|
55
58
|
"a+b+!c"
|
56
59
|
"a~(b+~c)"
|
60
|
+
"{foo}+{bar}"
|
57
61
|
|
58
62
|
Finally, here are a few examples of LogicTool usage:
|
59
63
|
|
@@ -614,6 +614,7 @@ module LogicTools
|
|
614
614
|
# --
|
615
615
|
# TODO consider the X~X and X+~X cases.
|
616
616
|
def reduce
|
617
|
+
# print "reducing #{self}\n"
|
617
618
|
# The operator used for the factors
|
618
619
|
fop = @op == :and ? :or : :and
|
619
620
|
# Gather the terms to sorted nodes
|
@@ -626,7 +627,8 @@ module LogicTools
|
|
626
627
|
terms.each_with_index do |term0,i|
|
627
628
|
skipped = false
|
628
629
|
terms.each_with_index do |term1,j|
|
629
|
-
next if (
|
630
|
+
next if (term0 == term1) # Same term, duplicates will be
|
631
|
+
# removed after
|
630
632
|
# Checks the X~X or X+~X cases.
|
631
633
|
if ( term0.op == :not and term0.child == term1 ) or
|
632
634
|
( term1.op == :not and term1.child == term0 ) then
|
@@ -640,8 +642,14 @@ module LogicTools
|
|
640
642
|
# skipped = true
|
641
643
|
# break
|
642
644
|
# end
|
643
|
-
if term1.cover?(term0) then
|
644
|
-
# term1
|
645
|
+
if term0.op == :and and term1.cover?(term0) then
|
646
|
+
# print "#{term1} is covering #{term0}\n"
|
647
|
+
# term1 covers term0 skip term0 for AND.
|
648
|
+
skipped = true
|
649
|
+
# break
|
650
|
+
elsif term0.op == :or and term0.cover?(term1) then
|
651
|
+
# print "#{term0} is covering #{term1}\n"
|
652
|
+
# term0 covers term1 skip term0 for OR.
|
645
653
|
skipped = true
|
646
654
|
# break
|
647
655
|
end
|
@@ -650,6 +658,7 @@ module LogicTools
|
|
650
658
|
end
|
651
659
|
# Avoid duplicates
|
652
660
|
nchildren.uniq!
|
661
|
+
# print "reduced nchildren=#{nchildren}\n"
|
653
662
|
# Generate the result
|
654
663
|
if (nchildren.size == 1)
|
655
664
|
return nchildren[0]
|
@@ -687,6 +696,7 @@ module LogicTools
|
|
687
696
|
## Creates a new tree where the current node is distributed over +node+
|
688
697
|
# according to the +dop+ operator.
|
689
698
|
def distribute(dop,node) # :nodoc:
|
699
|
+
# print "distrubte with self=#{self} and node=#{node}\n"
|
690
700
|
fop = dop == :and ? :or : :and
|
691
701
|
# print "dop=#{dop} fop=#{fop} self.op=#{@op}\n"
|
692
702
|
if (@op == dop) then
|
@@ -695,6 +705,7 @@ module LogicTools
|
|
695
705
|
else
|
696
706
|
# self operator if fop
|
697
707
|
if (node.op == fop) then
|
708
|
+
# print "(a+b)(c+d) case\n"
|
698
709
|
# node operator is also fop: (a+b)(c+d) or ab+cd case
|
699
710
|
nchildren = []
|
700
711
|
self.each do |child0|
|
@@ -707,10 +718,12 @@ module LogicTools
|
|
707
718
|
end
|
708
719
|
return NodeNary.make(fop,*nchildren).flatten
|
709
720
|
else
|
721
|
+
# print "(a+b)c case\n"
|
710
722
|
# node operator is not fop: (a+b)c or ab+c case
|
711
723
|
nchildren = self.map do |child|
|
712
724
|
NodeNary.make(dop,child,node).flatten
|
713
725
|
end
|
726
|
+
# print "nchildren=#{nchildren}\n"
|
714
727
|
return NodeNary.make(fop,*nchildren).flatten
|
715
728
|
end
|
716
729
|
end
|
@@ -748,6 +761,7 @@ module LogicTools
|
|
748
761
|
nchildren = node.map {|child| child.to_sum_product(true) }
|
749
762
|
# Distribute
|
750
763
|
while(nchildren.size>1)
|
764
|
+
# print "nchildren=#{nchildren}\n"
|
751
765
|
dist = []
|
752
766
|
nchildren.each_slice(2) do |left,right|
|
753
767
|
if right then
|
data/lib/logic_tools/version.rb
CHANGED