From bb247d9eb88b3e167a7ca63ba80609d5dda9af10 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sun, 1 Mar 2020 19:05:28 +0100 Subject: [PATCH] rs: Start. --- rs-tests.rkt | 12 ++++++++++++ rs.rkt | 31 +++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 rs-tests.rkt create mode 100644 rs.rkt diff --git a/rs-tests.rkt b/rs-tests.rkt new file mode 100644 index 0000000..9601a08 --- /dev/null +++ b/rs-tests.rkt @@ -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)))) diff --git a/rs.rkt b/rs.rkt new file mode 100644 index 0000000..69e3dc7 --- /dev/null +++ b/rs.rkt @@ -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)))])