logic_tools 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ ~a~b~c~d+~a~bc+~ac~d+b~cd+a~b~c~d+a~bd
2
+ got: ~ac~d+~b~c~d+~bcd+b~cd
3
+ good: ~b~c~d+b~cd+a~bd+~a~bc+~ac~d
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+ #########################################################################
3
+ # Simplifies a logic expression using the Quine Mc-Cluskey algorithm #
4
+ #########################################################################
5
+
6
+
7
+ # For building logic trees
8
+ require "logic_tools/logictree.rb"
9
+
10
+ # For parsing the inputs
11
+ require "logic_tools/logicparse.rb"
12
+
13
+ # For simplifying
14
+ require "logic_tools/logicsimplify.rb"
15
+
16
+ include LogicTools
17
+
18
+
19
+
20
+
21
+
22
+ ############################
23
+ # The main program
24
+
25
+ # First gets the expression to treat
26
+ $expr = nil
27
+ # Is it in the arguments?
28
+ unless $*.empty? then
29
+ # Yes, get the expression from them
30
+ $expr = $*.join
31
+ else
32
+ # Get the expression from standard input
33
+ print "Please enter your expression and end with ^D:\n"
34
+ $expr = ARGF.read
35
+ 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"
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+ ##############################################################
3
+ # Convert a logic expression to its conjunctive normal form #
4
+ ##############################################################
5
+
6
+
7
+ # For building logic tress
8
+ require "logic_tools/logictree.rb"
9
+
10
+ # For parsing the inputs
11
+ require "logic_tools/logicparse.rb"
12
+
13
+ include LogicTools
14
+
15
+
16
+
17
+
18
+
19
+ ############################
20
+ # The main program
21
+
22
+ # First gets the expression to treat
23
+ $expr = nil
24
+ # Is it in the arguments?
25
+ unless $*.empty? then
26
+ # Yes, get the expression from them
27
+ $expr = $*.join
28
+ else
29
+ # Get the expression from standard input
30
+ print "Please enter your expression and end with ^D:\n"
31
+ $expr = ARGF.read
32
+ 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"
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+ ##############################################################
3
+ # Convert a logic expression to its conjunctive normal form #
4
+ ##############################################################
5
+
6
+
7
+ # For building logic tress
8
+ require "logic_tools/logictree.rb"
9
+
10
+ # For parsing the inputs
11
+ require "logic_tools/logicparse.rb"
12
+
13
+ include LogicTools
14
+
15
+
16
+
17
+
18
+
19
+ ############################
20
+ # The main program
21
+
22
+ # First gets the expression to treat
23
+ $expr = nil
24
+ # Is it in the arguments?
25
+ unless $*.empty? then
26
+ # Yes, get the expression from them
27
+ $expr = $*.join
28
+ else
29
+ # Get the expression from standard input
30
+ print "Please enter your expression and end with ^D:\n"
31
+ $expr = ARGF.read
32
+ 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"
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+ ##########################
3
+ # Truth table generator #
4
+ ##########################
5
+
6
+
7
+ # For building logic tress
8
+ require "logic_tools/logictree.rb"
9
+
10
+ # For parsing the inputs
11
+ require "logic_tools/logicparse.rb"
12
+
13
+ include LogicTools
14
+
15
+
16
+
17
+
18
+
19
+ ############################
20
+ # The main program
21
+
22
+ # First gets the expression to treat
23
+ $expr = nil
24
+ # Is it in the arguments?
25
+ unless $*.empty? then
26
+ # Yes, get the expression from them
27
+ $expr = $*.join
28
+ else
29
+ # Get the expression from standard input
30
+ print "Please enter your expression and end with ^D:\n"
31
+ $expr = ARGF.read
32
+ end
33
+
34
+ # Parse the expression
35
+ $parsed = string2logic($expr)
36
+
37
+ # Display the variables
38
+ $vars = $parsed.getVariables
39
+ $vars.each { |var| print "#{var} " }
40
+ print "\n"
41
+
42
+ # Display the values
43
+ $parsed.each_line do |vars,val|
44
+ vars.each { |var| print "#{var.value ? 1 : 0} " }
45
+ print "#{val ? 1: 0}\n"
46
+ end
47
+
@@ -0,0 +1,3 @@
1
+ module LogicTools
2
+ VERSION = "0.2.1"
3
+ end
@@ -0,0 +1,44 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'logic_tools/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "logic_tools"
8
+ spec.version = LogicTools::VERSION
9
+ spec.authors = ["Lovic Gauthier"]
10
+ spec.email = ["lovic@ariake-nct.ac.jp"]
11
+
12
+ spec.summary = %q{A set of tools for processing logic expressions.}
13
+ spec.description = %Q{LogicTools is a set of command-line tools for processing logic expressions.
14
+ The tools include:<p>
15
+ * simplify_qm: for simplifying a logic expression.<p>
16
+ * std_conj: for computing the conjunctive normal form of a logic expression.<p>
17
+ * std_dij: for computing the disjunctive normal form a of logic expression.<p>
18
+ * truth_tbl: for generating the truth table of a logic expression.}
19
+ spec.homepage = "https://github.com/civol"
20
+ spec.license = "MIT"
21
+
22
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
23
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
24
+ # if spec.respond_to?(:metadata)
25
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
26
+ # else
27
+ # raise "RubyGems 2.0 or newer is required to protect against " \
28
+ # "public gem pushes."
29
+ # end
30
+
31
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
32
+ f.match(%r{^(test|spec|features)/})
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_development_dependency "bundler", "~> 1.13"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "minitest", "~> 5.0"
41
+
42
+ # Expressions are parsed using parslet
43
+ spec.add_dependency "parslet"
44
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logic_tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Lovic Gauthier
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: parslet
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: |-
70
+ LogicTools is a set of command-line tools for processing logic expressions.
71
+ The tools include:<p>
72
+ * simplify_qm: for simplifying a logic expression.<p>
73
+ * std_conj: for computing the conjunctive normal form of a logic expression.<p>
74
+ * std_dij: for computing the disjunctive normal form a of logic expression.<p>
75
+ * truth_tbl: for generating the truth table of a logic expression.
76
+ email:
77
+ - lovic@ariake-nct.ac.jp
78
+ executables:
79
+ - simplify_qm
80
+ - std_conj
81
+ - std_dij
82
+ - truth_tbl
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - ".gitignore"
87
+ - ".travis.yml"
88
+ - Gemfile
89
+ - LICENSE.txt
90
+ - README.md
91
+ - Rakefile
92
+ - bin/console
93
+ - bin/setup
94
+ - exe/simplify_qm
95
+ - exe/std_conj
96
+ - exe/std_dij
97
+ - exe/truth_tbl
98
+ - lib/logic_tools.rb
99
+ - lib/logic_tools/logicparse.rb
100
+ - lib/logic_tools/logicsimplify.rb
101
+ - lib/logic_tools/logictree.rb
102
+ - lib/logic_tools/simplify_bug.txt
103
+ - lib/logic_tools/simplify_qm.rb
104
+ - lib/logic_tools/std_conj.rb
105
+ - lib/logic_tools/std_dij.rb
106
+ - lib/logic_tools/truth_tbl.rb
107
+ - lib/logic_tools/version.rb
108
+ - logic_tools.gemspec
109
+ homepage: https://github.com/civol
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.6.8
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: A set of tools for processing logic expressions.
133
+ test_files: []