1
$\begingroup$

A function h that I've written (it uses Reduce) outputs a list of integer solutions of the form e.g.

(a0 = 1 && a1 = 2 && a2 = 3) || (a0 = 2 && a1 = 3 && a2 = 4) || ... .

Some of the solutions however are of the form e.g. (a2 \[Element] Integers && a0 = 1 && a1 = 2 && -6 <= a2 <= 8). I'd like to seperate the solutions in the latter form into the former form, i.e. I would like to have the latter ones appearing as

(a0 = 1 && a1 = 2 && a2 = -6) || (a0 = 1 && a1 = 2 && a2 = -5) || ... .

The reason I ask is because I am exporting the wholle list of solutions into a .csv file as follows:

solns = Table[h[b, a0, a1, 0, 12], 1]]

Export["solns.csv", solns]

When solutions are of the former form, the .csv output is manageable for me, but with the latter form it is too messy. Does anyone know a way to fix this?

Many thanks.

$\endgroup$
3
  • $\begingroup$ Can you put a short example of the output you wish to modify in copy-pastable form? $\endgroup$
    – bill s
    Sep 16, 2021 at 14:50
  • $\begingroup$ Hi Bill, here's an excerpt: (a0 == 26 && a1 == -15 && a2 == 49) || (a0 == 26 && a1 == -15 && a2 == 50) || (a0 == 26 && a1 == -15 && a2 == 51) || (a2 [Element] Integers && a0 == 27 && a1 == -15 && 39 <= a2 <= 50) || (a0 == 28 && a1 == -15 && a2 == 35) || $\endgroup$
    – mathphys
    Sep 16, 2021 at 14:56
  • $\begingroup$ sorry, maybe some of the symbols have changed slightly, e.g. I think the equals signs should just be = $\endgroup$
    – mathphys
    Sep 16, 2021 at 15:02

1 Answer 1

0
$\begingroup$

Say the output you are getting looks like:

out = (a0 == 1 && a1 == 2 && a2 == 3) || (a0 == 2 && a1 == 3 && a2 == 4) || 
      (a2 \[Element] Integers && a0 == 1 && a1 == 2 && -6 <= a2 <= 8) || (a1 \[Element] Integers && a0 == 1 && a1 == 2 && -6 <= a2 <= 8)

Then you can remove the extra "Element" terms by:

DeleteCases[out /. Element -> Nothing, Nothing, 2]

(a0 == 1 && a1 == 2 && a2 == 3) || (a0 == 2 && a1 == 3 && a2 == 4) || 
(a0 == 1 && a1 == 2 && -6 <= a2 <= 8) || (a0 == 1 && a1 == 2 && -6 <= a2 <= 8)
$\endgroup$
4
  • $\begingroup$ Thanks for the answer, but would it be possible to list out each of the e.g. 15 solutions from (a0 == 1 && a1 == 2 && -6 <= a2 <= 8) as solutions of the form (a0 == ... && a1 == ... && a2 == ...) ? $\endgroup$
    – mathphys
    Sep 16, 2021 at 15:15
  • $\begingroup$ I tried the solnsModified /. Or -> List method but it didn't seem to list them out. The things that changed were that the solutions no longer had brackets, and were delimited by commas instead of double vertical lines. $\endgroup$
    – mathphys
    Sep 16, 2021 at 15:31
  • $\begingroup$ Can you be clearer about what actual output you desire? I had thought the above was the task (to remove the "element of" and to make them a list) but apprently you are looking for something more. For instance, for the term (a0 == 1 && a1 == 2 && 6 <= a2 <= 8) what would you want the output to look like? $\endgroup$
    – bill s
    Sep 16, 2021 at 17:30
  • $\begingroup$ Thank you for the help everyone - setting SetSystemOptions[{"ReduceOptions" -> "DiscreteSolutionBound" -> 300}] as in the linked question solved my problem! $\endgroup$
    – mathphys
    Sep 17, 2021 at 8:26

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