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

Function SumRationalNumbers

ecgo/examples/log_up/main.go:28–52  ·  view source on GitHub ↗

Construct a binary summation tree to sum all the values

(api frontend.API, vs []RationalNumber)

Source from the content-addressed store, hash-verified

26
27// Construct a binary summation tree to sum all the values
28func SumRationalNumbers(api frontend.API, vs []RationalNumber) RationalNumber {
29 n := len(vs)
30 if n == 0 {
31 return RationalNumber{Numerator: 0, Denominator: 1}
32 }
33
34 vvs := make([]RationalNumber, len(vs))
35 copy(vvs, vs)
36
37 n_values_to_sum := len(vvs)
38 for n_values_to_sum > 1 {
39 half_size_floor := n_values_to_sum / 2
40 for i := 0; i < half_size_floor; i++ {
41 vvs[i] = vvs[i].Add(api, &vvs[i+half_size_floor])
42 }
43
44 if n_values_to_sum&1 != 0 {
45 vvs[half_size_floor] = vvs[n_values_to_sum-1]
46 }
47
48 n_values_to_sum = (n_values_to_sum + 1) / 2
49 }
50
51 return vvs[0]
52}
53
54type LogUpCircuit struct {
55 TableKeys [][]frontend.Variable

Callers 1

LogUpPolyValsAtAlphaFunction · 0.70

Calls 2

copyFunction · 0.85
AddMethod · 0.45

Tested by

no test coverage detected