MathGroup Archive 2013

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

Search the Archive

Re: How to apply tags to expression terms?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg130513] Re: How to apply tags to expression terms?
  • From: "djmpark" <djmpark at comcast.net>
  • Date: Wed, 17 Apr 2013 02:32:41 -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: <22368414.106150.1366087075873.JavaMail.root@m06>

Alexei,

The answers you received recommending TraditionalForm are probably the way
to go in most cases. But suppose that one prefers to work in StandardForm,
or for one reason or another TraditionalForm is also not the order you want
for terms or factors? Then I think a convenience routine might be useful.

I don't think the idea of using tags and trying to compute with such
expressions is too great. One would have to almost rewrite Mathematica
algebra! But we can write a useful routine for final display expressions.
So here is a routine that allows you to reorder terms in a Plus expression
or factors in a Times expression.

HoldOrderForm::usage = 
  "HoldOrderForm[permutation][expr] will reorder the terms or factors \
of a Plus or Times expression according to the permutation and put \
the result in a HoldForm.";

SyntaxInformation[HoldOrderForm] = {"ArgumentsPattern" -> {_}};

HoldOrderForm[permutation_?PermutationListQ][(f : Plus | Times)[
    args__]] /; Length[{args}] == Length[permutation] :=
 (HoldForm @@ {(List @@ f[args])[[permutation]]}) /. List -> f 

Then for your simple case:

-1 + x;
HoldOrderForm[{2, 1}]@% 

x - 1

Here is a case where we first reorder terms and then reorder the resulting
factors:

(1 - x + Exp[I x]) (x - 1)
Inner[#1[#2] &, {HoldOrderForm[{2, 1, 3}], HoldOrderForm[{2, 1}]}, 
 List @@ %, Times]
HoldOrderForm[{2, 1}]@% 

(1 + E^(I x) - x) (-1 + x) 
(x - 1) (E^(I x) + 1 - x)
(E^(I x) + 1 - x) (x - 1)

If you like it I'll put it in Presentations. Presemtations contains a number
of convenience routines for manipulating expressions to special forms. Some
of them just seemed useful to me but many of them came from questions on
MathGroup. If the ideas seem useful and not too specialized then I consider
including them. And they are in a common place where Presentations users can
find them.


David Park
djmpark at comcast.net 
http://home.comcast.net/~djmpark/index.html 


From: Alexei Boulbitch [mailto:Alexei.Boulbitch at iee.lu] 


Dear Community members,

I often see on this site an at the StackExchange the repeating questions of
how to rearrange some expression, that Mathematica "likes" to keep in one
form, but the user prefers another one. It is like in this trivial example:

    (x^2 - 1)/(x + 1) // Simplify

that Mathematica returns -1+x, rather than x-1 that might be wished by the
user.

I have seen many answers to this questions, and gave few mine. The problem
here is that the answers are non-universal: they strongly depend upon the
expression in question. Besides, they require some additional programming,
and the more complex is the formula to sort, the longer will be the part of
the sorting code. 

It seems that the problem of sorting terms of analytic expressions in the
desired order might be solved, if one could assign tags to the terms to be
sorted, and then sort the terms according to a specified list of such tags.

Now comes my question, do you know how to apply tags to expression terms?

I have seen an analogous functionality in the Presentation Master, the
package of  David Park. There, however, the tags are used to be assigned to
sub expressions, the held part of the expression in question. David, is it
possible to assign tags to expressions that are not held?

Thank you in advance.
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







  • Prev by Date: Re: Distribute one list element over another
  • Next by Date: AMD Benchmark[]
  • Previous by thread: Re: How to apply tags to expression terms?
  • Next by thread: Re: Trying to suspend or pause execution of a program.(updated)