123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151(*****************************************************************************)(* *)(* MIT License *)(* Copyright (c) 2022 Nomadic Labs <contact@nomadic-labs.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)(* Alternative representation of polynomials containing
the evaluations of a polynomial on a certain set and its
degree *)moduletypeEvaluations_sig=sigincludeOctez_bls12_381_polynomial.Evaluations_sig(** [size_evaluations] returns the maximum size of elements in evaluations *)valsize_evaluations:tSMap.t->int(** [find_evaluation m name] returns the evaluation for a given name [name] *)valfind_evaluation:tSMap.t->string->t(** [print_evaluations_name] prints [(name, degree, length)] for each evaluation *)valprint_evaluations_name:tSMap.t->unit(** [get_domain] returns the evaluation for ["X"] *)valget_domain:tSMap.t->domain(** [compute_evaluations] converts the coefficient representation of each
polynomial [pᵢ] to the evaluation representation.
Note:
- size of domain must be a power of two
- size of a polynomial [pᵢ] must be less than or equal to size of domain *)valcompute_evaluations:domain:domain->polynomialSMap.t->tSMap.t(** [compute_evaluations_update_map] writes the result of {!compute_evaluations} in
[evaluations]. If [domain] is not provided, {!get_domain} is called *)valcompute_evaluations_update_map:?domain:domain->evaluations:tSMap.t->polynomialSMap.t->tSMap.t(** [mul] invokes {!mul_c} with the evaluations for given names [poly_names] *)valmul:?res:t->evaluations:tSMap.t->poly_names:stringlist->?composition_gx:intlist*int->?powers:intlist->unit->t(** [linear] invokes {!linear_c} with the evaluations for given names [poly_names] *)vallinear:?res:t->evaluations:tSMap.t->poly_names:SMap.keylist->?linear_coeffs:scalarlist->?composition_gx:intlist*int->?add_constant:scalar->unit->tendmoduleMake(E:Octez_bls12_381_polynomial.Evaluations_sig):Evaluations_sigwithtypescalar=E.scalarandtypedomain=E.domainandtypepolynomial=E.polynomialandtypet=E.t=structincludeEletprint_evaluations_namemap=lets_eval="{"^SMap.fold(funkevalacc->acc^Printf.sprintf"\n %s -> (%d, %d)"k(degreeeval)(lengtheval))map""^"\n}"inPrintf.printf"\nevaluations : %s"s_eval(* Returns the maximum size of elements in evaluations ;
raise failure if max_size equals zero *)letsize_evaluationsevaluations=letevals=SMap.valuesevaluationsinletsize_max=List.fold_leftmax0@@List.maplengthevalsinifsize_max=0thenfailwith"size_evaluations: a maximum size of evaluations can't be zero!"elsesize_maxletnot_foundx=raise(Invalid_argument(Printf.sprintf"Evaluations : %s not found in evaluations map."x))letfind_evaluationevaluationsname=matchSMap.find_optnameevaluationswith|None->not_foundname|Somex->x(* Returns the evals of "X" as a domain
@raise Invalid_argument if "X" is not in evaluations
*)letget_domainevaluations=to_domain(find_evaluationevaluations"X")letcompute_evaluations~domainpoly_map=SMap.map(evaluation_fftdomain)poly_map(* Adds evaluation of poly_map’s polynomials on the domain given by the evaluation of "X"
@raise Invalid_argument if "X" is not in evaluations
*)letcompute_evaluations_update_map?domain~evaluationspoly_map=letdomain=matchdomainwithSomedomain->domain|None->get_domainevaluationsinSMap.union_disjointevaluations(compute_evaluations~domainpoly_map)letmul?res~evaluations~poly_names?composition_gx?powers()=letlist_eval=List.map(find_evaluationevaluations)poly_namesinmul_c?res~evaluations:list_eval?composition_gx?powers()letlinear?res~evaluations~poly_names?linear_coeffs?composition_gx?add_constant()=letlist_eval=List.map(find_evaluationevaluations)poly_namesinlinear_c?res~evaluations:list_eval?linear_coeffs?composition_gx?add_constant()end