Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Random Algebra

Name: Anonymous 2016-08-05 16:07

Given functions
f(a,b) = random(a) < random(b)
and
g(a,b) = a < random(a+b)

which if of them is more likely to result into 1, if random(n) returns arbitrary number in range of [0;n)?

Justify your answer.

Name: Anonymous 2016-08-05 17:10

f = g, because a < random(a+b) = a-random(a) < random(b)

Name: Anonymous 2016-08-05 17:38

(defun f (a b)
(if (< (random a) (random b)) 1 0))

(defun g (a b)
(if (< a (random b)) 1 0))

(defun count-fn-one (fn up-to)
"Counts how many times FN is 1"
(loop for i from 1 to up-to summing
(loop for j from 1 to up-to
summing (funcall fn i j))))

(defun which-is-more-one? (iters)
(if (> (count-fn-one #'f iters)
(count-fn-one #'g iters))
'F 'G))


...and the winner is:

* (which-is-more-one? 100)
F
* (which-is-more-one? 1000)
F
* (which-is-more-one? 10000)
F

Name: Anonymous 2016-08-05 17:50

>>3
BYTH MUSTED: lispers are no math geniuses and LISP wont make you smarter than average nigger.

Name: Anonymous 2016-08-05 17:54

>>4
what's wrong with it?

Name: Anonymous 2016-08-05 18:04

consider f(n,n) and g(n,n)

random(n) < random(n) has 50% chance of being true
n < random(2n) has 50% chance of being true as well

so f(n,n) = g(n,n)

Name: Anonymous 2016-08-05 20:12

Suppose a < b, what is the probability that random(a) < random(b)?

First let x < b, then the probability x < random(b) is (b-x)/b = 1 - x/b

So summing over all possible values of x uniformly, probability = 1/a integral x = 0 to a, 1 - x/b dx = a^2/a (1 - 1 / b)

idk?

Name: Anonymous 2016-08-05 20:21

oh wait, = 1 - a / 2b

Name: Anonymous 2016-08-05 21:51

>>7
PROBABILITY_OF(random(a+b)) = PROBABILITY_OF(random(a) + random(b))

Name: Anonymous 2016-08-05 23:19

>>9
oh so they are equal!

Name: Anonymous 2016-08-05 23:33

>>9
random(a+b) = random(a) + random(b) cannot be guaranteed to be true

Name: Anonymous 2016-08-05 23:43

>>10-11
you are fucking retarded

Name: Anonymous 2016-08-05 23:57

>>4
lisp isn't supposed to make you smarter
it's just a bigger lever than C

Name: Anonymous 2016-08-06 0:05

>>12
no, you are the retard!

Name: Anonymous 2016-08-06 0:35

>>13
ignore him, he's the one guy here who always gets triggered by lisp

Name: Anonymous 2016-08-06 2:09

random
Shalom!

Name: Anonymous 2016-08-06 3:41

Randomness is a jewish conspiracy now?

Name: Anonymous 2016-08-06 5:38

>>17 (((RDRAND))) (((RDSEED)))

Name: Anonymous 2016-08-06 11:58

ITT mental midgets

Name: Anonymous 2016-08-06 12:10

>>19
ITT: People who don't solve your homework

Name: Anonymous 2016-08-06 14:48

>>9,11
Just fuck off back to the ima/g/ereddits already, ``please.''

Name: Anonymous 2016-08-06 17:04

>>1
``
random(n) = [0;n)

random(n+m) = [0;n+m)
random(n) + random(m) = [0;n) + [0;m)
random(n+m) = [0;n) + [0;m)

f(a,b) = random(a) < random(b)
[0;a) < [0;b)

g(a,b) = a < random(a+b)
a < [0;a+b)
a < [0;a) + [0;b)
a - [0;a) < [0;b)
[0;a) < [0;b)

f(a,b) = g(a,b)
``

Name: Anonymous 2016-08-06 17:12

>>3
This is incorrect for two reasons.
One, you defined g incorrectly. It got random(a+b), not random(b).
Two, it's only probability check for three different randoms. You should have generated random(a) and random(b) first, then feed them to simplified f and g functions*, knowing random(a+b) is equal to random(a)+random(b). Only then you would get realistic results.

*
'a = random(a)
'b = random(b)
'f('a,'b) = 'a < 'b
'g(a,'a+'b) = a < 'a+'b

Name: Anonymous 2016-08-06 17:49

>>21
you're a retard

Name: Anonymous 2016-08-06 19:37

/prog/ is now officially proven to be full of inborn retards incapable of solving even elementary school problems, with exception of maybe one or two visitors. No wonder you vote Trump.

Name: Anonymous 2016-08-06 19:58

>>23
Alright fixed. Looks like you're right.

(defun fxn (a b)
(if (< a b) 1 0))

(defun count-ones (up-to)
(let ((f-count 0)
(g-count 0)
(a* 0)
(b* 0))
(dotimes (a up-to)
(progn (setf a* (random (1+ a)))
(dotimes (b up-to)
(progn (setf b* (random (1+ b)))
(setf f-count (+ f-count (fxn a* b*)))
(setf g-count (+ g-count (fxn a (+ a* b*))))))
(return `((F . ,f-count) (G . ,g-count)))))))

(defun which-is-more-one? (iters)
(let* ((result (count-ones iters))
(f-count (cdr (assoc 'F result)))
(g-count (cdr (assoc 'G result))))
(cond ((> f-count g-count) 'F)
((< f-count g-count) 'G)
(t '(F = G)))))


And testing we see they're the same

* (count-ones 100)
((F . 98) (G . 98))
* (count-ones 1000)
((F . 994) (G . 994))
* (count-ones 10000)
((F . 9991) (G . 9991))
* (which-is-more-one? 100000)
(F = G)

Name: Anonymous 2016-08-06 20:30

>>25
if the people here were idiots wouldn't they vote hillary instead?

Name: Anonymous 2016-08-06 21:31

>>27
Unless you're a toilet scrubbing mental midget, you wont be competing with mexicans for the unqualified jobs

Name: Anonymous 2016-08-06 21:40

>>28
Oh, I suppose H1B abuse is fine with you.

Name: Anonymous 2016-08-06 21:41

>>25
But /prog/ votes Hillary.

Name: Anonymous 2016-08-06 21:42

>>28
that's not really the decider

Name: Anonymous 2016-08-06 21:53

>>29
Mexicans illegals don't have higher education. They work in fields or in construction. Programmers without educations usually do freelance web coding stuff and live in some cheap country, like Mexico itself (pro-tip: USA is not the cheapest country to live in).

Name: Anonymous 2016-08-06 21:56

>>32
Only Ukraine would be cheaper than Mexico and have passable IT infrastructure at the same time. Yet most people in Ukraine don't speak english, as they are being forced to learn russian instead. So huge economic opportunity lost.

Name: Anonymous 2016-08-06 22:00

what's the deal with insulting people who can't easily solve the problem?

is somebody insecure about their problem solving ability?

Name: Anonymous 2016-08-06 22:02

Name: Anonymous 2016-08-06 22:10

>>35
The problem with that claim is that most "fat shaming" doesn't promote a desire for self-improvement, it just promotes low self-worth. Pointing out that losing weight will make you healthier and make you feel better about yourself is one thing, but that's not the form that "fat shaming" usually takes.

Name: Anonymous 2016-08-07 2:27

[0 ; a + b] - a > 0 -> g

[-a; b] > 0 -> g

(~?) p(G) = b / (a + b)

1,1 = 0.5, 2,1 = 0.33
0,0 = 0, 1,2 = 0.66

[0 ; b] - [0 ; a] > 0 -> f

(~?) p(F) = (0.5 * b) / a

1,1 = 0.5, 2,1 = 0.25

0,0 = 0, 1,2 = 0.75?

Name: Anonymous 2016-08-07 7:21

random(a + b) = random(a) + random(b) <-- Unproven
a < random(a) + random(b)
= a - random(a) < random(b)
= random(a) < random(b)

(defun random-a+b (n)
"By how much larger is random(a+b) than random(a)+random(b)?"
(float (/ (loop for a from 1 to n sum
(loop for b from 1 to n
summing (- (random (+ a b))
(+ (random a)
(random b)))))
(* n n))))

* (random-a+b 10000)
0.8115202

Name: Anonymous 2016-08-07 9:43

>>38
and..... lispers keep being reddit laughing-stock!

Name: Anonymous 2016-08-07 10:41

>>39
pls no bully

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List