[Mathematica 6.0+] Preserving order of variables


by Hepth
Tags: mathematica, order, preserving, variables
Hepth
Hepth is offline
#1
May26-09, 03:24 PM
PF Gold
Hepth's Avatar
P: 445
Is there a way to set Mathematica so that it preserves the order of variables.
i.e. I put:

F[x_] = A B x
F[a]
output : aAB

where I would want it: ABa

Thanks.
Phys.Org News Partner Science news on Phys.org
SensaBubble: It's a bubble, but not as we know it (w/ video)
The hemihelix: Scientists discover a new shape using rubber bands (w/ video)
Microbes provide insights into evolution of human language
CompuChip
CompuChip is offline
#2
May26-09, 05:04 PM
Sci Advisor
HW Helper
P: 4,301
I am having the same problem.
The best solution I have found in general is using NonCommutativeMultiply:
F[x_] := A ** B ** x
although you usually have to define lots of other stuff to get everything working out as you want.
In some cases (like where A and B are explicitly defined matrices) you can use matrix multiplication
F[x_] := A . B . x
or a function
F[x_] := AB[x]

Do you have anything specific in mind?
Hepth
Hepth is offline
#3
May26-09, 06:17 PM
PF Gold
Hepth's Avatar
P: 445
I just have a long string of things that could either be matrices or vectors or scalars or tensors or etc. I'm trying to do some simplifications and then use the output. Its nothing special, I just need to preserve order. I'm not doing any REAL products (like inner, outer, contractions, etc) just representative products. If I define everything as matrices/vectors etc then it'll try to simplify it which i don't want. It needs to stay symbolic, yet perform basic distribution multiplication.

I guess I'll try the noncommutative, that should work.
Thanks!

CompuChip
CompuChip is offline
#4
May27-09, 08:38 AM
Sci Advisor
HW Helper
P: 4,301

[Mathematica 6.0+] Preserving order of variables


If you want distributivity, you probably want to define something like
ExpandNCM[x_] := x //. {
   NonCommutativeMultiply[a__, b_ + c_, d__] :> a ** b ** d + a ** c ** d
   }
So that, for example,
a ** (b + c) ** d // ExpandNCM
gives
a ** b ** d + a ** c ** d
.

By the way, you can also try
ClearAttributes[Times, Orderless]
but I don't think it's the best solution because the Orderless attribute gets re-set seemingly at random.


Register to reply

Related Discussions
Order-preserving Embedding Functions Set Theory, Logic, Probability, Statistics 1
how do i plot a function of two variables in mathematica? Math & Science Software 3
Order-preserving injection Calculus & Beyond Homework 1
order (mathematica) Math & Science Software 4
second order diff eq with two variables Calculus & Beyond Homework 7