Zulip Chat Archive

Stream: Is there code for X?

Topic: concatenations of a pair of sets of lists


Paige Thomas (Jan 29 2024 at 06:41):

How would one go about defining this so that it type checks: def blah (α : Type) (R S : List α) := { r ++ s : List α | r ∈ R ∧ s ∈ S }? That is, the set of all concatenations of lists from two sets of lists, where the list that is first comes from the first set.

I get "invalid patterns, r is an explicit pattern variable, but it only occurs in positions that are inaccessible to pattern matching .(List.append r s)"

Ruben Van de Velde (Jan 29 2024 at 06:47):

First step would be to correct the types of R and S

Ruben Van de Velde (Jan 29 2024 at 06:48):

Then try (r ++ s) including the parentheses

Paige Thomas (Jan 29 2024 at 06:49):

def blah (α : Type) (R S : Set (List α)) := { (r ++ s) : List α | r ∈ R ∧ s ∈ S }
gives the same error.

Kyle Miller (Jan 29 2024 at 06:51):

def blah (α : Type) (R S : Set (List α)) := {r ++ s | (r  R) (s  S)}

Ruben Van de Velde (Jan 29 2024 at 06:51):

Thanks Kyle, I knew it was something with parentheses

Paige Thomas (Jan 29 2024 at 06:51):

huh, ok. I'm not sure what is going on there.

Paige Thomas (Jan 29 2024 at 06:52):

what does it mean without the ?

Paige Thomas (Jan 29 2024 at 06:54):

because this also fails def blah (α : Type) (R S : Set (List α)) := {(r ++ s) : List α | (r ∈ R) ∧ (s ∈ S)}.

Ruben Van de Velde (Jan 29 2024 at 06:58):

It's like \forall (r ∈ R) (s ∈ S), ...

Paige Thomas (Jan 29 2024 at 07:00):

I see. And it looks like the issue was that I put parentheses around the r ++ s, which I was doing in order to give the type to satisfy the type inference.

Paige Thomas (Jan 29 2024 at 07:00):

among other things

Paige Thomas (Jan 29 2024 at 07:00):

Thank you!

Paige Thomas (Jan 30 2024 at 03:46):

Is there a way to define the same thing but using Finset?

Paige Thomas (Jan 30 2024 at 04:20):

I'm trying to check that these definitions are what I want, but I can't #eval a Set.

def blah
  {α : Type}
  (R S : Set (List α)) :
  Set (List α) :=
  { r ++ s | (r  R) (s  S) }


def blah_n
  {α : Type}
  (R : Set (List α)) :
    Set (List α)
  | Nat.zero => R
  | Nat.succ n => blah R (blah_n R n)

#eval blah_n {[('a' : Char)]} 2

Paige Thomas (Jan 30 2024 at 04:24):

And this is because I am trying to define a more concrete instance of docs#RegularExpression and I'm having trouble defining the language of the closure operator (Kleene star).

Paige Thomas (Jan 30 2024 at 04:24):

inductive RegExp (α : Type) : Type
  | char : α  RegExp α
  | epsilon : RegExp α
  | zero : RegExp α
  | union : RegExp α  RegExp α  RegExp α
  | concat : RegExp α  RegExp α  RegExp α
  | closure : RegExp α  RegExp α


def RegExp.languageOf (α : Type) : RegExp α  Set (List α)
  | char x => { [x] }
  | epsilon => { [] }
  | zero => 
  | union R S => R.languageOf  S.languageOf
  | concat R S => { r ++ s | (r  R.languageOf) (s  S.languageOf) }
  | closure R => sorry

Paige Thomas (Jan 30 2024 at 04:25):

(unfolding the XY problem)


Last updated: May 02 2025 at 03:31 UTC