-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathTON-DRP.js
More file actions
112 lines (112 loc) · 4.2 KB
/
TON-DRP.js
File metadata and controls
112 lines (112 loc) · 4.2 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
//Encoding: -1 for '0', 0 for 'W', [b,a,-2] for C(a,b), x[1] for left part, x[0] for right part
register.push({
id:'ton-drp'
,name:'Degrees of Reflection with Passthrough'
,able:TON_limit
,compare:TON_noraise_compare
,display:TON_noraise_display
,FS:(()=>{
var data={}
,DRPStd={}
,smallpart = term=>{
var sow_smallpart = a=>{
if(a===0) return;
if(TON_noraise_compare(a,0)<0){
result.push(a)
}else{
sow_smallpart(a[0])
sow_smallpart(a[1])
}
}
,result=[]
sow_smallpart(term)
return result
}
,BuiltQ = (a,ai,b,a0,d)=>{
if(a===0||TON_noraise_compare(a,b)<0) return true
if(d===-1&&TON_noraise_compare(a,0)<0&&TON_noraise_compare(a,ai)>0) return false
if(TON_noraise_compare(a,d)<0) return BuiltQ(a,ai,b,a0,-1)
if(d===-1&&TON_noraise_compare(a[0],0)<0&&TON_noraise_compare(a[1],a0)<0) return BuiltQ(a,ai,b,a0,a)
return BuiltQ(a[0],ai,b,a0,d)&&BuiltQ(a[1],ai,b,a0,d)
}
,StandardQ = a=>{
var str = JSON.stringify(a)
if(DRPStd[str]){
return DRPStd[str]
}else if(typeof a==='number' || (StandardQ(a[1])&&StandardQ(a[0]) && (typeof a[0]==='number'||TON_noraise_compare(a[1],a[0][1])<=0) &&
smallpart(a[1]).every(x=>BuiltQ(x,x,a,a[1],-1)))){
return DRPStd[str]=true
}else{
return false
}
}
,Copy = x=>typeof x==='number'?x:[Copy(x[0]),Copy(x[1]),-2]
,TON = function*(term){
var flag=true,c1,c3
,n=0
,beta = Copy(term)
,len = (''+term).split(',').length
mainloop:while(true){
if(flag){
if(typeof beta==='number'&&beta>=0){ //gamma = 'W', m = 0, assuming beta != '0'
beta=-1
}else if(beta[1]===-1){ //gamma = '0', m = 1
beta=beta[0]
continue
}else if(typeof beta[1]==='number'&&beta[1]>=0){ //gamma = 'W', m = 1
beta[1]=-1
}else if(beta[1][1]===-1){ //gamma = '0', m = 2
beta=[[beta[0],beta[1][0],-2],0,-2]
}else if(typeof beta[1][1]==='number'&&beta[1][1]>=0){//gamma = 'W', m = 2
beta[1][1]=-1
}else{ //m > 2, the main part of step 1 and 2
c3=beta
c1=beta[1][1]
while(typeof c1[1]!=='number'){
c3=c3[1]
c1=c1[1]
}
if(c1[1]===-1){ //gamma = '0', m > 2
c3[1]=[[c3[1][0],c1[0],-2],0,-2]
}else{ //gamma = 'W', m > 2
c1[1]=-1
}
}
}
flag=true
while((''+beta).split(',').length<len+n*2){//better step 3
if(!StandardQ(beta)) continue mainloop
if(typeof beta!=='number'){
c1=beta
while(typeof c1[1]!=='number')c1=c1[1] //step 4
c1[1]=[c1[1],0,-2] //step 5
}else{
beta=[beta,0,-2] //step 4 and 5 for beta = '0' and 'W'
}
}
if(StandardQ(beta)){
n = yield Copy(beta)
flag=false
}
}
}
return (term,n)=>{
if(''+term==='Infinity'){
term = [-1,0,-2]
}
var datakey=''+term
,dataterm = data[datakey]
if(!dataterm){
dataterm = (data[datakey] = [])
dataterm.gen = TON(term)
dataterm[0] = dataterm.gen.next().value
}
if(dataterm[n]!==undefined) return dataterm[n]
return dataterm[n] = dataterm.gen.next(n).value
}
})()
,init:()=>[
{expr:Infinity,low:[-1],subitems:[]}
,{expr:-1,low:[-1],subitems:[]}
]
})