From e5627ead62a72382e29c153959676e237e6e9b95 Mon Sep 17 00:00:00 2001
From: Hunter Kippen <hunter.kippen@sandboxquantum.com>
Date: Wed, 1 Nov 2023 09:26:31 -0400
Subject: [PATCH] ntru.py: updated doctests. Changed *_parameters.homogeneous
 to _homogeneous

Doctests were changed in accordance with the updated homogeneity checks. Previously,
the +1 on line 261 of lwe_primal.py was removed, with the assumption that a homogeneous
instance would not need the additional dimension. This was a mistake, and improperly
gimping the dimension optimization functionality for homogeneous instances. This
commit rectifies this mistake by updating the doctests to be in line with the more
efficient implementation.
---
 estimator/lwe_parameters.py  |  2 +-
 estimator/lwe_primal.py      |  6 +++---
 estimator/ntru.py            | 14 +++++++-------
 estimator/ntru_parameters.py |  2 +-
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/estimator/lwe_parameters.py b/estimator/lwe_parameters.py
index 6043ad1..6822cba 100644
--- a/estimator/lwe_parameters.py
+++ b/estimator/lwe_parameters.py
@@ -31,7 +31,7 @@ def __post_init__(self, **kwds):
             self.Xe.n = self.m
 
     @property
-    def homogeneous(self):
+    def _homogeneous(self):
         return False
 
     def normalize(self):
diff --git a/estimator/lwe_primal.py b/estimator/lwe_primal.py
index 8127023..6f505f0 100644
--- a/estimator/lwe_primal.py
+++ b/estimator/lwe_primal.py
@@ -95,7 +95,7 @@ def cost_gsa(
         m = min(2 * ceil(sqrt(params.n * log(params.q) / log(delta))), m)
         tau = params.Xe.stddev if tau is None else tau
         # Account for homogeneous instances
-        if params.homogeneous:
+        if params._homogeneous:
             tau = False  # Tau false ==> instance is homogeneous
 
         d = PrimalUSVP._solve_for_d(params, m, beta, tau, xi) if d is None else d
@@ -139,7 +139,7 @@ def cost_simulator(
         xi = PrimalUSVP._xi_factor(params.Xs, params.Xe)
         tau = params.Xe.stddev if tau is None else tau
 
-        if params.homogeneous:
+        if params._homogeneous:
             tau = False
             d -= 1  # Remove extra dimension in homogeneous instances
 
@@ -344,7 +344,7 @@ def cost(
         # 1. Simulate BKZ-β
         # TODO: pick τ as non default value
 
-        if params.homogeneous:
+        if params._homogeneous:
             tau = False
             d -= 1
 
diff --git a/estimator/ntru.py b/estimator/ntru.py
index 53d0b2d..d9cdc37 100644
--- a/estimator/ntru.py
+++ b/estimator/ntru.py
@@ -41,7 +41,7 @@ def rough(self, params, jobs=1, catch_exceptions=True):
 
             >>> from estimator import *
             >>> _ = NTRU.estimate.rough(schemes.NTRUHPS2048509Enc)
-            usvp                 :: rop: ≈2^112.1, red: ≈2^112.1, δ: 1.004096, β: 384, d: 633, tag: usvp
+            usvp                 :: rop: ≈2^109.2, red: ≈2^109.2, δ: 1.004171, β: 374, d: 643, tag: usvp
 
         """
         params = params.normalize()
@@ -106,17 +106,17 @@ def __call__(
             >>> from estimator import *
             >>> _ = NTRU.estimate(schemes.NTRUHPS2048509Enc)
             usvp                 :: rop: ≈2^134.5, red: ≈2^134.5, δ: 1.004179, β: 373, d: 923, tag: usvp
-            bdd                  :: rop: ≈2^131.1, red: ≈2^130.1, svp: ≈2^130.2, β: 357, η: 390, d: 916, tag: bdd
-            bdd_hybrid           :: rop: ≈2^131.2, red: ≈2^130.2, svp: ≈2^130.2, β: 357, η: 390, ζ: 0, |S|: 1, ...
-            bdd_mitm_hybrid      :: rop: ≈2^185.9, red: ≈2^185.1, svp: ≈2^184.7, β: 371, η: 2, ζ: 159, ...
+            bdd                  :: rop: ≈2^130.9, red: ≈2^129.9, svp: ≈2^129.9, β: 356, η: 389, d: 917, tag: bdd
+            bdd_hybrid           :: rop: ≈2^130.9, red: ≈2^129.9, svp: ≈2^129.9, β: 356, η: 389, ζ: 0, |S|: 1, ...
+            bdd_mitm_hybrid      :: rop: ≈2^185.3, red: ≈2^184.5, svp: ≈2^184.2, β: 371, η: 2, ζ: 159, |S|: ≈2^228.0...
 
             >>> params = NTRU.Parameters(n=113, q=512, Xs=ND.UniformMod(3), Xe=ND.UniformMod(3))
             >>> _ = NTRU.estimate(params)
             usvp                 :: rop: ≈2^46.0, red: ≈2^46.0, δ: 1.011516, β: 59, d: 221, tag: usvp
             dsd                  :: rop: ≈2^37.9, red: ≈2^37.9, δ: 1.013310, β: 31, d: 226, tag: dsd
-            bdd                  :: rop: ≈2^42.8, red: ≈2^41.0, svp: ≈2^42.3, β: 41, η: 72, d: 227, tag: bdd
-            bdd_hybrid           :: rop: ≈2^42.8, red: ≈2^41.0, svp: ≈2^42.3, β: 41, η: 72, ζ: 0, |S|: 1, d: 227, ...
-            bdd_mitm_hybrid      :: rop: ≈2^56.1, red: ≈2^55.2, svp: ≈2^55.0, β: 41, η: 2, ζ: 32, |S|: ≈2^50.7, ...
+            bdd                  :: rop: ≈2^42.4, red: ≈2^41.0, svp: ≈2^41.8, β: 41, η: 70, d: 225, tag: bdd
+            bdd_hybrid           :: rop: ≈2^42.4, red: ≈2^41.0, svp: ≈2^41.8, β: 41, η: 70, ζ: 0, |S|: 1, d: 226, ...
+            bdd_mitm_hybrid      :: rop: ≈2^55.6, red: ≈2^54.7, svp: ≈2^54.6, β: 41, η: 2, ζ: 32, |S|: ≈2^50.7, ...
         """
         params = params.normalize()
 
diff --git a/estimator/ntru_parameters.py b/estimator/ntru_parameters.py
index e587103..c36f12b 100644
--- a/estimator/ntru_parameters.py
+++ b/estimator/ntru_parameters.py
@@ -33,7 +33,7 @@ def possibly_overstretched(self):
         return False
 
     @property
-    def homogeneous(self):
+    def _homogeneous(self):
         return True
 
     def normalize(self):