2
$\begingroup$

I have

Input =a**b**c

I want to have output such as

{a,b,c}

So I want to change **->, but replace code does not work. How can I do it?

$\endgroup$
  • $\begingroup$ Look at FullForm[Input] and FullForm[{a, b, c}] and note what change you really want. $\endgroup$ – Michael E2 Oct 24 '15 at 21:25
  • $\begingroup$ You can't use Input as a variable name because it is a reserved function. Try this: input = a ** b ** c; Apply[List, input] $\endgroup$ – bill s Oct 24 '15 at 21:28
2
$\begingroup$

It is recommended to look at the FullForm of the expression when you are trying to use a pattern and rules.

FullForm[a ** b ** c]

Mathematica graphics

Seeing this it becomes easy to then:

a ** b ** c /. NonCommutativeMultiply -> List
(* {a, b, c} *)

Typically, shorter is better. Bob Hanlon suggested using:

List @@ (a ** b ** c)
(* {a, b, c} *)

which is another solution.

|improve this answer|||||
$\endgroup$
  • $\begingroup$ @Bob Hanlon - Nice. I added to answer. $\endgroup$ – Jack LaVigne Oct 25 '15 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.