(**
This file is part of the Coquelicot formalization of real
analysis in Coq: http://coquelicot.saclay.inria.fr/

Copyright (C) 2011-2015 Sylvie Boldo
#<br />#
Copyright (C) 2011-2015 Catherine Lelay
#<br />#
Copyright (C) 2011-2015 Guillaume Melquiond

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
COPYING file for more details.
*)

Require Import Reals.
Require Import Rcomplements Hierarchy Derive RInt RInt_analysis Derive_2d Continuity ElemFct.
Require Import mathcomp.ssreflect.ssreflect mathcomp.ssreflect.ssrbool mathcomp.ssreflect.seq Datatypes.

(** * Reflective tactic for solving goals of the form [derivable_pt_lim] *)

Fixpoint Rn n T :=
  match n with
  | O => T
  | S n => R -> Rn n T
  end.

Inductive bop :=
  | Eplus
  | Emult.

Inductive uop :=
  | Eopp
  | Einv
  | Efct : forall (f f' : R -> R), (forall x, is_derive f x (f' x)) -> uop
  | Efct' : forall (f f' : R -> R) (df : R -> Prop), (forall x, df x -> is_derive f x (f' x)) -> uop.

Inductive expr :=
  | Var : nat -> expr
  | AppExt : forall k, Rn k R -> seq expr -> expr
  | AppExtD : forall k, Rn k R -> nat -> seq expr -> expr
  | App : expr -> expr -> expr
  | Subst : expr -> expr -> expr
  | Cst : R -> expr
  | Binary : bop -> expr -> expr -> expr
  | Unary : uop -> expr -> expr
  | Int : expr -> expr -> expr -> expr.

Section ExprInduction.

Hypothesis P : expr -> Prop.
Hypothesis P_Var : forall n, P (Var n).
Hypothesis P_AppExt : forall k f le, foldr (fun e acc  => P e /\ acc) True le -> P (AppExt k f le).
Hypothesis P_AppExtD : forall k f n le, foldr (fun e acc  => P e /\ acc) True le -> P (AppExtD k f n le).
Hypothesis P_App : forall e1 e2, P e1 -> P e2 -> P (App e1 e2).
Hypothesis P_Subst : forall e1 e2, P e1 -> P e2 -> P (Subst e1 e2).
Hypothesis P_Cst : forall r, P (Cst r).
Hypothesis P_Binary : forall o e1 e2, P e1 -> P e2 -> P (Binary o e1 e2).
Hypothesis P_Unary : forall o e, P e -> P (Unary o e).
Hypothesis P_Int : forall f e1 e2, P f -> P e1 -> P e2 -> P (Int f e1 e2).

Fixpoint expr_ind' (e : expr) : P e :=
  match e return P e with
  | Var n => P_Var n
  | AppExt k f le => P_AppExt k f le
    ((fix expr_ind'' (le : seq expr) : foldr (fun e acc => P e /\ acc) True le :=
       match le return foldr (fun e acc => P e /\ acc) True le with
       | nil => I
       | cons h q => conj (expr_ind' h) (expr_ind'' q)
       end) le)
  | AppExtD k f n le => P_AppExtD k f n le
    ((fix expr_ind'' (le : seq expr) : foldr (fun e acc => P e /\ acc) True le :=
       match le return foldr (fun e acc => P e /\ acc) True le with
       | nil => I
       | cons h q => conj (expr_ind' h) (expr_ind'' q)
       end) le)
  | App e1 e2 => P_App e1 e2 (expr_ind' e1) (expr_ind' e2)
  | Subst e1 e2 => P_Subst e1 e2 (expr_ind' e1) (expr_ind' e2)
  | Cst r => P_Cst r
  | Binary o e1 e2 => P_Binary o e1 e2 (expr_ind' e1) (expr_ind' e2)
  | Unary o e => P_Unary o e (expr_ind' e)
  | Int f e1 e2 => P_Int f e1 e2 (expr_ind' f) (expr_ind' e1) (expr_ind' e2)
  end.

End ExprInduction.

Fixpoint apply {T} p : Rn p T -> (nat -> R) -> T :=
  match p return Rn p T -> _ -> T with
  | O => fun (x : T) _ => x
  | S p => fun (f : Rn (S p) T) g => apply p (f (g p)) g
  end.

Lemma apply_ext :
  forall T k (f : Rn k T) g1 g2,
  (forall n, (n < k)%nat -> g1 n = g2 n) ->
  apply k f g1 = apply k f g2.
Proof.
(* Goal: forall (T : Type) (k : nat) (f : Rn k T) (g1 g2 : forall _ : nat, R) (_ : forall (n : nat) (_ : lt n k), @eq R (g1 n) (g2 n)), @eq T (@apply T k f g1) (@apply T k f g2) *)
intros T k f g1 g2 Hg.
(* Goal: @eq T (@apply T k f g1) (@apply T k f g2) *)
revert f.
(* Goal: forall f : Rn k T, @eq T (@apply T k f g1) (@apply T k f g2) *)
induction k.
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
(* Goal: forall f : forall _ : R, Rn k T, @eq T (@apply T k (f (g1 k)) g1) (@apply T k (f (g2 k)) g2) *)
intros f.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite Hg.
(* Goal: @eq T (@apply T k (f (g2 k)) g1) (@apply T k (f (g2 k)) g2) *)
(* Goal: lt k (S k) *)
apply IHk.
(* Goal: forall (n : nat) (_ : lt n k), @eq R (g1 n) (g2 n) *)
(* Goal: lt k (S k) *)
intros n Hn.
(* Goal: @eq R (g1 n) (g2 n) *)
(* Goal: lt k (S k) *)
apply Hg.
(* Goal: lt n (S k) *)
(* Goal: lt k (S k) *)
now apply lt_S.
(* Goal: lt k (S k) *)
apply lt_n_Sn.
Qed.

Definition Derive_Rn n (f : Rn n R) p g :=
  Derive (fun x => apply n f (fun i => if ssrnat.eqn i p then x else g i)) (g p).

Definition ex_derive_Rn n (f : Rn n R) p g :=
  ex_derive (fun x => apply n f (fun i => if ssrnat.eqn i p then x else g i)) (g p).

Fixpoint interp (l : seq R) (e : expr) : R :=
  match e with
  | Var n => nth R0 l n
  | AppExt k f le => apply k f (nth 0 (map (interp l) le))
  | AppExtD k f n le => Derive_Rn k f n (nth 0 (map (interp l) le))
  | App e1 e2 => interp ((interp l e2) :: l) e1
  | Subst e1 e2 => interp (set_nth R0 l 0 (interp l e2)) e1
  | Cst c => c
  | Binary o e1 e2 => match o with Eplus => Rplus | Emult => Rmult end (interp l e1) (interp l e2)
  | Unary o e => match o with Eopp => Ropp | Einv => Rinv | Efct f f' H => f | Efct' f f' df H => f end (interp l e)
  | Int e1 e2 e3 => RInt (fun x => interp (x :: l) e1) (interp l e2) (interp l e3)
  end.

Inductive domain :=
  | Never : domain
  | Always : domain
  | Partial : (R -> Prop) -> expr -> domain
  | Derivable : nat -> forall k, Rn k R -> seq expr -> domain
  | Derivable2 : nat -> nat -> forall k, Rn k R -> seq expr -> domain
  | Continuous : nat -> expr -> domain
  | Continuous2 : nat -> nat -> expr -> domain
  | Integrable : expr -> expr -> expr -> domain
  | ParamIntegrable : nat -> expr -> expr -> expr -> domain
  | LocallyParamIntegrable : nat -> expr -> expr -> domain
  | And : seq domain -> domain
  | Forall : expr -> expr -> domain -> domain
  | Forone : expr -> domain -> domain
  | Locally : nat -> domain -> domain
  | Locally2 : nat -> nat -> domain -> domain
  | ForallWide : nat -> expr -> expr -> domain -> domain.

Section DomainInduction.

Hypothesis P : domain -> Prop.
Hypothesis P_Never : P Never.
Hypothesis P_Always : P Always.
Hypothesis P_Partial : forall p e, P (Partial p e).
Hypothesis P_Derivable : forall n k f le, P (Derivable n k f le).
Hypothesis P_Derivable2 : forall m n k f le, P (Derivable2 m n k f le).
Hypothesis P_Continuous : forall n e, P (Continuous n e).
Hypothesis P_Continuous2 : forall m n e, P (Continuous2 m n e).
Hypothesis P_Integrable : forall f e1 e2, P (Integrable f e1 e2).
Hypothesis P_ParamIntegrable : forall n f e1 e2, P (ParamIntegrable n f e1 e2).
Hypothesis P_LocallyParamIntegrable : forall n f e, P (LocallyParamIntegrable n f e).
Hypothesis P_And : forall ld, foldr (fun d acc  => P d /\ acc) True ld -> P (And ld).
Hypothesis P_Forall : forall e1 e2 d, P d -> P (Forall e1 e2 d).
Hypothesis P_Forone : forall e d, P d -> P (Forone e d).
Hypothesis P_Locally : forall n d, P d -> P (Locally n d).
Hypothesis P_Locally2 : forall m n d, P d -> P (Locally2 m n d).
Hypothesis P_ForallWide : forall n e1 e2 d, P d -> P (ForallWide n e1 e2 d).

Fixpoint domain_ind' (d : domain) : P d :=
  match d return P d with
  | Never => P_Never
  | Always => P_Always
  | Partial d e => P_Partial d e
  | Derivable n k f le => P_Derivable n k f le
  | Derivable2 m n k f le => P_Derivable2 m n k f le
  | Continuous n e => P_Continuous n e
  | Continuous2 m n e => P_Continuous2 m n e
  | Integrable f e1 e2 => P_Integrable f e1 e2
  | ParamIntegrable n f e1 e2 => P_ParamIntegrable n f e1 e2
  | LocallyParamIntegrable n f e => P_LocallyParamIntegrable n f e
  | And ld => P_And ld
    ((fix domain_ind'' (ld : seq domain) : foldr (fun d acc => P d /\ acc) True ld :=
       match ld return foldr (fun d acc => P d /\ acc) True ld with
       | nil => I
       | cons h q => conj (domain_ind' h) (domain_ind'' q)
       end) ld)
  | Forall e1 e2 d => P_Forall e1 e2 d (domain_ind' d)
  | Forone e d => P_Forone e d (domain_ind' d)
  | Locally n d => P_Locally n d (domain_ind' d)
  | Locally2 m n d => P_Locally2 m n d (domain_ind' d)
  | ForallWide n e1 e2 d => P_ForallWide n e1 e2 d (domain_ind' d)
  end.

End DomainInduction.

Lemma foldr_prop_nth :
  forall {T} {P: T -> Prop} d l n,
  foldr (fun d acc => P d /\ acc) True l ->
  P d ->
  P (nth d l n).
Proof.
(* Goal: forall (T : Type) (P : forall _ : T, Prop) (d : T) (l : list T) (n : nat) (_ : @foldr T Prop (fun (d0 : T) (acc : Prop) => and (P d0) acc) True l) (_ : P d), P (@nth T d l n) *)
intros T P d l n Hl Hd.
(* Goal: P (@nth T d l n) *)
revert l n Hl.
(* Goal: forall (l : list T) (n : nat) (_ : @foldr T Prop (fun (d : T) (acc : Prop) => and (P d) acc) True l), P (@nth T d l n) *)
induction l.
(* Goal: forall (n : nat) (_ : lt n k), @eq R (@nth R (IZR Z0) (@map expr R (interp l1) le) n) (@nth R (IZR Z0) (@map expr R (interp l2) le) n) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (AppExtD k f n le)) (interp l2 (AppExtD k f n le)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (App e1 e2)) (interp l2 (App e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Subst e1 e2)) (interp l2 (Subst e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
intros n _.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite nth_nil.
(* Goal: forall n : nat, @eq R (@nth R (IZR Z0) (@cons R (interp l1 a) (@map expr R (interp l1) le)) n) (@nth R (IZR Z0) (@cons R (interp l2 a) (@map expr R (interp l2) le)) n) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (AppExtD k f n le)) (interp l2 (AppExtD k f n le)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (App e1 e2)) (interp l2 (App e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Subst e1 e2)) (interp l2 (Subst e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
intros [|n].
(* Goal: forall _ : @foldr T Prop (fun (d : T) (acc : Prop) => and (P d) acc) True (@cons T a l), P (@nth T d (@cons T a l) O) *)
(* Goal: forall _ : @foldr T Prop (fun (d : T) (acc : Prop) => and (P d) acc) True (@cons T a l), P (@nth T d (@cons T a l) (S n)) *)
now intros (H,_).
(* Goal: forall _ : @foldr T Prop (fun (d : T) (acc : Prop) => and (P d) acc) True (@cons T a l), P (@nth T d (@cons T a l) (S n)) *)
intros (_,H).
(* Goal: P (@nth T d (@cons T a l) (S n)) *)
now apply IHl.
Qed.

Fixpoint interp_domain (l : seq R) (d : domain) : Prop :=
  match d with
  | Never => False
  | Always => True
  | Partial p e => p (interp l e)
  | Derivable n k f le => ex_derive_Rn k f n (nth 0 (map (interp l) le))
  | Derivable2 m n k f le =>
    let le' := map (interp l) le in
    locally_2d (fun u v => ex_derive_Rn k f m (fun i => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else nth 0 le' i)) (nth 0 le' m) (nth 0 le' n) /\
    continuity_2d_pt (fun u v => Derive_Rn k f m (fun i => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else nth 0 le' i)) (nth 0 le' m) (nth 0 le' n)
  | Continuous n f => continuity_pt (fun x => interp (set_nth R0 l n x) f) (nth R0 l n)
  | Continuous2 m n f => continuity_2d_pt (fun x y => interp (set_nth R0 (set_nth R0 l n y) m x) f) (nth R0 l m) (nth R0 l n)
  | Integrable f e1 e2 => ex_RInt (fun x => interp (x :: l) f) (interp l e1) (interp l e2)
  | ParamIntegrable n f e1 e2 =>
    locally (nth R0 l n) (fun y => ex_RInt (fun t => interp (t :: set_nth R0 l n y) f) (interp l e1) (interp l e2))
  | LocallyParamIntegrable n f e =>
    let a := interp l e in
    exists eps : posreal, locally (nth R0 l n) (fun y => ex_RInt (fun t => interp (t :: set_nth R0 l n y) f) (a - eps) (a + eps))
  | And ld => foldr (fun d acc => interp_domain l d /\ acc) True ld
  | Forall e1 e2 s =>
    let a1 := interp l e1 in let a2 := interp l e2 in
    forall t, Rmin a1 a2 <= t <= Rmax a1 a2 ->
    interp_domain (t :: l) s
  | Forone e s => interp_domain (interp l e :: l) s
  | Locally n s =>
    locally (nth R0 l n) (fun x => interp_domain (set_nth R0 l n x) s)
  | Locally2 m n s =>
    locally_2d (fun x y => interp_domain (set_nth R0 (set_nth R0 l n y) m x) s) (nth R0 l m) (nth R0 l n)
  | ForallWide n e1 e2 s =>
    let a1 := interp l e1 in let a2 := interp l e2 in
    exists d : posreal,
    forall t u, Rmin a1 a2 - d < t < Rmax a1 a2 + d -> Rabs (u - nth R0 l n) < d ->
    interp_domain (t :: set_nth R0 l n u) s
  end.

Fixpoint is_const (e : expr) n : bool :=
  match e with
  | Var v => negb (ssrnat.eqn v n)
  | AppExt k f le => foldr (fun v acc => andb (is_const v n) acc) true le
  | AppExtD k f p le => false
  | App f e => andb (is_const f (S n)) (is_const e n)
  | Subst f e => andb (orb (ssrnat.eqn n 0) (is_const f n)) (is_const e n)
  | Cst _ => true
  | Binary b e1 e2 => andb (is_const e1 n) (is_const e2 n)
  | Unary u e => is_const e n
  | Int f e1 e2 => andb (is_const f (S n)) (andb (is_const e1 n) (is_const e2 n))
  end.

Lemma is_const_correct :
  forall e n, is_const e n = true ->
  forall l x1 x2,
  interp (set_nth 0 l n x1) e = interp (set_nth 0 l n x2) e.
Proof.
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 e) (interp l2 e) *)
induction e using expr_ind'.
(* *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl => k Hk l x1 x2.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2!nth_set_nth /=.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite -ssrnat.eqnE (ssrbool.negbTE Hk).
(* *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl => n Hc l x1 x2.
(* Goal: @eq R (@apply R k f (@nth R (IZR Z0) (@map expr R (interp l1) le))) (@apply R k f (@nth R (IZR Z0) (@map expr R (interp l2) le))) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (AppExtD k f n le)) (interp l2 (AppExtD k f n le)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (App e1 e2)) (interp l2 (App e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Subst e1 e2)) (interp l2 (Subst e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
apply apply_ext.
(* Goal: forall (n0 : nat) (_ : lt n0 k), @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x1)) le) n0) (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x2)) le) n0) *)
(* Goal: forall (n0 : nat) (_ : @eq bool (is_const (AppExtD k f n le) n0) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n0 x1) (AppExtD k f n le)) (interp (@set_nth R (IZR Z0) l n0 x2) (AppExtD k f n le)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (App e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (App e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (App e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Subst e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Subst e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Subst e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Cst r) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Cst r)) (interp (@set_nth R (IZR Z0) l n x2) (Cst r)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Binary o e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Binary o e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Binary o e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Unary o e) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Unary o e)) (interp (@set_nth R (IZR Z0) l n x2) (Unary o e)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Int e1 e2 e3) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Int e1 e2 e3)) (interp (@set_nth R (IZR Z0) l n x2) (Int e1 e2 e3)) *)
intros m _.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x1)) le) m) (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x2)) le) m) *)
(* Goal: forall (n0 : nat) (_ : @eq bool (is_const (AppExtD k f n le) n0) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n0 x1) (AppExtD k f n le)) (interp (@set_nth R (IZR Z0) l n0 x2) (AppExtD k f n le)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (App e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (App e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (App e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Subst e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Subst e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Subst e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Cst r) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Cst r)) (interp (@set_nth R (IZR Z0) l n x2) (Cst r)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Binary o e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Binary o e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Binary o e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Unary o e) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Unary o e)) (interp (@set_nth R (IZR Z0) l n x2) (Unary o e)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Int e1 e2 e3) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Int e1 e2 e3)) (interp (@set_nth R (IZR Z0) l n x2) (Int e1 e2 e3)) *)
revert m.
(* Goal: forall n : nat, @eq R (@nth R (IZR Z0) (@map expr R (interp l1) le) n) (@nth R (IZR Z0) (@map expr R (interp l2) le) n) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (AppExtD k f n le)) (interp l2 (AppExtD k f n le)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (App e1 e2)) (interp l2 (App e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Subst e1 e2)) (interp l2 (Subst e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
induction le.
(* Goal: forall m : nat, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x1)) (@nil expr)) m) (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x2)) (@nil expr)) m) *)
(* Goal: forall m : nat, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x1)) (@cons expr a le)) m) (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x2)) (@cons expr a le)) m) *)
(* Goal: forall (n0 : nat) (_ : @eq bool (is_const (AppExtD k f n le) n0) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n0 x1) (AppExtD k f n le)) (interp (@set_nth R (IZR Z0) l n0 x2) (AppExtD k f n le)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (App e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (App e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (App e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Subst e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Subst e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Subst e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Cst r) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Cst r)) (interp (@set_nth R (IZR Z0) l n x2) (Cst r)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Binary o e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Binary o e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Binary o e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Unary o e) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Unary o e)) (interp (@set_nth R (IZR Z0) l n x2) (Unary o e)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Int e1 e2 e3) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Int e1 e2 e3)) (interp (@set_nth R (IZR Z0) l n x2) (Int e1 e2 e3)) *)
intros m.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite nth_nil.
(* Goal: forall m : nat, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x1)) (@cons expr a le)) m) (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x2)) (@cons expr a le)) m) *)
(* Goal: forall (n0 : nat) (_ : @eq bool (is_const (AppExtD k f n le) n0) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n0 x1) (AppExtD k f n le)) (interp (@set_nth R (IZR Z0) l n0 x2) (AppExtD k f n le)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (App e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (App e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (App e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Subst e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Subst e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Subst e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Cst r) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Cst r)) (interp (@set_nth R (IZR Z0) l n x2) (Cst r)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Binary o e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Binary o e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Binary o e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Unary o e) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Unary o e)) (interp (@set_nth R (IZR Z0) l n x2) (Unary o e)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Int e1 e2 e3) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Int e1 e2 e3)) (interp (@set_nth R (IZR Z0) l n x2) (Int e1 e2 e3)) *)
apply andb_prop in Hc.
(* Goal: forall m : nat, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x1)) (@cons expr a le)) m) (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x2)) (@cons expr a le)) m) *)
(* Goal: forall (n0 : nat) (_ : @eq bool (is_const (AppExtD k f n le) n0) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n0 x1) (AppExtD k f n le)) (interp (@set_nth R (IZR Z0) l n0 x2) (AppExtD k f n le)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (App e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (App e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (App e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Subst e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Subst e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Subst e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Cst r) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Cst r)) (interp (@set_nth R (IZR Z0) l n x2) (Cst r)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Binary o e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Binary o e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Binary o e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Unary o e) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Unary o e)) (interp (@set_nth R (IZR Z0) l n x2) (Unary o e)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Int e1 e2 e3) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Int e1 e2 e3)) (interp (@set_nth R (IZR Z0) l n x2) (Int e1 e2 e3)) *)
intros [|m].
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
(* Goal: interp_domain (@cons R t l1) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
now apply H.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x1)) le) m) (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x2)) le) m) *)
(* Goal: forall (n0 : nat) (_ : @eq bool (is_const (AppExtD k f n le) n0) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n0 x1) (AppExtD k f n le)) (interp (@set_nth R (IZR Z0) l n0 x2) (AppExtD k f n le)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (App e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (App e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (App e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Subst e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Subst e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Subst e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Cst r) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Cst r)) (interp (@set_nth R (IZR Z0) l n x2) (Cst r)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Binary o e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Binary o e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Binary o e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Unary o e) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Unary o e)) (interp (@set_nth R (IZR Z0) l n x2) (Unary o e)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Int e1 e2 e3) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Int e1 e2 e3)) (interp (@set_nth R (IZR Z0) l n x2) (Int e1 e2 e3)) *)
apply IHle.
(* Goal: @foldr expr Prop (fun (e : expr) (acc : Prop) => and (forall (n : nat) (_ : @eq bool (is_const e n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) e) (interp (@set_nth R (IZR Z0) l n x2) e)) acc) True le *)
(* Goal: @eq bool (@foldr expr bool (fun (v : expr) (acc : bool) => andb (is_const v n) acc) true le) true *)
(* Goal: forall (n0 : nat) (_ : @eq bool (is_const (AppExtD k f n le) n0) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n0 x1) (AppExtD k f n le)) (interp (@set_nth R (IZR Z0) l n0 x2) (AppExtD k f n le)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (App e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (App e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (App e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Subst e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Subst e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Subst e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Cst r) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Cst r)) (interp (@set_nth R (IZR Z0) l n x2) (Cst r)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Binary o e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Binary o e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Binary o e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Unary o e) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Unary o e)) (interp (@set_nth R (IZR Z0) l n x2) (Unary o e)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Int e1 e2 e3) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Int e1 e2 e3)) (interp (@set_nth R (IZR Z0) l n x2) (Int e1 e2 e3)) *)
apply H.
(* Goal: @eq bool (@foldr expr bool (fun (v : expr) (acc : bool) => andb (is_const v n) acc) true le) true *)
(* Goal: forall (n0 : nat) (_ : @eq bool (is_const (AppExtD k f n le) n0) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n0 x1) (AppExtD k f n le)) (interp (@set_nth R (IZR Z0) l n0 x2) (AppExtD k f n le)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (App e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (App e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (App e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Subst e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Subst e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Subst e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Cst r) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Cst r)) (interp (@set_nth R (IZR Z0) l n x2) (Cst r)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Binary o e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Binary o e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Binary o e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Unary o e) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Unary o e)) (interp (@set_nth R (IZR Z0) l n x2) (Unary o e)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Int e1 e2 e3) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Int e1 e2 e3)) (interp (@set_nth R (IZR Z0) l n x2) (Int e1 e2 e3)) *)
apply Hc.
(* *)
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.
(* *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl => n.
(* Goal: forall (_ : is_true (andb (is_const e2 n) (is_const e3 n))) (l : list R) (x1 x2 : R), @eq R (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x1)) e1) (interp (@set_nth R (IZR Z0) l n x1) e2) (interp (@set_nth R (IZR Z0) l n x1) e3)) (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x2)) e1) (interp (@set_nth R (IZR Z0) l n x2) e2) (interp (@set_nth R (IZR Z0) l n x2) e3)) *)
move /ssrbool.andP => [H1 H2] l x1 x2.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite (IHe2 n H2 l x1 x2).
(* Goal: @eq R (interp (@cons R (interp (@set_nth R (IZR Z0) l n x2) e2) (@set_nth R (IZR Z0) l n x1)) e1) (interp (@cons R (interp (@set_nth R (IZR Z0) l n x2) e2) (@set_nth R (IZR Z0) l n x2)) e1) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Subst e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Subst e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Subst e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Cst r) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Cst r)) (interp (@set_nth R (IZR Z0) l n x2) (Cst r)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Binary o e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Binary o e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Binary o e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Unary o e) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Unary o e)) (interp (@set_nth R (IZR Z0) l n x2) (Unary o e)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Int e1 e2 e3) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Int e1 e2 e3)) (interp (@set_nth R (IZR Z0) l n x2) (Int e1 e2 e3)) *)
now apply: (IHe1 (S n) _ (interp (set_nth 0 l n x2) e2 :: l)).
(* *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Subst e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Subst e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Subst e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Cst r) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Cst r)) (interp (@set_nth R (IZR Z0) l n x2) (Cst r)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Binary o e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Binary o e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Binary o e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Unary o e) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Unary o e)) (interp (@set_nth R (IZR Z0) l n x2) (Unary o e)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Int e1 e2 e3) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Int e1 e2 e3)) (interp (@set_nth R (IZR Z0) l n x2) (Int e1 e2 e3)) *)
intros n.
(* Goal: forall (_ : @eq bool (is_const (Subst e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Subst e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Subst e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Cst r) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Cst r)) (interp (@set_nth R (IZR Z0) l n x2) (Cst r)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Binary o e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Binary o e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Binary o e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Unary o e) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Unary o e)) (interp (@set_nth R (IZR Z0) l n x2) (Unary o e)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Int e1 e2 e3) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Int e1 e2 e3)) (interp (@set_nth R (IZR Z0) l n x2) (Int e1 e2 e3)) *)
simpl is_const.
(* Goal: forall (_ : is_true (andb (is_const e2 n) (is_const e3 n))) (l : list R) (x1 x2 : R), @eq R (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x1)) e1) (interp (@set_nth R (IZR Z0) l n x1) e2) (interp (@set_nth R (IZR Z0) l n x1) e3)) (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x2)) e1) (interp (@set_nth R (IZR Z0) l n x2) e2) (interp (@set_nth R (IZR Z0) l n x2) e3)) *)
move /ssrbool.andP => [H1 H2] l x1 x2.
change (interp (set_nth 0 (set_nth 0 l n x1) 0 (interp (set_nth 0 l n x1) e2)) e1 =
  interp (set_nth 0 (set_nth 0 l n x2) 0 (interp (set_nth 0 l n x2) e2)) e1).
(* Goal: forall (_ : is_true (andb (is_const e2 n) (is_const e3 n))) (l : list R) (x1 x2 : R), @eq R (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x1)) e1) (interp (@set_nth R (IZR Z0) l n x1) e2) (interp (@set_nth R (IZR Z0) l n x1) e3)) (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x2)) e1) (interp (@set_nth R (IZR Z0) l n x2) e2) (interp (@set_nth R (IZR Z0) l n x2) e3)) *)
move: H1.
replace (orb (ssrnat.eqn n 0) (is_const e1 n)) with
  (orb (ssrnat.eqn n 0) (andb (negb (ssrnat.eqn n 0)) (is_const e1 n))).
(* Goal: forall (_ : is_true (andb (is_const e2 n) (is_const e3 n))) (l : list R) (x1 x2 : R), @eq R (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x1)) e1) (interp (@set_nth R (IZR Z0) l n x1) e2) (interp (@set_nth R (IZR Z0) l n x1) e3)) (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x2)) e1) (interp (@set_nth R (IZR Z0) l n x2) e2) (interp (@set_nth R (IZR Z0) l n x2) e3)) *)
move /ssrbool.orP => [H1|].
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite set_set_nth (set_set_nth 0 l n x2).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -ssrnat.eqnE H1.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite (IHe2 n H2 l x1 x2).
(* Goal: forall (_ : is_true (andb (is_const e2 n) (is_const e3 n))) (l : list R) (x1 x2 : R), @eq R (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x1)) e1) (interp (@set_nth R (IZR Z0) l n x1) e2) (interp (@set_nth R (IZR Z0) l n x1) e3)) (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x2)) e1) (interp (@set_nth R (IZR Z0) l n x2) e2) (interp (@set_nth R (IZR Z0) l n x2) e3)) *)
move /ssrbool.andP => [H1 H3].
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite set_set_nth (set_set_nth 0 l n x2).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -ssrnat.eqnE (ssrbool.negbTE H1).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite (IHe2 n H2 l x1 x2).
(* Goal: @eq R (interp l1 e1) (interp l2 e1) *)
(* Goal: @eq R (interp l1 e2) (interp l2 e2) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply IHe1.
(* Goal: @eq bool (orb (ssrnat.eqn n O) (andb (negb (ssrnat.eqn n O)) (is_const e1 n))) (orb (ssrnat.eqn n O) (is_const e1 n)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Cst r) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Cst r)) (interp (@set_nth R (IZR Z0) l n x2) (Cst r)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Binary o e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Binary o e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Binary o e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Unary o e) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Unary o e)) (interp (@set_nth R (IZR Z0) l n x2) (Unary o e)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Int e1 e2 e3) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Int e1 e2 e3)) (interp (@set_nth R (IZR Z0) l n x2) (Int e1 e2 e3)) *)
now case (ssrnat.eqn n 0).
(* *)
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.
(* *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl => n.
(* Goal: forall (_ : is_true (andb (is_const e2 n) (is_const e3 n))) (l : list R) (x1 x2 : R), @eq R (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x1)) e1) (interp (@set_nth R (IZR Z0) l n x1) e2) (interp (@set_nth R (IZR Z0) l n x1) e3)) (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x2)) e1) (interp (@set_nth R (IZR Z0) l n x2) e2) (interp (@set_nth R (IZR Z0) l n x2) e3)) *)
move /ssrbool.andP => [H1 H2] l x1 x2.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite (IHe1 n H1 l x1 x2) (IHe2 n H2 l x1 x2).
(* *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl => n H l x1 x2.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite (IHe n H l x1 x2).
(* *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl => n.
(* Goal: forall (_ : is_true (andb (is_const e2 n) (is_const e3 n))) (l : list R) (x1 x2 : R), @eq R (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x1)) e1) (interp (@set_nth R (IZR Z0) l n x1) e2) (interp (@set_nth R (IZR Z0) l n x1) e3)) (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x2)) e1) (interp (@set_nth R (IZR Z0) l n x2) e2) (interp (@set_nth R (IZR Z0) l n x2) e3)) *)
move /ssrbool.andP => [H1].
(* Goal: forall (_ : is_true (andb (is_const e2 n) (is_const e3 n))) (l : list R) (x1 x2 : R), @eq R (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x1)) e1) (interp (@set_nth R (IZR Z0) l n x1) e2) (interp (@set_nth R (IZR Z0) l n x1) e3)) (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x2)) e1) (interp (@set_nth R (IZR Z0) l n x2) e2) (interp (@set_nth R (IZR Z0) l n x2) e3)) *)
move /ssrbool.andP => [H2 H3] l x1 x2.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite (IHe2 n H2 l x1 x2) (IHe3 n H3 l x1 x2).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply RInt_ext => x _.
(* Goal: @eq (CompleteNormedModule.sort R_AbsRing R_CompleteNormedModule) (interp (@cons R x (@set_nth R (IZR Z0) l n x1)) e1) (interp (@cons R x (@set_nth R (IZR Z0) l n x2)) e1) *)
apply (IHe1 _ H1 (x :: l)).
Qed.

Lemma nth_map' :
  forall {T1} x1 {T2} (f : T1 -> T2) n s,
  nth (f x1) (map f s) n = f (nth x1 s n).
Proof.
(* Goal: forall (T1 : Type) (x1 : T1) (T2 : Type) (f : forall _ : T1, T2) (n : nat) (s : list T1), @eq T2 (@nth T2 (f x1) (@map T1 T2 f s) n) (f (@nth T1 x1 s n)) *)
intros T1 x T2 f n s.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case (ssrnat.leqP (size s) n) => Hs.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2?nth_default ?size_map //.
(* Goal: @eq T2 (@nth T2 (f x) (@map T1 T2 f s) n) (f (@nth T1 x s n)) *)
now apply nth_map.
Qed.

Lemma interp_ext :
  forall l1 l2 e,
  (forall k, nth 0 l1 k = nth 0 l2 k) ->
  interp l1 e = interp l2 e.
Proof.
(* Goal: forall (l1 l2 : list R) (e : expr) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 e) (interp l2 e) *)
intros l1 l2 e Hl.
(* Goal: forall _ : interp_domain l1 b, interp_domain l2 b *)
revert l1 l2 Hl.
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 e) (interp l2 e) *)
induction e using expr_ind'.
(* *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Var n)) (interp l2 (Var n)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (AppExt k f le)) (interp l2 (AppExt k f le)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (AppExtD k f n le)) (interp l2 (AppExtD k f n le)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (App e1 e2)) (interp l2 (App e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Subst e1 e2)) (interp l2 (Subst e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now simpl => l1 l2 Hl.
(* *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl => l1 l2 Hl.
(* Goal: @eq R (@apply R k f (@nth R (IZR Z0) (@map expr R (interp l1) le))) (@apply R k f (@nth R (IZR Z0) (@map expr R (interp l2) le))) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (AppExtD k f n le)) (interp l2 (AppExtD k f n le)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (App e1 e2)) (interp l2 (App e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Subst e1 e2)) (interp l2 (Subst e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
apply apply_ext.
(* Goal: forall (n : nat) (_ : lt n k), @eq R (@nth R (IZR Z0) (@map expr R (interp l1) le) n) (@nth R (IZR Z0) (@map expr R (interp l2) le) n) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (AppExtD k f n le)) (interp l2 (AppExtD k f n le)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (App e1 e2)) (interp l2 (App e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Subst e1 e2)) (interp l2 (Subst e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
intros n _.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp l1) le) n) (@nth R (IZR Z0) (@map expr R (interp l2) le) n) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (AppExtD k f n le)) (interp l2 (AppExtD k f n le)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (App e1 e2)) (interp l2 (App e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Subst e1 e2)) (interp l2 (Subst e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
revert n.
(* Goal: forall n : nat, @eq R (@nth R (IZR Z0) (@map expr R (interp l1) le) n) (@nth R (IZR Z0) (@map expr R (interp l2) le) n) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (AppExtD k f n le)) (interp l2 (AppExtD k f n le)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (App e1 e2)) (interp l2 (App e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Subst e1 e2)) (interp l2 (Subst e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
induction le.
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True (@cons domain a ld), @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True (@cons domain a ld) *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
simpl in H |- *.
(* Goal: forall n : nat, @eq R (@nth R (IZR Z0) (@cons R (interp l1 a) (@map expr R (interp l1) le)) n) (@nth R (IZR Z0) (@cons R (interp l2 a) (@map expr R (interp l2) le)) n) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (AppExtD k f n le)) (interp l2 (AppExtD k f n le)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (App e1 e2)) (interp l2 (App e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Subst e1 e2)) (interp l2 (Subst e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
destruct H as (Ha,Hb).
(* Goal: forall n : nat, @eq R (@nth R (IZR Z0) (@cons R (interp l1 a) (@map expr R (interp l1) le)) n) (@nth R (IZR Z0) (@cons R (interp l2 a) (@map expr R (interp l2) le)) n) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (AppExtD k f n le)) (interp l2 (AppExtD k f n le)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (App e1 e2)) (interp l2 (App e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Subst e1 e2)) (interp l2 (Subst e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
intros [|n].
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
(* Goal: @eq R (interp l1 a) (interp l2 a) *)
(* Goal: @eq R (@nth R (IZR Z0) (@cons R (interp l1 a) (@map expr R (interp l1) le)) (S n)) (@nth R (IZR Z0) (@cons R (interp l2 a) (@map expr R (interp l2) le)) (S n)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (AppExtD k f n le)) (interp l2 (AppExtD k f n le)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (App e1 e2)) (interp l2 (App e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Subst e1 e2)) (interp l2 (Subst e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply Ha.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x1)) le) m) (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x2)) le) m) *)
(* Goal: forall (n0 : nat) (_ : @eq bool (is_const (AppExtD k f n le) n0) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n0 x1) (AppExtD k f n le)) (interp (@set_nth R (IZR Z0) l n0 x2) (AppExtD k f n le)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (App e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (App e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (App e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Subst e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Subst e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Subst e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Cst r) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Cst r)) (interp (@set_nth R (IZR Z0) l n x2) (Cst r)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Binary o e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Binary o e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Binary o e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Unary o e) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Unary o e)) (interp (@set_nth R (IZR Z0) l n x2) (Unary o e)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Int e1 e2 e3) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Int e1 e2 e3)) (interp (@set_nth R (IZR Z0) l n x2) (Int e1 e2 e3)) *)
now apply IHle.
(* *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl => l1 l2 Hl.
(* Goal: @eq R (Derive_Rn k f n (@nth R (IZR Z0) (@map expr R (interp l1) le))) (Derive_Rn k f n (@nth R (IZR Z0) (@map expr R (interp l2) le))) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (App e1 e2)) (interp l2 (App e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Subst e1 e2)) (interp l2 (Subst e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
unfold Derive_Rn.
(* Goal: @eq R (Derive (fun x : R => @apply R k f (fun i : nat => if ssrnat.eqn i n then x else @nth R (IZR Z0) (@map expr R (interp l1) le) i)) (@nth R (IZR Z0) (@map expr R (interp l1) le) n)) (Derive (fun x : R => @apply R k f (fun i : nat => if ssrnat.eqn i n then x else @nth R (IZR Z0) (@map expr R (interp l2) le) i)) (@nth R (IZR Z0) (@map expr R (interp l2) le) n)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (App e1 e2)) (interp l2 (App e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Subst e1 e2)) (interp l2 (Subst e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
assert (Hn: forall n, nth 0 (map (interp l1) le) n = nth 0 (map (interp l2) le) n).
(* Goal: forall n : nat, @eq R (@nth R (IZR Z0) (@map expr R (interp l1) le) n) (@nth R (IZR Z0) (@map expr R (interp l2) le) n) *)
(* Goal: @eq R (Derive (fun x : R => @apply R k f (fun i : nat => if ssrnat.eqn i n then x else @nth R (IZR Z0) (@map expr R (interp l1) le) i)) (@nth R (IZR Z0) (@map expr R (interp l1) le) n)) (Derive (fun x : R => @apply R k f (fun i : nat => if ssrnat.eqn i n then x else @nth R (IZR Z0) (@map expr R (interp l2) le) i)) (@nth R (IZR Z0) (@map expr R (interp l2) le) n)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (App e1 e2)) (interp l2 (App e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Subst e1 e2)) (interp l2 (Subst e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
intros p.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite (nth_map' (Cst 0) (interp l1)) (nth_map' (Cst 0) (interp l2)).
(* Goal: @eq R (interp l1 (@nth expr (Cst (IZR Z0)) le p)) (interp l2 (@nth expr (Cst (IZR Z0)) le p)) *)
(* Goal: @eq R (Derive (fun x : R => @apply R k f (fun i : nat => if ssrnat.eqn i n then x else @nth R (IZR Z0) (@map expr R (interp l1) le) i)) (@nth R (IZR Z0) (@map expr R (interp l1) le) n)) (Derive (fun x : R => @apply R k f (fun i : nat => if ssrnat.eqn i n then x else @nth R (IZR Z0) (@map expr R (interp l2) le) i)) (@nth R (IZR Z0) (@map expr R (interp l2) le) n)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (App e1 e2)) (interp l2 (App e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Subst e1 e2)) (interp l2 (Subst e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply (foldr_prop_nth _ _ _ H).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite Hn.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply Derive_ext => t.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply apply_ext => p Hp.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite Hn.
(* *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl => l1 l2 Hl.
(* Goal: @eq (CompleteNormedModule.sort R_AbsRing R_CompleteNormedModule) (interp (@cons R x l1) e1) (interp (@cons R x l2) e1) *)
apply IHe1.
(* Goal: forall k : nat, @eq R (@nth R (IZR Z0) (@cons R t (@set_nth R R0 l1 n u)) k) (@nth R (IZR Z0) (@cons R t (@set_nth R R0 l2 n u)) k) *)
intros [|k].
(* Goal: @eq R (interp l1 e2) (interp l2 e2) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply IHe2.
(* Goal: @eq R (@nth R (IZR Z0) (@cons R (interp l1 e) l1) (S k)) (@nth R (IZR Z0) (@cons R (interp l2 e) l2) (S k)) *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
apply Hl.
(* *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Subst e1 e2)) (interp l2 (Subst e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
intros l1 l2 Hl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite /interp -/interp.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply IHe1 => k.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2!nth_set_nth /=.
(* Goal: @eq R (if @eqtype.eq_op ssrnat.nat_eqType k O then interp l1 e2 else @nth R (IZR Z0) l1 k) (if @eqtype.eq_op ssrnat.nat_eqType k O then interp l2 e2 else @nth R (IZR Z0) l2 k) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
case eqtype.eq_op.
(* Goal: @eq R (interp l1 e2) (interp l2 e2) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply IHe2.
(* Goal: @eq R (@nth R (IZR Z0) (@cons R (interp l1 e) l1) (S k)) (@nth R (IZR Z0) (@cons R (interp l2 e) l2) (S k)) *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
apply Hl.
(* *)
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.
(* *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl => l1 l2 Hl.
(* Goal: @eq R (match o with | Eplus => Rplus | Emult => Rmult end (interp l1 e1) (interp l1 e2)) (match o with | Eplus => Rplus | Emult => Rmult end (interp l2 e1) (interp l2 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
apply f_equal2.
(* Goal: @eq R (interp l1 e1) (interp l2 e1) *)
(* Goal: @eq R (interp l1 e2) (interp l2 e2) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply IHe1.
(* Goal: @eq R (interp l1 e2) (interp l2 e2) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply IHe2.
(* *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl => l1 l2 Hl.
(* Goal: @eq R (match o with | Eopp => Ropp | Einv => Rinv | Efct f f' H => f | Efct' f f' df H => f end (interp l1 e)) (match o with | Eopp => Ropp | Einv => Rinv | Efct f f' H => f | Efct' f f' df H => f end (interp l2 e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
apply f_equal.
(* Goal: @eq R (interp l1 e) (interp l2 e) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply IHe.
(* *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl => l1 l2 Hl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite (IHe2 l1 l2 Hl) (IHe3 l1 l2 Hl).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply RInt_ext => x _.
(* Goal: @eq (CompleteNormedModule.sort R_AbsRing R_CompleteNormedModule) (interp (@cons R x l1) e1) (interp (@cons R x l2) e1) *)
apply IHe1.
(* Goal: forall k : nat, @eq R (@nth R (IZR Z0) (@cons R t (@set_nth R R0 l1 n u)) k) (@nth R (IZR Z0) (@cons R t (@set_nth R R0 l2 n u)) k) *)
intros [|k].
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.
(* Goal: @eq R (@nth R (IZR Z0) (@cons R (interp l1 e) l1) (S k)) (@nth R (IZR Z0) (@cons R (interp l2 e) l2) (S k)) *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
apply Hl.
Qed.

Lemma interp_set_nth :
  forall n l e,
  interp (set_nth 0 l n (nth 0 l n)) e = interp l e.
Proof.
(* Goal: forall (n : nat) (l : list R) (e : expr), @eq R (interp (@set_nth R (IZR Z0) l n (@nth R (IZR Z0) l n)) e) (interp l e) *)
intros n l e.
(* Goal: @eq (NormedModule.sort R_AbsRing R_NormedModule) (interp (@cons R x (@set_nth R R0 l1 n y)) f) (interp (@cons R x (@set_nth R R0 l2 n y)) f) *)
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True ld, @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
apply interp_ext.
(* Goal: forall k : nat, @eq R (@nth R (IZR Z0) (@set_nth R (IZR Z0) l n (@nth R (IZR Z0) l n)) k) (@nth R (IZR Z0) l k) *)
intros k.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite nth_set_nth /=.
(* Goal: @eq R (@nth R (IZR Z0) l k) (if @eqtype.eq_op ssrnat.nat_eqType k n then @nth R (IZR Z0) l n else @nth R (IZR Z0) l k) *)
case ssrnat.eqnP.
(* Goal: forall _ : @eq nat k n, @eq R (@nth R (IZR Z0) l k) (@nth R (IZR Z0) l n) *)
(* Goal: forall _ : not (@eq nat k n), @eq R (@nth R (IZR Z0) l k) (@nth R (IZR Z0) l k) *)
intros H.
(* Goal: @eq R (match o with | Eopp => Ropp | Einv => Rinv | Efct f f' H => f | Efct' f f' df H => f end (interp l1 e)) (match o with | Eopp => Ropp | Einv => Rinv | Efct f f' H => f | Efct' f f' df H => f end (interp l2 e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply f_equal.
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.
Qed.

Lemma interp_domain_ext :
  forall l1 l2 b,
  (forall k, nth 0 l1 k = nth 0 l2 k) ->
  interp_domain l1 b -> interp_domain l2 b.
Proof.
(* Goal: forall (l1 l2 : list R) (b : domain) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)) (_ : interp_domain l1 b), interp_domain l2 b *)
intros l1 l2 b Hl.
(* Goal: forall _ : interp_domain l1 b, interp_domain l2 b *)
revert l1 l2 Hl.
induction b using domain_ind' ; try easy ;
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
  simpl => l1 l2 Hl.
(* *)
(* Goal: forall _ : p (interp l1 e), p (interp l2 e) *)
(* Goal: forall _ : ex_derive_Rn k f n (@nth R (IZR Z0) (@map expr R (interp l1) le)), ex_derive_Rn k f n (@nth R (IZR Z0) (@map expr R (interp l2) le)) *)
(* Goal: forall _ : and (locally_2d (fun u v : R => ex_derive_Rn k f m (fun i : nat => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else @nth R (IZR Z0) (@map expr R (interp l1) le) i)) (@nth R (IZR Z0) (@map expr R (interp l1) le) m) (@nth R (IZR Z0) (@map expr R (interp l1) le) n)) (continuity_2d_pt (fun u v : R => Derive_Rn k f m (fun i : nat => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else @nth R (IZR Z0) (@map expr R (interp l1) le) i)) (@nth R (IZR Z0) (@map expr R (interp l1) le) m) (@nth R (IZR Z0) (@map expr R (interp l1) le) n)), and (locally_2d (fun u v : R => ex_derive_Rn k f m (fun i : nat => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else @nth R (IZR Z0) (@map expr R (interp l2) le) i)) (@nth R (IZR Z0) (@map expr R (interp l2) le) m) (@nth R (IZR Z0) (@map expr R (interp l2) le) n)) (continuity_2d_pt (fun u v : R => Derive_Rn k f m (fun i : nat => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else @nth R (IZR Z0) (@map expr R (interp l2) le) i)) (@nth R (IZR Z0) (@map expr R (interp l2) le) m) (@nth R (IZR Z0) (@map expr R (interp l2) le) n)) *)
(* Goal: forall _ : continuity_pt (fun x : R => interp (@set_nth R R0 l1 n x) e) (@nth R R0 l1 n), continuity_pt (fun x : R => interp (@set_nth R R0 l2 n x) e) (@nth R R0 l2 n) *)
(* Goal: forall _ : continuity_2d_pt (fun x y : R => interp (@set_nth R R0 (@set_nth R R0 l1 n y) m x) e) (@nth R R0 l1 m) (@nth R R0 l1 n), continuity_2d_pt (fun x y : R => interp (@set_nth R R0 (@set_nth R R0 l2 n y) m x) e) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex_RInt R_NormedModule (fun x : R => interp (@cons R x l1) f) (interp l1 e1) (interp l1 e2), @ex_RInt R_NormedModule (fun x : R => interp (@cons R x l2) f) (interp l2 e1) (interp l2 e2) *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l1 n y)) f) (interp l1 e1) (interp l1 e2)), @locally R_UniformSpace (@nth R R0 l2 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l2 n y)) f) (interp l2 e1) (interp l2 e2)) *)
(* Goal: forall _ : @ex posreal (fun eps : posreal => @locally R_UniformSpace (@nth R R0 l1 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l1 n y)) f) (Rminus (interp l1 e) (pos eps)) (Rplus (interp l1 e) (pos eps)))), @ex posreal (fun eps : posreal => @locally R_UniformSpace (@nth R R0 l2 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l2 n y)) f) (Rminus (interp l2 e) (pos eps)) (Rplus (interp l2 e) (pos eps)))) *)
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True ld, @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
by rewrite (interp_ext _ _ _ Hl).
(* *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite -(eq_map (fun e => interp_ext _ _ e Hl)).
(* *)
(* Goal: forall _ : and (locally_2d (fun u v : R => ex_derive_Rn k f m (fun i : nat => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else @nth R (IZR Z0) (@map expr R (interp l1) le) i)) (@nth R (IZR Z0) (@map expr R (interp l1) le) m) (@nth R (IZR Z0) (@map expr R (interp l1) le) n)) (continuity_2d_pt (fun u v : R => Derive_Rn k f m (fun i : nat => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else @nth R (IZR Z0) (@map expr R (interp l1) le) i)) (@nth R (IZR Z0) (@map expr R (interp l1) le) m) (@nth R (IZR Z0) (@map expr R (interp l1) le) n)), and (locally_2d (fun u v : R => ex_derive_Rn k f m (fun i : nat => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else @nth R (IZR Z0) (@map expr R (interp l2) le) i)) (@nth R (IZR Z0) (@map expr R (interp l2) le) m) (@nth R (IZR Z0) (@map expr R (interp l2) le) n)) (continuity_2d_pt (fun u v : R => Derive_Rn k f m (fun i : nat => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else @nth R (IZR Z0) (@map expr R (interp l2) le) i)) (@nth R (IZR Z0) (@map expr R (interp l2) le) m) (@nth R (IZR Z0) (@map expr R (interp l2) le) n)) *)
(* Goal: forall _ : continuity_pt (fun x : R => interp (@set_nth R R0 l1 n x) e) (@nth R R0 l1 n), continuity_pt (fun x : R => interp (@set_nth R R0 l2 n x) e) (@nth R R0 l2 n) *)
(* Goal: forall _ : continuity_2d_pt (fun x y : R => interp (@set_nth R R0 (@set_nth R R0 l1 n y) m x) e) (@nth R R0 l1 m) (@nth R R0 l1 n), continuity_2d_pt (fun x y : R => interp (@set_nth R R0 (@set_nth R R0 l2 n y) m x) e) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex_RInt R_NormedModule (fun x : R => interp (@cons R x l1) f) (interp l1 e1) (interp l1 e2), @ex_RInt R_NormedModule (fun x : R => interp (@cons R x l2) f) (interp l2 e1) (interp l2 e2) *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l1 n y)) f) (interp l1 e1) (interp l1 e2)), @locally R_UniformSpace (@nth R R0 l2 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l2 n y)) f) (interp l2 e1) (interp l2 e2)) *)
(* Goal: forall _ : @ex posreal (fun eps : posreal => @locally R_UniformSpace (@nth R R0 l1 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l1 n y)) f) (Rminus (interp l1 e) (pos eps)) (Rplus (interp l1 e) (pos eps)))), @ex posreal (fun eps : posreal => @locally R_UniformSpace (@nth R R0 l2 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l2 n y)) f) (Rminus (interp l2 e) (pos eps)) (Rplus (interp l2 e) (pos eps)))) *)
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True ld, @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
intros Hb.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite -(eq_map (fun e => interp_ext _ _ e Hl)).
(* *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite Hl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply continuity_pt_ext => x.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply interp_ext => k.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2!nth_set_nth /=.
(* Goal: @eq R (if @eqtype.eq_op ssrnat.nat_eqType k O then interp l1 e2 else @nth R (IZR Z0) l1 k) (if @eqtype.eq_op ssrnat.nat_eqType k O then interp l2 e2 else @nth R (IZR Z0) l2 k) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now case eqtype.eq_op.
(* *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2!Hl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply continuity_2d_pt_ext => x y.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply interp_ext => k.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2!nth_set_nth /=.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case eqtype.eq_op => //.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2!nth_set_nth /=.
(* Goal: @eq R (if @eqtype.eq_op ssrnat.nat_eqType k O then interp l1 e2 else @nth R (IZR Z0) l1 k) (if @eqtype.eq_op ssrnat.nat_eqType k O then interp l2 e2 else @nth R (IZR Z0) l2 k) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now case eqtype.eq_op.
(* *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2!(interp_ext _ _ _ Hl).
(* Goal: forall _ : @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l1 n y)) f) (Rminus (interp l2 e) (pos d)) (Rplus (interp l2 e) (pos d)), @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l2 n y)) f) (Rminus (interp l2 e) (pos d)) (Rplus (interp l2 e) (pos d)) *)
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True ld, @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
apply ex_RInt_ext.
(* Goal: forall (x : R) (_ : and (Rlt (Rmin (Rminus (interp l2 e) (pos d)) (Rplus (interp l2 e) (pos d))) x) (Rlt x (Rmax (Rminus (interp l2 e) (pos d)) (Rplus (interp l2 e) (pos d))))), @eq (NormedModule.sort R_AbsRing R_NormedModule) (interp (@cons R x (@set_nth R R0 l1 n y)) f) (interp (@cons R x (@set_nth R R0 l2 n y)) f) *)
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True ld, @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
intros x _.
(* Goal: @eq (NormedModule.sort R_AbsRing R_NormedModule) (interp (@cons R x (@set_nth R R0 l1 n y)) f) (interp (@cons R x (@set_nth R R0 l2 n y)) f) *)
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True ld, @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
apply interp_ext.
(* Goal: forall k : nat, @eq R (@nth R (IZR Z0) (@cons R t (@set_nth R R0 l1 n u)) k) (@nth R (IZR Z0) (@cons R t (@set_nth R R0 l2 n u)) k) *)
intros [|k].
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.
(* Goal: @eq R (@nth R (IZR Z0) (@cons R (interp l1 e) l1) (S k)) (@nth R (IZR Z0) (@cons R (interp l2 e) l2) (S k)) *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
apply Hl.
(* *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite Hl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply filter_imp => y.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2!(interp_ext _ _ _ Hl).
(* Goal: forall _ : @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l1 n y)) f) (Rminus (interp l2 e) (pos d)) (Rplus (interp l2 e) (pos d)), @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l2 n y)) f) (Rminus (interp l2 e) (pos d)) (Rplus (interp l2 e) (pos d)) *)
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True ld, @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
apply ex_RInt_ext.
(* Goal: forall (x : R) (_ : and (Rlt (Rmin (Rminus (interp l2 e) (pos d)) (Rplus (interp l2 e) (pos d))) x) (Rlt x (Rmax (Rminus (interp l2 e) (pos d)) (Rplus (interp l2 e) (pos d))))), @eq (NormedModule.sort R_AbsRing R_NormedModule) (interp (@cons R x (@set_nth R R0 l1 n y)) f) (interp (@cons R x (@set_nth R R0 l2 n y)) f) *)
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True ld, @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
intros x _.
(* Goal: @eq (NormedModule.sort R_AbsRing R_NormedModule) (interp (@cons R x (@set_nth R R0 l1 n y)) f) (interp (@cons R x (@set_nth R R0 l2 n y)) f) *)
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True ld, @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
apply interp_ext.
(* Goal: forall k : nat, @eq R (@nth R (IZR Z0) (@cons R t (@set_nth R R0 l1 n u)) k) (@nth R (IZR Z0) (@cons R t (@set_nth R R0 l2 n u)) k) *)
intros [|k].
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite /= 2!nth_set_nth /= Hl.
(* *)
(* Goal: forall _ : @ex posreal (fun eps : posreal => @locally R_UniformSpace (@nth R R0 l1 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l1 n y)) f) (Rminus (interp l1 e) (pos eps)) (Rplus (interp l1 e) (pos eps)))), @ex posreal (fun eps : posreal => @locally R_UniformSpace (@nth R R0 l2 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l2 n y)) f) (Rminus (interp l2 e) (pos eps)) (Rplus (interp l2 e) (pos eps)))) *)
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True ld, @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
intros (d,H).
(* Goal: @ex posreal (fun eps : posreal => @locally R_UniformSpace (@nth R R0 l2 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l2 n y)) f) (Rminus (interp l2 e) (pos eps)) (Rplus (interp l2 e) (pos eps)))) *)
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True ld, @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
exists d.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -Hl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
move: H ; apply filter_imp => y.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite (interp_ext _ _ _ Hl).
(* Goal: forall _ : @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l1 n y)) f) (Rminus (interp l2 e) (pos d)) (Rplus (interp l2 e) (pos d)), @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l2 n y)) f) (Rminus (interp l2 e) (pos d)) (Rplus (interp l2 e) (pos d)) *)
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True ld, @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
apply ex_RInt_ext.
(* Goal: forall (x : R) (_ : and (Rlt (Rmin (Rminus (interp l2 e) (pos d)) (Rplus (interp l2 e) (pos d))) x) (Rlt x (Rmax (Rminus (interp l2 e) (pos d)) (Rplus (interp l2 e) (pos d))))), @eq (NormedModule.sort R_AbsRing R_NormedModule) (interp (@cons R x (@set_nth R R0 l1 n y)) f) (interp (@cons R x (@set_nth R R0 l2 n y)) f) *)
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True ld, @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
intros x _.
(* Goal: @eq (NormedModule.sort R_AbsRing R_NormedModule) (interp (@cons R x (@set_nth R R0 l1 n y)) f) (interp (@cons R x (@set_nth R R0 l2 n y)) f) *)
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True ld, @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
apply interp_ext.
(* Goal: forall k : nat, @eq R (@nth R (IZR Z0) (@cons R t (@set_nth R R0 l1 n u)) k) (@nth R (IZR Z0) (@cons R t (@set_nth R R0 l2 n u)) k) *)
intros [|k].
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite /= 2!nth_set_nth /= Hl.
(* *)
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True ld, @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
induction ld.
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True (@cons domain a ld), @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True (@cons domain a ld) *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
simpl in H |- *.
(* Goal: forall _ : and (interp_domain l1 a) (@foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True ld), and (interp_domain l2 a) (@foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld) *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
intros (H1,H2).
(* Goal: and (interp_domain l2 a) (@foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld) *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
split.
(* Goal: interp_domain l2 a *)
(* Goal: @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
apply (proj1 H _ _ Hl H1).
(* Goal: @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
now apply IHld.
(* *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2!(interp_ext _ _ _ Hl).
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
intros H t Ht.
(* Goal: interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
apply (IHb (t :: l1)).
(* Goal: forall k : nat, @eq R (@nth R (IZR Z0) (@cons R t (@set_nth R R0 l1 n u)) k) (@nth R (IZR Z0) (@cons R t (@set_nth R R0 l2 n u)) k) *)
intros [|k].
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.
(* Goal: @eq R (@nth R (IZR Z0) (@cons R (interp l1 e) l1) (S k)) (@nth R (IZR Z0) (@cons R (interp l2 e) l2) (S k)) *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
apply Hl.
(* Goal: interp_domain (@cons R t l1) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
now apply H.
(* *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
apply IHb.
(* Goal: forall k : nat, @eq R (@nth R (IZR Z0) (@cons R t (@set_nth R R0 l1 n u)) k) (@nth R (IZR Z0) (@cons R t (@set_nth R R0 l2 n u)) k) *)
intros [|k].
(* Goal: @eq (NormedModule.sort R_AbsRing R_NormedModule) (interp (@cons R x (@set_nth R R0 l1 n y)) f) (interp (@cons R x (@set_nth R R0 l2 n y)) f) *)
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True ld, @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
now apply interp_ext.
(* Goal: @eq R (@nth R (IZR Z0) (@cons R (interp l1 e) l1) (S k)) (@nth R (IZR Z0) (@cons R (interp l2 e) l2) (S k)) *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
apply Hl.
(* *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite Hl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply filter_imp => y.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply IHb => k.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite 2!nth_set_nth /= Hl.
(* *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2!Hl.
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R (IZR Z0) l2 m) (@nth R (IZR Z0) l2 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
apply locally_2d_impl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply locally_2d_forall => u v.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply IHb => k.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2!nth_set_nth /=.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case eqtype.eq_op => //.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2!nth_set_nth /=.
(* Goal: @eq R (if @eqtype.eq_op ssrnat.nat_eqType k O then interp l1 e2 else @nth R (IZR Z0) l1 k) (if @eqtype.eq_op ssrnat.nat_eqType k O then interp l2 e2 else @nth R (IZR Z0) l2 k) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now case eqtype.eq_op.
(* *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite Hl 2!(interp_ext _ _ _ Hl).
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R (IZR Z0) l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
intros (d,Hd).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
exists d => t u Ht Hu.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: IHb (Hd t u Ht Hu).
(* Goal: forall k : nat, @eq R (@nth R (IZR Z0) (@cons R t (@set_nth R R0 l1 n u)) k) (@nth R (IZR Z0) (@cons R t (@set_nth R R0 l2 n u)) k) *)
intros [|k].
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite /= 2!nth_set_nth /= Hl.
Qed.

Lemma interp_domain_set_nth :
  forall n l b,
  interp_domain (set_nth 0 l n (nth 0 l n)) b <-> interp_domain l b.
Proof.
(* Goal: forall (n : nat) (l : list R) (b : domain), iff (interp_domain (@set_nth R (IZR Z0) l n (@nth R (IZR Z0) l n)) b) (interp_domain l b) *)
intros n l b.
split ;
  apply interp_domain_ext => k.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite nth_set_nth /=.
(* Goal: @eq R (@nth R (IZR Z0) l k) (if @eqtype.eq_op ssrnat.nat_eqType k n then @nth R (IZR Z0) l n else @nth R (IZR Z0) l k) *)
case ssrnat.eqnP.
(* Goal: forall _ : @eq nat k n, @eq R (@nth R (IZR Z0) l k) (@nth R (IZR Z0) l n) *)
(* Goal: forall _ : not (@eq nat k n), @eq R (@nth R (IZR Z0) l k) (@nth R (IZR Z0) l k) *)
intros H.
(* Goal: @eq R (match o with | Eopp => Ropp | Einv => Rinv | Efct f f' H => f | Efct' f f' df H => f end (interp l1 e)) (match o with | Eopp => Ropp | Einv => Rinv | Efct f f' H => f | Efct' f f' df H => f end (interp l2 e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply f_equal.
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite nth_set_nth /=.
(* Goal: @eq R (@nth R (IZR Z0) l k) (if @eqtype.eq_op ssrnat.nat_eqType k n then @nth R (IZR Z0) l n else @nth R (IZR Z0) l k) *)
case ssrnat.eqnP.
(* Goal: forall _ : @eq nat k n, @eq R (@nth R (IZR Z0) l k) (@nth R (IZR Z0) l n) *)
(* Goal: forall _ : not (@eq nat k n), @eq R (@nth R (IZR Z0) l k) (@nth R (IZR Z0) l k) *)
intros H.
(* Goal: @eq R (match o with | Eopp => Ropp | Einv => Rinv | Efct f f' H => f | Efct' f f' df H => f end (interp l1 e)) (match o with | Eopp => Ropp | Einv => Rinv | Efct f f' H => f | Efct' f f' df H => f end (interp l2 e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply f_equal.
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.
Qed.

Definition index_not_const l n :=
  filter (fun v => ~~ is_const (nth (Cst 0) l v) n) (iota 0 (size l)).

Lemma uniq_index_not_const :
  forall n l,
  uniq (T:=ssrnat.nat_eqType) (index_not_const l n).
Proof.
(* Goal: forall (n : nat) (l : list expr), is_true (@uniq ssrnat.nat_eqType (index_not_const l n)) *)
intros n l.
(* Goal: is_true (@uniq ssrnat.nat_eqType (index_not_const l n)) *)
unfold index_not_const.
(* Goal: is_true (@uniq ssrnat.nat_eqType (@filter nat (fun v : nat => negb (is_const (@nth expr (Cst (IZR Z0)) l v) n)) (iota O (@size expr l)))) *)
apply filter_uniq.
(* Goal: is_true (@uniq ssrnat.nat_eqType (iota O (@size expr l))) *)
apply iota_uniq.
Qed.

Canonical ssrnat.nat_eqType.

Lemma index_not_const_correct :
  forall n l (k : nat),
  not (in_mem k (mem (index_not_const l n))) ->
  is_const (nth (Cst 0) l k) n = true.
Proof.
(* Goal: forall (n : nat) (l : list expr) (k : nat) (_ : not (is_true (@in_mem nat k (@mem (eqtype.Equality.sort ssrnat.nat_eqType) (seq_predType ssrnat.nat_eqType) (index_not_const l n))))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
intros n l k.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite /index_not_const (@mem_filter ssrnat.nat_eqType) mem_iota /=.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite ssrnat.add0n.
(* Goal: forall _ : forall _ : not (is_true (orb (ssrnat.eqn m t) (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (if ssrnat.eqn m t then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t) else @foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case E: ssrnat.leq.
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) true)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
case is_const.
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
now elim.
(* Goal: forall _ : forall _ : not (is_true (orb true (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
intros _.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite nth_default //.
(* Goal: is_true (ssrnat.leq (@size expr l) k) *)
revert E.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite ssrnat.ltnNge.
(* Goal: forall _ : @eq bool (negb (ssrnat.leq (@size expr l) k)) false, is_true (ssrnat.leq (@size expr l) k) *)
now case ssrnat.leq.
Qed.

Lemma interp_AppExt_set_nth_not_const :
  forall k f le l n x,
  interp (set_nth 0 l n x) (AppExt k f le) =
  apply k f (foldr (fun v acc i => if ssrnat.eqn i v then interp (set_nth 0 l n x) (nth (Cst 0) le v) else acc i)
    (nth 0 (map (interp l) le)) (index_not_const le n)).
Proof.
(* Goal: forall (k : nat) (f : Rn k R) (le : list expr) (l : list R) (n : nat) (x : R), @eq R (interp (@set_nth R (IZR Z0) l n x) (AppExt k f le)) (@apply R k f (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) (index_not_const le n))) *)
intros k f le l n x.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply apply_ext => m _.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) (index_not_const le n) m) *)
generalize (index_not_const_correct n le m).
(* Goal: forall _ : forall _ : not (is_true (@in_mem nat m (@mem (eqtype.Equality.sort ssrnat.nat_eqType) (seq_predType ssrnat.nat_eqType) (index_not_const le n)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) (index_not_const le n) m) *)
induction (index_not_const le n) as [|t s IHs].
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl => Hp.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case (ssrnat.leqP (size le) m) => Hs.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2?nth_default ?size_map //.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2?(nth_map (Cst 0)) //.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite (is_const_correct _ n _ l x (nth 0 l n)).
(* Goal: @eq R (interp (@set_nth R (IZR Z0) l n (@nth R (IZR Z0) l n)) (@nth expr (Cst (IZR Z0)) le m)) (interp l (@nth expr (Cst (IZR Z0)) le m)) *)
(* Goal: @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true *)
(* Goal: forall _ : forall _ : not (is_true (@in_mem nat m (@mem (eqtype.Equality.sort ssrnat.nat_eqType) (seq_predType ssrnat.nat_eqType) (@cons nat t s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) (@cons nat t s) m) *)
apply interp_set_nth.
(* Goal: @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true *)
(* Goal: forall _ : forall _ : not (is_true (@in_mem nat m (@mem (eqtype.Equality.sort ssrnat.nat_eqType) (seq_predType ssrnat.nat_eqType) (@cons nat t s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) (@cons nat t s) m) *)
now apply Hp.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite (@in_cons ssrnat.nat_eqType) /= -ssrnat.eqnE.
(* Goal: forall _ : forall _ : not (is_true (orb (ssrnat.eqn m t) (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (if ssrnat.eqn m t then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t) else @foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case E: (ssrnat.eqn m t).
(* Goal: forall _ : forall _ : not (is_true (orb true (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
intros _.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite (ssrnat.eqnP E).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case (ssrnat.leqP (size le) t) => Hs.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite 2?nth_default ?size_map.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite (nth_map (Cst 0)).
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
(* Goal: forall _ : forall _ : not (is_true (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply IHs.
Qed.

Fixpoint D (e : expr) n {struct e} : expr * domain :=
  match e with
  | Var v => (if ssrnat.eqn v n then Cst 1 else Cst 0, Always)
  | Cst _ => (Cst 0, Always)
  | AppExt k f le =>
    let lnc := index_not_const le n in
    let ld := map (fun e => D e n) le in
    match lnc with
    | nil => (Cst 0, Always)
    | v :: nil =>
      let '(d1,d2) := nth (Cst 0,Never) ld v in
      (Binary Emult d1 (AppExtD k f v le),
       And (Derivable v k f le :: d2 :: nil))
    | v1 :: v2 :: nil =>
      let '(d1,d2) := nth (Cst 0,Never) ld v1 in
      let '(d3,d4) := nth (Cst 0,Never) ld v2 in
      (Binary Eplus (Binary Emult d1 (AppExtD k f v1 le)) (Binary Emult d3 (AppExtD k f v2 le)),
       And (Derivable2 v1 v2 k f le :: d2 :: Derivable v2 k f le :: d4 :: nil))
    | _ => (Cst 0, Never)
    end
  | AppExtD k f v le => (Cst 0, Never)
  | App f e => (Cst 0, Never)
  | Subst f e => (Cst 0, Never)
  | Binary b e1 e2 =>
    let '(a1,b1) := D e1 n in
    let '(a2,b2) := D e2 n in
    match b, is_const e1 n, is_const e2 n with
    | Eplus, true, _ => (a2, b2)
    | Eplus, _, true => (a1, b1)
    | Eplus, _, _ => (Binary Eplus a1 a2, And (b1::b2::nil))
    | Emult, true, _ => (Binary Emult e1 a2, b2)
    | Emult, _, true => (Binary Emult a1 e2, b1)
    | Emult, _, _ => (Binary Eplus (Binary Emult a1 e2) (Binary Emult e1 a2), And (b1::b2::nil))
    end
  | Unary u e =>
    let '(a,b) := D e n in
    match u with
    | Eopp => (Unary Eopp a, b)
    | Einv => (Binary Emult (Unary Eopp a) (Unary Einv (Binary Emult e e)), And (b:: (Partial (fun x => x <> 0) e) :: nil))
    | Efct f f' H => (Binary Emult a (AppExt 1 f' [:: e]), b)
    | Efct' f f' df H => (Binary Emult a (AppExt 1 f' [:: e]), And (b :: (Partial df e) :: nil))
    end
  | Int f e1 e2 =>
    let '(a1,b1) := D e1 n in
    let '(a2,b2) := D e2 n in
    let '(a3,b3) := D f (S n) in
    match is_const f (S n), is_const e1 n, is_const e2 n with
    | true, true, _ =>
      (Binary Emult a2 (App f e2),
       And (b2::(Integrable f e1 e2)::(Forone e2 (Locally 0 (Continuous 0 f)))::nil))
    | true, false, true =>
      (Unary Eopp (Binary Emult a1 (App f e1)),
       And (b1::(Integrable f e1 e2)::(Forone e1 (Locally 0 (Continuous 0 f)))::nil))
    | true, false, false =>
      (Binary Eplus (Binary Emult a2 (App f e2)) (Unary Eopp (Binary Emult a1 (App f e1))),
       And (b1::b2::(Integrable f e1 e2)::(Forone e1 (Locally 0 (Continuous 0 f)))::(Forone e2 (Locally 0 (Continuous 0 f)))::nil))
    | false, true, true =>
      (Int a3 e1 e2,
       And ((ForallWide n e1 e2 b3)::(Locally n (Integrable f e1 e2))::
            (Forall e1 e2 (Continuous2 (S n) 0 a3))::nil))
    | false, false, true =>
      (Binary Eplus
        (Unary Eopp (Binary Emult a1 (App f e1)))
        (Int a3 e1 e2),
       And ((Forone e1 (Locally2 (S n) 0 (Continuous2 (S n) 0 a3)))::
            (Forall e1 e2 (Continuous2 (S n) 0 a3))::
            b1::(Forone e1 (Locally 0 (Continuous 0 f)))::
            ParamIntegrable n f e1 e2::LocallyParamIntegrable n f e1::
            ForallWide n e1 e2 b3::nil))
    | false, true, false =>
      (Binary Eplus
        (Binary Emult a2 (App f e2))
        (Int a3 e1 e2),
       And ((Forone e2 (Locally2 (S n) 0 (Continuous2 (S n) 0 a3)))::
            (Forall e1 e2 (Continuous2 (S n) 0 a3))::
            b2::(Forone e2 (Locally 0 (Continuous 0 f)))::
            ParamIntegrable n f e1 e2::LocallyParamIntegrable n f e2::
            ForallWide n e1 e2 b3::nil))
    | false, false, false =>
      (Binary Eplus
        (Binary Eplus
          (Binary Emult a2 (App f e2))
          (Unary Eopp (Binary Emult a1 (App f e1))))
        (Int a3 e1 e2),
       And ((Forone e1 (Locally2 (S n) 0 (Continuous2 (S n) 0 a3)))::
            (Forone e2 (Locally2 (S n) 0 (Continuous2 (S n) 0 a3)))::
            (Forall e1 e2 (Continuous2 (S n) 0 a3))::
            b1::(Forone e1 (Locally 0 (Continuous 0 f)))::
            b2::(Forone e2 (Locally 0 (Continuous 0 f)))::
            ParamIntegrable n f e1 e2::LocallyParamIntegrable n f e1::LocallyParamIntegrable n f e2::
            ForallWide n e1 e2 b3::nil))
    end
  end.

Lemma D_correct :
  forall (e : expr) l n,
  let '(a,b) := D e n in
  interp_domain l b ->
  is_derive (fun x => interp (set_nth R0 l n x) e) (nth R0 l n) (interp l a).
Proof.
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 e) (interp l2 e) *)
induction e using expr_ind'.

(* Var *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl => l k _.
apply is_derive_ext with (fun x => if ssrnat.eqn n k then x else nth 0 l n).
intros t.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite nth_set_nth.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case ssrnat.eqnP => [H|H].
eapply filterdiff_ext_lin.
apply filterdiff_id.
simpl => y ; apply sym_eq, Rmult_1_r.
eapply filterdiff_ext_lin.
apply filterdiff_const.
simpl => y ; apply sym_eq, Rmult_0_r.

(* AppExt *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl D => l n.
assert (Dle: forall v n l,
  let '(a,b) := D (nth (Cst 0) le v) n in
  interp_domain l b -> is_derive (fun x => interp (set_nth 0 l n x) (nth (Cst 0) le v)) (nth 0 l n) (interp l a)).
clear n l.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
induction le => v n l.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite nth_nil /= => _.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: is_derive_const.
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True (@cons domain a ld), @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True (@cons domain a ld) *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
simpl in H |- *.
destruct v as [|v].
(* Goal: @foldr expr Prop (fun (e : expr) (acc : Prop) => and (forall (n : nat) (_ : @eq bool (is_const e n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) e) (interp (@set_nth R (IZR Z0) l n x2) e)) acc) True le *)
(* Goal: @eq bool (@foldr expr bool (fun (v : expr) (acc : bool) => andb (is_const v n) acc) true le) true *)
(* Goal: forall (n0 : nat) (_ : @eq bool (is_const (AppExtD k f n le) n0) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n0 x1) (AppExtD k f n le)) (interp (@set_nth R (IZR Z0) l n0 x2) (AppExtD k f n le)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (App e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (App e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (App e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Subst e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Subst e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Subst e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Cst r) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Cst r)) (interp (@set_nth R (IZR Z0) l n x2) (Cst r)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Binary o e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Binary o e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Binary o e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Unary o e) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Unary o e)) (interp (@set_nth R (IZR Z0) l n x2) (Unary o e)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Int e1 e2 e3) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Int e1 e2 e3)) (interp (@set_nth R (IZR Z0) l n x2) (Int e1 e2 e3)) *)
apply H.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x1)) le) m) (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x2)) le) m) *)
(* Goal: forall (n0 : nat) (_ : @eq bool (is_const (AppExtD k f n le) n0) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n0 x1) (AppExtD k f n le)) (interp (@set_nth R (IZR Z0) l n0 x2) (AppExtD k f n le)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (App e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (App e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (App e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Subst e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Subst e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Subst e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Cst r) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Cst r)) (interp (@set_nth R (IZR Z0) l n x2) (Cst r)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Binary o e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Binary o e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Binary o e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Unary o e) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Unary o e)) (interp (@set_nth R (IZR Z0) l n x2) (Unary o e)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Int e1 e2 e3) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Int e1 e2 e3)) (interp (@set_nth R (IZR Z0) l n x2) (Int e1 e2 e3)) *)
now apply IHle.
(* Goal: forall (_ : is_true (andb (is_const e2 n) (is_const e3 n))) (l : list R) (x1 x2 : R), @eq R (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x1)) e1) (interp (@set_nth R (IZR Z0) l n x1) e2) (interp (@set_nth R (IZR Z0) l n x1) e3)) (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x2)) e1) (interp (@set_nth R (IZR Z0) l n x2) e2) (interp (@set_nth R (IZR Z0) l n x2) e3)) *)
move: (interp_AppExt_set_nth_not_const k f le l n) (uniq_index_not_const n le).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case (index_not_const le n) => [|v1 [|v2 [|v3 q]]] /= Hc.
(* . *)
intros _ _.
apply is_derive_ext with (fun x => apply k f (nth 0 (map (interp l) le))).
intros t.
apply sym_eq.
(* Goal: @eq bool (@foldr expr bool (fun (v : expr) (acc : bool) => andb (is_const v n) acc) true le) true *)
(* Goal: forall (n0 : nat) (_ : @eq bool (is_const (AppExtD k f n le) n0) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n0 x1) (AppExtD k f n le)) (interp (@set_nth R (IZR Z0) l n0 x2) (AppExtD k f n le)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (App e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (App e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (App e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Subst e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Subst e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Subst e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Cst r) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Cst r)) (interp (@set_nth R (IZR Z0) l n x2) (Cst r)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Binary o e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Binary o e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Binary o e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Unary o e) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Unary o e)) (interp (@set_nth R (IZR Z0) l n x2) (Unary o e)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Int e1 e2 e3) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Int e1 e2 e3)) (interp (@set_nth R (IZR Z0) l n x2) (Int e1 e2 e3)) *)
apply Hc.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: is_derive_const.
(* . *)
(* Goal: forall _ : forall _ : not (is_true (orb true (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
intros _.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case (ssrnat.leqP (size le) v1) => Hv1.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite nth_default ?size_map //.
now intros (_&F&_).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite (nth_map (Cst 0)) //.
(* Goal: forall (_ : is_true (andb (is_const e2 n) (is_const e3 n))) (l : list R) (x1 x2 : R), @eq R (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x1)) e1) (interp (@set_nth R (IZR Z0) l n x1) e2) (interp (@set_nth R (IZR Z0) l n x1) e3)) (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x2)) e1) (interp (@set_nth R (IZR Z0) l n x2) e2) (interp (@set_nth R (IZR Z0) l n x2) e3)) *)
move: (Dle v1 n l).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case (D (nth (Cst 0) le v1)) => /= [d1 d2] {Dle} Dle [H1 [H2 _]].
specialize (Dle H2).
apply is_derive_ext with (fun x => apply k f (fun i => if ssrnat.eqn i v1 then interp (set_nth 0 l n x) (nth (Cst 0) le v1) else nth 0 (map (interp l) le) i)).
intros t.
now apply sym_eq.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: (is_derive_comp (fun x => apply k f (fun i => if ssrnat.eqn i v1 then x else nth 0 (map (interp l) le) i))) Dle.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite interp_set_nth.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(nth_map (Cst 0) 0) //.
now apply Derive_correct.
(* . *)
intros Hv.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case (ssrnat.leqP (size le) v1) => Hv1.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite nth_default ?size_map //.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case (nth (Cst 0, Never) (map (fun e => D e n) le) v2) => [d3 d4].
now intros (_&F&_).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite (nth_map (Cst 0)) //.
(* Goal: forall (_ : is_true (andb (is_const e2 n) (is_const e3 n))) (l : list R) (x1 x2 : R), @eq R (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x1)) e1) (interp (@set_nth R (IZR Z0) l n x1) e2) (interp (@set_nth R (IZR Z0) l n x1) e3)) (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x2)) e1) (interp (@set_nth R (IZR Z0) l n x2) e2) (interp (@set_nth R (IZR Z0) l n x2) e3)) *)
move: (Dle v1 n l).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case (D (nth (Cst 0) le v1)) => /= [d1 d2] Dle1.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case (ssrnat.leqP (size le) v2) => Hv2.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite nth_default ?size_map //.
now intros (_&_&_&F&_).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite (nth_map (Cst 0)) //.
(* Goal: forall (_ : is_true (andb (is_const e2 n) (is_const e3 n))) (l : list R) (x1 x2 : R), @eq R (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x1)) e1) (interp (@set_nth R (IZR Z0) l n x1) e2) (interp (@set_nth R (IZR Z0) l n x1) e3)) (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x2)) e1) (interp (@set_nth R (IZR Z0) l n x2) e2) (interp (@set_nth R (IZR Z0) l n x2) e3)) *)
move: (Dle v2 n l).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case (D (nth (Cst 0) le v2)) => /= [d3 d4] Dle2 {Dle} [[H1 H2] [H3 [H4 [H5 _]]]].
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite Rmult_comm (Rmult_comm (interp l d3) _).
specialize (Dle1 H3).
specialize (Dle2 H5).
set (g u v := apply k f (fun i =>
  if ssrnat.eqn i v1 then u else if ssrnat.eqn i v2 then v else nth 0 (map (interp l) le) i)).
apply is_derive_ext with (fun x => g (interp (set_nth 0 l n x) (nth (Cst 0) le v1)) (interp (set_nth 0 l n x) (nth (Cst 0) le v2))).
intros t.
unfold g.
now apply sym_eq.
apply is_derive_Reals.
apply derivable_pt_lim_comp_2d with (f1 := g).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2!interp_set_nth.
assert (H1': ex_derive_Rn k f v1 (nth 0 (map (interp l) le))).
apply locally_2d_singleton in H1.
unfold ex_derive_Rn in H1 |- *.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite ssrnat.eqnE eqtype.eq_refl in H1.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: ex_derive_ext H1 => t.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply apply_ext => p Hp.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -ssrnat.eqnE.
(* Goal: forall _ : forall _ : not (is_true (orb (ssrnat.eqn m t) (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (if ssrnat.eqn m t then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t) else @foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case E: (ssrnat.eqn p v1) => //.
(* Goal: forall _ : forall _ : not (is_true (orb (ssrnat.eqn m t) (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (if ssrnat.eqn m t then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t) else @foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case E': (ssrnat.eqn p v2) => //.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite (ssrnat.eqnP E').
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite /Derive_Rn.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(nth_map (Cst 0) 0 (interp l) Hv1).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(nth_map (Cst 0) 0 (interp l) Hv2).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(Derive_ext (fun x => g x (nth 0 (map (interp l) le) v2))).
apply filterdiff_differentiable_pt_lim.
eapply filterdiff_ext_lin.
apply (is_derive_filterdiff g).
apply filter_imp with ( 2 := proj1 (locally_2d_locally _ _ _) H1).
(* Goal: forall _ : forall _ : not (is_true (orb (ssrnat.eqn m t) (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (if ssrnat.eqn m t then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t) else @foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case => u v H'.
unfold g.
unfold ex_derive_Rn in H'.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite ssrnat.eqnE eqtype.eq_refl in H'.
evar_last.
apply Derive_correct.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: ex_derive_ext H' => t.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply apply_ext => p Hp.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -ssrnat.eqnE.
now case E: (ssrnat.eqn p v1).
simpl ; reflexivity.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply is_derive_ext with (2 := Derive_correct _ _ H4) => t.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply apply_ext => p Hp.
(* Goal: forall _ : forall _ : not (is_true (orb (ssrnat.eqn m t) (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (if ssrnat.eqn m t then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t) else @foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case E: (ssrnat.eqn p v1) => //.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite (ssrnat.eqnP E).
revert Hv.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite /in_mem /= ssrnat.eqnE.
(* Goal: @eq R (if @eqtype.eq_op ssrnat.nat_eqType k O then interp l1 e2 else @nth R (IZR Z0) l1 k) (if @eqtype.eq_op ssrnat.nat_eqType k O then interp l2 e2 else @nth R (IZR Z0) l2 k) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now case eqtype.eq_op.
apply continuity_2d_pt_filterlim in H2.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: continuous_ext H2 => [[u v]].
(* Goal: @eq R (Derive_Rn k f n (@nth R (IZR Z0) (@map expr R (interp l1) le))) (Derive_Rn k f n (@nth R (IZR Z0) (@map expr R (interp l2) le))) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (App e1 e2)) (interp l2 (App e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Subst e1 e2)) (interp l2 (Subst e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
unfold Derive_Rn.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite ssrnat.eqnE eqtype.eq_refl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply Derive_ext => t.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply apply_ext => p Hp.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -ssrnat.eqnE.
now case E: (ssrnat.eqn p v1).
intros t ; reflexivity.
intros t.
(* Goal: @eq R (@apply R k f (@nth R (IZR Z0) (@map expr R (interp l1) le))) (@apply R k f (@nth R (IZR Z0) (@map expr R (interp l2) le))) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (AppExtD k f n le)) (interp l2 (AppExtD k f n le)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (App e1 e2)) (interp l2 (App e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Subst e1 e2)) (interp l2 (Subst e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
apply apply_ext.
intros p Hp.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case (ssrnat.eqn p v1) => //.
(* Goal: forall _ : forall _ : not (is_true (orb (ssrnat.eqn m t) (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (if ssrnat.eqn m t then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t) else @foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case E: (ssrnat.eqn p v2) => //.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite (ssrnat.eqnP E).
apply is_derive_Reals, Dle1.
apply is_derive_Reals, Dle2.
(* . *)
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.

(* AppExtD *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl => l p [].

(* App *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl => l n [].

(* Subst *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl => l n [].

(* Cst *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl => l n _.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: is_derive_const.

(* Binary *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl => l n.
specialize (IHe1 l n).
specialize (IHe2 l n).
destruct (D e1 n) as (a1,b1).
destruct (D e2 n) as (a2,b2).
(* Goal: forall _ : forall _ : not (is_true (orb (ssrnat.eqn m t) (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (if ssrnat.eqn m t then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t) else @foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case C1: (is_const e1 n).
(* . *)
assert (H1 := is_const_correct e1 n C1 l).
case o ; intros H2.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(Rplus_0_l (interp l a2)).
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: is_derive_plus.
apply is_derive_ext with (fun x => interp (set_nth 0 l n 0) e1).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : AbsRing.sort R_AbsRing => interp (@set_nth R R0 l n x) e) (@nth R R0 l n) (interp l d1) *)
apply H1.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: is_derive_const.
(* Goal: @eq R (interp l1 e2) (interp l2 e2) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply IHe2.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
replace (interp l e1 * interp l a2) with (0 * interp (set_nth 0 l n (nth 0 l n)) e2 + interp l e1 * interp l a2) by ring.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(interp_set_nth n _ e1).
apply is_derive_Reals.
apply (derivable_pt_lim_mult (fun x => interp (set_nth 0 l n x) e1) (fun x => interp (set_nth 0 l n x) e2)).
apply is_derive_Reals.
apply is_derive_ext with (fun x => interp (set_nth 0 l n 0) e1).
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : AbsRing.sort R_AbsRing => interp (@set_nth R R0 l n x) e) (@nth R R0 l n) (interp l d1) *)
apply H1.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: is_derive_const.
apply is_derive_Reals.
(* Goal: @eq R (interp l1 e2) (interp l2 e2) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply IHe2.
(* Goal: forall _ : forall _ : not (is_true (orb (ssrnat.eqn m t) (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (if ssrnat.eqn m t then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t) else @foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case C2: (is_const e2 n) => {C1}.
(* . *)
assert (H2 := is_const_correct e2 n C2 l).
case o ; intros H1.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(Rplus_0_r (interp l a1)).
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: is_derive_plus.
(* Goal: @eq R (interp l1 e1) (interp l2 e1) *)
(* Goal: @eq R (interp l1 e2) (interp l2 e2) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply IHe1.
apply is_derive_ext with (fun x => interp (set_nth 0 l n 0) e2).
apply H2.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: is_derive_const.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
replace (interp l a1 * interp l e2) with (interp l a1 * interp l e2 + interp (set_nth 0 l n (nth 0 l n)) e1 * 0) by ring.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(interp_set_nth n _ e2).
apply is_derive_Reals.
apply (derivable_pt_lim_mult (fun x => interp (set_nth 0 l n x) e1) (fun x => interp (set_nth 0 l n x) e2)).
now apply is_derive_Reals, IHe1.
apply is_derive_Reals.
apply is_derive_ext with (fun x => interp (set_nth 0 l n 0) e2).
apply H2.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: is_derive_const.
(* . *)
clear C2.
case o ; simpl ;
  intros (H1&H2&_) ;
  specialize (IHe1 H1) ;
  specialize (IHe2 H2).
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
now apply: is_derive_plus.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(interp_set_nth n _ e1) -(interp_set_nth n _ e2).
apply is_derive_Reals.
apply (derivable_pt_lim_mult (fun x => interp (set_nth 0 l n x) e1) (fun x => interp (set_nth 0 l n x) e2)) ;
  now apply is_derive_Reals.

(* Unary *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl => l n.
specialize (IHe l n).
destruct (D e n) as (a,b).
case o.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
(* Goal: forall _ : @eq nat k n, @eq R (@nth R (IZR Z0) l k) (@nth R (IZR Z0) l n) *)
(* Goal: forall _ : not (@eq nat k n), @eq R (@nth R (IZR Z0) l k) (@nth R (IZR Z0) l k) *)
intros H.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: is_derive_opp.
(* Goal: @eq R (interp l1 e) (interp l2 e) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply IHe.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
intros (H,(H0,_)).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -{2}(Rmult_1_r (interp l e)).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(interp_set_nth n l e) in H0 |-*.
apply is_derive_inv.
(* Goal: @eq R (interp l1 e) (interp l2 e) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply IHe.
exact H0.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
intros f f' Df H.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(interp_set_nth n l e).
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: is_derive_comp.
apply Df.
(* Goal: @eq R (interp l1 e) (interp l2 e) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply IHe.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
intros f f' df Df (H,(H0,_)).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(interp_set_nth n l e) in H0 |-*.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: is_derive_comp.
apply Df.
exact H0.
(* Goal: @eq R (interp l1 e) (interp l2 e) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply IHe.

(* Int *)
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl => l n.
specialize (IHe2 l n).
specialize (IHe3 l n).
(* Goal: forall (_ : is_true (andb (is_const e2 n) (is_const e3 n))) (l : list R) (x1 x2 : R), @eq R (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x1)) e1) (interp (@set_nth R (IZR Z0) l n x1) e2) (interp (@set_nth R (IZR Z0) l n x1) e3)) (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x2)) e1) (interp (@set_nth R (IZR Z0) l n x2) e2) (interp (@set_nth R (IZR Z0) l n x2) e3)) *)
move: (fun l => IHe1 l (S n)) => {IHe1} IHe1.
destruct (D e1 (S n)) as (a1,b1).
destruct (D e2 n) as (a2,b2).
destruct (D e3 n) as (a3,b3).
(* . *)
assert (HexI: forall f x, locally x (fun x => continuity_pt f x) -> exists eps : posreal, ex_RInt f (x - eps) (x + eps)).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
clear => f x [eps H].
exists (pos_div_2 eps).
apply ex_RInt_Reals_1.
apply RiemannInt_P6.
apply Rplus_lt_compat_l.
apply Rle_lt_trans with (2 := cond_pos _).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -Ropp_0.
apply Ropp_le_contravar.
apply Rlt_le.
apply cond_pos.
intros u Hu.
(* Goal: @foldr expr Prop (fun (e : expr) (acc : Prop) => and (forall (n : nat) (_ : @eq bool (is_const e n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) e) (interp (@set_nth R (IZR Z0) l n x2) e)) acc) True le *)
(* Goal: @eq bool (@foldr expr bool (fun (v : expr) (acc : bool) => andb (is_const v n) acc) true le) true *)
(* Goal: forall (n0 : nat) (_ : @eq bool (is_const (AppExtD k f n le) n0) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n0 x1) (AppExtD k f n le)) (interp (@set_nth R (IZR Z0) l n0 x2) (AppExtD k f n le)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (App e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (App e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (App e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Subst e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Subst e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Subst e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Cst r) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Cst r)) (interp (@set_nth R (IZR Z0) l n x2) (Cst r)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Binary o e1 e2) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Binary o e1 e2)) (interp (@set_nth R (IZR Z0) l n x2) (Binary o e1 e2)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Unary o e) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Unary o e)) (interp (@set_nth R (IZR Z0) l n x2) (Unary o e)) *)
(* Goal: forall (n : nat) (_ : @eq bool (is_const (Int e1 e2 e3) n) true) (l : list R) (x1 x2 : R), @eq R (interp (@set_nth R (IZR Z0) l n x1) (Int e1 e2 e3)) (interp (@set_nth R (IZR Z0) l n x2) (Int e1 e2 e3)) *)
apply H.
apply Rle_lt_trans with (pos_div_2 eps).
now apply Rabs_le_between'.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite (double_var eps).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(Rplus_0_r (pos_div_2 eps)).
apply Rplus_lt_compat_l.
apply (cond_pos (pos_div_2 eps)).
(* . *)
assert (HexD:
  ( exists d : posreal, forall t u, Rmin (interp l e2) (interp l e3) - d < t < Rmax (interp l e2) (interp l e3) + d ->
    Rabs (u - nth 0 l n) < d -> interp_domain (t :: set_nth 0 l n u) b1 ) ->
  forall t, Rmin (interp l e2) (interp l e3) <= t <= Rmax (interp l e2) (interp l e3) ->
  locally_2d (fun u v => is_derive (fun x => interp (v :: set_nth 0 l n x) e1) u (interp (v :: set_nth 0 l n u) a1)) (nth 0 l n) t).
intros (e,H) t Ht.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
exists e => /= u v Hu Hv.
assert (H': Rmin (interp l e2) (interp l e3) - e < v < Rmax (interp l e2) (interp l e3) + e).
apply (Rlt_le_trans _ _ e) in Hv. 2: apply Rle_refl.
apply Rabs_lt_between' in Hv.
(* Goal: and (interp_domain l2 a) (@foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld) *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
split.
apply Rle_lt_trans with (2 := proj1 Hv).
now apply Rplus_le_compat_r.
apply Rlt_le_trans with (1 := proj2 Hv).
now apply Rplus_le_compat_r.
(* Goal: forall (_ : is_true (andb (is_const e2 n) (is_const e3 n))) (l : list R) (x1 x2 : R), @eq R (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x1)) e1) (interp (@set_nth R (IZR Z0) l n x1) e2) (interp (@set_nth R (IZR Z0) l n x1) e3)) (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x2)) e1) (interp (@set_nth R (IZR Z0) l n x2) e2) (interp (@set_nth R (IZR Z0) l n x2) e3)) *)
move: (IHe1 _ (H v u H' Hu)) => {IHe1} /=.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite nth_set_nth /= eqtype.eq_refl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply is_derive_ext => z.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite set_set_nth /= eqtype.eq_refl.
(* . *)
assert (Htw: forall e : posreal, forall t, Rmin (interp l e2) (interp l e3) <= t <= Rmax (interp l e2) (interp l e3) ->
  Rmin (interp l e2) (interp l e3) - e < t < Rmax (interp l e2) (interp l e3) + e).
intros e t Ht.
(* Goal: and (interp_domain l2 a) (@foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld) *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
split.
apply Rlt_le_trans with (2 := proj1 Ht).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -{2}[Rmin _ _]Rplus_0_r -Ropp_0.
apply Rplus_lt_compat_l.
apply Ropp_lt_contravar.
apply cond_pos.
apply Rle_lt_trans with (1 := proj2 Ht).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -{1}[Rmax _ _]Rplus_0_r.
apply Rplus_lt_compat_l.
apply cond_pos.
(* Goal: forall _ : forall _ : not (is_true (orb (ssrnat.eqn m t) (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (if ssrnat.eqn m t then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t) else @foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case C1: (is_const e1 (S n)).
clear IHe1.
(* Goal: forall _ : forall _ : not (is_true (orb (ssrnat.eqn m t) (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (if ssrnat.eqn m t then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t) else @foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case C2: (is_const e2 n).
(* . *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
intros (H3&Hi&H1&_).
apply is_derive_ext with (comp (fun x => RInt (fun t => interp (t :: l) e1) (interp (set_nth 0 l n (nth 0 l n)) e2) x) (fun x => interp (set_nth 0 l n x) e3)).
intros t.
unfold comp.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(is_const_correct e2 n C2 l (nth 0 l n)).
apply RInt_ext.
intros z _.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(interp_set_nth (S n)).
apply (is_const_correct e1 (S n) C1 (z :: l)).
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: is_derive_comp.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2!interp_set_nth.
apply (is_derive_RInt (fun t : R => interp (t :: l)%SEQ e1) _ (interp l e2)).
apply HexI in H1.
(* Goal: forall _ : forall _ : not (is_true (orb (ssrnat.eqn m t) (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (if ssrnat.eqn m t then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t) else @foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case: H1 => e He.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
exists e => /= y Hy.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: RInt_correct.
eapply ex_RInt_Chasles.
apply Hi.
eapply ex_RInt_Chasles.
eapply ex_RInt_Chasles, He.
eapply ex_RInt_swap, @ex_RInt_Chasles_1, He.
apply Rabs_le_between'.
rewrite Rminus_eq_0 Rabs_R0 ; by apply Rlt_le, e.
eapply ex_RInt_swap, @ex_RInt_Chasles_2, He.
apply Rabs_le_between'.
(* Goal: forall _ : p (interp l1 e), p (interp l2 e) *)
(* Goal: forall _ : ex_derive_Rn k f n (@nth R (IZR Z0) (@map expr R (interp l1) le)), ex_derive_Rn k f n (@nth R (IZR Z0) (@map expr R (interp l2) le)) *)
(* Goal: forall _ : and (locally_2d (fun u v : R => ex_derive_Rn k f m (fun i : nat => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else @nth R (IZR Z0) (@map expr R (interp l1) le) i)) (@nth R (IZR Z0) (@map expr R (interp l1) le) m) (@nth R (IZR Z0) (@map expr R (interp l1) le) n)) (continuity_2d_pt (fun u v : R => Derive_Rn k f m (fun i : nat => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else @nth R (IZR Z0) (@map expr R (interp l1) le) i)) (@nth R (IZR Z0) (@map expr R (interp l1) le) m) (@nth R (IZR Z0) (@map expr R (interp l1) le) n)), and (locally_2d (fun u v : R => ex_derive_Rn k f m (fun i : nat => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else @nth R (IZR Z0) (@map expr R (interp l2) le) i)) (@nth R (IZR Z0) (@map expr R (interp l2) le) m) (@nth R (IZR Z0) (@map expr R (interp l2) le) n)) (continuity_2d_pt (fun u v : R => Derive_Rn k f m (fun i : nat => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else @nth R (IZR Z0) (@map expr R (interp l2) le) i)) (@nth R (IZR Z0) (@map expr R (interp l2) le) m) (@nth R (IZR Z0) (@map expr R (interp l2) le) n)) *)
(* Goal: forall _ : continuity_pt (fun x : R => interp (@set_nth R R0 l1 n x) e) (@nth R R0 l1 n), continuity_pt (fun x : R => interp (@set_nth R R0 l2 n x) e) (@nth R R0 l2 n) *)
(* Goal: forall _ : continuity_2d_pt (fun x y : R => interp (@set_nth R R0 (@set_nth R R0 l1 n y) m x) e) (@nth R R0 l1 m) (@nth R R0 l1 n), continuity_2d_pt (fun x y : R => interp (@set_nth R R0 (@set_nth R R0 l2 n y) m x) e) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex_RInt R_NormedModule (fun x : R => interp (@cons R x l1) f) (interp l1 e1) (interp l1 e2), @ex_RInt R_NormedModule (fun x : R => interp (@cons R x l2) f) (interp l2 e1) (interp l2 e2) *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l1 n y)) f) (interp l1 e1) (interp l1 e2)), @locally R_UniformSpace (@nth R R0 l2 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l2 n y)) f) (interp l2 e1) (interp l2 e2)) *)
(* Goal: forall _ : @ex posreal (fun eps : posreal => @locally R_UniformSpace (@nth R R0 l1 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l1 n y)) f) (Rminus (interp l1 e) (pos eps)) (Rplus (interp l1 e) (pos eps)))), @ex posreal (fun eps : posreal => @locally R_UniformSpace (@nth R R0 l2 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l2 n y)) f) (Rminus (interp l2 e) (pos eps)) (Rplus (interp l2 e) (pos eps)))) *)
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True ld, @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
by apply Rlt_le, Hy.
now apply continuity_pt_filterlim, locally_singleton.
now apply IHe3.
clear C2.
(* Goal: forall _ : forall _ : not (is_true (orb (ssrnat.eqn m t) (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (if ssrnat.eqn m t then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t) else @foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case C3: (is_const e3 n).
(* . *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
intros (H2&Hi&H1&_).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -Ropp_mult_distr_r_reverse.
apply is_derive_ext with (fun x => comp (fun x => RInt (fun t => interp (t :: l) e1) x (interp (set_nth 0 l n (nth 0 l n)) e3)) (fun x => interp (set_nth 0 l n x) e2) x).
intros t.
unfold comp.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(is_const_correct e3 n C3 l (nth 0 l n)).
apply RInt_ext.
intros z _.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(interp_set_nth (S n)).
apply (is_const_correct e1 (S n) C1 (z :: l)).
apply: (is_derive_comp (fun x0 : R => RInt (fun t : R => interp (t :: l) e1) x0 (interp (set_nth 0 l n (nth 0 l n)) e3))
  (fun x0 : R => interp (set_nth 0 l n x0) e2)).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2!interp_set_nth.
apply (is_derive_RInt' (fun t : R => interp (t :: l)%SEQ e1) _ _ (interp l e3)).
apply HexI in H1.
(* Goal: forall _ : forall _ : not (is_true (orb (ssrnat.eqn m t) (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (if ssrnat.eqn m t then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t) else @foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case: H1 => e He.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
exists e => /= y Hy.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: RInt_correct.
eapply ex_RInt_Chasles, Hi.
eapply ex_RInt_Chasles.
eapply ex_RInt_Chasles, He.
eapply ex_RInt_swap, @ex_RInt_Chasles_1, He.
apply Rabs_le_between'.
(* Goal: forall _ : p (interp l1 e), p (interp l2 e) *)
(* Goal: forall _ : ex_derive_Rn k f n (@nth R (IZR Z0) (@map expr R (interp l1) le)), ex_derive_Rn k f n (@nth R (IZR Z0) (@map expr R (interp l2) le)) *)
(* Goal: forall _ : and (locally_2d (fun u v : R => ex_derive_Rn k f m (fun i : nat => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else @nth R (IZR Z0) (@map expr R (interp l1) le) i)) (@nth R (IZR Z0) (@map expr R (interp l1) le) m) (@nth R (IZR Z0) (@map expr R (interp l1) le) n)) (continuity_2d_pt (fun u v : R => Derive_Rn k f m (fun i : nat => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else @nth R (IZR Z0) (@map expr R (interp l1) le) i)) (@nth R (IZR Z0) (@map expr R (interp l1) le) m) (@nth R (IZR Z0) (@map expr R (interp l1) le) n)), and (locally_2d (fun u v : R => ex_derive_Rn k f m (fun i : nat => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else @nth R (IZR Z0) (@map expr R (interp l2) le) i)) (@nth R (IZR Z0) (@map expr R (interp l2) le) m) (@nth R (IZR Z0) (@map expr R (interp l2) le) n)) (continuity_2d_pt (fun u v : R => Derive_Rn k f m (fun i : nat => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else @nth R (IZR Z0) (@map expr R (interp l2) le) i)) (@nth R (IZR Z0) (@map expr R (interp l2) le) m) (@nth R (IZR Z0) (@map expr R (interp l2) le) n)) *)
(* Goal: forall _ : continuity_pt (fun x : R => interp (@set_nth R R0 l1 n x) e) (@nth R R0 l1 n), continuity_pt (fun x : R => interp (@set_nth R R0 l2 n x) e) (@nth R R0 l2 n) *)
(* Goal: forall _ : continuity_2d_pt (fun x y : R => interp (@set_nth R R0 (@set_nth R R0 l1 n y) m x) e) (@nth R R0 l1 m) (@nth R R0 l1 n), continuity_2d_pt (fun x y : R => interp (@set_nth R R0 (@set_nth R R0 l2 n y) m x) e) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex_RInt R_NormedModule (fun x : R => interp (@cons R x l1) f) (interp l1 e1) (interp l1 e2), @ex_RInt R_NormedModule (fun x : R => interp (@cons R x l2) f) (interp l2 e1) (interp l2 e2) *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l1 n y)) f) (interp l1 e1) (interp l1 e2)), @locally R_UniformSpace (@nth R R0 l2 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l2 n y)) f) (interp l2 e1) (interp l2 e2)) *)
(* Goal: forall _ : @ex posreal (fun eps : posreal => @locally R_UniformSpace (@nth R R0 l1 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l1 n y)) f) (Rminus (interp l1 e) (pos eps)) (Rplus (interp l1 e) (pos eps)))), @ex posreal (fun eps : posreal => @locally R_UniformSpace (@nth R R0 l2 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l2 n y)) f) (Rminus (interp l2 e) (pos eps)) (Rplus (interp l2 e) (pos eps)))) *)
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True ld, @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
by apply Rlt_le, Hy.
eapply ex_RInt_swap, @ex_RInt_Chasles_2, He.
apply Rabs_le_between'.
rewrite Rminus_eq_0 Rabs_R0 ; by apply Rlt_le, e.
now apply continuity_pt_filterlim, locally_singleton.
(* Goal: @eq R (interp l1 e2) (interp l2 e2) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply IHe2.
(* . *)
clear C3.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
intros (H2&H3&Hi&H12&H13&_).
apply is_derive_ext with (fun x => RInt (fun t => interp (t :: l) e1) (interp (set_nth 0 l n x) e2) (interp (set_nth 0 l n x) e3)).
intros t.
apply RInt_ext.
intros z _.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(interp_set_nth (S n)).
apply (is_const_correct e1 (S n) C1 (z :: l)).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(interp_set_nth n l e2) -(interp_set_nth n l e3).
evar_last.
apply (is_derive_RInt_bound_comp (fun t : R => interp (t :: l)%SEQ e1)).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2!interp_set_nth.
eapply filter_imp.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
intros x Hx ; simpl.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: RInt_correct.
exact: Hx.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply @ex_RInt_locally => //.
now apply HexI.
now apply HexI.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite interp_set_nth.
now apply continuity_pt_filterlim, locally_singleton.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite interp_set_nth.
now apply continuity_pt_filterlim, locally_singleton.
(* Goal: @eq R (interp l1 e2) (interp l2 e2) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply IHe2.
now apply IHe3.
reflexivity.
(* Goal: forall _ : forall _ : not (is_true (orb (ssrnat.eqn m t) (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (if ssrnat.eqn m t then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t) else @foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case C2: (is_const e2 n).
clear IHe2.
(* Goal: forall _ : forall _ : not (is_true (orb (ssrnat.eqn m t) (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (if ssrnat.eqn m t then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t) else @foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case C3: (is_const e3 n).
clear IHe3.
(* . *)
clear C1.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
intros (H3&H2&H4&_).
apply is_derive_ext with (fun x => RInt (fun t => interp (t :: set_nth 0 l n x) e1) (interp (set_nth 0 l n (nth 0 l n)) e2) (interp (set_nth 0 l n (nth 0 l n)) e3)).
intros t.
(* Goal: @eq R (match o with | Eplus => Rplus | Emult => Rmult end (interp l1 e1) (interp l1 e2)) (match o with | Eplus => Rplus | Emult => Rmult end (interp l2 e1) (interp l2 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
apply f_equal2.
now apply is_const_correct.
now apply is_const_correct.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2!interp_set_nth.
destruct H3 as (d,H3).
assert (H3': locally (nth R0 l n) (fun x => forall t, Rmin (interp l e2) (interp l e3) <= t <= Rmax (interp l e2) (interp l e3) ->
  interp_domain (set_nth 0 (t :: l) (S n) x) b1)).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
exists d => y Hy t Ht.
apply H3.
(* Goal: and (interp_domain l2 a) (@foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld) *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
split.
apply Rlt_le_trans with (2 := proj1 Ht).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -{2}[Rmin _ _]Rplus_0_r -Ropp_0.
apply Rplus_lt_compat_l.
apply Ropp_lt_contravar.
apply cond_pos.
apply Rle_lt_trans with (1 := proj2 Ht).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -{1}[Rmax _ _]Rplus_0_r.
apply Rplus_lt_compat_l.
apply cond_pos.
exact Hy.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite (RInt_ext (fun x => interp (x :: l) a1) (fun x => Derive (fun t => interp (set_nth 0 (x :: l) (S n) t) e1) (nth 0 (x :: l) (S n)))).
apply is_derive_RInt_param.
(* Goal: @locally R_UniformSpace (@nth R (IZR Z0) l1 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l2 n y)) f) (Rminus (interp l2 e) (pos d)) (Rplus (interp l2 e) (pos d))) *)
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True ld, @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
move: H3' ; apply filter_imp => y H3' t Ht.
specialize (IHe1 _ (H3' t Ht)).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite nth_set_nth /= eqtype.eq_refl in IHe1.
exists (interp (set_nth 0 (t :: l) (S n) y) a1).
apply is_derive_ext with (f := fun x => interp (set_nth 0 (set_nth 0 (t :: l) (S n) y) (S n) x) e1) (2 := IHe1).
intros t'.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite set_set_nth eqtype.eq_refl.
intros t Ht.
apply continuity_2d_pt_ext_loc with (f := fun x y => interp (set_nth 0 (y :: l) (S n) x) a1).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
exists d => u v Hu Hv.
apply sym_eq.
apply is_derive_unique.
apply is_derive_ext with (f := fun z => interp (set_nth 0 (set_nth 0 (v :: l) (S n) u) (S n) z) e1).
intros z.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite set_set_nth eqtype.eq_refl.
pattern u at 2; replace u with (nth 0 (set_nth 0 (v :: l) (S n) u) (S n)).
(* Goal: @eq (CompleteNormedModule.sort R_AbsRing R_CompleteNormedModule) (interp (@cons R x l1) e1) (interp (@cons R x l2) e1) *)
apply IHe1.
apply H3.
apply Rabs_lt_between' in Hv.
(* Goal: and (interp_domain l2 a) (@foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld) *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
split.
apply Rle_lt_trans with (2 := proj1 Hv).
now apply Rplus_le_compat_r.
apply Rlt_le_trans with (1 := proj2 Hv).
now apply Rplus_le_compat_r.
exact Hu.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite nth_set_nth /= eqtype.eq_refl.
now apply H4.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
move: H2 ; apply filter_imp => y.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite (is_const_correct e2 n C2 l y (nth 0 l n)).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite (is_const_correct e3 n C3 l y (nth 0 l n)).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite 2!interp_set_nth.
intros t Ht.
apply sym_eq.
apply is_derive_unique.
apply locally_singleton in H3'.
apply (IHe1 (t :: l)).
cut (interp_domain (set_nth 0 (t :: l)%SEQ (S n) (nth 0 l n)) b1).
apply (interp_domain_set_nth (S n) (t :: l)).
apply H3'.
now split ; apply Rlt_le.
(* . *)
clear C1 C3.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
intros (H2&H3&H6&H7&H8&H10&H11&_).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite Rplus_comm Rmult_comm.
apply is_derive_ext with (fun x => RInt (fun t => interp (t :: set_nth 0 l n x) e1) (interp l e2) (interp (set_nth 0 l n x) e3)).
intros x.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite (is_const_correct e2 n C2 l x (nth 0 l n)).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite interp_set_nth.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(RInt_ext (fun x => Derive (fun t => interp (x :: set_nth 0 l n t) e1) (nth 0 l n))).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(interp_set_nth (S n) (interp l e3 :: l) e1).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(interp_set_nth n l e3) /=.
apply (is_derive_RInt_param_bound_comp_aux3 (fun x t => interp (t :: set_nth 0 l n x) e1)
  (interp l e2) (fun x => interp (set_nth 0 l n x) e3)).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite interp_set_nth.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite interp_set_nth.
now apply IHe3.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite interp_set_nth.
destruct H11 as (e&H11).
exists (pos_div_2 e).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
exists e => y Hy t Ht.
assert (Ht': Rmin (interp l e2) (interp l e3) - e < t < Rmax (interp l e2) (interp l e3) + e).
(* Goal: and (interp_domain l2 a) (@foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld) *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
split.
apply Rlt_le_trans with (2 := proj1 Ht).
apply Rlt_le_trans with (Rmin (interp l e2) (interp l e3) - pos_div_2 e).
apply Rplus_lt_compat_l.
apply Ropp_lt_contravar.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(Rplus_0_r (pos_div_2 e)) /= {2}(double_var e).
apply Rplus_lt_compat_l.
apply is_pos_div_2.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite /Rminus Rplus_min_distr_r.
apply Rle_min_compat_r.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -{2}[interp l e2]Rplus_0_r -Ropp_0.
apply Rplus_le_compat_l.
apply Ropp_le_contravar.
apply Rlt_le, cond_pos.
apply Rle_lt_trans with (1 := proj2 Ht).
apply Rle_lt_trans with (Rmax (interp l e2) (interp l e3) + pos_div_2 e).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite /Rminus Rplus_max_distr_r.
apply Rle_max_compat_r.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -{1}[interp l e2]Rplus_0_r.
apply Rplus_le_compat_l.
apply Rlt_le, cond_pos.
apply Rplus_lt_compat_l.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(Rplus_0_r (pos_div_2 e)) /= {2}(double_var e).
apply Rplus_lt_compat_l.
apply is_pos_div_2.
eexists.
(* Goal: forall (_ : is_true (andb (is_const e2 n) (is_const e3 n))) (l : list R) (x1 x2 : R), @eq R (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x1)) e1) (interp (@set_nth R (IZR Z0) l n x1) e2) (interp (@set_nth R (IZR Z0) l n x1) e3)) (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x2)) e1) (interp (@set_nth R (IZR Z0) l n x2) e2) (interp (@set_nth R (IZR Z0) l n x2) e3)) *)
move: (IHe1 _ (H11 t y Ht' Hy)) => {IHe1} /=.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite nth_set_nth /= eqtype.eq_refl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply is_derive_ext => z.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite set_set_nth eqtype.eq_refl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite interp_set_nth.
intros t Ht.
apply continuity_2d_pt_ext_loc with (f := fun x y => interp (set_nth 0 (y :: l) (S n) x) a1).
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: locally_2d_impl (HexD H11 t Ht).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply locally_2d_forall => u v H.
apply sym_eq.
now apply is_derive_unique.
now apply H3.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite interp_set_nth.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: locally_2d_impl H2.
specialize (HexD H11 _ (conj (Rmin_r _ _) (Rmax_r _ _))).
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: locally_2d_impl_strong HexD.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply locally_2d_forall => u v H.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite nth_set_nth /= eqtype.eq_refl.
apply continuity_2d_pt_ext_loc.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: locally_2d_impl H.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply locally_2d_forall => u' v' H.
apply sym_eq.
apply is_derive_unique.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite set_set_nth eqtype.eq_refl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite interp_set_nth.
apply locally_singleton in H7.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: continuity_pt_ext H7.
intros t.
apply sym_eq.
apply (interp_set_nth (S n) (t :: l)).
intros t Ht.
apply is_derive_unique.
apply (IHe1 (t :: l)).
destruct H11 as (e,H11).
specialize (H11 t (nth 0 l n)).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(interp_domain_set_nth (S n)) /=.
apply H11.
apply Htw.
now split ; apply Rlt_le.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite /Rminus Rplus_opp_r Rabs_R0.
apply cond_pos.
(* Goal: forall _ : forall _ : not (is_true (orb (ssrnat.eqn m t) (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (if ssrnat.eqn m t then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t) else @foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case C3: (is_const e3 n).
clear IHe3.
(* . *)
clear C1 C2.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
intros (H2&H3&H6&H7&H8&H10&H11&_).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite Rplus_comm Rmult_comm -Ropp_mult_distr_l_reverse.
apply is_derive_ext with (fun x => RInt (fun t => interp (t :: set_nth 0 l n x) e1) (interp (set_nth 0 l n x) e2) (interp l e3)).
intros x.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite (is_const_correct e3 n C3 l x (nth 0 l n)).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite interp_set_nth.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(RInt_ext (fun x => Derive (fun t => interp (x :: set_nth 0 l n t) e1) (nth 0 l n))).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(interp_set_nth (S n) (interp l e2 :: l) e1).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(interp_set_nth n l e2) /=.
apply (is_derive_RInt_param_bound_comp_aux2 (fun x t => interp (t :: set_nth 0 l n x) e1)
  (fun x => interp (set_nth 0 l n x) e2) (interp l e3)).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite interp_set_nth.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite interp_set_nth.
(* Goal: @eq R (interp l1 e2) (interp l2 e2) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply IHe2.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite interp_set_nth.
destruct H11 as (e&H11).
exists (pos_div_2 e).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
exists e => y Hy t Ht.
assert (Ht': Rmin (interp l e2) (interp l e3) - e < t < Rmax (interp l e2) (interp l e3) + e).
(* Goal: and (interp_domain l2 a) (@foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld) *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
split.
apply Rlt_le_trans with (2 := proj1 Ht).
apply Rlt_le_trans with (Rmin (interp l e2) (interp l e3) - pos_div_2 e).
apply Rplus_lt_compat_l.
apply Ropp_lt_contravar.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(Rplus_0_r (pos_div_2 e)) /= {2}(double_var e).
apply Rplus_lt_compat_l.
apply is_pos_div_2.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite /Rminus Rplus_min_distr_r.
apply Rle_min_compat_l.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -{2}[interp l e3]Rplus_0_r -Ropp_0.
apply Rplus_le_compat_l.
apply Ropp_le_contravar.
apply Rlt_le, cond_pos.
apply Rle_lt_trans with (1 := proj2 Ht).
apply Rle_lt_trans with (Rmax (interp l e2) (interp l e3) + pos_div_2 e).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite /Rminus Rplus_max_distr_r.
apply Rle_max_compat_l.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -{1}[interp l e3]Rplus_0_r.
apply Rplus_le_compat_l.
apply Rlt_le, cond_pos.
apply Rplus_lt_compat_l.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(Rplus_0_r (pos_div_2 e)) /= {2}(double_var e).
apply Rplus_lt_compat_l.
apply is_pos_div_2.
eexists.
(* Goal: forall (_ : is_true (andb (is_const e2 n) (is_const e3 n))) (l : list R) (x1 x2 : R), @eq R (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x1)) e1) (interp (@set_nth R (IZR Z0) l n x1) e2) (interp (@set_nth R (IZR Z0) l n x1) e3)) (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x2)) e1) (interp (@set_nth R (IZR Z0) l n x2) e2) (interp (@set_nth R (IZR Z0) l n x2) e3)) *)
move: (IHe1 _ (H11 t y Ht' Hy)) => {IHe1} /=.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite nth_set_nth /= eqtype.eq_refl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply is_derive_ext => z.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite set_set_nth eqtype.eq_refl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite interp_set_nth.
intros t Ht.
apply continuity_2d_pt_ext_loc with (f := fun x y => interp (set_nth 0 (y :: l) (S n) x) a1).
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: locally_2d_impl (HexD H11 t Ht).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply locally_2d_forall => u v H.
apply sym_eq.
now apply is_derive_unique.
now apply H3.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite interp_set_nth.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: locally_2d_impl H2.
specialize (HexD H11 _ (conj (Rmin_l _ _) (Rmax_l _ _))).
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: locally_2d_impl_strong HexD.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply locally_2d_forall => u v H.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite nth_set_nth /= eqtype.eq_refl.
apply continuity_2d_pt_ext_loc.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: locally_2d_impl H.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply locally_2d_forall => u' v' H.
apply sym_eq.
apply is_derive_unique.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite set_set_nth eqtype.eq_refl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite interp_set_nth.
apply locally_singleton in H7.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: continuity_pt_ext H7.
intros t.
apply sym_eq.
apply (interp_set_nth (S n) (t :: l)).
intros t Ht.
apply is_derive_unique.
apply (IHe1 (t :: l)).
destruct H11 as (e,H11).
specialize (H11 t (nth 0 l n)).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(interp_domain_set_nth (S n)) /=.
apply H11.
apply Htw.
now split ; apply Rlt_le.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite /Rminus Rplus_opp_r Rabs_R0.
apply cond_pos.
(* . *)
clear C1 C2 C3.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
intros (H1&H2&H3&H4&H5&H6&H7&H8&H9&H10&H11&_).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite Rplus_comm Rmult_comm (Rmult_comm (interp l a2)) -Ropp_mult_distr_l_reverse.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite [_*_+_]Rplus_comm -Rplus_assoc.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(RInt_ext (fun x => Derive (fun t => interp (x :: set_nth 0 l n t) e1) (nth 0 l n))).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(interp_set_nth (S n) (interp l e2 :: l) e1) -(interp_set_nth (S n) (interp l e3 :: l) e1).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(interp_set_nth n l e2) -(interp_set_nth n l e3) /=.
apply (is_derive_RInt_param_bound_comp (fun x t => interp (t :: set_nth 0 l n x) e1)
  (fun x => interp (set_nth 0 l n x) e2) (fun x => interp (set_nth 0 l n x) e3)).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2!interp_set_nth.
exact H8.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite interp_set_nth.
exact H9.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite interp_set_nth.
exact H10.
(* Goal: @eq R (interp l1 e2) (interp l2 e2) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
now apply IHe2.
now apply IHe3.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2!interp_set_nth.
destruct H11 as (e&H11).
exists (pos_div_2 e).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
exists e => y Hy t Ht.
assert (Ht': Rmin (interp l e2) (interp l e3) - e < t < Rmax (interp l e2) (interp l e3) + e).
(* Goal: and (interp_domain l2 a) (@foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld) *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
split.
apply Rlt_le_trans with (2 := proj1 Ht).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite /Rminus -Rplus_min_distr_r.
apply Rplus_lt_compat_l.
apply Ropp_lt_contravar.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(Rplus_0_r (pos_div_2 e)) /= {2}(double_var e).
apply Rplus_lt_compat_l.
apply is_pos_div_2.
apply Rle_lt_trans with (1 := proj2 Ht).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -Rplus_max_distr_r.
apply Rplus_lt_compat_l.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(Rplus_0_r (pos_div_2 e)) /= {2}(double_var e).
apply Rplus_lt_compat_l.
apply is_pos_div_2.
eexists.
(* Goal: forall (_ : is_true (andb (is_const e2 n) (is_const e3 n))) (l : list R) (x1 x2 : R), @eq R (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x1)) e1) (interp (@set_nth R (IZR Z0) l n x1) e2) (interp (@set_nth R (IZR Z0) l n x1) e3)) (@RInt R_CompleteNormedModule (fun x : R => interp (@cons R x (@set_nth R (IZR Z0) l n x2)) e1) (interp (@set_nth R (IZR Z0) l n x2) e2) (interp (@set_nth R (IZR Z0) l n x2) e3)) *)
move: (IHe1 _ (H11 t y Ht' Hy)) => {IHe1} /=.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite nth_set_nth /= eqtype.eq_refl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply is_derive_ext => z.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite set_set_nth eqtype.eq_refl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite 2!interp_set_nth.
intros t Ht.
apply continuity_2d_pt_ext_loc with (f := fun x y => interp (set_nth 0 (y :: l) (S n) x) a1).
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: locally_2d_impl (HexD H11 t Ht).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply locally_2d_forall => u v H.
apply sym_eq.
now apply is_derive_unique.
now apply H3.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite interp_set_nth.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: locally_2d_impl H1.
specialize (HexD H11 _ (conj (Rmin_l _ _) (Rmax_l _ _))).
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: locally_2d_impl_strong HexD.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply locally_2d_forall => u v H.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite nth_set_nth /= eqtype.eq_refl.
apply continuity_2d_pt_ext_loc.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: locally_2d_impl H.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply locally_2d_forall => u' v' H.
apply sym_eq.
apply is_derive_unique.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite set_set_nth eqtype.eq_refl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite interp_set_nth.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: locally_2d_impl H2.
specialize (HexD H11 _ (conj (Rmin_r _ _) (Rmax_r _ _))).
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: locally_2d_impl_strong HexD.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply locally_2d_forall => u v H.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite nth_set_nth /= eqtype.eq_refl.
apply continuity_2d_pt_ext_loc.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: locally_2d_impl H.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
apply locally_2d_forall => u' v' H.
apply sym_eq.
apply is_derive_unique.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
now rewrite set_set_nth eqtype.eq_refl.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite interp_set_nth.
apply locally_singleton in H5.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: continuity_pt_ext H5.
intros t.
apply sym_eq.
apply (interp_set_nth (S n) (t :: l)).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite interp_set_nth.
apply locally_singleton in H7.
(* Goal: interp_domain (@cons R t (@set_nth R R0 l2 n u)) b *)
apply: continuity_pt_ext H7.
intros t.
apply sym_eq.
apply (interp_set_nth (S n) (t :: l)).
intros t Ht.
apply is_derive_unique.
apply (IHe1 (t :: l)).
destruct H11 as (e,H11).
specialize (H11 t (nth 0 l n)).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite -(interp_domain_set_nth (S n)) /=.
apply H11.
apply Htw.
now split ; apply Rlt_le.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite /Rminus Rplus_opp_r Rabs_R0.
apply cond_pos.
Qed.

Fixpoint simplify_domain (d : domain) : domain :=
  match d with
  | And ld =>
    let l := foldr (fun d acc =>
      let d' := simplify_domain d in
      match d' with
      | Always => acc
      | And l => cat l acc
      | Never => Never :: nil
      | _ => d' :: acc
      end) nil ld in
    match l with
    | nil => Always
    | d :: nil => d
    | _ => And l
    end
  | Forall e1 e2 d =>
    let d' := simplify_domain d in
    match d' with
    | Always => Always
    | Never => Never
    | _ => Forall e1 e2 d'
    end
  | Forone e d =>
    let d' := simplify_domain d in
    match d' with
    | Always => Always
    | Never => Never
    | _ => Forone e d'
    end
  | Locally n d =>
    let d' := simplify_domain d in
    match d' with
    | Always => Always
    | Never => Never
    | _ => Locally n d'
    end
  | Locally2 m n d =>
    let d' := simplify_domain d in
    match d' with
    | Always => Always
    | Never => Never
    | _ => Locally2 m n d'
    end
  | ForallWide n e1 e2 d =>
    let d' := simplify_domain d in
    match d' with
    | Always => Always
    | Never => Never
    | _ => ForallWide n e1 e2 d'
    end
  | _ => d
  end.

Lemma simplify_domain_correct :
  forall d l,
  interp_domain l (simplify_domain d) -> interp_domain l d.
Proof.
intros d.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
induction d using domain_ind' => l ; try easy ; simpl.
(* And *)
set (f := fun (d : domain) (acc : seq domain) =>
  match simplify_domain d with
  | Never => Never :: nil
  | Always => acc
  | And l0 => l0 ++ acc
  | _ => simplify_domain d :: acc
  end).
intros H'.
have: (foldr (fun d acc => interp_domain l d /\ acc) True (foldr f nil ld)).
(* Goal: forall _ : p (interp l1 e), p (interp l2 e) *)
(* Goal: forall _ : ex_derive_Rn k f n (@nth R (IZR Z0) (@map expr R (interp l1) le)), ex_derive_Rn k f n (@nth R (IZR Z0) (@map expr R (interp l2) le)) *)
(* Goal: forall _ : and (locally_2d (fun u v : R => ex_derive_Rn k f m (fun i : nat => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else @nth R (IZR Z0) (@map expr R (interp l1) le) i)) (@nth R (IZR Z0) (@map expr R (interp l1) le) m) (@nth R (IZR Z0) (@map expr R (interp l1) le) n)) (continuity_2d_pt (fun u v : R => Derive_Rn k f m (fun i : nat => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else @nth R (IZR Z0) (@map expr R (interp l1) le) i)) (@nth R (IZR Z0) (@map expr R (interp l1) le) m) (@nth R (IZR Z0) (@map expr R (interp l1) le) n)), and (locally_2d (fun u v : R => ex_derive_Rn k f m (fun i : nat => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else @nth R (IZR Z0) (@map expr R (interp l2) le) i)) (@nth R (IZR Z0) (@map expr R (interp l2) le) m) (@nth R (IZR Z0) (@map expr R (interp l2) le) n)) (continuity_2d_pt (fun u v : R => Derive_Rn k f m (fun i : nat => if ssrnat.eqn i m then u else if ssrnat.eqn i n then v else @nth R (IZR Z0) (@map expr R (interp l2) le) i)) (@nth R (IZR Z0) (@map expr R (interp l2) le) m) (@nth R (IZR Z0) (@map expr R (interp l2) le) n)) *)
(* Goal: forall _ : continuity_pt (fun x : R => interp (@set_nth R R0 l1 n x) e) (@nth R R0 l1 n), continuity_pt (fun x : R => interp (@set_nth R R0 l2 n x) e) (@nth R R0 l2 n) *)
(* Goal: forall _ : continuity_2d_pt (fun x y : R => interp (@set_nth R R0 (@set_nth R R0 l1 n y) m x) e) (@nth R R0 l1 m) (@nth R R0 l1 n), continuity_2d_pt (fun x y : R => interp (@set_nth R R0 (@set_nth R R0 l2 n y) m x) e) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex_RInt R_NormedModule (fun x : R => interp (@cons R x l1) f) (interp l1 e1) (interp l1 e2), @ex_RInt R_NormedModule (fun x : R => interp (@cons R x l2) f) (interp l2 e1) (interp l2 e2) *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l1 n y)) f) (interp l1 e1) (interp l1 e2)), @locally R_UniformSpace (@nth R R0 l2 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l2 n y)) f) (interp l2 e1) (interp l2 e2)) *)
(* Goal: forall _ : @ex posreal (fun eps : posreal => @locally R_UniformSpace (@nth R R0 l1 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l1 n y)) f) (Rminus (interp l1 e) (pos eps)) (Rplus (interp l1 e) (pos eps)))), @ex posreal (fun eps : posreal => @locally R_UniformSpace (@nth R R0 l2 n) (fun y : R => @ex_RInt R_NormedModule (fun t : R => interp (@cons R t (@set_nth R R0 l2 n y)) f) (Rminus (interp l2 e) (pos eps)) (Rplus (interp l2 e) (pos eps)))) *)
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True ld, @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
by move: (foldr f nil ld) H' => [|h [|s]].
clear H'.
revert H.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
induction ld as [|t] => H.
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.
(* Goal: forall _ : @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l1 d) acc) True (@cons domain a ld), @foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True (@cons domain a ld) *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
simpl in H |- *.
(* Goal: forall n : nat, @eq R (@nth R (IZR Z0) (@cons R (interp l1 a) (@map expr R (interp l1) le)) n) (@nth R (IZR Z0) (@cons R (interp l2 a) (@map expr R (interp l2) le)) n) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (AppExtD k f n le)) (interp l2 (AppExtD k f n le)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (App e1 e2)) (interp l2 (App e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Subst e1 e2)) (interp l2 (Subst e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Cst r)) (interp l2 (Cst r)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Binary o e1 e2)) (interp l2 (Binary o e1 e2)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Unary o e)) (interp l2 (Unary o e)) *)
(* Goal: forall (l1 l2 : list R) (_ : forall k : nat, @eq R (@nth R (IZR Z0) l1 k) (@nth R (IZR Z0) l2 k)), @eq R (interp l1 (Int e1 e2 e3)) (interp l2 (Int e1 e2 e3)) *)
destruct H as (Ha,Hb).
revert Ha.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite /f -/f.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
case (simplify_domain t) ; simpl.
(* . *)
now intros _ (H,_).
(* . *)
exact (fun H1 H2 => conj (H1 l I) (IHld Hb H2)).
(* . *)
intros df e H1 (H2,H3).
exact (conj (H1 l H2) (IHld Hb H3)).
(* . *)
intros n k f' le H1 (H2,H3).
exact (conj (H1 l H2) (IHld Hb H3)).
(* . *)
intros m n k f' le H1 (H2,H3).
exact (conj (H1 l H2) (IHld Hb H3)).
(* . *)
intros n e H1 (H2,H3).
exact (conj (H1 l H2) (IHld Hb H3)).
(* . *)
intros m n e H1 (H2,H3).
exact (conj (H1 l H2) (IHld Hb H3)).
(* . *)
intros e0 e1 e2 H1 (H2,H3).
exact (conj (H1 l H2) (IHld Hb H3)).
(* . *)
intros n e0 e1 e2 H1 (H2,H3).
exact (conj (H1 l H2) (IHld Hb H3)).
(* . *)
intros n e0 e1 H1 (H2,H3).
exact (conj (H1 l H2) (IHld Hb H3)).
(* . *)
intros ls H1 H2.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
rewrite foldr_cat in H2.
refine ((fun H => conj (H1 l (proj1 H)) (IHld Hb (proj2 H))) _).
revert H2.
generalize (foldr f nil ld).
clear.
induction ls.
done.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
(* Goal: and (interp_domain l2 a) (@foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld) *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
split.
(* Goal: and (interp_domain l2 a) (@foldr domain Prop (fun (d : domain) (acc : Prop) => and (interp_domain l2 d) acc) True ld) *)
(* Goal: forall (_ : forall (t : R) (_ : and (Rle (Rmin (interp l1 e1) (interp l1 e2)) t) (Rle t (Rmax (interp l1 e1) (interp l1 e2)))), interp_domain (@cons R t l1) b) (t : R) (_ : and (Rle (Rmin (interp l2 e1) (interp l2 e2)) t) (Rle t (Rmax (interp l2 e1) (interp l2 e2)))), interp_domain (@cons R t l2) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
split.
apply H2.
eapply (fun s H => proj1 (IHls s H)).
apply H2.
now apply IHls.
(* . *)
intros e1 e2 d H1 (H2,H3).
exact (conj (H1 l H2) (IHld Hb H3)).
(* . *)
intros e d H1 (H2,H3).
exact (conj (H1 l H2) (IHld Hb H3)).
(* . *)
intros n d H1 (H2,H3).
exact (conj (H1 l H2) (IHld Hb H3)).
(* . *)
intros m n d H1 (H2,H3).
exact (conj (H1 l H2) (IHld Hb H3)).
(* . *)
intros n e1 e2 d H1 (H2,H3).
exact (conj (H1 l H2) (IHld Hb H3)).
(* Forall *)
revert IHd.
assert (HH: forall d', (forall l, interp_domain l d' -> interp_domain l d) ->
  interp_domain l (Forall e1 e2 d') -> interp_domain l (Forall e1 e2 d)).
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
intros d' H1 H2 t Ht.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : AbsRing.sort R_AbsRing => interp (@set_nth R R0 l n x) e) (@nth R R0 l n) (interp l d1) *)
apply H1.
now apply H2.
destruct (simplify_domain d) ; try (apply HH ; fail).
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
intros H _ t Ht.
(* Goal: interp_domain (@cons R t l1) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
now apply H.
(* Forone *)
revert IHd.
assert (HH: forall d', (forall l, interp_domain l d' -> interp_domain l d) ->
  interp_domain l (Forone e d') -> interp_domain l (Forone e d)).
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
intros d' H1 H2.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : AbsRing.sort R_AbsRing => interp (@set_nth R R0 l n x) e) (@nth R R0 l n) (interp l d1) *)
apply H1.
now apply H2.
destruct (simplify_domain d) ; apply HH.
(* Locally *)
revert IHd.
assert (HH: forall d', (forall l, interp_domain l d' -> interp_domain l d) ->
  interp_domain l (Locally n d') -> interp_domain l (Locally n d)).
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
intros d' H1 (eps,H2).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
exists eps => t Ht.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : AbsRing.sort R_AbsRing => interp (@set_nth R R0 l n x) e) (@nth R R0 l n) (interp l d1) *)
apply H1.
now apply H2.
destruct (simplify_domain d) ; try (apply HH ; fail).
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
intros H _.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
exists (mkposreal _ Rlt_0_1) => t Ht.
(* Goal: interp_domain (@cons R t l1) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
now apply H.
(* Locally2 *)
revert IHd.
assert (HH: forall d', (forall l, interp_domain l d' -> interp_domain l d) ->
  interp_domain l (Locally2 m n d') -> interp_domain l (Locally2 m n d)).
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
intros d' H1 (eps,H2).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
exists eps => u v Hu Hv.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : AbsRing.sort R_AbsRing => interp (@set_nth R R0 l n x) e) (@nth R R0 l n) (interp l d1) *)
apply H1.
now apply H2.
destruct (simplify_domain d) ; try (apply HH ; fail).
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
intros H _.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
exists (mkposreal _ Rlt_0_1) => u v Hu Hv.
(* Goal: interp_domain (@cons R t l1) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
now apply H.
(* ForallWide *)
revert IHd.
assert (HH: forall d', (forall l, interp_domain l d' -> interp_domain l d) ->
  interp_domain l (ForallWide n e1 e2 d') -> interp_domain l (ForallWide n e1 e2 d)).
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
intros d' H1 (e,H2).
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
exists e => t u Ht Hu.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : AbsRing.sort R_AbsRing => interp (@set_nth R R0 l n x) e) (@nth R R0 l n) (interp l d1) *)
apply H1.
now apply H2.
destruct (simplify_domain d) ; try (apply HH ; fail).
(* Goal: forall _ : not (is_true (andb (negb true) true)), @eq bool true true *)
(* Goal: forall _ : not (is_true (andb (negb false) true)), @eq bool false true *)
(* Goal: forall _ : not (is_true (andb (negb (is_const (@nth expr (Cst (IZR Z0)) l k) n)) false)), @eq bool (is_const (@nth expr (Cst (IZR Z0)) l k) n) true *)
easy.
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
simpl.
intros H _.
(* Goal: @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) t) (interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le t)) *)
(* Goal: forall _ : forall _ : not (is_true (orb false (@in_mem nat m (@mem nat (seq_predType ssrnat.nat_eqType) s)))), @eq bool (is_const (@nth expr (Cst (IZR Z0)) le m) n) true, @eq R (@nth R (IZR Z0) (@map expr R (interp (@set_nth R (IZR Z0) l n x)) le) m) (@foldr nat (forall _ : nat, R) (fun (v : nat) (acc : forall _ : nat, R) (i : nat) => if ssrnat.eqn i v then interp (@set_nth R (IZR Z0) l n x) (@nth expr (Cst (IZR Z0)) le v) else acc i) (@nth R (IZR Z0) (@map expr R (interp l) le)) s m) *)
exists (mkposreal _ Rlt_0_1) => u v Hu Hv.
(* Goal: interp_domain (@cons R t l1) b *)
(* Goal: forall _ : interp_domain (@cons R (interp l1 e) l1) b, interp_domain (@cons R (interp l2 e) l2) b *)
(* Goal: forall _ : @locally R_UniformSpace (@nth R R0 l1 n) (fun x : R => interp_domain (@set_nth R R0 l1 n x) b), @locally R_UniformSpace (@nth R R0 l2 n) (fun x : R => interp_domain (@set_nth R R0 l2 n x) b) *)
(* Goal: forall _ : locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l1 n y) m x) b) (@nth R R0 l1 m) (@nth R R0 l1 n), locally_2d (fun x y : R => interp_domain (@set_nth R R0 (@set_nth R R0 l2 n y) m x) b) (@nth R R0 l2 m) (@nth R R0 l2 n) *)
(* Goal: forall _ : @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l1 e1) (interp l1 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l1 e1) (interp l1 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l1 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l1 n u)) b), @ex posreal (fun d : posreal => forall (t u : R) (_ : and (Rlt (Rminus (Rmin (interp l2 e1) (interp l2 e2)) (pos d)) t) (Rlt t (Rplus (Rmax (interp l2 e1) (interp l2 e2)) (pos d)))) (_ : Rlt (Rabs (Rminus u (@nth R R0 l2 n))) (pos d)), interp_domain (@cons R t (@set_nth R R0 l2 n u)) b) *)
now apply H.
Qed.

Class UnaryDiff f := {UnaryDiff_f' : R -> R ;
  UnaryDiff_H : forall x, is_derive f x (UnaryDiff_f' x)}.
Class UnaryDiff' f := {UnaryDiff'_f' : R -> R ; UnaryDiff'_df : R -> Prop ;
  UnaryDiff'_H : forall x, UnaryDiff'_df x -> is_derive f x (UnaryDiff'_f' x)}.

Global Instance UnaryDiff_exp : UnaryDiff exp.
Proof.
(* Goal: UnaryDiff exp *)
  exists exp.
(* Goal: forall (x : R) (_ : Rlt (IZR Z0) x), @is_derive R_AbsRing R_NormedModule sqrt x (Rinv (Rmult (IZR (Zpos (xO xH))) (sqrt x))) *)
  move => x ; by apply is_derive_Reals, derivable_pt_lim_exp.
Defined.
Global Instance UnaryDiff_pow : forall n : nat, UnaryDiff (fun x => pow x n).
Proof.
(* Goal: forall n : nat, UnaryDiff (fun x : AbsRing.sort R_AbsRing => pow x n) *)
  intro n.
(* Goal: UnaryDiff (fun x : AbsRing.sort R_AbsRing => pow x n) *)
  exists (fun x => INR n * x ^ (Peano.pred n)).
(* Goal: forall (x : R) (_ : Rlt (IZR Z0) x), @is_derive R_AbsRing R_NormedModule sqrt x (Rinv (Rmult (IZR (Zpos (xO xH))) (sqrt x))) *)
  move => x ; by apply is_derive_Reals, derivable_pt_lim_pow.
Defined.
Global Instance UnaryDiff_Rabs : UnaryDiff' Rabs.
Proof.
(* Goal: UnaryDiff' Rabs *)
  exists (fun x => sign x) (fun x => x <> 0).
(* Goal: forall (x : R) (_ : Rlt (IZR Z0) x), @is_derive R_AbsRing R_NormedModule sqrt x (Rinv (Rmult (IZR (Zpos (xO xH))) (sqrt x))) *)
  move => x Hx0 ; by apply filterdiff_Rabs.
Defined.
Global Instance UnaryDiff_Rsqr : UnaryDiff Rsqr.
Proof.
(* Goal: UnaryDiff Rsqr *)
  exists (fun x => 2 * x).
(* Goal: forall (x : R) (_ : Rlt (IZR Z0) x), @is_derive R_AbsRing R_NormedModule sqrt x (Rinv (Rmult (IZR (Zpos (xO xH))) (sqrt x))) *)
  move => x ; by apply is_derive_Reals, derivable_pt_lim_Rsqr.
Defined.
Global Instance UnaryDiff_cosh : UnaryDiff cosh.
Proof.
(* Goal: UnaryDiff cosh *)
  exists sinh.
(* Goal: forall (x : R) (_ : Rlt (IZR Z0) x), @is_derive R_AbsRing R_NormedModule sqrt x (Rinv (Rmult (IZR (Zpos (xO xH))) (sqrt x))) *)
  move => x ; by apply is_derive_Reals, derivable_pt_lim_cosh.
Defined.
Global Instance UnaryDiff_sinh : UnaryDiff sinh.
Proof.
(* Goal: UnaryDiff sinh *)
  exists (fun x => cosh x).
(* Goal: forall (x : R) (_ : Rlt (IZR Z0) x), @is_derive R_AbsRing R_NormedModule sqrt x (Rinv (Rmult (IZR (Zpos (xO xH))) (sqrt x))) *)
  move => x ; by apply is_derive_Reals, derivable_pt_lim_sinh.
Defined.
Global Instance UnaryDiff_ps_atan : UnaryDiff' ps_atan.
Proof.
(* Goal: UnaryDiff' ps_atan *)
  exists (fun x => /(1+x^2)) (fun x => -1 < x < 1).
(* Goal: forall (x : R) (_ : Rlt (IZR Z0) x), @is_derive R_AbsRing R_NormedModule sqrt x (Rinv (Rmult (IZR (Zpos (xO xH))) (sqrt x))) *)
  move => x Hx ; by apply is_derive_Reals, derivable_pt_lim_ps_atan.
Defined.
Global Instance UnaryDiff_atan : UnaryDiff atan.
Proof.
(* Goal: UnaryDiff atan *)
  exists (fun x => /(1+x^2)).
(* Goal: forall (x : R) (_ : Rlt (IZR Z0) x), @is_derive R_AbsRing R_NormedModule sqrt x (Rinv (Rmult (IZR (Zpos (xO xH))) (sqrt x))) *)
  move => x ; by apply is_derive_Reals, derivable_pt_lim_atan.
Defined.
Global Instance UnaryDiff_ln : UnaryDiff' ln.
Proof.
(* Goal: UnaryDiff' ln *)
  exists (fun x => /x) (fun x => 0 < x).
(* Goal: forall (x : R) (_ : Rlt (IZR Z0) x), @is_derive R_AbsRing R_NormedModule sqrt x (Rinv (Rmult (IZR (Zpos (xO xH))) (sqrt x))) *)
  move => x Hx ; by apply is_derive_Reals, derivable_pt_lim_ln.
Defined.
Global Instance UnaryDiff_cos : UnaryDiff cos.
Proof.
(* Goal: UnaryDiff cos *)
  exists (fun x => - sin x ).
(* Goal: forall (x : R) (_ : Rlt (IZR Z0) x), @is_derive R_AbsRing R_NormedModule sqrt x (Rinv (Rmult (IZR (Zpos (xO xH))) (sqrt x))) *)
  move => x ; by apply is_derive_Reals, derivable_pt_lim_cos.
Defined.
Global Instance UnaryDiff_sin : UnaryDiff sin.
Proof.
(* Goal: UnaryDiff sin *)
  exists cos.
(* Goal: forall (x : R) (_ : Rlt (IZR Z0) x), @is_derive R_AbsRing R_NormedModule sqrt x (Rinv (Rmult (IZR (Zpos (xO xH))) (sqrt x))) *)
  move => x ; by apply is_derive_Reals, derivable_pt_lim_sin.
Defined.
Global Instance UnaryDiff_sqrt : UnaryDiff' sqrt.
Proof.
(* Goal: UnaryDiff' sqrt *)
  exists (fun x => / (2 * sqrt x)) (fun x => 0 < x).
(* Goal: forall (x : R) (_ : Rlt (IZR Z0) x), @is_derive R_AbsRing R_NormedModule sqrt x (Rinv (Rmult (IZR (Zpos (xO xH))) (sqrt x))) *)
  move => x Hx ; by apply is_derive_Reals, derivable_pt_lim_sqrt.
Defined.





Definition var : nat -> R.
(* Goal: forall _ : nat, R *)
exact (fun _ => R0).
Qed.

Ltac reify_helper a b z d :=
  match a with
  | Cst _ =>
    match b with
    | Cst _ => constr:(Cst d)
    | _ => z
    end
  | _ => z
  end.

Ltac reify fct nb :=
  let rec reify_aux fct l i :=
    match fct with
    | ?f ?a => let e := reify a nb in reify_aux f (e :: l) (S i)
    | _ => constr:((fct, rev l, i))
    end in
  match fct with
  | var ?i =>
    eval vm_compute in (Var (nb - i))
  | Rplus ?a ?b =>
    let a' := reify a nb in
    let b' := reify b nb in
    reify_helper a' b' (Binary Eplus a' b') fct
  | Ropp ?a =>
    let a' := reify a nb in
    match a' with
    | Cst _ => constr:(Cst fct)
    | _ => constr:(Unary Eopp a')
    end
  | Rminus ?a ?b =>
    let a' := reify a nb in
    let b' := reify b nb in
    reify_helper a' b' (Binary Eplus a' (Unary Eopp b')) fct
  | Rmult ?a ?b =>
    let a' := reify a nb in
    let b' := reify b nb in
    reify_helper a' b' (Binary Emult a' b') fct
  | Rinv ?a =>
    let a' := reify a nb in
    match a' with
    | Cst _ => constr:(Cst fct)
    | _ => constr:(Unary Einv a')
    end
  | Rdiv ?a ?b =>
    let a' := reify a nb in
    let b' := reify b nb in
    reify_helper a' b' (Binary Emult a' (Unary Einv b')) fct
  | RInt ?f ?a ?b =>
    let f := eval cbv beta in (f (var (S nb))) in
    let f' := reify f (S nb) in
    let a' := reify a nb in
    let b' := reify b nb in
    constr:(Int f' a' b')
  | pow ?f ?n =>
      reify ((fun x => pow x n) f) nb
  | context [var ?i] =>
    match fct with
    | ?f ?a =>
      let e := reify a nb in
      let ud := constr:(_ : UnaryDiff f) in
      constr:(Unary (Efct f (@UnaryDiff_f' f ud) (@UnaryDiff_H f ud)) e)
    | ?f ?a =>
      let e := reify a nb in
      let ud := constr:(_ : UnaryDiff' f) in
      constr:(Unary (Efct' f (@UnaryDiff'_f' f ud) (@UnaryDiff'_df f ud) (@UnaryDiff'_H f ud)) e)
    | _ =>
      match reify_aux fct (Nil expr) O with
      | (?f,?le,?k) => constr:(AppExt k f le)
      end
    end
  | _ => constr:(Cst fct)
  end.

Lemma auto_derive_helper :
  forall (e : expr) l n,
  let '(a,b) := D e n in
  interp_domain l (simplify_domain b) ->
  is_derive (fun x => interp (set_nth R0 l n x) e) (nth R0 l n) (interp l a).
Proof.
(* Goal: forall (e : expr) (l : list R) (n : nat), let 'pair a b := D e n in forall _ : interp_domain l (simplify_domain b), @is_derive R_AbsRing R_NormedModule (fun x : AbsRing.sort R_AbsRing => interp (@set_nth R R0 l n x) e) (@nth R R0 l n) (interp l a) *)
intros e l n.
(* Goal: let 'pair a b := D e n in forall _ : interp_domain l (simplify_domain b), @is_derive R_AbsRing R_NormedModule (fun x : AbsRing.sort R_AbsRing => interp (@set_nth R R0 l n x) e) (@nth R R0 l n) (interp l a) *)
generalize (D_correct e l n).
(* Goal: forall _ : let 'pair a b := D e n in forall _ : interp_domain l b, @is_derive R_AbsRing R_NormedModule (fun x : AbsRing.sort R_AbsRing => interp (@set_nth R R0 l n x) e) (@nth R R0 l n) (interp l a), let 'pair a b := D e n in forall _ : interp_domain l (simplify_domain b), @is_derive R_AbsRing R_NormedModule (fun x : AbsRing.sort R_AbsRing => interp (@set_nth R R0 l n x) e) (@nth R R0 l n) (interp l a) *)
destruct (D e n) as (d1,d2).
(* Goal: forall (_ : forall _ : interp_domain l d2, @is_derive R_AbsRing R_NormedModule (fun x : AbsRing.sort R_AbsRing => interp (@set_nth R R0 l n x) e) (@nth R R0 l n) (interp l d1)) (_ : interp_domain l (simplify_domain d2)), @is_derive R_AbsRing R_NormedModule (fun x : AbsRing.sort R_AbsRing => interp (@set_nth R R0 l n x) e) (@nth R R0 l n) (interp l d1) *)
intros H1 H2.
(* Goal: @is_derive R_AbsRing R_NormedModule (fun x : AbsRing.sort R_AbsRing => interp (@set_nth R R0 l n x) e) (@nth R R0 l n) (interp l d1) *)
apply H1.
(* Goal: interp_domain l d2 *)
now apply simplify_domain_correct.
Qed.

Ltac auto_derive_fun f :=
  let f := eval cbv beta in (f (var O)) in
  let e := reify f O in
  let H := fresh "H" in
  assert (H := fun x => auto_derive_helper e (x :: nil) 0) ;
  simpl in H ;
  unfold Derive_Rn, ex_derive_Rn in H ;
  simpl in H ;
  revert H.

Ltac auto_derive :=
  match goal with
  | |- is_derive ?f ?v ?l =>
    auto_derive_fun f ;
    let H := fresh "H" in
    intro H ;
    refine (@eq_ind R _ (is_derive f v) (H v _) l _) ;
    clear H
  | |- ex_derive ?f ?v =>
    eexists ;
    auto_derive_fun f ;
    let H := fresh "H" in
    intro H ;
    apply (H v) ;
    clear H
  | |- derivable_pt_lim ?f ?v ?l =>
    apply is_derive_Reals ;
    auto_derive
  | |- derivable_pt ?f ?v =>
    apply ex_derive_Reals_0 ;
    auto_derive
  end.
