Say there is a complex number a=x+I, where x is a real number. Then b=Join[{a},{1+I}], and I use Re[b].

The result is {Re[x],1}, but the desired result is {x,1}.

How can I set x as a global real number from the very beginning? Please be noted that x should be treated a real number no matter what kind of calculation is used.

I have read many questions, but none is fit to my situation.

This problem bothers me for a very long time, and I hope someone can give me the answer.

  • $\begingroup$ look for $Assumptions . The first example shows how to set global assumptions. $Assumptions = a > 0. $\endgroup$
    – Sumit
    Jul 2, 2018 at 13:13
  • $\begingroup$ Related: (66273) $\endgroup$
    – Lukas Lang
    Jul 2, 2018 at 13:14

2 Answers 2

$Assumptions = x \[Element] Reals

a = x + I
b = Join[{a}, {1 + I}]


{I + x, 1 + I}

{x, 1}

  • $\begingroup$ Thank you so much! It works! $\endgroup$
    – Robin_Lyn
    Jul 2, 2018 at 13:26


ComplexExpand[Re[b], TargetFunctions -> {Re, Im}]
(*{x, 1}*)

is what you're looking for!

  • $\begingroup$ Thank you for your help, but I need set 'x' as a global real number. And I have many calculation afterwards. Your answer is local. $\endgroup$
    – Robin_Lyn
    Jul 2, 2018 at 13:21
  • $\begingroup$ @Robin_Lyn You have to realize, though, that only functions that take an Assumptions option will be aware of global assumptions. Ulrich's approach, on the other hand, is explicit and local, which is actually a good thing so you don't fall into hard-to-debug situations that depend on remote assumptions / assignments. $\endgroup$
    – MarcoB
    Jul 2, 2018 at 13:25
  • $\begingroup$ @MarcoB Thank you for your advice. Now I know both the global and local definition for a variable. Many thanks again for Ulrich Neumann $\endgroup$
    – Robin_Lyn
    Jul 2, 2018 at 13:31
  • $\begingroup$ If you Set x to be a specific real number, it'll be that number, but there is no way in general to force Mathematica to treat a free symbol as representing a real number in all circumstances. $\endgroup$
    – John Doty
    Jul 2, 2018 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.