logic_tools 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +37 -30
- data/lib/logic_tools.rb +8 -1
- data/lib/logic_tools/logicinput.rb +43 -0
- data/lib/logic_tools/logicparse.rb +13 -14
- data/lib/logic_tools/logicsimplify.rb +93 -85
- data/lib/logic_tools/logictree.rb +327 -324
- data/lib/logic_tools/simplify_bug.txt +16 -5
- data/lib/logic_tools/simplify_qm.rb +31 -21
- data/lib/logic_tools/std_conj.rb +40 -21
- data/lib/logic_tools/std_dij.rb +40 -21
- data/lib/logic_tools/truth_tbl.rb +43 -22
- data/lib/logic_tools/version.rb +1 -1
- metadata +3 -2
@@ -1,6 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
= Known bugs
|
2
|
+
---
|
3
|
+
=== Bug 1
|
4
|
+
$ simplify_qm "~a~b~c~d+~a~bc+~ac~d+b~cd+a~b~c~d+a~bd"
|
5
|
+
|
6
|
+
-> got: ~ac~d+~b~c~d+~bcd+b~cd
|
7
|
+
expecting: ~ac~d+a~bd+~b~c~d+~bcd+b~cd
|
8
|
+
|
9
|
+
*FIXED*
|
6
10
|
|
11
|
+
---
|
12
|
+
=== Bug 2
|
13
|
+
$ simplify_qm "~~~a"
|
14
|
+
|
15
|
+
-> Crashes
|
16
|
+
|
17
|
+
*FIXED*
|
@@ -13,6 +13,12 @@ require "logic_tools/logicparse.rb"
|
|
13
13
|
# For simplifying
|
14
14
|
require "logic_tools/logicsimplify.rb"
|
15
15
|
|
16
|
+
# For the command line interface
|
17
|
+
require "logic_tools/logicinput.rb"
|
18
|
+
|
19
|
+
# For the command line interface
|
20
|
+
require "logic_tools/logicinput.rb"
|
21
|
+
|
16
22
|
include LogicTools
|
17
23
|
|
18
24
|
|
@@ -22,25 +28,29 @@ include LogicTools
|
|
22
28
|
############################
|
23
29
|
# The main program
|
24
30
|
|
25
|
-
|
26
|
-
|
27
|
-
#
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
## Now use the common command line interface
|
32
|
+
# # First gets the expression to treat
|
33
|
+
# $expr = nil
|
34
|
+
# # Is it in the arguments?
|
35
|
+
# unless $*.empty? then
|
36
|
+
# # Yes, get the expression from them
|
37
|
+
# $expr = $*.join
|
38
|
+
# else
|
39
|
+
# # Get the expression from standard input
|
40
|
+
# print "Please enter your expression and end with ^D:\n"
|
41
|
+
# $expr = ARGF.read
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
|
45
|
+
# Iterrate on each expression
|
46
|
+
each_input do |expr|
|
47
|
+
# Parse the expression
|
48
|
+
parsed = string2logic(expr)
|
49
|
+
|
50
|
+
# Simplify it
|
51
|
+
simple = parsed.simplify
|
52
|
+
# print "Computation done\n"
|
53
|
+
|
54
|
+
# Display the result
|
55
|
+
print simple.to_s, "\n"
|
35
56
|
end
|
36
|
-
|
37
|
-
# Parse the expression
|
38
|
-
$parsed = string2logic($expr)
|
39
|
-
|
40
|
-
# Simplify it
|
41
|
-
$simple = $parsed.simplify
|
42
|
-
|
43
|
-
# print "Computation done\n"
|
44
|
-
|
45
|
-
# Display the result
|
46
|
-
print $simple.to_s, "\n"
|
data/lib/logic_tools/std_conj.rb
CHANGED
@@ -10,6 +10,9 @@ require "logic_tools/logictree.rb"
|
|
10
10
|
# For parsing the inputs
|
11
11
|
require "logic_tools/logicparse.rb"
|
12
12
|
|
13
|
+
# For the command line interface
|
14
|
+
require "logic_tools/logicinput.rb"
|
15
|
+
|
13
16
|
include LogicTools
|
14
17
|
|
15
18
|
|
@@ -19,25 +22,41 @@ include LogicTools
|
|
19
22
|
############################
|
20
23
|
# The main program
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
## Now use the common command line interface
|
26
|
+
# # First gets the expression to treat
|
27
|
+
# $expr = nil
|
28
|
+
# # Is it in the arguments?
|
29
|
+
# unless $*.empty? then
|
30
|
+
# # Yes, get the expression from them
|
31
|
+
# $expr = $*.join
|
32
|
+
# else
|
33
|
+
# # Get the expression from standard input
|
34
|
+
# print "Please enter your expression and end with ^D:\n"
|
35
|
+
# $expr = ARGF.read
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# # Parse the expression
|
39
|
+
# $parsed = string2logic($expr)
|
40
|
+
#
|
41
|
+
# # Generates its conjunctive normal form
|
42
|
+
# $conj = $parsed.to_std_conjunctive
|
43
|
+
#
|
44
|
+
# # print "Computation done\n"
|
45
|
+
#
|
46
|
+
# # Display the result
|
47
|
+
# print $conj.to_s, "\n"
|
48
|
+
|
49
|
+
|
50
|
+
# Iterrate on each expression
|
51
|
+
each_input do |expr|
|
52
|
+
# Parse the expression
|
53
|
+
parsed = string2logic(expr)
|
54
|
+
|
55
|
+
# Generates its conjunctive normal form
|
56
|
+
conj = parsed.to_std_conjunctive
|
57
|
+
|
58
|
+
# print "Computation done\n"
|
59
|
+
|
60
|
+
# Display the result
|
61
|
+
print conj.to_s, "\n"
|
32
62
|
end
|
33
|
-
|
34
|
-
# Parse the expression
|
35
|
-
$parsed = string2logic($expr)
|
36
|
-
|
37
|
-
# Generates its conjunctive normal form
|
38
|
-
$conj = $parsed.to_std_conjunctive
|
39
|
-
|
40
|
-
# print "Computation done\n"
|
41
|
-
|
42
|
-
# Display the result
|
43
|
-
print $conj.to_s, "\n"
|
data/lib/logic_tools/std_dij.rb
CHANGED
@@ -10,6 +10,9 @@ require "logic_tools/logictree.rb"
|
|
10
10
|
# For parsing the inputs
|
11
11
|
require "logic_tools/logicparse.rb"
|
12
12
|
|
13
|
+
# For the command line interface
|
14
|
+
require "logic_tools/logicinput.rb"
|
15
|
+
|
13
16
|
include LogicTools
|
14
17
|
|
15
18
|
|
@@ -19,25 +22,41 @@ include LogicTools
|
|
19
22
|
############################
|
20
23
|
# The main program
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
## Now use the common command line interface
|
26
|
+
# # First gets the expression to treat
|
27
|
+
# $expr = nil
|
28
|
+
# # Is it in the arguments?
|
29
|
+
# unless $*.empty? then
|
30
|
+
# # Yes, get the expression from them
|
31
|
+
# $expr = $*.join
|
32
|
+
# else
|
33
|
+
# # Get the expression from standard input
|
34
|
+
# print "Please enter your expression and end with ^D:\n"
|
35
|
+
# $expr = ARGF.read
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# # Parse the expression
|
39
|
+
# $parsed = string2logic($expr)
|
40
|
+
#
|
41
|
+
# # Generates its disjunctive normal form
|
42
|
+
# $dij = $parsed.to_std_disjunctive
|
43
|
+
#
|
44
|
+
# # print "Computation done\n"
|
45
|
+
#
|
46
|
+
# # Display the result
|
47
|
+
# print $dij.to_s, "\n"
|
48
|
+
|
49
|
+
|
50
|
+
# Iterrate on each expression
|
51
|
+
each_input do |expr|
|
52
|
+
# Parse the expression
|
53
|
+
parsed = string2logic(expr)
|
54
|
+
|
55
|
+
# Generates its disjunctive normal form
|
56
|
+
dij = parsed.to_std_disjunctive
|
57
|
+
|
58
|
+
# print "Computation done\n"
|
59
|
+
|
60
|
+
# Display the result
|
61
|
+
print dij.to_s, "\n"
|
32
62
|
end
|
33
|
-
|
34
|
-
# Parse the expression
|
35
|
-
$parsed = string2logic($expr)
|
36
|
-
|
37
|
-
# Generates its disjonctive normal form
|
38
|
-
$dij = $parsed.to_std_disjonctive
|
39
|
-
|
40
|
-
# print "Computation done\n"
|
41
|
-
|
42
|
-
# Display the result
|
43
|
-
print $dij.to_s, "\n"
|
@@ -10,6 +10,9 @@ require "logic_tools/logictree.rb"
|
|
10
10
|
# For parsing the inputs
|
11
11
|
require "logic_tools/logicparse.rb"
|
12
12
|
|
13
|
+
# For the command line interface
|
14
|
+
require "logic_tools/logicinput.rb"
|
15
|
+
|
13
16
|
include LogicTools
|
14
17
|
|
15
18
|
|
@@ -19,29 +22,47 @@ include LogicTools
|
|
19
22
|
############################
|
20
23
|
# The main program
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
25
|
+
## Now use the common command line interface
|
26
|
+
# # First gets the expression to treat
|
27
|
+
# $expr = nil
|
28
|
+
# # Is it in the arguments?
|
29
|
+
# unless $*.empty? then
|
30
|
+
# # Yes, get the expression from them
|
31
|
+
# $expr = $*.join
|
32
|
+
# else
|
33
|
+
# # Get the expression from standard input
|
34
|
+
# print "Please enter your expression and end with ^D:\n"
|
35
|
+
# $expr = ARGF.read
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# # Parse the expression
|
39
|
+
# $parsed = string2logic($expr)
|
40
|
+
#
|
41
|
+
# # Display the variables
|
42
|
+
# $vars = $parsed.getVariables
|
43
|
+
# $vars.each { |var| print "#{var} " }
|
44
|
+
# print "\n"
|
45
|
+
#
|
46
|
+
# # Display the values
|
47
|
+
# $parsed.each_line do |vars,val|
|
48
|
+
# vars.each { |var| print "#{var.value ? 1 : 0} " }
|
49
|
+
# print "#{val ? 1: 0}\n"
|
50
|
+
# end
|
33
51
|
|
34
|
-
#
|
35
|
-
|
52
|
+
# Iterrate on each expression
|
53
|
+
each_input do |expr|
|
54
|
+
# Parse the expression
|
55
|
+
parsed = string2logic(expr)
|
36
56
|
|
37
|
-
# Display the variables
|
38
|
-
|
39
|
-
|
40
|
-
print "\n"
|
57
|
+
# Display the variables
|
58
|
+
vars = parsed.getVariables
|
59
|
+
vars.each { |var| print "#{var} " }
|
60
|
+
print "\n"
|
41
61
|
|
42
|
-
# Display the values
|
43
|
-
|
44
|
-
|
45
|
-
|
62
|
+
# Display the values
|
63
|
+
parsed.each_line do |vars,val|
|
64
|
+
vars.each { |var| print "#{var.value ? 1 : 0} " }
|
65
|
+
print "#{val ? 1: 0}\n"
|
66
|
+
end
|
67
|
+
print "\n"
|
46
68
|
end
|
47
|
-
|
data/lib/logic_tools/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logic_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lovic Gauthier
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- exe/std_dij
|
97
97
|
- exe/truth_tbl
|
98
98
|
- lib/logic_tools.rb
|
99
|
+
- lib/logic_tools/logicinput.rb
|
99
100
|
- lib/logic_tools/logicparse.rb
|
100
101
|
- lib/logic_tools/logicsimplify.rb
|
101
102
|
- lib/logic_tools/logictree.rb
|