Repository: sagemath/sage

Issue:
Height function for projective subvarieties
<div id="comment:0"></div>

We want to have a function that computes the height of the projective subvariety.

If X is a projective subvariety, then the height of X is the height of its associated Chow form.


CC:  @bhutz @EnderWannabe

Component: **algebraic geometry**

Author: **Jing Guo**

Branch/Commit: **[u/gh-guojing0/subvar](https://github.com/sagemath/sagetrac-mirror/tree/u/gh-guojing0/subvar) @ [`39f7ee2`](https://github.com/sagemath/sagetrac-mirror/commit/39f7ee231cffe13bee7ca84c25020877e5b16d00)**

Reviewer: **Ben Hutz**

_Issue created by migration from https://trac.sagemath.org/ticket/34559_




Discussion:
<div id="comment:1"></div>

Branch pushed to git repo; I updated commit sha1. New commits:
<table><tr><td><a href="https://github.com/sagemath/sagetrac-mirror/commit/0b4c296d5c61dc0249701a04368ab5e9093be66e"><code>0b4c296</code></a></td><td><code>34559: Height functions for projective subschemes</code></td></tr></table>

Changed commit from **[`627b2bd`](https://github.com/sagemath/sagetrac-mirror/commit/627b2bdfe922e2f9eed9d190c19df778674bdcfb)** to **[`0b4c296`](https://github.com/sagemath/sagetrac-mirror/commit/0b4c296d5c61dc0249701a04368ab5e9093be66e)**
<div id="comment:2"></div>

Branch pushed to git repo; I updated commit sha1. New commits:
<table><tr><td><a href="https://github.com/sagemath/sagetrac-mirror/commit/427e40a00ea58c0bbd70ea495f2db3c2e7c36671"><code>427e40a</code></a></td><td><code>34559: Add docs and examples</code></td></tr></table>

Changed commit from **[`0b4c296`](https://github.com/sagemath/sagetrac-mirror/commit/0b4c296d5c61dc0249701a04368ab5e9093be66e)** to **[`427e40a`](https://github.com/sagemath/sagetrac-mirror/commit/427e40a00ea58c0bbd70ea495f2db3c2e7c36671)**
Changed commit from **[`427e40a`](https://github.com/sagemath/sagetrac-mirror/commit/427e40a00ea58c0bbd70ea495f2db3c2e7c36671)** to **[`e77d5b5`](https://github.com/sagemath/sagetrac-mirror/commit/e77d5b5837f27f38c8cd1715cc0783035a939ec6)**
<div id="comment:3"></div>

Branch pushed to git repo; I updated commit sha1. New commits:
<table><tr><td><a href="https://github.com/sagemath/sagetrac-mirror/commit/e77d5b5837f27f38c8cd1715cc0783035a939ec6"><code>e77d5b5</code></a></td><td><code>34559: Correct examples</code></td></tr></table>

Reviewer: **Ben Hutz**
<div id="comment:5" align="right">comment:5</div>

This is looking fine. Just one thing. Any example longer than about 0.5s should be marked as

```
#long time
```
Changed commit from **[`e77d5b5`](https://github.com/sagemath/sagetrac-mirror/commit/e77d5b5837f27f38c8cd1715cc0783035a939ec6)** to **[`39f7ee2`](https://github.com/sagemath/sagetrac-mirror/commit/39f7ee231cffe13bee7ca84c25020877e5b16d00)**
<div id="comment:6"></div>

Branch pushed to git repo; I updated commit sha1. New commits:
<table><tr><td><a href="https://github.com/sagemath/sagetrac-mirror/commit/39f7ee231cffe13bee7ca84c25020877e5b16d00"><code>39f7ee2</code></a></td><td><code>34559: Long time comments</code></td></tr></table>

<div id="comment:7" align="right">comment:7</div>

Thanks and done.

Resolving patch:
diff --git a/src/sage/schemes/projective/projective_subscheme.py b/src/sage/schemes/projective/projective_subscheme.py
--- a/src/sage/schemes/projective/projective_subscheme.py
+++ b/src/sage/schemes/projective/projective_subscheme.py
@@ -1404,3 +1404,101 @@ def Chow_form(self):
         rel2 = rel + [CF]
         assert all(f in rel2 for f in CH.gens()), "did not find a principal generator"
         return alp(CF)
+
+    def global_height(self, prec=None):
+        """
+        Return the (projective) global height of the subscheme.
+
+        INPUT:
+
+        - ``prec`` -- desired floating point precision (default:
+          default ``RealField`` precision).
+
+        OUTPUT:
+
+        - a real number.
+
+        EXAMPLES::
+
+            sage: R.<x> = QQ[]
+            sage: NF.<a> = NumberField(x^2 - 5)
+            sage: P.<x,y,z> = ProjectiveSpace(NF, 2)
+            sage: X = P.subscheme([x^2 + y*z, 2*y*z, 3*x*y])
+            sage: X.global_height()
+            0.000000000000000
+
+        ::
+
+            sage: P.<x,y,z> = ProjectiveSpace(QQ, 2)
+            sage: X = P.subscheme([z^2 - 101*y^2 - 3*x*z])
+            sage: X.global_height() # long time
+            4.61512051684126
+        """
+        return self.Chow_form().global_height(prec)
+
+    def local_height(self, v, prec=None):
+        """
+        Return the (projective) local height of the subscheme.
+
+        INPUT:
+
+        - ``v`` -- a prime or prime ideal of the base ring.
+
+        - ``prec`` -- desired floating point precision (default:
+          default ``RealField`` precision).
+
+        OUTPUT:
+
+        - a real number.
+
+        EXAMPLES::
+
+            sage: R.<x> = QQ[]
+            sage: NF.<a> = NumberField(x^2 - 5)
+            sage: I = NF.ideal(3)
+            sage: P.<x,y,z> = ProjectiveSpace(NF, 2)
+            sage: X = P.subscheme([3*x*y - 5*x*z, y^2])
+            sage: X.local_height(I)
+            0.000000000000000
+
+        ::
+
+            sage: P.<x,y,z> = ProjectiveSpace(QQ, 2)
+            sage: X = P.subscheme([z^2 - 101*y^2 - 3*x*z])
+            sage: X.local_height(2)
+            0.000000000000000
+        """
+        return self.Chow_form().local_height(v, prec)
+
+    def local_height_arch(self, i, prec=None):
+        """
+        Return the local height at the ``i``-th infinite place of the subscheme.
+
+        INPUT:
+
+        - ``i`` -- an integer.
+
+        - ``prec`` -- desired floating point precision (default:
+          default ``RealField`` precision).
+
+        OUTPUT:
+
+        - a real number.
+
+        EXAMPLES::
+
+            sage: R.<x> = QQ[]
+            sage: NF.<a> = NumberField(x^2 - 5)
+            sage: P.<x,y,z> = ProjectiveSpace(NF, 2)
+            sage: X = P.subscheme([x^2 + y*z, 3*x*y])
+            sage: X.local_height_arch(1)
+            0.0000000000000000000000000000000
+
+        ::
+
+            sage: P.<x,y,z> = ProjectiveSpace(QQ, 2)
+            sage: X = P.subscheme([z^2 - 101*y^2 - 3*x*z])
+            sage: X.local_height_arch(1)
+            4.61512051684126
+        """
+        return self.Chow_form().local_height_arch(i, prec)
\ No newline at end of file


Test patch: