calculate the degree of gate constraints

This commit is contained in:
Balazs Komuves 2024-12-15 15:28:50 +01:00
parent e49a0cfdba
commit 4b34d8df89
No known key found for this signature in database
GPG Key ID: F63B7AEF18435562
3 changed files with 19 additions and 2 deletions

View File

@ -124,6 +124,18 @@ straightLineOperCount (MkStraightLine{..}) = final where
coms = map exprOperCount $ commits
final = mconcat defs <> mconcat coms
-- | Maximum degree of a gate's constraints
constraintDegree :: StraightLine -> Int
constraintDegree (MkStraightLine{..}) = maxdeg where
ndefs = length localdefs
table = array (0,ndefs-1) [ (i, exprDegree lkp rhs) | MkLocalDef i _ rhs <- localdefs ]
lkp var = case var of
LocalVar i _ -> table!i
ProofVar v -> case v of { PIV {} -> 0 ; _ -> 1 }
maxdeg = case commits of
[] -> 0
_ -> maximum (map (exprDegree lkp) commits)
--------------------------------------------------------------------------------
type Scope a = IntMap a

View File

@ -18,7 +18,7 @@ data PlonkyVar
= SelV Int -- ^ selector variable
| ConstV Int -- ^ constant variable
| WireV Int -- ^ wire variable
| PIV Int -- ^ public input hash variable
| PIV Int -- ^ public input hash variable (technically these are constants, not variables)
deriving (Eq,Ord,Show)
instance Pretty PlonkyVar where

View File

@ -70,6 +70,11 @@ test_fibonacci = do
let pubio_prg = gateProgram (PublicInputGate )
let const_prg = gateProgram (ConstantGate 2)
putStrLn $ "maximum degree of constraints in ArithmeticGate = " ++ show (constraintDegree arith_prg)
putStrLn $ "maximum degree of constraints in PosiedonGate = " ++ show (constraintDegree posei_prg)
putStrLn $ "maximum degree of constraints in PublicInputGate = " ++ show (constraintDegree pubio_prg)
putStrLn $ "maximum degree of constraints in ConstGate = " ++ show (constraintDegree const_prg)
let arith_evals = runStraightLine (fmap fromBase arith_row) arith_prg
let posei_evals = runStraightLine (fmap fromBase posei_row) posei_prg
let const_evals = runStraightLine (fmap fromBase const_row) const_prg
@ -92,5 +97,5 @@ test_fibonacci = do
--------------------------------------------------------------------------------
main :: IO
main :: IO ()
main = test_fibonacci