## 1002 Reputation

1 years, 231 days

## MaplePrimes Activity

### These are answers submitted by sursumCorda

```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])):

```

## set up transformation rules for patterns...

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?

## number of members...

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

## Locate functions...

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?

## Bug of `convert/D`?...

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.

## One way...

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"]]);

```

## Bug of PDEtools:-Solve...

@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.

## Physics:-Substitute...

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 ).

## depth...

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:   ...

A "terrible" way:

 > restart;
 >
 >
 (1)
 >
 >
 >
 (2)
 >

## applyrl...

```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

\

% - eq_m1_desired;
=
0 = 0

```

## Bug of `try`?...

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`)))):```

## scope of variables...

#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?)

## in one step...

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)
=

ModelicaVersion = Modelica 3.2.1

"

```

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

## Composition...

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

 >
 >
 >
 >
 >
 > 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:
 >
 >
 >
 dim := 7
 >
 (1)
 >
 >
 (2)
 >