## Simplify doesn’t do anything on a matrix, but works fine on its elements separately

I am performing some operations which arrive at a matrix

mat = {{-(γ^(3/2)/(-γ + Sqrt[1 + γ^2])) + Sqrt[    1 + γ^2]/(-γ + Sqrt[1 + γ^2]) +     Sqrt[γ] (-(        Sqrt[γ]/(-γ + Sqrt[         1 + γ^2])) + γ/(-γ + Sqrt[        1 + γ^2])),    Sqrt[1 + γ^2] (-(        Sqrt[γ]/(-γ + Sqrt[         1 + γ^2])) + γ/(-γ + Sqrt[        1 + γ^2])) +     Sqrt[γ] (-(γ^(        3/2)/(-γ + Sqrt[1 + γ^2])) + Sqrt[       1 + γ^2]/(-γ + Sqrt[1 + γ^2])),    0}, {0, -(γ/(-γ + Sqrt[1 + γ^2])) + Sqrt[    1 + γ^2]/(-γ + Sqrt[1 + γ^2]), 0}, {0, 0, 1}} 

Performing Simplify[] on this does nothing (it spits the same thing back out).

However, if I copy each element and perform Simplify[] on each element separately, it correctly simplifies down to

 {{1,γ,0},{0,1,0},{0,0,1}} 

What gives?

EDIT:

I just discovered that if I do Simplify[mat[[1]]], it properly simplifies down. No idea why that works.

## Ordering a list of elements as shortest euclidean distance between two points

I’ve got a list of points:

figdata = {{67.6769, -1.15057}, {67.9064, -1.30881}, {68.136, -1.01986}, {68.2508, -1.42347}, {68.5951, -1.5152}, {68.7098, -0.946475}, {69.2837, -1.63445}, {69.7428, -1.74453}, {69.9724, -0.905197}, {70.2019, -1.86378}, {70.8905, -0.850158}, {71.0053, -1.96009}, {71.6939, -0.836399}, {72.3826, -2.13438}, {72.6121, -0.822639}, {73.8746, -2.34995}, {73.9894, -0.891437}, {74.4485, -2.4004}, {75.1371, -0.951062}, {75.4815, -2.42792}, {76.1701, -0.987754}, {76.9735, -2.49672}, {77.4326, -1.03362}, {78.236, -2.52423}, {79.0394, -1.10242}, {80.4167, -2.54258}, {80.6462, -1.18039}, {82.2531, -1.26294}, {83.4008, -2.53799}, {84.319, -1.33633}, {85.5815, -1.40054}, {86.9588, -2.54258}, {87.1883, -1.48768}, {88.7951, -1.59317}, {90.0576, -2.54258}, {90.861, -1.67573}, {93.9599, -1.87295}, {92., -2.54258}, {93., -2.54258}, {95.7963, -2.54258}, {98., -2.54258}, {95.911, -1.95551}, {97.2883, -2.04265}, {99.469, -2.18483}, {100.502, -2.25363}, {100.732, -2.5013}, {101.305, -2.46002}, {101.42, -2.32702}, {101.879, -2.40499}} 

I need to plot this data using ListLinePlot so that two neighbouring appear connected with a line. I’ve tried using the following approach:

 Block[{data = figdata, nearel, datanew0 = {}, i = 1},  While[Length[data] > 1,   nearel =     Flatten[Nearest[Delete[data, i], data[[i]],       DistanceFunction -> "EuclideanDistance"]];   datanew0 = Append[datanew0, data[[i]]];   data = Delete[data, i];   i = Position[data, nearel][[1, 1]]   ];  datanew = datanew0  ] 

But, for a reason I don’t know, when I do:

p1 = ListLinePlot[datanew, Frame -> True,     PlotRange -> {{40, 108}, {-2.6, .8}}, AspectRatio -> 1,     FrameStyle -> 15]; p2 = ListPlot[datanew, Frame -> True,     PlotRange -> {{40, 108}, {-2.6, .8}}, AspectRatio -> 1,     FrameStyle -> 15, PlotStyle -> Red]; Show[p1, p2] 

The result i get is:

How would I write a code that solves this problem, and, what is wrong with my piece of code?

## removing commas from a list and just keeping the elements

I have the following list, I want to remove all commas and just be left with the elements of the set.

Tuples[{I, l}, 16]  {{I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I}, {I, I, I, I, I, I,        I, I, I, I, I, I, I, I, I, l}, {I, I, I, I, I, I, I, I, I, I, I, I,        I, I, l, I}, {I, I, I, I, I, I, I, I, I, I, I, I, I, I, l, l}, ....} 

EDIT: So what I want is something like:

{{IIIIIIIIIIIIIIII}, {IIIIIIIIIIIIIIIl}, {IIIIIIIIIIIIIIlI}, {IIIIIIIIIIIIIIll}, ....} 

## c# Maximum sum in circular array such that no two elements are adjacent

https://www.geeksforgeeks.org/maximum-sum-in-circular-array-such-that-no-two-elements-are-adjacent/

Maximum sum in circular array such that no two elements are adjacent Given a circular array containing of positive integers value. The task is to find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should be adjacent in the array.

Examples:

Input: circular arr = {1, 2, 3, 1} Output : 4 subsequence will be(1, 3), hence 1 + 3 = 4

Input: circular arr = {1, 2, 3, 4, 5, 1} Output: 9 subsequence will be(1, 3, 5), hence 1 + 3 + 5 = 9

using System; using Microsoft.VisualStudio.TestTools.UnitTesting;  namespace CirucularArray {     [TestClass]     public class MaximumSumCircularArrayNo2ElementsAreAdjacent     {         [TestMethod]         public void TestMethod1()         {             int[] arr = {1, 2, 3, 4, 5, 1};             int result = ComputeMaxSum(arr);             Assert.AreEqual(9, result);          }         [TestMethod]         public void TestMethod2()         {             int[] arr = { 5, 1, 2, 10};             int result = ComputeMaxSum(arr);             Assert.AreEqual(11, result);          }          [TestMethod]         public void TestMethod3()         {             int[] arr = { 5, 11, 1 };             int result = ComputeMaxSum(arr);             Assert.AreEqual(11, result);          }          private int ComputeMaxSum(int[] arr)         {             if (arr == null || arr.Length == 0)             {                 throw new MissingFieldException("arr is null");             }              if (arr.Length < 2)             {                 return arr[0];             }             int arrMinus1 = arr[1];             int arrMinus2 = arr[0];             if (arr.Length == 2)             {                 return Math.Max(arrMinus2, arrMinus1);             }             int sum = 0;              for (int i = 2; i < arr.Length; i++)             {                 sum = Math.Max(arr[i] + arrMinus2, arrMinus1);                 arrMinus2 = arrMinus1;                 arrMinus1 = sum;             }              return sum;         }     } } 

I think this solution is better than the one in geekforgeeks, can you please comment on time and space complexity and edge cases. Thanks

## Split a list of elements into sub lists, each with different criteria

I have a list of elements of different values, say 0 to 3. I want to split it into a certain number of sub lists, each accepting only certains elements. The sub lists may not always have the same length.

For example, I have a list of 12 elements: [0,0,0,1,1,1,2,2,2,3,3,3]. I want to split it into 3 sub lists:

• One that accepts all elements.
• One that only accepts 1, 2 and 3. That list could be [1,1,2,2] but not [0,0,2,3].
• One that only accepts 0, 2 and 3. That list could be [0,0,2,3] but not [1,1,2,2].

A sub list that accepts elements doesn’t mean it needs to contain these elements.

I tried filling each sub list in order with random elements from the parent list meeting the sub list criteria. With the example above, it could go like this:

• Fill the 1st list: [0,0,0,2]. Parent list is now [1,1,1,2,2,3,3,3].
• Fill the 2nd list: [2,2,3,3]. Parent list is now [1,1,1,3].
• Try to fill the 3rd list: only [1,1,1,3] is left but this list can’t take 1s. Start again.

Because of the use of random this is potentially O(∞). How can I improve it?

The algorithm must give uniform results, all combinations of sub lists having the same probability to be chosen.

## Trouble understanding proof regarding elements of an integral domain which are not product of irreductible elements.

I’m having trouble understanding the proof of a proposition regarding elements which are not product of irreductible elements in integral domains. The proposition is the following:

Let $$A$$ be an integral domain and $$a\in A$$ different of 0 and not a unit. If $$a$$ is not product of irreductible elements then there exists a sequence $$\{a_n\}_{n\in N}$$ of elements of $$A$$ such that $$a_{n+1}$$ is a proper divisor of $$a_n$$ for every natural $$n$$.

The proof that has been given to me is this:

Let’s build inductively a sequence with this property. Let $$a_0 = a$$ and suppose $$a_0,\dots,a_n$$, $$n\geq0$$ are already built. Since $$a_n$$ is not product of irreductibles it must be composite, this $$a_n = bc$$ with $$b,c$$ proper divisors of $$a_n$$. Clearly at least one of the two factors must not be product of irreductibles. We define $$a_{n+1}$$ as this factor.

