acer

32557 Reputation

29 Badges

20 years, 24 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

Here is a revision of the worksheet that threw an error for the OP in Maple 2023.

The problem was that using op on the expression containing a piecewise is not robust. Having some extra multiplicative factors outside the piecewise can break the well-meaning op calls. The symbolic integration can differ in form slightly between versions (while still being correct).

You could combine the factors into the piecewise (see attached). Better still you could use the conditions of your conditional to reduce the piecewise to the corresponding values (see attached).

ps. If you want the proc to return unevaluated when the argument passed is not numeric then you should return quoted 'procname'(...) instead. Your return of procname(...) throws a recursion error if f_U gets called with a non-numeric argument. The reason you didn't get such is that you only used it within seq which has special-evaluation rules.

PDFDerivation_ac_M2023.mw

No, please don't spawn a separate Question thread to ask how to get this code to run in a newer version.

I'll try to adjust it, and get back to you here.

Could you use ImageTools:-Scale on it, so first get it to a suitable size? Does it contain text that would be trickier to scale?

Could you provide an example of such a .png file?

We don't know how you created it, but perhaps you could initially create it as larger size.

@C_R Ok, your last response was posted just before my last. I think it shows I finally understood where you were starting from.

And so you could just use the replacement,

   varphi__0 = `#msub(mi("varphi"),mn("0"));`

instead of,

   varphi__0 = varphi[0]

that you might have previously set up. Eg,

restart

The inputs are entered using `ϕ`[0] as subscripted, ie. varphi__0

`ϕ__0` := `#msub(mi("varphi"),mn("0"));`

`#msub(mi("varphi"),mn("0"));`

eq := -t(0)+t(`ϕ`(t)) = Int(1/sqrt(2*C*cos(`ϕ`)-2*C*cos(`ϕ__0`)), `ϕ` = 0 .. `ϕ`(t), continuous)

-t(0)+t(varphi(t)) = Int(1/(2*C*cos(varphi)-2*C*cos(`#msub(mi("varphi"),mn("0"));`))^(1/2), varphi = 0 .. varphi(t), continuous)

H := t(0) = 0, `ϕ`(t) = `ϕ__0`, t(`ϕ__0`) = (1/4)*T

t(0) = 0, varphi(t) = `#msub(mi("varphi"),mn("0"));`, t(`#msub(mi("varphi"),mn("0"));`) = (1/4)*T

new := subs(H, eq)

(1/4)*T = Int(1/(2*C*cos(varphi)-2*C*cos(`#msub(mi("varphi"),mn("0"));`))^(1/2), varphi = 0 .. `#msub(mi("varphi"),mn("0"));`, continuous)

cond := C > 0, 0 < `&varphi;__0` and `&varphi;__0` < Pi

0 < C, 0 < `#msub(mi("varphi"),mn("0"));` and `#msub(mi("varphi"),mn("0"));` < Pi

isolate(`assuming`([simplify(value(new))], [cond]), T)

T = 4*InverseJacobiAM((1/2)*`#msub(mi("varphi"),mn("0"));`, csc((1/2)*`#msub(mi("varphi"),mn("0"));`))*csc((1/2)*`#msub(mi("varphi"),mn("0"));`)/C^(1/2)

NULL

Download Evaluation_of_elliptic_integrals_ac4.mw

As for your query about why the indexed name is a problem: The variable of integration is itself varphi, and the situation muddled and sometimes ambiguous if an indexed instance of that name is also present. It's a logical collision. The value one of the names depends on any running value of the other. And the meaning can be quite unclear. One can find many previous postings here about why one should not mix the main variable and indexed instances of it in calls to solve, int, dsolve, etc, etc. IMO it's not just the parsing that may be unclear; the very meaning can sometimes be unclear. So, don't mix a base name and indexed instances of it.

The bit of double indexing that you find mysterious is because of the mix of the name of integration and indexed instance of it. The problem being sent in to int, with the mix, is not well-defined. Garbage in, garbage out. At some point int will have to replace instances of the variable of integration, and those substitutions can produce nonsense if the replacement occurs on the base part of an already indexed name.

It occurs to me that your scenario might be one in which you start off with the expressions having the double-underscore name varphi__0, and want to only see the rendered subscript with upright Roman.

So, a similar replacement can work, and you can construct the replacement directly or programmatically. And here indexed names are not involved.

And, again, if you have just the single name to handle then it'd be simpler to just use the directly constructed replacement,

     L := { varphi__0 = `#msub(mi("varphi"),mn("0"));` }

restart

Starting off with `&varphi;`[0] as subscripted, ie. varphi__0

K := proc (nm) local v, i, res; i := parse(convert(nm, string)[9 .. ()]); res := Typesetting:-msub(Typesetting:-mi("varphi"), subs(Typesetting:-mi = Typesetting:-mn, Typesetting:-Typeset(Typesetting:-EV(i)))); nprintf(`#%a;`, res) end proc; Rep := proc () options operator, arrow; subsindets([args], suffixed(varphi__, anything), K)[] end proc

K(`&varphi;__0`)

`#Typesetting:-msub(Typesetting:-mi("varphi"),Typesetting:-mn("0"));`

K(`&varphi;__a,b,c`)

`#Typesetting:-msub(Typesetting:-mi("varphi"),Typesetting:-mrow(Typesetting:-mn("a"),Typesetting:-mo("&comma;"),Typesetting:-mn("b"),Typesetting:-mo("&comma;"),Typesetting:-mn("c")));`

eq := -t(0)+t(`&varphi;`(t)) = Int(1/sqrt(2*C*cos(`&varphi;`)-2*C*cos(`&varphi;__0`)), `&varphi;` = 0 .. `&varphi;`(t), continuous); Rep(eq)

0, "%1 is not a command in the %2 package", _Hold, Typesetting

H := t(0) = 0, `&varphi;`(t) = `&varphi;__0`, t(`&varphi;__0`) = (1/4)*T; Rep(H)

t(0) = 0, varphi(t) = `#Typesetting:-msub(Typesetting:-mi("varphi"),Typesetting:-mn("0"));`, t(`#Typesetting:-msub(Typesetting:-mi("varphi"),Typesetting:-mn("0"));`) = (1/4)*T

new := Rep(subs(H, eq))

(1/4)*T = Int(1/(2*C*cos(varphi)-2*C*cos(`#Typesetting:-msub(Typesetting:-mi("varphi"),Typesetting:-mn("0"));`))^(1/2), varphi = 0 .. `#Typesetting:-msub(Typesetting:-mi("varphi"),Typesetting:-mn("0"));`, continuous)

cond := C > 0, 0 < `&varphi;__0` and `&varphi;__0` < Pi; Rep(cond)

0 < C, 0 < `#Typesetting:-msub(Typesetting:-mi("varphi"),Typesetting:-mn("0"));` and `#Typesetting:-msub(Typesetting:-mi("varphi"),Typesetting:-mn("0"));` < Pi

ans := isolate(`assuming`([simplify(value(new))], [Rep(cond)]), T)

T = 4*InverseJacobiAM((1/2)*`#Typesetting:-msub(Typesetting:-mi("varphi"),Typesetting:-mn("0"));`, csc((1/2)*`#Typesetting:-msub(Typesetting:-mi("varphi"),Typesetting:-mn("0"));`))*csc((1/2)*`#Typesetting:-msub(Typesetting:-mi("varphi"),Typesetting:-mn("0"));`)/C^(1/2)


I don't know whether you want the list of replacements.

With that, you can undo the effect.

You can create such a list to involve just the one indexed name, or any found.
Ie, you can make it as targeted as you want, in case there are other indexed
names that you're prfer lest alone.

S := indets([eq, H], suffixed(varphi__, anything))

{varphi__0}

L := map(proc (s) options operator, arrow; K(s) = s end proc, {`&varphi;__0`})

{`#Typesetting:-msub(Typesetting:-mi("varphi"),Typesetting:-mn("0"));` = varphi__0}

L := map(proc (s) options operator, arrow; K(s) = s end proc, S)

{`#Typesetting:-msub(Typesetting:-mi("varphi"),Typesetting:-mn("0"));` = varphi__0}

subs(L, ans)

T = 4*InverseJacobiAM((1/2)*varphi__0, csc((1/2)*varphi__0))*csc((1/2)*varphi__0)/C^(1/2)

NULL

Download Evaluation_of_elliptic_integrals_accc.mw

Here is another example of an indexed name, for which double-underscore doesn't look so great.

It's just a simpler kind of temporary replacement...

restart

Evaluation with `&varphi;`[0] indexed

eq := -t(0)+t(`&varphi;`(t)) = Int(1/sqrt(2*C*cos(`&varphi;`)-2*C*cos(`&varphi;`[X+abs(P)])), `&varphi;` = 0 .. `&varphi;`(t), continuous)

-t(0)+t(varphi(t)) = Int(1/(2*C*cos(varphi)-2*C*cos(varphi[X+abs(P)]))^(1/2), varphi = 0 .. varphi(t), continuous)

H := t(0) = 0, `&varphi;`(t) = `&varphi;`[X+abs(P)], t(`&varphi;`[X+abs(P)]) = (1/4)*T

t(0) = 0, varphi(t) = varphi[X+abs(P)], t(varphi[X+abs(P)]) = (1/4)*T

new := subs(H, eq)

(1/4)*T = Int(1/(2*C*cos(varphi)-2*C*cos(varphi[X+abs(P)]))^(1/2), varphi = 0 .. varphi[X+abs(P)], continuous)

cond := C > 0, 0 < `&varphi;`[X+abs(P)] and `&varphi;`[X+abs(P)] < Pi

0 < C, 0 < varphi[X+abs(P)] and varphi[X+abs(P)] < Pi

Rep := proc () options operator, arrow; subsindets([args], specindex(anything, varphi), proc (nm) options operator, arrow; freeze(__K(nm)) end proc)[] end proc

new2 := Rep(new)

subsindets(isolate(`assuming`([simplify(value(new2))], [Rep(cond)]), T), specfunc(__K), op)

T = 4*InverseJacobiAM((1/2)*varphi[X+abs(P)], csc((1/2)*varphi[X+abs(P)]))*csc((1/2)*varphi[X+abs(P)])/C^(1/2)

Without the replacement...

isolate(`assuming`([simplify(value(new))], [cond]), T)

T = 4*2^(1/2)*(-(limit(((-cos(varphi)+cos(varphi[X+abs(P)]))/(-1+cos(varphi[X+abs(P)])))^(1/2)*InverseJacobiAM((1/2)*varphi, csgn(sin((1/2)*varphi[X+abs(P)]))*csc((1/2)*varphi[X+abs(P)]))/(cos(varphi)-cos(varphi[X+abs(P)]))^(1/2), varphi = 0, right))*(cos(varphi[X+abs(P)])-cos(varphi[X+abs(P)][X+abs(P)]))^(1/2)+((-cos(varphi[X+abs(P)])+cos(varphi[X+abs(P)][X+abs(P)]))/(-1+cos(varphi[X+abs(P)][X+abs(P)])))^(1/2)*InverseJacobiAM((1/2)*varphi[X+abs(P)], csgn(sin((1/2)*varphi[X+abs(P)][X+abs(P)]))*csc((1/2)*varphi[X+abs(P)][X+abs(P)])))/(C^(1/2)*(cos(varphi[X+abs(P)])-cos(varphi[X+abs(P)][X+abs(P)]))^(1/2))

NULL

Download Evaluation_of_elliptic_integrals_acc.mw

@lemelinm You could also get that new list of equations, T, with,

    T:=(u->u=GetValue(Constant(u))*GetUnit(Constant(u)))~(L)

@Motocycle Mayor Perhaps when you saw the problematic behavior you had inadvertantly done a restart, or tried after only re-opening the Document.

@TechnicalSupport Fwiw the OP's original attachment shows that it was last saved in Maple 2025.1, so presumably that's the version he was using.

I changed your Post into a Question.

Please submit your future queries as Questions.

@Motocycle Mayor Thank you.

Your Document runs ok and as expected in my Maple 2024.2.

Ribbiting_Disparities_29_ac_2024.2.mw

I'll have to get back to you about Maple 2025.1, unless someone else clarifies sooner.

ps. The line,
   with DataFrames
doesn't do anything or load anything. It's just a product of two names. It shouldn't hurt, though.

@Geoff For that alternate input,

restart

n, k := 4, 2

4, 2

sys := {Tree = Union(Z, Prod(`$`(Tree, k)))}

all := combstruct:-allstructs([Tree, sys], size = n)

lists := eval(all, Prod = (proc () options operator, arrow; [args] end proc))

Groupings := proc(LI::{list,posint}, k::posint)
local L, Tree, Leaf, sys, n, lists, LTS;
if k = 1 then error "k must be greater than 1" end if;
if LI::posint then L:=$LI; n:=LI;
else L:=LI; n:=nops(L); end if;
LTS := proc(LL)
   local count := 0, F := proc() count:=count+1; L[count]; end proc;
   eval(subs(Leaf='F'(),LL));
end proc:
sys := {Tree = 'Union'(Leaf, 'Prod'(Tree $ k)), Leaf = 'Atom'};
lists := eval(combstruct['allstructs']([Tree, sys], 'size' = n), 'Prod' = (()->[args]));
map(LTS, lists);
end proc:

 

Groupings([a, b, c, d], 2);

[[a, [b, [c, d]]], [a, [[b, c], d]], [[a, b], [c, d]], [[a, [b, c]], d], [[[a, b], c], d]]

Groupings([1, 2, 3, 4], 2)

[[1, [2, [3, 4]]], [1, [[2, 3], 4]], [[1, 2], [3, 4]], [[1, [2, 3]], 4], [[[1, 2], 3], 4]]

Groupings(4, 2)

[[1, [2, [3, 4]]], [1, [[2, 3], 4]], [[1, 2], [3, 4]], [[1, [2, 3]], 4], [[[1, 2], 3], 4]]

Download Groupings_ac4.mw

@Geoff Change the type specification of the L parameter (in the definition of procedure Groupings) to L::list instead, so it'll look like,

   Groupings := proc(L::list, k::posint)
      ...
   end proc:

@Motocycle Mayor A reasonable first step would be to attach an Excel data file that could be used with your Import command and which creates a representative example that reproduces the problem.

Uploading and attaching an Excel file and .mw Maple worksheet that can be used together to reproduce the problem is often a very good first step here.

In the absence of an actual worksheet it is more difficult for me to determine the cause, eg. whether Data is actually a DataFrame, etc.

Mentioning your Maple version (or marking it in the field at the top of your Question) might also be useful. Are you still using Maple 2019?

Could you please attach an Excel data file and the Import command which creates a representative example that illustrates the problem? You can use the green up-arrow in the Reply editor, to upload and insert links to files.

Are you sure that the entries of the column are all strings already? Have you tried,

   SubsDatatype(Data, "UN Region", string, conversion=String );

1 2 3 4 5 6 7 Last Page 2 of 595