- #1

Hepth

Gold Member

- 449

- 39

i.e. I put:

F[x_] = A B x

F[a]

output : aAB

where I would want it: ABa

Thanks.

You are using an out of date browser. It may not display this or other websites correctly.

You should upgrade or use an alternative browser.

You should upgrade or use an alternative browser.

- Mathematica
- Thread starter Hepth
- Start date

- #1

Hepth

Gold Member

- 449

- 39

i.e. I put:

F[x_] = A B x

F[a]

output : aAB

where I would want it: ABa

Thanks.

- #2

CompuChip

Science Advisor

Homework Helper

- 4,306

- 48

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?

- #3

Hepth

Gold Member

- 449

- 39

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

Thanks!

- #4

CompuChip

Science Advisor

Homework Helper

- 4,306

- 48

If you want distributivity, you probably want to define something like

So that, for example,

gives

.

By the way, you can also try

but I don't think it's the best solution because the Orderless attribute gets re-set seemingly at random.

Code:

```
ExpandNCM[x_] := x //. {
NonCommutativeMultiply[a__, b_ + c_, d__] :> a ** b ** d + a ** c ** d
}
```

So that, for example,

Code:

`a ** (b + c) ** d // ExpandNCM`

Code:

`a ** b ** d + a ** c ** d`

By the way, you can also try

Code:

`ClearAttributes[Times, Orderless]`

Last edited:

Share:

- Replies
- 3

- Views
- 3K