This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / Add-ons / Standard Packages / Miscellaneous  /


In high school algebra, exponents and radicals are taught early, but complex numbers are usually left to more advanced courses. Some algebra teachers have asked for a package that would allow them to avoid complex numbers. Mathematica is flexible enough to block out imaginary and complex numbers in a way that is mathematically correct.
Two ideas are implemented in the package RealOnly . Odd roots of negative numbers are defined to be negative, and calculations with unavoidable complex numbers are condensed to the symbol Nonreal. This is done by redefining the built-in functions Power and $Post.

  • Without loading the package, Mathematica calculates a cube root of a negative number to be complex. So no points are plotted for negative values of x and warning messages are generated.
  • In[1]:= Plot[x ^ (1/3), {x, -8, 8}];

    Plot::plnr: x is not a machine-size real number at x = -8..

    Plot::plnr: x is not a machine-size real number at x = -7.35093.

    Plot::plnr: x is not a machine-size real number at x = -6.64306.

    General::stop: Further output of Plot::plnr will be suppressed during this calculation.

  • Every cubic equation has three roots, counting multiplicity.
  • In[2]:= Solve[x^3 == -8.0]


  • Any one of these three roots could be taken as the cube root of . Ordinarily, Mathematica

    chooses the one with the least positive argument (the third solution in this case).
  • In[3]:= (-8.0) ^ (1/3)


    Automatic transformations caused by the RealOnly package.

  • This loads the package.
  • In[4]:= Needs["Miscellaneous`RealOnly`"]

  • Power has been redefined so that an odd root of a negative number is negative.
  • In[5]:= (-8.0) ^ (1/3)


  • Now the plot works for negative values of x.
  • In[6]:= Plot[x ^ (1/3), {x, -8, 8}];

  • In addition to modifying Power, the package suppresses complex numbers. This is now the solution of the cubic equation.
  • In[7]:= Solve[x^3 == -8.0]

    Nonreal::warning: Nonreal number encountered.


  • Very small imaginary parts are transformed to 0.
  • In[8]:= {23 + 0. I, Sin[ArcSin[23.]]}


  • A number with an imaginary part that is not small is transformed to Nonreal.
  • In[9]:= {ArcSin[23.], Sin[23. + I]}

    Nonreal::warning: Nonreal number encountered.


  • Finally, elementary calculations involving unavoidable complex numbers are transformed to Nonreal.
  • In[10]:= Tan[a + 23 / (a + b I)]

    Nonreal::warning: Nonreal number encountered.