Opened 3 years ago

Last modified 3 weeks ago

#25114 needs_work defect

Cannot plot Cone that is a halfplane in 2d

Reported by: yzh Owned by:
Priority: major Milestone: sage-9.4
Component: geometry Keywords: Cone, plot, IMA-PolyGeom
Cc: novoselt, jipilab, mkoeppe, mjo Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: u/yzh/cannot_plot_cone_that_is_a_halfplane_in_2d (Commits, GitHub, GitLab) Commit: 57f5898581472100027da43f1a34b5427c9f3d84
Dependencies: Stopgaps:

Status badges

Description

sage: halfplane = Cone([(1,0), (0,1), (-1,0)])
sage: halfplane.plot() 

raises UnboundLocalError: local variable 'r1' referenced before assignment.

Change History (11)

comment:1 Changed 3 years ago by yzh

  • Branch set to u/yzh/cannot_plot_cone_that_is_a_halfplane_in_2d

comment:2 Changed 3 years ago by yzh

  • Cc jipilab mkoeppe added
  • Commit set to 959187fab39c01a62f9c3389a238b48c58e95b77
  • Keywords IMA-PolyGeom added
  • Status changed from new to needs_review

New commits:

959187frepresent the rays of wall by a matrix. add doctest

comment:3 follow-up: Changed 3 years ago by novoselt

  • Status changed from needs_review to needs_work

While this may fix the plotting issue, it hides the real problem:

sage: N = ToricLattice(2); N
2-d lattice N
sage: NQ = N.base_extend(QQ); NQ
Vector space of dimension 2 over Rational Field
sage: r = N.gen(0); r
N(1, 0)
sage: S = N.submodule([r]); S
Sublattice <N(1, 0)>
sage: SQ = S.base_extend(QQ); SQ
 
Vector space of degree 2 and dimension 1 over Rational Field
Basis matrix:
[1 0]
sage: r in N, r in NQ
(True, True)
sage: r in S, r in SQ
(True, False)

Why is there this difference in behaviour of vector spaces and subspaces? The original code likely worked for halfplanes when it was written and there is no reason for it to stop.

comment:4 in reply to: ↑ 3 Changed 14 months ago by jipilab

Replying to novoselt:

While this may fix the plotting issue, it hides the real problem:

sage: N = ToricLattice(2); N
2-d lattice N
sage: NQ = N.base_extend(QQ); NQ
Vector space of dimension 2 over Rational Field
sage: r = N.gen(0); r
N(1, 0)
sage: S = N.submodule([r]); S
Sublattice <N(1, 0)>
sage: SQ = S.base_extend(QQ); SQ
 
Vector space of degree 2 and dimension 1 over Rational Field
Basis matrix:
[1 0]
sage: r in N, r in NQ
(True, True)
sage: r in S, r in SQ
(True, False)

Why is there this difference in behaviour of vector spaces and subspaces? The original code likely worked for halfplanes when it was written and there is no reason for it to stop.

Looking at the file src/sage/structure/parent.pyx in the __contains__ function, it returns False because:

sage: type(r)
<class 'sage.geometry.toric_lattice_element.ToricLatticeElement'>
sage: r2 = SQ(r); r2
(1, 0)
sage: type(r2)
<class 'sage.modules.vector_rational_dense.Vector_rational_dense'>

and

sage: r2 == r
False

Now, should this return True? I am not sure how to fix this...

comment:5 Changed 12 months ago by mkoeppe

  • Milestone changed from sage-8.2 to sage-9.2

pushing these forward to 9.2

comment:6 Changed 7 months ago by mkoeppe

  • Milestone changed from sage-9.2 to sage-9.3

comment:7 Changed 7 months ago by mjo

  • Cc mjo added

comment:8 Changed 2 months ago by mkoeppe

  • Milestone changed from sage-9.3 to sage-9.4

Setting new milestone based on a cursory review of ticket status, priority, and last modification date.

comment:9 follow-up: Changed 3 weeks ago by yzh

Is it possible to make the plotting work at least? It's a bit annoying to have encountered this same error after each reinstallation of Sage.

comment:10 Changed 3 weeks ago by git

  • Commit changed from 959187fab39c01a62f9c3389a238b48c58e95b77 to 57f5898581472100027da43f1a34b5427c9f3d84

Branch pushed to git repo; I updated commit sha1. New commits:

57f5898Merge branch 'develop' of git://trac.sagemath.org/sage into HEAD

comment:11 in reply to: ↑ 9 Changed 3 weeks ago by mjo

Replying to yzh:

Is it possible to make the plotting work at least? It's a bit annoying to have encountered this same error after each reinstallation of Sage.

I was juuuust about to agree with you. But the underlying problem here is serious. Equality is not transitive:

sage: N = ToricLattice(2)                                                       
sage: NQ = N.base_extend(QQ)                                                    
sage: r = N.gen(0)                                                              
sage: S = N.submodule([r])                                                      
sage: SQ = S.base_extend(QQ)                                                    
sage: r == S(r)                                                                 
True
sage: S(r) == SQ(r)                                                             
True
sage: r == SQ(r)                                                                
False
Note: See TracTickets for help on using tickets.