catlogic 0.0.3 → 1.0.0

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: fcf6e7fcb655d416e5ab00d93212b490860e2632
4
- data.tar.gz: b9b5d3856a9c181436aff598eb043589432c2cac
3
+ metadata.gz: 6312cc7710e89773cfc041b5affe729ba1b3b647
4
+ data.tar.gz: 5590b0ba2c25878ba794371fc6c0f0a762924c4e
5
5
  SHA512:
6
- metadata.gz: 06e48a30aa87c2ddd027040ea4d08d7f97edf336b5bb9c81213c21729ac2a1928d4363131a2a48b25755d0e8d74c2b1fa9534cde1eb55b5a19c201e7ba79ea8b
7
- data.tar.gz: 4bef72f6ee5103edd20c0e59b4024515cb321a381620563d08a4a04426ff030a2539b923549f89e41761ad06397610793aaa4cb30ee3fda7d64c1b643072c27e
6
+ metadata.gz: 679b421b4ce3c76b15de5246594833eb9782f27a32605b5ab6f8e0017b88d3409d71ba59ad4e4e6250990926e224c154acc8c10e1b35337eba1c57f20f75fdb9
7
+ data.tar.gz: 51ac946455ced01462986b901dcd46287d6a3d26584995b9d7057113e42ca663d251434e334019b667a1a59d8c14cfb295398a52696485bfcbb07be46b980af1
data/README.md CHANGED
@@ -1,36 +1,231 @@
1
1
  # Catlogic
2
2
 
3
+ This a library designed to construct, calculate, and investigate categorical propositions and syllogisms.
4
+
3
5
  ## Installation
4
6
 
7
+ While such a library may at first be intimidating for the novice to use, it is not beyond you!
8
+
9
+ If you are using a Unix system (a Mac or Linux machine) you should be able to use this library quite easily with IRB, requiring little set up or programming knowledge.
10
+
11
+ To install `catlogic`, run in your terminal
12
+
5
13
  gem install catlogic
14
+
15
+ To use in a script, simply require catlogic at the top of your file
16
+
17
+ require 'catlogic'
18
+
19
+ To use in `irb`, (the recommended way for a beginner to play around with the library), enter the irb shell by typing in the terminal:
20
+
21
+ irb
22
+
23
+ Now type at the prompt
24
+
25
+ require 'catlogic'
26
+
27
+ You are now ready to go. To quickly create a syllogism type:
6
28
 
29
+ syl = Catlogic::Form.new("AAA", 1).syllogism
30
+
31
+ Now you can test your syllogisms validity:
32
+
33
+ syl.validity
34
+
35
+ or generate a human readable output
36
+
37
+ syl.label
38
+
39
+ See below for a detailed discussion of the kinds of objects you can create.
40
+
7
41
  ## Usage
8
42
 
