1
$\begingroup$

I'm trying some transformations and they are getting complicated. It's common in physics to replace functions by symbols so you term get shorter.

Lets say I have transformation

xr[A_,B_] := K A + L B + KK A^2 + LL B^2,

where A = A[x_] and B = B[x_]

I want to input some random values of x. But for the code to be readable I want to substitute the quadratic part as

H =  KK A^2 + LL B^2

How do I go about this? I don't want to define H as a function, since that would make me have to write

xr[A,B] = xr[A,B,H] = xr[A,B,H[A,B]] = xr[A[x],B[x],H[A[x],B[x]]]

which just gets unwieldy.

Essentially I just want to be able to write H such that mathematica would understand that when I define

xr[A,B] := K A + L B + H

Output of sending a x value to it would be

xr[A[x],B[x]] = K A[x] + L B[x] + KK A[x]^2 + LL B[x]^2.

Hopefully you can understand what I'm trying to do. Thank you for your help.

Edit: This is just an example of function. Of course It wouldn't be useful in this case and I also know there are reasons why this specific type substitution wouldn't be a healthy practice but what are the alternatives.

$\endgroup$
3
  • 1
    $\begingroup$ Why can't you just define: H[A_, B_] = KK A^2 + LL B^2; xr[A_, B_] := K A + L B + H[A, B] ? $\endgroup$ Dec 11, 2021 at 9:56
  • 1
    $\begingroup$ Try this: xr[A_, B_] := k A + l*B + kk A^2 + ll B^2; xr[A, B] /. kk A^2 + ll B^2 -> H which returns H + A k + B l . $\endgroup$ Dec 11, 2021 at 12:45
  • $\begingroup$ Thank you very much $\endgroup$
    – Nitaa a
    Dec 12, 2021 at 13:07

1 Answer 1

4
$\begingroup$

You can display the unevaluated functions in any desired format.

Format[A[x_]] := A;
Format[B[x_]] := B;

xr[a_, b_] := K a + L b + KK a^2 + LL b^2

Then,

xr[A[x], B[x]]

(* K A + KK A^2 + L B + LL B^2 *)
$\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.