Zulip Chat Archive

Stream: new members

Topic: ring not respecting arbitrary


Yakov Pechersky (Mar 02 2021 at 18:54):

Is it expected that ring will think that separate arbitrary _ values are equal?

import tactic.ring

example :  (a b c : ), 2 * a + (b + 2 * c) = 0 :=
begin
  let a :  := arbitrary _,
  let b :  := arbitrary _,
  let c :  := arbitrary _,
  use [a, b, c],
  ring, -- 5 * a = 0
  sorry
end

Eric Wieser (Mar 02 2021 at 18:57):

is src#arbitrary irreducible? Edit: yes

Eric Wieser (Mar 02 2021 at 18:59):

I think by definition any terms constructed with the same function application must be equal to each other

Yakov Pechersky (Mar 02 2021 at 18:59):

Then I am not sure what arbitrary is supposed to do.

Eric Wieser (Mar 02 2021 at 18:59):

Well, it prevented you from replacing a with zero at least

Kevin Buzzard (Mar 02 2021 at 19:08):

Right --here a=b right? This is nothing to do with ring

Eric Wieser (Mar 02 2021 at 19:09):

Yes

Eric Wieser (Mar 02 2021 at 19:09):

I guess you could make a tactic that emits new definitions each time you invoke it?

Eric Wieser (Mar 02 2021 at 19:09):

And then you'd have things that are still defeq under the irreducible veil, but are no longer syntactically equal to each other

Eric Wieser (Mar 02 2021 at 19:11):

Or even:

@[irreducible] def arbitrary' (n : name) (α : Type*) [inhabited α] : α := default α

example :  (a b c : ), 2 * a + (b + 2 * c) = 0 :=
begin
  let a :  := arbitrary' `a _,
  let b :  := arbitrary' `b _,
  let c :  := arbitrary' `c _,
  use [a, b, c],
  ring, -- 2 * a + (b + 2 * c) = 0
  sorry
end

Yakov Pechersky (Mar 02 2021 at 19:13):

import tactic.ring

example : true :=
begin
  let a :  := sorry,
  let b :  := sorry,
  suffices : a = b, by trivial,
  refl
end

example : true :=
begin
  let a :  := sorry,
  let b :  := arbitrary _,
  suffices : a = b, by trivial,
  refl -- this fails
end

Kevin Buzzard (Mar 02 2021 at 20:39):

That'll teach you to sorry data

Yakov Pechersky (Mar 02 2021 at 20:51):

Then you'll be even more horrified at this:

@[irreducible] def arbitrary' (n : name) (α : Type*) [inhabited α] : α := default α

-- 1.1.17
-- (a) Find infinitely many matrices `B` such that `BA = I₂` when
-- `A = ![![2, 3], ![1, 2], ![2, 5]]`
-- (b) Prove that there is no matrix `C` such that `AC =  I₃`
example (A : matrix (fin 3) (fin 2) ) (hA : A = ![![2, 3], ![1, 2], ![2, 5]]) :
  ( (B : matrix (fin 2) (fin 3) ) , B.mul A = 1) 
   (C : matrix (fin 2) (fin 3) ), A.mul C  1 :=
begin
  split,
  { let c :  := arbitrary' `c _,
    set b :  := - 4 * c - 3 with hb,
    set a :  := - (2 * b + 5 * c) / 3 with ha,
    let d :  := arbitrary' `d _,
    set f :  := d + 1 with hf,
    set e :  := - 2 * (d + f) with he,
    set B : matrix (fin 2) (fin 3)  := ![![a, b, c], ![d, e, f]] with hB,
    use B,
    rw [hA],
    ext i j,
    fin_cases i;
    fin_cases j;
    simp [ha, hb, he, hf];
    ring },
  { sorry }
end

Eric Wieser (Mar 02 2021 at 21:00):

What's the punchline, for those of us on mobile?

Yakov Pechersky (Mar 02 2021 at 21:01):

That I'm doing symbolic calculations on explicit matrices using mathlib

Eric Wieser (Mar 02 2021 at 21:45):

Are you trying to use arbitrary' as a crutch for "infinitely many"?

Eric Wieser (Mar 02 2021 at 21:50):

I guess the statement would be something like ∃ (s : set $ matrix (fin 2) (fin 3) ℚ) (hs : s.infinite), ∀ B ∈ s, B.mul A = 1)

Eric Wieser (Mar 02 2021 at 21:50):

And then you use set.range f where f is a function from prod ℚ ℚ to a matrix

Eric Wieser (Mar 02 2021 at 22:10):

For your example though, I don't think you need arbirary' `name at all - using have c : ℚ := arbitrary _, instead of let does the job

Damiano Testa (Mar 03 2021 at 03:25):

You could also introduce variables in the statement and prove the following:

def B (R : Type*) [ring R] : R  matrix (fin 2) (fin 3) R :=
  λ d, ![![1, 1, -1], ![d, - 4 * d - 2, d + 1]]

lemma Binj (R : Type*) [ring R] : function.injective (B R) :=
  λ a b ab, (matrix.ext_iff.mpr ab) 1 0

-- 1.1.17
-- (a) Find infinitely many matrices `B` such that `BA = I₂` when
-- `A = ![![2, 3], ![1, 2], ![2, 5]]`
-- (b) Prove that there is no matrix `C` such that `AC =  I₃`
example (d : ) (A : matrix (fin 3) (fin 2) ) (hA : A = ![![2, 3], ![1, 2], ![2, 5]]) :
  (B  d).mul A = 1   (C : matrix (fin 2) (fin 3) ), A.mul C  1 :=
begin
  split,
  { ext i j,
    fin_cases i;
    fin_cases j;
    simp [hA, B];
    ring },
  { sorry }
end

at this point, all that you are missing is that is infinite.

Eric Wieser (Mar 03 2021 at 06:53):

Should docs#infinite have more instances?

Eric Wieser (Mar 03 2021 at 06:54):

For instance, instances for prod, sum, sigma, and pi would all be good starts

Mario Carneiro (Mar 03 2021 at 07:02):

It seems like there will be a lot of proof search in those instances

Eric Wieser (Mar 03 2021 at 07:11):

Is it morally any different to instance searches for fintype?

Mario Carneiro (Mar 03 2021 at 07:22):

Yes, because fintype is a conjunctive property in most cases, which means that you can prove or disprove in linear time wrt the type expression

Eric Wieser (Mar 03 2021 at 07:24):

Ah right, we end up with a similar problem to docs#pi.nontrivial

Eric Wieser (Mar 03 2021 at 07:25):

Although we could probably solve it in the same way?

Damiano Testa (Mar 03 2021 at 07:36):

In this specific case, you could either use the natural numbers, instead of \Q, in the matrix B, or use char_zero, right?

Yakov Pechersky (Mar 03 2021 at 14:01):

Probably, but I didn't want to deal with nat division

Damiano Testa (Mar 03 2021 at 14:07):

Ah, actually, I meant to say that replacing \Q by ℤ worked:

example (d : ) (A : matrix (fin 3) (fin 2) ) (hA : A = ![![2, 3], ![1, 2], ![2, 5]]) :
  (B  d).mul A = 1 :=
begin
  ext i j,
  fin_cases i;
  fin_cases j;
  simp [hA, B];
  ring,
end

Last updated: Dec 20 2023 at 11:08 UTC