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.

3
votes
1answer
69 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
29 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
694 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 ...
12
votes
1answer
120 views

Why is IsomorphicGraphQ so very slow (in this instance)

Can someone explain why the following code does not complete within a reasonable time? ...
8
votes
1answer
284 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 ...
3
votes
3answers
76 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
293 views

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

VectorQ and similar functions (MatrixQ, ArrayQ) treat certain second arguments specially. ...
2
votes
1answer
33 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
344 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 ...
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
0answers
42 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 ...
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 <...
0
votes
0answers
22 views

Why doesn't Head[expression] == Real serve as a test for expression being Real? [duplicate]

Although Head[expression] == Real seems to return True whenever expression is a Real, it does not return ...
0
votes
2answers
105 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
40 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
75 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
83 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
56 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
78 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 ...
0
votes
0answers
51 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
52 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
67 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: ...
1
vote
1answer
294 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
910 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 ...
4
votes
2answers
279 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 ...
1
vote
0answers
102 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 ...
16
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 ...
1
vote
0answers
52 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
185 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
741 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. ...
2
votes
1answer
52 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 ...
1
vote
2answers
49 views

Simplifying tests on a random set

I would like to simplify: ...
1
vote
1answer
114 views

Simplify nested If into a loop

I would like to simplify a set of tests (meant to be applied on a random set of parameters), written for now as nested If: ...
6
votes
1answer
83 views

TagSet for symbol inside NumericQ behaves differently than in other fooQ functions

I am trying to define some symbols as being numeric by using TagSet and encountered the following different behaviors between NumericQ and e.g. ...
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 ...
4
votes
2answers
99 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 ...
3
votes
2answers
143 views

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 ...
5
votes
2answers
159 views

RegionMember with geographical data

I'm trying to be able to calculate whether a coordinate is within a census tract. As an example, here's a particular census tract in Chicago defined as a set of polygon vertices: ...
5
votes
1answer
149 views

How to judge if two Dataset are equal

I don's sure this is a bug or not.Suppose I have a dataset ...
5
votes
1answer
112 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 ...
3
votes
2answers
84 views

FullSimplify yields different output with exact and decimal input

I'm trying to define a predicate function to identify if the expression is a geometric sequence. This is the function I came up with so far: ...
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 ...
5
votes
0answers
52 views

Optional in MatchQ [duplicate]

Why isn't the first one True in: ...
0
votes
2answers
72 views

SameQ shorthand [closed]

I thought that === is shorthand for SameQ? Then why do these two expressions yield True for one and False for the other? ...
5
votes
4answers
214 views

Determine whether some expression contains a symbol doing nothing?

I have expression like this: expr = xuyz; then Head[expr] = xuyz But I wanted the product of four factors, so it should ...
3
votes
1answer
131 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 ...
0
votes
2answers
64 views

f'[x] not the same as D[f[x],x]?! (Problems with Plotting..) [duplicate]

I have a very strange problem I'm sure I haven't had before, but I'm new to Mathematica, so maybe I'm just tired and can't see the obvious. The Problem is, that for some reason Plot[] won't work with ...
0
votes
1answer
101 views

Which condition?

I want to substitute integers in a list with theirs square, I tried these ...
8
votes
2answers
1k views

A hack for aggressive type-checking?

I tend to like programming in a style where I can be very explicit about the types of expressions. While Mathematica isn't and shouldn't be a strongly-typed language like Haskell, I think it would ...
2
votes
0answers
113 views

How to test solvability of a Diophantine equation?

When applying the BRC theorem I need to test if an equation has a non-zero solution in integers. The equation is of form: $$x^2 + by^2 + cz^2 = 0$$ We could try to directly check if this equation ...