Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
slel opened this issue Dec 7, 2019 · 5 comments
Open

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

slel opened this issue Dec 7, 2019 · 5 comments

Comments

@slel
Copy link
Member

slel commented Dec 7, 2019

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

Requested by Pierre Arnoux.

Wikipedia: https://en.wikipedia.org/wiki/Minkowski's_question-mark_function

Sage-devel discussion: https://groups.google.com/d/topic/sage-devel/uvGKvMQQpws/discussion

Component: number theory

Keywords: continued_fraction

Issue created by migration from https://trac.sagemath.org/ticket/28853

@slel slel added this to the sage-9.0 milestone Dec 7, 2019
@slel
Copy link
Member Author

slel commented Dec 7, 2019

comment:1

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)

@slel

This comment has been minimized.

@slel
Copy link
Member Author

slel commented Dec 7, 2019

comment:2

Sage-devel discussion: https://groups.google.com/d/topic/sage-devel/uvGKvMQQpws/discussion

@embray
Copy link
Contributor

embray commented Jan 6, 2020

comment:3

Ticket retargeted after milestone closed

@embray embray modified the milestones: sage-9.0, sage-9.1 Jan 6, 2020
@mkoeppe
Copy link
Member

mkoeppe commented Apr 14, 2020

comment:4

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.

@mkoeppe mkoeppe modified the milestones: sage-9.1, sage-9.2 Apr 14, 2020
@fchapoton fchapoton removed this from the sage-9.2 milestone Jun 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants