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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
(* Content-type: application/vnd.wolfram.mathematica *)

(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)

(* Examples.nb - ChaosSim Example Simulations *)
(* Practical demonstrations of chaos simulation capabilities *)

(* ::Title:: *)
(*ChaosSim Examples and Demonstrations*)


(* ::Section:: *)
(*Setup*)


(* Load ChaosSim framework *)
Get[FileNameJoin[{NotebookDirectory[], "ChaosSim.nb"}]]
Get[FileNameJoin[{NotebookDirectory[], "Visualizations.nb"}]]

Print[Style["ChaosSim Examples Loaded", Bold, 16, Blue]]
Print["Run each section to see different chaos simulations in action.\n"]


(* ::Section:: *)
(*Example 1: Basic Bernoulli Chaos*)


(* ::Text:: *)
(*This example demonstrates how Bernoulli numbers create weighted chaos patterns.*)
(*The Bernoulli numbers provide non-uniform probability distributions that*)
(*generate interesting chaotic behaviors.*)


Print[Style["=== Example 1: Bernoulli Chaos Simulation ===", Bold, 14, Purple]]

(* Generate Bernoulli chaos with 500 iterations *)
bernoulliExample = SimulateBernoulliChaos[500, 12];

(* Display statistics *)
Print["Statistics:"]
Print["  Mean: ", Mean[bernoulliExample]]
Print["  Standard Deviation: ", StandardDeviation[bernoulliExample]]
Print["  Min: ", Min[bernoulliExample], " | Max: ", Max[bernoulliExample]]

(* Visualize *)
ListPlot[bernoulliExample,
  PlotStyle -> {Blue, PointSize[Small]},
  PlotLabel -> Style["Example 1: Bernoulli Chaos", Bold, 14],
  AxesLabel -> {"Iteration", "State"},
  ImageSize -> Large,
  GridLines -> Automatic
]


(* ::Section:: *)
(*Example 2: Fibonacci Golden Spiral*)


(* ::Text:: *)
(*This creates a 3D golden spiral based on Fibonacci numbers.*)
(*The spiral demonstrates the connection between Fibonacci sequences*)
(*and natural chaotic patterns found in nature.*)


Print[Style["\n=== Example 2: Fibonacci Golden Spiral ===", Bold, 14, Purple]]

(* Generate 3D Fibonacci spiral *)
fibonacciSpiralPoints = FibonacciSpiral3D[20, 100];

Print["Generated ", Length[fibonacciSpiralPoints], " points in golden spiral"]
Print["Golden Ratio β‰ˆ ", N[GoldenRatio, 6]]

(* Visualize in 3D *)
ListPointPlot3D[fibonacciSpiralPoints,
  PlotStyle -> Directive[PointSize[Small]],
  ColorFunction -> Function[{x, y, z}, 
    ColorData["SunsetColors"][Norm[{x, y}]]
  ],
  BoxRatios -> {1, 1, 0.6},
  ImageSize -> Large,
  PlotLabel -> Style["Example 2: Fibonacci Golden Spiral", Bold, 14],
  AxesLabel -> {"X", "Y", "Z"},
  Background -> GrayLevel[0.95],
  ViewPoint -> {2, -2, 1.5}
]


(* ::Section:: *)
(*Example 3: Nash Equilibrium in Prisoner's Dilemma*)


(* ::Text:: *)
(*Classic game theory example: Finding Nash equilibrium in the Prisoner's Dilemma.*)
(*This demonstrates how game theory integrates with chaos simulation.*)


Print[Style["\n=== Example 3: Prisoner's Dilemma Nash Equilibrium ===", Bold, 14, Purple]]

(* Define Prisoner's Dilemma payoff matrices *)
(* (Cooperate, Defect) for each player *)
prisonerPayoff1 = {{-1, -3}, {0, -2}};  (* Player 1 payoffs *)
prisonerPayoff2 = {{-1, 0}, {-3, -2}};  (* Player 2 payoffs *)

Print["Player 1 Payoff Matrix (rows: P1 strategy, cols: P2 strategy):"]
Print[MatrixForm[prisonerPayoff1]]

Print["\nPlayer 2 Payoff Matrix:"]
Print[MatrixForm[prisonerPayoff2]]

(* Find Nash equilibrium *)
equilibria = FindNashEquilibrium[prisonerPayoff1, prisonerPayoff2];

Print["\nNash Equilibrium found at: ", equilibria]
Print["Interpretation: Both players choosing Defect (strategy 2, 2)"]

(* Visualize payoff matrices *)
GraphicsRow[{
  ArrayPlot[prisonerPayoff1,
    ColorFunction -> "Rainbow",
    PlotLabel -> "Player 1 Payoffs",
    FrameLabel -> {"P2 Strategy", "P1 Strategy"},
    PlotLegends -> Automatic
  ],
  ArrayPlot[prisonerPayoff2,
    ColorFunction -> "Rainbow",
    PlotLabel -> "Player 2 Payoffs",
    FrameLabel -> {"P2 Strategy", "P1 Strategy"},
    PlotLegends -> Automatic
  ]
}, ImageSize -> Large]


(* ::Section:: *)
(*Example 4: Chaotic Game Evolution*)


(* ::Text:: *)
(*Simulate a game where payoff matrices evolve chaotically over time.*)
(*This shows how Nash equilibria shift in dynamic, chaotic environments.*)


Print[Style["\n=== Example 4: Chaotic Game Evolution ===", Bold, 14, Purple]]

(* Run chaotic game simulation *)
chaosGameHistory = ChaosGameSimulation[100, 2, 0.3];

(* Extract data *)
rounds = chaosGameHistory[[All, 1]];
strategies = chaosGameHistory[[All, 2]];
equilibriaCounts = Length /@ chaosGameHistory[[All, 3]];

Print["Simulation complete: ", Length[rounds], " rounds"]
Print["Average equilibria per round: ", Mean[equilibriaCounts]]

(* Visualize strategy evolution *)
ListLinePlot[
  {strategies[[All, 1]], strategies[[All, 2]]},
  PlotStyle -> {{Blue, Thick}, {Red, Thick}},
  PlotLabel -> Style["Example 4: Strategy Evolution in Chaotic Game", Bold, 14],
  AxesLabel -> {"Round", "Strategy Choice"},
  PlotLegends -> {"Player 1", "Player 2"},
  ImageSize -> Large,
  GridLines -> Automatic
]


(* ::Section:: *)
(*Example 5: Multi-Agent Chaos System*)


(* ::Text:: *)
(*Simulate 5 agents seeking Nash equilibrium in a chaotic environment.*)
(*Agents adjust their strategies to minimize conflicts, creating emergent patterns.*)


Print[Style["\n=== Example 5: Multi-Agent Chaos Equilibrium ===", Bold, 14, Purple]]

(* Run multi-agent simulation *)
multiAgentChaos = MultiAgentChaosEquilibrium[5, 200];

(* Extract agent states over time *)
agentStates = multiAgentChaos[[All, 2]];

Print["Number of agents: 5"]
Print["Iterations: 200"]
Print["Final agent states: ", agentStates[[-1]]]
Print["State convergence: ", StandardDeviation[agentStates[[-1]]]]

(* Visualize all agents *)
ListLinePlot[
  Table[agentStates[[All, i]], {i, 1, 5}],
  PlotStyle -> Table[Directive[Thick, ColorData[97][i]], {i, 1, 5}],
  PlotLabel -> Style["Example 5: Multi-Agent State Evolution", Bold, 14],
  AxesLabel -> {"Iteration", "Agent State"},
  PlotLegends -> Table[StringTemplate["Agent ``"][i], {i, 1, 5}],
  ImageSize -> Large,
  GridLines -> Automatic
]


(* ::Section:: *)
(*Example 6: Unified Chaos Simulation*)


(* ::Text:: *)
(*Combines all three chaos types (Bernoulli, Fibonacci, Nash) into one system.*)
(*This demonstrates the full power of ChaosSim's integrated approach.*)


Print[Style["\n=== Example 6: Unified Chaos System ===", Bold, 14, Purple]]

(* Run unified simulation *)
unifiedChaos = UnifiedChaosSimulation[400];

(* Analyze correlations *)
correlations = ChaosCorrelationAnalysis[unifiedChaos];

Print["Unified chaos simulation complete"]
Print["Data points: ", Length[unifiedChaos]]
Print["\nCorrelation Analysis:"]
Print[Grid[
  Prepend[correlations, {"Component Pair", "Correlation"}],
  Frame -> All,
  Background -> {None, {LightBlue, White}}
]]

(* Visualize in 3D phase space *)
ListPointPlot3D[unifiedChaos,
  PlotStyle -> Directive[PointSize[Small]],
  ColorFunction -> Function[{x, y, z}, 
    ColorData["Rainbow"][z]
  ],
  BoxRatios -> {1, 1, 1},
  ImageSize -> Large,
  PlotLabel -> Style["Example 6: Unified Chaos Phase Space", Bold, 14],
  AxesLabel -> {"Bernoulli", "Fibonacci", "Nash"},
  Background -> Black,
  ViewPoint -> {1.5, -2.5, 1.2}
]


(* ::Section:: *)
(*Example 7: Bernoulli 3D Attractor*)


(* ::Text:: *)
(*A beautiful 3D attractor generated using Bernoulli number weights.*)
(*This creates complex, non-repeating patterns in 3D space.*)


Print[Style["\n=== Example 7: Bernoulli 3D Attractor ===", Bold, 14, Purple]]

(* Generate attractor *)
attractorPoints = BernoulliAttractor[3000, 3];

Print["Generated ", Length[attractorPoints], " points"]
Print["Attractor bounds:"]
Print["  X: [", Min[attractorPoints[[All, 1]]], ", ", Max[attractorPoints[[All, 1]]], "]"]
Print["  Y: [", Min[attractorPoints[[All, 2]]], ", ", Max[attractorPoints[[All, 2]]], "]"]
Print["  Z: [", Min[attractorPoints[[All, 3]]], ", ", Max[attractorPoints[[All, 3]]], "]"]

(* Create stunning visualization *)
ListPointPlot3D[attractorPoints,
  PlotStyle -> Directive[PointSize[Tiny]],
  ColorFunction -> Function[{x, y, z}, 
    ColorData["DarkRainbow"][Norm[{x, y, z}]/2]
  ],
  BoxRatios -> {1, 1, 1},
  ImageSize -> Large,
  PlotLabel -> Style["Example 7: Bernoulli Attractor", Bold, 14],
  AxesLabel -> {"X", "Y", "Z"},
  Background -> Black,
  Boxed -> False,
  ViewPoint -> {2, -2, 1}
]


(* ::Section:: *)
(*Example 8: Fibonacci Chaos Map*)


(* ::Text:: *)
(*Creates a chaotic map using Fibonacci ratios as the driving parameter.*)
(*Shows bifurcations and sensitivity to initial conditions.*)


Print[Style["\n=== Example 8: Fibonacci Chaos Map ===", Bold, 14, Purple]]

(* Generate Fibonacci chaos map *)
fibChaosMap = FibonacciChaosMap[800];

Print["Generated ", Length[fibChaosMap], " iterations"]
Print["Mean value: ", Mean[fibChaosMap]]
Print["Chaos entropy: ", ChaosEntropy[fibChaosMap]]

(* Create phase space plot *)
GraphicsRow[{
  ListPlot[fibChaosMap,
    PlotStyle -> {Orange, PointSize[Small]},
    PlotLabel -> "Time Series",
    AxesLabel -> {"Iteration", "Value"},
    ImageSize -> Medium
  ],
  ListPlot[Partition[fibChaosMap, 2, 1],
    PlotStyle -> {Red, PointSize[Tiny]},
    PlotLabel -> "Phase Space",
    AxesLabel -> {"x(t)", "x(t+1)"},
    ImageSize -> Medium,
    AspectRatio -> 1
  ]
}, ImageSize -> Large, 
  PlotLabel -> Style["Example 8: Fibonacci Chaos Map Analysis", Bold, 14]]


(* ::Section:: *)
(*Example 9: Comparative Chaos Analysis*)


(* ::Text:: *)
(*Compare all three types of chaos side-by-side.*)
(*Reveals unique characteristics of each approach.*)


Print[Style["\n=== Example 9: Comparative Chaos Analysis ===", Bold, 14, Purple]]

(* Generate all three types *)
iterations = 400;
bernoulliChaos = SimulateBernoulliChaos[iterations, 12];
fibonacciChaos = FibonacciChaosMap[iterations];
nashChaos = MultiAgentChaosEquilibrium[5, iterations][[All, 2, 1]];

(* Calculate statistics *)
Print["Chaos Type Statistics:"]
Print[Grid[{
  {"Type", "Mean", "Std Dev", "Entropy"},
  {"Bernoulli", Mean[bernoulliChaos], StandardDeviation[bernoulliChaos], 
   ChaosEntropy[bernoulliChaos]},
  {"Fibonacci", Mean[fibonacciChaos], StandardDeviation[fibonacciChaos], 
   ChaosEntropy[fibonacciChaos]},
  {"Nash", Mean[nashChaos], StandardDeviation[nashChaos], 
   ChaosEntropy[nashChaos]}
}, Frame -> All, Background -> {None, {LightYellow, White}}]]

(* Visualize comparison *)
ListLinePlot[
  {bernoulliChaos, fibonacciChaos, nashChaos},
  PlotStyle -> {
    {Blue, Thick, Opacity[0.7]},
    {Orange, Thick, Opacity[0.7]},
    {Green, Thick, Opacity[0.7]}
  },
  PlotLabel -> Style["Example 9: Chaos Type Comparison", Bold, 14],
  AxesLabel -> {"Iteration", "State Value"},
  PlotLegends -> {"Bernoulli", "Fibonacci", "Nash Equilibrium"},
  ImageSize -> Large,
  GridLines -> Automatic
]


(* ::Section:: *)
(*Example 10: Custom Chaos Application*)


(* ::Text:: *)
(*A practical example: Using chaos for random sampling in a market model.*)
(*Simulates price fluctuations driven by chaotic dynamics.*)


Print[Style["\n=== Example 10: Chaotic Market Simulation ===", Bold, 14, Purple]]

SimulateChaoticMarket[days_Integer, initialPrice_Real: 100.0] := Module[
  {chaos, prices, returns},
  
  (* Generate Bernoulli chaos for market volatility *)
  chaos = SimulateBernoulliChaos[days, 10];
  
  (* Convert chaos to price movements *)
  returns = (chaos - 0.5) * 0.1; (* Scale to Β±5% daily returns *)
  
  (* Calculate cumulative prices *)
  prices = FoldList[
    #1 * (1 + #2) &,
    initialPrice,
    returns
  ];
  
  prices
]

(* Run market simulation *)
marketPrices = SimulateChaoticMarket[250, 100.0];

Print["Market simulation: 250 trading days"]
Print["Initial price: $100.00"]
Print["Final price: $", marketPrices[[-1]]]
Print["Max price: $", Max[marketPrices]]
Print["Min price: $", Min[marketPrices]]
Print["Total return: ", (marketPrices[[-1]] - 100.0), "%"]

(* Visualize market *)
ListLinePlot[marketPrices,
  PlotStyle -> {Darker[Green], Thick},
  PlotLabel -> Style["Example 10: Chaotic Market Prices", Bold, 14],
  AxesLabel -> {"Trading Day", "Price ($)"},
  ImageSize -> Large,
  Filling -> Axis,
  FillingStyle -> Opacity[0.2, Green],
  GridLines -> Automatic
]


(* ::Section:: *)
(*Summary*)


Print[Style["\n\n" <> StringRepeat["=", 60], Bold, Blue]]
Print[Style["ChaosSim Examples Complete!", Bold, 18, Blue]]
Print[Style[StringRepeat["=", 60] <> "\n", Bold, Blue]]

Print["You have explored:"]
Print["  βœ“ Bernoulli number-based chaos generation"]
Print["  βœ“ Fibonacci sequence chaotic patterns"]
Print["  βœ“ Nash equilibrium in game theory"]
Print["  βœ“ Multi-agent chaos systems"]
Print["  βœ“ Unified chaos simulations"]
Print["  βœ“ 3D attractors and visualizations"]
Print["  βœ“ Practical applications (market simulation)"]

Print["\nNext steps:"]
Print["  β€’ Modify parameters in any example to explore variations"]
Print["  β€’ Create your own chaos combinations"]
Print["  β€’ Use Visualizations.nb for advanced plotting"]
Print["  β€’ Refer to README.md for detailed documentation"]

Print[Style["\nHappy chaos simulation! πŸŒ€", Bold, 16, Purple]]