4
$\begingroup$

Sometimes Mathematica generates solutions to a PDE which are hard to read, since it attaches assumptions to the result. If a user knows these assumptions are obvious physically, they might want to avoid having them included in the output so that it is easier to read.

I do not know how to tell Mathematica to avoid showing these assumptions. The option GenerateConditions->False does not work here, since this is a call to DSolve which does not accept this option. But DSolve internally uses Integrate

Is there other ways to do this? Here is a MWE

Example 1

Remove[L0];
ClearAll[u,t,k,x,f];
pde=D[u[x,t],t]==k D[u[x,t],{x,2}];
bc={Derivative[1,0][u][0,t]==0,Derivative[1,0][u][L0,t]==0}
ic=u[x,0]==f[x];
sol=DSolve[{pde,bc,ic},u[x,t],{x,t}];
sol=sol/.{K[1]->n,K[2]->x}

Mathematica graphics

The solution is correct. But I'd like to see it as

Mathematica graphics

I do not know how to pass GenerateConditions->False to Integrate which is internally used by DSolve.

Btw, Maple generates the same answer, without those assumptions by default, which makes it little easier to read

restart;
L:='L'; u:='u'; t:='t'; x:='x';
interface(showassumed=0);
assume(L>0);
pde:=diff(u(x,t),t)=k*diff(u(x,t),x$2);
bc:=D[1](u)(0,t)=0,D[1](u)(L,t)=0:
ic:=u(x,0)=f(x):
sol:=pdsolve([pde,bc,ic],u(x,t)):
sol:=subs(_Z2=n,sol);

Mathematica graphics

Example 2

It also depends on the PDE and the boundary conditions. For example, in this one, Mathematica generates strange Assumptions->True in the result, which I do not understand, and did not include assumptions on time or length or k as above. But the PDE solution is correct

Remove[L0];
ClearAll[u,t,k,x];
pde=D[u[x,t],t]==k D[u[x,t],{x,2}];
bc={u[0,t]==0,u[L0,t]==0};
ic=u[x,0]==f[x];
sol=DSolve[{pde,bc,ic},u[x,t],{x,t}];
sol=sol/.K[1]->n

Mathematica graphics

In summary, I'd just like an option to disable display of Assumptions in result if possible.

I convert these results to Latex, and with assumptions there, the output is hard to read.

Using version 11.3 on windows.

$\endgroup$

3 Answers 3

6
$\begingroup$

How about modifying $PrePrint?:

(* Solution 1 *)
$PrePrint = (# /. HoldPattern@Integrate[a__, (_ -> _) ..] :> Integrate[a]) &;
(* Solution 2 *)
$PrePrint = (# /. HoldPattern@Integrate[a__, OptionsPattern[]] :> Integrate[a]) &;

Notice we've only changed the display, sol and Out[…] are still expressions involving Assumptions.

$\endgroup$
4
$\begingroup$

I hate to state the obvious, but does the following do what you want?

% /. Integrate[x___, Assumptions -> _, y___] :> Integrate[x, y]
$\endgroup$
4
$\begingroup$

If you just want to improve the TeXForm output, you could modify the TraditionalForm Integrate formatting definition:

Unprotect[Integrate];
Integrate /: MakeBoxes[
    Integrate[a__, OptionsPattern[]],
    TraditionalForm
] /;! TrueQ@$IntFlag := Block[{$Foo=True},
    MakeBoxes[Integrate[a],TraditionalForm]
]
Protect[Integrate];

Then:

Integrate[f[x]Sin[x],{x,0,L0},Assumptions->True] //TeXForm

$\int_0^{\operatorname{L0}} f(x) \sin (x) \, dx$

$\endgroup$

Your Answer

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

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