Re: Rearranging terms - user-defined
- To: mathgroup at smc.vnet.net
- Subject: [mg127163] Re: Rearranging terms - user-defined
- From: Alexei Boulbitch <Alexei.Boulbitch at iee.lu>
- Date: Mon, 2 Jul 2012 22:21:12 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
Does anyone know how to tell mathematica the following: I have an expression like: a + bx -by and I want to factorise it like: a + b(x-y) BUT: I want Mathematica to show the difference (x-y) whenever possible (in the different calculations - not just place b outside the bracket). That's because equations are easier to discuss if they are written in a special way. Another example would be: using probabilities, I always want to write mathematica -(1-p) instead of -p+1 throughout the notebook. Sorry, for postig such a beginners question. I know there were similar questions, but it did't help. Thanks a lot! Yes, somebody does. You may do the following with your first expression Expr1 = a + b*x - b*y; First[expr1] + Factor[ Rest[expr1]] a + b (x - y) One may do it shorter using the package "Presentations" of David Park, like follows: expr1 // MapLevelParts[FactorOut[b], {{2, 3}}] a + b (x - y) This package has a number of functions (that are not present in the common Mathematica) that enable you to do such kind of transformations on any expression, but you will need to get the package first. That is what I would advise to do. Concerning your second question, try this: -Map[Minus, -p + 1] 1 - p To have them untransformed through your calculations you may use Hold and its variations, as HoldForm, HoldFirst etc.In Presentation there is a special tool for that, creating and releasing subexpressions. However, from the point of view of comfortably carrying long calculations I personally prefer to make substitutions instead. That is instead of 1-p use another variable, say, q -p + 1 /. p -> 1 - q q Have fun, Alexei Alexei BOULBITCH, Dr., habil. IEE S.A. ZAE Weiergewan, 11, rue Edmond Reuter, L-5326 Contern, LUXEMBOURG Office phone : +352-2454-2566 Office fax: +352-2454-3566 mobile phone: +49 151 52 40 66 44 e-mail: alexei.boulbitch at iee.lu