I have a
While loop that generates and prints an expression on each iteration (there can be thousands of iterations). UPDATE: Some expressions are generated in unevaluated form (e.g.
1 + 1) and printed in this form. This behavior should be kept in the modification explained below.
I want to modify it to print only new expressions — that do not appear as sub-expressions of any expression that has been generated at an earlier step. We assume that any expression is a sub-expression of itself, so no expression should be printed twice. Generated expressions may contain patterns, and they should be handled verbatim (each symbol represents only itself). For example:
(* Iteration 1 *) f[_] (* PRINTED *) (* Iteration 2 *) f (* Skipped *) (* Iteration 3 *) _ (* Skipped *) (* Iteration 4 *) Blank (* Skipped *) (* Iteration 5 *) f (* PRINTED *) (* Iteration 6 *) f[_] (* Skipped *) (* Iteration 7 *) g[f] (* PRINTED *)
What is the most efficient way to maintain a set of expressions that have been already printed and validate newly generated expressions against this set?