Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: How to apply tags to expression terms?
Posted:
Apr 17, 2013 2:30 AM


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@comcast.net http://home.comcast.net/~djmpark/index.html
From: Alexei Boulbitch [mailto:Alexei.Boulbitch@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 x1 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 nonuniversal: 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, L5326 Contern, LUXEMBOURG
Office phone : +35224542566 Office fax: +35224543566 mobile phone: +49 151 52 40 66 44
email: alexei.boulbitch@iee.lu



