-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
1589 lines (1214 loc) · 50.1 KB
/
main.cpp
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Bugs:
1) For test problem #16, program sometimes crashes if I randomly shuffle the statements vector
once in a while in attempt_proof().
2) For problem #20, to show a contradiction, the program keeps wanting to use
!Pv!Q and !(!Pv!Q). This works, but there's sometimes quicker ways. E.g., P and !P already
known, but program then derives !Pv!Q to show contradiction.
- Refer to page in notebook with big star.
Ideas:
1) Shuffle the statements vector in the attempt_proof() function sometimes. Could help
if the AI is stuck somewhere.
Notes:
1) If recording a message for starting a supposition, make sure the first four chars of the
text start with "Supp".
2) Then when finishing the supposition, record the message as the supposition_failed or
supposition_success const string vars. Do this specific recording at the very end of all
other recordings for the supposition.
3) Make sure all messages are stored in the steps_of_proof global vector.
4) When getting a new statement, always make sure you call the remove_outside_brackets function
on it.
*/
#include <iostream>
#include <vector>
#include <stdexcept>
#include <random>
#include <time.h>
#include <cstdlib>
#include <algorithm>
#include <assert.h>
using namespace std;
const string supposition_failed = "Failed supposition";
const string supposition_success = "Successful supposition";
const string contradiction_string = "contradiction";
void remove_any_spaces(string& statement) {
string new_statement;
for (char c: statement) {
if (c != ' ') {
new_statement += c;
}
}
statement = new_statement;
}
void get_user_inputs(vector<string>& premises, string& conclusion) {
cout << "Once you've entered some statement(s), enter \"done\" for the last statement you've entered to be the";
cout << " conclusion that gets proven.\n";
cout << "Or, if you'd like to quit the program, enter \"done\" right now, for statement #1.\n";
string user_input = "";
for (int i = 1; user_input != "done"; ++i) {
if (i > 1) {
premises.push_back(user_input);
}
cout << "Enter statement #" << i << ": ";
getline(cin, user_input);
}
if (!premises.empty()) {
for (string& premise: premises) {
remove_any_spaces(premise);
}
conclusion = premises[premises.size()-1];
premises.pop_back();
}
}
bool is_a_main_operator(char c) {
return c == 'v' || c == '^' || c == '!' || c == '>' || c == '=';
}
// Function returns -1 if there is no main operator.
int get_main_operator_index(const string& statement, bool look_for_certain_operator,
char certain_operator_to_look_for, bool exclude_certain_operator,
char certain_operator_to_exclude) {
if (!look_for_certain_operator && !exclude_certain_operator) {
int main_operator_index_without_negation = get_main_operator_index(statement, false, ' ', true, '!');
if (main_operator_index_without_negation != -1) {
return main_operator_index_without_negation;
}
}
int left_bracket_counter = 0;
int right_bracket_counter = 0;
for (int i = 0; i < statement.size(); ++i) {
char c = statement[i];
if (c == '(') {
++left_bracket_counter;
} else if (c == ')') {
++right_bracket_counter;
} else if (left_bracket_counter == right_bracket_counter &&
is_a_main_operator(c) &&
(!look_for_certain_operator || c == certain_operator_to_look_for) &&
(!exclude_certain_operator || c != certain_operator_to_exclude)) {
return i;
}
}
return -1;
}
bool is_statement_legal(const string& statement) {
bool unclosed_open_bracket = false;
int num_open_brackets = 0;
int num_closed_brackets = 0;
// TODO - Use a stack data structure here, to keep track of the number of
// unclosed open brackets. This is a stronger way of doing things than just using
// 1 bool variable, which is currently what's being done.
for (char c: statement) {
if (c == '(') {
++num_open_brackets;
unclosed_open_bracket = true;
} else if (c == ')') {
++num_closed_brackets;
if (!unclosed_open_bracket) {
return false;
} else if (num_closed_brackets >= num_open_brackets) {
unclosed_open_bracket = false;
// Since it's been closed by its corresponding closed bracket.
}
}
}
return (!unclosed_open_bracket && num_open_brackets == num_closed_brackets);
}
void remove_outside_brackets(string& statement) {
if (statement.empty()) {
throw runtime_error("empty string statement for remove_outside_brackets()");
} else if (statement[0] == '!' && get_main_operator_index(statement, false, ' ', false, ' ') == 0) {
statement = statement.substr(1, statement.size()-1);
remove_outside_brackets(statement);
// Now add the '!' back in:
if (statement.size() > 1) {
statement = "(" + statement + ")"; // So that the negation applies to the whole statement.
}
statement = "!" + statement;
} else {
string old_version = statement;
if (statement[0] == '(' && statement[statement.size()-1] == ')') {
statement = statement.substr(1, statement.size() - 2);
// Now make sure statement is legal:
if (!is_statement_legal(statement)) {
statement = old_version;
} else {
remove_outside_brackets(statement);
}
}
}
}
string get_left_statement(const string& statement, char main_operator) {
int main_operator_index = get_main_operator_index(statement, true, main_operator, false, ' ');
string left_statement = statement.substr(0, main_operator_index);
remove_outside_brackets(left_statement);
return left_statement;
}
string get_right_statement(const string& statement, char main_operator) {
int main_operator_index = get_main_operator_index(statement, true, main_operator, false, ' ');
string right_statement = statement.substr(main_operator_index + 1,
(statement.size() - main_operator_index - 1));
remove_outside_brackets(right_statement);
return right_statement;
}
bool in_vector(const vector<string>& statements, const string& s) {
return find(statements.begin(), statements.end(), s) != statements.end();
}
bool attempt_contradiction(vector<string> statements, string additional_statement) {
// CONTINUE HERE:
// Function returns true if a contradiction can be made using the statements.
// See if anything the additional_statement implies leads to a direct contradiction?
return false;
}
bool contains(const string& statement, const string& text)
{
return statement.find(text) != string::npos;
}
vector<string> get_statements_containing_statement(const vector<string>& statements,
const string& statement) {
vector<string> selected_strings;
for (const string& current: statements) {
if (contains(current, statement)) {
selected_strings.push_back(current);
}
}
return selected_strings;
}
bool is_a_conditional(const string& statement) {
return (get_main_operator_index(statement, true, '>', false, ' ')) != -1;
}
int index_of(const string& text, char c) {
int index = text.find(c);
assert(index != string::npos);
return index;
}
// TODO - Continue here for formatting the code and making it cleaner.
string get_stuff_after_character(const string& text, int index_of_character, bool eliminate_brackets)
{
// int index_of_character = index_of(text, c);
int starting_index = index_of_character + 1;
string objective = text.substr(starting_index, text.size() - starting_index);
if (eliminate_brackets)
{
remove_outside_brackets(objective);
}
return objective;
}
string get_stuff_before_character(const string& text, int index_of_character, bool eliminate_brackets)
{
// int index_of_character = index_of(text, c);
int ending_index = index_of_character - 1;
string objective = text.substr(0, ending_index + 1);
if (eliminate_brackets)
{
remove_outside_brackets(objective);
}
return objective;
}
vector<string> get_statements_where_statement_is_a_consequent(const vector<string>& statements,
const string& statement)
{
vector<string> chosen_statements;
for (string current: statements)
{
if (is_a_conditional(current))
{
int main_operator_index = get_main_operator_index(current, true, '>', false, ' ');
string consequent = get_stuff_after_character(current, main_operator_index, true);
if (statement == consequent)
{
chosen_statements.push_back(current);
}
}
}
return chosen_statements;
}
vector<string> get_vector_without_string(const vector<string>& vec, const string& element)
{
vector<string> replacement;
for (string current: vec)
{
if (current != element)
{
replacement.push_back(current);
}
}
return replacement;
}
bool is_proper_letter(char c)
{
// by proper letter, I mean any letter except for 'v', since this is the disjunction.
return (((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) && c != 'v');
}
bool has_statement(const vector<string>& statements, const string& statement)
{
for (string current: statements)
{
if (current == statement)
{
return true;
}
}
return false;
}
bool does_negation_apply_to_whole_statement(string statement)
{
if (statement[0] != '!')
{
return false;
}
statement = statement.substr(1, statement.size()-1);
if (statement.size() == 1)
{
return true;
}
if (statement[0] != '(')
{
return false;
}
// Now see if this opening bracket is only closed at the very end of the statement.
int open_bracket_counter = 1;
int closed_bracket_counter = 0;
for (int i = 1; i < statement.size(); i++)
{
if (statement[i] == '(')
{
open_bracket_counter ++;
}
else if (statement[i] == ')')
{
closed_bracket_counter ++;
}
if (open_bracket_counter == closed_bracket_counter)
{
return (i == statement.size()-1);
}
}
throw runtime_error("Statement doesn't have the same number of open and closed brackets");
}
bool is_negation_of(string first_statement, string second_statement)
{
// Return true if the first_statement is the negation of the second one.
// In this case, this means the first_statement is the one with a '!' in front of it.
if (first_statement[0] != '!')
{
return false;
}
// Check that the '!' in first_statement applies to the whole statement:
if (!does_negation_apply_to_whole_statement(first_statement))
{
return false;
}
// Remove the beginning '!' from first_statement:
first_statement = first_statement.substr(1, first_statement.size()-1);
// Remove any outside brackets:
remove_outside_brackets(first_statement);
remove_outside_brackets(second_statement); // just to be safe.
return (first_statement == second_statement);
}
bool any_contradictory_statements(const vector<string>& statements)
{
for (int i = 0; i < statements.size(); i++)
{
for (int x = 0; x < statements.size(); x++)
{
if (is_negation_of(statements[i], statements[x]))
{
return true;
}
}
}
return false;
}
// Pre-condition: There must be a pair of contradictory statements.
vector<string> get_contradictory_statements(const vector<string>& statements)
{
vector<string> result;
for (int i = 0; i < statements.size(); i++)
{
for (int x = 0; x < statements.size(); x++)
{
if (is_negation_of(statements[i], statements[x]))
{
result.push_back(statements[i]);
result.push_back(statements[x]);
return result;
}
}
}
throw runtime_error("No contradictory statements");
}
string negate_by_adding_exclamation(const string& statement)
{
string negated_statement;
if (statement.size() == 1)
{
negated_statement = "!" + statement;
}
else
{
negated_statement = "!(" + statement + ")";
}
return negated_statement;
}
// Post-condition: If there isn't an existing negation applying to the statement, the empty string is returned.
string negate_by_removing_exclamation(const string& statement)
{
string negated_statement = "";
if (does_negation_apply_to_whole_statement(statement))
{
negated_statement = statement.substr(1, statement.size()-1);
remove_outside_brackets(negated_statement);
}
return negated_statement;
}
int number_of_exclamation_marks_at_beginning(const string& statement)
{
int exclamation_counter = 0;
for (char c: statement)
{
if (is_proper_letter(c))
{
// c is a letter, so stop.
break;
}
if (c == '!')
{
exclamation_counter ++;
}
}
return exclamation_counter;
}
void remove_string_from_vec(vector<string>& vec, const string& element)
{
vector<string> replacement;
for (const string& current: vec)
{
if (current != element)
{
replacement.push_back(current);
}
}
vec = replacement;
}
vector<string> remove_duplicates(const vector<string>& vec)
{
vector<string> result;
for (const string& current: vec)
{
if (!in_vector(result, current))
{
result.push_back(current);
}
}
return result;
}
vector<string> get_primitive_statements(const vector<string>& statements)
{
vector<string> primitive_statements;
for (const string& current: statements)
{
for (char c: current)
{
if (is_proper_letter(c))
{
string s = "";
s += c;
primitive_statements.push_back(s);
s = "!" + s;
primitive_statements.push_back(s);
}
}
}
return remove_duplicates(primitive_statements);
}
bool only_implications_and_biconditionals(const vector<string>& statements)
{
for (string current: statements)
{
int main_operator_index = get_main_operator_index(current, false, ' ', false, ' ');
if (!(current[main_operator_index] == '>' || current[main_operator_index] == '='))
{
return false;
}
}
return true;
}
int get_num_occurrences(const string& s, char c)
{
int counter = 0;
for (char current: s)
{
if (current == c)
{
counter ++;
}
}
return counter;
}
bool any_equivalent_statement(const vector<string>& statements, const string& statement)
{
// Function returns true if there is a statement that is logically equivalent with statement via
// double negation introduction/removal.
int num_exclamations_of_statement = get_num_occurrences(statement, '!');
for (string current: statements)
{
if (current == statement)
{
return true;
}
// Now see if a double negation can be added/removed from current to make it like statement.
int num_exclamations_of_current = get_num_occurrences(current, '!');
if (num_exclamations_of_current > num_exclamations_of_statement)
{
current = negate_by_removing_exclamation(negate_by_removing_exclamation(current));
if (current == statement)
{
return true;
}
}
else if (num_exclamations_of_current < num_exclamations_of_statement)
{
current = negate_by_adding_exclamation(negate_by_adding_exclamation(current));
if (current == statement)
{
return true;
}
}
}
return false;
}
bool same_elements(vector<string> first, vector<string> second)
{
sort(first.begin(), first.end());
sort(second.begin(), second.end());
return (first == second);
}
void randomly_shuffle(vector<string>& vec)
{
vector<string> old_vec = vec;
vector<string> replacement;
while (!vec.empty())
{
int index = rand() % vec.size();
replacement.push_back(vec[index]);
vec.erase(vec.begin() + index);
}
if (!same_elements(old_vec, replacement))
{
throw runtime_error("randomly_shuffle function has a bug");
}
vec = replacement;
}
vector<string> steps_of_proof;
string base_conclusion = ""; // For each problem, this is the overall conclusion trying to be shown.
// If it's proven when in a base scope (not in an undischarged supp), then
// even if the current conclusion isn't it, return true up the call stack,
// since the problem is solved.
bool solved_base_conclusion_in_base_scope = false;
bool attempt_proof(vector<string> statements, string conclusion, bool is_overall_goal_contradiction,
bool& showed_contradiction_instead_of_conclusion, int num_embedded_supps)
{
// The "is_overall_goal_contradiction" parameter equals true if the purpose of proving the
// conclusion is to show a contradiction.
// So, even though the program is working towards inferring the conclusion, if a contradiction
// happens to arise with two contradictory premises, the program can stop and return true.
// Note that the main "focus" is on trying to show the conclusion, not going on tangents
// to derive a contradiction.
// If a contradiction is shown and the function returns, even though conclusion wasn't explicitly
// the contradiction_string, then the fourth parameter is set to true. The reason is to let
// the caller function know what happened (mainly just to print the appropriate thing to the screen
// when showing the proof steps later on).
// The 5th parameter, num_embedded_supps, is the number of embedded suppositions control is
// currently in.
// Ex: It equals 2 if control is in a supposition within a supposition.
/* if (rand() % 10 == 1)
{
randomly_shuffle(statements);
} */
for (string& current: statements)
{
remove_outside_brackets(current);
}
remove_outside_brackets(conclusion);
// steps_of_proof.push_back("CONC trying to prove: " + conclusion);
string message = "";
// Return true if the conclusion could be proven, false otherwise.
// Note that conclusion could be a statement, or the string "contradiction".
// In this case, the goal is to show/prove a contradiction with the statements I have.
if (conclusion == contradiction_string || is_overall_goal_contradiction)
{
if (any_contradictory_statements(statements))
{
vector<string> contradictory_statements = get_contradictory_statements(statements);
message = "Found a contradiction with " + contradictory_statements[0] +
" and " + contradictory_statements[1] + "\n";
steps_of_proof.push_back(message);
if (is_overall_goal_contradiction && conclusion != contradiction_string)
{
showed_contradiction_instead_of_conclusion = true;
}
return true;
}
}
// Will do this check after updating the statements with any new statements below.
// Try deriving new statements from the existing statements, and then try to prove
// the conclusion again.
// While I'm going through the existing statements, I might as well check if one of them
// equals the original_conclusion and conclusion.
int old_num_statements = statements.size();
for (int i = 0; i < statements.size(); i++)
{
string current = statements[i];
if (current == base_conclusion && num_embedded_supps == 0)
{
message = "Proved " + base_conclusion;
steps_of_proof.push_back(message);
solved_base_conclusion_in_base_scope = true;
return true;
}
if (current == conclusion)
{
message = "Reit " + conclusion + "\n";
steps_of_proof.push_back(message);
return true;
}
int main_operator_index = get_main_operator_index(current, false, ' ', false, ' ');
if (current[main_operator_index] == '^')
{
string left_statement = get_left_statement(current, '^');
string right_statement = get_right_statement(current, '^');
if (!in_vector(statements, left_statement))
{
statements.push_back(left_statement);
message = "Proved " + left_statement + " by conjunction eliminiation\n";
steps_of_proof.push_back(message);
}
if (!in_vector(statements, right_statement))
{
statements.push_back(right_statement);
message = "Proved " + right_statement + " by conjunction eliminiation\n";
steps_of_proof.push_back(message);
}
// Adding stuff to a vector I'm iterating through isn't an error, because one of the statements
// in a conjunction could be a conjunction itself, so I'd want to revisit it on its own
// and break it down as well.
}
if (current[main_operator_index] == '>')
{
string antecedent = get_stuff_before_character(current, main_operator_index, true);
if (in_vector(statements, antecedent))
{
string consequent = get_stuff_after_character(current, main_operator_index, true);
if (!in_vector(statements, consequent))
{
statements.push_back(consequent);
message = "Proved " + consequent + " by Modus Ponens on " + current + "\n";
steps_of_proof.push_back(message);
}
}
}
if (current[main_operator_index] == '=')
{
string left_side = get_stuff_before_character(current, main_operator_index, false);
string right_side = get_stuff_after_character(current, main_operator_index, false);
string forward_implication = left_side + '>' + right_side;
string backward_implication = right_side + '>' + left_side;
if (!in_vector(statements, forward_implication))
{
statements.push_back(forward_implication);
message = "Proved " + forward_implication + " by biconditional elimination\n";
steps_of_proof.push_back(message);
}
if (!in_vector(statements, backward_implication))
{
statements.push_back(backward_implication);
message = "Proved " + backward_implication + " by biconditional elimination\n";
steps_of_proof.push_back(message);
}
}
}
if (statements.size() != old_num_statements)
{
if (attempt_proof(statements, conclusion, is_overall_goal_contradiction,
showed_contradiction_instead_of_conclusion, num_embedded_supps))
{
return true;
}
}
if (conclusion == contradiction_string)
{
// I can't show a contradiction immediately, (already checked this at the beginning of this function),
// so instead go through each known statement, negate it, and see if it can be proven.
for (string current_statement: statements)
{
string negation1 = negate_by_removing_exclamation(current_statement);
string negation2 = negate_by_adding_exclamation(current_statement);
if (negation1 != "" && attempt_proof(statements, negation1, true,
showed_contradiction_instead_of_conclusion,
num_embedded_supps))
{
if (solved_base_conclusion_in_base_scope)
{
return true;
}
message = "Showed a contradiction\n";
steps_of_proof.push_back(message);
return true;
}
if (number_of_exclamation_marks_at_beginning(negation2) < 3 &&
attempt_proof(statements, negation2, true, showed_contradiction_instead_of_conclusion,
num_embedded_supps))
{
if (solved_base_conclusion_in_base_scope)
{
return true;
}
message = "Showed a contradiction\n";
steps_of_proof.push_back(message);
return true;
}
}
}
int main_operator_index_of_conclusion = get_main_operator_index(conclusion, false, ' ', false, ' ');
if (main_operator_index_of_conclusion == -1 && conclusion != contradiction_string)
{
// No main operator, and not "contradiction", so the conclusion is a single variable.
// To prove it, first see if it's in my statements vector:
if (in_vector(statements, conclusion))
{
message = "Showed " + conclusion + " by Reit\n";
steps_of_proof.push_back(message);
return true;
}
// Couldn't prove it directly, so see if I can do it via contradiction:
string negated_conclusion = negate_by_adding_exclamation(conclusion);
/*if (attempt_contradiction(statements, negated_conclusion)) {
message = "Proved " + conclusion + " via contradiction\n";
steps_of_proof.push_back(message);
return true; // proved the conclusion, since negating it implies a contradiction.
}*/
}
char main_operator = conclusion[main_operator_index_of_conclusion];
if (main_operator == '^' || main_operator == 'v')
{
string left_statement = "";
string right_statement = "";
if (main_operator == '^')
{
left_statement = get_left_statement(conclusion, '^');
right_statement = get_right_statement(conclusion, '^');
}
else if (main_operator == 'v')
{
left_statement = get_left_statement(conclusion, 'v');
right_statement = get_right_statement(conclusion, 'v');
}
bool first_reporter = false;
bool second_reporter = false;
// These will be sent by reference as the fourth parameter in the calls below.
bool first_proof = attempt_proof(statements, left_statement,
is_overall_goal_contradiction, first_reporter,
num_embedded_supps);
if (solved_base_conclusion_in_base_scope)
{
return true;
}
if (is_overall_goal_contradiction && first_reporter)
{
message = "Showed a contradiction\n";
steps_of_proof.push_back(message);
showed_contradiction_instead_of_conclusion = true;
return true;
}
if (main_operator == 'v' && first_proof)
{
message = "Proved " + conclusion + " by disjunction introduction\n";
steps_of_proof.push_back(message);
return true;
}
bool second_proof = attempt_proof(statements, right_statement,
is_overall_goal_contradiction, second_reporter,
num_embedded_supps);
if (solved_base_conclusion_in_base_scope)
{
return true;
}
if (is_overall_goal_contradiction && second_reporter)
{
message = "Showed a contradiction\n";
steps_of_proof.push_back(message);
showed_contradiction_instead_of_conclusion = true;
return true;
}
if (main_operator == '^')
{
if (first_proof && second_proof)
{
message = "Proved " + conclusion + " by conjunction introduction\n";
steps_of_proof.push_back(message);
return true;
}
}
else if (main_operator == 'v')
{
if (first_proof || second_proof)
{
message = "Proved " + conclusion + " by disjunction introduction\n";
steps_of_proof.push_back(message);
return true;
}
}
}
else if (main_operator == '!')
{
}
else if (main_operator == '>')
{
// Suppose the antecedent, and then try to prove the consequent:
string antecedent = get_stuff_before_character(conclusion, main_operator_index_of_conclusion, true);
string consequent = get_stuff_after_character(conclusion, main_operator_index_of_conclusion, true);