Carl Love

Carl Love

28050 Reputation

25 Badges

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

MaplePrimes Activity


These are replies submitted by Carl Love

@sursumCorda Acer may have some tools to help him trace the path through that tree to the 13th level without getting lost. But here is a completely different way to do the "micro-surgery" on that procedure that doesn't require that meticulous detail. The inequality that we want to change on line 24 is

`is/internal/SMTLIB_max_sys_size`(sys) <= 5

Rather than multiplying the right side by 2 (to change 5 to 10), we can multiply the left side by 1/2. This has the same mathematical effect; alas, it doesn't leave the code looking as nice. The reason that I mention it is that that change can be made with a simple subs command with no need for inert forms. The command is

`is/internal/SMTLIB`:= subs(
    `is/internal/SMTLIB_max_sys_size`= `is/internal/SMTLIB_max_sys_size`/2,
    eval(`is/internal/SMTLIB`)
);
protect(`is/internal/SMTLIB`);

The protect is to prevent you from accidentally doing this multiple times, which wasn't a potential problem with Acer's method.

I think that it's impossible to make the substitution target the whole inequality because it contains the local variable sys. (If it's possible, I'd love to know how.)

@sursumCorda This is an explanation of 

subsop([5,7,1,2,5,1,1,2,1,2,1,2,1]=10, ToInert(eval(`is/internal/SMTLIB`)))

Use showstat to view procedure `is/internal/SMTLIB`:

showstat(`is/internal/SMTLIB`);

Look for the inequality towards the end of line 24. It specifies some sort of resource-usage limitation with an upper limit of 5. Acer decided to change the upper limit to 10. One way to do that is to put the procedure into "inert form" (an extremely verbose tree structure), traverse the tree keeping track of the node numbers until you get to the 5, change it to 10, then reconstruct the "active form" of the procedure. The numbers mean "Starting from the root, take the 5th branch, then take the 7th branch of that, then take 1st branch of that, etc."

Yes, this has been a mysterious, intermittent problem on MaplePrimes for several years. No-one has found conclusive evidence that it's caused by the worksheet's type or contents or the poster's browser or settings. 

@acer You asked:

  •  [have I expressed this correctly?]

The is command is an evaluator for the universal quantifier, and coulditbe is an evaluator for the existential quantifier. The rules for quantifier negation are

  • not forall(x, P(x)) <=> exists(x, not P(x)),
  • not exists(x, P(x)) <=> forall(x, not P(x)).

Therefore, the translation of is(F1 implies F2) into a form that can be evaluated is 

is(F1 implies F2)  <=>  
is(not (not (F1 implies F2)))  <=>  
not coulditbe(not (F1 implies F2))  <=>
not coulditbe(F1 and not F2),

whereas you had not is(F1 and not F2).

@sursumCorda What haven't you responded to my Answer below?

@nm Yes, your guess as to why the code returns 2 is correct. If the answer is supposed to be 1, then I'm sure that your concept of "degree" of a differential equation is worthless. So, I'm not wasting any more time on something that's worthless. What does your beloved Mathematica say about the degree of this ODE?

Recall this definition of degree of a differential equation that you gave on 2019-July-19:

  • "In mathematics, the degree of a differential equation is the power of its highest derivative, after the equation has been made rational and integral in all of its derivatives"

What makes this equation different from the 2nd, 3rd, 5th, and 6th equations on your test list, for which you accept that the "degree" is 2?

Also consider your original Question:

"For an example, given 

restart;
ode:=(1+diff(y(x),x)^2)^(3/2)=diff(y(x),x$2)

I want the command to return 2 for the order of the ODE and degree is also 2 in this case."

What makes this new equation different from that?

@Ronan The scope of those variables must include both procedures ppp and Qprj. Therefore they muist be local to the outermost module, rt.

Can we see equations 20-25, which specify v_0(t), ..., v_5(t)?

@Anthrazit The first argument of XMLElement, the "a" in this case, is an identifier for the element itself and is not considered to be one of its children.

@PaulNewton You wrote:

  • Thank you, but I must agree with acer 27088 said yesterday at 745 AM
    In comparison, using complicated regular expression matching looks needlessly complicated here.

If you already know that your string ends with the reference number (such as 2.13) in parentheses, then I agree that Drop Take is easier. The point of the regular expression is to check whether the reference number is there, at the end. If it's not there, the Drop - Take will return whatever the last item in parentheses is, even if it's in the middle of the string. 

@Carl Love Consider these suggested improvements to your program:

is_prime:= proc(x::integer)
    if x < 2 then false
    elif x = 2 then true
    elif irem(x,2) = 0 then
        userinfo(1, is_prime, cat(``, x, ` is divisible by 2.`)); 
        false
    else
        local i, `i^2`:= 1;
        for i from 2 while (`i^2`+= 4*i++) <= x do
            if irem(x,i) = 0 then
                userinfo(1, is_prime, cat(``, x, ` is divisible by `, i, `.`));
                return false
            fi
        od;
        true
    fi
end proc:

infolevel[is_prime]:= 1:
is_prime(10^6+1);
is_prime: 1000001 is divisible by 101.
                             false
is_prime(10^6+3);
                              true

 

@sursumCorda Yes, you can usually run them. In this case, you certainly can. However, HamiltonianSAT is not a kernel function, but rather a local (rather than export) of module GraphTheory. To access module locals, you need to set

kernelopts(opaquemodules= false):

Then you can run, for example, 

GraphTheory:-HamiltonianSAT(G, true, true); #assuming G has been assigned a graph!

When accessing a module local this way, the module-name prefix, e.g., GraphTheory:-, is always needed, regardless of whether the module's package has been loaded with a with command.

@sursumCorda If you read the code with showstat(GraphTheory:-IsHamiltonian), I think that you'll understand what's going on. Information about a graph G can be stored in the graph's data structure with the command GraphTheory:-SetGraphAttribute and retrieved with GraphTheory:-GetGraphAttribute. Look for those commands in the code. It's simply remembering that it has already proven the graph is Hamiltonian. Some graphs from SpecialGraphs also have this information prestored. That's the case for your H3.

@MANUTTM Like this:

beta:= {$1..8}: 
plotdata:= Array(1..nops(K), 1..nops(beta), 1..12):
for j to nops(K) do
    k1:= K[j];
    for i to nops(beta) do 
        b:= beta[i]; 
        Etemp := eval(
            `&pi;central`(p, e, z), 
            [A= 0, B= 2, alpha= 50, beta= b, c= 5, k= k1, mu= 10, v= 1]
        );
        Soln:= NLPSolve(Etemp, p= 5..500, e= 0.5..10, z= 0..10, maximize);
        (etemp, ptemp, ztemp):= eval([e, p, z], Soln[2])[]; 
        `&pi;temp` := Soln[1];
        y_temp:= eval(y(p,e), [alpha= 50, beta= b, p= ptemp, k= k1, e= etemp]);
        q_temp:= y_temp + ztemp;
        E_decent := eval(
            `&pi;central`(p, e, z), 
            [A= 0, B= 2, alpha= 50, beta= b, c= 10, k= k1, mu= 10, v= 1]
        );
        Sol:= NLPSolve(E_decent, p= 5..500, e= 0.5..10, z= 0..10, maximize);
        (e_d, p_d, z_d):= eval([e, p, z], Sol[2])[];
        `&pi;_rd`:= Sol[1];
        y_d:= eval(y(p,e), [alpha= 50, beta= b, p= p_d, k= k1, e= e_d]);
        q_d:= y_d + z_d;
       `&pi;dmanf` := (w_d - c_d)*q_d;
       `&pi;_d` := `&pi;_rd` + `&pi;dmanf`;
        plotdata[j,i] := < 
            b | ztemp | ptemp | etemp | q_temp | `&pi;temp` | 
            z_d | p_d | e_d | q_d | `&pi;_rd` | `&pi;dmanf`
        >
    od
od:
(DocumentTools:-Tabulate@DataFrame)(
    evalf[5](<seq(seq(plotdata[j,i,2..], j= 1..nops(K)), i= 1..nops(beta))>),
    rows= [seq](seq(cat(`&beta; = `, i, `, K = `, j), j= 1..nops(K)), i= 1..nops(beta)),
    columns= [
        ` ztemp`, ` ptemp`, ` etemp`, ` q_temp`, ` &pi;temp`,
        ` z_d`, ` p_d`, ` e_d`, ` q_d`, ` &pi;_rd`, ` &pi;manf`
    ]
):
plots:-display(
    <seq(
        plot(
            [seq](Matrix(plotdata[j, .., [1,jj]]), jj= 3..5), legend= ['p', 'e', 'q'],
            style= pointline, symbol= [box, diamond, solidcircle], 
            labels= ['beta', ``], title= sprintf("k1 = %a", K[j]), axes= boxed
        ),
        j= 1..nops(K)
    )>^%T
); 

 

@Carl Love Here is the patch (which only took 22 minutes to write): 

restart:
sav:= eval(GraphTheory:-IsHamiltonian):
unprotect(GraphTheory:-IsHamiltonian):
GraphTheory:-IsHamiltonian:= overload([
    proc(G::GRAPHLN, cycle::name:= (), {method::identical(tsp):= ':-tsp'})
    option overload;
    uses GT= GraphTheory;
    local d, C;
        try (d,C):= GT:-TravelingSalesman(G, GT:-AdjacencyMatrix(G))
        catch "%1 expects a connected": return false
        end try;
        if d = infinity then return false fi;
        if cycle::name then cycle:= C fi;
        true
    end proc,

    eval(sav)
]):
protect(GraphTheory:-IsHamiltonian):

#Test on your example:
GT:= GraphTheory:
GT:- IsHamiltonian(GT:-CompleteGraph(3,3), 'C', method= tsp);
                              true
C;
                     [1, 2, 4, 5, 6, 3, 1]

 

First 65 66 67 68 69 70 71 Last Page 67 of 709