-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinimal.lean
More file actions
79 lines (61 loc) · 2.35 KB
/
Copy pathMinimal.lean
File metadata and controls
79 lines (61 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import Mathlib.Tactic.DeriveFintype
import CRNT.Basic.Complex
import CRNT.Basic.Reaction
import CRNT.Basic.Network
import CRNT.Stoich.Vector
import CRNT.Graph.Reachability
import CRNT.Graph.WeakReversibility
/-!
# Minimal example: a single irreversible reaction `A → B`
The smallest nontrivial network. It demonstrates building a `Network`, computing its
complex count, evaluating reaction vectors, and reasoning about (the failure of)
reachability. Being irreversible, it is **not** weakly reversible.
-/
namespace CRNT.Examples.Minimal
open CRNT
/-- Two species, `A` and `B`. -/
inductive Species
| A
| B
deriving DecidableEq, Fintype, Repr
open Species
/-- The complex consisting of one molecule of `A`. -/
def cA : Complex Species := fun s => match s with | A => 1 | B => 0
/-- The complex consisting of one molecule of `B`. -/
def cB : Complex Species := fun s => match s with | A => 0 | B => 1
/-- A single reaction channel. -/
inductive Rxn
| r1
deriving DecidableEq, Fintype, Repr
/-- The reaction map: `r1 : A → B`. -/
def rxn : Rxn → Reaction Species
| .r1 => { source := cA, target := cB }
/-- The network `A → B`. -/
def N : Network Species :=
{ R := Rxn, decEqR := inferInstance, fintypeR := inferInstance, reaction := rxn }
theorem cA_ne_cB : cA ≠ cB := by decide
/-- The network has exactly two complexes. -/
theorem numComplexes_eq : N.numComplexes = 2 := by decide
/-- There is one reaction. -/
theorem numReactions_eq : N.numReactions = 1 := by decide
/-- The reaction vector of `r1` is `B - A`: `-1` on `A` and `+1` on `B`. -/
theorem reactionVector_r1 :
N.reactionVector .r1 = fun s => match s with | A => (-1 : ℝ) | B => 1 := by
funext s
cases s <;>
simp [Network.reactionVector, N, rxn, Reaction.vector, cA, cB]
/-- From `B` no reaction fires, so `B` reaches nothing new. -/
theorem not_directlyReacts_from_cB (d : Complex Species) :
¬ N.DirectlyReacts cB d := by
rintro ⟨r, hs, -⟩
cases r
exact cA_ne_cB hs
/-- The network is not weakly reversible: there is no directed path from `B` back to
`A`. -/
theorem not_weaklyReversible : ¬ N.WeaklyReversible := by
intro h
have hr : Relation.ReflTransGen N.DirectlyReacts cB cA := h .r1
rcases Relation.ReflTransGen.cases_head hr with heq | ⟨e, hedge, -⟩
· exact cA_ne_cB heq.symm
· exact not_directlyReacts_from_cB e hedge
end CRNT.Examples.Minimal