Introduction

Why another programming language? Don’t we have enough of them? Well, let us try this real world experiment. Go to the best programmer you know. Pick the simplest formula you can think of: E=mc2. Ask how the Energy (E) can be calculated, for a mass (m) of 1kg, 2kg, 3kg,… 10kg and for a constant Speed of Light (3x10^8m/s). Let us just watch the programmer for what happens next. Yes, go ahead and start a stop watch! It is likely that the programmer would pull up a spreadsheet, and type formulae notations into the document such as on the right, and within a minute or so, give you the answers.

C =3*10^8
2 7
M
1 =D5*$E$3^2
=D5+1 =D6*$E$3^2
=D6+1 =D7*$E$3^2
=D12+1 =D13*$E$3^2
=D13+1 =D14*$E$3^2

Or maybe, the programmer would make a program, in some computer language to do this, and will come back to you in about an hour! Today, an ordinary computer can do billions of operations per second! And even with the best techniques, translating from our human language to ZCubes, Inc. 2 computer language takes minutes or hours even for the simplest of equations! This clearly shows the biggest problem with the current state of the art computer human interaction. That is why we created a simple language for you and the machine called:

z^3

The vision behind the z^3 language is specifically to make human interaction with computers convenient, simple and elegant, at any level of complexity, all immersed in a framework of immense power.

What is Z3

z^3 is a general purpose language that is easy to write and natural to read, powered by high performance, scalable, computing constructs which unlimits thinking and expression. z^3 console is launched from ZCubes platform on any HTML5 enabled browser.

FIGURE 1 - FRACTAL PATTERN GENERATED BY USING Z^3.

In the following sections of the document, z^3 specifics will be described in easy to follow examples.

ZCubes Platform

ZCubes is a platform for users to create and manipulate information. The website address is http://www.zcubes.com. To load the application simply click on the Z icon, or directly visit it at http://www.zcubes.com/zspace/zcubes.aspx. z^3 console is launched by clicking the icon on the bottom right of the ZCubes platform. Please refer to Appendix 1 for operators, symbols and notations used in ZOS.

Being an omni-functional platform, ZCubes allows creation of documents with unparalleled power, with almost any imaginable functionality provided at your finger tips. Upon load, the ZCubes Platform looks as below with a simple minimal interface: Menu items can be accessed by clicking the Z button.

The ZOS Console to interact with z^3 can be accessed using the command console button at the extreme right bottom. Commands can now be typed into the Enter ZOS Command area as indicated below.

Entering command like 1..10@SIN and pressing enter gives you the result in the window.

ZCubes Selected Features

ZCubes is a 3D platform, which changes its nature based on the user's perspective.

For example, it can function as a blackboard in one moment, and a presentation tool in another moment, or a spreadsheet in yet another moment.

The platform changes like a chameleon based on the attributes users wish to have anytime. More details on how to work with ZCubes is explained in section 8.

Data Collections

An array is a simple data structure to create, collect and manage data. z^3 transforms conventional arrays into something much more powerful called Sets.

Sets

Sets are new data types used in z^3. These are arrays (not necessarily rectangular) that are flexible in size, shape, types and contents, which make them extremely powerful. The term set is italicized throughout the document for easy identification. The following are notable properties of Sets, compared to conventional arrays:  Sets are unstructured arrays, or varied sizes and types.  Sets may contain other Sets of any complexity.  Sets are enhanced with several member functions1 in z^3. 1 A listing of these are given in Section 8.e Appendix V Member Functions. For example, sets can be printed out with the built-in member function print(), to get the internal representation in z^3. Set-based z^3 resolves complexity and scaling issues, while achieving high-performance, extreme flexibility or natural expressiveness.

Set - Simply a collection of data

Let us start with a simple example. At the ZOS Console, right after the command prompt indicated by $>, enter the command 1..3. Let us use the member function .print() to display the set representation in z^3. 1. $> 1..3 .print() [1,2,3] The “two dots” operator used in 1..3 creates a simple set, with 3 integer elements (1 at index 0, 2 at index 1, and 3 at index 2 positions). Sets have indexes starting at 0, which is a common practice in C-like languages. Once a set is created, various operations can be performed on it. As you shall see later, the results of many of these operations are also sets, which mean we can continuously apply these operations until desired results are achieved. ZCubes, Inc. 10 An interesting point to note is that the set 1..3 can be implicitly declared without any extra word or punctuations unlike most languages2. It is also important to see the use of .. operator as a technique to create a sequenced collection of number values (from lower end 1 to upper end 3 - in this case as a range). To create a set filled with a series, the [ ] operator is not required. Hence, whenever we use [ ] array operator along with .. operator, it indicates a set of set(s). This is effectively a set with index 0 containing three elements (this inside element being similar to the array in Example 1).

$> [1..3] 1 2 3

This is clearer when we apply .print(). 3. $> [1..3].print() [ [1,2,3 ] ] In the example above: the internal set representation is displayed as 1,2,3 . A set can contain other sets (containing any type of data) recursively (or one within the other without limits), as in the following,: 2 Several Series Generation Techniques are detailed in Appendix IV Series Generation

$> [2,4,1..3,2].print() [2,4, [1,2,3], 2]

In this example more complex items (including a set) is collected into one set: Location at Index 0 contains integer 2, at Index 1 contains integer 4, at Index 2 contains a set, and at the location at the last Index 3 contains integer 2. Sets created can then be operated on using functions (or even sets of functions) using the @ operator as shown below: 5. $> 1..3@COS Number COS 1 0.5403023058681398 2 -0.4161468365471424 3 -0.9899924966004454 However, aggregate functions such as SUM should be applied to the entire array, not to each element.

$> 1..3@SUM SUM 1 1 2 2 3 3

In the example above, the result may appear confusing at first, since SUM function is applied for each set element, if we use the @ operator. ZCubes, Inc. 12 The following example shows the application of function SUM() to a set (not separate elements). The three elements of set are added, resulting in 6, the expected answer. 7. $> SUM(1..3)6

Let us see another operator … (“three dots”) in action.

 $> 1...8 1 2 4 8

The “three dots” notation generates a set with 4 values, as a geometric series from 1 to 8 as 1, 2, 4, 8. Another example below shows geometric series from 1 to 30.

$> 1...30 1 2 4 8 16

Now let us look at more complex scenarios. In the following, the “two dots” (..) operator is compounded to make an even more powerful expression: 10. $> 1..10..2 1 3 5 7 9 Here the first .. indicates a series from a start value to an end value, and the second .. is used as an increment operator. Hence, the result includes all numbers from 1 to 10, with an increment of 2.

Set- Object Representation

In z^3, {} is used for the creation of object data structures (also known as associative or composite set (4.g)). The JavaScript associate array syntax and semantics are kept as they are.

$> A={a:1..3,b:1..4} 

[object Object] In Example 11, a set with two items (a as a set of 3 integer values, and b with another set of 4 integers) is dynamically created3. By simply using = (as assignment operator), A is defined as a variable, which now stores an associative set, which can then be referenced as below. 3 Here [object Object] indicates that the value is a complex object, with attributes, properties and methods, which can then be used to access its members.

$> A.a 1 2 3

Now A.a refers to the attribute a of the newly created variable A. Likewise, A.b will display the contents of item b of variable A. 4.a.i. SET – COMPLEX SET LAYOUTS Now, consider a simple set of three elements (equivalent to 1..3):

 $> [1,2,3] 1 2 3

A more complex layout of a similar set is given below, where 1 and 2 are in one element (stored as a sub set) of the new set.

 $>  [1..2,3] 1 2 3

Examples 15 to 18 below show slight variations on how non-regular layouts of set elements can be defined.

$> [1,2..3] 1 2 3
$> [1..3,1..3] 1 2 3 1 2 3 17. $> [1..2,1..5] 1 2 1 2 3 4 5 
$> [1,1..2,4] 1 1 2 4

These examples clearly demonstrate that using clear and elegant operators in z^3 (such as .. and …), simple, consistent and powerful structures can be created.

Set – Complex Set Layouts

Now, consider a simple set of three elements (equivalent to 1..3):

$> [1,2,3]

1 2 3 A more complex layout of a similar set is given below, where 1 and 2 are in one element (stored as a sub set) of the new set.

$> [1..2,3]

1 2 3 Examples 15 to 18 below show slight variations on how non-regular layouts of set elements can be defined.

$> [1,2..3]

1 2 3

ZCubes, Inc. 16

16. $> [1..3,1..3] 1 2 3 1 2 3 17. $> [1..2,1..5] 1 2 1 2 3 4 5

These examples clearly demonstrate that using clear and elegant operators in z^3 (such as .. and …), simple, consistent and powerful structures can be created.

Matrix – as a Set of Set(s)

Arguably, a matrix (which can be represented as a Set of Set(s)) is one of the most frequently needed and useful data structures in programming. A table can be visualized as an example of a matrix – such as a table containing rows and columns in a database, or a simple table with rows and columns in a simple document or the tabular grid(s) in spreadsheets. In mathematical terminology, matrix definitions and usage are very common - such as identity matrix, diagonal matrix, sparse matrix, and so on. Hence, operations on matrices are provided by z^3 using a rich set of operators and functions.

Matrix Operator(||)

Matrix construction can be done with the || operator. For example, creation of a 4x4 identity matrix can be done with the following simple notation:

 $> |4|
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

|4| as it is displayed above gives a 4 by 4 identity matrix by definition. Note that the matrix operator || is used here for both matrix declaration and initialization. If only one dimension is given, it is assumed that the matrix requested is an identity matrix. This highlights the simple and minimalist style provided by z^3 throughout. Similarly, |4,2| constructs a 4x2 matrix.

$> |4,2|
0 0
0 0
0 0
0 0

Similarly, |4,2,2| constructs a 4x2 matrix, with each cell having 2 values, all initialized to zero:

$> |4,2,2|
0 0
0 0
0 0
0 0

The variations of matrix construction can be seen in the following examples. The notation inside matrix definition can be with commas, the letter x, or a simple space.

$> |2x2|
0 0
0 0

A square matrix of 2 by 2 with initial values 0, is given by this notation.

23. $> |3x3|
0 0 0 0
0 0 0 0
0 0 0 0

Here a square matrix of 3 by 3 with initial values 0 is obtained. Similarly, you can define |4x2| or |2x4| as given below.

24. $> |4x2|
0 0 0
0 0 0
0 0 0
0 0 0
$> |2x4|
0 0 0 0 0
0 0 0 0 0

Now, let us look at some more advanced examples.

0 0 0 0 0
0 0 0 0 0

The example above gives a zero-filled 2 by 2 by 2 matrix (i.e., a matrix of 2 by 2, with each element containing a zero-filled 2-element matrix). The following gives a zero-filled matrix of 2 by 2 with 3 elements each.

Set input functions

The simplest case is SUM of set 1,2,3 is calculated by the following:

$> SUM 1..3

In the following Example 30, the set 1..3 and 2..4 are passed to the function SUM, and it gives the sum of all the numbers in both set. Compare this later, against the combinatorial arguments applied to functions (detailed in Section 4.f.i below). The following Commands (30, 31, 32) calculate the SUM of all parameters (each of which may be a set containing a series) provided in each case.

$> SUM 1..3 2..4 15

which is the same as:

$> SUM(1..3,2..4) 15 
$> SUM 1..3 2..4 1..4

We can have any number of arguments to aggregate functions. Commas and parenthesis can be omitted for simpler calls. For more complex calls, commas and parenthesis may be required to avoid ambiguity.

|| Binary Operation

The binary operation with matrix operator | |, called the “two bars” operator, is simple and natural to use. Two matrices of compatible sizes can be operated on with matrix operations, such as |+|, |-|, |*|, and |/|, as given below.

$> [1,2,3]|+|[1,2,3] 
2 4 6
$> [1,2,3]|-|[1,2,3] 
0 0 0
$> [1,2,3]|*|[[1],[2],[3]]
14 
$> [1,2,4]|/|[1,1,2] 1 2 2 
$> [[2],[2],[2]]|*|[1,2,3] 


2 4 6
2 4 6
2 4 6

Also the two bars of this operator can brace any arbitrary function or operator. Examples 38 to 41 show combining of two matrices using a simple function represented with x and y, provided in between the | | operator4.

$> 1..3|x+y|3..5 
4 6 8
$> 1..3|x*y|3..5
3 8 15
$>1..3|SIN(x)|3..5
0.8414709848078964 0.9092974268256813 0.141120008059867
$> 1..3|SIN(x)+y|3..5 
3.8414709848078963 4.909297426825681 5.141120008059867
4.e.i. MEMBER FUNCTIONS OF SET

A variety of useful and powerful member functions (listed in 8.e Appendix V Member Functions) are 4 x and y represent variables from sets on each side of the binary operation. x and y can be replaced by any two names for the variables.

provided for sets. Examples include, .print, .$, .index, .tenth, .random, etc. By convention, member functions are generally in all lowercase, while primary functions are generally in all uppercase. These member functions are invoked using dot-notation, like most conventional object-oriented languages.

$> |4x2| 
0 0
0 0
0 0
0 0

For example, .transpose() is a member function that will return the transpose of the marix.

$> |4x2|.transpose() 
0 0 0 0
0 0 0 0
$> |3x3|.random(3)
0.4868065193295479 1.9101847931742668 0.25111658102832735
0.5587615873664618 0.26558934850618243 2.996888898080215
0.9493648773059249 2.7146050329320133 2.2170031929854304

With the simple notation above, a 3x3 matrix is created, and filled with random numbers up to 3. The following shows the use of .fillwith() to fill the dynamically created matrix of size 3x3.

$> |3x3|.fillwith(8) 
8 8 8
8 8 8
8 8 8

Note that in the case above all cells are filled with 8, and in the case below a series of numbers from 1..9 are used.

$> |3x3|.fillwith(1..9) 
1 2 3 4 5 6 7 8 9

Again, matrix dimensions can be given implicitly (such as |2| for a |2x2| matrix). Functions like random(), deal(),and many other available functions listed in the Section 8.e Appendix V Member Functions can be used to manipulate sets.

$> |2|.deal() 
0.44067314197309315 0.14973507658578455
0.15162911941297352 0.7144281121436507
$> |2x3|.deal()
0.24147144774906337 0.4198728590272367 0.07390831736847758
0.48515111417509615 0.0688244975153704 0.28236311418004334


$> |3x3|.random(3)

creates a 3 by 3 set and fills it with random numbers with values upto 3.

$> A1=|2x2|.fillwith(3..6)
3 4
5 6

The .fillwith() member function is used to fill a 2 by 2 matrix with numbers 3, 4, 5, and 6. The member function det calculates the determinant of a Matrix.

$> A1.det()

-2.000000000000001

Note that the simple function DET() and det() also can be invoked to calculate the determinant of a Matrix.

$> det(A1)
-2.000000000000001

The statement above will calculate the determinant of the matrix A1 created in the previous step (Example 50).

$> IM(3).across(IM(3))


The .across() member function of set is powerful way to operate on two matrices, cell by cell. The result of this operation applies the operation among EVERY combination of cells among the matrices5. Even when we graduate into more complex combinations of computational constructs, the language keeps its fundamental simplicity and

This is similar to the TENSOR product of matrices. Here it simply provides the row column .index() as result.

consistency. Looping construct is rarely needed in z^3, as functions can be applied iteratively with implicit initialization (and increments) in a natural order and minimalistic style. While set and functions can be used in very rich ways with z^3's syntactical simplicity, traditional programming language syntax and style also can be used. This is beneficial for backward compatibility and for creating clever new possibilities of mixing traditional and newer styles.

4.f. @ Applied To Operator

To apply a function or set of functions to a set of values, we use the APPLIED TO operator, indicated by @. 54. $> 1..360@DSIN gives you a list of SIN(x) values for input ranging from 1 to 360. The @ operator can be a powerful ally when mixed with the concept of Combinatorial Arguments detailed below.

COMBINATORIAL ARGUMENTS

APPLYING COMBINATORIAL SET TO SET OF FUNCTIONS

SIMPLE FUNCTION REPRESENTATIONS

EASY MULTI-LINE REPRESENTATION OF Z^3 CODE

USING || AS "SUCH THAT" BOOLEAN EXPRESSIONS

Associative Set/Composite Set As Objects

<<< MEMBER ASSIGNMENT OPERATOR

GLOBAL ASSIGNMENTS USING <<<

The following example demonstrates the use of attribute assignment operator <<< to assign a set of functions to an attribute of an operator: 85. $> ["orange"]<<<SIN,COS orange Now this assigned a global variable called orange, that now contains a set of functions SIN and COS. Please note that SIN and COS take input in radians. DSIN and DCOS take input in degrees. This set of functions in orange is applied to a set of numbers 1..4, in Example 86. Also note that orange is now a global variable in the environment for easy use (as a set or collection of functions, which then becomes a powerful object to use to apply multiple functions at once).

Functions

Set of Functions

It is possible to use the expression in (Example 87) as a one line computation, or decomposed into multi-line computation (Commands 88 and 89). 87. $> 1..4@["x^2", "x*2", "x+2"] The example below, demonstrates the declaration of three functions, each with one parameter x, collected as a set and assigned to A for easy reuse. 88. $> A=[ "x^2", "x*2", "x+2"] In z^3, the data provided to such sets of functions can be a set (or set of sets) of any breadth and depth. The set of three functions are now invoked on a range of values 1..4 below: 89. $> 1..4@A Note that explicit looping constructs are avoided. The logic represented by the set of functions is applied to each data value in a sequence 1..4. This style of applying a set of data to a set of functions demonstrates z^3's functional approach (i.e., writing WHAT is to be computed, and hiding HOW it is computed). The built-in FOREACH function (same as FOR function) can also be used to achieve combinatorial arguments and set of functions in a straightforward manner6. FOREACH(1..2,2..4, "z=x*3*y") It is clear that the data set given as arguments are used from left to right7. The first set 1..2 behaves as the outer loop index values, and the secondary set 2..4 behaves as


Since lowercase for is a standard keyword in some platforms, FOREACH function is provided to side-step any conflict in case of case-sensitivity. 7 Any extra parameters are simply ignored, while using the matching values to compute the functions. the inner increments, for x and y values respectively, which are associated from left to right. 91. $> FOR(1..2,2..4, "z=x*3*y") As the following example clearly demonstrates that FOREACH is a rich function that takes data set in multiple forms, and sets of functions collected in a set: 92. $> FOREACH(INTS(3),[SIN,COS]) 93. $> FOR 1..3 SIN The parenthesis and commas can be dropped as in the previous example, if it would not cause a syntactic ambiguity. 94. $>

FOR 1..4 "X*X"

Simple Reusable Function Declarations

A function can be declared as follows: 95. $> Y1=u*t+0.5*a*t*2 Function Y1 with parameters: (u,t,a) is defined as u*t+0.5*a*t*2 Instantly, a function Y1 is created, with parameter u, t and a, with parameter 8 names which are automatically detected by z^3, in order of their appearance.


Global variables can be accessed from the inside of simple function definitions. However, to keep simplicity of variable names in local scope, any global variable up to 3 characters in length referenced inside the body of the function would need an _ (underscore) prefixed to its name. If there are similar names existing in the environment, z^3 will rename the function.

Combinatorial Arguments

The following gives an example of series and combinatorial arguments being used to replace the use of a spreadsheet to do such calculations! 96. $> FOR(1..3,2,3,Y1) Let’s check what would happen if more data values were provided as parameters, than that were defined in the function Y1 (which expects only 3 parameters u, t and a). FOR(1..3,2,3,8,Y1) As expected, the fourth parameter value 8 is ignored and the computation is completed with the first three parameters of the data set. Data can be simply listed following the function with a space as a separator as below. 98. $> FOR 1..3 2 3 8 Y1 If the user prefers to list the data in a parenthesis, data may be listed with a comma (,) operator as a separator. Consider an example of counting of PRIMES, up to a certain number. With z^3 notation, we can repeat this process for any set of numbers. In the example below, series of odd numbers (from 1 to 10) are created, and the count of primes that are within 1 to that number are then calculated. 99. $> FOR 1..10..2 "COUNT(PRIMES(x))" The ranges can now be expanded from 1..10 to 1..100000..10000, demonstrating powerful ways of combining z^3 notations to achieve complex expressive calculations, without sacrificing simplicity and scalability.. 100. $> FOR 1..100000..10000 "COUNT(PRIMES(x))"

Set $, $$, $$$ and $_ Member Functions

A set of functions can be invoked in every element in a set by using the powerful .$ (dollar) member function. 101. $> EVENS(4).$("x+2") 2 4 6 8 In this case, four even numbers are generated by the EVEN function, which are then incremented by 2. 1..5.$("1/x") 1 0.5 0.3333333333333333 0.25 0.2 The above output lists the reciprocals of numbers 1..5. Remember that .$ is not quite the same as .map functions that you may be familiar with, since .map operations only operate on the children in the first level of the array or set. On the other hand, .$ operates on every element in the set, recursively. 103. $> SUM(EVENS(4).$( "x+2")) The result of .$ is also a set, and can be fed into further member functions to operate on, such as SUM shown above. Now, consider the following command to add numbers from 1 to 10. 104. $> SUM(1..10) The member function (.$_) (dollar-underscore) can be used to apply an aggregate function (such as SUM) to the entire set, resulting in a single functional result. 105. $> 1..10.$_(SUM) The member function (.$$) (dollar-dollar) applies the set of functions provided on each row (by row) of the set. 106. $> MAGICSQUARE(4).$$(SUM) 34 34 34 34 The member function .$$$ (dollar-dollar-dollar) function works along columns, compared to (.$$) that operates on rows. 107. $> 1..10.$$$(SUM)

Set Functions and Set Programming

The use of sets as collections of statements and function calls creates an interesting possibility of program segments that is self-explanatory. 108. $> V=[a,b,[SIN(a),COS(b),SIN(b),COS(a)]] Function V with parameters:(a,b) is defined as [a,b,[SIN(a),COS(b),SIN(b),COS(a)]] The above function definition creates a function when called gives the input a and b, as well as the result, all as ONE set in the output! This creates the possibility of holding data sets that carry inputs and outputs of a process for reporting uses or further analysis. Such composites create a rich expression possibility for calculations in z^3. 109. $> V(1,2) Here, the results shows inputs 1 and 2 (a and b in the set program), followed by the array of results from the the computation of the set of functions [SIN(a),COS(b),SIN(b),COS(a)] in the set program. Such functions defined as set, gives unique expression power to programmers. In the example in Command 109, the input is effectively carried along with the output. Let us consider some powerful ways to create functions. 110. $> F1=[a+b,a-b] Function F1 with parameters:(a,b) is defined as [a+b,a-b] The function F1 is now defined, and calling it is simple. F1 1 2 Another example that demonstrates the expressive power: 112. $> F2=[a,b,a+b] Function F2 with parameters:(a,b) is defined as [a,b,a+b] 113.

F2 5 2 5 2 7 114. 
F2(3,9) 3 9 12 115.
F2 2*3 5

As can be clearly seen above, the outputs carry the inputs as well as the results, creating absolutely interesting possibilities of handling data, as well as avoid unnecessary complexity in programming. 116. $> F3=[SUM(a..b..c)] This effectively creates a function F3 that can add up series between a and b, of any interval c. F3 1 10 2 25 The sum of 1+3+5+7+9 is obtained as 25 by calling F3 with the parameters 1, 10 and 2. The following shows another interesting use of set Programming, coupled with || function definition (Section 4.e). 118. $> 1..4|[x^2,x^3]| Here the function [x^2,x^3] itself is a set. The result of this set function is applied on the series 1 to 4. The result is a 2 dimensional set of such combinations of output.

Advanced computation of lists

Trigonometric calculations are useful in a wide varied domains, such as electrical engineering,map projections etc. These require computation of lists. Series of values thus generated are heavily used during further computation, as inputs, as well as loop control variables; but most languages fail to support quick and easy generation of common collections and series. z^3 makes the generation of such lists incredibly easy, starting with x..y..z notation such as in 1..10..3. Generation of commonly used angles, in radians or degrees, can be easily achieved as given below. 119. $> DEG360BY45 RAD2*PiBY4 More examples and details of Series Generation are given in Appendix IV Series Generation (8.d). The series computed can be used as in cases like: 121. DEG360BY45@DSIN

Series computation

The design of z^3 attempts to provide natural language interfaces, with terse and powerful notations. Hence SUM 1..4 can also be implied by the following natural language expressions. 122. $> ADD 1 to 4 1 to 4 implies all numbers from 1 upto 4 (i.e., 1, 2, 3 and 4). Note that this is not the same as ADD 1 4 which should give the result 5. A series by an increment can be expressed using the x to y by z notation. 123. ADD 1 to 4 by 2 Obviously, the series here can also be represented as ADD(1..4..2)

Built-in Functions in z^3

z^3 has powerful prebuilt function libraries. This collection is continuing to grow daily; and already these number into the thousands. These range from functions in Mathematical, Statistical, Financial, Engineering, Medical, Database, and many other domains. Several of these standard library functions are documented at http://wiki.zcubes.com Consider some interesting available functions.

Permutations and Combinations

Permutation relates to the act of arranging all the members of a collection into some sequence or order; whereas Combination is a way of selecting items from a collection, such that the order of selection does not matter. z^3 comes with functions to list permutations and combinations of items, as well as techniques to count and list them. PERMUTATIONS(1..3) 1 All possible permutations of 1, 2 and 3 are shown above. 125. $> PERMUTATIONS(1..3,2) All possible permutations of 1, 2 and 3, in sets of two elements, are shown above. COMBINATIONS(1..3) 1 2 All possible combinations of 1, 2 and 3, of one element are shown. Next, all possible combinations of 1, 2 and 3, of two elements are shown. COMBINATIONS(1..3,2) 1 2 1 3 2 3


Common Number Series

EVENS is a function that returns x even numbers, for a requested x. 128. $> EVENS 4 The series thus generated can be input to functions as SUM, or vice versa. 129. $> SUM(EVENS(4)) EVENS(SUM(4)) 0 2 4 6 The following creates a jagged collection of 1, 2, 3 and 4 even numbers. 131. $> EVENS(1..4)

Simple Number Stats

STATS is a powerful function that applies a lot of Statistical Functions on a series of numbers. 132. $> STATS(1..100) Let us look at a larger collection of numbers. 133. $> STATS(1..1000) It scales-up for more complex needs easily, by considering the STATS function call for 1, 301, 601, and 901 in a series: 134. $> FOR 1..1000..300 "STATS(1..X)" FOR 1..1000..300 "STATS(1..X)" Now, Example 99 is scaled below to a larger range of data. 135. $> FOR 100..1000..300 "COUNT(PRIMES(X))" z^3 scales-up to handle larger range (though limited by your computers capacity), as shown in the following computation: 136. $> FOR 1...10000000 "COUNT(PRIMES(X))" Note the “three dots” operator between 1 and 10000000, which signifies the generation of a geometric series. Please try: FOR 1...10000000 "COUNT(PRIMES(X))" as a first attempt to test the capacity of your device.

Set Operations

Several operations are provided to operate on sets. Some examples with set-theoretical operations are given below: 137. $> UNION 1..3 4..5 DIFFERENCE 1..5 1..3 INTERSECTION 1..5 1..3

z^3 Simple Examples

z^3 language, while being based on global standards, is unlimited in scope by being open to extension. It does not take a single approach to problem expression and solution, but many approaches, which result in highly flexible possibilities of terse and verbose expressions based on user skill and style. Several example real-world problems are described in sections below.

Sets and Related Structures

7.a.i. MATRICES Set (or sets of sets) of complex dimensions can represent conventional matrix definitions in an effortless manner. z^3 provides a collection of powerful matrix functions and manipulation capabilities.

Matrices

Set (or sets of sets) of complex dimensions can represent conventional matrix definitions in an effortless manner. z^3 provides a collection of powerful matrix functions and manipulation capabilities.

Matrix Generation

With z^3, a wide variety of matrices can be generated with ease. In Section 4.c (Matrix Operator(||)), generation of a simple set is described. For example, |4,2| |4,2| generates a simple 4x2 matrix. Known types of matrices of required size can be generated using the MATRIX (or MATRIXWITH) function. For example, it is very common to fill a matrix with “positive”or “zero” or “negative” values as needed as follows: MATRIXWITH(4, "positive") MATRIXWITH(4, "negative") - MATRIXWITH(4, "zero") A matrix of size 4 of positive integers is generated below. 144. $> MATRIX (4, "positive:integer") Another example of a matrix of size 4 of negative integers is equally easy. 145. $> MATRIX (4, "negative:integer") Similarly, a matrix of 4x4 size of integers. 146. $> MATRIX (4, "integer") Similarly, a matrix of 4x4 size of Boolean values (0 or 1). MATRIX(4, "logical") MATRIX(4, "alternant",1..10, "[i,j]") MATRIX(4, "alternant",1..10, "i-j") More special matrices can also be generated as described below below.

Hilbert Matrix

The Hilbert matrix is a square matrix with entries being the unit fractions. For example, Hi,j = 1 / i+j-1. So, 2x2 Hilbert matrix is 1 1/2 1/2 1/3 For n, it is a square matrix nxn with the values as 1, 1/2, 1/3, 1/4, . . ., 1/n 1/2, 1/3, 1/4, 1/5, . . ., 1/n-1 1/3, 1/4, 1/5, 1/6, . . ., 1/n-2 . . . 1/n, 1/n-1, 1/n-2, . . ., 1/2n-1 In z^3, simply calling MATRIX function with arguments “hilbert” and size will provide the result: MATRIX("hilbert",2) MATRIX("hilbert",4) 7.1.1.3.

Hermitian Matrix

The Hilbert matrix is a square matrix with entries being the unit fractions. For example, Hi,j = 1 / i+j-1. So, 2x2 Hilbert matrix is For n, it is a square matrix nxn with the values as 1, In z^3, simply calling MATRIX function with arguments “hilbert” and size will provide the result: MATRIX("hilbert",2) MATRIX("hilbert",4)

Hermitian Matrix

Hermitian Matrix (or self-adjoint matrix) is a square matrix with complex entries that is equal to its own conjugate transpose, that is, the element in the i-th row and j-th column is equal to the complex conjugate of the element in the j-th row and i-th column, for all indices i and j: In mathematical representation: or Here is an example: z^3 67 152. $> MATRIX("hermitian")

Hankel Matrix

The Hankel matrix (or Catalecticant matrix), named after Hermann Hankel, is a square matrix with constant skew-diagonals (positive sloping diagonals), e.g. MATRIX("hankel")

Toeplitz matrix

The Toeplitz matrix or diagonal-constant matrix, named after Otto Toeplitz, is a matrix in which each descending diagonal from left to right is constant. The Hankel matrix above is closely related to the Toeplitz matrix (which is an upside-down Hankel matrix). For instance, the following matrix is a Toeplitz matrix in z^3: 154. $> MATRIX("toeplitz") MATRIX("toeplitz",4,1..4)

Hadamard Matrix

Named after the French mathematician Jacques Hadamard, a square matrix whose entries are either +1 or −1, and whose rows are mutually orthogonal, is called a Hadamard Matrix. In geometric terms, this means that every pair of two different rows in a Hadamard matrix represent two perpendicular vectors. In combinatorial terms, it means that every pair of rows have matching entries in exactly half of their columns and mismatched entries in the remaining columns. MATRIX("hadamard")

Vandermonde Matrix

Vandermonde Matrix, named after Alexandre-Théophile Vandermonde, is a matrix with terms of a geometric progression in each row, i.e., an m × n matrix. In z^3, the following is an example of Vandermonde matrix: 157. $> MATRIX("vandermonde") MATRIX("vandermonde",4,2) 159. $> MATRIX("vandermonde",4,1..4)

Upper and Lower-Triangular matrix and Symmetric matrix 70

In Upper Triangular Matrix, all elements under its diagonal are zero. In Lower-Triangular Matrix, all elements over the main diagonal are zeroes. In Symmetric Matrix both sides of the diagonal elements are filled, but with elements around the main diagonal symmetric in value. 160. $> MATRIX("upper-triangular",6)

MATRIX("lower-triangular",6)

MATRIX("symmetric",6) The hyphen between upper-triangular is optional.

Pascal Matrix

The elements of the symmetric Pascal matrix are the binomial coefficients, i.e. In other words: MATRIX("pascal",5) 1

Matrix Sizes

SIZE function can be used to find the size of sets. SIZE(|4x5|) 4 5 A second parameter can be used to indicate the size is to be obtained in a specific dimension. 165. $> SIZE(|4x5|,0..1) Ther result gives the size along dimensions 0 and 1, of an array of size 4x5.

Matrix Operations

The following code is used to generate a 3 by 3 set filled with 3. The RANDOM function is then called on each of the members using the $ function fills each element with random values within 0 through 3. As you can see MX is then assigned with the result. 166. $> MX=ARRAY(3,3,3) MX=ARRAY(3,3,3).$(RANDOM) The matrix MX is now added along a row using MROWOP using the + operator. 168. $> MROWOP(MX,"+",true) This result is interesting, as much as it is powerful. The true value as the second parameter indicates that the cumulative and running result as each element is operated on (as it applies columns in each row) are listed. Only cumulative result is provided if the third parameter is empty is false. 169. $> MROWOP(MX,"+",false) The same can be done for each column, with the top row indicating the cumulative result, and rows below this row showing results (when each element was added by row to the next element) in the column. 170. $> MCOLOP(MX,"+",true) MATRIXPACK(MX,2) MATRIXPACK splits the matrix into elements of sizes given as parameter. Here it divides matrix MX into pieces of 2 elements.

Matrix Arithmetic Operations

Simple Matrix addition, multiplications, negation, etc. can be obtained using MATRIX related functions such as below. MMULT([1,2,3],[[4],[4],[2]]) 18 Note the use of brackets for the vertical matrix as in [[4],[4],[2]] in Example 172. 1..3**3 is a simple notation to duplicate a set, by a requested number of times, indicated by **. In this case, 1..3 will be replicated 3 times. MMULT then operates on the two sets as below. 173. $> MMULT(1..3**3,1..3**3) 6 12 18 6 12 18 6 12 18 MMULT, does scalar multiplication of the argument is a scalar, with the matrix that is provided in the other argument. MMULT(1..10,2) MATRIXADD conducts simple addition of matrices. 175. $> MATRIXADD(1..5,1..5) MATRIXNEGATE multiplies each element by -1, or effectively negates the elements. 176. $> MATRIXNEGATE(ARRAY(4,4,10)) -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 MEQUAL checks each element in a set to see if it matches a provided value, in this case a 10x10 matrix filled by 2, is checked against 2. MEQUAL(ARRAY(10,10,2),2)

Vector Operations

Dot Product or Scalar Product of matrices can be conducted on vectors represented as matrices or sets using the DOTPRODUCT (also called SCALARPRODUCT) function. 178. $> DOTPRODUCT(1..3,4..6) 32 Similarly, Cross Product or Vector Product of matrices can be conducted on vectors represented as matrices or sets using the CROSSPRODUCT function. CROSSPRODUCT(1..3,4..6) -3 6 -3 The functions CROSSPRODUCT and VECTORPRODUCT are the same. 180. $> VECTORPRODUCT(1..3,4..6)

Matrix Determinants

In linear algebra, the determinant is a special value associated with a square matrix. For example, in a matrix that represents the coefficients of a System of Linear Equations, its determinant provides important information about the matrix. The system has a unique solution exactly when the determinant is nonzero; when the determinant is zero there are either no solutions or many solutions. Determinants occur throughout mathematics. In some cases they are used just as a compact notation for expressions that would otherwise be unwieldy to write down. For instance, the determinant of the matrix: A = [2 2 1;1 3 4; 2 6 2] |A| has the value as: (2x3x2 + 2x4x2 + 1x1x6) – (1x3x2 + 2x4x6 + 2x1x2) = -24 In z^3, the determinant of a matrix A is denoted as det(A), det A, or DET(A). 182. $> det(A) -24 In z^3, determinants of any size square matrix is easily calculated, as for the matrix x below (generated using deal member function). 183. $> x=|3|.deal() det(x) -0.036501362405503224 Determinant of an identity matrix is 1, as indicated in Example 185. det(IM(4)) The determinant of a randomly generated 3x3 matrix is given below. 186. $> det(deal|3x3|) 0.02381843917684589


Matrix Rotations

Matrix rotation can be achieved by the MATRIXROTATE function. 187. $> MATRIXROTATE(|4|,1) MATRIXROTATE(|4|,2) 0 0 1 0 0 1 0 0 0 0 1 0 0 1 0 0 189. $> MATRIXROTATE(|5|,4) A simpler z^3 notation for the same is given below, using member functions.

|5|.rotate(4)


Simple Matrix Merging with Functions

ARRAY(10,10,10) .merge(ARRAY(10,10,10)) .$(RANDOM).print() Here two 10x10 sets, filled with 10 are merged cell by cell and the result is merged together. To enter lines with soft line-break, use Shift+Enter, instead of simple Enter. It makes it simple to provide member functions indented under the main object as given above.

Across Matrices Merging with Functions

In z^3, .across() member function is a powerful operation that applies a specific function or set of functions on each pair of elements on the two input matrices. Consider a simple 3x3 identity matrix. IM(3) The .across() function applies SUM to the two identity matrices. 193. $> IM(3).across(IM(3),SUM) A more powerful example of applying a set of functions (SUM and AVG in the following case) on the each combination of elements of input matrices is shown next. IM(3) .across( IM(3), [SUM,AVG] )

Quick Multiplication Tables

Consider the following use of the across function to generate a Multiplication Table in Command 195. In this case, the .across function is used in such a way as to operate on every pair of numbers between 1 an 10. This is a simple demonstration of the .across operation, (which can also be used on an array of functions as indicated previously) to create useful collections of results, such as those that can be used for contour plotting etc. 1..10.across(1..10,PRODUCT).transpose() Using the power of sets, you can get the multiplication factors of any one number (using the [ ] element accessing capability). For example, the following command gets the multiplication table for the number 6 (note the 0 based indexing of sets as used). 196. $> 1..10 .across(1..10,PRODUCT) .transpose()[0][5]

Puzzles and Other Interesting Computations

There are several special problems and puzzles that are pre-solved in z^3 for enthusiasts, to analyze various case scenarios and to slice and dice such results.

Magic Square

In recreational mathematics, a Magic Square is an arrangement of numbers (usually integers) on a square grid, where the numbers in each row, the numbers in each column, and the numbers in the forward and backward main diagonals, all add up to the same number. A magic square has the same number of rows as it has columns, and in conventional math notation, "n" stands for the number of rows (and columns) it has. Thus, a magic square always contains n2 numbers, and its size (the number of rows and columns it has) is described as being "of the order n". The smallest nontrivial case, a 3 × 3 grid that is a magic square of order 3 is shown next. 197. $> MAGICSQUARE(3) In z^3, magic squares of any size can be created using the MAGICSQUARE function. 198. $> MAGICSQUARE(4) The sum of every row, column and diagonal, which should be a constant value, is called the Magic Constant or Magic Sum, M. Every normal magic square has a unique constant determined solely by the value of n, which can be calculated using this formula: The row wise and column wise sum of the magic square elements show that for an m of 4 rows and columns, 4*(4^2+1)/2 = 34 would be the magic constant. Commands 199 and 200 indicate that row-wise and column-wise summations of elements add up to a Magic Constant of 34. The .$$ and .$$$ member functions of sets are used to compute the row and column based sums. MAGICSQUARE(4).$$(SUM) MAGICSQUARE(4).$$$(SUM)

