Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do Calculus of Construction based languages use Setoids so much?

Tags:

agda

coq

lean

One finds that Setoids are widely used in languages such as Agda, Coq, ... Indeed languages such as Lean have argued that they could help avoid "Setoid Hell". What is the reason for using Setoids in the first place? Does the move to extensional type theories based on HoTT (such as cubical Agda) reduce the need for Setoids?

like image 427
Henry Story Avatar asked Dec 29 '20 14:12

Henry Story


People also ask

Is calculus harder than discrete math?

Linear algebra is considered harder than discrete math since it has more complex material, the subject material is difficult to visualize, and the mathematical proofs are more difficult. Calculus II is also harder than discrete math since it has more advanced concepts and ideas.

What would the world look like without calculus?

Without calculus, we wouldn't have cell phones, computers, or microwave ovens. We wouldn't have radio. Or television. Or ultrasound for expectant mothers, or GPS for lost travelers.

Is Linear algebra harder than calculus?

Linear algebra is easier than elementary calculus. In Calculus, you can get by without understanding the intuition behind theorems and just memorizing algorithms, which won't work well in the case of linear algebra. By understanding the theorems in linear algebra, all questions can be solved.

Is calculus the language of the universe?

“If calculus is the language of the universe, then Steven Strogatz is its Homer. With verve, insight, and simplicity, he explains the deep ideas underlying one of humankind's greatest intellectual achievements. Infinite Powers is an incalculable pleasure.”


2 Answers

As Li-yao Xia's answer describes, setoids are used when we don't have or don't want to use quotients.

In the HoTT book and in Lean quotients are (basically) axiomatized. One difference between Lean and the HoTT book is that the latter has many more higher inductive types, and Lean only has quotients and (regular) inductive types. If we just restrict our attention to quotients (set quotients in the HoTT book), it works the same in Lean and in Book HoTT. In this case you just postulate that given a type A and an equivalence R on A you have a quotient Q, and a function [-] : A → Q with the property ∀ x y : A, R x y → [x] = [y]. It comes with the following elimination principle: to construct a function g : Q → X for some type X (or hSet X in HoTT) we need a function f : A → X such that we can prove ∀ x y : A, R x y → f x = f y. This comes with the computation rule, that states ∀ x : A, g [x] ≡ f x (this is a definitional equality in both Lean and Book HoTT).

The main disadvantage of this quotient is that it breaks canonicity. Canonicity states that every closed term (that is, a term without free variables) in (say) the natural numbers normalizes to either zero or the successor of some natural number. The reason that this quotient breaks canonicity is that we can apply the elimination principle for = to the new equalities in a quotient, and a term like that will not reduce. In Lean the opinion is that this doesn't matter, since in all cases we care about we can still prove an equality, even though it might not be a definitional equality.

Cubical type theory has a fancy way to work with quotients while retaining canonicity. In CTT equality works differently, and this means that higher inductive types can be introduced while keeping canonicity. Potential disadvantages of CTT are that the type theory is a lot more complicated, and that you have to embrace HoTT (and in particular give up on proof irrelevance).

like image 111
Floris van Doorn Avatar answered Nov 11 '22 10:11

Floris van Doorn


[The answers by Lia-yao Xia and Floris van Doorn are both excellent, so I will try to augment them with additional information.]

Another view is that quotients, while used a lot in classical mathematics, are perhaps not so great after all. Not taking quotients but sticking to Groupoids is exactly where non-commutative geometry starts from! It teaches us that some quotients are incredibly badly behaved, and the last thing we want to do (in those cases!) is to actually quotient. But that the thing itself is not so bad, even quite good, if you treat it using the 'right' tools.

It is arguably also deeply embedded in all of category theory, where one doesn't quotient out equivalent objects. Taking of 'skeletons' in category theory is regarded to be in bad taste. The same is true of strictness, and a host of other things, all of which boil down to trying to squish things down that are better left as they are, as they do no harm at all. We're just used to wanting 'uniqueness' to be reflected in our representations - something we should just get over.

Setoid hell arises not because some coherences must be proven (you need to prove them to show you have a proper equivalence, and again whenever you define functions on raw representations instead of on the quotiented version). It arises when you're forced to prove these coherences again and again when defining functions that can't possibly "go wrong". So Setoid hell is actually caused by a failure to provide proper abstraction mechanisms.

In other words, if you're doing sufficient simple mathematics, where quotients are well-behaved, then there should be some automation that lets you work with that smoothly. Currently, in type theory, working out exactly what that could look like, is ongoing research. Floris' answer outlines well what one pitfall is: at some point, you give up that computations will be well-behaved, and from then on, are forced to do everything via proofs.

like image 41
Jacques Carette Avatar answered Nov 11 '22 12:11

Jacques Carette