Maple 9 の改良されたパッケージ: Part 1
|
CodeGeneration
|
|
CodeGeneration パッケージに、多くの改良が行われました。新しいエクスポートでは、Maple コードをVisual Basic(R) や MATLAB(R) 言語に変換したり、ユーザが現在の変換機能を拡張することができます。現在、トランスレータは、式、計算のシークエンス、プロシージャに加えて、モジュールを入力として受け取ります。これらの新機能について、効率に関する他の改良、Maple 言語のカバレージ、出力の質とともに、以下に述べます。
Warning, the protected name Matlab has been redefined and
unprotected
| (1.1) |
|
新たな言語への変換
|
|
•
|
2 つの新しいエクスポート、Matlab と VisualBasic は、それぞれ、 MATLAB と Visual Basic への変換を行います。つぎの例は、計算のシークエンスとプロシージャの変換を示します。
|
>
|
x := 'x': s := 's': t := 't': r := 'r':
cs := [s=1.0+x, t=ln(s)*exp(-x), r=exp(-x)+x*t]:
Matlab(cs);
|
s = 0.10e1 + x;
t = log(s) * exp(-x);
r = exp(-x) + x * t;
| |
>
|
f := proc(x, y) local a; if x < 1.0 then a := cos(y) else a := sin(y) end if; return 2*a; end proc:
VisualBasic(f);
|
Imports System.Math
Public Module CodeGenerationModule
Public Function f(ByVal x As Double, ByVal y As Double) As Double
Dim a As Double
If (x < 0.10E1) Then
a = Cos(y)
Else
a = Sin(y)
End If
Return 0.2E1 * a
End Function
End Module
| |
|
|
ユーザ定義の変換
|
|
•
|
CodeGeneration パッケージの変換機能は、現在、新しい CodeGeneration[LanguageDefinition] サブモジュールを使用して拡張されます。CodeGeneration トランスレータは、あらかじめ定義されたランゲージ定義モジュール、パッケージがサポートする各ターゲット言語のモジュールを使用します。LanguageDefinition サブモジュールには、既存の定義モジュールに指定された変換の重ね処理による消去や追加、あるいは、全く新しい言語の定義モジュールを指定できるエクスポートがあります。その後、コマンド Translate は、新しい定義を使用して変換に使用されます。
|
ここでは、ANSI C を拡張する言語を定義し、`my_function' という名前の Maple プロシージャの変換を `my_function_equivalent' と定義します。
>
|
LanguageDefinition:-Define( "SomeNewLanguage", extend="C",
AddFunction("my_function", [numeric]::numeric, "my_function_equivalent")
):
Translate( my_function(csc(x)+sin(x)), language="SomeNewLanguage" );
|
cg = my_function_equivalent(0.1e1 / sin(x) + sin(x));
| |
|
|
Maple 言語のカバレージの改良
|
|
>
|
m := module()
local g;
export f;
g := proc(x) cos(x)+sin(x) end proc:
f := proc(y) if y>=0.0 and y<=2.0*Pi then g(y) else 0.0 end if end proc:
end module:
Java(m);
|
import java.lang.Math;
class m {
public static double f (double y)
{
if (0.0e0 <= y && y <= 0.20e1 * Math.PI)
return(g(y));
else
return(0.0e0);
}
private static double g (double x)
{
return(Math.cos(x) + Math.sin(x));
}
}
| |
•
|
Maple try ステートメントは、現在、CodeGeneration により認識され、そのようなステートメントが存在するサポート言語の等価なステートメントに変換されます。
|
>
|
tproc := proc(a, b)
try
a/b;
catch:
printf("An error %s occurred.\n", lasterror);
end try;
end proc:
Java(tproc);
|
class CodeGenerationClass {
public static double tproc (double a, double b) throws Exception;
{
try {
return(a / b);
} catch (Exception except) {
System.out.println("An error " + except.getMessage() + " occurred.");
}
}
}
| |
•
|
トランスレータは、より多くの Maple コンストラクトが、それらを変換することができなくても、Maple コンストラクトを受け取ります。たとえば、Maple 8 では、認識されないコンテキストに見つけられたリストは、エラーを出します。現在、そのようなリストは、変更不可と変換され、ワーニングが表示されます。これらの状況では、出力は多くの場合、正しくありませんが、ユーザには、必要に応じてそれを修正する場合があります。
|
|
|
新規オプション
|
|
•
|
Maple 入力コードの解析をコントロールするために、2 つのオプション deducereturn と reduceanalysis があります。
|
•
|
プロシージャが入力として提供される場合、 任意のインプリシット出力 (implicit returns) を解釈し、それらをエクスプリシット出力 (explicit returns) に変換します。 しかし、deducereturn=false オプションが指定される場合、エクスプリシット出力へ変換せず、任意のインプリシット出力になるMaple コードは、変更不可と変換されます。 以下に例を示します。最初のコールは、デフォルトの動作を示します。一方、2 番目の動作は、deducereturn=false オプションの効果を示します。
|
>
|
f := proc(x) local y; y := x+10; end proc:
C(f);
|
int f (int x)
{
int y;
y = x + 10;
return(y);
}
| |
>
|
C(f, deducereturn=false);
|
void f (int x)
{
int y;
y = x + 10;
}
| |
•
|
方程式のリストとして指定される計算シークエンスが入力として与えられる場合、普通シークエンス全体が解析され、その結果、1 つの代入を解析する間に集められた型の情報は、つぎの代入での解析に適用されます。これに対し、オプション reduceanalysis=true は、計算のシークエンスが、 各時間に1つの代入が解析されるように指定します。このオプションを使用すると、変換に必要な時間とメモリを大幅に減らすことができますが、 ターゲットコードが代入の型に矛盾を含む可能性があります。
|
|
|
その他
|
|
•
|
Maple 8 では、インプリシット出力 (implicit returns) の エクスプリシット出力 (explicit returns) への変換は、戻り値をホールドする新しい変数の生成を常に必要とします。 現在、新しい変数は、必要な場合にのみ生成され、多くの場合、よりコンパクトな出力になります。
|
|
|
|
DEtools
|
|
•
|
DEtools パッケージには、新規関数 DEtools[dperiodic_sols] があります。これは、二重周期係数をもつ線形 ODE の解を検索します。二重周期関数は、Weierstrass form (P と P' の有理式) 、あるいは、Jacobi form (Jacobi 関数の有理式、たとえば、sn, cn, dn) で一般にあらわされます。
|
>
|
alias( P = WeierstrassP(x,g2,g3), Pp = WeierstrassPPrime(x,g2,g3),
sn = JacobiSN(x,k), cn = JacobiCN(x,k), dn = JacobiDN(x,k) ):
ode := diff(y(x),x$2) - (2*P + B)*y(x):
DEtools[dperiodic_sols](ode, y(x) );
|
![[(-P+B)^(1/2)*exp(-(1/2)*(Int(((-4*P^3+g2*P+g3)*(g3-4*B^3+g2*B))^(1/2)*Pp/((-4*P^3+g2*P+g3)*(-P+B)), x))), (-P+B)^(1/2)*exp((1/2)*(Int(((-4*P^3+g2*P+g3)*(g3-4*B^3+g2*B))^(1/2)*Pp/((-4*P^3+g2*P+g3)*(-P+B)), x)))]](/support/helpjp/helpview.aspx?si=2574/file01574/math322.png)
| (2.1) |
>
|
k := 3:
ode := diff(y(x),x$2) + (k^2*sn*cn/dn)*diff(y(x),x) + 9*dn^2*y(x):
DEtools[dperiodic_sols](ode, y(x) );
|
| (2.2) |
>
|
ode := (Pp + (P^2))*diff(y(x),x$2) + ((P)^3-P*Pp-diff(P,x$2))*diff(y(x),x)
+ ((Pp)^2-(P)^2*Pp-P*diff(P,x$2))*y(x):
DEtools[dperiodic_sols](ode, y(x));
|
| (2.3) |
>
|
M := matrix(6,6,[0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,0,2,2*x,0,0,1,0,x^2,0,2*x,0,0,1,0,x^2,-2,0,0,0]);
|
| (2.4) |
>
|
DEtools['matrixDE'](M,x,solution=polynomial);
|
| (2.5) |
|
DEtools[polysols] と DEtools[ratsols] に対して、 微分方程式系は、 第 1 引数で方程式のリスト、第 2 引数で変数のリストをとる、あるいは、第 1 引数で線形 ODE の係数のリストのリストのリスト (a list of lists of lists of coefficients of linear ODEs) 、 第 2 引数でそのような方程式の右辺のリスト、第 3 引数で独立変数をとるかのいずれかとして与えられます。各方程式は、1 変数の LODEs の和として表され、それらの各々は、係数のリストとして与えられます。従って、1 つの方程式は、係数のリストのリスト (a list of lists of coefficients )、リストのリストのシステム (a system as a list of lists of lists) として与えられます。後者のシークエンスは、ルーチンを用いたプログラミングにとって便利です。
|
>
|
sys := [diff(y1(x), x) - y2(x), diff(y2(x), x) - y3(x) - y4(x), diff(y3(x), x) - y5(x),
diff(y4(x), x) - 2*y1(x) - 2*x*y2(x) - y5(x), diff(y5(x), x) - x^2*y1(x) - 2*x*y3(x) - y6(x),
diff(y6(x), x) - x^2*y2(x) + 2*y3(x)];
|
![sys := [diff(y1(x), x)-y2(x), diff(y2(x), x)-y3(x)-y4(x), diff(y3(x), x)-y5(x), diff(y4(x), x)-2*y1(x)-2*x*y2(x)-y5(x), diff(y5(x), x)-x^2*y1(x)-2*x*y3(x)-y6(x), diff(y6(x), x)-x^2*y2(x)+2*y3(x)]](/support/helpjp/helpview.aspx?si=2574/file01574/math398.png)
| (2.6) |
>
|
vars := [y1(x), y2(x), y3(x), y4(x), y5(x), y6(x)];
|
| (2.7) |
>
|
DEtools['polysols'](sys, vars);
|
| (2.8) |
>
|
sysp := [[[0,1],[-1]],[[],[0,1],[-1],[-1]],[[],[],[0,1],[],[-1]],
[[-2],[-2*x],[],[0,1],[-1]],[[-x^2],[],[-2*x],[],[0,1],[-1]],
[[],[-x^2],[2],[],[],[0,1]]];
|
![sysp := [[[0, 1], [-1]], [[], [0, 1], [-1], [-1]], [[], [], [0, 1], [], [-1]], [[-2], [-2*x], [], [0, 1], [-1]], [[-x^2], [], [-2*x], [], [0, 1], [-1]], [[], [-x^2], [2], [], [], [0, 1]]]](/support/helpjp/helpview.aspx?si=2574/file01574/math421.png)
| (2.9) |
>
|
DEtools['polysols'](sysp, [0,0,0,0,0,0], x);
|
| (2.10) |
|
|
LibraryTools
|
|
•
|
LibraryTools パッケージには、新規ルーチンLibraryTools[Browse] があります。ルーチン LibraryTools[Browse] は、複数のライブラリの操作を簡単にする maplet インタフェースを表示します。ボタンをクリックして、新規ライブラリを作成、ナビゲートし、既存のライブラリのコンテンツを編集することができます。
|
>
|
LibraryTools[Browse]();
|
|
>
|
x := 'x':
sys := [y2(x)*x^2+3*y2(x)*x+2*y2(x)-2*y1(x)*x^2-4*y1(x)*x+y1(x+1)*x^2+y1(x+1)*x,y2(x+1)-y1(x)];
|
| (1) |
>
|
vars := [y1(x), y2(x)];
|
| (2) |
>
|
LREtools['polysols'](sys, vars,{}, 'output'='basis');
|
| (3) |
|
LinearAlgebra
|
|
|
例題
|
|
>
|
with(LinearAlgebra):
M := Matrix([[3,5],[-2,4]]):
MatrixFunction(M,sin(x),x);
|

| (4.1.1) |
>
|
SQ := MatrixFunction(M,x^(1/2),x);
|
| (4.1.2) |
| (4.1.3) |
•
|
浮動小数点システムに対する、スパースな線形反復ソルバの3つの新しいクラスが、ルーチン LinearAlgebra[LinearSolve] から導入されました。これらは、既存の対称的な反復ソルバを補足し、複素エルミート行列、実非対称、複素非エルミート行列の場合をカバーします。
|
|
|
例題
|
|
>
|
with(LinearAlgebra):
M := Matrix([[3,5],[-2,4]],storage=sparse,datatype=float):
b := Vector([1,2],datatype=float):
infolevel[LinearAlgebra]:=3;
|
| (4.2.1) |
>
|
x := LinearSolve(M,b,method=SparseIterative);
|
LinearSolve: "using method" SparseIterative
LinearSolve: "using method " SparseIterative
LinearSolve: "calling external function"
SparseLinearSolve: "using CGS method"
SparseLinearSolve:
"preconditioning with incomplete LU factorization"
SparseLinearSolve: "level of fill = " 0
SparseLinearSolve: "no pivoting applied"
SparseLinearSolve:
"dimension of workspaces for preconditioner = " 16
SparseLinearSolve:
"using infinity norm in stopping criteria"
SparseLinearSolve: "setting maximum iterations to " 200
SparseLinearSolve: "setting tolerance to " .10e-7
SparseLinearSolve: "NAG" hw_f11zaf
SparseLinearSolve: "NAG" hw_f11daf
SparseLinearSolve: "NAG" hw_f11dcf
SparseLinearSolve: "number of iterations" 1
SparseLinearSolve: "residual computed last as" .\
111022302462515654e-14
| (4.2.2) |
MatrixVectorMultiply: "calling external function"
MatrixVectorMultiply: hw_SpMatVecMulRR
VectorScalarMultiply: "calling external function"
VectorScalarMultiply: "NAG" hw_f06edf
VectorAdd: "calling external function"
VectorAdd: "NAG" hw_f06ecf
VectorNorm: "calling external function"
VectorNorm: "NAG: " hw_f06raf
| (4.2.3) |
>
|
infolevel[LinearAlgebra]:=0;
|
| (4.2.4) |
|
|
|
LREtools
|
|
•
|
関数 LREtools[hypergeomsols] は、論文: M. van Hoeij, ``Finite Singularities and Hypergeometric Solutions of Linear Recurrence Equations.'' J. Pure Appl. Algebra, 139, p. 109-131 (1999)に基づき実現します。 このアルゴリズムは、再帰関係の前方 あるいは 後方の 係数が、複雑な根をもつ多項式の場合、十分に高速です。つぎのような例があります。
|
>
|
LREtools[hypergeomsols](u(n+2) = 2*(n^4+4*n^3+6*n^2+5*n+3)*(n^4+n+1)*u(n),
u(n), {}, 'output'='basis');
|
CharacteristicPolynomial: working on determinant of minor
2
| (6.1) |
>
|
x := 'x':
sys := [y2(x)*x^2+3*y2(x)*x+2*y2(x)-2*y1(x)*x^2-4*y1(x)*x+y1(x+1)*x^2+y1(x+1)*x,y2(x+1)-y1(x)];
|
![sys := [x^2*y2(x)+3*x*y2(x)+2*y2(x)-2*x^2*y1(x)-4*y1(x)*x+y1(x+1)*x^2+y1(x+1)*x, y2(x+1)-y1(x)]](/support/helpjp/helpview.aspx?si=2574/file01574/math652.png)
| (6.2) |
>
|
vars := [y1(x), y2(x)];
|
| (6.3) |
>
|
LREtools['polysols'](sys, vars,{}, 'output'='basis');
|
| (6.4) |
>
|
LREtools[IsDesingularizable]((n-2)*(n^3+2)*E+n,E,n,'leading','output'='operator');
|
![true, -1/6+(-(1/6)*(n+2)^3+(4/3)*(n+2)^2-(10/3)*n-5)*E+(-(2/3)*(n+2)^3+(8/3)*(n+2)^2-(8/3)*n-19/3)*E^2+(-(n+2)^3-2)*E^3, []](/support/helpjp/helpview.aspx?si=2574/file01574/math681.png)
| (6.5) |
|
|
Slode
|
|
Slode パッケージには、新規関数 Slode[dAlembertian_formal_sol] があります。これは、多項式係数をもつ斉次線形微分方程式に対する d'Alembertian 級数をもつ形式解を見つけます。
>
|
ode:=(-4-x^2+2*x)*y(x)+(2*x-3*x^3-x^2)*diff(y(x),x)+(x^3-x^4)*diff(y(x),`$`(x,2));
|
| (7.1) |
>
|
Slode[dAlembertian_formal_sol](ode,y(x));
|
![x^2*(-(1/2)*(Sum(x^_n, _n = 0 .. infinity))+Sum((Sum((-1)^_n1*2^(-_n1)*(Product((_k^2+6*_k+9)/(_k+2), _k = 0 .. _n1-1)), _n1 = 0 .. _n-1))*x^_n, _n = 0 .. infinity))*_C[0]+exp(2/x)*(Sum(x^_n, _n = 0 .. infinity)-1/3)*_C[1]/x](/support/helpjp/helpview.aspx?si=2574/file01574/math715.png)
| (7.2) |
>
|
ode:=(x-1)^2*diff(y(x),`$`(x,3))-(x-1)*(x-7)*diff(y(x),`$`(x,2))-2*(2*x-5)*diff(y(x),x)-2*y(x);
|
| (7.3) |
>
|
Slode[dAlembertian_formal_sol](ode,y(x));
|
| (7.4) |
|
|
SNAP
|
|
•
|
SNAP パッケージに、新規関数 QRGCD が追加されました。これは、2 つの一変数多項式の approximate right GCD を計算します。詳細は、SNAP[QRGCD] を参照してください。
|
|
|
SolveTools
|
|
>
|
SolveTools[PolynomialSystem]({x^2+y^2-3,x*y+5},{x,y});
|
| (9.1) |
|
|
参照
|
|
alias, CodeGeneration, DEtools, Maple 9の改良されたパッケージ: Part 2, Maple 9 の新機能インデックス, infolevel, LibraryTools, LinearAlgebra, ListTools, LinearFunctionalSystems[PolynomialSolution], LinearFunctionalSystems[RationalSolution], LREtools[hypergeomsols], LREtools[IsDesingularizable], matrix, Matrix, Maple 9の新規パッケージ, proc, Slode[dAlembertian_formal_sol], SolveTools[PolynomialSystem], SNAP[QRGCD], trademarks, try/catch, Using Packages, Vector, with
|
|