Carl Love

Carl Love

25796 Reputation

25 Badges

10 years, 352 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

The information about a graph G's edges is stored in an Array as op(4,G). Although this structure doesn't seem to have a formal documented name, I find it to be the most convenient and most efficient way to access the edge infomation from a graph. Suppose that there are n vertices. Then op(4,G) is an Array indexed 1..n such that A[k] is the set of the indices of the neighbors of the kth vertex. In the code below, I construct this Array as a means to construct your graph. However, if the graph was constructed some other way, this Array could still be accessed as op(4,G)

restart:

GT:= GraphTheory:

Vs:= [x,y,z,w]:

n:= [$nops(Vs)]:

 

Popvs:= [-2, 1, 6, 3]:

Nbs:= Array([{2}, {1,3,4}, {2,4}, {2,3}]):

X:= GT:-Graph(Vs, Nbs);

GRAPHLN(undirected, unweighted, [x, y, z, w], Array(1..4, {(1) = {2}, (2) = {1, 3, 4}, (3) = {2, 4}, (4) = {2, 3}}), `GRAPHLN/table/1`, 0)

GT:-SetVertexPositions(X, [[0,0], [1,0], [1.5,1], [2,0]]):

newX:= GT:-RelabelVertices(X, [seq](cat(Vs[i], "=", add(Popvs[[i, Nbs[i][]]])), i= n));

GRAPHLN(undirected, unweighted, [`x=-1`, `y=8`, `z=10`, `w=10`], Array(1..4, {(1) = {2}, (2) = {1, 3, 4}, (3) = {2, 4}, (4) = {2, 3}}), `GRAPHLN/table/1`, 0)

GT:-DrawGraph(newX);

 

NULL

Download NeighborArray.mw

Your integrations are performed with respect to epsilon. Thus, it doesn't make sense to substitute a numeric value for epsilon. You've substituted 5000.

It's done with the background option, like this

plots:-display(ttt0, background= U1, axes = none, size = [400, 160]);

You needn't use ImageTools; you could just as well do this

U1:= "C:/Users/S/Desktop/StarPicture.jpg":
plots:-display(ttt0, background= U1, axes = none, size = [400, 160]);

The Maple command is gcdex. See help page ?gcdex. For example,

gcdex(x^3-1, x^2+2, x, 'a', 'b'): 'a'(x)=a, 'b'(x)=b;
                           

Maple currently has 6 inert infix arithmetic operators: %^%.%*%/%+, and %-. These have the same algebraic rules (precedence and associativity) as their non-inert counterparts. In addition any name---whether it be a function, procedure, or just a variable or named constant---can be made inert by prepending the name with %. In some cases, such as a non-alphanumeric name, the must be prepended inside back quotes (such that the entire name is in back quotes). Any number of prepended may be used, each of which represents a "level" of inertness. The value command removes one level of inertness from an expression.

Operators other than the 6 listed above can be made inert by using their prefix functional forms and including a %. For example, 

`%=`(a, b)

Your parameter values p3 contains cos gamma = 1/sqrt(2). That needs to be cos(gamma) = 1/sqrt(2).

Like this:

restart:
interface(imaginaryunit= _I):
Trans:= proc(A)
uses LA= LinearAlgebra;
local vA;
    if A::rtable then thisproc~(A^%T) 
    else
        vA:= value(A);
        `if`(vA::rtable and LA:-Equal(vA, vA^%T), A, 'procname'(A))
    fi
end proc
:  
`print/Trans`:= A-> A %^ %T:
F:= <1,2;3,4>: I:= <1,0;0,1>: `0`:= Matrix(2,3,0):
M:= <%I, %F; `%0`, `%0`>:

Trans(M) %. M;

 

I couldn't resist the urge to simplify Joe's procedure, and also to lift its restriction to purely symbolic operands. My operands can be arbitrary algebraic expressions.

