17 votes
Accepted

What is an easy way to transform an equality into a replacement rule?

With: eqns = (a == 1 && b == 2 && c == 0) Just use a built-in function: ToRules[eqns] ...
user avatar
  • 14.2k
9 votes

Removed all undefined from a list of rules

Select only NumericQ solution Select[rules, NumericQ[Last[#]]&] Or delete the instances ...
user avatar
  • 28.5k
8 votes
Accepted

Removed all undefined from a list of rules

t = rules /. HoldPattern[x_ -> Undefined] -> Nothing EDIT Another variation: Values[rules] can be used: (Also try ...
user avatar
  • 14.2k
8 votes

What is an easy way to transform an equality into a replacement rule?

Another way is the following: ReplaceAll[Equal -> Rule][Level[eqns, {1}]] (*{a -> 1, b -> 2, c -> 0}*)
user avatar
8 votes

What is an easy way to transform an equality into a replacement rule?

I expect there will be many solutions, probably the best alternative is to use ToRules, as suggested by @Syed. Anyhow, here I present you with two other simple ways....
user avatar
  • 28.5k
7 votes
Accepted

ReplaceAll with Powers

What about a^2/b^2 /.a->b c (*c^2*)
user avatar
7 votes

What is an easy way to transform an equality into a replacement rule?

Another way is to use Block. It uses the same idea that @rhermans suggested as you see; it redefines List and ...
user avatar
  • 5,594
7 votes
Accepted

Smart way to remove rules from lists, leaving just values, specifically from FindMinimum output

I want to add this reply in response to the comment written under the OP. The function Values does not work, as all the elements of the list are not rules. (the ...
user avatar
  • 5,594
6 votes

Replace list of list according to second list

☺ = # /. ({#, _} -> {##} & @@@ #2) &; p ~ ☺ ~ t1 {{2, 0}, {3, 0}, {4, 0}, {5, 1}, {8, 0}, {11, 1}}
user avatar
  • 348k
6 votes

Removed all undefined from a list of rules

We can use DeleteCases as follows: ...
user avatar
  • 348k
6 votes

Smart way to remove rules from lists, leaving just values, specifically from FindMinimum output

Let ruleNixer = Rule[_, v_] :> v; Example1 from the docs: FindMinimum[x Cos[x], {x, 2}] {-3.28837, {x -> 3.42562}} <...
user avatar
  • 14.2k
5 votes

Smart way to remove rules from lists, leaving just values, specifically from FindMinimum output

If you're needing to handle output from FindMinimum specifically, then since you know that structure you know how to "re-structure" it: ...
user avatar
  • 3,452
5 votes

What is an easy way to transform an equality into a replacement rule?

My method was to simply use a table to iterate over each element of the collection of equality and re-write them as a replacement rule: ...
user avatar
  • 635
5 votes
Accepted

Tropical Operation Conversions: Multiple Operations

I assume that you want to replace Addition by "Max" and Multiplication by addition. It is not clear how a negative term should be treated. For the time being I assume that it will be ...
user avatar
  • 23.9k
5 votes
Accepted

Replacement, PatternTest, Module related Question

The reason your attempt fails is that at the time the Function is applied to its arguments, m has not yet been replaced by ...
user avatar
  • 23.2k
5 votes
Accepted

Classifying elements, by the value of a fixed function, using Replace

L = Table[ConstantArray[1, RandomInteger[999]], 100000]; m = Replace[L, {x_List :> Quotient[Length@x, 100]}, {1}]; $$\{7,2,8,8,6,5,1,5,2,1,1,3,6,7,2,4,7,2,1,8,...
user avatar
  • 14.2k
4 votes

Tropical Operation Conversions: Multiple Operations

I'm not entirely sure if this is what you're looking for, but it seems you would just need to replace your x_ with x__ ...
user avatar
4 votes

Smart way to remove rules from lists, leaving just values, specifically from FindMinimum output

Odds and ends Single and two-variable examples: ...
user avatar
  • 212k
4 votes

Smart way to remove rules from lists, leaving just values, specifically from FindMinimum output

These methods work correctly with any number of variables of any dimensionality: ...
user avatar
4 votes
Accepted

Replace list of list according to second list

f = Values @ GroupBy[Join @ ##, First, Last] &; f[p, t1] {{2, 0}, {3, 0}, {4, 0}, {5, 1}, {8, 0}, {11, 1}}
user avatar
  • 348k
4 votes

Replace list of list according to second list

pos = Position[p[[All, 1]], #] & /@ First /@ t1 {{{4}}, {{6}}} ReplacePart[p, Thread[pos -> t1]] {{2, 0}, {3, 0}, {4,...
user avatar
  • 14.2k
3 votes

What is an easy way to transform an equality into a replacement rule?

The following also works: ...
user avatar
  • 5,594
3 votes

What is an easy way to transform an equality into a replacement rule?

Another way of obtaining the desired output is: ...
user avatar
  • 5,594
3 votes

What is an easy way to transform an equality into a replacement rule?

Similarly, one can go about it in the following manner: ...
user avatar
  • 5,594
3 votes

What is an easy way to transform an equality into a replacement rule?

Since we did all the normal ways, the following is fun. Extract the values and the parameters from the output of Reduce using ...
user avatar
  • 5,594
3 votes
Accepted

How to use "Replace" in matrix?

If B is found in the result you can replace it by Defer[B]: ...
user avatar
  • 19k
2 votes

Replace list of list according to second list

Slightly different p2 to include duplicates/same t1: ...
user avatar
  • 14.2k
2 votes
Accepted

ReplaceAll not working with change of sign

I'm not a big fan of using ReplaceAll as a way of asserting arithmetic relationships, but if that's what you really want, then try something like this: ...
user avatar
  • 3,452
1 vote

How to replace derivatives of a function with symbolic symbols and numbers with a replacement rule? (I.e. U'' maps to u2)

It is generally easier to deal with indexed variables and to format them for display in any desired manner. ...
user avatar
  • 119k

Only top scored, non community-wiki answers of a minimum length are eligible