solve.tex 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. \section{SOLVE Operator}\ttindex{SOLVE}
  2. SOLVE is an operator for solving one or more simultaneous algebraic
  3. equations. It is used with the syntax:
  4. \begin{verbatim}
  5. SOLVE(EXPRN:algebraic[,VAR:kernel|,VARLIST:list of kernels])
  6. :list.
  7. \end{verbatim}
  8. {\tt EXPRN} is of the form {\tt <expression>} or
  9. \{ {\tt <expression1>},{\tt <expression2>}, \dots \}. Each expression is an
  10. algebraic equation, or is the difference of the two sides of the equation.
  11. The second argument is either a kernel or a list of kernels representing
  12. the unknowns in the system. This argument may be omitted if the number of
  13. distinct, non-constant, top-level kernels equals the number of unknowns,
  14. in which case these kernels are presumed to be the unknowns.
  15. For one equation, {\tt SOLVE}\ttindex{SOLVE} recursively uses
  16. factorization and decomposition, together with the known inverses of
  17. {\tt LOG}, {\tt SIN}, {\tt COS}, {\tt \verb|^|}, {\tt ACOS}, {\tt ASIN}, and
  18. linear, quadratic, cubic, quartic, or binomial factors. Solutions
  19. of equations built with exponentials or logarithms are often
  20. expressed in terms of Lambert's {\tt W} function.\index{Lambert's W}
  21. This function is (partially) implemented in the special functions package.
  22. Linear equations are solved by the multi-step elimination method due to
  23. Bareiss, unless the switch {\tt CRAMER}\ttindex{CRAMER} is on, in which
  24. case Cramer's method is used. The Bareiss method is usually more
  25. efficient unless the system is large and dense.
  26. Non-linear equations are solved using the Groebner basis package.
  27. \index{Groebner} Users should note that this can be quite a
  28. time consuming process.
  29. {\it Examples:}
  30. \begin{verbatim}
  31. solve(log(sin(x+3))^5 = 8,x);
  32. solve(a*log(sin(x+3))^5 - b, sin(x+3));
  33. solve({a*x+y=3,y=-2},{x,y});
  34. \end{verbatim}
  35. {\tt SOLVE} returns a list of solutions. If there is one unknown, each
  36. solution is an equation for the unknown. If a complete solution was
  37. found, the unknown will appear by itself on the left-hand side of the
  38. equation. On the other hand, if the solve package could not find a
  39. solution, the ``solution'' will be an equation for the unknown in terms
  40. of the operator {\tt ROOT\_OF}\ttindex{ROOT\_OF}. If there
  41. are several unknowns, each solution will be a list of equations for the
  42. unknowns. For example,
  43. \begin{verbatim}
  44. solve(x^2=1,x); -> {X=-1,X=1}
  45. solve(x^7-x^6+x^2=1,x)
  46. 6
  47. -> {X=ROOT_OF(X_ + X_ + 1,X_,TAG_1),X=1}
  48. solve({x+3y=7,y-x=1},{x,y}) -> {{X=1,Y=2}}.
  49. \end{verbatim}
  50. The TAG argument is used to uniquely identify those particular solutions.
  51. Solution multiplicities are stored in the global variable {\tt
  52. ROOT\_MULTIPLICITIES} rather than the solution list. The value of this
  53. variable is a list of the multiplicities of the solutions for the last
  54. call of {\tt SOLVE}. \ttindex{SOLVE} For example,
  55. \begin{verbatim}
  56. solve(x^2=2x-1,x); root_multiplicities;
  57. \end{verbatim}
  58. gives the results
  59. \begin{verbatim}
  60. {X=1}
  61. {2}
  62. \end{verbatim}
  63. If you want the multiplicities explicitly displayed, the switch
  64. {\tt MULTIPLICITIES}\ttindex{MULTIPLICITIES} can be turned on. For example
  65. \begin{verbatim}
  66. on multiplicities; solve(x^2=2x-1,x);
  67. \end{verbatim}
  68. yields the result
  69. \begin{verbatim}
  70. {X=1,X=1}
  71. \end{verbatim}
  72. \subsection{Handling of Undetermined Solutions}
  73. When {\tt SOLVE} cannot find a solution to an equation, it normally
  74. returns an equation for the relevant indeterminates in terms of the
  75. operator {\tt ROOT\_OF}.\ttindex{ROOT\_OF} For example, the expression
  76. \begin{verbatim}
  77. solve(cos(x) + log(x),x);
  78. \end{verbatim}
  79. returns the result
  80. \begin{verbatim}
  81. {X=ROOT_OF(COS(X_) + LOG(X_),X_,TAG_1)} .
  82. \end{verbatim}
  83. An expression with a top-level {\tt ROOT\_OF} operator is implicitly a
  84. list with an unknown number of elements (since we don't always know how
  85. many solutions an equation has). If a substitution is made into such an
  86. expression, closed form solutions can emerge. If this occurs, the {\tt
  87. ROOT\_OF} construct is replaced by an operator {\tt ONE\_OF}.\ttindex{ONE\_OF}
  88. At this point it is of course possible to transform the result of the
  89. original {\tt SOLVE} operator expression into a standard {\tt SOLVE}
  90. solution. To effect this, the operator {\tt EXPAND\_CASES}
  91. \ttindex{EXPAND\_CASES} can be used.
  92. The following example shows the use of these facilities:
  93. \extendedmanual{\newpage}
  94. \begin{verbatim}
  95. solve(-a*x^3+a*x^2+x^4-x^3-4*x^2+4,x);
  96. 2 3
  97. {X=ROOT_OF(A*X_ - X_ + 4*X_ + 4,X_,TAG_2),X=1}
  98. sub(a=-1,ws);
  99. {X=ONE_OF({2,-1,-2},TAG_2),X=1}
  100. expand_cases ws;
  101. {X=2,X=-1,X=-2,X=1}
  102. \end{verbatim}
  103. \subsection{Solutions of Equations Involving Cubics and Quartics}
  104. Since roots of cubics and quartics can often be very messy, a switch
  105. {\tt FULLROOTS}\ttindex{FULLROOTS} is available, that, when off (the
  106. default), will prevent the production of a result in closed form. The
  107. {\tt ROOT\_OF} construct will be used in this case instead.
  108. In constructing the solutions of cubics and quartics, trigonometrical
  109. forms are used where appropriate. This option is under the control of a
  110. switch {\tt TRIGFORM},\ttindex{TRIGFORM} which is normally on.
  111. The following example illustrates the use of these facilities:
  112. \begin{verbatim}
  113. let xx = solve(x^3+x+1,x);
  114. xx;
  115. 3
  116. {X=ROOT_OF(X_ + X_ + 1,X_)}
  117. on fullroots;
  118. xx;
  119. - SQRT(31)*I
  120. ATAN(---------------)
  121. 3*SQRT(3)
  122. {X=(I*(SQRT(3)*SIN(-----------------------)
  123. 3
  124. \end{verbatim}
  125. \newpage
  126. \begin{verbatim}
  127. - SQRT(31)*I
  128. ATAN(---------------)
  129. 3*SQRT(3)
  130. - COS(-----------------------)))/SQRT(3),
  131. 3
  132. - SQRT(31)*I
  133. ATAN(---------------)
  134. 3*SQRT(3)
  135. X=( - I*(SQRT(3)*SIN(-----------------------)
  136. 3
  137. - SQRT(31)*I
  138. ATAN(---------------)
  139. 3*SQRT(3)
  140. + COS(-----------------------)))/SQRT(
  141. 3
  142. 3),
  143. - SQRT(31)*I
  144. ATAN(---------------)
  145. 3*SQRT(3)
  146. 2*COS(-----------------------)*I
  147. 3
  148. X=----------------------------------}
  149. SQRT(3)
  150. off trigform;
  151. xx;
  152. 2/3
  153. {X=( - (SQRT(31) - 3*SQRT(3)) *SQRT(3)*I
  154. 2/3 2/3
  155. - (SQRT(31) - 3*SQRT(3)) - 2 *SQRT(3)*I
  156. 2/3 1/3 1/3
  157. + 2 )/(2*(SQRT(31) - 3*SQRT(3)) *6
  158. 1/6
  159. *3 ),
  160. 2/3
  161. X=((SQRT(31) - 3*SQRT(3)) *SQRT(3)*I
  162. 2/3 2/3
  163. - (SQRT(31) - 3*SQRT(3)) + 2 *SQRT(3)*I
  164. 2/3 1/3 1/3
  165. + 2 )/(2*(SQRT(31) - 3*SQRT(3)) *6
  166. 1/6
  167. *3 ),
  168. 2/3 2/3
  169. (SQRT(31) - 3*SQRT(3)) - 2
  170. X=-------------------------------------}
  171. 1/3 1/3 1/6
  172. (SQRT(31) - 3*SQRT(3)) *6 *3
  173. \end{verbatim}
  174. \subsection{Other Options}
  175. If {\tt SOLVESINGULAR}\ttindex{SOLVESINGULAR} is on (the default setting),
  176. degenerate systems such as {\tt x+y=0}, {\tt 2x+2y=0} will be solved by
  177. introducing appropriate arbitrary constants.
  178. The consistent singular equation 0=0 or equations involving functions with
  179. multiple inverses may introduce unique new indeterminant kernels
  180. {\tt ARBCOMPLEX(j)}, or {\tt ARBINT(j)}, ($j$=1,2,...), % {\tt ARBREAL(j)},
  181. representing arbitrary complex or integer numbers respectively. To
  182. automatically select the principal branches, do {\tt off allbranch;} .
  183. \ttindex{ALLBRANCH} To avoid the introduction of new indeterminant kernels
  184. do {\tt OFF ARBVARS}\ttindex{ARBVARS} -- then no equations are generated for the free
  185. variables and their original names are used to express the solution forms.
  186. To suppress solutions of consistent singular equations do
  187. {\tt OFF SOLVESINGULAR}.
  188. To incorporate additional inverse functions do, for example:
  189. \begin{verbatim}
  190. put('sinh,'inverse,'asinh);
  191. put('asinh,'inverse,'sinh);
  192. \end{verbatim}
  193. together with any desired simplification rules such as
  194. \begin{verbatim}
  195. for all x let sinh(asinh(x))=x, asinh(sinh(x))=x;
  196. \end{verbatim}
  197. For completeness, functions with non-unique inverses should be treated as
  198. {\tt \verb|^|}, {\tt SIN}, and {\tt COS} are in the {\tt SOLVE}
  199. \ttindex{SOLVE} module source.
  200. Arguments of {\tt ASIN} and {\tt ACOS} are not checked to ensure that the
  201. absolute value of the real part does not exceed 1; and arguments of
  202. {\tt LOG} are not checked to ensure that the absolute value of the imaginary
  203. part does not exceed $\pi$; but checks (perhaps involving user response
  204. for non-numerical arguments) could be introduced using
  205. {\tt LET}\ttindex{LET} statements for these operators.
  206. \subsection{Parameters and Variable Dependency}
  207. The proper design of a variable sequence
  208. supplied as a second argument to {\tt SOLVE} is important
  209. for the structure of the solution of an equation system.
  210. Any unknown in the system
  211. not in this list is considered totally free. E.g.\ the call
  212. \begin{verbatim}
  213. solve({x=2*z,z=2*y},{z});
  214. \end{verbatim}
  215. produces an empty list as a result because there is no function
  216. $z=z(x,y)$ which fulfills both equations for arbitrary $x$ and $y$ values.
  217. In such a case the share variable {\tt requirements}\ttindex{requirements}
  218. displays a set of restrictions for the parameters of the system:
  219. \begin{verbatim}
  220. requirements;
  221. {x - 4*y}
  222. \end{verbatim}
  223. The non-existence of a formal solution is caused by a
  224. contradiction which disappears only if the parameters
  225. of the initial system are set such that all members
  226. of the requirements list take the value zero.
  227. For a linear system the set is complete: a solution
  228. of the requirements list makes the initial
  229. system solvable. E.g.\ in the above case a substitution
  230. $x=4y$ makes the equation set consistent. For a non-linear
  231. system only one inconsistency is detected. If such a system
  232. has more than one inconsistency, you must reduce them
  233. one after the other.
  234. \footnote{
  235. The difference between linear and non--linear
  236. inconsistent systems is based on the algorithms which
  237. produce this information as a side effect when attempting
  238. to find a formal solution; example:
  239. $solve(\{x=a,x=b,y=c,y=d\},\{x,y\}$ gives a set $\{a-b,c-d\}$
  240. while $solve(\{x^2=a,x^2=b,y^2=c,y^2=d\},\{x,y\}$ leads to $\{a-b\}$.
  241. }
  242. The set shows you also the dependency among the parameters: here
  243. one of $x$ and $y$ is free and a formal solution of the system can be
  244. computed by adding it to the variable list of {\tt solve}.
  245. The requirement set is not unique -- there may be other such sets.
  246. A system with parameters may have a formal solution, e.g.\
  247. \begin{verbatim}
  248. solve({x=a*z+1,0=b*z-y},{z,x});
  249. y a*y + b
  250. {{z=---,x=---------}}
  251. b b
  252. \end{verbatim}
  253. which is not valid for all possible values of the parameters.
  254. The variable {\tt assumptions}\ttindex{assumptions} contains then a list of
  255. restrictions: the solutions are valid only as long
  256. as none of these expressions vanishes. Any zero of one of them
  257. represents a special case that is not covered by the
  258. formal solution. In the above case the value is
  259. \extendedmanual{\newpage}
  260. \begin{verbatim}
  261. assumptions;
  262. {b}
  263. \end{verbatim}
  264. which excludes formally the case $b=0$; obviously this special
  265. parameter value makes the system singular. The set of assumptions
  266. is complete for both, linear and non--linear systems.
  267. {\tt SOLVE} rearranges the variable sequence
  268. to reduce the (expected) computing time. This behavior is controlled
  269. by the switch {\tt varopt}\ttindex{varopt}, which is on by default.
  270. If it is turned off, the supplied variable sequence is used
  271. or the system kernel ordering is taken if the variable
  272. list is omitted. The effect is demonstrated by an example:
  273. \begin{verbatim}
  274. s:= {y^3+3x=0,x^2+y^2=1};
  275. solve(s,{y,x});
  276. 6 2
  277. {{y=root_of(y_ + 9*y_ - 9,y_),
  278. 3
  279. - y
  280. x=-------}}
  281. 3
  282. off varopt; solve(s,{y,x});
  283. 6 4 2
  284. {{x=root_of(x_ - 3*x_ + 12*x_ - 1,x_),
  285. 4 2
  286. x*( - x + 2*x - 10)
  287. y=-----------------------}}
  288. 3
  289. \end{verbatim}
  290. In the first case, {\tt solve} forms the solution as a set of
  291. pairs $(y_i,x(y_i))$ because the degree of $x$ is higher --
  292. such a rearrangement makes the internal computation of the Gr\"obner basis
  293. generally faster. For the second case the explicitly given variable sequence
  294. is used such that the solution has now the form $(x_i,y(x_i))$.
  295. Controlling the variable sequence is especially important if
  296. the system has one or more free variables.
  297. As an alternative to turning off {\tt varopt}, a partial dependency among
  298. the variables can be declared using the {\tt depend}\index{depend}
  299. statement: {\tt solve} then rearranges the variable sequence but keeps any
  300. variable ahead of those on which it depends.
  301. \extendedmanual{\newpage}
  302. \begin{verbatim}
  303. on varopt;
  304. s:={a^3+b,b^2+c}$
  305. solve(s,{a,b,c});
  306. 3 6
  307. {{a=arbcomplex(1),b= - a ,c= - a }}
  308. depend a,c; depend b,c; solve(s,{a,b,c});
  309. {{c=arbcomplex(2),
  310. 6
  311. a=root_of(a_ + c,a_),
  312. 3
  313. b= - a }}
  314. \end{verbatim}
  315. Here {\tt solve} is forced to put $c$ after $a$ and after $b$, but
  316. there is no obstacle to interchanging $a$ and $b$.