Nonnegative-Floats are now generalized to Floats.

This commit is contained in:
Vincent St-Amour 2010-06-30 19:32:11 -04:00
parent de277d5d89
commit 06279de2ca
8 changed files with 20 additions and 24 deletions

View File

@ -76,8 +76,7 @@ Correct output N = 1000 is
;; -------------------------------
(: offset-momentum ( -> Void))
(define (offset-momentum)
(let: loop-i : Void ([i : (Listof body) *system*]
[px : Float 0.0] [py : Float 0.0] [pz : Float 0.0])
(let loop-i ([i *system*] [px 0.0] [py 0.0] [pz 0.0])
(if (null? i)
(begin
(set-body-vx! (car *system*) (/ (- px) +solar-mass+))
@ -92,7 +91,7 @@ Correct output N = 1000 is
;; -------------------------------
(: energy ( -> Float))
(define (energy)
(let: loop-o : Float ([o : (Listof body) *system*] [e : Float 0.0])
(let loop-o ([o *system*] [e 0.0])
(if (null? o)
e
(let* ([o1 (car o)]

View File

@ -85,8 +85,7 @@ Correct output N = 1000 is
;; -------------------------------
(: offset-momentum ( -> Void))
(define (offset-momentum)
(let: loop-i : Void ([i : Natural 0]
[px : Float 0.0] [py : Float 0.0] [pz : Float 0.0])
(let loop-i ([i 0] [px 0.0] [py 0.0] [pz 0.0])
(if (= i *system-size*)
(begin
(set-body-vx! (vector-ref *system* 0) (/ (- px) +solar-mass+))
@ -101,7 +100,7 @@ Correct output N = 1000 is
;; -------------------------------
(: energy ( -> Float))
(define (energy)
(let: loop-o : Float ([o : Natural 0] [e : Float 0.0])
(let loop-o ([o 0] [e 0.0])
(if (= o *system-size*)
e
(let* ([o1 (vector-ref *system* o)]

View File

@ -90,8 +90,7 @@ Correct output N = 1000 is
;; -------------------------------
(: offset-momentum ( -> Void))
(define (offset-momentum)
(let: loop-i : Void ([i : Natural 0]
[px : Float 0.0] [py : Float 0.0] [pz : Float 0.0])
(let loop-i ([i 0] [px 0.0] [py 0.0] [pz 0.0])
(if (unsafe-fx= i *system-size*)
(begin
(set-body-vx! (unsafe-vector-ref *system* 0) (fl/ (fl- 0.0 px) +solar-mass+))
@ -106,7 +105,7 @@ Correct output N = 1000 is
;; -------------------------------
(: energy ( -> Float))
(define (energy)
(let: loop-o : Float ([o : Natural 0] [e : Float 0.0])
(let loop-o ([o 0] [e 0.0])
(if (unsafe-fx= o *system-size*)
e
(let* ([o1 (unsafe-vector-ref *system* o)]

View File

@ -85,8 +85,7 @@ Correct output N = 1000 is
;; -------------------------------
(: offset-momentum ( -> Void))
(define (offset-momentum)
(let: loop-i : Void ([i : Natural 0]
[px : Float 0.0] [py : Float 0.0] [pz : Float 0.0])
(let loop-i ([i 0] [px 0.0] [py 0.0] [pz 0.0])
(if (= i *system-size*)
(begin
(set-body-vx! (vector-ref *system* 0) (fl/ (fl- 0.0 px) +solar-mass+))
@ -101,7 +100,7 @@ Correct output N = 1000 is
;; -------------------------------
(: energy ( -> Float))
(define (energy)
(let: loop-o : Float ([o : Natural 0] [e : Float 0.0])
(let loop-o ([o 0] [e 0.0])
(if (= o *system-size*)
e
(let* ([o1 (vector-ref *system* o)]

View File

@ -77,8 +77,7 @@ Correct output N = 1000 is
;; -------------------------------
(: offset-momentum ( -> Void))
(define (offset-momentum)
(let: loop-i : Void ([i : (Listof body) *system*]
[px : Float 0.0] [py : Float 0.0] [pz : Float 0.0])
(let loop-i ([i *system*] [px 0.0] [py 0.0] [pz 0.0])
(if (null? i)
(begin
(set-body-vx! (car *system*) (fl/ (fl- 0.0 px) +solar-mass+))
@ -93,7 +92,7 @@ Correct output N = 1000 is
;; -------------------------------
(: energy ( -> Float))
(define (energy)
(let: loop-o : Float ([o : (Listof body) *system*] [e : Float 0.0])
(let loop-o ([o *system*] [e 0.0])
(if (null? o)
e
(let* ([o1 (car o)]

View File

@ -45,8 +45,8 @@
(define (MultiplyAv n v Av)
(for ([i (in-range n)])
(flvector-set! Av i
(for/fold: : Float ([r : Float 0.0])
([j : Natural (in-range n)])
(for/fold ([r 0.0])
([j (in-range n)])
(fl+ r (fl* (A i j) (flvector-ref v j)))))))
;; multiply vector v by matrix A transposed
@ -54,8 +54,8 @@
(define (MultiplyAtv n v Atv)
(for ([i (in-range n)])
(flvector-set! Atv i
(for/fold: : Float ([r : Float 0.0])
([j : Natural (in-range n)])
(for/fold ([r 0.0])
([j (in-range n)])
(fl+ r (fl* (A j i) (flvector-ref v j)))))))
;; multiply vector v by matrix A and then by matrix A transposed

View File

@ -18,7 +18,7 @@
;; B=AtA A multiplied by A transposed
;; v.Bv /(v.v) eigenvalue of v
(let: loop : Float ([i : Natural 0][vBv : Float 0.0][vv : Float 0.0])
(let loop ([i 0][vBv 0.0][vv 0.0])
(if (= i n)
(flsqrt (fl/ vBv vv))
(let ([vi (flvector-ref v i)])
@ -38,8 +38,8 @@
(define (MultiplyAv n v Av)
(for: : Void ([i : Natural (in-range n)])
(flvector-set! Av i
(for/fold: : Float ([r : Float 0.0])
([j : Natural (in-range n)])
(for/fold ([r 0.0])
([j (in-range n)])
(fl+ r (fl* (A i j) (flvector-ref v j)))))))
;; multiply vector v by matrix A transposed
@ -47,8 +47,8 @@
(define (MultiplyAtv n v Atv)
(for: : Void ([i : Natural (in-range n)])
(flvector-set! Atv i
(for/fold: : Float ([r : Float 0.0])
([j : Natural (in-range n)])
(for/fold ([r 0.0])
([j (in-range n)])
(fl+ r (fl* (A j i) (flvector-ref v j)))))))
;; multiply vector v by matrix A and then by matrix A transposed

View File

@ -33,6 +33,7 @@
[(Value: 0) -Nat]
[(? (lambda (t) (subtype t -Nat))) -Nat]
[(? (lambda (t) (subtype t -Integer))) -Integer]
[(? (lambda (t) (subtype t -Flonum))) -Flonum]
[(Mu: var (Union: (list (Value: '()) (Pair: _ (F: var))))) t*]
[(Pair: t1 (Value: '())) (-lst t1)]
[(MPair: t1 (Value: '())) (-mlst t1)]