# How to have different $Assumptions for each notebook? Sometimes I keep two or more notebooks side by side. I noticed that changing$Assumptions in one notebook affects the others, although I have changed Notebook's default context to "Unique to this Notebook".

Is there any walk around of this?

• Just start a separate kernel for each notebook? – Henrik Schumacher May 24 '18 at 13:39
• How to do that? Quit kernel and start a new one? – ablmf May 24 '18 at 13:40
• See C.E.'s commente here on hwo to do it. – Henrik Schumacher May 24 '18 at 13:40
• You can set CellProlog/Epilog to set/reset assumptions – Kuba May 24 '18 at 13:50

## 1 Answer

There are less painful way than duplicating the kernel to have $Assumptions evaluate to different values. One way to do it, keeping the context local to each notebook, is to use a supporting variable $Assumptions := ToExpression["myAssumptions"]


You can then set the variable in different notebook and it will pick the context automatically

myAssumptions = a < 0;


If you want to keep the same context among all your notebooks, you can still use the same trick with a small modification

getContext[] :=
StringJoin["Notebook", ToString[Hash[InputNotebook[]]], ""]

setAssumption[expr_] := (# = expr) &@
ToExpression[getContext[] <> "myAssumptions", InputForm, Unevaluated]

$Assumptions := ToExpression[getContext[] <> "myAssumptions"]] setAssumption[a < 0];  In the current notebook you will have $Assumptions
(* a < 0 *)


while in another notebook you will see something like

$Assumptions (* Notebook944295401273993393myAssumptions *)  you can then set your different assumptions by doing the same and again $Assumptions will pick up the correct one.

setAssumption[a > 0];
$Assumptions (* a > 0 *)  You can even get fancier and define a value for when your custom assumptions are not set $Assumptions :=
If[ValueQ[#], #, True] &@
ToExpression[getContext[] <> "myAssumptions", InputForm, Unevaluated]