Posts

Showing posts with the label rpn

Comparing rpn (postfix) expressions for equivalency

Comparing rpn (postfix) expressions for equivalency How would one compare any two postfix notated expressions for equivalency? In the simplest example, foo(a, b) returns True for a = [3, 5, 'MUL'] b = [5, 3, 'MUL'] What would foo() look like in python? I imagine that one way is to evaluate both expressions and normalize them somehow. I expect that this is a well defined process but haven't found it yet. foo() Edit 1: This was a poorly worded question. I will try with better/more examples, and appreciate your patience as I try and ask the question clearly and precisely. expr1 = [a, b, 'MUL'] expr2 = [b, a, 'MUL'] OR expr1 = [a, b, 1, 'ADD', 'MUL'] expr2 = [a, b, 'MUL', a, 'ADD'] Do you have a function that calculates the notation? or are you asking here for someone here to help you create a code for that too? – Vincent Pakson Jul 2 at 5:42 ...