4
$\begingroup$

I have found no way to define the domain of Irrational numbers. I can easily define a test to see if a number is irrational by defining:

IrrationalQ[z_] := Element[z, Reals] && ! Element[z, Rationals]

IrrationalQ /@ Sqrt /@ Range[10]    
{False, True, True, False, True, True, True, True, False, True}

My question is how can I define a domain that would work with Element, something like

Element[Sqrt[2], Irrationals]

I am aware that the documentation list possible domains as Booleans, Complexes, Integers, Primes, Rationals, Reals, but it is not clear to me if that list is exclusive or not.

$\endgroup$
1
  • $\begingroup$ @Ymareth your very small edit got accepted, in part by me (because I forgot that my vote alone was not enough). Of course it is nice to have a good title, but please do not suggest edits that are too small. You can read about this on meta $\endgroup$ Feb 12, 2014 at 14:58

2 Answers 2

5
$\begingroup$

Here's another way, using TagSetDelayed:

Irrationals /: Element[x_, Irrationals] := 
  Element[x, Reals] && ! Element[x, Rationals];

Element[Sqrt[2], Irrationals]
(*
  True
*)

This should work for elementary calculation. However, I don't think there is way to fully incorporate Irrationals as a domain into Mathematica (e.g., into Reduce[expr, vars, domain] or Solve). Note also that the predicate

Element[x, Reals] && ! Element[x, Rationals];

does not evaluate to True or False with approximate numbers (obviously, perhaps) and that algorithms that use numeric heuristics might be unreliable or simply be bypassed.

(I suspect that the domain is used in most cases to choose an algorithm. The standard domains are what they are because so much work over the centuries has gone into developing algorithms for them.)

$\endgroup$
4
$\begingroup$

You are almost there:

Unprotect[Element];
Element[x_, Irrationals] := Element[x, Reals] && ! Element[x, Rationals];

Sqrt[2] \[Element] Irrationals
True
$\endgroup$
1
  • $\begingroup$ I was not aware at all of the ability to Unprotect. Thanks so much! $\endgroup$
    – rhermans
    Feb 12, 2014 at 12:37

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.