(* The record of operations *)

Structure fparams: Type := {
 K:> Set;               (* the scalar type *)
 v0: K;                (* 0 *)
 v1: K;                (* 1 *)
 eqK: K -> K -> bool;  (* = as a boolean function *)
 oppK: K -> K;         (* - unary *)
 addK : K -> K -> K;   (* + *)
 multK : K -> K -> K;  (* * *)
 invK : K -> K         (* 1/x *)
}.(* The record of operations *)

Structure fparams: Type := {
 K:> Set;               (* the scalar type *)
 v0: K;                (* 0 *)
 v1: K;                (* 1 *)
 eqK: K -> K -> bool;  (* = as a boolean function *)
 oppK: K -> K;         (* - unary *)
 addK : K -> K -> K;   (* + *)
 multK : K -> K -> K;  (* * *)
 invK : K -> K         (* 1/x *)
}.(* The record of operations *)

Structure fparams: Type := {
 K:> Set;               (* the scalar type *)
 v0: K;                (* 0 *)
 v1: K;                (* 1 *)
 eqK: K -> K -> bool;  (* = as a boolean function *)
 oppK: K -> K;         (* - unary *)
 addK : K -> K -> K;   (* + *)
 multK : K -> K -> K;  (* * *)
 invK : K -> K         (* 1/x *)
}.(* The record of operations *)

Structure fparams: Type := {
 K:> Set;               (* the scalar type *)
 v0: K;                (* 0 *)
 v1: K;                (* 1 *)
 eqK: K -> K -> bool;  (* = as a boolean function *)
 oppK: K -> K;         (* - unary *)
 addK : K -> K -> K;   (* + *)
 multK : K -> K -> K;  (* * *)
 invK : K -> K         (* 1/x *)
}.(* The record of operations *)

Structure fparams: Type := {
 K:> Set;               (* the scalar type *)
 v0: K;                (* 0 *)
 v1: K;                (* 1 *)
 eqK: K -> K -> bool;  (* = as a boolean function *)
 oppK: K -> K;         (* - unary *)
 addK : K -> K -> K;   (* + *)
 multK : K -> K -> K;  (* * *)
 invK : K -> K         (* 1/x *)
}.(* The record of operations *)

Structure fparams: Type := {
 K:> Set;               (* the scalar type *)
 v0: K;                (* 0 *)
 v1: K;                (* 1 *)
 eqK: K -> K -> bool;  (* = as a boolean function *)
 oppK: K -> K;         (* - unary *)
 addK : K -> K -> K;   (* + *)
 multK : K -> K -> K;  (* * *)
 invK : K -> K         (* 1/x *)
}.(* The record of operations *)

Structure fparams: Type := {
 K:> Set;               (* the scalar type *)
 v0: K;                (* 0 *)
 v1: K;                (* 1 *)
 eqK: K -> K -> bool;  (* = as a boolean function *)
 oppK: K -> K;         (* - unary *)
 addK : K -> K -> K;   (* + *)
 multK : K -> K -> K;  (* * *)
 invK : K -> K         (* 1/x *)
}.(* The record of operations *)

Structure fparams: Type := {
 K:> Set;               (* the scalar type *)
 v0: K;                (* 0 *)
 v1: K;                (* 1 *)
 eqK: K -> K -> bool;  (* = as a boolean function *)
 oppK: K -> K;         (* - unary *)
 addK : K -> K -> K;   (* + *)
 multK : K -> K -> K;  (* * *)
 invK : K -> K         (* 1/x *)
}.(* The record of operations *)

Structure fparams: Type := {
 K:> Set;               (* the scalar type *)
 v0: K;                (* 0 *)
 v1: K;                (* 1 *)
 eqK: K -> K -> bool;  (* = as a boolean function *)
 oppK: K -> K;         (* - unary *)
 addK : K -> K -> K;   (* + *)
 multK : K -> K -> K;  (* * *)
 invK : K -> K         (* 1/x *)
}.Notation "x ?= y" := (eqK _ x y) (at level 70) : field_scope.Notation "x + y" := (addK _ x y) : field_scope.Notation "- x" := (oppK _ x) : field_scope.Notation "x ^-1" := (invK _ x) (at level 25) : field_scope.Notation "x * y" := (multK _ x y) : field_scope.Notation "0" := (v0 _) : field_scope.Notation "1" := (v1 _) : field_scope.(* Properties associated with a params *)
Structure fparamsProp: Type := {
 eqK_dec: forall x y: p, if x ?= y then x = y else x <> y;        
          (* Boolean equality *)
 addK_assoc: forall x y z: p, (x + y) + z = x + (y + z);
          (* Associativity for + *)
 addK_com: forall x y: p, x + y = y + x;
          (* Commutativity for + *)
 addK0l: forall x: p, 0 + x = x;
          (* Left neutral  for + *)
 oppKr: forall x: p, x + - x = 0;
          (* Right opposite  for + *)
 multK_assoc: forall x y z: p, (x * y) * z = x * (y * z);
          (* Associativity for * *)
 multK_com: forall x y: p, x * y = y * x;
          (* Commutativity for * *)
 multK1l: forall x: p, 1 * x = x;
          (* Left neutral element for * *)
 add_multKl: forall x y z: p, (x + y) * z = x * z + y * z;
          (* Left distributivity of + over * *)
 one_diff_zero: 1 <> 0 :> p;
          (* Inverse *)
 invKl: forall x: p, x <> 0 -> x * x^-1 = 1
}.(* Properties associated with a params *)
Structure fparamsProp: Type := {
 eqK_dec: forall x y: p, if x ?= y then x = y else x <> y;        
          (* Boolean equality *)
 addK_assoc: forall x y z: p, (x + y) + z = x + (y + z);
          (* Associativity for + *)
 addK_com: forall x y: p, x + y = y + x;
          (* Commutativity for + *)
 addK0l: forall x: p, 0 + x = x;
          (* Left neutral  for + *)
 oppKr: forall x: p, x + - x = 0;
          (* Right opposite  for + *)
 multK_assoc: forall x y z: p, (x * y) * z = x * (y * z);
          (* Associativity for * *)
 multK_com: forall x y: p, x * y = y * x;
          (* Commutativity for * *)
 multK1l: forall x: p, 1 * x = x;
          (* Left neutral element for * *)
 add_multKl: forall x y z: p, (x + y) * z = x * z + y * z;
          (* Left distributivity of + over * *)
 one_diff_zero: 1 <> 0 :> p;
          (* Inverse *)
 invKl: forall x: p, x <> 0 -> x * x^-1 = 1
}.(* Properties associated with a params *)
Structure fparamsProp: Type := {
 eqK_dec: forall x y: p, if x ?= y then x = y else x <> y;        
          (* Boolean equality *)
 addK_assoc: forall x y z: p, (x + y) + z = x + (y + z);
          (* Associativity for + *)
 addK_com: forall x y: p, x + y = y + x;
          (* Commutativity for + *)
 addK0l: forall x: p, 0 + x = x;
          (* Left neutral  for + *)
 oppKr: forall x: p, x + - x = 0;
          (* Right opposite  for + *)
 multK_assoc: forall x y z: p, (x * y) * z = x * (y * z);
          (* Associativity for * *)
 multK_com: forall x y: p, x * y = y * x;
          (* Commutativity for * *)
 multK1l: forall x: p, 1 * x = x;
          (* Left neutral element for * *)
 add_multKl: forall x y z: p, (x + y) * z = x * z + y * z;
          (* Left distributivity of + over * *)
 one_diff_zero: 1 <> 0 :> p;
          (* Inverse *)
 invKl: forall x: p, x <> 0 -> x * x^-1 = 1
}.(* Properties associated with a params *)
Structure fparamsProp: Type := {
 eqK_dec: forall x y: p, if x ?= y then x = y else x <> y;        
          (* Boolean equality *)
 addK_assoc: forall x y z: p, (x + y) + z = x + (y + z);
          (* Associativity for + *)
 addK_com: forall x y: p, x + y = y + x;
          (* Commutativity for + *)
 addK0l: forall x: p, 0 + x = x;
          (* Left neutral  for + *)
 oppKr: forall x: p, x + - x = 0;
          (* Right opposite  for + *)
 multK_assoc: forall x y z: p, (x * y) * z = x * (y * z);
          (* Associativity for * *)
 multK_com: forall x y: p, x * y = y * x;
          (* Commutativity for * *)
 multK1l: forall x: p, 1 * x = x;
          (* Left neutral element for * *)
 add_multKl: forall x y z: p, (x + y) * z = x * z + y * z;
          (* Left distributivity of + over * *)
 one_diff_zero: 1 <> 0 :> p;
          (* Inverse *)
 invKl: forall x: p, x <> 0 -> x * x^-1 = 1
}.(* Properties associated with a params *)
Structure fparamsProp: Type := {
 eqK_dec: forall x y: p, if x ?= y then x = y else x <> y;        
          (* Boolean equality *)
 addK_assoc: forall x y z: p, (x + y) + z = x + (y + z);
          (* Associativity for + *)
 addK_com: forall x y: p, x + y = y + x;
          (* Commutativity for + *)
 addK0l: forall x: p, 0 + x = x;
          (* Left neutral  for + *)
 oppKr: forall x: p, x + - x = 0;
          (* Right opposite  for + *)
 multK_assoc: forall x y z: p, (x * y) * z = x * (y * z);
          (* Associativity for * *)
 multK_com: forall x y: p, x * y = y * x;
          (* Commutativity for * *)
 multK1l: forall x: p, 1 * x = x;
          (* Left neutral element for * *)
 add_multKl: forall x y z: p, (x + y) * z = x * z + y * z;
          (* Left distributivity of + over * *)
 one_diff_zero: 1 <> 0 :> p;
          (* Inverse *)
 invKl: forall x: p, x <> 0 -> x * x^-1 = 1
}.(* Properties associated with a params *)
Structure fparamsProp: Type := {
 eqK_dec: forall x y: p, if x ?= y then x = y else x <> y;        
          (* Boolean equality *)
 addK_assoc: forall x y z: p, (x + y) + z = x + (y + z);
          (* Associativity for + *)
 addK_com: forall x y: p, x + y = y + x;
          (* Commutativity for + *)
 addK0l: forall x: p, 0 + x = x;
          (* Left neutral  for + *)
 oppKr: forall x: p, x + - x = 0;
          (* Right opposite  for + *)
 multK_assoc: forall x y z: p, (x * y) * z = x * (y * z);
          (* Associativity for * *)
 multK_com: forall x y: p, x * y = y * x;
          (* Commutativity for * *)
 multK1l: forall x: p, 1 * x = x;
          (* Left neutral element for * *)
 add_multKl: forall x y z: p, (x + y) * z = x * z + y * z;
          (* Left distributivity of + over * *)
 one_diff_zero: 1 <> 0 :> p;
          (* Inverse *)
 invKl: forall x: p, x <> 0 -> x * x^-1 = 1
}.(* Properties associated with a params *)
Structure fparamsProp: Type := {
 eqK_dec: forall x y: p, if x ?= y then x = y else x <> y;        
          (* Boolean equality *)
 addK_assoc: forall x y z: p, (x + y) + z = x + (y + z);
          (* Associativity for + *)
 addK_com: forall x y: p, x + y = y + x;
          (* Commutativity for + *)
 addK0l: forall x: p, 0 + x = x;
          (* Left neutral  for + *)
 oppKr: forall x: p, x + - x = 0;
          (* Right opposite  for + *)
 multK_assoc: forall x y z: p, (x * y) * z = x * (y * z);
          (* Associativity for * *)
 multK_com: forall x y: p, x * y = y * x;
          (* Commutativity for * *)
 multK1l: forall x: p, 1 * x = x;
          (* Left neutral element for * *)
 add_multKl: forall x y z: p, (x + y) * z = x * z + y * z;
          (* Left distributivity of + over * *)
 one_diff_zero: 1 <> 0 :> p;
          (* Inverse *)
 invKl: forall x: p, x <> 0 -> x * x^-1 = 1
}.(* Properties associated with a params *)
Structure fparamsProp: Type := {
 eqK_dec: forall x y: p, if x ?= y then x = y else x <> y;        
          (* Boolean equality *)
 addK_assoc: forall x y z: p, (x + y) + z = x + (y + z);
          (* Associativity for + *)
 addK_com: forall x y: p, x + y = y + x;
          (* Commutativity for + *)
 addK0l: forall x: p, 0 + x = x;
          (* Left neutral  for + *)
 oppKr: forall x: p, x + - x = 0;
          (* Right opposite  for + *)
 multK_assoc: forall x y z: p, (x * y) * z = x * (y * z);
          (* Associativity for * *)
 multK_com: forall x y: p, x * y = y * x;
          (* Commutativity for * *)
 multK1l: forall x: p, 1 * x = x;
          (* Left neutral element for * *)
 add_multKl: forall x y z: p, (x + y) * z = x * z + y * z;
          (* Left distributivity of + over * *)
 one_diff_zero: 1 <> 0 :> p;
          (* Inverse *)
 invKl: forall x: p, x <> 0 -> x * x^-1 = 1
}.(* Properties associated with a params *)
Structure fparamsProp: Type := {
 eqK_dec: forall x y: p, if x ?= y then x = y else x <> y;        
          (* Boolean equality *)
 addK_assoc: forall x y z: p, (x + y) + z = x + (y + z);
          (* Associativity for + *)
 addK_com: forall x y: p, x + y = y + x;
          (* Commutativity for + *)
 addK0l: forall x: p, 0 + x = x;
          (* Left neutral  for + *)
 oppKr: forall x: p, x + - x = 0;
          (* Right opposite  for + *)
 multK_assoc: forall x y z: p, (x * y) * z = x * (y * z);
          (* Associativity for * *)
 multK_com: forall x y: p, x * y = y * x;
          (* Commutativity for * *)
 multK1l: forall x: p, 1 * x = x;
          (* Left neutral element for * *)
 add_multKl: forall x y z: p, (x + y) * z = x * z + y * z;
          (* Left distributivity of + over * *)
 one_diff_zero: 1 <> 0 :> p;
          (* Inverse *)
 invKl: forall x: p, x <> 0 -> x * x^-1 = 1
}.(* Properties associated with a params *)
Structure fparamsProp: Type := {
 eqK_dec: forall x y: p, if x ?= y then x = y else x <> y;        
          (* Boolean equality *)
 addK_assoc: forall x y z: p, (x + y) + z = x + (y + z);
          (* Associativity for + *)
 addK_com: forall x y: p, x + y = y + x;
          (* Commutativity for + *)
 addK0l: forall x: p, 0 + x = x;
          (* Left neutral  for + *)
 oppKr: forall x: p, x + - x = 0;
          (* Right opposite  for + *)
 multK_assoc: forall x y z: p, (x * y) * z = x * (y * z);
          (* Associativity for * *)
 multK_com: forall x y: p, x * y = y * x;
          (* Commutativity for * *)
 multK1l: forall x: p, 1 * x = x;
          (* Left neutral element for * *)
 add_multKl: forall x y z: p, (x + y) * z = x * z + y * z;
          (* Left distributivity of + over * *)
 one_diff_zero: 1 <> 0 :> p;
          (* Inverse *)
 invKl: forall x: p, x <> 0 -> x * x^-1 = 1
}.(* Properties associated with a params *)
Structure fparamsProp: Type := {
 eqK_dec: forall x y: p, if x ?= y then x = y else x <> y;        
          (* Boolean equality *)
 addK_assoc: forall x y z: p, (x + y) + z = x + (y + z);
          (* Associativity for + *)
 addK_com: forall x y: p, x + y = y + x;
          (* Commutativity for + *)
 addK0l: forall x: p, 0 + x = x;
          (* Left neutral  for + *)
 oppKr: forall x: p, x + - x = 0;
          (* Right opposite  for + *)
 multK_assoc: forall x y z: p, (x * y) * z = x * (y * z);
          (* Associativity for * *)
 multK_com: forall x y: p, x * y = y * x;
          (* Commutativity for * *)
 multK1l: forall x: p, 1 * x = x;
          (* Left neutral element for * *)
 add_multKl: forall x y z: p, (x + y) * z = x * z + y * z;
          (* Left distributivity of + over * *)
 one_diff_zero: 1 <> 0 :> p;
          (* Inverse *)
 invKl: forall x: p, x <> 0 -> x * x^-1 = 1
}.(* Properties associated with a params *)
Structure fparamsProp: Type := {
 eqK_dec: forall x y: p, if x ?= y then x = y else x <> y;        
          (* Boolean equality *)
 addK_assoc: forall x y z: p, (x + y) + z = x + (y + z);
          (* Associativity for + *)
 addK_com: forall x y: p, x + y = y + x;
          (* Commutativity for + *)
 addK0l: forall x: p, 0 + x = x;
          (* Left neutral  for + *)
 oppKr: forall x: p, x + - x = 0;
          (* Right opposite  for + *)
 multK_assoc: forall x y z: p, (x * y) * z = x * (y * z);
          (* Associativity for * *)
 multK_com: forall x y: p, x * y = y * x;
          (* Commutativity for * *)
 multK1l: forall x: p, 1 * x = x;
          (* Left neutral element for * *)
 add_multKl: forall x y z: p, (x + y) * z = x * z + y * z;
          (* Left distributivity of + over * *)
 one_diff_zero: 1 <> 0 :> p;
          (* Inverse *)
 invKl: forall x: p, x <> 0 -> x * x^-1 = 1
}.Fixpoint expK  (k: p) (n:nat) {struct n}: p := 
  match n with O => 1 | (S n1) => k * expK k n1 end.Notation "x ^ k" := (expK _ x%f k) : field_scope.Implicit Types x y z: p.

