Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
    
@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 at 14:58
add comment

2 Answers 2

up vote 4 down vote accepted

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

share|improve this answer
add comment

You are almost there:

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

Sqrt[2] \[Element] Irrationals
True
share|improve this answer
    
I was not aware at all of the ability to Unprotect. Thanks so much! –  rhermans Feb 12 at 12:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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