Is there a fast function "ExactExpressionQ" to test whether an expression is exact vs inexact? I'm looking for something like ExactNumberQ that works for expressions.
My attempt at this is
ExactExpressionQ[expr_] := FreeQ[expr, _Real|_Complex?InexactNumberQ]
ExactExpressionQ[0]
ExactExpressionQ[0.]
ExactExpressionQ[(2.1 + I) x]
ExactExpressionQ[Sin[x]]
(* True *)
(* False *)
(* False *)
(* True *)
Is there something better?
Floor[1.4*x]is treated as inexact? I thinkFlooralways produces exact integers if given numbers, whether exact or inexact. – Marius Ladegård Meyer Jun 04 '16 at 13:42ExactExpressionQtests whether the input expression is literally exact or not. – QuantumDot Jun 04 '16 at 14:07Complexcan head an exact number. Have to peek inside... – John Doty Jun 04 '16 at 14:28ExactExpressionQ[expr_] := FreeQ[expr, _?InexactNumberQ]– Bob Hanlon Jun 04 '16 at 14:29expr, whereas what I have PatternTests only if there is something with headComplex. – QuantumDot Jun 04 '16 at 14:35True(worst case), and I'm finding what I have so far is between 2 and 8 times faster. – QuantumDot Jun 04 '16 at 14:40-1would help and still give the desired result. (Can't test here though). – george2079 Jun 04 '16 at 15:06{-1}improves speed by factor 2. – QuantumDot Jun 04 '16 at 15:24