- added an example for evalm()
- removed ncpow()
@example
> lsolve(a+x*y==z,x);
y^(-1)*(z-a);
@example
> lsolve(a+x*y==z,x);
y^(-1)*(z-a);
-> lsolve([3*x+5*y == 7, -2*x+10*y == -5], [x, y]);
-[x==19/8,y==-1/40]
-> M = [[ [[1, 3]], [[-3, 2]] ]];
-[[ [[1,3]], [[-3,2]] ]]
+> lsolve(@{3*x+5*y == 7, -2*x+10*y == -5@}, @{x, y@});
+@{x==19/8,y==-1/40@}
+> M = [ [1, 3], [-3, 2] ];
+[[1,3],[-3,2]]
> determinant(M);
11
> charpoly(M,lambda);
lambda^2-3*lambda+11
> determinant(M);
11
> charpoly(M,lambda);
lambda^2-3*lambda+11
+> A = [ [1, 1], [2, -1] ];
+[[1,1],[2,-1]]
+> A+2*M;
+[[1,1],[2,-1]]+2*[[1,3],[-3,2]]
+> evalm(");
+[[3,7],[-4,3]]
@end example
Multivariate polynomials and rational functions may be expanded,
@end example
Multivariate polynomials and rational functions may be expanded,
@dots{}
@item @code{pseries} @tab Power Series, e.g. @math{x-1/6*x^3+1/120*x^5+O(x^7)}
@item @code{function} @tab A symbolic function like @math{sin(2*x)}
@dots{}
@item @code{pseries} @tab Power Series, e.g. @math{x-1/6*x^3+1/120*x^5+O(x^7)}
@item @code{function} @tab A symbolic function like @math{sin(2*x)}
-@item @code{lst} @tab Lists of expressions [@math{x}, @math{2*y}, @math{3+z}]
+@item @code{lst} @tab Lists of expressions @{@math{x}, @math{2*y}, @math{3+z}@}
@item @code{matrix} @tab @math{n}x@math{m} matrices of expressions
@item @code{relational} @tab A relation like the identity @math{x}@code{==}@math{y}
@item @code{indexed} @tab Indexed object like @math{A_ij}
@item @code{matrix} @tab @math{n}x@math{m} matrices of expressions
@item @code{relational} @tab A relation like the identity @math{x}@code{==}@math{y}
@item @code{indexed} @tab Indexed object like @math{A_ij}
- l.append(4*x); // l is now [x, 2, y, x+y, 4*x]
- l.prepend(0); // l is now [0, x, 2, y, x+y, 4*x]
+ l.append(4*x); // l is now @{x, 2, y, x+y, 4*x@}
+ l.prepend(0); // l is now @{0, x, 2, y, x+y, 4*x@}
-The matrix representation of the spinor metric is @code{[[ [[ 0, 1 ]], [[ -1, 0 ]] ]]}.
+The matrix representation of the spinor metric is @code{[[0, 1], [-1, 0]]}.
@cindex @code{epsilon_tensor()}
@cindex @code{lorentz_eps()}
@cindex @code{epsilon_tensor()}
@cindex @code{lorentz_eps()}
ex e = indexed(A, i, j) * indexed(X, j);
cout << e.simplify_indexed() << endl;
ex e = indexed(A, i, j) * indexed(X, j);
cout << e.simplify_indexed() << endl;
- // -> [[ [[2*y+x]], [[4*y+3*x]] ]].i
+ // -> [[2*y+x],[4*y+3*x]].i
e = indexed(A, i, j) * indexed(X, i) + indexed(X, j) * 2;
cout << e.simplify_indexed() << endl;
e = indexed(A, i, j) * indexed(X, i) + indexed(X, j) * 2;
cout << e.simplify_indexed() << endl;
- // -> [[ [[3*y+3*x,6*y+2*x]] ]].j
+ // -> [[3*y+3*x,6*y+2*x]].j
but it's the same for any two objects with the same label. This is also true
for color objects.
but it's the same for any two objects with the same label. This is also true
for color objects.
-As a last note, powers of non-commutative objects are not allowed in GiNaC.
-You can use the function
-
-@example
-ex ncpow(const ex & basis, unsigned exponent)
-@end example
-
-instead which returns an expanded product (e.g. @code{ncpow(a*b, 2)} becomes
+As a last note, positive integer powers of non-commutative objects are
+automatically expanded in GiNaC. For example, @code{pow(a*b, 2)} becomes
@samp{a*b*a*b} if @samp{a} and @samp{b} are non-commutative expressions).
@samp{a*b*a*b} if @samp{a} and @samp{b} are non-commutative expressions).
@example
> match((x+y)^a,(x+y)^a);
@example
> match((x+y)^a,(x+y)^a);
> match((x+y)^a,(x+y)^b);
FAIL
> match((x+y)^a,$1^$2);
> match((x+y)^a,(x+y)^b);
FAIL
> match((x+y)^a,$1^$2);
> match((x+y)^a,$1^$1);
FAIL
> match((x+y)^(x+y),$1^$1);
> match((x+y)^a,$1^$1);
FAIL
> match((x+y)^(x+y),$1^$1);
> match((x+y)^(x+y),$1^$2);
> match((x+y)^(x+y),$1^$2);
> match((a+b)*(a+c),($1+b)*($1+c));
> match((a+b)*(a+c),($1+b)*($1+c));
> match((a+b)*(a+c),(a+$1)*(a+$2));
> match((a+b)*(a+c),(a+$1)*(a+$2));
(Unpredictable. The result might also be [$1==c,$2==b].)
> match((a+b)*(a+c),($1+$2)*($1+$3));
(The result is undefined. Due to the sequential nature of the algorithm
and the re-ordering of terms in GiNaC, the match for the first factor
(Unpredictable. The result might also be [$1==c,$2==b].)
> match((a+b)*(a+c),($1+$2)*($1+$3));
(The result is undefined. Due to the sequential nature of the algorithm
and the re-ordering of terms in GiNaC, the match for the first factor
- may be [$1==a,$2==b] in which case the match for the second factor
- succeeds, or it may be [$1==b,$2==a] which causes the second match to
+ may be @{$1==a,$2==b@} in which case the match for the second factor
+ succeeds, or it may be @{$1==b,$2==a@} which causes the second match to
fail.)
> match(a*(x+y)+a*z+b,a*$1+$2);
fail.)
> match(a*(x+y)+a*z+b,a*$1+$2);
- (This is also ambiguous and may return either [$1==z,$2==a*(x+y)+b] or
- [$1=x+y,$2=a*z+b].)
+ (This is also ambiguous and may return either @{$1==z,$2==a*(x+y)+b@} or
+ @{$1=x+y,$2=a*z+b@}.)
> match(a+b+c+d+e+f,c);
FAIL
> match(a+b+c+d+e+f,c+$0);
> match(a+b+c+d+e+f,c);
FAIL
> match(a+b+c+d+e+f,c+$0);
> match(a+b+c+d+e+f,c+e+$0);
> match(a+b+c+d+e+f,c+e+$0);
> match(a*b^2,a^$1*b^$2);
FAIL
(The matching is syntactic, not algebraic, and "a" doesn't match "a^$1"
even if a==a^1.)
> match(x*atan2(x,x^2),$0*atan2($0,$0^2));
> match(a*b^2,a^$1*b^$2);
FAIL
(The matching is syntactic, not algebraic, and "a" doesn't match "a^$1"
even if a==a^1.)
> match(x*atan2(x,x^2),$0*atan2($0,$0^2));
> match(atan2(y,x^2),atan2(y,$0));
> match(atan2(y,x^2),atan2(y,$0));
@end example
@cindex @code{has()}
@end example
@cindex @code{has()}
cout << indexed(A, i, j, k).antisymmetrize(lst(i, j)) << endl;
// -> -1/2*A.j.i.k+1/2*A.i.j.k
cout << lst(a, b, c).symmetrize(lst(a, b, c)) << endl;
cout << indexed(A, i, j, k).antisymmetrize(lst(i, j)) << endl;
// -> -1/2*A.j.i.k+1/2*A.i.j.k
cout << lst(a, b, c).symmetrize(lst(a, b, c)) << endl;
- // -> 1/6*[a,b,c]+1/6*[c,a,b]+1/6*[b,a,c]+1/6*[c,b,a]+1/6*[b,c,a]+1/6*[a,c,b]
+ // -> 1/6*@{a,b,c@}+1/6*@{c,a,b@}+1/6*@{b,a,c@}+1/6*@{c,b,a@}+1/6*@{b,c,a@}+1/6*@{a,c,b@}