Re: checking the sign of all terms in a long expression
- To: mathgroup at smc.vnet.net
- Subject: [mg132569] Re: checking the sign of all terms in a long expression
- From: Dan siegal-gaskins <dantimatter at gmail.com>
- Date: Sat, 12 Apr 2014 05:16:59 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-outx@smc.vnet.net
- Delivered-to: mathgroup-newsendx@smc.vnet.net
- References: <20140411061009.8DE2B6A30@smc.vnet.net> <6E89E63B-4C08-4CA7-BA0B-ECCB2B06A812@math.umass.edu>
Thanks everyone for the quick responses!
It turns out that some of the terms are multiplied by negative numbers other than -1. This solution worked well:
toCheckv2 = a + a b + a b c + a c - 2 b + bc + d - e f;
Cases[toCheckv2 // ExpandAll, Times[_?Negative, __]]
{-2 b, -e f}
cheers
dan
On Apr 11, 2014, at 7:54 AM, Murray Eisenberg wrote:
> Are the symbols a, b, etc., just symbolic, as you seem to indicate, or might they be actual numeric values, too?
>
> If indeed the symbols a, b, etc. are just symbols and NOT numbers, then the following should help -- but note that Mathematica will automatically rearrange the terms of toCheck into its usual canonical form.
>
> toCheck = a + a b + a b c + a c - b + bc + d - e f
> (* a - b + a b + bc + a c + a b c + d - e f *)
>
> Flatten@Position[List@@toCheck, Times[-1,__]]
> (* {2, 8} *)
>
> If you insist on identifying the "negative" terms by their positions in the original expression, before it is evaluated, then you may want to treat it as a string, and the treatment will be trickier.
>
>
> On Apr 11, 2014, at 2:10 AM, dantimatter <google at dantimatter.com> wrote:
>
>>
>> hello all
>> is there to check the signs of all terms in a symbolic expression, like
>>
>> toCheck = a + a b + a b c + a c - b + bc + d ....
>>
>> in this case, with the assumption that the a, b, c etc are all positive, only one term is negative (b by itself) and the rest are positive. I have expressions like this that have a hundred or more terms and i'm worried i might not be catching all those that are of a different sign.
>>
>> thanks
>>
>
> Murray Eisenberg murray at math.umass.edu
> Mathematics & Statistics Dept.
> Lederle Graduate Research Tower phone 240 246-7240 (H)
> University of Massachusetts
> 710 North Pleasant Street
> Amherst, MA 01003-9305
>
>
>
>
>
>
- References:
- checking the sign of all terms in a long expression
- From: dantimatter <google@dantimatter.com>
- checking the sign of all terms in a long expression