prop_logic 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e6c98eb22a2749c09f37c1e6d696a8fd579b841
4
- data.tar.gz: 9899d1f4ca58451e53382c9087cddb41dc10cbbe
3
+ metadata.gz: 77ccbf85c3d54fc4d5bcd5032353a28e74e6d612
4
+ data.tar.gz: dccfb3cf95f54aeeeb6a1cfd649d107177ea47da
5
5
  SHA512:
6
- metadata.gz: 3b7a05895cf515208b136022a18464b176ce25ca246f4f783b6af01da4c56a92c859b94d8039f2d2a78167d2260639f682f0782235b2cb21ad5aeb97de638b40
7
- data.tar.gz: 6b63a27d59cd559090f9d119819bbbdabcf1b49a21004974fdc31c53990d9f6bd88eebe30c05320417353f4d3a06cd2f98258efbceb356c156cf0842bbdb28ce
6
+ metadata.gz: 3e6ea89510d51a1ffe984a38304194d6137c0b31bf47b9b798cfca56dce12d5e9a697a70e2475470d0608380fedd4aa31833f117fc0ab155f4747ed5dc558dd6
7
+ data.tar.gz: ae70b208a30819b3302e1deb9559ee31b5c9266ad4ad8640ae20d4a214b8d3a92a96b43a8e6a45d4226866edc36e8aa74e70954151935bcaa5df01cac7b7b3c2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # Ver. 0.1.2 (2016/03/07)
2
+ - Cache @variables (avoid recursive search)
3
+
1
4
  # Ver. 0.1.1 (2016/01/28)
2
5
  - `PropLogic.all_and`/`PropLogic.all_or` with less than one argument(s) behaviors fixed
3
6
  - And/or terms with duplicated subterms are no longer regarded as reduced
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # PropLogic
2
2
 
3
3
  [![Build Status](https://travis-ci.org/jkr2255/prop_logic.svg?branch=master)](https://travis-ci.org/jkr2255/prop_logic)
4
+ [![Gem Version](https://badge.fury.io/rb/prop_logic.svg)](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
@@ -67,8 +67,8 @@ module PropLogic
67
67
  return super unless reduced?
68
68
  return self if cnf?
69
69
  pool = []
70
- without_pools = PropLogic.all_and(*@terms.map{|t| t.tseitin(pool)})
71
- PropLogic.all_and(without_pools, *pool)
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)
@@ -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|
@@ -22,9 +22,9 @@ module PropLogic
22
22
  when ThenTerm
23
23
  (~(term.to_nnf)).to_nnf
24
24
  when AndTerm
25
- PropLogic.all_or(*term.terms.map{|t| (~t).to_nnf})
25
+ all_or(*term.terms.map{|t| (~t).to_nnf})
26
26
  when OrTerm
27
- PropLogic.all_and(*term.terms.map{|t| (~t).to_nnf})
27
+ all_and(*term.terms.map{|t| (~t).to_nnf})
28
28
  end
29
29
  end
30
30
 
@@ -66,13 +66,13 @@ module PropLogic
66
66
  return self if cnf?
67
67
  pool = []
68
68
  without_pools = tseitin(pool)
69
- PropLogic.all_and(without_pools, *pool)
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 | PropLogic.all_or(*terms))
75
+ pool << (~val | all_or(*terms))
76
76
  val
77
77
  end
78
78
 
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module PropLogic
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.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-01-28 00:00:00.000000000 Z
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.5.1
119
+ rubygems_version: 2.4.7
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: Propositional logic for Ruby