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

Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page