Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set tactic gives wrong type to variable #3111

Closed
Vierkantor opened this issue Jun 18, 2020 · 4 comments
Closed

set tactic gives wrong type to variable #3111

Vierkantor opened this issue Jun 18, 2020 · 4 comments
Labels
bug t-meta Tactics, attributes or user commands

Comments

@Vierkantor
Copy link
Collaborator

Noticed in this Zulip thread. The following code attempts to define 6 matrices:

import data.matrix.notation

example : true :=
let X1 := (![![1, 0], ![0, 0]] : matrix (fin 2) (fin 2) ℕ), -- X1 : fin 1.succ → fin 2 → ℕ
    X2 : matrix (fin 2) (fin 2) ℕ := ![![1, 0], ![0, 0]] in -- X2 : matrix (fin 2) (fin 2) ℕ
begin
  set Y1 := (![![1, 0], ![0, 0]] : matrix (fin 2) (fin 2) ℕ), -- Y1 : fin 1.succ → fin 2 → ℕ
  set Y2 : matrix (fin 2) (fin 2) ℕ := ![![1, 0], ![0, 0]], -- Y2 : fin 1.succ → fin 2 → ℕ
  let Z1 := (![![1, 0], ![0, 0]] : matrix (fin 2) (fin 2) ℕ), -- Z1 : fin 1.succ → fin 2 → ℕ
  let Z2 : matrix (fin 2) (fin 2) ℕ := ![![1, 0], ![0, 0]], -- Z2 : matrix (fin 2) (fin 2) ℕ

  trivial
end

I'd expect that all the variables above would have type matrix (fin 2) (fin 2) ℕ, or at least that X2, Y2 and Z2 would. Instead, Y2 has type fin 1.succ → fin 2 → ℕ. This is not just confusing to the user, but also resulted in the wrong has_mul.mul instance being inferred.

@Vierkantor Vierkantor added bug t-meta Tactics, attributes or user commands labels Jun 18, 2020
@gebner
Copy link
Member

gebner commented Jun 19, 2020

Why would you expect Lean to infer matrix _ _ _ as the type here? The notation ![] expands to vec_empty, which literally has the type fin 0 → α. There's no matrix mentioned anywhere. How could Lean know that we want matrix here?

@Vierkantor
Copy link
Collaborator Author

Because we explicitly give the type : matrix (fin 2) (fin 2) ℕ?

@gebner
Copy link
Member

gebner commented Jun 19, 2020

Because we explicitly give the type : matrix (fin 2) (fin 2) ℕ?

Ah, I completely missed that part. This is definitely a bug in set then.

But I wonder if the matrix notation should have matrix type. Also (![] : matrix 0 0 ℕ) * (![] : matrix 0 0 ℕ) doesn't work (for a similar reason).

@Vierkantor
Copy link
Collaborator Author

That's true! (if you write matrix (fin 0) (fin 0) ℕ)

I think the notation should stay the same, since the type fin n -> α also represents vectors. Perhaps turning matrix from a semireducible definition into something more opaque (a structure?) and inserting explicit coercions will be a good workaround for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug t-meta Tactics, attributes or user commands
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants