Ticket #14353: trac_14353_fan_cone_intersection.patch

File trac_14353_fan_cone_intersection.patch, 2.7 KB (added by vbraun, 9 years ago)

Updated patch

  • sage/geometry/fan.py

    # HG changeset patch
    # User Volker Braun <vbraun@stp.dias.ie>
    # Date 1364371924 -3600
    # Node ID 13fa8bc25c89ba70c1cfd61643c39a529fd91d6f
    # Parent  38d7d6e9f3308a153e06e2ccce893aa5b78c53b0
    Implement intersection of fans and fan with cone
    
    diff --git a/sage/geometry/fan.py b/sage/geometry/fan.py
    a b  
    15661566        except AttributeError: # The result is either incomplete or unknown.
    15671567            return RationalPolyhedralFan(new_cones, rc.rays(), rc.lattice())
    15681568
     1569    def intersection(self, fan):
     1570        """
     1571        Return the intersection with the given cone.
     1572
     1573        INPUT:
     1574
     1575        - ``fan`` -- a :class:`rational polyhedral fan
     1576          <sage.geometry.fan.RationalPolyhedralFan>` or a single
     1577          :class:`cone <sage.geometry.cone.Cone>`.
     1578
     1579        OUTPUT:
     1580
     1581        The intersection of the fan with the given cone as a new
     1582        fan. This is the fan generated by the intersections of the
     1583        cones of the fan with the specified ``cone``.
     1584
     1585        EXAMPLES::
     1586
     1587             sage: fan1 = Fan([Cone([(1,0), (0,1)])])
     1588             sage: fan2 = Fan([Cone([(1,1), (-1,1)])])
     1589             sage: fan12 = fan1.intersection(fan2)
     1590             sage: fan12.generating_cone(0).rays()
     1591             N(0, 1),
     1592             N(1, 1)
     1593             in 2-d lattice N
     1594             sage: fan21 = fan2.intersection(fan1)
     1595             sage: fan12.is_equivalent(fan21)
     1596             True
     1597
     1598             sage: fan = toric_varieties.P2().fan()
     1599             sage: fan.intersection(fan.generating_cone(0)).cones()
     1600             ((0-d cone of Rational polyhedral fan in 2-d lattice N,),
     1601              (1-d cone of Rational polyhedral fan in 2-d lattice N,
     1602               1-d cone of Rational polyhedral fan in 2-d lattice N),
     1603              (2-d cone of Rational polyhedral fan in 2-d lattice N,))
     1604             sage: fan.intersection(Cone([(1,2)])).cones()
     1605             ((0-d cone of Rational polyhedral fan in 2-d lattice N,),
     1606              (1-d cone of Rational polyhedral fan in 2-d lattice N,))
     1607             
     1608        The cone to intersect with need not be strictly convex::
     1609
     1610             sage: N2 = Cone([(1,0), (0,1), (-1,-1)])
     1611             sage: fan.intersection(N2).is_equivalent(fan)
     1612             True
     1613        """
     1614        if is_Cone(fan):
     1615            fan_cones = [fan]
     1616        else:
     1617            fan_cones = fan.generating_cones()
     1618        from sage.combinat.cartesian_product import CartesianProduct
     1619        cones = [c1.intersection(c2) for c1, c2 in
     1620                 CartesianProduct(self.generating_cones(), fan_cones)]
     1621        return Fan(cones, discard_faces=True)
     1622
    15691623    def _latex_(self):
    15701624        r"""
    15711625        Return a LaTeX representation of ``self``.