4

Say I have two arbitrary real constants $p,q$ that satisfy $p^2+q^2=1$. Is there any way to easily declare this relation in Mathematica?

Edit

More specifically I have this (among others) expression:

$$\frac{\sqrt{\frac{p^4 q^4(p^2-q^2)^2}{p^4 + q^4}}}{\sqrt{p^{10}+p^2q^8+p^8(-2+q^2)+2p^4q^4(-2+q^2)+q^6(-1+q^2)^2+p^6(1+2q^4)}}$$

Divide[Sqrt[Divide[p^4 q^4 (p^2 - q^2)^2, p^4 + q^4]], 
 Sqrt[p^{10} + p^2 q^8 + p^8 (-2 + q^2) + 2 p^4 q^4 (-2 + q^2) + 
   q^6 (-1 + q^2)^2 + p^6 (1 + 2 q^4)]]

and am asking whether there is a way to have Mathematica reduce it using the relation $\;q^2+p^2=1$.

Sjoerd C. de Vries
  • 65,815
  • 14
  • 188
  • 323
doppz
  • 143
  • 4
  • I am using Mathematica to do some tedious derivatives for me where the functions involved depend on arbitrary constants $a,b$ subject to to the relation $a^2+b^2=1$ which I feel will simplify my results. I was wondering if there is any way to declare this relation in Mathematica so that it may reduce the output, if possible. – doppz Jan 31 '14 at 23:07
  • This is unclear what you mean by declaring. Simplifying, reducing, solving, substituting, etc. – Artes Jan 31 '14 at 23:23
  • 2
    Not really, this isn't how people normally work in Mathematica, and there's no way to declare such a relation. This is why people think that your question is confusing. (To be fair, $Assumptions is similar to what you describe, but it probably won't help you much.) To make the question clear: give examples of calculations that you want to do with a and b and explain how you need to use the relationship between a and b in those calculations. The answer to you question will depend on precisely what sorts of calculations you need to do and how this relationship will be used. – Szabolcs Jan 31 '14 at 23:41
  • So again: the key is what you actually want to do and how you need to use $a^2+b^2=1$ in that. It's impossible to give a useful answer without this information. – Szabolcs Jan 31 '14 at 23:44
  • Thank you for the responses. More specifically I have this expression (among others) and am asking whether there is a way to have mathematica reduce it using the relation $q^2+p^2=1$. My apologies if my wording was inaccurate or confusing:$$\frac{\sqrt{\frac{p^4 q^4 \left(p^2-q^2\right)^2}{p^4+q^4}}}{\sqrt{p^{10}+p^2 q^8+p^8 \left(-2+q^2\right)+2 p^4 q^4 \left(-2+q^2\right)+q^6 \left(-1+q^2\right)^2+p^6 \left(1+2 q^4\right)}}.$$ – doppz Jan 31 '14 at 23:48
  • 2
    please include the mathematica code for your expression. It might be possible and I (and others) might be willing to take a stab at answering it, but I am certainly not willing to enter that expression by hand into mathematica syntax. – rm -rf Feb 01 '14 at 03:15

2 Answers2

5

There are many possible ways to tackle this task.

expr = Sqrt[ ((p^4 q^4 (p^2 - q^2))/(p^4 + q^4))]/Sqrt[ p^10 + p^2 q^8 
       + p^8 (-2 + q^2) + 2 p^4 q^4 (-2 + q^2) + q^6 (-1 + q^2)^2 + p^6 (1 + 2 q^4)];

Standard approach uses simplification techniques like Simplify or FullSimplify, the latter appears to be unnecessary here. Let's use the former function:

Simplify[ expr, p^2 + q^2 == 1]
 Sqrt[(p^4 q^4 (1 - 2 q^2))/(p^4 + q^4)]/Sqrt[q^2 - 5 q^4 + 8 q^6 - 4 q^8]

So we've got a slightly simplified expression, however one might be still dissatisfied with this result. Althoug one could play with ComplexityFunction but we provide another direct way using Eliminate and exploiting a formal variable a to eliminate q:

Eliminate[{expr == a, p^2 + q^2 == 1}, q]
a^2 (-1 + 4 p^2 - 6 p^4 + 4 p^6) == p^2 (1 - p^2)

So we have an expression a^2 (i.e. expr^2) written in terms of p. Let's now eliminate p:

Eliminate[{expr == a, p^2 + q^2 == 1}, p]
a^2 (-1 + 4 q^2 - 6 q^4 + 4 q^6) == q^2 (-1 + q^2)

We can also use Simplify with a replacement rule exploiting a simple pattern, i.e. substituting all even powers of p with an expression involving only q:

Simplify[ expr /. p^b_?EvenQ /; b > 0 -> (1 - q^2)^(b/2)]
Sqrt[-((q^4 (-1 + q^2)^2 (-1 + 2 q^2))/(1 - 2 q^2 + 2 q^4))]/Sqrt[q^2 - 5 q^4 
                                                                   + 8 q^6 - 4 q^8]     
Artes
  • 57,212
  • 12
  • 157
  • 245
2

This is a slightly corrected version of code I and others have used in MathGroup, StackOverflow, and MSE. It is at heart a recursive PolynomialReduce.

replacementFunction[expr_, rep_, vars_] := 
 Module[{num = Numerator[expr], den = Denominator[expr], 
   hed = Head[expr], base, expon}, 
  If[PolynomialQ[num, vars] && 
    PolynomialQ[den, vars] && ! NumberQ[den], 
   replacementFunction[num, rep, vars]/
    replacementFunction[den, rep, vars], 
   If[hed === Power && Length[expr] == 2, 
    base = replacementFunction[expr[[1]], rep, vars];
    expon = replacementFunction[expr[[2]], rep, vars];
    PolynomialReduce[base^expon, rep, vars][[2]], 
    If[Head[hed] === Symbol && 
      MemberQ[Attributes[Evaluate[hed]], NumericFunction],
     Map[replacementFunction[#, rep, vars] &, expr], 
     PolynomialReduce[expr, rep, vars][[2]]]]]]

On your example it will eliminate a variable. Whether this is useful depends on what you really require.

expr = Sqrt[((p^4 q^4 (p^2 - q^2))/(p^4 + q^4))]/
   Sqrt[p^10 + p^2 q^8 + p^8 (-2 + q^2) + 2 p^4 q^4 (-2 + q^2) + 
     q^6 (-1 + q^2)^2 + p^6 (1 + 2 q^4)];

replacementFunction[expr, p^2 + q^2 - 1, {p, q}]

(* Out[299]= Sqrt[-((q^4 (-1 + q^2)^2 (-1 + 2 q^2))/(
 1 - 2 q^2 + 2 q^4))]/Sqrt[-q^2 (-1 + q^2) (-1 + 2 q^2)^2] *)
Daniel Lichtblau
  • 58,970
  • 2
  • 101
  • 199