Skip to content

Commit 7e73efd

Browse files
wip code dump
1 parent 5b724ff commit 7e73efd

File tree

14 files changed

+2412
-12
lines changed

14 files changed

+2412
-12
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ __pycache__
33
*.pyc
44
*.egg-info
55
dist/*
6+
.ipynb_checkpoints
7+
*.ipynb
8+
doc/build/*

doc/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
SPHINXPROJ = pygrim
8+
SOURCEDIR = source
9+
BUILDDIR = build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

doc/source/_static/default.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@import url("classic.css");
2+
3+
div.body {
4+
min-width: 450px;
5+
max-width: 100%;
6+
}
7+

doc/source/algebraic.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Algebraic numbers backend
2+
=============================================
3+
4+
.. automodule:: pygrim.algebraic
5+
:members:
6+

doc/source/brain.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Brain for symbolic computation
2+
=============================================
3+
4+
.. automodule:: pygrim.brain
5+
:members:
6+

doc/source/conf.py

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
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/stable/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 = u'pygrim'
23+
copyright = u'2020, Fredrik Johansson'
24+
author = u'Fredrik Johansson'
25+
26+
# The short X.Y version
27+
version = u''
28+
# The full version, including alpha/beta/rc tags
29+
release = u''
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.autodoc',
43+
'sphinx.ext.doctest',
44+
'sphinx.ext.intersphinx',
45+
'sphinx.ext.mathjax',
46+
'sphinx.ext.viewcode',
47+
]
48+
49+
default_role = 'math'
50+
51+
# Add any paths that contain templates here, relative to this directory.
52+
templates_path = ['_templates']
53+
54+
# The suffix(es) of source filenames.
55+
# You can specify multiple suffix as a list of string:
56+
#
57+
# source_suffix = ['.rst', '.md']
58+
source_suffix = '.rst'
59+
60+
# The master toctree document.
61+
master_doc = 'index'
62+
63+
# The language for content autogenerated by Sphinx. Refer to documentation
64+
# for a list of supported languages.
65+
#
66+
# This is also used if you do content translation via gettext catalogs.
67+
# Usually you set "language" from the command line for these cases.
68+
language = None
69+
70+
# List of patterns, relative to source directory, that match files and
71+
# directories to ignore when looking for source files.
72+
# This pattern also affects html_static_path and html_extra_path .
73+
exclude_patterns = []
74+
75+
# The name of the Pygments (syntax highlighting) style to use.
76+
pygments_style = 'sphinx'
77+
78+
79+
# -- Options for HTML output -------------------------------------------------
80+
81+
# The theme to use for HTML and HTML Help pages. See the documentation for
82+
# a list of builtin themes.
83+
#
84+
html_theme = 'default'
85+
86+
html_context = {
87+
'css_files': ['_static/default.css'],
88+
}
89+
90+
# Theme options are theme-specific and customize the look and feel of a theme
91+
# further. For a list of options available for each theme, see the
92+
# documentation.
93+
#
94+
95+
html_theme_options = {
96+
'sidebarwidth' : 280,
97+
'collapsiblesidebar': True,
98+
'bodyfont': "'arial', sans-serif",
99+
'headfont': "'arial', sans-serif",
100+
'sidebarbtncolor': '#666',
101+
'sidebarbgcolor': '#444',
102+
'sidebarlinkcolor': '#ddd',
103+
'relbarbgcolor': '#333',
104+
'footerbgcolor': '#333',
105+
'headbgcolor': '#fff',
106+
}
107+
108+
# Add any paths that contain custom static files (such as style sheets) here,
109+
# relative to this directory. They are copied after the builtin static files,
110+
# so a file named "default.css" will overwrite the builtin "default.css".
111+
html_static_path = ['_static']
112+
113+
# Custom sidebar templates, must be a dictionary that maps document names
114+
# to template names.
115+
#
116+
# The default sidebars (for documents that don't match any pattern) are
117+
# defined by theme itself. Builtin themes are using these templates by
118+
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
119+
# 'searchbox.html']``.
120+
#
121+
# html_sidebars = {}
122+
123+
124+
# -- Options for HTMLHelp output ---------------------------------------------
125+
126+
# Output file base name for HTML help builder.
127+
htmlhelp_basename = 'pygrimdoc'
128+
129+
130+
# -- Options for LaTeX output ------------------------------------------------
131+
132+
latex_elements = {
133+
# The paper size ('letterpaper' or 'a4paper').
134+
#
135+
# 'papersize': 'letterpaper',
136+
137+
# The font size ('10pt', '11pt' or '12pt').
138+
#
139+
# 'pointsize': '10pt',
140+
141+
# Additional stuff for the LaTeX preamble.
142+
#
143+
# 'preamble': '',
144+
145+
# Latex figure (float) alignment
146+
#
147+
# 'figure_align': 'htbp',
148+
}
149+
150+
# Grouping the document tree into LaTeX files. List of tuples
151+
# (source start file, target name, title,
152+
# author, documentclass [howto, manual, or own class]).
153+
latex_documents = [
154+
(master_doc, 'pygrim.tex', u'pygrim Documentation',
155+
u'Fredrik Johansson', 'manual'),
156+
]
157+
158+
159+
# -- Options for manual page output ------------------------------------------
160+
161+
# One entry per manual page. List of tuples
162+
# (source start file, name, description, authors, manual section).
163+
man_pages = [
164+
(master_doc, 'pygrim', u'pygrim Documentation',
165+
[author], 1)
166+
]
167+
168+
169+
# -- Options for Texinfo output ----------------------------------------------
170+
171+
# Grouping the document tree into Texinfo files. List of tuples
172+
# (source start file, target name, title, author,
173+
# dir menu entry, description, category)
174+
texinfo_documents = [
175+
(master_doc, 'pygrim', u'pygrim Documentation',
176+
author, 'pygrim', 'One line description of project.',
177+
'Miscellaneous'),
178+
]
179+
180+
181+
# -- Extension configuration -------------------------------------------------
182+
183+
autodoc_default_options = {
184+
'members': True,
185+
'member-order': 'bysource',
186+
'special-members': '__init__',
187+
'undoc-members': True,
188+
'exclude-members': '__dict__, __weakref__',
189+
}
190+
191+
#autoclass_content = 'both'
192+
193+
def skip(app, what, name, obj, would_skip, options):
194+
if name == "__init__":
195+
return False
196+
return would_skip
197+
198+
def setup(app):
199+
app.connect("autodoc-skip-member", skip)
200+
201+
# -- Options for intersphinx extension ---------------------------------------
202+
203+
# Example configuration for intersphinx: refer to the Python standard library.
204+
intersphinx_mapping = {'https://docs.python.org/': None}
205+
206+

doc/source/expr.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Symbolic expressions
2+
=============================================
3+
4+
.. automodule:: pygrim.expr
5+
:members:
6+

doc/source/index.rst

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
.. pygrim documentation master file, created by
2+
sphinx-quickstart on Tue Feb 11 14:15:48 2020.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
Pygrim
7+
==================================
8+
9+
**Pygrim** is a Python library for working with symbolic mathematical expressions.
10+
11+
It is used to develop the Mathematical Functions Grimoire (Fungrim): http://fungrim.org/
12+
13+
The source repository is: https://github.com/fredrik-johansson/fungrim
14+
15+
Features
16+
--------
17+
18+
* Uses Grim expressions (http://fungrim.org/grim/)
19+
to represent mathematical formulas and theorems semantically
20+
* Conversion from symbolic expressions to LaTeX
21+
* Code for building the Fungrim website
22+
* Access to the Fungrim formula database from Python
23+
* Symbolic computation (evaluation/simplification of expressions)
24+
* Numerical evaluation of expressions
25+
26+
Module documentation
27+
--------------------
28+
29+
.. toctree::
30+
:maxdepth: 3
31+
:caption: Contents:
32+
33+
expr.rst
34+
brain.rst
35+
algebraic.rst
36+
37+
Dependencies
38+
-----------------------------
39+
40+
For building the Fungrim website:
41+
42+
* `node.js <https://nodejs.org/>`_
43+
* `KaTeX <https://www.npmjs.com/package/katex>`_
44+
45+
For building the image files on the Fungrim website:
46+
47+
* `Matplotlib <https://matplotlib.org/>`_
48+
* `mpmath <http://mpmath.org/>`_
49+
* `Python-FLINT <https://github.com/fredrik-johansson/python-flint>`_ and its dependencies (GMP, MPFR, FLINT, Arb)
50+
51+
For symbolic computation:
52+
53+
* `Python-FLINT <https://github.com/fredrik-johansson/python-flint>`_ and its dependencies (GMP, MPFR, FLINT, Arb)
54+
55+
Note: right now, Pygrim requires a git checkout of FLINT and a checkout of the development branch of Python-FLINT
56+
57+
Building the Fungrim website
58+
----------------------------
59+
60+
Run ``python3 fungrim.py`` in the root directory of the ``fungrim`` source repository, and the grimoire will appear in ``build/html/index.html``.
61+
62+
The first build may take several minutes (due to starting ``node.js`` thousands of times to run KaTeX for each formula), but subsequent rebuilds should be fast since this data is cached.
63+
64+
Run ``python fungrim.py img`` to build the image files.
65+
66+
Indices
67+
-------
68+
69+
* :ref:`genindex`
70+

pygrim/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
from .expr import *
44
from .brain import *
55

6+
# this should maybe not be exported, but it's currently
7+
# useful for development
8+
try:
9+
from flint import *
10+
from .algebraic import alg
11+
except ImportError:
12+
pass
13+
614
def test_fungrim_entry(id, num=100):
715
from .formulas import entries_dict
816
entry = entries_dict[id]
@@ -36,5 +44,17 @@ def test_fungrim(nstart=0):
3644
test_fungrim_entry(eid)
3745

3846
def test():
47+
print("----------------------------------------------------------")
48+
print("algebraic")
49+
print("----------------------------------------------------------")
50+
import doctest
51+
doctest.testmod(algebraic, verbose=True, raise_on_error=True)
52+
algebraic.TestAlgebraic().run()
53+
54+
print("----------------------------------------------------------")
55+
print("brain")
56+
print("----------------------------------------------------------")
57+
import doctest
58+
doctest.testmod(brain, verbose=True, raise_on_error=True)
3959
TestBrain().run()
4060

0 commit comments

Comments
 (0)