I am trying to transform
(((p v q) > (r v (p v q))) > ((p & s) v (r v s))) > (p & r)
into
~(~(~(p v q) v (r v (p v q))) v ((p & s) v (r v s))) v (p & r)
So it seems that the algorithm should be:
1. start with the left most character, go right, look for >, when the first > is found, go left and count the open and closed parentheses, when the open and closed parentheses equal each other then replace the open parentheses that eventually equaled the amount of closed parentheses with ~(
2. then return to the first > found, then go right and look for another > and repeat the procedure until all > have been transformed.
I used one of Rick's macros from another post to try to do it myself but I had problems with getting Excel to process ">" so I had to change the symbol to "t"
I did eventually get it to work but then I realized that the required algorithm is more complicated since it can only handle one t per sentence.
Code:
Function matim(ByVal S As String) As String
Dim X As Long, t As Long, Total As Long
t = InStr(1, S, "t", vbTextCompare)
For X = InStrRev(S, ")", t) To 1 Step -1
If Mid(S, X, 1) = ")" Then
Total = Total + 1
ElseIf Mid(S, X, 1) = "(" Then
Total = Total - 1
End If
If Total = 0 Then
S = Application.Replace(S, X, 0, "~")
Exit For
End If
Next
S = Replace(S, "t", "v", , , vbTextCompare)
matim = S
End Function
That code doesn't work.
My final bit of string manipulation will then be to transform v into &
This is done as follows:
(p v q) = ~(~p & ~q)
So the algorithm would go:
1. Start at letter 1, go right, find the first v.
2. Go right and look for either ( or a letter. Whichever one you find place a ~ to the left of it.
3. Find either the first letter to the right or the first ( and put a ~ to the left of it.
4. Then go left and find either the first letter or the first ).
5. If one finds a letter place a ~ to the left of it.
5a. Then continue left and place transform the next ( to ~(
6. If one finds a ) then count it and continue left. As soon as the number of ) equals the number of (, then replace ( with ~(
6a. Then continue left and it is always the case that the next character one finds is either ~ or (. If ~ do nothing and continue left and replace the first ( with ~(
7. Return to the beginning of the newly transformed string and repeat steps one through 6.
Input
(~(~(~(p v q) v (r v (p v q))) v ((p & s) v (r v s))) v (p & r))
1.
(~(~(~~(~p & ~q) v (r v (p v q))) v ((p & s) v (r v s))) v (p & r))
2.
(~(~~(~~~(~p & ~q) & ~(r v (p v q))) v ((p & s) v (r v s))) v (p & r))
3.
(~(~~(~~~(~p & ~q) & ~~(~r & ~(p v q))) v ((p & s) v (r v s))) v (p & r))
4.
(~(~~(~~~(~p & ~q) & ~~(~r & ~~(~p & ~q))) v ((p & s) v (r v s))) v (p & r))
5.
(~~(~~~(~~~(~p & ~q) & ~~(~r & ~~(~p & ~q))) & ~((p & s) v (r v s))) v (p & r))
6.
(~~(~~~(~~~(~p & ~q) & ~~(~r & ~~(~p & ~q))) & ~~(~(p & s) & ~(r v s))) v (p & r))
7.
(~~(~~~(~~~(~p & ~q) & ~~(~r & ~~(~p & ~q))) & ~~(~(p & s) & ~~(~r & ~s))) v (p & r))
8.
~(~~~(~~~(~~~(~p & ~q) & ~~(~r & ~~(~p & ~q))) & ~~(~(p & s) & ~~(~r & ~s))) & ~(p & r))
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgwviLabd7r_3KpP6wh4AaABAg. 9h5lFRmix1R9h78GftO_iE
https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg. 9h740K6COOA9h77HSGDH4A
https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg. 9h740K6COOA9h76fafzcEJ
https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg. 9h740K6COOA9h759YIjlaG
https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg. 9h740K6COOA9h74pjGcbEq
https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg
https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgzJJUDVv2Mb6YGkPYh4AaABAg. 9h5uPRbWIZl9h7165DZdjg
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
Bookmarks