CMSI 2820

CMSI 2820: Discrete Mathematics Cheat Sheet

Quick reference guide for course material. Sections unlock when homework is assigned.

Useful Terminal Commands

Git Commands

CommandDescriptionExample
git add [file/directory/path]Add a file/directory to the staging area. Use "." to add all changes currently in the working directory.git add .git add farm.pygit add src/
git commit -m "[commit message]"Commit changes to the repository. The -m flag is used to add a commit message to the commit and avoid the custom terminal interface.git commit -m "Completed HW1! 🎉"git commit -m "Fixed bug in farm.py"
git pushPush changes to the remote repository. This will update GitHub's cloud copy of the repository with the changes you have made locally.git push
git pullPull changes from the remote repository. This will update your local copy of the repository with the changes that have been made to the cloud repository.git pull

Python Commands

CommandDescriptionExample
python -m pytestRun the unit tests for the current project.python -m pytest
python [file.py]Run the file.py file. On MacOS, you may need to use `python3` instead of `python`.python proceedings.pypython3 test_farm.py
python -m pip install [package]Install a package using Python's Package Manager.python -m pip install pytestpython -m pip install numpy

Logic

Logical Operators

OperatorSymbolMeaningExample
Negation¬p or ~pNOT pIf p is true, ¬p is false
Conjunctionp ∧ qp AND qTrue only if both are true
Disjunctionp ∨ qp OR qTrue if at least one is true
Implicationp → qIf p then qFalse only if p is true and q is false
Biconditionalp ↔ qp if and only if qTrue if both have same truth value

Key Logical Equivalences

  • ¬(¬p) ≡ p (Double Negation)
  • p ∧ q ≡ q ∧ p (Commutative)
  • ¬(p ∧ q) ≡ ¬p ∨ ¬q (De Morgan's Laws)
  • p → q ≡ ¬p ∨ q (Implication)

Numbers

Divisibility Rules

  • 2: Last digit is even
  • 3: Sum of digits divisible by 3
  • 5: Last digit is 0 or 5
  • 9: Sum of digits divisible by 9
  • 10: Last digit is 0

Modular Arithmetic

  • a ≡ b (mod m) means m | (a - b)
  • (a + b) mod m = ((a mod m) + (b mod m)) mod m
  • (a × b) mod m = ((a mod m) × (b mod m)) mod m

Collections

Set Operations

OperationSymbolDefinition
UnionA ∪ BElements in A or B (or both)
IntersectionA ∩ BElements in both A and B
DifferenceA - BElements in A but not in B
ComplementA'Elements not in A
Cartesian ProductA × BAll ordered pairs (a, b)

Functions

Injective (One-to-One)

f(a) = f(b) implies a = b

Each output has at most one input

Surjective (Onto)

Every element in codomain is mapped

Range equals codomain

Bijective

Both injective and surjective

One-to-one correspondence

Combinatorics

Key Formulas

  • P(n,r) = n!/(n-r)! - Permutations (order matters)
  • C(n,r) = n!/(r!(n-r)!) - Combinations (order doesn't matter)
  • Sum Rule: If A and B are disjoint, |A ∪ B| = |A| + |B|
  • Product Rule: |A × B| = |A| × |B|

Common Patterns

  • Permutations with repetition: n^r
  • Combinations with repetition: C(n+r-1, r)
  • Pigeonhole Principle: If n+1 objects in n holes, at least one hole has 2+ objects

Graph Theory

Graph Properties

  • Handshaking Lemma: Sum of all vertex degrees = 2|E|
  • Complete Graph K_n: Has n(n-1)/2 edges
  • Tree: Connected acyclic graph with n-1 edges (n vertices)
  • Euler Path: Visits every edge exactly once
  • Hamiltonian Path: Visits every vertex exactly once

Graph Types

  • Bipartite: Vertices divided into 2 sets, edges only between sets
  • Complete Bipartite K(m,n): All possible edges between two sets
  • Planar: Can be drawn without edge crossings