Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3e287e9
WIP refactor experimental context
TurtlePU Sep 26, 2025
9870abf
fourmolu auto-commit
TurtlePU Sep 26, 2025
a5c6328
WIP experimental backend
TurtlePU Oct 1, 2025
c55cc4f
fourmolu auto-commit
TurtlePU Oct 1, 2025
f6d3057
WIP experimental backend compilation
TurtlePU Oct 2, 2025
6669b4c
fourmolu auto-commit
TurtlePU Oct 2, 2025
ae05f5f
WIP almost finished with node compilation
TurtlePU Oct 2, 2025
1bbe873
fourmolu auto-commit
TurtlePU Oct 2, 2025
e20cc07
working on hash computation
TurtlePU Oct 6, 2025
9326b8d
fourmolu auto-commit
TurtlePU Oct 6, 2025
0780b69
fourmolu auto-commit
sourabhxyz Sep 26, 2025
d22ec48
rm diff
TurtlePU Oct 9, 2025
f0d7674
- Children
TurtlePU Oct 9, 2025
fcb6b03
experimental backend DONE
TurtlePU Oct 9, 2025
eb819dd
fourmolu auto-commit
TurtlePU Oct 9, 2025
3857d79
move stuff around
TurtlePU Oct 9, 2025
e0e676a
fourmolu auto-commit
TurtlePU Oct 9, 2025
89791a5
fixed witness extractor
TurtlePU Oct 10, 2025
a82e424
migrated to HashTables
TurtlePU Oct 10, 2025
d1fad48
migrated to list polynomials
TurtlePU Oct 10, 2025
60be455
fourmolu auto-commit
TurtlePU Oct 10, 2025
62eb4fa
list polynomials -> polynomial expressions
TurtlePU Oct 15, 2025
4f56afa
fourmolu auto-commit
TurtlePU Oct 15, 2025
ee334df
+ separate Node module
TurtlePU Oct 17, 2025
714af0f
+ Experimental module is back
TurtlePU Oct 17, 2025
fcfc261
fixed Experimental benchmark
TurtlePU Oct 17, 2025
398db8a
add experimental backend benchmark to CI
TurtlePU Oct 17, 2025
2bb0bf8
fourmolu auto-commit
TurtlePU Oct 17, 2025
646e174
+ comments
TurtlePU Oct 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/main-pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ jobs:
- name: Benchmark compiler performance
run: cabal bench bench-compiler-performance

- name: Benchmark experimental compiler performance
run: cabal bench experimental-backend

- name: Benchmark polynomial multiplication
run: cabal bench bench-poly-mul

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{-# LANGUAGE BlockArguments #-}

module ZkFold.Algebra.Polynomial.Multivariate.Expression (Polynomial, evalPoly) where

import Control.Applicative (Applicative (..))
import Data.Foldable (Foldable)
import Data.Function ((.))
import Data.Functor (Functor, (<$>))
import Data.Traversable (Traversable)
import Numeric.Natural (Natural)

import ZkFold.Algebra.Class

data Polynomial a v
= PVar v
| PConst a
| Polynomial a v :+ Polynomial a v
| Polynomial a v :* Polynomial a v
deriving (Foldable, Functor, Traversable)

evalPoly :: Algebra a b => Polynomial a v -> (v -> b) -> b
evalPoly (PVar i) x = x i
evalPoly (PConst c) _ = fromConstant c
evalPoly (p :+ q) x = evalPoly p x + evalPoly q x
evalPoly (p :* q) x = evalPoly p x * evalPoly q x

instance Ring a => Applicative (Polynomial a) where
pure = PVar
fs <*> xs = evalPoly fs (<$> xs)

instance Zero a => Zero (Polynomial a v) where
zero = PConst zero

instance FromConstant c a => Scale c (Polynomial a v)

instance AdditiveSemigroup (Polynomial a v) where
(+) = (:+)

instance (FromConstant Natural a, Zero a) => AdditiveMonoid (Polynomial a v)

instance Ring a => AdditiveGroup (Polynomial a v) where
negate = scale (negate one :: a)

instance MultiplicativeSemigroup (Polynomial a v) where
(*) = (:*)

instance MultiplicativeMonoid a => MultiplicativeMonoid (Polynomial a v) where
one = fromConstant (one :: a)

instance FromConstant c a => FromConstant c (Polynomial a v) where
fromConstant = PConst . fromConstant

instance MultiplicativeMonoid a => Exponent (Polynomial a v) Natural where
(^) = natPow

instance {-# OVERLAPPING #-} FromConstant (Polynomial a v) (Polynomial a v)

instance {-# OVERLAPPING #-} Scale (Polynomial a v) (Polynomial a v)

instance Semiring a => Semiring (Polynomial a v)

instance Ring a => Ring (Polynomial a v)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module ZkFold.ArithmeticCircuit.Experimental where
module ZkFold.ArithmeticCircuit.Elem where

import Control.Applicative (pure)
import Control.DeepSeq (NFData (..), NFData1, liftRnf, rwhnf)
Expand All @@ -25,10 +25,9 @@ import Data.Ord (Ord (..))
import Data.Semigroup (Semigroup, (<>))
import Data.Semigroup.Generic (GenericSemigroupMonoid (..))
import qualified Data.Set as S
import Data.Traversable (traverse)
import Data.Traversable (Traversable, traverse)
import Data.Tuple (swap, uncurry)
import Data.Type.Equality (type (~))
import Data.Typeable (Typeable)
import GHC.Generics (Generic, Par1 (..), U1, (:*:) (..))
import Optics (zoom)
import Prelude (error)
Expand Down Expand Up @@ -95,10 +94,7 @@ newtype Polynomial a v = MkPolynomial

--------------- Type-preserving lookup constraint representation ---------------

data LookupEntry v
= forall f.
(Functor f, Foldable f, NFData1 f, Typeable f) =>
LEntry (f v) (LookupTable f)
data LookupEntry v = forall f. Traversable f => LEntry (f v) (LookupTable f)

------------- Box of constraints supporting efficient concatenation ------------

Expand Down
Loading