Zulip Chat Archive

Stream: general

Topic: sym notation


Yaël Dillies (Sep 20 2021 at 17:37):

Is there a better notation to build concrete elements in sym?

import data.sym.basic

example (α : Type*) (a b c : α) :
  sym α 3 :=
a :: b :: c :: sym.nil

Eric Wieser (Sep 20 2021 at 17:37):

(docs#sym)

Yaël Dillies (Sep 20 2021 at 17:38):

Eric, the documentation bot :rofl:

Kyle Miller (Sep 20 2021 at 17:39):

No one's ever really wanted to before :smile:. I'd suggest using :: like that, though if you want there's also

example (α : Type*) (a b c : α) : sym α 3 := ⟨[a, b, c], rfl

Yaël Dillies (Sep 20 2021 at 17:40):

Why is [, , ] notation not implemented for has_insert and has_nil?

Yaël Dillies (Sep 20 2021 at 17:40):

Oh wait, there's no has_nil!

Kyle Miller (Sep 20 2021 at 17:41):

I didn't check -- I'm pretty sure it's using the coercion from list there.

Eric Wieser (Sep 20 2021 at 17:43):

sym has no docs#has_insert anyway (nor can it, the types aren't right)

Yaël Dillies (Sep 20 2021 at 17:44):

Well, has_insert could well be heterogenous if we wanted to.

Yakov Pechersky (Sep 20 2021 at 18:01):

There's docs#has_emptyc

Chris Hughes (Sep 20 2021 at 19:03):

Can you use set notation {a, b, c} ?

Eric Wieser (Sep 20 2021 at 19:57):

No, that requires has_insert which can't apply here

Eric Wieser (Sep 20 2021 at 19:58):

@Yaël Dillies, you might have to fiddle with out_param to avoid confusing the elaborator

Yaël Dillies (Sep 20 2021 at 19:58):

Chris Hughes said:

Can you use set notation {a, b, c} ?

Didn't have much success doing so...

Yaël Dillies (Sep 20 2021 at 19:59):

Oh yeah, I'm not yet friend with the elaborator.

Yury G. Kudryashov (Sep 23 2021 at 02:00):

Why has_insert can't apply here? We can define it to mean cons.

Eric Wieser (Sep 23 2021 at 05:15):

Because it has signature insert : A → B → B which doesn't unify with cons.

Yakov Pechersky (Sep 23 2021 at 07:22):

import data.sym.basic

variable {α : Type*}

instance {n : } : has_coe_t (sym α n) (multiset α) :=
subtype.val

@[simp] lemma sym.coe_nil : ((sym.nil : sym α 0) : multiset α) = {} := rfl

@[simp] lemma sym.coe_cons {n : } (a : α) (s : sym α n) :
  ((sym.cons a s) : multiset α) = a :: (s : multiset α) :=
begin
  cases s,
  refl
end

instance [decidable_eq α] {n : } : decidable_eq (sym α n) := λ x y,
if h : (x : multiset α) = y
  then is_true (subtype.ext h)
  else is_false (λ H, h (congr_arg _ H))

notation `s[` l:(foldr `, ` (h t, sym.cons h t) sym.nil `]`) := l

-- for some reason, wouldn't work with subtype.decidable
example : s[1, 2, 3] = s[2, 1, 3] := dec_trivial

Last updated: Dec 20 2023 at 11:08 UTC