rs: Start.

This commit is contained in:
Sergiu Ivanov 2020-03-01 19:05:28 +01:00
parent 007c5b96bf
commit bb247d9eb8
2 changed files with 43 additions and 0 deletions

12
rs-tests.rkt Normal file
View File

@ -0,0 +1,12 @@
#lang typed/racket
;;; Tests for dds/rs.
(require typed/rackunit "rs.rkt")
(test-case "Basic definitions"
(let ([r (reaction (set 'a) (set 'b) (set 'c))]
[s1 (set 'a 'c)]
[s2 (set 'a 'b)])
(check-true (enabled? r s1))
(check-false (enabled? r s2))))

31
rs.rkt Normal file
View File

@ -0,0 +1,31 @@
#lang typed/racket
;;; dds/rs
;;; Definitions for working with reaction systems.
(provide
;; Structures
reaction
;; Functions
enabled?)
;;; =================
;;; Basic definitions
;;; =================
;;; A species is a symbol.
(define-type Species Symbol)
;;; A reaction is a triple of sets, giving the reactants, the
;;; inhibitors, and the products, respectively.
(struct reaction ([reactants : (Setof Symbol)]
[inhibitors : (Setof Symbol)]
[products : (Setof Symbol)]))
;;; A reaction is enabled on a set if all of its reactants are in the
;;; set and none of its inhibitors are.
(: enabled? (-> reaction (Setof Symbol) Boolean))
(define/match (enabled? r s)
[((reaction r i p) s)
(and (subset? r s) (set-empty? (set-intersect i s)))])