5
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ @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. $\endgroup$ – Alexander Gruber Jan 27 '14 at 8:37
  • 1
    $\begingroup$ 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.) $\endgroup$ – Michael E2 Jan 27 '14 at 11:30
  • $\begingroup$ 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. $\endgroup$ – Artes Jan 27 '14 at 13:29
4
$\begingroup$

First convert your conditions to a list of Rules

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

which gives

enter image description here

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

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

which produces

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Very nice result. +1 $\endgroup$ – ciao Jan 27 '14 at 9:24
1
$\begingroup$
Assuming[#, Simplify[{f[x], g[x]}]] & /@ List @@ conditions
{{f1 (1 + x), g1 x}, {g1 + g0 x, g0 + g1 x}}

Which, technically but with switched constants, is what is desired.

| improve this answer | |
$\endgroup$

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