Skip to content

Commit 870f2c8

Browse files
committed
Initial commit with parts of the documentation done.
0 parents  commit 870f2c8

24 files changed

+2295
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/
2+
venv/

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line.
5+
SPHINXOPTS =
6+
SPHINXBUILD = sphinx-build
7+
SOURCEDIR = source
8+
BUILDDIR = build
9+
10+
# Put it first so that "make" without argument is like "make help".
11+
help:
12+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
13+
14+
.PHONY: help Makefile
15+
16+
# Catch-all target: route all unknown targets to Sphinx using the new
17+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
18+
%: Makefile
19+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

README.md

Whitespace-only changes.

make.bat

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=source
11+
set BUILDDIR=build
12+
13+
if "%1" == "" goto help
14+
15+
%SPHINXBUILD% >NUL 2>NUL
16+
if errorlevel 9009 (
17+
echo.
18+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19+
echo.installed, then set the SPHINXBUILD environment variable to point
20+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
21+
echo.may add the Sphinx directory to PATH.
22+
echo.
23+
echo.If you don't have Sphinx installed, grab it from
24+
echo.http://sphinx-doc.org/
25+
exit /b 1
26+
)
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
33+
34+
:end
35+
popd

requirements.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
alabaster==0.7.12
2+
Babel==2.6.0
3+
certifi==2018.10.15
4+
chardet==3.0.4
5+
CommonMark==0.5.4
6+
docutils==0.14
7+
idna==2.7
8+
imagesize==1.1.0
9+
Jinja2==2.10
10+
MarkupSafe==1.0
11+
packaging==18.0
12+
purepng==0.2.0
13+
Pygments==2.2.0
14+
pyparsing==2.2.2
15+
pytz==2018.5
16+
recommonmark==0.4.0
17+
requests==2.20.0
18+
rinoh-typeface-dejavuserif==0.1.1
19+
rinoh-typeface-texgyrecursor==0.1.1
20+
rinoh-typeface-texgyreheros==0.1.1
21+
rinoh-typeface-texgyrepagella==0.1.1
22+
rinohtype==0.3.1
23+
six==1.11.0
24+
snowballstemmer==1.2.1
25+
Sphinx==1.8.1
26+
sphinxcontrib-websupport==1.1.0
27+
urllib3==1.24

