2
$\begingroup$

It is required to replace the ==

in equation

2b==E ^ x0- x0

with ->,

becoming:

2b ->E ^ x0- x0

My personal attempt was like this, but it didn't achieve the goal

eq1 = E^x0 - x0 - 2 b == 0
eq2 = eq1 /. k_ + m_ - 2 b == 0 :> 2 b == k + m
eq3 = eq2 /. Thread["==" -> "->"]
$\endgroup$
5
  • 1
    $\begingroup$ Solve[E^x0 - x0 - 2 b == 0 /. b -> b/2, b] /. b -> 2*b // Flatten // First $\endgroup$
    – I.M.
    Commented Sep 25, 2023 at 3:03
  • 8
    $\begingroup$ 2 b == E^x0 - x0 /. Equal -> Rule $\endgroup$
    – Syed
    Commented Sep 25, 2023 at 3:07
  • 2
    $\begingroup$ Why is ToRules not an option? $\endgroup$
    – mattiav27
    Commented Sep 25, 2023 at 3:08
  • $\begingroup$ MMA 13.3 ToRules works. $\endgroup$ Commented Sep 25, 2023 at 6:50
  • $\begingroup$ Does this answer your question? What is an easy way to transform an equality into a replacement rule? $\endgroup$
    – xzczd
    Commented Oct 7, 2023 at 5:50

1 Answer 1

2
$\begingroup$

A few observations

eq = 2 b == E^x0 - x0;

The Head of eq is Equal

Head @ eq

Equal

The Head is always at position 0

ps = Position[Equal] @ eq

{{0}}

Therefore we must ReplaceAt position 0

ReplaceAt[eq, _ :> Rule, ps]

2*b -> E^x0 - x0

or use ReplaceAll like Syed suggested in his commentary.

We can also use ToRules:

First @ ToRules @ eq

2*b -> E^x0 - x0

or Apply with its third argument:

Apply[Rule, eq, {0}]

2*b -> E^x0 - x0

Addendum

Like lericr mentioned in his comment, Apply doesn't need the third argument in this case and can also be written as:

Apply[Rule, eq];

or

Apply[Rule] @ eq

or

Rule @@ eq
$\endgroup$
2
  • $\begingroup$ The default levelspec is sufficient: Apply[Rule, eq]. Special form: Rule @@ eq. $\endgroup$
    – lericr
    Commented Sep 25, 2023 at 10:27
  • $\begingroup$ Thank you, I added your comment to the answer $\endgroup$
    – eldo
    Commented Sep 25, 2023 at 10:40

Your Answer

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

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