{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Definition\n\nLet $R$ be a [[ring|0B1261B5ED]], let $n = 2^m$ with $m \\ge 0$, and let $A$, $B$ be $n \\times n$ [[matrices|0VD9ZSWWJG]] over $R$.\nThe *Strassen algorithm* computes $C = AB$ as follows.\nIf $n = 1$, it returns the product of the two entries.\nOtherwise it splits $A$, $B$ and $C$ into four blocks of size $n/2$, as in $A = \\begin{pmatrix} A_{11} \u0026 A_{12} \\\\ A_{21} \u0026 A_{22} \\end{pmatrix}$.\nIt computes seven products, each by a recursive call:\n$$\\begin{aligned}\nM_1 \u0026= (A_{11} + A_{22})(B_{11} + B_{22}), \u0026 M_2 \u0026= (A_{21} + A_{22}) B_{11}, \\\\\nM_3 \u0026= A_{11}(B_{12} - B_{22}), \u0026 M_4 \u0026= A_{22}(B_{21} - B_{11}), \\\\\nM_5 \u0026= (A_{11} + A_{12}) B_{22}, \u0026 M_6 \u0026= (A_{21} - A_{11})(B_{11} + B_{12}), \\\\\nM_7 \u0026= (A_{12} - A_{22})(B_{21} + B_{22}).\n\\end{aligned}$$\nThen it returns\n$$C_{11} = M_1 + M_4 - M_5 + M_7, \\quad C_{12} = M_3 + M_5, \\quad C_{21} = M_2 + M_4, \\quad C_{22} = M_1 - M_2 + M_3 + M_6.$$\n\n## Remarks\n\nThe formulas never use commutativity of $R$, which is why they can be applied to blocks.\nWith $T(n)$ the number of ring operations, $T(n) = 7\\,T(n/2) + 18 (n/2)^2$, so $T(n) = O(n^{\\log_2 7})$ in [[big O notation|0TGV80E6A4]].\nMatrices of other sizes are padded with zero rows and columns up to the next power of $2$.\nExample: for $A = \\begin{pmatrix} 1 \u0026 2 \\\\ 3 \u0026 4 \\end{pmatrix}$ and $B = \\begin{pmatrix} 5 \u0026 6 \\\\ 7 \u0026 8 \\end{pmatrix}$, the products are $M_1 = 65$, $M_2 = 35$, $M_3 = -2$, $M_4 = 8$, $M_5 = 24$, $M_6 = 22$, $M_7 = -30$, and they give $C = \\begin{pmatrix} 19 \u0026 22 \\\\ 43 \u0026 50 \\end{pmatrix}$, which equals $AB$.\nNon-example: the schoolbook recursion with the eight block products $A_{i1} B_{1j} + A_{i2} B_{2j}$ satisfies $T(n) = 8\\,T(n/2) + O(n^2)$, which gives only $O(n^3)$.\nIn practice one switches to the ordinary method below some block size, because the extra additions make the recursion slower for small matrices.\n",
  "commit": "547b6eddb8f2feb8d579f2d633d22a27b7e132fc",
  "front": {
    "defines": "3CVWXDS4JQ",
    "kind": "definition",
    "msc": [
      "65F30",
      "68Q25",
      "15A69"
    ],
    "name": "Strassen algorithm",
    "sources": [
      {
        "url": "https://en.wikipedia.org/wiki/Strassen_algorithm"
      }
    ],
    "tag": "KF7HK5Z9XW",
    "uses": [
      "0VD9ZSWWJG",
      "032Q9FB8MT",
      "0B1261B5ED",
      "0TGV80E6A4"
    ]
  },
  "kind": "definition",
  "link": "https://math2.tamnd.com/node/KF7HK5Z9XW/",
  "links": [
    {
      "field": "defines",
      "target": "3CVWXDS4JQ"
    },
    {
      "field": "uses",
      "target": "0VD9ZSWWJG"
    },
    {
      "field": "uses",
      "target": "032Q9FB8MT"
    },
    {
      "field": "uses",
      "target": "0B1261B5ED"
    },
    {
      "field": "uses",
      "target": "0TGV80E6A4"
    }
  ],
  "markdown": "https://math2.tamnd.com/node/KF7HK5Z9XW.md",
  "msc": [
    "65F30",
    "68Q25",
    "15A69"
  ],
  "name": "Strassen algorithm",
  "prov": null,
  "role": "",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/KF7/KF7HK5Z9XW.md",
  "status": null,
  "tag": "KF7HK5Z9XW",
  "uri": "m2://KF7HK5Z9XW",
  "url": "https://math2.tamnd.com/wiki/strassen-algorithm-definition/",
  "writing": {
    "tag": "KF7HK5Z9XW",
    "kind": "definition",
    "level": "W0",
    "next": [
      {
        "what": "a source with a locator",
        "have": 0,
        "want": 1
      }
    ]
  }
}
