Difference between revisions of "RvsZ3"

From ZCubes Wiki
Jump to navigation Jump to search
Line 8: Line 8:
 
To set up a vector named x, say, consisting of five numbers, namely 10.4, 5.6, 3.1, 6.4 and 21.7, use the R command
 
To set up a vector named x, say, consisting of five numbers, namely 10.4, 5.6, 3.1, 6.4 and 21.7, use the R command
  
  > x <- c(10.4, 5.6, 3.1, 6.4, 21.7)
+
  ''> x <- c(10.4, 5.6, 3.1, 6.4, 21.7)''
  
 
Z3 command to set up a vector is:
 
Z3 command to set up a vector is:
Line 19: Line 19:
 
Assignment can also be made using the function ASSIGN(). An equivalent way of making the same assignment as above is with:
 
Assignment can also be made using the function ASSIGN(). An equivalent way of making the same assignment as above is with:
 
In R,
 
In R,
  > assign("x", c(10.4, 5.6, 3.1, 6.4, 21.7))
+
  ''> assign("x", c(10.4, 5.6, 3.1, 6.4, 21.7))''
  
 
In Z3, use the "ASSIGN" function as:
 
In Z3, use the "ASSIGN" function as:
 
  ASSIGN("x", [10.4, 5.6, 3.1, 6.4, 21.7])
 
  ASSIGN("x", [10.4, 5.6, 3.1, 6.4, 21.7])
  
Assignments can also be made in the other direction, using the obvious change in theassignment operator.  
+
Assignments can also be made in the other direction, using the obvious change in the assignment operator.  
 
So the same assignment could be made using
 
So the same assignment could be made using
 
  [10.4, 5.6, 3.1, 6.4, 21.7]==>x  
 
  [10.4, 5.6, 3.1, 6.4, 21.7]==>x  
  
 
The reciprocals of the above five values for x in R,
 
The reciprocals of the above five values for x in R,
> 1/x
+
''> 1/x''
 +
 
 
In Z3, We can use the function called Reciprocal,
 
In Z3, We can use the function called Reciprocal,
  '''RECIPROCAL(x)''' (the value of x is [10.4, 5.6, 3.1, 6.4, 21.7]
+
  RECIPROCAL(x) (the value of x is [10.4, 5.6, 3.1, 6.4, 21.7]  
  
 
Also we can use directly,
 
Also we can use directly,

Revision as of 00:49, 7 July 2021

Comparison of R vs Z3

Simple manipulations; numbers and vectors

Vectors and assignment

Z3 operates on named data structures. The simplest such structure is the numeric vector,which is a single entity consisting of an ordered collection of numbers. 

To set up a vector named x, say, consisting of five numbers, namely 10.4, 5.6, 3.1, 6.4 and 21.7, use the R command

> x <- c(10.4, 5.6, 3.1, 6.4, 21.7)

Z3 command to set up a vector is:

x<==[10.4, 5.6, 3.1, 6.4, 21.7];

Alternatively we can use the simple "=" also.

 x=[10.4, 5.6, 3.1, 6.4, 21.7]

Assignment can also be made using the function ASSIGN(). An equivalent way of making the same assignment as above is with: In R,

> assign("x", c(10.4, 5.6, 3.1, 6.4, 21.7))

In Z3, use the "ASSIGN" function as:

ASSIGN("x", [10.4, 5.6, 3.1, 6.4, 21.7])

Assignments can also be made in the other direction, using the obvious change in the assignment operator. So the same assignment could be made using

[10.4, 5.6, 3.1, 6.4, 21.7]==>x 

The reciprocals of the above five values for x in R,

> 1/x

In Z3, We can use the function called Reciprocal,

RECIPROCAL(x) (the value of x is [10.4, 5.6, 3.1, 6.4, 21.7] 

Also we can use directly,

([10.4,5.6,3.1,6.4,21.7]<>d40)@(x=>1/x)

The further assignment

> y <- c(x, 0, x)

would create a vector y with 11 entries consisting of two copies of x with a zero in the middle place.

Vector arithmetic



Please check back in couple of days. We are updating the page.