Balanced ternary logic
Clean, 231 ... 162 bytes

import StdEnv
$n=tl(foldr(\p[t:s]#d=sign(2*t/3^p)
=[t-d*3^p,d:s])[n][0..26])
@x y z=sum[3^p*[(a+b)/2,[1,-1,0,1,-1]!!(a+b+2),a*b]!!(z+1)\\a&lt;- $x&amp;b&lt;- $y&amp;p&lt;-[0..26]]


Defines the function @, taking three Ints and giving an Int.
Operators map as 1 -&gt; A, 0 -&gt; B, -1 -&gt; C.

Try it online!

The function $ folds a lambda over the digit places [0..26], into a list of ternary digits. It uses the head of the list it yields to keep a current total difference from the requisite number (which is why it is tailed prior to returning), and sign(2*t/3^p) to determine the current digit to yield. The sign trick is equivalent to if(abs(2*t)&lt;3^p)0(sign t).