Documentation

Jxm.HydrophobicPolarModelBasic

Hydrophobic-polar protein folding model: basics #

A treatment of the hydrophobic-polar protein folding model in a generality that covers rectangular, triangular and hexagonal lattices: P_rect, P_tri, P_hex.

We formalize the non-monotonicity of the objective function, refuting an unpublished conjecture of Stecher.

We prove objective function bounds: P_tri ≤ P_rect ≤ P_hex (using a theory of embeddings) and for any model, P ≤ b * l and P ≤ l * (l-1)/2 [see pts_earned_bound_loc']

(The latter is worth keeping when l ≤ 2b+1.)

where b is the number of moves and l is the word length. We also prove P ≤ b * l / 2 using "handshake lemma" type reasoning that was pointed out in Agarwala, Batzoglou et al. (RECOMB 97, Lemma 2.1) and a symmetry assumption on the folding model that holds for rect and hex but not for tri. The latter result required improving our definitions.

We prove the correctness of our backtracking algorithm for protein folding.

To prove some results about rotations (we can always assume our fold starts by going to the right) we use the type Fin n → α instead of Vector α n

theorem sum_pred₀ (n : ) :
kFinset.range n, (k - 1) = (n - 1) * (n - 2) / 2

∑₀^(n-1) (k-1) = (n-1)(n-2)/2. This uses the Lean convention 0-1=0.

theorem sum_pred (n : ) :
kFinset.range n.succ, (k - 1) = n * (n - 1) / 2

∑ⁿ₀ (k-1) = n (n-1) / 2. This uses the Lean convention 0-1=0.

def quad₃ :
Fin 6 × × × ×

The original protein folding model introduced by Ken Dill in 1985.

Equations
Instances For
    def pp :

    The convention is that p is plus, m is minus, and s is stationary.

    Equations
    Instances For
      def go_D :

      When using keys WASD for navigation, this is D.

      Equations
      Instances For
        def sp :

        The convention is that p is plus, m is minus, and s is stationary.

        Equations
        Instances For
          def mm :

          The convention is that p is plus, m is minus, and s is stationary.

          Equations
          Instances For
            def go_A :

            When using keys WASD for navigation, this is A.

            Equations
            Instances For
              def sm :

              The convention is that p is plus, m is minus, and s is stationary.

              Equations
              Instances For
                def pm :

                The convention is that p is plus, m is minus, and s is stationary.

                Equations
                Instances For
                  def mp :

                  The convention is that p is plus, m is minus, and s is stationary.

                  Equations
                  Instances For
                    def go_X :

                    When using keys WAZXDE for hexagonal navigation, this is X.

                    Equations
                    Instances For
                      def go_W :

                      When using keys WAZXDE for hexagonal navigation, this is W.

                      Equations
                      Instances For
                        def go_Z :

                        When using keys WAZXDE for hexagonal navigation, this is Z.

                        Equations
                        Instances For
                          def go_E :

                          When using keys WAZXDE for hexagonal navigation, this is E.

                          Equations
                          Instances For
                            def rectMap (a : Fin 4) :

                            The four directions, horizontal and vertical.

                            Equations
                            Instances For
                              def rect₃Map (a : Fin 3) :

                              Basically a fintype for the directions: left, right, up.

                              Equations
                              Instances For
                                def rect₃ (a : Fin 3) (x : × ) :

                                Three directions: left, right, up. Allows for polynomial-time optimal folding.

                                Equations
                                Instances For
                                  def rect (a : Fin 4) (x : × ) :

                                  The four directions as a map.

                                  Equations
                                  Instances For
                                    @[reducible, inline]
                                    abbrev κ (a : Fin 4) (x : × ) :

                                    .

                                    Equations
                                    Instances For
                                      def hexMap (a : Fin 6) :

                                      move_hex represents the degree-6 hexagonal/triangular lattice, although that in itself requires checking. This representation was designed to make the y-axis vertical to fit with a computer game. def move_hex : Fin 6 → ℤ×ℤ → ℤ×ℤ | 0 => go_D | 1 => go_A | 2 => go_X | 3 => go_W | 4 => go_E | 5 => go_Z #eval move_hex 0 (0,0) #eval move_hex 5 (1,0) If computer games are not to be used we can use this simpler implementation.

                                      Equations
                                      Instances For
                                        def hex₄Map (a : Fin 4) :

                                        A limited move set for hexMap.

                                        Equations
                                        Instances For
                                          def hex (a : Fin 6) (x : × ) :

                                          hexMap as a function on the plane.

                                          Equations
                                          Instances For
                                            def hex₄ (a : Fin 4) (x : × ) :

                                            hex₄Map as a function on the plane.

                                            Equations
                                            Instances For
                                              def go_WS :

                                              In the brick wall lattice, this function goes in whichever vertical direction is available.

                                              Equations
                                              Instances For
                                                def tri :
                                                Fin 3 × ×

                                                The available moves in brick wall lattice folding.

                                                Equations
                                                Instances For
                                                  def Fin_trans {l : } {k : Fin l} (i : Fin k) :
                                                  Fin l

                                                  Casting from Fin k to Fin l, where k < l.

                                                  Equations
                                                  Instances For
                                                    def Fin_trans_pred {l : } {k : Fin l} (i : Fin (↑k).pred) :
                                                    Fin l

                                                    Casting from Fin k.pred to Fin l, where k < l.

                                                    Equations
                                                    Instances For
                                                      def nearby {α : Type} {β : Type} [DecidableEq α] [Fintype β] (go : βαα) (p : α) (q : α) :

                                                      Two points are nearby if they are one move apart.

                                                      Equations
                                                      Instances For
                                                        def pt_loc {α : Type} {β : Type} [DecidableEq α] [Fintype β] (go : βαα) {l : } (fold : Mathlib.Vector α l) (i : Fin l) (j : Fin l) (phobic : Mathlib.Vector Bool l) :

                                                        The (H-P reduced) amino acid sequence phobic has a match at locations i, j, according to the fold fold.

                                                        Equations
                                                        Instances For
                                                          def pts_at' {α : Type} {β : Type} [DecidableEq α] [Fintype β] (go : βαα) {l : } (k : Fin l) (ph : Mathlib.Vector Bool l) (fold : Mathlib.Vector α l) :

                                                          The number of matches achieved with the fold fold for the amino acid sequence ph.

                                                          Equations
                                                          Instances For
                                                            def map_predicate {β : Type} {α : Type} [Fintype β] [Fintype α] (P : βBool) (φ : αβ) [DecidablePred fun (i : β) => P i = true] :
                                                            { x : α // x Finset.filter (fun (i : α) => P (φ i) = true) Finset.univ }{ x : β // x Finset.filter (fun (i : β) => P i = true) Finset.univ }

                                                            φ maps φ⁻¹' P to P.

                                                            Equations
                                                            Instances For
                                                              def embed_pred {l : } (k : Fin l) (P : Fin lFin lBool) [DecidablePred fun (i : Fin l) => P i k = true] :
                                                              { x : Fin (↑k).pred // x Finset.filter (fun (i : Fin (↑k).pred) => P (Fin_trans_pred i) k = true) Finset.univ }{ x : Fin l // x Finset.filter (fun (i : Fin l) => P i k = true) Finset.univ }

                                                              Cast a member of P to a member of P.

                                                              Equations
                                                              Instances For
                                                                theorem embed_pred_inj {l : } (k : Fin l) (P : Fin lFin lBool) [DecidablePred fun (i : Fin l) => P i k = true] :

                                                                embed_pred casting is injective.

                                                                theorem embed_pred_surj {l : } (k : Fin l) (P : Fin lFin lBool) [DecidablePred fun (i : Fin l) => P i k = true] (h : ∀ {x y : Fin l}, P x y = truex < (↑y).pred) :

                                                                embed_pred casting is surjective.

                                                                theorem embed_pred_bij {l : } (k : Fin l) {P : Fin lFin lBool} [DecidablePred fun (i : Fin l) => P i k = true] (h : ∀ {x y : Fin l}, P x y = truex < (↑y).pred) :

                                                                embed_pred casting is bijective.

                                                                theorem change_type_card_general'' {l : } (k : Fin l) (P : Fin lFin lBool) [DecidablePred fun (i : Fin l) => P i k = true] (h : ∀ {x y : Fin l}, P x y = true(↑x).succ < y) :
                                                                Fintype.card { x : Fin l // x Finset.filter (fun (i : Fin l) => P i k = true) Finset.univ } = Fintype.card { x : Fin (↑k).pred // x Finset.filter (fun (i : Fin (↑k).pred) => P (Fin_trans_pred i) k = true) Finset.univ }

                                                                The number of P's is the same if we count beyond the greatest element of P.

                                                                theorem change_type_card_improved {α : Type} {β : Type} [Fintype β] (go : βαα) [DecidableEq α] {l : } (k : Fin l) (ph : Mathlib.Vector Bool l) (fold : Mathlib.Vector α l) :
                                                                Fintype.card { x : Fin l // x Finset.filter (fun (i : Fin l) => pt_loc go fold i k ph = true) Finset.univ } = Fintype.card { x : Fin (↑k).pred // x Finset.filter (fun (i : Fin (↑k).pred) => pt_loc go fold (Fin_trans_pred i) k ph = true) Finset.univ }

                                                                The number of points is the same if we count beyond the last point.

                                                                def path_aux {α : Type} {β : Type} {l : } (go : βαα) (hd : β) (tl : Mathlib.Vector α l.succ) :
                                                                Mathlib.Vector α l.succ.succ

                                                                Helper function for path_at.

                                                                Equations
                                                                Instances For
                                                                  def path_at {α : Type} {β : Type} (base : α) (go : βαα) (moves : List β) :
                                                                  Mathlib.Vector α moves.length.succ

                                                                  Inductively defined path, starting at base (the origin, say), and proceeding through all moves according to the rules of go.

                                                                  Equations
                                                                  Instances For
                                                                    def path {α : Type} [Zero α] {β : Type} (go : βαα) (moves : List β) :
                                                                    Mathlib.Vector α moves.length.succ

                                                                    Using OfNat here since ℤ×ℤ and ℤ×ℤ×ℤ have a natural notion of base point or zero.

                                                                    Equations
                                                                    Instances For
                                                                      def embeds_in {α : Type} {b₀ : } {b₁ : } (go₀ : Fin b₀αα) (go₁ : Fin b₁αα) :

                                                                      The move set go₁ can simulate the move set go₀.

                                                                      Equations
                                                                      • embeds_in go₀ go₁ = ∀ (i : Fin b₀) (x : α), ∃ (j : Fin b₁), go₀ i x = go₁ j x
                                                                      Instances For
                                                                        def is_embedding {α : Type} {b₀ : } {b₁ : } (go₀ : Fin b₀αα) (go₁ : Fin b₁αα) (f : Fin b₀αFin b₁) :

                                                                        The move set go₁ simulates the move set go₀ via the map f.

                                                                        Equations
                                                                        • is_embedding go₀ go₁ f = ∀ (i : Fin b₀) (x : α), go₀ i x = go₁ (f i x) x
                                                                        Instances For
                                                                          def embeds_in_strongly {α : Type} {b₀ : } {b₁ : } (go₀ : Fin b₀αα) (go₁ : Fin b₁αα) :

                                                                          Like embeds_in, but with an explicit Skolem function.

                                                                          Equations
                                                                          Instances For
                                                                            theorem embeds_in_strongly_transitive {α : Type} {b₀ : } {b₁ : } {b₂ : } (go₀ : Fin b₀αα) (go₁ : Fin b₁αα) (go₂ : Fin b₂αα) :
                                                                            go₀ go₁go₁ go₂go₀ go₂

                                                                            Embedding of move sets is transitive.

                                                                            theorem embeds_in_strongly_reflexive {α : Type} {b : } (go : Fin bαα) :
                                                                            go go

                                                                            Embedding of move sets is reflexive.

                                                                            theorem embeds_of_strongly_embeds {α : Type} {b₀ : } {b₁ : } {go₀ : Fin b₀αα} {go₁ : Fin b₁αα} (h_embed : go₀ go₁) :
                                                                            embeds_in go₀ go₁

                                                                            Embedding using a Skolem function implies ordinary embedding.

                                                                            def tri_rect_embedding :
                                                                            Fin 3 × Fin 4

                                                                            For tri we can only assert a pointwise version of embed_models: It follows from tri_rect_embedding that any sequence of moves under tri generates a sequence in ℤ×ℤ that can also be generated using quad.

                                                                            Equations
                                                                            Instances For
                                                                              def rect_hex_embedding :
                                                                              Fin 4 × Fin 6

                                                                              Hexagonal move set extend rectangular.

                                                                              Equations
                                                                              Instances For

                                                                                Rectangular move set extends limited rectangular.

                                                                                Equations
                                                                                Instances For

                                                                                  rect_hex_embedding works as advertised.

                                                                                  tri_rect_embedding works as advertised.

                                                                                  def left_injective {α : Type} {β : Type} {γ : Type} (go : βαγ) :

                                                                                  A function of two variables is left injective if it is injective in its first argument.

                                                                                  Equations
                                                                                  Instances For
                                                                                    def right_injective {α : Type} {β : Type} {γ : Type} (go : βαγ) :

                                                                                    A function of two variables is right injective if it is injective in its second argument.

                                                                                    Equations
                                                                                    Instances For

                                                                                      tri is right injective.

                                                                                      tri is left injective.

                                                                                      hex is left injective.

                                                                                      hex is right injective.

                                                                                      def choice_ex {β : Type} [Fintype β] {l : } (P : βFin lProp) [DecidablePred fun (a : β) => ∃ (i : Fin l), P a i] [DecidablePred fun (i : Fin l) => ∃ (a : β), P a i] [(a : β) → DecidablePred fun (n : ) => ∃ (hq : n < l), P a n, hq] :
                                                                                      { x : β // x Finset.filter (fun (a : β) => ∃ (i : Fin l), P a i) Finset.univ }{ x : Fin l // x Finset.filter (fun (i : Fin l) => ∃ (a : β), P a i) Finset.univ }

                                                                                      If Anna has a brother, return a boy who has a sister.

                                                                                      Equations
                                                                                      Instances For
                                                                                        theorem choice_ex_injective {β : Type} [Fintype β] {l : } {P : βFin l.succProp} [DecidablePred fun (a : β) => ∃ (i : Fin l.succ), P a i] [DecidablePred fun (i : Fin l.succ) => ∃ (a : β), P a i] [(a : β) → DecidablePred fun (n : ) => ∃ (hq : n < l.succ), P a n, hq] (h_unique_dir : ∀ {i : Fin l.succ} {a₀ a₁ : β}, P a₀ iP a₁ ia₀ = a₁) :

                                                                                        If each girl has at most one brother, the map from girl-who-has-a-brother to boy-who-has-a-sister is injective.

                                                                                        theorem choice_ex_aux {β : Type} [Fintype β] {l : } {P : βFin lProp} [DecidablePred fun (i : Fin l) => ∃ (a : β), P a i] [DecidablePred fun (a : β) => ∃ (i : Fin l), P a i] [(a : β) → DecidablePred fun (n : ) => ∃ (hq : n < l), P a n, hq] {i : { x : Fin l // x Finset.filter (fun (i : Fin l) => ∃ (a : β), P a i) Finset.univ }} {a : β} (ha : P a i) :
                                                                                        P a (choice_ex P a, )

                                                                                        Anna is a sister of a chosen brother who has Anna as his sister.

                                                                                        theorem choice_ex_surjective {β : Type} [Fintype β] {l : } {P : βFin l.succProp} [DecidablePred fun (a : β) => ∃ (i : Fin l.succ), P a i] [DecidablePred fun (i : Fin l.succ) => ∃ (a : β), P a i] [(a : β) → DecidablePred fun (n : ) => ∃ (hq : n < l.succ), P a n, hq] (h_unique_loc : ∀ {a : β} {i₀ i₁ : Fin l.succ}, P a i₀P a i₁i₀ = i₁) :

                                                                                        If each girl has at most one brother, the map from girl-who-has-a-brother to boy-who-has-a-sister is surjective.

                                                                                        theorem choice_ex_bijective {β : Type} [Fintype β] {l : } {P : βFin l.succProp} [DecidablePred fun (a : β) => ∃ (i : Fin l.succ), P a i] [DecidablePred fun (i : Fin l.succ) => ∃ (a : β), P a i] [(a : β) → DecidablePred fun (n : ) => ∃ (hq : n < l.succ), P a n, hq] (h_unique_loc : ∀ {a : β} {i₀ i₁ : Fin l.succ}, P a i₀P a i₁i₀ = i₁) (h_unique_dir : ∀ {i : Fin l.succ} {a₀ a₁ : β}, P a₀ iP a₁ ia₀ = a₁) :

                                                                                        If each boy has at most one sister, and each girl has at most one brother, then the map that sends a boy who has a sister to a girl who has a brother is bijective.

                                                                                        theorem choice_ex_finset_card {β : Type} [Fintype β] {l : } {P : βFin l.succProp} [DecidablePred fun (a : β) => ∃ (i : Fin l.succ), P a i] [DecidablePred fun (i : Fin l.succ) => ∃ (a : β), P a i] [(a : β) → DecidablePred fun (n : ) => ∃ (hq : n < l.succ), P a n, hq] (h_unique_loc_dir : (∀ {a : β} {i₀ i₁ : Fin l.succ}, P a i₀P a i₁i₀ = i₁) ∀ {i : Fin l.succ} {a₀ a₁ : β}, P a₀ iP a₁ ia₀ = a₁) :
                                                                                        (Finset.filter (fun (a : β) => ∃ (i : Fin l.succ), P a i) Finset.univ).card = (Finset.filter (fun (i : Fin l.succ) => ∃ (a : β), P a i) Finset.univ).card

                                                                                        If each boy has at most one sister, and each girl has at most one brother, then there are an equal number of boys who have a sister and girls who have a brother is bijective.