The problem I have understanding this proof is that I don’t get why not being product of irreductibles implies it is composite. Wouldn’t such elements be irreductibles itself? I mean if it is composite, couldn’t we keep decomposing its factors until all of them are irreductible?

Thanks for your help.

## How many elements of order 5 are there in a group of order 45?

The Problem:

As the title asks: How many elements of order $$5$$ are there in a group of order $$45$$?

My Approach:

Let $$G$$ be a group of order $$45$$.

My first thought is to hit it with Sylow’s Theorems, which tells me that $$G$$ has a normal subgroup of order $$5$$ (call it $$N$$) and a normal subgroup of order $$9$$. Clearly $$4$$ out of the $$5$$ elements in $$N$$ must be of order $$5$$ (since they must divide the order of $$N$$); and clearly none of these elements are in the normal subgroup of order $$9$$.

So, this means $$G$$ has at least $$4$$ elements of order $$5$$. Are there any more, though? The only thing I can think of is to investigate the possibility of a subgroup of order 15… but how would I know if $$G$$ has such a subgroup? And, if it did, how would I know whether it intersects $$N$$ trivially?

## (DnD5e) Feedback on homebrew: Monk – Way of the Four Elements

I don’t have too many friends in the RPG community that could give me some valid balance/playability etc feedback on such a thing, and was hoping the community here could. I’ve created a new version of the Monk-Way of the Four Elements, which gives a little more freedom and versatility to the class. That being said, I’m not certain how overpowered (if at all) I’ve made this. If your only feedback is to rewrite it so it sounds more fantastical, that’s cool too.

## Create an array consisting of triples of consecutive identical elements

As I am learning programming using C#, I try to solve the following problem, for me it looks a bit difficult, please help:

Create an array consisting of triples of consecutive identical elements.

Below is what I came up with so far:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;  namespace Array3NumbersApp {     class Program     {         static void Main(string[] args)         {             int n = 99;             int[] buffer = new int[n];             Random rnd = new Random();              for (int i = 2; i < buffer.Length; i++)             {                  if (i % 3 == 0)                 {                     int k = rnd.Next(1, 30);                     buffer[i] = k;                     buffer[i-1] = k;                     buffer[i-2] = k;                 }             }              for (int i = 2; i < buffer.Length; i++)             {                 Console.Write(buffer[i -2 ] + " " + buffer[i-1] + " " + buffer[i] + " ");             }          }     } } 

Anyone can suggest what am I doing wrong in that program? Results I was getting, for example: 0 29 29 29 29 29 29 29 1 29 1 1 1 1 1 1 1 18 1 18 18 18 18 18 18 18 20 18 20 20 20 20 20 20 20 25 20 25 25 25 … It is not what is expected, right?

Please note, this is not a homework, but my attempts to come to grips with arrays… Thanks in advance for your comments! I highly appreciate your help.

## D8: Altering Views Exposed Form Elements and their Associated Labels

I have a series of Views Exposed Forms across a Drupal 8 website. My goal is to generate unique template suggestions so I can theme each individual input and their labels differently as needed.

Here is my current approach. Placed into theme.theme. I’ve hit a brick wall.

function HOOK_form_views_exposed_form_alter(array &$form, FormStateInterface$  form_state, $form_id) {$  form['#attributes']['twig-suggestion'] = $form['#id']; } function HOOK_theme_suggestions_input_alter(&$  suggestions, array $variables) {$  element = $variables['element']; if (isset($  element['#attributes']['twig-suggestion'])) {       $suggestions[] = 'input__' .$  element['#type'] . '__' . $element['#attributes']['twig-suggestion']; } } function HOOK_theme_suggestions_form_element_label_alter(&$  suggestions, &$variables,$  hook) {     $element =$  variables['element'];      if (isset($element['#attributes']['twig-suggestion'])) {$  suggestions[] = 'label__' . \$  element['#attributes']['twig-suggestion'];     } } 

All input and label [#attributes] are null via Kint.
Here are the URLs I have referenced for background:

1) http://kevinquillen.com/drupal/2017/01/28/adding-twig-template-suggestions-for-form-elements

2) https://www.chapterthree.com/blog/how-to-create-custom-theme-suggestions-drupal-8

3) https://yellowpencil.com/blog/getting-granular-with-drupal-eight-forms/