Class: Foft

Foft

Foft is a class that evaluates the
properties of Function or Foft objects that
generally receive and return objects of type

  • Number
  • Array of Number,
  • Array of Array

new Foft(params)

create a Foft instance that evaluates its Function terms
when given some parameter "t".

accepts an argument params that may be a(n):

  • function see params.terms for details
  • object see params for details
  • array of numbers see params.range for details
  • Foft instance will return a copy of the instance
Parameters:
Name Type Description
params Object | function | Array.<Number> | Foft
Properties
Name Type Argument Default Description
range Number | Array.<Number> <optional>

Range of two numerical values over which t is evaluated inclusively. If given a single number t0, range is [-t0,t0]

segmentDivisor Number <optional>

The number of segments to divide the range into when picking t values for evaluation.

terms function | Array.<function()> | Array.<Foft> <optional>
[]

A function that accepts a parameter t and returns a result of some operation on t

rangeoverride boolean <optional>
false

if true, will override any range provided and set range equal to [0, params.segmentDivisor]

harmonize boolean <optional>
false

if true, will harmonize the domains of any Foft terms to that of the new parent instance @see range, @see segmentDivisor

Source:
See:
  • Foft.oft
Throws:

TypeError

Examples
// returns a Foft instance
let MoT = new Foft()
// returns a Foft instance that
// describes an equation over the range [0,1] (inclusive)
// split into 22 segments (23) total points
let MoT = new Foft({
  range: [0, 1],
  segmentDivisor: 22,
  terms: (t) => t*2;
});
Foft also evaluates some of the properties
of the Function or Foft objects in its terms

Members


<static> divisor :Number

divisor By default, Foft instances divide into
this many segments

Type:
  • Number
Default Value:
  • 10
Source:

<static> funcKeys

methods for inter-instance communication

Source:
See:
  • tThis

<static> mathTypes

valid types that Foft can do math on

Source:
See:

<static> maxSafeDivisor

maxSafeDivisor the maximum safe to use divisor

Source:

<static> membKeys

members for inter-instance communication

Source:
See:
  • tThis

<static> opDict

an array of valid op keys

Source:
See:

<static> ops

ops an object containing operations, or ops, that
perform mathematical functions corresponding to their keys

Source:
See:

<static> R

dimensional labeling

Source:

<static> sweep :Array.<Number>

sweep By default, Foft instances evaluate functions over this range

Type:
  • Array.<Number>
Default Value:
  • [-1,1]
Source:

dabsrange

the absolute value of the delta
between the first and final values of the evaluation range

Source:

drange

the delta between the the first and final values of the evaluation range

Source:

dt

get the delta for t between the first and final values of the
evaluation range. May be innacurate when the range has more than two
terms

Source:

numSegments

The number of actual segments the Foft divides the evaluation range into

Source:

ofAlltT

get a Generator that yields
all Array=[t, this.oft(t)] for t in evaluation range
in form [t, this.oft(t)]

Source:
See:
  • oft

ofAlltTOp

get a Generator that yields all
this.oftOp(_t, _acc, _op) for _t in T,
_acc, _op provided by user

Source:
See:
  • ofAlltTOp

ofFirstt

return the oft for the first t in the evaluation range

Source:
See:
  • t0
  • oft

ofLastt

return the oft for the final t in the evaluation range

Source:
See:
  • range
  • oft

opcode

a Foft can have an opcode as defined in
Foft.ops. These codes represent mathematical operations
between Numbers and other types. They are useful for performing
said operations when the Function or Foft in the terms
Array

Source:
See:

opcode

set opcode - set the opcode to one of the opcodes
defined in Foft.ops

Source:

range

set range - only accepts an arraylike of calculables

Source:

range

get the evaluation range is the minimum and maximum values for t

Source:

segmentDivisor

set segmentDivisor - set the segment divisor for the evaluation range where

  • the range will be divided into (segmentDivisor+1) segments,
  • if given an arraylike parameter, use the 0th value
  • if given a calculable parameter, use it as-is
Source:

segmentDivisor

get segmentDivisor The number of segment divisors
(number of t evaluation points -1)
in this Foft

Source:

T

get a Generator yielding all values of t across instance evaluation range

Source:
Example
// get the default t values for which a Foft is
// evaluated
let MoT = new Foft({
  range: [0, Math.PI*2],
  segmentDivisor: 22,
  terms: (t) => [sin(t), cos(t)];
});
let T = [...MoT.T()]

t0

get the first value of t in the evaluation range T

Source:
See:
  • T

terms

the Function terms of this Foft object

Source:

tt

the last value of t in the evaluation range T

Source:
See:
  • T

Methods


<static> antiNormToRange( [t] [, TT])

given a Number t, amd a ramge TT, return a normalized (to Foft.sweep)
representation of the ratio between the two deltas A and B where

  1. A is the difference betewen t and TT[last]
  2. B is the difference between TT[last] and TT[first]

If t falls out of bounds of range, the value is returned as -/+ Infinity,
where:

  1. +Infinity corresponding to beyond the bound of TT[first], and
  2. -Infinity corresponding to beyond the bound of TT[last]
Parameters:
Name Type Argument Default Description
t number <optional>
0

the t to evaluate

TT Array.<number> <optional>
sweep

the range in which to test for TT

Source:
See:
  • normToRange
Returns:
Type
number

<static> areCalculables()

areCalculables return true IFF one of these conditions are met

  1. The provided arguments are ALL of Number type,
  2. The sole provided argument is an Array whose members are ALL of Number type,
  3. Any provided argument is an Array whose members are
    A. ALL of Number type, or
    B. nested Arrays whose submembers are all number types or Array,
    and ALL other arguments are Number type or Array with ALL members of Number type, and
  4. All arguments of number type are neither NaN nor -/+Infinity
Source:
See:
  • areNums
Returns:
Type
boolean

<static> areNums()

areNums return true IFF one of these conditions are met

  1. The provided arguments are ALL of Number type,
  2. The sole provided argument is an Array whose members are ALL of Number type,
  3. Any provided argument is an Array whose members are
    A. ALL of Number type, or
    B. nested Arrays whose submembers are all number types or Arrays
    and ALL other arguments are Number type or Array with ALL members of Number type,
Source:
See:
  • areCalculables
Returns:
Type
boolean

<static> dimensions(x)

return the size of the given x, where x can be a number or an arraylike or a nested arraylike

Parameters:
Name Type Description
x number | Array

the structure to get dimensions of

Source:
Returns:
Type
Array

<static> equiv()

determine whether the given number or Array-like arguments are satisfying the conditions:

  1. all of a single shared type,
  2. if numbers, of equal value,
  3. if arrays, composed of equal positional elements
  4. if other types, satisfying strict equality test

When comparing values that are NaN or containing NaN in the same positions, the function will return false because NaN doesn't equal NaN

Source:
Returns:
Type
boolean

<static> iInRange(t, TT, d)

given a number t, a range TT and a divisor d, return the value of the corresponding i such that

  1. i is proportional to the location of t within the range
  2. i is proportional to d
Parameters:
Name Type Description
t number

t to find in TT

TT Array.<number>

range

d type

divisor

Source:
Returns:
Type
null | number

<static> inRange(n [, m] [, mm])

determine whether a given number n falls
within any of the follwoing inclusive ranges
0. [ Foft.sweep[0], Foft.sweep[1] ]

  1. [0, m],
  2. [0, m[0]], (when provided unit-length array)
  3. [m[0], m[m.length-1]]
    4, [m, mm]
Parameters:
Name Type Argument Description
n Number

the number to test

m Number | Array.<Number> <optional>

the end of the range starting with 0, or
the Array representing the range [m[0], m[last]]
the begining of range ending in mm, or

mm Number <optional>

the optional end of the range

Source:
Returns:
Type
boolean

<static> isArrayLike(x)

determine whether a given argument x is "like" an array for the purposees of Foft calculations and parsing, returning true IFF x satisfies one of the following conditions:
1 - It is an Array
2 - It is a TypedArray
3 - It provides a Symbol.iterator property

The third condition allows for the parsing of various iterable objects, but it does not guarantee that such actions will produce calculable values.

Parameters:
Name Type Description
x ?
Source:
Returns:
Type
boolean

<static> isCalculable()

return true IFF all of the following conditions are met

  1. argument satisfies isNum (One Number argument)
  2. argument is not NaN
  3. argument is not +/-Infinity

This function does more calls than just using isFinite, however, it is used in the Foft class because the class also deals with arrays and objects.

Source:
See:
  • isNum
Returns:

description

Type
boolean

<static> isNum()

return true IFF both of the following conditions are met

  1. there was ONE argument provided, and
  2. the sole provided argument was a Number
Source:
Returns:
Type
boolean

<static> isOp(codeToParse)

given a string codeToParse, return true when code is found
in Foft.opDict

Parameters:
Name Type Description
codeToParse string
Source:
See:
Returns:
Type
boolean

<static> mathTypeOf( [a])

tell whether the given argument a is of one of the types that Foft can do math with and if so, which type

Parameters:
Name Type Argument Description
a ? <optional>
Source:
Returns:
Type
Symbol | null

<static> normToRange( [t] [, TT] [, NN])

given a Number t, amd a ramge TT, return a normalized (to an optional range NN or Foft.sweep)
representation of the ratio between the two deltas A and B where

  1. A is the difference betewen t and TT[first]
  2. B is the difference between TT[last] and TT[first]

If t falls out of bounds of range, the value is returned as -/+ Infinity,
where:

  1. -Infinity corresponding to beyond the bound of TT[first], and
  2. +Infinity corresponding to beyond the bound of TT[last]
Parameters:
Name Type Argument Default Description
t number <optional>
0

the t to evaluate

TT Array.<number> <optional>
sweep

the range in which to test for TT

NN Array.<number> <optional>
sweep

the target normalization range * @return {number}

Source:

<static> opParse(codeToParse)

given a string codeToParse, return
the corresponding operation function from Foft.ops

Parameters:
Name Type Description
codeToParse string
Source:
See:
Returns:

Foft.ops function corresponding to op

Type
function

<static> precision()

give precision warning in the form of an object that can be converted to a primitive.

Floating point math has inherent imprecisions. This function is for examining them.

Source:
Returns:

the object with primitive values:
{number} the maximum value for which no precision is lost
{string} as brief message

Type
object

<static> tThis(t, foft)

given a t and a Foft instance, produces an object with some keys for inter-instance communication corresponding to:
1 the result of evaluating certain methods of the calling instance for t @see funcKeys
2 certain members of the calling instance @see membKeys

Parameters:
Name Type Description
t Number

the t of the instance communicatiing

foft Foft

the instance doing communication

Source:
See:
  • oft
Returns:

communication object, or array of communication keys

Type
object | Array.<string>

addTerm(term [, harmonize])

add a term to the terms of this Foft instance

Parameters:
Name Type Argument Default Description
term function | Foft

A Function that takes a parameter (t) or
Foft

harmonize boolean <optional>
false

if true, and term is a Foft
instance, this overwrites the range and segmentDivisor of term to make them
reference the same-named parameters of this instance.

Source:
Returns:

true if length of terms grew

Type
boolean

antinormalizeT(t)

given a number t return a normalized representation of the ratio of a quantity n to the delta of the instance evaluation range such that the ratio of t to the delta of the evaluation range N satisfies
1.n = maximum normal - N

This is the remaining range for the normalized value provided by normalizeT

if t falls beyond the lower bound of the evaluation range, return +Infinity
if t falls beyond the upper bound of the evaluation range, return -Infinity

Parameters:
Name Type Description
t number
Source:
See:
  • normalizeT
Returns:

n

Type
number

dSubrange( [n] [, nn])

given indices n & nn
returns the delta between sub values in the Foft instance's
evaluation range, or: range[nn%range.length]-range[n%range.length],

when given no parameters, it uses 0 and 1

Parameters:
Name Type Argument Default Description
n Number <optional>
0

the starting range index.

nn Number <optional>
n+1%this.range.length

the end range index

Source:
Throws:

when given non-number parameter

Type
TypeError
Returns:
Type
Number

i(t)

given a Number t within a the evaluation range of this instance
(inclusive), return the value of the corresponding i such that

  1. i is proportional to the location of t within the range
  2. i is scaled to segmentDivisor

If t falls out of bounds of the range, nothing is returned

If the range has more than two elements, return an array of length range-1

Parameters:
Name Type Description
t Number
Source:
See:
  • iInRange
  • segmentDivisor
  • normalizeT
Returns:

[0, segmentDivisor]

Type
Number | null | Array.<(number|null)>

isInRange(t)

return true IFF a given t falls within the evaluation range of this instance

Parameters:
Name Type Description
t number
Source:
Returns:
Type
boolean

mapT( [callback] [, thisArg])

apply the Array.map native function to the elements yielded by
this[Symbol.iterator] with the given callback function and this argument
*

Parameters:
Name Type Argument Description
callback function <optional>

callback to apply

thisArg Object <optional>

this argument

Source:
See:
  • get [Symbol.iterator]

Returns:

map result

Type
Array

mapTOp( [callback] [, thisArg])

apply the Array.map native function to the elements of
this.ofAllTOp() with the given callback function and this argument

Parameters:
Name Type Argument Description
callback function <optional>

callback to apply

thisArg Object <optional>

this argument

Source:
See:
  • Array.map
  • ofAllTOp
Returns:

map result

Type
Array

normalizeT( [t] [, doAnti])

given a Number t, return a normalized (to Foft.sweep)
representation of the ratio between t and the delta of the evaluation
range of this Foft

If t falls out of bounds of range, the value is returned as -/+ Infinity

If the evaluation range has more than two values, e.g. [0,1,2],
then normalizeT checks in each subrange, e.g. [0,1], [1,2]
and returns an Array of normalized values corresponding to each range

Parameters:
Name Type Argument Default Description
t Number <optional>
0
doAnti boolean <optional>
false
Source:
See:
  • normToRange
  • sweep
Returns:
Type
Number | Array.<Number>

oft( [t] [, filterNulls] [, maketthis])

evaluate all of the terms held by this Mathoft for the
given t value.

When evaluating a Function or Foft term, the function or Foft is called with a this object containing certain useful data regarding the calling instance's evaluation of t @see tThis

When evaluating a Foft term, any t that falls outside that term's evaluation range will produce a null result. If the filterNulls parameter is true, then null values will be stripped from the returned result.

Parameters:
Name Type Argument Default Description
t Number <optional>
t0
filterNulls boolean <optional>
false
maketthis boolean <optional>
true
Source:
See:
  • isInRange
Returns:
Type
Number | Array.<Number> | Array.<Array>

oftNormal( [tNormal])

Accepts a Number tNormal that falls within Foft.sweep, inclusive, and when provided
1 . A NaN value, return NaN
2. +Infinity, returns evaluation from end bound of range
3. -Infinity, returns evaluation from start bound of range
4. Any other number even outside of normal range, returns value of that t.

Parameters:
Name Type Argument Default Description
tNormal Number <optional>
[-1,1]
Source:
See:
  • isCalculable
  • ofFirstt
  • ofLastt
  • sweep
  • oft
Returns:
Type
Number | Array.<Number>

oftOp(t [, _op] [, _acc])

Calculate the value of performing an operation _op on the
values returned by calculating this Foft instance's terms for
some evaluation value t. When given a parameter _acc, the calculation of _op will use _acc as its starting value.

This is intended to facilitate convenient manipulation of terms and results.

Parameters:
Name Type Argument Default Description
t Number

the t to evaluate

_op string <optional>
this.opcode

an opcode to perform @see Foft.ops

_acc Number | Array.<Number> | Array.<Array> <optional>
null

an accumulator value to start with @see Foft.ops -> base

Source:
See:
  • oft
Returns:
Type
Number | Array.<Number> | Array.<Array>

subT( [n])

get a generator function that yields segmentDivisor+1 values of t spanning the range [this.range[n], this.range[n+1]], where if n or n+1 fall beyond the bounds of this.range.length, they are constrained to fit

Parameters:
Name Type Argument Default Description
n Number <optional>
0

integer start index of range

Source:
Returns:

description

Type
type

toString()

toString

Source:
Returns:
Type
string