How to combine two sums and factor out a common element expression? - maxima

Here's the initial premise: two sums s1 and s2 are added; the sum element expressions have a common factor a[n].
s1: sum(r1[m,q]*b[m,n]*a[n],n,0,N)$
s2: sum(r2[m,q]*c[m,n]*a[n],n,0,N)$
s1+s2;
I expect the sums to be combined and the common element expression a[n] factored out:
s12: sum(a[n]*(r1[m,q]*b[m,n]+r2[m,q]*c[m,n]),n,0,N);
However, I'm unable to make Maxima produce such contraction. The most simplification I was able to obtain was using sumcontract(s1+s2) and it results in two sums without the common element being factored out:
r1[m,q]*sum(b[m,n]*a[n], n,0,N) + r2[m,q]*sum(c[m,n]*a[n], n,0,N);
How to make Maxima produce the factored out expression from s1+s2 as in s12 above?
NOTE: If we remove the r1 and r2, then the factor(sumcontract(s1+s2)) indeed results in the expected s12 expression. However, with both present, it results in two sums and does not factor out the a[n] as mentioned.

How about this. I've applied sumcontract, intosum, and factor.
(%i1) s1: sum(r1[m,q]*b[m,n]*a[n],n,0,N)$
(%i2) s2: sum(r2[m,q]*c[m,n]*a[n],n,0,N)$
(%i3) s1 + s2;
N N
==== ====
\ \
(%o3) r2 > c a + r1 > b a
m, q / m, n n m, q / m, n n
==== ====
n = 0 n = 0
(%i4) intosum (%);
N N
==== ====
\ \
(%o4) > c r2 a + > b r1 a
/ m, n m, q n / m, n m, q n
==== ====
n = 0 n = 0
(%i5) sumcontract (%);
N
====
\
(%o5) > (c r2 a + b r1 a )
/ m, n m, q n m, n m, q n
====
n = 0
(%i6) factor (%);
N
====
\
(%o6) > (c r2 + b r1 ) a
/ m, n m, q m, n m, q n
====
n = 0
In this, intosum is pushing constant factors back into the sum.

Related

Agda - Why is this case required to type check? In a simple proof that $forall m, 1 * m \equiv m$

After defining the naturals, addition and multiplication as usual, I set to write a proof that 1 is a neutral element.
p : (n : ℕ) -> (1 * n) ≡ n
p zero = refl
p (suc m) = refl
Which is fine!
Since refl appears in both alternatives, I thought this should type-check:
p : (n : ℕ) -> (1 * n) ≡ n
p _ = refl
But this fails with:
1 * n != n of type ℕ
when checking that the expression refl has type (1 * n) ≡ n
What causes type to not check here?
It's hard to diagnose an error without a MRE, no matter how standard you think your definitions are.
Your error presumably comes from the fact _+_ and _*_ are defined like so:
0 + n = n
m + 0 = m
suc m + n = suc (m + n)
0 * n = n
suc m * n = n + m * n
and so 1 * n = (suc 0) * n = n + 0 * n = n + 0 which is not judgmentally
equal to n because _+_ is strict in its first argument and so won't
evaluate until that first argument is constructor-headed.
Matching on n to expose a constructor is enough for _+_ to reduce:
0 + 0 is 0 by the first equation and suc m + 0 is suc m by the second.

Taylor series expansion in maxima

How to expand taylor series/polynomials about Q=0 , and then extract coefficients as a list
example :
taylor ( (sin(q)), q, 0, 9); //taylor expansion for first 9 terms gives the next line
(%o1)/T/ q\-q^3/6+q^5/120\-q^7/5040+q^9/362880+...
then using coeff ((%o1), q ^n); gives me the coefficient at n only, what i want is a list for all the coefficients of that expression
Try coeff plus makelist, e.g. something like: makelist(coeff(%o1, q, n), n, 0, 9);
Edit:
I see now that I misread your question and there is already an answer. Nevertheless I will keep it because it is related to your question.
Use powerseries instead of taylor:
(%i1) expr:powerseries(sin(x),x,0);
inf
==== i2 2 i2 + 1
\ (- 1) x
(%o1) > -----------------
/ (2 i2 + 1)!
====
i2 = 0
You can access the coefficient by the args or part function
(%i2) op(expr);
(%o2) sum
(%i3) args(expr);
i2 2 i2 + 1
(- 1) x
(%o3) [-----------------, i2, 0, inf]
(2 i2 + 1)!
(%i4) part(expr,1);
i2 2 i2 + 1
(- 1) x
(%o4) -----------------
(2 i2 + 1)!
(%i5) args(expr)[1];
i2 2 i2 + 1
(- 1) x
(%o5) -----------------
(2 i2 + 1)!
If you want to change the index variable:
(%i6) niceindices(expr),niceindicespref=[n];
inf
==== n 2 n + 1
\ (- 1) x
(%o6) > ---------------
/ (2 n + 1)!
====
n = 0

LaTeX, sloped boxes

