CChainArbor
Product

Product features · Matrix-chain cost planning

01

Start from the chain dimensions in the calling code and review a cost-table trace separately from the routine that multiplies matrix entries.

01

Connection

Base URL, credentials and a reachable server.

02

Selection

A model available through the configured endpoint.

03

Capabilities

Context limits and tool support are determined by the model and server.

Matrix-chain cost planning

● ● ●ChainArbor●
A concrete starting point · Matrix-chain cost planning ×
def chain_cost(dimensions):
    if type(dimensions) not in (list, tuple) or not 2 <= len(dimensions) <= 13:
        raise ValueError("one through twelve matrices")
    if any(type(d) is not int or not 1 <= d <= 1000 for d in dimensions):
        raise ValueError("dimensions 1 through 1000")
    n = len(dimensions)-1
    cost = [[0]*n for _ in range(n)]
    for width in range(2, n+1):
        for left in range(n-width+1):
            right = left+width-1
            cost[left][right] = min(
                cost[left][k]+cost[k+1][right]+
                dimensions[left]*dimensions[k+1]*dimensions[right+1]
                for k in range(left,right))
    return cost[0][n-1]
✳Find the minimum scalar-multiplication cost for a chain of up to 12 matrices.
✓ ChangesReview before applying ↗
Illustrative workspace
AI coding workspace

Your next change starts here.

Get the Windows app ↗