如何在Coq.Reals.Raxioms定义的实数上使用Ssreflect引理?
Great question! Let's walk through your needs and the solutions available:
Do you need to prove all structures from eqType up to ClosedReals?
Yes, you do. The ssralg.GRing.Ring operations (and the Num.real_closed_axiom) rely on a layered hierarchy of algebraic structures defined in MathComp:
- Start with
eqType(for foundational equality reasoning) - Then
choiceType(to support choice principles required for some algebraic constructions) - Followed by
zmoduleType,ringType,fieldType - Finally,
realClosedFieldType(to meet the requirements ofreal_closed_axiom)
Coq's standard library real numbers (Rdefinitions.R) don't come with these MathComp-style structure instances out of the box, so you either need to implement them yourself or use existing, battle-tested implementations.
Are there ready-made implementations?
Absolutely! The mathcomp-analysis library (a companion to MathComp for formal analysis) provides full bridge instances between Coq's standard R and MathComp's algebraic hierarchy.
Once you import the right modules, you can directly use ssralg's add, mul, and other ring operations on R, and leverage Num.real_closed_axiom without writing any manual proofs. Here's a quick example:
From mathcomp Require Import all_ssreflect all_algebra. From mathcomp.analysis Require Import realstruct. (* Use ssralg operations on standard reals directly *) Lemma add_comm (x y : R) : add x y = add y x. Proof. by apply addC. Qed. (* Access real closed field properties via Num.real_closed_axiom *) Lemma real_closed_poly (P : {poly R}) : exists x : R, poly_eval P x = 0 \/ (forall x : R, poly_eval P x > 0) \/ (forall x : R, poly_eval P x < 0). Proof. by apply real_closed_axiom. Qed.
This library handles all the tedious instance proofs for you, from eqType all the way up to realClosedFieldType.
Are there alternative approaches?
If you don't want to depend on mathcomp-analysis, you could manually implement each structure instance, but this is extremely time-consuming and error-prone:
- Define the
eqTypeinstance forRusing Coq's built-in equality on reals. - Add a
choiceTypeinstance (using classical logic, since Coq's standardRis built on classical reasoning). - Prove the axioms for
zmoduleType,ringType, andfieldTypeby linking Coq's real operations (Rplus,Rmult, etc.) to MathComp'sadd,mul, etc. - Finally, prove the real closed field axioms to satisfy
real_closed_axiom.
This manual route is not recommended unless you have very specific constraints—reusing mathcomp-analysis is almost always the smarter choice.
A quick note: Make sure you're using compatible versions of Coq, MathComp, and mathcomp-analysis to avoid version mismatch issues.
内容的提问来源于stack exchange,提问作者larsr

