ktye / i Goto Github PK
View Code? Open in Web Editor NEWinterpret
interpret
Hello,
I am trying to define a phase matrix, dependent by a parameter.
I defined this function:
P:{t:angle[1;x];(1 0;0 t)}
but if I run P 45, I receive this error:
P:{t:angle[1;x];(1 0;0 t)}
^
even if I do not use the temp var, by defining:
P:{(1 0;0 angle[1;x])}
I receive another error:
P:{(1 0;0 angle[1;x])}
^
Do you have any idea why that is?
thanks,
Fausto
syntax error
This project doesn't have a licence. Can I install it on https://ato.pxeger.com, and allow users to run their own K code in a sandbox with it? If so, can I also publish an unmodified copy as a Docker image on https://hub.docker.com?
ndrop(-1, x) calls ntake which does not reuse memory on rc1.
e.g.
s := sz(t)
if I32(yp-4) == 1 && bucket(s*nn(y)) == bucket(s*n) && t < Lt {
SetI32(yp-12, n)
return y
}
Hello,
I built k using the standard clang compiler available under MacOS Ventura.
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: x86_64-apple-darwin22.4.0
and I got no errors during the build phase.
But, in some case, I get some weird ascii chars output on the screen and not the proper output.
For example, running: ./k q.k t2.k
(where q.k is available -not the latest version at the moment, but it's not relevant for this error- at https://gist.github.com/TheFausap/1e16bee4b1f2e5224a408e87b1014083)
and t2.k is basically:
K00:ts[K0;K0]
A:ts[K00;K00]
B:ts[K00;K00]
if I want to print the state K00: and it should be |00> in standard notation, I have instead on the screen:
ktye/k
K00
`ket|1 0 0 0
pst K00
(1;"|�>")
if I am using the same files, but the binary is compiled using GCC under Linux (RockyLinux 9.1) I have the correct result.
ktye/k
K00
`ket|1 0 0 0
pst K00
(1;"|00>")
Is this expected with clang?
regards,
Fausto
https://github.com/ktye/i/releases/tag/latest only has k.c
, k.f
, k.wasm
, ktye.h
, no Go files
Is this intentional?
I had an issue importing the fonts into the font-editor. The fields for "space" and "char width" seem to be swapped. f10x20, for example has a max font width of 10, a char width of 1 and a space between characters of 10. This works when just using the font, but (if I understand it correctly) the editor expects the opposite, ie char width of 10 (on each char) and a (global) space between characters of 1.
e.g. (3 3⍴⍳9)[;-3-4]
e.g. modified indexed assign
#include<stdint.h>
void f(int32_t *x, int32_t y, int32_t z) { x[y]+=z; }
// f vs g
int32_t *I;
#define I32(x) I[(x)>>2]
#define SetI32(x,y) I[(x)>>2]=(y)
void g(uint64_t x, int32_t y, int32_t z) {
SetI32(((int32_t)(x)+(4*y)),(I32(((int32_t)(x)+(4*y)))+z));
}
with -O3
f:
movsx rsi, esi
add DWORD PTR [rdi+rsi*4], edx
ret
g:
lea eax, [rdi+rsi*4]
mov ecx, edx
mov rdx, QWORD PTR I[rip]
sar eax, 2
cdqe
add DWORD PTR [rdx+rax*4], ecx
ret
I:
.zero 8
currently the data section is (char-classes + z.k + ..):
1856 zz (uncompressed)
1143 zz.gz
1150 zz.zst (zstd -19)
1574 zz.lz4 (lz4 -12)
adding uncompressor for lz4 block is:
func u8(x int32) int32 { return I8(x) & 0xff }
func lz(p, e, d int32) int32 { //src-start, src-end, dst
for {
t := u8(p)
p++
l := t >> 4 //literal length
if l == 15 {
for {
l += u8(p)
p++
if u8(p-1) != 255 {
break
}
}
}
Memorycopy(d, p, l)
p += l
d += l
if p >= e {
return d
}
o := u8(p) | u8(p+1)<<8 //offset
p += 2
l = 4 + t&15 //match length
if l == 19 {
for {
l += u8(p)
p++
if u8(p-1) != 255 {
break
}
}
}
t = d + l
for d < t {
SetI8(d, u8(d-o))
d += 1
continue
}
}
return 0
}
this costs 244 bytes.
but compression saves only 1856-1574-19 = 301 bytes.
test code:
func TestZ(t *testing.T) { // write zz (uncompressed)
newtest()
os.WriteFile("zz", Bytes[132:280+1708], 0744)
reset()
}
func TestLz(t *testing.T) {
z, err := os.ReadFile("zz.lz12")
if err != nil {
t.Fatal(err)
}
z = z[11:]
z = z[:len(z)-8] // strip lz4 frame wrapper
var orig []byte
newtest()
orig = append(orig, Bytes[132:280+1708]...)
reset()
Bytes = make([]byte, 8192)
p, d := int32(132), int32(2048)
copy(Bytes[p:], z)
e := p + int32(len(z))
r := lz(p, e, d)
if string(orig) != string(Bytes[d:r]) {
t.Fatal("lz4 mismatch")
}
}
/in leb128
t:(0x5e0a000000000000;0xde14 /2654
0xffffff7f00000000;0xffffffff07 /2147483647
0x000000000000e03f;0x80808080808080f03f /4602678819172646912
0x010000000000f87f;0x81808080808080fcff00 /9221120237041090561
0x000000000000f07f;0x80808080808080f8ff00 /9218868437227405312
0xffffffffffffffff;0x7f /-1 (false)
0x00f0ffffffffffff;0x8060 /-4096
0x000000000000f0ff;0x8080808080808078 /-4503599627370496
0xffffffff000000ff;0xffffffff8f8080807f) /-72057589742960641 (false)
leb8:{r:!0;B:1v:,/+(8#2)\\256/256+|x;while[B&(8<#v)&+/v;b:-7#v;s:*b;v:-7_v;r,:$[((0~&/v)|0x00~s)&(+/v)|s;1;B:0],b];_2//'-8^r}
g:leb8't i:2*!2\#t
e:t 1+i
\g~'e
Should the upper case P
here be lower case?
I was trying to get an integer power of a complex number and I created a function:
pN:{t:y#x;$[y=0;1a;*/t]}
using it in this function (it generates a matrix representing a quantum Fourier transform of log2(x) qubits):
QFT:{(1%%x)*(pN[om x]''((!x)*\:!x))}
where om function is:
om:{angle[1;360%x]}
Can some rounding be applied for the angle part?
For example, the matrix for 3 qubits (QFT 8) is:
0.353553a 0.353553a 0.353553a 0.353553a 0.353553a 0.353553a 0.353553..
0.353553a 0.353553a44.999999 0.353553a89.999999 0.353553a134.999999 ..
0.353553a 0.353553a89.999999 0.353553a179.999999 0.353553a270 0.3535..
0.353553a 0.353553a134.999999 0.353553a270 0.353553a44.999999 0.3535..
0.353553a 0.353553a179.999999 0.353553a359.999999 0.353553a179.99999..
0.353553a 0.353553a224.999999 0.353553a89.999999 0.353553a314.999999..
0.353553a 0.353553a270 0.353553a179.999999 0.353553a89.999999 0.3535..
0.353553a 0.353553a315 0.353553a269.999999 0.353553a224.999999 0.353..
thanks
Fausto
3/-3+!7
0 -2 -1 0 1 2 0
should be
0 1 2 0 1 2 0
when trying to build k- with go version go1.13.1 linux/amd64.
./a.go:11:15: undefined: mku
maybe simplify as uf(l1(x))
returns 4#0n
derived functions don't know their arity.
that means, projections for {x;y;z}/ need to be explicit
parse error
l:(1;2 3)
d:`a`b`c!(4;5 6;7.)
l,d
should be lhs
In a shell:
$ k+ @
0
^
Segmentation fault
$ echo >/tmp/a.k
$ k+ /tmp/a.k
ktye/k+
^C
$ k+ /tmp/a.k @
0
^
Segmentation fault
When trying to exit k+ with Ctrl+D (rather than Ctrl+C), k+ outputs spaces forever rather than exiting.
256 256\3 /0 3 /is 3
3 4\128 /2 0
could be much smaller:
odo:{x\\!*/x} /coltim
Adam:
Seems that pretty much every function is buggy!
1=2 SYNTAX ERROR
fixed!3
''⍴1 2 3
~2 should domain error but doesn't.
⍴⍳0 gives ⍳0 instead of ,0
?n doesn't fail on negative numbers
3⍺10 fails, and ditto ⍵
prefix/suffix vector?5↑2 1
⍴10↓2 5
''>5
I can assign to a¯3 and assignment seems to echo the assigned result.
¯8*÷3 gives 0n instead of ¯2
Input. a←⎕ fails.
⌈/⍳0 seems to give ⍳0 instead of the smallest representable float.
⊤ seems to not work properly on non-scalars.
0÷0 gives 0n instead of 1
definitely not a proper \360 playground.
1000-0 1000
1000 1024
?
token&parse costs roughly 4300 bytes.
can we rewrite it shorter in k?
token/parse cannot be written in k because it loops.
but we could parse the parser and embed the instructions.
instruction embedding could be any of:
whatever, the result must be shorter than 4k of spacious wasm bytes.
Hi, thanks for creating this!
I have decided to use a small fork of ktye/k in a computer game project.
My fork is here: https://gitlab.com/talas777/spesh
I only plan to use the C-version and I used the LGPLv3+ license (my favorite).
Please let me know if there is some way I can credit you or give attribution.
Perhaps a link to your project?
I added "Copyright (c) 2022,2023 ktye", hope that wasn't too wrong?
Thanks again!
d:`b!`a!+`a`b!(1 2;3 4)
*d /fails
same as:
v:.d
v 0 /fails
or
k:`a!+`a`b!(1 2;3 4)
k 0 /fails
wasm/tco could be:
-waret:{("\n"/:y),"\nreturn"}
+waret:{$[(`tail':opts)&(T 1+x)':`cal`cli; "\n"/:|(,"return_",*y),1_y:|"\n"\:*y ;("\n"/:y),"\nreturn"]}
todo: this generates some return_nop
uptype is wrong for char atoms. maybe Kc should be:
func Kc(x int32) K { return K(0xff&uint32(x)) | K(ct)<<59 }
coltim: triadic take where the third argument specifies the fill. if the fill can be a list (matching the current "overtake" behavior) I think the variations could all be handled (cycling, using 0's, using nulls)
xy:(+/*)\:
xty:+/*\:'
break/continue with labels needs to calculate nesting level
1,"a"
1,"abc"
now new
each +'x same
over +/x same
scan +\x same
each2 x+'y same
over-init x+/y +/x,y
scan-init x+\y +\x,y
each-n F'[..] same (n>2)
over-n F/[..] same (n>2)
scan-n F\[..] same (n>2)
each-prior -':x ???
fixedpoint f/:x f/x (monadic)
fixedscan f\:x f\x
transition 0{L[x;y]}\x L\0,x
each-left x+\:y x+\y
each-right x+/:y x+/y
join x/:y c/y (chars only)
split x\:y c\y (chars only)
decode x//y n/y (numbers)
encode x\\y n\y (numbers)
div x\y y%x (int remains)
mod x/y x!y (i-atom only)
ndo f n/x retire
bin x'y same
lin x y'z {..}
in x':y a?v (remove shuffle/deal)
deal/shuffle n?v v(n?#v)
each-prior: maybe
sqrt %x sqrt x (verb-code)
rotate-fill n/a %x %1 2 3 /0 1 2
prior -':x x-%x
or define prior:{[f;x;x0]f[x;-1_x0,x]}
returns 0n
wasm f64.convert_i64_u fails in chrome for 0n 0w -0w
math.go:cosin_:
j := uint64(x * 1.2732395447351628)
,\1 2 3 could be (!0),\1 2 3
(,1;1 2;1 2 3)
(),\1 2 3 is broken just as (),/1 2 3 (no unify)
`k t is ok, but `l t fails if t is empty.
k:0#`
v:()
t:+k!v
t
T:{[x;k]$[`L?@'.x;,k x;(,*x),(,(#*x)#"-"),1
^
t
+(0#`)!()
should be identify matrix, but is 10-decode instead:
https://github.com/ktye/i/blob/master/adverbs.go#L188
token: this is not a comment.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.