Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to remove unneeded constraints

  • To: mathgroup at smc.vnet.net
  • Subject: [mg87965] Re: How to remove unneeded constraints
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Mon, 21 Apr 2008 03:27:30 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <fueeo7$b82$1@smc.vnet.net>

Kristian Schmidt wrote:

> 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.

Hi Kristian,

A possible solution that I would recommend uses *FreeQ[]* for pattern 
matching and *Pick[]* to build the list of constraints that do not 
contains the unneeded variables.

In[1]:=

(* We make an arbitrary list of constraints *)

conds = {E^(Subscript[s, 1, 1, 2] + Subscript[b, 3, 1]) > 1,
    E^(Subscript[s, 1, 1, 3] + Subscript[b, 3, 1])/+Subscript[b, 2, 2] 
<= 100,
    Abs[Log[Subscript[s, 1, 1, 3]^Sin[Subscript[b, 1, 2] Pi]]] <= 2};

(* We look for any expression that does not have a variable s for which 
the third index is 3 *)

FreeQ[#, Subscript[s, _, _, 3] ] & /@ conds

(*We look for any expression that does not have the variable b with 
first index equal to 3 *)

FreeQ[#, Subscript[b, 3, _] ] & /@ conds

(* The returned list does not contain any expression that contains the 
variable s for which its third index is 3 *)

Pick[conds, FreeQ[#, Subscript[s, _, _, 3] ] & /@ conds]

(* The following examples should be self-explanatory by now *)

Pick[#, FreeQ[#, Subscript[b, ___, 3, ___] ] & /@ #] &@conds

Pick[#, FreeQ[#, Subscript[_, 1, 2, ___] ] & /@ #] &@conds

Pick[#, FreeQ[#, Subscript[b, 1, 2] | Subscript[s, 1, _, 2]] & /@ #] &@conds

Out[2]= {True, False, False}

Out[3]= {False, False, True}

Out[4]=

   b    + s
    3,1    1,1,2
{E              > 1}

Out[5]=

                Sin[Pi b   ]
                        1,2
{Abs[Log[s                 ]] <= 2}
           1,1,3

Out[6]=

                       b    + s
   b    + s             3,1    1,1,3
    3,1    1,1,2      E
{E              > 1, -------------- <= 100}
                           b
                            2,2

Out[7]=

   b    + s
    3,1    1,1,3
  E
{-------------- <= 100}
       b
        2,2


Regards,
-- Jean-Marc


  • Prev by Date: Re: Parallel Computing Toolkit with ssh tunnels
  • Next by Date: Re: Re: A Problem with Simplify
  • Previous by thread: Re: How to remove unneeded constraints
  • Next by thread: Re: How to remove unneeded constraints