On Sat, 31 Dec 2022 at 04:56, Carl K <ca...@msn.com> wrote:
>
> I'm playing with physics problems. Can SymPy solve problem like this?
>
> Question: a**2+b**2+c**2==1 (real valued)
> Answer: -1<=a<=1,
>                 -sqrt(1-a**2)<=b<=sqrt(1-a**2),
>                   c is +- sqrt(1-a**2-b**2)

What you are asking for is a parametric solution to an underdetermined
system of equations. SymPy has two functions that can give a
parametric solution but they are only intended to solve equations and
return explicit values so do not handle inequalities:

In [22]: print(solve([a**2 + b**2 + c**2 - 1], [a, b, c]))
[(-sqrt(-b**2 - c**2 + 1), b, c), (sqrt(-b**2 - c**2 + 1), b, c)]

In [23]: print(nonlinsolve([a**2 + b**2 + c**2 - 1], [a, b, c]))
{(-sqrt(-b**2 - c**2 + 1), b, c), (sqrt(-b**2 - c**2 + 1), b, c)}

Here the solutions are represented parametrically with the unknowns b
and c treated as parameters. You can change which variables are
treated as parameters by changing the order of the symbols in the list
[a, b, c]. What is not returned here are the inequalities constraining
the ranges of the parameters. This is partly because both functions
return complex solutions and the restricted ranges you expected are
defined by requiring a, b and c to be real.

I think that the proper solver for something like this is cylindrical
algebraic decomposition (CAD) which SymPy does not have. With a
CAD-based routine for quantifier elimination you would give an input
statement like

  exists c in R such that a**2 + b**2 + c**2 - 1 = 0

Then the algorithm would eliminate the quantifier (exists c) and
return something like

  a**2 - 1 <= 0
  b**2 + a**2 - 1 <= 0

In a simple case like this these can then be rearranged into explicit
constraints for a, b and combined with the explicit parametric
solution given by solve.

--
Oscar

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxQavwc81YCqNdaARRWTJc5CwviszV2aowsSZQTrKeowkw%40mail.gmail.com.

Reply via email to