simplify repeated ternary expression