This commit is contained in:
AF 2021-07-24 18:08:13 +03:00
parent 105ec294d3
commit dac9ccf109
58 changed files with 505 additions and 413 deletions

110
main.py
View File

@ -1,4 +1,5 @@
# Copyright (c) PARRRATE T&V 2021. All rights reserved. # Copyright (c) PARRRATE T&V 2021. All rights reserved.
import math
import random import random
from bu4.common_interface import with_common_interface from bu4.common_interface import with_common_interface
@ -8,56 +9,59 @@ from bu4.evaluation.synced import synced
from bu4.parsing.toolchain.readfile import readfile from bu4.parsing.toolchain.readfile import readfile
from timesample import TimeSample from timesample import TimeSample
with TimeSample(' compilation'):
sys0 = synced(readfile('src/sys0')) with TimeSample('all'):
with TimeSample(' first, AP'): with TimeSample('sys0'):
print( with TimeSample('compilation'):
antiproxy(sys0)(0)(1)( sys0 = synced(readfile('src/sys0'))
lambda a: lambda b: a + b with TimeSample('first, AP'):
)( TimeSample.print(
lambda n: lambda x: lambda y: x if n == 0 else y antiproxy(sys0)(0)(1)(
)( lambda a: lambda b: a + b
lambda n: lambda x: lambda y: x if n & 1 else y )(
)( lambda n: lambda x: lambda y: x if n == 0 else y
lambda n: n >> 1 )(
) lambda n: lambda x: lambda y: x if n & 1 else y
) )(
with TimeSample(' second, AP'): lambda n: n >> 1
print( )
antiproxy(sys0)(0)(1)( )
lambda a: lambda b: a + b with TimeSample('second, AP'):
)( TimeSample.print(
lambda n: lambda x: lambda y: x if n == 0 else y antiproxy(sys0)(0)(1)(
)( lambda a: lambda b: a + b
lambda n: lambda x: lambda y: x if n & 1 else y )(
)( lambda n: lambda x: lambda y: x if n == 0 else y
lambda n: n >> 1 )(
) lambda n: lambda x: lambda y: x if n & 1 else y
) )(
with TimeSample(' third, EP'): lambda n: n >> 1
sys0 = with_common_interface(sys0) )
print(sys0) )
with TimeSample(' sys2'): with TimeSample('third, EP'):
with TimeSample(' compilation'): sys0 = with_common_interface(sys0)
sys2c = synced(readfile('src/sys2')) TimeSample.print(sys0)
with TimeSample(' runtime'): with TimeSample('sys2'):
sys2 = sys2c with TimeSample('compilation'):
sys2 = with_common_interface(sys2) sys2c = synced(readfile('src/sys2'))
print(sys2) with TimeSample('runtime'):
with TimeSample(' runtime'): sys2 = sys2c
sys2 = sys2c sys2 = with_common_interface(sys2)
sys2 = with_common_interface(sys2) TimeSample.print(sys2)
print(sys2) with TimeSample('runtime'):
with TimeSample(' full'): sys2 = sys2c
sys3 = with_common_interface(synced(readfile('src/sys3'))) sys2 = with_common_interface(sys2)
sys3 = sync(sys3.call(eproxy(5))) TimeSample.print(sys2)
print(sys3) with TimeSample('sys3'):
with TimeSample(' full'): sys3 = with_common_interface(synced(readfile('src/sys3')))
sys1 = with_common_interface(synced(readfile('src/sys1'))) sys3 = sync(sys3.call(eproxy(5)))
a_ = random.randrange(2 ** 64) TimeSample.print(sys3)
b_ = random.randrange(2 ** 64) with TimeSample('sys1'):
sys1 = sync(sys1.call(eproxy(a_))) sys1 = with_common_interface(synced(readfile('src/sys1')))
sys1 = sync(sys1.call(eproxy(b_))) a_ = random.randrange(2 ** 16)
print(sys1, b_ % a_) b_ = random.randrange(2 ** 16)
with TimeSample(' full'): sys1 = sync(sys1.call(eproxy(a_)))
print(with_common_interface(synced(readfile('src/sys4')))) sys1 = sync(sys1.call(eproxy(b_)))
TimeSample.print(sys1, math.gcd(a_, b_))
with TimeSample('sys4'):
TimeSample.print(with_common_interface(synced(readfile('src/sys4'))))

