lucaferranti / DedekindCutArithmetic.jl

Exact real arithmetic using Dedekind cuts
https://lucaferranti.com/DedekindCutArithmetic.jl/
MIT License
3 stars 0 forks source link
arbitrary-precision dedekind-reals exact-reals interval-arithmetic julia

DedekindCutArithmetic.jl

license: MIT Stable Documentation In development documentation Build Status Coverage Contributor Covenant ColPrac: Contributor's Guide on Collaborative Practices for Community Packages SciML Code Style

A Julia library for exact real arithmetic using Dedekind cuts and Abstract Stone Duality. Heavily inspired by the Marshall programming language.

Installation

  1. If you haven't already, install Julia. The easiest way is to install Juliaup. This allows to easily install and manage julia versions.

  2. Open the terminal and start a julia session by typing julia.

  3. Install the library by typing

    using Pkg; Pkg.add("DedekindCutArithmetic")
  4. The package can now be loaded (in the interactive REPL or in a script file) with the command

    using DedekindCutArithmetic
  5. That's it, have fun!

Quickstart example

The following snippet shows how to define the squareroot of a number and the maximum of a function $f: [0, 1] \rightarrow \mathbb{R}$ using Dedekind cuts. It also shows this definition is actually computable and can be used to give a tight rigorous bound of the value.

using DedekindCutArithmetic

# Textbook example of dedekind cuts, define square-root
my_sqrt(a) = @cut x ∈ ℝ, (x < 0) ∨ (x * x < a), (x > 0) ∧ (x * x > a)

# lazy computation, however it is automatically evaluated to 53 bits of precision if printed in the REPL.
sqrt2 = my_sqrt(2);

# evaluate to 80 bits precision, this gives an interval with width <2⁻⁸⁰ containing √2
refine!(sqrt2; precision=80)
# [1.4142135623730949, 1.4142135623730951]

# Define maximum of a function f: [0, 1] → ℝ as a Dedekind cut
my_max(f::Function) = @cut a ∈ ℝ, ∃(x ∈ [0, 1] : f(x) > a), ∀(x ∈ [0, 1] : f(x) < a)

f = x -> x * (1 - x)

fmax = my_max(f);

refine!(fmax) # evaluate to 53 bits of precision by default
# [0.24999999999999992, 0.25000000000000006]

Documentation

Contributing

Contributions are welcome! Here is a small decision tree with useful links. More details in the contributor's guide.

Copyright