The if condition checks for a single return value, so applying it to a tensor won’t work out of the box and you could index the tensor instead.
I.e. using the posted conditions, you could apply the changes to parts of the tensor.
Something like this might work:
kc = torch.randn(10, 2)
f = torch.zeros_like(kc)

idx1 = kc > 0.5
f[idx1] = (kc[idx1] - 0.5)**2

idx2 = (0 <= kc) & (kc <= 0.5)
f[idx2] = 0 # wouldn't be necessary, as f is already initialized as zeros

used_idx = torch.zeros_like(idx1).bool()
used_idx |= idx1
used_idx |= idx2
f[~used_idx] = kc[~used_idx]**2