{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Statement\n\nThe assignment axiom states that, after the assignment, any predicate that was previously true for the right-hand side of the assignment now holds for the variable. Formally, let $P$ be an assertion in which the variable $x$ is free. Then:\n\n$$\\dfrac{}{\\{P[E/x]\\} x := E \\{P\\}}$$\n\nwhere $P[E/x]$ denotes the assertion $P$ in which each free occurrence of $x$ has been replaced by the expression $E$.\n\nThe assignment axiom scheme means that the truth of $P[E/x]$ is equivalent to the after-assignment truth of $P$. Thus, were $P[E/x]$ true before the assignment, by the assignment axiom, then $P$ would be true afterwards. Conversely, were $P[E/x]$ false (i.e. $\\neg P[E/x]$ true) prior to the assignment statement, $P$ must then be false afterwards.\n\nExamples of valid triples include:\n\n- $$\\{ x+1 = 43 \\} y := x + 1 \\{ y = 43 \\}$$\n- $$\\{ x + 1 \\leq N \\} x := x + 1 \\{ x \\leq N \\}$$\n\nAll preconditions that are not modified by the expression can be carried over to the postcondition. In the first example, assigning $y:=x+1$ does not change the fact that $x+1=43$, so both statements may appear in the postcondition. Formally, this result is obtained by applying the axiom schema with $P$ being ($y=43$ and $x+1=43$), which yields $P[(x+1)/y]$ being ($x+1=43$ and $x+1=43$), which can in turn be simplified to the given precondition $x+1=43$.\n\nThe assignment axiom scheme is equivalent to saying that to find the precondition, first take the post-condition and replace all occurrences of the left-hand side of the assignment with the right-hand side of the assignment. Be careful not to try to do this backwards by following this *incorrect* way of thinking: $\\{P\\} x:=E \\{P[E/x]\\}$; this rule leads to nonsensical examples like:\n\n$$\\{ x = 5 \\} x := 3 \\{ 3 = 5 \\}$$\n\nAnother *incorrect* rule looking tempting at first glance is $\\{P\\} x:=E \\{P \\wedge x=E\\}$; it leads to nonsensical examples like:\n\n$$\\{ x = 5 \\} x := x + 1 \\{ x = 5 \\wedge x = x + 1 \\}$$\n\nWhile a given postcondition $P$ uniquely determines the precondition $P[E/x]$, the converse is not true. For example:\n\n- $$\\{ 0 \\leq y\\cdot y \\wedge y\\cdot y \\leq 9 \\} x := y \\cdot y \\{ 0 \\leq x \\wedge x \\leq 9 \\},$$\n- $$\\{ 0 \\leq y\\cdot y \\wedge y\\cdot y \\leq 9 \\} x := y \\cdot y \\{ 0 \\leq x \\wedge y\\cdot y \\leq 9 \\},$$\n- $\\{ 0 \\leq y\\cdot y \\wedge y\\cdot y \\leq 9 \\} x := y \\cdot y \\{ 0 \\leq y\\cdot y \\wedge x \\leq 9 \\}$, and\n- $$\\{ 0 \\leq y\\cdot y \\wedge y\\cdot y \\leq 9 \\} x := y \\cdot y \\{ 0 \\leq y\\cdot y \\wedge y\\cdot y \\leq 9 \\}$$\n\nare valid instances of the assignment axiom scheme.\n\nThe assignment axiom proposed by Hoare *does not apply* when more than one name may refer to the same stored value. For example,\n\n$$\\{ y = 3 \\} x := 2 \\{ y = 3 \\}$$\n\nis wrong if $x$ and $y$ refer to the same variable (aliasing), although it is a proper instance of the assignment axiom scheme (with both $\\{P\\}$ and $\\{P[2/x]\\}$ being $\\{y=3\\}$).\n",
  "commit": "4a3290d299c8b2cd6493fce2296920ba7f82d942",
  "front": {
    "inventory": [
      "9VC448M8FR"
    ],
    "kind": "statement",
    "name": "Assignment axiom schema",
    "role": "proposition",
    "sources": [
      {
        "locator": "Hoare logic, section Rules \u003e Assignment axiom schema",
        "mention": "wikipedia://en/182708#JQAJ",
        "note": "adopted",
        "sections": [
          "Statement"
        ],
        "wikipedia": "en:182708@r1359292368"
      }
    ],
    "tag": "EDH0T8EKDE"
  },
  "kind": "statement",
  "link": "https://math2.tamnd.com/node/EDH0T8EKDE/",
  "links": null,
  "markdown": "https://math2.tamnd.com/node/EDH0T8EKDE.md",
  "msc": null,
  "name": "Assignment axiom schema",
  "prov": null,
  "role": "proposition",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/EDH/EDH0T8EKDE.md",
  "status": null,
  "tag": "EDH0T8EKDE",
  "uri": "m2://EDH0T8EKDE",
  "url": "https://math2.tamnd.com/wiki/assignment-axiom-schema/",
  "writing": {
    "tag": "EDH0T8EKDE",
    "kind": "statement",
    "level": "W0",
    "next": [
      {
        "what": "edge uses out",
        "note": "each definition that the statement needs",
        "have": 0,
        "want": 1
      }
    ]
  }
}
