]> www.ginac.de Git - ginac.git/commitdiff
- list delimiters are now { } and matrix delimiters are [ ]
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Fri, 1 Jun 2001 22:50:33 +0000 (22:50 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Fri, 1 Jun 2001 22:50:33 +0000 (22:50 +0000)
- added evalm() function

ginsh/ginsh.1.in
ginsh/ginsh_lexer.ll
ginsh/ginsh_parser.yy

index 39ece405aa08c11a229ad97801d917d69a6bd158..94ef4b709299bb7a7c17b963dd0cc8e42d172d43 100644 (file)
@@ -191,22 +191,20 @@ Lists are used by the
 .B subs
 and
 .B lsolve
 .B subs
 and
 .B lsolve
-functions. A list consists of an opening square bracket
+functions. A list consists of an opening curly brace
+.RB ( { ),
+a (possibly empty) comma-separated sequence of expressions, and a closing curly
+brace
+.RB ( } ).
+.SS MATRICES
+A matrix consists of an opening square bracket
 .RB ( [ ),
 .RB ( [ ),
-a (possibly empty) comma-separated sequence of expressions, and a closing square
-bracket
+a non-empty comma-separated sequence of matrix rows, and a closing square bracket
+.RB ( ] ).
+Each matrix row consists of an opening square bracket
+.RB ( [ ),
+a non-empty comma-separated sequence of expressions, and a closing square bracket
 .RB ( ] ).
 .RB ( ] ).
-.SS MATRICES
-A matrix consists of an opening double square bracket
-.RB ( [[ ),
-a non-empty comma-separated sequence of matrix rows, and a closing double square
-bracket
-.RB ( ]] ).
-Each matrix row consists of an opening double square bracket
-.RB ( [[ ),
-a non-empty comma-separated sequence of expressions, and a closing double square
-bracket
-.RB ( ]] ).
 If the rows of a matrix are not of the same length, the width of the matrix
 becomes that of the longest row and shorter rows are filled up at the end
 with elements of value zero.
 If the rows of a matrix are not of the same length, the width of the matrix
 becomes that of the longest row and shorter rows are filled up at the end
 with elements of value zero.
@@ -272,6 +270,9 @@ detail here. Please refer to the GiNaC documentation.
 .BI evalf( "expression [" ", " level] )
 \- evaluates an expression to a floating point number
 .br
 .BI evalf( "expression [" ", " level] )
 \- evaluates an expression to a floating point number
 .br
+.BI evalm( expression )
+\- evaluates sums and products of matrices
+.br
 .BI expand( expression )
 \- expands an expression
 .br
 .BI expand( expression )
 \- expands an expression
 .br
@@ -440,12 +441,12 @@ x
 (x+1)^(\-2)*(\-x+x^2\-2)
 > series(sin(x),x==0,6);
 1*x+(\-1/6)*x^3+1/120*x^5+Order(x^6)
 (x+1)^(\-2)*(\-x+x^2\-2)
 > series(sin(x),x==0,6);
 1*x+(\-1/6)*x^3+1/120*x^5+Order(x^6)
