2
$\begingroup$

Say I have the following list:

{ 
  ({-Subscript[y, 2]}⊕1)/Subscript[y, 1], 
  ({-Subscript[y, 1], -Subscript[y, 3]}⊕1)/Subscript[y, 2], 
  ({-Subscript[y, 2]}⊕1)/Subscript[y, 3], 
  ({Subscript[y, 2]}⊕1)/Subscript[y, 1], 
  (-Subscript[y, 1]⊕Subscript[y, 3])/Subscript[y, 2], 
  (Subscript[y, 3]⊕(Subscript[y, 2] + Subscript[y, 3]))/Subscript[y, 1]
}

Now, whenever something of the form {-a,-b,c,...} appears, I want to multiply elements of such list, from left to right, so that I'd get -a(-b)c.... As you can see, if there is a minus before every of elements that I'm multiplying, I want this minus to stay in the output, i.e. we ignore signs when multiplying. The direct sum symbol it's just a place holder, for the time being.

The following does the job:

Times @@ HoldForm /@ {-Subscript[y, 1],-Subscript[y, 3],Subscript[y, 4]}

So now, I would like to apply this to the big list at the start of the question, but I'm not sure how to do this. The only thing that would change in that list would be in the second element of that list, i.e. the first part of the numerator, the rest of the list would stay the same. Could someone help?

$\endgroup$
  • $\begingroup$ Did you intend for some of the elements of the list to be lists as well? For instance, the first element of the list is ({-Subscript[y, 2]}\[CirclePlus]1)/Subscript[y, 1], which, because of the enclosing {}'s, is a list. Also, your first snippet of code doesn't evaluate correctly because there are some unmatched brackets/parentheses/curly braces. Can you please edit your post to address these issues? Otherwise, something like expr /. a : {-_, -_, __} :> (Times @@ HoldForm /@ a ) might work. $\endgroup$ – march Apr 15 at 17:14
1
$\begingroup$

If you only care about formatting, is this what you need?

input /. List -> (Row@*List)

enter image description here

$\endgroup$
  • $\begingroup$ Yes, that works well for my case, I like it! Thanks @Kuba! $\endgroup$ – amator2357 Apr 16 at 8:20

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.