material implication

kylefoley76

Well-known Member
Joined
Mar 1, 2010
Messages
1,553
For those of you who know propositional logic, this is the material implication rule, which takes

(p) -> (q)

and turns it into

~(p) v (q)

I have two problems. In one function I'd like the t in "t as long" to be replaced with the hex character:
21FE

But I won't always be using the hex character so for now I would also like to use the > to stand for the t "t as long". I couldn't get > to work so I just used t.


Code:
unction 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
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Ok, I figured out that the above algorithm can't handle multiple implications embedded in one sentence. For example it cannot 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 new 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.
 
Upvote 0
Kyle, I'll weigh in, but only briefly.

You can't get there from here. You need to write a parser, build a parse tree, and a PL expression evaluator. You can't do it by counting parentheses.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top