# How do I withdraw the rhs from a list of equations?

I have a list of equations that were solved for different values of another parameter and stored in a Table and has the form:

{a==0, a==1, a==2, a==3}


and so on. I want to withdraw only in rhs and store it in a list:

{0, 1, 2, 3}


I tried /.ToRules on the whole list as well as on the single elements because I thought, they could be evaluated easier. I expected {a->0,a->1,a->2,a->3} but it's giving me the same error for either one: "{ToRules} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing"

• Thanks for accepting a good answer, however I think you were too hasty doing that. While accepting is one of the things to do after your question is answered, we recommend that users should test answers before voting and wait 24 hours before accepting the best one. That allows people in all time zones to answer your question and an opportunity for other users to point alternatives, caveats or limitations of the available answers. Commented Feb 27, 2023 at 16:39
• Ok, that makes it 10+ different solutions then. Commented Feb 27, 2023 at 16:50

Perhaps

{a == 0, a == 1, a == 2, a == 3}[[All, 2]]
(*{0, 1, 2, 3}*)


or

{a == 0, a == 1, a == 2, a == 3} /.Equal->Rule
(*{a -> 0, a -> 1, a -> 2, a -> 3}*)

• fyi, you have typo. Rules should be Rule Commented Feb 27, 2023 at 15:07
• @Nasser Thanks for your hint Commented Feb 27, 2023 at 16:05

Using MapApply and Values:

Rule @@@ lis

(*{a -> 0, a -> 1, a -> 2, a -> 3}*)

Values@(Rule @@@ lis)

(*{0, 1, 2, 3}*)


# Using ToRules

You wanted to use ToRules. You could have Map (/@) it like this

ToRules/@{a == 0, a == 1, a == 2, a == 3}
(* {{a->0},{a->1},{a->2},{a->3}} *)


So a complete solution

Composition[First, Values, ToRules] /@ {a == 0, a == 1, a == 2, a == 3}
(*{0, 1, 2, 3}*)


or

First@*Values@*ToRules /@ {a == 0, a == 1, a == 2, a == 3}
(*{0, 1, 2, 3}*)


# Using MapApplyLast

Last @@@ {a == 0, a == 1, a == 2, a == 3}
(*{0, 1, 2, 3}*)


This is a hack that relies on the LHS (in this case a) been AtomQ.

# Using Cases

Cases[
{a == 0, a == 1, a == 2, a == 3}
,  Equal[lhs_,rhs_]:> rhs
]
(*{0, 1, 2, 3}*)


# Using ReplaceAll

{a == 0, a == 1, a == 2, a == 3} /. Equal[lhs_,rhs_]:> rhs
(*{0, 1, 2, 3}*)


or in operator mode

ReplaceAll[ Equal[lhs_,rhs_]:> rhs] @ {a == 0, a == 1, a == 2, a == 3}
(*{0, 1, 2, 3}*)


Another possibility

lis = {a == 0, a == 1, a == 2, a == 3}
Last /@ lis


In an equation Last is the RHS and First is the LHS.

If you want to make it Rule, I think Ulrich answer might be the easiest, which is to replace == by Rule. But you can also do

lis = {a == 0, a == 1, a == 2, a == 3}
Rule[First[#], Last[#]] & /@ lis


One possible way using Values:

lis = {a == 0, a == 1, a == 2, a == 3};
lis /. Equal -> Rule // Values


{0, 1, 2, 3}

Since you asked about rules, the following will replace each value appropriately

MapThread[ReplaceAll, {Table[a, {i, 1, Length@l}],
l /. Equal -> Rule}]


{0,1,2,3}

list = {a == 0, a == 1, a == 2, a == 3};


Using MapApply (new in 13.1)

MapApply[Last] @ list


Using ReplaceAt (new in 13.1)

ReplaceAt[_ :> Last, {All, 0}] @ list


Using Cases

Cases[_ == a_ :> a] @ list


All produce

{0, 1, 2, 3}