Menu

#4247 solve can't solve polynomial system of 2 eqs involving symbolic const

None
open
5
2025-02-03
2024-01-13
Raymond Toy
No

This was reported on Maxima stackoverflow

(%i1) eq1:43=%pi/4*d*d*h;
                                           2
                                      %pi d  h
(%o1)                            43 = ────────
                                         4
(%i2) eq2:d1=d0-2*h;
(%o2)                            d1 = d0 - 2 h
(%i3) eq3:d0=9;
(%o3)                               d0 = 9
(%i4) eq4:d=(d0+d1)/2;
                                      d1 + d0
(%o4)                             d = ───────
                                         2
(%i5) solve([eq1,eq2,eq3,eq4],[d,d1,h,d0]);
(%o5)                                 []
(%i6) solve([eq1,eq2,eq3,eq4],[d,d1,h]);
(%o6)                                 []

But solve can find solutions using the last 3 equations:

(%i7) solve([eq2,eq3,eq4],[d,d1,h,d0]);
(%o7)       [[d = %r159, d1 = 2 %r159 - 9, h = 9 - %r159, d0 = 9]]

This can be substituted into eq1 to get:

(%i8) subst(%o7,eq1);
                                                    2
                               %pi (9 - %r159) %r159
(%o8)                     43 = ──────────────────────
                                         4

Finally, solve can produce roots for this. Of course, they're messy, and the OP wanted a numerical solution:

(%i11) allroots(float(%o8));
(%o11) [%r159 = 3.027752659221862, %r159 = - 2.209973166894623, 
                                                      %r159 = 8.18222050767276]

Mapping these 3 solutions into the original set of equations we have:

(%i12) map(lambda([r],subst(r,%o7)), %o11);
(%o12) [[[d = 3.027752659221862, d1 = - 2.944494681556276, 
h = 5.972247340778138, d0 = 9]], [[d = - 2.209973166894623, 
d1 = - 13.419946333789246, h = 11.209973166894624, d0 = 9]], 
[[d = 8.18222050767276, d1 = 7.36444101534552, h = 0.8177794923272401, 
d0 = 9]]]

And the answer expected by the OP is the last solution:

(%i13) %o12[3];
(%o13) [[d = 8.18222050767276, d1 = 7.36444101534552, h = 0.8177794923272401, 
                                                                       d0 = 9]]

Related

Bugs: #4252

Discussion

  • Stavros Macrakis

     
  • Stavros Macrakis

    Here is a simpler example of a system of equations which solve/algsys cannot solve:

    solve([x = 1-%pi*y,1 = (x+1)^2*y],[x,y]) => []
    

    Substituting 2 or float(%pi) for %pi, solve returns numerical solutions with algexact:false (the default):

    solve([x = 1-2*y,1 = (x+1)^2*y],[x,y]) => [[x = 0.6062907292071994 %i + 0.4196433776070806, ...]]
    solve([x = 1-float(%pi)*y,1 = (x+1)^2*y],[x,y]) => [[x = 0.8945133161601903*%i+0.5099711601368948,...]]
    

    Substituting 3 or a for %pi, solve returns algebraic solutions:

    solve([x = 1-3*y,1 = (x+1)^2*y],[x,y]) => [[x = -2,y = 1],...]
    solve([x = 1-a*y,1 = (x+1)^2*y],[x,y]) => [[x = -((2^(17/3)*sqrt(3)*%i+2^(17/3))...
    

    This is all ridiculous. Clearly solve could be returning correct results in all these cases, including the original problem -- presumably numeric results for algexact:false (substituting the numerical values for constants) and symbolic results for algexact:true.

     

    Last edit: Stavros Macrakis 2024-01-15
    • Raymond Toy

      Raymond Toy - 2024-01-15

      Interesting! In the original equations, if I use pp for %pi, I get solutions. I guess this all boils down to algsys not working when %pi is included. I guess that's a hint that we could replace %pi with some gensym, solve the equations, and substitute back %pi for the gensym. This is pretty awful, though.

       
  • Raymond Toy

    Raymond Toy - 2024-01-15
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,4 +1,5 @@
    -This was reported on [Maxima stackoverflow](https://tackoverflow.com/questions/77623241/why-no-solution-in-wxmaxima/77733020?noredirect=1#comment137054578_77733020)
    +This was reported on [Maxima stackoverflow](https://stackoverflow.com/questions/77623241/why-no-solution-in-wxmaxima)
    +
    
     ```
     (%i1) eq1:43=%pi/4*d*d*h;
    
     
  • David Billinghurst

    • labels: solve --> solve, algsys
    • assigned_to: David Billinghurst
     
  • Stavros Macrakis

    • summary: solve can't solve polynomial system of 4 eqs --> solve can't solve polynomial system of 2 eqs involving symbolic const
     
  • Stavros Macrakis

    Here is a simpler example of a system of equations which solve/algsys cannot solve:

    solve([x = 1-%pi*y,1 = (x+1)^2*y],[x,y]) => []
    

    Substituting 2 or float(%pi) for %pi, solve returns numerical solutions with algexact:false (the default):

    solve([x = 1-2*y,1 = (x+1)^2*y],[x,y]) => [[x = 0.6062907292071994 %i + 0.4196433776070806, ...]]
    solve([x = 1-float(%pi)*y,1 = (x+1)^2*y],[x,y]) => [[x = 0.8945133161601903*%i+0.5099711601368948,...]]
    

    Substituting 3 or a for %pi, solve returns algebraic solutions:

    solve([x = 1-3*y,1 = (x+1)^2*y],[x,y]) => [[x = -2,y = 1],...]
    solve([x = 1-a*y,1 = (x+1)^2*y],[x,y]) => [[x = -((2^(17/3)*sqrt(3)*%i+2^(17/3))...
    

    This is all ridiculous. Clearly solve could be returning correct results in all these cases, including the original problem -- presumably numeric results for algexact:false (substituting the numerical values for constants) and symbolic results for algexact:true.
    (Other symbolic constants such as %e and %gamma have the same effect, although non-constants such as e and gamma are unproblematic.

     
  • Stavros Macrakis

     
  • Stavros Macrakis

    Here is a simpler example of a system of equations which solve/algsys cannot solve:

    solve([x = 1-%pi*y,1 = (x+1)^2*y],[x,y]) => []
    

    Substituting 2 or float(%pi) for %pi, solve returns numerical solutions with algexact:false (the default):

    solve([x = 1-2*y,1 = (x+1)^2*y],[x,y]) => [[x = 0.6062907292071994 %i + 0.4196433776070806, ...]]
    solve([x = 1-float(%pi)*y,1 = (x+1)^2*y],[x,y]) => [[x = 0.8945133161601903*%i+0.5099711601368948,...]]
    

    Substituting 3 or a for %pi, solve returns algebraic solutions:

    solve([x = 1-3*y,1 = (x+1)^2*y],[x,y]) => [[x = -2,y = 1],...]
    solve([x = 1-a*y,1 = (x+1)^2*y],[x,y]) => [[x = -((2^(17/3)*sqrt(3)*%i+2^(17/3))...
    
    This is all ridiculous. Clearly ``solve`` could be returning correct results in all these cases, including the original problem -- presumably numeric results for ``algexact:false`` (substituting the numerical values for constants) and symbolic results for ``algexact:true``.
    
     
  • David Billinghurst

    I have had a quick look at this. The problem is in the back-substitution phase of algsys - probably while checking that potential solutions satisfy the equations.

    We can eliminate y to obtain the cubic equation x^3+x^2-x+%pi-1

    (%i1) display2d:false$
    (%i2) eq1:x = 1-%pi*y$
    (%i3) eq2:1 = (x+1)^2*y$
    (%i4) solve(eq1,y);
    (%o4) [y = -((x-1)/%pi)]
    (%i5) eq2,%;
    (%o5) 1 = -(((x-1)*(x+1)^2)/%pi)
    (%i6) %pi*%;
    (%o6) %pi = -((x-1)*(x+1)^2)
    (%i7) expand(lhs(%)-rhs(%));
    (%o7) x^3+x^2-x+%pi-1
    

    A trace on ?algsys shows that the above cubic in x is obtained and a symbolic solution for x is returned (on the second call of ?algsys).

    Digging further will take some work. I seem to recall that algsys only switches to a numerical solution when solving polynomials in a single variable, and won't attempt a numerical solution while back-substituting if a symbolic solution is found at the lowest level.

    (%i8) ?trace(?algsys)$
    ;; Tracing function ALGSYS.
    (%i9) algsys([eq1,eq2],[x,y]);
    1. Trace:
    (ALGSYS
     '((#:X16637 1 1 0 (#:Y16636 1 (#:%PI16638 1 1) 0 -1))
       (#:X16637 2 (#:Y16636 1 -1) 1 (#:Y16636 1 -2) 0 (#:Y16636 1 -1 0 1))))
    2. Trace: (ALGSYS '((#:X16637 3 1 2 1 1 -1 0 (#:%PI16638 1 1 0 -1))))
    3. Trace: (ALGSYS 'NIL)
    3. Trace: ALGSYS ==> (NIL)
    2. Trace: ALGSYS ==>
    ((((MEQUAL) $X
       ((MTIMES SIMP) ((RAT SIMP) -1 18)
        ((MPLUS SIMP) 6
         ((MTIMES SIMP) -3 ((MEXPT SIMP) 2 ((RAT SIMP) 2 3))
          ((MEXPT SIMP)
           ((MPLUS SIMP) 16 ((MTIMES SIMP RATSIMP) -27 $%PI)
            ((MTIMES SIMP) ((MEXPT SIMP) 3 ((RAT SIMP) 3 2))
             ((MEXPT SIMP)
              ((MPLUS SIMP) ((MTIMES SIMP RATSIMP) -32 $%PI)
               ((MTIMES SIMP) 27 ((MEXPT SIMP RATSIMP) $%PI 2)))
              ((RAT SIMP) 1 2))))
           ((RAT SIMP) 1 3)))
         ((MTIMES SIMP) ((MEXPT SIMP) 2 ((RAT SIMP) 2 3))
          ((MEXPT SIMP)
           ((MPLUS SIMP) -432 ((MTIMES SIMP RATSIMP) 729 $%PI)
            ((MTIMES SIMP) ((MEXPT SIMP) 3 ((RAT SIMP) 9 2))
             ((MEXPT SIMP)
              ((MPLUS SIMP) ((MTIMES SIMP RATSIMP) -32 $%PI)
               ((MTIMES SIMP) 27 ((MEXPT SIMP RATSIMP) $%PI 2)))
              ((RAT SIMP) 1 2))))
           ((RAT SIMP) 1 3)))))))
     (((MEQUAL) $X
       ((MTIMES SIMP) ((RAT SIMP) -1 36)
        ((MPLUS SIMP) 12
         ((MTIMES SIMP)
          ((MPLUS SIMP) ((MTIMES SIMP) 3 ((MEXPT SIMP) 2 ((RAT SIMP) 2 3)))
           ((MTIMES SIMP) ((MEXPT SIMP) 2 ((RAT SIMP) 2 3))
            ((MEXPT SIMP) 3 ((RAT SIMP) 3 2)) $%I))
          ((MEXPT SIMP)
           ((MPLUS SIMP) 16 ((MTIMES SIMP RATSIMP) -27 $%PI)
            ((MTIMES SIMP) ((MEXPT SIMP) 3 ((RAT SIMP) 3 2))
             ((MEXPT SIMP)
              ((MPLUS SIMP) ((MTIMES SIMP RATSIMP) -32 $%PI)
               ((MTIMES SIMP) 27 ((MEXPT SIMP RATSIMP) $%PI 2)))
              ((RAT SIMP) 1 2))))
           ((RAT SIMP) 1 3)))
         ((MTIMES SIMP)
          ((MPLUS SIMP) ((MTIMES SIMP) -1 ((MEXPT SIMP) 2 ((RAT SIMP) 2 3)))
           ((MTIMES SIMP) ((MEXPT SIMP) 2 ((RAT SIMP) 2 3))
            ((MEXPT SIMP) 3 ((RAT SIMP) 1 2)) $%I))
          ((MEXPT SIMP)
           ((MPLUS SIMP) -432 ((MTIMES SIMP RATSIMP) 729 $%PI)
            ((MTIMES SIMP) ((MEXPT SIMP) 3 ((RAT SIMP) 9 2))
             ((MEXPT SIMP)
              ((MPLUS SIMP) ((MTIMES SIMP RATSIMP) -32 $%PI)
               ((MTIMES SIMP) 27 ((MEXPT SIMP RATSIMP) $%PI 2)))
              ((RAT SIMP) 1 2))))
           ((RAT SIMP) 1 3))))))))
    2. Trace:
    (ALGSYS
     '((#:Y16636 1
        (#:|(3^(9/2)*sqrt(27*%pi^2-32*%pi)+729*%pi-432)^(1/3)16819| 2
         (#:|2^(1/3)16817| 1 1) 1
         (#:|(3^(3/2)*sqrt(27*%pi^2-32*%pi)-27*%pi+16)^(1/3)16818| 1
          (#:|2^(1/3)16817| 4 -3) 0 (#:|2^(1/3)16817| 8 -3))
         0
         (#:|(3^(3/2)*sqrt(27*%pi^2-32*%pi)-27*%pi+16)^(1/3)16818| 2
          (#:|2^(1/3)16817| 1 9) 1 (#:|2^(1/3)16817| 8 9) 0 72))
        0 -162)
       (#:Y16636 1 (#:%PI16638 1 18) 0
        (#:|(3^(9/2)*sqrt(27*%pi^2-32*%pi)+729*%pi-432)^(1/3)16819| 1
         (#:|2^(1/3)16817| 2 -1) 0
         (#:|(3^(3/2)*sqrt(27*%pi^2-32*%pi)-27*%pi+16)^(1/3)16818| 1
          (#:|2^(1/3)16817| 2 3) 0 -24)))))
    3. Trace:
    (ALGSYS
     '((#:|(3^(9/2)*sqrt(27*%pi^2-32*%pi)+729*%pi-432)^(1/3)16819| 2
        (#:|(3^(3/2)*sqrt(27*%pi^2-32*%pi)-27*%pi+16)^(1/3)16818| 1 -18) 1
        (#:|(3^(3/2)*sqrt(27*%pi^2-32*%pi)-27*%pi+16)^(1/3)16818| 2 54 0
         (#:|2^(1/3)16817| 11 -27))
        0
        (#:|(3^(3/2)*sqrt(27*%pi^2-32*%pi)-27*%pi+16)^(1/3)16818| 1
         (#:|2^(1/3)16817| 11 81) 0
         (#:|sqrt(27*%pi^2-32*%pi)16847| 1 (#:|3^(1/2)16846| 9 2 3 -54))))))
    3. Trace: ALGSYS ==> NIL
    2. Trace: ALGSYS ==> NIL
    2. Trace:
    (ALGSYS
     '((#:Y16636 1
        (#:%I16639 1
         (#:|(3^(9/2)*sqrt(27*%pi^2-32*%pi)+729*%pi-432)^(1/3)16819| 2
          (#:|2^(1/3)16817| 1 (#:|3^(1/2)16846| 1 -1)) 1
          (#:|2^(1/3)16817| 8 (#:|3^(1/2)16846| 3 -1)) 0
          (#:|(3^(3/2)*sqrt(27*%pi^2-32*%pi)-27*%pi+16)^(1/3)16818| 2
           (#:|2^(1/3)16817| 1 (#:|3^(1/2)16846| 5 1)) 1
           (#:|2^(1/3)16817| 8 (#:|3^(1/2)16846| 5 -1))))
         0
         (#:|(3^(9/2)*sqrt(27*%pi^2-32*%pi)+729*%pi-432)^(1/3)16819| 2
          (#:|2^(1/3)16817| 1 -1) 1
          (#:|(3^(3/2)*sqrt(27*%pi^2-32*%pi)-27*%pi+16)^(1/3)16818| 1
           (#:|2^(1/3)16817| 7 -3) 0 (#:|2^(1/3)16817| 8 3))
          0
          (#:|(3^(3/2)*sqrt(27*%pi^2-32*%pi)-27*%pi+16)^(1/3)16818| 2
           (#:|2^(1/3)16817| 1 -9) 1 (#:|2^(1/3)16817| 8 -9) 0 144)))
        0 -324)
       (#:Y16636 1 (#:%PI16638 1 36) 0
        (#:%I16639 1
         (#:|(3^(9/2)*sqrt(27*%pi^2-32*%pi)+729*%pi-432)^(1/3)16819| 1
          (#:|2^(1/3)16817| 2 (#:|3^(1/2)16846| 1 -1)) 0
          (#:|(3^(3/2)*sqrt(27*%pi^2-32*%pi)-27*%pi+16)^(1/3)16818| 1
           (#:|2^(1/3)16817| 2 (#:|3^(1/2)16846| 3 -1))))
         0
         (#:|(3^(9/2)*sqrt(27*%pi^2-32*%pi)+729*%pi-432)^(1/3)16819| 1
          (#:|2^(1/3)16817| 2 1) 0
          (#:|(3^(3/2)*sqrt(27*%pi^2-32*%pi)-27*%pi+16)^(1/3)16818| 1
           (#:|2^(1/3)16817| 2 -3) 0 -48))))))
    3. Trace:
    (ALGSYS
     '((#:%I16639 1
        (#:|(3^(9/2)*sqrt(27*%pi^2-32*%pi)+729*%pi-432)^(1/3)16819| 2
         (#:|(3^(3/2)*sqrt(27*%pi^2-32*%pi)-27*%pi+16)^(1/3)16818| 1
          (#:|3^(1/2)16846| 5 4))
         1
         (#:|(3^(3/2)*sqrt(27*%pi^2-32*%pi)-27*%pi+16)^(1/3)16818| 2
          (#:|3^(1/2)16846| 7 4) 0
          (#:|2^(1/3)16817| 20 (#:|3^(1/2)16846| 5 1) 14 (#:|3^(1/2)16846| 5 -1)))
         0
         (#:|(3^(3/2)*sqrt(27*%pi^2-32*%pi)-27*%pi+16)^(1/3)16818| 1
          (#:|2^(1/3)16817| 20 (#:|3^(1/2)16846| 7 1) 14 (#:|3^(1/2)16846| 7 -1))))
        0
        (#:|(3^(9/2)*sqrt(27*%pi^2-32*%pi)+729*%pi-432)^(1/3)16819| 2
         (#:|(3^(3/2)*sqrt(27*%pi^2-32*%pi)-27*%pi+16)^(1/3)16818| 1 -36) 1
         (#:|(3^(3/2)*sqrt(27*%pi^2-32*%pi)-27*%pi+16)^(1/3)16818| 2 108 0
          (#:|2^(1/3)16817| 14 -27))
         0
         (#:|(3^(3/2)*sqrt(27*%pi^2-32*%pi)-27*%pi+16)^(1/3)16818| 1
          (#:|2^(1/3)16817| 14 81) 0
          (#:|sqrt(27*%pi^2-32*%pi)16847| 1 (#:|3^(1/2)16846| 9 -8 3 216)))))))
    3. Trace: ALGSYS ==> NIL
    2. Trace: ALGSYS ==> NIL
    1. Trace: ALGSYS ==> NIL
    (%o9) []
    
     
  • David Billinghurst

    Another related bug. algsys only finds two solutions of the cubic x^3+x^2-x+%pi-1. Solve returns three, as expected.

    This is now bug [#4252]

    Maxima 5.47.0 https://maxima.sourceforge.io
    using Lisp CLISP 2.49+ (2010-07-17)
    Distributed under the GNU Public License. See the file COPYING.
    Dedicated to the memory of William Schelter.
    The function bug_report() provides bug reporting information.
    (%i1) display2d:false;
    (%o1) false
    (%i2) eq1:x^3+x^2-x+%pi-1$
    (%i3) algsys([eq1],[x]);
    (%o3) [[x = -((2^(2/3)*(3^(9/2)*sqrt(27*%pi^2-32*%pi)+729*%pi-432)^(1/3)
              -3*2^(2/3)*(3^(3/2)*sqrt(27*%pi^2-32*%pi)-27*%pi+16)^(1/3)+6)
              /18)],
           [x = -(((2^(2/3)*sqrt(3)*%i-2^(2/3))
              *(3^(9/2)*sqrt(27*%pi^2-32*%pi)+729*%pi-432)^(1/3)
              +(2^(2/3)*3^(3/2)*%i+3*2^(2/3))
               *(3^(3/2)*sqrt(27*%pi^2-32*%pi)-27*%pi+16)^(1/3)+12)
              /36)]]
    (%i4) solve(eq1,x);
    (%o4) [x = (-1/2-(sqrt(3)*%i)/2)*((sqrt(%pi)*sqrt(27*%pi-32))/(2*3^(3/2))
                                     +(-(3*(%pi-1))-1)/6+(-1)/27)
                                     ^(1/3)
             +(4*((sqrt(3)*%i)/2+(-1)/2))/(9
                                          *((sqrt(%pi)*sqrt(27*%pi-32))
                                           /(2*3^(3/2))
                                           +(-(3*(%pi-1))-1)/6+(-1)/27)
                                           ^(1/3))+(-1)/3,
           x = ((sqrt(3)*%i)/2+(-1)/2)*((sqrt(%pi)*sqrt(27*%pi-32))/(2*3^(3/2))
                                       +(-(3*(%pi-1))-1)/6+(-1)/27)
                                       ^(1/3)
             +(4*(-1/2-(sqrt(3)*%i)/2))/(9*((sqrt(%pi)*sqrt(27*%pi-32))
                                           /(2*3^(3/2))
                                           +(-(3*(%pi-1))-1)/6+(-1)/27)
                                           ^(1/3))+(-1)/3,
           x = ((sqrt(%pi)*sqrt(27*%pi-32))/(2*3^(3/2))
             +(-(3*(%pi-1))-1)/6+(-1)/27)
             ^(1/3)
             +4/(9*((sqrt(%pi)*sqrt(27*%pi-32))/(2*3^(3/2))
                   +(-(3*(%pi-1))-1)/6+(-1)/27)
                   ^(1/3))+(-1)/3]
    
     

    Related

    Bugs: #4252


    Last edit: David Billinghurst 2024-01-16
  • David Billinghurst

    I added an example of this to the algsys documentation as 20.2.3 Example 2: Equations with irrational coefficients. Not much of a solution.

     

Log in to post a comment.