<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def substitute_symbol_table(table, version, max_id):
 """Substitutes a given shared symbol table for another version. * If the given table has **more** symbols than the requested substitute, then the generated symbol table will be a subset of the given table. * If the given table has **less** symbols than the requested substitute, then the generated symbol table will have symbols with unknown text generated for the difference. Args: table (SymbolTable):
 The shared table to derive from. version (int):
 The version to target. max_id (int):
 The maximum ID allocated by the substitute, must be ``>= 0``. Returns: SymbolTable: The synthesized table. """

    if not table.table_type.is_shared:
        raise ValueError('Symbol table to substitute from must be a shared table')
    if version <= 0:
        raise ValueError('Version must be grater than or equal to 1: %s' % version)
    if max_id < 0:
        raise ValueError('Max ID must be zero or positive: %s' % max_id)

    # TODO Recycle the symbol tokens from the source table into the substitute.
    if max_id <= table.max_id:
        symbols = (token.text for token in islice(table, max_id))
    else:
        symbols = chain(
            (token.text for token in table),
            repeat(None, max_id - table.max_id)
        )

    return SymbolTable(
        table_type=SHARED_TABLE_TYPE,
        symbols=symbols,
        name=table.name,
        version=version,
        is_substitute=True
    )