Carl Love

Carl Love

28055 Reputation

25 Badges

13 years, 4 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

By using matrix multiplication and matrix stacking, the code can be shortened to this:

restart:
Digits := 15:
T5Scheme:= proc(XY0::Matrix, a::Matrix, L::nonnegint)          
local i, k, N:= upperbound(XY0)[1], XY:= rtable(XY0);         
    for k to L do XY:= <seq(a.XY[i-2..i+2], i= 3..3^(k-1)*(N-6)+4)> od;  
    XY
end proc
:
## Initial polygon
q2:= -sqrt(2): q3:= sqrt(3):
XY:= < 
    -2,  1, 2,  0, q2, -2,  1, 2,  0, q2, -2,  1, 2,  0, q2  | #x
     0, q3, 0, -2, q2,  0, q3, 0, -2, q2,  0, q3, 0, -2, q2    #y
>/2:
st2:= <-2, 1, 2, 0, q2, -2  |  0, q3, 0, -2, q2, 0>/2:
L:= [13, -22, -81, -107, 179, 729, 1233]/1296:
a:= Array(-6..8, [L[], ListTools:-Reverse(L)[], 0]):
J:= [seq](6..-6, -3):
A:= <a[J], a[J+~1], a[J+~2]>:
st1:= T5Scheme(XY, A, 3):
plot([st1, st2], linestyle= [1, 3], color= [black, red]);

In almost all Maple commands, using an expression that's not an equation as an equation is equivalent to setting that expression equal to 0. Solving an expression set equal to 0 is almost equivalent to just solving its numerator set to 0, the only difference being that you might want to validate the solutions by checking whether they make the denominator 0, possibly under some restrictions. So, this works for your case:

pdsolve(numer~([eq1, eq2]));

Regarding your literal question "What does this error mean?": I don't know. It's very often much easier for me to correct or prevent an error in Maple than to understand it. It's a good question, but answering it might take several hours of investigating, digging through the code.

Using the same 1--8 numbering scheme as @lcz posted (from  Barik, S., Bapat, R.B., Pati, S.: "On the Laplacian spectra of product graphs" Appl. Anal. Discrete Math. 9, 39–58 (2015)), here is a procedure for any of the 2^8 = 256 possible products of two graphs:

RelationGraph:= proc(f, V::list({integer, symbol, string}))
local n:= {$1..nops(V)}, i, F:= i-> j-> f(V[i],V[j]);
    GraphTheory:-Graph(V, [seq](select(F(i), n, _rest), i= n))
end proc
:
GraphProducts:= proc(
    G::Graph, H::Graph, 
    Rel::{
        set(integer[1..8]), 
        identical(
            "Cartesian", "box", "strong", "normal", "AND", "modular", "homomorphic", 
            "lexicographic", "co-normal", "disjunctive", "OR",
            "tensor", "Kronecker", "categorical", "direct"
        )
    }:= "Cartesian",
    {
        vertex_format::{string, symbol}:= "%A:%A",
        labeltype::identical(string, symbol):= string
    }
)
local 
    V:= GraphTheory:-Vertices~([G,H]), 
    E:= op~(4, [G,H]),
    i, j, P:= [seq](seq([i,j], j= 1..nops(V[2])), i= 1..nops(V[1])), 
    Vgh:= (
        curry(`if`(labeltype=string, sprintf, nprintf), vertex_format)
        @ ((i,j)-> (V[1][i],V[2][j])) @ op
    )~(P),
    J:= op~(table(Vgh=~ P)),
    Edge:= (u,v,k)-> J[v][k] in E[k][J[u][k]],
    Eq:= (u,v,k)-> J[v][k] = J[u][k],
    Rs:= table([
        1= ((u,v)->     Edge(u,v,1) and       Eq(u,v,2)),
        2= ((u,v)-> not Edge(u,v,1) and       Eq(u,v,2)),
        3= ((u,v)->     Edge(u,v,1) and     Edge(u,v,2)),
        4= ((u,v)-> not Edge(u,v,1) and     Edge(u,v,2)),
        5= ((u,v)->     Edge(u,v,1) and not Edge(u,v,2)),
        6= ((u,v)-> not Edge(u,v,1) and not Edge(u,v,2)),
        7= ((u,v)->       Eq(u,v,1) and     Edge(u,v,2)),
        8= ((u,v)->       Eq(u,v,1) and not Edge(u,v,2))
    ]),
    Rels:= table([
        ("Cartesian", "box")=~ ``({1,7}), 
        ("strong", "normal", "AND")=~ ``({1,3,7}),
        "lexicographic"= ``({1,3,5,7}), 
        "modular"= ``({3,6}), 
        "homomorphic"= ``({5,7,8}), 
        ("co-normal", "disjunctive", "OR")=~ ``({1,3,4,5,7}),
        ("tensor", "Kronecker", "categorical", "direct")=~ ``({3})
    ])
