Engineering Mathematics for Computer Science: A Semester Guide from Logic to Probability

Follow six messages from sets and Boolean logic through least squares, derivatives, Bayes' rule and classification metrics, with each result checked step by step.

KnowledgeGate Team

Exam prep & CS education

Updated 23 Nov 20265 min read
Engineering Mathematics for Computer Science: A Semester Guide from Logic to Probability

Discrete mathematics, linear algebra, calculus, probability and statistics can look like five unrelated formula lists, which makes it hard to see why later Computer Science courses keep reusing them. A six-message spam-filter dataset links sets, a vector model, least squares, a derivative, Bayes' rule and a confusion matrix. Its checksum is a fitted weight of a=2/3, squared error 5/3, posterior P(spam | link)=2/3 and classification accuracy 2/3.

Use the GATE, PSU and Technical Exams page to place this mathematics route beside your other semester subjects.

1. Put the five mathematics blocks in a Computer Science learning order

A dependency-first revision chain is:

discrete structures -> vector representation -> optimisation by calculus -> probability under uncertainty -> statistical evaluation

This is a learning route, not a claim that every university teaches these units in this order. Sets, logic, relations, counting and graphs support databases, automata and algorithms. Vectors and matrices support graphics, networks and machine learning. Derivatives locate optima, probability models uncertain outcomes, and statistics tests what observed data supports.

The six-message example makes those connections concrete. Proof methods, eigenvalue algorithms, multivariable integration and full statistical inference still need their own study blocks. Zero to Hero is a wider semester route when you also need the adjacent Computer Science subjects.

2. Use discrete mathematics to define the data and the rule

Let 1 mean that a property is present. It does not mean that the row was predicted correctly.

Message

Link L

Urgent word U

Spam S

e1

1

1

1

e2

1

0

1

e3

0

1

0

e4

0

0

0

e5

1

0

0

e6

0

1

1

The universe is E={e1,e2,e3,e4,e5,e6}. The three sets are L={e1,e2,e5}, U={e1,e3,e6} and S={e1,e2,e6}. Therefore L intersect U={e1}, L union U={e1,e2,e3,e5,e6}, L minus S={e5}, S minus L={e6}, and L symmetric-difference S={e5,e6}. The predicate L and not U selects {e2,e5}.

The claim L implies S is false because e5 has L=1 and S=0. Two Boolean features permit 2^2=4 patterns, and all occur: (1,1) at e1, (1,0) at e2 and e5, (0,1) at e3 and e6, and (0,0) at e4. The Discrete Mathematics study-order guide develops the wider topic map.

3. Turn the same six rows into a linear-algebra model

Start with only the link feature. Define x=[1,1,0,0,1,0]^T and the true-label vector y=[1,1,0,0,0,1]^T. Both x and y are 6 by 1. In the zero-intercept model y_hat=a x, x^T x is 1 by 1, so a is a scalar fitted weight.

Least squares gives the normal equation (x^T x)a=x^T y. Compute each side:

  • x^T x=1+1+0+0+1+0=3

  • x^T y=1+1+0+0+0+0=2

  • 3a=2, so a=2/3

The prediction vector is y_hat=[2/3,2/3,0,0,2/3,0]^T. Subtracting it from the true labels gives y-y_hat=[1/3,1/3,0,0,-2/3,1]^T. Hence the squared error is 1/9+1/9+0+0+4/9+1=15/9=5/3.

The errors explain the model's limit. A link-only representation cannot distinguish spam e2 from non-spam e5, and it assigns no positive score to spam e6.

4. Use calculus to recover the same optimum and check it

Write the error directly from the six rows:

J(a)=sum_i(a x_i-y_i)^2=(a-1)^2+(a-1)^2+0+0+a^2+1=3a^2-4a+3

The final +1 is the unavoidable e6 error when link is the only feature. Differentiation gives J'(a)=6a-4. Setting it to zero gives a=2/3, and J''(a)=6>0 confirms a minimum. Substitution checks the value:

J(2/3)=3(4/9)-4(2/3)+3=4/3-8/3+3=5/3

For comparison, J(0)=3 and J(1)=2, so the fitted value is visibly better. A deliberately chosen gradient-descent step reaches it too. With a0=0 and learning rate eta=1/6, J'(0)=-4, so a1=a0-eta J'(a0)=0-(1/6)(-4)=2/3. That one-step arrival follows from this quadratic and this learning rate. It is not a general property of gradient descent.

Three-panel graphic showing the six-row dataset, the normal-equation fit a=2/3 with SSE=5/3, and the verified quadratic minimum at a=2/3.

5. Read the same count as a conditional probability

Count first. There are 3 spam messages, 3 non-spam messages, 3 linked messages and 2 messages in L intersect S. Thus P(S)=3/6=1/2, P(L)=3/6=1/2, P(L|S)=2/3 and P(L|not S)=1/3.

Now apply Bayes' rule with its full denominator:

P(S|L)=[P(L|S)P(S)]/[P(L|S)P(S)+P(L|not S)P(not S)]

Substitution gives [(2/3)(1/2)]/[(2/3)(1/2)+(1/3)(1/2)]=(1/3)/(1/2)=2/3. In the non-link set {e3,e4,e6}, one of three messages is spam, so P(S|not L)=1/3.

Here P(S|L)=2/3 equals the least-squares coefficient because a zero-intercept model on one binary indicator predicts the mean label among rows where the indicator is 1. This is a property of this setup, not an identity between Bayes' rule and least squares. Use the Probability guide for more conditional-probability practice.

6. Use statistics to evaluate what the model gets right and wrong

The label mean is y_bar=(1+1+0+0+0+1)/6=1/2. Every label is 1/2 away from that mean. Under the population-variance convention, variance=[6 x (1/2)^2]/6=1/4. Under the sample convention, it is [6 x (1/4)]/5=3/10. Stating the denominator prevents the two quantities from being confused.

Turn the link rule into class predictions by predicting spam whenever L=1. For e1 through e6, the predictions are [1,1,0,0,1,0]. The outcomes are:

  • True positives {e1,e2}, so TP=2

  • False positive {e5}, so FP=1

  • True negatives {e3,e4}, so TN=2

  • False negative {e6}, so FN=1

Therefore accuracy=(TP+TN)/6=4/6=2/3, precision=TP/(TP+FP)=2/3, and recall=TP/(TP+FN)=2/3. With P=R=2/3, F1=2PR/(P+R)=2/3. These values match because this table is balanced in a particular way, not because the four metrics must always be equal.

Set diagram and confusion matrix for the six messages, highlighting e5 as a false positive, e6 as a false negative, and all four metrics at 2/3.

7. Practise the exam-style joins and fix the recurring traps

These are exam-style prompts, not quoted previous-year questions.

  1. Exam-style Prompt A: Find L symmetric-difference S and decide whether L implies S. Answer: {e5,e6} and false, with e5 as the counterexample.

  2. Exam-style Prompt B: Given x and y, find a, y_hat and SSE. Answer: 2/3, [2/3,2/3,0,0,2/3,0]^T and 5/3.

  3. Exam-style Prompt C: Given J(a)=3a^2-4a+3, classify its stationary point. Answer: a=2/3, a minimum because J''=6>0.

  4. Exam-style Prompt D: Find P(S|L) and the confusion counts. Answer: 2/3 and (TP,FP,TN,FN)=(2,1,2,1).

Mistake

What goes wrong

Correct check

Omitting the universe

Complements become ambiguous

Write E before taking a complement

Multiplying incompatible matrix dimensions

The model expression is invalid

Annotate every vector and product dimension

Solving J'=0 without checking curvature

A maximum may be labelled a minimum

Compute J'' or inspect the function

Swapping P(S|L) with P(L|S)

The condition is reversed

Read the event after the bar first

Mixing division by 6 with division by 5

Population and sample variance are confused

State the variance convention

For optional drill, use the mapped Discrete Mathematics, Linear Algebra, Calculus, Probability and Statistics practice areas. Also check your university's official current syllabus and paper instructions before planning revision, since the order and assessment rules can vary.

8. Engineering Mathematics short version and the next study step

Recall the chain: define the universe and predicates -> encode them as vectors -> choose an error function -> differentiate and verify the optimum -> condition on evidence -> evaluate predictions with counts.

Use three self-checks. With eta=1/12 and a0=0, obtain a1=1/3, J(a1)=2, then a2=1/2. Add urgent as a second feature: X^T X=[[3,1],[1,3]] and X^T y=[2,2]^T give weights [1/2,1/2]^T and SSE 1. Finally, change e5's label to 1: then P(S|L)=1, with TP=3, FP=0, TN=2, FN=1 under the link rule.

When those checks work on paper, Engineering Mathematics for GATE is the focused structured next step.