3

I want to restrict my variables to certain ranges for my entire notebook, is there a way I can do that in one go without entering a different $assumption line for every variable?

Edit: I want to define the domain of variables for all calculations in my notebook (googling helped me frame my needs better!)

4
  • Just to understand a little better. Suppose you do Restrict[a,{0,1,2,3}] with a certain function Restrict[]. What is your expected behaviour if you later do a=5 ? Commented Nov 30, 2010 at 17:38
  • How about $Assumptions = Element[#, Reals] & /@ {a, b, c, d} Commented Nov 30, 2010 at 19:22
  • @Yaroslav That is actually equivalent to $Assumptions = Element[{a, b, c, d}, Reals], but for more general range restrictions, you're right. A simple Map should work. Commented Dec 1, 2010 at 2:35
  • Can you be more specific? Exactly what domain are you working with and is it the same for all variables? Commented Dec 1, 2010 at 2:36

2 Answers 2

4

Globally define as follows

$Assumptions = b >= 0 && c >= 0 && {u11, u13, u14} \[Element] Reals 

then use globally defined variables as follows

Simplify[expression with global variables] 
Sign up to request clarification or add additional context in comments.

Comments

2

If all of your variables are going to be (for example) Real, then you can intercept the creation of new symbols and add that assumption to $Assumptions. E.g.

$Assumptions = True; $NewSymbol = If[#2 === "Global`", Print["Created new Global` variable named ", #1, ". It is assumed to be real."]; $Assumptions = $Assumptions && Element[Symbol[#2 <> #1], Reals], Null (* other, probably a system symbol is created *)] &; 

Then if you create a new symbol that you don't want to be real, then you could follow up with something like $Assumptions = Most[$Assumptions].


Note: I don't necessarily claim that this approach is a good idea... It's probably best to just define the $Assumptions for the variables you are going to use. This can be done programmatically using Map, Table, etc.

3 Comments

I remember working in some version of BASIC where the first char of a variable name defined its type ...
@belisarius Yeah... that brings back some memories. It would be quite easy to modify my answer to behave like that.
@simon & belisarius If you were ever forced to worked with M$-style C-code, you would see the practice of naming by type taken to its horrible extreme. Google/Wikipedia tells me it even has a name: Hungarian Notation.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.