sursumCorda

1002 Reputation

13 Badges

1 years, 231 days

MaplePrimes Activity


These are answers submitted by sursumCorda

How about

DocumentTools['Tabulate'](<"", `<,>`(F(x)) | `<|>`(C), Matrix(numelems(F), numelems(C), fill = NULL)>, width = 50, fillcolor = (T, i, jj) -> ifelse(i = 1 or jj = 1, [210, 230, 255], [255, 255, 235])):

While @acer uses the _npassed (which is equivalent to nargs), @Carl Love uses a much advanced command overload. However, if you only intend to create the desired computation sequences in seconds, the following approach will be more convenient: 

> redefine(f, [f(a::algebraic, b::algebraic, c::algebraic) = a + b*c, f(a::algebraic, b::algebraic) = a/b]);
> f(0);
                                                         f(0)

> f(1, 2);
                                                          1/2

> f(3, 4, 5);
                                                          23

> f(6, 7, 8, 9);
                                                     f(6, 7, 8, 9)

> procbody(f):
s=****************, s[1]=**************** invalid MODDEF parameter sequence
Error, (in procbody) assembled object is invalid

Which implementation is the most efficient?

In my opinion, what you need is simply the symbol nargs. (Note that this syntax differs from another CAS's one.)

You say: "But I only want the names."
But the exports command (not the Describe command) does return a "exprseq" of names. For instance,

exports(PatternMatching);
 = 
         Define, Recogniser, AlgStruct, Tools, deftypes

Describe(PackageManagement);

# Package management utilities
module PackageManagement:

    # test whether a name is exported by a package
    pmember( nom::name, pkg )

    # return a list of the exports of a package
    pexports( pname )

Did I understand right?

The reason is: the output of convert(Eval(diff(varphi(t), t), t = 0), D) becomes unevaluated (and lowercase) eval(D(varphi)(t), t = 0). Actually, in some old release of Maple, the result is correct capitalized version. Besides, convert(``(Eval(diff(varphi(t), t), t = 0)), D) gives evaluated ``(D(varphi)(0)) instead. 

Why? In my opinion, this must be a bug.

 

For your specific purpose ("red if s is between 0 and ell/2, and green if s is between ell/2 and ell"), the easier way is:

plots:-spacecurve([cos(theta(s)), v(s), sin(theta(s))], s = 0 .. ell, colorscheme = ["Red", "Green"]);

Another way is:

data:=<seq(<cos(theta(s))|v(s)|sin(theta(s))|s>,s=0..ell,1e-3)>:
plots:-spacecurve(data[..,..3],colorscheme=["valuesplit",data[..,4],[0..ell/2="Red",ell/2..ell="Green"]]);

@vv Strangely, I find that if I use "y" (rather than "y(x)") in the "sol", then solve works well: 

y(x) = solve(subs(y(x) = y, sol), y);
 = 
                       /                                    2 
                       |/ /                              2\\  
                       || |      /    3       2         \ ||  
              1        || \RootOf\2 _Z  + 2 _Z  - _Z + 1/ /|  
 y(x) = -------------- \\x                                 /  
                   2                                          
        (exp(c[1]))  x                                        

                                              2 
   /   /                              2     \\  
   |   |      /    3       2         \      ||  
   \exp\RootOf\2 _Z  + 2 _Z  - _Z + 1/  c[1]//  

                                    3 
   /       /    3       2         \\  
   | RootOf\2 _Z  + 2 _Z  - _Z + 1/|  
   \x                              /  

                                             3
   /   /      /    3       2         \     \\ 
   \exp\RootOf\2 _Z  + 2 _Z  - _Z + 1/ c[1]// 

                                                    \
                                                    |
                                                    |
            /    3       2         \  2            2|
    + RootOf\2 _Z  + 2 _Z  - _Z + 1/ x  (exp(c[1])) /


Why? I don't know.

This problem is due to the limited ability of subs (see showstat(isolate, 17);). Actually, "2*I*A" (as well as "2*(I*A)") is parsed as "(2*I)*A", while the subs command just does syntactical exact-match replacements.
For example: 

> dismantle(I*A);

PROD(5)
   COMPLEX(2)
      INTPOS(2): 1
   INTPOS(2): 1
   NAME(4): A
   INTPOS(2): 1


> dismantle(2*(I*A));

PROD(5)
   COMPLEX(2)
      INTPOS(2): 2
   INTPOS(2): 1
   NAME(4): A
   INTPOS(2): 1


> dismantle(i*A);

PROD(5)
   NAME(4): i
   INTPOS(2): 1
   NAME(4): A
   INTPOS(2): 1


> dismantle((2*i)*A);

SUM(3)
   PROD(5)
      NAME(4): i
      INTPOS(2): 1
      NAME(4): A
      INTPOS(2): 1
   INTPOS(2): 2

They have different structures. So,  will never work directly (I mean, without any manual steps like  and ).

Use an explicit empty statement: 

to 1 do
    for i to 4 do for j to 4 do print([i, j]); if i = 2 and j = 3 then goto(al); end if; end do; end do;
    al;
    NULL;
end do;
 = 
                             [1, 1]

                             [1, 2]

                             [1, 3]

                             [1, 4]

                             [2, 1]

                             [2, 2]

                             [2, 3]

However, a better way is putting it to a procedure: 

# in 1-D Math
(proc() for _local(i) to 4 do for _local(j) to 4 do print([i, j]); if i = 2 and j = 3 then goto(al); fi; od; od; al; NULL; end)();
 = 
                             [1, 1]

                             [1, 2]

                             [1, 3]

                             [1, 4]

                             [2, 1]

                             [2, 2]

                             [2, 3]

 

A "terrible" way: 

restart;

ode := diff(phi(s), s, s)+K*cos(phi(s)) = 0

isolate(DETools:-firint(ode*DEtools:-intfactor(ode, phi(s)), phi(s)), c__1)

c__1 = -2*K*sin(phi(s))-(diff(phi(s), s))^2

(1)

unprotect(Eval)WARNING("Using `unprotect` can be dangerous!")

define(Eval, 'linear', conditional(Eval(a::anything, c::equation) = a, _type(a, freeof(_lhs(c)))), ('conditional')(Eval(a::anything^b::(nonunit(anything)), c::anything) = (Eval(a, c))^b, _type(b, freeof(_lhs(c)))), ('conditional')(Eval(a::anything*sin(b::anything), c::equation) = a*sin(Eval(b, c)), _type(a, freeof(_lhs(c)))))

Warning, Using `unprotect` can be dangerous!

 

subs(Eval(diff(phi(s), s), s = L) = `&phi;'`[0], map(Eval, c__1 = -2*K*sin(phi(s))-(diff(phi(s), s))^2, s = L))

c__1 = -2*K*sin(Eval(phi(s), s = L))-`&phi;'`[0]^2

(2)

unassign('Eval')


Download 236511-How-To-Integrate-This-Ode-And-How-To.mws

map2(applyrule, L__ads*L__fd/(L__fd + L__ads) = L__ads_p, eq_m1);
 = 
     (X__Tq E__B sin(delta) - R__T E__B cos(delta))//           
m1 =                                                \L__aqs L__l

                                         2              
   + L__aqs X__E + L__aqs L__ads_p + L__l  + 2 L__l X__E

                         2                     2       2
   + L__l L__ads_p + R__E  + 2 R__E R__a + R__a  + X__E 

                  \
   + X__E L__ads_p/


% - eq_m1_desired;
 = 
                             0 = 0

 

I don't why the try statement (in showstat(`convert/RootOf`, 80)) cannot catch some exception at first time.
However, if you add the following inelegant code: 

# restart;
`convert/RootOf` := FromInert(subsop([5, 8, 1, 1, 1, 1] = ToInert('membertype('identical(index) = real[integer]', map2(op, -1, indets(f1, 'specfunc(RootOf)'))) or f1::('RootOf'(anything)^anything)'), ToInert(eval(`convert/RootOf`)))):

your code will work. 

  #now use coulditbe, it should use hard value?

Well, the following instance may be what you want:

restart;showstat(`is/internal`, 161);

`is/internal` := proc(obj, prop)
local eqns, i, inds, oldinds, nobj, r, oprop, p, z, newind, lnames, lnenames;
       ...
 161   if r = FAIL and (nops(inds) <= 3 or _EnvTry = ('hard')) then
         ...
       end if;
       ...
end proc

foo1 := proc(f)::boolean_constant:
    undefine('_EnvTry');
    `assuming`([coulditbe(f)], real)
end:
foo2 := proc(f)::boolean_constant:
    _EnvTry := hard;
    `assuming`([coulditbe(f)], real)
end:

Now we can find that

foo1(And(x^2 + y^2 <= 11, x^3 - y^2 = 2, x*y > 3));
 = 
                              FAIL

foo2(And(x^2 + y^2 <= 11, x^3 - y^2 = 2, x*y > 3));
 = 
                              true

However, I don't know whether proc uses lexical scoping or dynamic scoping. (Maybe the former mechanism?)

Suppose that there exists some MapleSim model in the current dictionary.
For example, 

FileTools:-Compressed:-ReadFile("MapleSimVersion.manifest" in "CreateYourFirstModel.msim", string); # from Create Your First Model In MapleSim (maplesoft.com)
 = 
              "MapleSimMajorVersion = 2016


                MapleSimMinorVersion = 1


                ModelicaVersion = Modelica 3.2.1


                MapleSimVariant = MapleSim V4.1


                "


  Therefore, this model seems to be created in MapleSim 2016.1.

It appears that this seq version is more or less fater than yours (on my computer). 
 

restart; with(LinearAlgebra)

with(combinat); with(GroupTheory)

DetDef := proc (A) local i, n, sigma; description "Jeremy Johnson. Downloaded from https://www.cs.drexel.edu/~jjohnson/2016-17/winter/cs300/lectures/determinant.mw"; n := RowDimension(A); add(PermParity(Perm(sigma))*mul(A[i, sigma[i]], i = 1 .. n), `in`(sigma, permute([`$`(1 .. n)]))) end proc

InnerMatrix := proc (M::Matrix) SubMatrix(M, 2 .. RowDimension(M)-1, 2 .. ColumnDimension(M)-1) end proc

MatrixDet := proc (M::Matrix) local C, n, i, j; n := RowDimension(M)-1; Matrix(n, n, proc (i, j) options operator, arrow; Determinant(M([i, i+1], [j, j+1])) end proc) end proc

Dodgson := proc(M::Matrix)
 MatrixDet(M);
InnerMatrix(M) ^~ (-1) *~ MatrixDet(MatrixDet(M));
do if 1 < RowDimension(%) then InnerMatrix(`%%`) ^~ (-1) *~ MatrixDet(%);
end if;
until RowDimension(%) = 1;
Trace(%):
end proc:

Dodgsonseq := proc (E::Matrix) local w, dim, Z; dim := RowDimension(E); Z[dim] := E; Z[dim-1] := MatrixDet(E); Z[dim-2] := `~`[`*`](`~`[`^`](InnerMatrix(E), -1), MatrixDet(MatrixDet(E))); seq(assign('Z[w-1]', `~`[`*`](`~`[`^`](InnerMatrix(Z[w+1]), -1), MatrixDet(Z[w]))), w = dim-1 .. 1, -1); Trace(Z[1]) end proc

LaPlace := proc (M::Matrix) local c; add((-1)^(c+1)*M[1, c]*Minor(M, 1, c), c = 1 .. ColumnDimension(M)) end proc

dim := 7; A := Matrix(dim, dim, shape = symmetric, symbol = a)

                                  dim := 7

 

start_time := time(); st := time[real](); Det1 := abs(A); CPUtime_used_Build_in_Determinant := time()-start_time; REALtime_used_Build_in_Determinant := time[real]()-st; start_time := time(); st := time[real](); Det2 := DetDef(A); CPUtime_used_Jeremy_Johnson_Determinant := time()-start_time; REALtime_used_Jeremy_Johnson_Determinant := time[real]()-st; start_time := time(); st := time[real](); Det3 := Dodgsonseq(A); CPUtime_usedDodgsonseq := time()-start_time; REALCPUtime_usedDodgsonseq := time[real]()-st; start_time := time(); st := time[real](); Det4 := Dodgson(A); CPUtime_usedDodgson := time()-start_time; REALtime_usedDodgson := time[real]()-st; start_time := time(); st := time[real](); Det5 := LaPlace(A); CPUtime_usedLaPlace := time()-start_time; REALtime_usedLaPlace := time[real]()-st; simplify(Det1-Det2); simplify(Det1-Det3); simplify(Det1-Det4); simplify(Det1-Det5)
NULL

.109

 

.117

 

.297

 

.319

 

124.907

 

97.223

 

108.046

 

78.326

 

.125

 

.146

 

0

 

0

 

0

 

0

(1)

Dodgsonseq_new := proc (E::(`~Matrix`('square'))) local w, dim, Z; dim := LinearAlgebra['ColumnDimension'](E); if dim = 1 then RETURN(E(1)) else w, Z := MatrixDet(E), E; `$`('assign(('w', 'Z') = (`~`[`/`](MatrixDet(w), InnerMatrix(Z)), w))', dim-2); Trace(w) end if end proc

start_time := time(); st := time[real](); Det6 := Dodgsonseq_new(A); CPUtime_usedDodgsonseq_new := time()-start_time; REALtime_usedDodgsonseq_new := time[real]()-st; simplify(Det1-Det6)

101.172

 

79.417

 

0

(2)

 


 

Download test_Determinants_symbolic_Modified.mw

But I'm not sure if these hinge upon PC performance.

1 2 3 4 5 Page 3 of 5