Quantcast
Channel: User Daniel Lyons - Stack Overflow
Browsing latest articles
Browse All 43 View Live

Comment by Daniel Lyons on Proving OR is commutative with SSReflect

@AntonTrunov with the edit, do you find my new proof to be idiomatic of SSreflect?

View Article



Comment by Daniel Lyons on Proving OR is commutative with SSReflect

This is embarassing for me, but I just tried it in my Coq (8.10.1) and I get Error: Not an inductive product.

View Article

Comment by Daniel Lyons on Two lists have at least one common element without...

Your first clause is unnecessary, since if you omit it, Prolog will already fail.

View Article

Comment by Daniel Lyons on Prolog - Calculate fastest travel between 2...

'fct' means the same thing without quotes: it is an atom either way. So the predicate you want is probably something like sub_atom(fct, _, 1, _, t), to determine if your mode-of-transport contains a t.

View Article

Comment by Daniel Lyons on Visual prolog duplicates in list

I'd recommend you use SWI instead if you have the choice. Much more tooling, users, and help available with it, plus it is open source.

View Article


Comment by Daniel Lyons on CHR in SWI Prolog: Rule guard containing "just...

The introduction says "Only built-in constraints are allowed in a guard. These built-ins should be simple tests, i.e. the same constructs that occur in conditions of the host language." I suspect that...

View Article

Comment by Daniel Lyons on How to access database members when calling a...

The search is something Prolog does for you without you having to be explicit. If the user input is in a variable Booktitle, then book(Booktitle, _, _) is sufficient to retrieve it (or you could get...

View Article

Comment by Daniel Lyons on Z notation to prolog

I would greatly enjoy the Z notation you're attempting to meet. But even Prolog is not high-level enough to directly execute Z notation, which intentionally omits operational concerns. In the mean...

View Article


Comment by Daniel Lyons on Forward and Backward Chaining

My rule of thumb would be, if you know what needs to be done, but want AI to help figure out how, you probably want backward-chaining, because it is goal-directed and you already have the goal in mind....

View Article


Comment by Daniel Lyons on Prolog classification by giving points to classes

To be honest, I think you have an operational view of how to solve the problem already—which means you would be fighting Prolog to do it, because Prolog wants you to tell it what you want and let it...

View Article

Comment by Daniel Lyons on Replacing parts of expression in prolog

@AndersonGreen Thanks for that, I haven't used subsumes_term/2 before but it does look like it would be very useful!

View Article

Comment by Daniel Lyons on Difference function in prolog for multisets

What about the fact that the second argument contains two extra 'c's and an 'e'? Shouldn't the result be [a, a, b, c, c, e]?

View Article

Comment by Daniel Lyons on Cuts in a Prolog query?

There is no difference between a Prolog query and the body of a predicate, so your guess is essentially correct: none of the choice points before the cut will be backtracked to in order to satisfy the...

View Article


Answer by Daniel Lyons for Prolog: Define propositional logic statement...

You're running into an interesting global thing about Prolog that operators really bring to the surface, which is that operators are just another way of constructing terms.These operator definitions of...

View Article

Answer by Daniel Lyons for Prolog predecessor math

In general, adding with successor arithmetic means handling successor terms, which have the shape 0 or s(X) where X is also a successor term. This is addressed completely by this part of your...

View Article


Answer by Daniel Lyons for Prolog DCG Sytnax Error: Operator Expected

I'm afraid you've not actually managed to use the DCG you have defined. float/1 is a built-in that you are calling, and without quoting anything you haven't actually passed a string into anything to be...

View Article

Answer by Daniel Lyons for What does X evaluate to in the second operand of a...

I'm going to try and explain how this predicate works, because I think there is something amiss in your expectation of what Prolog is going to do and I'm not altogether sure what it is. Often, new...

View Article


Answer by Daniel Lyons for Unification of terms in Prolog

I'm kind of surprised you didn't just ask Prolog to do it for you:?- T1 = f(f(3,R,2),f(A,R,I),A), T2 = f(N,f(E,f(5,2),S),f(3,2,N)), T1=T2. T1 = T2, T2 = f(f(3, f(5, 2), 2), f(f(3, 2, f(3, f(5, 2), 2)),...

View Article

Answer by Daniel Lyons for SWI Prolog foreach/2

The documentation actually says what you believe is happening:Each member of the conjunction is a copy of Goal, where the variables it shares with Generator are filled with the values from the...

View Article

Answer by Daniel Lyons for Having trouble figuring out what I need to change...

On line 41, you have a space between a predicate and its arguments, which is not allowed:ask_type(Type) :- writef("Is it an animal, plant, or object? \n"), read (Type).Change it to this:ask_type(Type)...

View Article

Answer by Daniel Lyons for Returning List of possible answers

We've got a lot of issues here, starting with your question.Without concat/3 and how you are calling your code, it really isn't possible for anyone to solve your problems. None of your predicates take...

View Article


Answer by Daniel Lyons for How do I run a prolog file from the command line...

Your biggest problem is that your source code has quite a few issues. I have fixed them like so:parent(pam,bob).parent(tom,bob).parent(tom,liz).parent(bob,ann).parent(bob,pat).parent(pat,jim).main :-...

View Article


Answer by Daniel Lyons for Assign variable in list

I'm not sure what you mean by "paradigm," and I'm very unclear on what you're trying to do with this code. If you have this at the toplevel:array(p, [A,B,C]).you are defining a fact array/2, which...

View Article

Answer by Daniel Lyons for Logical exclusive or in Prolog

For the most part, logic variables are already exclusive because they can only be bound once. You have defined here a rule color/1 with four bodies. When you query with an uninstantiated variable,...

View Article

Answer by Daniel Lyons for Is there a way to compare three lists in prolog?

I think you're overthinking it. :) Turn your specification into code directly and then work out the details:sum(A, B, C) :- append(B, C, BC), permutation(A, BC), sumlist(B, Sum), sumlist(C, Sum).This...

View Article


Answer by Daniel Lyons for Prolog write n as sum of consecutive numbers

The key here is between/3, which relates numbers and ranges. Prolog is not going to conjure up numbers from thin air, you have to give it some clues. In this case, you can assume a range of numbers...

View Article

Answer by Daniel Lyons for Prolog repeating the same answer infinitely

Your problem is here:parent(X,Y):- married(Z,X), parent(Z,Y).Actually, you can see it a little more clearly if you remove married/2:parent(X,Y):- parent(Z,Y).This is going to lead to unbounded...

View Article

Answer by Daniel Lyons for Filter association table prolog

The easiest solution would be to convert this to a list, filter the list with the predicate, and then construct a new assoc.:- use_module(library(assoc)).:-...

View Article

Answer by Daniel Lyons for Generate all permutation of N (N - given)...

Well, let's compare to the SWI-Prolog implementation of permutation/2 (click the :- button to see the source. There's a bunch of type checking and then it resolves to a call to this predicate:perm([],...

View Article



Answer by Daniel Lyons for How do I append an element to the beginning of a...

I think you'll be surprised how easy the solution is. :)split(List, Split, Left, [Split|Right]) :- append(Left, [Split|Right], List).

View Article

Answer by Daniel Lyons for How to convert tree to list in Prolog?

You never explicitly said what your data structure looks like in Prolog, but I can infer that you have basically two kinds of tree node:tree(Element, Left, Right)voidTo handle any recursive data...

View Article

Answer by Daniel Lyons for How do I use an "either or" with a math function...

So, your first block cannot succeed because Cage2 is (X/Y), ... Cage2 is (Y/X) can only succeed if Cage2 is the same value both times. You are trying to reassign Cage2 here, and Prolog simply doesn't...

View Article

Answer by Daniel Lyons for What's correct way to make natural number rule in...

Dealing with naturals is usually improved considerably by using succ/2. is/2, as you have discovered, is required for Prolog to evaluate an arithmetic expression, but it has a single instantiation...

View Article


Answer by Daniel Lyons for prolog, duplicating in queries

Well, logically, Prolog is doing the right thing. You're saying P1 and P2 are siblings if P1 and P2 are different but share a parent. When you ask this to generate, it's going to locate P1 = herb, P2 =...

View Article

Answer by Daniel Lyons for Prolog inheritance logic: how to match?

I think you have an implicit "is-a" relationship that you haven't taught Prolog about. I think you want to approach it like this:%% owns(Person, Object)owns(jolene, roborally).%% is_a(Thing,...

View Article

Answer by Daniel Lyons for Calculate whether the sum of exactly three values...

I'm giving a partial solution here because it is an interesting problem even though the constraints are ridiculous.First, I want something like select/3, except that will give me the tail of the list...

View Article


Answer by Daniel Lyons for Get duplicate items in a list and display answer...

I find it a bit of a straightjacket to ignore the standard library. But you can fulfill the requirement by implementing the two predicates you need, which are member/2 and delete/3,...

View Article


Controlling Prolog variable value selection

Inspired by an earlier question I tried to implement something that would enumerate the possibilities for a boolean expression. However, I'm having trouble with variable choice. Here's my intended...

View Article

PostgreSQL: NOT IN versus EXCEPT performance difference (edited #2)

I have two queries that are functionally identical. One of them performs very well, the other one performs very poorly. I do not see from where the performance difference arises.Query #1:SELECT id FROM...

View Article

Stack overflow in Prolog DCG grammar rule: how to handle large lists...

I'm parsing a fairly simple file format consisting of a series of lines, each line having some space separated fields, that looks like this:l 0x9823 1s 0x1111 3l 0x1111 12⋮I'm using SWI-Prolog. This is...

View Article

Looping in Prolog metainterpreter

I'm writing a trivial metainterpreter in Prolog for self-education. Basically I want to carry along the "probability" of a given solution. To do this I just declare the probability of my clause being...

View Article


Prolog: "Vanilla" metainterpreter with builtins

This answer by Jan Burse shows one of the simplest implementations of a metainterpreter in Prolog:solve(true) :- !.solve((A,B)) :- !, solve(A), solve(B).solve(H) :- clause(H,B), solve(B).I would like...

View Article

Comment by Daniel Lyons on How to access list permutations in prolog?

@user129393192 I'm afraid I don't understand your question since there is no if-clause in perm, I don't see what I said about stack overflows in this 12-year-old answer. Perhaps you should open a...

View Article

Browsing latest articles
Browse All 43 View Live




Latest Images