2
$\begingroup$

For a better overview in my output, I would like to replace ** with nothing. Since

foobar /. ** -> ""

does not work I ask for help.

The ** is the Noncommutative multiplication.

Reference: NonCommutativeMultiply

Thanks!

$\endgroup$
  • 1
    $\begingroup$ Unless you are talking about the string "**", the expression ** is not a valid Wolfram Language expression, henceforth it will never be an output of any expression. What language are you using? $\endgroup$ – Fortsaint Jul 10 '19 at 8:38
  • 1
    $\begingroup$ Can you give an example input in which you'd like the asterisks removed? By the looks of it, you're working with strings, in which case you need StringReplace or StringDelete and specify appropriate string pattern you want to delete: reference.wolfram.com/language/tutorial/StringPatterns.html $\endgroup$ – Sjoerd Smit Jul 10 '19 at 8:38
  • $\begingroup$ I am using the noncommutative multiplication. And since my output is big I just want to leave it out after calculation. Since I know its an multiplication reference.wolfram.com/language/ref/NonCommutativeMultiply.html $\endgroup$ – BlackPhoton Jul 10 '19 at 8:44
  • 1
    $\begingroup$ user66499, i suggest you add the information in your comment to your question. $\endgroup$ – kglr Jul 10 '19 at 9:01
5
$\begingroup$
foobar = c ** b ** a;

foobar /. NonCommutativeMultiply[a__] :> Infix[NonCommutativeMultiply[a], "\[InvisibleTimes]"]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks for your help! $\endgroup$ – BlackPhoton Jul 10 '19 at 8:57
  • $\begingroup$ @user66499, my pleasure. Welcome to mma.se. $\endgroup$ – kglr Jul 10 '19 at 9:00
1
$\begingroup$

Stealing from @kglr, but taking advantage of Format instead of ReplaceAll

expression=c**b**a
(* c**b**a *)

FullForm[expression]
(* NonCommutativeMultiply[c,b,a]*)

Unprotect[NonCommutativeMultiply];
Format[NonCommutativeMultiply[k__]]:=Infix[NonCommutativeMultiply[k], "\InvisibleTimes]"];
Protect[NonCommutativeMultiply];

expression
(* c\[InvisibleTimes]b\[InvisibleTimes]a *)

FullForm[expression]
(* NonCommutativeMultiply[c,b,a] *)

Mathematica graphics

$\endgroup$

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.