patch for subs_algebraic

Chris Dams chrisd at sci.kun.nl
Wed Mar 5 12:39:52 CET 2003


Hello,

I discovered that the subs_algebraic subs_option does not yet go into
subexpressions. The attached patch makes this happen. Furthermore
nummatches was made into an int (it was an unsigned) because the unsigned
was not used anyway and the static_cast to integer that was introduced in
version 1.66.2.13 of mul.cpp completely kills subs_algebraic. I.e., it
converts the maximum unsigned integer to -1, which is not good.

Greetings,
Chris Dams

-------------- next part --------------
? .deps
? .libs
? Makefile
? Makefile.in
? exprseq.cpp
? exprseq.h
? function.cpp
? function.h
? indexed.cpp.modified
? indexed.cpp.patch
? input_lexer.cc
? input_parser.cc
? input_parser.cpp.cc
? input_parser.h
? libginac.la
? log
? lst.cpp
? lst.h
? matrix.cpp.changed
? matrix.h.changed
? numeric.cpp.modified
? numeric.cpp.patch
? patch
? printmul.patch
? substhings
? version.h
Index: expairseq.cpp
===================================================================
RCS file: /home/cvs/GiNaC/ginac/expairseq.cpp,v
retrieving revision 1.61.2.13
diff -r1.61.2.13 expairseq.cpp
400,403c400
< {	
< 	if ((options & subs_options::subs_algebraic) && is_exactly_a<mul>(*this))
< 		return static_cast<const mul *>(this)->algebraic_subs_mul(ls, lr, options);
< 
---
> {
406a404,405
> 	else if ((options & subs_options::subs_algebraic) && is_exactly_a<mul>(*this))
> 		return static_cast<const mul *>(this)->algebraic_subs_mul(ls, lr, options);
Index: mul.cpp
===================================================================
RCS file: /home/cvs/GiNaC/ginac/mul.cpp,v
retrieving revision 1.66.2.14
diff -r1.66.2.14 mul.cpp
521,522c521,522
< bool tryfactsubs(const ex & origfactor, const ex & patternfactor, unsigned & nummatches, lst & repls)
< {
---
> bool tryfactsubs(const ex & origfactor, const ex & patternfactor, int & nummatches, lst & repls)
> {	
559c559
< 	if (newnummatches < static_cast<int>(nummatches))
---
> 	if (newnummatches < nummatches)
565c565
< {
---
> {	
573c573
< 			unsigned nummatches = std::numeric_limits<unsigned>::max();
---
> 			int nummatches = std::numeric_limits<int>::max();
612c612
< 			unsigned nummatches = std::numeric_limits<unsigned>::max();
---
> 			int nummatches = std::numeric_limits<int>::max();
Index: power.cpp
===================================================================
RCS file: /home/cvs/GiNaC/ginac/power.cpp,v
retrieving revision 1.74.2.14
diff -r1.74.2.14 power.cpp
527c527
< extern bool tryfactsubs(const ex &, const ex &, unsigned &, lst &);
---
> extern bool tryfactsubs(const ex &, const ex &, int &, lst &);
530,540c530
< {
< 	if (options & subs_options::subs_algebraic) {
< 		for (size_t i=0; i<ls.nops(); i++) {
< 			unsigned nummatches = std::numeric_limits<unsigned>::max();
< 			lst repls;
< 			if (tryfactsubs(*this, ls.op(i), nummatches, repls))
< 				return (ex_to<basic>((*this) * power(lr.op(i).subs(ex(repls), subs_options::subs_no_pattern) / ls.op(i).subs(ex(repls), subs_options::subs_no_pattern), nummatches))).basic::subs(ls, lr, options);
< 		}
< 		return basic::subs(ls, lr, options);
< 	}
< 
---
> {	
544,547c534,535
< 	if (are_ex_trivially_equal(basis, subsed_basis)
< 	 && are_ex_trivially_equal(exponent, subsed_exponent))
< 		return basic::subs(ls, lr, options);
< 	else
---
> 	if (!are_ex_trivially_equal(basis, subsed_basis)
> 	 || !are_ex_trivially_equal(exponent, subsed_exponent)) 
548a537,549
> 
> 	if(!(options & subs_options::subs_algebraic))
> 		return basic::subs(ls, lr, options);
> 
> 	for (size_t i=0; i<ls.nops(); i++) {
> 		int nummatches = std::numeric_limits<int>::max();
> 		lst repls;
> 		if (tryfactsubs(*this, ls.op(i), nummatches, repls))
> 			return (ex_to<basic>((*this) * power(lr.op(i).subs(ex(repls), subs_options::subs_no_pattern) / ls.op(i).subs(ex(repls), subs_options::subs_no_pattern), nummatches))).basic::subs(ls, lr, options);
> 	}
> 
> 	ex result=basic::subs(ls, lr, options);
> 	return result;


More information about the GiNaC-devel mailing list