# Apply after with arguments

Though I have been using Mathematica on and off for many years to help with learning math, it is only recently I have been introduced to its functional programming style and power. So for example if I have a list

Table[k, {k, 1, 4}]


then I can do

Times @@ Table[k, {k, 1, 4}]


to get its product. But one of my favourites is the 'apply after'. For example:

( {
{Cosh[z], Sinh[z]},
{Sinh[z], Cosh[z]}
} ) - λ*IdentityMatrix[2]


will give me

{{-λ + Cosh[z], Sinh[z]}, {Sinh[z], -λ + Cosh[z]}}


(of course it looks much nice in free-form input) and I can see the matrix structure. But now once I see the matrix, I can go to the same input line and append a //Det to compute its determinant.

My question is at this point, is there a way to do "apply after" with arguments? For example can I go to the output line after computing the determinant and append something along the lines of,

λ^2 - 2 λ Cosh[z] + Cosh[z]^2 - Sinh[z]^2 == 0 //
Solve[#, λ]


To solve for lambda?

Basically I guess I want to pipe the output/expression into a certain place in a function call. Yes I know I can do

Solve[% == 0, λ]


on the next line but I was just curious.

• add & , that is , use λ^2 - 2 λ Cosh[z] + Cosh[z]^2 - Sinh[z]^2 == 0 // Solve[#, λ] & – kglr Dec 17 '17 at 22:22

λ^2 - 2 λ Cosh[z] + Cosh[z]^2 - Sinh[z]^2 == 0 // Solve[#, λ] &
λ^2 - 2 λ Cosh[z] + Cosh[z]^2 - Sinh[z]^2 == 0 // Function[Solve[#, λ]]
λ^2 - 2 λ Cosh[z] + Cosh[z]^2 - Sinh[z]^2 == 0    // Function[{x}, Solve[x,  λ]]


all give

{{λ -> Cosh[z] - Sinh[z]}, {λ -> Cosh[z] + Sinh[z]}}

For the case in comments below:

({{Cosh@z, Sinh@z}, {Sinh@z, Cosh@z}} - λ IdentityMatrix[2] // Det)==0 // Solve[#, λ] &


{{λ -> Cosh[z] - Sinh[z]}, {λ -> Cosh[z] + Sinh[z]}}

• I guess that works. I would have never guessed this...though we have to use parenthesis to apply after twice... (( { {Cosh[z], Sinh[z]}, {Sinh[z], Cosh[z]} } ) - [Lambda]*IdentityMatrix[2] // Det) == 0 // Solve[#, [Lambda]] & But I can live with that. – ITA Dec 17 '17 at 22:31
• @ITA, you don't need the inner parentheses. Thank you for the accept. – kglr Dec 17 '17 at 22:43