Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: coalton struct regression #888

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/discrete/numeric/cyclotomic8.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@
(fraction->reciprocable (to-fraction x)))
y)
((Cyclotomic8 a b c d)
(+ (+ (.* a (cis (/ (* 3 pi) 4)))
(.* b (cis (/ pi 2))))
(+ (.* c (cis (/ pi 4)))
(+ (+ (s* a (cis (/ (* 3 pi) 4)))
(s* b (cis (/ pi 2))))
(+ (s* c (cis (/ pi 4)))
(complex d 0))))))

(define-instance ((Complex :a)
Expand Down
2 changes: 1 addition & 1 deletion src/discrete/numeric/interval.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
(Interval (fromInt a) (fromInt a))))

(define-instance ((Ord :r) (Num :r) => (Linear (Interval :r) :r))
(define (.* a i)
(define (s* a i)
(match i
((Interval l r)
(if (>= a 0)
Expand Down
22 changes: 11 additions & 11 deletions src/discrete/numeric/linear-algebra.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ For example an N x N matrix has degree N."
(degree (:a -> Integer)))

(define-class ((Scalar :v :s) => (Linear :v :s))
"Defines scalar multiplication where (.* x (+ v u)) = (+ (.* x u) (.* x v))"
(.* (:s -> :v -> :v)))
"Defines scalar multiplication where (s* x (+ v u)) = (+ (s* x u) (s* x v))"
(s* (:s -> :v -> :v)))

(declare *. ((Linear :v :e) (Num :e) => (:v -> :e -> :v)))
(define (*. v s) (.* s v))
(declare *s ((Linear :v :e) (Num :e) => (:v -> :e -> :v)))
(define (*s v s) (s* s v))

(declare ./ ((Linear :v :e) (Reciprocable :e)
(declare s/ ((Linear :v :e) (Reciprocable :e)
=> (:e -> :v -> :v)))
(define (./ s v) (.* (/ 1 s) v))
(define (s/ s v) (s* (/ 1 s) v))

(declare /. ((Linear :v :e) (Reciprocable :e)
(declare /s ((Linear :v :e) (Reciprocable :e)
=> (:v -> :e -> :v)))
(define (/. v s) (./ s v))
(define (/s v s) (s/ s v))

(define-class ((Linear :v :e) => (Inner :v :e))
"An (indefinite) inner product that should satisfy:
- (<.> x y) = (<.> y x)
- (<.> z (+ (.* a x) (.* b y))) = (+ (*. (<.> z x) a) (*. (<.> z y) b)) "
- (<.> z (+ (s* a x) (s* b y))) = (+ (*s (<.> z x) a) (*s (<.> z y) b)) "
(<.> (:v -> :v -> :e)))

;; Note that normed spaces are a superset of definite inner product spaces.
(define-class ((Linear :v :e) => (Normed :v :e))
"A (indefinite) normed space that should satisify
- (norm (+ x y)) <= (+ (norm x) (norm y))
- (norm (.* s x)) = (* |s| (norm x))"
- (norm (s* s x)) = (* |s| (norm x))"
(norm (:v -> :e)))

(declare square-norm ((Inner :v :e) => (:v -> :e)))
Expand Down Expand Up @@ -263,7 +263,7 @@ Hermitian adjoint, or related involution - often notated †."

(define-instance ((Complex :e) (Num :e) (Num (Complex :e))
=> (Linear (Complex :e) :e))
(define (.* s v)
(define (s* s v)
(complex (* s (real-part v)) (* s (imag-part v)))))

(define-instance ((Linear (Complex :e) :e) (Complex :e)
Expand Down
2 changes: 1 addition & 1 deletion src/discrete/numeric/root2plex.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
(negate (floor (negate x)))))

(define-instance ((Num :a) => (Linear (Root2plex :a) :a))
(define (.* s v)
(define (s* s v)
(match v
((Root2plex a b)
(Root2plex (* s a) (* s b))))))
Expand Down
6 changes: 4 additions & 2 deletions src/discrete/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
)
;; linear-algebra.lisp
(:export
#:.*
#:*.
#:s*
#:*s
#:/s
#:s/
#:Inner
#:<.>
#:square-norm
Expand Down
12 changes: 6 additions & 6 deletions src/discrete/rz-approx/candidate-generation.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ to Corrolary 19 (arXiv:1212.6253v2)."
;; Base case finds an a + b√2 with an even a-term
(match (interval-solution
;; [x_0 / √2, x_1 / √2]
(*. x-set (Root2plex 0 (exact/ 1 2)))
(*s x-set (Root2plex 0 (exact/ 1 2)))
;; [-y_1 / √2, -y_0 / √2]
(.* (the (Root2plex Fraction) -1)
(*. y-set (Root2plex 0 (exact/ 1 2)))))
(s* (the (Root2plex Fraction) -1)
(*s y-set (Root2plex 0 (exact/ 1 2)))))
;; Give a + b √2
;; Return (2 * b) + a √2
((Root2plex a b) (Root2plex (* 2 b) a)))
Expand Down Expand Up @@ -238,7 +238,7 @@ rotation of the original vector U. That is:
(let u-a = (- (norm u) l))
;; (sin (arccos x)) = √(1 - x²)
(let u-b = (sqrt (- 1 (^ u-a 2))))
(Tuple (.* u-a u) (.* u-b u-orth)))
(Tuple (s* u-a u) (s* u-b u-orth)))

(declare j-sub-interval (Fraction -> (Interval Fraction) -> Integer
-> (Interval Fraction)))
Expand Down Expand Up @@ -378,8 +378,8 @@ Lemma 17 and this function corresponds to Theorem 22 in (arXiv:1212.6253v2)."
(let x0 = (parallelogram-segment lin delta-x beta-hat))
(let alpha-interval =
(if negate-x?
(.* scale (Interval (- x0 (into l-rational)) x0))
(.* scale (Interval x0 (+ x0 (into l-rational))))))
(s* scale (Interval (- x0 (into l-rational)) x0))
(s* scale (Interval x0 (+ x0 (into l-rational))))))
(let a-odd? = (odd? (root2-real-part beta)))
(let alpha = (rescaled-interval-solution
(not a-odd?) alpha-interval conj-interval))
Expand Down
9 changes: 7 additions & 2 deletions src/discrete/rz-approx/generate-solution.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ half of Algorithm 23 (arXiv:1212.6253v2)."
(into x)))))
(find-candidate attempts epsilon theta n))))

(monomorphize)
;; TODO: monomorphize was here but it won't compile as of Fri Jun 16 10:32:29 PDT 2023
;; (monomorphize)
(declare generate-maform-output-with-double
(Integer -> Integer -> Double-Float -> Double-float -> (Optional (List OutputGate1))))
(define (generate-maform-output-with-double candidate-attempts prime-attempts epsilon theta)
Expand Down Expand Up @@ -219,4 +220,8 @@ See `generate-solution' for information about EPSILON and THETA."
(map into ma)))))))))
(same-type theta
(global-phase-invariant-distance
m1 (map cyclotomic8->complex m2)))))
m1 (map cyclotomic8->complex m2))))



)
Loading