ContinuedFraction

com.phasmidsoftware.number.core.misc.ContinuedFraction
See theContinuedFraction companion object
case class ContinuedFraction(cf: ConFrac, infinite: Boolean = ..., markov: Double = ...)

This Class defines a Continued Fraction. See Continued Fraction.

Continued fractions are an interesting way of defining irrational (or rational) numbers. There are two distinct types:

Finite

Gives rise to a rational number or an approximation to an irrational number
Infinite
Gives rise to an irrational number

Value parameters

cf

the ConFrac that defines this ContinuedFraction.

infinite

whether this ContinuedFraction is infinite (defaults to true).

markov

the Markov constant for this particular ContinuedFraction (defaults to Hurwitz, i.e. the square root of 5)

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

Method to prepend a pair to the start of a continued fraction.

Method to prepend a pair to the start of a continued fraction.

Value parameters

p

the coefficient to prepend.

Attributes

Returns

a new ContinuedFraction with x prepended.

def prefix(n: Int): ContinuedFraction

Yield a finite ContinuedFraction from this by considering only a prefix of the coefficients.

Yield a finite ContinuedFraction from this by considering only a prefix of the coefficients.

Value parameters

n

the number of coefficients (terms) to consider. If n = 0, we get the number 1, if n = 1, we get a sub 0. and so on.

Attributes

Returns

a ContinuedFraction which is a prefix of this.

def toDouble(epsilon: Double): Option[Double]

Method to approximate this ContinuedFraction according to the value of epsilon. The result should be close to the value of the represented irrational by less than 1/d/d/markov.

Method to approximate this ContinuedFraction according to the value of epsilon. The result should be close to the value of the represented irrational by less than 1/d/d/markov.

Value parameters

epsilon

a small positive number.

Attributes

Returns

an optional Double approximation to the value of the infinite series.

def toRational(n: Int): Rational

Method to yield a Rational from the first n elements of this ContinuedFraction.

Method to yield a Rational from the first n elements of this ContinuedFraction.

Value parameters

n

the number of elements (coefficient pairs) to use in the evaluation.

Attributes

Returns

a Rational.

def toRational(epsilon: Double): Option[Rational]

Method to approximate this ContinuedFraction according to the value of epsilon. The result should be close to the value of the represented irrational by less than 1/d/d/markov.

Method to approximate this ContinuedFraction according to the value of epsilon. The result should be close to the value of the represented irrational by less than 1/d/d/markov.

Value parameters

epsilon

a small positive number.

Attributes

Returns

an optional Rational approximation to the value of the infinite series.

Inherited methods

def productElementNames: Iterator[String]

An iterator over the names of all the elements of this product.

An iterator over the names of all the elements of this product.

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

An iterator over all the elements of this product.

An iterator over all the elements of this product.

Attributes

Returns

in the default implementation, an Iterator[Any]

Inherited from:
Product

Concrete fields

lazy val coefficients: LazyList[Pair]

Method to get the coefficient pairs.

Method to get the coefficient pairs.

Attributes

Returns

a LazyList of Pairs.

See also

ConFrac#coefficients.

lazy val convergents: LazyList[Rational]

Method to get the convergents.

Method to get the convergents.

Attributes

Returns

a LazyList of Rationals.

See also

ConFrac#convergents.

lazy val reverseCoefficients: LazyList[Pair]

Method to get the coefficients in reverse order, providing that this ContinuedFraction is not infinite.

Method to get the coefficients in reverse order, providing that this ContinuedFraction is not infinite.

NOTE: this is never currently used.

Attributes

Returns

the coefficients in reverse order

Note

Throws ConFracException if cf is infinite.

lazy override val toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.