Questions tagged [expression-test]

Questions about Mathematica's predicate functions.

Questions about Mathematica's predicate functions, usually ending with Q (indicating "question"). These functions test the input expression whether it fits the condition defined by the predicate function. These functions can test numerical properties (Negative, Positive, OddQ, etc.), equality/identity/relation (Equal, SameQ, LessEqual, etc.), data types (NumericQ, IntegerQ, StringQ, SymbolQ, etc.), and general expressions (TrueQ, AtomQ, etc.).

Useful links

Example question

203 questions
32
votes
1 answer

_?NumericQ equivalent for lists

A few months ago I got a simple answer (see: 1 ) to the question of how to force numeric evaluation during use of functions such as NMinimize[] - namely the use of _?NumericQ in the argument list. I now have the same problem, only this time the…
Cuboid
  • 1,421
  • 11
  • 15
11
votes
1 answer

How am I misusing EvenQ, or, how are EvenQ and (Mod[2,#]==0)& differently evaluated?

While working on a problem, I was using EvenQ in a RegionPlot. I came across this interesting case (simplified here for specificity). I expected to see a bunch of stripes, but got nothing: RegionPlot[EvenQ[Floor[x]],{x,0,10},{y,0,10}] However,…
Piquan
  • 476
  • 2
  • 10
7
votes
2 answers

How to test whether a function is positive over the entire range of an interval?

I would like to test whether a function is positive over a given interval. Say I have f[x_] = -x^3 + x^2 + 7*x and wanted to know whether it is positive for all x in the interval [0,4]? It can easily seen by plotting the function that it is not, but…
m.user
  • 309
  • 2
  • 6
6
votes
1 answer

Rapidly testing for exact vs. inexact expressions

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,…
QuantumDot
  • 19,601
  • 7
  • 45
  • 121
5
votes
2 answers

Why is an integer not considered as a real?

Please consider the following: zeros={0.,0}; data={1, 0., 0}; DeleteCases[data, #]&/@zeros Head/@zeros (*{Real, Integer}*) (*{{1, 0}, {1, 0.}}*) For my understanding all integers (e.g. 0, 2) are element of the real numbers (e.g. 0.00000,…
John
  • 4,361
  • 1
  • 26
  • 41
5
votes
1 answer

lists of conditions

I have got coordinates in two list of Latitude and Longitude and would like to check if those coordinates are in a certain grid Example lists are: qLon={-7.48333, -10.4667, -8.66667, -7.48333} qLat={53.5, 52.5, 53.1167, 51.9833, 51.0167} Grid…
Khali
  • 53
  • 2
4
votes
1 answer

Can Mathematica point out why it thinks two symbolic expressions are different?

SameQ checks to see if symbolic expressions are the same. There are some caveats, as pointed out by the answers to: Understanding SameQ What is the proper way to verify that two expressions are equivalent? Consider the following two expressions: s…
bzm3r
  • 175
  • 7
4
votes
3 answers

How to check that these triangles are exactly the same triangle?

I have $6$ triangle: tris = Triangle/@Permutations[{{0,0,0},{1,0,0},{0,1,1}}] They are in every sense the same triangle. But how to check that these triangles are exactly the same triangle? And I note Equal @@ tris and SameQ @@ tris both cannot do…
yode
  • 26,686
  • 4
  • 62
  • 167
3
votes
1 answer

Understanding SameQ

I am new to Mathematica. So I have read the documentation for comparing expressions in Mathematica and I still don't get the SameQ (===) function. Let me give you a short example: 2+2 === 4 True Log[x*x] === 2*Log[x] False I hope I'm not seeing…
drabus
  • 427
  • 3
  • 9
3
votes
2 answers

Test if two or more elements are in a list

I have a list of two-element lists {{a,b},{c,d},{x,y}} I can use MemberQ to test if one of these lists is present, for example In[54]:= MemberQ[{{a, b}, {c, d}, {x, y}}, {c, d}] Out[54]= True I would like to test if at least two of the lists…
Okazaki
  • 257
  • 1
  • 7
2
votes
1 answer

IntegerQ and Element Integers give different results in one case

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
Basheer Algohi
  • 19,917
  • 1
  • 31
  • 78
2
votes
1 answer

Misuse of Equal and Unequal to test equality of colors

Start with: b = Blue; r = Red; According to the docs, one should use Equal (==) and Unequal (!=) only for testing equality of such things as numeric objects and string objects; and one should use SameQ (===) and UnsameQ (=!=) otherwise. So as…
murray
  • 11,888
  • 2
  • 26
  • 50
2
votes
1 answer

How to work with the symbol EndOfFile?

How to work with the symbol EndOfFile? I want to use the EndOfFile symbol to determine when my control structure reaches the end of a file. Case 1: suppose we reach the end of file while continuously reading numbers from it. Which correctly returns…
2
votes
1 answer

compare some functions

Assume that I have three function: sum1[n_] := Sum[Cos[k/n], {k, 0, n}] sum2[n_] := Sum[Sin[k/n], {k, 0, 2n}] sum3[n_] := Sum[Cos[k + 1/2n], {k, 0, 2n - 1}] For each $n<100$, how can I compare these three function? For example Mathematica tells me…
A. Mpi
  • 429
  • 2
  • 7
1
vote
1 answer

Sign of expression with several parameters

Briefly (with thank to all reader) Want to determine the sign in the interval $[0,1]$ of the expression $$ b (p-1) x^{-p}-\gamma +\eta _1 k_0+\frac{\beta _0 \left(\eta _1+\eta _2-1\right) (n-1) x^n}{\left(x^n+1\right)^2}+\frac{\beta _0…
Zbigniew
  • 411
  • 1
  • 4
  • 12
1
2