(c, b1, d, b2)
return rv.expand()
Construct c*b1 + d*b2.
Construct c*b1 + d*b2.
Construct c * b1 + d * b2 .
def _add_splines(c, b1, d, b2):
    """Construct c*b1 + d*b2."""
    if b1 == S.Zero or c == S.Zero:
        rv = piecewise_fold(d*b2)
    elif b2 == S.Zero or d == S.Zero:
        rv = piecewise_fold(c*b1)
    else:
        new_args = []
        n_intervals = len(b1.args)
        if n_intervals != len(b2.args):
            raise ValueError("Args of b1 and b2 are not equal")
        new_args.append((c*b1.args[0].expr, b1.args[0].cond))
        for i in range(1, n_intervals - 1):
            new_args.append((
                c*b1.args[i].expr + d*b2.args[i - 1].expr,
                b1.args[i].cond
            ))
        new_args.append((d*b2.args[-2].expr, b2.args[-2].cond))
        new_args.append(b2.args[-1])
        rv = Piecewise(*new_args)

    return rv.expand()
def _add_splines ( c , b1 , d , b2 ) : if b1 == S . Zero or c == S . Zero : rv = piecewise_fold ( d * b2 ) elif b2 == S . Zero or d == S . Zero : rv = piecewise_fold ( c * b1 ) else : new_args = [ ] n_intervals = len ( b1 . args ) if n_intervals != len ( b2 . args ) : raise ValueError ( "Args of b1 and b2 are not equal" ) new_args . append ( ( c * b1 . args [ 0 ] . expr , b1 . args [ 0 ] . cond ) ) for i in range ( 1 , n_intervals - 1 ) : new_args . append ( ( c * b1 . args [ i ] . expr + d * b2 . args [ i - 1 ] . expr , b1 . args [ i ] . cond ) ) new_args . append ( ( d * b2 . args [ - 2 ] . expr , b2 . args [ - 2 ] . cond ) ) new_args . append ( b2 . args [ - 1 ] ) rv = Piecewise ( * new_args ) return rv . expand ( )