Miscellaneous`RealOnly`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.
Plot::"plnr": "\!\(x\^\(1/3\)\) is not a machine-size real number at \!\(x\) = \!\(-7.999999333333333`\)."
Plot::"plnr": "\!\(x\^\(1/3\)\) is not a machine-size real number at \!\(x\) = \!\(-7.350928134833347`\)."
Plot::"plnr": "\!\(x\^\(1/3\)\) is not a machine-size real number at \!\(x\) = \!\(-6.64305920225002`\)."
General::"stop": "Further output of \!\(Plot :: \"plnr\"\) will be suppressed during this calculation."
Out[1]= |  |
Every cubic equation has three roots, counting multiplicity.
Out[2]= |  |
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).
Out[3]= |  |
Automatic transformations caused by the RealOnly package. This loads the package. Power has been redefined so that an odd root of a negative number is negative.
Out[5]= |  |
Now the plot works for negative values of x.
Out[6]= |  |
In addition to modifying Power, the package suppresses complex numbers. This is now the solution of the cubic equation.
Nonreal::"warning": "Nonreal number encountered."
Out[7]= |  |
Very small imaginary parts are transformed to 0.
Out[8]= |  |
A number with an imaginary part that is not small is transformed to Nonreal.
Nonreal::"warning": "Nonreal number encountered."
Out[9]= |  |
Finally, elementary calculations involving unavoidable complex numbers are transformed to Nonreal.
Nonreal::"warning": "Nonreal number encountered."
Out[10]= |  |
|