How to describe commutative rules in prolog?Alternative to express “Commutativity” in Prolog?Trying to implement commutativity in PrologHow to write prolog rule?Commutativity of disjunction in PrologUse Rule with in a Rule in PrologProlog - Describe facts and rulesCommutativity of Cut Operator in PrologHow to identify wasteful representations of Prolog termshow to change into rule (Prolog)Creating new rules

Use cases for M-0 & C-0?

How to avoid theft of potentially patentable IP when trying to obtain a Ph.D?

Why/when is AC-DC-AC conversion superior to direct AC-AC conversion?

Symplectisation as a functor between appropriate categories

Are there any examples of technologies have been lost over time?

Why is drive/partition number still used?

Why was Sauron preparing for war instead of trying to find the ring?

How to get CPU-G to run on 18.04

Sea level static test of an upper stage possible?

Correlation length anisotropy in the 2D Ising model

Why is it considered Acid Rain with pH <5.6

The best place for swimming in Arctic Ocean

What is the most efficient way to write 'for' loops in Matlab?

What do I do with a party that is much stronger than their level?

What language is Raven using for her attack in the new 52?

If a 2019 UA artificer has the Repeating Shot infusion on two hand crossbows, can they use two-weapon fighting?

What is the most common end of life issue for a car?

Heisenberg uncertainty principle in daily life

Craving for food?

How to store my pliers and wire cutters on my desk?

Catan Victory points

Could the rotation of a black hole cause other planets to rotate?

Vertical tennis ball into fancy new enumerate

How should we understand λαμβάνω in John 5:34?



How to describe commutative rules in prolog?


Alternative to express “Commutativity” in Prolog?Trying to implement commutativity in PrologHow to write prolog rule?Commutativity of disjunction in PrologUse Rule with in a Rule in PrologProlog - Describe facts and rulesCommutativity of Cut Operator in PrologHow to identify wasteful representations of Prolog termshow to change into rule (Prolog)Creating new rules






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








4















I intend to describe "a rule is commutative" in my database, an immediate idea is that like the code.



certain_rule(X,Y) :- X = struct(_X,Others) , Y = some_process_base_on(_X).
certain_rule(Y,X) :- X = struct(_X,Others) , Y = some_process_base_on(_X).


But if X is unbound, it will make X bind with struct(_X,Others) directly, then some_process_base_on(_X) will be unknown. Now my solution is insert compound(X) before breakdown X.



Usually, compound/1 is not strict enough, something unexpected will be taken in, functor/3 may be a better solution but too many rules will exist since too many functors I need to compare, even if I use member/2 to find functor in list I still construct too many combination.



Is there any better way to describe 'commutative', BTW, is there any better way to screen some specified structures out?










