4
$\begingroup$

If I execute

A = {Sin, Cos, Tan}
B = {ArcSin, ArcCos, ArcTan}
#[[1]]@#[[2]]@x & /@ Transpose[{A, B}]

the output is

{x,x,x}

which is to be expected. However, what I want is

{Sin[ArcSin[x]], Cos[ArcCos[x]], Tan[ArcTan[x]]}

Knowing that HoldForm[Sin[ArcSin[x]]] outputs Sin[ArcSin[x]], I tried

A = {Sin, Cos, Tan}
B = {ArcSin, ArcCos, ArcTan}
HoldForm[#[[1]]@#[[2]]@x] & /@ Transpose[{A, B}]

but this gives me

{{Sin,ArcSin}[[1]][{Sin,ArcSin}[[2]][x]],{Cos,ArcCos}[[1]][{Cos,ArcCos}[[2]][x]],{Tan,ArcTan}[[1]][{Tan,ArcTan}[[2]][x]]}

Much like Zach Braff's morning routine, this output is plagued by too much Hold.

How can I Hold the form of the expression without Holding the evaluation of Part?

$\endgroup$

3 Answers 3

3
$\begingroup$

Instead of Hold[], consider using Inactive[]:

MapThread[Inactive[#1][Inactive[#2][x]] &, {{Sin, Cos, Tan}, {ArcSin, ArcCos, ArcTan}}]

(equivalently, MapThread[Inactivate[#1[#2[x]]] &, {{Sin, Cos, Tan}, {ArcSin, ArcCos, ArcTan}}])

which would look like this on the front end:

inactivated functions

To remove Inactive[]:

Activate[%]
  {x, x, x}

In older versions, you can try Defer[] or HoldForm[] instead of Inactive[], e.g.

HoldForm[Sin][HoldForm[ArcSin][x]]

and to remove the held evaluation,

ReleaseHold[%]
$\endgroup$
5
$\begingroup$

Several alternatives:

Defer[#@#2@x] & @@@ Transpose[{A, B}] 
HoldForm[#@#2@x] & @@@ Transpose[{A, B}] 
MapThread[Compose[HoldForm@#, HoldForm@#2, x] &, {A, B}]
HoldForm[a[b @ x]] /. Thread[{a, b} -> #] & /@ Transpose[{A, B}] 
With[{a = #[[1]], b = #[[2]]}, HoldForm[a[b@x]]] & /@ Transpose[{A, B}]

all give

{Sin[ArcSin[x]],Cos[ArcCos[x]],Tan[ArcTan[x]]}

$\endgroup$
3
$\begingroup$

Another approach using operator forms (and avoiding slots, e.g., #):

Through @* Thread[HoldForm @* A @* B] @ x

{Sin[ArcSin[x]],Cos[ArcCos[x]],Tan[ArcTan[x]]}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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