I am developing an application in one part I am checking the if the functions are constant or not. I am using a couple of lines of code (it is possible that there is another way of doing it) but the code behaves differently when I use as a package instead of in a .nb file. The notebook code is
FunCons2[var1_, var2_, var3_, var4_] := Module[{fields}
, fields = Flatten[{var1, var2, var3, var4}]
; consz = fields /. z -> {a, b}
; consz
]
f1 = 1;
f2 = t^3 + (z - 1) (z - 2) + E^-t Sin[z];
f3 = {-1 + E^-t Cos[1], 2 (1 + E^-t Cos[2])};
f4 = Limit[f2, t -> 0];
FunCons2[f1, f4, f3, f2]
The output as you can see t is replaced a and b
{ {1, 2 - 3 z + z^2 + Sin[z], {-1 + E^-a Cos[1], -1 + E^-b Cos[1]}, {2 (1 + E^-a Cos[2]), 2 (1 + E^-b Cos[2])}, {a^3 + (-2 + z) (-1 + z) + E^-a Sin[z], b^3 + (-2 + z) (-1 + z) + E^-b Sin[z]}} }
and the package version is
Get[FileNameJoin[{NotebookDirectory[EvaluationNotebook[]],"CheckCons.wl"}]];
f1 = 1;
f2 = t^3 + (z - 1) (z - 2) + E^-t Sin[z];
f3 = {-1 + E^-t Cos[1], 2 (1 + E^-t Cos[2])};
f4 = Limit[f2, t -> 0];
CheckCons`FunCons[f1, f4, f3, f2]
The package
BeginPackage["CheckCons`"];
FunCons::usage="";
Begin["`Private`"];
FunCons[var1_,var2_,var3_,var4_]:=Module[{fields,a,b},
fields=Flatten[{var1,var2,var3,var4}];
consz=fields/.z->{a,b};
consz
]
End[];
EndPackage[];
And the output is
{ {1, 2 - 3 z + z^2 + Sin[z], -1 + E^-t Cos[1], 2 (1 + E^-t Cos[2]), t^3 + (-2 + z) (-1 + z) + E^-t Sin[z]} }
The problem is replacing z
with a
and b
. Inside the package the code does not replace it. I don't know why or how to avoid that.
{1,2-3 z+z^2+Sin[z],-1+E^-t Cos[1],2 (1+E^-t Cos[2]),t^3+(-2+z) (-1+z)+E^-t Sin[z]}
t and z are still the variable no private or global why I can't replace t or z directly. Even when you look at the output of Variables[Level[fields,{-1}]][[1]] it is {} or z or t. $\endgroup$?? CheckCons`FunCons
. $\endgroup$Attributes[FunCons]={Locked,Protected,ReadProtected}
$\endgroup$