[ << ] [ < ] [] [ > ] [ >> ]         [冒頭] [目次] [見出し] [ ? ]

2.1 クオート


[ << ] [ < ] [] [ > ] [ >> ]         [冒頭] [目次] [見出し] [ ? ]

2.1.1 quotetotex, quotetotex_env

quotetotex(q)

:: q を latex 形式で表現した文字列に変換する.

quotetotex_env(key,value)

:: quotetotex の動作を制御するパラメータを変更する.

quotetotex_env()

:: quotetotex の動作を制御するパラメータの現在値を戻す.

quotetotex_env(0)

:: quotetotex の動作を制御するパラメータをデフォールト値に戻す.

return

文字列(quotetotex) または リストまたはオブジェクト(quotetotex_env)

q

quote

key

文字列

value

オブジェクト

[3] quotetotex(quote(1/(x+1)));
\frac{ 1} { (  {x}+ 1)}
[4]  quotetotex(objtoquote(diff(x^x,x)));
   {x}^{  {x}- 1}   {x}+  \log( {x})   {x}^{ {x}}
[5] quotetotex_env("conv_rule",3);
[6] quotetotex(objtoquote( (alpha2beta+x_i_j)^2));
  {\alpha}_{2,\beta}^{ 2} +   2  {x}_{i,j}  {\alpha}_{2,\beta}+  {x}_{i,j}^{ 2}
参照

objtoquote print_tex_form(contrib)

ChangeLog


[ << ] [ < ] [] [ > ] [ >> ]         [冒頭] [目次] [見出し] [ ? ]

2.1.2 objtoquote

objtoquote(ob)

:: オブジェクトと quote 型のデータに変換する.

return

quote

ob

オブジェクト

[1150] quotetolist(quote(1+2));
[b_op,+,[internal,1],[internal,2]]
[1151] quotetolist(objtoquote(1+x));
[b_op,+,[internal,x],[internal,1]]3
参照

@ref{quotetotex} @ref{quotetolist}

ChangeLog


[ << ] [ < ] [] [ > ] [ >> ]         [冒頭] [目次] [見出し] [ ? ]

2.1.3 flatten_quote

flatten_quote(q,op)

:: quote の括弧をとりさる.

return

Quote

q

Quote

op

演算子を表す文字列.

[1288] flatten_quote(quote((1+2)+(3+4*(x+3))),"+");
quote(1+2+3+4*(x+3))
[1289] flatten_quote(quote( (x*y)*(p*3)-(x*y)*z),"*");
quote(x*y*p*3-x*y*z)
[1290] quotetolist(quote(1+2+3));
[b_op,+,[b_op,+,[internal,1],[internal,2]],[internal,3]]
参照

@ref{quotetolist}, @ref{print_tex_form}(contrib)

ChangeLog


[ << ] [ < ] [] [ > ] [ >> ]         [冒頭] [目次] [見出し] [ ? ]

2.1.4 quote_to_funargs, funargs_to_quote, remove_paren, get_function_name

quote_to_funargs(q)

:: quote を funarg 形式(リスト) へ.

funargs_to_quote(f)

:: funarg 形式を quote へ.

get_function_name(f)

:: funarg 形式の op を文字列へ.

remove_paren(q)

:: 上の関数を用いて書かれた余分な括弧を取り去る simplifier (asir-contrib マニュアルへ: todo)

return

quote(funargs_to_quote, remove_paren) か リスト(quote_to_funargs)

q

quote

f

リスト

次の例では (x+1)+(x+2) の括弧をはずして x+1+x+2 に変換している.

[0] ctrl("print_quote",1) $

[1] Q=quote((x+1)+(x+2));
[b_op,+,[u_op,(),[b_op,+,[internal,x],[internal,1]]],
        [u_op,(),[b_op,+,[internal,x],[internal,2]]]]

[2] FA=quote_to_funargs(Q);
[0,<...quoted...>,
  [u_op,(),[b_op,+,[internal,x],[internal,1]]],
  [u_op,(),[b_op,+,[internal,x],[internal,2]]]]

[3] FA2=quote_to_funargs(FA[2])[1];
[b_op,+,[internal,x],[internal,1]]

[4] FA3=quote_to_funargs(FA[3])[1];
[b_op,+,[internal,x],[internal,2]]

[5] funargs_to_quote([FA[0],FA[1],FA2,FA3]);
[b_op,+,[b_op,+,[internal,x],[internal,1]],
        [b_op,+,[internal,x],[internal,2]]]

次の例は OpenXM/asir-contrib 版の asir で実行.

[1287] load("noro_simplify.rr");
1
[1293] noro_simplify.remove_paren(quote( f(1-(x))));
quote(f(1-x))

funargs_to_quote を用いて既存の quote の子供を置き換えて 新しい quote をつくり出せる.

[1184] R=quote_to_funargs(quote(a+(b+c)));
[0,<...quoted...>,<...quoted...>,<...quoted...>]
[1185] T=quote_to_funargs(quote(1+2));
[0,<...quoted...>,<...quoted...>,<...quoted...>]
[1186] funargs_to_quote([0,R[1],R[2],T[2]]);
quote(a+1)
参照

@ref{quotetolist}

ChangeLog


[ << ] [ < ] [] [ > ] [ >> ]         [冒頭] [目次] [見出し] [ ? ]

2.1.5 eval_quote

eval_quote(Q);

:: quote 型データ Q を asir のオブジェクトに変換する.

return

オブジェクト

Q

quote型

ctrl("print_quote",2);
A=quote((x-1)^2+(x-1)+3);
     出力: ((((x)-(1))^(2))+((x)-(1)))+(3)
eval_quote(A);
     出力: x^2-x+3
print_input_form(A);     /* asir-contrib */
     出力: quote((x-1)^2+(x-1)+3)
参照

objtoquote, @ref{quotetolist}, @ref{eval_string}, @ref{quote_to_funargs}, @ref{funargs_to_quote}

ChangeLog


[ << ] [ < ] [] [ > ] [ >> ]         [冒頭] [目次] [見出し] [ ? ]

2.1.6 nqt_match

nqt_match(Expr,Pattern[,Mode])

:: ExprPattern にマッチ(適合)すると 1 を戻す. しないと 0 を戻す.

return

整数

Expr

quote型

Pattern

quote型

Mode

整数

ctrl("print_quote",2);
A=quote((x-y)*(x+y));
nqt_match(A,quote(P*Q));
[P,Q]
    出力:  [x-y, x+y]
nqt_match(A,quote(P*Q),1);
    マッチしない.
nqt_match(A,quote(P*Q),2);
    マッチしない.
qt_normalize(A,1);
    出力:  ((x)^(2))+((x)*(y))+((-1)*((y)^(2)))+((-1)*(y)*(x))
qt_normalize(A,2);
    出力:  ((x)*(x))+((x)*(y))+((-1)*(y)*(x))+((-1)*(y)*(y))
参照

nqt_match_rewrite, qt_rewrite

ChangeLog


[ << ] [ < ] [] [ > ] [ >> ]         [冒頭] [目次] [見出し] [ ? ]

2.1.7 nqt_match_rewrite

nqt_match_rewrite(Expr,Rule,Mode)

:: ExprRule に従い書き換える.

return

quote型

Expr

quote型

Rule

[Pattern,Action] かまたは [Pattern,Condition,Action]. これらの要素はすべて quote型.

Mode

整数

ctrl("print_quote",2);
nqt_match_rewrite(`x*y*z,[`X*Y,`X+Y],1);
   出力: (x)+((y)*(z))
A=`x*x;
nqt_match_rewrite(A,[`X*Y,`X+Y],1);
   出力: x^2   (マッチしていない)
nqt_match_rewrite(A,[`X*Y,`X+Y],2);
   出力: 2*x

適合についてのモードの違いを理解するために次の例および fnode標準形(qt_normalize) を参照.
quotetolist(qt_normalize(`x*x,0));
    出力:  [b_op,^,[internal,x],[internal,2]]
quotetolist(qt_normalize(`x*x,1));
    出力:  [b_op,^,[internal,x],[internal,2]]
quotetolist(qt_normalize(`x*x,2));
    出力:  [n_op,*,[internal,x],[internal,x]]
参照

nqt_match, qt_rewrite, qt_normalize

ChangeLog


[ << ] [ < ] [] [ > ] [ >> ]         [冒頭] [目次] [見出し] [ ? ]

2.1.8 qt_normalize

qt_normalize(Expr[,Mode])

:: Expr を fnode標準形に変換する. Modeにより標準形への展開アルゴリズムを指定できる.

return

quote型

Expr

quote型

Mode

整数

fnodeは quote型の実体である. fnode は木であり, 型 id および子供からなる. 型および子供を取り出す関数が funargs_to_quote である. また fnode をリストに変換する関数が quotetolist である.

fnode の標準形はパターンマッチング, 書き換えを容易におこなうために導入された. fnode の標準形を fn と書くとき, 標準形の BNF風表現での定義は以下のとおり.

 fn           = formula | functor(nf [,...]) | sum_of_monom
     fnode の標準形.  functor は関数よびだしみたいなもの.
 sum_of_monom = monom [+ ...]
     モノミアルの和
 monom        = [formula *] nfpow [* ...]
     モノミアル
 nfpow        = nf | nf^(nf)
     冪乗部分の標準形
 formula      = Risa object

Mode の違いについては以下の例も参考に.

ctrl("print_quote",2);
A=quote((x-y)*(x+y));
   出力:  ((x)-(y))*((x)+(y))
B=qt_normalize(A,0);
   出力: ((x)+((-1)*(y)))*((x)+(y))  Mode=0. 展開はされない. +, * は n_op (nary-op) へ.
quotetolist(B);
   出力: [n_op,*,[n_op,+,[internal,x],[n_op,*,[internal,-1],[internal,y]]],[n_op,+,[internal,x],[internal,y]]]

B=qt_normalize(A,1);
   出力: ((x)^(2))+((x)*(y))+((-1)*((y)^(2)))+((-1)*(y)*(x))
           Mode=1. 展開する. +, * は n_op (nary-op) へ. 巾をまとめる.
quotetolist(B);
   出力: [n_op,+,[b_op,^,[internal,x],[internal,2]],[n_op,*,[internal,x],[internal,y]],[n_op,*,[internal,-1],[b_op,^,[internal,y],[internal,2]]],[n_op,*,[internal,-1],[internal,y],[internal,x]]]

qt_normalize(A,2);
   出力: ((x)*(x))+((x)*(y))+((-1)*(y)*(x))+((-1)*(y)*(y))
           Mode=2. 展開する. +, * は n_op (nary-op) へ. 巾は使わない.
quotetolist(B);
   出力: [n_op,+,[b_op,^,[internal,x],[internal,2]],[n_op,*,[internal,x],[internal,y]],[n_op,*,[internal,-1],[b_op,^,[internal,y],[internal,2]]],[n_op,*,[internal,-1],[internal,y],[internal,x]]]

qt_normalize(`x^2,2);
   出力: (x)*(x)
       Mode=2. 巾は使わない. n-ary の * へ.
参照

nqt_match, nqt_match_rewrite, @ref{quotetolist}, @ref{quote_to_funargs}

ChangeLog


[ << ] [ < ] [] [ > ] [ >> ]         [冒頭] [目次] [見出し] [ ? ]

2.1.9 qt_set_coef

qt_set_coef(ParamList)

:: 以下 ParamList に現れる多項式変数を変数とする有理関数体を係数とする 非可換多項式を扱う.

return

リスト

ParamList

リスト

ctrl("print_quote",2);
qt_set_coef([a]);
B=qt_normalize(quote((a*x+a)^2),2);
     出力: ((a^2)*(x)*(x))+((2*a^2)*(x))+(a^2)
qt_normalize(B+B,2);
     出力: ((2*a^2)*(x)*(x))+((4*a^2)*(x))+(2*a^2)
参照

qt_normalize

ChangeLog


[ << ] [ < ] [] [ > ] [ >> ]         [冒頭] [目次] [見出し] [ ? ]

2.1.10 qt_set_ord

qt_set_ord(VarList)

:: VarList を変数順序とする.

return

リスト

VarList

リスト

ctrl("print_quote",2);
qt_normalize(quote(x+y),2);
     出力: (x)+(y)
qt_set_ord([y,x]);
     出力: [y,x,z,u,v,w,p,q,r,s,t,a,b,c,d,e,f,g, 以下省略 ]
qt_normalize(quote(x+y),2);
     出力: (y)+(x)
参照

qt_normalize, nqt_comp

ChangeLog


[ << ] [ < ] [] [ > ] [ >> ]         [冒頭] [目次] [見出し] [ ? ]

2.1.11 qt_set_weight

qt_set_weight(WeightVector)

:: 変数について weight ベクトルを設定する.

return

リスト

WeightVector

リスト

fnode f の weight w(f) は次の式で計算する.

 f が葉の場合は原則 0. qt_weight_vector で weight が与えられている不定元に
 ついてはその値.

 f がnodeの場合は次の規則で再帰的にきめる.
   w(f+g) = max(w(f),w(g))
   w(f g) = w(f) + w(g)
   w(f^n) = n w(f)
   関数については? -----まだ書いてない.
ctrl("print_quote",2);
qt_set_weight([[x,-1],[y,-1]]);
     結果: [[x,-1],[y,-1]]
qt_normalize(quote( 1+(x+y)+(x+y)^2),1);
     結果: (1)+(y)+(x)+((y)^(2))+((y)*(x))+((x)^(2))+((x)*(y))
参照

qt_normalize, qt_set_ord, qt_set_weight, dp_gr_main

ChangeLog


[ << ] [ < ] [] [ > ] [ >> ]         [冒頭] [目次] [見出し] [ ? ]

2.1.12 nqt_comp

nqt_cmp(Expr1,Exprt2)

:: Expr1Expr2 の順序を比較する.

return

整数

Expr1, Expr2

quote型

ctrl("print_quote",2);
qt_set_ord([y,x]); qt_set_weight([[x,-1],[y,-1]]);
[nqt_comp(`x,`y), nqt_comp(`y,`x), nqt_comp(`x,`x)];
     出力: [-1,1,0]
参照

qt_normalize, qt_set_ord, qt_set_weight

ChangeLog


[ << ] [ < ] [] [ > ] [ >> ]         [冒頭] [目次] [見出し] [ ? ]

2.1.13 qt_is_var, qt_is_coef

qt_is_var(Expr)

:: Expr が不定元に対応する quote なら 1 を戻す.

qt_is_coef(Expr)

:: Expr が係数の有理関数体に属するとき 1 を戻す.

return

整数

Expr

quote型

[qt_is_var(quote(x)), qt_is_var(quote(3/2))];
     出力: [1,0]
参照

qt_rewrite, nqt_match_rewrite

ChangeLog


[ << ] [ < ] [] [ > ] [ >> ]         [冒頭] [目次] [見出し] [ ? ]

2.1.14 qt_rewrite

qt_rewrite(Expr,Rules,Mode)

:: Expr を規則集合 Rules を用いて書き換える.

return

quote型

Expr

quote型

Rules

リスト

Mode

整数

注意: 数学的には X*Y=Y*X が可換性を与える規則だが, これをそのまま規則として 与えると書き換えが停止しない. 次の例では, 上の例のように順序比較し, たとえば, 順序が大きくなる場合のみに書き換えるべきである.

import("noro_rewrite.rr");
R=[[`X*Y,`nqt_comp(Y*X,X*Y)>0, `Y*X]];
qt_rewrite(`(x-y)^2,R,2);
     出力: quote(x*x+-2*x*y+y*y)

外積代数の計算 (asir-contrib をロードした状態).

import("noro_rewrite.rr");
Rext0=[quote(X*Y),quote(qt_is_var(X) && qt_is_var(Y) && nqt_comp(Y,X)>0),
                  quote(-Y*X)];
Rext1=[quote(X^N),quote(eval_quote(N)>=2),quote(0)];
Rext2=[quote(X*X),quote(0)];
Rext=[Rext0,Rext1,Rext2];
qt_rewrite(quote( (x+2*y)*(x+4*y) ), Rext,1);
     出力: 2*x*y

qt_set_coef([a,b,c,d]);
qt_rewrite(quote((a*x+b*y)*(c*x+d*y)), Rext,1);
     出力: (d*a-c*b)*x*y

微分の計算 (asir-contrib をロードした状態).

import("noro_rewrite.rr");
qt_set_coef([a,b]);
Rd1=[`d(X+Y), `d(X)+d(Y)];
Rd2=[`d(X*Y),`d(X)*Y+X*d(Y)];
Rd3=[`d(N), `qt_is_coef(N), `0];
Rd4=[`d(x),`1];
Rd=[Rd1,Rd2,Rd3,Rd4];
B=qt_rewrite( `d( (a*x+b)^3),Rd,2);
     出力: quote(3*a^3*x*x+6*b*a^2*x+3*b^2*a)
fctr(eval_quote(B));
     出力: [[3,1],[a,1],[a*x+b,2]]
参照

nqt_match, nqt_match_rewrite, qt_normalize

ChangeLog


[ << ] [ < ] [] [ > ] [ >> ]

この文書は3月 29, 2024texi2html 5.0を用いて生成されました。