This is my code.
I augmented the nkm hybrid model with an alpha parameter and changed the PC.
When I use other optimizers the OSR is smaller than commitment and discretion. But here I used the standardized vaules 0.5 and 1.5 for the OSR
In the case of a purely backward-looking and stationary expectations my discretion solution is similar to commitment.

When I change the parameters gamma_f and gamma_b step-by-step to 0.2 and 0.8 the OSR is in the middle. But for gamma_f 0.1 and gamma_9.0 I have the same struggle as in the purely backward-looking case.

just run the file and you will see the loss won’t be zero.
As I understand the concept of commitment the loss has to be zero because of the contemporaneous variable in the pc.

The loss in commitment and discretion is the same. I would agree to that because in the purely backward looking case we expect this result.
Now, I understand why the OSR is bigger than commitment and discretion solution. But Iam not sure about the loss value. I was thinking commitment and discretion both has to have a Loss of 0 and not 1,2860.

Now I think your are right. I had error in reasoning.
If the loss would be zero the system is perfect and the central bank does not need to do anything.
I was confused about the contemporaneous variable in the PC and why the OSR is bigger than the commitment and the discretion solution.
I tried OSR with taylor type , Ad-hoch Taylor rule and a pure forward looking TR.
In all other combinations between gamma_f and gamma_b (more weight on gamma_b)the forward-looking TR has the closest loss to commitment expect to this case we are talking about.
I refer to the paper of Leitemo (2008) if expectations are backward-looking the policy should be forward-looking. In my computation it is OSR Taylor type ( no forward-looking elements on it).
I tried to explain it to myself in the way:
Because of the alpha=0 the whole backward-looking part is zero, so the pc is not backward-looking anymore, but contemporaneous and thats why the OSR is the best choice.
Is this explanation right? But with alpha = 0 all combinations has no backward-looking part anymore but the forward-looking TR comes close to commitment.

I am not sure I am following.Ramsey, i.e. optimal policy under commitment should always be the best. OSR is a form of commitment, but where the policy is less flexible, so the loss must be higher. Whether optimal policy under discretion performs better than OSR cannot be said a priori. Regarding which type of OSR performs best, I don’t think we can say anything general that holds in all models.

under commitment I have a Loss of= 6,6634
Iam using a optimal simple rule of taylor type: i= gamma_pipi(+1) + gamma_xx(+1)
and get a Loss of 6,6634

OPTIMAL VALUE OF THE PARAMETERS:

gamma_pi 1.23027
gamma_x -0.081414

Objective function : 6.66336

My first question is:
Makes it sense that gamma_x is negative?
And how can I explain that this OSR is the best one compared to others?
In this case my PC and IS have forward-looking expectations, But can I say that my whole system is forward-looking and backward-looking? Does the part of the IS: phi*x(-1) dominate?

When I set phi=1 the IS curve looks like: x = x(-1)1/sigma(i- pi(+1))
In this case the OSR of Taylor type is the best choice follwed by interest rate smoothing OSR, which makes more sense for me.
The expectations of the agents are backward-looking in the IS. So we have a forward PC and a backward IS curve and the CB needs to react with osr of taylor type.

When I set phi= 0 the PC and IS are backward-looking and the best rule for the CB is with interest rate smoothing.

Under commitment, the individual takes the promises of the central bank into account.

In Gali, he says that if those promises are credible, it will bring down expected inflation, and overall inflation will be lower than under discretionary policy.

In some other texts, it says if the promises are credible, expected inflation will not increase as much under commitment, and overall inflation will be lower than under discretionary policy.

It looks like the promises-credibility-lower inflation story is qualitative in the model. Maybe not, but I cannot actually see which equation(s) embodies this story…and why the two narratives I have mentioned above are kinda a little bit different…but same concept though.