Open TheFausap opened 1 year ago
you could calculate integer powers like that:
pN:{angle[(abs x)^y;y*angle x]}
float^int
is power. angle
has a monadic and a dyadic form (get, construct).
but improves some numbers but not all.
or you can round the angle of the result z
(complex matrix)
angle'[abs z;_0.5+angle z]
but that does not fix all numbers as well.
the right way would be better floating point formatting. function sf formats floats: https://github.com/ktye/i/blob/master/string.go#L107 it's rather minimalistic but everything else needs much more code. ngn has correct rounding (ryu's algorithm), but no complex.
in the interpreter i usually live with that. for a real application, i would embed the interpreter and display the result including reformatting the numbers. you usually want more control, like number of digits. all of that is not included.
the matrix rounding is quite good for my purpose, but I don't understand why it's missing some values :)
z:QFT 8
angle'[abs z;_0.5+angle z]
0.353553a 0.353553a 0.353553a 0.353553a 0.353553a 0.353553a 0.353553..
0.353553a 0.353553a44.999999 0.353553a90 0.353553a135 0.353553a180 0..
0.353553a 0.353553a90 0.353553a180 0.353553a270 0.353553a360 0.35355..
0.353553a 0.353553a135 0.353553a270 0.353553a45 0.353553a180 0.35355..
0.353553a 0.353553a180 0.353553a360 0.353553a180 0.353553a360 0.3535..
0.353553a 0.353553a225 0.353553a90 0.353553a315 0.353553a180 0.35355..
0.353553a 0.353553a270 0.353553a180 0.353553a90 0.353553a360 0.35355..
0.353553a 0.353553a315 0.353553a270 0.353553a225 0.353553a180 0.3535..
because angle[r;a]
regenerates a complex number with sin/cos on the rounded a
.
complex is stored internally as real,image.
printing converts back to polar form.
is there a way to access the internal form?
you can get the real/imag part with _z, imag z or you can convert the underlying memory to floats (of twice the size), e.g.
`f 1a45 2a30
0.707106 0.707106 1.73205 0.999999
`f@,1a45 /atoms must be enlisted
0.707106 0.707106
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:
thanks Fausto