Questions about Mathematica's predicate functions.

learn more… | top users | synonyms

0
votes
0answers
40 views

Testing if a character is a whitespace [closed]

Is it possible to define a function which returns true if its only argument is a whitespace character (space, tab, newline, ecc...), false otherwise? I tried with various testing functions on the ...
4
votes
1answer
47 views

Using ValueQ to test whether “hash” key exists fails when key is given as variable

Please ignore ^^^ possible duplicate (raised by me). The solution doesn't cover my case. I'm trying to implement a simple hash table according to this top answer at "Is there HashTable structure in ...
4
votes
1answer
37 views

Testing for nontrivial evaluation

How can I tell programmatically if a function has evaluated in a nontrivial way? I'd like to do, essentially, something along the lines of f[x]===HoldForm[f[x]], a ...
11
votes
1answer
245 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 ...
9
votes
2answers
211 views

Test for non-numeric variables

I have a table, testdata, with numeric and non-numeric data. testData = {{1, 2, 3, no, 5}, {5, 6, 7, 8, 9.1}, {1, y, y, n, n}}; I can locate the positions of ...
-3
votes
1answer
60 views

Expression in mathematica [closed]

i have an expression: n*Subscript[e,3] Subscript[e,4] Subscript[e,7]...*Subscript[e,k]*Subscript[e,k] I would evaluate it such as return n*Subscript[e,3*4*k*k+1] ...
5
votes
2answers
135 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 ...
6
votes
1answer
61 views

Configurable tolerance for numerical equality?

In standard C++ the double values for 1. + 1.2*^-16 and 1. are not considered equal. But in Mathematica, I get the following: ...
9
votes
1answer
108 views

UnitaryMatrixQ function not returning true for a unitary matrix

So I know this matrix is unitary. It's a well proven fact in quantum mechanics and you can even check for yourself on pen and paper, Heres a quick proof: Assume $H$ is hermitian (i.e. $H^\dagger=H$) ...
6
votes
2answers
267 views

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 ...
6
votes
1answer
87 views

Faster square test for integers

This question was asked already in Jan '12 and the most recent answer is from Oct '12, so it's several Mathematica versions out of date. What is a faster test for whether an integer is a perfect ...
1
vote
1answer
74 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 ...
10
votes
1answer
518 views

Difficulty understanding difference between == and ===

After doing this: ...
11
votes
1answer
155 views

ValueQ returns false positive for one argument type only

I'm seeing some perplexing behavior from ValueQ in 10.3. Consider: ...
4
votes
4answers
335 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: ...
4
votes
1answer
65 views

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 ...
14
votes
1answer
158 views

IsomorphicGraphQ fails to recognize that two empty graphs are identical

Bug introduced in 9.0.1 or earlier and persisting through 10.4.0 Consider the following two graphs: ...
0
votes
2answers
42 views

Equality of expressions containing complex numbers [closed]

I am using Mathematica to test the equivalence of symbolic expressions. I run into what appears to be a bug when I test the equivalence of expressions involving an imaginary number taken to a complex ...
6
votes
1answer
98 views

SameQ for unsorted lists

I have to compare two or more lists and check if they are the same, but their elements can be in different position. For instance ...
5
votes
2answers
212 views

ParallelMemberQ

I tried to make a parallel version of MemberQ for use with a large list, but failed miserably in terms of performance. I used Partition to subdivide the list and ParallelMap to perform the MemberQ ...
25
votes
1answer
301 views

Does Mathematica store hidden information for matrix objects?

Bug introduced in 10.0 and fixed in 10.2.0 I found a case where calling one built-in function (HermitianMatrixQ) for a given matrix changes the behavior of ...
3
votes
1answer
197 views

Nested If statement with unevaluated arguments

I have a list of boolean functions {f1, f2, f3, ...} that take a value and return True or ...
13
votes
1answer
211 views

Unexpected slowness checking for empty list?

I thought I had a firm understanding of the differences between Equal and SameQ, but this has me puzzled: ...
6
votes
6answers
522 views

Determine if all the zeros in a list occur at the end

I have a collection of (short) lists of nonnegative integers. For each, I would like a predicate that decides if all of the zeros in the list appear at the end. For example, ...
1
vote
1answer
85 views

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 ...
0
votes
0answers
33 views

Testing for a vector of all reals [duplicate]

I want to test if an expression is a vector of all reals. I defined RealVector[expr_]:=VectorQ[expr,NumberQ[#]&&(Head[#]===Real)]; Trying this on ...
1
vote
1answer
186 views

How to properly apply NumericQ or s.th. similar here? - NDSolve inside NMaximize

I wrote a function that numerically solves a given Schrodinger equation and returns replacement rules to obtain the time evolution operator. It looks and is used as follows: ...
1
vote
1answer
233 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: ...
0
votes
1answer
66 views

How to use MemberQ for such Variables?

This is NOT the desired out come. I want this test to fail: ...
1
vote
1answer
138 views

How to determine if directories with executable permission and not

I have some directories that have the UNIX executable permission some does not. What tests could I write in Mathematica to test it?
2
votes
1answer
137 views

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: ...
17
votes
1answer
195 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 ...
14
votes
2answers
515 views

Better way to test that a matrix is upper-triangular?

Today, I got to thinking about how to test that a matrix was upper-triangular. So I had a try at it. Algorithm $\quad \quad a_{ij}=0 $ Or $i \leq j$ $\Rightarrow$ $True$ My solution is ...
8
votes
2answers
253 views

TrueQ returning False on true statement

Why does TrueQ return False on the following? TrueQ[Log[2]/Log[8] == 1/3] (* False *) ...
3
votes
1answer
175 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 ...
9
votes
0answers
158 views

Bug in PositiveDefiniteMatrixQ?

Fixed in 10.1.0. Exists in at least 9.0.1 -- 10.0.2. This seems like a bug in PositiveDefiniteMatrixQ to me: ...
2
votes
2answers
255 views

Sum with IntegerQ does not converge

Why does Mathematica return: Sum::div: Sum does not converge. >> when I input: ...
3
votes
2answers
220 views

Finding similar expressions in list

I have a function that returns to me lists of expressions, like: ...
2
votes
2answers
133 views

Testing for arbitrary algebraic expression in given variable

I want to test, for example with MatchQ, if the argument of a function is an arbitrary expression in a single or several variables whose names can be assumed to be ...
7
votes
3answers
169 views

Checking through an expression

I am writing a code that manipulates expressions that contains functions with an arbitrary number of arguments. An example expression is ...
7
votes
1answer
135 views

Mystery with ValueQ

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

Why does PolynomialQ[x^n, x] return False?

From what I can see PolynomialQ will return False whenever some exponent is another variable such as here: ...
7
votes
5answers
4k 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 ...
1
vote
2answers
668 views

Faster way to test if an expression equals zero

I want to test if expressions (mix of variables, functions and numbers) are zero valued, as fast as possible, and PossibleZeroQ is sometimes very slow. One solution ...
1
vote
2answers
571 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 ...
12
votes
2answers
196 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. ...
4
votes
1answer
153 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 ...
4
votes
1answer
374 views

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

The documentation for PossibleZeroQ says: With the setting Method...
2
votes
1answer
282 views

How to work with the symbol EndOfFile? [duplicate]

How to work with the symbol EndOfFile? I want to use the EndOfFile symbol to determine when my control structure reaches the end ...
17
votes
6answers
4k 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 ...