Documentation

PartialCombinatoryAlgebras.Programming

Programming with PCAs #

A (non-trivial) PCA is Turing-complete in the sense that it implements every partial computable function. We develop here basic programming constructs that witness this fact:

For any of the combinators so defined, say C, we also prove two lemmas: df_C characterizes totality of expressions involving C, and eq_C gives the characteristic equation for C. These lemmas are automatically used by simp.

def PCA.I {A : Type u} [PCA A] :

The identity combinator

Equations
Instances For
    def PCA.Expr.I {A : Type u} {Γ : Type u_1} :

    The expression denoting the identity combinator

    Equations
    • PCA.Expr.I = PCA.Expr.S ⬝ PCA.Expr.K ⬝ PCA.Expr.K
    Instances For
      @[simp]
      theorem PCA.df_I {A : Type u} [PCA A] :
      PCA.I ⇓
      @[simp]
      theorem PCA.eq_I {A : Type u} [PCA A] {u : Part A} :
      u ⇓ → PCA.I ⬝ u = u
      def PCA.K' {A : Type u} [PCA A] :
      Equations
      • PCA.K' = PCA.K ⬝ PCA.I
      Instances For
        def PCA.Expr.K' {A : Type u} {Γ : Type u_1} :
        Equations
        • PCA.Expr.K' = PCA.Expr.K ⬝ PCA.Expr.I
        Instances For
          @[simp]
          theorem PCA.df_K' {A : Type u} [PCA A] :
          PCA.K' ⇓
          @[simp]
          theorem PCA.eq_K' {A : Type u} [PCA A] (u v : Part A) :
          u ⇓ → v ⇓ → PCA.K' ⬝ u ⬝ v = v

          Pairing #

          def PCA.pair {A : Type u} [PCA A] :
          Equations
          Instances For
            @[simp]
            theorem PCA.df_pair {A : Type u} [PCA A] :
            PCA.pair ⇓
            @[simp]
            theorem PCA.df_pair_app {A : Type u} [PCA A] (u : Part A) :
            u ⇓ → (PCA.pair ⬝ u) ⇓
            @[simp]
            theorem PCA.df_pair_app_app {A : Type u} [PCA A] (u v : Part A) :
            u ⇓ → v ⇓ → (PCA.pair ⬝ u ⬝ v) ⇓
            @[simp]
            theorem PCA.eq_pair {A : Type u} [PCA A] (u v w : Part A) :
            u ⇓ → v ⇓ → w ⇓ → PCA.pair ⬝ u ⬝ v ⬝ w = w ⬝ u ⬝ v
            def PCA.fst {A : Type u} [PCA A] :
            Equations
            Instances For
              def PCA.fst.elm {A : Type u} [PCA A] {Γ : Type u_1} :
              Equations
              Instances For
                @[simp]
                theorem PCA.eq_fst {A : Type u} [PCA A] (u : Part A) :
                u ⇓ → PCA.fst ⬝ u = u ⬝ PCA.K
                def PCA.snd {A : Type u} [PCA A] :
                Equations
                Instances For
                  def PCA.snd.elm {A : Type u} [PCA A] {Γ : Type u_1} :
                  Equations
                  Instances For
                    @[simp]
                    theorem PCA.eq_snd {A : Type u} [PCA A] (u : Part A) :
                    u ⇓ → PCA.snd ⬝ u = u ⬝ PCA.K'
                    @[simp]
                    def PCA.eq_fst_pair {A : Type u} [PCA A] (u v : Part A) :
                    u ⇓ → v ⇓ → PCA.fst ⬝ (PCA.pair ⬝ u ⬝ v) = u
                    Equations
                    • ⋯ = ⋯
                    Instances For
                      @[simp]
                      def PCA.eq_snd_pair {A : Type u} [PCA A] (u v : Part A) :
                      u ⇓ → v ⇓ → PCA.snd ⬝ (PCA.pair ⬝ u ⬝ v) = v
                      Equations
                      • ⋯ = ⋯
                      Instances For
                        def PCA.ite {A : Type u} [PCA A] :

                        Conditional statements

                        Equations
                        • PCA.ite = PCA.I
                        Instances For
                          def PCA.fal {A : Type u} [PCA A] :

                          The bollean false

                          Equations
                          • PCA.fal = PCA.K'
                          Instances For
                            @[simp]
                            theorem PCA.df_fal {A : Type u} [PCA A] :
                            PCA.fal ⇓
                            @[simp]
                            theorem PCA.eq_fal {A : Type u} [PCA A] (u v : Part A) :
                            u ⇓ → v ⇓ → PCA.fal ⬝ u ⬝ v = v
                            def PCA.tru {A : Type u} [PCA A] :

                            The boolean true

                            Equations
                            • PCA.tru = PCA.K
                            Instances For
                              @[simp]
                              theorem PCA.df_tru {A : Type u} [PCA A] :
                              PCA.tru ⇓
                              @[simp]
                              theorem PCA.eq_ite_fal {A : Type u} [PCA A] (u v : Part A) :
                              u ⇓ → v ⇓ → PCA.ite ⬝ PCA.fal ⬝ u ⬝ v = v
                              @[simp]
                              theorem PCA.eq_ite_tru {A : Type u} [PCA A] (u v : Part A) :
                              u ⇓ → v ⇓ → PCA.ite ⬝ PCA.tru ⬝ u ⬝ v = u

                              The fixed point combinator #

                              def PCA.X {A : Type u} [PCA A] :
                              Equations
                              Instances For
                                @[simp]
                                theorem PCA.df_X {A : Type u} [PCA A] :
                                PCA.X ⇓
                                @[simp]
                                theorem PCA.df_X_app {A : Type u} [PCA A] (u : Part A) :
                                u ⇓ → (PCA.X ⬝ u) ⇓
                                @[simp]
                                theorem PCA.df_X_app_app {A : Type u} [PCA A] (u v : Part A) :
                                u ⇓ → v ⇓ → (PCA.X ⬝ u ⬝ v) ⇓
                                theorem PCA.eq_X {A : Type u} [PCA A] (u v w : Part A) :
                                u ⇓ → v ⇓ → w ⇓ → PCA.X ⬝ u ⬝ v ⬝ w = v ⬝ (u ⬝ u ⬝ v) ⬝ w
                                def PCA.Z {A : Type u} [PCA A] :
                                Equations
                                • PCA.Z = PCA.X ⬝ PCA.X
                                Instances For
                                  @[simp]
                                  theorem PCA.df_Z {A : Type u} [PCA A] :
                                  PCA.Z ⇓
                                  @[reducible]
                                  def PCA.Z.elm {A : Type u} [PCA A] {Γ : Type u_1} :
                                  Equations
                                  Instances For
                                    @[simp]
                                    theorem PCA.df_Z_app {A : Type u} [PCA A] (u : Part A) :
                                    u ⇓ → (PCA.Z ⬝ u) ⇓
                                    theorem PCA.eq_Z {A : Type u} [PCA A] (u v : Part A) :
                                    u ⇓ → v ⇓ → PCA.Z ⬝ u ⬝ v = u ⬝ (PCA.Z ⬝ u) ⬝ v
                                    def PCA.W {A : Type u} [PCA A] :
                                    Equations
                                    Instances For
                                      @[simp]
                                      def PCA.df_W {A : Type u} [PCA A] :
                                      PCA.W ⇓
                                      Equations
                                      • ⋯ = ⋯
                                      Instances For
                                        @[simp]
                                        def PCA.df_W_app {A : Type u} [PCA A] (u : Part A) :
                                        u ⇓ → (PCA.W ⬝ u) ⇓
                                        Equations
                                        • ⋯ = ⋯
                                        Instances For
                                          def PCA.eq_W {A : Type u} [PCA A] (u v : Part A) :
                                          u ⇓ → v ⇓ → PCA.W ⬝ u ⬝ v = v ⬝ (u ⬝ u ⬝ v)
                                          Equations
                                          • ⋯ = ⋯
                                          Instances For
                                            def PCA.Y {A : Type u} [PCA A] :
                                            Equations
                                            • PCA.Y = PCA.W ⬝ PCA.W
                                            Instances For
                                              @[simp]
                                              theorem PCA.df_Y {A : Type u} [PCA A] :
                                              PCA.Y ⇓
                                              theorem PCA.eq_Y {A : Type u} [PCA A] (u : Part A) :
                                              u ⇓ → PCA.Y ⬝ u = u ⬝ (PCA.Y ⬝ u)

                                              Curry numerals #

                                              def PCA.numeral {A : Type u} [PCA A] :
                                              ℕ → Part A

                                              Curry numeral

                                              Equations
                                              Instances For
                                                @[simp]
                                                theorem PCA.df_numeral {A : Type u} [PCA A] (n : ℕ) :
                                                def PCA.succ {A : Type u} [PCA A] :

                                                The successor of a Curry numeral

                                                Equations
                                                • PCA.succ = PCA.pair ⬝ PCA.fal
                                                Instances For
                                                  @[simp]
                                                  def PCA.df_succ {A : Type u} [PCA A] :
                                                  PCA.succ ⇓
                                                  Equations
                                                  • ⋯ = ⋯
                                                  Instances For
                                                    @[simp]
                                                    def PCA.df_succ_app {A : Type u} [PCA A] (u : Part A) :
                                                    u ⇓ → (PCA.succ ⬝ u) ⇓
                                                    Equations
                                                    • ⋯ = ⋯
                                                    Instances For
                                                      def PCA.iszero {A : Type u} [PCA A] :

                                                      Is a numeral equal to zero?

                                                      Equations
                                                      • PCA.iszero = PCA.fst
                                                      Instances For
                                                        @[simp]
                                                        theorem PCA.eq_iszero_0 {A : Type u} [PCA A] :
                                                        PCA.iszero ⬝ PCA.numeral 0 = PCA.tru
                                                        @[simp]
                                                        theorem PCA.eq_iszero_succ {A : Type u} [PCA A] (n : ℕ) :
                                                        PCA.iszero ⬝ PCA.numeral n.succ = PCA.fal
                                                        def PCA.pred {A : Type u} [PCA A] :

                                                        Predecessor of a Curry numeral

                                                        Equations
                                                        Instances For
                                                          @[simp]
                                                          def PCA.df_pred {A : Type u} [PCA A] :
                                                          PCA.pred ⇓
                                                          Equations
                                                          • ⋯ = ⋯
                                                          Instances For
                                                            @[reducible]
                                                            def PCA.pred.elm {A : Type u} [PCA A] {Γ : Type u_1} :
                                                            Equations
                                                            Instances For
                                                              @[simp]
                                                              theorem PCA.eq_pred {A : Type u} [PCA A] (u : Part A) :
                                                              u ⇓ → PCA.pred ⬝ u = PCA.fst ⬝ u ⬝ PCA.I ⬝ (PCA.snd ⬝ u)
                                                              @[simp]
                                                              theorem PCA.eq_pred_succ {A : Type u} [PCA A] (u : Part A) :
                                                              u ⇓ → PCA.pred ⬝ (PCA.succ ⬝ u) = u
                                                              def PCA.primrec.R {A : Type u} [PCA A] :
                                                              Equations
                                                              • One or more equations did not get rendered due to their size.
                                                              Instances For
                                                                def PCA.primrec.eq_R {A : Type u} [PCA A] (r u f m : Part A) (hr : r ⇓ ) (hu : u ⇓ ) (hf : f ⇓ ) (hm : m ⇓ ) :
                                                                PCA.primrec.R ⬝ r ⬝ u ⬝ f ⬝ m = PCA.fst ⬝ m ⬝ (PCA.K ⬝ u) ⬝ PCA.compile (PCA.abstr `y (PCA.Expr.elm (f.get hf) ⬝ (PCA.pred.elm ⬝ PCA.Expr.elm (m.get hm)) ⬝ (PCA.Expr.elm (r.get hr) ⬝ PCA.Expr.elm (u.get hu) ⬝ PCA.Expr.elm (f.get hf) ⬝ (PCA.pred.elm ⬝ PCA.Expr.elm (m.get hm)) ⬝ (PCA.Expr.S ⬝ PCA.Expr.K ⬝ PCA.Expr.K))))
                                                                Equations
                                                                • ⋯ = ⋯
                                                                Instances For
                                                                  @[simp]
                                                                  def PCA.primrec.df_R {A : Type u} [PCA A] :
                                                                  PCA.primrec.R ⇓
                                                                  Equations
                                                                  • ⋯ = ⋯
                                                                  Instances For
                                                                    def PCA.primrec.R.elm {A : Type u} [PCA A] {Γ : Type u_1} :
                                                                    Equations
                                                                    Instances For
                                                                      def PCA.primrec {A : Type u} [PCA A] :

                                                                      Primitive recursion

                                                                      Equations
                                                                      Instances For
                                                                        @[simp]
                                                                        theorem PCA.eq_primrec {A : Type u} [PCA A] (u f m : Part A) :
                                                                        u ⇓ → f ⇓ → m ⇓ → PCA.primrec ⬝ u ⬝ f ⬝ m = PCA.Z ⬝ PCA.primrec.R ⬝ u ⬝ f ⬝ m ⬝ PCA.I
                                                                        theorem PCA.eq_primrec_zero {A : Type u} [PCA A] (u f : Part A) :
                                                                        u ⇓ → f ⇓ → PCA.primrec ⬝ u ⬝ f ⬝ PCA.numeral 0 = u
                                                                        theorem PCA.eq_primrec_succ {A : Type u} [PCA A] (u f n : Part A) :
                                                                        u ⇓ → f ⇓ → n ⇓ → PCA.primrec ⬝ u ⬝ f ⬝ (PCA.succ ⬝ n) = f ⬝ n ⬝ (PCA.primrec ⬝ u ⬝ f ⬝ n)