MaplePrimes Questions

The old question "Longest distance in a graph via Maple code" offers some general methods to find longest paths in a given graph, while for directed acyclic graphs, the longest paths can be found much more directly via built-in functions. However, it apprears that even for small dags, Maple cannot solve this in an acceptable time. In the following example, I'd like to count the number of nodes that on longest paths for certain source and target vertexes.
 

restart;

_seed := 1234

Warning, the use of _seed is deprecated.  Please consider using one of the alternatives listed on the _seed help page.

 

G := GraphTheory:-RandomGraphs:-RandomNetwork(200, .2, 'acyclic', 'weights' = 0. .. 2)

G__0 := applyop(`-`, -1, G)``

GRAPHLN(directed, weighted, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200], Array(1..200, {(1) = {2, 3, 4}, (2) = {5}, (3) = {4, 5}, (4) = {5}, (5) = {6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}, (6) = {11, 12, 13, 14, 15, 17, 18, 19, 21}, (7) = {9, 10, 11, 16, 17, 20, 22}, (8) = {12, 14, 16, 17, 19, 20, 21, 22, 23}, (9) = {11, 14, 21, 23}, (10) = {11, 13, 18, 19, 20, 21, 23}, (11) = {14, 15, 16, 17, 18, 21, 23}, (12) = {13, 15, 18, 19, 20, 22}, (13) = {14, 15, 16, 17, 21}, (14) = {19, 20, 22}, (15) = {19, 20, 22, 23}, (16) = {17, 18, 21}, (17) = {19, 20, 23}, (18) = {19, 20, 21}, (19) = {20, 24, 25}, (20) = {22, 23, 25}, (21) = {23, 24, 25}, (22) = {23, 24, 25}, (23) = {24, 25}, (24) = {26, 27, 29}, (25) = {27, 28, 29}, (26) = {28, 29, 30}, (27) = {28, 29, 31, 32, 33}, (28) = {32, 33}, (29) = {32, 33}, (30) = {34, 35, 38, 39}, (31) = {32, 37, 38, 39}, (32) = {33, 36, 37, 38}, (33) = {35, 36, 39}, (34) = {36, 38, 39}, (35) = {37, 39}, (36) = {37, 39}, (37) = {39, 40}, (38) = {39, 40}, (39) = {40}, (40) = {41, 42}, (41) = {43, 44, 47, 48, 49}, (42) = {44, 45, 46, 47, 48, 49}, (43) = {47, 49, 50, 55, 56, 57}, (44) = {45, 48, 50, 51, 52, 53, 54, 56}, (45) = {46, 47, 49, 50, 52, 56}, (46) = {47, 48, 49, 50, 51, 52, 53, 56, 57}, (47) = {49, 50, 51, 52, 54, 56, 57}, (48) = {49, 51, 52, 53, 54, 55, 56, 57}, (49) = {50, 52, 53, 54, 57}, (50) = {51, 57}, (51) = {53, 54, 57}, (52) = {53, 55, 57}, (53) = {54, 56}, (54) = {56, 58}, (55) = {58}, (56) = {58}, (57) = {58}, (58) = {59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75}, (59) = {60, 61, 66, 68, 70, 71, 74, 75, 76, 77}, (60) = {61, 63, 67, 68, 70, 72, 73, 77}, (61) = {62, 66, 69, 70, 71, 72, 73, 75, 76, 77}, (62) = {65, 68, 75, 76, 77}, (63) = {65, 66, 69, 70, 72, 73, 76, 77}, (64) = {65, 67, 68, 69, 70, 71, 73, 77}, (65) = {66, 70, 72, 73, 74, 76}, (66) = {68, 70, 71, 72, 73, 74, 75, 76, 77}, (67) = {69, 70, 71, 74, 76}, (68) = {73, 74}, (69) = {71, 76, 77}, (70) = {71, 73, 77}, (71) = {72, 76, 77}, (72) = {75}, (73) = {75, 76}, (74) = {76}, (75) = {76}, (76) = {77, 78, 79, 80, 81, 82, 83, 85, 86}, (77) = {79, 80, 82, 84, 85}, (78) = {79, 83, 85, 87}, (79) = {81, 82, 83, 85, 86, 87}, (80) = {83, 86}, (81) = {83, 84, 87}, (82) = {87}, (83) = {85, 86, 87}, (84) = {85, 87}, (85) = {87}, (86) = {87}, (87) = {88, 89}, (88) = {90, 91, 92, 93, 94}, (89) = {90, 91, 93, 94, 95}, (90) = {96, 97, 99, 101, 103, 104, 107, 108, 109, 110, 112, 115, 117, 118, 120}, (91) = {92, 94, 96, 97, 98, 100, 101, 102, 105, 106, 107, 110, 113, 116, 117, 118, 120}, (92) = {95, 97, 98, 99, 101, 103, 106, 107, 108, 111, 112, 113, 115, 117, 119, 120}, (93) = {95, 96, 98, 100, 104, 106, 109, 111, 112, 113, 116, 118, 119, 120}, (94) = {95, 99, 100, 102, 103, 104, 106, 108, 109, 110, 111, 112, 113, 114, 115, 117, 118, 119, 120}, (95) = {97, 98, 99, 100, 102, 103, 104, 105, 107, 108, 109, 111, 112, 113, 114, 115, 116, 117, 118, 120}, (96) = {98, 100, 102, 103, 104, 106, 107, 110, 111, 114, 119, 120, 121}, (97) = {99, 100, 102, 104, 106, 107, 108, 109, 111, 114, 118, 119}, (98) = {102, 103, 107, 110, 111, 112, 113, 114, 116, 117, 119, 120, 121}, (99) = {101, 102, 104, 106, 107, 112, 117, 120}, (100) = {101, 104, 105, 106, 109, 110, 116, 117, 119, 120, 121}, (101) = {102, 105, 109, 110, 111, 112, 113, 114, 115, 117, 118, 119, 120}, (102) = {103, 106, 107, 108, 110, 112, 113, 114, 117, 118, 119}, (103) = {104, 105, 107, 108, 109, 110, 111, 113, 115, 116, 119, 120, 121}, (104) = {105, 106, 109, 110, 114, 115, 116, 118, 119}, (105) = {106, 108, 109, 110, 113, 114, 116, 117}, (106) = {107, 108, 109, 112, 114, 117, 118, 119, 121}, (107) = {110, 114, 116, 119, 120}, (108) = {111, 112, 113, 114, 118, 119, 120, 121}, (109) = {113, 116, 117, 118, 121}, (110) = {111, 113, 117, 119, 120, 121}, (111) = {112, 113, 115, 118, 120}, (112) = {113, 114, 116, 117, 118, 119, 120}, (113) = {116, 117, 119, 121}, (114) = {115, 116, 117, 121}, (115) = {116, 120}, (116) = {119, 121}, (117) = {118, 119, 121}, (118) = {121}, (119) = {121}, (120) = {121}, (121) = {122, 123, 124, 125, 126}, (122) = {123, 124, 125, 126, 127}, (123) = {126}, (124) = {126, 127}, (125) = {127}, (126) = {127}, (127) = {128, 129}, (128) = {130}, (129) = {130}, (130) = {131, 132}, (131) = {132, 133, 135}, (132) = {134, 135}, (133) = {134, 136, 137, 138, 140, 141, 142}, (134) = {135, 136, 139, 140, 141}, (135) = {136, 137, 139, 140, 141, 142}, (136) = {145, 146, 147}, (137) = {139, 141, 143, 145, 147, 148}, (138) = {139, 140, 143, 144, 145, 148}, (139) = {141, 143, 145}, (140) = {143, 145, 146, 147, 148}, (141) = {142, 144, 145, 146, 147}, (142) = {143, 144, 146, 148}, (143) = {145, 146, 147, 148}, (144) = {146, 149}, (145) = {147}, (146) = {149}, (147) = {149}, (148) = {149}, (149) = {150, 151, 152, 153, 154, 155, 156, 157, 158}, (150) = {152, 153, 155, 157, 158}, (151) = {152, 153, 159}, (152) = {154, 158}, (153) = {154, 155, 156}, (154) = {156, 158, 159}, (155) = {158}, (156) = {157, 158, 159}, (157) = {158}, (158) = {159}, (159) = {160, 161, 162, 163}, (160) = {161, 163, 166, 167}, (161) = {165, 166, 167}, (162) = {163, 165}, (163) = {164, 166, 167}, (164) = {166}, (165) = {166, 168, 169}, (166) = {169}, (167) = {168}, (168) = {169, 170, 171, 172, 173, 174, 177, 178, 179, 180, 182}, (169) = {170, 171, 172, 173, 174, 175, 176, 177, 178, 180, 181, 182}, (170) = {172, 173, 174, 175, 176, 180, 182, 183, 185}, (171) = {172, 174, 176, 177, 181, 182, 185}, (172) = {175, 176, 177, 183, 185}, (173) = {175, 176, 178, 183, 185}, (174) = {175, 180, 181, 183, 184, 185}, (175) = {181, 182, 183, 185}, (176) = {177, 178, 179, 182}, (177) = {178, 179, 184, 185}, (178) = {179, 180, 182, 183, 184}, (179) = {180, 182, 185}, (180) = {181, 182}, (181) = {184}, (182) = {185}, (183) = {187, 188, 190}, (184) = {187, 188, 189}, (185) = {186, 188, 190}, (186) = {187, 188, 190, 191, 193, 194, 196}, (187) = {188, 190, 192, 193, 194, 195}, (188) = {189, 190, 191, 192, 194}, (189) = {190, 191, 196}, (190) = {191, 192, 195, 196}, (191) = {193, 196, 199}, (192) = {194, 196, 198, 199}, (193) = {197, 199}, (194) = {195, 196, 197}, (195) = {196, 198, 199}, (196) = {198, 199}, (197) = {198}, (198) = {199, 200}, (199) = {200}, (200) = {}}), `GRAPHLN/table/1`, )

(1)

t, s := combinat:-randcomb(GraphTheory:-Vertices(G__0), 5^2), combinat:-randcomb(GraphTheory:-Vertices(G__0), integermul2exp(5, 2))

[12, 13, 22, 23, 41, 65, 70, 80, 88, 97, 105, 119, 124, 127, 129, 132, 135, 138, 146, 150, 165, 170, 189, 193, 199], [6, 13, 28, 29, 31, 41, 42, 49, 55, 85, 98, 104, 136, 141, 162, 166, 167, 168, 192, 199]

(2)

"DataFrame((`M__1`:=CodeTools:-Usage(Matrix(numelems(s),numelems(t),(i,j)->numelems((GraphTheory:-BellmanFordAlgorithm(`G__0`,s[i],t[j]))[1]),datatype=integer[2]))),'columns'=t,'rows'=s)"

memory used=7.99GiB, alloc change=0 bytes, cpu time=5.74m, real time=5.63m, gc time=22.55s

 

module DataFrame () description "two-dimensional rich data container"; local columns, rows, data, binder; option object(BaseDataObject); end module

(3)

"DataFrame((`M__2`:=CodeTools:-Usage(Matrix(numelems(s),numelems(t),proc(i::posint,j::posint,` $`)::nonnegint;  uses ListTools,GraphTheory; local ts::list(posint):=TopologicSort(`G__0`,'output'='permutation'),q::posint:=Search(t[j],ts),p::posint:=Search(s[i],ts); if  p>q then 0 elif q=p then 1 else numelems(BellmanFordAlgorithm(`G__0`,s[i],t[j])[1]) fi end,datatype=integer))),':-columns'=t,':-rows'=s)"

