fix(library/unifier): bug in occurs_check, the dependency may be eliminated by reducing term

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-08-21 17:56:18 -07:00
parent 3498d7ad61
commit 6cf73b51e2
2 changed files with 29 additions and 1 deletions

View file

@ -662,7 +662,18 @@ struct unifier_fn {
if (!m || is_meta(rhs)) if (!m || is_meta(rhs))
return Continue; return Continue;
expr bad_local; expr bad_local;
switch (occurs_context_check(m_subst, rhs, *m, locals, bad_local)) { auto status = occurs_context_check(m_subst, rhs, *m, locals, bad_local);
if (status == occurs_check_status::FailLocal || status == occurs_check_status::FailCircular) {
// Try to normalize rhs
// TODO(Leo): use a custom normalizer that uses reduction to solve just the failure.
// TODO(Leo): this code is using only whnf, we may fail to eliminate the failure.
// Example: ?M := f (pr1 (pair 0 ?M))
constraint_seq cs;
expr rhs_whnf = whnf(rhs, relax, cs);
if (rhs != rhs_whnf && process_constraints(cs))
return process_metavar_eq(lhs, rhs_whnf, j, relax);
}
switch (status) {
case occurs_check_status::FailLocal: case occurs_check_status::FailLocal:
set_conflict(mk_invalid_local_ctx_justification(lhs, rhs, j, bad_local)); set_conflict(mk_invalid_local_ctx_justification(lhs, rhs, j, bad_local));
return Failed; return Failed;

View file

@ -0,0 +1,17 @@
import logic data.nat data.prod
using nat prod
using decidable
variable modulo (x : ) (y : ) :
infixl `mod`:70 := modulo
variable gcd_aux : ×
definition gcd (x y : ) : := gcd_aux (pair x y)
theorem gcd_def (x y : ) : gcd x y = @ite (y = 0) (decidable_eq (pr2 (pair x y)) 0) nat x (gcd y (x mod y)) :=
sorry
theorem gcd_succ (m n : ) : gcd m (succ n) = gcd (succ n) (m mod succ n) :=
trans (gcd_def _ _) (if_neg (succ_ne_zero n) _ _)