2
$\begingroup$

I'm using Mathematica 11.0 on 64-bit Linux.

When performing a large operation calling an external bash script, I encounter this error: enter image description here

This is the line that causes the problem:

var = RunThrough["'" <> FileNameJoin[{NotebookDirectory[],"MathematicaList_GroupData.sh"}] <> "'" <> " -c R coxeter [3,2,7] 38", ""];

This line calls an external script, returning the output as a string and assigning it to the symbol var. The number 38 in the script above can be any positive integer. The larger it is, the longer the script takes and the longer the final output. Above some threshold, when the number is too large, this error occurs consistently, and the variable var is assigned Null.

My system is not running out of available RAM or CPU.

If I run the script manually from the terminal with the exact arguments as above in the RunThrough command, it behaves as expected and gives the correct output. It's just Mathematica which seems to have a problem reading this output.

I've also tried piping the output of the script to the file and reading it with Get, but the same error occurs. The output file looks to be well-formatted Mathematica syntax.

How can I resolve this error?


Here is a minimum working example that can reproduce the error: try running Get on this text file. The link is not permanent, but should last 6 months from the date of posting this question.

Here is sample data for an input of 4:

List[R[1],R[2],R[3],R[1]**R[2],R[2]**R[1],R[3]**R[1],R[1]**R[3],R[2]**R[3],R[1]**R[2]**R[3],R[2]**R[1]**R[3],R[1]**R[3]**R[1],R[3]**R[1]**R[2],R[2]**R[3]**R[1],R[1]**R[2]**R[1],R[3]**R[1]**R[3],R[1]**R[2]**R[3]**R[1],(R[1]**R[3])^2,R[2]**R[1]**R[3]**R[1],R[1]**R[3]**R[1]**R[2],R[2]**R[3]**R[1]**R[3],R[1]**R[2]**R[1]**R[3],R[2]**R[3]**R[1]**R[2],R[3]**R[1]**R[2]**R[3],(R[3]**R[1])^2]
$\endgroup$
  • 1
    $\begingroup$ What happens if you put the result of the bash script in a file and try to Get it? The output should be Mathematica syntax if RunThrough works. $\endgroup$ – Pillsy Apr 9 '17 at 1:53
  • $\begingroup$ @Pillsy - The same error occurs. The file is a single line of text, sized 1.9MB. I can't read the whole lot obviously, but looking at the beginning and end it looks to be well formatted Mathematica syntax as for any other input below 38. $\endgroup$ – Myridium Apr 9 '17 at 2:03
  • $\begingroup$ What kind of data are you getting from the script? A list? An array? Something else? $\endgroup$ – Pillsy Apr 9 '17 at 2:08
  • $\begingroup$ @Pillsy - I've added a link to the text file. Running Get on this file reproduces the error for me. I've also added sample data for an input of 4. $\endgroup$ – Myridium Apr 9 '17 at 2:25
1
$\begingroup$

I downloaded the text file as a string:

string = Import["http://filebin.ca/3IQbQp1Bk2H7", "String"];

Trying to turn it into an expression gave me the same syntax error you had:

sample = ToExpression[string, InputForm];
(* ToExpression::sntx: 
     Invalid syntax in or before "                                                         

        <<1627583>>                                                                     
       ^". *)

In order to get a better handle on that error, I used SyntaxLength to find its position:

error = SyntaxLength[string]
(* 1627792 *)

Then I took a small chunk of string around error to see if anything looked weird:

StringTake[string, {-10, +10} + error]
(* "[2]**R[3]**f\\1,R[1]**" *)

That backslash isn't valid syntax. I'm guessing that's your error. Similar errors appear three times in string:

StringCases[string, 
 Repeated[_, {10, 10}] ~~ "\\" ~~ Repeated[_, {10, 10}]]
(* {"]**R[3]**f\\1,R[1]**R[", 
    "]**R[1]**f\\3,R[2]**(R", 
    "]**R[1]**f\\3,R[2]**R["} *)

It looks like something is causing your script to generate output that isn't valid syntax when you give it an input of 38 or greater.

$\endgroup$
  • $\begingroup$ Thank you! I didn't know what that <<number>> meant. Now I do. I'm not sure what's causing those backslashes to appear. I'll have to look into it. $\endgroup$ – Myridium Apr 9 '17 at 3:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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