import ( "math.lib" ); square = _ <: *; // Complex in cartesian coordinates carte_cplx = _, _: (_, 1 : vectorize), (_, 1 : vectorize) : #; // Cartesian complex : basic operations ccplx_real = _, 0 : []; ccplx_imag = _, 1 : []; ccplx_conj = _ <: ccplx_real, ccplx_imag : _, (0, _ : -) : carte_cplx; ccplx_modul2 = _ <: ccplx_real, ccplx_imag : square, square : +; ccplx_modul = ccplx_modul2 : sqrt; ccplx_angle = _ <: (ccplx_imag, ccplx_real : / : atan), (ccplx_real, 0 : < : _, PI : *) : +; ccplx_div_real = _, _ <: ccplx_real, _, ccplx_imag, _ : /, / : carte_cplx; // cartesian complex : add, sub, mul and div ccplx_add = +; ccplx_sub = -; ccplx_mul = _, _ <: ccplx_real, ccplx_real, ccplx_imag, ccplx_imag,ccplx_real, ccplx_imag, ccplx_imag, ccplx_real : *, *, *, * : -, + : carte_cplx; ccplx_div = _, _ <: ccplx_real, ccplx_real, ccplx_imag, ccplx_imag, ccplx_imag, ccplx_real, ccplx_real, ccplx_imag, !, ccplx_real, !, ccplx_imag : *, *, *, *, square, square : +, -, + : carte_cplx, _ : ccplx_div_real; //ccplx_div = _, _ <: _, ccplx_conj, !, _ : ccplx_mul, ccplx_modul2 : ccplx_div_real; // Complex in polar coordinates polar_cplx = _, _: (_, 1 : vectorize), (_, 1 : vectorize) : #; pcplx_modul = _, 0 : []; pcplx_angle = _, 1 : []; pcplx_real = _ <: pcplx_modul, (pcplx_angle : cos) : *; pcplx_imag = _ <: pcplx_modul, (pcplx_angle : sin) : *; // conversion between cartesian complex and polar complex sca_abs = _ <: _, (>(0) : *(2) : -(1)) : *; sca2pcplx = _ <: sca_abs, (<(0) : *(PI)) : polar_cplx; polar2carte = _ <: pcplx_real, pcplx_imag : carte_cplx; carte2polar = _ <: ccplx_modul, ccplx_angle : polar_cplx; // Polar complex : add, sub, mul and div pcplx_add = _, _ : polar2carte, polar2carte : ccplx_add : carte2polar; pcplx_sub = _, _ : polar2carte, polar2carte : ccplx_sub : carte2polar; pcplx_mul = _, _ <: (pcplx_modul, pcplx_modul : *), (pcplx_angle, pcplx_angle : +) : polar_cplx; pcplx_div = _, _ <: (pcplx_modul, pcplx_modul : /), (pcplx_angle, pcplx_angle : -) : polar_cplx; //functions used in FFT real_pcplx_mul = _, ( _ <: pcplx_modul, pcplx_angle) : *, _ : polar_cplx; pcplx_moduls(n) = par(i, n, pcplx_modul);