MyNixOS website logo
Description

Examples for the Flint2 library.

Examples for Flint2 Haskell bindings for the flint library for number theory.

examples of complex_plot

Flint2-Examples

Introduction

Examples for the Flint2 Haskell wrapper of the Flint library.

Most of these are directly "translated" from C to Haskell so they are written using "imperative" constructs in Haskell to demonstrate the use of the Haskell wrapper (not intended as examples of elegant Haskell code). The structure of programs follows closely the structure of the C code (with some exceptions: e.g. swinnerton_dyer_poly uses a different algorithm, logistic uses a monad transformer instead of a for loop ...)

There are basic benchmarks in some of the programs. In some cases experimental support of multithreading is available. Checkout the options by typing prog -h.

Installation

  • Install the C-library available from Flint. There are packages available for various operating systems.

  • Install the Haskell interface with

cabal install Flint2 --lib
  • Check that your Cabal default local bin directory does not contain any conflicting names (see below for a list of binaries)!
  • Install the examples with
cabal install Flint2-Examples

'

Source code

To study the source code download the code from Github with. More documentation will hopefully available soon. Also check the flintlib site.

git clone https://github.com/monien/Flint2-Examples.git

Quick start

A simple example would be the factorization of integers (factor_integers). To find out what options are available use -h:

factor_integers -h

which prints

Factor integers.

Usage: factor_integer INTEGER [-t|--threads THREADS] [--timing]

  Factor integers.

Available options:
  INTEGER                  Integer given as expression (e.g. 2^64+1)
  -t,--threads THREADS     number of threads
  --timing                 timing
  -h,--help                Show this help text

Now typing

factor_integer 2^256-1

returns

[(3,1),(5,1),(17,1),(257,1),(641,1),(65537,1),(274177,1),(6700417,1),(67280421310721,1),(59649589127497217,1),(5704689200685129054721,1)]

A more advanced example: complex_plot

Try complex_plot by typing:

complex_plot

This will plot the phase of the Klein invariant in the upper half plane.

The app complex_plot has many more options. Using the help option one obtains

Plotting special functions in the complex plane.

Usage: complex_plot [--xa XA] [--xb XB] [--ya YA] [--yb YB] [--width WIDTH] 
                    [--height HEIGHT] [-c|--color-mode COLOR-MODE] 
                    [-f|--function FUNCTION] [-o|--output IMAGE-FILE]

  plotting special functions.

Available options:
  -c,--color-mode COLOR-MODE
                           possible values: 0 .. 6
  -f,--function FUNCTION   possible values: agm, ai, barnesg, besseli, besselj,
                           besselk, bessely, bi, digamma, ellipp, ellipsigma,
                           ellipzeta, erf, fresnelc, fresnels, gamma, lgamma,
                           modeta, modetaq, modj, modjq, modlambda, modlambdaq,
                           zeta
  -o,--output IMAGE-FILE   write output to IMAGE-FILE
  -h,--help                Show this help tex

Multithreading

To use the experimental support of multithreading it is most convenient to set the number of cores available using the environment variable GHCRTS (e.g. for 10 cores)

GHCRTS='-N10'
export GHCRTS
Metadata

Version

0.1.0.2

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows