DEV Community

Cover image for Exploring Numbers in Programming
Sarah Matta for Tech Talk Augusta

Posted on • Edited on

6 3 3 5 2

Exploring Numbers in Programming

Hi! I’m Sarah.

I am a self-taught programmer with a passion for where math meets programming.

This blog post represents a talk I gave at the inaugural Tech Talk Augusta.

As an introduction to my talks, I like to read the intro to Neil deGrasse Tyson’s Starry Messenger because it is applicable as well as impactful to STEM and it really sets the mood to consume and digest STEM considerations that you're about to hear (or read, in this instance). You can read it here: Starry Messenger

What is STEM? (o゜▽゜)o☆

Science, Technology, Engineering, and Mathematics. STEM builds the communities and realities that we live in. It both reflects on the past and propels us forward.

Today, let's focus on the M in STEM - Mathematics!

You Know More Math Than You Think ╰(°▽°)╯

I have always loved math, but I never progressed as far as I would have liked (and still would like to). I’ve heard many programmers say similar things. People often claim they “don’t know math.”

If you just thought to yourself:

(>﹏<)
“Yep, that’s me”

today I’m going to try to convince you that you know more than you realize.

Number Sense ♪(^∇^*)

What is Number Sense? ヾ(@⌒ー⌒@)ノ

I believe I have “strong number sense.” Number sense is the intuitive understanding of numbers and their relationships. It starts with grasping concepts like:

  • Quantities

  • More & less

  • Bigger & smaller

To understand these concepts is to understand math logic. Understanding math logic is comparable to understanding programming logic.

Math is Logic (~ ̄▽ ̄)~

How many of you know what this symbol is?

\sum

How many of you understand it?

i=1ni2 \sum_{i=1}^{n} i^2

This is Sigma notation, also known as summation. It represents:

  • Performing an operation (right)

  • Starting from a defined lower bound (bottom)

  • Going up to a defined upper bound (top)

  • Incrementing at each step

  • Adding each result to an overall sum

How many of you know what this is?

for (let i = start; i <= end; i++) {
    sum += operation(i);
}
Enter fullscreen mode Exit fullscreen mode

Yes! It’s a for loop.

Guess what? They’re the same! Sigma is a For Loop!

i=14i2 \sum_{i=1}^{4} i^2
i=14i2=12+22+32+42=30 \sum_{i=1}^{4} i^2 = {1}^{2}+{2}^{2}+{3}^{2}+{4}^{2}={30}
for (let i = 1; i <= 4; ++i){
    sum += i*i;
}
Enter fullscreen mode Exit fullscreen mode

Now, how many of you understand Sigma notation?

The Power of Number Sense in Programming (⓿_⓿)

Problem-Solving Foundation ( *︾▽︾)

Good number sense is foundational to problem-solving. And how many of us would call programming problem-solving? 🙋‍♂️

Math teaches logical reasoning and problem-solving skills that are essential in programming. It helps in breaking down complex problems into smaller, manageable parts just like writing a program or debugging code.

A friend once said:

“My high school geometry class is what helped me start to excel at programming. My teacher emphasized proof-based geometry, and it really helped me figure out how to break big problems down into smaller ones.”

Math is Logic, Programming is Logic (〃 ̄︶ ̄)人( ̄︶ ̄〃)

This talk is focused on numbers specifically, so let’s adventure beyond bits and bytes and explore The Numeric Foundation of Programming.

Precision vs. Accuracy: A Computational Perspective

If precision vs accuracy sounds familiar to you, you have probably taken a physics class! 😆

In programming, they have distinct meanings and can have profound implications.

  • Precision refers to the level of detail in a measurement or calculation. Example: the number of decimal places a computation can represent.

  • Accuracy refers to how close a result is to the actual, true value. It’s about correctness, not just detail.

Concept Definition Example
Precision Level of detail in a result 3.1415926535 (high precision, may not be accurate)
Accuracy Closeness to the true value 3.14 (lower precision, but accurate)

Speed vs. Correctness

  • Speed depends on numeric type and computation method.

  • Context determines the right approach.

So what does precision vs. accuracy mean in programming?

Binary vs. Decimal: The Foundations of Numeric Representation ◑﹏◐

Decimal vs. Binary in Csharp

// Decimal vs Binary floating-point comparison

double binaryResult = 0.1 + 0.2;  // 0.30000000000000004 - fast

decimal decimalResult = 0.1m + 0.2m;  // Exactly 0.3 - slow
Enter fullscreen mode Exit fullscreen mode
  • double binaryResult = 0.1 + 0.2; represents precision because it provides many decimal places but isn't exactly accurate. It’s faster but has a small error.

  • decimal decimalResult = 0.1m + 0.2m; represents accuracy because it gives exactly 0.3. It’s slower, but mathematically correct.

Binary Numerical Systems (Base-2)

Binary numbers are the native language of computers, representing data using only two states: 0 and 1. This fundamental representation stems from electronic circuitry's on/off nature.

Decimal Numerical Systems (Base-10)

Decimal numbers represent our natural human counting system, using ten distinct digits (0-9).

Performance Considerations

  • Binary is the most efficient for computer processing.
  • Decimal calculations are precise but the slowest for computer processing.
  • Decimal also requires conversion for computer storage.

Common Use Cases:

Type Used For
Binary Performance-critical computations, game development, memory-constrained environments
Decimal Financial calculations, scientific measurements

Conclusion []~( ̄▽ ̄)~*

Math is deeply embedded in programming. Understanding number sense, precision vs. accuracy, and binary vs. decimal can help programmers write more efficient and effective code.

So the next time you think, “I don’t know math”, remember - you already use it every day in programming!

AWS Q Developer image

Your AI Code Assistant

Ask anything about your entire project, code and get answers and even architecture diagrams. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Start free in your IDE

Top comments (2)

Collapse
 
kelvincode1234 profile image
Precious Kelvin Nwaogu

Maths are also used by programmers to build AI....This is so practical 🤗

Collapse
 
sarahmatta profile image
Sarah Matta

Absolutely! I'm currently reading a preview of a book called Rebels of Reason by John Willis & Derek Lewis. I attended a RAG workshop from John Willis at All Things Open AI conference, he gave out signed copied during the conference.

In it, he says "if you can grasp predictive text, you're halfway to understanding AI. It's not magic. It's math."

You can read about it here linkedin.com/pulse/first-look-rebe...

Image of DataStax

AI Agents Made Easy with Langflow

Connect models, vector stores, memory and other AI building blocks with the click of a button to build and deploy AI-powered agents.

Get started for free

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay