@@ -201,16 +201,16 @@ end
201201
202202function rationalize_if_possible (x:: QQBarFieldElem ) # Nemo algebraic number type
203203 if degree (x)== 1 && iszero (imag (x))
204- # Convert to rational using the existing rationalize function from general.jl
205- return rationalize (x)
204+ # Convert to rational using direct conversion
205+ return Rational {BigInt} (x)
206206 else
207207 return x
208208 end
209209end
210210
211211function rationalize_if_possible (f:: PolyRingElem{QQBarFieldElem} )
212212 if maximum (degree .(coefficients (f)))== 1
213- return polynomial (Nemo. QQ, QQ .( coefficients (f)) )
213+ return polynomial (Nemo. QQ, [ Rational {BigInt} (c) for c in coefficients (f)] )
214214 else
215215 return f
216216 end
@@ -225,31 +225,9 @@ function Eval(t::SumOfLogTerms; real_output::Bool=true)
225225 polynomial (F, [c (a) for c in coefficients (t. S)], var))) for a in as]
226226 end
227227
228- # Try to find roots, including complex ones for simple cases
229- as = roots (t. R) # First try rational roots
230-
231- # If we don't have enough roots and it's a quadratic, try to find complex roots
232- if length (as) < degree (t. R) && degree (t. R) == 2
233- # For quadratic ax^2 + bx + c, use quadratic formula
234- coeffs = collect (coefficients (t. R))
235- if length (coeffs) >= 2
236- # Pad with zeros if needed
237- while length (coeffs) < 3
238- push! (coeffs, zero (coeffs[1 ]))
239- end
240- a, b, c = coeffs[3 ], length (coeffs) > 1 ? coeffs[2 ] : zero (coeffs[1 ]), coeffs[1 ]
241-
242- if ! iszero (a)
243- discriminant = b^ 2 - 4 * a* c
244- # Create complex roots using QQBar
245- QQBar = algebraic_closure (Nemo. QQ)
246- sqrt_discriminant = QQBar (discriminant)^ (1 // 2 )
247- root1 = (- QQBar (b) + sqrt_discriminant) // (2 * QQBar (a))
248- root2 = (- QQBar (b) - sqrt_discriminant) // (2 * QQBar (a))
249- as = [root1, root2]
250- end
251- end
252- end
228+ # Find all roots including complex ones using the proper Nemo.jl API
229+ QQBar = algebraic_closure (Nemo. QQ)
230+ as = roots (QQBar, t. R)
253231 us = real .(as)
254232 vs = imag .(as)
255233 if iszero (vs) || ! real_output
0 commit comments