Boris Djalal
email: boris.djalal@gmail.com

A Constructive Formalisation of Semi-Algebraic Sets and Functions

Keywords: Formalisation of Mathematics, Semi-Algebraic Sets, Semi-Algebraic Functions, Coq, Quantifier Elimination, Real Algebraic Geometry, Substitution

Semi-algebraic sets and semi-algebraic functions are essential to specify and certify cylindrical algebraic decomposition algorithms. We formally define in Coq the base operations on semi-algebraic sets and functions using embedded firstorder formulae over the language of real closed fields, and we prove the correctness of their geometrical interpretation. In doing so, we exploit a previous formalisation of quantifier elimination on such embedded formulae to guarantee the decidability of several first-order properties and keep our development constructive. We also exploit it to formalise formulae substitution without having to handle bound variables.

Introduction

First-order formulae over real closed fields, which can express a wide range of problems (polynomial optimisation, topologically reliable algebraic curve display, termination proof of term-rewriting systems) [START_REF] Caviness | Quantifier Elimination and Cylindrical Algebraic Decomposition[END_REF] are decidable. Quantifier elimination, that consists in finding a logically equivalent formula without quantifiers, is the keystone of the decision procedures for first-order formulae presented in the literature [START_REF] Caviness | Quantifier Elimination and Cylindrical Algebraic Decomposition[END_REF]. The first quantifier elimination algorithm [START_REF] Tarski | A decision method for elementary algebra and geometry[END_REF] has complexity a tower of exponents of height linear in the number of variables [START_REF] Basu | Algorithms in Real Algebraic Geometry[END_REF]. The cylindrical algebraic decomposition (abbreviated by CAD from now on) was invented by George E. Collins to eliminate quantifiers with a better complexity than Tarski's original algorithm [START_REF] Johnson | Quantifier Elimination and Cylindrical Algebraic Decomposition[END_REF][START_REF] Brown | QEPCAD B: a program for computing with semi-algebraic sets using CADs[END_REF]: the complexity reduces to a double exponential in the number of quantifiers. The expression "CAD" denotes two different notions: the algorithm and its output. In this paper, we call "CAD" a partition of the geometric space into semi-algebraic (abbreviated by S.A. from now on) sets, which satisfies some additional properties as explained in Sect. 4.1. We call "CAD algorithm" any algorithm that returns such a partition. Moreover, CAD algorithms help to answer questions about central objects in real algebraic geometry, S.A. sets. For example: how to compute sample points of a given nonempty S.A. set or the CPP'18, January 07-08, 2018, Los Angeles, LA, USA 2018. number of points of a S.A. set, decide whether a S.A. set is open, closed or bounded, determine the connected components of a S.A. set [START_REF] Basu | Algorithms in Real Algebraic Geometry[END_REF].

To work on the correctness proof of a given CAD algorithm, one firstly needs to tackle the two following problems: formalise what constitutes a CAD output, then formalise what constitutes a CAD algorithm.

In the present work, we formalise two key concepts required to formalise what constitutes the output of a CAD, S.A. sets and S.A. functions, while exploiting a previous quantifier elimination formalised by Cohen and Mahboubi [START_REF] Cohen | A Formal Quantifier Elimination for Algebraically Closed Fields[END_REF]. Defining S.A. sets and S.A. functions brings us to solve intermediary problems to represent such objects in Coq.

In Sect. 2, we introduce preliminary notions required by the CAD, by S.A. sets and by S.A. functions.

Firstly, in Sect. 2.1, we briefly clarify what is a first order formula on a real closed field. On top of first-order formulae, we define sets of free variables in Sect. 2.2. This enables us to build the type of formulae with free variables in {X 0 , • • • , X n-1 } in Sect. 2.4. We remind what is quantifier elimination and how we use the one from Mathematical Components [START_REF] Mahboubi | Mathematical Components[END_REF] in Sect. 2. [START_REF] Brown | QEPCAD B: a program for computing with semi-algebraic sets using CADs[END_REF].

In particular, we use it in Sect. 3 to define the logical equivalence relation on such formulae in a decidable way (to keep our development constructive).

We describe the construction of the type of S.A. sets in Sect. [START_REF] Caruso | The SARAG Library: Some Algorithms in Real Algebraic Geometry[END_REF]. Firstly, we define the CAD and explain why we need the S.A. set concept in Sect. 4.1. Secondly, we formalise S.A. sets in Sect. 4.2 through a quotient structure by combining results on formulae. We prove that two S.A. sets are equal if, and only if, they contain the same elements. We then equip S.A. sets with a lattice structure.

In Sect. 5, we describe our formalisation of S.A. functions, whose graphs are S.A. sets. This formalisation requires to express functionality and totality of S.A. graphs in a decidable way (to keep our development constructive). We achieve this by constructing tailor-made reified formulae expressing functionality and totality and by proving their correctness, similarly to the reification technique presented in [START_REF] Lescuyer | Formalizing and Implementing a Reflexive Tactic for Automated Deduction in Coq[END_REF][START_REF] Mahboubi | Implementing the Cylindrical Algebraic Decomposition Within the Coq System[END_REF][START_REF] Paulin-Mohring | Introduction to the Coq Proof-Assistant for Practical Software Verification[END_REF]. These constructions rely on the substitution in formulae. We do not define the substitution in the usual way, as in [START_REF] Harrison | Formalizing Basic First Order Model Theory[END_REF][START_REF] Harrison | Handbook of Practical Logic and Automated Reasoning[END_REF]. Instead, we simplify the definition and specification of the substitution in formulae by exploiting quantifier elimination, in Sect. 6.1.

Using the same methodology as for functionality and totality, we show how to formalise the composition of two S.A. functions in Sect. 7 and the continuity of a S.A. function in Sect. 8. The latter turns out to be more difficult and we provide an incomplete proof of correctness.

In the present paper, we present modified snippets of our code available at https://github.com/math-comp/cad.

Preliminary Notions

In this section, we briefly remind (2.1) what is quantifier elimination (2.3) in the Mathematical Components settings; we present our contributions about free variables (2.2) and formulae (2.4) (3).

First-Order Formulae over Real Closed Fields

In this paper, we use first-order formulae over real closed fields to formalise S.A. sets. We now clarify these two notions.

One definition is that a real closed field is an ordered field that has no ordered algebraic extension [START_REF] Cohen | Construction of real algebraic numbers in Coq[END_REF]. In particular, it is equipped with the arithmetic operations (addition, negation, multiplication and thus exponentiation with a natural number) and with comparison. For example, the real numbers and the real algebraic number are real closed fields. To keep the analogy with real numbers, we denote a real closed field by R. However, in all our work, we do no suppose that R is archimedean, whereas the real numbers is archimedean.

