DSolve will not apply assumption m ∈ Integers

I am trying to solve a linear second order ODE using DSolve which involves an arbitrary integer m. DSolve gives me a solution when I set m to a particular integer (I have tried several, including negative/positive, even/odd, and 0). When I try to use the assumption m ∈ Integers and ask DSolve to solve this ODE for an arbitrary integer m, it does not work. Here is the input:

$Assumptions = m ∈ Integers testk = 0 == -16 c m^2 Cos[x] k[x] - c (-7 Sin[x] + Sin[3x]) k'[x] + Cos[x] Sin[x]^2 (m^2 (3 + 4 m Cos[x] + Cos[2 x]) Tan[x/2]^(2 m) + 4 c k''[x]) DSolve[ testk, k[x], x]  DSolve[ 0 == -16 c m^2 Cos[x] k[x] - c (-7 Sin[x] + Sin[3 x]) k'[x] + Cos[x] Sin[x]^2 (m^2 (3 + 4 m Cos[x] + Cos[2 x]) Tan[x/2]^(2 m) + 4 c k''[x], k[x], x]  Update: I have realized that the problem is that DSolve does not apply any of the global assumptions. Does anyone know how I can make DSolve apply the assumption that m ∈ Integers? I have tried using Assuming[,] to set the assumptions locally but that did not work either. - I do not think DSolve uses/accepts user assumptions. This was my understanding all along. Unless something changed in newer version of M. – Nasser Oct 20 '14 at 8:22 @Nasser Functions called by DSolve use $Assumptions (Simplify, Refine, Integrate etc.), but otherwise I don't think DSolve uses it. I think DSolve gets stuck trying to figure out how to reduce the problem to integrals. – Michael E2 Oct 20 '14 at 20:21

