Associativity

This Mathematica notebook is licensed under a MouseOver 
It creates the demonstrations used in my post  Monads for High School I

I hope anyone interested will feel free to improve this work and to use it in their own publications and coursework.

Definitions

op[x_,loc_]:=Text[Style[x,13,Bold,Background->White,FontFamily->"Arial"],loc]

op[x_,loc_,weight_]:=Text[Style[x,13,weight,Background->White,FontFamily->"Arial"],loc]

op[x_,loc_,weight_,color_]:=Text[Style[x,13,weight,color,Background->White,FontFamily->"Arial"],loc]

op["x",{0,1}]

op["Plus\n" a+b,{0,0}]

edge[loc1_,loc2_,sf_]:=Arrow[{loc1,loc2},Scaled[sf]]

spd=.0009

Remove[s]

Binary operation examples

plus[ b_,c_]:=Graphics[{
Arrowheads[0],
op[b+c,{-1/2,2}],
op[b,{-1,1}],
op[c,{0,1}],
edge[{-1/2,2},{-1,1},.5 spd],
edge[{-1/2,2},{0,1},.5spd]},
Background->White,ImageSize->60, AspectRatio->1]

plus[2,3]

plus[s_,b_,c_]:=Graphics[{
Arrowheads[0],
op[If [s>0,b+c,"Plus"],{-1/2,2}],
op[b,{-1,1}],
op[c,{0,1}],
edge[{-1/2,2},{-1,1},spd],
edge[{-1/2,2},{0,1},spd]},
Background->White,ImageSize->60, AspectRatio->1]

times[s_,b_,c_]:=Graphics[{
Arrowheads[0],
op[If [s>0,b*c,"Times"],{-1/2,2}],
op[b,{-1,1}],
op[c,{0,1}],
edge[{-1/2,2},{-1,1},spd],
edge[{-1/2,2},{0,1},spd]},
Background->White,ImageSize->60, AspectRatio->1]

minus[s_,b_,c_]:=Graphics[{
Arrowheads[0],
op[If [s>0,b-c,"Minus"],{-1/2,2}],
op[b,{-1,1}],
op[c,{0,1}],
edge[{-1/2,2},{-1,1},spd],
edge[{-1/2,2},{0,1},spd]},
Background->White,ImageSize->60, AspectRatio->1]

exp[s_,b_,c_]:=Graphics[{
Arrowheads[0],
op[If [s>0,b^c,"Exp"],{-1/2,2}],
op[b,{-1,1}],
op[c,{0,1}],
edge[{-1/2,2},{-1,1},spd],
edge[{-1/2,2},{0,1},spd]},
Background->White,ImageSize->60, AspectRatio->1]

f[m_,n_]:=If[m==n,1,n]

madeup[s_,b_,c_]:=Graphics[{Arrowheads[0],
op[If [s>0,f[b,c],"MadeUp"],{-1/2,2}],
op[b,{-1,1}],
op[c,{0,1}],
edge[{-1/2,2},{-1,1},spd],
edge[{-1/2,2},{0,1},spd]},
Background->White,ImageSize->60, AspectRatio->1]

{f[3,f[1,3]],f[f[3,1],3]}

This is binops.cdf

Manipulate[
Grid[{{plus[s,b,c],times[s,b,c]},{minus[s,b,c],exp[s,b,c]}}],
{{s,0,""},{0->"Reset",1->"Evaluate"}},
{{b,1,"left"},{1,2,3,4,5},ControlType->RadioButtonBar},
{{c,2,"right"},{1,2,3,4,5},ControlType->RadioButtonBar},Paneled->False,
ControlPlacement->Left,
SaveDefinitions->True]

Associativity

plus3a[s_,a_,b_,c_]:=Graphics[{
Arrowheads[0],
op[If [s>1,a+b+c,"Plus"],{-1/2,2}],
op[If[s>0,a+b,"Plus"],{-1,1}],
op[c,{0,1}],
op[a,{-1.5,0}],
op[b,{-.5,0}],
edge[{-.5,2},{-1,1},spd],
edge[{-.5,2},{0,1},spd],
edge[{-1,1},{-1.5,0},spd],
edge[{-1,1},{-.5,0},spd]},
Background->White,ImageSize->80, AspectRatio->1]

plus3b[s_,a_,b_,c_]:=Graphics[{
Arrowheads[0],
op[If [s>1,a+b+c,"Plus"],{-1/2,2}],
op[If[s>0,b+c,"Plus"],{0,1}],
op[a,{-1,1}],
op[b,{-.5,0}],
op[c,{.5,0}],
edge[{-1/2,2},{-1,1},spd],
edge[{-1/2,2},{0,1},spd],edge[{0,1},{-.5,0},spd],edge[{0,1},{.5,0},spd]},
Background->White,ImageSize->80, AspectRatio->1]

minus3a[s_,a_,b_,c_]:=Graphics[{
Arrowheads[0],
op[If [s>1,Style[(a-b)-c,Red],"Minus"],{-1/2,2}],
op[If[s>0,a-b,"Minus"],{-1,1}],
op[c,{0,1}],
op[a,{-1.5,0}],
op[b,{-.5,0}],
edge[{-.5,2},{-1,1},spd],
edge[{-.5,2},{0,1},spd],edge[{-1,1},{-1.5,0},spd],edge[{-1,1},{-.5,0},spd]},
Background->White,ImageSize->80, AspectRatio->1]

minus3b[s_,a_,b_,c_]:=Graphics[{
Arrowheads[0],
op[If [s>1,Style[a-(b-c),Red],"Minus"],{-1/2,2}],
op[If[s>0,b-c,"Minus"],{0,1}],
op[a,{-1,1}],
op[b,{-.5,0}],
op[c,{.5,0}],
edge[{-1/2,2},{-1,1},spd],
edge[{-1/2,2},{0,1},spd],edge[{0,1},{-.5,0},spd],edge[{0,1},{.5,0},spd]},
Background->White,ImageSize->80, AspectRatio->1]

This is assocexamples.cdf

Manipulate[Grid[
{{plus3a[s,a,b,c],"  ",plus3b[s,a,b,c]},{minus3a[s,a,b,c],"  ",minus3b[s,a,b,c]}}],
{{s,0,"Steps"},{0->"Reset",1,2}},
{{a,3},{0,1,2,3,4,5},ControlType->RadioButtonBar},
{{b,4},{0,1,2,3,4,5},ControlType->RadioButtonBar},
{{c,2},{0,1,2,3,4,5},ControlType->RadioButtonBar},Paneled->False,
ControlPlacement->Left,
SaveDefinitions->True]

Associativity for four entries

tree1

Manipulate[Show[
Graphics[
{
Arrowheads[0],
op[If [s>2,a+b+c+d,"Plus"],{0,2}],
op[If [s>0,a+b,"Plus"],{-2,1}],
op[If [s>1,c+d,"Plus"],{2,1}],
op[a,{-3,0}],
op[b,{-1,0}],
op[c,{1,0}],
op[d,{3,0}],
edge[{0,2},{-2,1},spd],
edge[{0,2},{2,1},spd],
edge[{2,1},{1,0},spd],
edge[{2,1},{3,0},spd],
edge[{-2,1},{-1,0},spd],
edge[{-2,1},{-3,0},spd]}],
Background->White,ImageSize->90, AspectRatio->4/5
],{{s,0,"Steps"},{1,2,3,0->"Reset"}},
{{a,1},{0,1,2,3,4,5},ControlType->RadioButtonBar},{{b,2},{0,1,2,3,4,5},ControlType->RadioButtonBar},{{c,3},{0,1,2,3,4,5},ControlType->RadioButtonBar},{{d,4},{0,1,2,3,4,5},ControlType->RadioButtonBar},
Paneled->False,ControlPlacement->Left,SaveDefinitions->True
]

Remove[tree1]

tree1[s_,a_,b_,c_,d_]=Graphics[
{
Arrowheads[0],
op[If [s>2,a+b+c+d,"Plus"],{0,2}],
op[If [s>0,a+b,"Plus"],{-2,1}],
op[If [s>1,c+d,"Plus"],{2,1}],
op[a,{-3,0}],
op[b,{-1,0}],
op[c,{1,0}],
op[d,{3,0}],
edge[{0,2},{-2,1},spd],
edge[{0,2},{2,1},spd],
edge[{2,1},{1,0},spd],
edge[{2,1},{3,0},spd],
edge[{-2,1},{-1,0},spd],
edge[{-2,1},{-3,0},spd]},Background->White,ImageSize->90, AspectRatio->4/5]

tree2

Manipulate[Show[
Graphics[
{
Arrowheads[0],
op[If [s>2,a+b+c+d,"Plus"],{0,2}],
op[a,{-1,1}],
op[If [s>1,b+c+d,"Plus"],{1,1}],
op[If [s>0,c+d,"Plus"],{2,0}],
op[b,{-0,0}],
op[c,{1,-1}],
op[d,{3,-1}],
edge[{0,2},{1,1},spd],
edge[{0,2},{-1,1},spd],
edge[{1,1},{2,0},spd],
edge[{1,1},{0,0},spd],
edge[{2,0},{1,-1},spd],
edge[{2,0},{3,-1},spd]}],
Background->White,ImageSize->90, AspectRatio->4/5],{{s,0,"Steps"},{1,2,3,0->"Reset"}},
{{a,1},{0,1,2,3,4,5},ControlType->RadioButtonBar},{{b,2},{0,1,2,3,4,5},ControlType->RadioButtonBar},{{c,3},{0,1,2,3,4,5},ControlType->RadioButtonBar},{{d,4},{0,1,2,3,4,5},ControlType->RadioButtonBar},
Paneled->False,ControlPlacement->Left,SaveDefinitions->True
]

tree2[s_,a_,b_,c_,d_]=Graphics[
{
Arrowheads[0],
op[If [s>2,a+b+c+d,"Plus"],{0,2}],
op[a,{-1,1}],
op[If [s>1,b+c+d,"Plus"],{1,1}],
op[If [s>0,c+d,"Plus"],{2,0}],
op[b,{-0,0}],
op[c,{1,-1}],
op[d,{3,-1}],
edge[{0,2},{1,1},spd],
edge[{0,2},{-1,1},spd],
edge[{1,1},{2,0},spd],
edge[{1,1},{0,0},spd],
edge[{2,0},{1,-1},spd],
edge[{2,0},{3,-1},spd]},Background->White,ImageSize->90, AspectRatio->4/5]

tree3

Manipulate[Show[
Graphics[
{
Arrowheads[0],
op[If [s>2,a+b+c+d,"Plus"],{0,2}],
op[If [s>1,b+c+d,"Plus"],{1,1}],
op[If [s>0,b+c,"Plus"],{0,0}],
op[a,{-1,1}],
op[b,{-1,-1}],
op[c,{1,-1}],
op[d,{2,0}],
edge[{0,2},{1,1},spd],
edge[{0,2},{-1,1},spd],
edge[{1,1},{2,0},spd],
edge[{1,1},{0,0},spd],
edge[{0,0},{1,-1},spd],
edge[{0,0},{-1,-1},spd]}],
Background->White,ImageSize->70, AspectRatio->1],{{s,0,"Steps"},{1,2,3,0->"Reset"}},
{{a,1},{0,1,2,3,4,5},ControlType->RadioButtonBar},{{b,2},{0,1,2,3,4,5},ControlType->RadioButtonBar},{{c,3},{0,1,2,3,4,5},ControlType->RadioButtonBar},{{d,4},{0,1,2,3,4,5},ControlType->RadioButtonBar},
Paneled->False,ControlPlacement->Left,SaveDefinitions->True
]

tree3[s_,a_,b_,c_,d_]=Graphics[
{Arrowheads[0],
op[If [s>2,a+b+c+d,"Plus"],{0,2}],
op[If [s>1,b+c+d,"Plus"],{1,1}],
op[If [s>0,b+c,"Plus"],{0,0}],
op[a,{-1,1}],
op[b,{-1,-1}],
op[c,{1,-1}],
op[d,{2,0}],
edge[{0,2},{1,1},spd],
edge[{0,2},{-1,1},spd],
edge[{1,1},{2,0},spd],
edge[{1,1},{0,0},spd],
edge[{0,0},{1,-1},spd],
edge[{0,0},{-1,-1},spd]},
Background->White,ImageSize->70, AspectRatio->1]

tree4

Manipulate[Show[
Graphics[
{
Arrowheads[0],
op[If [s>2,a+b+c+d,"Plus"],{0,2}],
op[d,{1,1}],
op[If [s>1,a+b+c,"Plus"],{-1,1}],
op[If [s>0,a+b,"Plus"],{-2,0}],
op[c,{0,0}],
op[a,{-3,-1}],
op[b,{-1,-1}],
edge[{0,2},{1,1},spd],
edge[{0,2},{-1,1},spd],
edge[{-1,1},{-2,0},spd],
edge[{-1,1},{0,0},spd],
edge[{-2,0},{-3,-1},spd],
edge[{-2,0},{-1,-1},spd]}],
Background->White,ImageSize->90, AspectRatio->4/5
],{{s,0,"Steps"},{1,2,3,0->"Reset"}},
{{a,1},{0,1,2,3,4,5},ControlType->RadioButtonBar},{{b,2},{0,1,2,3,4,5},ControlType->RadioButtonBar},{{c,3},{0,1,2,3,4,5},ControlType->RadioButtonBar},{{d,4},{0,1,2,3,4,5},ControlType->RadioButtonBar},
Paneled->False,ControlPlacement->Left,SaveDefinitions->True
]

tree4[s_,a_,b_,c_,d_]=Graphics[
{
Arrowheads[0],
op[If [s>2,a+b+c+d,"Plus"],{0,2}],
op[d,{1,1}],
op[If [s>1,a+b+c,"Plus"],{-1,1}],
op[If [s>0,a+b,"Plus"],{-2,0}],
op[c,{0,0}],
op[a,{-3,-1}],
op[b,{-1,-1}],
edge[{0,2},{1,1},spd],
edge[{0,2},{-1,1},spd],
edge[{-1,1},{-2,0},spd],
edge[{-1,1},{0,0},spd],
edge[{-2,0},{-3,-1},spd],
edge[{-2,0},{-1,-1},spd]},Background->White,ImageSize->90, AspectRatio->4/5]

tree5

Manipulate[Show[
Graphics[
{
Arrowheads[0],
op[If [s>2,a+b+c+d,"Plus"],{0,2}],
op[d,{1,1}],
op[If [s>1,a+b+c,"Plus"],{-1,1}],
op[If [s>0,b+c,"Plus"],{0,0}],
op[a,{-2,0}],
op[b,{-1,-1}],
op[c,{1,-1}],
edge[{0,2},{1,1},spd],
edge[{0,2},{-1,1},spd],
edge[{-1,1},{-2,0},spd],
edge[{-1,1},{0,0},spd],
edge[{0,0},{-1,-1},spd],
edge[{0,0},{1,-1},spd]}],
Background->White,ImageSize->70, AspectRatio->1
],{{s,0,"Steps"},{1,2,3,0->"Reset"}},
{{a,1},{0,1,2,3,4,5},ControlType->RadioButtonBar},{{b,2},{0,1,2,3,4,5},ControlType->RadioButtonBar},{{c,3},{0,1,2,3,4,5},ControlType->RadioButtonBar},{{d,4},{0,1,2,3,4,5},ControlType->RadioButtonBar},
Paneled->False,ControlPlacement->Left,SaveDefinitions->True
]

tree5[s_,a_,b_,c_,d_]=Graphics[
{
Arrowheads[0],
op[If [s>2,a+b+c+d,"Plus"],{0,2}],
op[d,{1,1}],
op[If [s>1,a+b+c,"Plus"],{-1,1}],
op[If [s>0,b+c,"Plus"],{0,0}],
op[a,{-2,0}],
op[b,{-1,-1}],
op[c,{1,-1}],
edge[{0,2},{1,1},spd],
edge[{0,2},{-1,1},spd],
edge[{-1,1},{-2,0},spd],
edge[{-1,1},{0,0},spd],
edge[{0,0},{-1,-1},spd],
edge[{0,0},{1,-1},spd]},
Background->White,ImageSize->70, AspectRatio->1]

tree6

Manipulate[
Show[Graphics[{
Arrowheads[0],
op[If [s>0,a+b+c+d,"Plus"],{-1/2,2}],
op[a,{-2,1}],
op[b,{-1,1}],
op[c,{0,1}],
op[d,{1,1}],
edge[{-1/2,2},{-2,1},spd],
edge[{-1/2,2},{-1,1},spd],
edge[{-1/2,2},{0,1},spd],
edge[{-1/2,2},{1,1},spd]},
Background->White,ImageSize->100, AspectRatio->1/2]],
{{s,0,""},{1->"Evaluate",0->"Reset"}},
{{a,1},{0,1,2,3,4,5},ControlType->RadioButtonBar},
{{b,2},{0,1,2,3,4,5},ControlType->RadioButtonBar},
{{c,3},{0,1,2,3,4,5},ControlType->RadioButtonBar},
{{d,4},{0,1,2,3,4,5},ControlType->RadioButtonBar},Paneled->False,
ControlPlacement->Left,
SaveDefinitions->True]

tree6[s_,a_,b_,c_,d_]=Graphics[
{
Arrowheads[0],
op[If [s>0,a+b+c+d,"Plus"],{-1/2,2}],
op[a,{-2,1}],
op[b,{-1,1}],
op[c,{0,1}],
op[d,{1,1}],
edge[{-1/2,2},{-2,1},spd],
edge[{-1/2,2},{-1,1},spd],
edge[{-1/2,2},{0,1},spd],
edge[{-1/2,2},{1,1},spd]},Background->White,ImageSize->100, AspectRatio->1/2]

This is assoc4.cdf

Manipulate[Grid[
{{tree1[s,a,b,c,d],tree2[s,a,b,c,d]},{tree3[s,a,b,c,d],tree4[s,a,b,c,d]},{tree5[s,a,b,c,d],tree6[s,a,b,c,d]}}],
{{s,0,"Steps"},{1,2,3,0->"Reset"}},
{{a,1,"first"},{0,1,2,3,4,5},ControlType->RadioButtonBar},
{{b,2,"second"},{0,1,2,3,4,5},ControlType->RadioButtonBar},
{{c,3,"third"},{0,1,2,3,4,5},ControlType->RadioButtonBar},
{{d,4,"fourth"},{0,1,2,3,4,5},ControlType->RadioButtonBar},Paneled->False,
ControlPlacement->Left,
SaveDefinitions->True]

Associative law as graph rewrite

mov[p_,q_,s_]:=(1-s)p+s q

mov[{.5,1.5},{1,0},s]

Manipulate[Show[Graphics[{
Arrowheads[0],
edge[{-.5,2},mov[{-1,1},{-.5,2},s],spd],
edge[{0,1},{-.5,2},spd],
edge[mov[{-1,1},{-.5,2},s],mov[{-1.5,0},{-1,1},s], spd],
edge[mov[{-1,1},{-.5,2},s],mov[{-.5,0},{-.5,1},s],spd],
op["Plus",{-.5,2}],
op["Plus",mov[{-1,1},{-.5,2},s]],
op["c",{0,1}],
op["a",mov[{-1.5,0},{-1,1},s]],
op["b",mov[{-.5,0},{-.5,1},s]]},
Background->White,ImageSize->80,AspectRatio->1.2-.5s]],{{s,0},0,1},SaveDefinitions->True,Paneled->False]

Manipulate[Show[Graphics[{
Arrowheads[0],edge[{-.5,2},mov[{0,1},{-.5,2},s],spd],
(*a*)edge[{-1.5,1},{-.5,2},spd],
(*c*)edge[mov[{0,1},{-.5,2},s],mov[{.5,0},{.5,1},s], spd],
(*b*)edge[mov[{0,1},{-.5,2},s],mov[{-.5,0},{-.5,1},s],spd],
op["Plus",{-.5,2}],
op["Plus",mov[{0,1},{-.5,2},s]],
op["c",mov[{.5,0},{.5,1},s]],
op["a",{-1.5,1}],
op["b",mov[{-.5,0},{-.5,1},s]],
},
Background->White,ImageSize->80,AspectRatio->1.2-.5s]],{{s,0},0,1},SaveDefinitions->True,Paneled->False]

This is assocslider3.cdf

Manipulate[
Grid[{{
Graphics[{
Arrowheads[0],
edge[{-.5,2},mov[{-1,1},{-.5,2},s],spd],
edge[{0,1},{-.5,2},spd],
edge[mov[{-1,1},{-.5,2},s],mov[{-1.5,0},{-1,1},s], spd],
edge[mov[{-1,1},{-.5,2},s],mov[{-.5,0},{-.5,1},s],spd],
op["Plus",{-.5,2}],
op["Plus",mov[{-1,1},{-.5,2},s]],
op["c",{0,1}],
op["a",mov[{-1.5,0},{-1,1},s]],
op["b",mov[{-.5,0},{-.5,1},s]]},
Background->White,ImageSize->70,AspectRatio->1.2-.5s], "   ",
Graphics[{
Arrowheads[0],edge[{-.5,2},mov[{0,1},{-.5,2},s],spd],
(*a*)edge[{-1.5,1},{-.5,2},spd],
(*c*)edge[mov[{0,1},{-.5,2},s],mov[{.5,0},{.5,1},s], spd],
(*b*)edge[mov[{0,1},{-.5,2},s],mov[{-.5,0},{-.5,1},s],spd],
op["Plus",{-.5,2}],
op["Plus",mov[{0,1},{-.5,2},s]],
op["c",mov[{.5,0},{.5,1},s]],
op["a",{-1.5,1}],
op["b",mov[{-.5,0},{-.5,1},s]],
},
Background->White,ImageSize->70,AspectRatio->1.2-.5s]
}}],
{{s,0},0,1},SaveDefinitions->True,Paneled->False]

Manipulate[Show[
Graphics[
{
Arrowheads[0],
edge[{0,2},{-2,1},spd],
edge[{0,2},{2,1},spd],
edge[{2,1},{1,0},spd],
edge[{2,1},{3,0},spd],
edge[{-2,1},{-1,0},spd],
edge[{1,0},{0,-1},spd],
edge[{-3,0},{-2,1},spd],
edge[{1,0},{2,-1},spd],
op["Plus",{0,2}],
op["Plus",{-2,1}],
op["Plus",{2,1}],
op["Plus",{1,0}],
op["a",{-3,0}],
op["b",{-1,0}],
op["c",{0,-1}],
op["d",{2,-1}],
op["e",{3,0}]}],
Background->White,ImageSize->120,AspectRatio->1.2],
{{s,0},0,1},SaveDefinitions->True,Paneled->False]

This is assocslider5.cdf

Manipulate[Show[Graphics[{
Arrowheads[0],
edge[{0,2},mov[{-2,1},{0,2},t],spd],
edge[{0,2},mov[{2,1},{0,2},u],spd],
edge[mov[{2,1},{0,2},u],mov[{1,0},{1,1},u],spd],
edge[mov[{2,1},{0,2},u],mov[{3,0},{3,1},u],spd],
edge[mov[{-2,1},{0,2},t],mov[{-1,0},{0,1},t],spd],
edge[mov[{1,0},mov[{2,1},{0,2},u],s],mov[{0,-1},mov[{1,0},{1,1},u],s],spd],
edge[mov[{-3,0},{-1,1},t],mov[{-2,1},{0,2},t],spd],edge[mov[{1,0},mov[{2,1},{0,2},u],s],mov[{2,-1},mov[{2,0},{2,1},u],s],spd],
op["Plus",{0,2}],
op["Plus",mov[{2,1},{0,2},u]],
op["Plus",mov[{-2,1},{0,2},t]],
op["Plus",mov[{1,0},mov[{2,1},{0,2},u],s]],
op["a",mov[{-3,0},{-1,1},t]],
op["b",mov[{-1,0},{0,1},t]],
op["c",mov[{0,-1},mov[{1,0},{1,1},u],s]],
op["d",mov[{2,-1},mov[{2,0},{2,1},u],s]],
op["e",mov[{3,0},{3,1},u]]}],
Background->White,ImageSize->100,AspectRatio->1.3-.4s-.5u],
{{s,0},0,1},{{t,0},0,1},{{u,0},0,1},SaveDefinitions->True,
ControlPlacement->Left,Paneled->False]

Example of a noncommutative associative operation: Allfuncs2

There are four functions from a two-element set {a, b} to itself.  The binary operation of composition of functions on that set I will call AllFuncs2.

la={0,1};ra={1,1};
lb={0,0};rb={1,0};sb=.28;ah=.22

funcdi[list_]:=Framed[Graphics[
{Arrowheads[ah],
list},
ImageSize->35,FrameTicks->False],FrameMargins->Tiny,FrameStyle->Black
]

funcdi[list_,color_]:=Framed[Graphics[
{Arrowheads[ah],
list},
ImageSize->35,FrameTicks->False],FrameMargins->Tiny,FrameStyle->color
]

switch=funcdi[{op["a",la],op["a",ra],op["b",lb],op["b",rb],
Arrow[{la,rb},sb],Arrow[{lb,ra},sb]},White]

switch

switchf[a]=b; switchf[b]=a;idf[a]=a;idf[b]=b;caf[a]=caf[b]=a;cbf[a]=cbf[b]=b;

id=funcdi[{
op["a",la],op["a",ra],op["b",lb],op["b",rb],
Arrow[{la,ra},sb],Arrow[{lb,rb},sb]},White]

id

ca=funcdi[{
op["a",la],op["a",ra],op["b",lb],op["b",rb],
Arrow[{la,ra},sb],Arrow[{lb,ra},sb]},White]

ca

cb=funcdi[{
op["a",la],op["a",ra],op["b",lb],op["b",rb],
Arrow[{la,rb},sb],Arrow[{lb,rb},sb]},White]

cb

Remove[comp]

comp[id,x_]:=x;comp[x_,id]:=x;comp[ca,switch]:=cb;comp[cb,switch]:=ca;comp[x_,ca]:=ca;comp[x_,cb]:=cb;comp[switch,switch]:=id;

comp[switch,id]

Graphics[{
Arrowheads[0],
edge[{-1,0},{0,1},.0006],
edge[{1,0},{0,1},.0006],
op["Comp",{0,1}],
op[switch,{-1,0},Plain],op[ca,{1,0},Plain]},ImageSize->130,AspectRatio->.8]

nameop[1]:=id;nameop[2]:=switch;nameop[3]:=ca;nameop[4]:=cb;

nameop[1]

nameop[2]

comp[cb,ca]

comp[nameop[3],nameop[4]]

op[comp[nameop[left],nameop[right]],{0,1}]

op[comp[nameop[2],nameop[1]],{0,1},Medium]

currentcolor:=Black

comp[nameop[4],nameop[2]]

This is compAllFuncs2.cdf

Manipulate[
Framed[Show[Graphics[{
White,Rectangle[{-2,-.6},{2,1.4}],Black,
Arrowheads[0],
edge[{-1,0},{0,1.2},.0003],
edge[{1,0},{0,1.2},.0003],
If[s==1,op[comp[left,right],{0,1},Plain],op["comp",{0,1.2}]],
op[left,{-1,0},Medium],op[right,{1,0},Plain]},ImageSize->100,AspectRatio->1.3]],FrameStyle->White],
{{s,0,""},{1->"Evaluate",0->"Reset"}},
{{left,nameop[3]},nameop/@{1,2,3,4},ControlType->RadioButtonBar},
{{right,nameop[2]},nameop/@{1,2,3,4},ControlType->RadioButtonBar},
ControlPlacement->Left,SaveDefinitions->True]

Remove[e]

leftajoin

-1-1.3+.74

1+1.3-.74

leftajoin={-1.56,.6};leftbjoin={-1.56,-.6};
rightajoin={1.56,.6};rightbjoin={1.56,-.6};

switch

larr[switch,leftajoin]=rightbjoin;
larr[switch,leftbjoin]=rightajoin;
larr[id,leftajoin]:=rightajoin;
larr[id,leftbjoin]:=rightbjoin;
larr[ca,x_]:=rightajoin;
larr[cb,x_]:=rightbjoin;

larr[switch,leftbjoin]

comp[nameop[2],nameop[1]]

larr[comp[nameop[2],nameop[1]],leftajoin]

larr[comp[nameop[2],nameop[1]],leftbjoin]

(*switchf[a]=b; switchf[b]=a;idf[a]=a;idf[b]=b;caf[a]=caf[b]=a;cbf[a]=cbf[b]=b;*)

This is compAllFuncs2show.cdf

Manipulate[(
Show[Graphics[{
White,Rectangle[{-2,-1},{2,1}],Black,
Arrowheads[.07],Black,
If[d<2,op[left,If[d==1,{-1.3+.74,0},{-1.3+.6,0}]],op[comp[left,right],{0,0},Plain]],If[d<2,op[right,If[d==1,{1.3-.74,0},{1.3+.6,0}],Plain]],Red,If[d==1,Arrow[{leftajoin,larr[comp[left,right],leftajoin]},sb+.4]],If[d==1,Arrow[{leftbjoin,larr[comp[left,right],leftbjoin]},sb+.4]],Black},ImageSize->100,AspectRatio->Automatic]]
),
{{d,0,""},{0->"Reset",1->"Join",2->"Compose"}},{{left,nameop[3]},nameop/@{1,2,3,4},ControlType->RadioButtonBar},
{{right,nameop[2]},nameop/@{1,2,3,4},ControlType->RadioButtonBar},
ControlPlacement->Left,SaveDefinitions->True]

Associativity for allfuncs2

plus3a[s_,a_,b_,c_]:=Graphics[{
Arrowheads[0],
op[If [s>1,a+b+c,"Plus"],{-1/2,2}],
op[If[s>0,a+b,"Plus"],{-1,1}],
op[c,{0,1}],
op[a,{-1.5,0}],
op[b,{-.5,0}],
edge[{-.5,2},{-1,1},spd],
edge[{-.5,2},{0,1},spd],
edge[{-1,1},{-1.5,0},spd],
edge[{-1,1},{-.5,0},spd]},
Background->White,ImageSize->80, AspectRatio->1]

plus3b[s_,a_,b_,c_]:=Graphics[{
Arrowheads[0],
op[If [s>1,a+b+c,"Plus"],{-1/2,2}],
op[If[s>0,b+c,"Plus"],{0,1}],
op[a,{-1,1}],
op[b,{-.5,0}],
op[c,{.5,0}],
edge[{-1/2,2},{-1,1},spd],
edge[{-1/2,2},{0,1},spd],edge[{0,1},{-.5,0},spd],edge[{0,1},{.5,0},spd]},
Background->White,ImageSize->80, AspectRatio->1]