dds/generic.rkt

36 lines
1.0 KiB
Racket
Raw Normal View History

2020-02-23 12:19:37 +01:00
#lang racket
;;; dds/generic
;;; Provides the definition of several generic interfaces for discrete
;;; dynamical systems.
(require racket/generic)
(provide
;; Generics
gen:dds
;; Functions
2020-02-23 13:28:51 +01:00
(contract-out [dds-step-one (-> dds? any/c (set/c any/c))]
[dds-step (-> dds? (set/c any/c) (set/c any/c))])
2020-02-23 12:19:37 +01:00
;; Predicates
(contract-out [dds? (-> any/c boolean?)]))
2020-02-23 13:28:51 +01:00
;;; 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)))))
2020-02-23 12:19:37 +01:00
;;; A discrete dynamical system.
(define-generics dds
;; Given a dds and a state, produce the next states of the dds.
2020-02-23 13:28:51 +01:00
(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)])