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

Matrix lenses? #286

Open
AlexKnauth opened this issue Sep 7, 2016 · 2 comments
Open

Matrix lenses? #286

AlexKnauth opened this issue Sep 7, 2016 · 2 comments

Comments

@AlexKnauth
Copy link
Collaborator

Should there be a lens constructor for matrices as functions from column-vectors to column-vectors?

For square invertable matrices it could be an isomorphism lens.

(define (matrix-lens/invertable m)
  (define m^-1 (matrix-inverse m))
  (make-isomorphism-lens
   (λ (a) (matrix* m a))
   (λ (b*) (matrix* m^-1 b*))))

But for non-invertable matrices (including non-square?), the setter function will sometimes have infinitely many results that would be valid.

(define (matrix-lens/noninvertable m)
  (make-lens
   (λ (a)
     ;; M*A = B
     (matrix* m a))
   (λ (a b*)
     ;; M*A = B
     (define b (matrix* m a))
     ;; M*A' = B'
     ;; What is A'?
     ;; There are many solutions if M has no inverse;
     ;; Which is the best one, which follows the lens laws?
     ;; The lens laws make the constraint that when B = B', the result should be A.
     ;; But that only helps in one specific case. What should this do?
     (define a->b (matrix- b a))
     (define b->b* (matrix- b* b))
     (error 'matrix-lens "I don't know what do if it's not an invertable matrix"))))

Are there any other constraints having to do with continuous-ness or anything else that would help make a sensible lens out of a non-invertable matrix?

@jackfirth
Copy link
Owner

Lenses for things provided from the math library in general could be very useful, but I'm not sure they should go in the main lens package. A side package like collections-lens would be better.

@AlexKnauth
Copy link
Collaborator Author

That makes sense. (And it would only have to depend on lens-common!) I'll do that once this is figured out.

Also, do you have any ideas for how the setter should use the original target vector to resolve which of the possible solutions it should return, and which would be the best for the lens laws?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants