Questions tagged [expression-test]

Questions about Mathematica's predicate functions.

Filter by
Sorted by
Tagged with
5
votes
2answers
238 views

How do I check if proportion of values in list are mostly positive?

I'd like to return a a boolean variable that tells me whether numbers in a list are mostly positive. For example: a = {3,2,3,4,-1,-2,-5,3} There are 5 ...
7
votes
4answers
572 views

how to write a condition for all elements of a list

I have a list a={no,no,no,no}; now I can want to an If so that if all elements of the above list are "yes" it does something ...
6
votes
1answer
147 views

when two associations are equal?

<|a -> 2, b -> 3|> == <|b -> 3, a -> 2|> returns False; can anybody explain why? If I am not mistaken ...
0
votes
0answers
75 views

PolynomialQ always yields True?

I have a question about the PolynomialQ function in Mathematica. I have the polynomial (this is the Chebyshev's polynomial of the first kind) $$B=\frac{1}{2} ([x - \sqrt{(-1 + x^2)}]^n + [x + \sqrt{[-...
21
votes
8answers
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.
0
votes
2answers
130 views

Specifying that function argument is positive

Struggling with something basic. Suppose when defining f[x_] the outcome depends on Sign[x]. When calling this function, how do I tell Mathematica the sign of the argument? My attempt: ...
1
vote
1answer
56 views

TrueQ returning False on true, non-numerical statement

I'm trying to test the following logical statement: state = {{1,1,1}}; Or[state != 0, state != Null] but it's returning False ...
0
votes
2answers
53 views

Test if function of multiple variables is positive or negative given variable constraints

I have a function of multiple variables (5 to be exact). I would like to know if this function is positive or negative given certain constraints on each of the 5 variables. Here is a simplified ...
1
vote
1answer
47 views

How does one test whether or not an integration has succeeded?

This must be a very simple matter--but how to address it eludes me at the moment. I have a series of integrands--and want to flag whether the symbolic integation has succeeded or not (in order to ...
14
votes
1answer
146 views

Why is IsomorphicGraphQ so very slow (in this instance)

Bug introduced in 10.0 or earlier and persisting through 12.0.0 Can someone explain why the following code does not complete within a reasonable time? ...
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 <...
3
votes
1answer
81 views

How to prove a numerical identity?

Let be a function power function f[s_, r_] := Piecewise[{{s^r, s >= 0}, {0, True}}]; And its convolution ...
0
votes
1answer
36 views

Testing which expression is greater

I have two expressions: expr1 = e^2/(8 + 4*e + e^2) and expr2 = (d^2 - 2*d*e + e^2)/(8 + d^2 - 2*d*2 - 2*d*e + 4*e + e^2) ...
8
votes
4answers
784 views

How to check is there any negative term in a large list?

I want to check if a data set of size $10^{10}$ contains any non-positive elements. Positive[Name of dataset] returns a list of ...
9
votes
1answer
116 views

Ordering real numeric quantities

Suppose I want to have a function (call it NLess) that given two real numeric quantities, a and b, it returns True if a is smaller than b, ignoring precision. Here are some test cases: ...
8
votes
1answer
293 views

Is there a defined priority for pattern matching?

If you define a function g, like so: g[x_?EvenQ] := "even" g[x_?NumberQ] := "number" why will Mathematica always return ...
5
votes
1answer
589 views

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

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

Check if number is irrational/transcendental

Mathematica provides functions to test whether a number is an integer, even or odd, prime, rational, real or complex. However, I could not find any explicit way to determine whether a number is ...
3
votes
3answers
85 views

How to check expression depends on symbol in a particular way

Consider these two expressions: expr1 = a d g[X, c]^2 + e g[X, f] + 3 expr2 = a d g[X, c]^2 + e X + 3 How do I check whether these expressions depend on ...
23
votes
1answer
296 views

Which second arguments is VectorQ/MatrixQ/ArrayQ optimized for?

VectorQ and similar functions (MatrixQ, ArrayQ) treat certain second arguments specially. ...
2
votes
1answer
37 views

Symbolic variable for If argument [duplicate]

i want to realize an if in this way : var=expression; If[var==0, Print[Hello]]; If[var!=0, Print[Hey]]; The system doesn't know if ...
11
votes
2answers
362 views

About shorthand notation for conditional pattern (Paul Wellin “Essentials of Programming in Mathematica”)

I am reading Paul Wellin's "Essentials of Programming in Mathematica". Mr. Wellin wrote the following in his book: There is a convenient shorthand notation for conditional patterns that is ...
17
votes
7answers
1k views

How to check if a vector is an eigenvector of a matrix using mathematica?

Here is a vector $$\begin{pmatrix}i\\7i\\-2\end{pmatrix}$$ Here is a matrix $$\begin{pmatrix}2& i&0\\-i&1&1\\0 &1&0\end{pmatrix}$$ Is there a simple way to determine ...
26
votes
4answers
585 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 ...
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: ...
0
votes
0answers
15 views

I want to extract coefficients of a linear formula. But my code didn't work [duplicate]

I want to extract coefficients of a linear formula and I wrote the following function. But it didn't work. ...
0
votes
2answers
108 views

Create my own `PrimeQ` function [closed]

I want to create my own functions, for example: Functions like IntegerQ,EvenQ and OddQ. My ...
0
votes
0answers
44 views

How to use === with condition?

I have two expressions, and they are same when k is positive and x is non-zero real number. Below code gives me ...
0
votes
0answers
42 views

How to test consistency of two assertions without hacking

Suppose I have a set of assumptions assum = x ∈ Reals && y ∈ Reals and I want to test an assertion like ...
0
votes
1answer
80 views

TrueQ returns False [closed]

I have coefficient of some expansion: Workingexpansion = tau/n - (A tau^2)/(27 n^3) - (B tau^3)/(5832 n^5); CoefficientList[Workingexpansion, tau][[2]] ...
0
votes
1answer
87 views

Trying to generate random even number

I am trying to generate a random even number, and then try to write the list of primes that are composing it as Goldbach conjecture says. It's just a test to learn how to use mathematica, so I would ...
5
votes
0answers
58 views

Testing for membership with Bags?

Is there a faster way to test for membership in an Internal`Bag other than unpacking the whole thing like this? ...
2
votes
2answers
89 views

How to tell whether a character is a letter-like form

Is there any way to programmatically tell whether a given character is a letter or letter-like form (see this reference page for what I mean)? One idea I had was to use ...
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 ...
0
votes
0answers
56 views

How to check if all the entries in columns of a matrix are equal?

Assume we have the following matrix/tensor. How can I test if the column has the same element? 4-6 and 8-9 columns has the same element. $ \left( \begin{array}{cccccccccc} \{2,3\} & \{2,3\} &...
1
vote
2answers
53 views

Make two expressions look alike OR check that they are the same

I would like to compare my Mathematica calulations with the results from a paper. I get: ...
0
votes
1answer
70 views

If ValueQ is buggy, what alternative is there?

The function ValueQ has been irritating me for a while. I can't find its use for anything. Inspect the following: ...
4
votes
2answers
253 views

How does RootOfUnityQ work?

How does Mathematica's RootOfUnityQ function work? That is, how does Mathematica know if a number is a root of unity? Example: Let $x = \frac{1-i \sqrt{2+\sqrt{5}}}{1+i \sqrt{2+\sqrt{5}}}$. Then <...
2
votes
1answer
385 views

problem with testing if two expressions are equal

I have a small problem: I have two expressions: a = (ia*l^3*p0)/(12*ia*l + 6*i*la) b = p0*l^2/(12*(1 + 0.5*i/ia*la/l)) Obviously, they are equal. Just take ...
14
votes
2answers
1k 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 ...
8
votes
2answers
533 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 ...
1
vote
0answers
113 views

Want to know more about _?MatrixQ [closed]

User, @AndrzejKozlowski has uploaded a number of interesting demonstrations to the Wolfram Demonstration Project. I have a particular interest these days in his Pricing a Bermudan Option with the ...
4
votes
2answers
102 views

Condition syntax: “when equal to any of”

I am trying to write a condition clause for a certain expression. I need to pick out the following cases: Mod[x*y, 10] == 8, or Mod[x*y, 10] == 3, or Mod[x*y, 10] == 7. I need to repeat ...
2
votes
1answer
140 views

How to remove symmetries from this list?

First of all, I work with modular arithmetics and the elements of the arithmetics are lists themselves. I recognize two kinds of symmetries - shift and mirroring. We could define shift of a list like ...
1
vote
0answers
59 views

Speed up for SequencePredictorFunction?

From Google Dive: SequencePredictorFunction is here, along with my test data. From pastbin: prediction function and data is here. Using the ...
9
votes
1answer
197 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 ...
10
votes
5answers
758 views

Test if a list is a constant integer multiple of another list

I have a list of lists, and I want to eliminate all the lists that are constant integer multiples of another list. My initial approach was to divide the lists using nested tables. ...
6
votes
2answers
405 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: ...
5
votes
1answer
117 views

PrimitiveMatrixQ?

Is there a simple way to test in Mathematica whether a non-negative square matrix $A$ is primitive? Primitive means that for some positive integer power $k$, all entries of $A^k$ (matrix power) are ...
2
votes
1answer
53 views

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 ...