-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathterms_lib.h
74 lines (57 loc) · 1.97 KB
/
terms_lib.h
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
// Copyright 2021 Oganyan Robert
#ifndef OGANYAN_LAMBDA_CALC_TERMS_LIB_H
#define OGANYAN_LAMBDA_CALC_TERMS_LIB_H
#include <iostream>
#include <string>
#include <map>
using std::map;
using std::string;
class LibFuncs {
private:
map<string, string> functions;
public:
LibFuncs() {
// Logical functions
functions["True"] = "(\\t (\\f t))";
functions["False"] = "(\\t (\\f f))";
functions["If"] = "(\\b (\\x (\\y b x y)))";
functions["And"] = "(\\b (\\c b c False))";
functions["Or"] = "(\\b (\\c b True c))";
functions["Not"] = "(\\b b False True)";
functions["IsZero"] = "(\\n n (\\c False) True)";
// Nums
functions["Zero"] = "(\\s (\\z z))";
functions["One"] = "(\\s (\\z s z))";
functions["Two"] = "(\\s (\\z s (s z)))";
// Arithmetic functions
functions["Scc"] = "(\\n (\\s (\\z s (n s z))))";
functions["Plus"] = "(\\n (\\m (\\s (\\z (n s (m s z))))))";
functions["Mult"] = "(\\n (\\m (\\s n (m s))))";
functions["Pow"] = "(\\n (\\m (\\s (\\ z (n s z)))))";
// Combinators
functions["I"] = "(\\x x)";
functions["S"] = "(\\f (\\g (\\x f x (g x))))";
functions["K"] = "(\\x (\\y x))";
functions["Omega"] = "((\\x x x)(\\x x x))";
functions["B"] = "(\\f (\\g (\\x f (g x))))";
functions["C"] = "(\\f (\\x (\\y f y x)))";
functions["V"] = "(\\x (\\y x y y))";
// Pairs
functions["Pair"] = "(\\f (\\s (\\b b f s)))";
functions["First"] = "(\\p p True)";
functions["Second"] = "(\\p p False)";
}
bool exist(const string &str) const {
return (functions.find(str) != functions.end());
}
// Not string& to avoid changing data
string operator[](const string &index) {
if (exist(index)) {
return functions[index];
}
else {
return "";
}
}
};
#endif //OGANYAN_LAMBDA_CALC_TERMS_LIB_H