Documentation

Cvc.Typed.Theory.Table

Tables, typed #

A table is a bag of tuples, indexed by Tab α β: a relation with duplicates kept. Its rows are the Tup α β tuples of Cvc.Typed.Theory.Relation, built with mkTup.

The bag operators are restated at a table's index (tableUnionMax, tableCount, …); tableToBag crosses to Bag, for bagMap and bagFold. cvc5 marks every table-specific kind experimental.

Crossing to and from bags #

Both directions are the identity on terms: a table is a bag of tuples, and only the index differs.

def Cvc.Typed.Term.tableToBag [Ω] {α : List Type} {β : Type} [Ord (Tup α β)] (table : Term (Tab α β)) :
Term (Bag (Tup α β))

Reads a table as the bag of tuples it is.

Equations
Instances For
    def Cvc.Typed.Term.tableOfBag [Ω] {α : List Type} {β : Type} [Ord (Tup α β)] (bag : Term (Bag (Tup α β))) :
    Term (Tab α β)

    Reads a bag of tuples as the table it is.

    Equations
    Instances For

      Table operators #

      def Cvc.Typed.Term.tableProduct [Ω] {α : List Type} {β : Type} {α' : List Type} {β' : Type} (lft : Term (Tab α β)) (rgt : Term (Tab α' β')) :
      Env (Term (Tab (α ++ β :: α') β'))

      Cartesian product: every pairing of rows, with the columns appended.

      Equations
      Instances For
        def Cvc.Typed.Term.tableJoin [Ω] {α : List Type} {β : Type} {α' : List Type} {β' : Type} (columns : Array (Nat × Nat)) (lft : Term (Tab α β)) (rgt : Term (Tab α' β')) :
        Env (Term (Tab (α ++ β :: α') β'))

        Equi-join: the product, keeping the pairings whose given column pairs agree.

        The result's sort is the product's, since the pairs only filter.

        Equations
        Instances For
          def Cvc.Typed.Term.tableGroup [Ω] {α : List Type} {β : Type} [Ord (Tab α β)] (columns : Array Nat) (table : Term (Tab α β)) :
          Env (Term (Bag (Tab α β)))

          Partitions the table, putting rows that agree on the given columns in the same part.

          Answers a bag of tables. The columns choose what is compared and so do not reach the result's sort.

          Equations
          Instances For
            def Cvc.Typed.Term.tableAggregate [Ω] {γ : Type} {α : List Type} {β : Type} [Ord γ] (columns : Array Nat) (f : Term (Tup α β → γ → γ)) (init : Term γ) (table : Term (Tab α β)) :
            Env (Term (Bag γ))

            Folds each group of rows that agree on the given columns.

            The groups are tableGroup's, but the answer is a bag of accumulators rather than a bag of tables: f runs over each group's rows starting from init, and the result collects one value of gamma per group.

            f is a function-sorted term, which Term.lambda builds. Its two arguments are a row of the table and the accumulator, in that order, and its result is the new accumulator — so gamma is fixed by init and by f's codomain together. This is SQL's GROUP BY with an aggregate function.

            The columns only say what is grouped, so they do not reach the result's sort. With none of them every row is in one group, which is an ordinary fold over the whole table.

            Equations
            Instances For
              def Cvc.Typed.Term.tableProject [Ω] {α : List Type} {β : Type} {α' : List Type} {β' : Type} (cols : Cols α β α' β') (table : Term (Tab α β)) :
              Env (Term (Tab α' β'))

              Projects every row onto the given columns, in the order given.

              Columns are written cols% [2, 0]. Untyped.Term.tableProject takes them as an Array Nat, for columns known only at run time.

              Equations
              Instances For

                The bag operators, at a table's index #

                def Cvc.Typed.Term.tableMember [Ω] {α : List Type} {β : Type} (row : Term (Tup α β)) (table : Term (Tab α β)) :

                Whether a row occurs at least once.

                Equations
                Instances For
                  def Cvc.Typed.Term.tableSubtable [Ω] {α : List Type} {β : Type} (lft rgt : Term (Tab α β)) :

                  Whether every row of the first table occurs at least as often in the second.

                  Equations
                  Instances For
                    def Cvc.Typed.Term.tableMake [Ω] {α : List Type} {β : Type} (row : Term (Tup α β)) (count : Term Int) :
                    Env (Term (Tab α β))

                    The table holding one row, with the given multiplicity.

                    Equations
                    Instances For
                      def Cvc.Typed.Term.tableCount [Ω] {α : List Type} {β : Type} (row : Term (Tup α β)) (table : Term (Tab α β)) :

                      How often a row occurs.

                      Equations
                      Instances For
                        def Cvc.Typed.Term.tableCard [Ω] {α : List Type} {β : Type} (table : Term (Tab α β)) :

                        How many rows the table holds, counting duplicates.

                        Equations
                        Instances For
                          def Cvc.Typed.Term.tableSetof [Ω] {α : List Type} {β : Type} (table : Term (Tab α β)) :
                          Env (Term (Tab α β))

                          The table with every multiplicity reduced to one.

                          Equations
                          Instances For
                            def Cvc.Typed.Term.tableChoose [Ω] {α : List Type} {β : Type} (table : Term (Tab α β)) :
                            Env (Term (Tup α β))

                            Some row of the table, unspecified which; undefined on the empty table.

                            Equations
                            Instances For
                              def Cvc.Typed.Term.tableUnionMax [Ω] {α : List Type} {β : Type} (lft rgt : Term (Tab α β)) :
                              Env (Term (Tab α β))

                              Union taking the greater multiplicity of each row.

                              Equations
                              Instances For
                                def Cvc.Typed.Term.tableUnionMaxN [Ω] {α : List Type} {β : Type} (tables : Terms (Tab α β)) (atLeastTwoElements : 2 ≤ Array.size tables := by (try grind) <;> fail "failed to prove term array has at least two elements") :
                                Env (Term (Tab α β))

                                N-ary version of tableUnionMax, requires at least two elements.

                                Equations
                                Instances For
                                  def Cvc.Typed.Term.tableUnionDisjoint [Ω] {α : List Type} {β : Type} (lft rgt : Term (Tab α β)) :
                                  Env (Term (Tab α β))

                                  Union adding the multiplicities of each row.

                                  Equations
                                  Instances For
                                    def Cvc.Typed.Term.tableUnionDisjointN [Ω] {α : List Type} {β : Type} (tables : Terms (Tab α β)) (atLeastTwoElements : 2 ≤ Array.size tables := by (try grind) <;> fail "failed to prove term array has at least two elements") :
                                    Env (Term (Tab α β))

                                    N-ary version of tableUnionDisjoint, requires at least two elements.

                                    Equations
                                    Instances For
                                      def Cvc.Typed.Term.tableInterMin [Ω] {α : List Type} {β : Type} (lft rgt : Term (Tab α β)) :
                                      Env (Term (Tab α β))

                                      Intersection taking the lesser multiplicity of each row.

                                      Equations
                                      Instances For
                                        def Cvc.Typed.Term.tableInterMinN [Ω] {α : List Type} {β : Type} (tables : Terms (Tab α β)) (atLeastTwoElements : 2 ≤ Array.size tables := by (try grind) <;> fail "failed to prove term array has at least two elements") :
                                        Env (Term (Tab α β))

                                        N-ary version of tableInterMin, requires at least two elements.

                                        Equations
                                        Instances For
                                          def Cvc.Typed.Term.tableDifferenceSubtract [Ω] {α : List Type} {β : Type} (lft rgt : Term (Tab α β)) :
                                          Env (Term (Tab α β))

                                          Difference subtracting multiplicities.

                                          Equations
                                          Instances For
                                            def Cvc.Typed.Term.tableDifferenceRemove [Ω] {α : List Type} {β : Type} (lft rgt : Term (Tab α β)) :
                                            Env (Term (Tab α β))

                                            Difference removing a row entirely wherever it occurs on the right.

                                            Equations
                                            Instances For
                                              def Cvc.Typed.Term.tableFilter [Ω] {α : List Type} {β : Type} (p : Term (Tup α β → Bool)) (table : Term (Tab α β)) :
                                              Env (Term (Tab α β))

                                              The rows satisfying a predicate.

                                              Equations
                                              Instances For
                                                def Cvc.Typed.Term.tableAll [Ω] {α : List Type} {β : Type} (p : Term (Tup α β → Bool)) (table : Term (Tab α β)) :

                                                Whether every row satisfies a predicate.

                                                Equations
                                                Instances For
                                                  def Cvc.Typed.Term.tableSome [Ω] {α : List Type} {β : Type} (p : Term (Tup α β → Bool)) (table : Term (Tab α β)) :

                                                  Whether some row satisfies a predicate.

                                                  Equations
                                                  Instances For
                                                    def Cvc.Typed.Term.tablePartition [Ω] {α : List Type} {β : Type} [Ord (Tab α β)] (p : Term (Tup α β → Tup α β → Bool)) (table : Term (Tab α β)) :
                                                    Env (Term (Bag (Tab α β)))

                                                    Partitions the rows by an equivalence, answering a bag of tables.

                                                    Equations
                                                    Instances For
                                                      def Cvc.Typed.Term.tableEmpty' [Ω] (α : List Type) (β : Type) [ToTypList α] [ToTyp β] :
                                                      Env (Term (Tab α β))

                                                      The empty table of the given shape.

                                                      Equations
                                                      Instances For
                                                        @[reducible, inline]
                                                        abbrev Cvc.Typed.Term.tableEmpty [Ω] {α : List Type} {β : Type} [ToTypList α] [ToTyp β] :
                                                        Env (Term (Tab α β))

                                                        The empty table of the given shape.

                                                        Equations
                                                        Instances For