SumMultiPartitions:= proc(L::{list,set}(algebraic))
uses J= Iterator, S= Statistics;
local x:= <{L[]}[]>^+, W, M:= J:-MultiPartition(eval([seq](x), S:-Tally([L[]]))); 
    [seq]([seq]((x.W)[..M:-length(M)]), W= M)
end proc
:
#Examples of usage:
SumMultiPartitions([a,b,c]);
  [[a + b + c], [a + b, c], [a + c, b], [a, b + c], [a, b, c]]

SumMultiPartitions([a,a,b,c]);
 [[2 a + b + c], [2 a + b, c], [2 a + c, b], [2 a, b + c], 
   [2 a, b, c], [a + b + c, a], [a + b, a + c], [a + b, a, c], 
   [a + c, a, b], [a, a, b + c], [a, a, b, c]]

SumMultiPartitions([3,3,5,7]);
[[18], [11, 7], [13, 5], [6, 12], [6, 5, 7], [15, 3], [8, 10], 
  [8, 3, 7], [10, 3, 5], [3, 3, 12], [3, 3, 5, 7]]

 

Assuming that you don't care about the order in which the output appears, I think that the following does what you want: 

SumPartitions:= proc(S::{set, list})
local p, J:= Iterator:-SetPartitions(nops(S)), `&<`:= curry; 
    {seq}((sort @ add~ @ map&<(map2,index,S) @ [op]~ @ J:-ToSets)(p), p= J)
end proc
:
#Examples of usage:
SumPartitions([a,b,c,d]);
{[a + b + c + d], [a, b + c + d], [b, a + c + d], [c, a + b + d], 
  [d, a + b + c], [a + b, c + d], [a + c, b + d], [a + d, b + c], 
  [a, b, c + d], [a, c, b + d], [a, d, b + c], [b, c, a + d], 
  [b, d, a + c], [c, d, a + b], [a, b, c, d]}

SumPartitions([a,a,b,c]); #Joe's multiset example
  {[2 a + b + c], [a, a + b + c], [b, 2 a + c], [c, 2 a + b], 
   [2 a, b + c], [a + b, a + c], [a, a, b + c], [a, b, a + c], 
   [a, c, a + b], [b, c, 2 a], [a, a, b, c]}

SumPartitions([a,b,c]);
  {[a + b + c], [a, b + c], [b, a + c], [c, a + b], [a, b, c]}

 

All symbolic (or unassigned) variables in Maple are by default assumed to represent complex numbers unless something is used that changes that default. Usually this is transparent (making no difference to final results) when the variables are only intended to represent reals. One case where it isn't completely transparent is when doing the dot product of two vectors of the same orientation with one or both containing variables. In that case, the definition of u.v is the inner product of conjugate(u) and (if they're column vectors) or of u and conjugate(v) (if they're row vectors). (There's a definition of complex conjugate in a paragraph below.) (By inner product, I mean the sum of the elementwise products.) The overbar is a symbol for the conjugate. This has no effect if the variables represent reals (conjugate(x) = x for x real), so it's still essentially (or mathematically) transparent except for the possibly unwanted visual presence of the overbar.

As you've noticed, this doesn't happen when you multiply a row vector by a column vector (with the row being the left operand!). A much simpler syntax for multiplying the two columns of Q is

Q[.., 1]^%T . Q[.., 2] 

The .. means "all rows"; the ^%T means the transpose. In 1D input, ^+ can also be used (and perhaps this now works in 2D also). Likewise ^%H or ^* can be used for the conjugate (aka Hermitian) transpose.

The complex conjugate of x + I*y (with x and real) is defined as x - I*y. The Maple command is conjugate. An overbar is the standard typeset representation of an unevaluated complex conjugate, just like a pair vertical bars is the standard typeset representation for an unevaluated absolute value. Applying conjugate to a vector or matrix just means that the operation is mapped over the elements. 

There are numerous other ways to either avoid or remove the overbars. I think the best overall way is to multiply (row . column), as shown above.

Since all the inequalities are polynomial, I think that this problem can be done by the solve command, assuming that the absence of a result without any warning can be taken for certain to mean that there's no solution.

First, let's do some rearrangement of logical formulas:

restart:
Prop:= eval(
    Logic:-BooleanSimplify(
        Logic:-Canonicalize(&not((p1 &and p2) &implies (p3 &and p4)), [p||(1..4)])
    ),
    [Logic:-`&and`, Logic:-`&or`, Logic:-`&not`]=~ [And, Or, Not]
);
     

V:= {a, b, c, d}:
S||(1..4):= seq((add@mul~@combinat:-choose)(V, k), k= 1..4): 
p1:= S1 > 0:
p2:= S2 > (add@mul~@[`$`]~)(V,2):
not_p3:= S3 <= 0:
not_p4:= S4 <= 0:
d1:= {p1, p2, not_p3}; d2:= {p1, p2, not_p4};


 

solve(d1, V, parametric, real);
                               []

solve(d2, V, parametric, real);
                               []

Therefore exists(V, Prop) is false. Therefore forall(V, not Prop) is true, where not Prop is the original implication that you wanted to prove.

However, MathematicalFunctions:-Coulditbe gives the opposite result, while using 124 times as much computation time as the solves. I don't trust it though.

CodeTools:-Usage(
    MathematicalFunctions:-Coulditbe(And(d1[])) assuming V[]::~real
);
memory used=7.03GiB, alloc change=136.82MiB, 
cpu time=3.61m, real time=3.47m, gc time=14.47s

                              true
CodeTools:-Usage(
    MathematicalFunctions:-Coulditbe(And(d2[])) assuming V[]::~real
);
memory used=10.76GiB, alloc change=98.64MiB,
cpu time=4.73m, real time=4.28m, gc time=33.34s

                              true

I tried a million random numerical evaluations in an attempt to find a witness to the above true results, but none were found:

R:= rand(-2. .. 2.):
to 10^6 do
    r4:= 'R'()$4:
    if andmap(evalb, eval(d1, V=~ r4)) or andmap(evalb, eval(d2, V=~ r4)) then
        print(r4);
        break
    fi
od: 

 

Your system of ODEs is not autonomous because the coefficients of the dependent variables x1(t) and x2(t) depend on the independent variable t.

The 2 after break doesn't make sense because you only have one loop; break only works for do-loops. I'm guessing that you want to "break" out of the whole procedure. The command for that is return.

Also, if you're using 2D Input: Multi-level break doesn't work in 2D Input, as noted on the ?break help page. None of the syntax enhancements made in the last 5 or so years work in 2D Input.

Looking at the code with showstat(GraphTheory:-IsHamiltonian) clearly shows that there's no mention of tsp nor use of any algorithm akin to solving a traveling-salesman problem. So, the help page is clearly wrong. There is a procedure GraphTheory:-TravelingSalesman, it has a help page, and I tested it 6 days ago (in response to this Question: "Traveling-salesman problem"). 

It seems necessarily inefficient to me to use a minimizing algorithm if you just want any Hamiltonian circuit. However, if you want, I could easily (30 - 60 minutes) write a patch for you to implement method = tsp in IsHamiltonian. So, let me know if that's what you want.

The StringTools package can process so-called regular expressions (such as are commonly used in Linux shell scripts). Let's say that you want to extract a number (possibly including periods) in parentheses from the end of a string.

StringTools:-RegMatch("\\([0-9.]*\\)$", L1, 'c');
                              true

c:= c[2..-2]; #Strings can be indexed like Arrays and lists.
                          c := "2.13"
#Even more slick:
StringTools:-RegMatch("\\(([0-9.]*)\\)$", L1, 'c', 'c'), c;
                          true, "2.13"
​​​
First 11 12 13 14 15 16 17 Last Page 13 of 374