View File

@ -5,4 +5,5 @@
@io/@ @io/@
@serialization/@ @serialization/@
@collections/@ @collections/@
@math/@
@numbers @numbers

View File

@ -1,7 +1,6 @@
@b! @b!
@01 @01
@add @zq
@mul @double
@sub @bitwise/@
@bitwise @arithmetic/@
@div

View File

@ -0,0 +1,4 @@
@add
@mul
@sub
@div

View File

@ -1,6 +1,3 @@
{ (b) </[b]/[0][b!]> | b_double }
{ (b) </ <(zq)(lb)(hb!) [hb!]> [b]> | b_halve }
{ {
/(b_add) /(b_add)
(bA)(bB) (bA)(bB)

View File

@ -0,0 +1,42 @@
{
{
(bD)
/(b_div)
(zqN)(lbN)(hb!N)
/
/(hQ)(hR)
{ /[hR]/[lbN][b!] | bR }
/(bRD)(bDR)
/(zqDR)(lbDR-unused)(hb!DR-unused)
/
/
[bR]
/
/[hQ]/[0][b!]
[pair]
/
/
[bRD]
/
/[hQ]/[1][b!]
[pair]
[zqDR]
[bDR]
/[bD]/[bR][b_sub]
</[b_div][hb!N]>
/
/
[b0]
/
[b0]
[pair]
[zqN]
[YC]
|
b_div
}
(bD)(bN)
//[bD][b_div][bN]
|
b_div
}

View File

@ -1,99 +0,0 @@
{
/(b_and)
(bA)(bB)
/(zqA)(lbA)(hb!A)
/
/(zqB)(lbB)(hb!B)
/
/
/[hb!B]/[hb!A][b_and]
/
/[lbB]/[lbA][and]
[b!]
/
[b0]
[zqB]
[bB]
/
[b0]
[zqA]
[bA]
[YC]
|
b_and
}
{
/(b_or)
(bA)(bB)
/(zqA)(lbA)(hb!A)
/
/(zqB)(lbB)(hb!B)
/
/
/[hb!B]/[hb!A][b_or]
/
/[lbB]/[lbA][or]
[b!]
/
[bA]
[zqB]
[bB]
/
[bB]
[zqA]
[bA]
[YC]
|
b_or
}
{
/(b_xor)
(bA)(bB)
/(zqA)(lbA)(hb!A)
/
/(zqB)(lbB)(hb!B)
/
/
/[hb!B]/[hb!A][b_xor]
/
/[lbB]/[lbA][xor]
[b!]
/
[bA]
[zqB]
[bB]
/
[bB]
[zqA]
[bA]
[YC]
|
b_xor
}
{
/(b_exclude)
(bA)(bB)
/(zqA)(lbA)(hb!A)
/
/(zqB)(lbB)(hb!B)
/
/
/[hb!B]/[hb!A][b_exclude]
/
/</[lbB][not]>/[lbA][and]
[b!]
/
[bA]
[zqB]
[bB]
/
[b0]
[zqA]
[bA]
[YC]
|
b_exclude
}

4
src/binary/bitwise/@.bu4 Normal file
View File

@ -0,0 +1,4 @@
@and
@or
@xor
@exclude

View File

@ -0,0 +1,24 @@
{
/(b_and)
(bA)(bB)
/(zqA)(lbA)(hb!A)
/
/(zqB)(lbB)(hb!B)
/
/
/[hb!B]/[hb!A][b_and]
/
/[lbB]/[lbA][and]
[b!]
/
[b0]
[zqB]
[bB]
/
[b0]
[zqA]
[bA]
[YC]
|
b_and
}

View File

@ -0,0 +1,24 @@
{
/(b_exclude)
(bA)(bB)
/(zqA)(lbA)(hb!A)
/
/(zqB)(lbB)(hb!B)
/
/
/[hb!B]/[hb!A][b_exclude]
/
/</[lbB][not]>/[lbA][and]
[b!]
/
[bA]
[zqB]
[bB]
/
[b0]
[zqA]
[bA]
[YC]
|
b_exclude
}

24
src/binary/bitwise/or.bu4 Normal file
View File

@ -0,0 +1,24 @@
{
/(b_or)
(bA)(bB)
/(zqA)(lbA)(hb!A)
/
/(zqB)(lbB)(hb!B)
/
/
/[hb!B]/[hb!A][b_or]
/
/[lbB]/[lbA][or]
[b!]
/
[bA]
[zqB]
[bB]
/
[bB]
[zqA]
[bA]
[YC]
|
b_or
}

View File

@ -0,0 +1,24 @@
{
/(b_xor)
(bA)(bB)
/(zqA)(lbA)(hb!A)
/
/(zqB)(lbB)(hb!B)
/
/
/[hb!B]/[hb!A][b_xor]
/
/[lbB]/[lbA][xor]
[b!]
/
[bA]
[zqB]
[bB]
/
[bB]
[zqA]
[bA]
[YC]
|
b_xor
}

View File

@ -1,36 +0,0 @@
{
(bD)
/(b_div)
(zqN)(lbN)(hb!N)
/
/(hQ)(hR)
{ /[hR]/[lbN][b!] | bR }
/(bRD)(bDR)
/(zqDR)(lbDR-unused)(hb!DR-unused)
/
/
[bR]
/
/[hQ]/[0][b!]
[pair]
/
/
[bRD]
/
/[hQ]/[1][b!]
[pair]
[zqDR]
[bDR]
/[bD]/[bR][b_sub]
</[b_div][hb!N]>
/
/
[b0]
/
[b0]
[pair]
[zqN]
[YC]
|
b_div
}

2
src/binary/double.bu4 Normal file
View File

@ -0,0 +1,2 @@
{ (b) </[b]/[0][b!]> | b_double }
{ (b) </ <(zq)(lb)(hb!) [hb!]> [b]> | b_halve }

8
src/binary/zq.bu4 Normal file
View File

@ -0,0 +1,8 @@
{
(b)
/(zq)(lb)(hb!)
[zq]
[b]
|
b_zq
}

View File

@ -1,2 +1,3 @@
@01 @01
@add @add
@double

View File

@ -1,2 +1 @@
{ (cA)(cB)(f)(x) //[x]</[f][cA]></[f][cB]> | c_add } { (cA)(cB)(f)(x) //[x]</[f][cA]></[f][cB]> | c_add }
{ (c) /[c]/[c][c_add] | c_double }

View File

@ -0,0 +1 @@
{ (c) /[c]/[c][c_add] | c_double }

View File

@ -1,3 +1,3 @@
(n0)(n1)(n_add)(n_zq)(n_lb)(n_h) (n0)(n1)(n_add)(n_zq)(n_lb)(n_h)
{ /[n_add]/[n1]/[n0] [b_to_n] | b_to_nx } { /[n_add]/[n1]/[n0] [_b_to_n] | b_to_n }
{ /[n_h]/[n_lb]/[n_zq][n_to_b] | n_to_bx } { /[n_h]/[n_lb]/[n_zq][_n_to_b] | n_to_b }

View File

@ -1 +1 @@
@deque @deque/@

View File

@ -1,96 +0,0 @@
{ (g) /? /? /? /? /[1][g] | dequeEmpty }
{ (item) (g) /[item]/[dequeEmpty]/[item]/[dequeEmpty]/[0][g] | dequeSingle }
{
(isEmpty)(lPopped)(lItem)(rPopped)(rItem)
[lPopped]
|
dequeLPopped
}
{
(isEmpty)(lPopped)(lItem)(rPopped)(rItem)
[lItem]
|
dequeLItem
}
{
(isEmpty)(lPopped)(lItem)(rPopped)(rItem)
[rPopped]
|
dequeRPopped
}
{
(isEmpty)(lPopped)(lItem)(rPopped)(rItem)
[rItem]
|
dequeRItem
}
{
/(dequeLPush)
(deque)(item)
/(isEmpty)(lPopped)(lItem)(rPopped)(rItem)
/
(g) /[rItem]/</[item]/[rPopped][dequeLPush]>/[item]/[deque]/[0] [g]
/
/[item][dequeSingle]
[isEmpty]
[deque]
[YC]
|
dequeLPush
}
{
/(dequeRPush)
(deque)(item)
/(isEmpty)(lPopped)(lItem)(rPopped)(rItem)
/
(g) /[item]/[deque]/[lItem]/</[item]/[lPopped][dequeRPush]>/[0] [g]
/
/[item][dequeSingle]
[isEmpty]
[deque]
[YC]
|
dequeRPush
}
{
(_0)(_1)(_add)
/(dequeLength)
(isEmpty)(lPopped)(lItem)(rPopped)(rItem)
/
/
/[dequeLength][lPopped]
/
[_1]
[_add]
/
[_0]
[isEmpty]
[YC]
|
dequeLLength
}
{
(_0)(_1)(_add)
/(dequeLength)
(isEmpty)(lPopped)(lItem)(rPopped)(rItem)
/
/
/[dequeLength][rPopped]
/
[_1]
[_add]
/
[_0]
[isEmpty]
[YC]
|
dequeRLength
}

View File

@ -0,0 +1,6 @@
@empty
@single
@pop
@push
@length
@reduce

View File

@ -0,0 +1 @@
{ (g) /? /? /? /? /[1][g] | dequeEmpty }

View File

@ -0,0 +1,35 @@
{
(_0)(_1)(_add)
/(dequeLength)
(isEmpty)(lPopped)(lItem)(rPopped)(rItem)
/
/
/[dequeLength][lPopped]
/
[_1]
[_add]
/
[_0]
[isEmpty]
[YC]
|
dequeLLength
}
{
(_0)(_1)(_add)
/(dequeLength)
(isEmpty)(lPopped)(lItem)(rPopped)(rItem)
/
/
/[dequeLength][rPopped]
/
[_1]
[_add]
/
[_0]
[isEmpty]
[YC]
|
dequeRLength
}

View File

@ -0,0 +1,27 @@
{
(isEmpty)(lPopped)(lItem)(rPopped)(rItem)
[lPopped]
|
dequeLPopped
}
{
(isEmpty)(lPopped)(lItem)(rPopped)(rItem)
[lItem]
|
dequeLItem
}
{
(isEmpty)(lPopped)(lItem)(rPopped)(rItem)
[rPopped]
|
dequeRPopped
}
{
(isEmpty)(lPopped)(lItem)(rPopped)(rItem)
[rItem]
|
dequeRItem
}

View File

@ -0,0 +1,29 @@
{
/(dequeLPush)
(deque)(item)
/(isEmpty)(lPopped)(lItem)(rPopped)(rItem)
/
(g) /[rItem]/</[item]/[rPopped][dequeLPush]>/[item]/[deque]/[0] [g]
/
/[item][dequeSingle]
[isEmpty]
[deque]
[YC]
|
dequeLPush
}
{
/(dequeRPush)
(deque)(item)
/(isEmpty)(lPopped)(lItem)(rPopped)(rItem)
/
(g) /[item]/[deque]/[lItem]/</[item]/[lPopped][dequeRPush]>/[0] [g]
/
/[item][dequeSingle]
[isEmpty]
[deque]
[YC]
|
dequeRPush
}

View File

@ -0,0 +1,29 @@
{
(g)
/(dequeReduce)
(x)
(isEmpty)(lPopped)(lItem)(rPopped)(rItem)
/
//</[lItem]/[x][g]>[dequeReduce][lPopped]
/
[x]
[isEmpty]
[YC]
|
dequeLReduce
}
{
(g)
/(dequeReduce)
(x)
(isEmpty)(lPopped)(lItem)(rPopped)(rItem)
/
//</[rItem]/[x][g]>[dequeReduce][rPopped]
/
[x]
[isEmpty]
[YC]
|
dequeRReduce
}

View File

@ -0,0 +1 @@
{ (item) (g) /[item]/[dequeEmpty]/[item]/[dequeEmpty]/[0][g] | dequeSingle }

View File

@ -24,5 +24,5 @@
[b] [b]
[YC] [YC]
| |
b_to_n _b_to_n
} }

View File

@ -13,5 +13,5 @@
/[n][n_zq] /[n][n_zq]
[YC] [YC]
| |
n_to_b _n_to_b
} }

View File

@ -1,5 +1,5 @@
@bool @bool/@
@pair @pair/@
@yc @yc
@id @id
@collector @collector

2
src/core/bool/01.bu4 Normal file
View File

@ -0,0 +1,2 @@
{ (x)(y) [x] | 1 }
{ (x)(y) [y] | 0 }

2
src/core/bool/@.bu4 Normal file
View File

@ -0,0 +1,2 @@
@01
@operations

View File

@ -1,5 +1,3 @@
{ (x)(y) [x] | 1 }
{ (x)(y) [y] | 0 }
{ (x) /[0]/[1][x] | bool } { (x) /[0]/[1][x] | bool }
{ (x) /[1]/[0][x] | not } { (x) /[1]/[0][x] | not }
{ (x)(y) /[0]/[y][x] | and } { (x)(y) /[0]/[y][x] | and }

View File

@ -16,4 +16,4 @@
} }
{ [1] | collecting } { [1] | collecting }
{ [0] | collect } { [0] | collect }

2
src/core/pair/@.bu4 Normal file
View File

@ -0,0 +1,2 @@
@pair
@operations

View File

@ -1,4 +1,3 @@
{ (x)(y)(g) /[y]/[x][g] | pair }
{ (_pair) /[1][_pair] | first } { (_pair) /[1][_pair] | first }
{ (_pair) /[0][_pair] | second } { (_pair) /[0][_pair] | second }
{ (x) /[x]/[x][pair] | double } { (x) /[x]/[x][pair] | double }

1
src/core/pair/pair.bu4 Normal file
View File

@ -0,0 +1 @@
{ (x)(y)(g) /[y]/[x][g] | pair }

View File

@ -1,4 +1,4 @@
@system @system/@
@pipe @pipe
@transform @transform
@sysbinary @sysbinary

View File

@ -1,92 +0,0 @@
{
(isInput)(out)(output)(input)
(g)
/[input]/[output]/[out]/[isInput]
[g]
|
system
}
{
(isInput)(out)(output)(input)
[isInput]
|
isSysInput
}
{
(isInput)(out)(output)(input)
[out]
|
outOf
}
{
(isInput)(out)(output)(input)
[output]
|
outputOf
}
{
(isInput)(out)(output)(input)
[input]
|
inputOf
}
{
(value)(sys)
/[value]/[inputOf][sys]
|
writeValue
}
{
(out)(output)
/
/[inputOf][output]
/
[output]
/
[out]
/
[0]
[system]
|
outSystem
}
{
(input)
/(this)
/
[input]
/
?
/
?
/
[1]
[system]
[YC]
|
inSimple
}
{
(out)(output)(input)
/
[input]
/
[output]
/
[out]
/
[1]
[system]
|
inSystem
}

4
src/io/system/@.bu4 Normal file
View File

