propose 0.0.1 → 0.0.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: 5e51a21663914889a221fc855ab81d9b864e4f7c
4
- data.tar.gz: c100032842cfb108b8181ca745767d428921aac4
3
+ metadata.gz: d85782cc245209ea1652fdfab739c34c4ef26722
4
+ data.tar.gz: 5b844f9c256d31e5afe1d0fb644908b59cba5df1
5
5
  SHA512:
6
- metadata.gz: 0fa8554ec8b5b662c683cf8b8dafd9beecbd90a92ace372f3dd18308d9e21ce05013343288c0394ca32841bdbe0007400f7c0b1e1124e1895cc263207b4697fb
7
- data.tar.gz: fd45c6fd818f0255ebae73f43c56feb70ea892b7a9e12fc12739d5604a7a3e7529b6abd5b8c506366b803a7cc3f4e681841fc2e3530c572d9d5689990c4cc576
6
+ metadata.gz: 57475acdf41eedf0797b0444d2a62f3ad6450327f7d1fdf71d197b246ef51901788b00ca6d97c79958d7f350034fe74a6e787f0735c553053e9e3cac64e0a88b
7
+ data.tar.gz: 47a6772312b2703530f8c6e921d03d3ae4bc824149287663e00d7de8475fa6e18a625d0bd2db6d1018318655a34a5dc7d55672eea6c65651a72399656a42eeb5
@@ -0,0 +1,164 @@
1
+ # Defines the grammar for propositional logic formulas.
2
+ grammar PropositionalLogic
3
+ rule statement
4
+ sequent
5
+ /
6
+ formula
7
+ end
8
+
9
+ rule formula
10
+ implication
11
+ /
12
+ disjunction
13
+ /
14
+ conjunction
15
+ /
16
+ unit
17
+ end
18
+
19
+ rule not
20
+ _? ('not' _ / '!' / '¬') _?
21
+ end
22
+
23
+ rule conjunction
24
+ left:unit and right:(conjunction / unit) {
25
+ def to_ast
26
+ Propose::Tree::Conjunction.new(left.to_ast, right.to_ast)
27
+ end
28
+ }
29
+ end
30
+
31
+ rule and
32
+ _ 'and' _
33
+ /
34
+ _? ('∧' / '&') _?
35
+ end
36
+
37
+ rule disjunction
38
+ left:(conjunction / unit) or right:(disjunction / conjunction / unit) {
39
+ def to_ast
40
+ Propose::Tree::Disjunction.new(left.to_ast, right.to_ast)
41
+ end
42
+ }
43
+ end
44
+
45
+ rule or
46
+ _ 'or' _
47
+ /
48
+ _? ('∨' / '|') _?
49
+ end
50
+
51
+ rule implication
52
+ left:(disjunction / conjunction / unit) imply right:formula {
53
+ def to_ast
54
+ Propose::Tree::Implication.new(left.to_ast, right.to_ast)
55
+ end
56
+ }
57
+ end
58
+
59
+ rule imply
60
+ _? ('=>' / '->') _?
61
+ /
62
+ _ ('imply' / 'implies') _
63
+ end
64
+
65
+ rule unit
66
+ literal
67
+ /
68
+ bracketed_formula
69
+ /
70
+ not bracketed_formula {
71
+ def to_ast
72
+ Propose::Tree::Negation.new(bracketed_formula.to_ast)
73
+ end
74
+ }
75
+ end
76
+
77
+ rule bracketed_formula
78
+ '(' _? formula _? ')' {
79
+ def to_ast
80
+ formula.to_ast
81
+ end
82
+ }
83
+ end
84
+
85
+ rule literal
86
+ not atom {
87
+ def to_ast
88
+ Propose::Tree::Negation.new(atom.to_ast)
89
+ end
90
+ }
91
+ /
92
+ atom
93
+ /
94
+ verum
95
+ /
96
+ falsum
97
+ end
98
+
99
+ rule atom
100
+ !(not / proves) name:[a-z]+ {
101
+ def to_ast
102
+ Propose::Tree::Atom.new(name.text_value.to_sym)
103
+ end
104
+ }
105
+ end
106
+
107
+ rule verum
108
+ 'T' {
109
+ def to_ast
110
+ Propose::Tree::Verum.instance
111
+ end
112
+ }
113
+ end
114
+
115
+ rule falsum
116
+ 'F' {
117
+ def to_ast
118
+ Propose::Tree::Falsum.instance
119
+ end
120
+ }
121
+ end
122
+
123
+ rule sequent
124
+ premises:premise_list proves conclusion:formula {
125
+ def to_ast
126
+ Propose::Tree::Sequent.new(premises.to_a, conclusion.to_ast)
127
+ end
128
+ }
129
+ /
130
+ proves formula {
131
+ def to_ast
132
+ Propose::Tree::Sequent.new([], formula.to_ast)
133
+ end
134
+ }
135
+ end
136
+
137
+ rule proves
138
+ _? 'proves' _
139
+ /
140
+ _? ('⊢' / '|-') _?
141
+ end
142
+
143
+ rule premise_list
144
+ premise:formula comma list:premise_list {
145
+ def to_a
146
+ [premise.to_ast] + list.to_a
147
+ end
148
+ }
149
+ /
150
+ premise:formula {
151
+ def to_a
152
+ [premise.to_ast]
153
+ end
154
+ }
155
+ end
156
+
157
+ rule comma
158
+ _? ',' _?
159
+ end
160
+
161
+ rule _
162
+ [\s]+
163
+ end
164
+ end
@@ -37,15 +37,20 @@ module Propose
37
37
 
38
38
  def print_truth_table(statement)
39
39
  tt = Propose::TruthTable.new(statement)
40
-
41
40
  atoms = tt.formula_atoms.to_a
41
+ table = create_table(statement, atoms, tt)
42
+
43
+ puts table.to_s
44
+ .gsub('T', 'T'.green)
45
+ .gsub('F', 'F'.red)
46
+ .gsub(table.title, table.title.cyan)
47
+ end
42
48
 
49
+ def create_table(statement, atoms, tt)
43
50
  table = Terminal::Table.new do |t|
44
51
  t << atoms + ['Result']
45
52
  t.add_separator
46
- tt.evaluations.each do |assignment, result|
47
- t << assignment.values.map { |v| shorthand_value(v) } + [shorthand_value(result)]
48
- end
53
+ add_truth_table_rows(t, tt)
49
54
  end
50
55
 
51
56
  table.title = statement.to_s
@@ -54,10 +59,13 @@ module Propose
54
59
  table.align_column(i, :center)
55
60
  end
56
61
 
57
- puts table.to_s
58
- .gsub('T', 'T'.green)
59
- .gsub('F', 'F'.red)
60
- .gsub(table.title, table.title.cyan)
62
+ table
63
+ end
64
+
65
+ def add_truth_table_rows(table, truth_table)
66
+ truth_table.evaluations.map do |assignment, result|
67
+ table << assignment.values.map { |v| shorthand_value(v) } + [shorthand_value(result)]
68
+ end
61
69
  end
62
70
 
63
71
  def shorthand_value(value)
@@ -24,8 +24,7 @@ module Propose::Tree
24
24
  end
25
25
 
26
26
  def to_s
27
- output = []
28
- output << (left.literal? ? left.to_s : "(#{left})")
27
+ output = [(left.literal? ? left.to_s : "(#{left})")]
29
28
  output << " #{operator} "
30
29
  output << (right.literal? ? right.to_s : "(#{right})")
31
30
  output.join
@@ -1,4 +1,4 @@
1
1
  # Specifies the gem version.
2
2
  module Propose
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: propose
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane da Silva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-03 00:00:00.000000000 Z
11
+ date: 2015-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -44,14 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.5'
47
+ version: 1.5.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.5'
54
+ version: 1.5.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: overcommit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.23.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.23.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +100,28 @@ dependencies:
86
100
  requirements:
87
101
  - - '='
88
102
  - !ruby/object:Gem::Version
89
- version: 0.25.0
103
+ version: 0.29.1
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - '='
95
109
  - !ruby/object:Gem::Version
96
- version: 0.25.0
110
+ version: 0.29.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: travis
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.7'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.7'
97
125
  description: Create, manipulate, and verify propositional logic sentences
98
126
  email: shane@dasilva.io
99
127
  executables:
@@ -102,6 +130,7 @@ extensions: []
102
130
  extra_rdoc_files: []
103
131
  files:
104
132
  - bin/propose
133
+ - grammar/propositional_logic.treetop
105
134
  - lib/propose.rb
106
135
  - lib/propose/atom_finder.rb
107
136
  - lib/propose/parser.rb