MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Matching Or expressions

  • To: mathgroup at
  • Subject: [mg72275] RE: [mg72250] Matching Or expressions
  • From: "David Park" <djmp at>
  • Date: Sun, 17 Dec 2006 06:20:37 -0500 (EST)


The short answer is that you want to use HoldPattern[Or[_]].

MatchQ[And[p, q], HoldPattern[Or[_]]]

The reason is that MatchQ evaluates its arguments.

x              and

_		   which is a pattern that will match anything!

David Park
djmp at

From: Johan Grönqvist [mailto:johan.gronqvist at]

The context of my problem is explained below.

I wish to distinguish expressions of the form And[p,q] from those of the
form Or[p,q], but the only thing I find is
MatchQ[myExpr, Or[_]]
and to my surprise I see that MatchQ[And[p,q],Or[_]] is True. Thus I can
not use this to match only the Or-expressions.



The context is as follows:

I wish to find the number of solutions to a  diophantine equation with a
finite number of solutions.

I do the following
sols = Reduce[eqns, vars, Integers]
and this gives me an expression that normally looks like Or[_,_,_] if
there are several solutions, or something else if there are not.

Now I wish to find the number of solutions using
Which[MatchQ[sols, Or[_]], Length[sols], DoOtherStuff]

The problem is that the MatchQ[ expr, Or[_] ] also matches e.g. (x==2 &&
y==4), which is only one solution.

  • Prev by Date: Re: Complex Numbers to list of points
  • Next by Date: Re: Matching Or expressions
  • Previous by thread: Re: Matching Or expressions
  • Next by thread: Re: Matching Or expressions