I have an "if decision tree" and I want to know if it's possible to optimize it:
def s(a, b):
"""
:param a: 0,1,2
:param b: 0,1,2
:return: 0,1,2
"""
if a == 0:
if b == 0:
return 2
elif b == 1:
return 2
else: # b == 2
return 0
elif a == 1:
if b == 0:
return 2
elif b == 1:
return 2
else: # b == 2
return 1
else: # a==2
if b == 0:
return 0
elif b == 1:
return 1
else: # b==2
return 2
All cases included, I'm trying use (a,b) == (1,2) or (a,b) == (2,1) return 1 and the same when return 0. Other cases return 2, but it is slower.
EDIT:
I have tested (time and valid (all valid)) all proposed "ifs" and:
s is my explicit function
ss is first proposed function
sss is second proposed function
etc.
and here I have profile:

andandorbut if you're concerned about optimizing an if-statement, you're usually over thinking optimization