I'd like to make a Find-A-Word for the library wall.
The solution (also for the wall) requires a box, enclosing the word.
Horizontal/vertical boxes are no problem. Sloped (slanted?) boxes are what's the problem.\I envisage a command like
\makebox (length, breadth, angle, co-ordinates of left-lower corner)
It may be that this has been done before.
Has anyone any suggestions?
William.
Using tikz and the tikzmarks library:
\documentclass{article}
\usepackage[hmargin=4cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}
\ttfamily
\noindent
\tikzmark{a:start}w d e w e r n \tikzmark{b:start}b v c w o i q\tikzmark{b:stop} v o i q t u h n r g j q v r o e q i o n j v k w
o q p i n t o j v k m o q e i n g k m f o r q e p i n k f m p i g n o j k m
f \tikzmark{c:start}v e p o q i o n j r g k m l e v q n b g j k v m e q n b o j g k v l m e q
n b j g f k l e m v q n j g k e m l v q n g j r f e l v q n j g f l k q g j
n\tikzmark{a:stop} v q e\tikzmark{c:stop} n p m k w g j k n e k e m l v q n g j r f e l v q n j g f l k q g j
\begin{tikzpicture}[remember picture, overlay]
\draw[red] ([shift={(0,1.5ex)}]pic cs:a:start) rectangle (pic cs:a:stop);
\draw[red] ([shift={(0,1.5ex)}]pic cs:b:start) rectangle (pic cs:b:stop);
\draw[red,rotate=45] ([shift={(1.5ex,1.5ex)}]pic cs:c:start) rectangle ([shift={(-0.5ex,0ex)}]pic cs:c:stop);
\end{tikzpicture}
\end{document}

Maxima CAS - substitution

I am trying to simplify a differential equation via substitution in maxima. However, the substitution does not seem to be working.
Here's my code:
depends (\rho,[t, r, \theta, z]); depends (V, [t, r, \theta, z]);
f_contin : diff (\rho, t) + diff (\rho*r*V[r], r)*(1/r) = 0;
base : diff (V[b]*r*\rho, r) = 0;
V_sub : V[r] = V[b] + \epsilon*V[r];
subst (V_sub, f_contin);
subst (base, %o6);
The last substitution did not work. What am I doing wrong here?
For clarity I add a Screenshot here:
The problem is that subst(a=b, c) (or equivalently subst(b, a, c)) can only make substitutions when a is an exact subexpression of c.
ratsubst (which see) can handle some cases when a is not an exact subexepression but in this case it doesn't seem to work.
But I think you can get the result you want by just subtracting the one equation from the other. Note that (a=b) - (c=d) yields a - c = b - d. Note also that I've put in another step (in %i7) to apply the diff operator. Also I've multiplied %o7 by r to get something like base.
(%i1) depends (\rho,[t, r, \theta, z]); depends (V, [t, r, \theta, z]);
(%o1) [rho(t, r, theta, z)]
(%o2) [V(t, r, theta, z)]
(%i3) f_contin : diff (\rho, t) + diff (\rho*r*V[r], r)*(1/r) = 0;
drho d
r V ---- + r (-- (V )) rho + V rho
drho r dr dr r r
(%o3) ---- + ------------------------------------ = 0
dt r
(%i4) base : diff (V[b]*r*\rho, r) = 0;
drho d
(%o4) V r ---- + (-- (V )) r rho + V rho = 0
b dr dr b b
(%i5) V_sub : V[r] = V[b] + \epsilon*V[r];
(%o5) V = epsilon V + V
r r b
(%i6) subst (V_sub, f_contin);
drho drho d
(%o6) ---- + (r (epsilon V + V ) ---- + r (-- (epsilon V + V )) rho
dt r b dr dr r b
+ (epsilon V + V ) rho)/r = 0
r b
(%i7) %o6, nouns;
drho drho d d
(%o7) ---- + (r (epsilon V + V ) ---- + r (epsilon (-- (V )) + -- (V )) rho
dt r b dr dr r dr b
+ (epsilon V + V ) rho)/r = 0
r b
(%i8) expand (r*%o7 - base);
drho drho d
(%o8) r ---- + epsilon r V ---- + epsilon r (-- (V )) rho + epsilon V rho = 0
dt r dr dr r r
The function subst (a,b,c) substitutes a for b in c. It uses 3 arguments, your first subst works because its interpreted as subst (V[b] + \epsilon*V[r],V[r], f_contin);
Your second subst is probably interpreted as subst (0,diff (V[b]*r*\rho, r),%) therefor nothing is substituted. What do you want to substitute for what?

maxima: expanding nested summation

I have the following Maxima code:
m:sum(x[i],i,1,N)/N;
and then I want to calculate $m^2$.
m2:m^2, sumexpand;
Then I get double summation:
sum(sum(x[i1]*x[i2],i1,1,N),i2,1,N)/N^2
What I want to achieve is to expand it into the two sums.
The first one is sum(x[i]^2,i,1,N) and the second is the rest over non-equal indices. How should I do that? How should I do that with arbitrary power of m?
sum is not declared linear by default; you can declare it linear and resimplify. Note that to get the expected effect, you have to declare the noun form of sum.
(%i1) m:sum(x[i],i,1,N)/N;
N
====
\
> x
/ i
====
i = 1
(%o1) --------
N
(%i2) m2:m^2, sumexpand;
N N
==== ====
\ \
> > x x
/ / i1 i2
==== ====
i1 = 1 i2 = 1
(%o2) ---------------------
2
N
(%i3) declare (nounify(sum), linear);
(%o3) done
(%i4) ''%o2;
N N
==== ====
\ \
( > x ) > x
/ i1 / i2
==== ====
i1 = 1 i2 = 1
(%o4) -----------------------
2
N

Resources