Usable Functions: abs(a) / |a| log(a) / log of a base e acos(a) / arc cosine of a max(a,b) asin(a) / arc sine of a min(a,b) atan(a) / arc tangent of a pow(a,b) / a to the power b atan2(a,b) / arc tangent of a/b random() / random n. in [0,1) ceil(a) / integer closest to a not < a round(a) / integer closest to a cos(a) / cosine of a sin(a) / sine of a exp(a) / exponential of a sqrt(a) / square root of a floor(a) / integer closest to a not > a tan(a) / tangent of a PI / π Note: M%%N is the remainder of M/N, != is "not equal" |
Examples [of TruthValue()]: # The probability that the roll of two balanced dice is 7 U1 = floor(random()*6+1); U2 = floor(random()*6+1); if (U1+U2==7) {V = 1} else {V = 0} # -> 1/6 # # The probability that throwing a pair of balanced dice their difference is 1 U1 = floor(random()*6+1); U2 = floor(random()*6+1); if (abs(U1-U2)==1) {V = 1} else {V = 0} # -> 5/18 # # The probability that 1/2 < random+random < 3/2 U1=random(); U2 = random(); if (U1+U2<1.5 & u1+U2>0.5) {V = 1} else {V = 0} # -> 3/4 # # The probability (by drawing 10 cards from a 40-pack deck) to get at least a # tris (ie 3 or 4 cards of the same value); try n = 5000, 10000, 20000, ... # # I put in random order the first 40 positive integers in C. I consider the numbers # from 1 to 10, ..., from 31 to 40 if they were the cards of the same suit # If C is 37 or 17 ... C%10 is 7 var C = new Array(40); var N = new Array(10); C[1]=floor(random()*40+1); for(i=2; i <= 40; i++) { U=0; while(U < 1) { C[i]=floor(random()*40+1); U=1; for(j=1; j < i; j++) { if(C[j]==C[i]) {U=0} } } } V=0; for(i=1; i<=10; i++) {N[i]=0}; i=1; while(i<11) { x=1+C[i]%10; N[x]=N[x]+1; if(N[x]==3) {i=11; V=1} else {i=i+1} } # # -> 38.4...% (it is not easy to find the exact value; with the script you can arrive for example to 38.452 +/- 0.129; # with R you can arrive to 38.436 +/- 0.047 (if you don't want to take too long) # # # The probability (by drawing 5 cards from a 52-pack deck) to get five cards all of the same suit # var C = new Array(52); C[1]=floor(random()*52+1); for(i=2; i <= 52; i++) { U=0; while(U < 1) { C[i]=floor(random()*52+1); U=1; for(j=1; j < i; j++) { if(C[j]==C[i]) {U=0} } } } V=1; A = floor(C[1]/13); i=2; while(i<=5) { if( floor(C[i]/13) != A ) {V=0; i=6} else {i=i+1} } # # -> about 0.2% # You can find - think about it - that the probability is 5148/choose(52,5) = 0.1980792% = 165/833 # # # # We have a floor made of parallel strips of wood and we drop a needle onto the floor. # The strips are large 2 dm; the length of the needle is 1 dm. # The probability that the needle will lie across a line between two strips: # D = random()*2*PI; h = random()*2; if(2-h < h) {h = 2-h}; H = abs(cos(D)/2); V=0; if(h < H) {V=1} # # -> 1/π (Proof) (n=20480000 31.825449218750002% +/- 0.030878393892865983%, # reciprocal: between 3.139094 and 3.145191) # This is the Buffon's needle problem (posed by Comte de Buffon in the 18th century). # The results 1/F of some experiments in which the relative frequency F was calculated: # Wolf (year 1850), tossing a needle 5000 times, 3.1596. Smith (1855), 3204 times, 3.1553 # Fox (1894), 1120 times, 3.1419. Lazzarini (1901), 3408 times, 3.1415929. # All these are a string of lies. #