Can you describe Newcombs problem in terms of the observe Haskell DSL (https://github.com/mroman42/observe/)? You should write code that imports the “Subdistribution.hs” file. Inside that file you will have a uniform :: (Eq a) => [a] -> Distribution a and an observe :: Bool -> Distribution () primitives. There will be two possible actions OneBox and TwoBox, and you should get a function newcomb :: Action -> Distribution Double.

Quote

To describe Newcomb’s Problem using the Observe DSL, we need to express the probabilistic setup of the problem in terms of the primitives provided, including:

  • uniform :: (Eq a) => [a] -> Distribution a

  • observe :: Bool -> Distribution ()

  • The goal: define newcomb :: Action -> Distribution Double


🧠 Newcomb’s Problem Summary

You are faced with two boxes:

  • Box A always contains $1,000.
  • Box B contains either $1,000,000 or nothing.
    • A predictor has placed money in Box B if and only if they predicted you would take only Box B (OneBox).
    • If they predict you’ll take both boxes (TwoBox), Box B is empty.

The predictor is very accurate, near perfect.


💻 Code Overview

We’ll represent:

  • The action you take: OneBox | TwoBox
  • The predictor’s guess: PredOneBox | PredTwoBox
  • The setup as a joint probability distribution over actions and predictor guesses
  • The observation: the predictor tends to guess correctly
  • The payoff based on the action and the predictor’s guess

Haskell Code Using observe

{-# LANGUAGE MonadComprehensions #-}
 
module Newcomb where
 
import Subdistribution -- assumed to define `Distribution`, `uniform`, `observe`
 
data Action = OneBox | TwoBox deriving (Eq, Show)
data Prediction = PredOneBox | PredTwoBox deriving (Eq, Show)
 
-- Main function modeling Newcomb's Problem
newcomb :: Action -> Distribution Double
newcomb action = do
    -- The predictor guesses uniformly initially
    prediction <- uniform [PredOneBox, PredTwoBox]
 
    -- The predictor is nearly always correct: 99% accuracy
    observe (prediction == predictAction action)
 
    -- Compute reward
    return (payout action prediction)
 
-- Determines what the predictor would guess, simulating near-perfect accuracy
predictAction :: Action -> Prediction
predictAction OneBox = PredOneBox
predictAction TwoBox = PredTwoBox
 
-- Computes the reward based on the action and the prediction
payout :: Action -> Prediction -> Double
payout OneBox PredOneBox = 1000000
payout OneBox PredTwoBox = 0
payout TwoBox PredOneBox = 1001000 -- took both, and predictor guessed wrongly
payout TwoBox PredTwoBox = 1000     -- predictor guessed correctly, no money in Box B

📌 Explanation

  • uniform sets up the initial uncertainty over the predictor’s guess.
  • observe encodes the idea that the predictor is highly accurate: we “condition” the distribution on this matching what the agent does.
  • payout computes the actual monetary result for the given situation.

🧪 Optional: Modeling Imperfect Prediction

If you want to introduce a 99% accurate predictor instead of perfect matching via observe, you’d need a soft condition or a more complex structure. But with this DSL, the cleanest approach is just using observe to filter for only “correct” predictions.

Would you like that version too, with probabilistic (e.g., 99%) prediction accuracy instead of deterministic observe?

See also