# Easy function returning commutators/ conjugates in spreadsheet?



## sneze2r (Nov 27, 2013)

Hello,
I've been looking for spreadsheet script with function that instead of uncomfortable notation [U2; R D R'] will show U2 R D R' U2 R D' R'. Has anyone made it? 
Is that even possible writing function like that? I don't know even what format of variable should be used, since there is no arrays of chars like (D,R,D), (L2) etc.?


----------



## irontwig (Nov 27, 2013)

How is that uncomfortable? You only need to read half as much, and at your level I guess you understand how comms work anyway, so I really don't see the problem.


----------



## sneze2r (Nov 27, 2013)

comutator notation is not big problem.

If i want to write down for example UF FD LF case which for me is: l' L' U' L U M' U' L' U L l, instead of it i could write down, that this is caseUFFDLF=setup(l',caseUFLUBU), where caseUFLUBU=mirror(caseUFRUBU) ..where.. caseUFRUBU=comm((R, U, R', U'),(M')). Problem with this would be only defining every idendity like R2R'=R, RM'=r...


----------



## Christopher Mowla (Nov 27, 2013)

I have been wanting to write a program that does this for a while. I am going to write one, but if someone else has done it already or also wishes to write one, please feel free.

sneze2r,
If I write this in Microsoft Excel, would that be fine?


----------



## sneze2r (Nov 27, 2013)

Yes, it would be great


----------



## Lucas Garron (Nov 28, 2013)

Since I had most of the work done, I just added an "Expand" tool to alg.cubing.net. It doesn't have an easy undo, but hopefully it should be useful.

Try it: [F: [R, U]]


----------



## Christopher Mowla (Nov 28, 2013)

Nice tool, Lucas.

I might be doing something wrong with your tool, but I can't get it to expand this [F U:[R2 F',UR]] correctly, for example.

I wrote a program in Mathematica so far (if you want Lucas, I can post the code) for which I will attempt to translate to Excel.

By the way, I know you're experienced with Mathematica, is there an easy way to make an executable from Mathematica code?


----------



## Christopher Mowla (Nov 29, 2013)

@ sneze2r,

I successfully translated my Mathematica code to Microsoft Excel macro code, and I believe I'm finished.

Expander​
How to Use:
1) Click the download link I have provided.
2) Click File-> Download
3) As you open it, click the "enable macro" button when prompted to choose.
4) Select any cell which has an algorithm in it (I provided a few samples).
5) Press Alt + F8 + Enter to run the code (it's possible that you need to close it the first time it's opened and reopen it to get it to start working).

You will see that its expansion is placed in the column to the _right_ of the cell selected (but it will be in the same row).

_I put an "input" and "output" header, but as I just mentioned above, I programmed it so that whichever cell you select, it gives the expansion in the cell on the right of it (if there is an algorithm that needs to be expanded in the cell you select).

_Lastly, you can only do one at a time (this is my first time programming in Excel, so I don't know how to apply it to large masses of data).

Enjoy! (I know I will, especially when I do examples for my single commutator project!)


Notes:

I used Microsoft Office 2003, so I hope that isn't a problem. 
This expander works for cube sizes 2x2x2 - 7x7x7 in WCA (wide w turns) and all versions of SiGN notation. It not only expands a commutator, but it expands any nested combination of commutators, conjugates, as well as extra moves in between. (It doesn't expand repeated sequences or parenthesized inversions or reflections, etc., however). 
Because this works up to the 7x7x7 in SiGN notation, your spacing does matter if you use it for 7x7x7 SiGN. However, no spaces are required if you use it for the 2x2x2 or 3x3x3, as there is really only one way to interpret notation for those small cube sizes. 
 
_If there are any bugs, let me know, but I doubt it, based on how I programmed it._

For those who would like to look at the code (you can obviously also see it in the macro editor in this Excel sheet), but it's interesting to see here that I really only needed one program to do this based on how I handled the inversion and all rearranging and reordering.

(Note: code lines beginning with an apostrophe are comments).


```
Sub Expander()
 
 '"Commutator and Conjugate Expander by Christopher Mowla"
 'November 29, 2013
 
 'Store the condensed notation text in currently selected cell as input.
 inputString = ActiveCell.Text
 
 Dim BeginningBracket As Integer
 Dim EndingBracket As Integer
 Dim tempString As String
 Dim tempString2 As String
 Dim delimiterPosition As Integer
 Dim stringX As String
 Dim stringY As String
 Dim expandString As String
  
 'Do a few preliminary replacements to avoid trouble
 inputString = Replace(inputString, "'2", "2")
 inputString = Replace(inputString, "2'", "2")
 
 'Replace all letters with numbers.
 'This will help us avoid errors in complex situations,
 'and it saves us from having to do any work for the inverse,
 'as I have assigned numbers to *2 moves which are the same
 'as their reverse (since *2 moves are the same on cubes).
 'In addition, I have assigned numbers to 's which are their
 'counterpart's reverse!
 'The order in which we make these substitutions matter.
    
    inputString = Replace(inputString, "2-3l2", "09190")
    inputString = Replace(inputString, "2-3r2", "09290")
    inputString = Replace(inputString, "2-3u2", "09390")
    inputString = Replace(inputString, "2-3d2", "09490")
    inputString = Replace(inputString, "2-3f2", "09590")
    inputString = Replace(inputString, "2-3b2", "09690")
        
    inputString = Replace(inputString, "2L2", "02120")
    inputString = Replace(inputString, "2R2", "02220")
    inputString = Replace(inputString, "2U2", "02320")
    inputString = Replace(inputString, "2D2", "02420")
    inputString = Replace(inputString, "2F2", "02520")
    inputString = Replace(inputString, "2B2", "02620")
    inputString = Replace(inputString, "2l2", "02720")
    inputString = Replace(inputString, "2r2", "02820")
    inputString = Replace(inputString, "2u2", "02920")
    inputString = Replace(inputString, "2d2", "03130")
    inputString = Replace(inputString, "2f2", "03230")
    inputString = Replace(inputString, "2b2", "03330")
    inputString = Replace(inputString, "2m2", "03430")
    inputString = Replace(inputString, "2e2", "03530")
    inputString = Replace(inputString, "2s2", "03630")
    inputString = Replace(inputString, "3L2", "03730")
    inputString = Replace(inputString, "3R2", "03830")
    inputString = Replace(inputString, "3U2", "03930")
    inputString = Replace(inputString, "3D2", "04140")
    inputString = Replace(inputString, "3F2", "04240")
    inputString = Replace(inputString, "3B2", "04340")
    inputString = Replace(inputString, "3l2", "04440")
    inputString = Replace(inputString, "3r2", "04540")
    inputString = Replace(inputString, "3u2", "04640")
    inputString = Replace(inputString, "3d2", "04740")
    inputString = Replace(inputString, "3f2", "04840")
    inputString = Replace(inputString, "3b2", "04940")
    inputString = Replace(inputString, "3m2", "05150")
    inputString = Replace(inputString, "3e2", "05250")
    inputString = Replace(inputString, "3s2", "05350")
    inputString = Replace(inputString, "4l2", "05450")
    inputString = Replace(inputString, "4r2", "05550")
    inputString = Replace(inputString, "4u2", "05650")
    inputString = Replace(inputString, "4d2", "05750")
    inputString = Replace(inputString, "4f2", "05850")
    inputString = Replace(inputString, "4b2", "05950")
    inputString = Replace(inputString, "4m2", "06160")
    inputString = Replace(inputString, "4e2", "06260")
    inputString = Replace(inputString, "4s2", "06360")
    inputString = Replace(inputString, "5l2", "06460")
    inputString = Replace(inputString, "5r2", "06560")
    inputString = Replace(inputString, "5u2", "06660")
    inputString = Replace(inputString, "5d2", "06760")
    inputString = Replace(inputString, "5f2", "06860")
    inputString = Replace(inputString, "5b2", "06960")
    inputString = Replace(inputString, "5m2", "07170")
    inputString = Replace(inputString, "5e2", "07270")
    inputString = Replace(inputString, "5s2", "07370")
    inputString = Replace(inputString, "6l2", "07470")
    inputString = Replace(inputString, "6r2", "07570")
    inputString = Replace(inputString, "6u2", "07670")
    inputString = Replace(inputString, "6d2", "07770")
    inputString = Replace(inputString, "6f2", "07870")
    inputString = Replace(inputString, "6b2", "07970")
    
    inputString = Replace(inputString, "L2", "0110")
    inputString = Replace(inputString, "R2", "0220")
    inputString = Replace(inputString, "U2", "0330")
    inputString = Replace(inputString, "D2", "0440")
    inputString = Replace(inputString, "F2", "0550")
    inputString = Replace(inputString, "B2", "0660")
    inputString = Replace(inputString, "M2", "0770")
    inputString = Replace(inputString, "E2", "0880")
    inputString = Replace(inputString, "S2", "0990")
    inputString = Replace(inputString, "l2", "01110")
    inputString = Replace(inputString, "r2", "01210")
    inputString = Replace(inputString, "u2", "01310")
    inputString = Replace(inputString, "d2", "01410")
    inputString = Replace(inputString, "f2", "01510")
    inputString = Replace(inputString, "b2", "01610")
    inputString = Replace(inputString, "m2", "01710")
    inputString = Replace(inputString, "e2", "01810")
    inputString = Replace(inputString, "s2", "01910")
    
    inputString = Replace(inputString, "x2", "08180")
    inputString = Replace(inputString, "y2", "08280")
    inputString = Replace(inputString, "z2", "08380")
    inputString = Replace(inputString, "Lw2", "08480")
    inputString = Replace(inputString, "Rw2", "08580")
    inputString = Replace(inputString, "Uw2", "08680")
    inputString = Replace(inputString, "Dw2", "08780")
    inputString = Replace(inputString, "Fw2", "08880")
    inputString = Replace(inputString, "Bw2", "08980")
                                  
    inputString = Replace(inputString, "2-3l'", "08510")
    inputString = Replace(inputString, "2-3l", "01580")
    inputString = Replace(inputString, "2-3r'", "09510")
    inputString = Replace(inputString, "2-3r", "01590")
    inputString = Replace(inputString, "2-3u'", "02610")
    inputString = Replace(inputString, "2-3u", "01620")
    inputString = Replace(inputString, "2-3d'", "02610")
    inputString = Replace(inputString, "2-3d", "01630")
    inputString = Replace(inputString, "2-3f'", "03610")
    inputString = Replace(inputString, "2-3f", "01640")
    inputString = Replace(inputString, "2-3b'", "04610")
    inputString = Replace(inputString, "2-3b", "01650")
                 
    inputString = Replace(inputString, "Lw'", "09410")
    inputString = Replace(inputString, "Lw", "01490")
    inputString = Replace(inputString, "Rw'", "02510")
    inputString = Replace(inputString, "Rw", "01520")
    inputString = Replace(inputString, "Uw'", "03510")
    inputString = Replace(inputString, "Uw", "01530")
    inputString = Replace(inputString, "Dw'", "04510")
    inputString = Replace(inputString, "Dw", "01540")
    inputString = Replace(inputString, "Fw'", "05510")
    inputString = Replace(inputString, "Fw", "01550")
    inputString = Replace(inputString, "Bw'", "06510")
    inputString = Replace(inputString, "Bw", "01560")
    
    inputString = Replace(inputString, "2L'", "0730")
    inputString = Replace(inputString, "2L", "0370")
    inputString = Replace(inputString, "2R'", "0830")
    inputString = Replace(inputString, "2R", "0380")
    inputString = Replace(inputString, "2U'", "0930")
    inputString = Replace(inputString, "2U", "0390")
    inputString = Replace(inputString, "2D'", "0540")
    inputString = Replace(inputString, "2D", "0450")
    inputString = Replace(inputString, "2F'", "0640")
    inputString = Replace(inputString, "2F", "0460")
    inputString = Replace(inputString, "2B'", "0740")
    inputString = Replace(inputString, "2B", "0470")
    inputString = Replace(inputString, "2l'", "0840")
    inputString = Replace(inputString, "2l", "0480")
    inputString = Replace(inputString, "2r'", "0940")
    inputString = Replace(inputString, "2r", "0490")
    inputString = Replace(inputString, "2u'", "0650")
    inputString = Replace(inputString, "2u", "0560")
    inputString = Replace(inputString, "2d'", "0750")
    inputString = Replace(inputString, "2d", "0570")
    inputString = Replace(inputString, "2f'", "0850")
    inputString = Replace(inputString, "2f", "0580")
    inputString = Replace(inputString, "2b'", "0950")
    inputString = Replace(inputString, "2b", "0590")
    inputString = Replace(inputString, "2m'", "0760")
    inputString = Replace(inputString, "2m", "0670")
    inputString = Replace(inputString, "2e'", "0860")
    inputString = Replace(inputString, "2e", "0680")
    inputString = Replace(inputString, "2s'", "0960")
    inputString = Replace(inputString, "2s", "0690")
    inputString = Replace(inputString, "3L'", "0870")
    inputString = Replace(inputString, "3L", "0780")
    inputString = Replace(inputString, "3R'", "0970")
    inputString = Replace(inputString, "3R", "0790")
    inputString = Replace(inputString, "3U'", "0980")
    inputString = Replace(inputString, "3U", "0890")
    inputString = Replace(inputString, "3D'", "02010")
    inputString = Replace(inputString, "3D", "01020")
    inputString = Replace(inputString, "3F'", "03010")
    inputString = Replace(inputString, "3F", "01030")
    inputString = Replace(inputString, "3B'", "04010")
    inputString = Replace(inputString, "3B", "01040")
    inputString = Replace(inputString, "3l'", "05010")
    inputString = Replace(inputString, "3l", "01050")
    inputString = Replace(inputString, "3r'", "06010")
    inputString = Replace(inputString, "3r", "01060")
    inputString = Replace(inputString, "3u'", "07010")
    inputString = Replace(inputString, "3u", "01070")
    inputString = Replace(inputString, "3d'", "08010")
    inputString = Replace(inputString, "3d", "01080")
    inputString = Replace(inputString, "3f'", "09010")
    inputString = Replace(inputString, "3f", "01090")
    inputString = Replace(inputString, "3b'", "02110")
    inputString = Replace(inputString, "3b", "01120")
    inputString = Replace(inputString, "3m'", "03110")
    inputString = Replace(inputString, "3m", "01130")
    inputString = Replace(inputString, "3e'", "04110")
    inputString = Replace(inputString, "3e", "01140")
    inputString = Replace(inputString, "3s'", "05110")
    inputString = Replace(inputString, "3s", "01150")
    inputString = Replace(inputString, "4l'", "06110")
    inputString = Replace(inputString, "4l", "01160")
    inputString = Replace(inputString, "4r'", "07110")
    inputString = Replace(inputString, "4r", "01170")
    inputString = Replace(inputString, "4u'", "08110")
    inputString = Replace(inputString, "4u", "01180")
    inputString = Replace(inputString, "4d'", "09110")
    inputString = Replace(inputString, "4d", "01190")
    inputString = Replace(inputString, "4f'", "02210")
    inputString = Replace(inputString, "4f", "01220")
    inputString = Replace(inputString, "4b'", "03210")
    inputString = Replace(inputString, "4b", "01230")
    inputString = Replace(inputString, "4m'", "04210")
    inputString = Replace(inputString, "4m", "01240")
    inputString = Replace(inputString, "4e'", "05210")
    inputString = Replace(inputString, "4e", "01250")
    inputString = Replace(inputString, "4s'", "06210")
    inputString = Replace(inputString, "4s", "01260")
    inputString = Replace(inputString, "5l'", "07210")
    inputString = Replace(inputString, "5l", "01270")
    inputString = Replace(inputString, "5r'", "08210")
    inputString = Replace(inputString, "5r", "01280")
    inputString = Replace(inputString, "5u'", "09210")
    inputString = Replace(inputString, "5u", "01290")
    inputString = Replace(inputString, "5d'", "02310")
    inputString = Replace(inputString, "5d", "01320")
    inputString = Replace(inputString, "5f'", "03310")
    inputString = Replace(inputString, "5f", "01330")
    inputString = Replace(inputString, "5b'", "04310")
    inputString = Replace(inputString, "5b", "01340")
    inputString = Replace(inputString, "5m'", "05310")
    inputString = Replace(inputString, "5m", "01350")
    inputString = Replace(inputString, "5e'", "06310")
    inputString = Replace(inputString, "5e", "01360")
    inputString = Replace(inputString, "5s'", "07310")
    inputString = Replace(inputString, "5s", "01370")
    inputString = Replace(inputString, "6l'", "08310")
    inputString = Replace(inputString, "6l", "01380")
    inputString = Replace(inputString, "6r'", "09310")
    inputString = Replace(inputString, "6r", "01390")
    inputString = Replace(inputString, "6u'", "02410")
    inputString = Replace(inputString, "6u", "01420")
    inputString = Replace(inputString, "6d'", "03410")
    inputString = Replace(inputString, "6d", "01430")
    inputString = Replace(inputString, "6f'", "04410")
    inputString = Replace(inputString, "6f", "01440")
    inputString = Replace(inputString, "6b'", "05410")
    inputString = Replace(inputString, "6b", "01450")
    
    inputString = Replace(inputString, "L'", "0210")
    inputString = Replace(inputString, "L", "0120")
    inputString = Replace(inputString, "R'", "0310")
    inputString = Replace(inputString, "R", "0130")
    inputString = Replace(inputString, "U'", "0410")
    inputString = Replace(inputString, "U", "0140")
    inputString = Replace(inputString, "D'", "0510")
    inputString = Replace(inputString, "D", "0150")
    inputString = Replace(inputString, "F'", "0610")
    inputString = Replace(inputString, "F", "0160")
    inputString = Replace(inputString, "B'", "0710")
    inputString = Replace(inputString, "B", "0170")
    inputString = Replace(inputString, "M'", "0810")
    inputString = Replace(inputString, "M", "0180")
    inputString = Replace(inputString, "E'", "0910")
    inputString = Replace(inputString, "E", "0190")
    inputString = Replace(inputString, "S'", "0320")
    inputString = Replace(inputString, "S", "0230")
    inputString = Replace(inputString, "l'", "0420")
    inputString = Replace(inputString, "l", "0240")
    inputString = Replace(inputString, "r'", "0520")
    inputString = Replace(inputString, "r", "0250")
    inputString = Replace(inputString, "u'", "0620")
    inputString = Replace(inputString, "u", "0260")
    inputString = Replace(inputString, "d'", "0720")
    inputString = Replace(inputString, "d", "0270")
    inputString = Replace(inputString, "f'", "0820")
    inputString = Replace(inputString, "f", "0280")
    inputString = Replace(inputString, "b'", "0920")
    inputString = Replace(inputString, "b", "0290")
    inputString = Replace(inputString, "m'", "0430")
    inputString = Replace(inputString, "m", "0340")
    inputString = Replace(inputString, "e'", "0530")
    inputString = Replace(inputString, "e", "0350")
    inputString = Replace(inputString, "s'", "0630")
    inputString = Replace(inputString, "s", "0360")
    
    inputString = Replace(inputString, "x'", "06410")
    inputString = Replace(inputString, "x", "01460")
    inputString = Replace(inputString, "y'", "07410")
    inputString = Replace(inputString, "y", "01470")
    inputString = Replace(inputString, "z'", "08410")
    inputString = Replace(inputString, "z", "01480")
    inputString = Replace(inputString, "(", "01570")
    inputString = Replace(inputString, ")", "07510")
 
 'Delete all white spaces, as we will add them back later.
 inputString = Replace(inputString, " ", "")
 
 'While there is at least one pair of brackets remaing to be evaluated,
 Do While InStr(inputString, "]") > 0
     
     'We find the first occurring closing bracket
     EndingBracket = InStr(inputString, "]")
     
     'And we then find the closest opening bracket to the left of
     'our located closing bracket
     tempString2 = Left(inputString, EndingBracket)
     BeginningBracket = InStrRev(tempString2, "[")
     
     'We grab this substring and store is as the variable tempString.
     tempString = Mid(inputString, BeginningBracket + 1, EndingBracket - BeginningBracket - 1)
     
     
     
     delimiterPosition = InStr(tempString, ",")
     
    'If it's a commutator
     If delimiterPosition > 0 Then
     
        stringX = Left(tempString, delimiterPosition - 1)
        stringY = Right(tempString, Len(tempString) - delimiterPosition)
        expandString = stringX + stringY + StrReverse(stringX) + StrReverse(stringY)
    
     Else
     'It's a conjugate
        delimiterPosition = InStr(tempString, ":")
        
        stringX = Left(tempString, delimiterPosition - 1)
        stringY = Right(tempString, Len(tempString) - delimiterPosition)
        expandString = stringX + stringY + StrReverse(stringX)
    
     End If
     
     'Finally, we insert our expanded substring in place of where its
     'condensed form originally was in our input string.
     inputString = Left(inputString, BeginningBracket - 1) + expandString + Mid(inputString, EndingBracket + 1, Len(inputString))
     
 
 Loop
 
 'Now we convert all numbers back to letters, and we're done!
 '(Order doesn't matter)
    
    inputString = Replace(inputString, "09190", " 2-3l2")
    inputString = Replace(inputString, "09290", " 2-3r2")
    inputString = Replace(inputString, "09390", " 2-3u2")
    inputString = Replace(inputString, "09490", " 2-3d2")
    inputString = Replace(inputString, "09590", " 2-3f2")
    inputString = Replace(inputString, "09690", " 2-3b2")
    
    inputString = Replace(inputString, "0110", " L2")
    inputString = Replace(inputString, "0220", " R2")
    inputString = Replace(inputString, "0330", " U2")
    inputString = Replace(inputString, "0440", " D2")
    inputString = Replace(inputString, "0550", " F2")
    inputString = Replace(inputString, "0660", " B2")
    inputString = Replace(inputString, "0770", " M2")
    inputString = Replace(inputString, "0880", " E2")
    inputString = Replace(inputString, "0990", " S2")
    inputString = Replace(inputString, "01110", " l2")
    inputString = Replace(inputString, "01210", " r2")
    inputString = Replace(inputString, "01310", " u2")
    inputString = Replace(inputString, "01410", " d2")
    inputString = Replace(inputString, "01510", " f2")
    inputString = Replace(inputString, "01610", " b2")
    inputString = Replace(inputString, "01710", " m2")
    inputString = Replace(inputString, "01810", " e2")
    inputString = Replace(inputString, "01910", " s2")
    inputString = Replace(inputString, "02120", " 2L2")
    inputString = Replace(inputString, "02220", " 2R2")
    inputString = Replace(inputString, "02320", " 2U2")
    inputString = Replace(inputString, "02420", " 2D2")
    inputString = Replace(inputString, "02520", " 2F2")
    inputString = Replace(inputString, "02620", " 2B2")
    inputString = Replace(inputString, "02720", " 2l2")
    inputString = Replace(inputString, "02820", " 2r2")
    inputString = Replace(inputString, "02920", " 2u2")
    inputString = Replace(inputString, "03130", " 2d2")
    inputString = Replace(inputString, "03230", " 2f2")
    inputString = Replace(inputString, "03330", " 2b2")
    inputString = Replace(inputString, "03430", " 2m2")
    inputString = Replace(inputString, "03530", " 2e2")
    inputString = Replace(inputString, "03630", " 2s2")
    inputString = Replace(inputString, "03730", " 3L2")
    inputString = Replace(inputString, "03830", " 3R2")
    inputString = Replace(inputString, "03930", " 3U2")
    inputString = Replace(inputString, "04140", " 3D2")
    inputString = Replace(inputString, "04240", " 3F2")
    inputString = Replace(inputString, "04340", " 3B2")
    inputString = Replace(inputString, "04440", " 3l2")
    inputString = Replace(inputString, "04540", " 3r2")
    inputString = Replace(inputString, "04640", " 3u2")
    inputString = Replace(inputString, "04740", " 3d2")
    inputString = Replace(inputString, "04840", " 3f2")
    inputString = Replace(inputString, "04940", " 3b2")
    inputString = Replace(inputString, "05150", " 3m2")
    inputString = Replace(inputString, "05250", " 3e2")
    inputString = Replace(inputString, "05350", " 3s2")
    inputString = Replace(inputString, "05450", " 4l2")
    inputString = Replace(inputString, "05550", " 4r2")
    inputString = Replace(inputString, "05650", " 4u2")
    inputString = Replace(inputString, "05750", " 4d2")
    inputString = Replace(inputString, "05850", " 4f2")
    inputString = Replace(inputString, "05950", " 4b2")
    inputString = Replace(inputString, "06160", " 4m2")
    inputString = Replace(inputString, "06260", " 4e2")
    inputString = Replace(inputString, "06360", " 4s2")
    inputString = Replace(inputString, "06460", " 5l2")
    inputString = Replace(inputString, "06560", " 5r2")
    inputString = Replace(inputString, "06660", " 5u2")
    inputString = Replace(inputString, "06760", " 5d2")
    inputString = Replace(inputString, "06860", " 5f2")
    inputString = Replace(inputString, "06960", " 5b2")
    inputString = Replace(inputString, "07170", " 5m2")
    inputString = Replace(inputString, "07270", " 5e2")
    inputString = Replace(inputString, "07370", " 5s2")
    inputString = Replace(inputString, "07470", " 6l2")
    inputString = Replace(inputString, "07570", " 6r2")
    inputString = Replace(inputString, "07670", " 6u2")
    inputString = Replace(inputString, "07770", " 6d2")
    inputString = Replace(inputString, "07870", " 6f2")
    inputString = Replace(inputString, "07970", " 6b2")
    inputString = Replace(inputString, "08180", " x2")
    inputString = Replace(inputString, "08280", " y2")
    inputString = Replace(inputString, "08380", " z2")
    inputString = Replace(inputString, "08480", " Lw2")
    inputString = Replace(inputString, "08580", " Rw2")
    inputString = Replace(inputString, "08680", " Uw2")
    inputString = Replace(inputString, "08780", " Dw2")
    inputString = Replace(inputString, "08880", " Fw2")
    inputString = Replace(inputString, "08980", " Bw2")
    
    inputString = Replace(inputString, "08510", " 2-3l'")
    inputString = Replace(inputString, "01580", " 2-3l")
    inputString = Replace(inputString, "09510", " 2-3r'")
    inputString = Replace(inputString, "01590", " 2-3r")
    inputString = Replace(inputString, "02610", " 2-3u'")
    inputString = Replace(inputString, "01620", " 2-3u")
    inputString = Replace(inputString, "02610", " 2-3d'")
    inputString = Replace(inputString, "01630", " 2-3d")
    inputString = Replace(inputString, "03610", " 2-3f'")
    inputString = Replace(inputString, "01640", " 2-3f")
    inputString = Replace(inputString, "04610", " 2-3b'")
    inputString = Replace(inputString, "01650", " 2-3b")
    
    inputString = Replace(inputString, "09410", " Lw'")
    inputString = Replace(inputString, "01490", " Lw")
    inputString = Replace(inputString, "02510", " Rw'")
    inputString = Replace(inputString, "01520", " Rw")
    inputString = Replace(inputString, "03510", " Uw'")
    inputString = Replace(inputString, "01530", " Uw")
    inputString = Replace(inputString, "04510", " Dw'")
    inputString = Replace(inputString, "01540", " Dw")
    inputString = Replace(inputString, "05510", " Fw'")
    inputString = Replace(inputString, "01550", " Fw")
    inputString = Replace(inputString, "06510", " Bw'")
    inputString = Replace(inputString, "01560", " Bw")
    inputString = Replace(inputString, "0120", " L")
    inputString = Replace(inputString, "0210", " L'")
    inputString = Replace(inputString, "0130", " R")
    inputString = Replace(inputString, "0310", " R'")
    inputString = Replace(inputString, "0140", " U")
    inputString = Replace(inputString, "0410", " U'")
    inputString = Replace(inputString, "0150", " D")
    inputString = Replace(inputString, "0510", " D'")
    inputString = Replace(inputString, "0160", " F")
    inputString = Replace(inputString, "0610", " F'")
    inputString = Replace(inputString, "0170", " B")
    inputString = Replace(inputString, "0710", " B'")
    inputString = Replace(inputString, "0180", " M")
    inputString = Replace(inputString, "0810", " M'")
    inputString = Replace(inputString, "0190", " E")
    inputString = Replace(inputString, "0910", " E'")
    inputString = Replace(inputString, "0230", " S")
    inputString = Replace(inputString, "0320", " S'")
    inputString = Replace(inputString, "0240", " l")
    inputString = Replace(inputString, "0420", " l'")
    inputString = Replace(inputString, "0250", " r")
    inputString = Replace(inputString, "0520", " r'")
    inputString = Replace(inputString, "0260", " u")
    inputString = Replace(inputString, "0620", " u'")
    inputString = Replace(inputString, "0270", " d")
    inputString = Replace(inputString, "0720", " d'")
    inputString = Replace(inputString, "0280", " f")
    inputString = Replace(inputString, "0820", " f'")
    inputString = Replace(inputString, "0290", " b")
    inputString = Replace(inputString, "0920", " b'")
    inputString = Replace(inputString, "0340", " m")
    inputString = Replace(inputString, "0430", " m'")
    inputString = Replace(inputString, "0350", " e")
    inputString = Replace(inputString, "0530", " e'")
    inputString = Replace(inputString, "0360", " s")
    inputString = Replace(inputString, "0630", " s'")
    inputString = Replace(inputString, "0370", " 2L")
    inputString = Replace(inputString, "0730", " 2L'")
    inputString = Replace(inputString, "0380", " 2R")
    inputString = Replace(inputString, "0830", " 2R'")
    inputString = Replace(inputString, "0390", " 2U")
    inputString = Replace(inputString, "0930", " 2U'")
    inputString = Replace(inputString, "0450", " 2D")
    inputString = Replace(inputString, "0540", " 2D'")
    inputString = Replace(inputString, "0460", " 2F")
    inputString = Replace(inputString, "0640", " 2F'")
    inputString = Replace(inputString, "0470", " 2B")
    inputString = Replace(inputString, "0740", " 2B'")
    inputString = Replace(inputString, "0480", " 2l")
    inputString = Replace(inputString, "0840", " 2l'")
    inputString = Replace(inputString, "0490", " 2r")
    inputString = Replace(inputString, "0940", " 2r'")
    inputString = Replace(inputString, "0560", " 2u")
    inputString = Replace(inputString, "0650", " 2u'")
    inputString = Replace(inputString, "0570", " 2d")
    inputString = Replace(inputString, "0750", " 2d'")
    inputString = Replace(inputString, "0580", " 2f")
    inputString = Replace(inputString, "0850", " 2f'")
    inputString = Replace(inputString, "0590", " 2b")
    inputString = Replace(inputString, "0950", " 2b'")
    inputString = Replace(inputString, "0670", " 2m")
    inputString = Replace(inputString, "0760", " 2m'")
    inputString = Replace(inputString, "0680", " 2e")
    inputString = Replace(inputString, "0860", " 2e'")
    inputString = Replace(inputString, "0690", " 2s")
    inputString = Replace(inputString, "0960", " 2s'")
    inputString = Replace(inputString, "0780", " 3L")
    inputString = Replace(inputString, "0870", " 3L'")
    inputString = Replace(inputString, "0790", " 3R")
    inputString = Replace(inputString, "0970", " 3R'")
    inputString = Replace(inputString, "0890", " 3U")
    inputString = Replace(inputString, "0980", " 3U'")
    inputString = Replace(inputString, "01020", " 3D")
    inputString = Replace(inputString, "02010", " 3D'")
    inputString = Replace(inputString, "01030", " 3F")
    inputString = Replace(inputString, "03010", " 3F'")
    inputString = Replace(inputString, "01040", " 3B")
    inputString = Replace(inputString, "04010", " 3B'")
    inputString = Replace(inputString, "01050", " 3l")
    inputString = Replace(inputString, "05010", " 3l'")
    inputString = Replace(inputString, "01060", " 3r")
    inputString = Replace(inputString, "06010", " 3r'")
    inputString = Replace(inputString, "01070", " 3u")
    inputString = Replace(inputString, "07010", " 3u'")
    inputString = Replace(inputString, "01080", " 3d")
    inputString = Replace(inputString, "08010", " 3d'")
    inputString = Replace(inputString, "01090", " 3f")
    inputString = Replace(inputString, "09010", " 3f'")
    inputString = Replace(inputString, "01120", " 3b")
    inputString = Replace(inputString, "02110", " 3b'")
    inputString = Replace(inputString, "01130", " 3m")
    inputString = Replace(inputString, "03110", " 3m'")
    inputString = Replace(inputString, "01140", " 3e")
    inputString = Replace(inputString, "04110", " 3e'")
    inputString = Replace(inputString, "01150", " 3s")
    inputString = Replace(inputString, "05110", " 3s'")
    inputString = Replace(inputString, "01160", " 4l")
    inputString = Replace(inputString, "06110", " 4l'")
    inputString = Replace(inputString, "01170", " 4r")
    inputString = Replace(inputString, "07110", " 4r'")
    inputString = Replace(inputString, "01180", " 4u")
    inputString = Replace(inputString, "08110", " 4u'")
    inputString = Replace(inputString, "01190", " 4d")
    inputString = Replace(inputString, "09110", " 4d'")
    inputString = Replace(inputString, "01220", " 4f")
    inputString = Replace(inputString, "02210", " 4f'")
    inputString = Replace(inputString, "01230", " 4b")
    inputString = Replace(inputString, "03210", " 4b'")
    inputString = Replace(inputString, "01240", " 4m")
    inputString = Replace(inputString, "04210", " 4m'")
    inputString = Replace(inputString, "01250", " 4e")
    inputString = Replace(inputString, "05210", " 4e'")
    inputString = Replace(inputString, "01260", " 4s")
    inputString = Replace(inputString, "06210", " 4s'")
    inputString = Replace(inputString, "01270", " 5l")
    inputString = Replace(inputString, "07210", " 5l'")
    inputString = Replace(inputString, "01280", " 5r")
    inputString = Replace(inputString, "08210", " 5r'")
    inputString = Replace(inputString, "01290", " 5u")
    inputString = Replace(inputString, "09210", " 5u'")
    inputString = Replace(inputString, "01320", " 5d")
    inputString = Replace(inputString, "02310", " 5d'")
    inputString = Replace(inputString, "01330", " 5f")
    inputString = Replace(inputString, "03310", " 5f'")
    inputString = Replace(inputString, "01340", " 5b")
    inputString = Replace(inputString, "04310", " 5b'")
    inputString = Replace(inputString, "01350", " 5m")
    inputString = Replace(inputString, "05310", " 5m'")
    inputString = Replace(inputString, "01360", " 5e")
    inputString = Replace(inputString, "06310", " 5e'")
    inputString = Replace(inputString, "01370", " 5s")
    inputString = Replace(inputString, "07310", " 5s'")
    inputString = Replace(inputString, "01380", " 6l")
    inputString = Replace(inputString, "08310", " 6l'")
    inputString = Replace(inputString, "01390", " 6r")
    inputString = Replace(inputString, "09310", " 6r'")
    inputString = Replace(inputString, "01420", " 6u")
    inputString = Replace(inputString, "02410", " 6u'")
    inputString = Replace(inputString, "01430", " 6d")
    inputString = Replace(inputString, "03410", " 6d'")
    inputString = Replace(inputString, "01440", " 6f")
    inputString = Replace(inputString, "04410", " 6f'")
    inputString = Replace(inputString, "01450", " 6b")
    inputString = Replace(inputString, "05410", " 6b'")
    inputString = Replace(inputString, "06410", " x'")
    inputString = Replace(inputString, "01460", " x")
    inputString = Replace(inputString, "07410", " y'")
    inputString = Replace(inputString, "01470", " y")
    inputString = Replace(inputString, "08410", " z'")
    inputString = Replace(inputString, "01480", " z")
    inputString = Replace(inputString, "01570", " (")
    inputString = Replace(inputString, "07510", ") ")
    
    'In the substitutiosn above we create an extra white space at the beginning of our string.
    'Let's delete it.
    inputString = Mid(inputString, 2, Len(inputString))
    
 
    'Store the expansion in the second column in the same row as input.
    Cells(ActiveCell.Row, ActiveCell.Column + 1) = inputString
     
End Sub
```


----------



## sneze2r (Nov 29, 2013)

It looks great, but i dont have excel, i have openoffice calc but this macro doesn't work there  is there any chance to convert this code to use it in google spreadsheets?


----------



## Christopher Mowla (Nov 29, 2013)

I would if I knew javascript, but I don't, and I think it's more time consuming to pick up than Excel. So maybe in the future I will do this.

However, someone who knows even the basics of javascript should be able to translate my code, since my algorithm is very simple.

For those who have Excel, I did edit the Excel spreadsheet to include moves 2-3u, for example.


----------



## Stefan (Nov 29, 2013)

Can you use Python in openoffice so something like this works? Or Lucas' JavaScript?


----------



## Christopher Mowla (Nov 29, 2013)

I searched about Python and openoffice and I found this. I doubt I would be able to do this at this point, as I have no experience with integrating different software or web-based languages. So I'll pass, but if someone wants to use my algorithm to write this, he or she is more than welcome.

Just in case the code in my post was not comprehensible, my algorithm is:


Spoiler: Algorithm



1) Input a string to be expanded.

2) Replace all '2s and 2's with 2s.

3) Replace all moves with numbers (you can easily see my choice of numbers...I put a zero on both sides of the numbers to securely separate them).
THE ORDER IN WHICH WE SUBSTITUTE DOES MATTER! (see my code to see what should be substituted first...feel free to substitute in this exact manner). (I also replaced parentheses and cube rotations.)

4) Delete all existing white spaces.

*5) Create a while loop* with the condition that there exists at least one "]" in the string (which we will update every iteration).

6) Find the location of the first occurring "]" and store that as an int variable.

7) Create a temporary string which is a substring of our main string, from the beginning to the location of the "]" we just found.

8) Find the location of the last occurring "[" in this substring and store that as an int variable.

9) Create a second temporary string which is a substring of our main string: start from location("[") + 1, to location("]") - location("[") -1.
(This is a substring of the form "X, Y" or "X: Y")

10) Find the location of "," in this substring. If there is no ",", then find the location of ":" in this substring (it's a conjugate, not a commutator).

11) Create another temporary string, say, stringX and a temporary string, say, stringY.

12) stringX is a substring of our "X, Y" or "X: Y" substring, starting from the beginning of it to location(":" or ",") -1.

13) string Y is a substring "" from location(":" or ",") + 1 to the end of this substring.

14) Create a final temporary string which is:
stringX + stringY + ReverseString(stringX) + ReverseString(stringY), if the delimiter is "," (we have a commutator) or
stringX + stringY + ReverseString(stringX), if the delimiter is ":" (we have a conjugate).
We now have a temporary string which has no braces, only expanded moves "X Y Reverse(X) Reverse(Y)" or "X Y Reverse(X)"
(a string of digits, but don't let that distract you, just think of it as moves).

15) We insert this temporary string in place of where it was in our main string. We replace "[X,Y]" or "[X:Y]" in our substring with our substring from step 14. That is, we store our main string as:
mainString([from beginning(mainString) to location("[") -1]) + our temporary string + mainString([from location "]" + 1, mainString length]).

*16) End the loop* (put the close loop code here).
Our entire main string is now a string of numbers without brackets, commas, and colons (assuming the user input the syntax correctly).

17) Substitute move notation letters in place of the numbers in our string (we just reverse the substitution we did at the beginning: ORDER OF SUBSTITUTION LINES DOES NOT MATTER).
Make sure that a single white space is substituted in addition to each letter move. For example, replace "09410" with " Lw'".

18) Delete extra white space at the beginning of the mainString (which started as our input string but is now our output string) by storing mainString as itself from slot 2 to the end of it.


(I've have to review my Mathematica code for my commutator project at the moment, so I can't spend anymore time on this than I already have).


----------



## Lucas Garron (Nov 30, 2013)

cmowla said:


> Nice tool, Lucas.
> 
> I might be doing something wrong with your tool, but I can't get it to expand this [F U:[R2 F',UR]] correctly, for example.



Oops, I, uh... had a bug in the simplification routine from a leftover refactor?
I've separated it into "Expand" and Simplify". I think it should be alright now, but is still subject to change:
[R U R2, R U2 R2]



cmowla said:


> I wrote a program in Mathematica so far (if you want Lucas, I can post the code) for which I will attempt to translate to Excel.
> 
> By the way, I know you're experienced with Mathematica, is there an easy way to make an executable from Mathematica code?



I originally wanted to write custom code for a task like this, but I've become convinced that this is a job for a proper parser (well, parser generator). It's much more robust and easier to adapt. It can also be ported to other languages more easily since it's based on a common family of parsers.

You're welcome to poke around with other stuff, but I don't think it'll be very useful in the end.
(And trying to distribute anything Mathematica-based is probably futile, even given the fact that Wolfram Language is *finally* out.)


----------



## sneze2r (Dec 5, 2013)

Stefan,
it didn't work, i've tried to apply it but there were errors.
Anyway, i try to write my script on google spreadsheet (.gs) and i started it with writing a mirror function(It is based on script tralnslating RU alphabet to EN)
Here is the code:


Spoiler: Script



var RU = [" ", "R","R2","R'","L","L2","L'","U","U2","U'","D","D2","D'","F","F2","F'","B","B2","B'"];
var EN = [" ", "L'","L2","L","R'","R2","R", "U'","U2","U","D'","D2","D","F'","F2","F","B'","B2","B"];
function returnIndexOf(arr, obj){
var result = arr.indexOf(obj);
if(result!=-1){
return result;
}else{
return 0;
}
}
function miror(s) {
var result = "";
var symbol = "";
var arr = s.split("");

for(i in arr){
symbol = EN[returnIndexOf(RU,arr_)];
result = result + symbol;
}
return result;
}

