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

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{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{∞}}$ (2.2)
 > $\mathrm{tan}\left(\frac{\mathrm{π}}{2}\right)$
 ${\mathrm{∞}}{+}{\mathrm{∞}}{}{I}$ (2.3)
 > $\mathrm{restart}$

Example 2

 > $\mathrm{f}:=\left({\mathrm{sin}\left(\mathrm{a}\right)}^{2}+{\mathrm{cos}\left(\mathrm{a}\right)}^{2}-1\right)\mathrm{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(\mathrm{f}\right),\mathrm{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}$
 > $\mathrm{f}:=\left({\mathrm{sin}\left(\mathrm{a}\right)}^{2}+{\mathrm{cos}\left(\mathrm{a}\right)}^{2}-1\right)\mathrm{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(\mathrm{f}\right)\right),\mathrm{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)
 > $\mathrm{f}:=\left({\mathrm{sin}\left(\mathrm{a}\right)}^{2}+{\mathrm{cos}\left(\mathrm{a}\right)}^{2}-1\right)\mathrm{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(\mathrm{f}\right),\mathrm{x}\right);$
 ${0}$ (2.10)