9
- require 'catlogic'
43
+ To use the library, some knowledge of categorical logic, propositions, and syllogisms is required.
44
+
45
+ I recommend taking a look at the relevant wikipedia pages: [http://en.wikipedia.org/wiki/Syllogism](http://en.wikipedia.org/wiki/Syllogism); [http://en.wikipedia.org/wiki/Syllogism](http://en.wikipedia.org/wiki/Syllogism), [http://en.wikipedia.org/wiki/Categorical_proposition](http://en.wikipedia.org/wiki/Categorical_proposition); [http://www.logicmuseum.com/wiki/Syllogism](http://www.logicmuseum.com/wiki/Syllogism); [http://en.wikipedia.org/wiki/Square_of_opposition](http://en.wikipedia.org/wiki/Square_of_opposition)
46
+
47
+ Here I will just define the basic terms of categorical logic required to understand and use the `catlogic` library.
48
+
49
+ ### The Proposition
50
+ Perhaps the most important unit of categorical logic is the categorical proposition.
51
+
52
+ Thus, one of the central objects in this library is the Proposition object. A Proposition is not, however, the smallest conceptual unit, but is constructed from five other pieces of information: quantity, subject term, quality, predicate term, and a truth value. A Proposition objects is therefore constructed from four elemental level objects and one boolean, like so:
53
+
54
+ proposition = Catlogic::Proposition.new(
55
+ Catlogic::Quantity.new("universal"),
56
+ Catlogic::Term.new("Dogs"),
57
+ Catlogic::Quality.new("affirmative"),
58
+ Catlogic::Term.new("Mammals"),
59
+ true)
60
+
61
+ Or this can be constructed in shorthand like so:
62
+
63
+ proposition = Catlogic::Proposition.new("universal", "Dogs", "affirmative", "Mammals", true)
64
+
65
+ The truth value defaults to true, so you can choose to omit explicitly declaring that the proposition is true.
66
+
67
+ In either case, this construction corresponds to the human readable proposition: "All Dogs are Mammals," which can be retrieved using the label method.
10
68
 
11
- # create a categorical proposition
12
- proposition = Proposition.new(Quantity.new("Universal"), Term.new("Dogs), Catlogic::Quality.new("Affirmative"), Term.new("Mortal"), true)
69
+ proposition.label
13
70
 
14
- # get the type of the proposition
71
+ will produce the String:
72
+
73
+ "All Dogs are Mammals"
74
+
75
+ Besides the subject and predicate term and truth value, every categorical proposition has a quantity, either "universal" (All) or "particular" (Some). Likewise every proposition has a quality, either "affirmative" (are) or "negative" (are not).
76
+
77
+ The combination of Quality and Quantity data yields one of four unique proposition types, represented by A, E, I, and O, which can be retrieved from any constructed proposition like so:
78
+
15
79
  proposition.type
16
80
 
17
- #get a human readable form of the proposition
18
- propostion.label
19
-
20
- #make immediate inferences
21
- #obverse
22
- proposition.obverse
81
+ But likewise, it is also possible to construct generic propositions starting from a given proposition type. This can be constructed as follows:
82
+
83
+ propositiontype = Catlogic::PropositionType.new("A")
23
84
 
24
- # Build a proposition from its type
25
- proposition = PropositionType.new("I").proposition
85
+ A generic proposition can be constructed from this by using the `proposition` method:
86
+
87
+ proposition = propositiontype.proposition
26
88
 
27
- # Build a syllogism
28
- syllogism = Syllogism.new(majorproposition, minorproposition, conclusion)
89
+ Calling the `proposition.label` method now returns `All S are P`.
90
+
91
+ A number of immediate inferences can be made from a give proposition. These can be called as follows:
92
+
93
+ proposition.contradictory
94
+ proposition.contrary
95
+ proposition.subcontrary
96
+ proposition.subaltern
97
+ proposition.converse
98
+ proposition.obverse
99
+ proposition.contrapolated
100
+
101
+
102
+ ### The Syllogism
103
+
104
+ The next major unit is the Syllogism, which is itself an object constructed from three Proposition objects, a major proposition, a minor proposition, and the conclusion.
105
+
106
+ It is constructed first by creating three propositions.
107
+
108
+ major = Catlogic:Proposition.new("universal", "Dogs", "affirmative", "Mammals")
29
109
 
30
- # Test the validity of a syllogism
31
- syllogism.validity
110
+ minor = Catlogic::Proposition.new("universal", "Cockapoos", "affirmative", "Dogs")
111
+
112
+ conclusion = Catlogic::Proposition.new("universal", "Cockapoos", "affirmative", "Mammals")
113
+
114
+ Note that I left off adding `true` at the end of these proposition constructions because, if not stated, the Proposition object defaults to true.
115
+
116
+ The Syllogism object is then constructed from these propositions:
117
+
118
+ syllogism = Catlogic::Syllogism.new(major, minor, conclusion)
32
119
 
33
- # Get form of syllogism
34
- syllogism.form
120
+ All of the different Proposition objects that make up the syllogism can be retrieved as follows:
121
+
122
+ syllogism.major
123
+ syllogism.minor
124
+ syllogism.conclusion
125
+
126
+ Each syllogism has a middle term. This middle term is the term repeated in the major and minor premises. It can be retrieved from a syllogism as follows.
127
+
128
+ syllogism.middle
129
+
130
+ This will return a Term object and, to get the human readable version of that term, simply ask for the label.
131
+
132
+ syllogism.middle.label
133
+
134
+ Which, in our case, is "Dogs".
135
+
136
+ Likewise each syllogism has a major term and a minor term.
137
+
138
+ The minor term is found in the subject position in the conclusion premise and the major term is found in the predicate position in the conclusion premise. The Term objects can be retrieved as follows:
139
+
140
+ syllogism.majorterm
141
+ syllogism.minorterm
142
+
143
+ A syllogism also has a unique Form, which is made up from a Mood object and Figure object. Each of these can be retrieved from a syllogism. The Mood is constituted by the three proposition types of the syllogism's three propositions.
144
+
145
+ syllogism.mood
146
+
147
+ returns a Mood object, itself constructed from three PropositionType objects. A human readable output can be retrieved by applying the method `.label` to the Mood object, like so:
148
+
149
+ syllogism.mood.label
150
+
151
+ This will return "AAA" because our syllogism is made up of three A proposition types.
152
+
153
+ The Form object is also constructed from a Figure object, which is determined by the position of the middle term in the major and minor premises. There are four possible figures, and a Figure object can be retrieved by applying the figure method to the syllogism.
154
+
155
+ syllogism.figure
156
+ syllogism.figure.label
157
+
158
+ The addition of the `.label` method returns the integer 1 because our sample syllogism is a figure one syllogism.
159
+
160
+ Combining the Mood and the Figure objects constructs a Form object which can also be retrieved from a Syllogism object.
161
+
162
+ syllogism.form
163
+ syllogism.form.label # == "AAA1"
164
+
165
+ The Mood and Figure can also be retrieved directly from the Form object
166
+
167
+ form = syllogism.form
168
+ form.mood
169
+ form.figure
170
+
171
+ The Form object is also very useful because it allows us to very quickly construct a generic syllogism for any possible syllogism.
172
+
173
+ The Form object can be constructed as follows.
174
+
175
+ form = Catlogic::Form.new("AAA", 1)
176
+
177
+ One can quickly create a syllogism from the given Form object by calling the syllogism method:
178
+
179
+ syllogism = form.syllogism
180
+
181
+ Besides retrieving information about a given syllogism, we can also test a syllogisms validity:
182
+
183
+ syllogism.validity
184
+
185
+ If valid it will return `true`, if invalid it will return `false`.
186
+
187
+ The validity method tests against six separate tests, that reduce the 256 possible syllogisms to the 24 valid (unconditionally and conditionally) syllogisms. Each of these tests can be run separately.
188
+
189
+ syllogism.undistributed_middle_test
190
+ syllogism.illicit_major_test
191
+ syllogism.illicit_minor_test
192
+ syllogism.exclusive_premises_test
193
+ syllogism.affirm_from_neg_test
194
+ syllogism.neg_from_affirms_test
195
+
196
+ ### Syllogism Pairs and Syllogism Collections
197
+ This is a more advanced use case, but it may happen that you have two or more premises and you actually want to compute possible syllogisms that can be constructed from this set and then test for validity.
198
+
199
+ To do this you can create a PremisePair Object from two Proposition objects
200
+
201
+ preimsepair = Catlogic:PremisePari.new(major, minor)
202
+
203
+ On a PremisePair object you can request an array of possible conclusions. For any premise pair it will return the four possible conclusion combinations.
204
+
205
+ There are enough resources at this point in the library to allow you to test the validity of those possible conclusions and determine if you can infer any new truths from the original set of known propositions.
206
+
207
+ This can be written your self or done using the PremiseCollection object.
208
+
209
+ The PremiseCollection object takes an array of two or more Proposition objects in any order, constructed like so:
210
+
211
+ collection = Catlogic::PremiseCollection.new([propostion1, proposition2, proposition3])
212
+
213
+ With this object constructed you can use the method `valid_syllogisms' to return an array of valid syllogisms that can be constructed from the input set.
214
+
215
+ collection.valid_syllogims
216
+
217
+ You can also search for just new inferred conclusions either with `inferred_truths_unique` or `inferred_truths_new`.
218
+
219
+ collection.inferred_truths_unique
220
+ collection.inferred_truths_new
221
+
222
+ `.inferred_truths_unique` will return non duplicate truths inferred from the given set.
223
+
224
+ `.inferred_truths_unique` will filter the above set excluding all inferred truths that were present in the original set.
225
+
226
+
227
+ Please post issues and feature requests.
228
+
229
+ Full documentation can be found at [http://www.rubydoc.info/gems/catlogic/](http://www.rubydoc.info/gems/catlogic/)
35
230
 
36
231
 
@@ -3,7 +3,7 @@ module Catlogic
3
3
 
4
4
  attr_reader :quantity, :subject, :quality, :predicate, :truthvalue
5
5
 
6
- def initialize(quantity, subject, quality, predicate, truthvalue)
6
+ def initialize(quantity, subject, quality, predicate, truthvalue=true)
7
7
  @quantity=quantity.to_quantity
8
8
  @subject=subject.to_term
9
9
  @quality=quality.to_quality
@@ -57,7 +57,8 @@ module Catlogic
57
57
 
58
58
  def contrary
59
59
  if @quantity.label == "particular"
60
- abort("There is no contrary for this type of propostion. Try subcontrary")
60
+ puts
61
+ return "There is no contrary for this type of propostion. Try subcontrary"
61
62
  end
62
63
  quality = @quality.opposite
63
64
 
@@ -73,7 +74,8 @@ module Catlogic
73
74
 
74
75
  def subcontrary
75
76
  if @quantity.label == "universal"
76
- abort("There is no subcontrary for this type of propostion. Try contrary.")
77
+ puts "There is no subcontrary for this type of propostion. Try contrary."
78
+ return
77
79
  end
78
80
 
79
81
  quality = @quality.opposite
@@ -1,3 +1,3 @@
1
1
  module Catlogic
2
- VERSION = "0.0.3"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catlogic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeffrey C. Witt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-03 00:00:00.000000000 Z
11
+ date: 2015-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler