Z^3 Language Documentation

<< Z3 home

Motivation

The power of a language is almost entirely in the notations and simplifications that are provided. Kenneth Iverson in his paper (http://www.eecg.toronto.edu/~jzhu/csc326/readings/iverson.pdf Notation as a Tool of Thought) details the importance of good notation to assist making thought easier.

z^3 expands on Javascript notations, and then enhances the notation to allow easy expression and simplicity.

Apart from a rich operator and notation set, the motivation of the z^3 language is to be as close to normally used mathematical notation (such as Σ, !, .. ,etc.) as commonly used.

Language Paradigms and Platforms

Languages are typically designed with one paradigm in mind. However, this limits the use of language. For example, functional programming is powerful, but languages of this flavor are rarely used in production systems. z^3 takes a different approach. It provides a chameleon like model, which allows the language to switch among multiple paradigms.

The language supports Imperative, Functional, Array-based, Multi-Platform, Spreadsheet-Like and Object-Oriented approaches, in a beautiful medium, enabled with superior notations.

z^3 conceptually brings the simplicity and power of spreadsheets to programs. In fact, z^3 contains all the functions that are native to commonly available Spreadsheets. z^3 can run in a browser client, desktop, server, or web-server. The platforms supported include Windows, Mac, Linux, etc. and even iOT devices.

Language Compatibility

z^3 translates/transpiles itself to Javascript before execution. The language keeps full compatibility with Javascript, because of which simple Javascript seamlessly runs without any changes required. This implies any program written in z^3 can use all Javascript libraries available. Additionally, on the server and desktop, z^3 has access to the entire npm.js ecosystem of libraries to adopt.

Please keep in mind that you can use any paradigm you are familiar with in Javascript in z^3. The notations indicated below are in additional to conventional notations that you may already be familiar with.

Operators

Assignment Operators

Of course, a simple assignment can be as simple as

a = 23;

as in Javascript, because of full backward compatibility.

In addition, z^3 allows assigning values to the left as well as to the right using <== and ==> operators. This allows better expressivity for more logical thinking.

a <== 23; 23 ==> a;

a <== 23; is equivalent to a=23; and both notations are equivalent in z^3.


:= : Quick Function Creation Operator

The quick function creation operator in z^3 ( := ) is similar to the => operator in Javascript. However, the advantage of := operator is that the parameters are not named explicitly (and is autodetected). For example to define a function such as v=u+a*t, v:=u+a*t is sufficient, and the parameters u, a and t are auto detected.

However, the fastest way to create a function is the "! operator Fabulous_!_Operator that can make any string into a function, without having to specify the paramters.

Any variable names with lowercase (such as ab, cde, etc) with less than 3 characters in length, is considered to be a local variable. All other names (including any longer variable lowercase names) are checked to see if there is a similar name already in a higher or global scope, and in which case, will not be treated as a local variable.

The => function definition operator in normal Javascript, differs slightly. Hence to define a function such as v=u+a*t, in Javascript (as well as z^3), it would require us to indicate it as v=(u,a,t)=>u+a*t;

The := operator in z^3 hence allows avoiding explicitly repeating the parameter names again in the argument list and function body.

v:=u+a*t and v=(u,a,t)=>u+a*t; both are equivalent to

  function v(u,a,t)
  { 
     return(u+a*t)
  }

@: Function Apply Operator

1..100@SIN

~: Transpose Operator


[[[1..10]~]~]~

↑ and ↓: Ascending and Descending Operator

	
	MAGICSQUARE(5)!
	(1..100)↓
	(1..100)↑

⧓,⧒,⧒ and ⋈: Between Operators

	a=-1;
	⧓(1,a,30)
	a=29;	
	⧓(1,a,30) //between g
	
	a=31;
	⧒(1,a,30) //xlbetween g
	a=30;
	⧒(1,a,30) //xlbetween g
	
	⧒(1,2,30) // xlb g
	⧒(1,1,30)
	
	a=29;
	⋈(1,-1..31,30);
	
	⧓(1,-1..5,4);
	
	[
		⧓(1,1,30),
		⧓(1,0,30),
		⧓(1,10,30),
		⧓(1,31,30),
		⧑(1,29,30),
		⧑(1,30,30),
		⧑(1,1,30),
		⧑(1,30,30),
		⋈(1,1,30),
		⋈(1,3,30)
	]

√: Square Root, Cube Root, Fourth Root and Nth Root Operators

	√(3+34)
	∛(27.01)
	√√64
	ROOTNTH(1..10,4) 
		// root is first parameter
	NTHROOT(1..10,4)
		// root is second parameter
	
	NTHROOT(1..100,2)
	NTHROOT(1..100,4)
	ROOTNTH(1..100,2)
	ROOTNTH(1..100,4)
	3√81

Logical Statements

If Statements

    a=3;
    (a<0)::{"whatever"},
    {
		!(a>4)::
			{"whateverelse"},
			{"whateverelseleft"}
    }  
	
    (a>4)::
	{"whateverelse"},
	{"whateverelseleft"}
			

   (b<0)::b=34,b=345;
   is equivalent to 
   if(b<0)
   {
      b=34;
   }
   else
   {
      b=345;
   }

   Both notations are equivalent and will work in z^3.

   Examples with else and else if. Note the , after each clause of if. 
   else clause does not have a condition, where as else if has a condition with ::
	x=34;
	(x<5)::	{x++}, 
	(x>5)::	{x--},
        	{x=x*2};
	x; 

   Same example written with more whitespace to show the structure.
	x=34;
	(x<5)::	
		{
			x++
		},
	(x>5)::	
		{
			x--
		},
        {
			x=x*2
		};
	x; 

        // because instead of if
        a=11;
	b=45;
	because(a<b)
	{
		a++
		OUTPUT(a)
	}


Switch Statements

Apart from the conventional Javascript switch statement syntax, z^3 enhances language simplicity with a new style.

The new z^3 switch statements syntax is as follows.


	discriminant:::
	{
           x, y:: 
        	  /*statements to be executed if x or y is true*/
        	  /*Break is automatically added. */
        	  /*Simply add an empty statement using a simple extra semicolon (;)) */
            ,
	   z:: 
        	  /*statements to be executed if z is true*/
            ,
	   default::
	}
For example,
	b=0;
	c=343;
	fruits="mango";
	fruits:::
	{
        "apple","tomato":: 
        	   b++;
        	   c=3.4;
           ,
	"mango":: 
        	   b=34905; 
                
            ,
        default::
        	
                b=45.6;
            
	}
	[b,c];  
	
	switch(a)
	{
		case b:
		case c:
			break;
		default:
			break;
	}

Both notations work in z^3

Loops

	a=1;
	do
	{
		a++
	}
	until(a>20); // do while(!condition)
	a; // here this will be 21, since !condition is checked like a do while loop.
	
	
	
	a=11;
	do
	{
		a++
	}
	unless(a==11); 
	a;

Function Declarations

	function y(x)
	{
		∵(x<345)
		{
			∴(x+3434)
		}
		∵(x>345)
		{
			∴(x-3434)
		}
	}
	y(13);

The letter Ƒ can also be used instead of the full term function.
	
	Ƒ y(x)
	{
		∵(x<345)
		{
			∴(x+3434)
		}
		∵(x>345)
		{
			∴(x-3434)
		}
	}
	y(13);

Existential Quantification

	a=1..100;
	∀a("x<810")
	∃a("x<810")
	∄a("x<810")
	
	a=1..100;
	[∀a("x<810"),∃a("x<810"),∄a("x<810")]
	a=1..100;
	[∀a("x<810"),∃a("x<810"),(!∄a("x<0"))]
	
	a=1..100;
	b= ∀a("y*2<200");
	b.result
	
	a=1..100;
	b= ∀a("y*2<=50");
	a.pick(b.result)
	
	//make a pick operator based on a similar array of true false. or non-existant to get the values out.
	//PICK
	
	a=1..100;
	b= ∀a("y*2<50");
	a.pick(b.result)
	


List of Operators


+,  -,  *,  /, ^, %	 - Arithmetic Operators
| |    - Array Function and Creation Operator
..     - Arithmetic Series Creation (repeated for increments, leading for iota)
...    - Geometric Series Creation  (repeated for increments, leading for iota)
@      - apply to
#      - Series or Special Case Qualifier for Dates, Calci  Cells, and Sequences, etc. when used as a prefix. #a-z for example.
#      - Dyadic/Binary used for Arrayfying functions, Splitting Strings, Searching and Filtering Arrays, etc.
!      - Factorial. 
!      - When applied to strings, creates a function (lambda) from the string by guessing parameters etc.  For example, 
                 ("x^5+y^4+z^5"!)(2,3,4); 
                 (or) 
                 s="x^5+y^4";
                 g=(s!);
	         g(1,3);

##     - Prefix used to indicate long variable names with spaces. 
         (e.g., ##Speed of the Car=34, which gets translated to SpeedoftheCar = 34;)
<<<    - Member or Variable Assignment
()     - Function Call
[]     - Set Creation
       - Object Set 
       - Set Object Membership
.      - Member Function Dereferencing.	
. mf   - Member Function
.$ mf(function, parameters)   - Element-wise Function Application
.$$ mf (special	        – Row-wise Function Application
.$$$ mf (special) 	– Column-wise Function Application
.$_ mf (special)	- Cumulative Function Application (all)

::     - If
:::    - switch

=     - Assignment to the left
<==   - Assignment to the left
==>   - Assignment to the right
:=    - Quick function definition operator. 

All operators in Javascript, also have the same meaning in z^3, except binary operators such as |, & and ~. 
Binary | is used to indicate matrix boundaries, and is replaced with |||.
Binary & is used to indicate matrix related items, and is replaced with &&&.
Binary ~ is used to indicate matrix transpose, and is replaced with ~~~.

!C! for Combinations
!P! for Permutations


%% (Fractions. Such as 1.2%%3 or 3%%4 etc)
xn (Big Int. Such as 10n)
xd30 (High Accuracy Decimals. Such as 1000d50) 
x+iy (Complex Numbers. Such as 23+34i )

± Sign Function (such as ∏±a for Product of Sign of an array a)

Series Comprehension

Examples

from..to..by
(Arithmetic Progression, separated by spacing)

from..to..intox
(Arithmetic Progression, separated into segments)

1..100..5x
(5 parts)

1..100..5xe
(5 part segments, without end segment)

1..100..5xes
(5 parts, and with the interval spacing as part of the result)

from...to...by
(Geometric Progression, separated by spacing)

from..to..intox
(Geometric Progression, separated into segments)

1...2000..2
1...2000..20x

Terms such as radpiby10 and deg360by45 give series that divide pi or 360deg etc. into pieces as indicated.
0㎭	0.6283185307179586㎭	1.2566370614359172㎭	1.8849555921538759㎭	2.5132741228718345㎭	3.141592653589793㎭	3.7699111843077517㎭	4.39822971502571㎭	5.026548245743669㎭	5.654866776461628㎭	6.283185307179586㎭

0°	45°	90°	135°	180°	225°	270°	315°	360°

radpiby4 gives
0㎭	0.7853981633974483㎭	1.5707963267948966㎭	2.356194490192345㎭	3.141592653589793㎭

Short Cut Keys

CTRL+G - to convert into Greek Code
CTRL+U - Converts SIGMA to Σ
SHIFT+ENTER- Gives Parameter Expansion
Double tap SHIFT - Toggle Capital and Small Letter [Ex: Convert FRACTAL to fractal and vice verse]
CTRL+SPACE - Function Listing

z^3 Notable Features for Simplicity in Programming

Variable Names with Spaces in z^3

Variables with spaces can be used in z^3. Such variables need to be prefixed with ##

Example:

##Value Of Color = 34;

In the background, this is converted to a

ValueOfColor = 34;


Complex Numbers

Complex numbers can be expressed as given below.

SIN((1..10)+ⅈ3)

To type ⅈ, simply type com then (shift+space). The real part can be given in a loop as an array.

In newer versions of Z (4.0+), we can notate a complex number as 1+3i or 2+3j or 54+6k or 34-45i etc.

International Natural Language Script Support

Programs can be written in z^3 using any natural language script. The symbols box on the More section of the code editor can be used to type in from any language supported by Unicode, including emojis. Also mathematical notations such as π can be used as is. To type pi as π, first type pi in the code editor followed by SHIFT+SPACE. Only a few letters (such as alp) is required to type in alpha, for example, α. CTRL+U may be used to enter capital letter: Σ can be entered by sig and CTRL+U.

Unit Conversions

Unit conversions and Unit Of Measures Units are natural part of z^3 language. Read more.

Unit Prefixes

Metrix Prefixes

Y	yotta
Z	zetta
E	exa 
P	peta 
T	tera 
G	giga 
M	mega 
k	kilo 
h	hecto
e	deka 
d	deci 
c	centi
m	milli
u	micro
n	nano
p	pico
f	femto
a	atto 
z	zepto
y	yocto

<< Back to Z3 home