-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstrict_argument.ex
256 lines (216 loc) · 5.7 KB
/
strict_argument.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
ExUnit.start()
defmodule StrictArgument do
@moduledoc """
Strict Argument Generator.
Supplies primitives to form an argument based on Aristotelian syllogism.
For more information follow the link: https://en.wikipedia.org/wiki/Syllogism
"""
defguard is_category(category)
when category in [:major, :minor]
defguard is_scope(scope)
when scope in [:universal, :particular]
defguard is_pole(pole)
when pole in [:affirmative, :negative]
defguard is_premise(category, term1, term2, scope, pole)
when is_category(category)
and is_binary(term1)
and is_binary(term2)
and is_scope(scope)
and is_pole(pole)
@todos """
* add premise types somehow. typespecs or maybe resolve as structs?
"""
@doc """
Forms a premise based on major | minor category,
for given terms and type information.
Returns a map, consists of terms, type.
"""
def premise(category, term1, term2, scope, pole)
when is_premise(category, term1, term2, scope, pole)
do
%{__category__: category, terms: [term1, term2], type: {scope, pole}}
end
@doc """
Forms a conclusion for given major and minor premises.
Returns a map, consists of o subject, predicate and type.
"""
def conclude(
%{
__category__: :major,
terms: [middle, predicate],
type: {:universal, :affirmative}
},
%{
__category__: :minor,
terms: [subject, middle],
type: {:universal, :affirmative}
}
) do
%{
terms: [subject: subject, predicate: predicate],
type: {:universal, :affirmative}
}
end
def conclude(
%{
__category__: :major,
terms: [middle, predicate],
type: {:universal, :negative}
},
%{
__category__: :minor,
terms: [subject, middle],
type: {:universal, :affirmative}
}
) do
%{
terms: [subject: subject, predicate: predicate],
type: {:universal, :negative}
}
end
def conclude(
%{
__category__: :major,
terms: [predicate, middle],
type: {:universal, :affirmative}
},
%{
__category__: :minor,
terms: [subject, middle],
type: {:particular, :negative}
}
) do
%{
terms: [
subject: subject, predicate: predicate
],
type: {:particular, :negative}
}
end
def conclude(
%{
__category__: :major,
terms: [middle, predicate],
type: {:universal, :affirmative}
},
%{
__category__: :minor,
terms: [middle, subject],
type: {:universal, :affirmative}
}
) do
%{
terms: [
subject: subject, predicate: predicate
],
type: {:particular, :affirmative}
}
end
end
defmodule StrictArgumentTest do
use ExUnit.Case, async: true
@barbara """
all men are mortal.
all greeks are men.
∴ all greeks are mortal.
"""
test "proposes a major premise" do
major = StrictArgument.premise(
:major, "man", "mortal", :universal, :affirmative
)
assert major == %{
__category__: :major,
terms: ["man", "mortal"],
type: {:universal, :affirmative}
}
end
test "proposes a minor premise" do
minor = StrictArgument.premise(
:minor, "greek", "man", :universal, :affirmative
)
assert minor == %{
__category__: :minor,
terms: ["greek", "man"],
type: {:universal, :affirmative}
}
end
test "concludes all greeks are mortal following @barbara" do
major = StrictArgument.premise(
:major, "man", "mortal", :universal, :affirmative
)
minor = StrictArgument.premise(
:minor, "greek", "man", :universal, :affirmative
)
conclusion = StrictArgument.conclude(major, minor)
assert conclusion == %{
terms: [
subject: "greek",
predicate: "mortal"
],
type: {:universal, :affirmative}
}
end
@celarent """
No birds can travel through space.
All chickens are birds.
∴ No chickens can travel through space.
"""
test "conclude no chickens can travel through space following @celarent" do
major = StrictArgument.premise(
:major, "bird", "travel through space", :universal, :negative
)
minor = StrictArgument.premise(
:minor, "chicken", "bird", :universal, :affirmative
)
conclusion = StrictArgument.conclude(major, minor)
assert conclusion == %{
terms: [
{:subject, "chicken"},
{:predicate, "travel through space"}
],
type: {:universal, :negative}
}
end
@baroco """
All informative things are useful.
Some websites are not useful.
∴ Some websites are not informative things.
"""
test "conclude some websites are not informative following baroco" do
major = StrictArgument.premise(
:major, "informative thing", "useful", :universal, :affirmative
)
minor = StrictArgument.premise(
:minor, "website", "useful", :particular, :negative
)
conclusion = StrictArgument.conclude(major, minor)
assert conclusion == %{
terms: [
{:subject, "website"},
{:predicate, "informative thing"}
],
type: {:particular, :negative}
}
end
@darapti """
All squares are rectangles.
All squares are rhombuses.
∴ Some rhombuses are rectangles.
"""
test "conclude some rhombuses are rectangles following darapti" do
major = StrictArgument.premise(
:major, "square", "rectangle", :universal, :affirmative
)
minor = StrictArgument.premise(
:minor, "square", "rhombuse", :universal, :affirmative
)
conclusion = StrictArgument.conclude(major, minor)
assert conclusion == %{
terms: [
{:subject, "rhombuse"},
{:predicate, "rectangle"}
],
type: {:particular, :affirmative}
}
end
end