reverse - How to make a fact work both way in Prolog (takes arguments in any order)? -


I want to define the facts that are correct in both ways (they all have the faith of 2). I found success with the fact that the "opposite" relationship was expressed by this fact:
  Contrast Deficiency (Plus, Loans). Contrast (X, Y): - Contrast Deficit (Y, X). Contrast (X, Y): - Inverted decline (X, Y).   

I am trying to create a simple equation solver, and I would also like to define if A = B then B = A I just can not write: < pre> equal (a, b): - equal (b, a).

Because I exit the local stack error. Although I can not do that as I did with the "opposite" fact because on some rules it is necessary to work "equal" ("opposite" only got input from the facts).

Is there any way I would like to avoid defining the two rules of "equal"?

Edit:

I just want to declare general mathematical facts to see if I have to solve other more complex tasks. I can use Prolog, where I do not know the mechanism to solve the simple facts only.

So far I have used to define things like equal / 2: if A = B + C, then C = AB I want to define two ways that thereby define me There is no need to do that if B + C = A, then A-B = C can ideally solve an equation for C after the new rule: a = (b + c) / d -> B + C = A / D - & gt; c = (a / d) -b

Reason I can not use swaps because I have recursive rules for equal / 2.

Keep in mind that this will not always work for simple equations, because not all the necessary facts are defined.

Here's the current program with a question:

  5? - equal (v, x). X = Opper (S, Per, T)% operators: per, bar, plus, minus% equation (LHS, RHS): Physics equation is used to declare% equal (LHS, RHS): query equation (S , Opr (v, times, t))% s = v * t equation (a, opr (opr (b, plus, c), per, d)). % A = (b + c) / d contrast decline (plus, minus). Contrast Deficiency (counter, bar) Contrast (X, Y): - Contrast Deficit (Y, X). Contrast (X, Y): - Inverted decline (x, y) is equal to (r, op (a, o, b)): - equation (r, opper (a, o, b)) if any equation is r = aob , R = AOB, where O is an operator (+ - * /) is equal to (a, op (r, oa, b)): - equal (r, op (a, ox, b)), opposite (o, OX), declaring at a time: if R = A / B then A = R * B, if R = AB then A = R + B, if R = A + B then A = RB, if R = AB then A = R + B    

I'm not sure that Not you understand correctly, but simple code you are not then?

  equal (X, X).   

Could you please show some sample input and output that you want to achieve using equal / 2 ?

And about the opposite, I will write it like this:

  Reversal Decrease (plus, debt) Reverse (good, evil) Reveal Declined Degradation (Window, Linux) Swap (P, X, Y): - Permutation ([x, y], [x1, y1]), call (p, x1, y1) Contrast (X, Y): - Swap (contrast, exclare, X, Y).   

Anytime you want to use predicate with arity 2 and try the arguments, you can use swap / 3 in the way given above You can.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -