Logo GenPRES

BigRational Module

Parses, converts, formats and calculates with BigRational values, including divisors, multiples of an increment and ranges from a minimum to a maximum. The module is compiled with the Module suffix, so that its compiled name does not clash with the BigRational type.

Types and nested modules

Type/Module Description

Tests

Holds the Unquote tests of the valueToFactorRatio function.

BigRationalException

Exception type

Message

Message type to be used when an exception message is warranted

Functions and values

Function or value Description

BigRational.apply f x

Full Usage: BigRational.apply f x

Parameters:
Returns: 'a
Type parameters: 'a

Apply a f to bigrational x

f : BigRational -> 'a
x : BigRational
Returns: 'a

BigRational.calcCartesian op vs1 vs2

Full Usage: BigRational.calcCartesian op vs1 vs2

Parameters:
Returns: BigRational[]

BigRational.calcConc max conc

Full Usage: BigRational.calcConc max conc

Parameters:
Returns: RationalX seq

Calculate the set of possible solutions with a concentration conc up to a maximum value max in descending order

max : BigInteger
conc : RationalX
Returns: RationalX seq

BigRational.calcMinOrMaxToMultiple isMax isIncl incrs minOrMax

Full Usage: BigRational.calcMinOrMaxToMultiple isMax isIncl incrs minOrMax

Parameters:
    isMax : bool - Specifies whether the maximum value is being calculated.
    isIncl : bool - Indicates whether the result should be inclusive or exclusive of minOrMax.
    incrs : Set<RationalX> - A set of positive increments to consider for adjusting the starting value.
    minOrMax : RationalX - The starting value for which to calculate the minimum or maximum.

Returns: RationalX The calculated minimum or maximum value based on the provided conditions.

Calculates the minimum or maximum value that can be obtained by adding (or subtracting) positive increments to a given starting value (minOrMax).

isMax : bool

Specifies whether the maximum value is being calculated.

isIncl : bool

Indicates whether the result should be inclusive or exclusive of minOrMax.

incrs : Set<RationalX>

A set of positive increments to consider for adjusting the starting value.

minOrMax : RationalX

The starting value for which to calculate the minimum or maximum.

Returns: RationalX

The calculated minimum or maximum value based on the provided conditions.

BigRational.calculate n1 o n2

Full Usage: BigRational.calculate n1 o n2

Parameters:
    n1 : 'a option
    o : 'a -> 'b -> 'c
    n2 : 'b option

Returns: 'c option
Type parameters: 'a, 'b, 'c

Perform a calculation when both n1 and n2 are 'some'

n1 : 'a option
o : 'a -> 'b -> 'c
n2 : 'b option
Returns: 'c option

BigRational.denominator br

Full Usage: BigRational.denominator br

Parameters:
Returns: bigint

Get the denominator of a BigRational

br : BigRational
Returns: bigint

BigRational.distinct xs

Full Usage: BigRational.distinct xs

Parameters:
Returns: BigRational[]

Order-preserving distinct over a BigRational array using the default .NET equality comparer. Because BigRational (RationalX) is a struct that implements IEquatable<_>, this takes the unboxed equality path, avoiding the per-element boxing that F#'s structural Array.distinct incurs for a [] struct. Behaviour matches Array.distinct (keeps the first occurrence of each value).

xs : BigRational[]
Returns: BigRational[]

BigRational.divisorsOfBigInt

Full Usage: BigRational.divisorsOfBigInt

Returns: BigInteger -> BigInteger list

Get all divisors of a BigInt

Returns: BigInteger -> BigInteger list

BigRational.divisorsOfBigR

Full Usage: BigRational.divisorsOfBigR

Returns: BigRational -> BigRational list

Get all the divisors of a BigRational

Returns: BigRational -> BigRational list

BigRational.exactDecimalRegex

Full Usage: BigRational.exactDecimalRegex

Returns: Regex

A decimal as its exact text writes it: an optional minus sign, digits, and digits after a decimal point. Only the digits 0 to 9, as .NET reads every Unicode digit for \d.

Returns: Regex

BigRational.fixPrecision n

Full Usage: BigRational.fixPrecision n

Parameters:
    n : int

Returns: RationalX -> float

Fix the precision of a BigRational and return the result as a float

n : int
Returns: RationalX -> float

BigRational.formatDecimal format br

Full Usage: BigRational.formatDecimal format br

Parameters:
Returns: string

The text that the format function makes of the decimal of a BigRational. A value beyond the range of a decimal is written as its fraction.

format : decimal -> string
br : BigRational
Returns: string

BigRational.fromBigInt z

Full Usage: BigRational.fromBigInt z

Parameters:
    z : bigint

Returns: RationalX

Create a BigRational from an bigint

z : bigint
Returns: RationalX

BigRational.fromDecimal d

Full Usage: BigRational.fromDecimal d

Parameters:
    d : decimal

Returns: RationalX

Create a BigRational from a decimal

d : decimal
Returns: RationalX

BigRational.fromFloat f

Full Usage: BigRational.fromFloat f

Parameters:
    f : float

Returns: RationalX option

Converts a float to a BigRational through decimal, so that a float read from a text such as 0.14 gives the exact value 7/50. A float that the decimal does not give back exactly, or that is beyond the range of a decimal, is converted with Double.floatToFract. None for infinity and not a number.

f : float
Returns: RationalX option

BigRational.fromInt x

Full Usage: BigRational.fromInt x

Parameters:
    x : int

Returns: RationalX

Create a BigRational from an int

x : int
Returns: RationalX

BigRational.gcd a b

Full Usage: BigRational.gcd a b

Parameters:
Returns: RationalX

Get the greatest common divisor of two BigRationals a and b

a : BigRational
b : BigRational
Returns: RationalX

BigRational.getDivisors modulo zero one two n

Full Usage: BigRational.getDivisors modulo zero one two n

Parameters:
    modulo : ^a -> ^a -> ^a
    zero : ^a
    one : ^a
    two : ^b
    n : ^a

Returns: ^a list
Modifiers: inline
Type parameters: ^a, ^b (requires (static member Abs : ^a -> ^a) and (static member op_Division : ^a * ^b -> ^a) and (static member get_One : -> ^a) and (static member op_Addition : ^a * ^a -> ^a) and comparison and (static member op_Division : ^a * ^b -> ^a))

Generic function to calculate all divisors of n, using a modulo function

modulo : ^a -> ^a -> ^a
zero : ^a
one : ^a
two : ^b
n : ^a
Returns: ^a list

BigRational.id

Full Usage: BigRational.id

Returns: BigRational -> BigRational

Utility to enable type inference

Returns: BigRational -> BigRational

BigRational.isDivisor zero dividend divisor

Full Usage: BigRational.isDivisor zero dividend divisor

Parameters:
    zero : 'a
    dividend : ^b
    divisor : ^c

Returns: bool
Modifiers: inline
Type parameters: 'a, ^b, ^c (requires equality and (static member op_Modulus : ^b * ^c -> 'a) and (static member op_Modulus : ^b * ^c -> 'a))

Generic function to check whether a divisor is a divisor of a dividend, i.e. the number being divided

zero : 'a
dividend : ^b
divisor : ^c
Returns: bool

BigRational.isDivisorOfBigInt dividend divisor

Full Usage: BigRational.isDivisorOfBigInt dividend divisor

Parameters:
    dividend : bigint
    divisor : bigint

Returns: bool

Check whether a divisor divides a dividend

dividend : bigint
divisor : bigint
Returns: bool

BigRational.isDivisorOfBigR dividend divisor

Full Usage: BigRational.isDivisorOfBigR dividend divisor

Parameters:
Returns: bool

Check whether a divisor divides a dividend

dividend : BigRational
divisor : BigRational
Returns: bool

BigRational.isMultiple incr v

Full Usage: BigRational.isMultiple incr v

Parameters:
Returns: bool

Checks whether v is a multiple of incr

incr : BigRational
v : BigRational
Returns: bool

BigRational.lcm a b

Full Usage: BigRational.lcm a b

Parameters:
Returns: RationalX

Get the least common multiple of two BigRationals a and b

a : BigRational
b : BigRational
Returns: RationalX

BigRational.maxExclMultipleOf

Full Usage: BigRational.maxExclMultipleOf

Returns: Set<RationalX> -> RationalX -> RationalX

Calculates the maximum value (exclusive) that can be obtained by adding positive increments to a given starting value (minOrMax) and returning the smallest result.

Returns: Set<RationalX> -> RationalX -> RationalX
Example

 3N |> BigRational.maxExclMultipleOf (set [2N; 3N]) = 2N
val set: elements: 'T seq -> Set<'T> (requires comparison)

BigRational.maxInclMultipleOf

Full Usage: BigRational.maxInclMultipleOf

Returns: Set<RationalX> -> RationalX -> RationalX

Calculates the maximum value (inclusive) that can be obtained by adding positive increments to a given starting value (minOrMax) and returning the smallest result.

Returns: Set<RationalX> -> RationalX -> RationalX
Example

 3N |> BigRational.maxInclMultipleOf (set [2N; 3N; 4N]) = 3N
val set: elements: 'T seq -> Set<'T> (requires comparison)

BigRational.minExclMultipleOf

Full Usage: BigRational.minExclMultipleOf

Returns: Set<RationalX> -> RationalX -> RationalX

Calculates the minimum value (exclusive) that can be obtained by adding positive increments to a given starting value (minOrMax) and returning the smallest result.

Returns: Set<RationalX> -> RationalX -> RationalX
Example

 3N |> BigRational.minExclMultipleOf (set [2N; 3N]) = 4N
val set: elements: 'T seq -> Set<'T> (requires comparison)

BigRational.minInclMultipleOf

Full Usage: BigRational.minInclMultipleOf

Returns: Set<RationalX> -> RationalX -> RationalX

Calculates the minimum value (inclusive) that can be obtained by adding positive increments to a given starting value (minOrMax) and returning the smallest result.

Returns: Set<RationalX> -> RationalX -> RationalX
Example

 3N |> BigRational.minInclMultipleOf (set [2N; 3N]) = 3N
 3N |> BigRational.minInclMultipleOf (set [2N..2N..10N]) = 4N
val set: elements: 'T seq -> Set<'T> (requires comparison)

BigRational.minIncrMaxToSeq min incr max

Full Usage: BigRational.minIncrMaxToSeq min incr max

Parameters:
Returns: BigRational seq

Takes a min, set of increments, and max and returns a sequence of all values that are a multiple of an increment, have a minimum value that is a multiple of that increment and a maximum value that is a multiple of that increment.

min : RationalX
incr : RationalX seq
max : RationalX
Returns: BigRational seq
Example

 minIncrMaxToSeq 1N [2N; 3N] 13N
 |> Seq.toList
 // returns [2N; 3N; 4N; 6N; 8N; 9N; 10N; 12N]
module Seq from Microsoft.FSharp.Collections
val toList: source: 'T seq -> 'T list

BigRational.numDenom v

Full Usage: BigRational.numDenom v

Parameters:
Returns: RationalX * RationalX

Split a rational number in a numerator and denominator

v : BigRational
Returns: RationalX * RationalX

BigRational.numerator br

Full Usage: BigRational.numerator br

Parameters:
Returns: bigint

Get the numerator of a BigRational

br : BigRational
Returns: bigint

BigRational.one

Full Usage: BigRational.one

Returns: RationalX

Constant 1

Returns: RationalX

BigRational.opIsAdd op

Full Usage: BigRational.opIsAdd op

Parameters:
Returns: bool

Check whether the operator is addition

op : RationalX -> RationalX -> RationalX
Returns: bool

BigRational.opIsDiv op

Full Usage: BigRational.opIsDiv op

Parameters:
Returns: bool

Check whether the operator is divsion

op : RationalX -> RationalX -> RationalX
Returns: bool

BigRational.opIsMult op

Full Usage: BigRational.opIsMult op

Parameters:
Returns: bool

Check whether the operator is multiplication

op : RationalX -> RationalX -> RationalX
Returns: bool

BigRational.opIsSubtr op

Full Usage: BigRational.opIsSubtr op

Parameters:
Returns: bool

Check whether the operator is subtraction

op : RationalX -> RationalX -> RationalX
Returns: bool

BigRational.optToString _arg1

Full Usage: BigRational.optToString _arg1

Parameters:
Returns: string

Convert an optional BigRational to a string. If None then return empty string.

_arg1 : BigRational option
Returns: string

BigRational.parse

Full Usage: BigRational.parse

Returns: string -> BigRational

Parse a string to a bigrational Raises an exception Message when the string cannot be parsed

Returns: string -> BigRational

BigRational.parseCont succ fail s

Full Usage: BigRational.parseCont succ fail s

Parameters:
Returns: 'a
Type parameters: 'a

Parse a string and pass the result either to succ or fail function

succ : RationalX -> 'a
fail : Message -> 'a
s : string
Returns: 'a

BigRational.raiseExc m

Full Usage: BigRational.raiseExc m

Parameters:
Returns: 'a
Type parameters: 'a

Raise exception with message m

m : Message
Returns: 'a

BigRational.reduceRatio num denom

Full Usage: BigRational.reduceRatio num denom

Parameters:
Returns: RationalX * RationalX

Reduce a ratio where num is the numerator and denom is the denominator

num : BigRational
denom : BigRational
Returns: RationalX * RationalX

BigRational.three

Full Usage: BigRational.three

Returns: RationalX

Constant 3

Returns: RationalX

BigRational.toDecimal

Full Usage: BigRational.toDecimal

Returns: BigRational -> decimal

Create a decimal from a BigRational

Returns: BigRational -> decimal

BigRational.toDecimalString br

Full Usage: BigRational.toDecimalString br

Parameters:
Returns: string option

The exact decimal form of a BigRational, "0.5" for 1/2, or None when it has none, as 1/3, or when it is beyond the range of a decimal. Unlike toDecimal, which goes through a float, nothing is rounded.

br : BigRational
Returns: string option

BigRational.toDouble br

Full Usage: BigRational.toDouble br

Parameters:
Returns: float

Create a float from a BigRational

br : RationalX
Returns: float

BigRational.toFloat br

Full Usage: BigRational.toFloat br

Parameters:
Returns: float

Convert a BigRational to a float

br : BigRational
Returns: float

BigRational.toMaxMultipleOf

Full Usage: BigRational.toMaxMultipleOf

Returns: RationalX -> RationalX -> RationalX

Calculates the largest multiple of a specified quantity (multiple) that is less than or equal to the given value.

Returns: RationalX -> RationalX -> RationalX
Example

 3N |> BigRational.toMaxMultipleOf 2N = 2N

BigRational.toMinMultipleOf

Full Usage: BigRational.toMinMultipleOf

Returns: RationalX -> RationalX -> RationalX

Calculates the smallest multiple of a specified quantity (multiple) that is greater than or equal to the given value.

Returns: RationalX -> RationalX -> RationalX
Example

 3N |> BigRational.toMinMultipleOf 2N = 4N

BigRational.toMultipleOf isMinOrMax multiple value

Full Usage: BigRational.toMultipleOf isMinOrMax multiple value

Parameters:
Returns: RationalX
 Calculates the nearest multiple of the given multiple based on whether it's required
 to be a minimum or maximum value.

 - Parameters:
   - isMinOrMax: Specifies whether the value should be the minimum or maximum multiple.
   - multiple: The increment value for which to find the nearest multiple.
   - value: The value for which the nearest multiple needs to be calculated.

 - Returns: The calculated nearest multiple value.
isMinOrMax : bool
multiple : RationalX
value : RationalX
Returns: RationalX

BigRational.toString v

Full Usage: BigRational.toString v

Parameters:
Returns: string

Convert a bigrational to a string

v : BigRational
Returns: string

BigRational.toStringExact br

Full Usage: BigRational.toStringExact br

Parameters:
Returns: string

The exact text of a BigRational: its decimal form when it has a finite one, "0.5", else the reduced fraction, "1/3".

br : BigRational
Returns: string

BigRational.toStringNl br

Full Usage: BigRational.toStringNl br

Parameters:
Returns: string

Convert a BigRational to a string in Dutch format

br : BigRational
Returns: string

BigRational.tryParse

Full Usage: BigRational.tryParse

Returns: string -> RationalX option

Try to parse a string and return None if it fails otherwise Some bigrational

Returns: string -> RationalX option

BigRational.tryParseExact s

Full Usage: BigRational.tryParseExact s

Parameters:
    s : string

Returns: RationalX option

A BigRational from its exact text: a decimal, "0.5", or a fraction, "1/3" or "500/1"; None for anything else. A decimal takes only a leading sign and a decimal point, so an exponent, a group separator or a decimal comma is refused. Its digits are read as they are, so a decimal of any length stays exact.

s : string
Returns: RationalX option

BigRational.two

Full Usage: BigRational.two

Returns: RationalX

Constant 2

Returns: RationalX

BigRational.valueToBigIntFactorRatio v (arg2, arg2, arg2, arg2)

Full Usage: BigRational.valueToBigIntFactorRatio v (arg2, arg2, arg2, arg2)

Parameters:
    v : BigRational
    arg1 : bigint option
    arg2 : bool
    arg3 : bigint option
    arg4 : bool

Returns: (bigint * bigint) option

Calculate a rational factor ratio for a given input value based on conditions.

v : BigRational
arg1 : bigint option
arg2 : bool
arg3 : bigint option
arg4 : bool
Returns: (bigint * bigint) option

BigRational.valueToFactorRatio v (arg2, arg2, arg2, arg2)

Full Usage: BigRational.valueToFactorRatio v (arg2, arg2, arg2, arg2)

Parameters:
Returns: (RationalX * RationalX) option
 Calculate a rational factor ratio for a given input value based on conditions.

 This function takes an input value v of type BigRational and a tuple r containing the following components:
   - n: An optional numerator.
   - nIsMult: A boolean flag indicating whether the numerator should be a multiple of n (true) or exact value (false).
   - d: An optional denominator.
   - dIsMult: A boolean flag indicating whether the denominator should be a multiple of d (true) or exact value (false).
 Parameters:
   - v: The input value for which the factor ratio is calculated (of type BigRational).
   - r: A tuple containing the conditions and components for calculating the factor ratio.
 Returns:
   - If the calculated factor ratio accurately represents the original value, returns Some (n, d).
   - Otherwise, returns None.
v : BigRational
arg1 : RationalX option
arg2 : bool
arg3 : RationalX option
arg4 : bool
Returns: (RationalX * RationalX) option

BigRational.zero

Full Usage: BigRational.zero

Returns: RationalX

Constant 0

Returns: RationalX

Active patterns

Active pattern Description

BigRational.(|Mult|Div|Add|Subtr|NoMatch|) op

Full Usage: BigRational.(|Mult|Div|Add|Subtr|NoMatch|) op

Parameters:
Returns: Choice<unit, unit, unit, unit, unit>

Match an operator op to either multiplication, division, addition or subtraction. Returns NoMatch otherwise

op : RationalX -> RationalX -> RationalX
Returns: Choice<unit, unit, unit, unit, unit>

BigRational.(|Mul|Div|Add|Sub|) op

Full Usage: BigRational.(|Mul|Div|Add|Sub|) op

Parameters:
Returns: Choice<unit, unit, unit, unit>

ToDo: doesn't return NoOp but fails, have to rewrite Match an operator op to either multiplication, division, addition or subtraction, returns NoOp when the operation is neither.

op : RationalX -> RationalX -> RationalX
Returns: Choice<unit, unit, unit, unit>

Type something to start searching.