Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: Matching Or expressions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg72259] Re: [mg72250] Matching Or expressions
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sun, 17 Dec 2006 06:19:59 -0500 (EST)
  • References: <200612161018.FAA12216@smc.vnet.net>

On 16 Dec 2006, at 19:18, Johan Grönqvist wrote:

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


Note that:


Or[_]
_

So  MatchQ[And[p,q],Or[_]] evaluates to MatchQ[And[p,q],_] and, not  
surprisingly, this in turn evaluates to True. All you need to do is:


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

False

and your problem is gone.

Andrzej Kozlowski


  • Prev by Date: Problems with Set, SetDelayed and replacement rules...
  • Next by Date: RE: Re: Combinatorica parameters
  • Previous by thread: Matching Or expressions
  • Next by thread: Re: Matching Or expressions