Mathematical optimization – Local function in the block does not evaluate

I am currently working on the implementation of a non-linear constraint constraint optimization algorithm in Mathematica. I managed to make it work to a certain extent. However, it performs too many intermediate steps (unconstrained optimizations using Newton's method). Therefore, I want to add more precise stopping conditions, which require moving the Newton function within the scope of the nonlinear resizing function.

My problem is that the function 'newton & # 39; is not under evaluation.

                nlr[f_, c_, x0_, y0_, [Epsilon]_, nu_, k_]: = Block[
    {newton, vars = Variables@Level[f, {-1}], L, dL, F, con, [Psi],
re[Psi], itt},
[Psi][t_]    : =
By pieces[{{Log[t + 1], t> = -0.5}, {-2 t ^ 2 + 1/2 + Log[1/2],
t < -0.5}}];
d[Psi][t_] := 
Piecewise[{{1/(1.0 + t), t >= -0.5}, {-4.0 t, t < -0.5}}];
con[x_] := 
ReplaceAll[c, Rule[#[[1]], #[[2]]] & /@ Transpose@{vars, x}];
F[x_] := 
ReplaceAll[f, Rule[#[[1]], #[[2]]] & /@ Transpose@{vars, x}];

newton[[Phi]_, x00_] := Block[
 {vars = Variables@Level[[Phi], {-1}], df, H, F, itt},

 df = D[[Phi], {vars}];
 H = D[[Phi], {vars, 2}];
 F[x_] := 
  ReplaceAll[[Phi], 
   Rule[#[[1]], #[[2]]] & /@ Transpose@{vars, x}];

 itt[x_] := Block[{dx, grad, a, [Lambda] = 0.0001},
   grad = 
    ReplaceAll[df, Rule[#[[1]], #[[2]]] & /@ Transpose@{vars, x}];

   (*Regularization*)
   [Lambda] = 
    NestWhile[
     10*# &, [Lambda], ! 
       PositiveDefiniteMatrixQ[
        ReplaceAll[H + #*IdentityMatrix[Length@vars], 
         Rule[#[[1]], #[[2]]] & /@ Transpose@{vars, x}]] &, 1, 20];

   dx = -Inverse[
       ReplaceAll[H + [Lambda]*IdentityMatrix[Length@vars], 
        Rule[#[[1]], #[[2]]] & /@ Transpose@{vars, x}]].grad;

   (*Armijo Step size*)
   a = NestWhile[#/2 &, 1,
     ReplaceAll[f, 
         Rule[#[[1]], #[[2]]] & /@ Transpose@{vars, x + #*dx}] - 
        ReplaceAll[f, 
         Rule[#[[1]], #[[2]]] & /@ Transpose@{vars, x}] >=
nu # grad.dx &,
1, 10];

Return[x + a dx];
];

Back @ NestWhileList[itt, x00,
Standard[
Replaces all[Df
Rule[#[[1]], #[[2]]]& / @ Transpose @ {vars, #}]]>
Replaces all[Cond,
Rule[#[[1]], #[[2]]]& / @ Transpose @ {vars, #}]And
1, 50]];



it[xy_] : = Block[{xs, ys, [CapitalPhi]}
[CapitalPhi] = f - 1 / k xy[[2]]. ([Psi] / @ (k * c));
xs = newton[[[[[CapitalPhi], xy[[1]][Epsilon], naked];
Impression[Length@xs, " Newton Steps"];
Print @ xs;
xs = Last @ xs;
Print @ xs;
Yes[Length@Select[con[xs], # < 0 &] > 0
Impression["Constraint Violation: ", Norm@Select[con[xs], # < 0 &]];,
      Print["No Constraint Violation"]];
     ys = xy[[2]]*(d[Psi] /@ (k con[xs]));
     Return@{xs, ys};
     ];

   Return@NestWhileList[itt, {x0, y0},
     Max[Min@(-con[#[[1]]]),
        Norm@
         ReplaceAll[D[f - 1/k #[[2]].([Psi] /@ (k*c)), {vars}], 
          Rule[#[[1]], #[[2]]] & /@ Transpose@{vars, #[[1]]}],
        Norm[DiagonalMatrix[#[[2]]].con[#[[1]]]]
        ] >= [Epsilon] And
1, 10];
];

Please refer to the enclosed notebook for more details.

Notepad: https://drive.google.com/file/d/1tv-WkXagG6Z6PZm4u4g8DAq_i8igGz-M/view?usp=sharing