From: Richard Fateman on 17 Jun 2010 02:04 S. B. Gray wrote: > Suppose I have a long complex expression in which terms like > (x^2+y^3-x^2y^2+Sqrt[z3+y2]) (for a simple example) appear many times > along with various powers and the reciprocals of it, etc. To make the > expression comprehensible and to make the computation faster, I would > like to substitute say "f1xyz" for it everywhere it appears. The normal > /. and -> substitutions and patterns are not adequate for this. Of > course at evaluation time I want to compute f1xyz only once and not have > the final formula revert to the original variables. How do I prevent that? > > Also a welcome addition to Mathematica would be the ability to find these > repeated expressions automatically and put them in, because doing it > manually is very error-prone and slow. > > Tips will be appreciated! > > Steve Gray > > say you want to replace expression E1 by f where it occurs, even if it occurs in powers etc, in big expression B. First, simplify B to a single fraction N/D. divide N by E1, with remainder, to get Q and R. that is N= Q*E1+R. replace N with Q*f+R. Same with denominator D. Actually, you might want to divide N by E1^s for some power s, if you think that occurs too. This idea may not be a single command in Mathematica, though it has been described and used at least since 1971, called ratsubst. RJF
From: Sjoerd C. de Vries on 18 Jun 2010 01:26 Mathematica does not replace the expression if I put a simple 2 in front of the first term, whereas most any human sees the simple reduction that's possible: In: 2 x^2 + y^3 - x^2 y^2 + Sqrt[z3 + y2] /. x^2 + y^3 - x^2 y^2 + Sqrt[z3 + y2] -> flxyz Out: 2 x^2 - x^2 y^2 + y^3 + Sqrt[y2 + z3] could be easily reduced to x^2 +flxyz Cheers -- Sjoerd On Jun 6, 12:42 pm, "David Park" <djmp...(a)comcast.net> wrote: > "The normal > /. and -> substitutions and patterns are not adequate for this." > > That sounds like a completely unfounded statement so why don't you > demonstrate it? > > David Park > djmp...(a)comcast.nethttp://home.comcast.net/~djmpark/ > > From: S. B. Gray [mailto:stev...(a)ROADRUNNER.COM] > > Suppose I have a long complex expression in which terms like > (x^2+y^3-x^2y^2+Sqrt[z3+y2]) (for a simple example) appear many times > along with various powers and the reciprocals of it, etc. To make the > expression comprehensible and to make the computation faster, I would > like to substitute say "f1xyz" for it everywhere it appears. The normal > /. and -> substitutions and patterns are not adequate for this. Of > course at evaluation time I want to compute f1xyz only once and not have > the final formula revert to the original variables. How do I prevent that? > > Also a welcome addition to Mathematica would be the ability to find these > repeated expressions automatically and put them in, because doing it > manually is very error-prone and slow. > > Tips will be appreciated! > > Steve Gray
From: Bob Hanlon on 18 Jun 2010 07:44 Keep the LHS of the replacement rule simple and the match will be robust: 2 x^2 + y^3 - x^2 y^2 + Sqrt[z3 + y2] /. Sqrt[z3 + y2] -> flxyz - (x^2 + y^3 - x^2 y^2) flxyz + x^2 Bob Hanlon ---- "Sjoerd C. de Vries" <sjoerd.c.devries(a)gmail.com> wrote: ============= Mathematica does not replace the expression if I put a simple 2 in front of the first term, whereas most any human sees the simple reduction that's possible: In: 2 x^2 + y^3 - x^2 y^2 + Sqrt[z3 + y2] /. x^2 + y^3 - x^2 y^2 + Sqrt[z3 + y2] -> flxyz Out: 2 x^2 - x^2 y^2 + y^3 + Sqrt[y2 + z3] could be easily reduced to x^2 +flxyz Cheers -- Sjoerd On Jun 6, 12:42 pm, "David Park" <djmp...(a)comcast.net> wrote: > "The normal > /. and -> substitutions and patterns are not adequate for this." > > That sounds like a completely unfounded statement so why don't you > demonstrate it? > > David Park > djmp...(a)comcast.nethttp://home.comcast.net/~djmpark/ > > From: S. B. Gray [mailto:stev...(a)ROADRUNNER.COM] > > Suppose I have a long complex expression in which terms like > (x^2+y^3-x^2y^2+Sqrt[z3+y2]) (for a simple example) appear many times > along with various powers and the reciprocals of it, etc. To make the > expression comprehensible and to make the computation faster, I would > like to substitute say "f1xyz" for it everywhere it appears. The normal > /. and -> substitutions and patterns are not adequate for this. Of > course at evaluation time I want to compute f1xyz only once and not have > the final formula revert to the original variables. How do I prevent that? > > Also a welcome addition to Mathematica would be the ability to find these > repeated expressions automatically and put them in, because doing it > manually is very error-prone and slow. > > Tips will be appreciated! > > Steve Gray
From: Harrie Kraai on 19 Jun 2010 07:46 I asked a similar question about a year ago, http://groups.google.com/group/comp.soft-sys.math.mathematica/msg/a95d4651a5634771 and got this as the best answer: http://groups.google.com/group/comp.soft-sys.math.mathematica/msg/7cca617e1b4928c6 leading me to Experimental`OptimizeExpression But, also look at http://www.wolfram.com/technology/guide/CommonSubexpressionDetectionCollection/ perhaps Mathematica is doing something behind the scenes already. Harrie S. B. Gray wrote: > Suppose I have a long complex expression in which terms like > (x^2+y^3-x^2y^2+Sqrt[z3+y2]) (for a simple example) appear many times > along with various powers and the reciprocals of it, etc. To make the > expression comprehensible and to make the computation faster, I would > like to substitute say "f1xyz" for it everywhere it appears. The normal > /. and -> substitutions and patterns are not adequate for this. Of > course at evaluation time I want to compute f1xyz only once and not have > the final formula revert to the original variables. How do I prevent that? > > Also a welcome addition to Mathematica would be the ability to find these > repeated expressions automatically and put them in, because doing it > manually is very error-prone and slow. > > Tips will be appreciated! > > Steve Gray > >
First
|
Prev
|
Pages: 1 2 Prev: Mac OS X hard disk space used up by virtual memory Next: Push to clipboard? |