@ -0,0 +1,4 @@
@system
@operations
@writevalue
@constructs/@

View File

@ -0,0 +1,3 @@
@outsystem
@insimple
@insystem

View File

@ -0,0 +1,16 @@
{
(input)
/(this)
/
[input]
/
?
/
?
/
[1]
[system]
[YC]
|
inSimple
}

View File

@ -0,0 +1,14 @@
{
(out)(output)(input)
/
[input]
/
[output]
/
[out]
/
[1]
[system]
|
inSystem
}

View File

@ -0,0 +1,14 @@
{
(out)(output)
/
/[inputOf][output]
/
[output]
/
[out]
/
[0]
[system]
|
outSystem
}

View File

@ -0,0 +1,27 @@
{
(isInput)(out)(output)(input)
[isInput]
|
isSysInput
}
{
(isInput)(out)(output)(input)
[out]
|
outOf
}
{
(isInput)(out)(output)(input)
[output]
|
outputOf
}
{
(isInput)(out)(output)(input)
[input]
|
inputOf
}

8
src/io/system/system.bu4 Normal file
View File

@ -0,0 +1,8 @@
{
(isInput)(out)(output)(input)
(g)
/[input]/[output]/[out]/[isInput]
[g]
|
system
}

View File

@ -0,0 +1,6 @@
{
(value)(sys)
/[value]/[inputOf][sys]
|
writeValue
}