memory used=4.34GiB, alloc change=32.00MiB, cpu time=3.26m, real time=3.19m, gc time=14.34s

 

module DataFrame () description "two-dimensional rich data container"; local columns, rows, data, binder; option object(BaseDataObject); end module

(4)

EqualEntries(M__ || (1 .. 2))

true

(5)

 


 

Download longest_paths_in_a_DAG.mw

Unfortunately, I have to wait for almost four minutes in the above instance. Can this task be done in 0.4s?

In the Grading Quiz, it is possible for students to indicate whether the answer is correct or incorrect. In the context menu, it is also possible to add an icon instead of the text.

For some reason, I can't get this to work! If I assign an icon to the correct answer, the same icon is transferred to the incorrect answer.

Is there a way that I'm missing that can show two different icons rather than the same one?

 


How to force Maple to prove equality (2) under conditions cond.

 

restart:

# Given
#     0 < u < 1
#     0 < v < 1
#     theta > 1
#
# let F the function defined by:

F := (u, v) -> exp(-((-ln(u))^theta+(-ln(v))^theta)^(1/theta))

proc (u, v) options operator, arrow; exp(-((-ln(u))^theta+(-ln(v))^theta)^(1/theta)) end proc

(1)

# How to prove this equality for any n > 0?

'F(u^(1/n), v^(1/n))^n' = 'F(u, v)'

F(u^(1/n), v^(1/n))^n = F(u, v)

(2)

cond := u > 0, u < 1, v > 0, v < 1, theta > 1, n > 1:

simplify(F(u^(1/n), v^(1/n))^n - F(u, v)) assuming cond;

(exp(-(((-ln(u))^theta+(-ln(v))^theta)*n^(-theta))^(1/theta)))^n-exp(-((-ln(u))^theta+(-ln(v))^theta)^(1/theta))

(3)

 

 

Download Stable.mw


Thanks for your help.

Hi, I am using ArchLinux and used Maple's official installer to install it. Whenever I export my Maple files as PDF all my "-" symbols are converted to "K" for some reason. Has anyone else had this issue or have an idea on how to fix it?

Below is a screenshot of what I mean. "-" has been replaced with "K"

Hi! Do you know how can I plot revolution of this curve:

plot(1 + 1/4*sin(8*(1 + 1/8*sin(16*(1 + 1/16*sin(32*t))))), t = 0 .. 2*Pi, coords = polar)

to get a wrinkled torus like this:

Abelprijs 2015 voor John Nash en Louis Nirenberg - NEMO Kennislink

Do u have any idea? (I've tried to convert this polar curve to cartesian coords but I don't get it)

map won't work with left quotes

L:=[2,"foo",4]

Hello

I have a list with n positive integer numbers and a positive integer k.

I would like to write a Malple programm, that calculates, in how many ways k can be written as a sum of numbers in the list.

Easy examles: let the list be [2,3,6,9].

k=9 can be written in 4 ways: 9=9, 9=6+3, 9=3+3+3, 9=3+2+2+2. The result therefore shoud be 4.

k=8 can be written in 3 ways: 8=6+2, 8=3+3+2, 8=2+2+2+2. The result therefore shoud be 3.

Thank you very much your help!

I cannot get this to work:

Print all the non-string entries in a list:

L := [1, 2, "abc", "a", 7.0, infinity]:

for x in L do
    if type(x, 'string') then
        next;
    end if;
    print(x);
end do;

Hi everyone,

I am using Maple for quite a while, now I would like to do something new.

I am a teacher at a german highschool and I would like to generate class tests with maple. Say for an example, I need 30 tests,  where the first task is calculating the first derivative of a function. This function should be different for every person, for example f(x)=a*x^3+3x^2, where the value of a is different in every test (probably random).

So what I need is a way to generate nice looking sheets in Maple (including page breaks, titles and so on). Is there a way to generate such a thing in maple or do I have to export to TeX and adjust there quite a bit?

Maybe someone has done a similar thing. Actually I am looking for something like serial letters in Maple.

Any idea, how I could do such a thing?

Thanx for your help,

Axel

GraphTheory:-GraphEqual says that G1 and G2 are equal, but GraphTheory:-AllPairsDistance gives different results instead: 

restart;

with(GraphTheory)

M := `<|>`(`<,>`(0, 0, 0), `<,>`(1, 0, 0), `<,>`(1, 1, 0))

G__1 := Graph(convert(-M, Matrix, datatype = integer[8]))

G__2 := Graph(convert(-M, Matrix, datatype = integer))

GraphEqual(G__1, G__2)

true

(1)

AllPairsDistance(G__1)

AllPairsDistance(G__2)

Matrix(%id = 36893491227039185244)

 

Error, (in GraphTheory:-AllPairsDistanceExt) negative cycle detected

 

 

Download allpairs.mw

So, which one is incorrect? Any reasons?

restart

with(PolynomialIdeals):

``

``

randomzero := proc (ListVar) local A, G, i, lm, B, f, g; option trace; A := ListVar; G := NULL; for i to nops(A) do f := A[i]^(i+1)+randpoly([op(`minus`({op(A)}, {A[i]}))], terms = 1, coeffs = rand(-4 .. -1), degree = i); G := G, f end do; print(IsZeroDimensional(`<,>`(G))); RETURN([G]) end proc:

randomzero([x, y])

{--> enter randomzero, args = [x, y]

 

[x, y]

 

"G:="

 

x^2-y-4

 

x^2-y-4

 

y^3-3*x

 

x^2-y-4, y^3-3*x

 

true

 

<-- exit randomzero (now at top level) = [x^2-y-4, y^3-3*x]}

 

[x^2-y-4, y^3-3*x]

(1)

``

Download bug.mw

Hi

I think there is a bug in the "randpoly" command. please see the attached file line 7 of my procedure "randomzero". Why x^2-y-4 is created while terms=1 is considered and the outputs must contain binomial?

Some work, while others don't work. 
 

restart;

`assuming`([is(1/(sqrt(n*(n+1))*(sqrt(n)+sqrt(n+1))) = 1/sqrt(n)-1/sqrt(n+1))], [n::posint])

true

(1)

sum(1/sqrt(n)-1/sqrt(n+1), n = 1 .. infinity)

1

(2)

sum(1/(sqrt(n*(n+1))*(sqrt(n)+sqrt(n+1))), n = 1 .. infinity)

sum(1/((n*(n+1))^(1/2)*(n^(1/2)+(n+1)^(1/2))), n = 1 .. infinity)

(3)

`assuming`([sum(binomial(3*n, n)*x^n/(2*n+1), n = 0 .. infinity)], [abs(x) <= 4/27])

(2/3)*3^(1/2)*sin((1/3)*arcsin((3/2)*3^(1/2)*x^(1/2)))/x^(1/2)

(4)

`assuming`([eval(binomial(3*n, n)*x^n/(2*n+1), n = 0)+sum(binomial(3*n, n)*x^n/(2*n+1), n = 1 .. infinity, parametric)], [abs(x) <= 4/27])

1+x*hypergeom([1, 4/3, 5/3], [2, 5/2], (27/4)*x)

(5)

simplify(convert(1+x*hypergeom([1, 4/3, 5/3], [2, 5/2], (27/4)*x)-hypergeom([1/3, 2/3], [3/2], (27/4)*x), elementary), symbolic)

(1/3)*(3*x^(1/2)+3*x^(3/2)*hypergeom([1, 4/3, 5/3], [2, 5/2], (27/4)*x)-2*3^(1/2)*sin((1/3)*arcsin((3/2)*3^(1/2)*x^(1/2))))/x^(1/2)

(6)

plot((1/3)*(3*x^(1/2)+3*x^(3/2)*hypergeom([1, 4/3, 5/3], [2, 5/2], (27/4)*x)-2*3^(1/2)*sin((1/3)*arcsin((3/2)*3^(1/2)*x^(1/2))))/x^(1/2), x = -4/27 .. 4/27)

 

verify(0, (1/3)*(3*x^(1/2)+3*x^(3/2)*hypergeom([1, 4/3, 5/3], [2, 5/2], (27/4)*x)-2*3^(1/2)*sin((1/3)*arcsin((3/2)*3^(1/2)*x^(1/2))))/x^(1/2), 'equal')

FAIL

(7)

NULL


 

Download unable_to_sum.mw

How to explain this behavior?
I have read the help page, but I can not get the point.

Please, is there anyway I can solve this problem with a nice output? The solution I got is complicated. Please, helper is need

f := exp(-beta*x)*x^(5-alpha)

int(f, x)

beta^(alpha-6)*(-x^(-alpha)*beta^(-alpha)*(alpha^4-14*alpha^3+71*alpha^2-154*alpha+120)*(alpha-6)*(beta*x)^((1/2)*alpha)*exp(-(1/2)*beta*x)*WhittakerM(-(1/2)*alpha, -(1/2)*alpha+1/2, beta*x)/(-alpha+6)+x^(-alpha)*beta^(-alpha)*(beta^4*x^4-alpha*beta^3*x^3+alpha^2*beta^2*x^2+5*beta^3*x^3-alpha^3*beta*x-9*alpha*beta^2*x^2+alpha^4+12*alpha^2*beta*x+20*beta^2*x^2-14*alpha^3-47*alpha*beta*x+71*alpha^2+60*beta*x-154*alpha+120)*(alpha-6)*(beta*x)^((1/2)*alpha)*exp(-(1/2)*beta*x)*WhittakerM(-(1/2)*alpha+1, -(1/2)*alpha+1/2, beta*x)/(-alpha+6))

How to write a program that obtains the value of the function by giving different values
Like the example below:

 

I rephrased my previous question in a more synthetic form
(there was probably a lot in it that I thought was important for understanding the problem, but I realized afterwards that it only added confusion).

The true question is yellow-highlighted in the code below

restart

# The result below seems natural: we were taught in school that exp 
# being a bijective function we can get rid of it in the equality to
# solve and write simply x=Pi.

x = solve(exp(x)=exp(Pi), x)

x = Pi

(1)

# But the solution method solve uses is not that natural (and I
# don't really understand it).
# infolevel[solve] := 10:
# x = solve(exp(x)=exp(Pi), x);

# Replacing now exp by some undefined function f produces a
# kind of "no-solution" answer: this seems quite normal because
# not knowing the properties of f one cannot simply get rid of it.

infolevel[solve] := 0:
x = solve(f(x)=f(Pi), x)

x = RootOf(f(_Z)-f(Pi))

(2)

# Finally replace f by a bijective function with no analytic expression.

s = solve(erf(x)=erf(Pi), x) assuming x::real

s = RootOf(erf(_Z)-erf(Pi))

(3)

# It would have seem reasonable for Maple to answer x=Pi, or
# at least it is what I would have done given the properties
# of the erf function.
#
# How can I "force" Maple to "simplify" it's RootOf result to get
# x=Pi?


Download solve_erf.mw

For those interested in the motivations of this quastion, see here Where_does_the_question_come_from.mw

The original question is here Original_question.pdf

First 61 62 63 64 65 66 67 Last Page 63 of 2308