Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Math Every Programmer Needs

The Math Every Programmer Needs

This talk was given at RailsConf 2023

Leave your fear of math behind along with the equations and symbols, we're headed to Ruby-land! On this whirlwind tour, we’ll explore how to write better conditionals with Boolean algebra, figure out how many test cases we need with combinatorics, a mental model for breaking down large tasks with graph theory, and more.

You’ll leave this talk equipped to better do your job with some ideas, techniques, and mental models from the wonderfully practical world of discrete math.

Joël Quenneville

April 24, 2023
Tweet

More Decks by Joël Quenneville

Other Decks in Technology

Transcript

  1. Truth Table owner? admin? can_edit_admin_post? true true true true false

    true false true true false false false owner? || admin? true true true false
  2. Individual negation signed_out? untrusted_ip? Correct true true false true false

    true false true true false false true individual negation false false false true
  3. DeMorgan signed_out? untrusted_ip? Correct true true false true false true

    false true true false false true DeMorgan false true true true
  4. describe "#can_read?" do it "allows admin to access public article"

    it "allows admin to access private article" it "allows non-admin to access public article" it "disallows non-admin from accessing private article" end Enough tests?
  5. Modified truth table Article is public? User is admin? Can

    read? true true true true false true false true true false false false nil true true nil false false
  6. describe User do let(:organization) { create(:organization) } let(:user) { create(:user,

    organization: organization) } let!(:admin) { create(:user, admin: true, organization: organization) } # lots of other tests describe "Invoices" do let(:product) { create(:product) } let(:invoice) { create(:invoice, owner: user, items: [product] } it "is complete" do expect(invoice).to be_complete end it "is an active product" do expect(product).to be_active end end end
  7. Ideas from Discrete Math Break cycles in your dependency graphs

    Compound states multiply DeMorgan laws Truth tables Use Boolean operators Evaluate dependency graph bottom- up Evaluating a graph node requires evaluating downstream nodes