Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
sage.repl.ipython_kernel (widget_from_tuple, slider): Handle symbolic…
Browse files Browse the repository at this point in the history
… subrings like SR
  • Loading branch information
Matthias Koeppe committed Nov 1, 2021
1 parent 038eb9f commit ff83c4c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/sage/repl/ipython_kernel/interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from .widgets import EvalText, SageColorPicker
from .widgets_sagenb import input_grid
from sage.structure.element import parent
from sage.symbolic.ring import SR
import sage.rings.abc
from sage.plot.colors import Color
from sage.structure.element import Matrix

Expand Down Expand Up @@ -209,6 +209,14 @@ def widget_from_tuple(cls, abbrev, *args, **kwds):
Dropdown(index=1, options={'one': 1, 'two': 2, 'three': 3}, value=2)
sage: sage_interactive.widget_from_tuple( (sqrt(2), pi) )
FloatSlider(value=2.277903107981444, max=3.141592653589793, min=1.4142135623730951)
TESTS:
Symbolic subrings::
sage: SCR = SR.subring(no_variables=True)
sage: sage_interactive.widget_from_tuple( (SCR(sqrt(2)), SCR(pi)) )
FloatSlider(value=2.277903107981444, max=3.141592653589793, min=1.4142135623730951)
"""
# Support (description, abbrev)
if len(abbrev) == 2 and isinstance(abbrev[0], str):
Expand All @@ -223,7 +231,7 @@ def widget_from_tuple(cls, abbrev, *args, **kwds):
# Numerically evaluate symbolic expressions

def n(x):
if parent(x) is SR:
if isinstance(parent(x), sage.rings.abc.SymbolicRing):
return x.numerical_approx()
else:
return x
Expand Down
14 changes: 11 additions & 3 deletions src/sage/repl/ipython_kernel/widgets_sagenb.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
from sage.structure.all import parent
from sage.arith.srange import srange
from sage.plot.colors import Color
from sage.symbolic.ring import SR
from sage.rings.all import RR
import sage.rings.abc


from .widgets import HTMLText as text_control
Expand Down Expand Up @@ -234,6 +233,14 @@ def slider(vmin, vmax=None, step_size=None, default=None, label=None, display_va
True
sage: slider(5, display_value=False).readout
False
Symbolic subrings work like ``SR``::
sage: SCR = SR.subring(no_variables=True)
sage: w = slider(SCR(e), SCR(pi)); w
TransformFloatSlider(value=2.718281828459045, max=3.141592653589793, min=2.718281828459045)
sage: parent(w.get_interact_value())
Real Field with 53 bits of precision
"""
kwds = {"readout": display_value}
if label:
Expand Down Expand Up @@ -271,7 +278,8 @@ def err(v):
p = parent(sum(x for x in (vmin, vmax, step_size) if x is not None))

# Change SR to RR
if p is SR:
if isinstance(p, sage.rings.abc.SymbolicRing):
from sage.rings.real_mpfr import RR
p = RR

# Convert all inputs to the common parent
Expand Down

0 comments on commit ff83c4c

Please sign in to comment.