Zulip Chat Archive

Stream: new members

Topic: Naming Conventions


Alex Zhang (Aug 03 2021 at 16:21):

protected def is_sym (A : matrix I I α) : Prop := A = A

lemma is_sym_apply {A : matrix I I α} (h : A.is_sym) (i j : I) :
A i j = A i j :=
by {simp [matrix.is_sym] at h, rw h}

lemma is_sym_ext {A : matrix I I α} :
( i j, A i j = A i j)  A.is_sym :=
by {intro h, ext, exact h i j}

lemma is_sym_iff (A : matrix I I α) : A.is_sym   i j, A i j = A i j :=
is_sym_apply, is_sym_ext

Are the three lemma names I gave consistent with the name conventions?

Yakov Pechersky (Aug 03 2021 at 16:26):

I wouldn't do protected def. I would call the first lemma is_sym.apply.

Alex Zhang (Aug 03 2021 at 16:27):

or perhaps

lemma is_sym_ext {A : matrix I I α} (h : A.is_sym) (i j : I) :
A i j = A i j :=
by {simp [matrix.is_sym] at h, rw h}

lemma is_sym_of {A : matrix I I α} :
( i j, A i j = A i j)  A.is_sym :=
by {intro h, ext, exact h i j}

lemma is_sym_iff (A : matrix I I α) : A.is_sym   i j, A i j = A i j :=
is_sym_ext, is_sym_of

Alex Zhang (Aug 03 2021 at 16:28):

@Yakov Pechersky I did that because I think matrix.is_sym is parallel with some other .is_syms existing in mathlib. Some bridges can be then built.

Yakov Pechersky (Aug 03 2021 at 16:31):

I only found sym_sesq_form and sym_bilin_form with is_sym. Neither is protected afaik. The nice part of not protected is that open matrix will let you just say is_sym.

Alex Zhang (Aug 03 2021 at 16:35):

I am not sure whether there is any advantage of using the dot notation in this case.

Yakov Pechersky (Aug 03 2021 at 16:36):

Dot notation lets you write h.apply i j to mean Aᵀ i j = A i j when you have (h : A.is_sym) (i j : I)

Alex Zhang (Aug 03 2021 at 16:38):

oh, that's nice.

Alex Zhang (Aug 03 2021 at 16:40):

Which version of the lemma names is better do you think? @Yakov Pechersky @Eric Wieser when changing both to is_sym.

Yakov Pechersky (Aug 03 2021 at 16:43):

I could call the last one as is_sym.ext_iff. Where would you use it?

Yakov Pechersky (Aug 03 2021 at 16:43):

You can prove it just by rw [is_sym, matrix.ext_iff]

Alex Zhang (Aug 03 2021 at 16:46):

Yakov Pechersky said:

I could call the last one as is_sym.ext_iff. Where would you use it?

I think that is useful in many further theorems.

Yakov Pechersky (Aug 03 2021 at 16:47):

Sure, but since you know that A^T = A you could just rewrite that, you don't need to require it to be fully applied.

Alex Zhang (Aug 03 2021 at 16:49):

Yes. The three lemmas are very simple APIs anyway. I was just a little bit concerned about which names are better.

Alex Zhang (Aug 03 2021 at 16:52):

Modified according to your suggestion!

def is_sym (A : matrix I I α) : Prop := A = A

lemma is_sym.ext_iff {A : matrix I I α} : A.is_sym   i j, A i j = A i j :=
by rw [is_sym, matrix.ext_iff]

lemma is_sym.apply {A : matrix I I α} (h : A.is_sym) (i j : I) :
A i j = A i j := is_sym.ext_iff.1 h i j

lemma is_sym.ext {A : matrix I I α} :
( i j, A i j = A i j)  A.is_sym := is_sym.ext_iff.2

Alex Zhang (Aug 03 2021 at 16:56):

It will be useful to prove

def cir (v : fin n  α) : matrix (fin n) (fin n) α
| i j := v (i - j)

lemma cir_is_sym_ext_iff (v : fin n  α) :
(cir v).is_sym   i j, v (j - i) = v (i - j) :=
by simp [is_sym.ext_iff, cir]

for example.

Eric Wieser (Aug 03 2021 at 16:57):

Why would you want to prove that and not (cir v).is_sym ↔ ∀ i, v i = v (-i)?

Eric Wieser (Aug 03 2021 at 16:58):

I'm not really sure any of these lemmas are worth having

Yakov Pechersky (Aug 03 2021 at 16:59):

You can make them, and then when you use them in a more complex lemma, we can see if there are good golfing strategies that retain expressability/comprehensability

Eric Wieser (Aug 03 2021 at 16:59):

The only lemma I'd want is is_sym.eq (h : A.is_sym) : Aᵀ = A := h for dot notation.

Alex Zhang (Aug 03 2021 at 17:01):

I was not careful enough, it should be (cir v).is_sym ↔ ∀ i, v (-i) = v i .

Alex Zhang (Aug 03 2021 at 17:02):

Eric Wieser said:

The only lemma I'd want is is_sym.eq (h : A.is_sym) : Aᵀ = A := h for dot notation.

Why is this useful? Why don't we just use unfold or simp or etc?

Eric Wieser (Aug 03 2021 at 17:02):

Because then you can do rw [h.eq]

Eric Wieser (Aug 03 2021 at 17:03):

see docs#commute.eq which is the same idea

Alex Zhang (Aug 03 2021 at 17:04):

OK. I see the point.


Last updated: Dec 20 2023 at 11:08 UTC