source/algorithms/deutsch.rst

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
.. highlight:: none
2+
3+
Deutsch's algorithm
4+
===================
5+
6+
Deutsch's algorithm will be our first quantum algorithm to look into.
7+
As will be the style throughout the documentation, we will try to keep the mathematics to
8+
minimum and focus on the implementation.
9+
This doesn't mean that we won't try to understand why and how the algorithm works but
10+
we will seek to only use the mathematics necessary to get us to our goal.
11+
If it is your wish to study the algorithm in depth, references are given at the end of the section.
12+
13+
Here is how this section is organized: first, we will we will set up the problem with all
14+
the information necessary to understand the problem we are trying to solve.
15+
Then we will state the problem and comment on it. Afterwards we shall present a classical
16+
solution to the problem and comment on the solution. Following the classical solution
17+
we will present a quantum solution. Then we shall close with some concluding remarks.
18+
19+
Introduction
20+
------------
21+
22+
Imagine the following: you are given a function :math:`f:\mathbb{B} \to \mathbb{B}`
23+
where :math:`\mathbb{B}=\{0, 1\}`. So this function takes zero or one and returns
24+
zero or one.
25+
26+
What are the possible input/output combinations of this function?
27+
28+
* First combination: :math:`f(0) \to 1` and :math:`f(1) \to 1`.
29+
* Second combination: :math:`f(0) \to 0` and :math:`f(1) \to 1`.
30+
* Third combination: :math:`f(0) \to 1` and :math:`f(1) \to 0`.
31+
* Fourth combination: :math:`f(0) \to 0` and :math:`f(1) \to 0`.
32+
33+
Notice that for the first and the fourth combinations, the output doesn't change
34+
irrespective of the input. The output is constant; hence the function is said to be
35+
constant in both combinations.
36+
The second and the third combinations though are different: the number of zeros in
37+
the output is the same as the number of ones. There is a balance in the output; hence
38+
we call it balanced in both combinations.
39+
40+
.. admonition:: Balanced and constant functions
41+
42+
A function :math:`f:\mathbb{B} \to \mathbb{B}` is said to be constant if :math:`f(0)=f(1)`.
43+
It is said to be balanced if :math:`f(0) \neq f(1)`.
44+
45+
46+
There are lots of interesting questions we can ask about this function (yes, actually a lot).
47+
But here one we are going to try to solve: suppose we are given one of the four combinations
48+
randomly. Without being told which one and being allowed to look inside,
49+
we are asked if it is balanced or constant. This is called Deutsch's problem after David Deutsch
50+
who first proposed a quantum solution to this problem in 1985 (and mind you, his solution worked
51+
only half the time). When we are given a function which implementation we don't know,
52+
we call it a black box or more formally an oracle.
53+
54+
.. admonition:: Deutsch's problem
55+
56+
Let :math:`f:\mathbb{B} \to \mathbb{B}` be an oracle. Is :math:`f` balanced or constant?
57+
58+
59+
One remark though, however obvious, is that we are going to need to call the oracle, pass it
60+
our input(s). Note that nothing is said about reading the output. Read on to find out why.
61+
62+
.. note::
63+
Throughout the section, we are going to assume that we are given combinations as oracles
64+
of the form :math:`f_{i}(n)` for :math:`\forall i \in \{0, 1, 2, 3\}` and :math:`n \in \mathbb{B}`.
65+
66+
Classical solution
67+
------------------
68+
69+
So we are given the oracle, now we need to find out if it is balanced or constant.
70+
As programmers, part our business is finding out how to solve problems efficiently.
71+
Many things may go into the final but right now, we do know that we would like to reduce
72+
the number of times we call the oracle. The more we call it the longer it will take to
73+
make our decision of whether we have a balanced or constant oracle.
74+
75+
So how many times exactly do we need to call the oracle here?
76+
77+
If we call the oracle passing it :math:`0`, the first combination will return :math:`1`.
78+
But the third combination will also return :math:`1`. Note also that the second combination
79+
will return :math:`0` with :math:`0`. So if cannot hope to know if the oracle is balanced
80+
or constant by passing it :math:`0` alone. The same argument applies for :math:`1`.
81+
82+
But note that if we call the oracle with :math:`0` then with :math:`1`, we can make some progress.
83+
If :math:`f(0)=0` and :math:`f(1)=0` are equal then we know the oracle is constant by definition.
84+
The same argument can be used by definition of a balanced function.
85+
86+
So we need to call the oracle once for :math:`f(0)` and once for :math:`f(1)` to solve
87+
the problem. Two calls to the oracle are necessary (we can't make a decision with only one call)
88+
and sufficient (we learn nothing new by a third call).
89+
90+
Here is the classical code that solves Deutsch's problem. You can find it in the ``algorithms`` sections of the language repository.
91+
92+
.. code::
93+
94+
import io
95+
import oracles.classical
96+
97+
98+
def __main__ = (val args : [string]) -> void:
99+
-- step 1 : call the oracle with 0
100+
val left = Oracle.f0(0b0)
101+
102+
-- step 2 : call the oracle again but with 1
103+
val right = Oracle.f0(0b1)
104+
105+
-- step 3 : compare both results to determine if the oracle is constant or balanced
106+
if left == right:
107+
Io.println("The oracle contains a constant function.")
108+
else:
109+
Io.println("The oracle contains a balanced function.")
110+
111+
-- we are done
112+
return
113+
114+
115+

source/conf.py

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Configuration file for the Sphinx documentation builder.
4+
#
5+
# This file does only contain a selection of the most common options. For a
6+
# full list see the documentation:
7+
# http://www.sphinx-doc.org/en/master/config
8+
9+
# -- Path setup --------------------------------------------------------------
10+
11+
# If extensions (or modules to document with autodoc) are in another directory,
12+
# add these directories to sys.path here. If the directory is relative to the
13+
# documentation root, use os.path.abspath to make it absolute, like shown here.
14+
#
15+
# import os
16+
# import sys
17+
# sys.path.insert(0, os.path.abspath('.'))
18+
19+
20+
# -- Project information -----------------------------------------------------
21+
22+
project = 'Avalon Programming Language'
23+
copyright = '2018, Ntwali Bashige'
24+
author = 'Ntwali Bashige'
25+
26+
# The short X.Y version
27+
version = ''
28+
# The full version, including alpha/beta/rc tags
29+
release = '0.0.1'
30+
31+
32+
# -- General configuration ---------------------------------------------------
33+
34+
# If your documentation needs a minimal Sphinx version, state it here.
35+
#
36+
# needs_sphinx = '1.0'
37+
38+
# Add any Sphinx extension module names here, as strings. They can be
39+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
40+
# ones.
41+
extensions = [
42+
'sphinx.ext.intersphinx',
43+
'sphinx.ext.mathjax',
44+
'sphinx.ext.ifconfig',
45+
'sphinx.ext.githubpages',
46+
'rinoh.frontend.sphinx',
47+
]
48+
49+
# Add any paths that contain templates here, relative to this directory.
50+
templates_path = ['_templates']
51+
52+
# The suffix(es) of source filenames.
53+
# You can specify multiple suffix as a list of string:
54+
#
55+
# source_suffix = ['.rst', '.md']
56+
source_suffix = '.rst'
57+
58+
# The master toctree document.
59+
master_doc = 'index'
60+
61+
# The language for content autogenerated by Sphinx. Refer to documentation
62+
# for a list of supported languages.
63+
#
64+
# This is also used if you do content translation via gettext catalogs.
65+
# Usually you set "language" from the command line for these cases.
66+
language = None
67+
68+
# List of patterns, relative to source directory, that match files and
69+
# directories to ignore when looking for source files.
70+
# This pattern also affects html_static_path and html_extra_path.
71+
exclude_patterns = []
72+
73+
# The name of the Pygments (syntax highlighting) style to use.
74+
pygments_style = None
75+
76+
77+
# -- Options for HTML output -------------------------------------------------
78+
79+
# The theme to use for HTML and HTML Help pages. See the documentation for
80+
# a list of builtin themes.
81+
#
82+
html_theme = 'default'
83+
84+
# Theme options are theme-specific and customize the look and feel of a theme
85+
# further. For a list of options available for each theme, see the
86+
# documentation.
87+
#
88+
# html_theme_options = {}
89+
90+
# Add any paths that contain custom static files (such as style sheets) here,
91+
# relative to this directory. They are copied after the builtin static files,
92+
# so a file named "default.css" will overwrite the builtin "default.css".
93+
html_static_path = ['_static']
94+
95+
# Custom sidebar templates, must be a dictionary that maps document names
96+
# to template names.
97+
#
98+
# The default sidebars (for documents that don't match any pattern) are
99+
# defined by theme itself. Builtin themes are using these templates by
100+
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
101+
# 'searchbox.html']``.
102+
#
103+
# html_sidebars = {}
104+
105+
106+
# -- Options for HTMLHelp output ---------------------------------------------
107+
108+
# Output file base name for HTML help builder.
109+
htmlhelp_basename = 'avalon-doc'
110+
111+
112+
# -- Options for LaTeX output ------------------------------------------------
113+
114+
latex_elements = {
115+
# The paper size ('letterpaper' or 'a4paper').
116+
#
117+
'papersize': 'letterpaper',
118+
119+
# The font size ('10pt', '11pt' or '12pt').
120+
#
121+
'pointsize': '10pt',
122+
123+
# Additional stuff for the LaTeX preamble.
124+
#
125+
'preamble': '',
126+
127+
# Latex figure (float) alignment
128+
#
129+
'figure_align': 'htbp',
130+
}
131+
132+
# Grouping the document tree into LaTeX files. List of tuples
133+
# (source start file, target name, title,
134+
# author, documentclass [howto, manual, or own class]).
135+
latex_documents = [
136+
(master_doc, 'avalon-lang.tex', 'Avalon Programming Language Documentation',
137+
'Ntwali Bashige', 'manual'),
138+
]
139+
140+
141+
# -- Options for manual page output ------------------------------------------
142+
143+
# One entry per manual page. List of tuples
144+
# (source start file, name, description, authors, manual section).
145+
man_pages = [
146+
(master_doc, 'avalonprogramminglanguage', 'Avalon Programming Language Documentation',
147+
[author], 1)
148+
]
149+
150+
151+
# -- Options for Texinfo output ----------------------------------------------
152+
153+
# Grouping the document tree into Texinfo files. List of tuples
154+
# (source start file, target name, title, author,
155+
# dir menu entry, description, category)
156+
texinfo_documents = [
157+
(master_doc, 'avalon-lang', 'Avalon Programming Language Documentation',
158+
author, 'avalon-lang', 'One line description of project.',
159+
'Miscellaneous'),
160+
]
161+
162+
163+
# -- Options for Epub output -------------------------------------------------
164+
165+
# Bibliographic Dublin Core info.
166+
epub_title = project
167+
168+
# The unique identifier of the text. This can be a ISBN number
169+
# or the project homepage.
170+
#
171+
# epub_identifier = ''
172+
173+
# A unique identification for the text.
174+
#
175+
# epub_uid = ''
176+
177+
# A list of files that should not be packed into the epub file.
178+
epub_exclude_files = ['search.html']
179+
180+
181+
# -- Extension configuration -------------------------------------------------
182+
183+
# -- Options for intersphinx extension ---------------------------------------
184+
185+
# Example configuration for intersphinx: refer to the Python standard library.
186+
intersphinx_mapping = {'https://docs.python.org/': None}

0 commit comments

Comments
 (0)