Skip to contents

Optimal parenthesisation of a matrix chain (matrix-chain DP)

Usage

morie_geron_matmul_order(dims)

Arguments

dims

Chain dimensions; matrix i has shape (dims[i], dims[i+1]).

Value

list(cost, split) with cost the min multiplication count.

Examples

V <- c(1, 2, 3, 4, 5, 6, 7, 8)
morie_geron_matmul_order(V)
#> $cost
#> [1] 166
#> 
#> $split
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,]    0    1    2    3    4    5    6
#> [2,]    0    0    2    3    4    5    6
#> [3,]    0    0    0    3    4    5    6
#> [4,]    0    0    0    0    4    5    6
#> [5,]    0    0    0    0    0    5    6
#> [6,]    0    0    0    0    0    0    6
#> [7,]    0    0    0    0    0    0    0
#>