Prolog: identify if two functors are identical *without* variable binding The Next CEO of Stack Overflowprolog term without a functorIn Prolog, is a fact the same as a functor?Not fixed arity for a functor (Prolog)Parse To Prolog Variables Using DCGIn prolog, functors vs predicates, and goalsProlog Syntax Issue - Variable FunctorProlog checking if two lists are identicalBind variables to constants in PrologHow to identify wasteful representations of Prolog termsProlog variable as functor

When you upcast Blindness/Deafness, do all targets suffer the same effect?

Why does the flight controls check come before arming the autobrake on the A320?

Why is information "lost" when it got into a black hole?

Does soap repel water?

Is French Guiana a (hard) EU border?

Reference request: Grassmannian and Plucker coordinates in type B, C, D

Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?

Should I tutor a student who I know has cheated on their homework?

Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?

Why the difference in type-inference over the as-pattern in two similar function definitions?

A Man With a Stainless Steel Endoskeleton (like The Terminator) Fighting Cloaked Aliens Only He Can See

Are police here, aren't itthey?

If Nick Fury and Coulson already knew about aliens (Kree and Skrull) why did they wait until Thor's appearance to start making weapons?

Solving system of ODEs with extra parameter

How to get from Geneva Airport to Metabief?

Does increasing your ability score affect your main stat?

Chain wire methods together in Lightning Web Components

Why is quantifier elimination desirable for a given theory?

Where do students learn to solve polynomial equations these days?

Powershell. How to parse gci Name?

Why doesn't UK go for the same deal Japan has with EU to resolve Brexit?

Why this way of making earth uninhabitable in Interstellar?

Can MTA send mail via a relay without being told so?

Is micro rebar a better way to reinforce concrete than rebar?



Prolog: identify if two functors are identical *without* variable binding



The Next CEO of Stack Overflowprolog term without a functorIn Prolog, is a fact the same as a functor?Not fixed arity for a functor (Prolog)Parse To Prolog Variables Using DCGIn prolog, functors vs predicates, and goalsProlog Syntax Issue - Variable FunctorProlog checking if two lists are identicalBind variables to constants in PrologHow to identify wasteful representations of Prolog termsProlog variable as functor










2















So I have two lists:



[location(A),package(B)]


and



[location(C),package(B),truck(D)]


I want to add these together without adding identical terms. That is, the result should be



[location(A),package(B),location(C),truck(D)] %Package B doesn't get repeated


I can write my own remove_duplicates, but it will identify location(A) as matching location(C), and I need them both.



The purpose is to make a rule, later to be asserted, in which I may have multiple locations, packages, and trucks referenced. The rule contains variables so it can match different states/situations with locations, packages, and trucks specified. My learning algorithm adds preconditions to that rule as it searches for the right set of preconditions.



If this needs to be done with ground terms instead, I think I will have the problem that it must be variables at a later time.










share|improve this question



















  • 2





    p(B) == p(B). at the prompt succeeds, while p(B) == p(C). fails. This suggests you could use == in your predicate. (note that B=C, p(B) == p(C). succeeds, so do be careful not to unify any variables). and it is not "functors" but "compound terms" you're referring to -- it is p that is the functor in the compound term p(B).

    – Will Ness
    Mar 8 at 16:06












  • There may be a simpler way, but you could use =../2 to examine the term as a list, then compare each list element (arguments) using ==/2 rather than =/2.

    – lurker
    Mar 8 at 16:28











  • In practise it is often necessary to find reasonable tradeoffs, including some hacks to cut some corners. Having said that, it seems you start the architectural "phase one: modeling" off by searching for workarounds. Warning: there's trouble ahead!

    – repeat
    Mar 8 at 21:43












  • For instance, why you are sure about using (dynamic) asserted rules later on?

    – repeat
    Mar 8 at 21:47
















2















So I have two lists:



[location(A),package(B)]


and



[location(C),package(B),truck(D)]


I want to add these together without adding identical terms. That is, the result should be



[location(A),package(B),location(C),truck(D)] %Package B doesn't get repeated


I can write my own remove_duplicates, but it will identify location(A) as matching location(C), and I need them both.



