Is there a simple way to grab or reference one side of an equation?

Minimal example of what I mean:

    eq = x^2==3x
    (*Pseudo Code*)
    in: Grab_lefthandside(eq)
    out: x^2
  • 4
    $\begingroup$ eq[[1]] or First@eq $\endgroup$
    – Jason B.
    Aug 30 '16 at 13:25
  • $\begingroup$ tested and worked, tyvm. So it is internally an array...? $\endgroup$ Aug 30 '16 at 13:29
  • $\begingroup$ Check FullForm[eq]. $\endgroup$
    – Karsten 7.
    Aug 30 '16 at 13:34
  • 1
    $\begingroup$ @AskingQuestions. Everything (basically) in Mathematica is an expression of which you can take Parts. Sin[x][[1]] gives x, for instance. Even Graphics` objects: look at FullForm[Plot[x, {x, 0, 1}]]. $\endgroup$
    – march
    Aug 30 '16 at 16:43

You can change Equal to List and you will have the list of left and right hand sides of the equation.

First[List @@ (x^2 == 3 x)]
  • 3
    $\begingroup$ Part, First, Last, etc. operate on expressions not just a List. There is no need to convert to a List to use them. Try f[a, b, c] // First $\endgroup$
    – Bob Hanlon
    Aug 30 '16 at 15:27
  • $\begingroup$ That is true. However, I wanted to show how one can extract and manipulate all the objects in an expression. $\endgroup$ Aug 31 '16 at 5:56

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.