1
$\begingroup$

Consider the following expression:

EXPR = Map[Simplify@Exp[#] &, b Log[f[t]] + a (Log[f[t]] - Log[g[t]]) - c Log[g[t]]]

whose output is:

$f(t)^a g(t)^{-a}+f(t)^b+g(t)^{-c}$

I want to replace the all the additions with multiplications, while otherwise retaining the form of the output. I.e., I want to hold the form of each individual term in the output of EXPR, so as to obtain:

$f(t)^a g(t)^{-a} f(t)^b g(t)^{-c}$

I need to hold the forms of the terms to obtain the desired output, because once I change the additions to multiplications MMA automatically combines the terms:

EXPR/. {Plus -> Times}

$f(t)^{a+b} g(t)^{-a-c}$

So I instead tried this, which doesn't work because it's following the standard behavior for Hold and thus outputting each "EXPR[[i]]" verbatim, rather than outputting each EXPR[[i]] and holding its respective form.

Product[Hold@EXPR[[i]], {i, 1, Length[EXPR]}]

$\text{Hold}[\text{EXPR}[[i]]]^3$

Finally, these approaches (both of which give the same output) do hold the form of each term in EXPR's output, but surround each with extraneous Hold[] syntax.

Product[Hold@Evaluate@EXPR[[i]], {i, 1, Length[EXPR]}]    
Product[Hold[#] &[EXPR[[i]]], {i, 1, Length[EXPR]}]

$\text{Hold}\left[f(t)^b\right] \text{Hold}\left[g(t)^{-c}\right] \text{Hold}\left[f(t)^a g(t)^{-a}\right]$

$\endgroup$
  • $\begingroup$ Do you need this because the multiplication is non-commutative? Or is there another goal here? $\endgroup$ – Marius Ladegård Meyer Aug 17 '18 at 22:50
  • $\begingroup$ No, it's purely a formatting issue. The question was motivated by my attempt to answer this question: mathematica.stackexchange.com/questions/180127/… I've gotten close, but the next step is replacing the additions with multiplications, while otherwise holding the form. More generally, it made me curious whether there was a way to apply Hold/HoldForm/Unevaluated, etc. to parts of an expression's output, as opposed to the input expression itself, should I encounter future cases where that type of manipulation is useful. $\endgroup$ – theorist Aug 17 '18 at 22:59
  • $\begingroup$ Hold@Evaluate@EXPR /. {Plus -> Times}? $\endgroup$ – jkuczm Aug 18 '18 at 16:43
2
$\begingroup$

You can change the head of EXPR to Inactive[Times]:

Inactive[Times] @@ EXPR

enter image description here

Alternatively,

EXPR /. Plus ->Inactive[Times]

same result

$\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.