9 Metatheorems from Invariants
For the purposes of this chapter, a theorem is a (true) statement about particular equations, for example ‘(387 implies 43)’ is a theorem. A metatheorem is a general statement about implications; one can usually get many theorems from a single metatheorem. This chapter is all about generating many interesting metatheorems using a meta-metatheorem, called the fundamental property of invariants. If all this is making your head spin, don’t worry. Look at the sections below for examples of metatheorems you can probably agree are both concrete and interesting. Once you have done that, come back here and we will show you how to prove these and other metatheorems using invariants.
9.1 Invariants
Let
Extending this idea, suppose we compute the set of all equations which are implied by
While computing
If we can find an invariant which is computable for each term
More succinctly, for an invariant
When using this result, we commonly take the contrapositive: if
The fundamental property of invariants is not a theorem, nor a metatheorem: it is a meta-metatheorem, in the sense that it will allow us to get a metatheorem for every invariant we find.
Example: absorption law
Let
We will talk about proving statements like this one (say in Lean) later on; take it as given for now. The invariant is clear: we define
Example: associativity
For a more complicated example, let
There is an invariant lurking behind: it is the (ordered) list of variables appearing in an expression, counting repetitions. More formally, we define
If we were coding a computer program that computes
We can compute other examples, but the invariant can get complicated even for simple equations. Exercise: what is the invariant for commutativity? Answer: To compute
9.2 Expanding the language
The method of invariants really shines when we expand our formal language. Right now our language consists of variables, parentheses, the equal sign, and
We will add the symbol
If
Again, this clearly agrees with our previous definition. Although
Example: associativity and idempotency
Let
Example: associativity and commutativity
For a similar example, we can let
Trivia: this was the first example of a metatheorem obtained by use of an invariant.
Example: associativity and commutativity with a twist
We can keep expanding our language if it helps us express more intricate invariants. For instance, we can add the symbol ‘1’ to our language. Let
for some fixed positive integer
The invariant
9.3 Proving metatheorems from invariants in Lean
For the rest of this chapter we readopt the convention of calling ‘theorem’ an important result, not necessarily pertaining to specific equations.
An invariant is generally a syntactic property of an expression. However, invariants can also be described and calculated semantically through the notion of a lifting magma family, described below. The general idea is that the value of an invariant for an expression can be computed by substituting specific values for the variables in the expression and evaluating the result in a certain magma in the lifting magma family; additional requirements ensure that the fundamental property of invariants is satisfied.
A lifting magma family is a family of magmas
For each type
, there is a function .Given a function
, there is a magma homomorphism such that for all in .
The free Abelian groups form a lifting magma family. When the underlying set is finite, the groups are isomorphic to
Lists form a lifting magma family.
The key consequence of the Definition 9.7 is that it is significantly easier to check whether an equation is satisfied in a lifting magma family.
Suppose
Determining whether
Let
If
The result of evaluating an expression along the function
In the case of Abelian groups, the result of evaluation is the variables in the expression with multiplicity. In the case of lists, the result of evaluation is the variables in the expression in the order they appear.
When the lifting magma family has good computational properties, calculating the invariant becomes easy.
Given an equation
However, for the purpose of generating invariants, we are interested in lifting magma families with convenient descriptions that are computationally tractable.
Suppose
This offers a way of generating examples of lifting magma families with good computational properties for computing invariants of expressions.
9.4 Generating laws from equations
The invariants defined in this chapter are properties of the syntax of the equations being considered. In other words, they are properties of the laws associated with the equations, rather than of the equations themselves. Proving non-implications using invariants requires a way to operate on the syntax of the equations and then translate the reasoning back to results about the original equations.
A magma law can be generated from an equation by accessing the syntax used in its definition and converting it to a declaration representing a magma law through metaprogramming. There is a choice in the variable set of the magma law – one one hand, it can be a finite set whose size matches the number of variables, and on the other hand, it can be the set of natural numbers. The advantage of the former is that one can generate proofs that the satisfiability of the magma law is equivalent to the satisfiability of the original equation (this only needs to be done for variable sets of size up to six, since that is the maximum size currently being considered in the project; it’s convenient to prove individual lemmata for each variable set size establishing this equivalence). The advantage of the latter is that it bypasses the need to cast between various finite sets while constructing a model as a counter-example.
One approach is to generate both forms of the law, using the first to establish the equisatisfiability of the law and the equation and then transporting this result to the second form of the law. The conversion from the first form to the second is summarised in the lemma below.
[Compatibility between magma laws over finite sets and the natural numbers] Let
9.5 Conclusion: Beyond Invariants
We are still lacking:
A large collection of invariants.
An estimate for how many implications the resulting metatheorems will settle.
Algorithms (in Lean, Python, or otherwise) to compute known invariants.
General results about lifting magmas.
Formalization of the method of invariants and resulting metatheorems.
Knowledge about the category-theoretic interpretation of invariants (see the questions in the note for category theorists).
Related to the last bullet point, we note the following. If all that matters about invariants is the fundamental property, we can apply the old French trick of turning a (meta-meta)theorem into a definition.
Q: If we were to define invariants as any functions satisfying the fundamental property, would anything change? (For those who read the note for category theorists: an equivalent redefinition is to consider invariants as functors