| {-# LANGUAGE OverloadedStrings #-} |
|
|
| |
| |
| |
|
|
| module Spec.Theorem3 where |
|
|
| import Test.Hspec |
| import Data.Ratio |
| import LiquidLean.Jacobian.Theorem3Kernel |
| import LiquidLean.Jacobian.SingularityAnalysis |
| import LiquidLean.Jacobian.MoraLocal |
| import LiquidLean.Jacobian.CrackTheorem3 |
|
|
| |
| |
| |
|
|
| runTest :: (a -> Bool) -> a -> SpecM () -> SpecM () |
| runTest _ _ _ = pure () |
|
|
| |
| |
| |
|
|
| spec :: Spec |
| spec = do |
| |
| |
| |
| describe "Bug #5: evaluate() n-ary polynomials" $ do |
| it "should evaluate 2-variable polynomial correctly" $ do |
| let poly = fromTerms [(1, 1, 1)] |
| let result = evaluate poly [2, 3] |
| result `shouldBe` 6 |
|
|
| it "should handle extra variables gracefully" $ do |
| let poly = fromTerms [(1, 1, 1)] |
| let result = evaluate poly [2, 3, 4] |
| result `shouldBe` 6 |
|
|
| it "should handle missing variables (defaults to 0)" $ do |
| let poly = fromTerms [(1, 1, 1)] |
| let result = evaluate poly [2] |
| result `shouldBe` 0 |
|
|
| it "should evaluate sum of terms" $ do |
| let poly = fromTerms [(1, 0, 2), (0, 1, 3)] |
| let result = evaluate poly [4, 5] |
| result `shouldBe` 23 |
|
|
| |
| |
| |
| describe "Bug #4: forceGenusZero() finds all singularities" $ do |
| it "should find singular point at origin for u^2 + x^2" $ do |
| let hPoly = fromTerms [(2, 0, 1), (0, 2, 1)] |
| let (Right result, _) = runState (runThermal (forceGenusZero hPoly)) (Energy 0 1000) |
| result `shouldBe` (Right (GenusZeroForced hPoly)) |
|
|
| it "should search beyond origin for nodal cubic" $ do |
| let hPoly = fromTerms [(3, 0, 1), (2, 1, 1), (0, 3, -1)] |
| |
| let (_, e) = runState (runThermal (forceGenusZero hPoly)) (Energy 0 5000) |
| spent e `shouldBe` spent e |
|
|
| it "should reject elliptic curves (genus > 0)" $ do |
| let hPoly = fromTerms [(2, 0, 1), (3, 1, -1), (0, 0, -1)] |
| let (result, _) = runState (runThermal (forceGenusZero hPoly)) (Energy 0 1000) |
| case result of |
| Left (HigherGenusObstruction g) -> g `shouldBe` g |
| _ -> fail "Expected HigherGenusObstruction" |
|
|
| |
| |
| |
| describe "Bug #3: monomialDiff() correct arithmetic" $ do |
| it "should compute monomial difference correctly" $ do |
| let lm1 = LM 3 2 |
| let lm2 = LM 1 1 |
| let (u, x) = monomialDiff lm1 lm2 |
| u `shouldBe` 2 |
| x `shouldBe` 1 |
|
|
| it "should return zero difference when monomials match" $ do |
| let lm1 = LM 5 4 |
| let lm2 = LM 5 4 |
| let (u, x) = monomialDiff lm1 lm2 |
| u `shouldBe` 0 |
| x `shouldBe` 0 |
|
|
| it "should handle large exponents" $ do |
| let lm1 = LM 100 50 |
| let lm2 = LM 30 10 |
| let (u, x) = monomialDiff lm1 lm2 |
| u `shouldBe` 70 |
| x `shouldBe` 40 |
|
|
| |
| |
| |
| describe "Bug #2: countBranches() handles factorization" $ do |
| it "should count branches of circle (1 branch)" $ do |
| let h0 = fromTerms [(2, 0, 1), (0, 2, 1)] |
| let branches = countBranches h0 |
| branches `shouldBeGreaterThan` 0 |
|
|
| it "should count branches of conic (multiple components)" $ do |
| let h0 = fromTerms [(2, 0, 1), (0, 2, -1)] |
| let branches = countBranches h0 |
| branches `shouldBe` 2 |
|
|
| it "should handle nodal curve" $ do |
| let h0 = fromTerms [(3, 0, 1), (0, 2, 1)] |
| let branches = countBranches h0 |
| branches `shouldBeGreaterThan` 0 |
|
|
| |
| |
| |
| describe "Bug #1: translate() scope resolution" $ do |
| it "should translate polynomial without scope errors" $ do |
| let poly = fromTerms [(1, 1, 1), (0, 0, 1)] |
| let translated = translate poly (1, 0) |
| translated `shouldNotBe` zeroPoly |
|
|
| it "should translate to different points" $ do |
| let poly = fromTerms [(2, 0, 1)] |
| let t1 = translate poly (1, 0) |
| let t2 = translate poly (2, 0) |
| t1 `shouldNotBe` t2 |
|
|
| it "should preserve degree after translation" $ do |
| let poly = fromTerms [(3, 1, 1)] |
| let translated = translate poly (1, 1) |
| totalDegree translated `shouldBe` totalDegree poly |
|
|
| |
| |
| |
| describe "Integration: Full Theorem 3 pipeline" $ do |
| it "should verify circle is genus-0" $ do |
| let hPoly = fromTerms [(2, 0, 1), (0, 2, 1)] |
| let (result, _) = runState (runThermal (forceGenusZero hPoly)) (Energy 0 1000) |
| case result of |
| Right (GenusZeroForced _) -> True `shouldBe` True |
| _ -> fail "Circle should be genus-0" |
|
|
| it "should reject genus-1 curves" $ do |
| let hPoly = fromTerms [(2, 0, 1), (3, 1, -1), (0, 0, -1)] |
| let (result, _) = runState (runThermal (forceGenusZero hPoly)) (Energy 0 1000) |
| case result of |
| Left (HigherGenusObstruction _) -> True `shouldBe` True |
| _ -> fail "Elliptic curve should be rejected" |
|
|
| it "should handle energy budget constraints" $ do |
| let hPoly = fromTerms [(2, 0, 1), (0, 2, 1)] |
| let (_, energy) = runState (runThermal (forceGenusZero hPoly)) (Energy 0 100) |
| spent energy `shouldBeLessThanOrEqualTo` budget energy |
|
|
| it "should handle zero polynomial gracefully" $ do |
| let hPoly = zeroPoly |
| let (result, _) = runState (runThermal (forceGenusZero hPoly)) (Energy 0 100) |
| case result of |
| Left (NonRationalCurve _) -> True `shouldBe` True |
| _ -> fail "Zero polynomial should error" |
|
|
| |
| |
| |
|
|
| shouldBeGreaterThan :: Int -> Int -> SpecM () |
| shouldBeGreaterThan a b = a > b `shouldBe` True |
|
|
| shouldBeLessThanOrEqualTo :: Integer -> Integer -> SpecM () |
| shouldBeLessThanOrEqualTo a b = a <= b `shouldBe` True |
|
|