-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Potential for a cong helper macro in Tactic module #1136
Comments
This would be a very nice addition. :) |
agda-holes auto-applies Also, the exact syntax is up for bikeshedding. One possibility is that it becomes an alternative form of |
I quite like the idea of using ⌞ (b + c) + a * b ⌟ + a * c ≡⌞⟨ +-assoc b c (a * b) ⟩⌟ |
That would be a very nice addition. Opinions:
|
OK, I think I prefer that too, so how does this sound?
This second form would be convenient for use in single line proofs, where the If we had a open import Tactic.Holes would use open import Tactic.Holes {{mycong}} would use a different, user-specified implementation. |
Although visually the proposed syntax is fine, I am a little worried about how much effort it takes to input, and that comes from someone who is completely sold on the unicode front :) Why not either |
Oh, I like those suggestions! Especially the first one. [Sometimes it takes a bad syntax suggestion to prod someone else to have a better one... yeah, I'll go with that! ;) ] |
@ajrouvoet's suggestion would make it nicely compatible with the |
Talking about syntax, the categories library had the much nicer IMO |
Just to add my voice that this would be a great idea! I like the
@ajrouvoet I too would like to do something about the |
And now issue #1138 seems to have been introduced for discussing just that. We should keep the discussion here about cong-helper. |
Just a heads up: I'm writing my own implementation, not based on agda-holes. I have the implementation of foo : (a b c : ℤ) → ⌊ a + b ⌋ + c ≡ b + a + c
foo a b c = ⌊⌋ (+-comm a b) This should also work with the It is currently proving a bit tricky to write the The code is sitting at 139 lines in a single file. It is being tested against |
Hmmph. Even with foo2 : (a b c : ℤ) → ⌊ a + b ⌋ + c ≡ b + a + c
foo2 a b c = begin
⌊ a + b ⌋ + c ≡⟨ ⌊⌋ (+-comm a b) ⟩
b + a + c ∎ the type of the term given to the |
Sorry to spam, but I fixed that problem with the normalisation - adding {-# NOINLINE ⌊_⌋ #-} stopped the eager normalisation. |
And now |
To help visualise possible syntax, here's a slightly more complex proof that works with the new macro: Note that default font rendering on GitHub does not maintain fixed width glyphs - view this in Emacs for best results foo : (a b c d : ℤ) → (a + b) * (c + d) ≡ a * c + a * d + b * c + b * d
foo a b c d = begin
(a + b) * (c + d) ≡⟨ *-distribˡ-+ (a + b) _ _ ⟩
⌊ (a + b) * c ⌋ + (a + b) * d ≡⌊ *-distribʳ-+ c a b ⌋
a * c + b * c + ⌊ (a + b) * d ⌋ ≡⌊ *-distribʳ-+ d a b ⌋
a * c + b * c + (a * d + b * d) ≡⟨ +-assoc (a * c) _ _ ⟩
a * c + ⌊ b * c + (a * d + b * d)⌋ ≡⌊ +-comm (b * c) _ ⌋
a * c + ((a * d + b * d) + b * c) ≡⟨ sym $ +-assoc (a * c) _ _ ⟩
⌊ a * c + (a * d + b * d) ⌋ + b * c ≡⌊ sym $ +-assoc (a * c) _ _ ⌋
a * c + a * d + b * d + b * c ≡⟨ +-assoc (a * c + a * d) _ _ ⟩
a * c + a * d + ⌊ b * d + b * c ⌋ ≡⌊ +-comm (b * d) _ ⌋
a * c + a * d + (b * c + b * d) ≡⟨ sym $ +-assoc (a * c + a * d) _ _ ⟩
a * c + a * d + b * c + b * d ∎ I have chosen |
In order to be generic over more {-# OPTIONS --without-K --safe #-}
open import Reflection
open import Reflection.Term
open import Reflection.Argument
open import Function.Base
open import Data.List
open import Data.Nat
failed-apply : Term → Arg Term → TC Term
failed-apply t (arg _ a) = typeError $ strErr "Attempted to apply" ∷ termErr a ∷ strErr "to" ∷ termErr t ∷ []
apply : Arg Term → Term → TC Term
subst : ℕ → Term → Term → TC Term
subst-args : ℕ → Term → List (Arg Term) → TC (List (Arg Term))
apply a (var x args) = return $ var x (args ∷ʳ a)
apply a (con c args) = return $ con c (args ∷ʳ a)
apply a (def f args) = return $ def f (args ∷ʳ a)
apply a (meta x args) = return $ meta x (args ∷ʳ a)
-- TODO: irrelevant arguments are not handled yet - not sure how to
apply (vArg x) (vLam _ t) = subst 0 x t
apply (hArg x) (hLam _ t) = subst 0 x t
apply (iArg x) (iLam _ t) = subst 0 x t
-- TODO - pattern lambdas and pi terms
apply a (pat-lam cs args) = typeError $ strErr "TODO" ∷ []
apply a (pi _ _) = typeError $ strErr "TODO" ∷ []
apply a t = failed-apply t a -- catch all
subst i x (var j args) with compare i j
... | less m k = do -- decrement j by one since λ was eliminated
args ← subst-args i x args
return $ var (m + k) args -- j ≡ suc (m + k)
... | greater _ _ = do -- j refers to variable inside eliminated λ
args ← subst-args i x args
return $ var j args
subst i x (var j []) | equal _ = return x
subst i x (var j (arg v a ∷ as)) | equal _ = do
a′ ← subst i x a
xa ← apply (arg v a′) x
subst i xa (var j as)
subst i x (con c args) = do
args ← subst-args i x args
return $ con c args
subst i x (def f args) = do
args ← subst-args i x args
return $ def f args
subst i x (lam v (abs s t)) = do
t ← subst (suc i) x t
return $ lam v (abs s t)
subst i x (meta m args) = do
args ← subst-args i x args
return $ meta m args
subst i x (sort s) = return $ sort s
subst i x (lit l) = return $ lit l
subst i x unknown = return unknown
subst i x (pat-lam cs args) = typeError $ strErr "TODO" ∷ []
subst i x (pi a b) = typeError $ strErr "TODO" ∷ []
subst-args i x [] = return []
subst-args i x (arg v a ∷ as) = do
a ← subst i x a
as ← subst-args i x as
return $ arg v a ∷ as
|
In general substitution of terms is not terminating since reflected terms are untyped. You might want to take a look at https://github.com/UlfNorell/agda-prelude/blob/master/src/Tactic/Reflection/Substitute.agda for a way to define a safe version of substitution (and application) that is terminating. |
That safe version looks ideal for my purposes, thanks! It looks like something that would be very useful to have in the standard library. |
I'm a little concerned by UlfNorell/agda-prelude#65 however. |
Yup, agreed. If you've after you've had a fiddle with it, we'd definitely appreciate you opening a pull request 😄 |
Heads up: I now have it working with Before I make a PR, there are some things to take care of:
From what I have learnt here it should be possible to make a "selective normalisation" function that would greatly help #1071. |
The PR is up (#1158). |
An alternative proposal was added in #1658 |
agda-holes is a library that makes working with
cong
more convenient and succinct. This issue is for discussing the possibility of adding some similar functionality inside theTactic
module alongside the ring and monoid solvers.agda-holes is not usable as-is. It has bit-rotted from the current stable Agda, and it also relies on uses of the
TERMINATING
pragma, which would presumably need to be removed and the corresponding functions refactored. It would also need to be made properly agnostic overcong
implementations (e.g. from cubical Agda). I might be interested in undertaking the work to make it suitable for inclusion when I get some time, so I'm interested in whether this sounds like a good idea.The text was updated successfully, but these errors were encountered: