Solving calculator problems

Harold Thimbleby - http://www.uclic.ucl.ac.uk/harold

This file is the background for establishing some matrix identities for the calculator examples used in the papers.

•Utility functions...

In[26]:=

NameOf[matrix_, name_List] := NameOf[matrix] = RowBox[Map[NameOf[matrix, #] &, name]] ; NameOf[matrix_, name_String] := NameOf[matrix] = FrameBox[GridBox[{{name}}]] ;  problemNameOf[matrix_, name_String] := problemNameOf[matrix] = FrameBox[GridBox[{{name}}]] ; problemNameOf[matrix_] := NameOf[matrix] ; <br /> explain[mat_] := Module[{v = {StyleForm["d", FontSlant -> Italic, FontFamily -> "Times"], StyleForm["m", FontSlant -> Italic, FontFamily -> "Times"]}},  {problemNameOf[mat], "=", MatrixForm[mat], "    ", {v} // TraditionalForm, " -> ", {v . mat} // TraditionalForm} ] ; <br /> explainList[matlist_] := StylePrint[GridBox[Map[(explain[#]) &, matlist], ColumnAlignments -> Left] // DisplayForm, Background -> RGBColor[1, 1, 0.6]]

•Define basic keys

In[7]:=

NameOf[ac = (0   0), "AC"] ;               0   1 NameOf[mp = (1   1), "M+"] ;               0   1 NameOf[mm = (1    -1), "M-"] ;               0    1 NameOf[cs = (-1   0 ), "±"] ;               0    1 NameOf[mrc = (0   0), "MRC"] ;                1   1 NameOf[mmrce = (1    0 ), {"-", "MRC", "="}] ;                  -1   1 NameOf[mrcmrc = (0   0), {"MRC", "MRC"}] ;                   1   0 mats = { ac, mp, mm, mrc, cs, mmrce, mrcmrc} ;

General :: spell1 :  Possible spelling error: new symbol name \" mats \" is similar to existing symbol \" mat \".

•Summarise key definitions

In[15]:=

StylePrint[RowBox @ Map[NameOf, {ac, mp, mm, cs, mmrce}] // DisplayForm, Background -> RGBColor[1, 1, 0.6]]

AC M + M - ± - MRC =

In[16]:=

explainList[mats]

AC = ( 0   0 )    0   1      ( d   m )  -> ( 0   m )
M + = ( 1   1 )    0   1      ( d   m )  -> ( d       d + m )
M - = ( 1    -1 )    0    1      ( d   m )  -> ( d       m - d )
MRC = ( 0   0 )    1   1      ( d   m )  -> ( m   m )
± = ( -1   0  )    0    1      ( d   m )  -> ( -d   m  )
- MRC = = ( 1    0  )    -1   1      ( d   m )  -> ( d - m   m     )
MRC MRC = ( 0   0 )    1   0      ( d   m )  -> ( m   0 )

•Define the goals

In[17]:=

problemNameOf[swap = (0   1), "SWAP DISPAY & MEMORY"] ;                        1   0 problemNameOf[savedisplay = (1   1), "SAVE DISPLAY"] ;                               0   0 problemNameOf[zerodisplay = (0   0), "ZERO DISPLAY"] ;                               0   1 problemNameOf[zeroeverything = (0   0), "ZERO DISPAY & MEMORY"] ;                                  0   0 problemNameOf[zeromemory = (1   0), "ZERO MEMORY"] ;                              0   0

In[22]:=

explainList[newmats = {swap, savedisplay, zeromemory, zeroeverything, zerodisplay}]

SWAP DISPAY & MEMORY = ( 0   1 )    1   0      ( d   m )  -> ( m   d )
SAVE DISPLAY = ( 1   1 )    0   0      ( d   m )  -> ( d   d )
ZERO MEMORY = ( 1   0 )    0   0      ( d   m )  -> ( d   0 )
ZERO DISPAY & MEMORY = ( 0   0 )    0   0      ( d   m )  -> ( 0   0 )
ZERO DISPLAY = ( 0   0 )    0   1      ( d   m )  -> ( 0   m )

•Solve goals using the keys

The function howto finds the shortest products (with no more terms than maxTerms) that get to the goal. You can change limit to make it search further. Note that maxTerms refers to matrices, rather than button presses (e.g., mrcmrc is the product of two button presses).

In[23]:=

howto[goal_, maxTerms_: 8] :=  Module[{rec, tried, i},  rec[m_, depth_, maxDepth_, soln_] :=  Module[{n, product, s, i},  If[MemberQ[tried, μ[m]], Return[False]] ;  AppendTo[tried, μ[m]] ;  For[n = 1, n <= Length[mats], n ++,  product = m . mats _ [[ n ]] ;  s = Append[soln, NameOf[mats _ [[ n ]]]] ;  If[goal == product,  StylePrint[RowBox[{"To implement ", problemNameOf[goal], "press", RowBox[s]}] // DisplayForm, Background -> RGBColor[1, 1, 0.5]] ;  Return[True],  If[depth < maxDepth && rec[product, depth + 1, maxDepth, s],  Return[True] ] ] ; ] ;  Return[False] ; ] ;  For[i = 1, i <= maxTerms, i ++,  tried = {} ;  If[rec[IdentityMatrix[2], 1, i, {}], Return[]] ] ;  StylePrint[RowBox[{problemNameOf[goal], " not possible in no more than ", ToString @ maxTerms, " terms."}] // DisplayForm, Background -> RGBColor[1, 1, 0.5]] ]

General :: spell1 :  Possible spelling error: new symbol name \" product \" is similar to existing symbol \" Product \".

In[24]:=

Scan[howto, newmats]

To implement  SWAP DISPAY & MEMORY press M + - MRC = M + ±

To implement  SAVE DISPLAY press - MRC = M + MRC

To implement  ZERO MEMORY press - MRC = M + MRC MRC

To implement  ZERO DISPAY & MEMORY press MRC MRC AC

To implement  ZERO DISPLAY press AC

In[25]:=

howto[swap, 3]

SWAP DISPAY & MEMORY  not possible in no more than  3  terms .


Converted by Mathematica  (May 2, 2003)