Comments (3)
Hello @chansey97
I agree that the -<
operator should have a symmetric counterpart. In Qi, the values
we work with can be viewed categorically as product objects, which naturally have a dual concept: sum objects. Therefore, not only -<
, but other operators such as ><
, ==*
, fanout
, n>
, ⏚
, etc., that handle values
(product objects), should also have symmetric operators for handling covalues
(sum objects), like <>
, ==+
, fanin
, n<
, ≂
, etc.. Here is our previous discussion: #62 (comment).
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 covalues
, it's essentially values
tagged with a natural number. For instance, (values 1 "a")
represents a value in Number × String
, whereas (covalues '(1 2) 0)
and (covalues '(a b) 1)
represent values in (Number × Number) + (Symbol × Symbol)
.
The -<
operator corresponds to the categorical concept of pairing. For example, given a : G -> X
and b : G -> Y
, then (-< a b) : G -> X × Y
.
The dual of -<
is >-
, known as copairing, which operates as follows: given a : X -> T
and b : Y -> T
, then (>- a b) : X + Y -> T
.
from qi.
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 (~datum
) to matching literals (~literal
). See Literally Causing Problems for more details on how this can affect applications. If you have time, you may want to test qi-cat
with the lets-write-a-qi-compiler
branch to see if it is affected (but you may want to wait until later today as we are hoping to merge a few PRs including First Optimizations). It would also be helpful in general to see if we've broken anything else!
from qi.
Hi @countvajhula ,
I’ve tried lets-write-a-qi-compiler
and all the qi-cat
tests passed. I didn’t notice any issues.
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 values
processed by qi
. For example, (~> (1 1 1) (-< D E))
results in (values 14 10 11 15 16 19)
, which we can view as a 3×2 matrix. If we transpose it, we get (values 14 15 10 16 11 19)
, and then we can use ><
, which can distribute input values (#64) , to get (values 29 26 30)
.
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 transpose+
, which deals with covalues
.
By the way, for/values
seems to be very useful for qi
. Do you think it’s worth considering implementing it in qi?
from qi.
Related Issues (20)
- Tracing flows for debugging HOT 1
- Error message shows core instead of surface language
- Bad error message on mistakenly providing keyword arguments
- `ground` could be compiled to `(lambda _ (values))`, which might be more efficient HOT 1
- Where to host the Qi wiki?
- Add source code links in meeting notes
- Revisit use of the name `pass` HOT 2
- Should we support `((f))` syntax for higher order functions? HOT 2
- Move backup docs into a subfolder on the Pages site
- Incorporate the new benchmarking suite into CI HOT 1
- Review premature termination of multi-level optimization HOT 2
- Language composition to extend the compiler
- Investigate hierarchical reporting of expansion events in the compiler
- Reliably detect and deforest list-like operations on pure values HOT 2
- Arity inference compiler pass
- Formally specify Qi Normal Form
- Identify other cases where we could support bindings
- Methodology to formalize and theoretically validate compiler behavior
- Review `feedback` for ways to keep minutiae abstracted
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qi.