-> lsolve([3*x+5*y == 7], [x, y]);
-[x==\-5/3*y+7/3,y==y]
-> lsolve([3*x+5*y == 7, \-2*x+10*y == \-5], [x, y]);
-[x==19/8,y==\-1/40]
-> M = [[ [[a, b]], [[c, d]] ]];
-[[ [[\-x+x^2\-2,(x+1)^2]], [[c,d]] ]]
+> lsolve({3*x+5*y == 7}, {x, y});
+{x==\-5/3*y+7/3,y==y}
+> lsolve({3*x+5*y == 7, \-2*x+10*y == \-5}, {x, y});
+{x==19/8,y==\-1/40}
+> M = [ [a, b], [c, d] ];
+[[\-x+x^2\-2,(x+1)^2],[c,d]]
 > determinant(M);
 \-2*d\-2*x*c\-x^2*c\-x*d+x^2*d\-c
 > collect(", x);
 > determinant(M);
 \-2*d\-2*x*c\-x^2*c\-x*d+x^2*d\-c
 > collect(", x);
index a8a2b10e15dc0f4da964eabdfb7fceafd6cda26b..932f80b4dcfb8f83e84c3c109f109246c15559b6 100644 (file)
@@ -89,10 +89,6 @@ score                        return T_SCORE;
 \"\"                   return T_QUOTE2;
 \"\"\"                 return T_QUOTE3;
 
 \"\"                   return T_QUOTE2;
 \"\"\"                 return T_QUOTE3;
 
-                       /* matrix delimiters */
-\[\[                   return T_MATRIX_BEGIN;
-\]\]                   return T_MATRIX_END;
-
                        /* numbers */
 {D}+                   |
 "#"{D}+"R"{AN}+                |
                        /* numbers */
 {D}+                   |
 "#"{D}+"R"{AN}+                |
index ce27972dbfc0f51385c9a31a3622d1d20ff03266..fcc66f42a7442fe0a751b7b935ebf43d2df16759 100644 (file)
@@ -89,7 +89,7 @@ static void print_help_topics(void);
 /* Tokens (T_LITERAL means a literal value returned by the parser, but not
    of class numeric or symbol (e.g. a constant or the FAIL object)) */
 %token T_NUMBER T_SYMBOL T_LITERAL T_DIGITS T_QUOTE T_QUOTE2 T_QUOTE3
 /* Tokens (T_LITERAL means a literal value returned by the parser, but not
    of class numeric or symbol (e.g. a constant or the FAIL object)) */
 %token T_NUMBER T_SYMBOL T_LITERAL T_DIGITS T_QUOTE T_QUOTE2 T_QUOTE3
-%token T_EQUAL T_NOTEQ T_LESSEQ T_GREATEREQ T_MATRIX_BEGIN T_MATRIX_END
+%token T_EQUAL T_NOTEQ T_LESSEQ T_GREATEREQ
 
 %token T_QUIT T_WARRANTY T_PRINT T_IPRINT T_TIME T_XYZZY T_INVENTORY T_LOOK T_SCORE
 
 
 %token T_QUIT T_WARRANTY T_PRINT T_IPRINT T_TIME T_XYZZY T_INVENTORY T_LOOK T_SCORE
 
@@ -224,8 +224,8 @@ exp : T_NUMBER              {$$ = $1;}
        | exp '^' exp           {$$ = power($1, $3);}
        | exp '!'               {$$ = factorial($1);}
        | '(' exp ')'           {$$ = $2;}
        | exp '^' exp           {$$ = power($1, $3);}
        | exp '!'               {$$ = factorial($1);}
        | '(' exp ')'           {$$ = $2;}
-       | '[' list_or_empty ']' {$$ = $2;}
-       | T_MATRIX_BEGIN matrix T_MATRIX_END    {$$ = lst_to_matrix(ex_to_lst($2));}
+       | '{' list_or_empty '}' {$$ = $2;}
+       | '[' matrix ']'        {$$ = lst_to_matrix(ex_to_lst($2));}
        ;
 
 exprseq        : exp                   {$$ = exprseq($1);}
        ;
 
 exprseq        : exp                   {$$ = exprseq($1);}
@@ -240,8 +240,8 @@ list        : exp                   {$$ = lst($1);}
        | list ',' exp          {lst l(static_cast<lst &>(*($1.bp))); $$ = l.append($3);}
        ;
 
        | list ',' exp          {lst l(static_cast<lst &>(*($1.bp))); $$ = l.append($3);}
        ;
 
-matrix : T_MATRIX_BEGIN row T_MATRIX_END               {$$ = lst($2);}
-       | matrix ',' T_MATRIX_BEGIN row T_MATRIX_END    {lst l(static_cast<lst &>(*($1.bp))); $$ = l.append($4);}
+matrix : '[' row ']'           {$$ = lst($2);}
+       | matrix ',' '[' row ']' {lst l(static_cast<lst &>(*($1.bp))); $$ = l.append($4);}
        ;
 
 row    : exp                   {$$ = lst($1);}
        ;
 
 row    : exp                   {$$ = lst($1);}
@@ -280,6 +280,7 @@ static ex f_degree(const exprseq &e) {return e[0].degree(e[1]);}
 static ex f_denom(const exprseq &e) {return e[0].denom();}
 static ex f_eval1(const exprseq &e) {return e[0].eval();}
 static ex f_evalf1(const exprseq &e) {return e[0].evalf();}
 static ex f_denom(const exprseq &e) {return e[0].denom();}
 static ex f_eval1(const exprseq &e) {return e[0].eval();}
 static ex f_evalf1(const exprseq &e) {return e[0].evalf();}
+static ex f_evalm(const exprseq &e) {return e[0].evalm();}
 static ex f_expand(const exprseq &e) {return e[0].expand();}
 static ex f_gcd(const exprseq &e) {return gcd(e[0], e[1]);}
 static ex f_has(const exprseq &e) {return e[0].has(e[1]) ? ex(1) : ex(0);}
 static ex f_expand(const exprseq &e) {return e[0].expand();}
 static ex f_gcd(const exprseq &e) {return gcd(e[0], e[1]);}
 static ex f_has(const exprseq &e) {return e[0].has(e[1]) ? ex(1) : ex(0);}
@@ -499,6 +500,7 @@ static const fcn_init builtin_fcns[] = {
        {"eval", fcn_desc(f_eval2, 2)},
        {"evalf", fcn_desc(f_evalf1, 1)},
        {"evalf", fcn_desc(f_evalf2, 2)},
        {"eval", fcn_desc(f_eval2, 2)},
        {"evalf", fcn_desc(f_evalf1, 1)},
        {"evalf", fcn_desc(f_evalf2, 2)},
+       {"evalm", fcn_desc(f_evalm, 1)},
        {"expand", fcn_desc(f_expand, 1)},
        {"gcd", fcn_desc(f_gcd, 2)},
        {"has", fcn_desc(f_has, 2)},
        {"expand", fcn_desc(f_expand, 1)},
        {"gcd", fcn_desc(f_gcd, 2)},
        {"has", fcn_desc(f_has, 2)},