#lang typed/racket ;;; dds/bn ;;; This module provides some quick definitions for running Boolean ;;; networks. A Boolean network is a set of Boolean variables which ;;; are updated according to their corresponding update functions. ;;; The variables to be updated at each step are given by the mode. (provide Variable State UpdateFunc Network update make-state make-bn) (define-type Variable Symbol) ;;; A state of a Boolean network is a mapping from the variables of the ;;; network to their Boolean values. (define-type State (HashTable Variable Boolean)) ;;; An update function is a Boolean function computing a Boolean value ;;; from the given state. (define-type UpdateFunc (-> State Boolean)) ;;; A Boolean network is a mapping from its variables to its update ;;; functions. (define-type Network (HashTable Variable UpdateFunc)) ;;; Given a state s updates all the variables from xs. This ;;; corresponds to a parallel mode. (: update (-> Network State (Listof Variable) State)) (define (update bn ; the Boolean network s ; the state to operate on xs) ; the variables to update (let ([new-s : State (hash-copy s)]) (for ([x xs]) (let ([f (hash-ref bn x)]) (hash-set! new-s x (f s)))) new-s)) ;;; A version of make-hash restricted to creating Boolean states. (: make-state (-> (Listof (Pairof Variable Boolean)) State)) (define (make-state mappings) (make-hash mappings)) ;;; A version of make-hash restricted to creating Boolean networks. (: make-bn (-> (Listof (Pairof Variable UpdateFunc)) Network)) (define (make-bn funcs) (make-hash funcs))