{ "cells" : [ { "cell_origin" : "client", "cell_type" : "latex", "cells" : [ { "cell_origin" : "client", "cell_type" : "latex_view", "source" : "\\algorithm{take_match}{Select a subset of terms in a sum for further computations.}\n\nThe \\algo{take_match} and \\algo{replace_match} algorithms enable you to temporarily work\nonly on a part of an expression. You select the terms that you want to work on with\n\\algo{take_match}. When you are done, put the result back into the larger expression \nwith \\algo{replace_match}.\n\nA simple example shows how this works:" } ], "hidden" : true, "source" : "\\algorithm{take_match}{Select a subset of terms in a sum for further computations.}\n\nThe \\algo{take_match} and \\algo{replace_match} algorithms enable you to temporarily work\nonly on a part of an expression. You select the terms that you want to work on with\n\\algo{take_match}. When you are done, put the result back into the larger expression \nwith \\algo{replace_match}.\n\nA simple example shows how this works:" }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "latex_view", "source" : "\\begin{dmath*}{}A C+B D G+C D A\\end{dmath*}" } ], "source" : "ex:=A C + B D G + C D A;" }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "latex_view", "source" : "\\begin{dmath*}{}B D G+C D A\\end{dmath*}" } ], "source" : "take_match(_, $D Q??$);" }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "latex_view", "source" : "\\begin{dmath*}{}B D G+Q D A\\end{dmath*}" } ], "source" : "substitute(_, $C -> Q$);" }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "latex_view", "source" : "\\begin{dmath*}{}A C+B D G+Q D A\\end{dmath*}" } ], "source" : "replace_match(_);" }, { "cell_origin" : "client", "cell_type" : "latex", "cells" : [ { "cell_origin" : "client", "cell_type" : "latex_view", "source" : "As you can see here, the replacement $C\\rightarrow Q$ was only done on the 2nd and 3rd term\nof the original expression, to which we restricted all manipulations using the \\algo{take_match}\ncommand.\n\nThis of course also works with more complicated, tensorial expressions, as the example below shows." } ], "hidden" : true, "source" : "As you can see here, the replacement $C\\rightarrow Q$ was only done on the 2nd and 3rd term\nof the original expression, to which we restricted all manipulations using the \\algo{take_match}\ncommand.\n\nThis of course also works with more complicated, tensorial expressions, as the example below shows." }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "latex_view", "source" : "\\begin{dmath*}{}A_{m n} \\chi B^{m}\\,_{p}+\\psi A_{n p}\\end{dmath*}" } ], "source" : "ex:= A_{m n} \\chi B^{m}_{p} + \\psi A_{n p};" }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "latex_view", "source" : "\\begin{dmath*}{}A_{m n} \\chi B^{m}\\,_{p}\\end{dmath*}" } ], "source" : "take_match(_, $\\chi Q??$);" }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "latex_view", "source" : "\\begin{dmath*}{}C_{m n} \\chi B^{m}\\,_{p}\\end{dmath*}" } ], "source" : "substitute(_, $A_{m n} -> C_{m n}$);" }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "latex_view", "source" : "\\begin{dmath*}{}C_{m n} \\chi B^{m}\\,_{p}+\\psi A_{n p}\\end{dmath*}" } ], "source" : "replace_match(_);" }, { "cell_origin" : "client", "cell_type" : "latex", "cells" : [ { "cell_origin" : "client", "cell_type" : "latex_view", "source" : "When you are working on a part of an expression, you can restrict attention further by applying\n\\algo{take_match} again. The \\algo{replace_match} then puts sub-expressions back into the larger expression in \nreverse order:" } ], "hidden" : true, "source" : "When you are working on a part of an expression, you can restrict attention further by applying\n\\algo{take_match} again. The \\algo{replace_match} then puts sub-expressions back into the larger expression in \nreverse order:" }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "latex_view", "source" : "\\begin{dmath*}{}A B+C B+C D B\\end{dmath*}" } ], "source" : "ex:=A B + C B + C D B;" }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "latex_view", "source" : "\\begin{dmath*}{}C B+C D B\\end{dmath*}" } ], "source" : "take_match(_, $C Q??$);" }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "latex_view", "source" : "\\begin{dmath*}{}Q B+Q D B\\end{dmath*}" } ], "source" : "substitute(_, $C -> Q$);" }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "latex_view", "source" : "\\begin{dmath*}{}Q D B\\end{dmath*}" } ], "source" : "take_match(_, $D Q??$);" }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "latex_view", "source" : "\\begin{dmath*}{}Q D R\\end{dmath*}" } ], "source" : "substitute(_, $B -> R$);" }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "latex_view", "source" : "\\begin{dmath*}{}Q B\\end{dmath*}" } ], "source" : "replace_match(_);" }, { "cell_origin" : "client", "cell_type" : "input", "cells" : [ { "cell_origin" : "server", "cell_type" : "latex_view", "source" : "\\begin{dmath*}{}A B+Q B\\end{dmath*}" } ], "source" : "replace_match(_);" }, { "cell_origin" : "client", "cell_type" : "input", "source" : "" } ], "description" : "Cadabra JSON notebook format", "version" : 1 }