Skip to content

Latest commit

 

History

History
51 lines (34 loc) · 1.75 KB

mlwp_solutions.md

File metadata and controls

51 lines (34 loc) · 1.75 KB

author: niplav, created: 2024-09-26, modified: 2024-09-29, language: english, status: in progress, importance: 2, confidence: likely

.

Solutions to “ML For The Working Programmer”

Chapter 2

2.1

Done.

2.2

Reasons for treating reals and integers as different:

  1. Speed. Knowing that a variable is an integer can allow compiler-writers to write compilers that produce faster programs.
  2. No access to the reals. The reals are, ah, unreal. Almost all are uncomputable, many computable ones are better conceived of as functions, not numbers—pi, or Euler's constant, or whatever, are never stored anywhere fully, we just have access to some digits by executing the function.
  3. Approximation through floating points is meh. 32-bit floating point numbers actually can't represent some integers above ~10⁷.

Reasons for treating reals and reals (in this case probably floating point numbers or arbitrary-precision rational numbers) as the same:

  1. Convience.
  2. Ease of learning.
  3. Elegance.

I think that scripting languages can treat them as the same by default by now (given our Moorean utopia), but anything that wants to be used in product needs to give users the option to specify the type, and optimize accordingly.

2.3

  • double: No, since 2 is clearly not a real.
  • f: No, since Math.sin is only defined for reals.
  • g: Yes.

2.4

Prediction: Error messages for both ~1 and 10.

Result: Uncaught exception. Close enough.