{"size": 1936, "ext": "rktl", "max_stars_repo_path": "pkgs/racket-benchmarks/tests/racket/benchmarks/shootout/typed/spectralnorm-generic.rktl", "max_stars_repo_name": "lkh01/racket", "max_stars_repo_stars_event_min_datetime": "2018-07-05T21:18:24.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-04T14:48:37.000Z", "max_issues_repo_path": "pkgs/racket-benchmarks/tests/racket/benchmarks/shootout/typed/spectralnorm-generic.rktl", "max_issues_repo_name": "lkh01/racket", "max_issues_repo_issues_event_min_datetime": "2017-05-10T07:33:20.000Z", "max_issues_repo_issues_event_max_datetime": "2018-07-19T15:49:46.000Z", "max_forks_repo_path": "pkgs/racket-benchmarks/tests/racket/benchmarks/shootout/typed/spectralnorm-generic.rktl", "max_forks_repo_name": "lkh01/racket", "max_forks_repo_forks_event_min_datetime": "2016-04-25T11:47:57.000Z", "max_forks_repo_forks_event_max_datetime": "2017-05-09T14:52:48.000Z"}
{"max_stars_count": 4, "max_issues_count": 9, "max_forks_count": 3, "avg_line_length": 40.3333333333, "max_line_length": 106, "alphanum_fraction": 0.4023760331}
;; The Computer Language Benchmarks Game
;; http://shootout.alioth.debian.org/
;; Translated from Mike Pall's Lua version.

(require racket/cmdline racket/trace racket/contract racket/flonum)

(let* ([A (lambda: ((i : Natural) (j : Natural))
            (let ([ij (+ i j)])
              (/ 1.0 (+ (* (* ij (+ ij 1))
                           0.5)
                        (+ i 1)))))]
       [Av 
        (lambda: ((x : (Vectorof Float)) (y : (Vectorof Float)) (N : Natural))
          (for: ([i : Natural (in-range N)])
            (vector-set!
             y i
             (let: L : Float ([a : Float 0.0] [j : Natural 0])
               (if (= j N) a
                   (L (+ a (* (vector-ref x j) (A i j)))
                      (+ j 1)))))))]
       [Atv
        (lambda: ((x : (Vectorof Float)) (y : (Vectorof Float)) (N : Natural))
          (for: ([i : Natural (in-range N)])
            (vector-set!
             y i
             (let: L : Float ([a : Float 0.0] [j : Natural 0])
               (if (= j N) a
                   (L (+ a (* (vector-ref x j) (A j i)))
                      (+ j 1)))))))]
       [AtAv (lambda: ((x : (Vectorof Float)) (y : (Vectorof Float)) (t : (Vectorof Float)) (N : Natural))
               (Av x t N) (Atv t y N))]
       [N (command-line #:args (#{n : String}) (assert (string->number n) exact-nonnegative-integer?))]
       [u (make-vector N 1.0)]
       [v (make-vector N 0.0)]
       [t (make-vector N 0.0)])
  (for: ([i : Natural (in-range 10)])
    (AtAv u v t N)
    (AtAv v u t N))
  (displayln (real->decimal-string 
              (flsqrt 
               (let: L : Float ([vBv : Float 0.0] [vv : Float 0.0] [i : Natural 0])
                 (if (= i N) (/ vBv vv)
                     (let ([ui (vector-ref u i)] [vi (vector-ref v i)])
                       (L (+ vBv (* ui vi))
                          (+ vv (* vi vi))
                          (+ i 1))))))
              9)))
