f1[x_] := IntegerQ[x]
f2[x_] := Element[x, Integers]
Both functions give identical results in everything except for such case:
f1[4.]
(*False*)
f2[4.]
(*4. \[Element] Integers*)
Any idea why?
Thanks
f1[x_] := IntegerQ[x]
f2[x_] := Element[x, Integers]
Both functions give identical results in everything except for such case:
f1[4.]
(*False*)
f2[4.]
(*4. \[Element] Integers*)
Any idea why?
Thanks
IntegerQ is meant for programming and tests for a data type, not whether something is mathematically an integer.
Element is meant to represent a mathematical concept.
The two are not interchangeable.
Functions ending in ...Q always return True or False. Since the data type of x is not Integer (in the programming sense---it's a symbol), IntegerQ[x] returns False.
4.0, 4, 4/1, 8/2, etc. are different representations of the same mathematical concept, the number four, which is a member of Z. Element tests mathematical set-inclusion while IntegerQ checks if the argument is "structurally" represented in Mathematica as an Integer type or not.
– István Zachar
Jan 04 '15 at 10:29
IntegerQ. "IntegerQ[expr]returnsFalseunless expr is manifestly an integer (i.e. has headInteger).Simplify[expr\[Element]Integers]can be used to try to determine whether an expression is mathematically equal to an integer." – Mark Adler Jan 04 '15 at 05:514.is an approximate real number. If you interpret it as4+O($MachineEpsilon), then you can see it may or may not be an exact integer soElementproperly returns unevaluated . – george2079 Jan 05 '15 at 20:13