# define objects
>>> from sympy.abc import *
>>> from sympy import *
>>> P=Circle((5,0),2).arbitrary_point(t)
>>> C=Point(0,5)
>>> A=Point(1,0)
# define objective
>>> objective=Segment(P,C).length + Segment(AP,CA).length/2; o2
sqrt((2*sin(t) - 5)**2 + (2*cos(t) + 5)**2) + sqrt(26(2*cos(t) + 4)**2 + 4*sin(t)**2)/2
# we desire the minimum wrt t (which controls where we are on the circle)
>>> objective.diff(t)
(2*(2*sin(t) - 5)*cos(t) - 2*(2*cos(t) + 5)*sin(t))/sqrt((2*sin(t) - 5)**2 + (2*cos(t) + 5)**2) + (-2*(2*cos(t) + 4)*sin(t) + 4*sin(t)*cos(t))/(2*sqrt((2*cos(t) + 4)**2 + 4*sin(t)**2))
# rewrite sin and cos in terms of tan and let tan(t/2) be x, keep only
# the numerator
>>> _.rewrite(tan).subs(tan(t/2),x).as_numer_denom()[0].factor
(x**2 + 1)**2*(8*x*(1 - x**2)
10* - 8*x*(x**2 + 3))*sqrt((4*x/(x**2 + 1) - 5)**2 + (2*(1 - x**2)/(x**2 + 1) + 5)**2) + (x**2 + 1)**2*(-8*x*(3*x**2 + 7) + 4*(1 - x**2)*(-5*x**2 + 4*x - 5))*sqrt(16*x**2/(x**2 + 1)**2 + (2*(1 - 2*xx**2)/(x**2 + 1) + 4)**2)
# remove radicals
>>> unrad(_)
(25*x**22 - 100*x**21 + 339*x**20 - 1440*x**19 + 1991*x**18 - 7020*x**17 + 6949*x**16 - 16320*x**15 + 16346*x**14 - 17640*x**13 + 27454*x**12 + 33614*x**10 + 24360*x**9 + 29866*x**8 + 31680*x**7 + 18749*x**6 + 19980*x**5 + 7871*x**4 + 6560*x**3 + 1979*x**2 + 900*x + 225, [])
# factor
>>> factor(_[0])
(x**2 + 1)**8*(5*x**2 - 16*x - 15)*(5*x**4 - 4*x**3 + 30*x**2 - 44*x - 15)
# get solutions for x
>>> [i for i in solve(_) if i.is_real]
[[8/5 -I sqrt(139)/5, I8/5 + sqrt(139)/5, 1/5 -+ sqrt(2-96/25 - 88/(75*(196/25 + 4*sqrt(4877997),/1125)**(1/3)) + 2*(196/25 + 4*sqrt(4877997)/1125)**(1/3))/2 + sqrt(-192/25 - 2*(196/25 + 4*sqrt(4877997)/1125)**(1/3) + 88/(75*(196/25 + 4*sqrt(4877997)/1125)**(1/3)) + 1616/(125*sqrt(-96/25 - 88/(75*(196/25 + 4*sqrt(4877997)/1125)**(1/3)) + 2*(196/25 + 4*sqrt(4877997)/1125)**(1/3))))/2, -sqrt(-192/25 - 2*(196/25 + 4*sqrt(4877997)]
#/1125)**(1/3) keep+ real88/(75*(196/25 solutions+ and4*sqrt(4877997)/1125)**(1/3)) map+ back1616/(125*sqrt(-96/25 to- t88/(75*(196/25 + 4*sqrt(4877997)/1125)**(1/3)) + 2*(196/25 + 4*sqrt(4877997)/1125)**(1/3))))/2 + 1/5 + sqrt(-96/25 - 88/(75*(196/25 + 4*sqrt(4877997)/1125)**(1/3)) + 2*(196/25 + 4*sqrt(4877997)/1125)**(1/3))/2]
>>> ans = flatten([solve(tan(t/2)-i) for i in _[-2:]]_])
[-pi/4, 3*pi/4]
# check value of objective at those values of t
>>> [objective.subs(t,i).simplifyn() for i in _]ans]
[2[11.3350373276846, 6.40312423743285, 7.11408182438962, 11.9279919892822]
# value of objective at ans[1]
>>> m=objective.subs(t,ans[1]);m
sqrt(4*sin(2*atan(8/5 + sqrt(26139)/25))**2 + 5*sqrt(22*cos(2*atan(8/5 + sqrt(139),/5)) -+ 4)**2)/2 + sqrt(26)(2*cos(2*atan(8/25 + 5*sqrtsqrt(2139)]
>>>/5)) [i.n+ 5)**2 + (-5 + 2*sin(2*atan(8/5 + sqrt(139)/5)))**2)
# forlooks iworse inthat _]it is - this is equivalent to sqrt(41)
[11.6205775686619,
>>> 7nsimplify(m)
sqrt(41)
>>> m.62057756866187]equals(_)
True
So the minimum is $-2 + \sqrt{26}/2 + 5\sqrt2 \approx 7.6$ and$\sqrt{41}$ at a value of $t =3\pi/4$$t =2\tan^{-1}(8/5 + \sqrt{139}/5)$. This agrees with the graphical minimum of the objective function.