MCPcopy Create free account
hub / github.com/PolyhedraZK/ExpanderCompilerCollection / SumRationalNumbers

Function SumRationalNumbers

circuit-std-go/logup/utils.go:29–57  ·  view source on GitHub ↗

Construct a binary summation tree to sum all the values

(api frontend.API, rs []RationalNumber)

Source from the content-addressed store, hash-verified

27
28// Construct a binary summation tree to sum all the values
29func SumRationalNumbers(api frontend.API, rs []RationalNumber) RationalNumber {
30 n := len(rs)
31 if n == 0 {
32 return RationalNumber{Numerator: 0, Denominator: 1}
33 }
34
35 if !IsPowerOf2(n) {
36 fmt.Println(n)
37 panic("The length of rs should be a power of 2")
38 }
39
40 cur := rs
41 next := make([]RationalNumber, 0)
42
43 for n > 1 {
44 n >>= 1
45 for i := 0; i < n; i++ {
46 next = append(next, cur[i*2].Add(api, &cur[i*2+1]))
47 }
48 cur = next
49 next = next[:0]
50 }
51
52 if len(cur) != 1 {
53 panic("Summation code may be wrong.")
54 }
55
56 return cur[0]
57}
58
59func SimpleMin(a uint, b uint) uint {
60 if a < b {

Callers 2

FinalCheckFunction · 0.70
CheckMethod · 0.70

Calls 3

IsPowerOf2Function · 0.85
PrintlnMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected