# How penalty function is formulated

**Penalty Function:**

While going through the examples of NOT and AND gate, not able to get how penalty function is getting formulated, is there any paper done on this or is it derivable from the output combination?

For AND gate: x1x2−2(x1+x2)z+3z.

For NOT gate: 2xz−x−z+1

If you have any documentation for formating this function or on what basis this is derived can someone please provide a link for the same.

**Problem statement on quantum:**

We are trying to evaluate one of our problem statement to use on Quantum to solve it or to find the best model to solve it on quantum.

Is it possible to do rule-based processing on Quantum?

**Problem:** The system is having a list of rules with ranking defined (rule can be categorized like for set1 there are plenty of rules, for set2 there are another plenty of rules), now when any entity comes and starts processing it will start applying rules based on ranking for each category and derive the end result.

The above functionality is generic functionality, but it is actually a claim processing steps like based on rules what amount of claim should be paid and denied.

**Note:** I have just started exploring the quantum capabilities, if anyone could help on this it would be great

## Comments

David J(Report)Hello,

For the above two examples of AND and NOT gates, one helpful tip is to create a truth table of the target variable values you want.

You can see the truth tables for the above two using the ExactSolver, as they have only a few variables.

Here is a code example for using the ExactSolver to give a truth table for the NOT gate:

Here is the output:

As you can see from this example, the valid states have lower energy.

Although this doesn't exactly outline an explicit strategy, it helps to reformulate how we think about the problems and solutions.

David J(Report)One approach that can be taken to implement the rule-based processing is using penalty models:

https://docs.ocean.dwavesys.com/projects/penaltymodel/en/latest/

It's possible to weight each of these penalty models independently so that they can be prioritized.

This post might also be useful, as it is a similar question about problem formulation:

https://support.dwavesys.com/hc/en-us/community/posts/360044154913-Trying-to-build-a-penalty-function-for-a-XOR-table

Lagrange parameters, as mentioned in this presentation could also be useful in setting softer, violable constraints:

https://www.dwavesys.com/media/vsufwv1d/14-1041a-a_setting_the_chain_strength.pdf

I hope this is helpful.

Please feel free to ask more questions or for clarification.

Kirlos Guerguis(Report)Thank you, David, Now I am able to understand how that penalty function was formulated for AND and NOT gate.

Please sign in to leave a comment.