The purpose is to make a rule, later to be asserted, in which I may have multiple locations, packages, and trucks referenced. The rule contains variables so it can match different states/situations with locations, packages, and trucks specified. My learning algorithm adds preconditions to that rule as it searches for the right set of preconditions.



If this needs to be done with ground terms instead, I think I will have the problem that it must be variables at a later time.










share|improve this question



















  • 2





    p(B) == p(B). at the prompt succeeds, while p(B) == p(C). fails. This suggests you could use == in your predicate. (note that B=C, p(B) == p(C). succeeds, so do be careful not to unify any variables). and it is not "functors" but "compound terms" you're referring to -- it is p that is the functor in the compound term p(B).

    – Will Ness
    Mar 8 at 16:06












  • There may be a simpler way, but you could use =../2 to examine the term as a list, then compare each list element (arguments) using ==/2 rather than =/2.

    – lurker
    Mar 8 at 16:28











  • In practise it is often necessary to find reasonable tradeoffs, including some hacks to cut some corners. Having said that, it seems you start the architectural "phase one: modeling" off by searching for workarounds. Warning: there's trouble ahead!

    – repeat
    Mar 8 at 21:43












  • For instance, why you are sure about using (dynamic) asserted rules later on?

    – repeat
    Mar 8 at 21:47














2












2








2








So I have two lists:



[location(A),package(B)]


and



[location(C),package(B),truck(D)]


I want to add these together without adding identical terms. That is, the result should be



[location(A),package(B),location(C),truck(D)] %Package B doesn't get repeated


I can write my own remove_duplicates, but it will identify location(A) as matching location(C), and I need them both.



The purpose is to make a rule, later to be asserted, in which I may have multiple locations, packages, and trucks referenced. The rule contains variables so it can match different states/situations with locations, packages, and trucks specified. My learning algorithm adds preconditions to that rule as it searches for the right set of preconditions.



If this needs to be done with ground terms instead, I think I will have the problem that it must be variables at a later time.










share|improve this question
















So I have two lists:



[location(A),package(B)]


and



[location(C),package(B),truck(D)]


I want to add these together without adding identical terms. That is, the result should be



[location(A),package(B),location(C),truck(D)] %Package B doesn't get repeated


I can write my own remove_duplicates, but it will identify location(A) as matching location(C), and I need them both.



The purpose is to make a rule, later to be asserted, in which I may have multiple locations, packages, and trucks referenced. The rule contains variables so it can match different states/situations with locations, packages, and trucks specified. My learning algorithm adds preconditions to that rule as it searches for the right set of preconditions.



If this needs to be done with ground terms instead, I think I will have the problem that it must be variables at a later time.







prolog






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 21:33









repeat

16.2k443139




16.2k443139










asked Mar 8 at 15:39









Topological SortTopological Sort

1,5791432




1,5791432







  • 2





    p(B) == p(B). at the prompt succeeds, while p(B) == p(C). fails. This suggests you could use == in your predicate. (note that B=C, p(B) == p(C). succeeds, so do be careful not to unify any variables). and it is not "functors" but "compound terms" you're referring to -- it is p that is the functor in the compound term p(B).

    – Will Ness
    Mar 8 at 16:06












  • There may be a simpler way, but you could use =../2 to examine the term as a list, then compare each list element (arguments) using ==/2 rather than =/2.

    – lurker
    Mar 8 at 16:28











  • In practise it is often necessary to find reasonable tradeoffs, including some hacks to cut some corners. Having said that, it seems you start the architectural "phase one: modeling" off by searching for workarounds. Warning: there's trouble ahead!

    – repeat
    Mar 8 at 21:43












  • For instance, why you are sure about using (dynamic) asserted rules later on?

    – repeat
    Mar 8 at 21:47













  • 2





    p(B) == p(B). at the prompt succeeds, while p(B) == p(C). fails. This suggests you could use == in your predicate. (note that B=C, p(B) == p(C). succeeds, so do be careful not to unify any variables). and it is not "functors" but "compound terms" you're referring to -- it is p that is the functor in the compound term p(B).

    – Will Ness
    Mar 8 at 16:06












  • There may be a simpler way, but you could use =../2 to examine the term as a list, then compare each list element (arguments) using ==/2 rather than =/2.

    – lurker
    Mar 8 at 16:28











  • In practise it is often necessary to find reasonable tradeoffs, including some hacks to cut some corners. Having said that, it seems you start the architectural "phase one: modeling" off by searching for workarounds. Warning: there's trouble ahead!

    – repeat
    Mar 8 at 21:43












  • For instance, why you are sure about using (dynamic) asserted rules later on?

    – repeat
    Mar 8 at 21:47








2




2





p(B) == p(B). at the prompt succeeds, while p(B) == p(C). fails. This suggests you could use == in your predicate. (note that B=C, p(B) == p(C). succeeds, so do be careful not to unify any variables). and it is not "functors" but "compound terms" you're referring to -- it is p that is the functor in the compound term p(B).

– Will Ness
Mar 8 at 16:06






p(B) == p(B). at the prompt succeeds, while p(B) == p(C). fails. This suggests you could use == in your predicate. (note that B=C, p(B) == p(C). succeeds, so do be careful not to unify any variables). and it is not "functors" but "compound terms" you're referring to -- it is p that is the functor in the compound term p(B).

– Will Ness
Mar 8 at 16:06














There may be a simpler way, but you could use =../2 to examine the term as a list, then compare each list element (arguments) using ==/2 rather than =/2.

– lurker
Mar 8 at 16:28





There may be a simpler way, but you could use =../2 to examine the term as a list, then compare each list element (arguments) using ==/2 rather than =/2.

– lurker
Mar 8 at 16:28













In practise it is often necessary to find reasonable tradeoffs, including some hacks to cut some corners. Having said that, it seems you start the architectural "phase one: modeling" off by searching for workarounds. Warning: there's trouble ahead!

– repeat
Mar 8 at 21:43






In practise it is often necessary to find reasonable tradeoffs, including some hacks to cut some corners. Having said that, it seems you start the architectural "phase one: modeling" off by searching for workarounds. Warning: there's trouble ahead!

– repeat
Mar 8 at 21:43














For instance, why you are sure about using (dynamic) asserted rules later on?

– repeat
Mar 8 at 21:47






For instance, why you are sure about using (dynamic) asserted rules later on?

– repeat
Mar 8 at 21:47













1 Answer
1






active

oldest

votes


















3














Assuming order is not significant, a simple solution is to use the de facto standard append/3 predicate and the standard sort/2 predicate. For example:



| ?- append([location(A),package(B)], [location(C),package(B),truck(D)], List), sort(List, Sorted).

List = [location(A),package(B),location(C),package(B),truck(D)]
Sorted = [location(A),location(C),package(B),truck(D)]





share|improve this answer























  • Can you say why that works? It seems sort is smart enough to know what's identical without unifying. I might have a use for that in other contexts.

    – Topological Sort
    Mar 10 at 15:03











  • @TopologicalSort sort/2uses, per spec, term equality, not term unification. It also removes duplicated terms.

    – Paulo Moura
    Mar 10 at 15:38











  • Looking up your terms, I see that = does unification and == does equality. I ask you to put that in your answer, because that's what I was really getting at. I'll accept your answer anyway, because it solves the problem neatly and directly, but for posterity I think it would be good to add that.

    – Topological Sort
    Mar 10 at 19:21











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%2f55066482%2fprolog-identify-if-two-functors-are-identical-without-variable-binding%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









3














Assuming order is not significant, a simple solution is to use the de facto standard append/3 predicate and the standard sort/2 predicate. For example:



| ?- append([location(A),package(B)], [location(C),package(B),truck(D)], List), sort(List, Sorted).

List = [location(A),package(B),location(C),package(B),truck(D)]
Sorted = [location(A),location(C),package(B),truck(D)]





share|improve this answer























  • Can you say why that works? It seems sort is smart enough to know what's identical without unifying. I might have a use for that in other contexts.

    – Topological Sort
    Mar 10 at 15:03











  • @TopologicalSort sort/2uses, per spec, term equality, not term unification. It also removes duplicated terms.

    – Paulo Moura
    Mar 10 at 15:38











  • Looking up your terms, I see that = does unification and == does equality. I ask you to put that in your answer, because that's what I was really getting at. I'll accept your answer anyway, because it solves the problem neatly and directly, but for posterity I think it would be good to add that.

    – Topological Sort
    Mar 10 at 19:21















3














Assuming order is not significant, a simple solution is to use the de facto standard append/3 predicate and the standard sort/2 predicate. For example:



