Threshold implementation of ternary systems