@comment $OpenXM: OpenXM/src/asir-doc/parts/builtin/poly.texi,v 1.8 2004/05/15 08:25:12 takayama Exp $ \BJP @node 多項式および有理式の演算,,, 組み込み函数 @section 多項式, 有理式の演算 \E \BEG @node Polynomials and rational expressions,,, Built-in Function @section operations with polynomials and rational expressions \E @menu * var:: * vars:: * uc:: * coef:: * deg mindeg:: * nmono:: * ord:: * sdiv sdivm srem sremm sqr sqrm:: * tdiv:: * %:: * subst psubst:: * diff:: * ediff:: * res:: * fctr sqfr:: * modfctr:: * ufctrhint:: * ptozp:: * prim cont:: * gcd gcdz:: * red:: @end menu \JP @node var,,, 多項式および有理式の演算 \EG @node var,,, Polynomials and rational expressions @subsection @code{var} @findex var @table @t @item var(@var{rat}) \JP :: @var{rat} の主変数. \EG :: Main variable (indeterminate) of @var{rat}. @end table @table @var @item return \JP 不定元 \EG indeterminate @item rat \JP 有理式 \EG rational expression @end table @itemize @bullet \BJP @item 主変数に関しては, @xref{Asir で使用可能な型}. @item デフォルトの変数順序は次のようになっている. @code{x}, @code{y}, @code{z}, @code{u}, @code{v}, @code{w}, @code{p}, @code{q}, @code{r}, @code{s}, @code{t}, @code{a}, @code{b}, @code{c}, @code{d}, @code{e}, @code{f}, @code{g}, @code{h}, @code{i}, @code{j}, @code{k}, @code{l}, @code{m}, @code{n}, @code{o},以後は変数の現れた順. \E \BEG @item See @ref{Types in Asir} for main variable. @item Indeterminates (variables) are ordered by default as follows. @code{x}, @code{y}, @code{z}, @code{u}, @code{v}, @code{w}, @code{p}, @code{q}, @code{r}, @code{s}, @code{t}, @code{a}, @code{b}, @code{c}, @code{d}, @code{e}, @code{f}, @code{g}, @code{h}, @code{i}, @code{j}, @code{k}, @code{l}, @code{m}, @code{n}, @code{o}. The other variables will be ordered after the above noted variables so that the first comer will be ordered prior to the followers. \E @end itemize @example [0] var(x^2+y^2+a^2); x [1] var(a*b*c*d*e); a [2] var(3/abc+2*xy/efg); abc @end example @table @t \JP @item 参照 \EG @item References @fref{ord}, @fref{vars}. @end table \JP @node vars,,, 多項式および有理式の演算 \EG @node vars,,, Polynomials and rational expressions @subsection @code{vars} @findex vars @table @t @item vars(@var{obj}) \JP :: @var{obj} に含まれる変数のリスト. \EG :: A list of variables (indeterminates) in an expression @var{obj}. @end table @table @var @item return \JP リスト \EG list @item obj \JP 任意 \EG arbitrary @end table @itemize @bullet \BJP @item 与えられた式に含まれる変数のリストを返す. @item 変数順序の高いものから順に並べる. \E \BEG @item Returns a list of variables (indeterminates) contained in a given expression. @item Lists variables according to the variable ordering. \E @end itemize @example [0] vars(x^2+y^2+a^2); [x,y,a] [1] vars(3/abc+2*xy/efg); [abc,xy,efg] [2] vars([x,y,z]); [x,y,z] @end example @table @t \JP @item 参照 \EG @item References @fref{var}, @fref{uc}, @fref{ord}. @end table \JP @node uc,,, 多項式および有理式の演算 \EG @node uc,,, Polynomials and rational expressions @subsection @code{uc} @findex uc @table @t @item uc() \JP :: 未定係数法のための不定元を生成する. \EG :: Create a new indeterminate for an undermined coeficient. @end table @table @var @item return \JP @code{vtype} が 1 の不定元 \EG indeterminate with its @code{vtype} 1. @end table @itemize @bullet \BJP @item @code{uc()} を実行するたびに, @code{_0}, @code{_1}, @code{_2},... という 不定元を生成する. @item @code{uc()} で生成された不定元は, 直接キーボードから入力することができない. これは, プログラム中で未定係数を自動生成する場合, 入力などに含まれる 不定元と同一のものが生成されることを防ぐためである. @item 通常の不定元 (@code{vtype} が 0) の自動生成には @code{rtostr()}, @code{strtov()} を用いる. @item @code{uc()} で生成された不定元の不定元としての型 (@code{vtype}) は 1 である. (@xref{不定元の型}.) \E \BEG @item At every evaluation of command @code{uc()}, a new indeterminate in the sequence of indeterminates @code{_0}, @code{_1}, @code{_2}, @dots{} is created successively. @item Indeterminates created by @code{uc()} cannot be input on the keyboard. By this property, you are free, no matter how many indeterminates you will create dynamically by a program, from collision of created names with indeterminates input from the keyboard or from program files. @item Functions, @code{rtostr()} and @code{strtov()}, are used to create ordinary indeterminates (indeterminates having 0 for their @code{vtype}). @item Kernel sub-type of indeterminates created by @code{uc()} is 1. (@code{vtype(uc())}=1) \E @end itemize @example [0] A=uc(); _0 [1] B=uc(); _1 [2] (uc()+uc())^2; _2^2+2*_3*_2+_3^2 [3] (A+B)^2; _0^2+2*_1*_0+_1^2 @end example @table @t \JP @item 参照 \EG @item References @fref{vtype}, @fref{rtostr}, @fref{strtov}. @end table \JP @node coef,,, 多項式および有理式の演算 \EG @node coef,,, Polynomials and rational expressions @subsection @code{coef} @findex coef @table @t @item coef(@var{poly},@var{deg}[,@var{var}]) \JP :: @var{poly} の @var{var} (省略時は主変数) に関する @var{deg} 次の係数. \BEG :: The coefficient of a polynomial @var{poly} at degree @var{deg} with respect to the variable @var{var} (main variable if unspecified). \E @end table @table @var @item return \JP 多項式 \EG polynomial @item poly \JP 多項式 \EG polynomial @item var \JP 不定元 \EG indeterminate @item deg \JP 自然数 \EG non-negative integer @end table @itemize @bullet \BJP @item @var{poly} の @var{var} に関する @var{deg} 次の係数を出力する. @item @var{var} は, 省略すると主変数 @t{var}(@var{poly}) だとみなされる. @item @var{var} が主変数でない時, @var{var} が主変数の場合に比較して 効率が落ちる. \E \BEG @item The coefficient of a polynomial @var{poly} at degree @var{deg} with respect to the variable @var{var}. @item The default value for @var{var} is the main variable, i.e., @t{var(@var{poly})}. @item For multi-variate polynomials, access to coefficients depends on the specified indeterminates. For example, taking coef for the main variable is much faster than for other variables. \E @end itemize @example [0] A = (x+y+z)^3; x^3+(3*y+3*z)*x^2+(3*y^2+6*z*y+3*z^2)*x+y^3+3*z*y^2+3*z^2*y+z^3 [1] coef(A,1,y); 3*x^2+6*z*x+3*z^2 [2] coef(A,0); y^3+3*z*y^2+3*z^2*y+z^3 @end example @table @t \JP @item 参照 \EG @item References @fref{var}, @fref{deg mindeg}. @end table \JP @node deg mindeg,,, 多項式および有理式の演算 \EG @node deg mindeg,,, Polynomials and rational expressions @subsection @code{deg}, @code{mindeg} @findex deg @findex mindeg @table @t @item deg(@var{poly},@var{var}) \JP :: @var{poly} の, 変数 @var{var} に関する最高次数. \EG :: The degree of a polynomial @var{poly} with respect to variable. @item mindeg(@var{poly},@var{var}) \JP :: @var{poly} の, 変数 @var{var} に関する最低次数. \BEG :: The least exponent of the terms with non-zero coefficients in a polynomial @var{poly} with respect to the variable @var{var}. In this manual, this quantity is sometimes referred to the minimum degree of a polynomial for short. \E @end table @table @var @item return \JP 自然数 \EG non-negative integer @item poly \JP 多項式 \EG polynomial @item var \JP 不定元 \EG indeterminate @end table @itemize @bullet \BJP @item 与えられた多項式の変数 @var{var} に関する最高次数, 最低次数を出力する. @item 変数 @var{var} を省略することは出来ない. \E \BEG @item The least exponent of the terms with non-zero coefficients in a polynomial @var{poly} with respect to the variable @var{var}. In this manual, this quantity is sometimes referred to the minimum degree of a polynomial for short. @item Variable @var{var} must be specified. \E @end itemize @example [0] deg((x+y+z)^10,x); 10 [1] deg((x+y+z)^10,w); 0 [75] mindeg(x^2+3*x*y,x); 1 @end example \JP @node nmono,,, 多項式および有理式の演算 \EG @node nmono,,,Polynomials and rational expressions @subsection @code{nmono} @findex nmono @table @t @item nmono(@var{rat}) \JP :: @var{rat} の単項式の項数. \EG :: Number of monomials in rational expression @var{rat}. @end table @table @var @item return \JP 自然数 \EG non-negative integer @item rat \JP 有理式 \EG rational expression @end table @itemize @bullet \BJP @item 多項式を展開した状態での 0 でない係数を持つ単項式の項数を求める. @item 有理式の場合は, 分子と分母の項数の和が返される. @item 函数形式 (@ref{不定元の型}) は, 引数が何であっても単項とみなされる. (1 個の不定元と同じ. ) \E \BEG @item Number of monomials with non-zero number coefficients in the full expanded form of the given polynomial. @item For a rational expression, the sum of the numbers of monomials of the numerator and denominator. @item A function form is regarded as a single indeterminate no matter how complex arguments it has. \E @end itemize @example [0] nmono((x+y)^10); 11 [1] nmono((x+y)^10/(x+z)^10); 22 [2] nmono(sin((x+y)^10)); 1 @end example @table @t \JP @item 参照 \EG @item References @fref{vtype}. @end table \JP @node ord,,, 多項式および有理式の演算 \EG @node ord,,, Polynomials and rational expressions @subsection @code{ord} @findex ord @table @t @item ord([@var{varlist}]) \JP :: 変数順序の設定 \EG :: It sets the ordering of indeterminates (variables). @end table @table @var @item return \JP 変数のリスト \EG list of indeterminates @item varlist \JP 変数のリスト \EG list of indeterminates @end table @itemize @bullet \BJP @item 引数があるとき, 引数の変数リストを先頭に出し, 残りの変数がその後に 続くように変数順序を設定する. 引数のあるなしに関わらず, @code{ord()} の終了時における変数順序リストを返す. @item この函数による変数順序の変更を行っても, 既にプログラム変数などに 代入されている式の内部形式は新しい順序に従っては変更されない. 従って, この函数による順序の変更は, @b{Asir} の起動直後, あるいは, 新たな変数が現れた時点に行われる べきである. 異なる変数順序のもとで生成された式どうしの演算 が行われた場合, 予期せぬ結果が生ずることもあり得る. \E \BEG @item When an argument is given, this function rearranges the ordering of variables (indeterminates) so that the indeterminates in the argument @var{varlist} precede and the other indeterminates follow in the system's variable ordering. Regardless of the existence of an argument, it always returns the final variable ordering. @item Note that no change will be made to the variable ordering of internal forms of objects which already exists in the system, no matter what reordering you specify. Therefore, the reordering should be limited to the time just after starting @b{Asir}, or to the time when one has decided himself to start a totally new computation which has no relation with the previous results. Note that unexpected results may be obtained from operations between objects which are created under different variable ordering. \E @end itemize @example [0] ord(); [x,y,z,u,v,w,p,q,r,s,t,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,_x,_y,_z,_u,_v, _w,_p,_q,_r,_s,_t,_a,_b,_c,_d,_e,_f,_g,_h,_i,_j,_k,_l,_m,_n,_o, exp(_x),(_x)^(_y),log(_x),(_x)^(_y-1),cos(_x),sin(_x),tan(_x), (-_x^2+1)^(-1/2),cosh(_x),sinh(_x),tanh(_x), (_x^2+1)^(-1/2),(_x^2-1)^(-1/2)] [1] ord([dx,dy,dz,a,b,c]); [dx,dy,dz,a,b,c,x,y,z,u,v,w,p,q,r,s,t,d,e,f,g,h,i,j,k,l,m,n,o,_x,_y, _z,_u,_v,_w,_p,_q,_r,_s,_t,_a,_b,_c,_d,_e,_f,_g,_h,_i,_j,_k,_l,_m,_n, _o,exp(_x),(_x)^(_y),log(_x),(_x)^(_y-1),cos(_x),sin(_x),tan(_x), (-_x^2+1)^(-1/2),cosh(_x),sinh(_x),tanh(_x), (_x^2+1)^(-1/2),(_x^2-1)^(-1/2)] @end example \JP @node sdiv sdivm srem sremm sqr sqrm,,, 多項式および有理式の演算 \EG @node sdiv sdivm srem sremm sqr sqrm,,, Polynomials and rational expressions @subsection @code{sdiv}, @code{sdivm}, @code{srem}, @code{sremm}, @code{sqr}, @code{sqrm} @findex sdiv @findex sdivm @findex srem @findex sremm @findex sqr @findex sqrm @table @t @item sdiv(@var{poly1},@var{poly2}[,@var{v}]) @itemx sdivm(@var{poly1},@var{poly2},@var{mod}[,@var{v}]) \JP :: @var{poly1} を @var{poly2} で割る除算が最後まで実行できる場合に商を求める. \BEG :: Quotient of @var{poly1} divided by @var{poly2} provided that the division can be performed within polynomial arithmetic over the rationals. \E @item srem(@var{poly1},@var{poly2}[,@var{v}]) @item sremm(@var{poly1},@var{poly2},@var{mod}[,@var{v}]) \JP :: @var{poly1} を @var{poly2} で割る除算が最後まで実行できる場合に剰余を求める. \BEG :: Remainder of @var{poly1} divided by @var{poly2} provided that the division can be performed within polynomial arithmetic over the rationals. \E @item sqr(@var{poly1},@var{poly2}[,@var{v}]) @item sqrm(@var{poly1},@var{poly2},@var{mod}[,@var{v}]) \BJP :: @var{poly1} を @var{poly2} で割る除算が最後まで実行できる場合に商, 剰余を 求める. \E \BEG :: Quotient and remainder of @var{poly1} divided by @var{poly2} provided that the division can be performed within polynomial arithmetic over the rationals. \E @end table @table @var @item return \JP @code{sdiv()}, @code{sdivm()}, @code{srem()}, @code{sremm()} : 多項式, @code{sqr()}, @code{sqrm()} : @code{[商,剰余]} なるリスト \EG @code{sdiv()}, @code{sdivm()}, @code{srem()}, @code{sremm()} : polynomial @code{sqr()}, @code{sqrm()} : a list @code{[quotient,remainder]} @item poly1 poly2 \JP 多項式 \EG polynomial @item v \JP 不定元 \EG indeterminate @item mod \JP 素数 \EG prime @end table @itemize @bullet \BJP @item @var{poly1} を @var{poly2} の主変数 @t{var}(@var{poly2}) ( 引数 @var{v} がある場合には @var{v}) に関する多項式と見て, @var{poly2} で, 割り算を行う. @item @code{sdivm()}, @code{sremm()}, @code{sqrm()} は GF(@var{mod}) 上で計算する. @item 多項式の除算は, 主係数どうしの割算により得られた商と, 主変数の適当な冪の 積を @var{poly2} に掛けて, @var{poly1} から引くという操作を @var{poly1} の次数が @var{poly2} の次数より小さくなるまで繰り返して 行う. この操作が, 多項式の範囲内で行われるためには, 各ステップにおいて 主係数どうしの除算が, 多項式としての整除である必要がある. これが, 「除算 が最後まで実行できる」ことの意味である. @item 典型的な場合として, @var{poly2} の主係数が, 有理数である場合, あるいは, @var{poly2} が @var{poly1} の因子であることがわかっている場合など がある. @item @code{sqr()} は商と剰余を同時に求めたい時に用いる. @item 整数除算の商, 剰余は @code{idiv}, @code{irem} を用いる. @item 係数に対する剰余演算は @code{%} を用いる. \E \BEG @item Regarding @var{poly1} as an uni-variate polynomial in the main variable of @var{poly2}, i.e. @t{var(@var{poly2})} (@var{v} if specified), @code{sdiv()} and @code{srem()} compute the polynomial quotient and remainder of @var{poly1} divided by @var{poly2}. @item @code{sdivm()}, @code{sremm()}, @code{sqrm()} execute the same operation over GF(@var{mod}). @item Division operation of polynomials is performed by the following steps: (1) obtain the quotient of leading coefficients; let it be Q; (2) remove the leading term of @var{poly1} by subtracting, from @var{poly1}, the product of Q with some powers of main variable and @var{poly2}; obtain a new @var{poly1}; (3) repeat the above step until the degree of @var{poly1} become smaller than that of @var{poly2}. For fulfillment, by operating in polynomials, of this procedure, the divisions at step (1) in every repetition must be an exact division of polynomials. This is the true meaning of what we say ``division can be performed within polynomial arithmetic over the rationals.'' @item There are typical cases where the division is possible: leading coefficient of @var{poly2} is a rational number; @var{poly2} is a factor of @var{poly1}. @item Use @code{sqr()} to get both the quotient and remainder at once. @item Use @code{idiv()}, @code{irem()} for integer quotient. @item For remainder operation on all integer coefficients, use @code{%}. \E @end itemize @example [0] sdiv((x+y+z)^3,x^2+y+a); x+3*y+3*z [1] srem((x+y+z)^2,x^2+y+a); (2*y+2*z)*x+y^2+(2*z-1)*y+z^2-a [2] X=(x+y+z)*(x-y-z)^2; x^3+(-y-z)*x^2+(-y^2-2*z*y-z^2)*x+y^3+3*z*y^2+3*z^2*y+z^3 [3] Y=(x+y+z)^2*(x-y-z); x^3+(y+z)*x^2+(-y^2-2*z*y-z^2)*x-y^3-3*z*y^2-3*z^2*y-z^3 [4] G=gcd(X,Y); x^2-y^2-2*z*y-z^2 [5] sqr(X,G); [x-y-z,0] [6] sqr(Y,G); [x+y+z,0] [7] sdiv(y*x^3+x+1,y*x+1); divsp: cannot happen return to toplevel @end example @table @t \JP @item 参照 \EG @item References @fref{idiv irem}, @fref{%}. @end table \JP @node tdiv,,, 多項式および有理式の演算 \EG @node tdiv,,, Polynomials and rational expressions @subsection @code{tdiv} @findex tdiv @table @t @item tdiv(@var{poly1},@var{poly2}) \JP :: @var{poly1} が @var{poly2} で割り切れるかどうか調べる. \EG :: Tests whether @var{poly2} divides @var{poly1}. @end table @table @var @item return \JP 割り切れるならば商, 割り切れなければ 0 \EG Quotient if @var{poly2} divides @var{poly1}, 0 otherwise. @item poly1 poly2 \JP 多項式 \EG polynomial @end table @itemize @bullet \BJP @item @var{poly2} が @var{poly1} を多項式として割り切るかどうか調べる. @item ある多項式が既約因子であることはわかっているが, その重複度がわからない 場合に, @code{tdiv()} を繰り返し呼ぶことにより重複度がわかる. \E \BEG @item Tests whether @var{poly2} divides @var{poly1} in polynomial ring. @item One application of this function: Consider the case where a polynomial is certainly an irreducible factor of the other polynomial, but the multiplicity of the factor is unknown. Application of @code{tdiv()} to the polynomials repeatedly yields the multiplicity. \E @end itemize @example [11] Y=(x+y+z)^5*(x-y-z)^3; x^8+(2*y+2*z)*x^7+(-2*y^2-4*z*y-2*z^2)*x^6 +(-6*y^3-18*z*y^2-18*z^2*y-6*z^3)*x^5 +(6*y^5+30*z*y^4+60*z^2*y^3+60*z^3*y^2+30*z^4*y+6*z^5)*x^3 +(2*y^6+12*z*y^5+30*z^2*y^4+40*z^3*y^3+30*z^4*y^2+12*z^5*y+2*z^6)*x^2 +(-2*y^7-14*z*y^6-42*z^2*y^5-70*z^3*y^4-70*z^4*y^3-42*z^5*y^2 -14*z^6*y-2*z^7)*x-y^8-8*z*y^7-28*z^2*y^6-56*z^3*y^5-70*z^4*y^4 -56*z^5*y^3-28*z^6*y^2-8*z^7*y-z^8 [12] for(I=0,F=x+y+z,T=Y; T=tdiv(T,F); I++); [13] I; 5 @end example @table @t \JP @item 参照 \EG @item References @fref{sdiv sdivm srem sremm sqr sqrm}. @end table \JP @node %,,, 多項式および有理式の演算 \EG @node %,,, Polynomials and rational expressions @subsection @code{%} @findex % @table @t @item @var{poly} % @var{m} \JP :: 整数による剰余 \EG :: integer remainder to all integer coefficients of the polynomial. @end table @table @var @item return \JP 整数または多項式 \EG integer or polynomial @item poly \JP 整数または整数係数多項式 \EG integer or polynomial with integer coefficients @item m \JP 整数 \EG intger @end table @itemize @bullet \BJP @item @var{poly} の各係数を @var{m} で割った剰余で置き換えた多項式を返す. @item 結果の係数は全て正の整数となる. @item @var{poly} は整数でもよい. この場合, 結果が正に正規化されることを除けば @code{irem()} と同様に用いることができる. @item @var{poly} の係数, @var{m} とも整数である必要があるが, チェックは行なわれない. \E \BEG @item Returns a polynomial whose coefficients are remainders of the coefficients of the input polynomial divided by @var{m}. @item The resulting coefficients are all normalized to non-negative integers. @item An integer is allowed for @var{poly}. This can be used for an alternative for @code{irem()} except that the result is normalized to a non-negative integer. @item Coefficients of @var{poly} and @var{m} must all be integers, though the type checking is not done. \E @end itemize @example [0] (x+2)^5 % 3; x^5+x^4+x^3+2*x^2+2*x+2 [1] (x-2)^5 % 3; x^5+2*x^4+x^3+x^2+2*x+1 [2] (-5) % 4; 3 [3] irem(-5,4); -1 @end example @table @t \JP @item 参照 \EG @item References @fref{idiv irem}. @end table \JP @node subst psubst,,, 多項式および有理式の演算 \EG @node subst psubst,,, Polynomials and rational expressions @subsection @code{subst}, @code{psubst} @findex subst @findex psubst @table @t @item subst(@var{rat}[,@var{varn},@var{ratn}]*) @item psubst(@var{rat}[,@var{var},@var{rat}]*) \BJP :: @var{rat} の @var{varn} に @var{ratn} を代入 (@var{n}=1,2,... で左から右に順次代入する). \E \BEG :: Substitute @var{ratn} for @var{varn} in expression @var{rat}. (@var{n}=1,2,@dots{}. Substitution will be done successively from left to right if arguments are repeated.) \E @end table @table @var @item return \JP 有理式 \EG rational expression @item rat ratn \JP 有理式 \EG rational expression @item varn \JP 不定元 \EG indeterminate @end table @itemize @bullet \BJP @item 有理式の特定の不定元に, 定数あるいは多項式, 有理式などを代入するのに用いる. @item @t{subst}(@var{rat},@var{var1},@var{rat1},@var{var2},@var{rat2},...) は, @t{subst}(@t{subst}(@var{rat},@var{var1},@var{rat1}),@var{var2},@var{rat2},...) と同じ意味である. @item 入力の左側から順に代入を繰り返すために, 入力の順によって結果が変わることがある. @item @code{subst()} は, @code{sin()} などの函数の引数に対しても代入を行う. @code{psubst()} は, このような函数を一つの独立した不定元と見なして, そ の引数には代入は行わない. (partial substitution のつもり) @item @b{Asir} では, 有理式の約分は自動的には行わないため, 有理式の代入は, 思わぬ計算時間の増大を引き起こす場合がある. 有理式を代入する場合には, 問題に応じた独自の函数を書いて, なるべく分母, 分子が大きくならないように配慮することもしばしば必要となる. @item 分数を代入する場合も同様である. @item @code{subst}の引数@var{rat}がリスト,配列,行列,あるいは分散表現多項式で あった場合には, それぞれの要素または係数に対して再帰的に@code{subst}を 行う. \E \BEG @item Substitutes rational expressions for specified kernels in a rational expression. @item @t{subst}(@var{r},@var{v1},@var{r1},@var{v2},@var{r2},@dots{}) has the same effect as @t{subst}(@t{subst}(@var{r},@var{v1},@var{r1}),@var{v2},@var{r2},@dots{}). @item Note that repeated substitution is done from left to right successively. You may get different result by changing the specification order. @item Ordinary @code{subst()} performs substitution at all levels of a scalar algebraic expression creeping into arguments of function forms recursively. Function @code{psubst()} regards such a function form as an independent indeterminate, and does not attempt to apply substitution to its arguments. (The name comes after Partial SUBSTitution.) @item Since @b{Asir} does not reduce common divisors of a rational expression automatically, substitution of a rational expression to an expression may cause unexpected increase of computation time. Thus, it is often necessary to write a special function to meet the individual problem so that the denominator and the numerator do not become too large. @item The same applies to substitution by rational numbers. \E @end itemize @example [0] subst(x^3-3*y*x^2+3*y^2*x-y^3,y,2); x^3-6*x^2+12*x-8 [1] subst(@@@@,x,-1); -27 [2] subst(x^3-3*y*x^2+3*y^2*x-y^3,y,2,x,-1); -27 [3] subst(x*y^3,x,y,y,x); x^4 [4] subst(x*y^3,y,x,x,y); y^4 [5] subst(x*y^3,x,t,y,x,t,y); y*x^3 [6] subst(x*sin(x),x,t); sint(t)*t [7] psubst(x*sin(x),x,t); sin(x)*t @end example \JP @node diff,,, 多項式および有理式の演算 \EG @node diff,,, Polynomials and rational expressions @subsection @code{diff} @findex diff @table @t @item diff(@var{rat}[,@var{varn}]*) @item diff(@var{rat},@var{varlist}) \JP :: @var{rat} を @var{varn} あるいは @var{varlist} の中の変数で順次微分する. \BEG :: Differentiate @var{rat} successively by @var{var}'s for the first form, or by variables in @var{varlist} for the second form. \E @end table @table @var @item return \JP 式 \EG expression @item rat \JP 有理式 (初等函数を含んでもよい) \EG rational expression which contains elementary functions. @item varn \JP 不定元 \EG indeterminate @item varlist \JP 不定元のリスト \EG list of indeterminates @end table @itemize @bullet \BJP @item 与えられた初等函数を @var{varn} あるいは @var{varlist} の中の変数で 順次微分する. @item 左側の不定元より, 順に微分していく. つまり, @t{diff}(@var{rat},@t{x,y}) は, @t{diff}(@t{diff}(@var{rat},@t{x}),@t{y}) と同じである. \E \BEG @item Differentiate @var{rat} successively by @var{var}'s for the first form, or by variables in @var{varlist} for the second form. @item differentiation is performed by the specified indeterminates (variables) from left to right. @t{diff}(@var{rat},@t{x,y}) is the same as @t{diff}(@t{diff}(@var{rat},@t{x}),@t{y}). \E @end itemize @example [0] diff((x+2*y)^2,x); 2*x+4*y [1] diff((x+2*y)^2,x,y); 4 [2] diff(x/sin(log(x)+1),x); (sin(log(x)+1)-cos(log(x)+1))/(sin(log(x)+1)^2) [3] diff(sin(x),[x,x,x,x]); sin(x) @end example \JP @node ediff,,, 多項式および有理式の演算 \EG @node ediff,,, Polynomials and rational expressions @subsection @code{ediff} @findex ediff @table @t @item ediff(@var{poly}[,@var{varn}]*) @item ediff(@var{poly},@var{varlist}) \JP :: @var{poly} を @var{varn} あるいは @var{varlist} の中の変数で順次オイラー微分する. \BEG :: Differentiate @var{poly} successively by Euler operators of @var{var}'s for the first form, or by Euler operators of variables in @var{varlist} for the second form. \E @end table @table @var @item return \JP 多項式 \EG polynomial @item poly \JP 多項式 \EG polynomial @item varn \JP 不定元 \EG indeterminate @item varlist \JP 不定元のリスト \EG list of indeterminates @end table @itemize @bullet \BJP @item 左側の不定元より, 順にオイラー微分していく. つまり, @t{ediff}(@var{poly},@t{x,y}) は, @t{ediff}(@t{ediff}(@var{poly},@t{x}),@t{y}) と同じである. \E \BEG @item differentiation is performed by the specified indeterminates (variables) from left to right. @t{ediff}(@var{poly},@t{x,y}) is the same as @t{ediff}(@t{ediff}(@var{poly},@t{x}),@t{y}). \E @end itemize @example [0] ediff((x+2*y)^2,x); 2*x^2+4*y*x [1] ediff((x+2*y)^2,x,y); 4*y*x @end example \JP @node res,,, 多項式および有理式の演算 \EG @node res,,, Polynomials and rational expressions @subsection @code{res} @findex res @table @t @item res(@var{var},@var{poly1},@var{poly2}[,@var{mod}]) \JP :: @var{var} に関する @var{poly1} と @var{poly2} の終結式. \EG :: Resultant of @var{poly1} and @var{poly2} with respect to @var{var}. @end table @table @var @item return \JP 多項式 \EG polynomial @item var \JP 不定元 \EG indeterminate @item poly1 poly2 \JP 多項式 \EG polynomial @item mod \JP 素数 \EG prime @end table @itemize @bullet \BJP @item 二つの多項式 @var{poly1} と @var{poly2} の, 変数 @var{var} に関する 終結式を求める. @item 部分終結式アルゴリズムによる. @item 引数 @var{mod} がある時, GF(@var{mod}) 上での計算を行う. \E \BEG @item Resultant of two polynomials @var{poly1} and @var{poly2} with respect to @var{var}. @item Sub-resultant algorithm is used to compute the resultant. @item The computation is done over GF(@var{mod}) if @var{mod} is specified. \E @end itemize @example [0] res(t,(t^3+1)*x+1,(t^3+1)*y+t); -x^3-x^2-y^3 @end example \JP @node fctr sqfr,,, 多項式および有理式の演算 \EG @node fctr sqfr,,, Polynomials and rational expressions @subsection @code{fctr}, @code{sqfr} @findex fctr @findex sqfr @table @t @item fctr(@var{poly}) \JP :: @var{poly} を既約因子に分解する. \EG :: Factorize polynomial @var{poly} over the rationals. @item sqfr(@var{poly}) \JP :: @var{poly} を無平方分解する. \EG :: Gets a square-free factorization of polynomial @var{poly}. @end table @table @var @item return \JP リスト \EG list @item poly \JP 有理数係数の多項式 \EG polynomial with rational coefficients @end table @itemize @bullet \BJP @item 有理数係数の多項式 @var{poly} を因数分解する. @code{fctr()} は既約因子分解, @code{sqfr()} は無平方因子分解. @item 結果は [[@b{数係数},1],[@b{因子},@b{重複度}],...] なるリスト. @item @b{数係数} と 全ての @b{因子}^@b{重複度} の積が @var{poly} と等しい. @item @b{数係数} は, (@var{poly}/@b{数係数}) が, 整数係数で, 係数の GCD が 1 となる ような多項式になるように選ばれている. (@code{ptozp()} 参照) \E \BEG @item Factorizes polynomial @var{poly} over the rationals. @code{fctr()} for irreducible factorization; @code{sqfr()} for square-free factorization. @item The result is represented by a list, whose elements are a pair represented as [[@b{num},1],[@b{factor},@b{multiplicity}],...]. @item Products of all @b{factor}^@b{multiplicity} and @b{num} is equal to @var{poly}. @item The number @b{num} is determined so that (@var{poly}/@b{num}) is an integral polynomial and its content (GCD of all coefficients) is 1. (@xref{ptozp}.) \E @end itemize @example [0] fctr(x^10-1); [[1,1],[x-1,1],[x+1,1],[x^4+x^3+x^2+x+1,1],[x^4-x^3+x^2-x+1,1]] [1] fctr(x^3+y^3+(z/3)^3-x*y*z); [[1/27,1],[9*x^2+(-9*y-3*z)*x+9*y^2-3*z*y+z^2,1],[3*x+3*y+z,1]] [2] A=(a+b+c+d)^2; a^2+(2*b+2*c+2*d)*a+b^2+(2*c+2*d)*b+c^2+2*d*c+d^2 [3] fctr(A); [[1,1],[a+b+c+d,2]] [4] A=(x+1)*(x^2-y^2)^2; x^5+x^4-2*y^2*x^3-2*y^2*x^2+y^4*x+y^4 [5] sqfr(A); [[1,1],[x+1,1],[-x^2+y^2,2]] [6] fctr(A); [[1,1],[x+1,1],[-x-y,2],[x-y,2]] @end example @table @t \JP @item 参照 \EG @item References @fref{ufctrhint}. @end table \JP @node ufctrhint,,, 多項式および有理式の演算 \EG @node ufctrhint,,, Polynomials and rational expressions @subsection @code{ufctrhint} @findex ufctrhint @table @t @item ufctrhint(@var{poly},@var{hint}) \JP :: 次数情報を用いた 1 変数多項式の因数分解 \BEG :: Factorizes uni-variate polynomial @var{poly} over the rational number field when the degrees of its factors are known to be some integer multiples of @var{hint}. \E @end table @table @var @item return \JP リスト \EG list @item poly \JP 有理数係数の 1 変数多項式 \EG uni-variate polynomial with rational coefficients @item hint \JP 自然数 \EG non-negative integer @end table @itemize @bullet \BJP @item 各既約因子の次数が @var{hint} の倍数であることがわかっている場合に @var{poly} の既約因子分解を @code{fctr()} より効率良く行う. @var{poly} が, @var{d} 次の拡大体上における ある多項式のノルム (@ref{代数的数に関する演算}) で無平方である場合, 各既約因子の次数は @var{d} の倍数となる. このような場合に 用いられる. \E \BEG @item By any reason, if the degree of all the irreducible factors of @var{poly} is known to be some multiples of @var{hint}, factors can be computed more efficiently by the knowledge than @code{fctr()}. @item When @var{hint} is 1, @code{ufctrhint()} is the same as @code{fctr()} for uni-variate polynomials. An typical application where @code{ufctrhint()} is effective: Consider the case where @var{poly} is a norm (@ref{Algebraic numbers}) of a certain polynomial over an extension field with its extension degree @var{d}, and it is square free; Then, every irreducible factor has a degree that is a multiple of @var{d}. \E @end itemize @example [10] A=t^9-15*t^6-87*t^3-125; t^9-15*t^6-87*t^3-125 0msec [11] N=res(t,subst(A,t,x-2*t),A); -x^81+1215*x^78-567405*x^75+139519665*x^72-19360343142*x^69 +1720634125410*x^66-88249977024390*x^63-4856095669551930*x^60 +1999385245240571421*x^57-15579689952590251515*x^54 +15956967531741971462865*x^51 ... +140395588720353973535526123612661444550659875*x^6 +10122324287343155430042768923500799484375*x^3 +139262743444407310133459021182733314453125 980msec + gc : 250msec [12] sqfr(N); [[-1,1],[x^81-1215*x^78+567405*x^75-139519665*x^72+19360343142*x^69 -1720634125410*x^66+88249977024390*x^63+4856095669551930*x^60 -1999385245240571421*x^57+15579689952590251515*x^54 ... -10122324287343155430042768923500799484375*x^3 -139262743444407310133459021182733314453125,1]] 20msec [13] fctr(N); [[-1,1],[x^9-405*x^6-63423*x^3-2460375,1], [x^18-486*x^15+98739*x^12-9316620*x^9+945468531*x^6-12368049246*x^3 +296607516309,1],[x^18-8667*x^12+19842651*x^6+19683,1], [x^18-324*x^15+44469*x^12-1180980*x^9+427455711*x^6+2793253896*x^3 +31524548679,1], [x^18+10773*x^12+2784051*x^6+307546875,1]] 167.050sec + gc : 1.890sec [14] ufctrhint(N,9); [[-1,1],[x^9-405*x^6-63423*x^3-2460375,1], [x^18-486*x^15+98739*x^12-9316620*x^9+945468531*x^6-12368049246*x^3 +296607516309,1],[x^18-8667*x^12+19842651*x^6+19683,1], [x^18-324*x^15+44469*x^12-1180980*x^9+427455711*x^6+2793253896*x^3 +31524548679,1], [x^18+10773*x^12+2784051*x^6+307546875,1]] 119.340sec + gc : 1.300sec @end example @table @t \JP @item 参照 \EG @item References @fref{fctr sqfr}. @end table \JP @node modfctr,,, 多項式および有理式の演算 \EG @node modfctr,,, Polynomials and rational expressions @subsection @code{modfctr} @findex modfctr @table @t @item modfctr(@var{poly},@var{mod}) \JP :: 有限体上での多項式の因数分解 \EG :: Factorizer over small finite fields @end table @table @var @item return \JP リスト \EG list @item poly \JP 整数係数の多項式 \EG Polynomial with integer coefficients @item mod \JP 自然数 \EG non-negative integer @end table @itemize @bullet \BJP @item 2^29 未満の自然数 @var{mod} を標数とする素体上で多項式 @var{poly} を既約因子に分解する. @item 結果は [[@b{数係数},1],[@b{因子},@b{重複度}],...] なるリスト. @item @b{数係数} と 全ての @b{因子}^@b{重複度} の積が @var{poly} と等しい. @item 大きな位数を持つ有限体上の因数分解には @code{fctr_ff} を用いる. (@ref{有限体に関する演算},@pxref{fctr_ff}). \E \BEG @item This function factorizes a polynomial @var{poly} over the finite prime field of characteristic @var{mod}, where @var{mod} must be smaller than 2^29. @item The result is represented by a list, whose elements are a pair represented as [[@b{num},1],[@b{factor},@b{multiplicity}],...]. @item Products of all @b{factor}^@b{multiplicity} and @b{num} is equal to @var{poly}. @item To factorize polynomials over large finite fields, use @code{fctr_ff} (@pxref{Finite fields},@ref{fctr_ff}). \E @end itemize @example [0] modfctr(x^10+x^2+1,2147483647); [[1,1],[x+1513477736,1],[x+2055628767,1],[x+91854880,1], [x+634005911,1],[x+1513477735,1],[x+634005912,1], [x^4+1759639395*x^2+2045307031,1]] [1] modfctr(2*x^6+(y^2+z*y)*x^4+2*z*y^3*x^2+(2*z^2*y^2+z^3*y)*x+z^4,3); [[2,1],[2*x^3+z*y*x+z^2,1],[2*x^3+y^2*x+2*z^2,1]] @end example @table @t \JP @item 参照 \EG @item References @fref{fctr sqfr}. @end table \JP @node ptozp,,, 多項式および有理式の演算 \EG @node ptozp,,, Polynomials and rational expressions @subsection @code{ptozp} @findex ptozp @table @t @item ptozp(@var{poly}) \JP :: @var{poly} を有理数倍して整数係数多項式にする. \BEG :: Converts a polynomial @var{poly} with rational coefficients into an integral polynomial such that GCD of all its coefficients is 1. \E @end table @table @var @item return \JP 多項式 \EG polynomial @item poly \JP 多項式 \EG polynomial @end table @itemize @bullet \BJP @item 与えられた多項式 @var{poly} に適当な有理数を掛けて, 整数係数かつ 係数の GCD が 1 になるようにする. @item 分数の四則演算は, 整数の演算に比較して遅いため, 種々の多項式演算 の前に, 多項式を整数係数にしておくことが望ましい. @item 有理式を約分する @code{red()} で分数係数有理式を約分しても, 分子多項式の係数は有理数のままであり, 有理式の分子を求める @code{nm()} では, 分数係数多項式は, 分数係数のままの形で出力されるため, 直ちに整数係数多項式を得る事は出来ない. @item オプション factor が設定された場合の戻り値はリスト [g,c] である. ここで c は有理数であり, g がオプションのない場合の戻り値であり, @var{poly} = c*g となる. \E \BEG @item Converts the given polynomial by multiplying some rational number into an integral polynomial such that GCD of all its coefficients is 1. @item In general, operations on polynomials can be performed faster for integer coefficients than for rational number coefficients. Therefore, this function is conveniently used to improve efficiency. @item Function @code{red} does not convert rational coefficients of the numerator. You cannot obtain an integral polynomial by direct use of the function @code{nm()}. The function @code{nm()} returns the numerator of its argument, and a polynomial with rational coefficients is the numerator of itself and will be returned as it is. @item When the option factor is set, the return value is a list [g,c]. Here, c is a rational number, g is an integral polynomial and @var{poly} = c*g holds. \E @end itemize @example [0] ptozp(2*x+5/3); 6*x+5 [1] nm(2*x+5/3); 2*x+5/3 @end example @table @t \JP @item 参照 \EG @item References @fref{nm dn}. @end table \JP @node prim cont,,, 多項式および有理式の演算 \EG @node prim cont,,, Polynomials and rational expressions @subsection @code{prim}, @code{cont} @findex prim @table @t @item prim(@var{poly}[,@var{v}]) \JP :: @var{poly} の原始的部分 (primitive part). \EG :: Primitive part of @var{poly}. @item cont(@var{poly}[,@var{v}]) \JP :: @var{poly} の容量 (content). \EG :: Content of @var{poly}. @end table @table @var @item return poly \JP 有理数係数多項式 \EG polynomial over the rationals @item v \JP 不定元 \EG indeterminate @end table @itemize @bullet \BJP @item @var{poly} の主変数 (引数 @var{v} がある場合には @var{v}) に関する原始的部分, 容量を求める. \E \BEG @item The primitive part and the content of a polynomial @var{poly} with respect to its main variable (@var{v} if specified). \E @end itemize @example [0] E=(y-z)*(x+y)*(x-z)*(2*x-y); (2*y-2*z)*x^3+(y^2-3*z*y+2*z^2)*x^2+(-y^3+z^2*y)*x+z*y^3-z^2*y^2 [1] prim(E); 2*x^3+(y-2*z)*x^2+(-y^2-z*y)*x+z*y^2 [2] cont(E); y-z [3] prim(E,z); (y-z)*x-z*y+z^2 @end example @table @t \JP @item 参照 \EG @item References @fref{var}, @fref{ord}. @end table \JP @node gcd gcdz,,, 多項式および有理式の演算 \EG @node gcd gcdz,,, Polynomials and rational expressions @subsection @code{gcd}, @code{gcdz} @findex gcd @table @t @item gcd(@var{poly1},@var{poly2}[,@var{mod}]) @item gcdz(@var{poly1},@var{poly2}) \JP :: @var{poly1} と @var{poly2} の gcd. \EG :: The polynomial greatest common divisor of @var{poly1} and @var{poly2}. @end table @table @var @item return \JP 多項式 \EG polynomial @item poly1 poly2 \JP 多項式 \EG polynomial @item mod \JP 素数 \EG prime @end table @itemize @bullet \BJP @item 二つの多項式の最大公約式 (GCD) を求める. @item @code{gcd()} は有理数体上の多項式としての GCD を返す. すなわち, 結果は整数係数で, かつ係数の GCD が 1 になるような多項式, または, 互いに素の場合は 1 を返す. @item @code{gcdz()} は @var{poly1}, @var{poly2} ともに整数係数の場合に, 整数環上の多項式としての GCD を返す. すなわち, @code{gcd()} の値に, 係数全体の整数 GCDの値を掛けたものを返す. @item 引数 @var{mod} がある時, @code{gcd()} は GF(@var{mod}) 上での GCD を返す. @item @code{gcd()}, @code{gcdz()} Extended Zassenhaus アルゴリズムによる. 有限体上の GCD は PRS アルゴリズムによっているため, 大きな問題, GCD が 1 の場合などにおいて効率が悪い. \E \BEG @item Functions @code{gcd()} and @code{gcdz()} return the greatest common divisor (GCD) of the given two polynomials. @item Function @code{gcd()} returns an integral polynomial GCD over the rational number field. The coefficients are normalized such that their GCD is 1. It returns 1 in case that the given polynomials are mutually prime. @item Function @code{gcdz()} works for arguments of integral polynomials, and returns a polynomial GCD over the integer ring, that is, it returns @code{gcd()} multiplied by the contents of all coefficients of the two input polynomials. @item @code{gcd()} computes the GCD over GF(@var{mod}) if @var{mod} is specified. @item Polynomial GCD is computed by an improved algorithm based on Extended Zassenhaus algorithm. @item GCD over a finite field is computed by PRS algorithm and it may not be efficient for large inputs and co-prime inputs. \E @end itemize @example [0] gcd(12*(x^2+2*x+1)^2,18*(x^2+(y+1)*x+y)^3); x^3+3*x^2+3*x+1 [1] gcdz(12*(x^2+2*x+1)^2,18*(x^2+(y+1)*x+y)^3); 6*x^3+18*x^2+18*x+6 [2] gcd((x+y)*(x-y)^2,(x+y)^2*(x-y)); x^2-y^2 [3] gcd((x+y)*(x-y)^2,(x+y)^2*(x-y),2); x^3+y*x^2+y^2*x+y^3 @end example @table @t \JP @item 参照 \EG @item References @fref{igcd igcdcntl}. @end table \JP @node red,,, 多項式および有理式の演算 \EG @node red,,, Polynomials and rational expressions @subsection @code{red} @findex red @table @t @item red(@var{rat}) \JP :: @var{rat} を約分したもの. \EG :: Reduced form of @var{rat} by canceling common divisors. @end table @table @var @item return \JP 有理式 \EG rational expression @item rat \JP 有理式 \EG rational expression @end table @itemize @bullet \BJP @item @b{Asir} は有理数の約分を常に自動的に行う. しかし, 有理式については通分は行うが, 約分はユーザーが指定しない限り行わない. この約分を行うコマンドが @t{red} である. @item EZGCD により @var{rat} の分子, 分母を約分する. @item 出力される有理式の分母の多項式は, 各係数の GCD が 1 の 整数係数多項式である. 分子については整数係数多項式となるとは限らない. @item GCD は大変重い演算なので, 他の方法で除ける共通因子は可能な限り除くのが 望ましい. また, 分母, 分子が大きくなってからのこの函数の呼び出しは, 非常に時間が掛かる場合が多い. 有理式演算を行う場合は, ある程度 頻繁に, 約分を行う必要がある. \E \BEG @item @b{Asir} automatically performs cancellation of common divisors of rational numb ers. But, without an explicit command, it does not cancel common polynomial divisors of rational expressions. (Reduction of rational expressions to a common denominator will be always done.) Use command @t{red()} to perform this cancellation. @item Cancel the common divisors of the numerator and the denominator of a rational expression @var{rat} by computing their GCD. @item The denominator polynomial of the result is an integral polynomial which has no common divisors in its coefficients, while the numerator may have rational coefficients. @item Since GCD computation is a very hard operation, it is desirable to detect and remove by any means common divisors as far as possible. Furthermore, a call to this function after swelling of the denominator and the numerator shall usually take a very long time. Therefore, often, to some extent, reduction of common divisors is inevitable for operations of rational expressions. \E @end itemize @example [0] (x^3-1)/(x-1); (x^3-1)/(x-1) [1] red((x^3-1)/(x-1)); x^2+x+1 [2] red((x^3+y^3+z^3-3*x*y*z)/(x+y+z)); x^2+(-y-z)*x+y^2-z*y+z^2 [3] red((3*x*y)/(12*x^2+21*y^3*x)); (y)/(4*x+7*y^3) [4] red((3/4*x^2+5/6*x)/(2*y*x+4/3*x)); (9/8*x+5/4)/(3*y+2) @end example @table @t \JP @item 参照 \EG @item References @fref{nm dn}, @fref{gcd gcdz}, @fref{ptozp}. @end table