Skip to content

Instantly share code, notes, and snippets.

@paulp
Last active March 6, 2017 22:12
Show Gist options
  • Save paulp/c9065356441cdc2632e8d62adb85e302 to your computer and use it in GitHub Desktop.
Save paulp/c9065356441cdc2632e8d62adb85e302 to your computer and use it in GitHub Desktop.
matryoshka
*** v *** *** vopt *** *** vsub *** *** voptsub ***
'x := 'x := <?> <?>
| | | |
+- 3 +- 3 +- <?> +- 10
| | | | |
`- <?> `- <?> | +- 2 `- <?>
| | | | |
+- <?> +- 10 | `- 3 +- 3
| | | | |
| +- 2 `- <?> `- <?> `- 3
| | | |
| `- 'x +- 'x +- 5
| | |
`- <?> `- 'x `- 3
|
+- 5
|
`- 'x
val v = let('x, 3, mul(mul(2, 'x), mul(5, 'x)))
val vopt = v.cata[Fix[Exp]] {
case Mul(Embed(LinearTerm(n1, v1)), Embed(LinearTerm(n2, v2))) if v1 == v2 => mul(n1 * n2, mul(v1, v1))
case x => x.embed
}
val vsub = v.topDownCata(noVars[Fix])(subst)
val voptsub = vopt.topDownCata(noVars[Fix])(subst)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment