ocaml - Understanding the semantics behind the code -


i have ocaml code, , have hard time formalize function mi_pol coq because not understand code working, example @

aux (vec_add add const (vector ci v)) args ps  

and

args.(i-1) <- mat_add add args.(i-1) (matrix ci m); aux const args ps 

and

aux (vec_0 z dim) (array.make n (mat_0 z dim)) ps 

this code:

let vector = list.map;;  let clist x =   let rec aux k = if k <= 0 [] else x :: aux (k-1) in aux;;  let vec_add add v1 v2 =   try list.map2 add v1 v2   invalid_argument _ ->     error_fmt "sum of 2 vectors of different size";;  let mat_add add m1 m2 =   try list.map2 (vec_add add) m1 m2   invalid_argument _ ->     error_fmt "sum of 2 matrices of different size";;  (*vector 0 *) let vec_0 z dim = clist z dim;;    (* matrix 0 *) let mat_0 z dim = clist (vec_0 z dim) dim;; let comp f g x = f (g x);;  (* matrix transpose *) let transpose ci =   let rec aux = function     | [] | [] :: _ -> []     | cs -> list.map (comp ci list.hd) cs :: aux (list.map list.tl cs)   in aux;;    (* matrix *) let matrix ci m =   try transpose ci m   failure _ -> error_fmt "ill-formed matrix";;  let mi_pol z add ci =   let rec aux const args = function     | [] -> { mi_const = const; mi_args = array.to_list args }     | polynomial_sum qs :: ps -> aux const args (qs @ ps)     | polynomial_coefficient (coefficient_matrix [v]) :: ps     | polynomial_coefficient (coefficient_vector v) :: ps ->       aux (vec_add add const (vector ci v)) args ps     | polynomial_product [p] :: ps -> aux const args (p :: ps)     | polynomial_product [polynomial_coefficient (coefficient_matrix m);                            polynomial_variable i] :: ps ->       args.(i-1) <- mat_add add args.(i-1) (matrix ci m);       aux const args ps     | _ -> not_supported "todo"   in fun dim n -> function     | polynomial_sum ps -> aux (vec_0 z dim) (array.make n (mat_0 z dim)) ps     | _ -> not_supported       "todo";; 

any appreciate. if can have coq code mi_pol me lot.

it appears take polynomial on vector space, , compute sum of (transpose of) (matrix) coefficients attached each variable. args array such args.(i) sum of coefficients on i-th variable, , const sum of constant scalars.

i don't know what's meaning of operation, suspect doesn't mean in general case (working on arbitrary products of sums of products of ...; lead strange non-linear/homogeneous behaviors). suppose there implicit constraints on shape of actual values of polynomial type are, example may linear in variables.


Comments