Re: How to remove unneeded constraints

*To*: mathgroup at smc.vnet.net*Subject*: [mg87940] Re: How to remove unneeded constraints*From*: Szabolcs Horvát <szhorvat at gmail.com>*Date*: Mon, 21 Apr 2008 03:22:51 -0400 (EDT)*Organization*: University of Bergen*References*: <fueeo7$b82$1@smc.vnet.net>

Kristian Schmidt wrote: > Hello > > The problem I am working on is a pretty large problem, which I am solving by dividing it into a lot of subproblems. > > As such, I have a large list of constraints that apply to the entire problem, but are not relevant for each individual subproblem. > > This becomes a problem when I use Refine, as it takes a very long time when you have a lot of conditions, even though the conditions don't pertain to the problem. Example: > In[25]:= Table[Timing@Refine[p>q,Map[Subscript[x,#]>0&,Range[i]]],{i,1000,5000,1000}] > Out[25]= {{0.547,p>q},{1.797,p>q},{3.875,p>q},{8.594,p>q},{10.468,p>q}} > > And it only gets worse. > > However, for each individual call to Refine I make, I only need a small subset of the total constraints. > > So what I want to do is something like this: > expr = some expression of n different variables; > cond = DeleteCases[totalConstraints, all cases which do not contain a variable from expr]; > result = Refine[expr,cond]; > > I have no idea how to construct a pattern powerful enough to do what is required for the DeleteCases call, though. > > All of the variables are of the form Subscript[s,_,_,_] or Subscript[b,_,_] and the conditions can also contain expressions of several variables. > > I'd be most grateful for any help. Thank you. > The following should work if the constraints are just a linear concatenation of equations/inequalities: In[1]:= expr = Subscript[a, 1] + Subscript[a, 2] Subscript[a, 3] Out[1]= Subscript[a, 1] + Subscript[a, 2] Subscript[a, 3] In[2]:= constraints = And @@ (Subscript[a, #] > 0 & /@ Range[5000]); In[3]:= Timing[ filteredConstraints = With[ {relevantVariables = Union@Cases[expr, Subscript[__], Infinity]}, Select[constraints, ! FreeQ[#, Alternatives @@ relevantVariables] &] ] ] Out[3]= {0.047, Subscript[a, 1] > 0 && Subscript[a, 2] > 0 && Subscript[a, 3] > 0} In[4]:= Refine[expr > 0, filteredConstraints] // Timing Out[4]= {0., True} In[5]:= Refine[expr > 0, constraints] // Timing Out[5]= {10.797, True}