lion137 / propositional_calculus_evaluate

evaluates propositional logic expression
MIT License
4 stars 0 forks source link

Are contributions accepted? Have a few ideas. #1

Open srd4 opened 4 years ago

srd4 commented 4 years ago

I saw your comment on r/python today. Coincidentally I worked last week in something similar after being introduced to propositional logic at a discrete maths course. I'm interested in collaborating and thought about some ideas and improvements:

Totally up for helping with the project if you want help at all. Thanks for reading, and have a good day!!

lion137 commented 4 years ago

Hi, Thanks for interest and feedback.

On Sat, 2 Nov 2019 at 21:42, Daniel Gil notifications@github.com wrote:

I saw your comment on r/python today. Coincidentally I worked last week in something similar after being introduced to propositional logic at a discrete maths course. I'm interested in collaborating and thought about some ideas and improvements:

  • Implementing truth tables. This can be used to verify equivalence between different formulas.
  • Using english words as conectives to join formulas, i.e, ~a && b being posible to write as "not a and b" (and complexer) and to be recognized. This wouldn't be difficult given how well your implementation seems to be written, kudos for that.
  • Documenting the code and make it a bit more readable for people who want to collaborate.

Totally up for helping with the project if you want help at all. Thanks for reading, and have a good day!!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/lion137/propositional_calculus_evaluate/issues/1?email_source=notifications&email_token=ACNCEM3Y4FKXM7GDVDWH5JDQRXQ3VA5CNFSM4JIIBEOKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HWMOOMA, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACNCEM4XIOBIHWTJKME44HTQRXQ3VANCNFSM4JIIBEOA .

-- Buy silver - Crash JP Morgan! Those who can die live freely!

srd4 commented 4 years ago

I actually couldn't help and play with the code a bit yasterday. As I said, I'm taking a course on discrete maths and wanted to try a few expressions I had on my notes. I noticed that it was a bit slow to write symbols (or I'm just not used to it, I guess) I do type quite fast and wanted to try many expressions so I beggan analysing the code and found an easy way arround it. Didn't event need to touch the rest of the stuff:

def replaceEnglish(formula):
    #Replaces english operators in formula with equivalent symbols.
    equivalences = dict({"not":"~", "and":"&&", "or":"||", "if only if":"<=>","only if":"<=>", "then":"=>"})

    for equivalence in equivalences:
        if equivalence in formula:
            formula = formula.replace(equivalence,equivalences[equivalence])

    return formula

User input just needs to be passed here once and there'll be no problem with the rest of the code.

I don't want to paste the whole thing here so take, for example, that to prove the equivalence (~ p => ~ q) <=> (q => p) I would make something like "not p then not q == p or not q == not q or p == q then p" and want to know if I made any mistakes along the way:

> not p then not q == p or not q == not q or p  == q then p
Formulas are equal
> not p then not q == p or not q == not q or p  == q then x
q then x is not equal

As I say, I managed to make it work, and also is using messages from your check() to reference a specific error on formulas:

> a or not a == weird a
Invalid symbols on formula 2

Other than that, I noticed a few minimal redundancies on the code and have due to understand how eval and parse really work, also made a different version of the tokenize function and moved some stuff repl function to make it all work, mainly because of the changes I was making but also noticed that the help commands where not working and corrected it too. The comments you say would really help. You made a good job making the mechanics of this thing. And I'm telling you because I tried it myself a few days ago lol.

I'm willing to collaborate as much as I can, actually learned a bunch of stuff just messing with it and want to keep learning even more! I guess I'll be reading what you sent, tell me if you want to see more of what I implemented.