# How to define the irrational domain or any other arbitrary domain?

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.

-
@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 – Jacob Akkerboom Feb 12 '14 at 14:58

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.)

-

You are almost there:

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

Sqrt[2] \[Element] Irrationals

True

-
I was not aware at all of the ability to Unprotect. Thanks so much! – rhermans Feb 12 '14 at 12:37