=================================================================== RCS file: /home/cvs/OpenXM/src/asir-doc/parts/ff.texi,v retrieving revision 1.1 retrieving revision 1.5 diff -u -p -r1.1 -r1.5 --- OpenXM/src/asir-doc/parts/ff.texi 1999/12/08 05:47:44 1.1 +++ OpenXM/src/asir-doc/parts/ff.texi 2003/04/19 15:44:56 1.5 @@ -1,19 +1,52 @@ +@comment $OpenXM: OpenXM/src/asir-doc/parts/ff.texi,v 1.4 2003/04/19 10:36:30 noro Exp $ +\BJP @node $BM-8BBN$K4X$9$k1i;;(B,,, Top @chapter $BM-8BBN$K4X$9$k1i;;(B +\E +\BEG +@node Finite fields,,, Top +@chapter Finite fields +\E @menu +\BJP * $BM-8BBN$NI=8=$*$h$S1i;;(B:: * $BM-8BBN>e$G$N(B 1 $BJQ?tB?9`<0$N1i;;(B:: +* $B>.I8?tM-8BBN>e$G$NB?9`<0$N1i;;(B:: * $BM-8BBN>e$NBJ1_6J@~$K4X$9$k1i;;(B:: * $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B:: +\E +\BEG +* Representation of finite fields:: +* Univariate polynomials on finite fields:: +* Polynomials on small finite fields:: +* Elliptic curves on finite fields:: +* Functions for Finite fields:: +\E @end menu +\BJP @node $BM-8BBN$NI=8=$*$h$S1i;;(B,,, $BM-8BBN$K4X$9$k1i;;(B @section $BM-8BBN$NI=8=$*$h$S1i;;(B +\E +\BEG +@node Representation of finite fields,,, Finite fields +@section Representation of finite fields +\E @noindent -@b{Asir} $B$K$*$$$F$O(B, $BM-8BBN$O(B, $B@5I8?tAGBN(B GF(p), $BI8?t(B 2 $B$NM-8BBN(B GF(2^n) +\BJP +@b{Asir} $B$K$*$$$F$O(B, $BM-8BBN$O(B, $B@5I8?tAGBN(B GF(@var{p}), $BI8?t(B 2 $B$NM-8BBN(B GF(2^@var{n}), +GF(@var{p}) $B$N(B @var{n} $Bl9g(B GF(p), n $Bl(B -$B9g(B, f(x) mod 2 $B$rDj5AB?9`<0$H$9$k(B GF(2^n) $B$r$=$l$>$l4pACBN$H$7$F%;%C%H$9(B -$B$k(B. @code{setmod_ff()} $B$K$*$$$F$O0z?t$N4{Ls%A%'%C%/$O9T$o$:(B, $B8F$S=P$7B&(B +\BJP +@code{setmod_ff()} $B$O(B, $B$5$^$6$^$J%?%$%W$NM-8BBN$r4pACBN$H$7$F%;%C%H$9$k(B. +$B0z?t$,@5@0?t(B @var{p} $B$N>l9g(B GF(@var{p}), @var{n} $Bl(B +$B9g(B, f(x) mod 2 $B$rDj5AB?9`<0$H$9$k(B GF(2^@var{n}) $B$r$=$l$>$l4pACBN$H$7$F%;%C%H$9(B +$B$k(B. $B$^$?(B, $BM-8BAGBN$NM-8B\$7$/$O(B @xref{$B?t$N7?(B}. +@code{setmod_ff()} $B$K$*$$$F$O0z?t$N4{Ls%A%'%C%/$O9T$o$:(B, $B8F$S=P$7B&(B $B$,@UG$$r;}$D(B. $B4pACBN$H$O(B, $B$"$/$^$GM-8BBN$N85$H$7$F@k8@$"$k$$$ODj5A$5$l$?%*%V%8%'%/%H$,(B, @@ -43,12 +87,41 @@ x^50+x^4+x^3+x^2+1 $B$k(B. 0 $B$G$J$$M-8BBN$N85$O(B, $B?t%*%V%8%'%/%H$G$"$j(B, $B<1JL;R$NCM$O(B 1 $B$G$"$k(B. -$B$5$i$K(B, 0 $B$G$J$$M-8BBN$N85$N?t<1JL;R$O(B, GF(p) $B$N>l9g(B 6, GF(2^n) $B$N>l9g(B 7 +$B$5$i$K(B, 0 $B$G$J$$M-8BBN$N85$N?t<1JL;R$O(B, GF(@var{p}) $B$N>l9g(B 6, GF(2^@var{n}) $B$N>l9g(B 7 $B$H$J$k(B. -$BM-8BBN$N85$NF~NOJ}K!$O(B, $BM-8BBN$Nl9g(B, +$BM-8BBN$N85$NF~NOJ}K!$O(B, $BM-8BBN$Nl9g(B, @code{simp_ff()} $B$K$h$k(B. +\E +\BEG +If @var{p} is a positive integer, @code{setmod_ff(@var{p})} sets +GF(@var{p}) as the current base field. +If @var{f} is a univariate polynomial of degree @var{n}, +@code{setmod_ff(@var{f})} sets GF(2^@var{n}) as the current +base field. GF(2^@var{n}) is represented +as an algebraic extension of GF(2) with the defining polynomial +@var{f mod 2}. Furthermore, finite extensions of prime finite fields +can be defined. @xref{Types of numbers}. +In all cases the primality check of the argument is +not done and the caller is responsible for it. + +Correctly speaking there is no actual object corresponding to a 'base field'. +Setting a base field means that operations on elements of finite fields +are done according to the arithmetics of the base field. Thus, if +operands of an arithmetic operation are both rational numbers, then the result +is also a rational number. However, if one of the operands is in +a finite field, then the other is automatically regarded as in the +same finite field and the operation is done in the finite field. + +A non zero element of a finite field belongs to the number and has object +identifier 1. Its number identifier is 6 if the finite field is GF(@var{p}), +7 if it is GF(2^@var{n}). + +There are several methods to input an element of a finite field. +An element of GF(@var{p}) can be input by @code{simp_ff()}. +\E + @example [0] P=pari(nextprime,2^50); 1125899906842679 @@ -60,7 +133,9 @@ x^50+x^4+x^3+x^2+1 6 @end example -$B$^$?(B, GF(2^n) $B$N>l9g$$$/$D$+$NJ}K!$,$"$k(B. +\JP $B$^$?(B, GF(2^@var{n}) $B$N>l9g$$$/$D$+$NJ}K!$,$"$k(B. +\EG In the case of GF(2^@var{n}) the following methods are available. + @example [0] setmod_ff(x^50+x^4+x^3+x^2+1); x^50+x^4+x^3+x^2+1 @@ -74,43 +149,109 @@ x^50+x^4+x^3+x^2+1 (@@^9+@@^8+@@^7+@@^6+@@^5+@@^4+@@^3+@@^2+@@+1) @end example +\BJP $BM-8BBN$N85$O?t$G$"$j(B, $BBN1i;;$,2DG=$G$"$k(B. @code{@@} $B$O(B -GF(2^n) $B$N(B, GF(2)$B>e$N@8@.85$G$"$k(B. $B>\$7$/$O(B @xref{$B?t$N7?(B}. +GF(2^@var{n}) $B$N(B, GF(2) $B>e$N@8@.85$G$"$k(B. $B>\$7$/$O(B @xref{$B?t$N7?(B}. +\E +\BEG +Elements of finite fields are numbers and one can apply field arithmetics +to them. @code{@@} is a generator of GF(2^@var{n}) over GF(2). +@xref{Types of numbers}. +\E @noindent +\BJP @node $BM-8BBN>e$G$N(B 1 $BJQ?tB?9`<0$N1i;;(B,,, $BM-8BBN$K4X$9$k1i;;(B @section $BM-8BBN>e$G$N(B 1 $BJQ?tB?9`<0$N1i;;(B +\E +\BEG +@node Univariate polynomials on finite fields,,, Finite fields +@section Univariate polynomials on finite fields +\E @noindent +\BJP @samp{fff} $B$G$O(B, $BM-8BBN>e$N(B 1 $BJQ?tB?9`<0$KBP$7(B, $BL5J?J}J,2r(B, DDF, $B0x?tJ,2r(B, $BB?9`<0$N4{LsH=Dj$J$I$N4X?t$,Dj5A$5$l$F$$$k(B. $B$$$:$l$b(B, $B7k2L$O(B [@b{$B0x;R(B}, @b{$B=EJ#EY(B}] $B$N%j%9%H$H$J$k$,(B, $B0x;R$O(B monic $B$H$J$j(B, $BF~NOB?9`<0$Ne$G$N0x?tJ,2r$O(B, DDF $B$N8e(B, $B.B?9`<0$r5a$a(B, $B$=$N:,(B $B$r(B Cantor-Zassenhaus $B%"%k%4%j%:%`$K$h$j5a$a$k(B, $B$H$$$&J}K!$r.I8?tM-8BBN>e$G$NB?9`<0$N1i;;(B,,, $BM-8BBN$K4X$9$k1i;;(B +@section $B>.I8?tM-8BBN>e$G$NB?9`<0$N1i;;(B +\E +\BEG +@node Polynomials on small finite fields,,, Finite fields +@section Polynomials on small finite fields +\E + +\BJP +$B>.I8?tM-8BBN78?t$NB?9`<0$K8B$j(B, $BB?JQ?tB?9`<0$N0x?tJ,2r$,(B +$BAH$_9~$_4X?t$H$7$Fe$GB?JQ?t(B +$BB?9`<0$N0x?tJ,2r$r9T$&$,(B, $Be$N0x;R$r9=@.$9$k(B, $B$H$$$&J}K!$G7W;;$7$F$$$k(B. +\E + +\BEG +A multivariate polynomial over small finite field +set by @code{setmod_ff(p,n)} can be factorized by +using a builtin function @code{sffctr()}. @code{modfctr()} +also factorizes a polynomial over a finite prime field. +Internally, @code{modfctr()} creates a sufficiently large +field extension of the specified ground field, and +it calls @code{sffctr()}, then it constructs irreducible +factors over the ground field from the factors returned by +@code{sffctr()}. +\E + +\BJP @node $BM-8BBN>e$NBJ1_6J@~$K4X$9$k1i;;(B,,, $BM-8BBN$K4X$9$k1i;;(B @section $BM-8BBN>e$NBJ1_6J@~$K4X$9$k1i;;(B +\E +\BEG +@node Elliptic curves on finite fields,,, Finite fields +@section Elliptic curves on finite fields +\E +\BJP $BM-8BBN>e$NBJ1_6J@~$K4X$9$k$$$/$D$+$N4pK\E*$J1i;;$,(B, $BAH$_9~$_4X?t$H$7$F(B $BDs6!$5$l$F$$$k(B. -$BBJ1_6J@~$N;XDj$O(B, $BD9$5(B 2 $B$N%Y%/%H%k(B @var{[a b]} $B$G9T$&(B. @var{a}, @var{b} +$BBJ1_6J@~$N;XDj$O(B, $BD9$5(B 2 $B$N%Y%/%H%k(B [@var{a b}] $B$G9T$&(B. @var{a}, @var{b} $B$OM-8BBN$N85$G(B, @code{setmod_ff} $B$GDj5A$5$l$F$$$kM-8BBN$,AGBN$N>l9g(B, @var{y^2=x^3+ax+b}, $BI8?t(B 2 $B$NBN$N>l9g(B @var{y^2+xy=x^3+ax^2+b} $B$rI=$9(B. @@ -122,20 +263,59 @@ GF(2^n) $B$N(B, GF(2)$B>e$N@8@.85$G$"$k(B. $B>\$7 @itemize @bullet @item $BL58B1sE@$O(B 0. -@item $B$=$l0J30$NE@$O(B, $BD9$5(B 3 $B$N%Y%/%H%k(B @var{[x y z]}. $B$?$@$7(B, @var{z} $B$O(B +@item $B$=$l0J30$NE@$O(B, $BD9$5(B 3 $B$N%Y%/%H%k(B [@var{x y z}]. $B$?$@$7(B, @var{z} $B$O(B 0 $B$G$J$$(B. @end itemize -$B$H$$$&E@$G$"$k(B. @var{[x y z]} $B$O@F]$H$9$k$K$O(B, @var{[x y 1]} $B$J$k%Y%/%H%k$r(B +$B$H$$$&E@$G$"$k(B. [@var{x y z}] $B$O@F]$H$9$k$K$O(B, [@var{x y 1}] $B$J$k%Y%/%H%k$r(B $B@8@.$9$kI,MW$,$"$k(B. $B1i;;7k2L$b@Fe$N@8@.85$G$"$k(B. $B>\$7 * gf2nton:: * ptogf2n:: * gf2ntop:: +* ptosfp sfptop:: * defpoly_mod2:: * fctr_ff:: * irredcheck_ff:: @@ -158,37 +339,85 @@ GF(2^n) $B$N(B, GF(2)$B>e$N@8@.85$G$"$k(B. $B>\$7 * extdeg_ff:: @end menu -@node setmod_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\JP @node setmod_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\EG @node setmod_ff,,, Functions for Finite fields @subsection @code{setmod_ff} @findex setmod_ff @table @t @item setmod_ff([@var{prime}|@var{poly}]) -:: $BM-8BBN$N@_Dj(B, $B@_Dj$5$l$F$$$kM-8BBN$NK!(B, $BDj5AB?9`<0$NI=<((B +@itemx setmod_ff(@var{prime},@var{n}]) +\JP :: $BM-8BBN$N@_Dj(B, $B@_Dj$5$l$F$$$kM-8BBN$NK!(B, $BDj5AB?9`<0$NI=<((B +\EG :: Sets/Gets the current base fields. @end table @table @var @item return -$B?t$^$?$OB?9`<0(B +\JP $B?t$^$?$OB?9`<0(B +\EG number or polynomial @item prime -$BAG?t(B +\JP $BAG?t(B +\EG prime @item poly -GF(2) $B>e4{Ls$J(B 1 $BJQ?tB?9`<0(B +\JP GF(2) $B>e4{Ls$J(B 1 $BJQ?tB?9`<0(B +\EG univariate polynomial irreducible over GF(2) +@item n +\JP $B3HBgl9g(B @var{prime}, -GF(2^n) $B$N>l9gDj5AB?9`<0$rJV$9(B. +$B0z?t$,(B @var{p} $B$H(B @var{n} $B$N;~(B, +GF(@var{p^n}) $B$r4pACBN$H$7$F@_Dj$9$k(B. @var{p^n} $B$O(B @var{2^29} $BL$K~$G(B +$B$J$1$l$P$J$i$J$$(B. $B$^$?(B, @var{p} $B$,(B @var{2^14} $B0J>e$N$H$-(B, +@var{n} $B$O(B 1 $B$G$J$1$l$P$J$i$J$$(B. @item -GF(2^n) $B$NDj5AB?9`<0$O(B, GF(2) $B>e(B n $Bl9g(B @var{prime}, +GF(2^@var{n}) $B$N>l9gDj5AB?9`<0$rJV$9(B. +$B4pACBN$,(B GF(p^@var{n}) +(@var{p^n} $B$,(B @var{2^14} $BL$K~(B) $B$N>l9g(B, +[@var{p},@var{defpoly},@var{prim_elem}] $B$rJV$9(B. $B$3$3$G(B, @var{defpoly} +$B$O(B, @var{n} $BhK!72$N@8@.85$r0UL#$9$k(B. +@item +GF(2^@var{n}) $B$NDj5AB?9`<0$O(B, GF(2) $B>e(B n $BH(B +\JP @item $B;2>H(B +\EG @item References @fref{defpoly_mod2} @end table -@node field_type_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\JP @node field_type_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\EG @node field_type_ff,,, Functions for Finite fields @subsection @code{field_type_ff} @findex field_type_ff @table @t @item field_type_ff() -:: $B@_Dj$5$l$F$$$k4pACBN$NH(B +\JP @item $B;2>H(B +\EG @item References @fref{setmod_ff} @end table -@node field_order_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\JP @node field_order_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\EG @node field_order_ff,,, Functions for Finite fields @subsection @code{field_order_ff} @findex field_order_ff @table @t @item field_order_ff() -:: $B@_Dj$5$l$F$$$k4pACBN$N0L?t(B +\JP :: $B@_Dj$5$l$F$$$k4pACBN$N0L?t(B +\EG :: Order of the current base field. @end table @table @var @item return -$B?t(B +\JP $B@0?t(B +\EG integer @end table @itemize @bullet +\BJP @item $B@_Dj$5$l$F$$$k4pACBN$N0L?t(B ($B85$N8D?t(B) $B$rJV$9(B. @item -$B@_Dj$5$l$F$$$kBN$,(B GF(q) $B$J$i$P(B q $B$rJV$9(B. +$B@_Dj$5$l$F$$$kBN$,(B GF(@var{q}) $B$J$i$P(B q $B$rJV$9(B. +\E +\BEG +@item +Returns the order of the current base field. +@item +@var{q} is returned if the current base field is GF(@var{q}). +\E @end itemize @example @@ -280,29 +536,42 @@ x^2+x+1 @end example @table @t -@item $B;2>H(B +\JP @item $B;2>H(B +\EG @item References @fref{setmod_ff} @end table -@node characteristic_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\JP @node characteristic_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\EG @node characteristic_ff,,, Functions for Finite fields @subsection @code{characteristic_ff} @findex characteristic_ff @table @t @item characteristic_ff() -:: $B@_Dj$5$l$F$$$kBN$NI8?t(B +\JP :: $B@_Dj$5$l$F$$$kBN$NI8?t(B +\EG :: Characteristic of the current base field. @end table @table @var @item return -$B?t(B +\JP $B@0?t(B +\EG integer @end table @itemize @bullet +\BJP @item $B@_Dj$5$l$F$$$kBN$NI8?t$rJV$9(B. @item -GF(p) $B$N>l9g(B p, GF(2^n) $B$N>l9g(B 2 $B$rJV$9(B. +GF(@var{p}) $B$N>l9g(B @var{p}, GF(2^@var{n}) $B$N>l9g(B 2 $B$rJV$9(B. +\E +\BEG +@item +Returns the characteristic of the current base field. +@item +@var{p} is returned if GF(@var{p}), where @var{p} is a prime, is set. +@var{2} is returned if GF(2^@var{n}) is set. +\E @end itemize @example @@ -320,29 +589,42 @@ x^2+x+1 @end example @table @t -@item $B;2>H(B +\JP @item $B;2>H(B +\EG @item References @fref{setmod_ff} @end table -@node extdeg_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\JP @node extdeg_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\EG @node extdeg_ff,,, Functions for Finite fields @subsection @code{extdeg_ff} @findex extdeg_ff @table @t @item extdeg_ff() -:: $B@_Dj$5$l$F$$$k4pACBN$N(B, $BAGBN$KBP$9$k3HBgl9g(B 1, GF(2^n) $B$N>l9g(B n $B$rJV$9(B. +GF(@var{p}) $B$N>l9g(B 1, GF(2^@var{n}) $B$N>l9g(B @var{n} $B$rJV$9(B. +\E +\BEG +@item +Returns the extension degree of the current base field over the prime field. +@item +1 is returned if GF(@var{p}), where @var{p} is a prime, is set. +@var{n} is returned if GF(2^@var{n}) is set. +\E @end itemize @example @@ -360,27 +642,36 @@ x^2+x+1 @end example @table @t -@item $B;2>H(B +\JP @item $B;2>H(B +\EG @item References @fref{setmod_ff} @end table -@node simp_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\JP @node simp_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\EG @node simp_ff,,, Functions for Finite fields @subsection @code{simp_ff} @findex simp_ff @table @t @item simp_ff(@var{obj}) -:: $B?t(B, $B$"$k$$$OB?9`<0$N78?t$rM-8BBN$N85$KJQ49(B +\JP :: $B?t(B, $B$"$k$$$OB?9`<0$N78?t$rM-8BBN$N85$KJQ49(B +\BEG +:: Converts numbers or coefficients of polynomials into elements +in finite fields. +\E @end table @table @var @item return -$B?t$^$?$OB?9`<0(B +\JP $B?t$^$?$OB?9`<0(B +\EG number or polynomial @item obj -$B?t$^$?$OB?9`<0(B +\JP $B?t$^$?$OB?9`<0(B +\EG number or polynomial @end table @itemize @bullet +\BJP @item $B?t(B, $B$"$k$$$OB?9`<0$N78?t$rM-8BBN$N85$KJQ49$9$k(B. @item @@ -389,6 +680,27 @@ x^2+x+1 @item $BM-8BBN$N85$KBP$7(B, $BK!$"$k$$$ODj5AB?9`<0$K$h$k(B reduction $B$r9T$&>l9g$K$b(B $BMQ$$$k(B. +@item +$B>.I8?tM-8BBN$N85$KJQ49$9$k>l9g(B, $B0lC6AGBN>e$K@\JQ49$9$k$K$O(B @code{ptosfp()} $B$r(B +$BMQ$$$k(B. +\E +\BEG +@item +Converts numbers or coefficients of polynomials into elements in finite +fields. +@item +It is used to convert integers or intrgral polynomials int +elements of finite fields or polynomials over finite fields. +@item +An element of a finite field may not have the reduced representation. +In such case an application of @code{simp_ff} ensures that the output has +the reduced representation. +If a small finite field is set as a ground field, +an integer is projected the finite prime field, then +it is embedded into the ground field. @code{ptosfp()} +can be used for direct projection to the ground field. +\E @end itemize @example @@ -400,36 +712,53 @@ x^10+10*x^9+45*x^8+120*x^7+210*x^6+252*x^5+210*x^4+120 1*x^10+1*x^9+1*x+1 [3] ntype(coef(@@@@,10)); 6 +[4] setmod_ff(2,3); +[2,x^3+x+1,x] +[5] simp_ff(1); +@@_0 +[6] simp_ff(2); +0 +[7] ptosfp(2); +@@_1 @end example @table @t -@item $B;2>H(B -@fref{setmod_ff}, @fref{lmptop}, @fref{gf2nton} +\JP @item $B;2>H(B +\EG @item References +@fref{setmod_ff}, @fref{lmptop}, @fref{gf2nton}, @fref{ptosfp sfptop} @end table -@node random_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\JP @node random_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\EG @node random_ff,,, Functions for Finite fields @subsection @code{random_ff} @findex random_ff @table @t @item random_ff() -:: $BM-8BBN$N85$NMp?t@8@.(B +\JP :: $BM-8BBN$N85$NMp?t@8@.(B +\EG :: Random generation of an element of a finite field. @end table @table @var @item return -$BM-8BBN$N85(B +\JP $BM-8BBN$N85(B +\EG element of a finite field @end table @itemize @bullet +\BJP @item $BM-8BBN$N85$rMp?t@8@.$9$k(B. @item -GF(p) $B$N>l9g(B, 0 $B0J>e(B p $BL$K~$N@0?t$G$"$i$o$5$l$k(B GF(p) $B$N85(B, -GF(2^n) $B$N>l9g(B, n $Be$NB?9`<0$GI=$5$l$k(B GF(2^n) $B$r(B -$BJV$9(B. -@item @code{random()}, @code{lrandom()} $B$HF1$8(B 32bit $BMp?tH/@84o$r;HMQ$7$F$$$k(B. +\E +\BEG +@item +Generates an element of the current base field randomly. +@item +The same random generator as in @code{random()}, @code{lrandom()} +is used. +\E @end itemize @example @@ -445,35 +774,49 @@ return to toplevel @end example @table @t -@item $B;2>H(B +\JP @item $B;2>H(B +\EG @item References @fref{setmod_ff}, @fref{random}, @fref{lrandom} @end table -@node lmptop,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\JP @node lmptop,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\EG @node lmptop,,, Functions for Finite fields @subsection @code{lmptop} @findex lmptop @table @t @item lmptop(@var{obj}) -:: GF(p) $B78?tB?9`<0$N78?t$r@0?t$KJQ49(B +\JP :: GF(@var{p}) $B78?tB?9`<0$N78?t$r@0?t$KJQ49(B +\EG :: Converts the coefficients of a polynomial over GF(@var{p}) into integers. @end table @table @var @item return -$B@0?t78?tB?9`<0(B +\JP $B@0?t78?tB?9`<0(B +\EG integral polynomial @item obj -GF(p)$B78?tB?9`<0(B +\JP GF(@var{p}) $B78?tB?9`<0(B +\EG polynomial over GF(@var{p}) @end table @itemize @bullet +\BJP @item -GF(p) $B78?tB?9`<0$N78?t$r@0?t$KJQ49$9$k(B. +GF(@var{p}) $B78?tB?9`<0$N78?t$r@0?t$KJQ49$9$k(B. @item -GF(p) $B$N85$O(B, 0 $B0J>e(B p $BL$K~$N@0?t$GI=8=$5$l$F$$$k(B. +GF(@var{p}) $B$N85$O(B, 0 $B0J>e(B p $BL$K~$N@0?t$GI=8=$5$l$F$$$k(B. $BB?9`<0$N3F78?t$O(B, $B$=$NCM$r@0?t%*%V%8%'%/%H(B($B?t<1JL;R(B 0)$B$H$7$?$b$N$K(B $BJQ49$5$l$k(B. +\E +\BEG @item -GF(p) $B$N85$O(B, $B@0?t$KJQ49$5$l$k(B. +Converts the coefficients of a polynomial over GF(@var{p}) into integers. +@item +An element of GF(@var{p}) is represented by a non-negative integer @var{r} less than +@var{p}. +Each coefficient of a polynomial is converted into an integer object +whose value is @var{r}. +\E @end itemize @example @@ -495,34 +838,51 @@ x^10+537*x^9+45*x^8+427*x^7+210*x^6+295*x^5+210*x^4+42 @end example @table @t -@item $B;2>H(B +\JP @item $B;2>H(B +\EG @item References @fref{simp_ff} @end table -@node ntogf2n,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\JP @node ntogf2n,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\EG @node ntogf2n,,, Functions for Finite fields @subsection @code{ntogf2n} @findex ntogf2n @table @t @item ntogf2n(@var{m}) -:: $B<+A3?t$r(B GF(2^n) $B$N85$KJQ49(B +\JP :: $B<+A3?t$r(B GF(2^@var{n}) $B$N85$KJQ49(B +\EG :: Converts a non-negative integer into an element of GF(2^@var{n}). @end table @table @var @item return -GF(2^n) $B$N85(B +\JP GF(2^@var{n}) $B$N85(B +\EG element of GF(2^@var{n}) @item m -$BHsIi@0?t(B +\JP $BHsIi@0?t(B +\EG non-negative integer @end table @itemize @bullet +\BJP @item $B<+A3?t(B @var{m} $B$N(B 2 $B?JI=8=(B @var{m}=@var{m0}+@var{m1}*2+...+@var{mk}*2^k -$B$KBP$7(B, GF(2^n)=GF(2)[t]/(g(t)) $B$N85(B +$B$KBP$7(B, GF(2^@var{n})=GF(2)[t]/(g(t)) $B$N85(B @var{m0}+@var{m1}*t+...+@var{mk}*t^k mod g(t) $B$rJV$9(B. @item $BDj5AB?9`<0$K$h$k>jM>$O<+F0E*$K$O7W;;$5$l$J$$$?$a(B, @code{simp_ff()} $B$r(B $BE,MQ$9$kI,MW$,$"$k(B. +\E +\BEG +@item +Let @var{m} be a non-negative integer. +@var{m} has the binary representation +@var{m}=@var{m0}+@var{m1}*2+...+@var{mk}*2^k. +This function returns an element of GF(2^@var{n})=GF(2)[t]/(g(t)), +@var{m0}+@var{m1}*t+...+@var{mk}*t^k mod g(t). +@item +Apply @code{simp_ff()} to reduce the result. +\E @end itemize @example @@ -535,29 +895,35 @@ x^30+x+1 @end example @table @t -@item $B;2>H(B +\JP @item $B;2>H(B +\EG @item References @fref{gf2nton} @end table -@node gf2nton,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\JP @node gf2nton,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\EG @node gf2nton,,, Functions for Finite fields @subsection @code{gf2nton} @findex gf2nton @table @t @item gf2nton(@var{m}) -:: GF(2^n) $B$N85$r<+A3?t$KJQ49(B +\JP :: GF(2^@var{n}) $B$N85$r<+A3?t$KJQ49(B +\EG :: Converts an element of GF(2^@var{n}) into a non-negative integer. @end table @table @var @item return -$BHsIi@0?t(B +\JP $BHsIi@0?t(B +\EG non-negative integer @item m -GF(2^n) $B$N85(B +\JP GF(2^@var{n}) $B$N85(B +\EG element of GF(2^@var{n}) @end table @itemize @bullet @item -@code{gf2nton} $B$N5UJQ49$G$"$k(B. +\JP @code{gf2nton} $B$N5UJQ49$G$"$k(B. +\EG The inverse of @code{gf2nton}. @end itemize @example @@ -574,31 +940,44 @@ x^30+x+1 @end example @table @t -@item $B;2>H(B +\JP @item $B;2>H(B +\EG @item References @fref{gf2nton} @end table -@node ptogf2n,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\JP @node ptogf2n,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\EG @node ptogf2n,,, Functions for Finite fields @subsection @code{ptogf2n} @findex ptogf2n @table @t @item ptogf2n(@var{poly}) -:: $B0lJQ?tB?9`<0$r(B GF(2^n) $B$N85$KJQ49(B +\JP :: $B0lJQ?tB?9`<0$r(B GF(2^@var{n}) $B$N85$KJQ49(B +\EG :: Converts a univariate polynomial into an element of GF(2^@var{n}). @end table @table @var @item return -GF(2^n) $B$N85(B +\JP GF(2^@var{n}) $B$N85(B +\EG element of GF(2^@var{n}) @item poly -$B0lJQ?tB?9`<0(B +\JP $B0lJQ?tB?9`<0(B +\EG univariate polynomial @end table @itemize @bullet @item -@var{poly} $B$NI=$9(B GF(2^n) $B$N85$r@8@.$9$k(B. $B78?t$O(B, 2 $B$G3d$C$?M>$j$K(B +\BJP +@var{poly} $B$NI=$9(B GF(2^@var{n}) $B$N85$r@8@.$9$k(B. $B78?t$O(B, 2 $B$G3d$C$?M>$j$K(B $BJQ49$5$l$k(B. @var{poly} $B$NJQ?t$K(B @code{@@} $B$rBeF~$7$?7k2L$HEy$7$$(B. +\E +\BEG +Generates an element of GF(2^@var{n}) represented by @var{poly}. +The coefficients are reduced modulo 2. +The output is equal to the result by substituting @code{@@} for +the variable of @var{poly}. +\E @end itemize @example @@ -609,34 +988,51 @@ x^30+x+1 @end example @table @t -@item $B;2>H(B +\JP @item $B;2>H(B +\EG @item References @fref{gf2ntop} @end table -@node gf2ntop,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\JP @node gf2ntop,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\EG @node gf2ntop,,, Functions for Finite fields @subsection @code{gf2ntop} @findex gf2ntop @table @t @item gf2ntop(@var{m}[,@var{v}]) -:: GF(2^n) $B$N85$rB?9`<0$KJQ49(B +\JP :: GF(2^@var{n}) $B$N85$rB?9`<0$KJQ49(B +\EG :: Converts an element of GF(2^@var{n}) into a polynomial. @end table @table @var @item return -$B0lJQ?tB?9`<0(B +\JP $B0lJQ?tB?9`<0(B +\EG univariate polynomial @item m -GF(2^n) $B$N85(B +\JP GF(2^@var{n}) $B$N85(B +\EG an element of GF(2^@var{n}) @item v -$BITDj85(B +\JP $BITDj85(B +\EG indeterminate @end table @itemize @bullet +\BJP @item @var{m} $B$rI=$9B?9`<0$r(B, $B@0?t78?t$NB?9`<0%*%V%8%'%/%H$H$7$FJV$9(B. -@item @var{v} $B$N;XDj$,$J$$>l9g(B, $BD>A0$N(B @code{ptogf2n()} $B8F$S=P$7(B +@item +@var{v} $B$N;XDj$,$J$$>l9g(B, $BD>A0$N(B @code{ptogf2n()} $B8F$S=P$7(B $B$K$*$1$k0z?t$NJQ?t(B ($B%G%U%)%k%H$O(B @code{x}), $B;XDj$,$"$k>l9g$K$O(B $B;XDj$5$l$?ITDj85$rJQ?t$H$9$kB?9`<0$rJV$9(B. +\E +\BEG +@item +Returns a polynomial representing @var{m}. +@item +If @var{v} is used as the variable of the output. +If @var{v} is not specified, the variable of the argument +of the latest @code{ptogf2n()} call. The default variable is @code{x}. +\E @end itemize @example @@ -652,27 +1048,111 @@ t^13+t^12+t^11+t^10 @end example @table @t -@item $B;2>H(B +\JP @item $B;2>H(B +\EG @item References @fref{ptogf2n} @end table -@node defpoly_mod2,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\JP @node ptosfp sfptop,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\EG @node ptosfp sfptop,,, Functions for Finite fields +@subsection @code{ptosfp}, @code{sfptop} +@findex ptosfp +@findex sfptop + +@table @t +@item ptosfp(@var{p}) +@itemx sfptop(@var{p}) +\JP :: $B>.I8?tM-8BBN$X$NJQ49(B, $B5UJQ49(B +\EG :: Transformation to/from a small finite field +@end table + +@table @var +@item return +\JP $BB?9`<0(B +\EG polynomial +@item p +\JP $BB?9`<0(B +\EG polynomial +@end table + +@itemize @bullet +\BJP +@item +@code{ptosfp()} $B$O(B, $BB?9`<0$N78?t$r(B, $B8=:_@_Dj$5$l$F$$$k>.I8?tM-8BBN(B +GF(p^@var{n}) $B$N85$KD>@\JQ49$9$k(B. $B78?t$,4{$KM-8BBN$N85$N>l9g$OJQ2=$7$J$$(B. +$B@5@0?t$N>l9g(B, $B$^$:0L?t$G>jM>$r7W;;$7$?$"$H(B, $BI8?t(B @var{p} $B$K$h$j(B @var{p} +$B?JE83+$7(B, @var{p} $B$r(B x $B$KCV$-49$($?B?9`<0$r(B, $B86;O85I=8=$KJQ49$9$k(B. +$BNc$($P(B, GF(3^5) $B$O(B GF(3)[x]/(x^5+2*x+1) $B$H$7$FI=8=$5$l(B, $B$=$N3F(B +$B85$O86;O85(B x $B$K4X$9$k$Y$-;X?t(B @var{k} $B$K$h$j(B @var{@@_k} $B$H$7$F(B +$BI=<($5$l$k(B. $B$3$N$H$-(B, $BNc$($P(B @var{23 = 2*3^2+3+2} $B$O(B, 2*x^2+x+2 +$B$HI=8=$5$l(B, $B$3$l$O7k6I(B x^17 $B$HK!(B x^5+2*x+1 $B$GEy$7$$$N$G(B, +@var{@@_17} $B$HJQ49$5$l$k(B. +@item +@code{sfptop()} $B$O(B @code{ptosfp()} $B$N5UJQ49$G$"$k(B. +\E +\BEG +@item +@code{ptosfp()} converts coefficients of a polynomial to +elements in a small finite field GF(@var{p^n}) set as a ground field. +If a coefficient is already an element of the field, +no conversion is done. If a coefficient is a positive integer, +then its residue modulo @var{p^n} is expanded as @var{p}-adic integer, +then @var{p} is substituted by @var{x}, finally the polynomial +is converted to its correspoding logarithmic representation +with respect to the primitive element. +For example, GF(3^5) is represented as F(3)[@var{x}]/(@var{x^5+2*x+1}), +and each element of the field is represented as @var{@@_k} +by its exponent @var{k} with respect to the primitive element @var{x}. +@var{23 = 2*3^2+3+2} is represented as @var{2*x^2+x+2} and +it is equivalent to @var{x^17} modulo @var{x^5+2*x+1}. +Therefore an integer @var{23} is conterted to @var{@@_17}. +@item +@code{sfptop()} is the inverse of @code{ptosfp()}. +\E +@end itemize + +@example +[196] setmod_ff(3,5); +[3,x^5+2*x+1,x] +[197] A = ptosfp(23); +@@_17 +[198] 9*2+3+2; +23 +[199] x^17-(2*x^2+x+2); +x^17-2*x^2-x-2 +[200] sremm(@@,x^5+2*x+1,3); +0 +[201] sfptop(A); +23 +@end example + +@table @t +\JP @item $B;2>H(B +\EG @item References +@fref{setmod_ff}, @fref{simp_ff} +@end table +\JP @node defpoly_mod2,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\EG @node defpoly_mod2,,, Functions for Finite fields @subsection @code{defpoly_mod2} @findex defpoly_mod2 @table @t @item defpoly_mod2(@var{d}) -:: GF(2) $B>e4{Ls$J0lJQ?tB?9`<0$N@8@.(B +\JP :: GF(2) $B>e4{Ls$J0lJQ?tB?9`<0$N@8@.(B +\EG :: Generates an irreducible univariate polynomial over GF(2). @end table @table @var @item return -$BB?9`<0(B +\JP $BB?9`<0(B +\EG univariate polynomial @item d -$B@5@0?t(B +\JP $B@5@0?t(B +\EG positive integer @end table @itemize @bullet +\BJP @item @samp{fff} $B$GDj5A$5$l$F$$$k(B. @item @@ -682,33 +1162,54 @@ t^13+t^12+t^11+t^10 3 $B9`<0$,B8:_$7$J$1$l$P(B, $B4{Ls(B 5 $B9`<0$NCf$G(B, $BBh(B 2 $B9`$N.$5$/(B, $B$=$NCf$GBh(B 3 $B9`$N.$5$/(B, $B$=$NCf$GBh(B 4 $B9`$N.$5$$$b$N$rJV$9(B. +\E +\BEG +@item +Defined in @samp{fff}. +@item +An irreducible univariate polynomial of degree @var{d} is returned. +@item +If an irreducible trinomial @var{x^d+x^m+1} exists, then the one +with the smallest @var{m} is returned. +Otherwise, an irreducible pentanomial @var{x^d+x^m1+x^m2+x^m3+1} +(@var{m1>m2>m3} is returned. +@var{m1}, @var{m2} and @var{m3} are determined as follows: +Fix @var{m1} as small as possible. Then fix @var{m2} as small as possible. +Then fix @var{m3} as small as possible. +\E @end itemize @example @end example @table @t -@item $B;2>H(B +\JP @item $B;2>H(B +\EG @item References @fref{setmod_ff} @end table -@node fctr_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\JP @node fctr_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\EG @node fctr_ff,,, Functions for Finite fields @subsection @code{fctr_ff} @findex fctr_ff @table @t @item fctr_ff(@var{poly}) -:: 1 $BJQ?tB?9`<0$NM-8BBN>e$G$N4{LsJ,2r(B +\JP :: 1 $BJQ?tB?9`<0$NM-8BBN>e$G$N4{LsJ,2r(B +\EG :: Irreducible univariate factorization over a finite field. @end table @table @var @item return -$B%j%9%H(B +\JP $B%j%9%H(B +\EG list @item poly -$BM-8BBN>e$N(B 1 $BJQ?tB?9`<0(B +\JP $BM-8BBN>e$N(B 1 $BJQ?tB?9`<0(B +\EG univariate polynomial over a finite field @end table @itemize @bullet +\BJP @item @samp{fff} $B$GDj5A$5$l$F$$$k(B. @item @@ -719,6 +1220,19 @@ t^13+t^12+t^11+t^10 $B=EJ#EY$G$"$k(B. @item @var{poly} $B$NH(B +\JP @item $B;2>H(B +\EG @item References @fref{setmod_ff} @end table -@node irredcheck_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\JP @node irredcheck_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\EG @node irredcheck_ff,,, Functions for Finite fields @subsection @code{irredcheck_ff} @findex irredcheck_ff @table @t @item irredcheck_ff(@var{poly}) -:: 1 $BJQ?tB?9`<0$NM-8BBN>e$G$N4{LsH=Dj(B +\JP :: 1 $BJQ?tB?9`<0$NM-8BBN>e$G$N4{LsH=Dj(B +\EG :: Primality check of a univariate polynomial over a finite field. @end table @table @var @item return 0|1 @item poly -$BM-8BBN>e$N(B 1 $BJQ?tB?9`<0(B +\JP $BM-8BBN>e$N(B 1 $BJQ?tB?9`<0(B +\EG univariate polynomial over a finite field @end table @itemize @bullet +\BJP @item @samp{fff} $B$GDj5A$5$l$F$$$k(B. @item $BM-8BBN>e$N(B 1 $BJQ?tB?9`<0$N4{LsH=Dj$r9T$$(B, $B4{Ls$N>l9g(B 1, $B$=$l0J30$O(B 0 $B$rJV$9(B. +\E +\BEG +@item +Defined in @samp{fff}. +@item +Returns 1 if @var{poly} is irreducible over the current base field. +Returns 0 otherwise. +\E @end itemize @example @@ -767,34 +1294,50 @@ x^10+14687973587364016969 @end example @table @t -@item $B;2>H(B +\JP @item $B;2>H(B +\EG @item References @fref{setmod_ff} @end table -@node randpoly_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\JP @node randpoly_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\EG @node randpoly_ff,,, Functions for Finite fields @subsection @code{randpoly_ff} @findex randpoly_ff @table @t @item randpoly_ff(@var{d},@var{v}) -:: $BM-8BBN>e$N(B $BMp?t78?t(B 1 $BJQ?tB?9`<0$N@8@.(B +\JP :: $BM-8BBN>e$N(B $BMp?t78?t(B 1 $BJQ?tB?9`<0$N@8@.(B +\EG :: Generation of a random univariate polynomial over a finite field. @end table @table @var @item return -$BB?9`<0(B +\JP $BB?9`<0(B +\EG polynomial @item d -$B@5@0?t(B +\JP $B@5@0?t(B +\EG positive integer @item v -$BITDj85(B +\JP $BITDj85(B +\EG indeterminate @end table @itemize @bullet +\BJP @item @samp{fff} $B$GDj5A$5$l$F$$$k(B. @item @var{d} $BH(B +\JP @item $B;2>H(B +\EG @item References @fref{setmod_ff}, @fref{random_ff} @end table -@node ecm_add_ff ecm_sub_ff ecm_chsgn_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\JP @node ecm_add_ff ecm_sub_ff ecm_chsgn_ff,,, $BM-8BBN$K4X$9$kH!?t$N$^$H$a(B +\EG @node ecm_add_ff ecm_sub_ff ecm_chsgn_ff,,, Functions for Finite fields @subsection @code{ecm_add_ff}, @code{ecm_sub_ff}, @code{ecm_chsgn_ff} @findex ecm_add_ff @findex ecm_sub_ff @@ -823,26 +1368,31 @@ x^10+14687973587364016969 @table @t @item ecm_add_ff(@var{p1},@var{p2},@var{ec}) @itemx ecm_sub_ff(@var{p1},@var{p2},@var{ec}) -@itemx ecm_chsgn_ff(@var{p1},@var{p2},@var{ec}) -:: $BBJ1_6J@~>e$NE@$N2C;;(B, $B8:;;(B, $B5U85(B +@itemx ecm_chsgn_ff(@var{p1}) +\JP :: $BBJ1_6J@~>e$NE@$N2C;;(B, $B8:;;(B, $B5U85(B +\EG :: Addition, Subtraction and additive inverse for points on an elliptic curve. @end table @table @var @item return -$B%Y%/%H%k$^$?$O(B 0 -@item p1,p2 -$BD9$5(B 3 $B$N%Y%/%H%k$^$?$O(B 0 +\JP $B%Y%/%H%k$^$?$O(B 0 +\EG vector or 0 +@item p1 p2 +\JP $BD9$5(B 3 $B$N%Y%/%H%k$^$?$O(B 0 +\EG vector of length 3 or 0 @item ec -$BD9$5(B 2 $B$N%Y%/%H%k(B +\JP $BD9$5(B 2 $B$N%Y%/%H%k(B +\EG vector of length 2 @end table @itemize @bullet +\BJP @item $B8=:_@_Dj$5$l$F$$$kM-8BBN>e$G(B, @var{ec} $B$GDj5A$5$l$kBJ1_6J@~>e$N(B $BE@(B @var{p1}, @var{p2} $B$NOB(B @var{p1+p2}, $B:9(B @var{p1-p2}, $B5U85(B @var{-p1} $B$rJV$9(B. @item @var{ec} $B$O(B, $B@_Dj$5$l$F$$$kM-8BBN$,4qI8?tAGBN$N>l9g(B, -@var{y^2=x^3+ec[0]x+ec[1]}, $BI8?t(B 2 $B$N>l9g(B @var{y^2+xy=x^3+ec[0]x^2+ec[1]} +y^2=x^3+ec[0]x+ec[1], $BI8?t(B 2 $B$N>l9g(B y^2+xy=x^3+ec[0]x^2+ec[1] $B$rI=$9(B. @item $B0z?t(B, $B7k2L$H$b$K(B, $BL58B1sE@$O(B 0 $B$GI=$5$l$k(B. @@ -855,6 +1405,33 @@ x^10+14687973587364016969 $B$G3d$kI,MW$,$"$k(B. @item @var{p1}, @var{p2} $B$,BJ1_6J@~>e$NE@$+$I$&$+$N%A%'%C%/$O$7$J$$(B. +\E +\BEG +@item +Let @var{p1}, @var{p2} be points on the elliptic curve represented by +@var{ec} over the current base field. +ecm_add_ff(@var{p1},@var{p2},@var{ec}), ecm_sub_ff(@var{p1},@var{p2},@var{ec}) +and ecm_chsgn_ff(@var{p1}) returns +@var{p1+p2}, @var{p1-p2} and @var{-p1} respectively. +@item +If the current base field is a prime field of odd order, then +@var{ec} represents y^2=x^3+ec[0]x+ec[1]. +If the characteristic of the current base field is 2, +then @var{ec} represents y^2+xy=x^3+ec[0]x^2+ec[1]. +@item +The point at infinity is represented by 0. +@item +If an argument denoting a point is a vector of length 3, +then it is the projective coordinate. In such a case +the third coordinate must not be 0. +@item +If the result is a vector of length 3, then the third coordinate +is not equal to 0 but not necessarily 1. To get the result by +the affine coordinate, the first and the second coordinates should +be divided by the third coordinate. +@item +The check whether the arguments are on the curve is omitted. +\E @end itemize @example @@ -878,7 +1455,8 @@ x^10+14687973587364016969 @end example @table @t -@item $B;2>H(B +\JP @item $B;2>H(B +\EG @item References @fref{setmod_ff} @end table