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
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
add a comment |
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
2
p(B) == p(B).
at the prompt succeeds, whilep(B) == p(C).
fails. This suggests you could use==
in your predicate. (note thatB=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 isp
that is the functor in the compound termp(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
add a comment |
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
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
prolog
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, whilep(B) == p(C).
fails. This suggests you could use==
in your predicate. (note thatB=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 isp
that is the functor in the compound termp(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
add a comment |
2
p(B) == p(B).
at the prompt succeeds, whilep(B) == p(C).
fails. This suggests you could use==
in your predicate. (note thatB=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 isp
that is the functor in the compound termp(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
add a comment |
1 Answer
1
active
oldest
votes
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)]
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
@TopologicalSortsort/2
uses, 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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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)]
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
@TopologicalSortsort/2
uses, 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
add a comment |
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)]
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
@TopologicalSortsort/2
uses, 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
add a comment |
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)]
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)]
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
@TopologicalSortsort/2
uses, 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
add a comment |
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
@TopologicalSortsort/2
uses, 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/2
uses, per spec, term equality, not term unification. It also removes duplicated terms.– Paulo Moura
Mar 10 at 15:38
@TopologicalSort
sort/2
uses, 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
2
p(B) == p(B).
at the prompt succeeds, whilep(B) == p(C).
fails. This suggests you could use==
in your predicate. (note thatB=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 isp
that is the functor in the compound termp(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