This problem is similar to this problem using package to verify solution of ode with Association, Naming scope/context handling but when I used the solution/trick given there, I still get a problem.
I am not well versed in low level package programming to figure what other tricks I need for this and it seems the solutions are way too complicated for me to understand.
Here is MWE. Given this package
BeginPackage["mypkg`"]
Unprotect @@ Names["mypkg`*"];
ClearAll @@ Names["mypkg`*"];
dsolve::usage = "..."
Begin["`Private`"]
dsolve[y_,x_]:= Module[{assoc},
assoc=<| "x"->x,"y"->y|>;
process[assoc]
];
process[assoc_Association]:=Module[{x,y},
x=assoc["x"];
y=assoc["y"];
Inactivate[Integrate[1/Log[1+K[1]^2],{K[1],0,y[x]}]]
];
End[];
Protect @@ Names["mypkg`*"];
EndPackage[]
And now
SetDirectory[NotebookDirectory[]]
Get["mypkg.m"]
mypkg`dsolve[y, x]
The solution given in the above link is to use @@ List[...]
instead. So I replaced the line
Inactivate[Integrate[1/Log[1+K[1]^2],{K[1],0,y[x]}]]
with
Inactivate @@ List[Integrate[1/Log[1+K[1]^2],{K[1],0,y[x]}]]
And this did indeed fix the context issue, but now I get a new problem
Get["mypkg.m"]
mypkg`dsolve[y, x]
You see, it tried to do the integration.
What I want is to use Inactivate
to prevent the integral from evaluating but without the Private
context showing up. i.e. I want the above output but with Mathematica actually doing the integral and getting this error, as I know this integral can't be integrated.
I am doing this so I can replace the form of the unevaluated integral to one with the upper limit being $y(x)$ as this is the form I prefer.
Any other tricks I should try?
V 13.2 on windows.
With[{upper = y[x]}, Inactivate[Integrate[1/Log[1 + K[1]^2], {K[1], 0, upper}]] ]
like you would inx = 1; Hold[x]
$\endgroup$Inactivate
supposed not to evaluate what is inside it in first place? Or does it evaluate some parts on its arguments first? may be I misunderstoodInactivate
Note that in Global context this works as is without having to doWith
trick. i.,e.Inactivate[Integrate[1/Log[1 + K[1]^2], {K[1], 0, y[x]}]]
works with no error. That is why I thought it is related to naming/context issue. !Mathematica graphics I do not think I will ever be able to understand fully Mathematica's evaluation/naming/contexts mixing... $\endgroup$With
is needed inside the package and not needed outside the package as I am not able to figure it out myself. Thanks. $\endgroup$With
trick" No, the problem is still there. The following should help you see what's wrong:x = xx; y = yy; Inactivate[Integrate[1/Log[1 + K[1]^2], {K[1], 0, y[x]}]]
. Also, if you just want to stopIntegrate
, it's better to writeInactivate[Integrate[1/Log[1 + K[1]^2], {K[1], 0, y[x]}], Integrate]
(otherwiseInactivate
will make almost every headInactive
) or simplyInactive[Integrate][1/Log[1 + K[1]^2], {K[1], 0, y[x]}]
. These avoid the mentioned issue, too. $\endgroup$