rcst / rim

rim provides an interface to Maxima for R. Maxima is a powerful and fairly complete computer algebra system.
10 stars 2 forks source link

Knitr Engine Throws Error when Solving Rational Inequalities by fourier_elim #46

Open HankNu opened 21 hours ago

HankNu commented 21 hours ago

I can solve this inequality in Xmaxima.

load("fourier_elim");
fourier_elim([x^2-1>0],[x]);
(%o1) /usr/local/share/maxima/5.47.0/share/fourier_elim/fourier_elim.lisp
(%i2) 
(%o2)                        [1 < x] or [x < - 1]

Then I try to test this route with rim in R.

library(rim)
maxima.start()
maxima.version()

But fourier_elimcannot be knitted,

load("fourier_elim");
load("fourier_elim");
fourier_elim([x^2-1>0],[x]);

which throw the error as below:

[fourier_elim_1]     Error in `if (grepl("no-convert", p <- private$reply$result$wol$rstr)) ...`:
! the condition has length > 1
Backtrace:
  1. rmarkdown::render(...)
  2. knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
  3. knitr:::process_file(text, output)
  6. knitr:::process_group(group)
  7. knitr:::call_block(x)
  8. knitr:::block_exec(params)
 11. rim (local) engine(options)
 12. maxima.env$mx$get(pc)

Warning message:
In maxima.env$mx$get(pc) : WARNING: redefining BIGFLOAT::WHILE in DEFMACRO

Quitting from lines 701-703 [fourier_elim_1] (rim123.Rmd)
Execution halted

Then I find that solve_rat_ineq can be knitted well.

load(solve_rat_ineq);
solve_rat_ineq(x^2-1>0);

My environment is

sessionInfo()
maxima.version()

There is some other inequalities to be tested.

fourier_elim((x + y < 5) and (x - y >8),[x,y]);
fourier_elim(((x + y < 5) and x < 1) or (x - y >8),[x,y]);
HankNu commented 21 hours ago

I guess it is because the output of fourier_elim can not be done with by rim, e.g.

(%i1) load(solve_rat_ineq);
solve_rat_ineq(x^2-1>0);
(%o1) /usr/local/share/maxima/5.47.0/share/solve_rat_ineq/solve_rat_ineq.mac
(%i2) 
(%o2)                        [[x < - 1], [x > 1]]
(%i3) load("fourier_elim");
fourier_elim([x^2-1>0],[x]);
(%o3) /usr/local/share/maxima/5.47.0/share/fourier_elim/fourier_elim.lisp
(%i4) 
(%o4)                        [1 < x] or [x < - 1]

As we can see, the first output (%o2) is a list [[x < - 1], [x > 1]], but the second output (%o4) is a string [1 < x] or [x < - 1].

HankNu commented 20 hours ago

This is the PDF output of my Rmd.

fourier_elim_test.pdf