We use operations on R to define terms and first-order formulae. A term over R is a variable X i , i ∈ N or else a formal operation over terms. Formal arithmetic operations are: addition, multiplication, exponentiation, and negation. A formula over a field R is defined inductively as a formal comparison of two terms or else as a formal logical operation on formulae. A formal logical operation is either a formal logical connective (and, or, implication, negation) or a formal quantification of a formula over a variable -quantifying over an already bounded variable or missing variable is thus allowed. For example, ∃X 0 ∃X 0 X 0 = 0, ∃X 0 X 1 = 0 and ∃X

2 ∃X 3 (X 2 + X 3 -X 0 = 0)∧( 1 3 X 2 X 3 -X 1 )∧(X 2 < X 3 ) are valid for- mulae over R.
In our work, we exploit a previous formalisation of real closed fields and first-order formulae from Mathematical Components.

Free Variables

The free variables of a first-order formula are the variables that are not bound by a quantifier. They are the dimensions of R n that matter in the geometric interpretation of the formula, so they play a central role in S.A. sets over R n as described in Sect. 2.4. We compute the free variables recursively as follows: the free variables of the term X i is the set {X i }; the free variables of a quantification formula of the form Q X i ϕ, Q ∈ {∀, ∃}, are the free variables of the subformula ϕ minus X i . In all other cases, the free variables of a formula is the union of the free variables of its subformulae. For example, the free variables of ∃X

2 ∃X 3 (X 2 + X 3 -X 0 = 0)∧( 1 3 X 2 X 3 -X 1 )∧ (X 2 < X 3 ) is the set {X 0 }.
In Coq, finite sets can be represented by sequences without duplicates. With this representation, In our formalisation, we use the appropriate, higher level, notion of finite set from Mathematical Components instead of sequences. It allows us to work with the Coq equality (=) on finite sets, instead of the extensional equivalence (=i in Coq) on sequences of variables. Moreover, we automatically get a decidable equality on sets of variables, because the equality on natural numbers is decidable. We use this to keep our development constructive (but we do not run any decision procedure).

Semantics of First-Order Formulae and

Quantifier Elimination Terms and formulae are geometrically interpreted respectively as elements of R and Coq first-order formulae. The interpretation has already been defined by Cohen [START_REF] Cohen | A Formal Quantifier Elimination for Algebraically Closed Fields[END_REF] and corresponds to two functions eval and holds, which take an environment e to give values to free variables and respectively output an element of R and an element of Prop. An open formula with free variables in X 0 , • • • , X n-1 can be viewed as a predicate on R n , i.e. a subset of R n .

In this work we exploit the formalisation of a quantifier elimination procedure from a previous work by Cohen and Mahboubi [START_REF] Cohen | A Formal Quantifier Elimination for Algebraically Closed Fields[END_REF], which applies to formulae over a real closed field.

Firstly we use the existing decision procedure, rcf_sat, to decide whether a given first-order formula f is true in a given environment e. It is expressed b ythe expression rcf_sat e f (with type bool) in Coq where e assignes values to all free variables of f. When f is closed, this is written as rcf_sat [::] f. In particular, we use this decision procedure to define the decidable logical equivalence of two first-order formulae in Sect. [START_REF] Brown | QEPCAD B: a program for computing with semi-algebraic sets using CADs[END_REF].

