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

Cannot pattern match on exist in program definitions #24

Open
Tuplanolla opened this issue Apr 23, 2021 · 0 comments
Open

Cannot pattern match on exist in program definitions #24

Tuplanolla opened this issue Apr 23, 2021 · 0 comments

Comments

@Tuplanolla
Copy link

Tuplanolla commented Apr 23, 2021

Version

Coq 8.13.2

Operating system

Red Hat Enterprise Linux Workstation 7.4

Description of the problem

It is not possible to pattern match on terms
belonging to the sig type family in the following Program Definitions,
because the witnesses seem to get projected out by some hidden coercion.
However, changing sig into sigT or Ssig will allow
implementing the inspect pattern just fine.

From Coq Require Import Lia Logic.StrictProp NArith.NArith.

Obligation Tactic := idtac.

Section Context.

Import N.

Local Open Scope N_scope.

Context (f : N -> N) (mono : forall (a b : N) (l : a < b), f a < f b).

Print Coercions.

Fail Program Definition f_inspect (n : N) : positive :=
  let m := f (succ n) - f n in
  match exist _ m (eq_refl m) with
  | exist _ N0 e => _
  | exist _ (Npos p) e => p
  end.

Fail Program Definition f_inspect (n : N) : positive :=
  let m := f (succ n) - f n in
  match exist _ m (eq_refl m) in sig _ return positive with
  | exist _ N0 e => _
  | exist _ (Npos p) e => p
  end.

Program Definition f_inspect (n : N) : positive :=
  let m := f (succ n) - f n in
  match existT _ m (eq_refl m) in sigT _ return positive with
  | existT _ N0 e => _
  | existT _ (Npos p) e => p
  end.
Next Obligation. intros n m _ _ e. pose proof mono n (succ n) as l. lia. Qed.

Program Definition f_inspect' (n : N) : positive :=
  let m := f (succ n) - f n in
  match Sexists (fun n : N => Squash (m = n)) m (squash (eq_refl m)) in
  Ssig _ return positive with
  | Sexists _ N0 e => _
  | Sexists _ (Npos p) e => p
  end.
Next Obligation.
  intros n m _ _ e'.
  exfalso. apply sEmpty_ind. induction e' as [e].
  pose proof mono n (succ n) as l. lia. Qed.

End Context.
The command has indeed failed with message:
Found a constructor of inductive type sig while a constructor of N is expected.
The command has indeed failed with message:
Wrong inductive type.

Notes

This may be related to coq/coq#4341 or coq/coq#10877.

@proux01 proux01 transferred this issue from coq/coq Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant