fork download
  1. open System
  2. open System.Diagnostics
  3.  
  4. type complex = C of float*float
  5.  
  6. let check (n: int) = true
  7.  
  8. let sum (a: complex) (b: complex) =
  9. match a, b with
  10. | C(x1, y1), C(x2, y2) -> C(x1+x2, y1+y2)
  11.  
  12. let mult (a: complex) (b: complex) =
  13. match a, b with
  14. | C(x1, y1), C(x2, y2) -> C(x1*x2-y1*y2, x1*y2+x2*y1)
  15.  
  16. let exp (e: float) =
  17. C(cos e, -sin e)
  18.  
  19. let opp (c: complex) =
  20. match c with
  21. | C(a, b) -> C(-a, -b)
  22.  
  23. let rec transform (x: complex array) =
  24. if not (check x.Length) then failwith "Error, input size invalid"
  25.  
  26. if x.Length = 1 then x
  27. else
  28. let even = Array.init (x.Length/2) (fun i -> x.[2*i])
  29. let odd = Array.init (x.Length/2) (fun i -> x.[2*i+1])
  30. let es: complex array = transform even
  31. let os: complex array = transform odd
  32. let ret: complex array = Array.zeroCreate x.Length
  33.  
  34. for i in 0..(x.Length/2)-1 do
  35. let e = 2. * Math.PI * float i / float x.Length
  36. ret.[i] <- sum (es.[i]) (mult (exp e) (os.[i]))
  37. ret.[i+(x.Length/2)] <- sum (es.[i]) (mult (opp (exp e)) (os.[i]))
  38.  
  39. ret
  40.  
  41. let rndGen = new System.Random(int System.DateTime.Now.Ticks)
  42. let a: complex array = Array.init 65536 (fun _ ->
  43. let x, y = float rndGen.next(128), float rndGen.next(128)
  44. C(x, y)
  45. )
  46. let t = new Stopwatch()
  47. t.Start()
  48. //let x = transform [|C(1., 0.); C(1., 0.); C(1., 0.); C(1., 0.) |]
  49. let x = transform a
  50. printfn "tempo di esecuzione: %i" t.ElapsedMilliseconds
  51. printfn "%A" x
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/home/PvmNPG/prog.fs(43,22): error FS0597: Successive arguments should be separated by spaces or tupled, and arguments involving function or method applications should be parenthesized

/home/PvmNPG/prog.fs(43,46): error FS0597: Successive arguments should be separated by spaces or tupled, and arguments involving function or method applications should be parenthesized
stdout
Standard output is empty