Message Boards Message Boards

0
|
794 Views
|
0 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Feed the result of HoldComplete to codeformatter.

Posted 1 year ago

I want to use the output of HoldComplete as the input of CodeFormat, as shown below:

In[106]:= count=0;(matrices=NestWhile[(Print[count++];
Union[#~Join~Flatten[Outer[Dot,{gMatrix,hMatrix,kMatrix},#,1],1]])&,{IdentityMatrix[7]},Length[#2]!=Length[#1]&,2,99])//Length//Timing//HoldComplete

Out[106]= HoldComplete[
 Timing[
   Length[matrices = 
     NestWhile[(Print[count++]; 
        Union[Join[#1, 
          Flatten[Outer[Dot, {gMatrix, hMatrix, kMatrix}, #1, 1], 
           1]]]) &, {IdentityMatrix[7]}, Length[#2] != Length[#1] &, 
      2, 99]]]]

In[104]:= CodeFormat["
Timing[Length[
  matrices = 
   NestWhile[(Print[count++]; 
      Union[Join[#1, 
        Flatten[Outer[Dot, {gMatrix, hMatrix, kMatrix}, #1, 1], 
         1]]]) &, {IdentityMatrix[7]}, Length[#2] != Length[#1] &, 2, 
    99]]]
"]

Out[104]= "Timing[
    Length[
        matrices =
            NestWhile[
                (
                    Print[count++];
                    Union[Join[#1, Flatten[Outer[Dot, {gMatrix, \
hMatrix,
                         kMatrix}, #1, 1], 1]]]
                )&
                ,
                {IdentityMatrix[7]}
                ,
                Length[#2] != Length[#1]&
                ,
                2
                ,
                99
            ]
    ]
]"

How to integrate the above process to obtain the final expression in the following form instead of the formatted result of the string?

Timing[
    Length[
        matrices =
            NestWhile[
                (
                    Print[count++];
                    Union[Join[#1, Flatten[Outer[Dot, {gMatrix, hMatrix,
                         kMatrix}, #1, 1], 1]]]
                )&
                ,
                {IdentityMatrix[7]}
                ,
                Length[#2] != Length[#1]&
                ,
                2
                ,
                99
            ]
    ]
]

Best regards,
Zhao

POSTED BY: Hongyi Zhao
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract