2015-07-22 17:39:30 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "kernel/type_checker.h"
|
|
|
|
#include "library/head_map.h"
|
2015-07-27 19:57:28 +00:00
|
|
|
#include "library/io_state_stream.h"
|
2015-07-22 17:39:30 +00:00
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
class simp_rule_sets;
|
|
|
|
|
2015-07-23 22:56:45 +00:00
|
|
|
class simp_rule_core {
|
|
|
|
protected:
|
2015-07-22 17:39:30 +00:00
|
|
|
name m_id;
|
|
|
|
levels m_univ_metas;
|
|
|
|
list<expr> m_metas;
|
|
|
|
expr m_lhs;
|
|
|
|
expr m_rhs;
|
|
|
|
expr m_proof;
|
2015-07-23 22:56:45 +00:00
|
|
|
simp_rule_core(name const & id, levels const & univ_metas, list<expr> const & metas,
|
|
|
|
expr const & lhs, expr const & rhs, expr const & proof);
|
2015-07-22 17:39:30 +00:00
|
|
|
public:
|
|
|
|
name const & get_id() const { return m_id; }
|
|
|
|
levels const & get_univ_metas() const { return m_univ_metas; }
|
|
|
|
list<expr> const & get_metas() const { return m_metas; }
|
|
|
|
expr const & get_lhs() const { return m_lhs; }
|
|
|
|
expr const & get_rhs() const { return m_rhs; }
|
|
|
|
expr const & get_proof() const { return m_proof; }
|
2015-07-23 22:56:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class simp_rule : public simp_rule_core {
|
|
|
|
bool m_is_permutation;
|
|
|
|
simp_rule(name const & id, levels const & univ_metas, list<expr> const & metas,
|
|
|
|
expr const & lhs, expr const & rhs, expr const & proof, bool is_perm);
|
|
|
|
friend simp_rule_sets add_core(type_checker & tc, simp_rule_sets const & s, name const & id,
|
|
|
|
levels const & univ_metas, expr const & e, expr const & h);
|
|
|
|
public:
|
2015-07-22 17:39:30 +00:00
|
|
|
friend bool operator==(simp_rule const & r1, simp_rule const & r2);
|
2015-07-23 22:56:45 +00:00
|
|
|
bool is_perm() const { return m_is_permutation; }
|
2015-07-22 17:39:30 +00:00
|
|
|
format pp(formatter const & fmt) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool operator==(simp_rule const & r1, simp_rule const & r2);
|
|
|
|
inline bool operator!=(simp_rule const & r1, simp_rule const & r2) { return !operator==(r1, r2); }
|
|
|
|
|
2015-07-23 22:56:45 +00:00
|
|
|
class congr_rule : public simp_rule_core {
|
|
|
|
list<expr> m_congr_hyps;
|
|
|
|
congr_rule(name const & id, levels const & univ_metas, list<expr> const & metas,
|
|
|
|
expr const & lhs, expr const & rhs, expr const & proof, list<expr> const & congr_hyps);
|
|
|
|
friend void add_congr_core(environment const & env, simp_rule_sets & s, name const & n);
|
|
|
|
public:
|
|
|
|
friend bool operator==(congr_rule const & r1, congr_rule const & r2);
|
|
|
|
list<expr> const & get_congr_hyps() const { return m_congr_hyps; }
|
|
|
|
format pp(formatter const & fmt) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool operator==(congr_rule const & r1, congr_rule const & r2);
|
|
|
|
inline bool operator!=(congr_rule const & r1, congr_rule const & r2) { return !operator==(r1, r2); }
|
|
|
|
|
2015-07-22 17:39:30 +00:00
|
|
|
class simp_rule_set {
|
2015-07-23 22:56:45 +00:00
|
|
|
typedef head_map<simp_rule> simp_set;
|
|
|
|
typedef head_map<congr_rule> congr_set;
|
|
|
|
name m_eqv;
|
|
|
|
simp_set m_simp_set;
|
|
|
|
congr_set m_congr_set;
|
2015-07-22 17:39:30 +00:00
|
|
|
public:
|
|
|
|
simp_rule_set() {}
|
|
|
|
/** \brief Return the equivalence relation associated with this set */
|
|
|
|
simp_rule_set(name const & eqv);
|
2015-07-23 22:56:45 +00:00
|
|
|
bool empty() const { return m_simp_set.empty() && m_congr_set.empty(); }
|
2015-07-22 17:39:30 +00:00
|
|
|
name const & get_eqv() const { return m_eqv; }
|
|
|
|
void insert(simp_rule const & r);
|
|
|
|
void erase(simp_rule const & r);
|
2015-07-23 22:56:45 +00:00
|
|
|
void insert(congr_rule const & r);
|
|
|
|
void erase(congr_rule const & r);
|
2015-07-27 19:57:28 +00:00
|
|
|
void erase_simp(name_set const & ids);
|
|
|
|
void erase_simp(buffer<name> const & ids);
|
2015-07-23 22:56:45 +00:00
|
|
|
list<simp_rule> const * find_simp(head_index const & h) const;
|
|
|
|
void for_each_simp(std::function<void(simp_rule const &)> const & fn) const;
|
|
|
|
list<congr_rule> const * find_congr(head_index const & h) const;
|
|
|
|
void for_each_congr(std::function<void(congr_rule const &)> const & fn) const;
|
2015-07-22 17:39:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class simp_rule_sets {
|
|
|
|
name_map<simp_rule_set> m_sets; // mapping from relation name to simp_rule_set
|
2015-07-23 22:56:45 +00:00
|
|
|
template<typename R> void insert_core(name const & eqv, R const & r);
|
|
|
|
template<typename R> void erase_core(name const & eqv, R const & r);
|
2015-07-22 17:39:30 +00:00
|
|
|
public:
|
|
|
|
void insert(name const & eqv, simp_rule const & r);
|
|
|
|
void erase(name const & eqv, simp_rule const & r);
|
2015-07-23 22:56:45 +00:00
|
|
|
void insert(name const & eqv, congr_rule const & r);
|
|
|
|
void erase(name const & eqv, congr_rule const & r);
|
2015-07-27 19:57:28 +00:00
|
|
|
void erase_simp(name_set const & ids);
|
|
|
|
void erase_simp(buffer<name> const & ids);
|
2015-07-22 17:39:30 +00:00
|
|
|
void get_relations(buffer<name> & rs) const;
|
|
|
|
simp_rule_set const * find(name const & eqv) const;
|
2015-07-23 22:56:45 +00:00
|
|
|
list<simp_rule> const * find_simp(name const & eqv, head_index const & h) const;
|
|
|
|
list<congr_rule> const * find_congr(name const & eqv, head_index const & h) const;
|
|
|
|
void for_each_simp(std::function<void(name const &, simp_rule const &)> const & fn) const;
|
|
|
|
void for_each_congr(std::function<void(name const &, congr_rule const &)> const & fn) const;
|
2015-07-27 19:57:28 +00:00
|
|
|
format pp(formatter const & fmt, format const & header, bool simp, bool congr) const;
|
|
|
|
format pp_simp(formatter const & fmt, format const & header) const;
|
|
|
|
format pp_simp(formatter const & fmt) const;
|
|
|
|
format pp_congr(formatter const & fmt) const;
|
|
|
|
format pp(formatter const & fmt) const;
|
2015-07-22 17:39:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
simp_rule_sets add(type_checker & tc, simp_rule_sets const & s, name const & id, expr const & e, expr const & h);
|
|
|
|
simp_rule_sets join(simp_rule_sets const & s1, simp_rule_sets const & s2);
|
|
|
|
|
|
|
|
environment add_simp_rule(environment const & env, name const & n, bool persistent = true);
|
2015-07-23 00:21:47 +00:00
|
|
|
environment add_congr_rule(environment const & env, name const & n, bool persistent = true);
|
|
|
|
|
2015-07-23 22:56:45 +00:00
|
|
|
/** \brief Return true if \c n is an active simplification rule in \c env */
|
2015-07-22 17:39:30 +00:00
|
|
|
bool is_simp_rule(environment const & env, name const & n);
|
2015-07-24 01:49:50 +00:00
|
|
|
/** \brief Return true if \c n is an active congruence rule in \c env */
|
|
|
|
bool is_congr_rule(environment const & env, name const & n);
|
2015-07-23 22:56:45 +00:00
|
|
|
/** \brief Get current simplification rule sets */
|
2015-07-22 17:39:30 +00:00
|
|
|
simp_rule_sets get_simp_rule_sets(environment const & env);
|
2015-07-23 22:56:45 +00:00
|
|
|
/** \brief Get simplification rule sets in the given namespace. */
|
2015-07-23 01:47:56 +00:00
|
|
|
simp_rule_sets get_simp_rule_sets(environment const & env, name const & ns);
|
2015-07-27 19:57:28 +00:00
|
|
|
|
|
|
|
io_state_stream const & operator<<(io_state_stream const & out, simp_rule_sets const & s);
|
|
|
|
|
2015-07-22 17:39:30 +00:00
|
|
|
void initialize_simp_rule_set();
|
|
|
|
void finalize_simp_rule_set();
|
|
|
|
}
|