Zulip Chat Archive
Stream: mathlib4
Topic: HomogeneousPow instances in mathlib
Edward van de Meent (Dec 23 2024 at 11:20):
in discord, a question came up about tetration, where the OP defined it as follows:
def tetration {α : Type u_1} [HomogeneousPow α] [One α] (x : α) (n : ℕ) : α :=
match x, n with
|x, 0 => 1
|x, Nat.succ n => x ^ (tetration x n)
although the definition compiles, it is not useful at all, since the only instance for docs#HomogeneousPow is for Float
, rather than also for Nat
, Real
, and maybe Complex
. do we want to have these instances? or maybe should we prefer to have HomogeneousPow α
reduce to Pow α α
or something like that?
Edward van de Meent (Dec 23 2024 at 11:31):
small bits of context: right now, docs#HPow , docs#Pow and docs#HomogeneousPow are all separate one-field classes (yes, they don't extend eachother) and have instances in the sensible direction, but there are no instances or anything to turn HPow a b a
into Pow a b
or Pow a a
into HomogeneousPow a
Eric Wieser (Dec 23 2024 at 11:40):
I think this might just be a notation implementation detail (cc @Kyle Miller), and for the definition above you should just use Pow α α
Edward van de Meent (Dec 23 2024 at 12:02):
as far as i can tell, HPow
is the only notation class among them, since b ^ a
means HPow.hpow b a
Eric Wieser (Dec 23 2024 at 12:05):
Right, but I think this plays a part in the custom elaborator that implements that notation
Edward van de Meent (Dec 23 2024 at 12:06):
you mean the rightact%
elaborator?
Edward van de Meent (Dec 23 2024 at 12:08):
i can't seem to find source code for that elaborator, is it built in? found it
Edward van de Meent (Dec 23 2024 at 12:14):
as far as i can tell, there is no mention of Pow
or HomogeneousPow
there...
Eric Wieser (Dec 23 2024 at 12:16):
lean4#2854 has some context
Edward van de Meent (Dec 23 2024 at 12:21):
so, if i'm reading this right, you're correct in saying that HomogeneousPow
(and as it turns out NatPow
as well) are implementation details...
Both
NatPow
andHomogeneousPow
provide a defaultPow
instance, and types can choose to implement an instance for one of these two depending on whether they would prefer the exponent to default to being aNat
or to the base's type
Edward van de Meent (Dec 23 2024 at 12:28):
i suppose it would be useful if these get marked as such? they are, but apparently not clearly enough
Edward van de Meent (Dec 23 2024 at 12:31):
would the docs be improved if it were to explicitly say "this class should not be used as an argument"?
Eric Wieser (Dec 23 2024 at 12:47):
I think "prefer writing [Pow A A]
to [HomogeneousPow A]
in argument lists" would be clearer
Kyle Miller (Dec 23 2024 at 20:34):
It should be HPow in argument lists, since HPow does not provide Pow instances.
Kyle Miller (Dec 23 2024 at 20:37):
I would not say NatPow or HomogeneousPow are implementation details — they're intended to be used by users to specify how the exponentiation should elaborate by default.
Edward van de Meent (Dec 23 2024 at 20:39):
Is there a reason to distinguish between Pow A B
and HPow A B A
?
Kyle Miller (Dec 23 2024 at 20:44):
In what sense?
Kyle Miller (Dec 23 2024 at 20:45):
For writing instances? Probably not. For argument lists? Yes, because HPow
does not provide Pow
instances.
Edward van de Meent (Dec 23 2024 at 20:47):
From a design POV, what is wrong with having abbrev Pow (A : Type*) (B : Type*) := HPow A B A
?
Last updated: May 02 2025 at 03:31 UTC