Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [expression-test]

Questions about Mathematica's predicate functions.

79
votes
11answers
17k views

How to check if a 2D point is in a polygon?

Background: I use code from An Efficient Test For A Point To Be In A Convex Polygon Wolfram Demonstration to check if a point ( mouse pointer ) is in a ( convex ) polygon. Clearly this code fails for ...
11
votes
2answers
2k views

Evaluating an If condition to yield True/False

I would like to decide whether an option passed to my custom function has the value Automatic or something else. This is my attempt: ...
22
votes
2answers
716 views

Implementing a safe ValueQ that does not evaluate its argument

Mathematica has a built-in function ValueQ. Quoting the docs, ValueQ[expr] gives True if ...
21
votes
9answers
3k views

How do you check if there are any equal arguments(even sublist) in a list?

I would like to set up a function which has to return True if at least two arguments of a given List are equal. So if I give {1,4,6,2} to the function it has to ...
27
votes
1answer
3k views

_?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 <...
18
votes
3answers
368 views

How can I test properties of a symbol from the string name without the symbol completely evaluating

Suppose I have a few symbols, one of which has a value: {abc1, abc2 = 5, abc3}; I can use Names to get the list of names, as ...
18
votes
6answers
3k views

Fastest square number test

What is the fastest possible square number test in Mathematica, both for machine size and big integers? I presume starting in version 8 the fastest will be a dedicated C LibraryLink function.
22
votes
6answers
9k views

How to check if an expression is a real-valued number

What is a simple, fast way to test whether an expression is a real-valued number? I ask since there is no RealQ function. If we call this test ...
12
votes
1answer
437 views

Why does Assuming[x > 0, TrueQ[x > 0]] return False?

Assuming[x>0,TrueQ[x>0]] should, as I understand it, test TrueQ[x>0] after assuming ...
21
votes
4answers
1k views

Why does Mathematica claim there is no even prime?

I wonder if this is a bug, or if I'm misunderstanding something: Exists[n, EvenQ[n] && PrimeQ[n]] // Resolve (* ==> False *) So if I interpret this ...
14
votes
1answer
225 views

IsomorphicGraphQ fails to recognize that two empty graphs are identical

Bug introduced in 9.0.1 or earlier and fixed in 11.0.1 Consider the following two graphs: ...
16
votes
2answers
1k views

How do I get Mathematica to return a function call unevaluated?

How do I get Mathematica to return a function call (conditionally) unevaluated? I expect this may use the slightly-mysterious Hold function. As a toy example, ...
8
votes
2answers
454 views

Using OddQ and EvenQ in piecewise functions: Buggy?

I was trying to evaluate a sum over a piecewise function, not unlike this example. However, my piecewise function needed to be defined differently for even and odd ...
9
votes
2answers
584 views

TrueQ returning False on true statement

Why does TrueQ return False on the following? TrueQ[Log[2]/Log[8] == 1/3] (* False *) ...
26
votes
4answers
562 views

Is there a GraphicsPrimitiveQ (or a complete list of Heads of graphics primitives)?

For various reasons related to workflow associated with creating figures for journals, I am creating functions that will accept graphics primitives and a set of options and spit out a ...
18
votes
3answers
3k views

Checking if a point is in a convex 3D polyhedron

Extending from these questions How to check if a 3D point is in a planar polygon? and How to check if a 2D point is in a polygon?. I'm trying to do this to render specific shapes made up of spheres. ...
14
votes
2answers
956 views

Checking if a word exists

Probably the simplest way to check a word if it exists is to use DictionaryWordQ[] DictionaryWordQ["color"] True But it ...
13
votes
2answers
229 views

How can one write a robust ListableQ function?

I would like to have a test that determines if a particular function is Listable. In the case of Symbols this is merely a matter of checking Attributes. ...
20
votes
2answers
3k views

Determine whether some expression contains a given symbol

Given a symbol t and an expression expr, how can I determine whether or not the symbol t ...
9
votes
5answers
14k views

How to detect if a sequence of integers is consecutive

I'm not a math-guy really (a programmer actually) and this is my first question. And excuse me if I can not explain my problem good. The problem is I have a sequence of integers and I want to detect ...
9
votes
2answers
626 views

How does Mathematica decide that Log[2,8] is integer?

At school we learned that $\log_b(x)=\log(x)/\log(b)$, which is implemented in Mathematica as Log[b, x], but the results are different. ...
3
votes
1answer
262 views

Why does pattern test not work in this case to restrict the function parameters?

I was looking at this Q&A about using pattern test (pattern_?test) vs pattern condition (pattern_/;cond) and came across ...
8
votes
1answer
172 views

Can anyone guess what Internal`RadicalMemberQ does?

There is an undocumented function Internal`RadicalMemberQ which takes two arguments. But whatever input I try for the two arguments, it seems to crash the kernel (...
17
votes
1answer
222 views

A bug in the overloading of MemberQ and FreeQ for Association?

Bug introduced in 10.0.0 and fixed in 10.1.0. While answering Pattern match for nested Association I came across behavior of MemberQ and ...
6
votes
5answers
839 views

Checking if all the variables are present in the defined function

I want to check if a user input the function with all the specified variables or not. For that I choose the replace variables with some values and check for if the result is a number or not via a ...
5
votes
1answer
578 views

How to check if a given expression is an “explicit algebraic number”?

The documentation for PossibleZeroQ says: With the setting Method->"ExactAlgebraics"...
5
votes
4answers
374 views

Picking points in a plane under a curve given by a list

Suppose that I have a set of points in a plane, which range from $x\in [0,20]$ and $y\in[0,10]$, and a curve given by a list of points in the same region: ...
2
votes
1answer
399 views

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: ...
12
votes
1answer
443 views

Why is an empty list not tested by VectorQ?

I am a bit amazed by this behavior of VectorQ[ expr, test ]: VectorQ[ {}, NumberQ ] True It seems that the test itself is ...
10
votes
1answer
590 views

Difficulty understanding difference between == and ===

After doing this: ...
4
votes
1answer
207 views

How can I test properties of a symbol without unwanted evaluation

Problem How to get the head, size, dimensions, etc. of a symbol without evaluating it? Since Mathematica does not allocate fix storage space and type to symbols it is not trivial to query runtime ...
2
votes
1answer
105 views

Are UnsamQ and Not[SameQ] the same function? [closed]

Why are the following functions a[x___] := If[ UnsameQ[x, Null], 1, 2, 3] b[x___] := If[ Not[SameQ[x, Null]], 1, 2, 3] different? For example ...
22
votes
2answers
1k views

Why no RationalQ or RealQ?

Interesting pattern came up as I go through the homework replies of my students. Why is there no RationalQ or RealQ? We have <...
12
votes
1answer
220 views

ValueQ returns false positive for one argument type only

I'm seeing some perplexing behavior from ValueQ in 10.3. Consider: ...
9
votes
1answer
187 views

1 is not the SameQ as Null, but why might 1 be Equal to Null?

The command SameQ[1, Null] returns False which is what I would expect, but the command ...
7
votes
1answer
142 views

Mystery with ValueQ

Consider the following ClearAll[jd]; ValueQ[jd] We expect False and get it. Now consider ...
6
votes
2answers
3k views

Difference between != and =!=

I (think I) understand the difference between == (semantic) and === (syntactic). So when comparing != and =!= I was expecting a similar difference. So can anyone explain why the third line in this ...
6
votes
1answer
166 views

How to test if a GeoPosition is inside a geographic Polygon?

I have tried the following: ...
5
votes
2answers
508 views

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 ...
5
votes
1answer
126 views

Can I make IsomorphicGraphQ consider other properties besides the EdgeRules?

Consider two graphs, which are isomorphic to each other based on the vertices and edges, ...
2
votes
2answers
439 views

Sum with IntegerQ does not converge

Why does Mathematica return: Sum::div: Sum does not converge. >> when I input: ...
2
votes
1answer
172 views

Can I make NumericQ Listable? Why isn't there an Option to test in ListQ?

I have a function which takes lists as arguments. But it shall be evaluated only, if the elements in the lists are all numeric. Otherwise I want the function to remain unevaluated. There is a ...
2
votes
2answers
1k views

How to pick a solution from a list of solutions using a test?

I have a list of solutions that depends on a parameter b3 and I'd like to get the solution for which the x value is minimal when ...
1
vote
1answer
552 views

Count number of summands?

Consider fun = a+b+c+d/e If we want to get the number of summands, we can use Length[fun], which properly gives ...