-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
146 lines (113 loc) · 4.19 KB
/
main.go
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
// TOGO from here:
// 1. time spending analysis in _Merge
// 2. GoRoutins
// 3. Input Related Behavior
// 4. Rasterizations(DFS)
package main
import (
"GoHilbert/propositional"
"fmt"
"time"
"github.com/dghubble/trie"
"github.com/sbwhitecap/tqdm"
)
var ProofPatterns [][]*propositional.Formula
var PatternsTrie *trie.PathTrie
var TimeOfBasicArrowCheck int64;
var TimeOfArrowDestruction int64;
var TimeOfHardCopy int64;
var TimeOfAtomRespacing int64;
var TimeOfDecomposition int64;
var TimeOfFinalPush int64;
var inMergeTime int64;
func _Merge(order int, A *propositional.Formula, A_then_C *propositional.Formula) {
// fmt.Println("Checking:", A, " and ", A_then_C)
overallCheckpoint := time.Now()
checkpoint := time.Now()
decomposition, err := propositional.DestructWithString(A_then_C, "((Ant)>(Con))");
if err != nil {
return;
}
antecedent := decomposition["Ant"]
consequent := decomposition["Con"]
TimeOfBasicArrowCheck += time.Since(checkpoint).Microseconds()
checkpoint = time.Now()
if _, err := propositional.Destruct(A, antecedent); err != nil {
return
}
TimeOfArrowDestruction += time.Since(checkpoint).Microseconds()
checkpoint = time.Now()
// make sure to make a new formula tree
A_then_C, _ = propositional.CopyFormula(A_then_C)
propositional.NewIdentifiers(A_then_C, "Q_TMP_")
TimeOfHardCopy += time.Since(checkpoint).Microseconds()
checkpoint = time.Now()
decomposition, _ = propositional.DestructWithString(A_then_C, "((Ant)>(Con))")
antecedent = decomposition["Ant"]
consequent = decomposition["Con"]
replacementMap, err := propositional.Destruct(A, antecedent);
if err != nil {
return
}
propositional.ReplaceAtoms(consequent, &replacementMap)
TimeOfAtomRespacing += time.Since(checkpoint).Microseconds()
checkpoint = time.Now()
consequent, err = propositional.CopyFormula(consequent)
propositional.NewIdentifiers(consequent, "P")
if err != nil {
return
}
TimeOfDecomposition += time.Since(checkpoint).Microseconds()
checkpoint = time.Now()
if PatternsTrie.Get(consequent.String()) != nil {
return
}
PatternsTrie.Put(consequent.String(), true)
// fmt.Printf("New Pattern at order=%v --> %v\n", order, consequent)
ProofPatterns[order] = append(ProofPatterns[order], consequent)
TimeOfFinalPush += time.Since(checkpoint).Microseconds()
checkpoint = time.Now()
inMergeTime += time.Since(overallCheckpoint).Microseconds()
}
func Merge(order int, X *propositional.Formula, Y *propositional.Formula) {
_Merge(order, X, Y)
_Merge(order, Y, X)
}
func main() {
PatternsTrie = trie.NewPathTrie()
ProofPatterns = make([][]*propositional.Formula, 10)
Axiom1, _ := propositional.NewFormula("((A)>((B)>(A)))")
Axiom2, _ := propositional.NewFormula("(((A)>((B)>(C)))>(((A)>(B))>((A)>(C))))")
ProofPatterns[0] = append(ProofPatterns[0],
Axiom1,
Axiom2,
)
PatternsTrie.Put(Axiom1.String(), true)
PatternsTrie.Put(Axiom2.String(), true)
for order := 1; order < 6; order++ {
start := time.Now()
iterations := 0
// below line is similar to --> for idx, P1 := range ProofPatterns[order - 1] {
tqdm.R(0, len(ProofPatterns[order - 1]), func(idx interface{}) (brk bool) {
P1 := ProofPatterns[order - 1][idx.(int)]
for i := 0; i < order - 1; i++ {
for _, P2 := range ProofPatterns[i] {
iterations++
Merge(order, P1, P2)
}
}
for i := 0; i <= idx.(int); i++ {
iterations++
Merge(order, P1, ProofPatterns[order - 1][i])
}
return false;
});
elapsed := time.Since(start).Milliseconds()
fmt.Println("-----------------------------------------------------------------------------------------------")
fmt.Printf("Finalizing order %v at %v members took %v for %v iterations\n", order, len(ProofPatterns[order]), elapsed, iterations)
fmt.Printf("--Time Analysis--\nTimeOfBasicArrowCheck: %v\nTimeOfArrowDestruction: %v\nTimeOfHardCopy: %v\nTimeOfAtomRespacing: %v\nTimeOfDecomposition: %v\nTimeOfFinalPush: %v\n", TimeOfBasicArrowCheck, TimeOfArrowDestruction, TimeOfHardCopy, TimeOfAtomRespacing, TimeOfDecomposition, TimeOfFinalPush)
fmt.Printf("OVERALL IN FUNCTION TIME: %v\n", inMergeTime)
fmt.Println("===============================================================================================")
fmt.Println("")
}
}