# How to “ReplaceAll” using a set of conditional expressions instead of a list of rules [closed]

Suppose that I have two linear functions

f[x_] := f0 + f1 x
g[x_] := g0 + g1 x


and a (possibly rather complicated) set of conditional expressions, obtained through Reduce. For example, we might have something like this:

conditions = (f0 == f1 && g0 == 0) || (f0 == g1 && g0 == f1)


What I would like to do is write something like

{f[x],g[x]} /. conditions


and receive as output the set of pairs of $f$ and $g$ adhering to that formula. In this case we'd have

{{a + ax, bx}, {a + bx, b + ax}}


(or maybe {{f0 + f0x, g1x}, {f0 + f1x, f1 + f0x}} to stick with original variable names).

How can I do this?

-
@Mr.Wizard I get the conditions through Reduceing a system of equations in $g_0,g_1,f_0,f_1$ and then FullSimplifying, so these should be solutions. I'm really just trying to transform the coefficient logic into polynomial logic. –  Alexander Gruber Jan 27 at 8:37
According to the documentation for Reduce, this is how: {f[x], g[x]} /. {ToRules@conditions}. The only issue is adjusting the variables in Reduce to get them in the order you desire. (It's unclear whether you want f0 replaced by f1 or vice versa, or sometimes both.) –  Michael E2 Jan 27 at 11:30
As suggested by MichaelE2 {f[x], g[x]} /. {ToRules @ conditions} is what you need. See e.g. How to get intersection values from a parametric graph? where Solve couldn't provide solutions so we had used ToRules @ Reduce[...]. Another useful method you might find here: Simplifying expressions with square roots. –  Artes Jan 27 at 13:29

## closed as off-topic by Michael E2, bobthechemist, Sjoerd C. de Vries, Silvia, ArtesJan 28 at 0:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Michael E2, bobthechemist, Sjoerd C. de Vries, Silvia, Artes
If this question can be reworded to fit the rules in the help center, please edit the question.

First convert your conditions to a list of Rules

myrules = Apply[List, conditions /. {Equal -> Rule}, {0, 1}]


which gives

Then Apply those Rules to your List using a pure function and Map (/@)

ReplaceAll[{f[x], g[x]}, #] & /@ myrules


which produces

-
Very nice result. +1 –  rasher Jan 27 at 9:24
Assuming[#, Simplify[{f[x], g[x]}]] & /@ List @@ conditions

{{f1 (1 + x), g1 x}, {g1 + g0 x, g0 + g1 x}}