Questions about Mathematica's predicate functions.

learn more… | top users | synonyms

2
votes
1answer
119 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: ...
9
votes
2answers
565 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. ...
10
votes
1answer
92 views

IsomorphicGraphQ fails to recognize that two empty graphs are identical

Bug introduced in 9.0.1 or earlier and persisting through 10.2.0 Consider the following two graphs: ...
25
votes
1answer
275 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 ...
0
votes
2answers
37 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
91 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 ...
16
votes
1answer
181 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 ...
13
votes
1answer
169 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: ...
20
votes
4answers
844 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 ...
2
votes
1answer
122 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 ...
6
votes
6answers
519 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
60 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 ...
1
vote
1answer
111 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: ...
0
votes
0answers
31 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
185 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
60 views

How to use MemberQ for such Variables?

This is NOT the desired out come. I want this test to fail: ...
0
votes
1answer
111 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?
14
votes
2answers
468 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 ...
1
vote
2answers
592 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 ...
3
votes
1answer
133 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 ...
3
votes
2answers
202 views

Finding similar expressions in list

I have a function that returns to me lists of expressions, like: ...
2
votes
2answers
124 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
165 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 ...
4
votes
1answer
135 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 ...
6
votes
2answers
263 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: ...
15
votes
5answers
3k 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 ...
1
vote
2answers
407 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
187 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. ...
18
votes
9answers
1k 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 ...
14
votes
3answers
264 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 ...
20
votes
2answers
508 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 ...
4
votes
1answer
327 views
16
votes
1answer
812 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 _?NumericQ in the argument list. I ...
2
votes
1answer
219 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 ...
15
votes
5answers
2k views

Fastest square number test

What is the fastest possible square number test in Mathematica 7, both for machine size and big integers? I presume in version 8 the fastest will be a dedicated C LibraryLink function.
5
votes
2answers
365 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
153 views

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: ...
0
votes
1answer
63 views

What is the most elegant way to see if an expression is affected by a certain symbol? [duplicate]

Possible Duplicate: Determine whether some expression contains a given symbol Let's say I have some expression: sample = {1, 1/q, f[m]} And I want to ...
2
votes
2answers
135 views

Using FreeQ with implicit functions

In Mathematica 7, I want to determine whether a list of free of numbers greater than 1 or not. It seems like using FreeQ would be a concise way to do this: ...
11
votes
1answer
308 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 ...