NonNegativeQ

Stephan Kaufmann

The function NonNegativeQ tries to find out if expressions can not be negative.

Reference

Author

Stephan Kaufmann
Institute of Mechanics
Swiss Federal Institute of Technology
ETH Zentrum, HG F38.4 
CH-8092 Zuerich
Switzerland
kaufmann@ifm.ethz.ch

Copyright Notice

Copyright © 1992 by Stephan Kaufmann

Permission is hereby granted to make copies of	this file for any purpose other than direct profit,	or as part of a commercial product, provided this copyright notice is left intact.	Sale is prohibited.
	
Permission is hereby granted to reproduce part or all of this file provided that the source is acknowledged.

Version

Notebook Version 2.2 (E)

History

Changes in Version 2.2 (August 93):
Completely rewritten in a more efficient way

Requirements

Mathematica Version: 2.0 or higher.

If[$VersionNumber < 2.0, Print[
  "This package requires Mathematica version 2.0 or higher."]]

Restriction

The function NonNegativeQ, defined in this package, does not attempt to be complete.

Discussion

Idea

The Mathematica functions Positive, Negative and NonNegative evaluate for numbers only. They can be used to define properties of symbols but for combinations of such symbols, the properties are not evaluated any further, e.g.:

Positive[a] ^= True;

Positive[a^2]

The function NonNegativeQ (defined in this package) tries to find out if the result can not be negative. In such cases, it returns True, otherwise False.

Examples

The symbol a shall be positive:

Positive[a] ^= True;

Then, a^2 is not negative:

NonNegativeQ[a^2]

Nothing is said about b yet:

NonNegativeQ[b]

We now fix it to be non negative:

NonNegativeQ[b] ^= True;

Then, the following product can be evaluated:

NonNegativeQ[a b]

With

Negative[c] ^= True;

it is possible to analyse:

NonNegativeQ[- a b c]

Implementation

Preparation

BeginPackage["SKPackages`NonNegativeQ`"];

Off[General::spell1];

NonNegativeQ::usage =
"NonNegativeQ[expr] returns True if expr is obviously not negative and else False. Properties of symbols can be defined with the functions Positive, NonNegative and Negative (e.g.: x /: Positive[x] = True). Real symbols can be declared by definitions like a /: Im[a] = 0";

On[General::spell1];

Begin["`Private`"];

Definitions

RealTest[x_?AtomQ] := True /; NonNegativeQ[x]

RealTest[x_] := True /; Im[x] == 0 ||
  Positive[x] || NonNegative[x] || Negative[x]

RealTest[x_ + y_] := RealTest[x] && RealTest[y]

RealTest[x_ y_] := RealTest[x] && RealTest[y]

RealTest[x_^_Integer] := RealTest[x]

NonNegativeQ[x_] := True /; Positive[x] || NonNegative[x]

NonNegativeQ[x_?(!AtomQ[#]&)] := NNQ[Factor[x]]

NonNegativeQ[x_] := False

NNQ[x_ y_] := (NNQ[x] && NNQ[y]) || (NNQ[-x] && NNQ[-y]) /;
    x =!= -1 && y =!= -1

NNQ[x_ + y_] := NNQ[x] && NNQ[y]

NNQ[x_^_?OddQ] := NNQ[x] /; RealTest[x]

NNQ[-x_^_?OddQ] := NNQ[-x] /; RealTest[x]

NNQ[x_^_?EvenQ] := True /; RealTest[x]

NNQ[Abs[x_]] := True

NNQ[Sqrt[x_]] := True /; RealTest[x]

NNQ[Exp[x_]] := True /; RealTest[x]

NNQ[-x_] := True /;
  Positive[-x] || NonNegative[-x] || Negative[x]

NNQ[x_] := True /;
  Positive[x] || NonNegative[x] || Negative[-x]

NNQ[x_?AtomQ] := NonNegativeQ[x]

NNQ[x_] := False

Finish

End[];

EndPackage[];