acer

30305 Reputation

29 Badges

18 years, 256 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

It seems that it can be done -- at least for smaller n -- by temporary substitutions a[i]=S[i]+b[i], then resubstituting for S[i] at the end.

The timing increases with n. Perhaps over badly. I lost patience waiting for P(7) to finish. There are also memory consumption issues involved. The OP did mention "small m" in the Question's title, however.

Of course, this is somewhat ad hoc and tailored for the problem at hand. I started by considering replacing a patterned collection of the arguments to the trig calls present. I tried a few, before success.

It might, however, suggest a broader approach. I mean, something other than scanning around speculatively for substitutions or selective freezing.

restart;

sineExpr:=(m::posint)-> local t,j;
                        add(mul(ifelse(j<>t,
                                       ':-sin'(a[j]-b[t])/':-sin'(b[j]-b[t]),
                                       ':-sin'(a[t]-b[t])),j=1..m),t=1..m):

 

P:=proc(n) local i,e,r,u,S;
  e:=sineExpr(n):
  r:=[seq(a[i]=S[i]+b[i],i=1..n)];
  u:=[seq(S[i]=a[i]-b[i],i=1..n)];
  eval(combine(simplify(expand(eval(e,r)))),u);
end proc:

 

seq(CodeTools:-Usage(print(P(i))), i=1..6);

sin(a[1]-b[1])

memory used=24.02MiB, alloc change=38.01MiB, cpu time=229.00ms, real time=229.00ms, gc time=33.99ms

sin(a[1]-b[1]+a[2]-b[2])

memory used=4.63MiB, alloc change=0 bytes, cpu time=54.00ms, real time=54.00ms, gc time=0ns

sin(a[3]-b[3]+a[2]-b[2]+a[1]-b[1])

memory used=62.38MiB, alloc change=70.00MiB, cpu time=680.00ms, real time=649.00ms, gc time=135.74ms

sin(a[4]-b[4]+a[3]-b[3]+a[2]-b[2]+a[1]-b[1])

memory used=21.23MiB, alloc change=0 bytes, cpu time=192.00ms, real time=193.00ms, gc time=0ns

sin(a[3]-b[3]+a[4]-b[4]+a[5]-b[5]+a[1]-b[1]+a[2]-b[2])

memory used=124.24MiB, alloc change=-4.00MiB, cpu time=1.25s, real time=1.14s, gc time=230.99ms

sin(a[6]-b[6]+a[3]-b[3]+a[1]-b[1]+a[4]-b[4]+a[5]-b[5]+a[2]-b[2])

memory used=1.58GiB, alloc change=163.77MiB, cpu time=15.36s, real time=13.51s, gc time=3.41s

Download sinId_accc.mw

And further words of caution. Some similar substitutions only work (here, with these particular intermediate steps) only for limited n values, eg.

restart;

sineExpr:=(m::posint)-> local t,j;
                        add(mul(ifelse(j<>t,
                                       ':-sin'(a[j]-b[t])/':-sin'(b[j]-b[t]),
                                       ':-sin'(a[t]-b[t])),j=1..m),t=1..m):

 

P2:=proc(n) local i,e,r,T;
  e:=sineExpr(n):
  r:=add(b[i],i=1..n)=T;
  eval(combine(simplify(expand(simplify(e,{r})))),(rhs=lhs)(r));
end proc:

 

seq(CodeTools:-Usage(print(P2(i))), i=1..4);

sin(a[1]-b[1])

memory used=28.61MiB, alloc change=71.01MiB, cpu time=262.00ms, real time=333.00ms, gc time=0ns

sin(-b[1]-b[2]+a[1]+a[2])

memory used=24.48MiB, alloc change=37.00MiB, cpu time=272.00ms, real time=444.00ms, gc time=80.57ms

sin(a[1]+a[3]+a[2]-b[1]-b[2]-b[3])

memory used=120.70MiB, alloc change=28.89MiB, cpu time=1.26s, real time=1.38s, gc time=245.30ms

-(-sin(-4*b[3]+a[3]+a[4]+a[2]+a[1]-2*b[2]+2*b[4])+sin(2*b[2]+a[3]+a[4]+a[2]+a[1]-2*b[1]-4*b[4])+sin(-4*b[1]+2*b[2]+a[3]+a[4]+a[2]+a[1]-2*b[3])+sin(-4*b[2]-2*b[1]+a[3]+a[4]+a[2]+a[1]+2*b[3])+sin(a[3]+a[4]+a[2]+a[1]-2*b[3]+2*b[1]-4*b[4])-sin(-4*b[2]+a[3]+a[4]+a[2]+a[1]-2*b[1]+2*b[4])-sin(a[3]+a[4]+a[2]+a[1]-2*b[2]+2*b[1]-4*b[4])-sin(-2*b[3]+a[3]+a[4]+a[2]+a[1]-4*b[1]+2*b[4])-sin(2*b[2]+a[3]+a[4]+a[2]+a[1]-4*b[1]-2*b[4])-sin(-4*b[1]-2*b[2]+a[3]+a[4]+a[2]+a[1]+2*b[3])+sin(2*b[3]+a[3]+a[4]+a[2]+a[1]-2*b[2]-4*b[4])+sin(-2*b[2]+a[3]+a[4]+a[2]+a[1]-4*b[1]+2*b[4])+sin(-4*b[3]+a[3]+a[4]+a[2]+a[1]-2*b[1]+2*b[4])-sin(-4*b[3]-2*b[1]+2*b[2]+a[3]+a[4]+a[2]+a[1])-sin(2*b[1]+a[3]+a[4]+a[2]+a[1]-4*b[3]-2*b[4])+sin(2*b[1]-4*b[2]+a[3]+a[4]+a[2]+a[1]-2*b[4])+sin(2*b[2]+a[3]+a[4]+a[2]+a[1]-4*b[3]-2*b[4])-sin(2*b[3]+a[3]+a[4]+a[2]+a[1]-4*b[2]-2*b[4])+sin(2*b[3]+a[3]+a[4]+a[2]+a[1]-4*b[1]-2*b[4])-sin(-4*b[2]+a[3]+a[4]+a[2]+a[1]-2*b[3]+2*b[1])+sin(-4*b[3]+a[3]+a[4]+a[2]+a[1]-2*b[2]+2*b[1])-sin(2*b[2]+a[3]+a[4]+a[2]+a[1]-2*b[3]-4*b[4])-sin(2*b[3]+a[3]+a[4]+a[2]+a[1]-2*b[1]-4*b[4])+sin(-4*b[2]+a[3]+a[4]+a[2]+a[1]-2*b[3]+2*b[4]))/(2*cos(-b[3]+3*b[2]+b[1]-3*b[4])-2*cos(3*b[3]-b[2]+b[1]-3*b[4])+2*cos(b[1]-3*b[2]+3*b[3]-b[4])-2*cos(3*b[1]-3*b[2]+b[3]-b[4])-2*cos(b[1]+3*b[2]-3*b[3]-b[4])-2*cos(3*b[1]-b[2]-3*b[3]+b[4])-2*cos(-b[3]-3*b[2]+b[1]+3*b[4])+2*cos(3*b[1]+b[2]-3*b[3]-b[4])-2*cos(b[2]-b[3]+3*b[1]-3*b[4])+2*cos(3*b[1]-3*b[2]-b[3]+b[4])+2*cos(-b[2]-3*b[3]+b[1]+3*b[4])+2*cos(b[3]-b[2]+3*b[1]-3*b[4]))

memory used=18.29GiB, alloc change=120.27MiB, cpu time=3.66m, real time=3.64m, gc time=55.68s

Download sinId_acb.mw

With an extra step you can obtain both any custom gridline color as well as the nicer curve (directly using the plot command, as you did) in your Maple 2023, as demonstrated in the following attachment.

restart

with(plots)

k := .9787011+(-10.88627-.9787011)/(1+(x/(0.4490702e-3))^1.792529)^.3004597

.9787011-11.8649711/(1+1001898.702*x^1.792529)^.3004597

plots:-display(plot(k, x = 10 .. 0.1e7, view = [10 .. 0.1e7, .92 .. .99], color = "Blue", background = "Ivory", filled = [color = "Cyan", transparency = .9], axis = [mode = log], size = [600, 300]), axis = [gridlines = [color = gray]])

Download gridlines_change_plot_ac.mw

Unfortunately your color adjustment to gridlines in the axis option does not work directly with plot's default of adaptive=geometric in Maple 2023.

That makes it fall back to adaptive=true, which produces that suboptimal curve portion that you've shown.

That's been fixed in Maple 2024.0, and your example works ok there.

ps. Supplying only gridlines=true produces a slightly darker shade than your forced color=gray.

You could import the whole thing as a Matrix, and then convert the second column to a list.

Eg,

   M:=ImportMatrix("example.txt",source=delimited,delimiter=" ");
   convert(M[..,2],list);

 

ps. I suspect that you could also do that first step as,
   ImportMatrix("dat_ex.txt",source=Matlab)

for n from 1 to 10 do
add(add(add(1/(i*j*k),i=1..n-j-k),j=1..n-2),k=1..n-2);
end do;

0

0

1

5/2

17/4

49/8

967/120

801/80

4523/378

84095/6048

Download add_exex.mw

And here is some timing comparison. I've used Maple 2023.2.1 here instead, because in my Linux 2024.0 the Iterator's internal fails to Compile (to faster code) and without compilation that Iterator approach takes very much longer.

I've changed the upper ends of the ranges from n down to n-2 in Ronan's approach using piecewise (since i,j,k are each at least 1). That improves the timing to compute all values n=1..30 from 1.872sec down to 1.422sec.

I've also included a further revision to that (end-point) modification of Ronan's approach, in which `if` is used instead of piecewise. Using piecewise here is a poor idea, in terms of performance.

kernelopts(version);

`Maple 2023.2, X86 64 LINUX, Nov 24 2023, Build ID 1762575`

restart;
str:=time[real]():
for n from 1 to 30 do
add(add(add(1/(i*j*k),i=1..n-j-k),j=1..n-2),k=1..n-2);
end do:
time[real]()-str;

0.31e-1

restart;
str:=time[real]():
for n from 1 to 30 do
add(add(add(`if`(i+j+k<=n, 1/(i*j*k),0),i=1..n-2),j=1..n-2),k=1..n-2);
end do:
time[real]()-str;

0.87e-1

restart;
s:=(n::posint)->add(add(1/~mul~(ListTools:-FlattenOnce(combinat:-permute~(combstruct['allstructs']('Partition'(l),'size'=3))))),l=3..n):
str:=time[real]():
seq(s(n), n = 1 .. 30):
time[real]()-str;

Warning, (in s) `l` is implicitly declared local

.381

restart;
str:=time[real]():
for n from 1 to 30 do
add(add(add(piecewise(i+j+k<=n, 1/(i*j*k),0),i=1..n-2),j=1..n-2),k=1..n-2);
end do:
time[real]()-str;

1.422

restart;
str:=time[real]():
s := 0:
for n to 30 do
    comps := Iterator:-Composition(n, parts = 3);
    s := s + add(1/mul(comp), comp in comps);
    #print(s);
end do:
time[real]()-str;

54.126

Download nested_cond_sum_ex_comp.mw

This site has been having several (new) issues in the past month or so.

1) It is slow to access, and ofter very slow
2) sometimes submissions are very slow (and if previewed, sometimes so slow that it seems stuck)
3) the response counter is much more broken than before

Several people have made posts about all this. I don't know whether anyone's fixing it.

expr:=(10*(5+sqrt(41)))/(sqrt(70+10*sqrt(41))*sqrt(130+10*sqrt(41))):

 

simplify(factor(expr))

(1/2)*2^(1/2)

Download rad_exx.mw

[edit] I see now that Thomas had already mentioned evala@factor. which is great. Also possible is radnormal@factor here.

The following variants involve three calls, without using factor.

radnormal(evala( combine(expr) ));
simplify(evala( combine(expr) ));
evala(radnormal( combine(expr) ));
simplify(radnormal( combine(expr) ));

That leads to noticing that the following expression (obtained from combine(expr) in M2024.0 at least) does not produce the same result (or normal form) under repeated calls to either evala or radnormal. This deserves a separate bug report, which I shall make.

restart;

foo := (5+41^(1/2))*(1/(7+41^(1/2))/(13+41^(1/2)))^(1/2);

(5+41^(1/2))*(1/((7+41^(1/2))*(13+41^(1/2))))^(1/2)

radnormal(foo);

(1/16)*(33-5*41^(1/2))^(1/2)*41^(1/2)+(5/16)*(33-5*41^(1/2))^(1/2)

radnormal(radnormal(foo));

(1/2)*2^(1/2)

evala(foo);

(1/16)*(33-5*41^(1/2))^(1/2)*41^(1/2)+(5/16)*(33-5*41^(1/2))^(1/2)

evala(evala(foo));

(1/2)*2^(1/2)

Download rad_exxx.mw

I wouldn't prefer the LinearAlgebra:-Column command for any example for which Matrix-indexing is convenient and terse. That's just a personal preference.

Eg,

M := LinearAlgebra:-RandomMatrix(5);

Matrix(5, 5, {(1, 1) = -81, (1, 2) = -98, (1, 3) = -76, (1, 4) = -4, (1, 5) = 29, (2, 1) = -38, (2, 2) = -77, (2, 3) = -72, (2, 4) = 27, (2, 5) = 44, (3, 1) = -18, (3, 2) = 57, (3, 3) = -2, (3, 4) = 8, (3, 5) = 92, (4, 1) = 87, (4, 2) = 27, (4, 3) = -32, (4, 4) = 69, (4, 5) = -31, (5, 1) = 33, (5, 2) = -93, (5, 3) = -74, (5, 4) = 99, (5, 5) = 67})

seq(M[..,i],i=1..5);

Vector(5, {(1) = -81, (2) = -38, (3) = -18, (4) = 87, (5) = 33}), Vector(5, {(1) = -98, (2) = -77, (3) = 57, (4) = 27, (5) = -93}), Vector(5, {(1) = -76, (2) = -72, (3) = -2, (4) = -32, (5) = -74}), Vector(5, {(1) = -4, (2) = 27, (3) = 8, (4) = 69, (5) = 99}), Vector(5, {(1) = 29, (2) = 44, (3) = 92, (4) = -31, (5) = 67})

Download Matrix_Cols.mw

Your code has several invalid calls to int, and several missing commas in the code of the plot calls.

Please compare worksheets.

ode_Plots_error_ac.mw

Do you mean something like the following? We can get similar effects using a loop, or using seq.

M := Matrix(4,4):

for i from 1 to 4 do
  for j from 1 to i do
    M[i,j] := [i,j];
  end do;
end do:

M;

Matrix(4, 4, {(1, 1) = [1, 1], (1, 2) = 0, (1, 3) = 0, (1, 4) = 0, (2, 1) = [2, 1], (2, 2) = [2, 2], (2, 3) = 0, (2, 4) = 0, (3, 1) = [3, 1], (3, 2) = [3, 2], (3, 3) = [3, 3], (3, 4) = 0, (4, 1) = [4, 1], (4, 2) = [4, 2], (4, 3) = [4, 3], (4, 4) = [4, 4]})

seq( seq( [i,j], j=1..i ), i=1..4);

[1, 1], [2, 1], [2, 2], [3, 1], [3, 2], [3, 3], [4, 1], [4, 2], [4, 3], [4, 4]

 

Download loop_ex1.mw

Ok, so there are a few issues to deal with.

1) Instead of using _rest to pass along any extra options to the plotting commands I set it up to use a new keyword option plopts. That avoids a clash with using the lowercase names for Qdim's keyword options. There are several stock Library commands that use such an approach. (You can back that out, and use the capitalized names or other, if you prefer. I just wanted to show this to you.)
2) I also made the point and line options work, by having Qdim explicitly name a terse substitute pt for plottools in its uses syntax. I also did the same for plots in that uses. This allows for reasonably terse (but understandable) code.
3) I also made Qdim's lowercase print option work, by invoking the global command by :-print instead.
4) I also put uneval quotes around keyword options in use in Qdim, and uneval quotes around the global versions of (stock unprotected) names used as option values. This is to guard against Qdim breaking if any of these names got assigned some values at the top-level. I used maplemint to discover such.

I suggest you stress test (as your examples do).

restart;

# changed  points   to point
#          linetype to line
#          scl      to scale   # lower case dont know if clashes
#          clr      to colour
#          prnt     to print

Prntmsg:="y"; Geomclr:="Blue";

"y"

"Blue"

Qdim := proc(P1, P2, {Q:=[ NULL,:-align={':-left'}]},
                     {vec1::list:=[NULL,:-align={':-below',':-right'}]},
                     {scale::{list,numeric}:=1},
                     {leader::{-1,0,1}:= 1},
                     {dimofset::{1,2,3,4,5,6}:=1},
                     {point::list:=['color' = ':-blue', symbol = ':-solidcircle', 'symbolsize' = 8]},
                     {line::list:=['thickness'=3]},
                     {colour::`string`:="blonde"},
                     {print:=Prntmsg},
                     {plopts::list:=[]})
description " plots Quadrance symbol and value (Q)";
uses pl=plots, pt=plottools; # RationalTrigonometry;
local a,f,g,h,v1,delta,mp, BoxQ,Qsymbol,pt1,pt2,pt3,pt4,Scl,
      ptxtp1,ptxtp2,txtplt1,txtplt2,plttyp,thk,l12,pts12;

if P1[1]::{list, Vector[row]} then
   pt1:=`if`(P1[1]::Vector[row],convert(P1[1],list),P1[1]);
   plttyp:=`if`(nops(pt1)=3,3,2); # print(pt1,plttyp);
   ptxtp1:=[op(pt1),op(P1[2..-1])];
   txtplt1:=true;  
 else
   pt1:=`if`(P1::Vector[row],convert(P1,list),P1);#print(pt1);
   plttyp:=nops(pt1);
   txtplt1:=false;
end if;    

if P2[1]::{list, Vector[row]} then
   pt2:=`if`(P2[1]::Vector[row],convert(P2[1],list),P2[1]);#print(pt2);
   if plttyp<>nops(pt2) then error `different dimension in inputs`end if;
   ptxtp2:=[op(pt2),op(P2[2..-1])];
   txtplt2:=true;
 else
   pt2:=`if`(P2::Vector[row],convert(P2,list),P2);#print(pt2);
   if plttyp<>nops(pt2) then error `different dimension in inputs`end if;
   txtplt2:=false;
end if;

#if scl::numeric then
    Scl:=scale;
 #else
  # pt3:=`if`(scl[1]::Vector[row],convert(scl[1],list),scl[1]);
   #pt4:=`if`(scl[2]::Vector[row],convert(scl[2],list),scl[2]);
    #if plttyp = 2 then
     #  Scl:=evalf(sqrt(Quadrance(pt3,pt4,"b","n")/Quadrance(pt1,pt2,"b","n")));
     #else
      # Scl:=evalf(sqrt(Quadrance(pt3,pt4,"n")/Quadrance(pt1,pt2,"n")));
   # end if;
#end if;
if plttyp =2 then
     a :=Scl* dimofset*0.1*leader*[-pt2[2]+pt1[2], pt2[1]-pt1[1]]; #dimension leader lines
  else
     a :=Scl* dimofset*0.1*leader*[-pt2[2]+pt1[2], pt2[1]-pt1[1],pt2[3]-pt1[3]]; #dimension leader lines
end if;
delta:=Scl*(pt2-pt1);
mp:=(1-1/2)*pt1+1/2*pt2;  #midpoint of line
#print(Scl,a,delta,mp);
if plttyp = 2 then
    BoxQ:=[[a[1]+mp[1]+.05*delta[1]-.01*delta[2],a[2]+mp[2]+.05*delta[2]+.01*delta[1]],
           [a[1]+mp[1]-.05*delta[1]-.01*delta[2],a[2]+mp[2]-.05*delta[2]+.01*delta[1]],
           [a[1]+mp[1]-.05*delta[1]+.01*delta[2],a[2]+mp[2]-.05*delta[2]-.01*delta[1]],
           [a[1]+mp[1]+.05*delta[1]+.01*delta[2],a[2]+mp[2]+.05*delta[2]-.01*delta[1]]];
 else
    BoxQ:=[[a[1]+mp[1]+.05*delta[1]-.01*delta[2],a[2]+mp[2]+.05*delta[2]+.01*delta[1],a[3]+mp[3]+.05*delta[3]],
           [a[1]+mp[1]-.05*delta[1]-.01*delta[2],a[2]+mp[2]-.05*delta[2]+.01*delta[1],a[3]+mp[3]-.05*delta[3]],
           [a[1]+mp[1]-.05*delta[1]+.01*delta[2],a[2]+mp[2]-.05*delta[2]-.01*delta[1],a[3]+mp[3]-.05*delta[3]],
           [a[1]+mp[1]+.05*delta[1]+.01*delta[2],a[2]+mp[2]+.05*delta[2]-.01*delta[1],a[3]+mp[3]+.05*delta[3]]];
end if;

if leader<>0  then
   thk:='thickness'=0
 elif line<>[] then
   thk:=line[op(ListTools:-Search(op(select(has,line,'thickness')),line))];
 else
   thk:='thickness'=0;
end if;

Qsymbol:= [pt:-line(pt1,pt1+a,'thickness'=0,plopts[]),
           pt:-line(pt1+a,mp-.05*delta+a,thk,plopts[]),
           pt:-line(op([BoxQ[1],BoxQ[2]]),'thickness'=0,plopts[]),
           pt:-line(op([BoxQ[2],BoxQ[3]]),'thickness'=0,plopts[]),
           pt:-line(op([BoxQ[3],BoxQ[4]]),'thickness'=0,plopts[]),
           pt:-line(op([BoxQ[4],BoxQ[1]]),'thickness'=0,plopts[]),
           pt:-line(pt2+a,mp+.05*delta+a,thk,plopts[]),
           pt:-line(pt2,pt2+a,'thickness'=0,plopts[])];
    
if point<>[]then           
pts12:=pt:-point([pt1,pt2],point[]);  #end points
else
pts12:=NULL;
end if;
if line<>[] then
l12:=pt:-line(pt1,pt2,line[]);
  else
  l12:=NULL;
  end if;
if plttyp = 2 then
    f := pl:-textplot([op((pt1+pt2)/2+1*(a)),op(Q)]);  #Quadrance text
   if txtplt1 then
      g := pl:-textplot( ptxtp1);
    else
      g:=NULL;
   end if;
   if txtplt2 then
      h := pl:-textplot( ptxtp2);
    else
     h:= NULL;
   end if;
    v1:=pl:-textplot([op((pt1+pt2)/2), op(vec1)]);#`#mover(mi("v"),mo("&rharu;"))`[1,2]   {':-below',':-right'}
 else

   f := pl:-textplot3d([op((pt1+pt2)/2+1*(a)),op(Q)]);
   if txtplt1 then
         g := pl:-textplot3d( ptxtp1);
      else
         g:=NULL;
   end if;
   if txtplt2 then
         h := pl:-textplot3d( ptxtp2);
      else
         h:=NULL;
   end if;
    v1:=pl:-textplot3d([op(pt1+pt2)/2,op(vec1)]);#`#mover(mi("v"),mo("&rharu;"))`[1,2]   {':-below',':-right'}
end if;
#print("pltyp" , plttyp)  ;
if print="y" then :-print(cat("Quadrance symbols  ",colour,"  geometry")); end if;
if leader = 0 then    
    pl:-display(pts12,f,g,h,Qsymbol,'axes'=':-none','scaling'=':-constrained');
 else       
         pl:-display(pts12,l12,f,g,h,Qsymbol,'axes'=':-none','scaling'=':-constrained');     
end if;
end proc:

maplemint(Qdim);

Procedure Qdim( P1, P2, { Q := [NULL, :-align = {':-left'}], colour::string :=
    "blonde", dimofset::{1, 2, 3, 4, 5, 6} := 1, leader::{-1, 0, 1} := 1,
    line::list := [('thickness') = 3], plopts::list := [], point::list :=
    [('color') = (':-blue'), symbol = (':-solidcircle'), ('
symbolsize') = 8],
    print := Prntmsg, scale::{list, numeric} := 1, vec1::list := [NULL,
    :-align = {':-below', ':-right'}] } )
  These local variables were never used:  pt3, pt4
  These local variables were assigned a value, but otherwise unused:  v1

 

P1:=[2,3,6]:
P2:=[1,5,7]:
P3:=P1+1/3*(P2-P1)

[5/3, 11/3, 19/3]

plt1:=Qdim([P1,typeset("P1=",P1),align=below],[P2,P2,align=right ],
           dimofset=2,Q=["Q12\n",align =above],plopts=[colour=black]);

"Quadrance symbols  blonde  geometry"

plt2:=Qdim([P1,typeset("P1=",P1),align=below],[P3,P3,align=right ],
           scale=2,Q=["Q13\n",align =above],print="n");
#scl affects the linine up of dimesion lines prnt="n" no message displayed

plt3:=Qdim(P3,P2,scale=1,Q=["Q23\n",align =above],point=[],
           line=[],colour="RED");
#doesn't plot points and line. shows use of `clr`

"Quadrance symbols  RED  geometry"

plots:-display(plt1,plt2,plt3)

P5:=[1,2]:P6:=[-1,4]:

Qdim([P5,"P5   ",align={below,left}],[P6,"   P6",align={right}],
     Q=[typeset("\nQ[5,6]"),align={below,left}],line=[linestyle=dash],
     point=[symbolsize=20,symbol=solidcircle,colour=orange]);

"Quadrance symbols  blonde  geometry"

Qdim([P5,"P5   ",align={below,left}],[P6,"   P6",align={right}],
     leader=0,Q=[typeset("\nQ[5,6]"),align={below,left}],
     point=[symbolsize=18]);

"Quadrance symbols  blonde  geometry"

 

Download 2024-03-09_Example_parm_names_changed_acc.mw

I've used Maple 2024.0 here.

restart

expr1 := m^3*r*(cos(theta)^6*a^6-9*cos(theta)^4*a^4*r^2+11*cos(theta)^2*a^2*r^4-(1/3)*r^6)*(cos(theta)^2*a^2-(1/3)*r^2)/(r^2+cos(theta)^2*a^2)^9

expr2 := (a^8*(r^10-10*m*r^9+(5*(a^2+8*m^2))*r^8-80*m^3*r^7+(10*(a^4+12*a^2*m^2+8*m^4))*r^6+(4*(-15*a^4*m-40*a^2*m^3-8*m^5))*r^5+(10*(a^6+12*a^4*m^2+8*a^2*m^4))*r^4+(40*(-a^6*m-2*a^4*m^3))*r^3+(5*(a^8+8*a^6*m^2))*r^2-10*a^8*m*r+a^10)*cos(theta)^8-(1/3)*(28*(-30*sin(theta)^2*a^4*m*r^5*(1/7)+r^10-10*m*r^9+(5*(a^2+8*m^2))*r^8+(40*(-a^2*m-2*m^3))*r^7+(10*(a^4+12*a^2*m^2+8*m^4))*r^6+(32*(-5*a^2*m^3-m^5))*r^5+(10*(a^6+12*a^4*m^2+8*a^2*m^4))*r^4+(40*(-a^6*m-2*a^4*m^3))*r^3+(5*(a^8+8*a^6*m^2))*r^2-10*a^8*m*r+a^10))*a^6*r^2*cos(theta)^6+(14*(-260*sin(theta)^2*a^6*m*r^3*(1/7)+r^10-10*m*r^9+(5*(a^2+8*m^2))*r^8+(40*(-a^2*m-2*m^3))*r^7+(10*(a^4+12*a^2*m^2+8*m^4))*r^6+(4*(-15*a^4*m-40*a^2*m^3-8*m^5))*r^5+(10*(a^6+12*a^4*m^2+8*a^2*m^4))*r^4-80*a^4*m^3*r^3+(5*(a^8+8*a^6*m^2))*r^2-10*a^8*m*r+a^10))*a^4*r^4*cos(theta)^4-4*a^2*(-10*a^8*m*r*sin(theta)^2+r^10-10*m*r^9+(5*(a^2+8*m^2))*r^8+(40*(-a^2*m-2*m^3))*r^7+(10*(a^4+12*a^2*m^2+8*m^4))*r^6+(4*(-15*a^4*m-40*a^2*m^3-8*m^5))*r^5+(10*(a^6+12*a^4*m^2+8*a^2*m^4))*r^4+(40*(-a^6*m-2*a^4*m^3))*r^3+(5*(a^8+8*a^6*m^2))*r^2+a^10)*r^6*cos(theta)^2+(1/9)*r^8*(a^2-2*m*r+r^2)^5)*m^3*r/((r^2+a^2*cos(theta)^2)^9*(a^2-2*m*r+r^2)^5)

factor(expand(combine(expr2), trig))

(1/9)*r*m^3*(3*cos(theta)^2*a^2-r^2)*(3*cos(theta)^6*a^6-27*cos(theta)^4*a^4*r^2+33*cos(theta)^2*a^2*r^4-r^6)/(r^2+cos(theta)^2*a^2)^9

NULL

Download QuestionSimplifyMultivariateRationalFunction_ac.mw

Since simplify is not by itself (well, no longer, since M2023) finding the trig simplification then the key to my approach above is to force the trig combine of the sin and cos terms in the second expression. The subsequent trig expand gets the simpler thing with just cos.

I shall submit bug reports against the regression & weaknesses in simplify.

If you're going to use plot3d to construct 3d lines then you might as well pass the option grid=[2,2] and cut down the wasted memory. The default is [49,49], but you only need the end-points, so without that option your plot3d construction is unnecessarily about 25 times too big.

Similarly, if you're using spacecurve for mere lines and want solid colors then you could pass numpoints=2 to that command, again to avoid unnecessarily wasting time and space. (It's hard to measure the time gain, since the example is already very quick.)

That might all seem pedantic, but those kind of considerations can really come into play when one starts animating/exploring plots, etc.

But why not just use plottools:-line, with the two Vectors you already have? I mean, instantiating them both at the end-points for lambda. That get's that memory efficiency directly.

restart

with(plottools): with(plots,display):

l:=([2,-3,1],<3,7/9,6>):   # 3d line point + vector

P:=[7,-8,9]:

pl:=`+`~(lambda*l[2],l[1]): #3d line as vector eqn

vnl:=`-`~(pl,P) : #vector from Point P to 3D line

vnl.l[2] assuming `real` ; #dot product of vectors= 0 when perpendicular

(3694/81)*lambda-532/9

sol:=solve( {  }, [lambda] )[];

[lambda = 2394/1847]

intP:=eval(pl,sol):  #intersection point

l2:=P,eval(vnl,sol) :  #perpendicular 3D line through P

pl2:=`+`~(lambda*l2[2],l2[1]): #3D line as vector eqn

display(
      line(eval(pl,lambda=-.5),eval(pl,lambda=1.8),thickness=0,colour=orange),
      line(eval(pl2,lambda=-.5),eval(pl2,lambda=1.8),thickness=0,colour=purple),
      point(P,colour=blue ,symbolsize=15,symbol=solidsphere),
      point(l[1],colour=green ,symbolsize=15,symbol=solidsphere),
      point(eval(pl,sol),colour=red ,symbolsize=15,symbol=solidsphere),
      arrow(l,0.2, 0.4, 0.1,colour=green),
      arrow(l2,0.2, 0.4, 0.1,colour=blue),
      axes=normal,scaling=constrained);

Download Perpendicular_3D_lines_ac.mw

You might be able to get by with,

     is(simplify(tmp - r) = 0)

quite often.

I'm not sure what you want, as "simpler".

I haven't included anything like alias or LargeExpression:-Veil.

But maybe there are some ideas here for you (including a variety of "expression size" metrics),
expression_to_simplify_ideas.mw

You also asked about this behavior in August, 2021.

Your call to the parse command constructs the global name `a`, which is not your procedure's assigned local a.

restart;

p := proc()
  local a;
  return addressof(parse("a")),
         addressof(:-a),
         addressof(a);
end proc:

p();

36893628368009992380, 36893628368009992380, 36893628368009992636

Download parse_ex.mw

restart;

a := 17:

p := proc()
  local a;
  a := 25;
  return parse("a",statement);
end proc:

p();

17

Download parse_ex2.mw

First 6 7 8 9 10 11 12 Last Page 8 of 315