From: Christian Bauer Date: Fri, 1 Jun 2001 22:50:33 +0000 (+0000) Subject: - list delimiters are now { } and matrix delimiters are [ ] X-Git-Tag: release_0-9-0~19 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=abc4512627b3eb04732698e48dc88771d7904e71;ds=sidebyside - list delimiters are now { } and matrix delimiters are [ ] - added evalm() function --- diff --git a/ginsh/ginsh.1.in b/ginsh/ginsh.1.in index 39ece405..94ef4b70 100644 --- a/ginsh/ginsh.1.in +++ b/ginsh/ginsh.1.in @@ -191,22 +191,20 @@ Lists are used by the .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 ( [ ), -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 ( ] ). -.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. @@ -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 evalm( expression ) +\- evaluates sums and products of matrices +.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) -> 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); diff --git a/ginsh/ginsh_lexer.ll b/ginsh/ginsh_lexer.ll index a8a2b10e..932f80b4 100644 --- a/ginsh/ginsh_lexer.ll +++ b/ginsh/ginsh_lexer.ll @@ -89,10 +89,6 @@ score return T_SCORE; \"\" return T_QUOTE2; \"\"\" return T_QUOTE3; - /* matrix delimiters */ -\[\[ return T_MATRIX_BEGIN; -\]\] return T_MATRIX_END; - /* numbers */ {D}+ | "#"{D}+"R"{AN}+ | diff --git a/ginsh/ginsh_parser.yy b/ginsh/ginsh_parser.yy index ce27972d..fcc66f42 100644 --- a/ginsh/ginsh_parser.yy +++ b/ginsh/ginsh_parser.yy @@ -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 -%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 @@ -224,8 +224,8 @@ exp : T_NUMBER {$$ = $1;} | 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);} @@ -240,8 +240,8 @@ list : exp {$$ = lst($1);} | list ',' exp {lst l(static_cast(*($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(*($1.bp))); $$ = l.append($4);} +matrix : '[' row ']' {$$ = lst($2);} + | matrix ',' '[' row ']' {lst l(static_cast(*($1.bp))); $$ = l.append($4);} ; 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_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);} @@ -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)}, + {"evalm", fcn_desc(f_evalm, 1)}, {"expand", fcn_desc(f_expand, 1)}, {"gcd", fcn_desc(f_gcd, 2)}, {"has", fcn_desc(f_has, 2)},