Zulip Chat Archive

Stream: Is there code for X?

Topic: Ico_union_right


Gareth Ma (Nov 02 2023 at 05:26):

Does this code really not exist? Ico is Finset here.

import Mathlib
open Finset
example {a b : } (h : a  b) : Ico a b.succ = Ico a b  {b} := by
  sorry

Gareth Ma (Nov 02 2023 at 05:27):

There is List.Ico.succ_top for the list version

Gareth Ma (Nov 02 2023 at 05:27):

(By the way, how do I use that docs4#List.Ico.succ_top thing?)

Gareth Ma (Nov 02 2023 at 05:27):

... Like that

Gareth Ma (Nov 02 2023 at 05:35):

import Mathlib

open Nat Finset

set_option profiler true
set_option trace.profiler true

example {a b : } (h : a  b) : Ico a b.succ = Ico a b  {b} := by
  ext t
  rw [mem_Ico, mem_union, mem_Ico]
  constructor
  · intro h1, h2
    by_cases h : t = b
    · rw [h, mem_singleton]
      right
      rfl
    · push_neg at h
      rw [lt_succ] at h2
      have := lt_of_le_of_ne h2 h
      left
      constructor <;> linarith
  · intro h
    cases' h with h h
    · let h1, h2 := h
      constructor <;> linarith
    · rw [mem_singleton] at h
      constructor <;> linarith

It's true btw, just put together a terrible proof with some tactic abuse

Gareth Ma (Nov 02 2023 at 05:35):

If someone has a couple minutes, feel free to golf it and pr :(

Gareth Ma (Nov 02 2023 at 05:50):

I golfed it a little :P

example {a b : } (ha : a  b) : Ico a b.succ = Ico a b  {b} := by
  ext t
  rw [mem_Ico, mem_union, mem_Ico, lt_succ_iff_lt_or_eq, mem_singleton]
  constructor
  · exact fun h1, h2  match h2 with
    | .inl h => .inl h1, h
    | .inr h => .inr h
  · exact fun h  match h with
    | .inl h1, h2 => h1, .inl h2
    | .inr h' => h'.symm  ha, .inr h'

Gareth Ma (Nov 02 2023 at 05:50):

(Why does it look completely different :joy: )

Ruben Van de Velde (Nov 02 2023 at 06:29):

How about this?

import Mathlib
open Finset
example {a b : } (h : a  b) : Ico a b.succ = Ico a b  {b} := by
  rw [Nat.succ_eq_add_one]
  rw [Nat.Ico_succ_right]
  rw [ Ico_insert_right h]
  rw [@insert_eq]
  rw [@union_comm]

Gareth Ma (Nov 02 2023 at 06:30):

Ahh thanks a lot. Your first rw is not needed :)

Ruben Van de Velde (Nov 02 2023 at 06:35):

Yeah, rw_search finds Try this: rw [Nat.Ico_succ_right, @union_comm, ← Ico_insert_right h]

Yaël Dillies (Nov 02 2023 at 06:42):

docs#Nat.Ico_succ_right_eq_insert_Ico

Gareth Ma (Nov 02 2023 at 06:44):

lemma Finset.Ico_union_right {a b : } (h : a  b) : Ico a b  {b} = Ico a b.succ := by
  rw [Ico_succ_right_eq_insert_Ico h, union_comm] ; rfl

yay

Yaël Dillies (Nov 02 2023 at 06:47):

You should use docs#Finset.insert_eq (or not use ∪ {b} in the first place, really).

Gareth Ma (Nov 02 2023 at 06:51):

I see, I will change my code for that


Last updated: Dec 20 2023 at 11:08 UTC