1
src/math/@.bu4 Normal file
View File

@ -0,0 +1 @@
@gcd

23
src/math/gcd.bu4 Normal file
View File

@ -0,0 +1,23 @@
{
(_div)(_zq)
/(gcd)
(_a)(_b)
/
/
[_a]
/
/
/
[_b]
/
[_a]
[_div]
[second]
[gcd]
/
[_b]
/[_a][_zq]
[YC]
|
_gcd
}

View File

@ -3,5 +3,5 @@
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
@ci @ci
/[^4][b_to_nx] /[^4][b_to_n]
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

View File

@ -3,15 +3,15 @@
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
@ci @ci
{ /[b_zq]/[b_div][_gcd] | gcd }
(a)(b) (a)(b)
/ /
/ /
/ /[b][n_to_b]
/ /
/[a][n_to_bx] /[a][n_to_b]
[b_div] [gcd]
/[b][n_to_bx] [b_to_n]
[second]
[b_to_nx]
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

View File

@ -8,5 +8,5 @@
[^5] [^5]
/ /
[^4] [^4]
[b_sub][second][b_to_nx] [b_sub][second][b_to_n]
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

View File

@ -28,9 +28,9 @@
[sysDecorator] [sysDecorator]
> >
/ /
/[b_to_nx][sysTransform] /[b_to_n][sysTransform]
/ /
/[n_to_bx][sysTransform] /[n_to_b][sysTransform]
[sysDecorator] [sysDecorator]

View File

@ -3,10 +3,10 @@
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
@ci @ci
{ /[b_add]/[b1]/[b0][dequeLLength] | dequeLength } { /[b_add]/[b1]/[b0][dequeLLength] | dequeLength }
{ /[b!]//[pair]/[dequeEmpty][dequeLPush][dequeLPush] | deque } { /[b7]//[b1]//[b5]/[dequeEmpty][dequeLPush][dequeLPush][dequeLPush] | deque }
/ /
/[dequeLength][deque] /</[b0]/[b_add][dequeLReduce]>[deque]
[b_to_nx] [b_to_n]
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

View File

@ -15,8 +15,17 @@ class TimeSample:
TimeSample.level += 1 TimeSample.level += 1
self.__t = time.time() self.__t = time.time()
@classmethod
def tabulate(cls):
print(' ' * 4 * cls.level, end='')
@classmethod
def print(cls, *args):
cls.tabulate()
print(*args)
def __exit__(self, exc_type, exc_val, exc_tb): def __exit__(self, exc_type, exc_val, exc_tb):
TimeSample.level -= 1 TimeSample.level -= 1
print(' ' * 4 * self.level, end='') self.tabulate()
print(*self.args, time.time() - self.__t) print(*self.args, time.time() - self.__t)
print() print()