2
$\begingroup$

I am wondering if it is possible to get domain and codomain of a function in Mathematica (by using only built-in functions if possible). For example, I would like to give as input the function $tan(x)$ and to obtain the output "domain" $x \neq \frac{\pi}{2} + k \, \pi $ with $k$ integer, and "codomain" $R$.

Thank you so much for your willingness.

$\endgroup$

1 Answer 1

3
$\begingroup$

You can use FunctionDomain and FunctionRange:

FunctionDomain[Tan[x], x]

1/2 + x/π ∉ Integers

FunctionRange[Tan[x],x,y]

True

FunctionRange[Sin[x], x, y]

-1 <= y <= 1

Update on questions in comments:

  • how the answer $1/2 + x/π ∉ \mathbb{Z}$ is related to the right result $ x ≠ π / 2 + k π $?

The two expressions are equivalent: Move $\pi/2$ to the lhs and divide both sides of the second expression by $\pi$ to get $ x/π - 1/2 ≠ k $ ($k$ integer).

  • Why does Mathematica return the first expression (not the second) as the answer?

The first one is simpler by LeafCount:

1/2 + x/π ∉ Integers // LeafCount

11

ForAll[k, Element[k, Integers], x != k + π/2] // LeafCount

14

$\endgroup$
7
  • $\begingroup$ Hello @kglr thank you for your extremely clear reply. True means R or C? $\endgroup$ Nov 8, 2018 at 8:48
  • $\begingroup$ @Gennaro, my pleasure. Thank you for the accept. $\endgroup$
    – kglr
    Nov 8, 2018 at 8:49
  • 1
    $\begingroup$ True means R or C? $\endgroup$ Nov 8, 2018 at 8:50
  • $\begingroup$ @GennaroArguzzi, i think it means Reals. $\endgroup$
    – kglr
    Nov 8, 2018 at 9:08
  • $\begingroup$ Hi @kglr, I have another doubt: how the answer 1/2 + x/π ∉ Integers is related to the right result $x \neq \frac{\pi}{2} + k \, \pi$? $\endgroup$ Nov 10, 2018 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.