# 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: x1x22(x1+x2)z+3z.

For NOT gate: 2xzxz+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

• 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:

`from dimod import ExactSolversampler = ExactSolver()sampleset = sampler.sample_qubo({(0, 0):-1, (1, 1):-1, (0, 1):2})print(sampleset)`

Here is the output:

`  0 1   energy  num_oc.1 1 0   -1.0    13 0 1   -1.0    10 0 0    0.0    12 1 1    0.0    1['BINARY', 4 rows, 4 samples, 2 variables]`

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.

• 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/sites/default/files/04_Victoria%20Qubits%20Presentation.pdf