prop_logic 0.1.1 → 0.1.2
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/CHANGELOG.md +3 -0
- data/README.md +4 -1
- data/lib/prop_logic/and_term.rb +2 -2
- data/lib/prop_logic/functions.rb +3 -0
- data/lib/prop_logic/not_term.rb +2 -2
- data/lib/prop_logic/or_term.rb +2 -2
- data/lib/prop_logic/term.rb +6 -1
- data/lib/prop_logic/version.rb +1 -1
- data/lib/prop_logic.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77ccbf85c3d54fc4d5bcd5032353a28e74e6d612
|
4
|
+
data.tar.gz: dccfb3cf95f54aeeeb6a1cfd649d107177ea47da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e6ea89510d51a1ffe984a38304194d6137c0b31bf47b9b798cfca56dce12d5e9a697a70e2475470d0608380fedd4aa31833f117fc0ab155f4747ed5dc558dd6
|
7
|
+
data.tar.gz: ae70b208a30819b3302e1deb9559ee31b5c9266ad4ad8640ae20d4a214b8d3a92a96b43a8e6a45d4226866edc36e8aa74e70954151935bcaa5df01cac7b7b3c2
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# PropLogic
|
2
2
|
|
3
3
|
[](https://travis-ci.org/jkr2255/prop_logic)
|
4
|
+
[](https://badge.fury.io/rb/prop_logic)
|
4
5
|
|
5
6
|
PropLogic implements propositional logic in Ruby, usable like normal variables.
|
6
7
|
|
@@ -57,6 +58,9 @@ diff = (~a | ~b).equiv?(~(a & b)) # true
|
|
57
58
|
SAT solver bundled with this gem is brute-force solver (intended only for testing), so it is inappropriate to use for
|
58
59
|
real-scale problems.
|
59
60
|
|
61
|
+
In CRuby and Rubinius, bindings to MiniSat ([jkr2255/prop_logic-minisat](https://github.com/jkr2255/prop_logic-minisat)) is available.
|
62
|
+
It is a plugin for this gem, so no code (except require and Gemfile) needs to be changed to use `prop_logic-minisat`.
|
63
|
+
|
60
64
|
## References
|
61
65
|
`PropLogic::Term` is immutable, meaning that all calculations return new Terms.
|
62
66
|
### `PropLogic::Term` instance methods
|
@@ -141,4 +145,3 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
141
145
|
## ToDo
|
142
146
|
|
143
147
|
- Introduce special blocks to build terms inside
|
144
|
-
- Add nontrivial SAT solver for practical usage
|
data/lib/prop_logic/and_term.rb
CHANGED
@@ -67,8 +67,8 @@ module PropLogic
|
|
67
67
|
return super unless reduced?
|
68
68
|
return self if cnf?
|
69
69
|
pool = []
|
70
|
-
without_pools =
|
71
|
-
|
70
|
+
without_pools = all_and(*@terms.map{|t| t.tseitin(pool)})
|
71
|
+
all_and(without_pools, *pool)
|
72
72
|
end
|
73
73
|
|
74
74
|
def tseitin(pool)
|
data/lib/prop_logic/functions.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module PropLogic
|
2
2
|
module Functions
|
3
|
+
module_function
|
3
4
|
def all_or(*args)
|
4
5
|
Term.get OrTerm, *args
|
5
6
|
end
|
@@ -14,6 +15,8 @@ module PropLogic
|
|
14
15
|
end
|
15
16
|
|
16
17
|
extend Functions
|
18
|
+
include Functions
|
19
|
+
public_class_method(*Functions.private_instance_methods(false))
|
17
20
|
|
18
21
|
def all_combination(arr)
|
19
22
|
0.upto(arr.length) do |num|
|
data/lib/prop_logic/not_term.rb
CHANGED
@@ -22,9 +22,9 @@ module PropLogic
|
|
22
22
|
when ThenTerm
|
23
23
|
(~(term.to_nnf)).to_nnf
|
24
24
|
when AndTerm
|
25
|
-
|
25
|
+
all_or(*term.terms.map{|t| (~t).to_nnf})
|
26
26
|
when OrTerm
|
27
|
-
|
27
|
+
all_and(*term.terms.map{|t| (~t).to_nnf})
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
data/lib/prop_logic/or_term.rb
CHANGED
@@ -66,13 +66,13 @@ module PropLogic
|
|
66
66
|
return self if cnf?
|
67
67
|
pool = []
|
68
68
|
without_pools = tseitin(pool)
|
69
|
-
|
69
|
+
all_and(without_pools, *pool)
|
70
70
|
end
|
71
71
|
|
72
72
|
def tseitin(pool)
|
73
73
|
val = Variable.new
|
74
74
|
terms = @terms.map{|t| t.tseitin(pool)}
|
75
|
-
pool << (~val |
|
75
|
+
pool << (~val | all_or(*terms))
|
76
76
|
val
|
77
77
|
end
|
78
78
|
|
data/lib/prop_logic/term.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'ref'
|
2
|
+
require 'prop_logic/functions'
|
2
3
|
|
3
4
|
module PropLogic
|
4
5
|
class Term
|
6
|
+
include Functions
|
7
|
+
|
5
8
|
def initialize
|
6
9
|
raise NotImplementedError, 'Term cannot be initialized'
|
7
10
|
end
|
@@ -104,6 +107,8 @@ module PropLogic
|
|
104
107
|
return @table[key] if @table[key]
|
105
108
|
ret = klass.__send__ :new, *terms
|
106
109
|
@table[key] = ret
|
110
|
+
# kick caching mechanism
|
111
|
+
ret.variables
|
107
112
|
ret.freeze
|
108
113
|
end
|
109
114
|
|
@@ -112,7 +117,7 @@ module PropLogic
|
|
112
117
|
end
|
113
118
|
|
114
119
|
def variables
|
115
|
-
@terms.map(&:variables).flatten.uniq
|
120
|
+
@variables ||= @terms.map(&:variables).flatten.uniq
|
116
121
|
end
|
117
122
|
|
118
123
|
def assign(trues, falses, variables = nil)
|
data/lib/prop_logic/version.rb
CHANGED
data/lib/prop_logic.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require "prop_logic/version"
|
2
2
|
require "prop_logic/term"
|
3
|
+
require 'prop_logic/functions'
|
3
4
|
require "prop_logic/and_term"
|
4
5
|
require "prop_logic/or_term"
|
5
6
|
require "prop_logic/not_term"
|
6
7
|
require "prop_logic/then_term"
|
7
8
|
require 'prop_logic/variable'
|
8
9
|
require 'prop_logic/constants'
|
9
|
-
require 'prop_logic/functions'
|
10
10
|
require 'prop_logic/brute_force_sat_solver'
|
11
11
|
require 'prop_logic/sat_solver'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prop_logic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jkr2255
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ref
|
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
116
|
version: '0'
|
117
117
|
requirements: []
|
118
118
|
rubyforge_project:
|
119
|
-
rubygems_version: 2.4.
|
119
|
+
rubygems_version: 2.4.7
|
120
120
|
signing_key:
|
121
121
|
specification_version: 4
|
122
122
|
summary: Propositional logic for Ruby
|