I'm having a problem when i can't cancel the -2 and the cosB, for example;

From the cosine rule to find the area of a triangle:

Here i can just cancel the and as

The problem arises when i cant cancel these two components so what do i do? For example;