2
$\begingroup$

Warning : At least in my PC (windows 10, mathematica V12.2), some of the codes here led to fatal error.

Fatal means mathematica will freeze + 'Abort Evaluation' will not work. I had to quit the kernel and lose everything.

So save every working .nb files and then try this.

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

This post is related with previous post Extracting list structure from nested list

The answerer "kglr" emphasized that
Note: Internal`CopyListStructure[arg1_, arg2_] requires Length[Flatten@arg1] == Length @ arg2

But what if Length of Flatten@arg1 are arg2 different?

In[1] Internal`CopyListStructure[{{a, {b, {{{{{c}}}}, d}}}}, {1, 2, 3, 4}]
Out[1] {{1, {2, {{{{{3}}}}, 4}}}}  
(** standard case, works OK **)


In[2] Internal`CopyListStructure[{{a, {b, {{{{{c}}}}, d}}}}, {1, 2, 3, 4, 5}]
Out[2] Internal`CopyListStructure[{{a, {b, {{{{{c}}}}, d}}}}, {1, 2, 3, 4, 5}] 
(** arg2 is longer case : Does nothing - Parrots back what I say. **)

In[3]  Internal`CopyListStructure[{{a, {b, {{{{{c}}}}, d}}}}, {1, 2, 3}]
Out[3]  {{1, {2, {{{{{3}}}}, d}}}}
(** Flatten@arg1 is longer case : Does as much as one can. **)

In[4]  Internal`CopyListStructure[{{a, {b, {{{{{c}}}}, d}}}}, {1, 2}]
Out[4]  
(** Flatten@arg1 is longer case : But this time, fatal error**)

In[5]  Internal`CopyListStructure[{{a, {b, {{{{{c}}}}, d}}}}, {1}]
Out[5]  
(** Flatten@arg1 is longer case : But this time, fatal error**)

I want to know that you(your PC) are having the same trouble.

I think there is a workaround but why does mathematica produces such fatal errors when Flatten@arg1 is longer?

Don't you think this is a bug?

$\endgroup$
0

1 Answer 1

15
$\begingroup$

Internal context functions have been written for specific uses inside Mathematica internal code. They may expect that the input satisfies certain properties, and may crash if it doesn't. From the code comment:

CopyListStructure[e, f]: e is a nested list, f is a flat list, and Length[Flatten[e]]==Length[f]. Returns an expression ans with the same nested list structure as e, and such that Flatten[ans]===f.

Also, an internal function may or may not exist in future versions of Mathematica.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.