2
$\begingroup$

I am trying to find conservation laws of a system, and I'd like to rewrite terms of the form $$A\frac{dA^*}{dt}+A^*\frac{dA}{dt}$$

as $$\frac{d}{dt}|A|^2,$$ where $A$ is a complex valued function and $A^*$ is its conjugate.

Is it possible to take a large list of terms, and have mathematica rewrite all the terms it can as perfect derivatives?

EDIT: I will include a minimal example. I am trying to find a constant $\beta$ so that the terms provided below can be written in the form $\frac{\partial}{\partial X}\left(something\right)$:

(-A[X, T])*Ap[X, T]^2*Derivative[1, 0][A][X, T] - (5/2)*A[X, T]^2*Ap[X, T]^3*
Derivative[1, 0][A][X, T] - (1/2)*I*β*Ap[X, T]^2*Derivative[1, 0][A][X, 
T]^2 - 
A[X, T]^2*Ap[X, T]*Derivative[1, 0][Ap][X, T] - (5/2)*A[X, T]^3*Ap[X, T]^2*
Derivative[1, 0][Ap][X, T] + (5/2)*β*Ap[X, T]*Derivative[1, 0][A][X,
T]^2*
Derivative[1, 0][Ap][X, T] + (1/2)*I*β*A[X, T]^2*Derivative[1, 0][Ap][X, 
T]^2 + 
(5/2)*β*A[X, T]*Derivative[1, 0][A][X, T]*Derivative[1, 0][Ap][X, T]^2 - 
I*β*Ap[X, T]*Derivative[1, 0][A][X, T]*Derivative[1, 0][bϕ][X, T] + 
I*β*A[X, T]*Derivative[1, 0][Ap][X, T]*Derivative[1, 0][bϕ][X, T] - 
(1/4)*I*A[X, T]*Ap[X, T]^2*Derivative[2, 0][A][X, T] - 
(1/4)*β*Ap[X, T]^2*Derivative[1, 0][A][X, T]*Derivative[2, 0][A][X, T] + 
(1/2)*β*Derivative[1, 0][Ap][X, T]*Derivative[2, 0][A][X, T] + 
(3/2)*β*A[X, T]*Ap[X, T]*Derivative[1, 0][Ap][X, T]*
Derivative[2, 0][A][X, T] + 
(1/4)*I*A[X, T]^2*Ap[X, T]*Derivative[2, 0][Ap][X, T] + 
(1/2)*β*Derivative[1, 0][A][X, T]*Derivative[2, 0][Ap][X, T] + 
(3/2)*β*A[X, T]*Ap[X, T]*Derivative[1, 0][A][X, T]*
Derivative[2, 0][Ap][X, T] - 
(1/4)*β*A[X, T]^2*Derivative[1, 0][Ap][X, T]*Derivative[2, 0][Ap][X, T] 
+  
(1/8)*A[X, T]*Ap[X, T]^2*Derivative[3, 0][A][X, T] + 
(1/8)*I*β*Derivative[1, 0][Ap][X, T]*Derivative[3, 0][A][X, T] + 
(1/8)*A[X, T]^2*Ap[X, T]*Derivative[3, 0][Ap][X, T] - 
(1/8)*I*β*Derivative[1, 0][A][X, T]*Derivative[3, 0][Ap][X, T] - 
(1/16)*β*Derivative[1, 0][Ap][X, T]*Derivative[4, 0][A][X, T] - 
(1/16)*β*Derivative[1, 0][A][X, T]*Derivative[4, 0][Ap][X, T]
$\endgroup$
  • 2
    $\begingroup$ Can you give a practical example of a (not so) large list of terms? $\endgroup$ – Szabolcs Mar 16 '16 at 19:51
  • 1
    $\begingroup$ @Szabolcs A (maybe not too small?) example has been provided. $\endgroup$ – Nick P Mar 16 '16 at 22:00
2
$\begingroup$

The approach below might give some ideas for how one can proceed.

