ConFrac

com.phasmidsoftware.number.core.misc.ConFrac
See theConFrac companion object
class ConFrac(val b: Long, co: => Option[CF]) extends Evaluatable, Takeable

This Class defines a lazily-evaluated Generalized Continued Fraction, somewhat like a LazyList.

Value parameters

b

the (additive) coefficient, represented on the Wikipedia page (Generalized CF) as b.

co

an optional reference to a ConFrac.

Attributes

Companion
object
Graph
Supertypes
trait Takeable
trait Evaluatable
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def +:(p: Pair): ConFrac

Method to prepend an (b, a) pair of coefficients to this ConFrac. This is particularly useful if the value before the semi-colon (in the standard representation) is not part of a repeating sequence.

Method to prepend an (b, a) pair of coefficients to this ConFrac. This is particularly useful if the value before the semi-colon (in the standard representation) is not part of a repeating sequence.

Value parameters

p

the coefficient pair to prepend before this ConFrac. Typically, this will be (b, 1).

Attributes

Returns

a new ConFrac whose initial value is y and whose co value is Some(this).

def render(depth: Int): String
def renderConvergents(length: Int): String
def take(n: Int): ConFrac

Method to convert an infinite continued fraction into a finite continued fraction.

Method to convert an infinite continued fraction into a finite continued fraction.

NOTE: this method is not tail-recursive, thus you should limit n to about 100

Value parameters

n

the number of elements to take.

Attributes

Returns

a ConFrac which starts out the same as this, but after n elements, the tail (co) will be None.

def takeWhile(predicate: Rational => Boolean): ConFrac

Method to convert an infinite continued fraction into a finite continued fraction.

Method to convert an infinite continued fraction into a finite continued fraction.

NOTE: this method is not tail-recursive.

Value parameters

predicate

the predicate which operates on the current rational approximation, such that, as long as true is returned, we continue to take elements.

Attributes

Returns

a ConFrac which starts out the same as this but, once the predicate has failed on this, the tail (co) will be None.

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

Method to convert this ConFrac to an (optional) Double, according to the epsilon value.

Method to convert this ConFrac to an (optional) Double, according to the epsilon value.

NOTE: this method invokes toNominalRational(Double), which is not tail-recursive.

Value parameters

epsilon

the maximum allowable error.

Attributes

Returns

an optional approximate value.

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

Method to convert this ConFrac to an (optional) Rational, according to the epsilon value.

Method to convert this ConFrac to an (optional) Rational, according to the epsilon value.

Note that, if epsilon is too small, the result may be None.

NOTE: this method invokes toRationalOption, which is not tail-recursive.

Value parameters

epsilon

the desired tolerance from the ideal values.

markov

the Markov constant for this ConFrac.

Attributes

Returns

either Some(r), where r approximates this ConFrac, or None if the tolerance value could not be achieved.

This method is solely for evaluating continued fractions according to a numerical criterion (z).

This method is solely for evaluating continued fractions according to a numerical criterion (z).

NOTE: this method is not tail-recursive.

Attributes

Returns

the Rational equivalent of this continued fraction.

Concrete fields

val b: Long
lazy val coefficients: LazyList[Pair]

Method to get the coefficients.

Method to get the coefficients.

NOTE: this method is not tail-recursive but it will only recurse as deeply as required by the number of elements which must be evaluated.

Attributes

Returns

a LazyList[Pair] which can never be empty.

lazy val convergents: LazyList[Rational]

Method to yield the "convergents" from this ConFrac.

Method to yield the "convergents" from this ConFrac.

Attributes

Returns

a lazy list of Rationals.

lazy val reverseCoefficients: LazyList[Pair]

Convert this ConFrac into a (lazy) list of coefficients.

Convert this ConFrac into a (lazy) list of coefficients.

NOTE: currently, this does not support infinite ConFrac objects. However, we don't currently use this method, other than in the Spec file.

Attributes

Returns

a lazy list of the coefficients, ending with x.

lazy val tailOption: Option[CF]

Alias method because we can't make co a val.

Alias method because we can't make co a val.

Attributes

Returns

the value of co.

lazy val toRational: Rational

This method is solely for evaluating FINITE continued fractions. You will throw a Stack exception if you attempt this with an infinite (continuous) fraction.

This method is solely for evaluating FINITE continued fractions. You will throw a Stack exception if you attempt this with an infinite (continuous) fraction.

Attributes

Returns

the Rational equivalent of this finite continued fraction.

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.