factory-0.0.0.2: Rational arithmetic in an irrational world.

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 Algorithm algorithm whereSource

Defines the methods expected of a square-root algorithm.

Methods

squareRootFromSource

Arguments

:: Real operand 
=> algorithm 
-> Estimate

An initial estimate from which to start.

-> DecimalDigits

The required precision.

-> operand

The value for which to find the square-root.

-> Result

Returns an improved estimate of the square-root, found using the specified algorithm, accurate to at least the required number of decimal digits.

squareRootSource

Arguments

:: Real operand 
=> algorithm 
-> DecimalDigits

The required precision.

-> operand

The value for which to find the square-root.

-> Result

Returns an estimate of the square-root, found using the specified algorithm, accurate to at least the required number of decimal digits.

Instances

class Iterator algorithm whereSource

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

Methods

stepSource

Arguments

:: Real operand 
=> algorithm 
-> operand

The value for which the square-root is required; y.

-> Result

The current estimate; x(n).

-> Result

An improved estimate; x(n+1).

convergenceOrderSource

Arguments

:: algorithm 
-> ConvergenceOrder

The ultimate ratio of successive terms as the iteration converges.

Instances

Types

Type-synonyms

type Result = RationalSource

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 -> DecimalDigitsSource

  • 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 -> ResultSource

  • 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 => operand -> EstimateSource

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

Predicates

isPrecise :: Real operand => operand -> Result -> BoolSource

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