def reparameterize(
        base, parameters, translation, filename=None,
        title=None, insert_after=None, docs=None, name=None,
        source=None,
    ):
    """
    Reparameterize an existing model.

    *base* is the original modelinfo. This cannot be a reparameterized model;
    only one level of reparameterization is supported.

    *parameters* are the new parameter definitions that will be
    included in the model info.

    *translation* is a string each line containing *var = expr*.  The variable
    *var* can be a new intermediate value, or it can be a parameter from
    the base model that will be replace by the expression.  The expression
    *expr* can be any C99 expression, including C-style if-expressions
    *condition ? value1 : value2*.  Expressions can use any new or existing
    parameter that is not being replaced including intermediate values that
    are previously defined.  Parameters can only be assigned once, never
    updated.  C99 math functions are available, as well as any functions
    defined in the base model or included in *source* (see below).

    *filename* is the filename for the replacement model.  This is usually
    *__file__*, giving the path to the model file, but it could also be a
    nominal filename for translations defined on-the-fly.

    *title* is the model title, which defaults to *base.title* plus
    " (reparameterized)".

    *insert_after* controls parameter placement.  By default, the new
    parameters replace the old parameters in their original position.
    Instead, you can provide a dictionary *{'par': 'newpar1,newpar2'}*
    indicating that new parameters named *newpar1* and *newpar2* should
    be included in the table after the existing parameter *par*, or at
    the beginning if *par* is the empty string.

    *docs* constains the doc string for the translated model, which by default
    references the base model and gives the *translation* text.

    *name* is the model name (default = :code:`"constrained_" + base.name`).

    *source* is a list any additional C source files that should be included to
    define functions and constants used in the translation expressions.  This
    will be included after all sources for the base model.  Sources will only
    be included once, even if they are listed in both places, so feel free to
    list all dependencies for the helper function, such as "lib/polevl.c".
    """
    if not isinstance(base, modelinfo.ModelInfo):
        base = load_model_info(base)
    if name is None:
        name = filename if filename is not None else "constrained_" + base.name
    name = os.path.basename(name).split('.')[0]
    if title is None:
        title = base.title + " (reparameterized)"
    if docs is None:
        lines = "\n    ".join(s.lstrip() for s in translation.split('\n'))
        docs = _REPARAMETERIZE_DOCS%{'base': base.id, 'translation': lines}
    #source = merge_deps(base.source, source)
    source = (base.source + [f for f in source if f not in base.source]
              if source else base.source)


    # TODO: don't repeat code from generate._build_translation
    base_pars = [par.id for par in base.parameters.kernel_parameters]
    old_pars = [match.group(1) for match in _LHS_RE.finditer(translation)
                if match.group(1) in base_pars]
    new_pars = [modelinfo.parse_parameter(*p) for p in parameters]
    table = modelinfo.derive_table(base.parameters, remove=old_pars,
                                   insert=new_pars, insert_after=insert_after)

    caller = copy.copy(base)
    caller.translation = translation
    caller.name = caller.id = name
    caller.docs = docs
    caller.filename = filename
    caller.parameters = table
    caller.source = source
    return caller