]> www.ginac.de Git - ginac.git/commitdiff
added map()
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Mon, 25 Jun 2001 22:04:11 +0000 (22:04 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Mon, 25 Jun 2001 22:04:11 +0000 (22:04 +0000)
ginsh/ginsh.1.in
ginsh/ginsh_parser.yy

index 5f780648f980317baed030827422dd7b904182d0..a66c23e1295276511c077daf74fc7c5ff9275381 100644 (file)
@@ -279,14 +279,14 @@ detail here. Please refer to the GiNaC documentation.
 .BI expand( expression )
 \- expands an expression
 .br
 .BI expand( expression )
 \- expands an expression
 .br
-.BI find( expression ", " expression )
+.BI find( expression ", " pattern )
 \- returns a list of all occurrences of a pattern in an expression
 .br
 .BI gcd( expression ", " expression )
 \- greatest common divisor
 .br
 \- returns a list of all occurrences of a pattern in an expression
 .br
 .BI gcd( expression ", " expression )
 \- greatest common divisor
 .br
-.BI has( expression ", " expression )
-\- returns "1" if the first expression contains the second (which may contain wildcards) as a subexpression, "0" otherwise
+.BI has( expression ", " pattern )
+\- returns "1" if the first expression contains the pattern as a subexpression, "0" otherwise
 .br
 .BI inverse( matrix )
 \- inverse of a matrix
 .br
 .BI inverse( matrix )
 \- inverse of a matrix
@@ -306,6 +306,9 @@ detail here. Please refer to the GiNaC documentation.
 .BI lsolve( equation-list ", " symbol-list )
 \- solve system of linear equations
 .br
 .BI lsolve( equation-list ", " symbol-list )
 \- solve system of linear equations
 .br
+.BI map( expression ", " pattern )
+\- apply function to each operand; the function to be applied is specified as a pattern with the "$0" wildcard standing for the operands
+.br
 .BI match( expression ", " pattern )
 \- check whether expression matches a pattern; returns a list of wildcard substitutions or "FAIL" if there is no match
 .br
 .BI match( expression ", " pattern )
 \- check whether expression matches a pattern; returns a list of wildcard substitutions or "FAIL" if there is no match
 .br
index a94b92c775b1b71ec20178bdb3d8fcb65f18846e..16601cee15d2e6792ec74446bcc37f77a5a6e070 100644 (file)
@@ -394,6 +394,19 @@ static ex f_is(const exprseq &e)
        return (bool)ex_to<relational>(e[0]) ? ex(1) : ex(0);
 }
 
        return (bool)ex_to<relational>(e[0]) ? ex(1) : ex(0);
 }
 
+class apply_map_function : public map_function {
+       ex apply;
+public:
+       apply_map_function(const ex & a) : apply(a) {}
+       ex operator()(const ex & e) { return apply.subs(wild() == e, true); }
+};
+
+static ex f_map(const exprseq &e)
+{
+       apply_map_function fcn(e[1]);
+       return e[0].map(fcn);
+}
+
 static ex f_match(const exprseq &e)
 {
        lst repl_lst;
 static ex f_match(const exprseq &e)
 {
        lst repl_lst;
@@ -526,6 +539,7 @@ static const fcn_init builtin_fcns[] = {
        {"lcoeff", fcn_desc(f_lcoeff, 2)},
        {"ldegree", fcn_desc(f_ldegree, 2)},
        {"lsolve", fcn_desc(f_lsolve, 2)},
        {"lcoeff", fcn_desc(f_lcoeff, 2)},
        {"ldegree", fcn_desc(f_ldegree, 2)},
        {"lsolve", fcn_desc(f_lsolve, 2)},
+       {"map", fcn_desc(f_map, 2)},
        {"match", fcn_desc(f_match, 2)},
        {"nops", fcn_desc(f_nops, 1)},
        {"normal", fcn_desc(f_normal1, 1)},
        {"match", fcn_desc(f_match, 2)},
        {"nops", fcn_desc(f_nops, 1)},
        {"normal", fcn_desc(f_normal1, 1)},