First off, let me say that I am quite a beginner in Prolog. I can create simple rules and facts (I know how to, for example, recursively define the predecessor relation etc).
However, now I am given a problem where I am given four numbers 40, 10, 12, 30 and I need to add them via two rules (these numbers actually represent electrical resistances). I have these two rules:
series(R1,R2,Re) :- Re is R1 + R2.
parallel(R1,R2,Re) :- Re is ((R1 * R2) / (R1 + R2))
40 and 10 need to be added via the parallel rule, the total of them then needs to be added to 12 via the series rule, the sum of which needs to be added to 30 via the parallel rule.
I am completely stumped by how to do this. I have two main questions.
parallel(30,Rx,X).
Where of course Rx would be a numerical value. I know that if I input a query of this kind, I get the result as output.
Thank you for your time!
40 and 10 need to be added via the parallel rule, the total of them then needs to be added to 12 via the series rule, the sum of which needs to be added to 30 via the parallel rule.
These steps become this code:
some_rule_name_here(Answer) :-
parallel(40, 10, Step1),
series(Step1, 12, Step2),
parallel(Step2, 30, Answer).
Then query:
?- some_rule_name_here(X).