<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def add(*args):
 """Polynomial addition."""

    if len(args) > 2:
        return add(args[0], add(args[1], args[1:]))

    if len(args) == 1:
        return args[0]

    part1, part2 = args

    if isinstance(part2, Poly):

        if part2.dim > part1.dim:
            part1 = chaospy.dimension.setdim(part1, part2.dim)
        elif part2.dim < part1.dim:
            part2 = chaospy.dimension.setdim(part2, part1.dim)

        dtype = chaospy.poly.typing.dtyping(part1.dtype, part2.dtype)

        core1 = part1.A.copy()
        core2 = part2.A.copy()

        if np.prod(part2.shape) > np.prod(part1.shape):
            shape = part2.shape
            ones = np.ones(shape, dtype=int)
            for key in core1:
                core1[key] = core1[key]*ones
        else:
            shape = part1.shape
            ones = np.ones(shape, dtype=int)
            for key in core2:
                core2[key] = core2[key]*ones

        for idx in core1:
            if idx in core2:
                core2[idx] = core2[idx] + core1[idx]
            else:
                core2[idx] = core1[idx]
        out = core2

        return Poly(out, part1.dim, shape, dtype)

    part2 = np.asarray(part2)

    core = part1.A.copy()
    dtype = chaospy.poly.typing.dtyping(part1.dtype, part2.dtype)

    zero = (0,)*part1.dim

    if zero not in core:
        core[zero] = np.zeros(part1.shape, dtype=int)

    core[zero] = core[zero] + part2

    if np.prod(part2.shape) > np.prod(part1.shape):

        ones = np.ones(part2.shape, dtype=dtype)
        for key in core:
            core[key] = core[key]*ones

    return Poly(core, part1.dim, None, dtype)