expr = (-A[X, T])*Ap[X, T]^2*Derivative[1, 0][A][X, T] - (5/2)*
    A[X, T]^2*Ap[X, T]^3*Derivative[1, 0][A][X, T] - (1/2)*I*\[Beta]*
    Ap[X, T]^2*Derivative[1, 0][A][X, T]^2 - 
   A[X, T]^2*Ap[X, T]*Derivative[1, 0][Ap][X, T] - (5/2)*A[X, T]^3*
    Ap[X, T]^2*Derivative[1, 0][Ap][X, T] + (5/2)*\[Beta]*Ap[X, T]*
    Derivative[1, 0][A][X, T]^2*Derivative[1, 0][Ap][X, T] + (1/2)*
    I*\[Beta]*A[X, T]^2*Derivative[1, 0][Ap][X, T]^2 + (5/2)*\[Beta]*
    A[X, T]*Derivative[1, 0][A][X, T]*Derivative[1, 0][Ap][X, T]^2 - 
   I*\[Beta]*Ap[X, T]*Derivative[1, 0][A][X, T]*
    Derivative[1, 0][b\[Phi]][X, T] + 
   I*\[Beta]*A[X, T]*Derivative[1, 0][Ap][X, T]*
    Derivative[1, 0][b\[Phi]][X, T] - (1/4)*I*A[X, T]*Ap[X, T]^2*
    Derivative[2, 0][A][X, T] - (1/4)*\[Beta]*Ap[X, T]^2*
    Derivative[1, 0][A][X, T]*
    Derivative[2, 0][A][X, T] + (1/2)*\[Beta]*
    Derivative[1, 0][Ap][X, T]*
    Derivative[2, 0][A][X, T] + (3/2)*\[Beta]*A[X, T]*Ap[X, T]*
    Derivative[1, 0][Ap][X, T]*Derivative[2, 0][A][X, T] + (1/4)*I*
    A[X, T]^2*Ap[X, T]*Derivative[2, 0][Ap][X, T] + (1/2)*\[Beta]*
    Derivative[1, 0][A][X, T]*
    Derivative[2, 0][Ap][X, T] + (3/2)*\[Beta]*A[X, T]*Ap[X, T]*
    Derivative[1, 0][A][X, T]*
    Derivative[2, 0][Ap][X, T] - (1/4)*\[Beta]*A[X, T]^2*
    Derivative[1, 0][Ap][X, T]*Derivative[2, 0][Ap][X, T] +
   (1/8)*A[X, T]*Ap[X, T]^2*Derivative[3, 0][A][X, T] + (1/8)*
    I*\[Beta]*Derivative[1, 0][Ap][X, T]*
    Derivative[3, 0][A][X, T] + (1/8)*A[X, T]^2*Ap[X, T]*
    Derivative[3, 0][Ap][X, T] - (1/8)*I*\[Beta]*
    Derivative[1, 0][A][X, T]*
    Derivative[3, 0][Ap][X, T] - (1/16)*\[Beta]*
    Derivative[1, 0][Ap][X, T]*
    Derivative[4, 0][A][X, T] - (1/16)*\[Beta]*
    Derivative[1, 0][A][X, T]*Derivative[4, 0][Ap][X, T];

We set up the derivative relations in terms of a norm squared (I assume Ap is intended as the conjugate of A). I just use normA but it is the square really.

relation = A[X, T]*Ap[X, T] - normA[X, T];
replacements = NestList[D[#, X] &, relation, 4];

Find the variables we'll try to reduce.

mainvars = {A[X, T], Ap[X, T]};
allvars = Flatten[NestList[D[#, X] &, mainvars, 4]];

Compute a Groebner basis so we'll have a canonical reduction. Note that I use a term order that makes this fairly fast though it might not be best in terms of outcome.

gb = GroebnerBasis[replacements, allvars, 
   MonomialOrder -> DegreeReverseLexicographic, 
   CoefficientDomain -> RationalFunctions];

Now reduce modulo that Groebner basis.

PolynomialReduce[expr, gb, al(* {A[X, T]*Ap[X, T] - normA[X, T], 
Ap[X, T]*Derivative[1, 0][A][X, T] + 
 A[X, T]*Derivative[1, 0][Ap][X, T] - 
Derivative[1, 0][normA][X, T], 
2*Derivative[1, 0][A][X, T]*Derivative[1, 0][Ap][X, T] + 
 Ap[X, T]*Derivative[2, 0][A][X, T] + 
A[X, T]*Derivative[2, 0][Ap][X, T] - 
 Derivative[2, 0][normA][X, T], 
3*Derivative[1, 0][Ap][X, T]*Derivative[2, 0][A][X, T] + 
 3*Derivative[1, 0][A][X, T]*Derivative[2, 0][Ap][X, T] + 
 Ap[X, T]*Derivative[3, 0][A][X, T] + 
A[X, T]*Derivative[3, 0][Ap][X, T] - 
 Derivative[3, 0][normA][X, T], 
6*Derivative[2, 0][A][X, T]*Derivative[2, 0][Ap][X, T] + 
 4*Derivative[1, 0][Ap][X, T]*Derivative[3, 0][A][X, T] + 
 4*Derivative[1, 0][A][X, T]*Derivative[3, 0][Ap][X, T] + 
 Ap[X, T]*Derivative[4, 0][A][X, T] + 
A[X, T]*Derivative[4, 0][Ap][X, T] - 
 Derivative[4, 0][normA][X, T]} *)lvars, 
  MonomialOrder -> DegreeReverseLexicographic, 
  CoefficientDomain -> RationalFunctions][[2]]

(* {A[X, T]*Ap[X, T] - normA[X, T], 
 Ap[X, T]*Derivative[1, 0][A][X, T] + 
     A[X, T]*Derivative[1, 0][Ap][X, T] - 
  Derivative[1, 0][normA][X, T], 
   2*Derivative[1, 0][A][X, T]*Derivative[1, 0][Ap][X, T] + 
     Ap[X, T]*Derivative[2, 0][A][X, T] + 
  A[X, T]*Derivative[2, 0][Ap][X, T] - 
     Derivative[2, 0][normA][X, T], 
   3*Derivative[1, 0][Ap][X, T]*Derivative[2, 0][A][X, T] + 
     3*Derivative[1, 0][A][X, T]*Derivative[2, 0][Ap][X, T] + 
     Ap[X, T]*Derivative[3, 0][A][X, T] + 
  A[X, T]*Derivative[3, 0][Ap][X, T] - 
     Derivative[3, 0][normA][X, T], 
   6*Derivative[2, 0][A][X, T]*Derivative[2, 0][Ap][X, T] + 
     4*Derivative[1, 0][Ap][X, T]*Derivative[3, 0][A][X, T] + 
     4*Derivative[1, 0][A][X, T]*Derivative[3, 0][Ap][X, T] + 
     Ap[X, T]*Derivative[4, 0][A][X, T] + 
  A[X, T]*Derivative[4, 0][Ap][X, T] - 
     Derivative[4, 0][normA][X, T]} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.