Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Maxima's grind function fails when used in mcall #33

Open
odysseus9672 opened this issue Jul 28, 2017 · 5 comments
Open

Bug: Maxima's grind function fails when used in mcall #33

odysseus9672 opened this issue Jul 28, 2017 · 5 comments

Comments

@odysseus9672
Copy link
Contributor

When I try to use the grind function in mcall I get a warning. Using string on the same example works fine:

julia> mcall( m"string(x+5*h)" )
 
                                     x+5*h

julia> mcall( m"grind(x+5*h)" )
WARNING: Invalid Maxima expression
 
incorrect syntax: Missing )
'(x+5*h$
      ^

Here's the corresponding i/o from a Maxima session:

(%i1) string(x + 5*h);
(%o1)                                x+5*h
(%i2) grind(x + 5*h);

x+5*h$
(%o2)                                done

The reason for using grind is that it, basically, does the same thing as string, but it breaks the output up into individual lines. Here, for example, is the output of grind for a longer expression:

(-(4*m^2*r0^9)/h^5)-(6*m^2*r0^8)/h^4-(9*m^2*r0^7)/h^3-(36*r0^7)/h^5
                   -(15*m^2*r0^6)/(2*h^2)-(54*r0^6)/h^4-(9*m^2*r0^5)/(5*h)
                   -(72*r0^5)/h^3+(m^2*r0^4)/4-(45*r0^4)/h^2-(12*r0^3)/h
                   -(11*h^4*m^2)/840-(3*h^2)/14$

while for string it's:

(-(4*m^2*r0^9)/h^5)-(6*m^2*r0^8)/h^4-(9*m^2*r0^7)/h^3-(36*r0^7)/h^5-(15*m^2*r0^6)/(2*h^2)-(54*r0^6)/h^4-(9*m^2*r0^5)/(5*h)-(72*r0^5)/h^3+(m^2*r0^4)/4-(45*r0^4)/h^2-(12*r0^3)/h-(11*h^4*m^2)/840-(3*h^2)/14

(possibly with quote marks that Maxima isn't displaying).

I'm not sure if the difference is that grind attempts to print the line to Maxima's output stream, while string just returns a string. As such, maybe this belongs in "won't fix", since fixing it may involve a major restructuring of how Maxima.jl interfaces with Maxima (i.e. giving the user some way to access Maxima's stdout).

For my use case, setting the flag grind : True will actually suffice.

@nsmith5 nsmith5 added the bug label Jul 28, 2017
@nsmith5
Copy link
Owner

nsmith5 commented Jul 28, 2017

Hmm, yeah that final $ in the output is very likely the problem. Though I'll have to take a closer look to be sure.

Note that you don't need to make calls to string in maxima. string(::MExpr) on the julia side already returns this "flat" representation of Maxima expressions

@odysseus9672
Copy link
Contributor Author

Right. I'm less interested in the flat representation than in the flat representation broken up over multiple lines for future readability, though.

@nsmith5
Copy link
Owner

nsmith5 commented Jul 28, 2017

Hmm, ok. And the full 2d representation isn't appropriate either?
eg,

      2   9       2   8      2   7        7       2   6        6      2   5
    4 m  r0     6 m  r0    9 m  r0    36 r0    15 m  r0    54 r0    9 m  r0
 (- --------) - -------- - -------- - ------ - --------- - ------ - --------
        5           4          3         5          2         4       5 h
       h           h          h         h        2 h         h
                                 5    2   4        4        3       4  2      2
                            72 r0    m  r0    45 r0    12 r0    11 h  m    3 h
                          - ------ + ------ - ------ - ------ - -------- - ----
                               3       4         2       h        840       14
                              h                 h

@odysseus9672
Copy link
Contributor Author

No, I'm trying to generate a Julia module which can get the once over with the precompiler. Attempting this the straightforward way, with just in time compilation of the Maxima expressions, was requiring more memory than my machine has. I also want the generated files to be, at least somewhat, human readable, which grind style formatting helps with. I don't need the grind function, since I can use the grind flag in conjunction with the string function to get the result I need. That is:

(%i1) grind:True;
(%o1)                                True
(%i2) string((-(4*m^2*r0^9)/h^5)-(6*m^2*r0^8)/h^4-(9*m^2*r0^7)/h^3-(36*r0^7)/h^5-(15*m^2*r0^6)/(2*h^2)-(54*r0^6)/h^4-(9*m^2*r0^5)/(5*h)-(72*r0^5)/h^3+(m^2*r0^4)/4-(45*r0^4)/h^2-(12*r0^3)/h-(11*h^4*m^2)/840-(3*h^2)/14
);
(%o2) (-(4*m^2*r0^9)/h^5)-(6*m^2*r0^8)/h^4-(9*m^2*r0^7)/h^3-(36*r0^7)/h^5
                   -(15*m^2*r0^6)/(2*h^2)-(54*r0^6)/h^4-(9*m^2*r0^5)/(5*h)
                   -(72*r0^5)/h^3+(m^2*r0^4)/4-(45*r0^4)/h^2-(12*r0^3)/h
                   -(11*h^4*m^2)/840-(3*h^2)/14

@nsmith5
Copy link
Owner

nsmith5 commented May 30, 2019

This is an old, conversation but just to finalize this: it does seem to be the fact that grind uses stdout. This interferes with Maxima.jl (which is communicating with maxima over a pipe). Labelling this as won't fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants