Opened 22 months ago

# Provide Minkowski's question mark function and Conway's box function

Reported by: Owned by: slelievre major sage-wishlist number theory continued_fraction N/A

This is to provide Minkowski's question mark function and Conway's box function.

Requested by Pierre Arnoux.

### comment:1 Changed 22 months ago by slelievre

Tentative implementation for Minkowski's question mark function:

```def mqm(x):
r"""
Minkowski's question-mark function.

Reference: :wikipedia:`Minkowski's_question-mark_function`.
"""
c = list(continued_fraction(x)[:30])
res = c[0]
aa = c[1:]
s = 2.
for a in aa:
s = (-s) >> a
res -= s
return res
```

and for Conway's box function:

```def box(x):
r"""
Conway's box function.

Reference: :wikipedia:`Minkowski's_question-mark_function`.
"""
aa = [floor(x)]
s = (RR(x - aa[0])/2).str(base=2)[2:]
if 'e-' in s:
s, e = s.split('e-')
s = '0' * (int(e)-1) + '1' + s
y = [int(i) for i in s]
d = 1
while y and any(y):
try:
a = y.index(d)
except ValueError:
a = len(y)
aa.append(a)
y = y[a:]
d = 1 - d
return RR(continued_fraction(aa))
```

Plots of these two functions and their compositions:

```plots = [
plot(lambda x: mqm(x), (0, 1), aspect_ratio=1),
plot(lambda x: box(x), (0, 1), aspect_ratio=1),
plot(lambda x: mqm(box(x)), (0, 1), aspect_ratio=1),
plot(lambda x: box(mqm(x)), (0, 1), aspect_ratio=1),
]
graphics_array(plots, ncols=2)
```

### comment:2 Changed 22 months ago by slelievre

• Description modified (diff)

### comment:3 Changed 21 months ago by embray

• Milestone changed from sage-9.0 to sage-9.1

Ticket retargeted after milestone closed

### comment:4 Changed 17 months ago by mkoeppe

• Milestone changed from sage-9.1 to sage-9.2

Batch modifying tickets that will likely not be ready for 9.1, based on a review of the ticket title, branch/review status, and last modification date.

### comment:5 Changed 15 months ago by chapoton

• Milestone changed from sage-9.2 to sage-wishlist
Note: See TracTickets for help on using tickets.