;    
    RelationGraph(
        subs(_R= op(Rels[Rel]), (u,v)-> u<>v and ormap(k-> Rs[k](u,v), _R)),
        Vgh
    )
end proc
:
#Usage:
G:= GraphTheory:-CycleGraph(5): H:= GraphTheory:-CycleGraph(4):
GH:= GraphProducts(G, H, "co-normal", labeltype= symbol);
    GH := Graph 3: an undirected unweighted graph with 20 vertices and 140 edge(s

The third argument can be any subset of {1,2,3,4,5,6,7,8}; seven of the subsets are given string names (with some synonyms) for convenience. The labeltype of the product's vetrtices defaults to string.

What you want can be done with the || operator, which is very similar to cat, but without the evaluation issue that's causing your problem.

x||(a,b,c):= y =~ x^~(1,2,3);
rhs~([x||(a,c)])[];

 

Of course it can't be done. For it to be possible at all, at least the positions of the 0s must be the same.

Here is a procedure that plots the numbers themselves on the triangle's sides with the text orientation parallel to sides.

restart
:
RandPythTriple:= proc({upper::posint:= 2^62})
local 
    ub:= isqrt(iquo(upper, 2)),
    n:= rand(1..iquo(ub,2))(),
    m:= rand(1+n..ub)()
;
    (min,max)(m^2-n^2, 2*m*n), m^2+n^2
end proc
:
PlotTriple:= proc(a::posint, b::posint, c::posint)
uses P= plots, PT= plottools;
local prim:= igcd(a,b,c)=1, A:= a/c, B:= b/c;
    P:-display(
        PT:-polygon([[0,0], [0,A], [B,0]], 'color'= `if`(prim, 'red', 'blue')),
        P:-textplot(
            [
                [0, A/2, a, 'rotation'= Pi/2, 'align'= 'left'],
                [B/2, 0, b, 'align'= 'below'],
                [B/2, 1.1*A/2, c, 'rotation'= -arctan(a/b)]
            ],
            'font'= ['times', 'bold', 16]
        ),
        'title'= cat(`if`(prim, "Primitive ", ""), "Pythagorean Triple"),
        'titlefont'= ['times', 'bold', 20],
        'view'= [0..B, 0..A], 'axes'= 'none', 'scaling'= 'constrained', _rest
    )
end proc
:
PlotTriple(RandPythTriple(upper= 99));

Like this:

simplify(ans, zero);

Like this:

a__01 #Two underscores

 

To return all the values of w, replace your for loop (all 3 lines) with this:

w:= [seq](gamma__1*alpha/(4*k__1*qq[i]^2/d^2-alpha__3*xi/eta__1), i= 1..m);

That makes w a list. What you had makes w a table. There's nothing wrong with using a table, but they're slightly more difficult to return.

As promised, here's a general procedure for all such questions involving an equivalence relation between the rows of two matrices.
 

restart
:

A:= <
    1, 3, 3, 2, 3, 2, 2, 3, 3, 2, 0;
    1, 3, 3, 2, 3, 1, 1, 2, 3, 3, 2;
    1, 3, 2, 2, 2, 3, 1, 2, 3, 3, 2;
    1, 3, 5, 3, 2, 2, 3, 3, 2, 0, 0;
    1, 3, 5, 3, 1, 1, 2, 3, 3, 2, 0;
    1, 3, 4, 2, 3, 1, 2, 3, 3, 2, 0;
    1, 3, 6, 4, 2, 3, 3, 2, 0, 0, 0;
    1, 3, 6, 3, 1, 2, 3, 3, 2, 0, 0;
    1, 3, 5, 5, 5, 3, 2, 0, 0, 0, 0;
    1, 3, 3, 3, 5, 4, 3, 2, 0, 0, 0;
    1, 3, 4, 4, 4, 3, 3, 2, 0, 0, 0;
    1, 3, 3, 4, 6, 5, 2, 0, 0, 0, 0;
    1, 3, 5, 5, 6, 4, 0, 0, 0, 0, 0;
    1, 3, 5, 6, 4, 3, 2, 0, 0, 0, 0;
    1, 3, 3, 5, 5, 2, 3, 2, 0, 0, 0;
    1, 3, 5, 5, 3, 2, 3, 2, 0, 0, 0;
    1, 3, 3, 4, 3, 3, 2, 3, 2, 0, 0;
    1, 3, 4, 4, 2, 3, 2, 3, 2, 0, 0;
    1, 3, 5, 2, 1, 2, 3, 2, 3, 2, 0;
    1, 3, 5, 3, 2, 3, 2, 3, 2, 0, 0;
    1, 3, 4, 3, 1, 2, 3, 2, 3, 2, 0;
    1, 3, 3, 3, 2, 2, 3, 2, 3, 2, 0;
    1, 3, 3, 3, 1, 1, 2, 3, 2, 3, 2;
    1, 3, 2, 2, 3, 1, 2, 3, 2, 3, 2
>:

For testing, I construct matrix B by permuting (at random) a subset of the rows of A and then doing a random cyclic permutation on the interior columns.

(r,c):= op(1,A);

24, 11

C:= combinat:

cc:= rand(2..c-1)();

8

 

B:= A[C:-randperm(r)[..rand(1..r)()], [1, cc..-2, 2..cc-1, c]];

_rtable[36893491101098178908]

CycPermRep:= proc(r::posint, M::Matrix)
description "
This procedure returns (as a list) the lexicographically least cyclic permutation of
M[r, 2..-2]. The time complexity is O(c) where c is the number of columns of M.
";
local A:= [seq](M[r, 2..-2]), p;
    {seq}(A[[p..-1, 1..p-1]], p= ListTools:-SearchAll({A[]}[1], A))[1]
end proc
:

MatrixRowMatch:= proc(A::Matrix, B::Matrix, ClRep)
description "
Author: Carl Love <carl.j.love@gmail.com> 2022-Aug-28
.
For matrices A and B, this procedure produces a bipartite graph showing a relation between
the rows of A and those of B. The relation is determined by the 3rd argument, procedure or
operator ClRep.
.
The matrices can be any sizes; if one has fewer columns than the other, it'll be padded
on the right with 0s. Then the matrices are stacked into a single matrix AB. ClRep's
arguments will be a row number i of AB, AB itself, and any extra arguments passed to this
procedure. It should return a canonical identifier (of any immutable type) of the
relation's equivalence class that contains row AB[i]. (The return value should be
immutable, such as a list; thus, it shouldn't be a vector.)
.
The equivalence classes are used to form a bipartite graph by removing connections from A
to itself and B to itself. The graph's vertices are
[cat(\"A\", 1..ra), cat(\"B\", 1..rb)] where ra and rb are the numbers of rows of A and
B.
.
The time complexity of this algorithm is O(r*C) where r is the number of rows of AB and C
is the time complexity of C1Rep.
";
local AB, Cl, ra, ca, rb, cb, r, RepRem, rest:= _rest;
    (ra, ca):= op(1, A); (rb, cb):= op(1, B); r:= ra+rb;
    AB:= <<A | Matrix((ra, max(0, cb-ca)))>, <B | Matrix((rb, max(0, ca-cb)))>>;
    RepRem:= proc(i::posint) option remember; ClRep(i, AB, rest) end proc;
    Cl:= ListTools:-Classify(RepRem, [$1..r]);
    GraphTheory:-Graph(
        [cat("A", 1..ra), cat("B", 1..rb)],
        Array(1..r, i-> remove(`if`(i > ra, `>`, `<=`), Cl[RepRem(i)], ra))
    )
end proc
:

BG:= MatrixRowMatch(A, B, CycPermRep);

GRAPHLN(undirected, unweighted, ["A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "A10", "A11", "A12", "A13", "A14", "A15", "A16", "A17", "A18", "A19", "A20", "A21", "A22", "A23", "A24", "B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8", "B9", "B10", "B11", "B12", "B13", "B14"], Array(1..38, {(1) = {34}, (2) = {28}, (3) = {}, (4) = {30}, (5) = {}, (6) = {}, (7) = {27}, (8) = {}, (9) = {32}, (10) = {35}, (11) = {}, (12) = {33}, (13) = {31}, (14) = {29}, (15) = {25}, (16) = {}, (17) = {26}, (18) = {}, (19) = {38}, (20) = {}, (21) = {}, (22) = {36}, (23) = {}, (24) = {37}, (25) = {15}, (26) = {17}, (27) = {7}, (28) = {2}, (29) = {14}, (30) = {4}, (31) = {13}, (32) = {9}, (33) = {12}, (34) = {1}, (35) = {10}, (36) = {22}, (37) = {24}, (38) = {19}}), `GRAPHLN/table/1`, 0)

GT:= GraphTheory:

E:= GT:-Edges(BG);

{{"A1", "B10"}, {"A10", "B11"}, {"A12", "B9"}, {"A13", "B7"}, {"A14", "B5"}, {"A15", "B1"}, {"A17", "B2"}, {"A19", "B14"}, {"A2", "B4"}, {"A22", "B12"}, {"A24", "B13"}, {"A4", "B6"}, {"A7", "B3"}, {"A9", "B8"}}

for e in E do
    print(A[parse(e[1][2..])], B[parse(e[2][2..])])
od;

Vector[row](11, {(1) = 1, (2) = 3, (3) = 3, (4) = 2, (5) = 3, (6) = 2, (7) = 2, (8) = 3, (9) = 3, (10) = 2, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 3, (3) = 3, (4) = 2, (5) = 3, (6) = 3, (7) = 2, (8) = 3, (9) = 2, (10) = 2, (11) = 0})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 3, (4) = 3, (5) = 5, (6) = 4, (7) = 3, (8) = 2, (9) = 0, (10) = 0, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 2, (3) = 0, (4) = 0, (5) = 3, (6) = 3, (7) = 3, (8) = 5, (9) = 4, (10) = 3, (11) = 0})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 3, (4) = 4, (5) = 6, (6) = 5, (7) = 2, (8) = 0, (9) = 0, (10) = 0, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 0, (3) = 0, (4) = 0, (5) = 3, (6) = 3, (7) = 4, (8) = 6, (9) = 5, (10) = 2, (11) = 0})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 5, (4) = 5, (5) = 6, (6) = 4, (7) = 0, (8) = 0, (9) = 0, (10) = 0, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 0, (3) = 0, (4) = 0, (5) = 3, (6) = 5, (7) = 5, (8) = 6, (9) = 4, (10) = 0, (11) = 0})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 5, (4) = 6, (5) = 4, (6) = 3, (7) = 2, (8) = 0, (9) = 0, (10) = 0, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 0, (3) = 0, (4) = 0, (5) = 3, (6) = 5, (7) = 6, (8) = 4, (9) = 3, (10) = 2, (11) = 0})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 3, (4) = 5, (5) = 5, (6) = 2, (7) = 3, (8) = 2, (9) = 0, (10) = 0, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 2, (3) = 0, (4) = 0, (5) = 3, (6) = 3, (7) = 5, (8) = 5, (9) = 2, (10) = 3, (11) = 0})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 3, (4) = 4, (5) = 3, (6) = 3, (7) = 2, (8) = 3, (9) = 2, (10) = 0, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 3, (3) = 2, (4) = 0, (5) = 3, (6) = 3, (7) = 4, (8) = 3, (9) = 3, (10) = 2, (11) = 0})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 5, (4) = 2, (5) = 1, (6) = 2, (7) = 3, (8) = 2, (9) = 3, (10) = 2, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 2, (3) = 3, (4) = 2, (5) = 3, (6) = 5, (7) = 2, (8) = 1, (9) = 2, (10) = 3, (11) = 0})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 3, (4) = 2, (5) = 3, (6) = 1, (7) = 1, (8) = 2, (9) = 3, (10) = 3, (11) = 2}), Vector[row](11, {(1) = 1, (2) = 2, (3) = 3, (4) = 3, (5) = 3, (6) = 3, (7) = 2, (8) = 3, (9) = 1, (10) = 1, (11) = 2})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 3, (4) = 3, (5) = 2, (6) = 2, (7) = 3, (8) = 2, (9) = 3, (10) = 2, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 2, (3) = 3, (4) = 2, (5) = 3, (6) = 3, (7) = 3, (8) = 2, (9) = 2, (10) = 3, (11) = 0})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 2, (4) = 2, (5) = 3, (6) = 1, (7) = 2, (8) = 3, (9) = 2, (10) = 3, (11) = 2}), Vector[row](11, {(1) = 1, (2) = 3, (3) = 2, (4) = 3, (5) = 3, (6) = 2, (7) = 2, (8) = 3, (9) = 1, (10) = 2, (11) = 2})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 5, (4) = 3, (5) = 2, (6) = 2, (7) = 3, (8) = 3, (9) = 2, (10) = 0, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 3, (3) = 2, (4) = 0, (5) = 3, (6) = 5, (7) = 3, (8) = 2, (9) = 2, (10) = 3, (11) = 0})

