Determine programmatically whether an expression is always defined

39 Views Asked by At

I would like to determine programmatically whether a given expression is always defined, or if it could have an undefined result.

For instance, take the following computation:

a = rand() * 1000  // a real number >=0 and <1000
b = trunc( a )*2   // an even number between 0 and 1998
c = sin( a )       // a real number >=-1 and <=1
d = pow( c, b )    // a positive real number >=0 and <=1
e = log( a )       // either undefined (-Infinity), or a real number <6.907…
f = sqrt( e )      // either undefined, or a real number >=0 and <2.628…

How can I write a program that tells me that e and f can be undefined, while the others are always defined? Is this even possible?

I asked on StackOverflow (Detect whether an expression could have an undefined result) and would love to find an existing library. Some commenters suggested to post here.

I've tried to approach this using interval arithmetic. That works with a lot of continuous functions, but doesn't work with others. For instance pow(-1, x) requires to know whether x is 0 or a positive even number.

Would you know other ways to approach this problem?