## Married functions

On Gödel Escher Bach, on page 137 there are two “married” functions defined:

for n >= 1:

F(n) = n – M(F(n – 1))

M(n) = n – F(M(n – 1))

for n = 0:

F(0) = 1, M(0) = 0

I wondered whether it is easy to define three function that increase their value every time n is increased by three, using only addition, subtracting and recursive calls to the previous value of the functions. It turns out it is not too hard to find some.

for n >= 1

F(n) = n – M(n – 1) – N(F(n – 1) + M(n – 1) + N(n – 1) – 2)

M(n) = F(n – 1)

N(n) = M(n – 1)

for n = 0:

F(0) = 1, M(0) = 0, N(0) = 0

## Reverse recursively single linked list

There are two main ways to reverse a linked list: iteratively and recursively. I find the recursive solution easier to understand and cleaner. Unfortunately, I didn’t find any examples with tail recursion in the top results that I looked at, so I list my approach.

If someone wants to try their own approach, they can try on:

https://leetcode.com/problems/reverse-linked-list/

## On marginalization

“I can’t bear to hear a human being spoken of with contempt just because of his group identification-even by other human beings. It’s these respectable people here who create those hooligans out there.”

The quote is from Dors from “Prelude to foundation” by Isaac Asimov.

“These respectable people here” refers to the snobbish class of people who made these comments. The “hooligans out there” refers to the marginalized part of the community who has developed violent behaviour.

## Russell’s paradox

Let A be any set. We define B such as:

Can it be that ? No.

Proof by contradiction.

Assume .

- If then by the definition of B:

. Contradiction. - If then by the definition of B:

. Contradiction.

Therefore .

## Some notes on Decision Theory

Once upon a time, I took a course in Decision Theory at ETH. Here are some notes:

normative theory vs descriptive theory (maths vs psychology)

prospect theory

options vs choices

money pump

bond vs shares

Main notions:

- Slide
- Normative: Perfect rationality, optimality, payoff maximality
- Descriptive: How real people think and make decisions.
- bias: persistent and systematic deviation from rationality

- Prescriptive: How can we help people to make better decisions. How can we structure the choice environment to minimize decision errors and biases.
- People use limited heuristics in making decisions
- Decision maker
- individual, couple, family, firm, country
- any monolithic cognitive agent

- Goals, preferences, wants, desires
- options, alternatives, courses of action
- beliefs
- Decision under
- certainty
- all options and outcomes are completely known to the DM (military diet, ups example)

- risk
- When all the choices and options are known but there are well defined stochastic nodes (gambling, insurance, investing)

- uncertainty
- options are not well defined, or probabilities are not defined (or both) (examples most of life)

- certainty
- Preferences
- Revealed, Complete, Transitive, Independent, Stable

- People often satisfice instead of optimize
- People guess, estimate and try to do “well enough’’ rather than optimally.
- Rationality is bounded in two ways.
- Information from the environment
- cognitive capacity

- Sometimes close enough is fine, sometimes not
- Cognitive illusions: Monty hall problem
- Limitations in attention and memory. There are tools which compensate for that.
- Multi Attribute Evaluation (MAUT)
- identify options
- define goals
- quantify subjective evaluations
- weight and scale different evaluations so they can be aggregated meaningfully.
- make reasonable and justifiable decisions

- Problem, Objectives, Alternatives, Consequences, Tradeoffs (PrOACT)
- Comparative, multiple stakeholders (probably not equally important), multiple goals (maybe not equally important), multiple choices with multiple attibutes, judgements are necessary, quantify!
- Identify the decision maker
- Identify the alternatives
- the relevant attributes
- assign values to the attributes of each alternatives
- determine a weight for each attribute
- for each alternative, compute a weighted mean
- make a provisional decision
- get feedback and run a sensitivity analysis

- compensatory vs noncompensatory
- sometimes some alternatives are not acceptable (minimum requirements)

- minor changes may cause a change in the resulting decision
- “fair’’ method and easy to develop political support
- analytic hierarchy process: binary comparison of pairs of attributes in terms of their importance and then assign a weight (how much better is on alternative compared to the other)
- built in check for transitivity and consistency
- a well defined process to turn subjective judgements into more objective ratings

- Secretary problem
- What makes a good decision (good outcome or good reasons?)
- expected value
- probability (classical, frequency, subjective)
- it can be hard for people to reason about probabilities correctly (monty hall, other pitfalls)
- birthday problem
- bayes rule
- st petersburg gamble
- Moral worth: Bernoulli: the worth of something is not the same as its value → Definition of utility (utility = value^a)
- Expected utility does not work always
- Allais gambles. The result is a contradiction to EUT.
- Feelings about risk: People will accept 1000 times greater risks if they are their own volition, rather than involuntary
- O.J. SImpson example
- People are generally risk averse, but to varying degrees
- EVT defines rationality if the goal of the DM is to maximize value in the long run
- EUT defines rationality if the goal of the DM is to maximize utility (moral worth) in the long run
- Risk seeking in the domain of losses, risk averse in the domain of gains
- Decision framing
- Money trump

- Sequential investment problem
- Persistent cognitive noise
- systematic departures from EUT – biases
- Friedman-Savage utility function
- Prospect theory
- descriptive account of decision theory under risk
- aims to account for systematic deviations from eut and evt
- Coding — outcomes relative to the current state in terms of gains and losses
- combination — joining similar prospects
- segregation — isolation of sure things
- cancellation — discarding shared components
- simplification — rounding
- elimination of dominated options

