Questions tagged [expression-test]

142 questions
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.
45 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 ...
142 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? ...
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 <...
74 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 ...
30 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) ...
708 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 ...
115 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: ...
287 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 ...
578 views

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

The documentation for PossibleZeroQ says: With the setting Method->"ExactAlgebraics"...
292 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 ...
78 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 ...
293 views

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

VectorQ and similar functions (MatrixQ, ArrayQ) treat certain second arguments specially. ...
35 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 ...
349 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 ...
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 ...
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 ...
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: ...
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. ...
106 views

Create my own PrimeQ function [closed]

I want to create my own functions, for example: Functions like IntegerQ,EvenQ and OddQ. My ...
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 ...
23 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 ...
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 ...
78 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][] ...
85 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 ...
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? ...
81 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 ...
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 ...
52 views

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

Simplifying tests on a random set

I would like to simplify: ...
123 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: ...
225 views

...