{ "cells": [ { "cell_type": "markdown", "id": "674e5388", "metadata": {}, "source": [ "# Representing Data (OUTLINE)\n", "\n", "> **Status: outline only.** No prose written, no exercises written. This file exists to\n", "> pin down scope, vocabulary, and standards claims before any drafting happens.\n", "> Delete this block when the chapter is real.\n", "\n", "**Placement:** after Chapter 7 (Iteration and Search), before Chapter 8.\n", "**Slot:** one week. Not a Monday insert; this is bigger than 6b.\n", "**Prerequisites used:** iteration and string traversal (ch7), return values (ch6),\n", "recursion (ch5), docstrings and doctests (6b), `//` and `%` (ch1).\n", "\n", "**Why it exists:** AP topics 2.1 and 2.2 and CA DA.8 and DA.9 currently have no carrier\n", "anywhere in the course. Big Idea 2 is 17 to 22% of the multiple choice, and 20 of its 22\n", "vocabulary terms are unmet. This chapter closes the representation half. The analysis half\n", "(2.3, 2.4) stays with chapters 12 and 13.\n", "\n", "**Why after 7 and not earlier:** run-length encoding needs iteration over a string. Placing\n", "this earlier splits the block in two and orphans the compression code." ] }, { "cell_type": "markdown", "id": "b69e15ad", "metadata": {}, "source": [ "## What this chapter covers\n", "\n", "### 1. Everything is bits\n", "- One physical thing, two states. Why two and not ten\n", "- The same bits mean different things depending on what you claim they are\n", "- **Terms:** bit, byte, binary, digital data\n", "\n", "### 2. Place value, base 2\n", "- Base 10 as a system of powers, not as \"the way numbers are\"\n", "- Base 2 as the identical system with a different base\n", "- Reading a byte: 8 bits, 0 to 255, and where 255 comes from\n", "- **Terms:** binary, decimal, place value\n", "- *Watch:* this is the section where math-anxious students disengage. Anchor it in\n", " odometers and place value they already own, not in arithmetic drills\n", "\n", "### 3. Conversion, by hand and in code\n", "- Decimal to binary: repeated division by 2, collecting remainders\n", "- Binary to decimal: sum of powers\n", "- Built-ins: `bin()`, `int(s, 2)`, `format()`\n", "- **Code:** `to_binary(n)` and `from_binary(s)`, written by students\n", "- **Code:** the round trip as a doctest. `from_binary(to_binary(37))` returns `37`.\n", " First time students write a test whose expected value they did not compute by hand\n", "- *Optional:* recursive `to_binary`, since repeated division is a natural recursion\n", "\n", "### 4. Hexadecimal as shorthand\n", "- Four bits per digit, so one byte is exactly two hex digits\n", "- Where they'll actually meet it: color codes, I2C addresses in the Pico unit, ROS2 later\n", "- **Terms:** hexadecimal\n", "- *Scope note:* teach as notation, not as an exam topic. The Pico I2C chapter is the\n", " place where it earns its keep\n", "\n", "### 5. Bits as text\n", "- ASCII: a table, nothing more\n", "- `ord()` and `chr()`\n", "- Unicode and why 128 characters stopped being enough\n", "- **Terms:** ASCII, Unicode, character encoding\n", "- *Hook:* the mojibake demo. Text that \"looks broken\" is bits read with the wrong claim\n", "\n", "### 6. Bits as color\n", "- RGB, three bytes, 0 to 255 each\n", "- Hex color codes as the same three bytes in the notation from section 4\n", "- **Terms:** RGB, pixel\n", "\n", "### 7. Analog and digital\n", "- Continuous versus discrete. Sound and light are analog; storage is not\n", "- **Sampling:** rate and bit depth as two separate knobs\n", "- *Watch:* students think only about rate. Bit depth needs its own example\n", "- Why no sample is ever the whole signal\n", "- **Terms:** analog data, digital data, sampling\n", "- *Teach as a contrast pair.* Individually these definitions are near-empty\n", "\n", "### 8. When the bits run out\n", "- **Overflow:** a value too large for the bits available\n", "- Python hides this. Integers are arbitrary precision, so overflow needs a deliberate\n", " demo. Fixed-width arithmetic, a hand-rolled 8-bit adder, or the Pico\n", "- **Roundoff:** revisit `0.1 + 0.2` from Chapter 1 and the forward reference from 6b\n", "- **Terms:** overflow error, roundoff error\n", "- *Scope note:* DAT-1.B.3 puts specific range limits for real numbers **out of scope**.\n", " Explain the cause, do not drill the ranges\n", "\n", "### 9. Compression\n", "- The idea: fewer bits, same or nearly the same meaning\n", "- **Lossless:** run-length encoding, built and tested by students\n", "- **Code:** `rle_encode(s)` and `rle_decode(s)`, round-trip tested\n", "- **The case that matters:** input where RLE makes the output *larger*. This is the\n", " insight the exam actually tests\n", "- **Lossy:** what JPEG and MP3 throw away, and why you cannot get it back\n", "- Choosing between them: the exam tests the choice, not the definitions\n", "- **Terms:** lossless compression, lossy compression, compression ratio\n", "\n", "### 10. Debugging\n", "- Errors of *interpretation*: right bits, wrong claim about what they mean\n", "- Off-by-one in place value. The `2**n` versus `2**(n-1)` mistake\n", "- Round-trip tests as the tool that catches encoding bugs the eye cannot" ] }, { "cell_type": "markdown", "id": "c84a7418", "metadata": {}, "source": [ "## Deliberately not here\n", "\n", "| Topic | Where instead | Why |\n", "|---|---|---|\n", "| **Metadata** | *Little Brother* | EXIF is simultaneously DAT-2.B and the surveillance thread. Free coverage on both sides |\n", "| **Data cleaning, correlation, data sets, information** | Chapters 12, 13 | Topic 2.3, already carried |\n", "| **Data visualization** | still unassigned | CA DA.10, no plotting anywhere in the course. Not this chapter's job, but do not lose track of it |\n", "| **Bitwise operators** | nowhere yet | Not an AP topic. May earn a place in the robotics unit |\n", "| **Two's complement** | nowhere | Beyond scope, and Python hides it completely |\n", "| **Floating-point layout** | nowhere | DAT-1.B.3 explicitly excludes real-number range limits |" ] }, { "cell_type": "markdown", "id": "0c2f1ad0", "metadata": {}, "source": [ "\n", "## Glossary\n", "\n", "Terms this chapter claims. AP tier in brackets: **F** foundational, **C** needs\n", "instruction time, **L** low priority. Terms marked ★ are high-frequency on released\n", "exam items.\n", "\n", "**bit** *[F]*: A single binary digit, 0 or 1.\n", "\n", "**byte** *[F]*: Eight bits. Enough to hold one of 256 values.\n", "\n", "**binary** *[L, ★]*: Base-2 representation, using only the digits 0 and 1.\n", "\n", "**decimal** *[F]*: Base-10, the system you already use.\n", "\n", "**hexadecimal** *[F]*: Base-16, using 0 through 9 and A through F. Four bits per digit,\n", "so one byte is exactly two hex digits.\n", "\n", "**digital data** *[C]*: Values represented in discrete steps, ultimately as bits.\n", "\n", "**analog data** *[C]*: Values that vary continuously and smoothly, with no steps.\n", "\n", "**sampling** *[C]*: Approximating an analog signal by measuring it at regular intervals.\n", "Two independent settings: how often you measure (rate) and how precisely you record each\n", "measurement (bit depth).\n", "\n", "**ASCII** *[F]*: A table assigning a number from 0 to 127 to each of a small set of\n", "characters.\n", "\n", "**Unicode** *[F]*: A far larger table, covering the writing systems ASCII left out.\n", "\n", "**character encoding** *[C]*: The agreement about which numbers stand for which\n", "characters. Read bits with the wrong encoding and you get the right data as the wrong\n", "text.\n", "\n", "**RGB** *[F]*: Color stored as three numbers, the amounts of red, green, and blue, each\n", "usually one byte.\n", "\n", "**overflow error** *[C]*: An error that happens when a value is too large for the number\n", "of bits available to hold it.\n", "\n", "**roundoff error** *[C]*: A loss of precision that happens because a fixed number of bits\n", "cannot represent some numbers exactly.\n", "\n", "**lossless compression** *[C, ★]*: Reduces size while allowing the original to be\n", "reconstructed exactly.\n", "\n", "**lossy compression** *[C, ★]*: Reduces size further, but only an approximation of the\n", "original can be recovered.\n", "\n", "**compression ratio** *[--]*: Compressed size divided by original size. *(Ours, not exam\n", "vocabulary. Included because it makes the lossless/lossy tradeoff measurable rather than\n", "verbal.)*\n", "\n", "**run-length encoding** *[--]*: A lossless scheme that replaces runs of a repeated value\n", "with the value and a count. *(Ours. The exam names no specific algorithm.)*\n", "\n", "\n", "" ] }, { "cell_type": "markdown", "id": "deea027a", "metadata": {}, "source": [ "\n", "**See also:** the [full vocabulary glossary](https://python.porttack.com/alignment/ap-vocabulary-glossary.html) collects every term in this book, alphabetized, alongside the complete AP CSP exam vocabulary list.\n", "" ] }, { "cell_type": "markdown", "id": "b6243edf", "metadata": {}, "source": [ "## Vocabulary load\n", "\n", "Fifteen to seventeen new terms in one week, which is the largest single-chapter\n", "vocabulary load in the course.\n", "\n", "Three mitigations, all built into the section order above:\n", "\n", "1. **Contrast pairs.** analog/digital, lossless/lossy, bit/byte, overflow/roundoff. Eight\n", " terms taught as four ideas.\n", "2. **Notation terms carry themselves.** binary, decimal, hexadecimal, ASCII, RGB are all\n", " \"here is a table, here is how to read it.\" They need exposure, not instruction time.\n", "3. **Defer the quiz.** Put these on the following Monday's entry quiz, not the same\n", " week's.\n", "\n", "The terms that genuinely need instruction time, and where the period actually goes:\n", "**sampling** (two knobs, not one), **lossless versus lossy** (the choice, not the\n", "definitions), and **overflow** (which Python actively hides)." ] }, { "cell_type": "markdown", "id": "976c091a", "metadata": {}, "source": [ "\n", "---\n", "\n", "## Standards alignment\n", "\n", "**AP CSP:** 2.1 Binary Numbers, 2.2 Data Compression. Big Idea 2, 17-22% of the exam\n", "**California 9-12:** 9-12.DA.8, 9-12.DA.9\n", "**CSTA 2026:** *(TBD)*\n", "**CA CTE (ICT):** *(TBD)*\n", "\n", "**Exclusion to respect:** DAT-1.B.3 puts specific range limitations for real numbers\n", "outside course and exam scope. Explain why roundoff happens; do not drill float ranges.\n", "\n", "\n", "" ] }, { "cell_type": "markdown", "id": "c78f6c8b", "metadata": {}, "source": [ "## Open questions before drafting\n", "\n", "1. **Overflow demo.** Python won't overflow natively. Options: simulate fixed width with\n", " masking, build an 8-bit adder by hand, or borrow the Pico. The masking version is the\n", " least motivated and the Pico version is the most, but the Pico version means this\n", " chapter depends on hardware being available in the fall.\n", "2. **Does this chapter get exercises in the notebook, or a separate problem set?** It is\n", " part concept and part code, and the concept half does not fit the notebook exercise\n", " format well. Possibly notebook exercises for sections 3 and 9, written response\n", " elsewhere.\n", "3. **Sound or image for the sampling demo?** Sound is more intuitive and needs audio in\n", " the classroom. Image is easier to show in a notebook and connects to section 6.\n", "4. **Time.** One week is the assumption. Ten sections is a lot for one week, and sections\n", " 1 and 2 may collapse into one. Worth cutting to fit before drafting rather than after.\n", "5. **Chapter number.** `7b` follows the `6b` convention, but `check_sync.py` and the\n", " build scripts assume numeric chapter names. Confirm 6b's fix covers this before\n", " adding a second non-numeric chapter." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }