diff --git a/generic.rkt b/generic.rkt index ccfb928..44763f7 100644 --- a/generic.rkt +++ b/generic.rkt @@ -11,11 +11,25 @@ ;; Generics gen:dds ;; Functions - (contract-out [dds-step-one (-> dds? any/c (set/c any/c))]) + (contract-out [dds-step-one (-> dds? any/c (set/c any/c))] + [dds-step (-> dds? (set/c any/c) (set/c any/c))]) ;; Predicates (contract-out [dds? (-> any/c boolean?)])) +;;; Given a dds and a set of starting states, produce the set of +;;; states reachable in one step. This is a fallback for dds-step. +(define (fallback-dds-step dds ss) + (list->set (flatten (for/list ([s ss]) (dds-step-one dds s))))) + ;;; A discrete dynamical system. (define-generics dds ;; Given a dds and a state, produce the next states of the dds. - (dds-step-one dds state)) + (dds-step-one dds state) + ;; Given a dds and a set of starting states, produce the set of + ;; states reachable in one step. This method falls back to running + ;; dds-step-one for all states. + (dds-step dds states) + + #:defined-predicate dds-implements? + #:fallbacks + [(define dds-step fallback-dds-step)]) diff --git a/networks-tests.rkt b/networks-tests.rkt index cb1bc72..ce91a36 100644 --- a/networks-tests.rkt +++ b/networks-tests.rkt @@ -113,5 +113,9 @@ [syn (make-syn-dynamics n)] [s (st '((a . #t) (b . #f)))]) (check-equal? (dds-step-one asyn s) (set (st '((a . #f) (b . #f))) - (st '((a . #t) (b . #f))))) - (check-equal? (dds-step-one syn s) (set (st '((a . #f) (b . #f))))))) + (st '((a . #t) (b . #f))))) + (check-equal? (dds-step-one syn s) (set (st '((a . #f) (b . #f))))) + (check-equal? (dds-step asyn (set (st '((a . #t) (b . #t))) + (st '((a . #f) (b . #t))))) + (set (st '((a . #f) (b . #t))) + (st '((a . #t) (b . #t))))))) diff --git a/networks.rkt b/networks.rkt index 1032bcb..02e7b90 100644 --- a/networks.rkt +++ b/networks.rkt @@ -36,7 +36,8 @@ [make-dynamics-from-func (-> network? (-> (listof variable?) mode?) dynamics?)] [make-asyn-dynamics (-> network? dynamics?)] [make-syn-dynamics (-> network? dynamics?)] - [dds-step-one (-> dynamics? state? (set/c state?))]) + [dds-step-one (-> dynamics? state? (set/c state?))] + [dds-step (-> dynamics? (set/c state?) (set/c state?))]) ;; Predicates (contract-out [variable? (-> any/c boolean?)] [state? (-> any/c boolean?)]