| ?- append([location(A),package(B)], [location(C),package(B),truck(D)], List), sort(List, Sorted).

List = [location(A),package(B),location(C),package(B),truck(D)]
Sorted = [location(A),location(C),package(B),truck(D)]





share|improve this answer























  • Can you say why that works? It seems sort is smart enough to know what's identical without unifying. I might have a use for that in other contexts.

    – Topological Sort
    Mar 10 at 15:03











  • @TopologicalSort sort/2uses, per spec, term equality, not term unification. It also removes duplicated terms.

    – Paulo Moura
    Mar 10 at 15:38











  • Looking up your terms, I see that = does unification and == does equality. I ask you to put that in your answer, because that's what I was really getting at. I'll accept your answer anyway, because it solves the problem neatly and directly, but for posterity I think it would be good to add that.

    – Topological Sort
    Mar 10 at 19:21













3












3








3







Assuming order is not significant, a simple solution is to use the de facto standard append/3 predicate and the standard sort/2 predicate. For example:



| ?- append([location(A),package(B)], [location(C),package(B),truck(D)], List), sort(List, Sorted).

List = [location(A),package(B),location(C),package(B),truck(D)]
Sorted = [location(A),location(C),package(B),truck(D)]





share|improve this answer













Assuming order is not significant, a simple solution is to use the de facto standard append/3 predicate and the standard sort/2 predicate. For example:



| ?- append([location(A),package(B)], [location(C),package(B),truck(D)], List), sort(List, Sorted).

List = [location(A),package(B),location(C),package(B),truck(D)]
Sorted = [location(A),location(C),package(B),truck(D)]






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 8 at 16:55









Paulo MouraPaulo Moura

12.8k21426




12.8k21426












  • Can you say why that works? It seems sort is smart enough to know what's identical without unifying. I might have a use for that in other contexts.

    – Topological Sort
    Mar 10 at 15:03











  • @TopologicalSort sort/2uses, per spec, term equality, not term unification. It also removes duplicated terms.

    – Paulo Moura
    Mar 10 at 15:38











  • Looking up your terms, I see that = does unification and == does equality. I ask you to put that in your answer, because that's what I was really getting at. I'll accept your answer anyway, because it solves the problem neatly and directly, but for posterity I think it would be good to add that.

    – Topological Sort
    Mar 10 at 19:21

















  • Can you say why that works? It seems sort is smart enough to know what's identical without unifying. I might have a use for that in other contexts.

    – Topological Sort
    Mar 10 at 15:03











  • @TopologicalSort sort/2uses, per spec, term equality, not term unification. It also removes duplicated terms.

    – Paulo Moura
    Mar 10 at 15:38











  • Looking up your terms, I see that = does unification and == does equality. I ask you to put that in your answer, because that's what I was really getting at. I'll accept your answer anyway, because it solves the problem neatly and directly, but for posterity I think it would be good to add that.

    – Topological Sort
    Mar 10 at 19:21
















Can you say why that works? It seems sort is smart enough to know what's identical without unifying. I might have a use for that in other contexts.

– Topological Sort
Mar 10 at 15:03





Can you say why that works? It seems sort is smart enough to know what's identical without unifying. I might have a use for that in other contexts.

– Topological Sort
Mar 10 at 15:03













@TopologicalSort sort/2uses, per spec, term equality, not term unification. It also removes duplicated terms.

– Paulo Moura
Mar 10 at 15:38





@TopologicalSort sort/2uses, per spec, term equality, not term unification. It also removes duplicated terms.

– Paulo Moura
Mar 10 at 15:38













Looking up your terms, I see that = does unification and == does equality. I ask you to put that in your answer, because that's what I was really getting at. I'll accept your answer anyway, because it solves the problem neatly and directly, but for posterity I think it would be good to add that.

– Topological Sort
Mar 10 at 19:21





Looking up your terms, I see that = does unification and == does equality. I ask you to put that in your answer, because that's what I was really getting at. I'll accept your answer anyway, because it solves the problem neatly and directly, but for posterity I think it would be good to add that.

– Topological Sort
Mar 10 at 19:21



















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%2f55066482%2fprolog-identify-if-two-functors-are-identical-without-variable-binding%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

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived