0

I have propositional and temporal logic expressions like:

"phi1 => phi2"; 
"phi1 U phi2";
"X phi1".

I would like to represent them using prefix notation, i.e, "phi1 U phi2" would be represented as "U phi1 phi2". Any ideas on which data type to use to represent "U phi1 phi2"? I'm using python and I know I can represent it as a string, but I was wondering if there something more efficient because I need to acess each term of the expression individually. Also tried to represent it as ("U","phi1","phi2") which works fine, but for more complex formula it becomes heavy on "()".

Thanks in advance

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
  • Do you wand to evaluate them later on? In that case I would recommend to use a stack like sctructure (you could use lists in python). – Muhammed B. Aydemir Feb 10 '21 at 11:13
  • I'd use tuple for that ('U','phi1','phi2'). You don't need list object methods for storing that kind of info. And probably end of the day you get simpler implementation than using string and parsing it. – ex4 Feb 10 '21 at 12:03
  • Yes, that's what I'm using for that reason. – user849172 Feb 10 '21 at 12:07
  • I agree. Using tuples seems fine. Since you wont modify it (tuples are immutable). And in case you need some functions that you don't get with tuples, you can just convert it. – Muhammed B. Aydemir Feb 10 '21 at 12:24

0 Answers0