Code Monkey home page Code Monkey logo

Comments (3)

NoahStoryM avatar NoahStoryM commented on July 28, 2024 1

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.

countvajhula avatar countvajhula commented on July 28, 2024 1

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.

NoahStoryM avatar NoahStoryM commented on July 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.