share|improve this question






























    4















    I intend to describe "a rule is commutative" in my database, an immediate idea is that like the code.



    certain_rule(X,Y) :- X = struct(_X,Others) , Y = some_process_base_on(_X).
    certain_rule(Y,X) :- X = struct(_X,Others) , Y = some_process_base_on(_X).


    But if X is unbound, it will make X bind with struct(_X,Others) directly, then some_process_base_on(_X) will be unknown. Now my solution is insert compound(X) before breakdown X.



    Usually, compound/1 is not strict enough, something unexpected will be taken in, functor/3 may be a better solution but too many rules will exist since too many functors I need to compare, even if I use member/2 to find functor in list I still construct too many combination.



    Is there any better way to describe 'commutative', BTW, is there any better way to screen some specified structures out?










    share|improve this question


























      4












      4








      4


      1






      I intend to describe "a rule is commutative" in my database, an immediate idea is that like the code.



      certain_rule(X,Y) :- X = struct(_X,Others) , Y = some_process_base_on(_X).
      certain_rule(Y,X) :- X = struct(_X,Others) , Y = some_process_base_on(_X).


      But if X is unbound, it will make X bind with struct(_X,Others) directly, then some_process_base_on(_X) will be unknown. Now my solution is insert compound(X) before breakdown X.



      Usually, compound/1 is not strict enough, something unexpected will be taken in, functor/3 may be a better solution but too many rules will exist since too many functors I need to compare, even if I use member/2 to find functor in list I still construct too many combination.



      Is there any better way to describe 'commutative', BTW, is there any better way to screen some specified structures out?










      share|improve this question
















      I intend to describe "a rule is commutative" in my database, an immediate idea is that like the code.



      certain_rule(X,Y) :- X = struct(_X,Others) , Y = some_process_base_on(_X).
      certain_rule(Y,X) :- X = struct(_X,Others) , Y = some_process_base_on(_X).


      But if X is unbound, it will make X bind with struct(_X,Others) directly, then some_process_base_on(_X) will be unknown. Now my solution is insert compound(X) before breakdown X.



      Usually, compound/1 is not strict enough, something unexpected will be taken in, functor/3 may be a better solution but too many rules will exist since too many functors I need to compare, even if I use member/2 to find functor in list I still construct too many combination.



      Is there any better way to describe 'commutative', BTW, is there any better way to screen some specified structures out?







      prolog






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 26 at 21:33









      Paulo Moura

      13.5k2 gold badges14 silver badges26 bronze badges




      13.5k2 gold badges14 silver badges26 bronze badges










      asked Mar 26 at 18:28









      LuLiLuLi

      215 bronze badges




      215 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          1














          First, note that your clauses are equivalent to writing:



          certain_rule(struct(X,_), some_process_base_on(X)).
          certain_rule(some_process_base_on(X), struct(X,_)).


          A possible solution to screen for valid structures is to use a table of valid structures. For example:



          valid_structure(-) :-
          !,
          fail.
          valid_structure(struct(_,_)).
          valid_structure(some_process_base_on(_)).
          ...


          The first clause will screen out variables while preserving first-argument indexing for the predicate. You could then define a gatekeeper predicate:



          certain_rule_gatekeeper(X, Y) :-
          once((valid_structure(X); valid_structure(Y))),
          certain_rule(X, Y).


          To address commutativity, would a definition such as the following would work in your specific case?



          certain_rule_gatekeeper(X, Y) :-
          once((valid_structure(X); valid_structure(Y))),
          once((certain_rule(X, Y); certain_rule(Y, X))).


          Sample calls using just one of the clauses above for the certain_rule/2 predicate (thus avoiding duplicated information):



          | ?- certain_rule_gatekeeper(X, Y). 
          no

          | ?- certain_rule_gatekeeper(struct(X,_), Y).
          Y = some_process_base_on(X)
          yes

          | ?- certain_rule_gatekeeper(Y, struct(X,_)).
          Y = some_process_base_on(X)
          yes

          | ?- certain_rule_gatekeeper(some_process_base_on(X), Y).
          Y = struct(X,_)
          yes

          | ?- certain_rule_gatekeeper(Y, some_process_base_on(X)).
          Y = struct(X,_)
          yes





          share|improve this answer




















          • 1





            It was helpful for a lot, except that I need to call the rule to get some values, so commutativity in gatekeeper doesn't work, but base on the solution that implement screen by defining various valid_structure/1 facts have solved almost all the problem.Thanks very much.

            – LuLi
            Mar 26 at 23:38











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55363995%2fhow-to-describe-commutative-rules-in-prolog%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          First, note that your clauses are equivalent to writing:



          certain_rule(struct(X,_), some_process_base_on(X)).
          certain_rule(some_process_base_on(X), struct(X,_)).


          A possible solution to screen for valid structures is to use a table of valid structures. For example:



          valid_structure(-) :-
          !,
          fail.
          valid_structure(struct(_,_)).
          valid_structure(some_process_base_on(_)).
          ...


          The first clause will screen out variables while preserving first-argument indexing for the predicate. You could then define a gatekeeper predicate:



          certain_rule_gatekeeper(X, Y) :-
          once((valid_structure(X); valid_structure(Y))),
          certain_rule(X, Y).


          To address commutativity, would a definition such as the following would work in your specific case?



          certain_rule_gatekeeper(X, Y) :-
          once((valid_structure(X); valid_structure(Y))),
          once((certain_rule(X, Y); certain_rule(Y, X))).


          Sample calls using just one of the clauses above for the certain_rule/2 predicate (thus avoiding duplicated information):



          | ?- certain_rule_gatekeeper(X, Y). 
          no

          | ?- certain_rule_gatekeeper(struct(X,_), Y).
          Y = some_process_base_on(X)
          yes

          | ?- certain_rule_gatekeeper(Y, struct(X,_)).
          Y = some_process_base_on(X)
          yes

          | ?- certain_rule_gatekeeper(some_process_base_on(X), Y).
          Y = struct(X,_)
          yes

          | ?- certain_rule_gatekeeper(Y, some_process_base_on(X)).
          Y = struct(X,_)
          yes





          share|improve this answer




















          • 1





            It was helpful for a lot, except that I need to call the rule to get some values, so commutativity in gatekeeper doesn't work, but base on the solution that implement screen by defining various valid_structure/1 facts have solved almost all the problem.Thanks very much.

            – LuLi
            Mar 26 at 23:38
















          1














          First, note that your clauses are equivalent to writing:



          certain_rule(struct(X,_), some_process_base_on(X)).
          certain_rule(some_process_base_on(X), struct(X,_)).


          A possible solution to screen for valid structures is to use a table of valid structures. For example:



          valid_structure(-) :-
          !,
          fail.
          valid_structure(struct(_,_)).
          valid_structure(some_process_base_on(_)).
          ...


          The first clause will screen out variables while preserving first-argument indexing for the predicate. You could then define a gatekeeper predicate:



          certain_rule_gatekeeper(X, Y) :-
          once((valid_structure(X); valid_structure(Y))),
          certain_rule(X, Y).


          To address commutativity, would a definition such as the following would work in your specific case?



          certain_rule_gatekeeper(X, Y) :-
          once((valid_structure(X); valid_structure(Y))),
          once((certain_rule(X, Y); certain_rule(Y, X))).


          Sample calls using just one of the clauses above for the certain_rule/2 predicate (thus avoiding duplicated information):



          | ?- certain_rule_gatekeeper(X, Y). 
          no

          | ?- certain_rule_gatekeeper(struct(X,_), Y).
          Y = some_process_base_on(X)
          yes

          | ?- certain_rule_gatekeeper(Y, struct(X,_)).
          Y = some_process_base_on(X)
          yes

          | ?- certain_rule_gatekeeper(some_process_base_on(X), Y).
          Y = struct(X,_)
          yes

          | ?- certain_rule_gatekeeper(Y, some_process_base_on(X)).
          Y = struct(X,_)
          yes





          share|improve this answer




















          • 1





            It was helpful for a lot, except that I need to call the rule to get some values, so commutativity in gatekeeper doesn't work, but base on the solution that implement screen by defining various valid_structure/1 facts have solved almost all the problem.Thanks very much.

            – LuLi
            Mar 26 at 23:38














          1












          1








          1







          First, note that your clauses are equivalent to writing:



          certain_rule(struct(X,_), some_process_base_on(X)).
          certain_rule(some_process_base_on(X), struct(X,_)).


          A possible solution to screen for valid structures is to use a table of valid structures. For example:



          valid_structure(-) :-
          !,
          fail.
          valid_structure(struct(_,_)).
          valid_structure(some_process_base_on(_)).
          ...


          The first clause will screen out variables while preserving first-argument indexing for the predicate. You could then define a gatekeeper predicate:



          certain_rule_gatekeeper(X, Y) :-
          once((valid_structure(X); valid_structure(Y))),
          certain_rule(X, Y).


          To address commutativity, would a definition such as the following would work in your specific case?



          certain_rule_gatekeeper(X, Y) :-
          once((valid_structure(X); valid_structure(Y))),
          once((certain_rule(X, Y); certain_rule(Y, X))).


          Sample calls using just one of the clauses above for the certain_rule/2 predicate (thus avoiding duplicated information):



          | ?- certain_rule_gatekeeper(X, Y). 
          no

          | ?- certain_rule_gatekeeper(struct(X,_), Y).
          Y = some_process_base_on(X)
          yes

          | ?- certain_rule_gatekeeper(Y, struct(X,_)).
          Y = some_process_base_on(X)
          yes

          | ?- certain_rule_gatekeeper(some_process_base_on(X), Y).
          Y = struct(X,_)
          yes

          | ?- certain_rule_gatekeeper(Y, some_process_base_on(X)).
          Y = struct(X,_)
          yes





          share|improve this answer















          First, note that your clauses are equivalent to writing:



          certain_rule(struct(X,_), some_process_base_on(X)).
          certain_rule(some_process_base_on(X), struct(X,_)).


          A possible solution to screen for valid structures is to use a table of valid structures. For example:



          valid_structure(-) :-
          !,
          fail.
          valid_structure(struct(_,_)).
          valid_structure(some_process_base_on(_)).
          ...


          The first clause will screen out variables while preserving first-argument indexing for the predicate. You could then define a gatekeeper predicate:



          certain_rule_gatekeeper(X, Y) :-
          once((valid_structure(X); valid_structure(Y))),
          certain_rule(X, Y).


          To address commutativity, would a definition such as the following would work in your specific case?



          certain_rule_gatekeeper(X, Y) :-
          once((valid_structure(X); valid_structure(Y))),
          once((certain_rule(X, Y); certain_rule(Y, X))).


          Sample calls using just one of the clauses above for the certain_rule/2 predicate (thus avoiding duplicated information):



          | ?- certain_rule_gatekeeper(X, Y). 
          no

          | ?- certain_rule_gatekeeper(struct(X,_), Y).
          Y = some_process_base_on(X)
          yes

          | ?- certain_rule_gatekeeper(Y, struct(X,_)).
          Y = some_process_base_on(X)
          yes

          | ?- certain_rule_gatekeeper(some_process_base_on(X), Y).
          Y = struct(X,_)
          yes

          | ?- certain_rule_gatekeeper(Y, some_process_base_on(X)).
          Y = struct(X,_)
          yes






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 26 at 21:58

























          answered Mar 26 at 21:50









          Paulo MouraPaulo Moura

          13.5k2 gold badges14 silver badges26 bronze badges




          13.5k2 gold badges14 silver badges26 bronze badges







          • 1





            It was helpful for a lot, except that I need to call the rule to get some values, so commutativity in gatekeeper doesn't work, but base on the solution that implement screen by defining various valid_structure/1 facts have solved almost all the problem.Thanks very much.

            – LuLi
            Mar 26 at 23:38













          • 1





            It was helpful for a lot, except that I need to call the rule to get some values, so commutativity in gatekeeper doesn't work, but base on the solution that implement screen by defining various valid_structure/1 facts have solved almost all the problem.Thanks very much.

            – LuLi
            Mar 26 at 23:38








          1




          1





          It was helpful for a lot, except that I need to call the rule to get some values, so commutativity in gatekeeper doesn't work, but base on the solution that implement screen by defining various valid_structure/1 facts have solved almost all the problem.Thanks very much.

          – LuLi
          Mar 26 at 23:38






          It was helpful for a lot, except that I need to call the rule to get some values, so commutativity in gatekeeper doesn't work, but base on the solution that implement screen by defining various valid_structure/1 facts have solved almost all the problem.Thanks very much.

          – LuLi
          Mar 26 at 23:38









          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55363995%2fhow-to-describe-commutative-rules-in-prolog%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript