Ticket #8626 (needs_work defect)

Opened 3 years ago

Last modified 3 years ago

qqbar and SR

Reported by: jason Owned by: AlexGhitza
Priority: major Milestone: sage-5.10
Component: coercion Keywords:
Cc: cwitty Work issues:
Report Upstream: N/A Reviewers:
Authors: Merged in:
Dependencies: Stopgaps:

Description (last modified by jason) (diff)

It would be nice if roots of quadratics printed using the quadratic formula in QQbar, i.e.,

sage: QQbar(sqrt(2))
sqrt(2)

Additionally, it would be nice if we could wrap qqbar elements as SR objects.

The first patch just affects printing of qqbar elements. The second lets you do more than just print (e.g., SR(QQbar(sqrt(2))) should give you sqrt(2), not just print sqrt(2))

Attachments

trac-8626-qqbar-sqrt-printing.patch Download (1.3 KB) - added by jason 3 years ago.
trac-8626-qqbar-symbolics.patch Download (3.1 KB) - added by jason 3 years ago.
apply on top of previous patch

Change History

comment:1 Changed 3 years ago by jason

This patch almost certainly needs work, but does give some nice results:

sage: QQbar(sqrt(5))  
sqrt(20)/2
sage: QQbar(sqrt(2))  
sqrt(8)/2

Things are not simplified because I don't want to do any extra work in the printing.

comment:2 Changed 3 years ago by jason

Another example with this patch:

sage: m=matrix(2,2,[0,1,1,1]);m
[0 1]
[1 1]
sage: m.eigenvalues()          
[(--1-sqrt(5))/2, (--1+sqrt(5))/2]

comment:3 Changed 3 years ago by jason

That last patch corrects the double negative, so I get:

sage: m=matrix(2,2,[0,1,1,1]);m
[0 1]
[1 1]
sage: m.eigenvalues()  
[(1-sqrt(5))/2, (1+sqrt(5))/2]

Changed 3 years ago by jason

Changed 3 years ago by jason

apply on top of previous patch

comment:4 Changed 3 years ago by jason

I've attached a work-in-progress patch that allows qqbar elements to be converted to symbolics elements in a smart way, i.e., square roots become symbolic square roots, etc.

comment:5 Changed 3 years ago by jason

  • Status changed from new to needs_work

comment:6 Changed 3 years ago by jason

  • Cc cwitty added
  • Priority changed from minor to major

Here is another problem that could probably be solved if qqbar elements could be converted to symbolics. The application for this example was trying to plot a line from the eigenvector of a matrix:

sage: A=matrix(QQ,2,2,[2,5,1,2])
sage: EV=A.right_eigenvectors()
sage: EV
[(-0.2360679774997897?, [(1, -0.4472135954999580?)], 1), (4.236067977499789?, [(1, 0.4472135954999580?)], 1)]
sage: evec=EV[0][1][0]
sage: var('t')
t
sage: evec.n()*t # works fine
(t, -0.447213595499958*t)
sage: t*evec
Traceback (most recent call last):
...
NotImplementedError: symbol

comment:7 Changed 3 years ago by jason

  • Component changed from algebra to coercion
  • Description modified (diff)
  • Summary changed from qqbar quadratic elements to qqbar and SR

comment:8 Changed 3 years ago by jason

  • Description modified (diff)
Note: See TracTickets for help on using tickets.