1
$\begingroup$

Say I have a Mathematica programme/function $f[z_,w_{} ] = \mathrm{Reduce}[\cdots]$ which outputs a list of solutions, which looks something like $$a = 1 \&\& ((0\leq b \leq 1000 \&\& -5 \leq c \leq 65)) $$ $$a = 2 \&\& ((32\leq b \leq 860 \&\& -4 \leq c \leq 36)) $$ and so on for all cases of $a$ (here $1 \leq a \leq 10$). Here $a,b,c$ are all integers.

I have another function $g$ written in Mathematica taking values in four integers that I would like to evaluate on each solution in the list above. Is it possible to write code which does this in Mathematica? I have searched online but haven't had much luck. Thanks!

$\endgroup$
3
  • $\begingroup$ (1) is $d$ missing by accident? (2) Also is this actually a list of solutions, or an Or of solutions? (3) it would probably help to have the output itself, or a simplified form of it, as actual code for copying/pasting! (4) also: what numbers exactly do you hope to evaluate g on, if b and the like are only specified up to bounds? or would you like the image of the entire interval under g? $\endgroup$ – thorimur Jun 6 at 2:08
  • 1
    $\begingroup$ @thorimur Hi, thanks for your reply! Yes thanks, I added $d$ by accident. Yes, it's a list - Mathematica outputs it the way I've written (with the double "and" symbols). Yes sorry, I forgot to specify this - $a,b,c$ are integers so I hope to evaluate $g$ on each discrete solution in the list. So for the updated question, I'd hope to evaluate $g$ on $(a,b,c)=(1,0,-5), (1,0,-4)$ and so on. $\endgroup$ – mathphys Jun 6 at 2:16
  • $\begingroup$ The function ToRules will change the output of Reduce to rules. $\endgroup$ – Daniel Huber Jun 6 at 8:04
0
$\begingroup$

Here's one way:

g[a,b,c] /. Solve[f[z,w], {a,b,c}, Integers]

You may need to surround it with a Block if you have a,b,c defined elsewhere:

Block[{a,b,c},
  g[a,b,c] /. Solve[f[z,w], {a,b,c}, Integers]
]

If indeed f outputs a list, you may also need to replace the List head with an Or head, or map over the list of solutions for each case of a if you want a list of lists:

Block[{a,b,c},
  g[a,b,c] /. Solve[Or @@ f[z,w], {a,b,c}, Integers]
]

Block[{a,b,c},
  (g[a,b,c] /. Solve[#, {a,b,c}, Integers]) & /@ f[z,w]
]

Let me know if it works! :)

$\endgroup$
1
  • $\begingroup$ Hi, apologies for my late response, and thanks very much for your reply! :) Yes, I think this will work. Unfortunately, I realised earlier today that applying the second function $g$ doesn't solve the problem that I'm trying to solve correctly, but it's useful to know how to combine the output of a Reduce function with another function for the future. Thanks again! :) $\endgroup$ – mathphys Jun 6 at 22:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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