You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Better documentation of --lossy-unification requested by @MatthiasHu.
This is an example where --lossy-unification loses a solution that is found without this flag:
{-# OPTIONS --lossy-unification #-}open importAgda.Builtin.Boolopen importAgda.Builtin.Natopen importAgda.Builtin.Equality-- Non-injective functionsmutualeven : Nat → Bool
even zero = true
even (suc n) = odd n
odd : Nat → Bool
odd zero = false
odd (suc n) = even n
mutual
X = _
Y = _
-- lossy unification sets X=Y_ : even X ≡ even Y
_ = refl
_ : X ≡ 2 + Y
_ = refl
-- With --lossy-unification this fails:-- 2 != 4 of type Nat-- when checking that the expression refl has type X ≡ 2 + Y_ : X ≡ 2
_ = refl
TODO: an example where --lossy-unification is necessary for success.
{-# OPTIONS --lossy-unification #-}open importAgda.Builtin.Boolopen importAgda.Builtin.Equalityf : Bool → Bool
f true = true
f false = true
test : f false ≡ f _
test = refl
Yes. I saw that my example can be rewritten to prove both points:
mutual
X = _
Y = _
-- lossy unification sets X=Y_ : even X ≡ even Y
_ = refl
_ : X ≡ 2
_ = refl
-- With --lossy-unification, all variables are solved and the following equation triggers an error.-- Without --lossy-unification, Y is still unsolved and the following equation is needed to solve it._ : X ≡ 2 + Y
_ = refl
I don't think we should encourage use of this option. As I wrote elsewhere:
Note that Agda is not really designed for the use of lossy unification. In "A comprehensible guide to a new unifier for CIC including universe polymorphism and overloading" Ziliani and Sozeau argue for a form of lossy, first-order unification. They present an example with multiple solutions, and claim that the first-order solution is the natural, expected one. However, they also deliberately do not include constraint postponement, in favour of a more predictable unification algorithm.
With non-lossy unification you have the guarantee that, if the code type-checks, and you can find one consistent way to instantiate all meta-variables, then that is the way that the code is interpreted by the system (in the absence of bugs). With lossy unification the solution you have in mind might not be the one the system uses. If the unification algorithm is very simple and predictable, then that is perhaps fine, but Agda's unification algorithm is arguably rather complicated.
Something along these lines could perhaps be integrated into the documentation.
Activity
jespercockx commentedon Nov 4, 2022
How about this example?
andreasabel commentedon Nov 4, 2022
Yes. I saw that my example can be rewritten to prove both points:
nad commentedon Nov 4, 2022
I don't think we should encourage use of this option. As I wrote elsewhere:
Something along these lines could perhaps be integrated into the documentation.
nad commentedon Nov 28, 2022
I plan to add something like this to the 2.6.3 changelog (see #6365).