Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: help on Rewrite rules

  • To: mathgroup at smc.vnet.net
  • Subject: [mg50890] Re: [mg50875] help on Rewrite rules
  • From: Andrzej Kozlowski <andrzej at akikoz.net>
  • Date: Sun, 26 Sep 2004 05:31:54 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 25 Sep 2004, at 14:55, Jon Palmer wrote:

> *This message was transferred with a trial version of CommuniGate(tm)
> Pro*
> I am having trouble simplifying expressions in mathematica. My
> epxerissions
> involve two parameters x & y that parameterise a unit circle so that
>
> x^2 + y^2 =1
>
> Without chosing a particular parameterization for x and y I want to
> simplify
> epxpertions of the form:
>
>
> 3x^2 + 2y^2               -----> 2 + x^2
> or
> (x^2 + y^2)^(1/2)        -----> 1
>
> and more importantly for should perform the simplification
>
> A[x^2] + B [y^2] + C[x^2+y^2]    -----> A[ x^2] + B[ y^2] + C[1]
>
> where A,B&C are functions.
>
> I assume that this can me achieved with a relatively simple rewrite
> rule but
> I have had very limited success making this work. Can anyone suggest a
> solution,
>
> Many thanks
> Jon Palmer
>
> P.S. I also want to expand the problem to that of three variables x,y&z
> parameterizing a unit sphere but I suspect that this will be obvious
> form
> the solution of the unit circle problem.
>
>
 
First of all, your question is rather ambiguous. You say you want  3x^2
+ 2y^2 to be "simplified" to  2 + x^2, why not
 
 
Simplify[3*x^2 + 2*y^2, x^2 + y^2 == 1]
 
3 - y^2
 
?
 
What is exactly the criterion that should be used to choose one rather
than another of the various possible expressions? In this case it looks
like you want to eliminate y, but then you say that the expression
 
A[x^2] + B [y^2] + C[x^2+y^2]


should be converted to A[x^2] + B [y^2] + C[1]. Why not to A[x^2] + B
[1-x^2] + C[1]? You seem to be using human judgement here of the kind
that can't be programmed. In fact Mathematica's Simplify is trying to
simulate something similar and will return:

Simplify[A[x^2] + B[y^2] + C[x^2 + y^2], x^2 + y^2 == 1]

A[x^2] + B[y^2] + C[1]

But there is no way to guarantee that in general Simplify will return
the output you want.

If you want simply to eliminate y^2, that could be achieved by using
ReplaceAll with the local  rule y^2->1-x^2 as in


Simplify[3*x^2 + 2*y^2 /. y^2 -> 1 - x^2]

2 + x^2

For simple situations this is enough but it will not work if explicit
y^2 does not appear in your expression, e.g.:


y*(y + 1) + x^2 /. y^2 -> 1 - x^2


x^2 + y*(1 + y)

Mathematica of course can't do "semantic" pattern matching, so it has
to see an explicit "syntactic" pattern in order to perform a
replacement. In this case you could deal with this problem by first
applying ExpandAll to your expression.


ExpandAll[y*(y + 1) + x^2] /. y^2 -> 1 - x^2

1 + y

ExpandAll want help however in this case:


y^3 + y*x^2 /. y^2 -> 1 - x^2

x^2*y + y^3

This time what you want is Factor:


Factor[y^3 + y*x^2] /. y^2 -> 1 - x^2

y

You can in fact define a function that will deal with all the above
cases:



f[expr_] := expr /.
    (z_)?(PolynomialQ[#1, {x, y}] &&
         !FreeQ[#1, x | y] & ) :>
     Last[PolynomialReduce[z, x^2 + y^2 - 1,{y,x}]]

Now:



f[3*x^2 + 2*y^2]

2 + x^2



f[A[x^2] + B[y^2] + C[x^2 + y^2]]


A[x^2] + B[1 - x^2] + C[1]



f[y*(y + 1) + x^2]

1 + y

and


f[y^3 + y*x^2]

y

While this is not true "semantic pattern matching" it comes as close to
it as anything in symbolic algebra, though of course it only works for
polynomial relationships between x and y.



Andrzej Kozlowski
Chiba, Japan
http://www.akikoz.net/~andrzej/
http://www.mimuw.edu.pl/~akoz/


  • Prev by Date: Re: help on Rewrite rules
  • Next by Date: Re: Re: trimming a string
  • Previous by thread: Re: help on Rewrite rules
  • Next by thread: Simple questions with Complex Numbers