Relations, typed #
A relation is a set of tuples, indexed by Rel α β: its tuples are Tup α β, whose components
are the list α followed by β. So Rel [Int] Bool relates Ints to Bools, and Rel [] α is
a unary relation. A tuple is built with mkTup (.cons a (.last b)), and a component is read at a
typed position, t.tupAt col%1.
The set operators are restated at a relation's index (relUnion, relMember, …); relToSet
crosses to Set, for setMap and setFold. cvc5 marks every relation-specific kind experimental.
Tuples #
The components of a tuple, in order, along with the index they denote.
last and cons are the only builders, so the number of terms and the number of components the
index describes stay in step.
- terms : Cvc.Untyped.Terms
Instances For
The final component.
Instances For
Adds a component in front of the ones collected so far.
Equations
- Cvc.Typed.Term.Tup.Components.cons component rest = { terms := #[component.erase] ++ Cvc.Typed.Term.Tup.Components.terms✝ rest }
Instances For
The components' terms, sort-erased and in order; free.
Equations
Instances For
The components' terms, sort-erased and in order; free.
Instances For
The tuple whose components are the given ones.
A component that is itself a tuple stays one: Tup [α] (Tup [β] γ) denotes
(Tuple α (Tuple β γ)), not a three-component tuple.
Equations
- Cvc.Typed.Term.mkTup components = Cvc.Untyped.Term.mkTuple (Cvc.Typed.Term.Tup.Components.terms✝ components)
Instances For
Every component but the first, as a tuple.
A projection rather than a selection, since the result has more than one component in general.
Composing it with tupFst reaches any position.
Equations
- tuple.tupRest = Cvc.Untyped.Term.tupleProject (Array.map (fun (x : Nat) => x + 1) (Array.range (αs.length + 1))) tuple.erase
Instances For
The component at the given position, at that component's own type.
The general form of tupFst/tupLast, and the way to reach a middle component without composing
tupRest: t.tupAt col%1 is the second one.
Equations
- tuple.tupAt idx = Cvc.Untyped.Term.tupleSelect idx.toNat tuple.erase
Instances For
The tuple of the components at the given positions: t.tupProject cols% [2, 0].
Projecting one position gives a one-component tuple, where tupAt gives the component.
Equations
- Cvc.Typed.Term.tupProject cols tuple = Cvc.Untyped.Term.tupleProject cols.toArray tuple.erase
Instances For
Crossing to and from sets #
Both directions are the identity on terms: a relation is a set of tuples, and only the index
differs. They are here for the operators that leave the relation world, and for interoperating with
code written against Set.
Relational operators #
Composition: lft's last component and rgt's first are the same mu, and both are dropped.
The shared mu is cvc5's joinability requirement, stated in the signature rather than checked at
run time.
Instances For
Reverses every tuple's components.
Equations
- rel.relTranspose = rel.erase.relTranspose
Instances For
The identity relation over a unary relation's elements.
Rel [] α is the unary relation — the split index says so directly, with no separate
one-component tuple type needed.
Instances For
Partitions the relation, putting tuples that agree on the given components in the same part.
Answers a set of relations. The indices choose what is compared and so do not reach the result's sort.
Equations
- Cvc.Typed.Term.relGroup indices rel = Cvc.Untyped.Term.relGroup indices rel.erase
Instances For
Folds each group of tuples that agree on the given components.
The groups are relGroup's, but the answer is a set of accumulators rather than a set of
relations: f runs over each group's tuples 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 tuple of the
relation 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, and nothing about the fold has to be checked at run
time.
The indices only say what is grouped, so they do not reach the result's sort. With none of them every tuple is in one group, which is an ordinary fold over the whole relation.
Equations
- Cvc.Typed.Term.relAggregate indices f init rel = Cvc.Untyped.Term.relAggregate indices f.erase init.erase rel.erase
Instances For
Equi-join: the product, keeping the pairings whose given component pairs agree.
The result's sort is the product's, since the pairs only filter.
Equations
- Cvc.Typed.Term.relTableJoin indices lft rgt = Cvc.Untyped.Term.relTableJoin indices lft.erase rgt.erase
Instances For
Projects every tuple onto the given components, in the order given.
Positions are written cols% [2, 0], and may reorder and repeat components.
Untyped.Term.relProject takes them as an Array Nat, for positions known only at run time.
Equations
- Cvc.Typed.Term.relProject cols rel = Cvc.Untyped.Term.relProject cols.toArray rel.erase
Instances For
The set operators, at a relation's index #
Same operators, same behaviour; only the index differs, so a relation never has to be read as a set to be built or constrained.
Whether the relation has no tuple.
Equations
- rel.relIsEmpty = rel.erase.setIsEmpty
Instances For
Whether the relation has exactly one tuple.
Equations
- rel.relIsSingleton = rel.erase.setIsSingleton
Instances For
The relation holding exactly one tuple.
Equations
- elm.relSingleton = elm.erase.setSingleton
Instances For
N-ary version of relUnion, requires at least two elements.
Equations
- Cvc.Typed.Term.relUnionN rels atLeastTwoElements = Cvc.Untyped.Term.setUnionN rels atLeastTwoElements
Instances For
N-ary version of relInter, requires at least two elements.
Equations
- Cvc.Typed.Term.relInterN rels atLeastTwoElements = Cvc.Untyped.Term.setInterN rels atLeastTwoElements
Instances For
N-ary version of relMinus, requires at least two elements.
Equations
- Cvc.Typed.Term.relMinusN rels atLeastTwoElements = Cvc.Untyped.Term.setMinusN rels atLeastTwoElements
Instances For
Complement, against every tuple of the relation's shape.
Equations
- rel.relComplement = rel.erase.setComplement
Instances For
The empty relation of the given shape.
Equations
- Cvc.Typed.Term.relEmpty' α β = do let __do_lift ← Cvc.Srt.of (Cvc.Tup α β) Cvc.Untyped.Term.setEmpty __do_lift
Instances For
The relation holding every tuple of its shape.
Equations
- Cvc.Typed.Term.relUniverse' α β = do let __do_lift ← Cvc.Srt.of (Cvc.Tup α β) Cvc.Untyped.Term.setUniverse __do_lift