This is a tiny Flask application to calculate the p-adic absolute-value of a rational number.
- Install the Flask, WTForms, and flask_wtf packages (see
requirements.txt
). python p_adic_controller.py
runs the application in a browser at http://127.0.0.1:5000/test.
p_adic_controller.py
contains the app logic.
p_adic_view.html
is the Jinja view template.
p_adic_model.py
is a WTForms Form subclass. This will be updated to a Flask-WTF FlaskForm subclass to include CSRF protection.
p_adic_compute
contains the computation functions. p_adic_abs
is the old version.
The function p_adic_abs
takes a prime
- an integer, when the answer is a whole number
- a string expressed as a ratio of integer a/b, when the answer is a float
Example in terminal:
import p_adic_compute as p
p.p_adic_abs(5, 1/200)
25
p.p_adic_abs(5, 200)
'1/25'
Floats are converted to an integer ratio with the fractions
package. This is chosen to analyze the result for pedagogical rather than computational purposes. This will be refactored so that either version can be chosen.