Error, (in ...) numeric exception: division by zero - Maple Programming Help

# Online Help

###### All Products    Maple    MapleSim

Home : Support : Online Help : System : Error Message Guide : divisionbyzero

Error,  (in ...) numeric exception: division by zero

 Description In Maple, dividing by zero produces a division by zero error. However, sometimes the division by zero is not apparent.

Examples

Example 1

 > $\mathrm{restart}$
 > $\mathrm{ln}(0)$
 > $\mathrm{tan}\left(\frac{\mathrm{π}}{2}\right)$

Solution: Replace the NumericEventHandler for division by zero.

 > $\mathrm{NumericEventHandler}\left(\mathrm{division_by_zero}=\mathbf{proc}\left(\mathrm{operator},\mathrm{operands},\mathrm{defVal}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{if}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{operator}=\mathrm{ln}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{then}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{return}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}−\mathrm{∞}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{else}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{return}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{defVal}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end if}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end proc}\right);$$\mathrm{division}\mathrm{_by_zero}=\mathbf{proc}\left(\mathrm{operator},\mathrm{operands},\mathrm{defVal}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{defVal}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end proc}$
 ${\mathrm{division_by_zero}}{=}{\mathrm{default}}$
 ${\mathrm{division}}{}{\mathrm{_by_zero}}{=}{\mathbf{proc}}\left({\mathrm{operator}}{,}{\mathrm{operands}}{,}{\mathrm{defVal}}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{defVal}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (2.1)
 > $\mathrm{ln}\left(0\right)$
 ${-}{\mathrm{\infty }}$ (2.2)
 > $\mathrm{tan}\left(\frac{\mathrm{π}}{2}\right)$
 ${\mathrm{\infty }}{+}{\mathrm{\infty }}{}{I}$ (2.3)
 > $\mathrm{restart}$

Example 2

 > $f≔\left({\mathrm{sin}\left(a\right)}^{2}+{\mathrm{cos}\left(a\right)}^{2}-1\right)x$
 ${f}{≔}\left({{\mathrm{sin}}{}\left({a}\right)}^{{2}}{+}{{\mathrm{cos}}{}\left({a}\right)}^{{2}}{-}{1}\right){}{x}$ (2.4)
 > $\mathrm{int}\left(\mathrm{sin}\left(f\right),x\right);$
 ${-}\frac{{\mathrm{cos}}{}\left(\left({{\mathrm{sin}}{}\left({a}\right)}^{{2}}{+}{{\mathrm{cos}}{}\left({a}\right)}^{{2}}{-}{1}\right){}{x}\right)}{{{\mathrm{sin}}{}\left({a}\right)}^{{2}}{+}{{\mathrm{cos}}{}\left({a}\right)}^{{2}}{-}{1}}$ (2.5)
 > $\mathrm{simplify}\left(\right);$

The weakness is in int, which does not identify ${\mathrm{sin}\left(a\right)}^{2}+{\mathrm{cos}\left(a\right)}^{2}-1$ as equal to 0.  Simplifying the expanded output from int then leads to division by zero. A stronger zero-testing routine is required earlier in the process. However, using the strongest possible zero-testing routine by default is inefficient.

Solution 1: For a single expression, simplify before taking the integral.

 > $\mathrm{restart}$
 > $f≔\left({\mathrm{sin}\left(a\right)}^{2}+{\mathrm{cos}\left(a\right)}^{2}-1\right)x$
 ${f}{≔}\left({{\mathrm{sin}}{}\left({a}\right)}^{{2}}{+}{{\mathrm{cos}}{}\left({a}\right)}^{{2}}{-}{1}\right){}{x}$ (2.6)
 > $\mathrm{int}\left(\mathrm{simplify}\left(\mathrm{sin}\left(f\right)\right),x\right);$
 ${0}$ (2.7)

Solution 2: For numerous expressions, control zero-testing using Normalizer.

 > $\mathrm{restart}$
 > $\mathrm{Normalizer}≔\mathrm{simplify}$
 ${\mathrm{Normalizer}}{≔}{\mathrm{simplify}}$ (2.8)
 > $f≔\left({\mathrm{sin}\left(a\right)}^{2}+{\mathrm{cos}\left(a\right)}^{2}-1\right)x$
 ${f}{≔}\left({{\mathrm{sin}}{}\left({a}\right)}^{{2}}{+}{{\mathrm{cos}}{}\left({a}\right)}^{{2}}{-}{1}\right){}{x}$ (2.9)
 > $\mathrm{int}\left(\mathrm{sin}\left(f\right),x\right);$
 ${0}$ (2.10)
 > $\mathrm{Normalizer}≔\mathrm{normal}:$

 See Also