outcomes and payoff in probability games

I am reading probability from AI point of view from book Artificial Intellegence A Modern approach by Russel and Norving. Below is text snippet from chapter 13.

One argument for the axioms of probability, first stated in 1931 by Bruno de Finetti (and translated into English in de Finetti (1993)), is as follows: If an agent has some degree of belief in a proposition a, then the agent should be able to state odds at which it is indifferent to a bet for or against a. Think of it as a game between two agents: Agent 1 states, “my degree of belief in event a is 0.4.” Agent 2 is then free to choose whether to wager for or against a at stakes that are consistent with the stated degree of belief. That is, Agent 2 could choose to accept Agent 1’s bet that a will occur, offering $ 6 against Agent 1’s $ 4. Or Agent 2 could accept Agent 1’s bet that ¬a will occur, offering $ 4 against Agent 1’s $ 6. Then we observe the outcome of a, and whoever is right collects the money. If an agent’s degrees of belief do not accurately reflect the world, then you would expect that it would tend to lose money over the long run to an opposing agent whose beliefs more accurately reflect the state of the world.

If Agent 1 expresses a set of degrees of belief that violate the axioms of probability theory then there is a combination of bets by Agent 2 that guarantees that Agent 1 will lose money every time.

Below shows that if Agent 2 chooses to bet $ 4 on a, $ 3 on b, and $ 2 on ¬(a ∨ b), then Agent 1 always loses money, regardless of the outcomes for a and b. De Finetti’s theorem implies that no rational agent can have beliefs that violate the axioms of probability

enter image description here

My question is how we got values inf last column for example a,b column how we got -6, -7 an 2. Kindly explain.

Thanks for your time

How to add a keyboard shortcut to open a Palette

I would like to add a hotkey or keyboard shortcut to open a Mathematica Palettte, like e.g. the Basic Math Assistant. I found a number of questions like this one or this one with answers suggesting to make changes to the KeyEventTranslations.tr file. But I could not figure out how to apply these ideas to make a shortcut for a general menu command.

Cannot assign to function call when looping through and converting excel files [closed]

With this code:

 xls = pd.ExcelFile('test.xlsx') sn = xls.sheet_names for i,snlist in list(zip(range(1,13),sn)):     'df{}'.format(str(i)) =  pd.read_excel('test.xlsx',sheet_name=snlist, skiprows=range(6))  

I get this error:

‘df{}’.format(str(i)) = pd.read_excel(‘test.xlsx’,sheet_name=snlist, skiprows=range(6)) ^ SyntaxError: cannot assign to function call

df+str(i) also return error

i want to make result as: df1 = pd.read_excel.. list1… df2 = pd.read_excel… list2….

How to make NSolve faster?

Can somebody help me, to make these program faster? u and r are parameters, a,b,c,d,q,w,Ca are variables. I need to numerical solve these system for many values of u and r. And it take 10 seconds for every values of r and u. Can I make it faster?

u = 1.9; j = 1; While[u <= 4, u = u + 0.1; r = 0;  While [r <= 0.1, r = r + 0.001;   s1[[j++]] =     NSolve[{Ca/u^2 +         r (6 a (c^2 - d^2) + 12 b c d +            6 (q^2 + w^2 + a^2 + b^2 + c^2 + d^2) Ca + Ca^3) == 0,      a (1/u^2 - 1) + r (3 a (a^2 + b^2) + 6 a (c^2 + d^2) -            3 w^2 q + q^3 + 6 a (q^2 + w^2) + 3 c^2 Ca - 3 d^2 Ca +            3 a Ca^2) == 0.5,      b (1/u^2 - 1) +         r (3 b (a^2 + b^2) + 6 b (c^2 + d^2) - w^3 + 3 w q^2 +            6 b (q^2 + w^2) + 6 c d Ca + 3 b Ca^2) == 0,      c (1/u^2 - 0.25) +         r (6 (a^2 + b^2) c + 3 c (c^2 + d^2) + 6 c (q^2 + w^2) +            6 (a c + b d) Ca + 3 c Ca^2) == 0,      d (1/u^2 - 0.25) +         r (6 (a^2 + b^2) d + 3 d (c^2 + d^2) + 6 d (q^2 + w^2) +            6 (-a d + b c) Ca + 3 d Ca^2) == 0,      q (1/u^2 - 0.25) +         r (6 (a^2 + b^2) q + 6 (c^2 + d^2) q + 3 q (q^2 + w^2) +            3 (a q^2 - a w^2 + 2 b q w) + 3 q Ca^2) == 0,      w (1/u^2 - 0.25) +         r (6 (a^2 + b^2) w + 6 (c^2 + d^2) w + 3 w (q^2 + w^2) +            3 (-2 a q w + b q^2 - b w^2) + 3 w Ca^2) == 0      }, {a, b, c, d, q, w, Ca}, Reals, VerifySolutions -> False]];] 

How to ask to attach the plots vertically in the given code?

I use this code

{P1 = RegionPlot[0 <= Cos[y x] <= 1/2, {y, 0, 3}, {x, 0, 5},     PlotStyle -> LightBlue,     FrameLabel -> {{Style[Rotate["F", 270 Degree], 15],        None}, {Style["y", 15], None}}, BaseStyle -> 15],   P2 = RegionPlot[0 <= Cos[-y x] <= 1/2, {y, 0, 3}, {x, 0, -5},     PlotStyle -> LightBlue,     FrameLabel -> {{Style[Rotate["G", 270 Degree], 15],        None}, {Style["y", 15], None}}, BaseStyle -> 15]}  

and the result is

enter image description here

How can I ask Mathematica to attach the two plots vertically as follows

enter image description here

Too small to represent and Chop in inaccessible algorithm


Overview

I want to apply a specified Chop function to every step in an function call in Mathematica (in my case LegendreP), especially when encountering a machine underflow error. The resulting function should be applicable to a dataframe.

The Setup

I am trying to calculate a function including an associated Legendre function with complex indices

function[t_] = 1/Sin[t] * LegendreP[-1/2 + V * I, l+1, Cos[t]]

where t is between 0 and Pi, V is of order of magnitude 10 and l is between 10 and 100. Beside the function I need its logarithmic derivative function'/function.

Ideally I want to do this by applying the function to a dataframe and appending the result in a separate column.

Append[#, "function" -> function[#timeframe]]

where timeframe is a column with all the t values.

The Problem

When I run this code for any l bigger than 12 and very small t~1e-5 values, the LegendreP Algorithm throws a machine underflow error General::munfl because it cannot execute a multiplication of extremly small complex numbers.

While for a single call or a plot, it seems to do some chopping or return Indeterminate, when I write it to a dataframe with

Append[#, "function" -> function[#timeframe]]

it just returns Failure and does not write anything to the dataframe.

What I have tried so far

I have tried to use Chop and Threshold, but this does not seem to apply to the single steps of the algorithm but only the final result.

The way I "solve" the problem at the moment is to catch the error and return 0 instead of my function. This is not ideal since the real or imaginary part of the step in question and the result might not be negligible while the other one is, or it might diverge instead of converge to 0.

Since the multiplication that raises the error lists numbers ~1e-300 or so, I doubt that the problem is solvable by increasing the precision.

My Goal

Ideally I’d like to call Chop, whenever Mathematica encounters a machine underflow. The behavior of Chop on complex numbers is exactly what I need. This way I should be able to preserve the real or imaginary part that does not vanish.

Is the error handling different, when applied to a dataframe as it relates to this question (for plots or even single evaluation points I don’t have the same issue) or can an indeterminate/NaN be written to a dataframe?

Is there a way to set a "global chop rule"?

Grateful for any hint 😀

Writing mathematical expression in a file

I am trying to write a mathematical expression as variable = expression in the output file.

The current method that I am doing is through WriteString as

expr = -((a*b*y^2*(-1 + z)*z*(1 + a*b + z))/(1 + a*b)^2) +         (z*(1 + a*b - a*b*z + (z + a*b*z)^2))/(1 + a*b)^2 -         (y*z*((-1 + z)^2 + a*b*(2 - 3*z + z^2) + a^2*b^2*(1 - z + z^2)))/(1 + a*b)^2 expression = CForm[expr] /. {Power->pow}; (*expression = CForm[HornerForm[expr]] /. {Power->pow};*) str=OpenWrite["output.hh"]; WriteString[str," double variable = ", expression,";"]; (*WriteString[str," double variable = ", ExportString[expression,"Text"]];*) Close[str]; 

The output is

 cat output.hh  double variable = -(a*b*(-1 + z)*z*(1 + a*b + z)*pow(1 + a*b,-2)*pow(y,2)) - y*z*pow(1 + a*b,-2)*(pow(-1 + z,2) + a*b*(2 - 3*z + pow(z,2)) + pow(a,2)*pow(b,2)*(1 - z + pow(z,2))) + z*pow(1 + a*b,-2)*(1 + a*b - a*b*z + pow(z + a*b*z,2)); 

I want to break the line as the original expr (or after some user-specified column say 80) i.e.

 double variable = -(a*b*(-1 + z)*z*(1 + a*b + z)*pow(1 + a*b,-2)*pow(y,2)) -                    y*z*pow(1 + a*b,-2)*(pow(-1 + z,2) + a*b*(2 - 3*z + pow(z,2)) + pow(a,2)*pow(b,2)*(1 - z + pow(z,2))) +                     z*pow(1 + a*b,-2)*(1 + a*b - a*b*z + pow(z + a*b*z,2)); 

Although this might not lead to optimized expression for numerical evaluation, however it is wanted as beautification. Also how should one optimize expression for further processing to other languages. Any suggestion? Experimental`OptimizeExpression and HornerForm are some options. Any other recommendation? MathCode is much costly 😀

finding FWHM of a dataset with unknown mathematical equation

I have a dataset. I have plotted using "Listloglinearplot". Now I need to find the FWHM (full width half maxima) of the same, However I dont know which mathematical eqution describes best to fit my dataset to find out FWHM. I have the following data and plot:

dataset={{0., 0.0518175}, {1., 0.0306299}, {1.9, 0.610295}, {2.,    1.32653}, {2.2, 4.01183}, {2.5, 6.37931}, {3., 6.50091}, {5.,    6.54052}, {6., 6.57276}, {8.2, 6.59119}, {15., 6.56125}, {20.,    6.5267}, {30., 6.4484}, {45., 6.2987}, {60., 6.11953}, {75.,    5.84962}, {90., 5.43738}, {100., 4.96757}, {105., 4.54382}, {120.,    3.42917}, {135., 2.23092}, {150., 1.55222}, {165., 0.679385}, {180.,    0.444479}} dataplot =   ListLogLinearPlot[dataset,    PlotStyle -> {Dashing[{.0071, 0.005, 0.005}], Blue},    PlotMarkers -> {\[FilledCircle], 15}, Frame -> True,    FrameStyle -> Directive[Black, Thickness[0.002]],    FrameLabel -> {Style["x", Black, FontFamily -> "Times New Roman",       FontSize -> 26],      Style["y", Black, FontFamily -> "Times", FontSize -> 26]},    PlotRange -> {{0, 190}, {1, 7.2}}, FrameTicks -> Automatic,    ImageSize -> 650,    BaseStyle -> {FontFamily -> "Times", FontSize -> 10}] 

Can anyone please help me with the mathematical equation?

Thank you.

Passing an expression to the Plot Function does not Work

Solving a differential equation I found that its solution was analytic, and I stored it as an expression from the default rule output of the DSolve[] function:

soleq2 = y[x] /. soleq2[[1, 1]]

Which has output:

Sqrt[x] BesselJ[Sqrt[13]/2, x] C[1] + Sqrt[x] BesselY[Sqrt[13]/2, x] C[2]

I then plotted this:

Manipulate[Plot[soleq2, {x, 0, 10}], {C[1], 0, 10}, {C[2], 0, 10}]

but the plot does not show anything, only the sliders for the modulation of C[1] and C[2]. I tried substituting these constants with other letters thinking their format might interfere with the kernel, but to no avail.