improvement (hopefully) to subs and a patch included
Hello everybody, Here is a patch that is supposed to make substitutions, optionally, a bit more semantic (as opposed to syntactic). I also wrote a bit of documentation for it, so hava a look at the patch for a description. (Also corrected some spelling errors in the manual). This disadvantage of this patch is that it breaks compatibility of the interface. The subs method gets an extra optional argument like this ex subs(const lst & ls, const lst & lr, unsigned options = 0, bool no_pattern = false) const This is inconvenient if people have written subclasses. They will need to include this extra option everywhere. Furthermore if you use the no_pattern optional argument, you will also hava a problem. However, I think that the option-argument has the potential of being quite usefull, and the no_pattern-argument is probably only for people getting really deep into the internals of GiNaC, so I really think this is the correct order. Note that further additions to the subs-method would go into new subs_options, so that further breaking of the interface will not be necesary. However, for this reason, I guess this patch should not be included until the 1.1 release. I do not know whether diff -c -r --exclude=CVS is the most convenient format for a patch for you. If this is going to take you hours to do the patching, I will be happy to send some other format. Greetings, Chris Dams
Hi! On Mon, Nov 18, 2002 at 12:11:28PM +0000, Chris Dams wrote:
Here is a patch that is supposed to make substitutions, optionally, a bit more semantic (as opposed to syntactic).
This looks interesting. Any particular reason why sums aren't treated in a "smart" (should we call that "algebraic") way?
The subs method gets an extra optional argument like this
ex subs(const lst & ls, const lst & lr, unsigned options = 0, bool no_pattern = false) const
The 'no_pattern' could be moved to 'options' (something like 'subs_options::no_pattern').
cout << (4*x*x*x-2*x*x+5*x-1).subs(pow(x,wild())==pow(a,wild()), subs_options::subs_smart) << endl; // --> -1+5*x+4*x^3-2*x^2
Not "-1+5*a+4*a^3-2*a^2"? (I haven't tried the patch yet...)
I do not know whether diff -c -r --exclude=CVS is the most convenient format for a patch for you.
"cvs diff" is fine (no, you don't need to resend the patch :). Bye, Christian -- / Coding on PowerPC and proud of it \/ http://www.uni-mainz.de/~bauec002/
Hello, On Wed, 27 Nov 2002, Christian Bauer wrote:
On Mon, Nov 18, 2002 at 12:11:28PM +0000, Chris Dams wrote:
Here is a patch that is supposed to make substitutions, optionally, a bit more semantic (as opposed to syntactic).
This looks interesting. Any particular reason why sums aren't treated in a "smart" (should we call that "algebraic") way?
In my experience it is quite often so that the most useful form to manipulate expressions in, is the expanded form. When using this form most things can be achieved by only using "smart" (or "algebraic") substitutions on multiplications. For instance, the cos^2(whatever)+sin^2(whatever)==1 example in the FAQ, becomes cos^2(wild())==1-sin^2(wild()) and after expanding again, one gets a more or less canonical form for a polynomial of sin's an cos'es that only has cos to the power 0 or 1. Generally, I think the primary use of the smart substitutions (I have no objections if you call them "algebraic") is to canoncialize expressions in the users favourite expression domain to the users favourite canonical form. For this one quite often only needs smart/algebraic substitions for multiplications and no smartness for additions. Furthermore, smart substitution in additions is a bit of a difficult subject if one has expanded expressions in mind.
The subs method gets an extra optional argument like this
ex subs(const lst & ls, const lst & lr, unsigned options = 0, bool no_pattern = false) const
The 'no_pattern' could be moved to 'options' (something like 'subs_options::no_pattern').
Does sound like a good idea. Hadn't yet thought about that.
cout << (4*x*x*x-2*x*x+5*x-1).subs(pow(x,wild())==pow(a,wild()), subs_options::subs_smart) << endl; // --> -1+5*x+4*x^3-2*x^2
Not "-1+5*a+4*a^3-2*a^2"? (I haven't tried the patch yet...)
Have thought about it, but then I came to the conclusion that the way things go now, this would preferably be based on smartness (or algebraicness) in the .match() method (and is not terribly convenient to realize in a way that users would think of as being consistent without that). The problem is that pow(x,wild()) does not match x, which is used internally to find the number of times a pattern matches. I prefered smarting (or algebraicing) one method at the time (be it only for keeping the size of my patches moderate) and perhaps the time for smarting .match() will never come because my guess would be that the kind of pattern in which the exponent is a wildcard is not of terribly much use in most cases if smart substitution is available. Bye, Chris Dams
participants (3)
-
Chris Dams
-
chrisd@catv7250.extern.kun.nl
-
Christian Bauer