-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.js
More file actions
159 lines (130 loc) · 3.61 KB
/
core.js
File metadata and controls
159 lines (130 loc) · 3.61 KB
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
"use strict"
// this is a somewhat more elegant (and maybe faster?) rewrite of main.js. it's not finished yet.
class Struc // as in: algebraic structure. a set of operations defined on a set of operands
{
constructor (opArray = []) {this.a = opArray}
//get op
static fromString (opString, separators = [","," ",""])
{
struc = new Struc ()
for (var singleOp of opString.split(separators[0]))
struc.opFromString (singleOp, separators.slice(1))
return struc
}
opFromString (opString, separators = [","," ",""])
{
splitRecursive (splitString, separators)
{
var content = []; var depth = 0
if (depth < separators.length)
for (var substring of splitString.split (separators [0]))
content.push
(Struc.splitRecursive (substring, separators.slice(1)))
else content = splitString
return content
}
this.a.push (splitRecursive (opString, separators))
}
static fromNum (opNumS, width = 3, depht = 2)
{
var struc = new Struc ()
if (Array.isArray (opNumS))
for (var opNum of opNum) struc.opFromNum (opNum, width, depht)
else struc.opFromNum (opNumS, width, depht)
return struc
}
opFromNum (opNum, width = 3, depht = 2)
{
//const cellNum = Math.pow(width, depht)
var op = []; var cellCount = 0
function fillCellsRecursive (number, width, depht, offset)
{
//if
var array = []
var count = offset
while (count < depht)
{
number
count++
}
return array
}
}
depth (index = 0, current = this.a)
{
if (Array.isArray(current))
return this.depth (0, current [0]) + 1
else return 0
}
width (index = 0) { return this.a[index].length }
lookup (path = [], current = this.a)
{
if (path.length == 0) return current
{
return this.lookup
(path.slice(1), current [path [0]])
}
}
}
class Term // in postfix notation: operators after operand. this makes parentheses and precedence rules unnessecary.
{
constructor (termArray = [], depth = 2)
{ this.a = termArray; this.depth = depth }
step (struc, stack = [], progress = 0)
{
if (this.a[progress] < 0) // negative numbers are operators
{
const op = -1 - this.a [progress]
const path = [op].concat (stack.splice (- this.depth))
stack.push (struc.lookup (path))
}
else stack.push (this.a[progress])
return stack
}
evaluate (struc)
{
var progress = 0; var stack = []
while (progress < this.a.length)
stack = this.step (struc, stack, progress ++)
return stack
}
isEqual (struc)
{
var stack = this.evaluate(struc)
var result = true
for (var element of stack)
result = result && stack[0] == element
return result
}
}
class Property // algebraic property, defined by equalities and logical quantors
{
constructor (propertyArray, quantors, depth = 2)
{ this.a = propertyArray; this.quantors = quantors; this.depth = depth }
static fromString (propString, depth = 2)
{
// lower case for existance claims, upper case for universal claims. variables are evaluated in alphabeitical order
const lower = "abcdefghijklmnopqrstuvwxyz"
const upper = lower.toUpperCase()
const opSymbols = "*+/-&|%$"
var quantCount = 0; var quantors = []
while (quantCount < lower.length)
{
if (propString.includes (lower[quantCount]))
quantors.push (false)
else if (propString.includes (upper[quantCount]))
quantors.push (true)
else break
quantCount++
}
var propArray = propString.split("")
var opCount = 0; var index
while (propString.includes (opSymbols[opCount]))
{
index = propArray.indexOf(opSymbols[opCount])
if (index > 0) propArray [index] = -1 - opCount
else opCount ++
}
return new Property (propArray, quantors, depth)
}
}