Joe Riel

9660 Reputation

23 Badges

20 years, 17 days

MaplePrimes Activity


These are replies submitted by Joe Riel

f := z + conjugate(z)^2;
frontend(diff, [f,conjugate(z)]);  
                                        _
                                      2 z

A trivial "bug" with that procedure is it returns 9 if the input is 0. 

I usually avoid the conditional when computing a "shifted" modulus:

  modp(a-1, 9) + 1

A trivial "bug" with that procedure is it returns 9 if the input is 0. 

I usually avoid the conditional when computing a "shifted" modulus:

  modp(a-1, 9) + 1

As you suspect, using a constant value is not correct. Following is the simulation I put together to check my solution. This plots the expected value as a function of the threshold versus a competition using the optimal strategy, that is, using the golden mean as the threshold.  As you will see, the maximum occurs at that golden mean (more or less).

picks := proc(n::posint)
    rtable(1..n, 1..2
           , frandom(0..1, 1)
           , 'subtype = Array'
           , 'datatype=float[8]'
          );
end proc:

simulate := proc( th1::float, th2::float, num::posint
                  , picks1 :: Array(datatype=float[8])
                  , picks2 :: Array(datatype=float[8])
                )
option autocompile;
local i,tot,pick1,pick2;
    tot := 0;
    for i to num do
        pick1 := picks1[i,1];
        if pick1 < th1 then
            pick1 := picks1[i,2];
        end if;
        pick2 := picks2[i,1];
        if pick2 < th2 then
            pick2 := picks2[i,2];
        end if;
        if pick1 >= pick2 then
            tot := tot + 1;
        end if;
    end do;
    tot;
end proc:

num := 10^6:
picks1 := picks(num):
picks2 := picks(num):

sim := proc()
local phi,f,x;
global num,picks1,picks2;
    phi := (1+sqrt(5))/2:
    f := x -> evalf(simulate(x,  evalf(1/phi), num, picks1, picks2 )/num):
    print(plot([seq]([x,f(x)], x = 0.61 .. 0.63, 0.0001)));
    NULL;
end proc:

sim();

Represent a line through the origin with slope m by the vector [1,m].  Two lines are perpendicular when their dot product is 0.

v1 := [1,m1]:
v2 := [1,m2]:
perp := inner(v1,v2) = 0;
                             perp := 1+m1*m2 = 0
isolate(perp, m1*m2);
                              m1*m2 = -1

Represent a line through the origin with slope m by the vector [1,m].  Two lines are perpendicular when their dot product is 0.

v1 := [1,m1]:
v2 := [1,m2]:
perp := inner(v1,v2) = 0;
                             perp := 1+m1*m2 = 0
isolate(perp, m1*m2);
                              m1*m2 = -1

Yes, your interpretation is correct.  There is a presumption that rotating a line 90 degrees makes it perpendicular to the original ...

Yes, your interpretation is correct.  There is a presumption that rotating a line 90 degrees makes it perpendicular to the original ...

1/2*(x1+x2) is the expected value [of a single "pick"] given that the value is between x1 and x2.  So 1/2*(x+1) is the expected value given that the value is between x and 1, that is, greater than x. Using integrals one can compute it as

int(xx, xx = x..1)/(1-x)

however, it is easier to compute this geometrically.  That is, this is just the mean value of a linear function, which always occur at the midpoint and is equal to the arithmetic mean of the endpoints.  Hence 1/2*(x+1).

It is the inverse of the golden mean.

 

Hi Alex.  I've lost any notes I might have made for that solution, however, it is easy enough to redo.  The method I use here is not rigorous, nor a proof, but is simpler and may be easier to understand than a more thorough analysis.

First, it should be clear that there is only one reasonable strategy, that is, find a threshold, say x, such that if the first number is less than x pick again, otherwise use the first number. Given that, we compute the expected value:

 E = P(n1<x)*E(n2) + (1-P(n1<x))*E(n1)
    = x*1/2           + (1-x)*(1/2*(x+1))
    = x/2 + (1-x^2)/2

Now we reasonably---but incorrectly---assume that optimal value of x is the one that maximizes E.  This maximal value is easily found,

  xsol := solve(diff(E,x)=0, {x});
                       xsol := {x = 1/2}

 Emax := subs(xsol, E);
                       Emax := 5/8

Suppose now that we are playing against an opponent who always achieves this value, that is, who uses this strategy and whose first pick is always 5/8 and so keeps that value.  Clearly if we get a number less than 5/8 for the first pick, we should then pick again otherwise we are guaranteed to lose.  So let us use 5/8, rather than 1/2, as our threshold.  Our probability of winning against this opponent is

  Pwin = P(n1>5/8) + P(n1<=5/8)*P(n2>5/8) = 3/8 + (5/8)*(3/8) = 39/64

which is greater than 1/2 and so is a winning strategy.  This demonstrates that maximizing the expected value is not necessarily the optimal strategy.

Now we iterate this technique.  That is, the expected value of using 5/8 as a threshold is E(5/8) = 79/128.  If we play against an opponent that always achieves that value, then our threshold should be x = E(5/8).   Now comes the insightful part.  That is, the optimal value must occur when x = E(x).  Solving that gives

solve(E = x, {x});
                  {x = -1/2*5^(1/2)-1/2}, {x = 1/2*5^(1/2)-1/2}

The root we want is the positive one, x = 1/2*5^(1/2)-1/2.

 

 

 

I'm fairly sure what he means is that he's already run the script with interface(prettyprint=1) and would like to convert that output to a form readable by Maple.  I doubt that there is a reasonable way to do that.  You'll have to rerun the script, but prepend the command interface(prettyprint=0). 

I'm fairly sure what he means is that he's already run the script with interface(prettyprint=1) and would like to convert that output to a form readable by Maple.  I doubt that there is a reasonable way to do that.  You'll have to rerun the script, but prepend the command interface(prettyprint=0). 

One could use something like the following to make such a situation slightly more tractable:

frontend(proc() global y; y := args; args end, [f(x)+g(x)+h(x)]):
y;
                                 O + O + O
subsindets(y, `local`, x -> `tools/genglobal`[1](O));
                                 O1 + O2 + O3

But madness it is...

One could use something like the following to make such a situation slightly more tractable:

frontend(proc() global y; y := args; args end, [f(x)+g(x)+h(x)]):
y;
                                 O + O + O
subsindets(y, `local`, x -> `tools/genglobal`[1](O));
                                 O1 + O2 + O3

But madness it is...

First 112 113 114 115 116 117 118 Last Page 114 of 195