4
$\begingroup$

Related to this Can we abuse notation and write equations in differential one-form?

Is it possible to ApplySides a form of Integrate to an equation in differential one-form, so to achieve the following sequence:

$$ \mathrm{d}x = \frac{1}{y}\mathrm{d}y $$

ApplySides[Integrate, \[DifferentialD]x == 1/y \[DifferentialD]y]

$$\int \mathrm{d}x = \int \frac{1}{y}\mathrm{d}y $$

$$ x = \log y $$

$\endgroup$
2
  • $\begingroup$ \[Integral]\[DifferentialD]x==\[Integral]1/y\[DifferentialD]y is valid code, though it of course doesn't use ApplySides. Many Apply-esque things, like OperatorApplied, fail to insert \[Integral] before a syntax error. Same problem with Hold and friends. Perhaps these are worth adding to the question. $\endgroup$
    – Adam
    Feb 25, 2021 at 18:52
  • $\begingroup$ I added an answer to the linked Q&A that applies DSolve to a differential equation in such a form. It does not integrate each. so it does not do what is asked; but you still might find it convenient. $\endgroup$
    – Michael E2
    Feb 25, 2021 at 20:59

3 Answers 3

4
$\begingroup$

The use of \[DifferentialD]x to input an integral only work when converting boxes or a string representation. If you already have the equation in the OP in the kernel, it has the form

Equal[DifferentialD[x], Times[Power[y, -1], DifferentialD[y]]]

The way to apply an integral sign to it is to convert back to box form (or a string).

ApplySides[
 Fold[ToExpression[
     RowBox[{"\[Integral]", MakeBoxes[#, StandardForm]}]] &, #, 
   Cases[#, _DifferentialD, {0, Infinity}]] &,
 \[DifferentialD]x == 1/y \[DifferentialD]y]

(*  x == Log[y]  *)

(* assumes DifferentialD[..] is a factor *)
ApplySides[
 Fold[ToExpression[
     "\[Integral]" <> ToString[#/#2, InputForm] <> 
      ToString[#2, InputForm]] &, #, 
   Cases[#, _DifferentialD, {0, Infinity}]] &,
 \[DifferentialD]x == 1/y \[DifferentialD]y]

(*  x == Log[y]  *)

Another alternative would be to parse the expression and apply Integrate, which seems simpler in the present case when I look at it:

(* assumes DifferentialD[..] is a factor *)
ApplySides[
 Fold[Integrate[#/#2, First@#2] &, #, 
   Cases[#, _DifferentialD, {0, Infinity}]] &,
 \[DifferentialD]x == 1/y \[DifferentialD]y]

(*  x == Log[y]  *)
$\endgroup$
3
$\begingroup$

You could try:

f[ex_] := (int = (ex /. DifferentialD[_] -> 1); 
  dif = ex /. x___   DifferentialD[a_] -> a /. DifferentialD[a_] -> a;
   Inactive[Integrate][ex /. DifferentialD[_] -> 1 , dif])

ApplySides[f, \[DifferentialD]x == 1/y \[DifferentialD]y]

enter image description here

$\endgroup$
3
$\begingroup$

Here's a different approach, more general than asked for. It's not as suitable for Can we abuse notation and write equations in differential one-form? as for here, perhaps. In the following, it is not necessary to write one of the variables as a function of the others. It is more general in that it will integrate exact one-forms, not just separable ones, as well as two-variable forms for which an integrating factor can be found. And it will integrate exact forms of three or more variables. (It won't search for an integrating factor when there are more than two variables, however.)

ClearAll[integrate1Form];
integrate1Form::nonhom = "Not a homogeneous 1-form.";
integrate1Form::inexact = "Not an exact 1-form.";
integrate1Form[eq_] :=
  Module[{U, dvars, vars, res, vf, mu, P, Q},
   dvars = Union@Cases[eq, _DifferentialD, Infinity];
   vars = dvars[[All, 1]];
   vf = Replace[
     CoefficientArrays[eq, dvars],
     {{0, one_} :> Normal@one,
      {Except[0], __} :> $Failed}];
   If[Length@vf == 2,
    {P, Q} = vf;
    mu = DSolve`DSolveFirstOrderODEDump`IntegratingFactor[Q, 
      P, -D[P, y] + D[Q, x], x, y];
    If[FreeQ[mu, $Failed],
     vf *= mu]
    ];
   If[FreeQ[vf, $Failed],
    res = DSolveValue[
      D[U @@ vars, {vars}] == vf,
      U @@ vars, vars],
    Message[integrate1Form::nonhom];
    res = $Failed
    ];
   If[! FreeQ[res, DSolveValue],
    Message[integrate1Form::inexact]
    ];
   Simplify[res == 0] /; FreeQ[res, $Failed | DSolveValue]
   ];

A separable equation:

integrate1Form[\[DifferentialD]x == 
  1/y \[DifferentialD]y + \[DifferentialD]y]
(*  x + C[1] == y + Log[y]  *)

An equation with an integrating factor:

integrate1Form[\[DifferentialD]x == 
  1/y \[DifferentialD]y + x \[DifferentialD]y]
(*  E^-y x + C[1] == ExpIntegralEi[-y]  *)

An equation in which an integrating factor could not be found:

integrate1Form[(x + y) \[DifferentialD]x == 1/y \[DifferentialD]y]

integrate1Form::inexact : Not an exact 1-form.

(*  integrate1Form[(x + y) \[DifferentialD]x == \[DifferentialD]y/y]  *)

An exact form in three variables:

integrate1Form[
 2 x y \[DifferentialD]x + (x^2 - 2 y z^3 ) \[DifferentialD]y == 
  3 y^2 z^2 \[DifferentialD]z]
(*  x^2 y + C[1] == y^2 z^3  *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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