TimeConstrained with absolute timing

0

Due to backwards compatibility issues, I am using Mathematica 8.0 and it seems to have an issue with TimeConstrained.

I am using this function to set a limit to the time elapsed in a FullSimplify call:

FullSimplifyTime[Equation_, TrigSimplify_, TimeConstraint_] :=
 (Module[{Result, OriginalEquation},
   Print["Starting FullSimplify with ", TimeConstraint , 
    " second time constraint."];
   OriginalEquation = Equation;
   (* Set up a timed constrained equation, 
   return original equation if time is exceeded*)
   Result = TimeConstrained[
     FullSimplify[Equation, Trig -> TrigSimplify],
     TimeConstraint,
     NULL
     ];
   If [Result == NULL,
    Result = OriginalEquation;
    Print["Time constraint exceeded."];
    Return[Result]
    ];
   Print["Simplified within time constraint."];
   Return[Result]
   ]
  )

I have used it without any issues, until now.

When trying to simplify this expression:

exp = L1 + (L7 (1 - (4 L7 (L1 - L2 Cos[\[CapitalTheta]2]) (Sqrt[(
              L1^2 + L2^2 - 
               2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
                L2 Cos[\[CapitalTheta]2])^2] + (
              L2 Sin[\[CapitalTheta]2])/(-L1 + 
               L2 Cos[\[CapitalTheta]2])) (-1 + (Sqrt[(
                L1^2 + L2^2 - 
                 2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
                  L2 Cos[\[CapitalTheta]2])^2] + (
                L2 Sin[\[CapitalTheta]2])/(-L1 + 
                 L2 Cos[\[CapitalTheta]2]))^2) + \[Sqrt](-(L1 - 
                 L2 Cos[\[CapitalTheta]2] + 
                 2 (L6 - L7) (Sqrt[(
                    L1^2 + L2^2 - 
                    2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
                    L2 Cos[\[CapitalTheta]2])^2] + (
                    L2 Sin[\[CapitalTheta]2])/(-L1 + 
                    L2 Cos[\[CapitalTheta]2])) + (L1 - 
                    L2 Cos[\[CapitalTheta]2]) (Sqrt[(
                    L1^2 + L2^2 - 
                    2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
                    L2 Cos[\[CapitalTheta]2])^2] + (
                    L2 Sin[\[CapitalTheta]2])/(-L1 + 
                    L2 Cos[\[CapitalTheta]2]))^2) (L1 - 
                L2 Cos[\[CapitalTheta]2] + 
                2 (-L6 + L7) (Sqrt[(
                   L1^2 + L2^2 - 
                    2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
                    L2 Cos[\[CapitalTheta]2])^2] + (
                   L2 Sin[\[CapitalTheta]2])/(-L1 + 
                    L2 Cos[\[CapitalTheta]2])) + (L1 - 
                   L2 Cos[\[CapitalTheta]2]) (Sqrt[(
                   L1^2 + L2^2 - 
                    2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
                    L2 Cos[\[CapitalTheta]2])^2] + (
                   L2 Sin[\[CapitalTheta]2])/(-L1 + 
                    L2 Cos[\[CapitalTheta]2]))^2) (L1 - 
                L2 Cos[\[CapitalTheta]2] - 
                2 (L6 + L7) (Sqrt[(
                   L1^2 + L2^2 - 
                    2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
                    L2 Cos[\[CapitalTheta]2])^2] + (
                   L2 Sin[\[CapitalTheta]2])/(-L1 + 
                    L2 Cos[\[CapitalTheta]2])) + (L1 - 
                   L2 Cos[\[CapitalTheta]2]) (Sqrt[(
                   L1^2 + L2^2 - 
                    2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
                    L2 Cos[\[CapitalTheta]2])^2] + (
                   L2 Sin[\[CapitalTheta]2])/(-L1 + 
                    L2 Cos[\[CapitalTheta]2]))^2) (L1 - 
                L2 Cos[\[CapitalTheta]2] + 
                2 (L6 + L7) (Sqrt[(
                   L1^2 + L2^2 - 
                    2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
                    L2 Cos[\[CapitalTheta]2])^2] + (
                   L2 Sin[\[CapitalTheta]2])/(-L1 + 
                    L2 Cos[\[CapitalTheta]2])) + (L1 - 
                   L2 Cos[\[CapitalTheta]2]) (Sqrt[(
                   L1^2 + L2^2 - 
                    2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
                    L2 Cos[\[CapitalTheta]2])^2] + (
                   
                   L2 Sin[\[CapitalTheta]2])/(-L1 + 
                    L2 Cos[\[CapitalTheta]2]))^2)))^2/((L1 - 
             L2 Cos[\[CapitalTheta]2])^2 + 
           2 (L1^2 - 2 L6^2 - 4 L1 L7 + 2 L7^2 + 
              L2 Cos[\[CapitalTheta]2] (-2 L1 + 4 L7 + 
                 L2 Cos[\[CapitalTheta]2])) (Sqrt[(
              L1^2 + L2^2 - 
               2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
                L2 Cos[\[CapitalTheta]2])^2] + (
              L2 Sin[\[CapitalTheta]2])/(-L1 + 
               L2 Cos[\[CapitalTheta]2]))^2 + (L1 - 
              L2 Cos[\[CapitalTheta]2])^2 (Sqrt[(
              L1^2 + L2^2 - 
               2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
                L2 Cos[\[CapitalTheta]2])^2] + (
              L2 Sin[\[CapitalTheta]2])/(-L1 + 
               L2 Cos[\[CapitalTheta]2]))^4)^2))/(1 + (4 L7 (L1 - 
            L2 Cos[\[CapitalTheta]2]) (Sqrt[(
            L1^2 + L2^2 - 
             2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
              L2 Cos[\[CapitalTheta]2])^2] + (
            L2 Sin[\[CapitalTheta]2])/(-L1 + 
             L2 Cos[\[CapitalTheta]2])) (-1 + (Sqrt[(
              L1^2 + L2^2 - 
               2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
                L2 Cos[\[CapitalTheta]2])^2] + (
              L2 Sin[\[CapitalTheta]2])/(-L1 + 
               L2 Cos[\[CapitalTheta]2]))^2) + \[Sqrt](-(L1 - 
               L2 Cos[\[CapitalTheta]2] + 
               2 (L6 - L7) (Sqrt[(
                  L1^2 + L2^2 - 
                   2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
                    L2 Cos[\[CapitalTheta]2])^2] + (
                  L2 Sin[\[CapitalTheta]2])/(-L1 + 
                   L2 Cos[\[CapitalTheta]2])) + (L1 - 
                  L2 Cos[\[CapitalTheta]2]) (Sqrt[(
                  L1^2 + L2^2 - 
                   2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
                    L2 Cos[\[CapitalTheta]2])^2] + (
                  L2 Sin[\[CapitalTheta]2])/(-L1 + 
                   L2 Cos[\[CapitalTheta]2]))^2) (L1 - 
              L2 Cos[\[CapitalTheta]2] + 
              2 (-L6 + L7) (Sqrt[(
                 L1^2 + L2^2 - 
                  2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
                   L2 Cos[\[CapitalTheta]2])^2] + (
                 L2 Sin[\[CapitalTheta]2])/(-L1 + 
                  L2 Cos[\[CapitalTheta]2])) + (L1 - 
                 L2 Cos[\[CapitalTheta]2]) (Sqrt[(
                 L1^2 + L2^2 - 
                  2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
                   L2 Cos[\[CapitalTheta]2])^2] + (
                 L2 Sin[\[CapitalTheta]2])/(-L1 + 
                  L2 Cos[\[CapitalTheta]2]))^2) (L1 - 
              L2 Cos[\[CapitalTheta]2] - 
              2 (L6 + L7) (Sqrt[(
                 L1^2 + L2^2 - 
                  2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
                   L2 Cos[\[CapitalTheta]2])^2] + (
                 L2 Sin[\[CapitalTheta]2])/(-L1 + 
                  L2 Cos[\[CapitalTheta]2])) + (L1 - 
                 L2 Cos[\[CapitalTheta]2]) (Sqrt[(
                 L1^2 + L2^2 - 
                  2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
                   L2 Cos[\[CapitalTheta]2])^2] + (
                 L2 Sin[\[CapitalTheta]2])/(-L1 + 
                  L2 Cos[\[CapitalTheta]2]))^2) (L1 - 
              L2 Cos[\[CapitalTheta]2] + 
              2 (L6 + L7) (Sqrt[(
                 L1^2 + L2^2 - 
                  2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
                   L2 Cos[\[CapitalTheta]2])^2] + (
                 L2 Sin[\[CapitalTheta]2])/(-L1 + 
                  L2 Cos[\[CapitalTheta]2])) + (L1 - 
                 L2 Cos[\[CapitalTheta]2]) (Sqrt[(
                 L1^2 + L2^2 - 
                  2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
                   L2 Cos[\[CapitalTheta]2])^2] + (
                 L2 Sin[\[CapitalTheta]2])/(-L1 + 
                  L2 Cos[\[CapitalTheta]2]))^2)))^2/((L1 - 
           L2 Cos[\[CapitalTheta]2])^2 + 
         2 (L1^2 - 2 L6^2 - 4 L1 L7 + 2 L7^2 + 
            L2 Cos[\[CapitalTheta]2] (-2 L1 + 4 L7 + 
               L2 Cos[\[CapitalTheta]2])) (Sqrt[(
            L1^2 + L2^2 - 
             2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
              L2 Cos[\[CapitalTheta]2])^2] + (
            L2 Sin[\[CapitalTheta]2])/(-L1 + 
             L2 Cos[\[CapitalTheta]2]))^2 + (L1 - 
            L2 Cos[\[CapitalTheta]2])^2 (Sqrt[(
            L1^2 + L2^2 - 
             2 L1 L2 Cos[\[CapitalTheta]2])/(L1 - 
              L2 Cos[\[CapitalTheta]2])^2] + (
            L2 Sin[\[CapitalTheta]2])/(-L1 + 
             L2 Cos[\[CapitalTheta]2]))^4)^2);

It seems to work fine in Mathematica 12.1:

AbsoluteTiming[FullSimplifyTime[exp, True, 10];]

*Starting FullSimplify with 10 second time constraint.*

*Time constraint exceeded.*

{10.0546, Null}

But it gets stuck in Mathematica 8.0, it won't show the time exceeded message.

Any idea on what is going on or how to fix it? If this is a known issue in Mathematica 8.0, is there any way to constraint an evaluation using absolute timing?

Thank you.

Guillermo Oliver

Posted 2021-02-03T23:45:22.377

Reputation: 399

No answers