I have a set of replacement rules I use to analytically compute nested integrals of very long symbolic expressions since Integrate literally takes forever. To do that I use List@@ to transform a sum into a list of summands and apply my rules to each element of the list list. An example that causes problems at later evaluation is e.g.
list = {Cos[x], Sin[x], -( Cos[t3 (d1 - d2)]/(1728 tg^3 (d1 - d2)^2)) + Cos[t3 (d1 - d2)]/(864 tg^3 (d1 - d2) (-d1 + d2)) + Cos[t3 (d1 - d2)]/(864 tg^3 (d1 - d2) (2 (d1 - d2) - 2 (-d1 + d2))) - Cos[t3 (d1 - d2)]/(864 tg^3 (d1 - d2) (2 (d1 - d2) + 2 (-d1 + d2))) + Cos[3 t3 (d1 - d2)]/(1728 tg^3 (d1- d2)^2) - Cos[t3 (d1 - d2) - 2 t3 (-d1 + d2)]/(864 tg^3 (d1 - d2) (2 (d1- d2) - 2 (-d1 + d2))) - Cos[t3 (d1 - d2) + 2 t3 (-d1 + d2)]/(864 tg^3 (d1 - d2) (-d1 + d2)) + Cos[3 t3 (d1 - d2) + 2 t3 (-d1 + d2)]/(864 tg^3 (d1 - d2) (2 (d1 - d2) + 2 (-d1 + d2))) + (t3 Sin[t3 (d1 - d2)])/(432 tg^3 (d1 - d2))}; For later computation I do for instance need list[[3]] /. {d1 -> 0.045, d2 -> -0.35} which will evaluate to Indeterminate since there is a 1/0 component inside due to the way the previous replacement rules work. But observe that
(Simplify@list[[3]]) /. {d1 -> 0.045, d2 -> -0.35} works fine and yields the correct result (compared to Integrate result for that specific element), since the terms causing ComplexInfinity in fact cancel out. Note that I cannot include Simplify in my replacement rules because there are only few terms having that particular problem, simplifying the rest is not necessary and takes forever as well.
My goal is to perform a check, e.g. apply the replacement {d1 -> 0.045, d2 -> -0.35} to my list list, look for Indeterminate warning and only apply Simplify to those terms that cause the warning. The simplified terms should still depend on d1,d2 so the replacement of those should only be used to find critical list elements.
How can this be achieved at all? In principle, I would prefer a solution where you would directly apply Simplify if the warning is recognized to avoid multiple calls of the list. However, since I am clueless on how to do it at all I will be happy with any solution, anyway.
Edit To avoid misunderstandings: For this example, Simplify yields a result almost instantly. That is not the case for my full set of lists/terms. There seems to be no chance to Simplify the list - even with appropriate assumptions - in reasonable timescales.
Edit 2 As pointed out in a comment below, Szabolcs' suggestion to Map a function like checkInt[expr_, rule_] := Quiet[Check[expr /. rule, Simplify[expr]]]; over list did indeed work (i) at all and (ii) in reasonable time. Compared to trying to simplify the whole list - which has not even finished after multiple days - I was now able to achieve what I want in roughly 35 minutes.
Mapthis?f[expr_] := Module[{result}, result = expr /. rules; If[result == Indeterminate, result = Simplify[expr] /. rules]; result]. Or this?Check[# /. rules, Simplify[#] /. rules] &.Checkcan check for specific messages only andQuietcan silence them. $\endgroup$Map[f,list]does not work since it seems that theIndeterminatecase is not recognized properly. However, your second suggestion usingCheckworks perfectly fine! If you post it as an answer, I can accept. Also, many thanks for pointing to RUBI which may definitely be of interest for me :) $\endgroup$