11
11
#include " parsing/unif.h"
12
12
#include " utils/utils.h"
13
13
14
- using namespace std ;
15
-
16
14
void print_parsing_tree (const ParsingTree< SymTok, LabTok > &pt) {
17
15
bool first = true ;
18
16
for (const auto &child : pt.children ) {
19
17
if (!first) {
20
- cout << " " ;
18
+ std:: cout << " " ;
21
19
}
22
20
print_parsing_tree (child);
23
21
first = false ;
24
22
}
25
23
if (!first) {
26
- cout << " " ;
24
+ std:: cout << " " ;
27
25
}
28
- cout << pt.children .size () << " " << pt.label ;
26
+ std:: cout << pt.children .size () << " " << pt.label ;
29
27
}
30
28
31
29
void print_trace (const ProofTree< Sentence > &pt, const LibraryToolbox &tb, const Assertion &ass) {
@@ -39,17 +37,17 @@ void print_trace(const ProofTree< Sentence > &pt, const LibraryToolbox &tb, cons
39
37
auto it = find (ass.get_ess_hyps ().begin (), ass.get_ess_hyps ().end (), pt.label );
40
38
auto parsing_tree = tb.parse_sentence (pt.sentence .begin ()+1 , pt.sentence .end (), tb.get_turnstile_alias ());
41
39
if (it == ass.get_ess_hyps ().end ()) {
42
- cout << " # " << essentials_num << " " << tb.resolve_label (pt.label ) << " " << tb.print_sentence (pt.sentence , SentencePrinter::STYLE_PLAIN) << endl;
43
- // cout << essentials_num << " " << pt.label << " " << tb.print_sentence(pt.sentence, SentencePrinter::STYLE_NUMBERS) << endl;
44
- cout << essentials_num << " " << pt.label << " " ;
40
+ std:: cout << " # " << essentials_num << " " << tb.resolve_label (pt.label ) << " " << tb.print_sentence (pt.sentence , SentencePrinter::STYLE_PLAIN) << std:: endl;
41
+ // std:: cout << essentials_num << " " << pt.label << " " << tb.print_sentence(pt.sentence, SentencePrinter::STYLE_NUMBERS) << std:: endl;
42
+ std:: cout << essentials_num << " " << pt.label << " " ;
45
43
print_parsing_tree (parsing_tree);
46
- cout << endl;
44
+ std:: cout << std:: endl;
47
45
} else {
48
- cout << " # 0 _hyp" << (it - ass.get_ess_hyps ().begin ()) << " " << tb.print_sentence (pt.sentence , SentencePrinter::STYLE_PLAIN) << endl;
49
- // cout << "0 0 " << tb.print_sentence(pt.sentence, SentencePrinter::STYLE_NUMBERS) << endl;
50
- cout << " 0 0 " ;
46
+ std:: cout << " # 0 _hyp" << (it - ass.get_ess_hyps ().begin ()) << " " << tb.print_sentence (pt.sentence , SentencePrinter::STYLE_PLAIN) << std:: endl;
47
+ // std:: cout << "0 0 " << tb.print_sentence(pt.sentence, SentencePrinter::STYLE_NUMBERS) << std:: endl;
48
+ std:: cout << " 0 0 " ;
51
49
print_parsing_tree (parsing_tree);
52
- cout << endl;
50
+ std:: cout << std:: endl;
53
51
}
54
52
}
55
53
@@ -80,14 +78,14 @@ struct ProofStat {
80
78
size_t ess_hyp_steps = 0 ;
81
79
};
82
80
83
- ostream &operator <<(ostream &os, const ProofStat &stat) {
81
+ std:: ostream &operator <<(std:: ostream &os, const ProofStat &stat) {
84
82
return os << stat.proof_size << " " << stat.ess_proof_size << " " << stat.ess_hyp_num << " " << stat.ess_hyp_steps ;
85
83
}
86
84
87
85
struct StepContext {
88
86
ParsingTree2< SymTok, LabTok > thesis;
89
- vector< ParsingTree2< SymTok, LabTok > > hypotheses;
90
- set< pair< LabTok, LabTok > > dists;
87
+ std:: vector< ParsingTree2< SymTok, LabTok > > hypotheses;
88
+ std:: set< std:: pair< LabTok, LabTok > > dists;
91
89
};
92
90
93
91
namespace boost {
@@ -107,10 +105,10 @@ struct hash< StepContext > {
107
105
108
106
struct StepProof {
109
107
LabTok label;
110
- vector< StepContext > children;
108
+ std:: vector< StepContext > children;
111
109
};
112
110
113
- unordered_map< StepContext, StepProof, boost::hash< StepContext > > mega_map;
111
+ std:: unordered_map< StepContext, StepProof, boost::hash< StepContext > > mega_map;
114
112
115
113
void proof_stat_unwind_tree (const ProofTree< Sentence > &pt, const Assertion &ass, ProofStat &stat) {
116
114
if (pt.essential ) {
@@ -133,7 +131,7 @@ int proofs_stats_main(int argc, char *argv[]) {
133
131
// auto &tb = data.tb;
134
132
135
133
TextProgressBar tpb (100 , (double ) lib.get_assertions ().size ());
136
- vector< pair< LabTok, ProofStat > > proofs_stats;
134
+ std:: vector< std:: pair< LabTok, ProofStat > > proofs_stats;
137
135
for (const Assertion &ass : lib.get_assertions ()) {
138
136
if (!ass.is_valid ()) {
139
137
continue ;
@@ -152,7 +150,7 @@ int proofs_stats_main(int argc, char *argv[]) {
152
150
// stat.proof_size = proof.get_labels().size();
153
151
stat.ess_hyp_num = ass.get_ess_hyps ().size ();
154
152
proof_stat_unwind_tree (exec->get_proof_tree (), ass, stat);
155
- proofs_stats.push_back (make_pair (ass.get_thesis (), stat));
153
+ proofs_stats.push_back (std:: make_pair (ass.get_thesis (), stat));
156
154
tpb.report (ass.get_thesis ());
157
155
}
158
156
tpb.finished ();
@@ -162,7 +160,7 @@ int proofs_stats_main(int argc, char *argv[]) {
162
160
});
163
161
164
162
for (size_t i = 0 ; i < 20 ; i++) {
165
- cout << lib.resolve_label (proofs_stats[i].first ) << " : " << proofs_stats[i].second << endl;
163
+ std:: cout << lib.resolve_label (proofs_stats[i].first ) << " : " << proofs_stats[i].second << std:: endl;
166
164
}
167
165
168
166
return 0 ;
@@ -172,14 +170,14 @@ static_block {
172
170
}
173
171
174
172
void gen_theorems (const BilateralUnificator< SymTok, LabTok > &unif,
175
- const vector< ParsingTree2< SymTok, LabTok > > &open_hyps,
176
- const vector< LabTok > &steps,
173
+ const std:: vector< ParsingTree2< SymTok, LabTok > > &open_hyps,
174
+ const std:: vector< LabTok > &steps,
177
175
size_t hyps_pos,
178
- const vector< const Assertion* > &useful_asses,
176
+ const std:: vector< const Assertion* > &useful_asses,
179
177
const ParsingTree2< SymTok, LabTok > &final_thesis,
180
178
LibraryToolbox &tb,
181
179
size_t depth,
182
- const function< void (const ParsingTree2< SymTok, LabTok >&, const vector< ParsingTree2< SymTok, LabTok > >&, const vector< LabTok >&, LibraryToolbox&)> &callback) {
180
+ const std:: function< void (const ParsingTree2< SymTok, LabTok >&, const std:: vector< ParsingTree2< SymTok, LabTok > >&, const std:: vector< LabTok >&, LibraryToolbox&)> &callback) {
183
181
if (depth == 0 || hyps_pos == open_hyps.size ()) {
184
182
auto unif2 = unif;
185
183
SubstMap2< SymTok, LabTok > subst;
@@ -189,7 +187,7 @@ void gen_theorems(const BilateralUnificator< SymTok, LabTok > &unif,
189
187
return ;
190
188
}
191
189
auto thesis = substitute2 (final_thesis, tb.get_standard_is_var (), subst);
192
- vector< ParsingTree2< SymTok, LabTok > > hyps;
190
+ std:: vector< ParsingTree2< SymTok, LabTok > > hyps;
193
191
for (const auto &hyp : open_hyps) {
194
192
hyps.push_back (substitute2 (hyp, tb.get_standard_is_var (), subst));
195
193
}
@@ -200,14 +198,14 @@ void gen_theorems(const BilateralUnificator< SymTok, LabTok > &unif,
200
198
tb.new_temp_var_frame ();
201
199
const Assertion &ass = *assp;
202
200
ParsingTree2< SymTok, LabTok > thesis;
203
- vector< ParsingTree2< SymTok, LabTok > > hyps;
201
+ std:: vector< ParsingTree2< SymTok, LabTok > > hyps;
204
202
tie (hyps, thesis) = tb.refresh_assertion2 (ass);
205
203
auto unif2 = unif;
206
204
auto steps2 = steps;
207
205
unif2.add_parsing_trees2 (open_hyps[hyps_pos], thesis);
208
206
steps2.push_back (ass.get_thesis ());
209
207
if (unif2.is_unifiable ()) {
210
- // cout << "Attaching " << tb.resolve_label(ass.get_thesis()) << " in position " << hyps_pos << endl;
208
+ // std:: cout << "Attaching " << tb.resolve_label(ass.get_thesis()) << " in position " << hyps_pos << std:: endl;
211
209
auto open_hyps2 = open_hyps;
212
210
open_hyps2.erase (open_hyps2.begin () + hyps_pos);
213
211
open_hyps2.insert (open_hyps2.end (), hyps.begin (), hyps.end ());
@@ -219,17 +217,17 @@ void gen_theorems(const BilateralUnificator< SymTok, LabTok > &unif,
219
217
}
220
218
221
219
size_t count = 0 ;
222
- void print_theorem (const ParsingTree2< SymTok, LabTok > &thesis, const vector< ParsingTree2< SymTok, LabTok > >&hyps, const vector< LabTok > &steps, LibraryToolbox &tb) {
220
+ void print_theorem (const ParsingTree2< SymTok, LabTok > &thesis, const std:: vector< ParsingTree2< SymTok, LabTok > >&hyps, const std:: vector< LabTok > &steps, LibraryToolbox &tb) {
223
221
::count++;
224
222
bool finished = hyps.empty ();
225
223
if (::count % 10000 == 0 || finished) {
226
- cout << ::count << endl;
227
- cout << tb.print_sentence (thesis) << endl;
228
- cout << " with the hypotheses:" << endl;
224
+ std:: cout << ::count << std:: endl;
225
+ std:: cout << tb.print_sentence (thesis) << std:: endl;
226
+ std:: cout << " with the hypotheses:" << std:: endl;
229
227
for (const auto &hyp : hyps) {
230
- cout << " * " << tb.print_sentence (hyp) << endl;
228
+ std:: cout << " * " << tb.print_sentence (hyp) << std:: endl;
231
229
}
232
- cout << " Proved with steps: " << tb.print_proof (steps) << endl;
230
+ std:: cout << " Proved with steps: " << tb.print_proof (steps) << std:: endl;
233
231
}
234
232
if (finished) {
235
233
exit (0 );
@@ -240,8 +238,8 @@ void print_theorem(const ParsingTree2< SymTok, LabTok > &thesis, const vector< P
240
238
}
241
239
242
240
int gen_random_theorems_main (int argc, char *argv[]) {
243
- random_device rand_dev;
244
- mt19937 rand_mt;
241
+ std:: random_device rand_dev;
242
+ std:: mt19937 rand_mt;
245
243
rand_mt.seed (rand_dev ());
246
244
247
245
auto &data = get_set_mm ();
@@ -253,7 +251,7 @@ int gen_random_theorems_main(int argc, char *argv[]) {
253
251
// LabTok target_label = lib.get_label(target_label_str);
254
252
// auto target_pt = tb.get_parsed_sents2()[target_label];
255
253
256
- ostringstream oss;
254
+ std:: ostringstream oss;
257
255
for (int i = 1 ; i < argc; i++) {
258
256
oss << argv[i] << " " ;
259
257
}
@@ -262,27 +260,27 @@ int gen_random_theorems_main(int argc, char *argv[]) {
262
260
auto target_pt = pt_to_pt2 (target_pt1);
263
261
LabTok target_label = 0 ;
264
262
265
- vector< const Assertion* > useful_asses;
263
+ std:: vector< const Assertion* > useful_asses;
266
264
for (const auto &ass : lib.get_assertions ()) {
267
265
if (ass.is_valid () && lib.get_sentence (ass.get_thesis ()).at (0 ) == tb.get_turnstile ()) {
268
266
/* if (ass.get_thesis() >= target_label) {
269
267
break;
270
268
}*/
271
269
if (ass.is_theorem () && ass.has_proof () && ass.get_proof_operator (lib)->is_trivial ()) {
272
- // cout << "Proof for " << lib.resolve_label(ass.get_thesis()) << " is trivial" << endl;
270
+ // std:: cout << "Proof for " << lib.resolve_label(ass.get_thesis()) << " is trivial" << std:: endl;
273
271
} else {
274
272
if (ass.get_thesis () != target_label && ass.get_thesis ()) {
275
273
useful_asses.push_back (&ass);
276
274
}
277
275
}
278
276
}
279
277
}
280
- sort (useful_asses.begin (), useful_asses.end (), [&lib](const auto &x, const auto &y) {
278
+ std:: sort (useful_asses.begin (), useful_asses.end (), [&lib](const auto &x, const auto &y) {
281
279
return x->get_ess_hyps ().size () < y->get_ess_hyps ().size () || (x->get_ess_hyps ().size () == y->get_ess_hyps ().size () && lib.get_sentence (x->get_thesis ()).size () > lib.get_sentence (y->get_thesis ()).size ());
282
280
});
283
- cout << " There are " << useful_asses.size () << " useful assertions" << endl;
281
+ std:: cout << " There are " << useful_asses.size () << " useful assertions" << std:: endl;
284
282
285
- set< LabTok > target_vars;
283
+ std:: set< LabTok > target_vars;
286
284
collect_variables2 (target_pt, standard_is_var, target_vars);
287
285
std::function< bool (LabTok) > is_var = [&target_vars,&standard_is_var](LabTok x) {
288
286
if (target_vars.find (x) != target_vars.end ()) {
@@ -292,26 +290,26 @@ int gen_random_theorems_main(int argc, char *argv[]) {
292
290
};
293
291
294
292
BilateralUnificator< SymTok, LabTok > unif (is_var);
295
- vector< ParsingTree2< SymTok, LabTok > > open_hyps;
293
+ std:: vector< ParsingTree2< SymTok, LabTok > > open_hyps;
296
294
LabTok th_label;
297
- tie (th_label, ignore) = tb.new_temp_var (tb.get_turnstile_alias ());
295
+ std:: tie (th_label, std:: ignore) = tb.new_temp_var (tb.get_turnstile_alias ());
298
296
ParsingTree2< SymTok, LabTok > final_thesis = var_parsing_tree (th_label, tb.get_turnstile_alias ());
299
297
final_thesis = target_pt;
300
298
open_hyps.push_back (final_thesis);
301
- vector< LabTok > steps;
299
+ std:: vector< LabTok > steps;
302
300
303
301
gen_theorems (unif, open_hyps, steps, 0 , useful_asses, final_thesis, tb, 2 , print_theorem);
304
302
return 0 ;
305
303
306
304
for (size_t i = 0 ; i < 5 ; i++) {
307
305
if (open_hyps.empty ()) {
308
- cout << " Terminating early" << endl;
306
+ std:: cout << " Terminating early" << std:: endl;
309
307
break ;
310
308
}
311
309
while (true ) {
312
310
// Select a random hypothesis, a random open hypothesis and let them match
313
- size_t ass_idx = uniform_int_distribution< size_t >(0 , useful_asses.size ()-1 )(rand_mt);
314
- size_t hyp_idx = uniform_int_distribution< size_t >(0 , open_hyps.size ()-1 )(rand_mt);
311
+ size_t ass_idx = std:: uniform_int_distribution< size_t >(0 , useful_asses.size ()-1 )(rand_mt);
312
+ size_t hyp_idx = std:: uniform_int_distribution< size_t >(0 , open_hyps.size ()-1 )(rand_mt);
315
313
const Assertion &ass = *useful_asses[ass_idx];
316
314
if (i == 0 && ass.get_ess_hyps ().size () == 0 ) {
317
315
continue ;
@@ -320,12 +318,12 @@ int gen_random_theorems_main(int argc, char *argv[]) {
320
318
continue ;
321
319
}
322
320
ParsingTree2< SymTok, LabTok > thesis;
323
- vector< ParsingTree2< SymTok, LabTok > > hyps;
321
+ std:: vector< ParsingTree2< SymTok, LabTok > > hyps;
324
322
tie (hyps, thesis) = tb.refresh_assertion2 (ass);
325
323
auto unif2 = unif;
326
324
unif2.add_parsing_trees2 (open_hyps[hyp_idx], thesis);
327
325
if (unif2.unify2 ().first ) {
328
- cout << " Attaching " << tb.resolve_label (ass.get_thesis ()) << " in position " << hyp_idx << endl;
326
+ std:: cout << " Attaching " << tb.resolve_label (ass.get_thesis ()) << " in position " << hyp_idx << std:: endl;
329
327
unif = unif2;
330
328
open_hyps.erase (open_hyps.begin () + hyp_idx);
331
329
open_hyps.insert (open_hyps.end (), hyps.begin (), hyps.end ());
@@ -339,14 +337,14 @@ int gen_random_theorems_main(int argc, char *argv[]) {
339
337
tie (res, subst) = unif.unify2 ();
340
338
341
339
if (res) {
342
- cout << " Unification succedeed and proved:" << endl;
343
- cout << tb.print_sentence (substitute2 (final_thesis, tb.get_standard_is_var (), subst)) << endl;
344
- cout << " with the hypotheses:" << endl;
340
+ std:: cout << " Unification succedeed and proved:" << std:: endl;
341
+ std:: cout << tb.print_sentence (substitute2 (final_thesis, tb.get_standard_is_var (), subst)) << std:: endl;
342
+ std:: cout << " with the hypotheses:" << std:: endl;
345
343
for (const auto &hyp : open_hyps) {
346
- cout << " * " << tb.print_sentence (substitute2 (hyp, tb.get_standard_is_var (), subst)) << endl;
344
+ std:: cout << " * " << tb.print_sentence (substitute2 (hyp, tb.get_standard_is_var (), subst)) << std:: endl;
347
345
}
348
346
} else {
349
- cout << " Unification failed" << endl;
347
+ std:: cout << " Unification failed" << std:: endl;
350
348
}
351
349
352
350
return 0 ;
0 commit comments