networks: Make sectioning more fine-grained.
This commit is contained in:
parent
aa7ba6de8a
commit
75b19c7977
2 changed files with 16 additions and 9 deletions
|
@ -208,7 +208,7 @@
|
||||||
#hash((a . #f) (b . #t)) #hash((a . #t) (b . #t)))
|
#hash((a . #f) (b . #t)) #hash((a . #t) (b . #t)))
|
||||||
(set (set 'a)))))
|
(set (set 'a)))))
|
||||||
|
|
||||||
(test-case "Functions"
|
(test-case "Tabulating functions and networks"
|
||||||
(check-equal? (tabulate/domain-list (λ (x y) (and x y)) '((#f #t) (#f #t)))
|
(check-equal? (tabulate/domain-list (λ (x y) (and x y)) '((#f #t) (#f #t)))
|
||||||
'((#f #f #f) (#f #t #f) (#t #f #f) (#t #t #t)))
|
'((#f #f #f) (#f #t #f) (#t #f #f) (#t #t #t)))
|
||||||
(check-equal? (tabulate (λ (x y) (and x y)) '(#f #t) '(#f #t))
|
(check-equal? (tabulate (λ (x y) (and x y)) '(#f #t) '(#f #t))
|
||||||
|
@ -216,7 +216,9 @@
|
||||||
(check-equal? (tabulate/boolean (lambda (x y) (and x y)))
|
(check-equal? (tabulate/boolean (lambda (x y) (and x y)))
|
||||||
'((#f #f #f) (#f #t #f) (#t #f #f) (#t #t #t)))
|
'((#f #f #f) (#f #t #f) (#t #f #f) (#t #t #t)))
|
||||||
(let ([func (λ (st) (not (hash-ref st 'a)))])
|
(let ([func (λ (st) (not (hash-ref st 'a)))])
|
||||||
(check-equal? (tabulate-state/boolean func '(a)) '((a f) (#f #t) (#t #f))))
|
(check-equal? (tabulate-state/boolean func '(a)) '((a f) (#f #t) (#t #f)))))
|
||||||
|
|
||||||
|
(test-case "Constructing functions"
|
||||||
(check-equal? (boolean-power 2) '((#f #f) (#f #t) (#t #f) (#t #t)))
|
(check-equal? (boolean-power 2) '((#f #f) (#f #t) (#t #f) (#t #t)))
|
||||||
(check-equal? (stream->list (boolean-power/stream 2)) '((#f #f) (#f #t) (#t #f) (#t #t)))
|
(check-equal? (stream->list (boolean-power/stream 2)) '((#f #f) (#f #t) (#t #f) (#t #t)))
|
||||||
(let ([negation (table->function '((#t #f) (#f #t)))]
|
(let ([negation (table->function '((#t #f) (#f #t)))]
|
||||||
|
@ -228,7 +230,7 @@
|
||||||
(check-false (f1 #f)) (check-false (f1 #t))
|
(check-false (f1 #f)) (check-false (f1 #t))
|
||||||
(check-false (f1/list '(#f))) (check-false (f1/list '(#t)))))
|
(check-false (f1/list '(#f))) (check-false (f1/list '(#t)))))
|
||||||
|
|
||||||
(test-case "Random Boolean functions and networks"
|
(test-case "Random functions and networks"
|
||||||
(random-seed 0)
|
(random-seed 0)
|
||||||
(check-equal? (random-boolean-table 2) '((#f #f #t) (#f #t #t) (#t #f #f) (#t #t #f)))
|
(check-equal? (random-boolean-table 2) '((#f #f #t) (#f #t #t) (#t #f #f) (#t #t #f)))
|
||||||
(let ([f (random-boolean-function 2)])
|
(let ([f (random-boolean-function 2)])
|
||||||
|
|
17
networks.rkt
17
networks.rkt
|
@ -404,9 +404,9 @@
|
||||||
(list->set (build-all-boolean-states (hash-keys (dynamics-network dyn))))))
|
(list->set (build-all-boolean-states (hash-keys (dynamics-network dyn))))))
|
||||||
|
|
||||||
|
|
||||||
;;; =========
|
;;; =================================
|
||||||
;;; Functions
|
;;; Tabulating functions and networks
|
||||||
;;; =========
|
;;; =================================
|
||||||
|
|
||||||
;;; Given a function and a list of domains for each of its arguments,
|
;;; Given a function and a list of domains for each of its arguments,
|
||||||
;;; in order, produces a list of lists giving the values of arguments
|
;;; in order, produces a list of lists giving the values of arguments
|
||||||
|
@ -446,6 +446,11 @@
|
||||||
(define (tabulate-state/boolean func args #:headers [headers #t])
|
(define (tabulate-state/boolean func args #:headers [headers #t])
|
||||||
(tabulate-state func (make-boolean-domains args) #:headers headers))
|
(tabulate-state func (make-boolean-domains args) #:headers headers))
|
||||||
|
|
||||||
|
|
||||||
|
;;; ======================
|
||||||
|
;;; Constructing functions
|
||||||
|
;;; ======================
|
||||||
|
|
||||||
;;; Given a table like the one produced by the tabulate functions,
|
;;; Given a table like the one produced by the tabulate functions,
|
||||||
;;; creates a function which has this behaviour.
|
;;; creates a function which has this behaviour.
|
||||||
;;;
|
;;;
|
||||||
|
@ -504,9 +509,9 @@
|
||||||
(stream-map table->function/list (enumerate-boolean-tables n)))
|
(stream-map table->function/list (enumerate-boolean-tables n)))
|
||||||
|
|
||||||
|
|
||||||
;;; =====================================
|
;;; =============================
|
||||||
;;; Random Boolean functions and networks
|
;;; Random functions and networks
|
||||||
;;; =====================================
|
;;; =============================
|
||||||
|
|
||||||
;;; Generates a random truth table for a Boolean function of arity n.
|
;;; Generates a random truth table for a Boolean function of arity n.
|
||||||
(define (random-boolean-table n)
|
(define (random-boolean-table n)
|
||||||
|
|
Loading…
Reference in a new issue