(* Specifications: *)
Lemma eqKI: forall x, x ?= x = true.
Lemma eqK_spec x y: eq_Spec x y (x ?= y).
Lemma oppKl: forall x, - x + x = 0.
Lemma addK_cancel x y z: x + y = x + z -> y = z.
Lemma addK_eq_opp: forall x y, x + (-y) = 0 -> x = y.
Lemma addK0r x: x + 0 = x.
Lemma opp_oppK x: - (- x) = x.
Lemma multK1r x: x * 1 = x.
Lemma add_multKr x y z: z * (x + y) = z * x + z * y.
Lemma oppK0: - 0 = 0 :> p.
Lemma opp_addK x y: - (x + y) = - x + - y.
Lemma multK0l x: 0 * x = 0.
Lemma multK0r x: x * 0 = 0.
Lemma opp_multKl x y: - (x * y) = - x * y.
Lemma opp_multKr x y: - (x * y) = x * - y.
Lemma opp_multK1l x: - x = (-(1)) * x.
Lemma opp_multK1r x: - x = x * (-(1)).
Lemma multK_m1_m1: -(1) * -(1) = 1 :>p.
Lemma expK2m1 n: (-(1)) ^ n * (- (1)) ^ n =1.
Lemma expK_add n1 n2 a: a ^ (n1 + n2) = a ^n1 * a ^ n2.
Lemma expKm1_even n: even n -> (-(1))^ n = 1 with expKm1_odd n: odd n -> (-(1))^ n = -(1).
Lemma expKm1_sub m n: m <= n -> (-(1))^ (n - m) = (-(1))^ (n + m).
Lemma expKm1_2 n: (-(1))^ (2 * n) = 1.
Lemma expKm1_2E n m: (-(1))^ (2 * n + m) = (-(1))^ m.
Lemma invKr x: x <> 0 -> x^-1 * x = 1.
Lemma multK_cancel x y z: x <> 0 -> x * y = x * z -> y = z.
Lemma multK_swap x y z: x * (y * z) = y * (x * z).
Lemma multK_integral x y : x * y = 0 -> x = 0 \/ y = 0.
Lemma expK_integral x n : x^n = 0 -> x = 0.
Lemma expKm1_n0 n : (-(1))^n <> 0.