Question: converting RealRange entries to normal list

when getting sequence of RealRange, I'd like to convert this to normal list. Currently I have to use map twice on the result, but I think there should be simpler way.

Below is what I do. I was wondering if there is a better way in Maple to do this, may be a built in command?

Basically, if the input is

RealRange(-2*Pi,Open(-7/4*Pi)), RealRange(Open(-5/4*Pi),Open(-3/4*Pi)), 
RealRange(Open(-1/4*Pi),Open(1/4*Pi)), RealRange(Open(3/4*Pi),Open(5/4*Pi)), 
RealRange(Open(7/4*Pi),2*Pi)

I want to change the above to normal list like this (without any Open, etc.. in it) to make it easier to post process (say for plotting and so on)

[[-2*Pi, -7/4*Pi], [-5/4*Pi, -3/4*Pi], [-1/4*Pi, 1/4*Pi], [3/4*Pi, 5/4*Pi], [7/4*Pi, 2*Pi]]

This is what I do now on an example that generates sequence of RealRange
 

restart;

f:=x->2*x-tan(x);
the_intervals:=solve(diff(f(x),x)>0 and x>=-2*Pi and x<= 2*Pi,x);

proc (x) options operator, arrow; 2*x-tan(x) end proc

RealRange(-2*Pi, Open(-(7/4)*Pi)), RealRange(Open(-(5/4)*Pi), Open(-(3/4)*Pi)), RealRange(Open(-(1/4)*Pi), Open((1/4)*Pi)), RealRange(Open((3/4)*Pi), Open((5/4)*Pi)), RealRange(Open((7/4)*Pi), 2*Pi)

lprint(the_intervals);

RealRange(-2*Pi,Open(-7/4*Pi)), RealRange(Open(-5/4*Pi),Open(-3/4*Pi)),
RealRange(Open(-1/4*Pi),Open(1/4*Pi)), RealRange(Open(3/4*Pi),Open(5/4*Pi)),
RealRange(Open(7/4*Pi),2*Pi)

map(X->convert(X,list),[the_intervals]);
map(X1->map(X2->`if`(has(X2,Open),op(X2),X2),X1),%);

[[-2*Pi, Open(-(7/4)*Pi)], [Open(-(5/4)*Pi), Open(-(3/4)*Pi)], [Open(-(1/4)*Pi), Open((1/4)*Pi)], [Open((3/4)*Pi), Open((5/4)*Pi)], [Open((7/4)*Pi), 2*Pi]]

[[-2*Pi, -(7/4)*Pi], [-(5/4)*Pi, -(3/4)*Pi], [-(1/4)*Pi, (1/4)*Pi], [(3/4)*Pi, (5/4)*Pi], [(7/4)*Pi, 2*Pi]]

lprint(%);

[[-2*Pi, -7/4*Pi], [-5/4*Pi, -3/4*Pi], [-1/4*Pi, 1/4*Pi], [3/4*Pi, 5/4*Pi], [7/
4*Pi, 2*Pi]]

 


 

Download convert_realrange_to_list.mw

 

Please Wait...