-
Notifications
You must be signed in to change notification settings - Fork 419
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
elaboration of ^
shouldn't try to put the arguments in the same type
#2220
Comments
^
shouldn't use binop%
^
shouldn't try to put the arguments in the same type
The idea is to have a default instance for macro_rules | `($x ^ $y) => `(HPow.hPow $x $y)
class Semiring (R : Type) extends Pow R Nat
instance : Semiring Nat where
@[default_instance high] instance [Semiring R] : Pow R Nat := inferInstance
example (n : Nat) := ∃ k, n = 2 ^ k -- works fine (We have that instance in |
@gebner A design I've been thinking about that would help with Here's a simple proposal for how to handle this: add
The effect is that Another design would be to adjust
|
I have a prototype of my suggestion at https://gist.github.com/kmill/bc58941368cc60738f3c932fe2546c9d With it, we can see the following behavior: import Mathlib.binop2
import Mathlib.Data.Real.Basic
#check (3 : ℝ) ^ 2
-- 3 is real
-- 2 is a nat
#check (1 : ℝ) + 3 ^ 2
-- 1 is real
-- 3 is real
-- 2 is a nat
#check (1 + 3 ^ 2 : ℝ)
-- 1 is real
-- 3 is real
-- 2 is a nat In particular, exponentiation is modeled as a right action, and only the LHS participates in the coercion protocol. Some more examples with Mathlib's left action notation: import Mathlib.binop2
import Mathlib.Algebra.Algebra.Basic
macro_rules | `($x • $y) => `(leftact% HSMul.hSMul $x $y)
#check (1 • 2 : ℝ)
-- 1 is a nat
-- 2 is real
variable [Ring R] [AddCommMonoid M] [Module R M] (r : R) (N : Submodule R M) (m : M) (n : N)
#check m + r • n
-- m + r • ↑n : M We'll see how it works in practice in some mathlib files, and then if it seems good I'll create a PR. I think it only involves adding about 15 lines. |
An undergraduate just ran into this issue: they had a working file, and then added an import (which gave an instance of (z : \C)^(y : \C)), and a import Mathlib.RingTheory.RootsOfUnity.Basic
import Mathlib.Data.Complex.Basic
-- uncomment this import to break the proof
--import Mathlib.Analysis.SpecialFunctions.Pow.Complex
-- uncomment this hack to fix it again
--local macro_rules | `($x ^ $y) => `(HPow.hPow $x $y)
example (q : ℕ+) : ζ ∈ rootsOfUnity q ℂ ↔ ((ζ : ℂˣ) : ℂ) ^ ((q : ℕ+) : ℕ) = 1 := by
simp only [mem_rootsOfUnity']
done |
The solution of adding
in which uncommenting the macro changes the elaboration of |
leanprover-community/mathlib4#6852 has a large-scale experiment with my modifications to the In Bhavik's example, the conclusion elaborates as |
Because of leanprover/lean4#2220, `z ^ (n : ℕ)` was interpreted as `z ^ (↑n : ℂ)`. Add a workaround, fix proofs, move part of a proof to a new lemma.
Because of leanprover/lean4#2220, `z ^ (n : ℕ)` was interpreted as `z ^ (↑n : ℂ)`. Add a workaround, fix proofs, move part of a proof to a new lemma.
When reading this file, it is difficult to tell whether statements are about ordinal or natural powers; especially given that when leanprover/lean4#2220 is fixed the meanings may change. This adds type annotations to remove the ambiguity.
When reading this file, it is difficult to tell whether statements are about ordinal or natural powers; especially given that when leanprover/lean4#2220 is fixed the meanings may change. This adds type annotations to remove the ambiguity.
Description
The macro for the
^
notation for exponentiation is defined asHowever, the
binop%
elaborator tries to make the type ofx
andy
the same, which is not desired for exponentiation.MWE
The desired result is that all checks use the
instHPowRealNat
instance, i.e. that4
is interpreted as aNat
.Additional Notes
Just removing
binop%
and replacing the macro with the following fixes the current issue, but it causes problems in other elaboration problems.With this macro an example like the following fails.
Zulip Discussion
link
The text was updated successfully, but these errors were encountered: