ND1 Data Types (MorphEngine v.1.4)

 

ND1 supports the following data types:

Real Number, Fraction, Continued Fraction, Boolean, Complex Number, Binary Number, BigInt, BigFloat, Vector (including List and Array), Matrix, Expression (including Name), String, RPL+ Program, JavaScript Function, JavaScript Object, Code, Image, TaggedObject


Operators/functions are defined which operate on one or multiple of these types. These are listed under Functions.


Details for each type are as follows:


Real Number ℝ

A real-valued number.
Examples: 2.3, +12.856e-23, 5
When entering a real number, do not enter a thousands separator.

All basic operators (+, *, etc.) operate on real numbers. In addition there are math menus (Trig, Logs) and a dedicated menu, Real, with functions that operate on real numbers.
Reals are defined in the range from MINR to MAXR, which are available as symbolic constants.

Reals in ND1 have an internal IEEE-758 (64-bit “double”) representation. The symbolic constant maxInt specifies the greatest integer than can be accurately represented. If larger integers are required, BigInts should be used.

BigFloat ℝ

A real-valued arbitrary-precision decimal number.
Examples: 1.4142135623730950488016887242096980784826 (square root of two to many places), 2.71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642 (number e to 100 places)
When entering a BigFloat, do not enter a thousands separator. You can also obtain BigFloats from real conversion, computation, ContinuedFraction evaluation, and programmatic creation.
For BigFloats derived from conversion and computation a precision governs, that is set via a function, setBigFPrecision. The default precision is 32 digits.

The toBigF and fromBigF (or fromBig) functions can be used to convert from a to a real number. The toBig function will convert an given number into a BigFloat if it’s a non-integer.

Basic arithmetic operators (+, *, -, /, ^, 1/x, neg) operate on BigFloats. In addition there are functions from various menus that are defined on BigFloats: sign, rem, mod, max, min, abs, ceil, floor, fract, int, isInt, size, squared, modpow, exp, incr, decr, INCR, DECR, sqrt, split.
BigInt

A BigInt is a binary integer number in base 10 (decimal number), base 2 (binary number), base 8 (octal number), or base 16 (hexadecimal number), with arbitrary precision. That is, there is no limit to the number of digits in the number.
Examples: 0x2a00000432342347657651 (hexadecimal), 341313211312131o (octal), 10010101b (binary), 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000 (decimal for 100!)

An integer with more than 15 decimal digits is automatically made into a BigInt upon entry. Otherwise, any Real or Binary Number can be converted into a BigInt with the toBigNum function. A non-integer real will be truncated. The toBig function will convert a given number into a BigInt, if it’s an integer. The fromBigNum (or fromBig) functions can be used to convert back to a real number. 

Other ways of obtaining a BigInt is via computation or programmatic creation. Certain functions, such as factorial,  will return a BigInt result for large input values.

Basic operators (+, *, etc.) operate on BigInts. In addition, most functions in the Integer and Binary menus work with BigInts. Binary’s menu wordsize has no bearing on BigInts.



Fraction ℚ

A rational number.
Examples: 1 3/4, 7/4
To enter a fraction, use the iOS keyboard and type it as a proper or improper fraction, or mixed number.

There’s a dedicated menu, x/y (Fraction), with functions that operate on fractions, allow them to be constructed from Reals, and convert them to Reals or components.
All basic arithmetic (+, -, /, *) and comparison (==, <=, <, etc.) operators, as well as neg, inv, sign, mod, max, min, abs, squared, incr (INCR), decr (DECR) work on fractions.
ContinuedFraction

A continued fraction in linear notation. Periodic and non-periodic continued fractions are supported.
Examples: [3;7,15,1,292] (approximation of pi), [1;(1)] (golden ratio), [1,(2)] (square root of two)
To enter a continued fraction, use the iOS keyboard and type it in linear notation. Or use the toCF or toSqrtCF function to create one from a real.

There’s a dedicated menu, x/y (Fraction), with functions that operate on continued fractions, allow them to be constructed from Reals, and convert them to Reals, Fractions, convergents, or terms.
A few arithmetic (1/x, neg) and comparison (==, <=, <, etc.) operators, as well as sign, size work on continued fractions.

Note: Periodic continued fractions evaluate to a BigFloat, while non-periodic ones evaluate to a fraction.



Boolean bool

A value of true or false.
Returned by test operators in the Program menu and mainly used by RPL Programs, inside control structures.



Complex Number ()

A point in the two-dimensional complex plane, usually denoted x+iy, complex numbers in ND1 are denoted (x, y), where x is the real part, and y the imaginary part of the complex number.
Examples: (3, 5), (-2, 4.5653)
When entering a complex number on the edit line, it is not necessary to provide the closing parenthesis.

Almost all operators defined for real numbers also apply to complex numbers. In addition, some operators have an extended range (e.g., square root of a negative number), or produce a complex number as result of an extended range (e.g., inverse sine of a number larger than one).
There’s one menu with operators exclusively for this data type: Complex

Composita:

The components of a complex number can be arbitrary expressions, but they be evaluable by the time the complex number becomes an operand.
Examples:   (‘2+3’, 6)
                    (‘sin(a)+π’, ‘2*b’) [both a and b must be evaluable for this number to be usable in a calculation]

Note: a composita will not display the single quotes when displayed on the stack, but they’re required during entry if the expression is to be retained. The single quotes remain part of the datum and will re-appear upon inspection (edit line / database).

If single quotes are not used during entry, the expression will evaluate immediately.
For example, “(2+3, 6” will enter as (5, 5).



Binary Number 101

An integer number in base 2 (binary number), base 8 (octal number), or base 16 (hexadecimal number).
Examples: 0x2a (hexadecimal), 034 (octal), 34o (octal), 100101b (binary)
These can be entered as shown.

Basic operators (“+”, “*”, etc.) operate on binary numbers. In addition, there is a dedicated menu, Binary, for operations on binary numbers. Binary numbers are always integers and represented within a given number of bits, set by a “set wordsize” function (store_ws) from the Binary menu. Word lengths from 1 to 32 bits are supported.

Real Numbers (always in base 10, that is, decimal) can also be used with Binary functions, with no need for conversion, and designation, as Binary Numbers. When used with a binary function, a fractional real is truncated to become an integer.

Support for hexadecimal numbers and octal numbers (using the notation with a leading zero only) exists outside the special binary functions, where ever Real Numbers are used. When these are entered on the edit line or evaluated they will be converted into the normal decimal representation of Real Numbers.



Vector (Array, List) []
 
A vector, or array, or list, is a collection of other types: Real Numbers, Complex Numbers, Expressions, Strings, RPL Programs.
In ND1, there’s no distinction in syntax between a mathematical vector, an array, or a list. The word “vector” is mostly used when a mathematical vector is present, otherwise the word “array” is used.

Each member in the collection is referred to as “element”.
If a vector has only number values for its elements, it is a mathematical vector, on which certain operators are defined. Some operators require a vector to have a certain number of elements, called “size”. (For example, the cross-product is only defined on two vectors of size 3, that is, having three elements.)

Examples:   [3, 5, 8]                               (a three-dimensional vector)
                    [-2, 4.5653]                         (a two-dimensional vector)
                    [“A String”, (3,4), ‘sin(x)’]  (an array having string, complex number, and expression elements)

When entering a vector on the edit line, it is not necessary to provide the closing bracket.

Various of the common operators (such as “+”, “-”, “neg”) are also defined for mathematical vectors.
There’s one menu with operators exclusively for this data type: Array

Composita:

The elements of an array/vector can be arbitrary types, incl. expressions containing variables.
Select operators are designed to work on arrays with an arbitrary collection of types.
For example, an array [3, ‘3+4’, “Hello “] can be added (“+” operator) to an array [2, ‘sin(r)’, “there”].

Note: expressions in a vector/array will not display the single quotes when displayed on the stack, but they’re required during entry if the expression is to be retained. (If single quotes are not used during entry, the expression will evaluate immediately.) The single quotes remain part of the element and will re-appear upon inspection (edit line / database).

Per-Member Operation:

Built-in functions that operate on a single real-valued input and return one output (of arbitrary type) can be applied to a vector, with the effect of their applying to each member.
For example, “sin” run a vector [π, ‘x’, ‘4-5’] will yield a vector [0, ‘sin(x)’, -0.8414...].

Matrix [[]]

A matrix is a two-dimensional “grid” of elements of other types: Real Numbers or Expressions. (Complex numbers and other types not yet supported.)
A matrix can be thought of as a vector of vectors, where the size of each component vector is the same.
The word “element” is used to refer to the elements of the vectors, not the vectors themselves.

Examples:   [[1, 2],[3,4]]
                    [[-2, 4.5653], [‘b’,‘a*sin(x)’]]

There’s three ways to enter a matrix on the edit line:
Abbreviated, comma-separated: [[1,2[3,4        [no need for closing brackets]
Abbreviated, space-separated: [[1 2[3 4          [no need for closing brackets]
Full, comma-separated: [[1,2],[3,4]]

Besides the common operators (“+”, “-”, “*”, “/”, “1/x”), operators for this type are in the Array menu.

Composita:

The elements of a matrix can be arbitrary types, incl. expressions containing variables.
Select operators are designed to work on matrices with an arbitrary collection of types.

Note: expressions in a vector/array will not display the single quotes when displayed on the stack, but they’re required during entry if the expression is to be retained. (If single quotes are not used during entry, the expression will evaluate immediately.) The single quotes remain part of the element and will re-appear upon inspection (edit line / database).

Per-Member Operation:

Built-in functions that operate on a single real-valued input and return one output (of arbitrary type) can be applied to a matrix, with the effect of their applying to each member.
For example, “round” run a matrix [[π, 2.3],[4.2, ‘7/2’]] will yield a matrix [[3,2],[4,4]].



String “”

A sequence of characters in double quotes.
Examples:    “This is a string”                                                                    (an ordinary text string)
                    “data:image/png;base64,UIOGYUIGD678Huigyuf87...”        (a data URL (screenshot) string)

Any character sequence that starts with a double-quote becomes a string. The closing quote will be automatically provided, if necessary.

Of the basic operators, only “+” is defined for strings.
The functions that operate on this data type are in the String menu.



Expression (and Name) ‘’

A mathematical algebraic evaluable expression that, when evaluated, yields exactly one value, where value can be of any type.
Delimited by single quotes, an expression combines literals, variables, operators/functions, and parentheses.

Literals can be of the following types: Real Number, Complex Number, Vector, Matrix

Examples:    ‘(2+3)*5‘               (a simple real-valued expression)
                     ‘sin(x)+cos(y)‘      (an expression using one operator (“+”), two functions, and two variables)
                     ‘(4,5)+(2,3)‘          (an expression using one operator (“+”), and two complex number literals)                             
                     ‘[4,5]+A‘                (an expression using one operator (“+”), one vector literal, and a variable)                                             
                     ‘[[3,4],[1,2]]*[3,4]’  (an expression specifying a literal matrix-vector multiplication)

An expression needs to be algebraically correct. An invalid expression will yield a syntax error when evaluated.

Names

A name looks like an expression but only contains a character sequence. Examples: ‘A’, ‘myVar’, ‘myFunc2’
Names are used as handles for variables and functions. Referring to a name without quotes recalls the variable, and evaluates the function, previously stored under that name.



RPL+ Program ≪≫

A RPL+ program definition. RPL+ is a superset of RPL, and backwards compatible to it.

Delimited by “≪“ and “≫” special characters, an RPL+ Program is an execution context for instructions understood by ND1. The instructions are all the operators/functions that ND1 uses for stack manipulation and special language elements for flow control (to implement for- and while-loops, do conditional execution, etc.).
An RPL+ Program can be both an operator, as well as an operand (=data on which another operator, such as another program or function).

An RPL+ Program can use user functions, without reservations. It can call other RPL+ Programs (sub-programs) and JavaScript programs.

An RPL+ Program can serve as a user function and can be transparently used in expressions.

An RPL+ Program is executed when a key with its name is tapped, its name is entered, or it is evaluated.

Recalling a variable that contains an RPL+ Program, will show its definition and permit editing. Similarly, such a variable may be “visited” for editing.

JavaScript Function

An anonymous JavaScript function definition.

A JavaScript function can be entered on the edit line in its usual form, beginning with the word “function” (w/o quotes). The function has to be anonymous, that is, have no name.
A function definition will only enter if it parses free of syntax errors. If entered on an expanded edit line, any error location is communicated back to the user.
If evaluated, a function will undergo a syntax check. (This is useful for functions edited off-line and appearing as database entries.)

A JavaScript function can be written in pure JavaScript or against the MorphEngine API. It can use frameworks and other external dependencies, which it can declare with a special require MorphEngine API function.

A JavaScript function can serve as a user function and can be transparently used in expressions.
A JavaScript function is executed when a key with its name is tapped, or its name is entered.

Recalling a variable containing an JavaScript function will show its definition and permit editing. Similarly, such a variable may be “visited” for editing.



JavaScript Objects {}

Native objects in the JavaScript language. A JavaScript Object encapsulates a dictionary of keys and values, where keys are strings, and values can be any valid JavaScript types. Any kind of object can appear on the stack and be used by functions that know how to access its keys (properties).

A generic object will appear on the stack as
        [object Object]

The following conventions exists to yield more appropriate information display:
If the object contains a “stringValue” property, it will display instead
If the object is a registered data type, its type’s class will be employed (via toHTML() or toString()) to obtain its visual representation

Objects can be entered on the edit line in standard JavaScript object notation. Generic JavaScript objects can be edited on the edit line (notwithstanding their representation on the stack), as can registered types that permit this.

Examples:
- a user function “function() { return {“a”:1, “b”:”hi” }; }” would, when run, return a dictionary on the stack with a numerical value of 1 for a key named “a”, and a string “hi” for a key named “b”. It would display as [object Object].
- an object entered on the edit line as {“stringValue”: 3.14159} (w/o quotes) would display as 3.14159 on the stack. 

There’s no size limitation for a JavaScript object.

There are no functions defined in the shipping function set of ND1 that operate on JavaScript Objects, but nothing precludes user functions to operate on JavaScript objects.
In the future, specific JavaScript Objects may be recognized as new types in the shipping function set.


Code code

Source Code in a supported language.

Code objects can be created by entering text (arbitrary text, but considered to be valid source code) on the edit line preceded with the special characters sequence “/*” (w/o quotes).
Code objects are mainly used by the “inject” function but can be regular operands to any function that supports the type.

A special global constant exists, which denotes an empty object: noCode


Image image

A bitmap image. Supported bit-depths are 1-bit and 8-bit, supported color spaces are gray and RGBA.

Images are created with the “image” function, which serves as “constructor.”
Images can be displayed, and they can be regular inputs to functions that support this type.

Screenshots are images.


TaggedObject

Any of the other supported objects, tagged with a text string. 

Examples:   :Speed:5                                            (a Real tagged with string “Speed”)
                    :Result:587652876587657653234    (a BigInt tagged with string “Result”)
                    :data:[1,2,3,4]                                    (an array tagged with string “data”)

Entered with special :: syntax, a tagged object decorates another object. It will have limited ability to participate in calculations. Reals will continue to function normally. For example, :Speed:5 can be multiplied by a Real.
 

Supported Types

(c) 2011 Naive Design. All rights reserved.

pdf (12/27/11)http://naivedesign.com/docs/ND1_Reference_DataTypes.pdf