Secondly, we use the quantifier elimination procedure in Sect. 6.1. A quantifier elimination procedure returns an equivalent quantifier-free formula. However, the existing quantifier elimination procedure, quantifier_elim, is not specified enough to guarantee that no free variable is introduced. Based on quantifier_elim, we define another one, qf_elim, which does not introduce new free variable, as follows. In Coq, we consider an input formula f and the quantifier-free equivalent g given by quantifier_elim. The formula g may introduce new free variables from the variables set formula_fv g `\`formula_fv f. The instantiation of these extra variables does not affect f. Thus, the instantiation of these extra variables in g returns a formula equivalent to g. We choose to instantiate these variables in g with 0. We define quantifier_elim in Coq. We formally prove that the resulting formula is equivalent to f, that it is quantifier-free, and the following statement that its free variables are among those of f: Lemma qf_elim_fv (f : formula R) : formula_fv (qf_elim f) <= formula_fv f.

where <= denotes the subset relation.

2.4

Formulae with less than n Free Variables S.A. sets of R n involve a finite number of variables among X 0 , • • • , X n-1 . Since we can find an equivalent formula without bound variables (Sect. 2.3), we consider formulae with free variables among X 0 , • • • , X n-1 , which we denote by

F n = {φ ∈ F | freevar(φ) ⊆ {X 0 , • • • , X n-1 }}.
In Coq, we denote R by R and n by n and we encode X 0 , • • • , X n-1 by the variables 'X_0, . . . ,'X_(n -1) and we define the decidable predicate freevar(φ)

⊆ {X 0 , • • • , X n-1 } by: Definition nvar (n : nat) := fun (f : formula R) => formula_fv f <= mnfset O n.
where mnfset O n is the set of natural numbers ranging from 0 to n -1. The set F n is then formalised by:

Record formulan := MkFormulan { underlying_f : formula R ; _ : nvar underlying_f }. Notation "'{formula_' n R }" := (formulan R n).
Formulae over R with less than n free variables inherit the choice type structure from F . Given any inhabitated predicate (inhabitated decidable property) over a choice type structure, one can choose a witness of that predicate. We choose the same witness for any logically equivalent property. See the Mathematical Components book [START_REF] Mahboubi | Mathematical Components[END_REF] for more information on choice types.

We automatically cast elements of F n to elements of F using the Coq implicit coercion mechanism:

Coercion underlying_f : formulan >-> formula.
The theorems which apply to F also apply to F n , by coercion. For example, the formula constructor And expects two elements of F , yet we can apply it to two elements f and g of F n and get the element f /\ g of F .

In our example, f /\ g still has n variables. We prove this in Coq:

Lemma and_formulan (f g : {formula_n R}) : nvar n (f /\ g)%oT.

where oT makes interpret the symbol /\ in the scope of formulae. This situation is similar to tuples in Mathematical Components. Tuples are sequences with a given length. When we concatenate two tuples, we obtain a sequence whose length is the sum of the lengths. In Mathematical Components, this piece of information is recovered automatically by declaring a canonical solution [START_REF] Mahboubi | Mathematical Components[END_REF].

In a similar way, we automatically recover the piece of information about f /\ g by declaring and_formulan as a canonical solution:

Canonical Structure formulan_and f g := MkFormulan (and_formulan f g).

Then, the system is able to build the proof of nvar underlying_f on the fly for any two specific values f and g, and lift f /\ g to F n . We implement similar solutions for other operations.

2.5 Decidable Equivalence Relation over Formulae with less than n Free Variables To define S.A. sets in (see Sect. 4), we need to define the logical equivalence relation over F n .

In all this Sect., we suppose that we have an equivalence relation equivf over F (see Sect. 3) such that its restriction to F n is the logical equivalence relation over F n . We show how to formalise this restriction in a more general settings.

Since we can use elements of F n in place for elements of F , we can see equivf as an equivalence relation on F n . In Coq, we define a new relation on {formula_n R} by restricting equivf to formulae with free variables in X 0 , • • • , X n-1 ; we then prove that this restriction is an equivalence relation.

Instead of directly proving that the subrelation induced by equivf on formula_n F is also an equivalence relation, we generalise this construction over the types formula and formula_n R: any equivalence relation on a type T induces an equivalence relation sub_r on any subtype of T (subtype structures are explained in the Mathematical Components book [START_REF] Mahboubi | Mathematical Components[END_REF]). We define sub_r in Coq by: Variables (T : eqType) (P : pred T) (sT : subType P) (r : equiv_rel T). Definition sub_r (x y : sT) := r (val x) (val y).

We bring down reflexivity (sub_r_refl), symmetry (sub_r_sym) and transitivity (sub_r_trans) of sub_r to the reflexivity, symmetry and transitivity of equiv_rel, respectively. This way, we formally prove these three properties for the subrelation sub_r. We make the equivalence structure of the subrelation a canonical structure, so that this structure is recovered automatically by the system: Canonical sub_r_equiv := EquivRel sub_r sub_r_refl sub_r_sym sub_r_trans.

Our generic canonical solution takes the proof that the broader relation is an equivalence relation and the desired subtype, then automatically builds the equivalence relation induced on the subtype. We apply this generic construction to define the logical equivalence sub_equivf on F n , in Coq:

Definition sub_equivf := @sub_r _ _ [subType of {formula_n R}] equivf_equiv.

First Reification case for the Equivalence Relation over Formulae

In this section, we define a logical equivalence relation on formulae, such that its restriction to F n (see Sect. 2.5) is a decidable equivalence. We show how to use reification to express this relation in a decidable way. Let ϕ and ψ denote two formulae. We consider the following relation: ϕ and ψ are equivalent if they evaluate to the same truth-value in all environments of size n (any free variable X i with n < i is assigned to the default value 0). In Coq, this can be expressed by the following property of type Prop: forall (e : n.-tuple F), holds e f <-> holds e g, where e is a sequence of size n (in other words e is a tuple of size n, denoted n.-tuple F). To write a decidable version of this property, we first need to express it through the specific formula type expected by rcf_sat (this is called reification), then evaluate its boolean truth-value with rcf_sat. We firstly remark that holds e f <-> holds e g is the definition of holds e (f <==> g) where <==> is the equivalence in the language of real closed fields. We are thus able to express the connector <-> on Prop in the language of real closed fields. (In our code, the constant <==> is not directly part of the language, but we define it in terms of ==> and /\.)

To complete the reification, we push quantification over e inward, so that quantification over e is replaced by n quantifications over variables. The latter quantifications are part of the targeted first-order language. A reified version of the property above thus has the form

∀X 0 • • • ∀X n-1 ϕ ⇐⇒ ψ , in Coq: nquantify O n Forall (f <==> g) Listing 1.
where the function nquantify i n Q prefixes any formula with the block quantification

Q X i • • • Q X i+n-1 from the in- dex i up to the index i + n -1 with
Q being one of the quantifiers ∀ or ∃. We illustrate the working of nquantify on the following example. The application of nquantify 3 2 Forall on the formula ∃X 5

(X 5 = X 3 ∨ X 5 = X 4 )∧X 3 ≤ X 5 ∧ X 4 ≤ X 5 outputs the formula ∀X 3 ∀X 4 ∃X 5 (X 5 = X 3 ∨ X 5 = X 4 )∧ X 3 ≤ X 5 ∧ X 4 ≤ X 5 .
The resulting formula is closed (we remark that it means that any numbers pair (X 3 , X 4 ) have a maximum X 5 ). This formula (Listing 1) is called a reified formula according to the reification techniques presented in other works [START_REF] Lescuyer | Formalizing and Implementing a Reflexive Tactic for Automated Deduction in Coq[END_REF][START_REF] Mahboubi | Implementing the Cylindrical Algebraic Decomposition Within the Coq System[END_REF][START_REF] Paulin-Mohring | Introduction to the Coq Proof-Assistant for Practical Software Verification[END_REF]. Since it is a first-order formula in the expected type, we can apply rcf_sat on it. We evaluate it in the empty environment (which assigns any free variable to the default assignment value 0). In Coq, a decidable version of our equivalence relation is expressed by:

Definition equivf (f g : formula R) := rcf_sat [::] (nquantify O n Forall (f <==> g)).
Our decidable version is used for the only sake of constructivity of our development, we do not use it to make computations; contrary to other works [START_REF] Lescuyer | Formalizing and Implementing a Reflexive Tactic for Automated Deduction in Coq[END_REF][START_REF] Mahboubi | Implementing the Cylindrical Algebraic Decomposition Within the Coq System[END_REF][START_REF] Paulin-Mohring | Introduction to the Coq Proof-Assistant for Practical Software Verification[END_REF], where the reification is used to compute decision procedures to replace proof steps with computations (reflection). The second point of comparison with these works [START_REF] Lescuyer | Formalizing and Implementing a Reflexive Tactic for Automated Deduction in Coq[END_REF][START_REF] Mahboubi | Implementing the Cylindrical Algebraic Decomposition Within the Coq System[END_REF][START_REF] Paulin-Mohring | Introduction to the Coq Proof-Assistant for Practical Software Verification[END_REF]] is that we do not need a tactic to automatically generate reified formulae.

We prove in Coq that equivf is reflexive, symmetric and transitive. We make the equivalence structure of equivf a canonical structure.

The certification of equivf is a consequence of the certifications of rcf_sat and nquantify. We certify the universal block quantification as follows. Evaluating the formula nquantify a k Forall f in an environment is not affected by the values associated by this environment to variables X i for a ≤ i; variables X i for a ≤ i < a+k are bound by the block quantification and variables X i or a + k ≤ i are evaluated to 0 by definition of our block quantification. Thus, we consider environments e whose size is exactly a. We formally prove:

Lemma nforallP (k : nat) (e : seq R) (f : formula R) : forall v : k.-tuple R, holds (e ++ v) f <-> holds e (nquantify (size e) k Forall f).
where ++ denotes the sequences concatenation. This lemma states that the evaluation of the universal block quantification over f in the environment e is true if, and only if, the evaluation of f is true in any environment e ++ v where v is a sequence of length k.

Similarly, we formally certify the existential block quantification:

Lemma nexistsP (k : nat) (e : seq R) (f : formula R) : exists v : k.-tuple R, holds (e ++ v) f <-> holds e (nquantify (size e) k Exists f).

Formalisation of Semi-Algebraic Sets

A S.A. set of R n is the set that realizes a formula of F n . It is a subset of F n . However, numerous elements of F n , some of which are quantifier-free, realize the same S.A. set. Testing for the equality of two S.A. sets amounts to testing for the equivalence of two elements of F n under any environment.

We firstly explain why we need the S.A. set concept by introducing CAD in Sect. 4.1. Then, in Sect. 4.2, we explain how we build S.A. sets as the mathematical quotient of F n by exploiting the logical equivalence relation over F n . projections) [START_REF] Basu | Algorithms in Real Algebraic Geometry[END_REF][START_REF]CAD[END_REF]. When n = 1, the above definition of CAD amounts to.

Cylindrical Algebraic Decomposition Definition

A CAD of R n is a partition (C j ) 1≤j ≤c (c ∈ N * ) of R n into connected S.A. sets C i ,
Another view of the CAD output is a bottom-up view, which starts by defining the CAD in dimension 1, then 2, etc. It is the original approach of Collins [START_REF] Caviness | Quantifier Elimination and Cylindrical Algebraic Decomposition[END_REF]. In dimension 1, a CAD is a finite partition of R into intervals (including singletons). For example, ]-∞, 0[, [0, ∞[ (Fig. 1a) and [-∞, 0], [0], [0, ∞] (Fig. 1b) are two valid CAD of R. Then, one defines inductively a CAD of R n+1 by using a CAD of R n . A cell in the CAD of R n+1 is defined above a cell of the given CAD of R n by providing one or two delimiting continuous S.A. functions; we define S.A. functions in Sect. 5. For example, the CAD (Fig. 2) defined by the cells:

• {(x, y) ∈ F 2 |x < 0, 0 < y} 1 • {(x, y) ∈ F 2 |x < 0, y ≤ 0} 2 • {(x, y) ∈ F 2 |0 ≤ x, y < √ x -1} 3 • {(x, y) ∈ F 2 |0 ≤ x, y = √ x -1} 4
• {(x, y) ∈ F 2 |0 ≤ x, √ x -1 < y ≤ 2 -x 2 } 5 • {(x, y) ∈ F 2 |0 ≤ x, 2 -x 2 < y} 6
is a valid CAD of R 2 built on top of the CAD of Fig. 1a. Both views are based on continuous S.A. functions, because S.A. set connectedness (in the higher level view) is equivalent to S.A. path connectedness of S.A. sets, where paths are expressed with S.A. functions. This shows the central role played by S.A. functions, whose continuity is a firstorder property and thus is decidable (see Sect. 7).

Definition of Semi-Algebraic Sets as a Quotient

We require that S.A. sets have the standard equality of the system (= in Coq). It is not always possible to build properly a quotient with the standard equality in Coq [START_REF] Cohen | Pragmatic Quotient Types in Coq[END_REF]. One possibility would be to compute a canonical equivalent representative of any formula, such that we compute the same representative for any two equivalent formulae.

Instead, we build the quotient out of our decidable equivalence relation, exploiting the second solution of Cohen [START_REF] Cohen | Pragmatic Quotient Types in Coq[END_REF] provided in the generic quotient module of Mathematical Components. S.A. sets is the quotient of F n by the logical equivalence relation (that we defined in Sect. 3):

Definition SAtype := {eq_quot sub_equivf}.

We create a notation in Coq to denote S.A. sets of R n by: {SAset F^n}.

This construction is possible because the base type F n has a choice structure (choiceType in Coq) and the equivalence relation is decidable (that is it returns a bool in Coq).

The equality of two S.A. sets s1 and s2 means that their underlying formulae are logically equivalent; or, equivalentally: ∀x ∈ R n x ∈ s1 ⇐⇒ x ∈ s2 (written s1 =i s2 in Coq). We formally prove the equivalence of S.A. sets viewed as formulae and viewed as sets, which states:

Lemma SAsetP (s1 s2 : {SAset R^n}) : reflect (s1 =i s2) (s1 == s2).

We equip S.A. sets with a lattice structure with bottom and top elements by implementing the porder interface from the developement version of Mathematical Components [START_REF] Cohen | Finmap Library[END_REF]. Specifically, we define the elements: empty, singleton, bottom and top; and the decidable operations: inclusion order, meet and join. We exploit the lemma SAsetP and formally prove that meet and join are associative and commutative, that the inclusion is reflexive, antisymmetric and transitive. We formally prove the distributivity of meet over join.

Reification Problem for the Functionality Property in the Formalisation of Semi-Algebraic Functions

In Sect.

→ R m . The graph of f is the set {(x, y) ∈ R n × R m | f (x ) = y} ⊆ R n+m .
We define a S.A. function from R n to R m as a S.A. set G of R n+m that satisfies the two following properties:

• it is total with respect to n and m (total_SAset).

• it is functional with respect to n and m (funct_SAset) We pack n consecutive universal (resp. existential) quantifications over R into one universal (resp. existential) quantification over R n (block quantification). The totality of G is expressed through a first-order formula:

∀x ∈ R n ∃y ∈ R m (x, y) ∈ G.
The functionality of G is then expressed through a first-order formula: }.

∀x ∈ R n ∀y ∈ R m ∀z ∈ R m (x, y) ∈ G ∧ (x, z) ∈ G =⇒ y = z (in
In Coq, such a definition of SAfun as a subtype of SAset requires the decidability of the graphs's property. Then, the Hedberg theorem applies to the type representing the graphs's property, so that this type is uniquely inhabited.

From this uniqueness we get that deciding the structural equality between two S.A. functions comes down to deciding the equality between two S.A. We apply the reification technique presented in Sect. 3 to the totality property (resp. the functionality property) in order to express P (resp. Q) in a decidable way.

In the language of real closed fields, we need n variables to represent x, m variables to represent y and m variables to represent z. We choose to represent x by the consecutive variables 'X_0, . . . ,'X_(n -1), y by the consecutive variables 'X_n, . . . ,'X_(n + m -1) and z by the consecutive variables 'X_(n + m), . . . ,'X_(n + 2*m -1) (see Fig. 3).

Since the definition of the totality (resp. functionality) property is in a prenex normal form, we achieve the reification of the totality (resp. functionality) in two steps. Firstly, we reify the quantifier-free part of the property. Finally, we apply block quantification on the resulting formula.

We start with building a tailored reified formula representing row_mx x y \in G (which does not use the variable z). The underlying formula f of G (obtained by forgetting the constraint on its free variables) already does the job, by definition (see Fig. 4a). We complete the reification of the totality of G by adding the quantifiers, in Coq: nquantify O n Forall (nquantify n m Exists f).

• • • • • • • • • X 0 X n-1 X n X n+m-1 X n+m X n+2m-1 x y z
Figure 3. representation of variables x, y and z

• • • • • • f X 0 X n-1 X n X n+m-1 (a) formula f • • • • • • f X 0 X n-1 X n+m X n+2m-1 (b) formula f resulting from renaming variables in f Figure 4
The reification of Q is problematic. If we keep the same representation for variables x, y and z, then (x, y) ∈ G still directly reifies to (the underlying formula of) f. However, we cannot directly use f to express (x, z) ∈ G, because z is expected to be represented by 'X_n, . . . , 'X_(n + m -1), not by 'X_(n + m), . . . ,'X_(n + 2*m -1). In Sect. 6, we show how to reify (x, z) ∈ G and Q by performing substitutions in formula.

Use of Substitution to reify the Functionality Property

Consider the formula f obtained by renaming the variables 'X_n, . . . , 'X_(n + m -1) in f (see Fig. 4a) to the respective variables 'X_(n + m), . . . ,'X_(n + 2*m -1) (see Fig. 4b).

Using the bracket notation for simultaneous substitution, we have:

f = f['X_n / 'X_(n + m), . . . , 'X_(n + m -1) / 'X_(n + 2*m -1)].
Then, the subterm (x, z) ∈ G of P directly reifies to the formula f itself. The subterm (x, y) ∈ G ∧ (x, z) ∈ G of P thus reifies to f /\ f, and the proposition ∀x

∈ R n ∀y ∈ R m ∀z ∈ R m (x, y) ∈ G ∧ (x, z) ∈ G reifies to: nquantify O (n + 2*m) Forall (f /\ f).
For the moment, let's admit that y = z is represented by a reified formula eq_vec (miming n+m-1 i=n X i = X i+m ). Then, the property P finally reifies to:

nquantify O (n + 2 * m) Forall (f /\ f) ==> eq_vec.
We explain how we formalise the substitution in Sect. 6.1 and how to formalise f, f and eq_vec in Sect. 6.2, which completes the formalisation of the functionality property.

A new Formalisation of Substitution in Formulae

We have used simultaneous substitution of variables for terms in the formula f to define f. We call it a "block substitution", because all substitution variables (from 0 to n -1) form a block of consecutive variables. In all our reifications, we will use block substitutions only.

The formalisation of the substitution in formulae is tricky: one should operate substitution for free occurences of variables only. Moreover, one should prevent free variables in introduced terms from falling under the scope of quantifiers, which is solved by alpha conversion [START_REF] Harrison | Formalizing Basic First Order Model Theory[END_REF][START_REF] Harrison | Handbook of Practical Logic and Automated Reasoning[END_REF]. Simultaneity in substitution does not pose any difficulty.

Instead, we use a new, simpler, formalisation of the block substitution exploiting the formalisation of the quantifier elimination. Firstly, we define the substitution of variables for terms in a given term, in a way similar to [START_REF] Harrison | Handbook of Practical Logic and Automated Reasoning[END_REF]. Secondly, based on the substitution in term, we define the substitution of variables for terms in a given formula. We avoid alpha conversion by exploiting quantifier elimination. To the knowledge of the author, it is the first time that the simultaneous substitution of variables for terms in a formula is formalised in this way.

Consider the substitution t[s 0 / 'X_0, . . . , s p-1 / 'X_(p -1)] where t, s 0 , . . . , s p-1 are terms and p is a natural number. Let 'X_(n -1) be the free variable in t with highest index. When n ≤ p the above substitution boils down to t[s 0 / 'X_0, . . . , s n-1 / 'X_(n -1)]. When p < n, for convenience, variables with index greater than p are assigned to 0. That is, we formalise the following slighlty modified version of substitution:

t[s 0 / 'X_0, . . . , s p-1 / 'X_(p -1), 0 / 'X_p, . . . , 0 / 'X_(n -1) ].

Since the variable names are natural numbers, the mapping from variable names to terms can be encoded by a sequence of terms. In Coq, we define the substitution subst_term of terms for variables in a given term t with:

Definition subst_term (s : seq (term F)) := let fix sterm (t : term F) := match t with | 'X_i => if (i < size s) then (nth 'X_O s i) else 0 | t1 + t2 => (sterm t1) + (sterm t2) | -t => -(sterm t) | t *+ i => (sterm t) *+ i | t1 * t2 => (sterm t1) * (sterm t2) | t ^-1 => (sterm t) ^-1 | t ^+ i => (sterm t) ^+ i | _ => t end in sterm.
With this encoding, it is possible to keep variables unchanged by assigning their own index explicitly. For example, the substitution t[t 1 / 'X_2, t 2 / 'X_4] where variables with index greater than 5 are assigned to 0 is expressed by: subst_term [::'X_0 ; 'X_1 ; t1 ; 'X_3 ; t2 ; 'X_5]%oT t. We formally prove the correctness property for the function subst_term:

Lemma eval_subst e (s : seq (term F)) (t : term F) : eval e (subst_term s t) = eval

[::] (subst_term [seq (subst_term [seq x%oT | x <-e] u) | u <-s] t).
This lemma reads as follows. Evaluating a substituted term subst_term s t in an environment e boils down to evaluating the substitutors s in an environment e (which outputs [seq (subst_term [seq x%oT | x <-e] u)| u <-s]) then operate the substitution with the new substitutors, and finally evaluating the result in the empty environment.

In Coq, we define the substitution in formulae in two steps. Firstly, we define a function qf_subst_formula which performs substitution in quantifier free formulae; in this case there is no bound variables problem. In Coq, the function qf_subst_formula is defined by:

Fixpoint qf_subst_formula s (f : formula F) := let sterm := subst_term s in match f with | (t1 == t2) => (sterm t1) == (sterm t2) | t1 <% t2 => (sterm t1) <% (sterm t2) | t1 <=% t2 => (sterm t1) <=% (sterm t2) | Unit t => Unit (sterm t) | f1 /\ f2 => (qf_subst_formula s f1) /\ (qf_subst_formula s f2) | f1 \/ f2 => (qf_subst_formula s f1) \/ (qf_subst_formula s f2) | f1 ==> f2 => (qf_subst_formula s f1) ==> (qf_subst_formula s f2) | ~f => ~(qf_subst_formula s f) | ('forall 'X_i, _) | ('exists 'X_i, _) => False | _ => f end%oT.
When applied to quantification formulae, qf_subst_formula returns the arbitrary default False formula. Secondly, we define the substitution in formulae by combining qf_elim and qf_subst_formula: Definition subst_formula s (f : formula F) := qf_subst_formula s (qf_elim f).

We formally prove the correctness property for the function subst_formula:

Lemma holds_subst e s f : holds e (subst_formula s f) <-> holds [::] (subst_formula [seq (subst_term (map Const e) t) | t <-s] f).

This lemma reads as follows. Evaluating a substituted term subst_term s f in an environment e boils down to evaluating the substitutors s in an environment e (which ouputs

| (t1 == t2) => (sterm t1) == (sterm t2) | t1 <% t2 => (sterm t1) <% (sterm t2) | t1 <=% t2 => (sterm t1) <=% (sterm t2) | Unit t => Unit (sterm t) | f1 /\ f2 => (qf_subst_formula s f1) /\ (qf_subst_formula s f2) | f1 \/ f2 => (qf_subst_formula s f1) \/ (qf_subst_formula s f2) | f1 ==> f2 => (qf_subst_formula s f1) ==> (qf_subst_formula s f2) | ~f => ~(qf_subst_formula s f) | ('forall 'X_i, _) | ('exists 'X_i, _) => False | _ => f end%oT.
7 Application of Block Reasoning to the Composition of two Semi-Algebraic Functions

In Coq, S.A. functions are viewed as functions by declaring a coercion:

Coercion safun_to_fun : SAfun >-> Funclass.

Given f of type {SAfun R^m -> R^n}, g of type {SAfun R^n -> R^p} and x of type 'rV[R]_m, this allows us to write f x (of type 'rV[R]_n) and the composition g \o f. However, the latter term has type 'rV[R]_m -> 'rV[R]_p, whereas the composition of two S.A. functions is also a S.A. function.

To solve this problem, we use block reasoning as in Sect. 5 and build a formula SAcomp_graph f g that represents g of as a S.A. set and prove its correctness:

Lemma SAcomp_graphP (m n p : nat) (f : {SAfun R^m -> R^n}) (g : {SAfun R^n -> R^p})

(u : 'rV[R]_m) (v : 'rV[R]_p) : (row_mx u v \in SAcomp_graph f g) = (g (f u) == v).
Based on this lemma, we prove that our formula compo f g is both functional and total, which enables us to build the S.A. composition sa_comp f g. Finally, we prove the correctness of the S.A. composition with respect to the function composition:

Lemma SAcompP (m n p : nat) (f : {SAfun R^m -> R^n}) (g : {SAfun R^n -> R^p}) : SAcomp f g =1 g \o f.
that is, the S.A. composition is the composition of functions.

Application of Block Reasoning to reify the Continuity of two Semi-Algebraic Functions

Block reasoning also applies to the continuity of a S.A. function. Since all norms are equivalent in finite dimension, we can express continuity with the supremum norm ∥.∥ ∞ :

∀x ∈ R n ∀ϵ ∈ R ∃η ∈ R ∀y ∈ R n ∥x -y∥ ∞ ≤ η =⇒ ∥ f (x ) -f (y)∥ ∞ ≤ ϵ
where the subtraction and the sup functions are semi-algebraic.

As a result, we can prove that the continuity of a S.A. function is a decidable property. We show how to use block reasoning to produce a reified formulae for the continuity of two S.A. functions. The certification of the resulting formula is still a work in progress.

Since the definition of the continuity is in a prenex normal form, we achieve the reification of the continuity in two steps. Firstly, we reify the quantifier-free part of the continuity property. Finally, we apply block quantification on the resulting formulae.

Reifying the quantifier-free part of the continuity property boils down to reifying κ = ∥x -y∥ ∞ ≤ η =⇒ ∥u -v ∥ ∞ ≤ ϵ and adding the relations f (x ) = u and f (y) = v -once variables 'X_i are chosen to represent x and u (resp. y and v), we already know how to represent f (x ) = u (resp. f (y) = v), by using substitution.

The language of reified formulae already has a constant (==> in Coq) to express the logical implication. Thus, reifying κ boils down to reifying ∥x -y ∥ ∞ ≤ η and ∥u -v ∥ ∞ ≤ ϵ. Indeed, the reification of ∥u -v ∥ ∞ ≤ ϵ is obtained by reifying ∥x -y∥ ∞ ≤ η for m instead of n and renaming variables. Moreover, the language of reified formulae already has a constant (<=% in Coq) to express the inequality in R. Thus, reifying κ boils down to reifying ∥x -y∥ ∞ , which we decompose into three steps. We separately reify subtraction in R n , coordinate-wise absolute value in R n and the coordinate maximum function from R n to R. We combinate these three constructions to reify ∥x -y∥ ∞ .

Given variables blocks representing x and y, we firstly create a formula [START_REF] Cohen | Pragmatic Quotient Types in Coq[END_REF] representing the subtraction xy. This formula has a third variables block to represent the output xy and a subformula to express the ternary relation between x, y and xy. Then, we create a formula (8) representing coordinate-wise absolute value. This formula has a block to represent z, a block to represent the vector (|z i |) i , (0 ≤ i < n), and a subformula to express the binary relation between z and (|z i |) i . We apply it to represent the vector |x i -y i | (0 ≤ i < n). Finally, we create a formula (8) representing the coordinates maximum of a vector. This formula has a block to represent z, a single variable to represent max 0≤i <n z i and a subformula to represent the relation between z and max 0≤i <n z i . We apply it to represent ∥x -y∥ ∞ .

Block Reasoning Extension

In this paragraph, we extend block reasoning with block subtraction (8), block absolute value (8) and block maximum [START_REF] Cohen | Pragmatic Quotient Types in Coq[END_REF].

These constructions are parameterised by the desired sequences of variables

:= ((\big[Or/False]_(i < size v) ('X_n == 'X_(nth O v i))) /\ (\big[And/True]_(i < size v) ('X_(nth O v i) <=% 'X_n)))%oT.
We also prove the following correctness properties for sub_vec and abs_vec, in Coq: We now come back to the reification of κ. ♦

To reify κ, each S.A. function application occurring in κ (subtraction, absolute value, maximum and f) requires variables 'X_i to represent both its inputs and its ouput. Let denote the output dimension of f by p, in other words f has type R n → R p .

We need n variables to represent x, n variables to represent y, n variables to represent x -y, n variables to represent the row |x i - We use a similar variable representation for the subformula ∥u -v ∥ ∞ ≤ ϵ, starting at index 4*n + 2. We choose to represent u by the consecutive variables 'X_0 . . . , 'X_(n -1), v by the consecutive variables 'X_n, . . . , 'X_(2*n -1), uv by the consecutive variables 'X_(2*n), . . . , 'X_(3*n -1), |u i -v i | (0 ≤ i < n) by the consecutive variables 'X_(3*n), . . . , 'X_(4*n -1), ∥u -v ∥ ∞ by the variable 'X_(4*n) and ϵ by 'X_(4*n + 1) (see Fig. 5c).

y i | (0 ≤ i < n), one variable to represent ∥x -y ∥ ∞ = max
i -v i | (0 ≤ i < n), one variable to represent ∥u -v ∥ ∞ = max 0≤i <n |u i -v i
Indeed, the reification of ∥u -v ∥ ∞ ≤ ϵ is obtained by reifying ∥x -y ∥ ∞ ≤ η for m instead of n and by renaming variables by shifting indices by 4n + 2 positions.

By exploiting block reasoning on our variable representation, ∥x -y∥ ∞ ≤ η reifies to the following Coq formula applied to n:

Definition bloc (i : nat) : formula F := (sub_vec (iota 0 i) (iota i i) (iota (2 * i) i)) /\ (abs_vec (iota (2 * i) i) (iota (3 * i) i)) /\ (max_vec (iota (3 * i) i) (4 * i)) /\ ('X_(4 * i) <=% 'X_((4 * i).+1)).
To reify ∥u -v ∥ ∞ ≤ ϵ, we thus rename variables 'X_0 . . which we denote by beta. We now have to restrict κ to values x, y, u and v such that f (x ) = u and f (y) = v. We already know how to reify the latter equations by applying block substitutions on f ; we reify the quantifier-free part of the continuity property in Coq with: beta /\ (subst_formula ((iota 0 n) ++ (iota (4 * n + 2) m)) f) /\ (subst_formula ((iota n n) ++ (iota (4 * n + m + 2) m)) f).

which we denote by gamma.

We now achieve the full reification of the continuity property by adding all the quantifications with:

Related Work

The main related work is the book Algorithms In Real Algebraic Geometry [START_REF] Basu | Algorithms in Real Algebraic Geometry[END_REF], which describes various algorithms including "CAD algorithms". While this book contains "paper" algorithms and proofs, it comes with implementations 10

A Constructive Formalisation of Semi-Algebraic Sets and Functions CPP'18, January 07-08, 2018, Los Angeles, LA, USA

• • • • • • X 0 X 4n+1 X 4n+2 X 4n+4m+3 (a) X 0 X n-1 • • • x X n X 2n-1 • • • y X 2n X 3n-1 • • • x -y X 3n X 4n-1 • • • |xi -yi | ∥x -y∥∞ η (b) X 4n+2 • • • u • • • v • • • u -v X 4n+4m+1 • • • |ui -vi | ∥u -v ∥∞ ϵ (c)
Figure 5. representation of the input variables, intermediate variables and output variables of the continuity property of some algorithms in Maxima [START_REF] Caruso | The SARAG Library: Some Algorithms in Real Algebraic Geometry[END_REF]. We use this book as our main reference. Formal proofs of real algebraic geometry theory and algorithms in a proof assistant started, up to our knowledge, with Mahboubi's formalisation of Collins' "CAD algorithms" [START_REF] Mahboubi | Contributions à la certification des calculs dans R : théorie, preuves, programmation[END_REF]. She certified the key component which computes Sturm sequences efficiently using subresultants. Then, Cohen and Mahboubi [START_REF] Cohen | A Formal Quantifier Elimination for Algebraically Closed Fields[END_REF] formalised a quantifier elimination algorithm, following one of the many algorithms in Algorithms In Real Algebraic Geometry [START_REF] Basu | Algorithms in Real Algebraic Geometry[END_REF] with an approach similar to Tarski's initial proof [START_REF] Tarski | A decision method for elementary algebra and geometry[END_REF]. The latter formalisation relies on algebraic arguments, which makes it a solid ground for our current work.

The first closest formal proof to our work was John Harrison's HOL Light [START_REF] Harrison | Theorem Proving with the Real Numbers[END_REF] quantifier elimination procedure, but it is viewed as a decision procedure and does not tackle real algebraic geometry theory. There have been several other formalisations of Sturm theorem, in HOL Light [START_REF] Harrison | Verifying the accuracy of polynomial approximations in HOL[END_REF] and then in PVS [START_REF] Narkawicz | Formally-Verified Decision Procedures for Univariate Polynomial Computation Based on Sturm's and Tarski's Theorems[END_REF] and concurrently in Isabelle/HOL [START_REF] Eberl | A Decision Procedure for Univariate Real Polynomials in Isabelle/HOL[END_REF][START_REF] Lawrence | A Complete Decision Procedure for Univariate Polynomial Problems in Isabelle/HOL[END_REF]. Also there is a proof of Rouché Theorem [START_REF] Li | A Formal Proof of Cauchy's Residue Theorem[END_REF] to tackle another aspect of "CAD algorithms".

The work we present here is different from other formalisations because it does not focus on the algorithmic ingredients present in "CAD algorithms" but rather on the theory that is necessary to describe its result precisely.

Conclusion and Future Work

We have shown how we handle S.A. sets and S.A. functions concepts in Coq for the needs of the CAD formalisation. The methods we use to formalise and certify functionality and totality of S.A. functions also apply to the continuity of a S.A. function. This paves the way for the formalisation of continuous S.A. functions and thus the CAD output.

In a straight continuation of our construction of the composition of two S.A. functions, we should be able to provide other S.A. functions, such as: polynomials, linear functions and the nth virtual roots applications (as defined by Gonzalez-Vega, Lombardi, & Mahé [START_REF] Gonzalez-Vega | Virtual roots of real polynomials[END_REF]).

CPP' 18 ,

 18 January 07-08, 2018, Los Angeles, LA, USA Boris Djalal

AFigure 2 .

 2 Figure 1

  sets. In Coq, we represent R n by the vectors 'rV[R]_n from Mathematical Components. The totality of G is expressed by the term P in Prop: forall (x : 'rV[R]_n), exists (y : 'rV[R]_m), row_mx x y \in G and the functionality of G is then expressed by the term Q in Prop: forall (x : 'rV[R]_n), forall (y z : 'rV[R]_m), row_mx x y \in G -> row_mx x z \in G -> y = z where row_mx denotes the vectors concatenation.

6

 6

A

  Constructive Formalisation of Semi-Algebraic Sets and Functions CPP'18, January 07-08, 2018, Los Angeles, LA, USA match f with

  Lemma sub_vecP (e : seq F) (v1 v2 v3 : seq nat) : rcf_sat e (sub_vec v1 v2 v3) = ((sizev1 == size v2) && (size v1 == size v3)) && [forall i, (e_(nth O v3 (i : 'I_(size v1))) == e_(nth O v1 i) -e_(nth O v2 i))].Lemma abs_vecP (e : seq F) (v1 v2 : seq nat) : rcf_sat e (abs_vec v1 v2) = (size v1 == size v2) && [forall i, e_(nth O v2 (i : 'I_(size v1))) == |e _(nth O v1 i)|].

  0≤i <n |x i -y i | and one variable to represent η. Similarly, we need m variables to represent u, m variables to represent v, m variables to represent uv, m variables to represent the row |u

  | and one variable to represent ϵ. We choose to represent x by the consecutive variables 'X_0 . . . , 'X_(n -1), y by the consecutive variables 'X_n, . . . , 'X_(2*n -1), x -y by the consecutive variables 'X_(2*n), . . . , 'X_(3*n -1), |x i -y i | (0 ≤ i < n) by the consecutive variables 'X_(3*n), . . . , 'X_(4*n -1), ∥x -y∥ ∞ by the variable 'X_(4*n) and η by the variable 'X_(4*n + 1) (see Fig.5b).

  . , 'X_(4*m + 1) to 'X_(4*n + 2) . . . , 'X_(4*n + 4*m + 3) in bloc m, with block substitution: ∥u -v ∥ ∞ ≤ ϵ reifies to: subst_formula (iota (4 * n + 2) (4 * m + 1)) (bloc m) thus, κ reifies to: (bloc n) ==> (subst_formula (iota (4 * n + 2) (4 * m + 1)) (bloc m))

  Definition is_continuous_form (f : {formula_(n + m) F}) := nquantify 0 n Forall ('forall 'X_(4 * n + 4 * m + 3), ('exists 'X_(4 * n + 1), (nquantify n (2 * n) Forall (nquantify (2 * n) (2 * n + 1) Forall (nquantify (4 * n + 2) (4 * m + 1) Forall gamma))))).

  the code snippet 6.2 we use this property to certify the Coq predicate SAfunc). We define S.A. functions in Coq by:

	Record SAfun := MkSAfun
	{
	SAgraph :> {SAset R^(n + m)};
	_ : (SAgraph \in total_SAset) && (SAgraph \in funct_SAset)

9

  Definition sub_vec (v1 v2 v3 : seq nat) : formula F := if ((size v1 == size v2) && (size v1 == size v3)) then \big[And/True]_(i < size v1) ( 'X_(nth O v1 i) == 'X_(nth O v2 i) + 'X_(nth O v3 i))%oT Definition max_vec (v : seq nat) (n : nat) : formula F

	else False.
	Definition abs_vec (v1 v2 : seq nat) : formula F :=
	if size v1 == size v2
	then (\big[And/True]_(i < size v1) (abs (nth O v1 i)) (
	nth O v2 i))%oT
	else False.

Acknowledgments

Pretty Coq code listing was done thanks to Assia Mahboubi's file [18]. We thank our colleagues for their input on this work: Assia Mahboubi, Cyril Cohen, my co-supervisor, Damien Rouhling, Enrico Tassi, José Grimm, Laurent Théry, Matej Košík, Yves Bertot, my supervisor, and the MAP working group about real geometry, including Marie-Françoise Roy and Henri Lombardi.

CPP'18, January 07-08, 2018, Los Angeles, LA, USA Boris Djalal

[seq (subst_term (map Const e)t)| t <-s]) then operate the substitution with the new substitutors, and finally evaluating the result in the empty environment.

Complete Formalisation of the Functionality Property

We are now able to detail the whole reification of the functionality property, by formalising f with the help of subst_formula The formula f rewrites as:

We get the expected substitution for the following reasons. The variables 'X_0, . . . , 'X_(n -1) are respectively replaced by 'X_0, . . . , 'X_(n -1), which has no effect. Then the variables 'X_n, . . . , 'X_(n + m -1) are respectively replaced by variables 'X_(n + m), . . . , 'X_(n + 2*m -1), which is what we intend to do.

Finally, we need to express the equality of y and z, that is the equality of the variable 'X_i with 'X_(i + m)

. We view this conjonction of equalities as a binary relation between two blocks of consecutive variables, the first one ranging from n to n + m -1, the second one ranging from n + m to n + 2*m -1. In Coq, we express this binary relation by:

We choose that eq_vec returns the formula False when the input sequences have different lengths. We formally prove the correctness property for the function eq_vec:

Lemma holds_eq_vec e v1 v2 : holds e (eq_vec v1 v2) <-> subst_env v1 e = subst_env v2 e.

We have now all the bricks to reify the functionality property:

We can replace f by the equivalent formula (subst_formula (iota 0 n ++ iota n m) f) in the definition of functional, to simplifies the correctness proof of functional.

We formally prove the correctness property of SAfunc: Lemma SAfuncE (s : {SAset F ^(n + m)}) : reflect (forall (x : 'rV[F]_n), forall (y1 y2 : 'rV[F]_m), (row_mx x y1) \in s -> (row_mx x y2) \in s -> y1 = y2) (s \in SAfunc).

Block Reasoning

We call block reasoning the methodology used to express the functionality property in a decidable way (this methodology is partially applied to express equivf). Block reasoning may apply to other first-order properties in the language of real closed fields. Block reasoning is divided into two parts. In the first part, we create a tailor-made reified formula, eventually exploiting block substitution (subst_formula) and block quantification (nquant). In the second part, we prove the correctness of the created formula, eventually exploiting environment substitution (subst_env) or certification of block quantification (nforallP) and (nexistsP). We apply block reasoning to formalise the composition of two S.A. functions; as summarised in Sect. 7. In Sect. 8, we explain how we use this methodology to express the continuity of two S.A. functions, which turns out to be more difficult than the formalisation of the composition. Reifying the continuity property leads us to extend block reasoning. We achieve the first part for the continuity property.

In all our methodology case studies, we use block substitution only to rename variables. That is, we substitute terms, which are variables only, for variables in formulae. Instead of providing a variable sequence, we simply provide an integer sequence. For convenience, we use a specialised version of block substitution, as follows: