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

Correct normalizations #133

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
10 changes: 1 addition & 9 deletions qi-lib/flow/core/normalize.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
;; (~> (pass f) (>< g)) → (>< (if f g ⏚))
[(thread _0 ... (pass f) (amp g) _1 ...)
#'(thread _0 ... (amp (if f g ground)) _1 ...)]
;; merge amps in sequence
[(thread _0 ... (amp f) (amp g) _1 ...)
#'(thread _0 ... (amp (thread f g)) _1 ...)]
;; merge pass filters in sequence
[(thread _0 ... (pass f) (pass g) _1 ...)
#'(thread _0 ... (pass (and f g)) _1 ...)]
Expand All @@ -48,9 +45,6 @@
;; composition of identity flows is the identity flow
[(thread (~datum _) ...)
#'_]
;; identity flows composed using a relay
[(relay (~datum _) ...)
#'_]
;; amp and identity
[(amp (~datum _))
#'_]
Expand All @@ -69,11 +63,9 @@
;; and we can only know this at runtime.
[(thread _0 ... collect sep _1 ...)
#'(thread _0 ... _1 ...)]
;; collapse `values` and `_` inside a threading form
;; collapse `values` inside a threading form
[(thread _0 ... (esc (#%host-expression (~literal values))) _1 ...)
#'(thread _0 ... _1 ...)]
[(thread _0 ... (~datum _) _1 ...)
#'(thread _0 ... _1 ...)]
[(#%blanket-template (hex __))
#'hex]
;; return syntax unchanged if there are no applicable normalizations
Expand Down
13 changes: 1 addition & 12 deletions qi-test/tests/compiler/rules.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,6 @@
(pass f)
(amp g))
#'(amp (if f g ground)))
(test-normalize "merge amps in sequence"
#'(thread (amp f) (amp g))
#'(amp (thread f g)))
(test-normalize "merge pass filters in sequence"
#'(thread (pass f) (pass g))
#'(pass (and f g)))
Expand Down Expand Up @@ -496,11 +493,6 @@
#'(thread _ _)
#'(thread _)
#'_)
(test-normalize "relay composition of identity flows"
#'(relay _ _ _)
#'(relay _ _)
#'(relay _)
#'_)
(test-normalize "amp under identity"
#'(amp _)
#'_)
Expand All @@ -524,10 +516,7 @@
;; #'(thread f))
(test-normalize "_ is collapsed inside ~>"
#'(thread _ f _)
#'(thread f))
(test-normalize "consecutive amps are combined"
#'(thread (amp f) (amp g))
#'(thread (amp (thread f g)))))
#'(thread f)))

(test-suite
"compilation sequences"
Expand Down
60 changes: 45 additions & 15 deletions qi-test/tests/flow.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -1540,25 +1540,55 @@
;; "equivalences" that are not really equivalences are formally checked
(test-suite
"counterexamples"
(let ()
(define-flow g (-< add1 sub1))
(define-flow f positive?)
(define (f* x y) (= (sub1 x) (add1 y)))
(define (amp-pass g f) (☯ (~> (>< g) (pass f) ▽)))
(define (amp-if g f) (☯ (~> (>< (~> g (if f _ ground))) ▽)))
(check-equal? (apply (amp-pass g f) (range -3 4))
(test-suite
"(~> (>< g) (pass f)) ─/→ (>< (~> g (if f _ ⏚)))"
(let ()
(define-flow g (-< add1 sub1))
(define-flow f positive?)
(define (f* x y) (= (sub1 x) (add1 y)))
(define (amp-pass g f) (☯ (~> (>< g) (pass f) ▽)))
(define (amp-if g f) (☯ (~> (>< (~> g (if f _ ground))) ▽)))
(test-equal? "amp-pass"
(apply (amp-pass g f) (range -3 4))
(list 1 2 3 1 4 2))
(check-exn exn:fail?
(thunk (apply (amp-if g f) (range -3 4))))
(check-exn exn:fail?
(test-exn "amp-pass"
exn:fail?
(thunk (apply (amp-pass g f*) (range -3 4))))
(check-equal? (apply (amp-if g f*) (range -3 4))
(test-exn "amp-if"
exn:fail?
(thunk (apply (amp-if g f) (range -3 4))))
(test-equal? "amp-if"
(apply (amp-if g f*) (range -3 4))
(list -2 -4 -1 -3 0 -2 1 -1 2 0 3 1 4 2)))
(let ()
(check-equal? ((☯ (~> (>< string->number) (pass _))) "a" "2" "c")
(let ()
(test-equal? "amp-pass"
((☯ (~> (>< string->number) (pass _))) "a" "2" "c")
2)
(check-equal? ((☯ (~> (>< (if _ string->number ground)) ▽)) "a" "2" "c")
(list #f 2 #f)))))))
(test-equal? "amp-if"
((☯ (~> (>< (if _ string->number ground)) ▽)) "a" "2" "c")
(list #f 2 #f))))
(test-suite
"(~> (>< f) (>< g)) ─/→ (>< (~> f g))"
(test-equal? "amp-amp"
((☯ (~> (>< (-< add1 sub1))
(>< (-< sub1 add1))
▽))
3)
(list 3 5 1 3))
(test-exn "merged amp"
exn:fail?
(thunk
((☯ (>< (~> (-< add1 sub1)
(-< sub1 add1))))
3))))
(test-suite
"(~> (== _ ...)) ─/→ _"
(test-exn "relay-_"
exn:fail?
(thunk
((☯ (== _ _ _))
3)))
(test-equal? "relay-_" ((☯ _) 3) 3))))))

(module+ main
(void (run-tests tests)))
Loading