-
Notifications
You must be signed in to change notification settings - Fork 13
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
Symmetry operator of -< #128
Comments
Hello @chansey97 I agree that the I’ve previously developed qi-cat, which implements these dual operators. Unfortunately, due to personal reasons, I haven’t been able to produce comprehensive documentation for it (I plan to address this when time permits). To briefly introduce The The dual of |
Btw @NoahStoryM , unrelated to the present issue but, we are gearing up to release Qi 4 which includes the optimizing compiler. One of the big changes with backwards compatibility implications is the change from matching datum literals ( |
Hi @countvajhula , I’ve tried Also, I read @chansey97’s code and I found an interesting way. It seems that we can perform a matrix-like transpose operation on the Here is the code: #lang racket
(require qi/cat (for-syntax syntax/parse))
;; 1 8 5
;; 3 4 3
;; 8 2 1
(define-flow D
(~> (-< (~> (== (* 1) (* 8) (* 5)) +)
(~> (== (* 3) (* 4) (* 3)) +)
(~> (== (* 8) (* 2) (* 1)) +))))
;; 9 4 2
;; 5 4 7
;; 8 4 7
(define-flow E
(~> (-< (~> (== (* 9) (* 4) (* 2)) +)
(~> (== (* 5) (* 4) (* 7)) +)
(~> (== (* 8) (* 4) (* 7)) +))))
(define add (procedure-reduce-arity + 2))
(define-syntax for/values
(syntax-parser
[(_ (clause ...) body ...+)
#'(apply values (for/list (clause ...) body ...))]))
(define (transpose* m n)
(λ arg*
(define v* (list->vector arg*))
(for/values ([id (in-range (* m n))])
(define-values (j i) (quotient/remainder id n))
(vector-ref v* (+ (* i m) j)))))
(define-flow D+E (~> (-< D E) (transpose* 3 2) (>< add)))
And it's not hard to implement the dual operator By the way, |
The operator
-<
currently is not symmetrical, i.e. lacks its mirror operator>-
.Two examples are provided below to demonstrate why it is useful.
The 1st one is the matrix addition.
Here is a possible solution:
The D+E seems ugly, because we have to collect them into a list, but I would like to write it like the following, if possible:
This example is inspired from Graphical Linear Algebra. In GLA, Pawel introduced a syntactic sugar called "m-wire". so the the string diagram of matrix addition can be simplified to:
Image from https://www.cs.ox.ac.uk/qpl2015/slides/sobocinski-tutorial.pdf p.25
The 2nd comes from meru.rkt
Using the expected operator
>-
, the solution would be more concise:P.S. This issue has been discussed on Racket Discord and @countvajhula proposed a solution. Currently we could write the following macro to workaround it.
More details see https://discord.com/channels/571040468092321801/979642553471221790/1182246331922780251
The text was updated successfully, but these errors were encountered: