Z3Help
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. 8. $> 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. 9. $> 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): 13. $> [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. 14. $> [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. 15. $> [1,2..3] 1 2 3 16. $> [1..3,1..3] 1 2 3 1 2 3 17. $> [1..2,1..5] 1 2 1 2 3 4 5 18. $> [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:
19. $> |4|
| 1 | 0 | 0 | 0 | |
| 0 | 1 | 0 | 0 | |
| 0 | 0 | 1 | 0 | |
| 0 | 0 | 0 | 1 |