Small parsimony problem
AbbreviationMin-plus cost semiring#✓fully proved
The cost semiring: MinTropical (WithTop ℕ), with min as addition and + as
multiplication.
abbrev Cost : Type := MinTropical (WithTop ℕ)
Used by 16
Sankoff's algorithm
DefinitionTotal substitution cost of a labeling#✓fully proved
The total substitution cost of a labeling x of the non-root vertices of t with root
state s: the sum over all edges of the cost untrop (P a b) from the parent's state a to
the child's state b.
def edgeCost : (t : Tree L S Cost) → S → Labeling t → WithTop ℕ
| leaf _, _, _ => 0
| node P l Q r, s, z =>
(untrop (P s z.1.1) + edgeCost l z.1.1 z.1.2) + (untrop (Q s z.2.1) + edgeCost r z.2.1 z.2.2)
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
abbrev Cost : Type := MinTropical (WithTop ℕ)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:70
def Labeling : Tree L S R → Type v
| leaf _ => PUnit
| node _ l _ r => (S × Labeling l) × (S × Labeling r)
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:101
Uses 3 · Used by 4
DefinitionLabeling agrees with the observed leaf states#✓fully proved
The labeling x (with root state s) agrees with the observed states σ at every leaf.
def Agrees (σ : L → S) : (t : Tree L S Cost) → S → Labeling t → Prop
| leaf l, s, _ => s = σ l
| node _ l _ r, _, z => Agrees σ l z.1.1 z.1.2 ∧ Agrees σ r z.2.1 z.2.2
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
abbrev Cost : Type := MinTropical (WithTop ℕ)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:70
def Labeling : Tree L S R → Type v
| leaf _ => PUnit
| node _ l _ r => (S × Labeling l) × (S × Labeling r)
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:101
Uses 3 · Used by 4
DefinitionTropical leaf weights of observed states#✓fully proved
The leaf weights of the observed states σ: the tropical one (cost 0) at the observed
state and the tropical zero (cost ⊤) at every other state.
def leafObs (σ : L → S) (l : L) (s : S) : Cost :=
if s = σ l then 1 else 0
abbrev Cost : Type := MinTropical (WithTop ℕ)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:70
Uses 1 · Used by 7
TheoremTropical weight of a labeling equals its edge cost#✓fully proved
The weight of a labeling in the tropical semiring is its edge cost if it agrees with the
leaf states and ⊤ otherwise.
theorem untrop_weight (σ : L → S) :
∀ (t : Tree L S Cost) (s : S) (x : Labeling t),
untrop (weight (leafObs σ) t s x) = if Agrees σ t s x then edgeCost t s x else ⊤
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
abbrev Cost : Type := MinTropical (WithTop ℕ)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:70
def Labeling : Tree L S R → Type v
| leaf _ => PUnit
| node _ l _ r => (S × Labeling l) × (S × Labeling r)
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:101
def weight : (t : Tree L S R) → S → Labeling t → R
| leaf l, s, _ => obs l s
| node P l Q r, s, z =>
(P s z.1.1 * weight l z.1.1 z.1.2) * (Q s z.2.1 * weight r z.2.1 z.2.2)
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:134
def leafObs (σ : L → S) (l : L) (s : S) : Cost :=
if s = σ l then 1 else 0
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:102
def Agrees (σ : L → S) : (t : Tree L S Cost) → S → Labeling t → Prop
| leaf l, s, _ => s = σ l
| node _ l _ r, _, z => Agrees σ l z.1.1 z.1.2 ∧ Agrees σ r z.2.1 z.2.2
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:85
def edgeCost : (t : Tree L S Cost) → S → Labeling t → WithTop ℕ
| leaf _, _, _ => 0
| node P l Q r, s, z =>
(untrop (P s z.1.1) + edgeCost l z.1.1 z.1.2) + (untrop (Q s z.2.1) + edgeCost r z.2.1 z.2.2)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:79
Uses 7 · Used by 1
DefinitionSankoff's algorithm#✓fully proved
The minimum cost of the subtree t given the state s at its
root, computed by Felsenstein's pruning recursion over the tropical semiring.
def sankoff (σ : L → S) (t : Tree L S Cost) (s : S) : WithTop ℕ :=
untrop (prune (leafObs σ) t s)
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
abbrev Cost : Type := MinTropical (WithTop ℕ)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:70
def prune : Tree L S R → S → R
| leaf l, s => obs l s
| node P l Q r, s => (∑ a, P s a * prune l a) * (∑ b, Q s b * prune r b)
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:152
def leafObs (σ : L → S) (l : L) (s : S) : Cost :=
if s = σ l then 1 else 0
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:102
Uses 4 · Used by 7
TheoremSankoff's algorithm computes the small-parsimony cost#✓fully proved
sankoff σ t s is the minimum
total edge cost over all labelings of the non-root vertices that agree with the observed states
at the leaves (with root state s).
theorem sankoff_eq_inf (σ : L → S) (t : Tree L S Cost) (s : S) :
sankoff σ t s = (Finset.univ.filter (Agrees σ t s)).inf (edgeCost t s)
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
abbrev Cost : Type := MinTropical (WithTop ℕ)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:70
def sankoff (σ : L → S) (t : Tree L S Cost) (s : S) : WithTop ℕ :=
untrop (prune (leafObs σ) t s)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:121
def Agrees (σ : L → S) : (t : Tree L S Cost) → S → Labeling t → Prop
| leaf l, s, _ => s = σ l
| node _ l _ r, _, z => Agrees σ l z.1.1 z.1.2 ∧ Agrees σ r z.2.1 z.2.2
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:85
def edgeCost : (t : Tree L S Cost) → S → Labeling t → WithTop ℕ
| leaf _, _, _ => 0
| node P l Q r, s, z =>
(untrop (P s z.1.1) + edgeCost l z.1.1 z.1.2) + (untrop (Q s z.2.1) + edgeCost r z.2.1 z.2.2)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:79
Sources
- Sankoff (1975).
Uses 12 · Used by 2
TheoremSankoff's cost is a lower bound#✓fully proved
Sankoff's cost is a lower bound for the cost of every labeling that agrees with the leaf states.
theorem sankoff_le_edgeCost (σ : L → S) (t : Tree L S Cost) (s : S) (x : Labeling t)
(hx : Agrees σ t s x) : sankoff σ t s ≤ edgeCost t s x
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
abbrev Cost : Type := MinTropical (WithTop ℕ)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:70
def Labeling : Tree L S R → Type v
| leaf _ => PUnit
| node _ l _ r => (S × Labeling l) × (S × Labeling r)
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:101
def Agrees (σ : L → S) : (t : Tree L S Cost) → S → Labeling t → Prop
| leaf l, s, _ => s = σ l
| node _ l _ r, _, z => Agrees σ l z.1.1 z.1.2 ∧ Agrees σ r z.2.1 z.2.2
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:85
def sankoff (σ : L → S) (t : Tree L S Cost) (s : S) : WithTop ℕ :=
untrop (prune (leafObs σ) t s)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:121
def edgeCost : (t : Tree L S Cost) → S → Labeling t → WithTop ℕ
| leaf _, _, _ => 0
| node P l Q r, s, z =>
(untrop (P s z.1.1) + edgeCost l z.1.1 z.1.2) + (untrop (Q s z.2.1) + edgeCost r z.2.1 z.2.2)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:79
Uses 7
TheoremSankoff's cost is attained#✓fully proved
Sankoff's cost is attained: if it is finite, some labeling that agrees with the leaf states
has exactly this cost. (It is ⊤ exactly when every agreeing labeling uses a forbidden change,
or when t is a single leaf whose observed state is not s.)
theorem exists_edgeCost_eq_sankoff (σ : L → S) (t : Tree L S Cost) (s : S)
(h : sankoff σ t s ≠ ⊤) : ∃ x, Agrees σ t s x ∧ edgeCost t s x = sankoff σ t s
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
abbrev Cost : Type := MinTropical (WithTop ℕ)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:70
def sankoff (σ : L → S) (t : Tree L S Cost) (s : S) : WithTop ℕ :=
untrop (prune (leafObs σ) t s)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:121
def Agrees (σ : L → S) : (t : Tree L S Cost) → S → Labeling t → Prop
| leaf l, s, _ => s = σ l
| node _ l _ r, _, z => Agrees σ l z.1.1 z.1.2 ∧ Agrees σ r z.2.1 z.2.2
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:85
def edgeCost : (t : Tree L S Cost) → S → Labeling t → WithTop ℕ
| leaf _, _, _ => 0
| node P l Q r, s, z =>
(untrop (P s z.1.1) + edgeCost l z.1.1 z.1.2) + (untrop (Q s z.2.1) + edgeCost r z.2.1 z.2.2)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:79
Uses 7
TheoremSankoff's recursion at a leaf#✓fully proved
Sankoff's recursion at a leaf: cost 0 at the observed state, ⊤ elsewhere.
theorem sankoff_leaf (σ : L → S) (l : L) (s : S) :
sankoff σ (leaf l) s = if s = σ l then 0 else ⊤
def sankoff (σ : L → S) (t : Tree L S Cost) (s : S) : WithTop ℕ :=
untrop (prune (leafObs σ) t s)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:121
Uses 5
TheoremSankoff's recursion at an internal vertex#✓fully proved
Sankoff's recursion at an internal vertex: the cost of state s is the sum, over the two
children, of the minimum over the child's state a of the edge cost from s to a plus the
child's cost at a.
theorem sankoff_node (σ : L → S) (P Q : S → S → Cost) (l r : Tree L S Cost) (s : S) :
sankoff σ (node P l Q r) s =
Finset.univ.inf (fun a => untrop (P s a) + sankoff σ l a) +
Finset.univ.inf (fun b => untrop (Q s b) + sankoff σ r b)
abbrev Cost : Type := MinTropical (WithTop ℕ)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:70
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
def sankoff (σ : L → S) (t : Tree L S Cost) (s : S) : WithTop ℕ :=
untrop (prune (leafObs σ) t s)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:121
Uses 5
Fitch's algorithm
DefinitionUnit substitution cost#✓fully proved
The unit cost: 0 for no change and 1 for a change of state.
def unitCost (a b : S) : Cost :=
trop (if a = b then 0 else 1)
abbrev Cost : Type := MinTropical (WithTop ℕ)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:70
Uses 1 · Used by 4
DefinitionTree with unit costs on every edge#✓fully proved
Every edge of the tree carries the unit cost.
def IsUnitCost : Tree L S Cost → Prop
| leaf _ => True
| node P l Q r => P = unitCost ∧ Q = unitCost ∧ IsUnitCost l ∧ IsUnitCost r
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
abbrev Cost : Type := MinTropical (WithTop ℕ)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:70
def unitCost (a b : S) : Cost :=
trop (if a = b then 0 else 1)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:177
Uses 3 · Used by 2
DefinitionFitch's algorithm#✓fully proved
The set of candidate states at the root of the subtree and the number of changes counted so far. The edge weights of the tree are ignored. Each child is evaluated once per node, so the recursion makes one call per vertex.
def fitch {R : Type w} (σ : L → S) : Tree L S R → Finset S × ℕ
| leaf l => ({σ l}, 0)
| node _ l _ r =>
let a := fitch σ l
let b := fitch σ r
if (a.1 ∩ b.1).Nonempty then (a.1 ∩ b.1, a.2 + b.2) else (a.1 ∪ b.1, a.2 + b.2 + 1)
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
Uses 1 · Used by 3
TheoremFitch's algorithm computes the small-parsimony score#✓fully proved
On a binary tree with unit costs, Fitch's count equals the minimum, over root states, of Sankoff's cost.
theorem fitch_score_eq (σ : L → S) (t : Tree L S Cost) (ht : IsUnitCost t) :
((fitch σ t).2 : WithTop ℕ) = Finset.univ.inf (sankoff σ t)
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
abbrev Cost : Type := MinTropical (WithTop ℕ)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:70
def IsUnitCost : Tree L S Cost → Prop
| leaf _ => True
| node P l Q r => P = unitCost ∧ Q = unitCost ∧ IsUnitCost l ∧ IsUnitCost r
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:181
def fitch {R : Type w} (σ : L → S) : Tree L S R → Finset S × ℕ
| leaf l => ({σ l}, 0)
| node _ l _ r =>
let a := fitch σ l
let b := fitch σ r
if (a.1 ∩ b.1).Nonempty then (a.1 ∩ b.1, a.2 + b.2) else (a.1 ∪ b.1, a.2 + b.2 + 1)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:188
def sankoff (σ : L → S) (t : Tree L S Cost) (s : S) : WithTop ℕ :=
untrop (prune (leafObs σ) t s)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:121
Sources
- Fitch (1971); Hartigan (1973).
TheoremFitch's root set is the set of optimal root states#✓fully proved
On a binary tree with unit costs, a root state is in Fitch's set if and only if Sankoff's cost at that state is the minimum.
theorem fitch_set_eq (σ : L → S) (t : Tree L S Cost) (ht : IsUnitCost t) :
(fitch σ t).1 = Finset.univ.filter (fun s => sankoff σ t s = (fitch σ t).2)
inductive Tree (L : Type u) (S : Type v) (R : Type w) where
/-- A leaf with label `l`. -/
| leaf : L → Tree L S R
/-- An internal node with transition weights `P` to the left child and `Q` to the right one. -/
| node : (S → S → R) → Tree L S R → (S → S → R) → Tree L S R → Tree L S R
CSLibExt/Bioinformatics/Phylogenetics/FelsensteinPruning.lean:75
abbrev Cost : Type := MinTropical (WithTop ℕ)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:70
def IsUnitCost : Tree L S Cost → Prop
| leaf _ => True
| node P l Q r => P = unitCost ∧ Q = unitCost ∧ IsUnitCost l ∧ IsUnitCost r
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:181
def fitch {R : Type w} (σ : L → S) : Tree L S R → Finset S × ℕ
| leaf l => ({σ l}, 0)
| node _ l _ r =>
let a := fitch σ l
let b := fitch σ r
if (a.1 ∩ b.1).Nonempty then (a.1 ∩ b.1, a.2 + b.2) else (a.1 ∪ b.1, a.2 + b.2 + 1)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:188
def sankoff (σ : L → S) (t : Tree L S Cost) (s : S) : WithTop ℕ :=
untrop (prune (leafObs σ) t s)
CSLibExt/Bioinformatics/Phylogenetics/Parsimony.lean:121
Sources
- Hartigan (1973).
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.