I think I have solved this ODE (I didn't verify the solution). The problem with DSolve is Integrate was not terminating for this inhomogeneous equation.

So what I did was solve the homogeneous equation, then applied variation of parameters described here:

homode = -16c*m^2Cos[x]k[x] - c(Sin[3x] - 7Sin[x])k'[x] + 4c*Cos[x]Sin[x]^2k''[x] == 0;

homsol = First[k[x] /. DSolve[homode, k[x], x]];

u1 = homsol /. {C[1] -> 1, C[2] -> 0};
u2 = homsol /. {C[1] -> 0, C[2] -> 1};

f = m^2(3 + 4m Cos[x] + Cos[2x])Tan[x/2]^(2m)Cos[x]Sin[x]^2/(4c*Cos[x] Sin[x]^2);

W = Wronskian[homode, k, x];

A = -HoldForm[Integrate[#, x]]&[u2*f/W];
B = HoldForm[Integrate[#, x]]&[u1*f/W];

TraditionalForm[k[x] == u1 C[1] + u2 C[2] + A u1 + B u2]


--- Edit ---

I have verified this solution is correct and I thought I'd share because this is the first time I've found a real use for Inactive over Hold... exciting!

So instead of using HoldForm to hold A and B, I use Inactivate:

A = Inactivate[-Integrate[u2*f/W, x], Integrate];
B = Inactivate[Integrate[u1*f/W, x], Integrate];

final = u1 C[1] + u2 C[2] + A u1 + B u2;

FullSimplify[testk /. {k[x] -> final, k'[x] -> D[final, x], k''[x] -> D[final, {x, 2}]}]

True

-
By substitution, I have verified that this solution by @Chip Hurst is formally correct, although I believe that t should be replaced by x in the definitions of A and B. – bbgodfrey Nov 19 '14 at 14:24
@bbgodfrey yes, thank you! This is fixed now. – Chip Hurst Nov 19 '14 at 17:53
very nice use of Inactivate, which I had not seen before. Allows a much simpler method to verify correctness of solution than the method I used. By the way, assuming m>0 and running Simplify on the solution gives a somewhat simpler answer. – bbgodfrey Nov 19 '14 at 19:29

Update: I thought I would check this out in V10.1. I found no difference in DSolve, but I was able to an answer relatively quickly (compare with my original attempt). It's in a different form than the original, but it's equivalent.

Using the same substitution as Chip Hurst in his Apr 22 answer, and after some coaxing, I got to this solution:

testk = 0 == -16 c m^2 Cos[x] k[x] - c (-7 Sin[x] + Sin[3 x]) k'[x] +
Cos[x] Sin[x]^2 (m^2 (3 + 4 m Cos[x] + Cos[2 x]) Tan[x/2]^(2 m) +
4 c k''[x]);
ode = testk /. x -> x[u] /.
First@Solve[{h'[u] == D[k[x[u]], u],
h''[u] == D[k[x[u]], u, u]}, {k'[x[u]], k''[x[u]]}] /.
k[x[u]] -> h[u] /. x -> ArcCos /.
Tan[ArcCos[u]/2]^a_ :> ((1 - u)/(1 + u))^(a/2) // FullSimplify;

solu = DSolve[ode, h, u];

Assuming[m ∈ Integers && m >= 0,
fubar = Simplify[h[Cos[x]] /. First@solu] /.
Exp[A__*ArcTanh[Cos[x]]] :>
Simplify[ExpToTrig[Simplify[TrigToExp[E^(A ArcTanh[Cos[x]])]]]] //
Simplify
];

solx = Function @@ {x, fubar}
(*
Function[x, (1/(8 c m (-1 + 4 m^2))) *
(m^3 (-((-1 + Cos[x])^2/(1 + Cos[x])))^m *
(1 + 4 m^2 + 4 m Cos[x] + (-1 + 4 m^2) Cos[2 x]) +
4 c (-1 + Cos[x])^m *
((-1 + 4 m^2) C[1] - m C[2] + 2 m ((-1 + 4 m^2) C[1] + m C[2]) Cos[x]) *
Cosh[m (Log[1 + Cos[x]] - Log[2 Sin[x/2]^2])] -
4 c (-1 + Cos[x])^m *
((-1 + 4 m^2) * C[1] + m C[2] + 2 m ((-1 + 4 m^2) C[1] - m C[2]) Cos[x]) *
Sinh[m (Log[1 + Cos[x]] - Log[2 Sin[x/2]^2])])]
*)


Check:

Assuming[m ∈ Integers,
testk /. k -> solx // FullSimplify
]
(*  True  *)


Original solution found

For what it's worth, using the same substitution as Chip Hurst in his Apr 22 answer, and after some coaxing, I originally got to this solution:

solx = Function[x,
1/(4 Sqrt[
m^2]) (2 C[1] (1 + 2 Sqrt[m^2] Cos[x]) Cot[x/2]^(-2 Sqrt[m^2]) - (
2 C[2] (Sqrt[m^2] - 2 m^2 Cos[x]) Cot[x/2]^(2 Sqrt[m^2]))/(-1 +
4 m^2) + ((m^2)^(
3/2) (1 + 2 m Cos[x] + (-1 + 4 m^2) Cos[x]^2) Tan[x/2]^(2 m))/(
c (-1 + 4 m^2)))]


Unfortunately, crashes, trying different things, memory leaks or something messing up Simplify and FullSimplify or other confusing behavior, plus stupidly copying and saving the wrong step means there is one step missing in the path to the solution.

Check:

testk /. k -> solx // Simplify
(*  True  *)


[It is arguably a simpler solution, but I did not discover a way to transform the new solution to this one.]

One of the problems is that applying the assumption that m is an integer causes different things to happen under the hood in simplification. But some simplifications are valid whether m is an integer or not. The following example shows that an early application of the assumption slows things down quite a bit. Simplifications are usually done under time constraints, which may lead to failure.

ode /. First@solu //
Simplify[#, m ∈ Integers && u ∈ Reals] & // AbsoluteTiming
(*  {17.843582, True} *)

ode /. First@solu // Simplify //
Simplify[#, m ∈ Integers && u ∈ Reals] & // AbsoluteTiming
(*  {7.273103, True}  *)


It is a sheer guess that this has something to do with the problem.

-
Very nice! I have no idea why my ODE didn't solve with DSolve since it works for me in V9 and V10 today. – Chip Hurst Nov 20 '14 at 20:50
@ChipHurst If you throw in the assumption Element[m, Integers] with DSolve (with Assuming, say), DSolve runs longer than I'm willing to wait. That may be the difference between now and before. – Michael E2 Nov 21 '14 at 1:04

Not sure if this will help, but you can transform your ODE to have rational coefficients by subbing $t = \cos x$, which gives

$k'(x)=-\sqrt{1-t^2} k'(t), \quad k''(x)=(1-t^2)k''(t)-t k'(t), \;\; \text{ and } \;\; x=\cos ^{-1}(t)$:

testk=-16 c m^2 Cos[x] k[x]-c (-7 Sin[x]+Sin[3x]) k'[x]+Cos[x] Sin[x]^2 (m^2 (3+4 m Cos[x]+Cos[2 x]) Tan[x/2]^(2 m)+4 c k''[x]);

$fromTrig={k'[x]:>(-Sqrt[1-t^2])*k'[t],k[x]->k[t],k''[x]->-t*k'[t]+k''[t]-t^2*k''[t],x->ArcCos[t]}; simped = Simplify[FunctionExpand[testk/.$fromTrig],-1<t<1&&m\[Element]Integers];

Collect[(1+t)^m PowerExpand[simped], {k[t],k'[t],k''[t]}]==0

-2 m^2 (1-t)^m t (-1+t^2) (1+2 m t+t^2)-16 c m^2 t (1+t)^m k[t] +
8 c (1+t)^m (-1+t^2) k'[t]+4 c t (1+t)^m (-1+t^2)^2 k''[t] == 0

-
You might be interested in my answer. – Michael E2 Nov 20 '14 at 16:58