Skip to content

Commit 4ae0255

Browse files
committed
proposal for signed representatives througout
1 parent 599bce0 commit 4ae0255

1 file changed

Lines changed: 202 additions & 9 deletions

File tree

theories/algebra/PolyReduce.ec

Lines changed: 202 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -790,15 +790,208 @@ end PolyReduceZpCentered.
790790
(* ==================================================================== *)
791791
abstract theory PolyReduceZpCenteredField.
792792
793-
clone include PolyReduceZpCentered.
793+
clone include ZpCenteredField.
794+
795+
clone include PolyReduceZp with
796+
theory Zp <- ZMR.
797+
import PolyReduce.
794798
import ZMR.
795-
axiom prime_p : prime p.
796-
797-
(* Field-only lemmas (creprN, creprND, ...) live in ZpCenteredField. Pull *)
798-
(* them in as a sub-theory with types + prime_p unified — no content *)
799-
(* duplication, just an extra proof obligation for the rebinding. *)
800-
clone import ZpCenteredField as ZpCF with
801-
theory ZMR <- ZMR
802-
proof prime_p by exact prime_p.
799+
800+
(* ==================================================================== *)
801+
(* Centered-representation infinity-norm machinery on polyXnD1. *)
802+
(* (Duplicated from [PolyReduceZpCentered] — both theories provide the *)
803+
(* same inf-norm surface on top of their respective coefficient rings.)*)
804+
(* ==================================================================== *)
805+
806+
op poly_infnorm_lt (q : polyXnD1) (b : int) : bool =
807+
forall i, 0 <= i < n => `|q.[i]| < b.
808+
809+
op poly_infnorm_le (q : polyXnD1) (b : int) : bool =
810+
forall i, 0 <= i < n => `|q.[i]| <= b.
811+
812+
lemma poly_infnorm_lt_le (q : polyXnD1) (b : int) :
813+
poly_infnorm_lt q b => poly_infnorm_le q b.
814+
proof. by move=> H i Hi; have := H i Hi; smt(). qed.
815+
816+
lemma poly_infnorm_le_mono (q : polyXnD1) (b1 b2 : int) :
817+
b1 <= b2 => poly_infnorm_le q b1 => poly_infnorm_le q b2.
818+
proof. by move=> Hb H i Hi; have := H i Hi; smt(). qed.
819+
820+
lemma poly_infnorm_lt_mono (q : polyXnD1) (b1 b2 : int) :
821+
b1 <= b2 => poly_infnorm_lt q b1 => poly_infnorm_lt q b2.
822+
proof. by move=> Hb H i Hi; have := H i Hi; smt(). qed.
823+
824+
lemma poly_infnorm_le_ub (q : polyXnD1) :
825+
poly_infnorm_le q (p %/ 2)
826+
by move=> i Hi; smt(abs_zp_ub).
827+
828+
lemma poly_infnorm_le_zero :
829+
poly_infnorm_le zeroXnD1 0.
830+
proof. move=> i Hi; rewrite rcoeff0; smt(abs_zp_zero). qed.
831+
832+
lemma poly_infnorm_le_add (q r : polyXnD1) (bq br : int) :
833+
poly_infnorm_le q bq
834+
=> poly_infnorm_le r br
835+
=> poly_infnorm_le (q + r) (bq + br).
836+
proof.
837+
move=> Hq Hr i Hi.
838+
rewrite rcoeffD; have := abs_zp_triangle q.[i] r.[i].
839+
have := Hq i Hi; have := Hr i Hi; smt().
840+
qed.
841+
842+
lemma poly_infnorm_lt_add (q r : polyXnD1) (bq br : int) :
843+
poly_infnorm_lt q bq
844+
=> poly_infnorm_lt r br
845+
=> poly_infnorm_lt (q + r) (bq + br).
846+
proof.
847+
move=> Hq Hr i Hi.
848+
rewrite rcoeffD; have := abs_zp_triangle q.[i] r.[i].
849+
have := Hq i Hi; have := Hr i Hi; smt().
850+
qed.
851+
852+
lemma poly_infnorm_le_opp (q : polyXnD1) (b : int) :
853+
poly_infnorm_le q b => poly_infnorm_le (- q) b.
854+
proof.
855+
move=> H i Hi.
856+
rewrite -rcoeffN -abs_zpN.
857+
have := H i Hi; smt().
858+
qed.
859+
860+
lemma poly_infnorm_lt_opp (q : polyXnD1) (b : int) :
861+
poly_infnorm_lt q b => poly_infnorm_lt (- q) b.
862+
proof.
863+
move=> H i Hi.
864+
rewrite -rcoeffN -abs_zpN.
865+
have := H i Hi; smt().
866+
qed.
867+
868+
op inf_norm (q : polyXnD1) : Nneg.nneg =
869+
Nneg.BMaxN.bigi predT (fun i => Nneg.ofint `|q.[i]|) 0 n.
870+
871+
lemma poly_infnorm_le_iff (q : polyXnD1) (b : int) :
872+
0 <= b =>
873+
(poly_infnorm_le q b <=> Nneg.(<=) (inf_norm q) (Nneg.ofint b)).
874+
proof.
875+
move=> ge0_b; rewrite /poly_infnorm_le /inf_norm Nneg.BMaxN.big_le_iff.
876+
have valK_b : Nneg.val (Nneg.ofint b) = b by apply Nneg.valK_pos.
877+
have step : forall a, 0 <= a =>
878+
Nneg.(<=) (Nneg.ofint a) (Nneg.ofint b) <=> a <= b.
879+
- move=> a ge0_a; rewrite /Nneg.(<=) valK_b.
880+
by have -> : Nneg.val (Nneg.ofint a) = a by apply Nneg.valK_pos.
881+
split.
882+
- move=> H; split; first by apply Nneg.zero_le.
883+
move=> i; rewrite mem_range => Hi _ /=.
884+
have ge0_a : 0 <= `|q.[i]| by smt().
885+
by rewrite step //; apply H; smt().
886+
- case=> _ H i Hi.
887+
have Hi' : i \in range 0 n by rewrite mem_range; smt().
888+
have ge0_a : 0 <= `|q.[i]| by smt().
889+
have := H i Hi' _; first by [].
890+
by rewrite /= step.
891+
qed.
892+
893+
lemma poly_infnorm_lt_iff (q : polyXnD1) (b : int) :
894+
1 <= b =>
895+
(poly_infnorm_lt q b <=> Nneg.(<=) (inf_norm q) (Nneg.ofint (b - 1))).
896+
proof.
897+
move=> ge1_b.
898+
have -> : poly_infnorm_lt q b <=> poly_infnorm_le q (b - 1)
899+
by rewrite /poly_infnorm_lt /poly_infnorm_le; smt().
900+
by apply poly_infnorm_le_iff; smt().
901+
qed.
902+
903+
(* -------------------------------------------------------------------- *)
904+
(* Vector / Matrix layer. *)
905+
906+
clone import DynMatrix as VM with
907+
theory ZR <- ComRingDflInv.
908+
import VM.Vectors.
909+
910+
op vec_infnorm_lt (v : vector) (b : int) : bool =
911+
forall i, 0 <= i < size v => poly_infnorm_lt v.[i] b.
912+
913+
op vec_infnorm_le (v : vector) (b : int) : bool =
914+
forall i, 0 <= i < size v => poly_infnorm_le v.[i] b.
915+
916+
op inf_normv (v : vector) : Nneg.nneg =
917+
Nneg.BMaxN.bigi predT (fun i => inf_norm v.[i]) 0 (size v).
918+
919+
lemma vec_infnorm_le_iff (v : vector) (b : int) :
920+
0 <= b =>
921+
(vec_infnorm_le v b <=> Nneg.(<=) (inf_normv v) (Nneg.ofint b)).
922+
proof.
923+
move=> ge0_b; rewrite /vec_infnorm_le /inf_normv Nneg.BMaxN.big_le_iff.
924+
split.
925+
- move=> H; split; first by apply Nneg.zero_le.
926+
move=> i; rewrite mem_range => Hi _ /=.
927+
have := H i _; first by smt().
928+
by rewrite -(poly_infnorm_le_iff _ _ ge0_b).
929+
- case=> _ H i Hi.
930+
have Hi' : i \in range 0 (size v) by rewrite mem_range; smt().
931+
have := H i Hi' _; first by [].
932+
by rewrite /= -(poly_infnorm_le_iff _ _ ge0_b).
933+
qed.
934+
935+
lemma vec_infnorm_lt_iff (v : vector) (b : int) :
936+
1 <= b =>
937+
(vec_infnorm_lt v b <=> Nneg.(<=) (inf_normv v) (Nneg.ofint (b - 1))).
938+
proof.
939+
move=> ge1_b.
940+
have -> : vec_infnorm_lt v b <=> vec_infnorm_le v (b - 1).
941+
- rewrite /vec_infnorm_lt /vec_infnorm_le.
942+
split=> H i Hi; have := H i Hi.
943+
+ by rewrite /poly_infnorm_lt /poly_infnorm_le; smt().
944+
+ by rewrite /poly_infnorm_lt /poly_infnorm_le; smt().
945+
by apply vec_infnorm_le_iff; smt().
946+
qed.
947+
948+
import VM.Matrices.
949+
950+
op mat_infnorm_lt (m : matrix) (b : int) : bool =
951+
forall i j, 0 <= i < rows m => 0 <= j < cols m =>
952+
poly_infnorm_lt m.[(i, j)] b.
953+
954+
op mat_infnorm_le (m : matrix) (b : int) : bool =
955+
forall i j, 0 <= i < rows m => 0 <= j < cols m =>
956+
poly_infnorm_le m.[(i, j)] b.
957+
958+
op inf_normm (m : matrix) : Nneg.nneg =
959+
Nneg.BMaxN.bigi predT
960+
(fun i => Nneg.BMaxN.bigi predT
961+
(fun j => inf_norm m.[(i, j)]) 0 (cols m))
962+
0 (rows m).
963+
964+
lemma mat_infnorm_le_iff (m : matrix) (b : int) :
965+
0 <= b =>
966+
(mat_infnorm_le m b <=> Nneg.(<=) (inf_normm m) (Nneg.ofint b)).
967+
proof.
968+
move=> ge0_b; rewrite /mat_infnorm_le /inf_normm Nneg.BMaxN.big_le_iff.
969+
split.
970+
- move=> H; split; first by apply Nneg.zero_le.
971+
move=> i; rewrite mem_range => Hi _ /=.
972+
rewrite Nneg.BMaxN.big_le_iff; split; first by apply Nneg.zero_le.
973+
move=> j; rewrite mem_range => Hj _ /=.
974+
by rewrite -(poly_infnorm_le_iff _ _ ge0_b); apply H; smt().
975+
- case=> _ H i j Hi Hj.
976+
have Hi' : i \in range 0 (rows m) by rewrite mem_range; smt().
977+
have := H i Hi' _; first by [].
978+
rewrite /= Nneg.BMaxN.big_le_iff => -[_ Hr].
979+
have Hj' : j \in range 0 (cols m) by rewrite mem_range; smt().
980+
have := Hr j Hj' _; first by [].
981+
by rewrite /= -(poly_infnorm_le_iff _ _ ge0_b).
982+
qed.
983+
984+
lemma mat_infnorm_lt_iff (m : matrix) (b : int) :
985+
1 <= b =>
986+
(mat_infnorm_lt m b <=> Nneg.(<=) (inf_normm m) (Nneg.ofint (b - 1))).
987+
proof.
988+
move=> ge1_b.
989+
have -> : mat_infnorm_lt m b <=> mat_infnorm_le m (b - 1).
990+
- rewrite /mat_infnorm_lt /mat_infnorm_le.
991+
split=> H i j Hi Hj; have := H i j Hi Hj.
992+
+ by rewrite /poly_infnorm_lt /poly_infnorm_le; smt().
993+
+ by rewrite /poly_infnorm_lt /poly_infnorm_le; smt().
994+
by apply mat_infnorm_le_iff; smt().
995+
qed.
803996
804997
end PolyReduceZpCenteredField.

0 commit comments

Comments
 (0)