The Domains Package
This example worksheet demonstrates commands from the Domains package. The Domains package can be used to create domains of computation and then develop code for complicated algorithms.
restart
with⁡Domains:
---------------------- Domains version 1.0 --------------------- Initially defined domains are Z and Q the integers and rationals Abbreviations, e.g. DUP for DenseUnivariatePolynomial, also made
Basic Examples Using Domains Z and Q
The domains Z (the integers) and Q (the rationals) have been defined. Let's do some operations.
ZGcd8,12
4
Q`+`12,13,14
1312
What are the objects Z and Q? Z and Q are Maple tables
type⁡Z,table
true
The table contains operations (Maple procedures) for computing in Z and Q. What operations are available?
show⁡Z,operations
` Signatures for constructor Z` ` note: operations prefixed by -- are not available` ` * : (Z,Z*) -> Z` ` * : (Integers,Z) -> Z` ` + : (Z,Z*) -> Z` ` - : Z -> Z` ` - : (Z,Z) -> Z` ` 0 : Z` ` 1 : Z` ` < : (Z,Z) -> Boolean` ` <= : (Z,Z) -> Boolean` ` <> : (Z,Z) -> Boolean` ` = : (Z,Z) -> Boolean` ` > : (Z,Z) -> Boolean` ` >= : (Z,Z) -> Boolean` ` Abs : Z -> Z` ` Characteristic : Integers` ` Coerce : Integers -> Z` ` Div : (Z,Z) -> Union(Z,FAIL)` ` EuclideanNorm : Z -> Integers` ` Factor : Z -> [Z,[[Z,Integers]*]]` ` Gcd : Z* -> Z` ` Gcdex : (Z,Z,Name) -> Z` ` Gcdex : (Z,Z,Name,Name) -> Z` ` Input : Expression -> Union(Z,FAIL)` ` Inv : Z -> Union(Z,FAIL)` ` Lcm : Z* -> Z` ` Max : (Z,Z*) -> Z` ` Min : (Z,Z*) -> Z` ` Modp : (Z,Z) -> Z` ` Mods : (Z,Z) -> Z` ` ModularHomomorphism : () -> (Z -> Z,Z)` ` Normal : Z -> Z` ` Output : Z -> Expression` ` Powmod : (Z,Integers,Z) -> Z` ` Prime : Z -> Boolean` ` Quo : (Z,Z) -> Z` ` Quo : (Z,Z,Name) -> Z` ` Random : () -> Z` ` RelativelyPrime : (Z,Z) -> Boolean` ` Rem : (Z,Z) -> Z` ` Rem : (Z,Z,Name) -> Z` ` Sign : Z -> UNION(1,-1,0)` ` SmallerEuclideanNorm : (Z,Z) -> Boolean` ` Sqrfree : Z -> [Z,[[Z,Integers]*]]` ` Type : Expression -> Boolean` ` Unit : Z -> Z` ` UnitNormal : Z -> [Z,Z,Z]` ` Zero : Z -> Boolean` ` ^ : (Z,Integers) -> Z`
Creating Domains
Let's do some operations in Q[x], i.e. univariate polynomials over Q. First we have to create the domain Q[x]; let's call it C.
C:=DenseUnivariatePolynomial⁡Q,x:
The name DenseUnivariatePolynomial indicates that the data structure being used is a dense one. Let's input a polynomial.
m:=CInput⁡x4−10 x2+1
m:=x4−10⁢x2+1
What can we do with the polynomial m?
CDegreem # compute its degree
C`^`m,2 # square it
1−20⁢x2+102⁢x4−20⁢x6+x8
What other operations are there for univariate polynomials? A list of the operations is given by show(C,operations);
a:=C[Random]⁡
a:=−9487+2831⁢x−25⁢x2
Every Domains domain has a Random function which returns a randomly generated element from a domain, which is useful for writing documentation examples! Domains can also compute with matrices and other objects. Let's compute the inverse of a 3 by 3 Hilbert matrix using Domains. First, we must create the matrix domain.
M:=SquareMatrix3,Q:
A≔MInput1,12,13,12,13,14,13,14,15
A:=1,12,13,12,13,14,13,14,15
M[Det]⁡A
12160
M[Inv]⁡A
9,−36,30,−36,192,−180,30,−180,180
Let's now compute with matrices of polynomials in Q[x]. Let's use 2 by 2 matrices to keep the examples small.
M:=SquareMatrix⁡2,C:
A≔MInputx,x2,1− x2,1+x2
A:=x,x2,1−x2,1+x2
MDetA #Compute det(A)
x−x2+x3+x4
MInvA #Compute A−1
Error, (in Domains:-notImplemented) operation is not implemented
That's right, you can't compute the inverse of a matrix of polynomials, because the result is in general a rational function. Now let us demonstrate the power of Domains by doing the same Matrix problems with a Matrix of different entries, this time algebraic numbers. For example, suppose we want to compute with the roots of the polynomial m=x4−10 x2 +1. In Maple one uses the RootOf function as follows
aliasα=RootOf⁡x4−10⁢x2+1=0,x:
simplify⁡1α
−α⁢α2−10
In Domains, we will create a simple algebraic extension using the polynomial m as the minimal polynomial thus
F≔SAEC,m:
a≔FInputx
a:=x
ai≔FInva
ai:=10⁢x−x3
Domains generalizes very naturally to compute over F
M:=SquareMatrix⁡2,F:
A:=M[Input]⁡1,x,x3,x2
A:=1,x,x3,x2
1−9⁢x2
98−18⁢x2,−898⁢x+98⁢x3,−98⁢x+18⁢x3,898−98⁢x2
Examples with Univariate Power Series
For our last examples, some calculations with univariate power series. First let's create a univariate power series domain in x over Q.
PS:=LazyUnivariatePowerSeries⁡Q,x:showPS,operations
` Signatures for constructor PS` ` note: operations prefixed by -- are not available` ` * : (PS,PS*) -> PS` ` * : (Integers,PS) -> PS` ` + : (PS,PS*) -> PS` ` - : PS -> PS` ` - : (PS,PS) -> PS` ` / : (PS,PS) -> PS` ` / : (PS,Integers) -> PS` ` 0 : PS` ` 1 : PS` ` <> : (PS,PS) -> Boolean` ` = : (PS,PS) -> Boolean` ` -- AbsoluteDegree : Integers` ` Characteristic : Integers` ` Coeff : (PS,Integers) -> Q` ` CoefficientRing : Ring` ` Coerce : Integers -> PS` ` Constant : Q -> PS` ` Cos : PS -> Union(PS,FAIL)` ` Cosh : PS -> Union(PS,FAIL)` ` Diff : PS -> PS` ` Div : (PS,PS) -> Union(PS,FAIL)` ` EuclideanNorm : PS -> Integers` ` Exp : PS -> Union(PS,FAIL)` ` Factor : PS -> [PS,[[PS,Integers]*]]` ` Gcd : PS* -> PS` ` Gcdex : (PS,PS,Name) -> PS` ` Gcdex : (PS,PS,Name,Name) -> PS` ` Input : Expression -> Union(PS,FAIL)` ` Integrate : PS -> Union(PS,FAIL)` ` Inv : PS -> PS` ` Lcm : PS* -> PS` ` Ln : PS -> Union(PS,FAIL)` ` Log : PS -> Union(PS,FAIL)` ` Lorder : PS -> Integers` ` Monomial : () -> PS` ` Monomial : Integers -> PS` ` Normal : PS -> PS` ` Output : PS -> Expression` ` Powmod : (PS,Integers,PS) -> PS` ` Prime : PS -> Boolean` ` Quo : (PS,PS) -> PS` ` Quo : (PS,PS,Name) -> PS` ` R* : (Q,PS) -> PS` ` R/ : (PS,Q) -> PS` ` Random : () -> PS` ` RelativelyPrime : (PS,PS) -> Boolean` ` Rem : (PS,PS) -> PS` ` Rem : (PS,PS,Name) -> PS` ` Series : [[Q,Integers]] -> PS` ` Shift : (PS,Integers) -> PS` ` Sin : PS -> Union(PS,FAIL)` ` Sinh : PS -> Union(PS,FAIL)` ` SmallerEuclideanNorm : (PS,PS) -> Boolean` ` Sqrfree : PS -> [PS,[[PS,Integers]*]]` ` Tan : PS -> Union(PS,FAIL)` ` Tanh : PS -> Union(PS,FAIL)` ` Type : Expression -> Boolean` ` Unit : PS -> PS` ` UnitNormal : PS -> [PS,PS,PS]` ` Variable : Name` ` ^ : (PS,PS) -> PS` ` ^ : (PS,Integers) -> PS` ` ^ : (PS,Rationals) -> PS` ` order : PS -> Integers`
Let's compute the series for ex.
a:=PS[Input]⁡x
e:=PS[Exp]⁡a
e:=1+x+12⁢x2+16⁢x3+124⁢x4+1120⁢x5+O⁡x6
PS[`^`]⁡e,3
1+3⁢x+92⁢x2+92⁢x3+278⁢x4+8140⁢x5+O⁡x6
Lazy univariate power series are "lazy" which means coefficients are computed on demand; that is, we can compute a series to higher order without having to recompute any previously computed coefficients.
PS[Output]⁡e,10
1+x+12⁢x2+16⁢x3+124⁢x4+1120⁢x5+1720⁢x6+15040⁢x7+140320⁢x8+1362880⁢x9+13628800⁢x10+O⁡x11
Here are the Legendre polynomials computed from their generating function:
11−2 x t+t2=∑kLnx⋅tk
First create the domain: LUPS == LazyUnivariatePowerSeries
P≔LUPSLUPS⁡Q,x,t:p≔PInput1−2⁢x⁢t+t2
p:=1−2⁢x⁢t+t2
P[`^`]⁡p,−12
1+x⁢t+−12+32⁢x2⁢t2+−32⁢x+52⁢x3⁢t3+38−154⁢x2+358⁢x4⁢t4+158⁢x−354⁢x3+638⁢x5⁢t5+O⁡t6
Compare the output from Domains with that from Maple
seq⁡orthopoly[P]⁡i,x,i=0..5
1,x,−12+32⁢x2,−32⁢x+52⁢x3,38−154⁢x2+358⁢x4,158⁢x−354⁢x3+638⁢x5
See Also
Domains
Return to Index for Example Worksheets
Download Help Document