How to assume real variables?

If you have an expression that contains variables, i.e. non-numeric symbols, and you want to simplify that expression assuming that all variables are real: How can that be achieved?

Unfortunately Simplify[expr,Reals] like in Solve is accepted, but the assumption “Reals” is ignored.

An example with expected result Abs[1+x]:

Block[{x, expr},
 expr = Sqrt[(1 + 2 Conjugate[x] + x^2)];
 {expr, Simplify[expr, Reals], Simplify[expr, Element[x,Reals]]}
 ]

==>

{Sqrt[1 + x^2 + 2 Conjugate[x]], Sqrt[1 + x^2 + 2 Conjugate[x]], Abs[1 + x]}

Of course I could use the last syntax Simplify[expr, Element[x, Reals]] but only if I knew the variables within expr. Often expr or its predecessors are unknown since passed into a function as a parameter. Then, before simplification, I had to scan the complete expr for its variables.

Hi Werner,

Not sure if this will work for your actual use case, but you can specify that all symbols are Reals, e.g.

Block[{x, expr},
 expr = Sqrt[(1 + 2 Conjugate[x] + x^2)];
 {expr, Simplify[expr, Reals, Assumptions -> Element[_Symbol, Reals]]}]
(* {Sqrt[1 + x^2 + 2 Conjugate[x]], Abs[1 + x]} *)

Thanks Rohit, this is perfect. I was not aware that assumptions can use patterns.

BTW: The second parameter in Simplify is superfluous. Here some more examples how to use:

Block[{x, expr},
  expr = Sqrt[(1 + 2 Conjugate[x] + x^2)];
  Print[{expr, 1, Simplify[expr, Assumptions -> Element[_Symbol, Reals]]}];
  Print[{expr, 2, Simplify[expr, Element[_Symbol, Reals]]}];
  Print[{expr, 3, Assuming[Element[_Symbol, Reals], Simplify[expr]]}];
  $Assumptions = Element[_Symbol, Reals];
  Print[{expr, 4, Simplify[expr]}];
  ];

==>

{Sqrt[1+x^2+2 Conjugate[x]],1,Abs[1+x]}
{Sqrt[1+x^2+2 Conjugate[x]],2,Abs[1+x]}
{Sqrt[1+x^2+2 Conjugate[x]],3,Abs[1+x]}
{Sqrt[1+x^2+2 Conjugate[x]],4,Abs[1+x]}

Of course this works for many variables as well:

Block[{x, y, expr1, expr2},
  $Assumptions = True;
  expr1 = Sqrt[(1 + 2 Conjugate[x] + x^2)];
  expr2 = Sqrt[x^2 + 2 x Conjugate[y] + y^2];
  
  Print["Without assumptions: ", $Assumptions];
  Print[{expr1, Simplify[expr1]}];
  Print[{expr2, Simplify[expr2]}];
  
  Assuming[Element[_Symbol, Reals],
   Print["With assumptions: ", $Assumptions];
   Print[{expr1, Simplify[expr1]}];
   Print[{expr2, Simplify[expr2]}]
   ];
  ];

==>

Without assumptions: True
{Sqrt[1+x^2+2 Conjugate[x]],Sqrt[1+x^2+2 Conjugate[x]]}
{Sqrt[x^2+y^2+2 x Conjugate[y]],Sqrt[x^2+y^2+2 x Conjugate[y]]}
With assumptions: Element[_Symbol, Reals]
{Sqrt[1+x^2+2 Conjugate[x]],Abs[1+x]}
{Sqrt[x^2+y^2+2 x Conjugate[y]],Abs[x+y]}