Changeset 614 for branches


Ignore:
Timestamp:
12/18/12 19:39:55 (3 years ago)
Author:
mmckerns
Message:

cleaned up documentation; bugfix for when nvars is less than list of variables;
added sympy-specific functions from alta's mystic.constraints

Location:
branches/decorate
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • branches/decorate/symbolic.py

    r613 r614  
    215215Returns a tuple of inequality constraints and a tuple of equality constraints. 
    216216 
     217Inputs: 
     218    constraints -- a string of symbolic constraints, with one constraint 
     219        equation per line. Constraints can be equality and/or inequality 
     220        constraints. Standard python syntax should be followed (with the 
     221        math and numpy modules already imported). 
     222 
    217223    For example: 
    218224        >>> constraints = ''' 
     
    221227        >>> penalty_parser(constraints, nvars=3) 
    222228        (('-(x[0] - (0.))',), ('x[2] - (x[0]/2.)',)) 
     229 
     230Additional Inputs: 
     231    nvars -- number of variables. Includes variables not explicitly 
     232        given by the constraint equations (e.g. 'x2' in the example above). 
     233    variables -- desired variable name. Default is 'x'. A list of variable 
     234        name strings is also accepted for when desired variable names 
     235        don't have the same base, and can include variables that are not 
     236        found in the constraints equation string. 
    223237    """ 
    224238   #from mystic.tools import src 
    225239   #ndim = len(get_variables(src(func), variables)) 
    226240    if list_or_tuple_or_ndarray(variables): 
     241        if nvars: variables = variables[:nvars] 
    227242        constraints = replace_variables(constraints, variables) 
    228243        varname = '$' 
     
    287302The left-hand side of each constraint must be simplified to support assignment. 
    288303 
     304Inputs: 
     305    constraints -- a string of symbolic constraints, with one constraint 
     306        equation per line. Constraints can be equality and/or inequality 
     307        constraints. Standard python syntax should be followed (with the 
     308        math and numpy modules already imported). 
     309 
    289310    For example: 
    290311        >>> constraints = ''' 
     
    293314        >>> constraints_parser(constraints, nvars=3) 
    294315        ('x[2] = x[0]/2.', 'x[0] = max(0., x[0])') 
     316 
     317Additional Inputs: 
     318    nvars -- number of variables. Includes variables not explicitly 
     319        given by the constraint equations (e.g. 'x2' in the example above). 
     320    variables -- desired variable name. Default is 'x'. A list of variable 
     321        name strings is also accepted for when desired variable names 
     322        don't have the same base, and can include variables that are not 
     323        found in the constraints equation string. 
    295324    """ 
    296325   #from mystic.tools import src 
    297326   #ndim = len(get_variables(src(func), variables)) 
    298327    if list_or_tuple_or_ndarray(variables): 
     328        if nvars: variables = variables[:nvars] 
    299329        constraints = replace_variables(constraints, variables) 
    300330        varname = '$' 
Note: See TracChangeset for help on using the changeset viewer.