factory-0.3.0.0: Rational arithmetic in an irrational world.

Safe HaskellSafe
LanguageHaskell2010

Factory.Math.SquareRoot

Contents

Description

AUTHOR
Dr. Alistair Ward
DESCRIPTION
  • Exports a common interface for square-root implementations.
  • Provides utilities for these implementations.

Synopsis

Type-classes

class Algorithmic algorithm where Source #

Defines the methods expected of a square-root algorithm.

Minimal complete definition

squareRootFrom

Methods

squareRootFrom :: (Real operand, Show operand) => algorithm -> Estimate -> DecimalDigits -> operand -> Result Source #

squareRoot :: (Real operand, Show operand) => algorithm -> DecimalDigits -> operand -> Result Source #

Instances

Algorithmic Algorithm Source # 

Methods

squareRootFrom :: (Real operand, Show operand) => Algorithm -> Estimate -> DecimalDigits -> operand -> Result Source #

squareRoot :: (Real operand, Show operand) => Algorithm -> DecimalDigits -> operand -> Result Source #

class Iterator algorithm where Source #

The interface required to iterate, from an estimate of the required value, to the next approximation.

Minimal complete definition

step, convergenceOrder

Methods

step :: Real operand => algorithm -> operand -> Result -> Result Source #

convergenceOrder :: algorithm -> ConvergenceOrder Source #

Types

Type-synonyms

type Result = Rational Source #

The result-type; actually, only the concrete return-type of simplify, stops it being a polymorphic instance of Fractional.

type Estimate = (Result, DecimalDigits) Source #

Contains an estimate for the square-root of a value, and its accuracy.

Functions

getAccuracy :: Real operand => operand -> Result -> DecimalDigits Source #

  • For a given value and an estimate of its square-root, returns the number of decimals digits to which the square-root is accurate; including the integral digits.
  • CAVEAT: the result returned for an exact match has been bodged.

getDiscrepancy :: Real operand => operand -> Result -> Result Source #

  • The signed difference between the square of an estimate for the square-root of a value, and that value.
  • Positive when the estimate is too low.
  • CAVEAT: the magnitude is twice the error in the square-root.

getEstimate :: (Real operand, Show operand) => operand -> Estimate Source #

Uses Double-precision floating-point arithmetic, to obtain an initial estimate for the square-root, and its accuracy.

Predicates

isPrecise :: Real operand => operand -> Result -> Bool Source #

True if the specified estimate for the square-root, is precise.