Difference between revisions of "RvsZ3"
Line 43: | Line 43: | ||
===Vector arithmetic=== | ===Vector arithmetic=== | ||
− | + | ||
Vectors can be used in arithmetic expressions, in which case the operations are performed element by element. Vectors occurring in the same expression need not all be of the same length. If they are not, the value of the expression is a vector with the same length as the longest vector which occurs in the expression. So with the above assignments the R command | Vectors can be used in arithmetic expressions, in which case the operations are performed element by element. Vectors occurring in the same expression need not all be of the same length. If they are not, the value of the expression is a vector with the same length as the longest vector which occurs in the expression. So with the above assignments the R command | ||
+ | |||
''> v <- 2*x + y + 1'' | ''> v <- 2*x + y + 1'' | ||
generates a new vector v of length 11 constructed by adding together, element by element, 2*x repeated 2.2 times, y repeated just once, and 1 repeated 11 times. | generates a new vector v of length 11 constructed by adding together, element by element, 2*x repeated 2.2 times, y repeated just once, and 1 repeated 11 times. | ||
Line 52: | Line 53: | ||
In Z3 the elementary arithmetic operators are the usual +, -, *, / and ^ for raising to a power. Also we can use the functions SUM,SUB,PRODUCT,DIVIDE and POWER instead of using arithmetic operators. | In Z3 the elementary arithmetic operators are the usual +, -, *, / and ^ for raising to a power. Also we can use the functions SUM,SUB,PRODUCT,DIVIDE and POWER instead of using arithmetic operators. | ||
− | In addition all of the common arithmetic functions are available. LOG, EXP, SQRT, SIN, COS, TAN, SEC,COSEC,COTAN, Hyperbolic functions and so on. For trignometric functions we can find the values in Deg and Radians also. | + | |
+ | In addition all of the common arithmetic functions are available. LOG, EXP, SQRT, SIN, COS, TAN, SEC,COSEC,COTAN, Hyperbolic functions and so on. For trignometric functions we can find the values in Deg and Radians also. | ||
+ | |||
MAX and MIN select the largest and smallest elements of a vector respectively. | MAX and MIN select the largest and smallest elements of a vector respectively. | ||
Line 60: | Line 63: | ||
In Z3,to find the mean value we can use function called MEAN(x), AVG(x) or AVERAGE(x). | In Z3,to find the mean value we can use function called MEAN(x), AVG(x) or AVERAGE(x). | ||
+ | |||
In R,sort(x) returns a vector of the same size as x with the elements arranged in increasing order; | In R,sort(x) returns a vector of the same size as x with the elements arranged in increasing order; | ||
SORTING(x) returns the vector in increasing order in Z3. | SORTING(x) returns the vector in increasing order in Z3. |
Revision as of 04:12, 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
Vectors can be used in arithmetic expressions, in which case the operations are performed element by element. Vectors occurring in the same expression need not all be of the same length. If they are not, the value of the expression is a vector with the same length as the longest vector which occurs in the expression. So with the above assignments the R command
> v <- 2*x + y + 1
generates a new vector v of length 11 constructed by adding together, element by element, 2*x repeated 2.2 times, y repeated just once, and 1 repeated 11 times.
With the same Assignment Z3 command is.
v=2*x+y+1
In Z3 the elementary arithmetic operators are the usual +, -, *, / and ^ for raising to a power. Also we can use the functions SUM,SUB,PRODUCT,DIVIDE and POWER instead of using arithmetic operators.
In addition all of the common arithmetic functions are available. LOG, EXP, SQRT, SIN, COS, TAN, SEC,COSEC,COTAN, Hyperbolic functions and so on. For trignometric functions we can find the values in Deg and Radians also.
MAX and MIN select the largest and smallest elements of a vector respectively.
In R,two statistical functions are mean(x) which calculates the sample mean, which is the same as sum(x)/length(x), and var(x) which gives
sum((x-mean(x))^2)/(length(x)-1)
or sample variance.
In Z3,to find the mean value we can use function called MEAN(x), AVG(x) or AVERAGE(x).
In R,sort(x) returns a vector of the same size as x with the elements arranged in increasing order; SORTING(x) returns the vector in increasing order in Z3.
Please check back in couple of days. We are updating the page.