But I now struggle with how to integrate it with the second part (the optimizations), e.g. how to put the implicit Orderings and Ring in this generated Product:
```scala
  def optimizeProductChain[R,C,V](p: IndexedSeq[Literal[R,C,V]]): (Long, Matrix2[R,C,V]) = {
(...)
    def generatePlan(i: Int, j: Int): Matrix2[R,C,V] = {
      if (i == j) p(i)
      else {
        val k = splitMarkers((i, j))
        val left = generatePlan(i, k)
        val right = generatePlan(k + 1, j)
        val result = Product(left, right, true)
     (...)