Operator products summing

Is there a way to perform the below summation in Mathematica?

$ $ \frac{\left(\hat{X}_{ij}+i\delta_{ij}\right)}{i}\frac{\left(\hat{X}_{kl}+i\delta_{kl}\right)}{i}$ $

I am finding the issue because order matters here. X is operator. So it’s order is important. g and X are antisymmetric tensors. The answer to the above equation I am expecting is:

$ $ -\sum_{i,j,k,l}\left(g_{ijkl}\hat{X}_{ij}\hat{X}_{kl}+ig_{ijkl}\hat{X}_{ij}\delta_{kl}+ig_{ijkl}\delta_{ij}\hat{X}_{kl}-g_{ijkl}\delta_{ij}\delta_{kl}\right)$ $ $ $ =-\sum_{i,j,k,l}g_{ijkl}\hat{X}_{ij}\hat{X}_{kl}$ $

Can I implement this using the following code:

SumHeld /: MakeBoxes[SumHeld[expr_, ranges__], form_] :=   MakeBoxes[Sum[expr, ranges], form]  SumHeld /:    SyntaxInformation[    SumHeld] = {"LocalVariables" -> {"Table", {2, Infinity}}}; SumHeld /: c_?NumericQ SumHeld[rest_, range__] :=   SumHeld[c rest, range] IndexUnify[HoldPattern@Plus[sums : SumHeld[_, __] ..]] :=   Plus @@ With[{targetIndices = List @@ #[[-1, 2 ;;, 1]],        sourceIndicesList = List @@@ #[[;; , 2 ;;, 1]]},       Function[{sum, sourceIndices},         sum /. Thread[          sourceIndices ->            Take[targetIndices, Length@sourceIndices]]] @@@        Transpose@{#, sourceIndicesList}] &@   SortBy[Flatten /@ {sums}, Length]  SumTogether[HoldPattern@Plus[sums : SumHeld[_, sameRanges__] ..]] :=   SumHeld[Plus @@ {sums}[[;; , 1]], sameRanges] SumTogether[HoldPattern@Plus[sums : SumHeld[_, __] ..]] /;    UnsameQ @@ {sums}[[;; , 2 ;;]] :=   Plus @@ SumTogether@*Plus @@@ GatherBy[{sums}, Rest]  SumHeld[expr_, {lst_List,     dim_}] := (term |->      SumHeld[term,       Sequence @@        Table[If[Count[term, patt, \[Infinity]] == 2, {patt, dim},          Nothing], {patt, lst}]]) /@ expr 

How to modify the above code to incorporate to handle operators?

Standard way to define a linear operator?

Say I want to define some simple linear operator. I can do this by

f[c_?NumericQ x_] := c f[x] f[x_ + y_] := f[x] + f[y] 

Or let’s define a bi-linear operator instead

f[c_?NumericQ x_, y_] := c f[x, y] f[x_, c_?NumericQ y_] := c f[x, y] f[x_ + y_, z_] := f[x, z] + f[y, z] f[x_, y_ + z_] := f[x, y] + f[x, z] 

My problem is that I need to do this kind of things very often and then the definitions like above are repeated over and over. It would probably not be easy to describe all intended uses briefly here, but I hope that my intentions are clear. Isn’t there some standard concise way to define operators with some common properties?

Composition of functions and operator forms of built-in functions

I am trying to replicate the behaviour of some of the built-in operator forms (for Map, Apply etc) but struggling to understand the way Composition works. For a concrete example:

list = {1 \[UndirectedEdge] 10, 2 \[UndirectedEdge] 11, 3 \[UndirectedEdge] 11, 4 \[UndirectedEdge] 10}  Map[Apply[Rule]]@list  %: {1 -> 10, 2 -> 11, 3 -> 11, 4 -> 10} 

produces the result I was looking for in this case.

My question is how to replicate the composition of operator forms above. This naive attempt doesn’t work as intended and produces an error message:


Rule::argr: Rule called with 1 argument; 2 arguments are expected.

%: Map[Apply[Rule[{1 \[UndirectedEdge] 10, 2 \[UndirectedEdge] 11, 3 \[UndirectedEdge] 11, 4 \[UndirectedEdge] 10}]]] 

I’ve tried various combinations of parentheses to control the evaluation to avail – the example I started with appears to build an operator form of the composition of Apply and Rule then maps it over the list input but that is not what the composition I attempted does.

So, how to produce the same with Composition or other constructs?

I’m asking really to try and get a fuller understanding of these types of construction work.

Convention of a += operator in pseudo-code

I have to write some algorithm in pseudocode for a paper. For this I have the "$ \leftarrow$ " to assign a value.

$ x \leftarrow y^2$

now I want to write a method which adds to the variable. In normal Python code I would write x += 1 for this. Is there a style convention how to layout this in pseudo-code in a paper? I dont really like the redundance of $ x \leftarrow x+1$ .

Defining an mathematical operator in Mathematica

I’m trying to learn mathematica to use in my thesis. I have basic problems with definitions, calculations etc. Let me ask a question.

I want to define anti derivative operator and derivative operator, then a new operator with composition of these operators. Compositions must be identity, so if I give a function into new operator it will turn out the function what I gave it.

To explain better, I will try to write these in mathematical sense;

Here $ D^m$ denotes standard derivative operator $ m$ times and anti-derivative operator $ I_m$ defined with

\begin{cases}  f(x), & m=0 \ \int_0^{x} \dfrac{(x-y)^{m-1}}{(m-1)!}f(u)du, &  m\geq 1 \end{cases} 

which seems

Editor gives an error so I use code option and screenshot to code

Now, if we composite these functions, $ [D^m\circ I_m](f)(x)$ these will give us directly $ f(x)$ . I want to define these operators in Mathematica and see composition of operators.

Actually these problem is not my main problem but the answers will shows me what I need, then I will try to learn myself again.

Thanks for your helps, if I wrote incomprehensible or wrong forgive me.

does NP close under Pref operator [closed]

recently i saw a proof of the statement: "P is not closed under Pref operator" in short, we defined L={<M,w>#y : M(w) accepts and y is an accepting run of M(w) } it is easy to give a polynomial algorithm that checks the conditions. so, we get contradiction since P is in R and Pref(L) contains A_TM which isn’t decidable

my question is: how do i proof that NP is not close under Pref ??

Intelligent use of XOR operator to find missing number

I’ve come across the following problem on leetcode & tried to solve it with the following code however there seems to be an even better solution that takes advantage of XOR. Leetcode has a description for XOR solution however I can’t grasp it in its entirety.

I just can’t wrap my head around why we need to initialize missing variable with length of array, why not initialize it with Zero & when we do initialize it with Zero, why can’t this algo find the missing number? Can someone please explain it?

enter image description here

Following was my solution before I learned Leetcode suggested XOR solution is even better & faster

class Solution {     public int missingNumber(int[] nums) {         if(nums.length == 1)             return nums[0] == 0 ? 1 : 0;          int missing = 0;         boolean tempNums[] = new boolean[nums.length+1]; //cuz one is missing          for(int i:nums) {             tempNums[i] = true;         }          for(int i=0; i<tempNums.length; i++)             if(!tempNums[i]) {                 missing = i;                 break;             }         return missing;     } } 

Bit manipulation involving and operator

Given a special function

F(X,Y,Z) = (X ∧ Z)⋅(Y ∧ Z) where ∧ is bitwise AND operator; X,Y,Z are non-negative integers; and ‘.’ represents product

We want to maximize the function F(X,Y,Z) for given X and Y by choosing an appropriate Z. Additionally we have been given limits L and R for Z

To summarize, we need to find a non-negative integer Z (L≤Z≤R) such that F(X,Y,Z) = maxL ≤ k ≤ R(F(X,Y,k)) If there is more than one such value of Z, we should find the smallest one in the range [L,R]

Note: X, Y, L and R are chosen in such a way that maxL≤k≤R(F(X,Y,k)) never exceeds 262

Example: For X, Y, L, R = 7, 12, 4, 17 respectively, answer = 15

I understand the problem, but need help to find an optimal solution for this.

Why do I get this warning when using a null conditional operator?

In the OnTriggerEnter2D function of my Bullet script, I have the following code:

private void OnTriggerEnter2D(Collider2D other) {      if (other.CompareTag("Enemy"))      {          var enemy = other.GetComponent<Enemy>();          enemy?.Death();      } } 

The reason for the null conditional operator (the question mark) in enemy?.Death() is because the Death function actually destroys the Enemy component script, so it suppresses an error when the bullet hits the enemy again. It’s supposed to be shorthand for:

if (enemy != null)     enemy.Death(); 

The code works; the error is suppressed. However, the IDE that I’m using, Jetbeans Rider, gives the following warning:

‘?.’ on a type deriving from ‘UnityEngine.Object’ bypasses the lifetime check on the underlying Unity object.

What does that mean exactly? Should I continue using the null conditional operator?