- probability weighting function — the estimation that people do on probabilities (magnification of small values in the expense of larger values)
- 4 fold pattern of risk preferences
- risk seeking over low p gains — lotteries
- risk averse over low p losses — insurance
- risk averse over high p losses — certainty effect
- risk seeking over high p losses — end of the day effect

- certainty effect
- insurance which does not pay with a very small probability

- end of the day effect
- people make large bets on the last day to “break even’’

- Shortcomings
- average choices on average
- not for every one
- not even for someone over the domain of time
- no insight — just better predictions
- does not scale. (portfolio example, mulistage risky decisions)

- Dynamic decision contexts are defined by:
- sequential choices are made and they are interspersed with updated information about the environment
- the decision environment changes over time (depending on the choices of DM)

- normative approaches
- maximize expected payoff
- dynamic programming

- descriptive approaches
- case studies
- experimental methods (behavioral laboratories)
- human behaviour is compared to the normative approach
- identification of systematic departures from optimality — existent cognitive mechanisms can be accounted for
- ⇒ people predictably irrational (underlying assumption)

- optimal stopping
- example: secretary problem
- target: select a maximum value
- full information games
- perfectly known distribution
- draw a number from [0,20] — given the relative order of the number that you encountered so far but not the number

- partial information
- known distribution but not its parameters
- german tank problem

- no information
- iid random variables with unknown distribution
- secretary problem
- Sometimes called the Sultan’s Dowry Problem, the Marriage Problem, or the Fussy Suitor Problem
- optimal decision policy — threshold (e^{-1})
- generalized secretary problem
- persistent bias for stopping too soon
- probability distortion and not risk aversion is the (assumed) answer

- Other dynamic decision problem
- sell a good over a time interval where offers in a specific range arrive with a probability

- Kelly criterion
- always bet the same proportion (2p – 1)
- maximizes the expected geometric mean
- poor criterion in prediction decision makers behavior
- people have strong urge to adjust their investments
- evidence of learning to adjust less over rounds
- if we charge people when they adjust, we help them

- sequential investment problem
- optimal policy: bet max or not according to whether we are “above or below the expectation’’

- Heuristics as rule of thumb.
- gambler’s fallacy (law of small numbers)
- hot hand fallacy (law of small numbers)
- stars
- availability heuristics (how easy it is to recall a piece of information)
- anchoring and adjustment
- factorial where presented the larger number first or last
- use of early values to predict

- framing effect (the influence of questions)
- confirmation bias
- are people really irrational — heuristics evolved for some reason. Carefully designed corner case are examined.

- public goods game
- selfish players take no interest
- social optimal is far off
- many people are pro-social
- design vector according to the answers

- overconfidence quiz
- attentional
- selective memory/information search: confirmation bias
- selective encoding: excuses/rationalizations
- selective encoding : rewarded events are remembered better

- motivational
- need to appear competent and confident to tothers and oneself. confidence and optimism help to get things done.

- attentional

- bordeaux and regression
- wisdom of crowds
- risky decision theory
**and gambling** - rush of winning
- highly reinforcing

## Hofstadter sequence

On the book Gödel, Escher, Bach: an Eternal Golden Braid, on Chapter III page 73 there is a puzzle on a sequence of numbers:

1 3 7 12 18 26 35 45 56 69 …

The puzzle is about characterising the sequence of numbers, that is, coming up with a way to find the next number of the sequence. You may want to try it yourself before reading the rest of the post.

The section of the chapter where this puzzle belongs talks about Recursive Enumerable Sets vs Recursive Sets. The main point of the chapter is that:

There exist formal systems whose set of non-theorems is not the set of theorems of any formal system.

When the author presents the puzzle, he calls for some reflection on the chapter in order to find a formula that describes the sequence.

Trying to solve that, I started observing the differences between subsequent numbers, which in our case is

2 4 5 6 8 9 10 11 13

And then again I looked at the differences of between those numbers

2 1 1 2 1 1 1 2

Now, this sequence rings a bell. The notes in music have differences in tones and semitones:

si (1/2) do (1/1) re (1/1) mi (1/2) fa (1/1) sol (1/1) la (1/1) si

where 1/2 represents a semitone and 1/1 represents a tone.

If we look carefully, we notice that the last sequence of differences that we found is the same one as the one in tones and semitones where the fractions are reversed.

I thought this could be a solution since one of the main topics of the book is the interplay of music and maths. On the other hand, the discussion on the chapter was not used. By looking up the description of the sequence on the web, I found the Hofstadter sequence. Looking at the sequence, I had doubts that I had found an equivalent definition.

Finally, a simple Python script to check whether the two sequences are the same.

Apparently, they are not equivalent. Moreover, we don’t even know whether the Hofstandter sequence is defined for all n.

Nevertheless, the beginning of the sequence presents a funny coincidence and writing the Python code to check the non-equivalence of the two sequences made me appreciate even more the power of generators in Python.

## On diversity

“The people of the Settlements select themselves. They select people like themselves. There’s a shared culture, even, to some extent, a shared physical appearance on each Settlement. Earth, on the other hand, is, and through all of history has been, a wild mixture of cultures, all enriching each other, competing with each other, suspicious of each other. Tanayama and many other Earthmen– myself, for instance–consider such a mixture to be a source of strength, and feel that cultural homogeneity on the Settlements weakens them and, in the long run, shortens their potential life span.”

From the book Nemesis by Asimov, page 123.