Re: extract from Reduce

• To: mathgroup at smc.vnet.net
• Subject: [mg130361] Re: extract from Reduce
• From: Peter Pein <petsie at dordos.net>
• Date: Thu, 4 Apr 2013 22:32:36 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• Delivered-to: l-mathgroup@wolfram.com
• Delivered-to: mathgroup-newout@smc.vnet.net
• Delivered-to: mathgroup-newsend@smc.vnet.net
• References: <kjkc5k\$7n0\$1@smc.vnet.net>

```Am 04.04.2013 19:10, schrieb hamiltoncycle at gmail.com:
> I have a result from the command Reduce that looks like this (as an example):
>
> a:= x==3||x==4||x==7
>
> I need to extract the numbers but I can't find a nice way to handle the case when there is only one equation, for instance:
>
> a:= x==6
>
> currently I check what the head of the expression is (Head[a]) and handle the case Head[a]=Or with a Map[] and the case Head[a]="Equal" with a[[2]]. Not very nice, but I guess that there is a neat way to do it.
>
> cheers, Robert
>

Hi Robert,

say you've got a quite simple result of Reduce:

In[1]:= InputForm[a = Reduce[Mod[x, 3] == Mod[1 + x^2, 5], x, Integers]]
Out[1]//InputForm=
Element[C[1], Integers] && (x == 3 + 15*C[1] || x == 10 + 15*C[1] ||
x == 11 + 15*C[1] || x == 12 + 15*C[1] || x == 14 + 15*C[1])

then

In[2]:= Cases[LogicalExpand[a] /. And | Or -> List,
HoldPattern[Equal[v___, x, w___]] :> Sequence[v, w],
Infinity] // InputForm
Out[2]//InputForm=
{3 + 15*C[1], 10 + 15*C[1], 11 + 15*C[1], 12 + 15*C[1], 14 + 15*C[1]}

a= x==3||x==4||x==7

Refine[x, #]& /@ List @@ a

would be sufficient to get
{3, 4, 7}

hth,
Peter

```

• Prev by Date: Re: find position in a list made by string by searching incomplete string
• Next by Date: Re: "Displaying" the meaning of zero
• Previous by thread: Re: extract from Reduce
• Next by thread: Re: extract from Reduce