Carl Love

## 26862 Reputation

11 years, 304 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

## Environment variables; kernelopts(level)...

printlevel is an "environment variable". That means that if its value is changed within a procedure, then it is automatically reset to its previous value when the procedure exits. Thus, you don't need to store the previous value or reset printlevel yourself.

What you're calling the "depth" can be measured by kernelopts(level).

## Limitations of assuming...

I ignore your weird use of RETURN. Without it, the second integral gives true*x, whereas I'd expect false*x. There are reasonable limitations on the "depth" within an expression to which assuming can penetrate. Compare:

(coulditbe(y=1) assuming y>=0, y<=x) assuming additionally, x>0, x<1;

true

coulditbe(y=1) assuming y>=0, y<=x, x>0, x<1;

false

The first case seems more akin to your integral.

## ListTools:-Classify...

Your graph_list can be partitioned into a table of equivalence classes under isomorphism by

ListTools:-Classify(g-> [seq](op(4, GraphTheory:-CanonicalGraph(g))), graph_list)

## unapply...

Define the function with unapply:

f:= unapply(a*x, x)

A synonym for unapply is MakeFunction.

## Extra spaces in 2d input...

I assume that you're using 2D Input which you've converted to 1D for posting here. If so, then you need to remove any space characters you have after displaytextplot, and draw. Also, the arguments to display need to be in parentheses. If I change your display command to

```display(
textplot(
[
[coordinates(S)[], "S"], [coordinates(P)[], "P"], [coordinates(H)[], "H"],
[coordinates(K)[], "K"], [coordinates(M)[], "M"]
], font = [times, bold, 16], align = [above, right]
),
draw([
delta(color = blue), deltap(color = blue), D(color = red), c1(color = black),
S(color = black, symbol = solidcircle, symbolsize = 16),
P(color = black, symbol = solidcircle, symbolsize = 16)
]),
scaling = constrained, axes = none, view = [-15 .. 15, -15 .. 15]
);```

then I get this plot (for which you'll likely want to change some of the sizes):

## Simplify doesn't work on equations...

The simplify command doesn't work on equations (except in the sense that it's mapped to the left and right sides independently). In common mathematical usage, as taught in secondary-school algebra, "simplification" is only performed on expressions, not equations.

## Using standard plot3d...

The Python code shown in your forum link handles the minutiae of setting up grids/meshes for 3D plots and converting spherical and cylindrical coordinates to rectangular. This is unnecessary in Maple; the plot3d command handles that in the background.

```(* Original Python code:

from matplotlib import pyplot as plt
from math import sqrt, pi, cos, sin
import numpy as np

fig = plt.figure()

t_grid = np.linspace(-1 - sqrt(7), -1 + sqrt(7), 50)
s_grid = np.linspace(-1, 1, 50)
T, S = np.meshgrid(t_grid, s_grid)
theta_fun = lambda t, s: 0.2 * pi * (t + 1 + sqrt(7)) / sqrt(7) - 0.4 * pi + 0.1
phi_fun = lambda t, s: pi * s / (4 * sqrt(2)) * sqrt(max(2 - t ** 2 / abs(t - 3), 0))
for k in range(1, 16):
phi0 = 0.4 * pi * k
r = 14 - 0.8 * k
x_fun = lambda t, s: r * cos(phi0 + phi_fun(t, s)) * cos(theta_fun(t, s))
y_fun = lambda t, s: r * sin(phi0 + phi_fun(t, s)) * cos(theta_fun(t, s))
z_fun = lambda t, s: r * sin(theta_fun(t, s))
X = np.array(list(map(x_fun, T.flatten(), S.flatten()))).reshape((50, 50))
Y = np.array(list(map(y_fun, T.flatten(), S.flatten()))).reshape((50, 50))
Z = np.array(list(map(z_fun, T.flatten(), S.flatten()))).reshape((50, 50))
ax.plot_surface(X, Y, Z, cmap='Reds')
z = np.linspace(-25, -10, 50)
p = np.linspace(0, 2 * pi, 50)
Z, P = np.meshgrid(z, p)
X = np.cos(P)
Y = np.sin(P)
ax.plot_surface(X, Y, Z, cmap='Greens')
ax.set_box_aspect(aspect=(1, 1, 1.5))
*)```

The original author plotted the petals using a nonstandard form of spherical coordinates that has the cos(theta) and sin(theta) exchanged, where theta is the altitude angle. I adjusted this to standard spherical coordinates by replacing theta with Pi/2 - theta. The original stem was done using standard cylindrical coordinates.

I don't know the exact details of the Python coloring function cmap. I made an approximation using plot option colorscheme and the ColorTools package.

For the lightmodel, I simply chose what looked best to me from the very limited choices (five) Maple offers. I chose an orientation that looked good to me.

My algebraic formulas are mathematically equivalent to the Python; however, I simplified them, so they're not syntactically identical. If Python has some difference between math.sin and numpy.sin (likewise for cos), I don't know what it is. The original author used both (perhaps unintentionally).

Surprisingly, Maple has no plot option equivalent to aspect, so I used plottools:-scale, which will do essentially the same thing provided that the options axes= none and scaling= constrained are used and that one doesn't care about the actual numerical values stored in the plot.

```#Maple translation:
cmap:= C-> colorscheme= ([ColorTools:-Lighten, ColorTools:-Darken] @@~ 2)(C):
aspect:= (S::And(list(realcons), 3 &under nops))-> (P::specfunc(PLOT3D))->
plots:-display(plottools:-scale(P, S[]), 'axes'= 'none', 'scaling'= 'constrained')
:
k:= [\$1..16]:
(aspect([1, 1, 3/2]) @ plots:-display)(
plot3d(
`[]`~(
14 -~ 4/5*~k,
Pi*~(2/5*~k +~ s*sqrt(max(2 - t^2/abs(t-3), 0)/32)),
(Pi*(7 - 2/sqrt(7)*(t+1)) - 1)/10
),
t= -1-sqrt(7)..-1+sqrt(7), s= -1..1, coords= spherical, cmap("Red")
),
plot3d(1, theta= 0..2*Pi, z= -25..-10, coords= cylindrical, cmap("Green")),
style= surface, lightmodel= light4, orientation= [49, 52, 27]
);
```

## It's hopeless...

Your system is far more than "a little" complicated. I think that there's no hope of solving this (with Maple or anything else). Maple will likely continue working on it until it runs out of memory, and then crash.

Yes, it's reasonable for it to run for days, weeks, etc., on such a system.

No, there's no way that multi-core processing can help with this.

I believe that both of those answers would be true for any mathematical software.

For what its worth, you can easily (nearly instatntaneously) eliminate 4 of the variables. The complexity of the remaining two equations might help you appreciate why this is unsolvable.

(Sols, Eqs):= eliminate({eq||(1..6)}, {u,v,w,x, y})[]:
print~(Sols): print~(Eqs=~0):

## hastype(..., typefunc(name, Not(mathfunc...

I believe that this simple procedure handles all the cases presented so far, requiring no input other than the equation itself. It also accepts and gracefully handles expressions

• implicitly equated to 0,
• with only 1 term,
• with multiple unknown dependent functions (such as would appear in any system of DEs),
• with no unknown dependent functions, or
• with no diff (such as may appear in a system of DAEs).
```LeftRight:= proc(Q::{`=`(algebraic), algebraic})
local
_0,
(L,R):= selectremove(hastype, _0 + `if`(Q::`=`, (lhs-rhs)(Q), Q), 'typefunc'(name, Not(mathfunc)))
;
eval(`if`(L=0, R=0, L = -R), _0= 0)
end proc
:
test_cases := <
diff(u(x,t),t,t) + 3 + 2*diff(u(x,t),t) + 4*t + x^2 + x^3/3
+ diff(u(x,t),t,x,x) + diff(u(x,t),x,x,x,x) = x*t^2,
y(x) + diff(y(x),x) + cos(x) + g(y(x)) + diff(f(x),x) + 1/x = sin(x),
diff(f(x),x) + 1/x = sin(x),
y(x) + x,
x*diff(y(x),x) + x = y(x) + diff(y(x),x\$2),
x^2 + 1/y(x) + diff(y(x),x) + sin(x) = y(x)^2,
1 + x,
diff(y(x),x)= 0,
diff(y(x),x\$2) = y(x) - x,
sin(x)+y(x)=0
>:
<test_cases | <seq(`&nbsp;`, numelems(test_cases))> | LeftRight~(test_cases)>;
```

## In any base, without NumberTheory...

Here is a set of procedures that do what your procedure was expected to do, and do it in any base, not just base-10. For pedagogical reasons, I have not used any package commands. All commands that I use (except ifactors) are simple integer arithmetic. I did this for pedagogical reasons; I don't have anything against  the NumberTheory package. Many of my procedures duplicate functionality from NumberTheory. And their code is so arithmetically simple that I think you'll be able to learn from them. All of these procedures run in time equal to or slightly less than their NumberTheory counterparts.

Also, it seems that RepeatDecimal subpackage of NumberTheory is limited to base-10.

 > restart:
 > interface(prompt= "") :

(*
P_log(N,p) returns (e, N/p^e) where e is the largest exponent such that p^e divides N.
*)
P_log:= proc(N::posint, p::And(posint, Not(1))) local e:= 0, n, q:= N;
while irem((n:= q), p, 'q') = 0 do e++ od;
(e,n)
end proc
:
(*
Totient(m) returns the number of elements in the multiplicative group mod m.
This is also called "Euler's totient" or "Euler's phi".
*)
Totient:= (m::posint)-> local p; mul(p[1]^(p[2]-1)*(p[1]-1), p= ifactors(m)[2])
:
(*
Base(N,R) returns a list of minimal length d of the base-R (or radix-R) digits of N in order from
most-significant to least-significant digit.
*)
Base:= (N::nonnegint, R::And(posint, Not(1)), d::posint)->
local n:= N, D:= R^max(d, 1 + ilog[R](n)); [do iquo(n, (D/= R), 'n') until D=1]
:
(*
P_factors(n) returns a list of the distinct prime factors of n.
*)
P_factors:= (n::integer)-> index~(ifactors(n)[2], 1)
:
(*
M_Order(X,m) returns the smallest T>0 such that X^T mod m = 1, a.k.a., the multiplicative
order of X (mod m).
For convenience, I allow modulus m=1 and return 0 in any such case.
*)
M_Order:= proc(X::posint, m::And(posint, satisfies(m-> igcd(m,X)=1)))
local p, T:= Totient(m), q, x:= irem(X,m);
for p in P_factors(T) do while irem(T,p,'q') = 0 and x&^q mod m = 1 do T:= q od od;
`if`(m=1, 0, T)
end proc
:
(*
periode(r,R) returns [q, nops(dL), dL] where
representation of rational number r,
and
dL is the list of repeating digits in radix-R representation.

"Radix" is a more-formal word for "base", as in "base-10 arithmetic".
The radix R defaults to 10.
*)
periode:= proc(r::{integer,fraction}, R::And(posint, Not(1)):= 10)
local b:= denom(r), f, i, p, q:= 0, M;
for f in P_factors(R) do (i,b):= P_log(b,f); q:= max(q,i) od;
[q, (p:= M_Order(R,b)), Base(abs(numer(frac(r*R^q)))*(R^p-1)/b, R, p)]
end proc
:

#Test cases:
periode(2/3);

periode(2/35);

periode(3/140);

periode(3/5, 2);

periode(1/13);

#Preben's example:
CodeTools:-Usage(periode(1007/200035));

memory used=2.29MiB, alloc change=0 bytes, cpu time=0ns, real time=4.00ms, gc time=0ns

## Use `is` for mathematical equality...

Your problem comes from using the default equality operator = to check the mathematical equality of algebraic expressions, but = only checks whether the expressions are syntactically identical in their unsimplified form. That's a much stronger form of equality than mathematical equality. Use the command is to check mathematical equality. Your code should include something to do if is returns FAIL, which means that it couldn't determine mathematical equality. Here's a revision of your procedure:

 > restart:
 > CauchyRiemann:= proc(expr::algebraic, z::name:= ':-z') local     x, y,     (u,v):= op(evalc([Re,Im](eval(expr, z= x+I*y)))),     (u_x, u_y, v_x, v_y):= op(diff~([u,u,v,v], [x,y,x,y])),     (flag1, flag2):= op(is~([u_x, u_y] =~ [v_y, -v_x]) assuming additionally, (x,y)::~real) ;       print~([         'f(z)'=expr, ``,         'u(x,y)'=u, 'u[x](x,y)'=u_x, 'u[y](x,y)'=u_y, ``,         'v(x,y)'=v, 'v[x](x,y)'=v_x, 'v[y](x,y)'=v_y, ``,              if flag1 then 'u[x]=v[y]', u_x=v_y         elif not flag1 then 'u[x]<>v[y]', u_x<>v_y         else `Couldn't determine whether ` || ('u[x]=v[y]')         fi,         if flag2 then 'u[y] = -v[x]', u_y = -v_x         elif not flag2 then 'u[y] <> -v[x]', u_y <> -v_x         else `Couldn't determine whether ` || ('u[y] = -v[x]')         fi,         ``,         if flag1 and flag2 then            `Fullfill the Cauchy-Riemann Equations`,            `The derivative is:`='u[x]+I*v[y]', 'diff(f(z),z)'=u_x+I*v_y         else            `Cauchy-Riemann ?`         fi,         ``     ]);     flag1 and flag2 end proc:          f(z):=1/(z+2): CauchyRiemann(f(z));

 >

## Explicit multiplication...

Use explicit multiplication symbols:

PDE :=
diff(G(a, H, phi, PI), a)*(aH) + diff(G(a, H, phi, PI), H)*(k/a^2 - kappa^2/2*PI^2/a^6)
+ diff(G(a, H, phi, PI), phi)*(PI/a^3)
= diff(G(a, H, phi, PI), PI)*(a^3*diff(V(phi), phi))
;

pdsolve(PDE, G);

## As a simple convex planar quadrilateral...

[This Answer is similar to @Kitonum's, but I wrote it independently before seeing his. I first solve for the four angles given the constrsaints, then I construct the points and plot.]

The Answer by @C_R shows a self-intersecting quadrilateral. However, it's possible to satisfy all the constraints with a simple convex planar quadrilateral:

```restart
:
#Divide all distances by 10. Express each in both directions:
(ab, bc, cd, da):= ((ba, cb, dc, ad):= (17, 17, 29, 18))
:
#one side of Law of Cosines:
LoC:= (a::symbol, b::symbol, c::symbol)->
eval(cat(a,b)^2 + cat(b,c)^2 - 2*cat(a,b)*cat(b,c)*cos(b)):

angs:= fsolve(
{
#law of cosines viewing diagonal ac as a side of triangles abc and adc:
LoC(a,b,c) = LoC(a,d,c),
#law of cosines viewing diagonal bd as a side of triangles bcd and abd:
LoC(b,c,d) = LoC(b,a,d),
#law of cosines for equality of diagonals:
LoC(a,b,c) = LoC(d,c,b),
#sum of interior angles:
a+b+c+d = 2*Pi
},
{(a,b,c,d)=~ 0..Pi}
);
angs := {a = 1.879417129, b = 1.962935269, c = 1.228331866, d = 1.212501044}

#Construct it: Arbitrarily put A at origin and B directly to the right of A:
A:= [0,0]:  B:= A +~ [ab,0]:
C:= B +~ bc*~(cos,sin)(eval(Pi-b, angs));
`&D;`:= A +~ da*~(cos,sin)(eval(a, angs));
C := [23.49681980, 15.70959364]
D := [-5.467408027, 17.14956120]
plots:-display(
plot([[A,B,C,`&D;`,A], [A,C], [B,`&D;`]], thickness= 3, color= [red, blue\$2]),
plots:-textplot(
[
[A[], "A", align= {below, left}],
[B[], "B", align= {below, right}],
[C[], "C", align= {above, right}],
[`&D;`[], "D", align= {above, left}]
], font= [HELVETICA, BOLD, 16]
),
axes= none, scaling= constrained
);
```

```#Verify constraints:
dist(A,B);
17
dist(B,C);
16.99999999
dist(C,`&D;`);
29.00000001
dist(A,`&D;`);
18.00000000
dist(A,C);
28.26467536
dist(B,`&D;`);
28.26467536
```

## numer, lhs, rhs...

This can be applied to any equation, and is often very useful. In this case, it returns exactly what you want.

numer((lhs-rhs)(eq)) = 0

It just seems like luck or happenstance to me that using x as the 2nd argument and 1 as the 3rd did what you wanted.

## Field of square roots...

This works:

factor(%, indets(%, sqrt));

The answer is awkward IMO, because a denominator is introduced, but it is correct.

 1 2 3 4 5 6 7 Last Page 3 of 386
﻿