Questions tagged [prolog-defaulty]

Use this only with Prolog when noting defaulty code, a wordplay combining "default" and "faulty.

When Prolog code needs a default case when everything else fails it is know as being defaulty which is a wordplay combining default and faulty.

Prolog code should not be defaulty!!!

References:

Clean vs. defaulty representations
The cost of defaulty representations
Logic Programming Implementation Part I: The WAM - Scroll down to page 46 to find "Processing a Defaulty Data Structure"

16 questions
7
votes
2 answers

Prolog - simplify derivative

so I just got started with Prolog this semester, and got the homework to implement a pretty basic d(function, variable, derivative) which I did like this: d(X,X,1) :- !. d(C,X,0) :- atomic(C). %, (C \= X). d(X**E,X,E*X**(E-1)). d(U+V,X,A+B) :-…
4cello
  • 73
  • 1
  • 5
5
votes
1 answer

prolog catch all clause that's only active if no other clause is

I have a predicate that relates a modal logic formula to its negative normal form. All connectives except the modal operators, conjunction, and disjunction are eliminated, and negation is pushed as far into the leaves of the expression as…
Greg Nisbet
  • 6,710
  • 3
  • 25
  • 65
5
votes
1 answer

Prolog - formulas in propositional logic

I am trying to make a predicate in order to validate if a given input represents a formula. I am allowed to use only to propositional atoms like p, q, r, s, t, etc. The formulas which I have to test are the following: neg(X) - represents the…
Simon
  • 4,999
  • 21
  • 69
  • 97
5
votes
1 answer

Term expansion for a list of terms

Say I want to have a number of rules that all follow the same pattern. I have ran into this situation when I want to avoid non-deterministic behavior by explicitly listing all possible first arguments. I know, however, that I need to do exactly the…
user1812457
3
votes
2 answers

Prolog: how to do "check(a++b++c++d equals d++a++c++b) -> yes"

Let's define custom operators - let it be ++,equals :- op(900, yfx, equals). :- op(800, xfy, ++). And fact: check(A equals A). I try to make predicate, let it be check/1, that will return true in all following situations: check( a ++ b ++ c ++ d…
Grzegorz Wierzowiecki
  • 10,545
  • 9
  • 50
  • 88
3
votes
1 answer

Prolog - subsitution and evaluation

Hello good people of programming . Logic programming is always fascinating compare to imperative programming. As pursuing unknown of logic programming, there is some problems encountering arithmetic expressions. Here is the code I have done so…
KAI
  • 33
  • 3
3
votes
3 answers

Combing generator results and writing result to stream

Currently I can generate expression trees. expression_tree([_|N_s],N_s, [number(0)]). expression_tree([_|N_s0],N_s1, [op(neg),[E1]]) :- expression_tree(N_s0,N_s1, E1). expression_tree([_|N_s0],N_s2, [op(add), [E1, E2]]) :- …
Guy Coder
  • 24,501
  • 8
  • 71
  • 136
3
votes
3 answers

Deep Reverse in PROLOG - Lists

Hey I'm trying to create a predicate for the generating of a deep reverse on nested Lists in PROLOG. Currently I got this predicate reverse(L,A) :- rev(L,[], A). rev([],A,A). rev([H|L],R,A) :- rev(L,[H|R],A). The result looks like…
2
votes
3 answers

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 outcome: ?- eval(X^Y, R). R = 0^0; R = 0^1; R =…
Daniel Lyons
  • 22,421
  • 2
  • 50
  • 77
2
votes
1 answer

Constraints over arbitrary length sublists using CLP(FD)

I'm trying to wrap my head around CLP(FD). Here's a simple example of where I'm not sure of the most idiomatic approach. Suppose we have a List of numbers (L), with some numbers already filled, like this. L = [_, _, _, 3, _, _, _, 4, _, _, 2,…
Hugo Sereno Ferreira
  • 8,600
  • 7
  • 46
  • 92
2
votes
1 answer

Constrain integer to be in set

I'm using the in/1 predicate to try and constrain an integer to take values from a certain set: ?- use_module(library(clpfd)). gen_in_set(X) :- X in [0, 1, 3, 5, 7]. I didn't expect this to work, since [...] is list notation. I could of course…
Tudor Timi
  • 7,453
  • 1
  • 24
  • 53
1
vote
1 answer

CLPFD domain declaration with in or inequalities

?- X in 1..100. X in 1..100. ?- X #> 0, X #< 101. X in 1..100. So far so good! Now let's imagine that the sup bound of X depends on Y in 100..200. ?- Y in 100..200, X #> 0, X #=< Y. Y in 100..200, Y#>=X, X in 1..200. The domain of X propagates…
Fatalize
  • 3,513
  • 15
  • 25
1
vote
1 answer

Tree leaf traversal in Prolog

I experience some issues when I'm training prolog exercises,the problem below is, The predicate defines what it means to be a tree, and can be used to test whether a term is a tree: tree(t(L,R)) :- tree(L), tree(R). tree(T) :- T\=t(_ , _). By…
user2953788
  • 157
  • 3
  • 17
0
votes
2 answers

How to write Prolog - defining basic operators?

I'm fairly new to Prolog and I want to create a predicate that behaves as follows calculate(add(1, sub(4,1)),Result). Result = 4. This is doing: 1 + (4 - 1) = 4 I'm familiar with predicates but I don't know where to start in terms of being able to…
0
votes
2 answers

Setting types of unbound variables in Prolog

I'm trying to find a way to set the type of a variable before it has been bound to a value. Unfortunately, the integer/1 predicate cannot be used for this purpose: %This goal fails if Int is an unbound variable. get_first_int(Int,List) :- …
Anderson Green
  • 30,230
  • 67
  • 195
  • 328
1
2