prop_logic 0.1.0 → 0.1.1

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: 37cd959dffbbeeb64bde6b241794bec73c4415a6
4
- data.tar.gz: 3a836ab88dd8e721b0e10ed4f1d0d7ffdb93fdd1
3
+ metadata.gz: 5e6c98eb22a2749c09f37c1e6d696a8fd579b841
4
+ data.tar.gz: 9899d1f4ca58451e53382c9087cddb41dc10cbbe
5
5
  SHA512:
6
- metadata.gz: 50f268b87efd5333fcbffbe2e72a48e13e87c25ed79e12d570f37043e692dae4d5eb02d9e7291e1262ee26e18509e0274dc018a801fb4d62ad60b4f2c214e37f
7
- data.tar.gz: 1c74a4734264ed6395a0eba5806e03902c138b65f2ddc45551f01e9fd2ad36aa2f6e1ead12006749e4af542c064c015339f40853cf8ac6eefae0b4d46b40660f
6
+ metadata.gz: 3b7a05895cf515208b136022a18464b176ce25ca246f4f783b6af01da4c56a92c859b94d8039f2d2a78167d2260639f682f0782235b2cb21ad5aeb97de638b40
7
+ data.tar.gz: 6b63a27d59cd559090f9d119819bbbdabcf1b49a21004974fdc31c53990d9f6bd88eebe30c05320417353f4d3a06cd2f98258efbceb356c156cf0842bbdb28ce
data/.travis.yml CHANGED
@@ -6,4 +6,7 @@ rvm:
6
6
  - 2.0.0
7
7
  - rbx-3.9
8
8
  - jruby-9.0.1.0
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: rbx-3.9
9
12
 
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Ver. 0.1.1 (2016/01/28)
2
+ - `PropLogic.all_and`/`PropLogic.all_or` with less than one argument(s) behaviors fixed
3
+ - And/or terms with duplicated subterms are no longer regarded as reduced
4
+
5
+ # Ver. 0.1.0 (2016/01/27)
6
+ Initial version
data/README.md CHANGED
@@ -84,7 +84,11 @@ NNF doesn't contain following terms:
84
84
  `#nnf?` checks if the term is NNF, and `#to_nnf` returns term converted to NNF.
85
85
 
86
86
  #### Reduction
87
- Term is regarded as reduced if it is NNF and it contains no constants (`PropLogic::True`/`PropLogic::False`).
87
+ Term is regarded as reduced if:
88
+ 0. it is NNF
89
+ 0. it contains no constants (`PropLogic::True`/`PropLogic::False`)
90
+ 0. it contains no ambivalent terms
91
+ 0. it contains no duplicated terms
88
92
 
89
93
  `#reduced?` checks if the term is reduced, and `#reduce` returns reduced term.
90
94
 
@@ -15,6 +15,11 @@ module PropLogic
15
15
  end
16
16
  end
17
17
  return unless @is_reduced
18
+ # check duplication of terms
19
+ if @terms.any?{ |term| @terms.index(term) != @terms.rindex(term)}
20
+ @is_reduced = false
21
+ return
22
+ end
18
23
  # check contradicted variables (mark as unreduced)
19
24
  # Negated terms (except variables) doesn't come here
20
25
  not_terms = @terms.select{ |t| t.is_a?(NotTerm) }
@@ -37,7 +42,7 @@ module PropLogic
37
42
 
38
43
  def reduce
39
44
  return self if reduced?
40
- reduced_terms = @terms.map(&:reduce)
45
+ reduced_terms = @terms.map(&:reduce).uniq
41
46
  reduced_terms.reject!{|term| term.equal?(True)}
42
47
  return True if reduced_terms.empty?
43
48
  if reduced_terms.any?{|term| term.equal?(False)}
@@ -14,6 +14,11 @@ module PropLogic
14
14
  end
15
15
  end
16
16
  return unless @is_reduced
17
+ # check duplication of terms
18
+ if @terms.any?{ |term| @terms.index(term) != @terms.rindex(term)}
19
+ @is_reduced = false
20
+ return
21
+ end
17
22
  # check obvious variables (mark as unreduced)
18
23
  # Negated terms (except variables) doesn't come here
19
24
  not_terms = @terms.select{ |t| t.is_a?(NotTerm) }
@@ -36,7 +41,7 @@ module PropLogic
36
41
 
37
42
  def reduce
38
43
  return self if reduced?
39
- reduced_terms = @terms.map(&:reduce)
44
+ reduced_terms = @terms.map(&:reduce).uniq
40
45
  reduced_terms.reject!{|term| term.equal?(False)}
41
46
  return False if reduced_terms.empty?
42
47
  if reduced_terms.any?{|term| term.equal?(True)}
@@ -76,6 +76,7 @@ module PropLogic
76
76
  end
77
77
 
78
78
  def self.validate_terms(*terms)
79
+ raise ArgumentError, 'no terms given' if terms.empty?
79
80
  terms.map do |term|
80
81
  case term
81
82
  when TrueClass
@@ -90,11 +91,14 @@ module PropLogic
90
91
  end
91
92
  end
92
93
 
94
+ private_class_method :validate_terms
95
+
93
96
  def self.get(klass, *terms)
94
97
  @table ||= Ref::WeakValueMap.new
95
98
  terms = validate_terms(*terms)
96
99
  if klass == AndTerm || klass == OrTerm
97
100
  terms = terms.map{|t| t.is_a?(klass) ? t.terms : t}.flatten
101
+ return terms[0] if terms.length == 1
98
102
  end
99
103
  key = klass.name + terms.map(&:object_id).join(',')
100
104
  return @table[key] if @table[key]
@@ -1,3 +1,3 @@
1
1
  module PropLogic
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
4
+ version: 0.1.1
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-26 00:00:00.000000000 Z
11
+ date: 2016-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ref
@@ -17,8 +17,8 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.0'
20
- prerelease: false
21
20
  type: :runtime
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
@@ -31,8 +31,8 @@ dependencies:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.7'
34
- prerelease: false
35
34
  type: :development
35
+ prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
@@ -45,8 +45,8 @@ dependencies:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '10.0'
48
- prerelease: false
49
48
  type: :development
49
+ prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
@@ -59,8 +59,8 @@ dependencies:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3.0'
62
- prerelease: false
63
62
  type: :development
63
+ prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
@@ -76,6 +76,7 @@ files:
76
76
  - ".gitignore"
77
77
  - ".rspec"
78
78
  - ".travis.yml"
79
+ - CHANGELOG.md
79
80
  - Gemfile
80
81
  - LICENSE.txt
81
82
  - README.md
@@ -115,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
116
  version: '0'
116
117
  requirements: []
117
118
  rubyforge_project:
118
- rubygems_version: 2.5.1
119
+ rubygems_version: 2.4.5.1
119
120
  signing_key:
120
121
  specification_version: 4
121
122
  summary: Propositional logic for Ruby