I would like to determine whether a given expression can 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 there any library that can check this for me?
I'm currently writing in JavaScript, but I'm willing to change language if there's no such library for JS, but it's there for other languages.
Using python and its library sympy, there is sympy.calculus.util.continuous_domain.
Output:
Unfortunately, replacing
b = 3
withb = Symbol('b', integer = True)
orb = floor(a)
both result in a spectacular crash offunction_range(d, a, Interval(0,1000))
. You can still get thecontinuous_domain
, but not thefunction_range
.