_


_

Anyway, after executing this when i write in cell: =miror("R") it returns 1, when i write =miror("R U R'") i returns me a 6... It always return a length of my alg with spaces and primes " ' ", can anybody notice where in the code mistake is?_


----------



## Jakube (Dec 5, 2013)

If I try your code, with miror("R") it returns L'. Don't know, why you get the length. 
Although there are a few mistakes. For instance miror("R'") returns L''. 
I rewrote your code, so that it works: 



Spoiler: mirror-function





```
function mirror(s) {
  var RU = ["R", "L", "U", "D", "F", "B"];
  var EN = ["L", "R", "U", "D", "F", "B"];
  var result = "";
  var symbol = "";
  var index = 0;
  
  for(var i = 0; i < s.length; i++){
    symbol = s.charAt(i);
    if (symbol == " "){
      result += " ";
      continue;
    }
    
    index = RU.indexOf(symbol);
    if (index == -1) {
      return "ERROR";
    }
    
    result += EN[index];
    
    symbol = s.charAt(i+1);
    if (symbol == "'"){
      i++;
    } else if (symbol == "2") {
      result += "2";
      i++;
    } else {
      result += "'";
    }
  }
  return result;
}
```




I also wrote a function, which expands commutators. 



Spoiler: expandCommutator





```
function expandCommutator(s){
  var A = ""; 
  var B = ""; 
  var result = "";
  var i = 0;
  var inA = false;
  
  while(i < s.length && s.charAt(i) != "[") {
    result += s.charAt(i);
    i++;
  }
  
  i++;
  while(i < s.length && s.charAt(i) != ";") {
    A += s.charAt(i);
    i++;
  }
  
  i++;
  while(i < s.length && s.charAt(i) != "]") {
    B += s.charAt(i);
    i++;
  }
  
  result += A + B + inverse(A) + inverse(B);
  
  i++;
  while(i < s.length) {
    result += s.charAt(i);
    i++;
  }
  
  return cancle(result);
}

function inverse(s) {
  var moves = ["R", "L", "U", "D", "F", "B"];
  var result = "";
  var symbol = "";

  for(var i = s.length - 1; i >= 0; i--){
    symbol = s.charAt(i);
    if (symbol == "'"){
      i--;
      result += s.charAt(i);
    } else if (symbol == "2") {
      i--;
      result += s.charAt(i) + "2";
    } else if (moves.indexOf(symbol) != -1){
      result += symbol + "'";
    }
  }
  return result;
}

// cancles (R2 R -> R') and formats the moves
function cancle(s){
  s += " ";
  var moves = ["R", "L", "U", "D", "F", "B"];
    var result = "";
  var move = "";
  var moveCnt = 0;
  var symbol = "";
  var t = "";
  
  var cancled = true;
  while (cancled) {
    cancled = false;
    move = "A";
    moveCnt = 0;
    for (var i = 0; i < s.length; i++){
      symbol = s.charAt(i);
      if (moves.indexOf(symbol) != -1) {
        //move detected
        if (move == symbol) {
          //same move as the previous, update moveCnt
          cancled = true;
          symbol = s.charAt(i+1);
          if (symbol == "'") {
            i++;
            moveCnt += 3;
          } else if (symbol == "2") {
            i++;
            moveCnt += 2;
          } else {
            moveCnt += 1;
          }
        } else {
          //new move detected, print old move
          if (moveCnt%4 != 0) {
            result += move; 
            if (moveCnt%4 == 2) {
              result += "2";
            } else if (moveCnt%4 == 3) {
              result += "'";
            }
            result += " ";
          }
          //remember new move
          move = symbol; 
          symbol = s.charAt(i+1);
          if (symbol == "'") {
            i++;
            moveCnt = 3;
          } else if (symbol == "2") {
            moveCnt = 2;
          } else {
            moveCnt = 1;
          }
        }
      }
    }
    //add last move
    if (moveCnt%4 != 0) {
      result += move; 
      if (moveCnt%4 == 2) {
        result += "2";
      } else if (moveCnt%4 == 3) {
        result += "'";
      }
      result += " ";
    }
    //switch variables for the next cancelations
    s = result; 
    result = "";
  }
  return s;
}
```




It even cancles moves: for example

=expandCommutator("R2 [RFR';B2] R2") gives R' F R' B2 R F' R' B2 R2
=expandCommutator("[R U R2; R U2 R2]") gives R U R' U R U2 R'

The code may be a bit ugly. I don't even know which language this is (JavaScript?). 
Nested Commutator don't work.


----------



## Stefan (Dec 5, 2013)

Jakube said:


> Spoiler: mirror-function
> 
> 
> 
> ...



Same thing a little shorter:


```
function mirror(s) {
  return s.replace(/([LRFBUD])([2']?)/g, function(m, s, a){
    return 'LRFBUD'.charAt('RLFBUD'.indexOf(s)) + ["'",'2','']["#2'".indexOf(a)];
  });
}
```
or

```
function mirror(s) {
  return s.replace(/([LRFBUD])([2']?)/g, function(m, s, a){
    return ((s=='L')?'R':(s=='R')?'L':s) + ((a=='')?"'":(a=='2')?a:'');
  });
}
```
Try it at ideone.


----------



## sneze2r (Dec 5, 2013)

Thanks Jakube for the code! That is all what i needed  i also expanded it so it include rotation x y z (no double rotation like x2 beacouse i never use it in bld)
I've just added to every array "x", "y", "z". To mirror function i had to add extra if's to make it return "x" for "x" and "x' " for "x' ". Code is very noobish, i only know basic of c++ basics:


Spoiler: code mirror



function mir(s) {
var RU = ["R", "L", "U", "D", "F", "B","y","z","x"];
var EN = ["L", "R", "U", "D", "F", "B","y","z","x"];
var result = "";
var symbol = "";
var symboll = "";
var extra = "";
var index = 0;

for(var i = 0; i < s.length; i++){
symbol = s.charAt(i);
symboll = s.charAt(i+1);

if (symbol == " "){
result += " ";
continue;
}
if(symbol == "x" && symboll == "'"){
result+= "x";
result+= "'";
i++;
continue;
}
if(symbol == "x"){
result+= "x";
continue;
}

index = RU.indexOf(symbol);
if (index == -1) {
return "ERROR";
}

result += EN[index];

symbol = s.charAt(i+1);
if (symbol == "'"){
i++;
} else if (symbol == "2") {
result += "2";
i++;
} else {
result += "'";
}
}
return result;
}


Maybe during writing down my edge bld algs i'll came up with cancelation like RM'=r etc.

About Stefan's code: It looks very good despite i have no idea what does / and ? mean  it will be usefull anyway!
Greetings,
Grzegorz


----------



## Stefan (Dec 5, 2013)

sneze2r said:


> About Stefan's code: It looks very good despite i have no idea what does / and ? mean



I'm just using regular expressions. They're quite useful.


----------

