Carl Love

Carl Love

28015 Reputation

25 Badges

12 years, 300 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@soran Thank you. That's simple and easy to remember.

Why do you want to declare it constant? What would that allow you to do that you couldn't do by just using it without any special declaration (or assumption)?

I'm not necessarily suggesting that you shouldn't declare (or assume) it a constant, but in my experience it's usually (not always) not particularly useful to do so.

@Maxwell_MA I deleted your Question which was essentially a duplicate of this Question. I will give you some help on this momentarily. 

@vv Vote up.

It's possible to reduce the number of subset comparisons by a factor of more than 2 and the number of union operations by about 2 orders, like this

Dynkin:= proc(C::set(set), X::set:= `union`(C[]))    
local D, newD:= (C minus {{}}) union {X};
    if not `union`(C[]) subset X then 
        error "Invalid input: C must contain subsets of X"
    fi; 
    while newD <> D do
        D:= newD;
        newD:= D union 
            map(
                P-> P[2] minus P[1], 
                select(`subset`@op, combinat:-choose(D,2))
            )
    od;
    D union {{}}
end proc
:

Note that I switched the order of arguments and X (partly so that could be given a default value).

@Rouben Rostamian  The three transformations of your double-angle identities can be done with combine.

The half-angle transformations can be done a bit more efficiently by using a table instead of an if statement: 

`convert/half_angle`:= module()
local
    F:= [sin, cos, tan, cot],
    T:= table(
        F =~ [2*sin*cos, 2*cos^2-1, 2*tan/(1-tan^2), (cot^2-1)/2/cot]
    ),
    TT:= {F[]}(anything),
    ModuleApply:= expr-> evalindets(expr, TT, f-> T[op(0,f)](op(f)/2))
;
end module
: 

 

@Rouben Rostamian  In my opinion, applyrule is crap, and I would always replace it with subsindetsevalindets, or something similar.

Since the third argument to subsindets or evalindets is a procedure, there's no limit to the number of rules you can use or their complexity. To do what you just asked:

subsindets(
    sin(x)+cos(x),
    {sin, cos}(anything),
    f-> 
        local x:= op(f)/2;
        if op(0,f)=sin then 2*sin(x)*cos(x) else 1-2*sin(x)^2 fi
);

 

@lcz While it may not conform to the usual custom, it is far more convenient and efficient for most programming purposes. The first step in almost every GraphTheory program that I write is to construct a table matching the vertex labels to their indices. The indices are also the indices into the adjacency matrix.

@Felipe_123 The question is if there is a P that works, is it sufficient for your purpose to return just that P? Or do you need returned all P that work?

@Joe Riel In procedure Fullnumelems(L1) should be numelems(L1[1]) or its equivalent. There's no good reason why the number of elements in the vectors should be the same as the number of vectors in the lists; that just happens to be true in the example shown.

@C_R Thanks. A triple interobang can indeed be created as a Maple symbol like this

nprintf(`#mo(%a)`, cat("&#8253;"$3));

Such creations can be used like any other Maple symbol (or variable); in particular, they can be function names. Also try

nprintf(`#msup(msup(mo(%a),mo(%a)),mo(%a))`, "&#8253;"$3);

@C_R To provide a further example of functional syntax, your simplify_expanded can be simplified to

simplify_expanded:= 1@@0 = simplify@`/`@op@expand~@[numer,denom]:

Since every element of that is already a functional operator, there's no need for any -> or any variables.

1@@0 is a multivariate identity operator. Some other identity operators are D[]`@`(), and ()-> args.

In my Answer, I essentially claimed that if G had a Hamiltonian path beginning at v, then any depth-first search applied to (G,v) would necessarily return a Hamiltonian path[*1]. I was wrong about that. Depending on the order that vertices are selected, it's still possible to reach a "dead end" before all vertices are exhausted, in which case a "branch" will be taken from one of the vertices on the stack that connects to a not-yet-seen vertex.

Despite that incorrect claim, the posted code does correctly perform the function stated in its description.

[*1] In other words, I'd claimed, incorrectly, that if G had a spanning tree that was a simple path starting at (such a path is called Hamiltonian) then the depth-first search starting at v would necessarily return it or another simple path.

The stack command was superceded by SimpleStack about 20 years ago. The help page ?stack says stack can also be replaced with DEQueue (a stack being a double-ended queue where only one end is used).

Here it is using 1D input.

restart:
f:= x-> sin(100/(x+13)); g:= x-> 10/(10*x+3);

C:= fsolve(f(x)=g(x), x= 20);
                        C := 19.35519742

FG:= Int(f(x)-g(x), x= C..E, continuous): fg:= value(FG): FG=fg;

fsolve(fg = 3, E= C..infinity);
                          28.05987548

Download IntCont.mw

Oops, I forgot to address that issue in my Answer, although I'd originally intended to. By using keyword option continuous as the 3rd argument to int, the integration will be carried out and the warning will be avoided. This option is equivalent to specifying that the interval of integration doesn't contain the singularity at x = -13 or the one at x = -3/10.

First 101 102 103 104 105 106 107 Last Page 103 of 708