gcd
This commit is contained in:
parent
105ec294d3
commit
dac9ccf109
110
main.py
110
main.py
@ -1,4 +1,5 @@
|
||||
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
||||
import math
|
||||
import random
|
||||
|
||||
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 timesample import TimeSample
|
||||
|
||||
with TimeSample(' compilation'):
|
||||
sys0 = synced(readfile('src/sys0'))
|
||||
with TimeSample(' first, AP'):
|
||||
print(
|
||||
antiproxy(sys0)(0)(1)(
|
||||
lambda a: lambda b: a + b
|
||||
)(
|
||||
lambda n: lambda x: lambda y: x if n == 0 else y
|
||||
)(
|
||||
lambda n: lambda x: lambda y: x if n & 1 else y
|
||||
)(
|
||||
lambda n: n >> 1
|
||||
)
|
||||
)
|
||||
with TimeSample(' second, AP'):
|
||||
print(
|
||||
antiproxy(sys0)(0)(1)(
|
||||
lambda a: lambda b: a + b
|
||||
)(
|
||||
lambda n: lambda x: lambda y: x if n == 0 else y
|
||||
)(
|
||||
lambda n: lambda x: lambda y: x if n & 1 else y
|
||||
)(
|
||||
lambda n: n >> 1
|
||||
)
|
||||
)
|
||||
with TimeSample(' third, EP'):
|
||||
sys0 = with_common_interface(sys0)
|
||||
print(sys0)
|
||||
with TimeSample(' sys2'):
|
||||
with TimeSample(' compilation'):
|
||||
sys2c = synced(readfile('src/sys2'))
|
||||
with TimeSample(' runtime'):
|
||||
sys2 = sys2c
|
||||
sys2 = with_common_interface(sys2)
|
||||
print(sys2)
|
||||
with TimeSample(' runtime'):
|
||||
sys2 = sys2c
|
||||
sys2 = with_common_interface(sys2)
|
||||
print(sys2)
|
||||
with TimeSample(' full'):
|
||||
sys3 = with_common_interface(synced(readfile('src/sys3')))
|
||||
sys3 = sync(sys3.call(eproxy(5)))
|
||||
print(sys3)
|
||||
with TimeSample(' full'):
|
||||
sys1 = with_common_interface(synced(readfile('src/sys1')))
|
||||
a_ = random.randrange(2 ** 64)
|
||||
b_ = random.randrange(2 ** 64)
|
||||
sys1 = sync(sys1.call(eproxy(a_)))
|
||||
sys1 = sync(sys1.call(eproxy(b_)))
|
||||
print(sys1, b_ % a_)
|
||||
with TimeSample(' full'):
|
||||
print(with_common_interface(synced(readfile('src/sys4'))))
|
||||
|
||||
with TimeSample('all'):
|
||||
with TimeSample('sys0'):
|
||||
with TimeSample('compilation'):
|
||||
sys0 = synced(readfile('src/sys0'))
|
||||
with TimeSample('first, AP'):
|
||||
TimeSample.print(
|
||||
antiproxy(sys0)(0)(1)(
|
||||
lambda a: lambda b: a + b
|
||||
)(
|
||||
lambda n: lambda x: lambda y: x if n == 0 else y
|
||||
)(
|
||||
lambda n: lambda x: lambda y: x if n & 1 else y
|
||||
)(
|
||||
lambda n: n >> 1
|
||||
)
|
||||
)
|
||||
with TimeSample('second, AP'):
|
||||
TimeSample.print(
|
||||
antiproxy(sys0)(0)(1)(
|
||||
lambda a: lambda b: a + b
|
||||
)(
|
||||
lambda n: lambda x: lambda y: x if n == 0 else y
|
||||
)(
|
||||
lambda n: lambda x: lambda y: x if n & 1 else y
|
||||
)(
|
||||
lambda n: n >> 1
|
||||
)
|
||||
)
|
||||
with TimeSample('third, EP'):
|
||||
sys0 = with_common_interface(sys0)
|
||||
TimeSample.print(sys0)
|
||||
with TimeSample('sys2'):
|
||||
with TimeSample('compilation'):
|
||||
sys2c = synced(readfile('src/sys2'))
|
||||
with TimeSample('runtime'):
|
||||
sys2 = sys2c
|
||||
sys2 = with_common_interface(sys2)
|
||||
TimeSample.print(sys2)
|
||||
with TimeSample('runtime'):
|
||||
sys2 = sys2c
|
||||
sys2 = with_common_interface(sys2)
|
||||
TimeSample.print(sys2)
|
||||
with TimeSample('sys3'):
|
||||
sys3 = with_common_interface(synced(readfile('src/sys3')))
|
||||
sys3 = sync(sys3.call(eproxy(5)))
|
||||
TimeSample.print(sys3)
|
||||
with TimeSample('sys1'):
|
||||
sys1 = with_common_interface(synced(readfile('src/sys1')))
|
||||
a_ = random.randrange(2 ** 16)
|
||||
b_ = random.randrange(2 ** 16)
|
||||
sys1 = sync(sys1.call(eproxy(a_)))
|
||||
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'))))
|
||||
|
@ -1,7 +1,6 @@
|
||||
@b!
|
||||
@01
|
||||
@add
|
||||
@mul
|
||||
@sub
|
||||
@bitwise
|
||||
@div
|
||||
@zq
|
||||
@double
|
||||
@bitwise/@
|
||||
@arithmetic/@
|
||||
|
4
src/binary/arithmetic/@.bu4
Normal file
4
src/binary/arithmetic/@.bu4
Normal file
@ -0,0 +1,4 @@
|
||||
@add
|
||||
@mul
|
||||
@sub
|
||||
@div
|
@ -1,6 +1,3 @@
|
||||
{ (b) </[b]/[0][b!]> | b_double }
|
||||
{ (b) </ <(zq)(lb)(hb!) [hb!]> [b]> | b_halve }
|
||||
|
||||
{
|
||||
/(b_add)
|
||||
(bA)(bB)
|
42
src/binary/arithmetic/div.bu4
Normal file
42
src/binary/arithmetic/div.bu4
Normal 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
|
||||
}
|
@ -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
4
src/binary/bitwise/@.bu4
Normal file
@ -0,0 +1,4 @@
|
||||
@and
|
||||
@or
|
||||
@xor
|
||||
@exclude
|
24
src/binary/bitwise/and.bu4
Normal file
24
src/binary/bitwise/and.bu4
Normal 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
|
||||
}
|
24
src/binary/bitwise/exclude.bu4
Normal file
24
src/binary/bitwise/exclude.bu4
Normal 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
24
src/binary/bitwise/or.bu4
Normal 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
|
||||
}
|
24
src/binary/bitwise/xor.bu4
Normal file
24
src/binary/bitwise/xor.bu4
Normal 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
|
||||
}
|
@ -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
2
src/binary/double.bu4
Normal 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
8
src/binary/zq.bu4
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
(b)
|
||||
/(zq)(lb)(hb!)
|
||||
[zq]
|
||||
[b]
|
||||
|
|
||||
b_zq
|
||||
}
|
@ -1,2 +1,3 @@
|
||||
@01
|
||||
@add
|
||||
@double
|
||||
|
@ -1,2 +1 @@
|
||||
{ (cA)(cB)(f)(x) //[x]</[f][cA]></[f][cB]> | c_add }
|
||||
{ (c) /[c]/[c][c_add] | c_double }
|
||||
|
1
src/church_numerals/double.bu4
Normal file
1
src/church_numerals/double.bu4
Normal file
@ -0,0 +1 @@
|
||||
{ (c) /[c]/[c][c_add] | c_double }
|
@ -1,3 +1,3 @@
|
||||
(n0)(n1)(n_add)(n_zq)(n_lb)(n_h)
|
||||
{ /[n_add]/[n1]/[n0] [b_to_n] | b_to_nx }
|
||||
{ /[n_h]/[n_lb]/[n_zq][n_to_b] | n_to_bx }
|
||||
{ /[n_add]/[n1]/[n0] [_b_to_n] | b_to_n }
|
||||
{ /[n_h]/[n_lb]/[n_zq][_n_to_b] | n_to_b }
|
||||
|
@ -1 +1 @@
|
||||
@deque
|
||||
@deque/@
|
||||
|
@ -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
|
||||
}
|
6
src/collections/deque/@.bu4
Normal file
6
src/collections/deque/@.bu4
Normal file
@ -0,0 +1,6 @@
|
||||
@empty
|
||||
@single
|
||||
@pop
|
||||
@push
|
||||
@length
|
||||
@reduce
|
1
src/collections/deque/empty.bu4
Normal file
1
src/collections/deque/empty.bu4
Normal file
@ -0,0 +1 @@
|
||||
{ (g) /? /? /? /? /[1][g] | dequeEmpty }
|
35
src/collections/deque/length.bu4
Normal file
35
src/collections/deque/length.bu4
Normal 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
|
||||
}
|
27
src/collections/deque/pop.bu4
Normal file
27
src/collections/deque/pop.bu4
Normal 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
|
||||
}
|
29
src/collections/deque/push.bu4
Normal file
29
src/collections/deque/push.bu4
Normal 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
|
||||
}
|
29
src/collections/deque/reduce.bu4
Normal file
29
src/collections/deque/reduce.bu4
Normal 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
|
||||
}
|
1
src/collections/deque/single.bu4
Normal file
1
src/collections/deque/single.bu4
Normal file
@ -0,0 +1 @@
|
||||
{ (item) (g) /[item]/[dequeEmpty]/[item]/[dequeEmpty]/[0][g] | dequeSingle }
|
@ -24,5 +24,5 @@
|
||||
[b]
|
||||
[YC]
|
||||
|
|
||||
b_to_n
|
||||
_b_to_n
|
||||
}
|
||||
|
@ -13,5 +13,5 @@
|
||||
/[n][n_zq]
|
||||
[YC]
|
||||
|
|
||||
n_to_b
|
||||
_n_to_b
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
@bool
|
||||
@pair
|
||||
@bool/@
|
||||
@pair/@
|
||||
@yc
|
||||
@id
|
||||
@collector
|
||||
|
2
src/core/bool/01.bu4
Normal file
2
src/core/bool/01.bu4
Normal file
@ -0,0 +1,2 @@
|
||||
{ (x)(y) [x] | 1 }
|
||||
{ (x)(y) [y] | 0 }
|
2
src/core/bool/@.bu4
Normal file
2
src/core/bool/@.bu4
Normal file
@ -0,0 +1,2 @@
|
||||
@01
|
||||
@operations
|
@ -1,5 +1,3 @@
|
||||
{ (x)(y) [x] | 1 }
|
||||
{ (x)(y) [y] | 0 }
|
||||
{ (x) /[0]/[1][x] | bool }
|
||||
{ (x) /[1]/[0][x] | not }
|
||||
{ (x)(y) /[0]/[y][x] | and }
|
@ -16,4 +16,4 @@
|
||||
}
|
||||
|
||||
{ [1] | collecting }
|
||||
{ [0] | collect }
|
||||
{ [0] | collect }
|
||||
|
2
src/core/pair/@.bu4
Normal file
2
src/core/pair/@.bu4
Normal file
@ -0,0 +1,2 @@
|
||||
@pair
|
||||
@operations
|
@ -1,4 +1,3 @@
|
||||
{ (x)(y)(g) /[y]/[x][g] | pair }
|
||||
{ (_pair) /[1][_pair] | first }
|
||||
{ (_pair) /[0][_pair] | second }
|
||||
{ (x) /[x]/[x][pair] | double }
|
1
src/core/pair/pair.bu4
Normal file
1
src/core/pair/pair.bu4
Normal file
@ -0,0 +1 @@
|
||||
{ (x)(y)(g) /[y]/[x][g] | pair }
|
@ -1,4 +1,4 @@
|
||||
@system
|
||||
@system/@
|
||||
@pipe
|
||||
@transform
|
||||
@sysbinary
|
||||
|
@ -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
4
src/io/system/@.bu4
Normal file
@ -0,0 +1,4 @@
|
||||
@system
|
||||
@operations
|
||||
@writevalue
|
||||
@constructs/@
|
3
src/io/system/constructs/@.bu4
Normal file
3
src/io/system/constructs/@.bu4
Normal file
@ -0,0 +1,3 @@
|
||||
@outsystem
|
||||
@insimple
|
||||
@insystem
|
16
src/io/system/constructs/insimple.bu4
Normal file
16
src/io/system/constructs/insimple.bu4
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
(input)
|
||||
/(this)
|
||||
/
|
||||
[input]
|
||||
/
|
||||
?
|
||||
/
|
||||
?
|
||||
/
|
||||
[1]
|
||||
[system]
|
||||
[YC]
|
||||
|
|
||||
inSimple
|
||||
}
|
14
src/io/system/constructs/insystem.bu4
Normal file
14
src/io/system/constructs/insystem.bu4
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
(out)(output)(input)
|
||||
/
|
||||
[input]
|
||||
/
|
||||
[output]
|
||||
/
|
||||
[out]
|
||||
/
|
||||
[1]
|
||||
[system]
|
||||
|
|
||||
inSystem
|
||||
}
|
14
src/io/system/constructs/outsystem.bu4
Normal file
14
src/io/system/constructs/outsystem.bu4
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
(out)(output)
|
||||
/
|
||||
/[inputOf][output]
|
||||
/
|
||||
[output]
|
||||
/
|
||||
[out]
|
||||
/
|
||||
[0]
|
||||
[system]
|
||||
|
|
||||
outSystem
|
||||
}
|
27
src/io/system/operations.bu4
Normal file
27
src/io/system/operations.bu4
Normal 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
8
src/io/system/system.bu4
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
(isInput)(out)(output)(input)
|
||||
(g)
|
||||
/[input]/[output]/[out]/[isInput]
|
||||
[g]
|
||||
|
|
||||
system
|
||||
}
|
6
src/io/system/writevalue.bu4
Normal file
6
src/io/system/writevalue.bu4
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
(value)(sys)
|
||||
/[value]/[inputOf][sys]
|
||||
|
|
||||
writeValue
|
||||
}
|
1
src/math/@.bu4
Normal file
1
src/math/@.bu4
Normal file
@ -0,0 +1 @@
|
||||
@gcd
|
23
src/math/gcd.bu4
Normal file
23
src/math/gcd.bu4
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
(_div)(_zq)
|
||||
/(gcd)
|
||||
(_a)(_b)
|
||||
/
|
||||
/
|
||||
[_a]
|
||||
/
|
||||
/
|
||||
/
|
||||
[_b]
|
||||
/
|
||||
[_a]
|
||||
[_div]
|
||||
[second]
|
||||
[gcd]
|
||||
/
|
||||
[_b]
|
||||
/[_a][_zq]
|
||||
[YC]
|
||||
|
|
||||
_gcd
|
||||
}
|
@ -3,5 +3,5 @@
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
@ci
|
||||
|
||||
/[^4][b_to_nx]
|
||||
/[^4][b_to_n]
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
14
src/sys1.bu4
14
src/sys1.bu4
@ -3,15 +3,15 @@
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
@ci
|
||||
|
||||
{ /[b_zq]/[b_div][_gcd] | gcd }
|
||||
|
||||
(a)(b)
|
||||
|
||||
/
|
||||
/
|
||||
/
|
||||
/
|
||||
/[a][n_to_bx]
|
||||
[b_div]
|
||||
/[b][n_to_bx]
|
||||
[second]
|
||||
[b_to_nx]
|
||||
/[b][n_to_b]
|
||||
/
|
||||
/[a][n_to_b]
|
||||
[gcd]
|
||||
[b_to_n]
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
@ -8,5 +8,5 @@
|
||||
[^5]
|
||||
/
|
||||
[^4]
|
||||
[b_sub][second][b_to_nx]
|
||||
[b_sub][second][b_to_n]
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
@ -28,9 +28,9 @@
|
||||
[sysDecorator]
|
||||
>
|
||||
/
|
||||
/[b_to_nx][sysTransform]
|
||||
/[b_to_n][sysTransform]
|
||||
/
|
||||
/[n_to_bx][sysTransform]
|
||||
/[n_to_b][sysTransform]
|
||||
[sysDecorator]
|
||||
|
||||
|
||||
|
@ -3,10 +3,10 @@
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
@ci
|
||||
|
||||
{ /[b_add]/[b1]/[b0][dequeLLength] | dequeLength }
|
||||
{ /[b!]//[pair]/[dequeEmpty][dequeLPush][dequeLPush] | deque }
|
||||
{ /[b_add]/[b1]/[b0][dequeLLength] | dequeLength }
|
||||
{ /[b7]//[b1]//[b5]/[dequeEmpty][dequeLPush][dequeLPush][dequeLPush] | deque }
|
||||
|
||||
/
|
||||
/[dequeLength][deque]
|
||||
[b_to_nx]
|
||||
/</[b0]/[b_add][dequeLReduce]>[deque]
|
||||
[b_to_n]
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
@ -15,8 +15,17 @@ class TimeSample:
|
||||
TimeSample.level += 1
|
||||
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):
|
||||
TimeSample.level -= 1
|
||||
print(' ' * 4 * self.level, end='')
|
||||
self.tabulate()
|
||||
print(*self.args, time.time() - self.__t)
|
||||
print()
|
||||
|
Loading…
Reference in New Issue
Block a user