I got the impression that was an exercise in maths not programming, so p ∨ q is easier to understand than p ∨ ¬p ∧ q.

Chances are the compiler will not be programmed to do that sort of optimisation and if somebody wrote that in real life, they might not realise that there is such a simpler form. So you would have to simplify the expression yourself with the specialised carbon‑based technology which I so frequently advocate: pencil paper and eraser

I was taught to write truth tables in binary 0…2ⁿ − 1 ascending FFF…TTT (but other people write them in descending order). The expression above can be reduced to two predicates remembering that x > 0 ≡ ¬(x ≤ 0) and a two‑predicate expression can be expressed as four lines.

`p q | 0 1 2 3 4 5 6 7 8 9 a b c d e f
`

F F | F F F F F F F F T T T T T T T T

F T | F F F F T T T T F F F F T T T T

T F | F F T T F F T T F F T T F F T T

T T | F T F T F T F T F T F T F T F T
Assuming you are using two‑valued logic where the Law of the Excluded Middle applies, those four rows comprise the entire gamut of possibilities for the values of any two‑predicate logical expression. If you replace all the Ts with 1s and the Fs with 0s, the left block reads 0‑1‑2‑3 and the right block reads 0…f if you read down the columns. The sixteen expressions can be expressed as

0 =

*false*
1 = p ∧ q

2 = p ⇏ q i.e. p does not imply q

3 = p

4 = p ⇍ q i.e. p does not follow from q (see also line b)

5 = q

6 = p ⊕ q i.e. p xor q

7 = p ∨ q

8 = p ↓ q i.e. p nor q equivalent to ¬(p ∨ q)

9 = p ↔ q i.e. p iff q

a = ¬q

b = p ⇐ q i.e. p follows from q. This is equivalent to q ⇒ p

c = ¬p

d = p ⇒ q

e = p ↑ q i.e. p nand q equivalent to ¬(p ∧ q)

f =

*true*
Notice there is a symmetrical

pattern. If you add up two columns and get f, then one of those columns is the negation of the other.

Also two of the lines (the tautology and the contradiction) are independent of either predicate and four of the lines are independent of one predicate. So only ten lines actually require both.

Any two‑valued predicate which contains more than two terms can be simplified to one of those sixteen expressions above. If you are programming and you end up with something like this

… you should be able to work out that you can simplify it to

This sort of algebra has been around for 3000 years (when I did logic I learnt that it was the oldest language anybody on the course would ever use, older than any computer language and older than English) so there are all sorts of “laws” some with names like the contrapositive law. It is a good idea to reduce the expressions to those using only these six operators if you can (and ()): ¬ ∧ ⊕ ∨ ⇒ ↔

If you are coding in Java®

¬p is !p

p ∧ q is p && q

p ⊕ q is p ^ q

p ∨ q is p || q

p ⇒ q is p ? q : true

and p ↔ q is p == q

…but the precedences are different from what one uses in logic.