networks: Slightly optimize interaction?.

This commit is contained in:
Sergiu Ivanov 2020-11-15 00:02:44 +01:00
parent 8a1f4c682e
commit bfc48ff453

View File

@ -404,14 +404,15 @@
;;; state f(s') in which the value for y is different from f(s).
(define (interaction? network doms x y)
(define states-not-x (build-all-states (hash-remove doms x)))
(define dom-x (hash-ref doms x))
(define y-func (hash-ref network y))
(define (different-ys-exist? st)
(define x-states (for/list ([x-val (in-list (hash-ref doms x))])
(define x-states (for/list ([x-val (in-list dom-x)])
(hash-set st x x-val)))
(for*/first ([st1 x-states]
[st2 x-states]
#:unless (equal? (hash-ref st1 x) (hash-ref st2 x))
#:unless (equal? ((hash-ref network y) st1)
((hash-ref network y) st2)))
#:unless (equal? (y-func st1) (y-func st2)))
#t))
(for*/first ([st (in-list states-not-x)]
#:when (different-ys-exist? st))