N-Queens Puzzle

Chess composer Max Bezzel published the Eight Queens Puzzle in 1848. Franz Nauck published the first solutions in 1850, and also extended the puzzle to the n-queens problem, with n queens on a chessboard of n×n squares. Since then, many mathematicians including Carl Friedrich Gauss have worked on both the eight queens puzzle and its generalized n-queens version. Eight queens puzzle is the problem of placing eight chess queens on an 8×8 chessboard so that no two queens attack each other. Thus, a solution requires that no two queens share the same row, column, or diagonal. The eight queens puzzle is an example of the more general n-queens problem of placing n queens on an n×n chessboard, where solutions exist for all natural numbers n with the exception of n=2 and n=3. In computer programming, the solution to this problem is considered a classic involving problem-solving, algorithms, and data structures. This approach has several applications in scheduling, distributed systems, networking, etc. There are two explicit solutions for n=4 and the solutions can be obtained in z^3 as follows: NQUEENS(4) In z^3, the user can use the NQUEEN function in several ways to get the solution, as well as explore and discover patterns associated with these solutions. NQUEENS() The result will be 92 solutions to 8Queens problem, the first and last are given in the following: More interestingly, you can compute and get in a range of data values for different sizes as follows: NQUEENS(1..8) It scales-up easily, and consider sizes of chessboards with sizes 8..12. 204. $> NQUEENS(8..12) The results of Example 204 range from 352 solutions for 8 queens upto 14200 Solutions for 12 queens. In simpler cases, solutions could be sparse as follows. 205. $> 1..4@NQUEENS For practical purposes, the results become too large when it gets to a size of 19 queens.

Birthday Probability

In probability theory, birthday probability is a simple yet interesting problem. The history of this problem is obscure. Possibly, Harold Davenport or Richard von Mises proposed what we consider today to be the birthday problem. This problem solves the probability of at least two of the n people in a room sharing a birthday. In a group of n people, there are 365n possible combinations of birthdays. The simplest solution is to determine the probability of no matching birthdays and then subtract this probability from 1. When n ≤ 365: In a random group of 23 people, there is actually about a 50–50 chance that two of them will have the same birthday. Sample solutions for the following problems in z^3 are as follows: BIRTHDAYPROBABILITY(23,365) 0.5131345029080766 This is known as the birthday paradox. In a room of 75 there’s a 99.9% chance of two people birth day matching. In a group of 6 people, the following gives how many of them celebrate their birthday in the same month? BIRTHDAYPROBABILITY(6,12) 0.7745997705740058 The decimal value is equivalent percentage value of 78%. In a list of 40 people, it is 88%. 208. $> BIRTHDAYPROBABILITY(40) BIRTHDAYPROBABILITY(10..100..10)

Towers Of Hanoi

The Tower of Hanoi puzzle was invented by the French mathematician Edouard Lucas in 1883. This puzzle is also known as Towers of Brahma. The Tower of Hanoi problem is isomorphic to finding a Hamiltonian path on an n-hypercube. Suppose three rods, as shown in the figure, and several disks with different sizes which can slide onto any rod. The disks are arranged in ascending order of size on one rod, with the smallest one at the top in a stack, such that it makes a conical shape. The objective of the game is to move all the disks onto a different pole with the following conditions:  Only one disk can be moved at a time  Only the uppermost disk can be moved from any stack.  The smaller disk should always occupy the upper position of each stack at all times. The puzzle can be solved in seven moves for three disks. The minimum number of moves required to solve a Tower of Hanoi puzzle is 2^n - 1, where n is the number of disk. Hence the number of steps can be expected to increase rapidly, with the number of disks. Using z^3, number of steps to can be calculated for varying n: 1..100..5@"2^n-1" When n=3, we expect 7 steps. 211. $> 3@"2^n-1" z^3 gives the following solution for 3 disks, which has 7 steps. At each step it also indicates the move made. Since the number of steps can be astronomical for a moderate number of disks, these calculations can exceed the capacity of the computer quite easily. TOWERSOFHANOI(4) In z^3, the user can use the some other objects (instead of numbers) like: 213. $> TOWERSOFHANOI(["cat","dog","wolf"]) More detailed solution showing step-by-step situation can also be obtained using z^3 as follows. Here, the disks are replaced by cat, dog and wolf, and the detailed moves to solve the problem is given by z^3. TOWERSOFHANOI(["cat","dog","wolf"],true) The following Example indicates the number of steps for each number of disks ranging from 1 to 10, calculated after actually conducting the solution. FOR 1..10 "TOWERSOFHANOI(x,true).length"

Floyds Triangle

Floyd’s triangle is the collection of natural numbers arranged in a right triangle to the left. It is named after Robert Floyd. Each line in Floyd’s triangle has one more element than the previous row, and has consecutive numbers from the left in each row. The nth row in the Floyd Triangle sums to n(n^2 + 1)/2, same as the constant of an n×n magic square. In z^3, Floyd’s triangle displays as follows, with the first parameter indicating the number of rows to be displayed, and the second number indicating the limit of the natural number to be displayed. FLOYDSTRIANGLE(20,34) 217. $> FLOYDSTRIANGLE(1..3) 7.

Fractals-Mandelbrot

Lissajous

Graphing Data curve

Financial Functions

Statistical Functions:

Appendices

Appendix I Operators

Appendix II: Simple Set and Objects

Set

Associative Set/Objects

Appendix III: Javascript and z^3

Using Set Member Functions

Appendix IV Series Generation

Arithmetic Series

Geometric Series

Prepacked Series

Date Series

Alphabet Series

Appendix V Member Functions

How to work with zcubes