Implement union method for Grid instances
Addition (union operation) shall also be implemented for the underlying Grid instances. Previously, addition/union is already implemented for multi-index set of exponents (Issue #124 (closed)).
The addition between two instances of Grid
instances means:
- add the underlying multi-index set that results in a new multi-index set.
- create a new instance of
Grid
with the new multi-index set.
Inplace multiplication will not be implemented for the time being as it will create another level of complexity in the codebase to maintain the mutability of an instance. This issue assumes that adding two instances of Grid
will return a new instance of Grid
.
This issue is part of the update and refactoring of the Grid
class (Issue #135).
Implementation details
A common operation that appears in multiplication, addition, and dimension expansion is "merging". A merging is defined by creating a new instance of Grid
with a new multi-index set as long as the underlying generating functions and points of the two instances are compatible:
- If the generating functions are available in both instances and they are compatible: create a new instance with the given multi-index set and the generating function
- If the generating functions are available in both instances and they are incompatible: raise an exception. There is no reference to which the grids can be merged
- If there is no generating function and the generating points are compatible: create a new instance with the given multi-index set and the larger generating points
- If there is no generating function and the generating points are incompatible: raise an exception. There is no reference to which the grids can be merged
Via merging, the difference between dimension expansion, multiplication, and addition is the multi-index set used to create the merged instance.
The bigger picture
Allowing the addition between instances of Grid
will improve the encapsulation within the polynomial-polynomial addition and subtraction (see, for instance, Issue #140 (closed) for polynomials in the Newton basis).
Addition or subtraction between polynomials then means:
- Expand the dimension of the polynomial whose the lower dimension
- Add the underlying
Grid
instances - Add the underlying
MultiIndexSet
instances if they are not the same as the one attached to theGrid
instance - Process the coefficients according to the basis (note that addition in different bases may yield a different procedure to process the resulting coefficients)
- Create a new instance of polynomial with the new
Grid
instance, coefficients, and (when applicable)MultiIndexSet
instance.