Carl Love

Carl Love

28020 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

For each integral that you want, define a function name for that integral (typically it's a function of the upper limit of integration), add an ODE to the system that specifies the derivative of that function (trivial to do by the fundamental theorem of calculus), and add an initial condition that says that the integral at the initial value is 0. Example:

sys:= {
    diff(y(x), x) = y(x)^2, diff(y_int(x), x) = y(x),
    y(0)=1, y_int(0)=0
}:
dsol:= dsolve(sys, numeric):
dsol(0.5);
[x = 0.5, y(x) = 2.00000005567745, y_int(x) = 0.693147093956047]

So, the above says that int(y(x), x= 0..0.5) = 0.693147....

 

@emendes You should investigate the possibility that simplify(..., symbolic), without assumptions, correctly performs the simplifications that you want. It does in this case. Using it is like asking simplify to make whatever reasonable assumptions it needs to make in order to perform the simplification. Typical things that it may assume are that radicands are positive or that variables in radicands are positive. However, it may assume too much: Occasionally its assumptions viewed in totality are contradictory. See the paragraph on symbolic at ?simplify,details. 

Echoing acer's advice: When comparing complicated algebraic expressions for equality, attempt to simplify their difference to 0 rather than compare their separate simplifications. Positive results are pretty much guaranteed correct (modulo the possibility of some severe bug), but negative results don't mean much. It may be possible to confirm negative results by numeric substitution for the variables, but check that the numeric substitutions satisfy the appropriate assumptions.

If the symbolic option is too risky for you, you can use the real assumption (without needing to specify variables). This may directly cause simplification to 0 (it doesn't in this case), or it may provide information that you can easily translate into further assumptions (it very much does in this case). Example: In this case, do

simplify(numer~(eval([y,z], aa[1]) - eval([y,z], bb[2]))) assuming real;

You'll see in the output that the first list entry (the numerator of y) has a factor of signum(alpha[1,8]) - 1 (lookup ?signum) and that the numerator of z has a factor of abs(alpha[1,8]) - alpha[1,8]. Both of these factors would be 0 under the assumption alpha[1,8] > 0. This may be how acer discovered this assumption.

Maybe the efficiency of this can be improved (advice, anyone? @Joe Riel ?), but it's certainly not horrible. [Edit: Actually, it's pretty good. See time tests in 1st Reply.]


TreeToPrufer:= proc(T::satisfies(GraphTheory:-IsTree))
option `Author: Carl Love <carl.j.love@gmail.com> 2020-Nov-7`;
uses GT= GraphTheory;
local
    v, V:= GT:-Vertices(T), Ns:= table(V=~ ({op}@GT:-Neighbors)~(T,V)),
    H:= heap[new](
        (u,v)-> (local d:= nops(u[2]) - nops(v[2])) > 0 or d=0 and {u[1], v[1]}[1] = v[1],
        [op]~([indices](Ns, ':-pairs'))[]
    )
;
    [
        to nops(V)-2 do
            heap[insert]([(v:= heap[extract](H))[2][], (Ns[v[2][]] minus= {v[1]})], H);
            v[2][]
        od
    ]
end proc
#This procedure is intended for 1D input only.
:
GT:= GraphTheory:
T:= GT:-RandomGraphs:-RandomTree(9):
TreeToPrufer(T);
                     [4, 3, 4, 8, 8, 9, 4]

GT:-DrawGraph(T);

Meanwhile, I'll work on the inverse procedure.

Here is efficient, interruptable code for this sequence. You can interrupt the code, check the sequence, and continue where you left off. You can even do this after a restart or in another session. The only way to stop this code is the interrupt button. Since it uses very little memory and places little burden on the GUI, this isn't a problem.

As it runs, it prints a line of 6 numbers for each sequence entry:

  1. the index k
  2. the kth prime in the sequence
  3. the position of this prime in the canonical sequence of primes (i.e., pi(p))
  4. the number of digits in the prime which is the concatenation of the sequence so far
  5. the accumulated run time of the current run in seconds
  6. the run time required for the current entry
restart
:
OEIS:= module()
option `Author: Carl Love <carl.j.love@gmail.com> 2020-Nov-7`;
export
    Seq:= Array(1..0),

    ModuleApply:= proc()
    local k, P, p, X, Cat:= (n,m)-> Scale10(n, length(m))+m, ST:= time(), st:= ST;
        P:= foldl(Cat, 0, seq(Seq));
        for k from numelems(Seq)+1 do
            p:= 2;
            do 
                while assigned(Used[p]) do p:= nextprime(p) od;
                X:= Cat(P,p);
                if isprime(X) then
                    P:= X;
                    Seq(k):= p;
                    Used[p]:= ();
                    userinfo(
                        1, OEIS, NoName,
                        printf(
                            "%d\t%d\t%d\t%d\t%5.1f\t%4.1f\n",
                             k, p, numtheory:-pi(p), length(P), time()-ST, time()-st,
                             proc() st:= time(); return end proc()
                        )
                    );
                    break
                else
                    p:= nextprime(p)
                fi
            od
        od
    end proc,

    FirstUnseenPrimes:= proc(n:= 9)
    local p:= 2, k, R:= Array(1..0);
        for k to n do
            while assigned(Used[p]) do p:= nextprime(p) od;
            R(k):= p;
            p:= nextprime(p)
        od;
        seq(R)
    end proc
;
local Used:= table()
;
end module
:
infolevel[OEIS]:= 1:
OEIS();
1	2	1	1	  0.0	 0.0
2	3	2	2	  0.1	 0.1
3	11	5	4	  0.1	 0.0
4	7	4	5	  0.1	 0.0
5	41	13	7	  0.1	 0.0
6	31	11	9	  0.1	 0.0
7	17	7	11	  0.1	 0.0
8	163	38	14	  0.1	 0.0
9	23	9	16	  0.1	 0.0
10	79	22	18	  0.1	 0.0
11	197	45	21	  0.1	 0.0
12	241	53	24	  0.1	 0.0
13	29	10	26	  0.1	 0.0
14	37	12	28	  0.1	 0.0
15	59	17	30	  0.1	 0.0
16	193	44	33	  0.1	 0.0
17	227	49	36	  0.1	 0.0
18	229	50	39	  0.1	 0.0
19	239	52	42	  0.1	 0.0
20	439	85	45	  0.1	 0.0
21	929	158	48	  0.1	 0.0
22	337	68	51	  0.1	 0.0
23	257	55	54	  0.1	 0.0
24	1447	229	58	  0.1	 0.0
25	509	97	61	  0.1	 0.0
26	19	8	63	  0.1	 0.0
27	293	62	66	  0.1	 0.0
28	1723	269	70	  0.1	 0.0
29	1619	256	74	  0.1	 0.0
30	937	159	77	  0.1	 0.0
31	179	41	80	  0.1	 0.0
32	367	73	83	  0.2	 0.0
33	251	54	86	  0.2	 0.0
34	1063	179	90	  0.2	 0.0
35	4241	581	94	  0.2	 0.0
36	1291	210	98	  0.2	 0.0
37	521	98	101	  0.2	 0.0
38	1951	297	105	  0.2	 0.0
39	443	86	108	  0.2	 0.0
40	139	34	111	  0.2	 0.0
41	191	43	114	  0.2	 0.0
42	1753	273	118	  0.2	 0.0
43	1217	199	122	  0.2	 0.0
44	673	122	125	  0.2	 0.0
45	53	16	127	  0.2	 0.0
46	883	153	130	  0.2	 0.0
47	809	140	133	  0.2	 0.0
48	109	29	136	  0.3	 0.0
49	5381	709	140	  0.3	 0.0
50	3733	521	144	  0.3	 0.0
51	311	64	147	  0.3	 0.0
52	967	163	150	  0.3	 0.0
53	449	87	153	  0.3	 0.0
54	2683	389	157	  0.3	 0.0
55	9239	1145	161	  0.4	 0.0
56	577	106	164	  0.4	 0.0
57	971	164	167	  0.4	 0.0
58	1453	231	171	  0.4	 0.0
59	101	26	174	  0.4	 0.0
60	1051	177	178	  0.4	 0.0
61	107	28	181	  0.4	 0.0
62	3301	464	185	  0.4	 0.0
63	233	51	188	  0.4	 0.0
64	1627	258	192	  0.5	 0.0
65	2729	398	196	  0.5	 0.0
66	2689	391	200	  0.5	 0.0
67	5669	747	204	  0.5	 0.0
68	1597	251	208	  0.5	 0.0
69	2153	325	212	  0.5	 0.0
70	1117	187	216	  0.6	 0.0
71	5099	681	220	  0.6	 0.0
72	10429	1276	225	  0.7	 0.1
73	5303	703	229	  0.7	 0.0
74	6991	899	233	  0.8	 0.0
75	4253	583	237	  0.8	 0.0
76	1777	275	241	  0.8	 0.0
77	281	60	244	  0.8	 0.0
78	349	70	247	  0.8	 0.0
79	5273	699	251	  0.9	 0.0
80	1543	243	255	  0.9	 0.0
81	1997	302	259	  0.9	 0.0
82	1867	285	263	  0.9	 0.0
83	1109	186	267	  0.9	 0.0
84	769	136	270	  0.9	 0.0
85	167	39	273	  1.0	 0.0
86	4261	585	277	  1.0	 0.0
87	3821	530	281	  1.0	 0.0
88	14923	1747	286	  1.2	 0.1
89	173	40	289	  1.2	 0.0
90	1531	242	293	  1.2	 0.0
91	71	20	295	  1.2	 0.0
92	13267	1577	300	  1.3	 0.1
93	14699	1720	305	  1.5	 0.1
94	3877	537	309	  1.5	 0.0
95	137	33	312	  1.5	 0.0
96	2389	355	316	  1.6	 0.0
97	3803	529	320	  1.6	 0.1
98	2671	387	324	  1.7	 0.0
99	5879	774	328	  1.8	 0.1
100	1039	175	332	  1.8	 0.0
101	1439	228	336	  1.8	 0.0
102	421	82	339	  1.8	 0.0
103	3929	545	343	  1.9	 0.1
104	22921	2558	348	  2.2	 0.3
105	1367	219	352	  2.2	 0.0
106	6823	877	356	  2.4	 0.2
107	12239	1462	361	  2.5	 0.2
108	3709	518	365	  2.6	 0.0
109	1019	171	369	  2.6	 0.0
110	829	145	372	  2.6	 0.0
111	3467	486	376	  2.7	 0.1
112	2767	403	380	  2.7	 0.0
113	6947	891	384	  2.9	 0.1
114	757	134	387	  2.9	 0.0
115	3593	503	391	  3.1	 0.2
116	3163	447	395	  3.1	 0.1
117	1787	277	399	  3.2	 0.0
118	1303	213	403	  3.2	 0.0
119	9413	1164	407	  3.4	 0.2
120	21283	2391	412	  3.8	 0.4
121	4547	616	416	  3.8	 0.1
122	5653	744	420	  4.0	 0.2
123	6761	870	424	  4.2	 0.2
124	1483	235	428	  4.2	 0.0
125	8693	1083	432	  4.4	 0.2
126	823	143	435	  4.4	 0.0
127	30971	3338	440	  5.1	 0.7
128	7699	977	444	  5.3	 0.2
129	4289	589	448	  5.4	 0.1
130	6301	820	452	  5.6	 0.2
131	2999	430	456	  5.7	 0.1
132	5839	766	460	  5.8	 0.2
133	1091	182	464	  5.9	 0.0
134	541	100	467	  5.9	 0.0
135	6971	896	471	  6.1	 0.2
136	11821	1417	476	  6.3	 0.3
137	2819	410	480	  6.4	 0.1
Warning,  computation interrupted
seq(OEIS:-Seq);
2, 3, 11, 7, 41, 31, 17, 163, 23, 79, 197, 241, 29, 37, 59, 193, 
  227, 229, 239, 439, 929, 337, 257, 1447, 509, 19, 293, 1723, 
  1619, 937, 179, 367, 251, 1063, 4241, 1291, 521, 1951, 443, 
  139, 191, 1753, 1217, 673, 53, 883, 809, 109, 5381, 3733, 311, 
  967, 449, 2683, 9239, 577, 971, 1453, 101, 1051, 107, 3301, 
  233, 1627, 2729, 2689, 5669, 1597, 2153, 1117, 5099, 10429, 
  5303, 6991, 4253, 1777, 281, 349, 5273, 1543, 1997, 1867, 1109, 
  769, 167, 4261, 3821, 14923, 173, 1531, 71, 13267, 14699, 3877, 
  137, 2389, 3803, 2671, 5879, 1039, 1439, 421, 3929, 22921, 
  1367, 6823, 12239, 3709, 1019, 829, 3467, 2767, 6947, 757, 
  3593, 3163, 1787, 1303, 9413, 21283, 4547, 5653, 6761, 1483, 
  8693, 823, 30971, 7699, 4289, 6301, 2999, 5839, 1091, 541, 
  6971, 11821, 2819
OEIS:-FirstUnseenPrimes();
               5, 13, 43, 47, 61, 67, 73, 83, 89
#Resume execution where it left off:
OEIS();
138	4723	637	484	  0.2	 0.2
139	269	57	487	  0.2	 0.0
140	2221	331	491	  0.3	 0.1
141	773	137	494	  0.3	 0.1
142	607	111	497	  0.4	 0.0
143	11801	1414	502	  0.7	 0.4
144	3529	493	506	  0.8	 0.1
145	5333	706	510	  1.0	 0.2
146	2467	365	514	  1.2	 0.2
147	8501	1060	518	  1.5	 0.3
148	43	14	520	  1.5	 0.0
149	1223	200	524	  1.5	 0.0
150	14461	1696	529	  2.0	 0.5
151	8237	1034	533	  2.3	 0.3
152	859	149	536	  2.4	 0.0
153	11621	1398	541	  2.8	 0.4
154	3307	465	545	  3.0	 0.2
155	4373	597	549	  3.2	 0.2
156	9871	1218	553	  3.5	 0.4
157	7451	943	557	  3.8	 0.3
158	4273	587	561	  4.0	 0.2
159	2213	330	565	  4.1	 0.1
160	67	19	567	  4.2	 0.0
161	2267	336	571	  4.4	 0.2
162	2029	308	575	  4.5	 0.1
163	6689	862	579	  4.8	 0.3
164	3061	438	583	  5.0	 0.2
165	4349	594	587	  5.3	 0.2
166	9067	1127	591	  5.7	 0.5
167	4649	628	595	  6.0	 0.3
Warning,  computation interrupted
seq(OEIS:-Seq);
2, 3, 11, 7, 41, 31, 17, 163, 23, 79, 197, 241, 29, 37, 59, 193, 
  227, 229, 239, 439, 929, 337, 257, 1447, 509, 19, 293, 1723, 
  1619, 937, 179, 367, 251, 1063, 4241, 1291, 521, 1951, 443, 
  139, 191, 1753, 1217, 673, 53, 883, 809, 109, 5381, 3733, 311, 
  967, 449, 2683, 9239, 577, 971, 1453, 101, 1051, 107, 3301, 
  233, 1627, 2729, 2689, 5669, 1597, 2153, 1117, 5099, 10429, 
  5303, 6991, 4253, 1777, 281, 349, 5273, 1543, 1997, 1867, 1109, 
  769, 167, 4261, 3821, 14923, 173, 1531, 71, 13267, 14699, 3877, 
  137, 2389, 3803, 2671, 5879, 1039, 1439, 421, 3929, 22921, 
  1367, 6823, 12239, 3709, 1019, 829, 3467, 2767, 6947, 757, 
  3593, 3163, 1787, 1303, 9413, 21283, 4547, 5653, 6761, 1483, 
  8693, 823, 30971, 7699, 4289, 6301, 2999, 5839, 1091, 541, 
  6971, 11821, 2819, 4723, 269, 2221, 773, 607, 11801, 3529, 
  5333, 2467, 8501, 43, 1223, 14461, 8237, 859, 11621, 3307, 
  4373, 9871, 7451, 4273, 2213, 67, 2267, 2029, 6689, 3061, 4349, 
  9067, 4649
OEIS:-FirstUnseenPrimes();
               5, 13, 47, 61, 73, 83, 89, 97, 103
#Example of continuing processing after a restart:
currentdir("C:/Users/carlj/desktop"):
save OEIS, "OEIS.map";
restart:
currentdir("C:/Users/carlj/desktop"):
read "OEIS.map":
infolevel[OEIS]:= 1:
OEIS();
168	11383	1374	600	  0.6	 0.6
169	9539	1181	604	  1.0	 0.5
170	21613	2428	609	  2.0	 1.0
171	5471	722	613	  2.2	 0.2
172	6007	784	617	  2.6	 0.4
173	5507	728	621	  2.8	 0.3
174	1399	222	625	  2.9	 0.1
175	983	166	628	  3.0	 0.1
176	28771	3134	633	  4.4	 1.4
177	3257	460	637	  4.6	 0.2
178	10639	1298	642	  5.2	 0.5
179	5237	697	646	  5.5	 0.3
180	1459	232	650	  5.6	 0.1
181	8669	1079	654	  6.0	 0.5
182	19183	2176	659	  7.0	 1.0
183	4133	569	663	  7.3	 0.3
184	8803	1096	667	  7.8	 0.5
Warning,  computation interrupted
OEIS:-FirstUnseenPrimes();
               5, 13, 47, 61, 73, 83, 89, 97, 103
save OEIS, "OEIS.map":

OEIS_a083758.mw

Here is another method, which combines the good features of nm's and Kitonum's Answers:

eq:= a %* (2*A + 2*B) + b %* C = c %* (2*A + B) + d %* (B*2) + e %* (C + 4*B);

Like nm's solution, this is part of an integrated network of commands and operators specifically designed for working with inert expressions. Like Kitonum's solution, this targets the exact parts of the expression that you want to be inert, and it can be applied before any automatic simplifications have already "ruined" the form that you want (that doesn't happen for this example, but it will for others).

The value command can be used to remove the inertness (or any inertness that is achieved by prefixing symbols with %).

Unlike your mixing-tank problem, the symbolics of this problem have been fully specified. You just need to enter the equations, use dsolve, then solve, then plot. Doing so doesn't require the slightest bit of understanding of Newton's law of cooling. The entirety of the law is expressed in the differential equation given in the problem: The rate of change of temperature (i.e., the deriavtive T'(t)) is proportional to (i.e., equals a constant k multiplied by) the difference in temperature between an object (T(t)) and its surroundings (A(t)).

To determine the equilibrium solutions, i.e., when y'=0, replace diff(y(t), t) with 0 in the differential equation, and solve the remaining equation algebraically (i.e., not as a differential equation) for y(t). In this case, it'll simply be a quadratic equation:

solve(subs(diff(y(t),t)= 0, LG), y(t))

It doesn't matter whether you do this before or after setting numeric values for aYc, and H.

The values that you find will correspond to places where the solution curve is horizontal, or constant.

I assume that when you say "solve for x", you mean solve f(x,y)=0 for x. Here's an example with a simple function. However, fsolve can give a variety of non-answers, and you may need to decide how to deal with these. These non-answers become much more likely as f becomes more complicated. My simple example has none of these non-answers.

f:= (x,y)-> sin(x)-y:
f_inv:= proc(y::numeric) local x; try fsolve(f(x,y), x) catch: FAIL end try end proc:
Y:= <seq(-1..1, 0.01)>:
f_inv_Y:= f_inv~(Y):
#Check for the possible presence of non-answers:
type(f_inv_Y, 'Vector'(numeric));
                              true
#No non-answers found.
plot(<Y | f_inv_Y>);

Also depending on the complexity of f, you may wish to put a timelimit on each individual fsolve and return the non-answer FAIL if the time is exceeded for a particular y. If you need this, I'll be happy to show you how.

I believe that the above will work in Maple 6; I only have a slight skepticism about the seq command. If it doesn't work, it can be adjusted for Maple 6, I'm sure.

Use a table of Records, like this:

Plots:= table([
    P1 = Record(
        "plot"= plot(x, size= [250$2]), 
        "label"= "first-degree function"
    ),
    P2 = Record(
        "plot"= plot(x^2, size= [250$2]),
        "label"= "second-degree function"
    )
]);
Choice:= RandomTools:-Generate(choose({indices(Plots)}))[];
Plots[Choice]:-plot;
Plots[Choice]:-label;

 

If the discard rule is as I stated in my most-recent Reply above, then the following procedure will do it. Its second argument, V, is what you call the category-1 variables. There's no need to specify the category-2 variables since, obviously, any name that isn't a category-1 variable is a category-2 variable.

RemoveUncommomFactors:= (S::{set,list}(algebraic), V::set(name))->
     map(primpart, S, V)
:
RemoveUncommomFactors({a*x, b*x, c*(x+y)}, {x,y});
                           {x, x + y}

 

 

Hints: The way that you've phrased the question suggests that a is a completely free variable. But this is not true. For any ellipse, a = sqrt(b^2 + c^2). We might as well fix c=1, so b=1 and a=sqrt(2). And we might as well fix the position by saying that the equation is x^2/2 + y^2 = 1, so F1 = (-1,0) and F2 = (1,0).

To get a parameterized solution, replace with convert(Q, rational) in the LinearSolve command. I don't know why this isn't mentioned on the help page.

Look at the piecewise structure with lprint:

lprint(f)

You'll see that the operands of f that you want are the even-numbered ones, plus the final one:

seq(op(k,f), k= 2..nops(f), 2), `if`(nops(f)::odd, op(-1, f), NULL);

Assumptions are usually ignored by solve. Put the inequality together with the equation:

solve({x^2 - x - 2, x > 0}, x)

 

Unfortunately, expand isn't threadsafe. And, you must also make local to be threadsafe. This latter point is a clear-cut case of improperly shared global memory, which is the essence of being non-threadsafe. There's a possibility that simply making local is enough to correct the problem (because perhaps expand for pure polynomials doesn't use global memory). I wouldn't rely on it, but I'd be curious to see your results if your only change is to make local. Please test and report back. Meanwhile, I'll try optimizing that code.

Is there a reason that you put the monomials in lists rather than sets? Sets seems like the natural choice because I don't think that you'd want order to matter when the membership test is done.

First 83 84 85 86 87 88 89 Last Page 85 of 395