# Examples of flattening code to create an R1CS

When preparing logic for use in a zkSnark, one needs to first "flatten" the code so it can be written as a series of constraints.

I'm finding it hard to find examples of doing this. For instance, how would I do convert the following logic into a series of constraints:

if ((input_1 && input_2) || input_3) {
result = input_1 + input_2
} else {
result = input_3
}


How would you go about converting this into an arithmetic statement that can then be then re-written as a series of constraints? Or does there exist any examples of this sort of process that someone could learn from?

• In my opinion this is a pure programming question and is that's why off-topic here. Apr 16 '20 at 17:28
• Yes, you might be right actually. I'll try posting on Stack Overflow maybe. Thanks. Apr 16 '20 at 19:40

def main(field a, field b, field c) -> (field):