Vector[row](11, {(1) = 1, (2) = 3, (3) = 6, (4) = 4, (5) = 2, (6) = 3, (7) = 3, (8) = 2, (9) = 0, (10) = 0, (11) = 0}), Vector[row](11, {(1) = 1, (2) = 2, (3) = 0, (4) = 0, (5) = 3, (6) = 6, (7) = 4, (8) = 2, (9) = 3, (10) = 3, (11) = 0})

Vector[row](%id = 36893491101175625596), Vector[row](%id = 36893491101175625716)

GT:-DrawGraph(BG, layout= bipartite);

 

Download MatrixRowMatch.mw

Here is a procedure for it (based on my limited understanding from a very quick lookup of the definition of the co-normal product of graphs). Let me know if I got it right. The definition that I used is that conormal(G,H) contains the edge {u1:v1, u2:v2} iff (G contains {u1, u2} or H contains {v1, v2}). 

restart
:
RelationGraph:= (f, V::list({integer, symbol, string}))->
local n:= {$nops(V)}, i, F:= i-> j-> f(V[i],V[j]);
    GraphTheory:-Graph(V, [seq](select(F(i), n, _rest), i= n))
:
ConormalProduct:= proc(
    G::Graph, H::Graph, {vertex_format::{string, symbol}:= "%a:%a"}
)
local Vg, Vh, ng, nh, Ng, Nh, P, i, j, Vgh, K;
    (Vg,Vh):= op(GraphTheory:-Vertices~([G,H]));
    (ng,nh):= op(`..`~(1, nops~([Vg,Vh])));
    (Ng,Nh):= op(op~(4, [G,H]));
    P:= [seq](seq([i,j], j= nh), i= ng);
    Vgh:= (curry(sprintf, vertex_format)@((i,j)-> (Vg[i],Vh[j]))@op)~(P);
    K:= op~(table(Vgh=~ P));
    RelationGraph(
        proc(a, b, $)
        local u, v, x, y; 
            (u,v):= K[a]; (x,y):= K[b]; 
            x in Ng[u] or y in Nh[v]
        end proc,
        Vgh
    )
end proc
:

 

I've had many problems using coerce over the years, although it seems much better in Maple 2022 than previously. That's why for a previous Question from you, I recommended using coercion procedures whose names begin rather than using the coerce parameter modifier.

I have no experience using Maple's debugger (or any other debugger for that matter), but as far as I can tell, the following works with the debugger and correctly does the coercion. Let me know if it works for you.

restart;
~list:= (e, T::type)->
    if e::{set, thistype}(T) then [`if`](e::set, e[], e)
    else error "%1 not cercible to type list(%2)", A, T
    fi
:
A:= module()
option object;
export 
    ode, ic,

    ModuleCopy::static:= proc(_self, proto::A, ode::`=`, {ic::~list(`=`):= []}, $)
        print("ode=",ode);
        print("ic=",ic)
    end proc
;
end module;

foo:= proc(ode::`=`, {ic::~list(`=`):= []}, $)
local o;
    #DEBUG();
    o:= Object(A, ode, ':-ic'= ic)
end proc:

foo(diff(y(x),x)=1); 

 

The last word of your description is `vectors"`. It should be `vectors`".

It can be done by

I *~ soln

If I use your n:= 434160 and create a random x n tridiagonal matrix with options shape= band[1, 1], datatype= hfloat and a random n-vector with datatype= hfloat and then simply call X:= LinearSolve(A, B), it takes 0.047 seconds, the memory usage is trivial, and the infinity norm of the residual vector A.X - B is 2e-9.

restart:
Digits:= 15:
n:= 434160:
LA:= LinearAlgebra:

A:= LA:-RandomMatrix(
    (n,n), generator= -99. .. 99., shape= band[1,1], datatype= hfloat
):
B:= LA:-RandomVector(n, generator= -99. .. 99., datatype= hfloat):
X:= CodeTools:-Usage(
    LA:-LinearSolve(A, B)
):
memory used=20.08MiB, alloc change=19.88MiB, cpu time=47.00ms, real time=52.00ms, gc time=0ns

abserr:= LA:-Norm(A.X - B);
                                               -9
               abserr := 2.06871675345610129 10  

(The RandomMatrix command above takes several minutes to complete.)

First 40 41 42 43 44 45 46 Last Page 42 of 395