![]() |
N.S.B. Cosmic Center |
![]() |
JavaScript & MathScript Interactive Document Generator-Demo-07This document is generated by N.S.B. JavaScript & MathScript Interactive Document Generator version 001. Introduction to N.S.B. JavaScript & MathScript Interactive Document Generator MathScript Functions (cont.) We continue exploring the MathScript functions that can be used for general symbolic manipulations. The function join() can be used to combine the elements of two function with the same head. Let us first write and execute this: input(1)=> join[f,g]output(1)=> join[f, g]Notice that input(2)=> %/.{f=>F[a,b], g=>F[x,y,z]}output(2)=> F[a, b, x, y, z]So we obtained a function that joins input(3)=> join[x+2y, 3x-4y+z]output(3)=> x+(2*y)+(3*x)+((-4)*y)+zinput(4)=> %+2zoutput(4)=> (4*x)+((-2)*y)+(3*z)input(5)=> join[x y^2 z, 2 z x]output(5)=> x*(y^2)*z*2*x*zinput(6)=> %*1output(6)=> 2*(x^2)*(y^2)*(z^2)You should have noticed that The function input(7)=> %2 // reverseoutput(7)=> F[z, y, x, b, a]The functions input(8)=> %// rotlftoutput(8)=> F[y, x, b, a, z]input(9)=> %// rotlftoutput(9)=> F[x, b, a, z, y]input(10)=> %// rotrgtoutput(10)=> F[y, x, b, a, z]input(11)=> %// rotationsoutput(11)=> {F[y, x, b, a, z], F[x, b, a, z, y], F[b, a, z, y, x], F[a, z, y, x, b], F[z, y, x, b, a]}In the above array, we have five different orders of elements, neither of which is a sorted order. This gives us the opportunity to apply the function input(12)=> map[isSorted, %]output(12)=> {false, false, false, false, false}input(13)=> map[sort, %%]output(13)=> {F[a, b, x, y, z], F[a, b, x, y, z], F[a, b, x, y, z], F[a, b, x, y, z], F[a, b, x, y, z]}input(14)=> map[isSorted, %]output(14)=> {true, true, true, true, true}The function input(15)=> {x,y,z,w}output(15)=> {x, y, z, w}input(16)=> %//permutationsoutput(16)=> {{x, y, z, w}, {y, x, z, w}, {y, z, x, w}, {y, z, w, x}, {x, z, y, w}, {z, x, y, w}, {z, y, x, w}, {z, y, w, x}, {x, z, w, y}, {z, x, w, y}, {z, w, x, y}, {z, w, y, x}, {x, y, w, z}, {y, x, w, z}, {y, w, x, z}, {y, w, z, x}, {x, w, y, z}, {w, x, y, z}, {w, y, x, z}, {w, y, z, x}, {x, w, z, y}, {w, x, z, y}, {w, z, x, y}, {w, z, y, x}}The function input(17)=> map[signature, %]output(17)=> {-1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1}In the above result, we see that the number of positive permutations is equal to the number of negative ones. To check this, it is our opportunity to use the function input(18)=> countMemberOf[1,%17]output(18)=> 12input(19)=> countMemberOf[-1,%17]output(19)=> 12Before proceeding to the next demodoc, where we shall continue to introduce more functions and features of MathScript, why don't you practice using MathScript live by clicking the program page below, and apply what you learned on this page, whichever way you like. Program PageNext |
||
![]() |
Home |
![]() |