Prolog permutation type_error [duplicate] - prolog

In normal situation, we can use ";" to show the next answer if there is one.
But if I do this, it shows me
error: char_code/2: Cannot represent due to 'character_code'
In stead of ";", I use "shift + ;", and prolog gives me a prompt
Unknown action: : (h for help) Action?
then if I input ";", the designable answers will be shown one by one.
What is the problem?

Use swipl-win.exe instead of swipl.exe can solve this problem.(I tried 6.x and 7.x)
By the way, swipl works well under MacOS.

Related

Please Explain Octave-Error : operator /: nonconformant arguments (op1 is 1x1, op2 is 1x10)

I have an issue running a certain script in octave.
This is the code that produces the error:
#germanium
T=410:20:600;
x=linspace(400,410,100);
y=linspace(10^9,10^9,100);
k=8.5*10 .^(-5);
Eg=0.59;
Nc300=1.02*10^13;
Nc=Nc300*((T/300).^(3/2));
n=Nc*(e.^(-Eg/(2*k*T)));
plot(T,n,x,y,'m');
grid on
xlabel('Temprature');
ylabel('Electron Density n');
title('Germanium n(T)');
As mentioned in the Title, the error that is produced is the following:
error: ger5: operator /: nonconformant arguments (op1 is 1x1, op2 is 1x10)
I have done a lot of testing, and I figured that the problem originates from the T variable on the 9th line : n=Nc*(e.^(-Eg/(2*k*T)));
The codes run fine without it. For example :
#germanium
T=410:20:600;
x=linspace(400,410,100);
y=linspace(10^9,10^9,100);
k=8.5*10 .^(-5);
Eg=0.59;
Nc300=1.02*10^13;
Nc=Nc300*((T/300).^(3/2));
n=Nc*(e.^(-Eg/(2*k*500)));
plot(T,n,x,y,'m');
grid on
xlabel('Temprature');
ylabel('Electron Density n');
title('Germanium n(T)');
In which case I simply replaced T with 500 , the code runs perfectly fine.
Sadly T, can not be replaced by a certain number since it is the variable used in my graph. Although I did some digging, I never managed to fully understand this error, or how to fix it, thus any help would be greatly appreciated.
Thanks.
Add a . before your *, /, and ^ signs. This will ensure that octave uses scalar multiplication instead of matrix multiplication.
n=Nc.*(e.^(-Eg./(2.*k.*T)));

Datalog code not working in DrRacket

I am trying to run this prolog code in DrRacket: http://www.anselm.edu/homepage/mmalita/culpro/graf1.html
#lang datalog
arc(a,b).
arc(b,c).
arc(a,c).
arc(a,d).
arc(b,e).
arc(e,f).
arc(b,f).
arc(f,g).
pathall(X,X,[]).
pathall(X,Y,[X,Z|L]):- arc(X,Z),pathall(Z,Y,L). % error on this line;
pathall(a,g)?
However, it is giving following error:
read: expected a `]' to close `['
I suspect '|' symbol is not being read as head-tail separator of the list. Additionally, [] is also giving error (if subsequent line is removed):
#%app: missing procedure expression;
probably originally (), which is an illegal empty application in: (#%app)
How can these be corrected so that the code works and searches for paths between a and g ?
The Datalog module in DrRacket is not an implementation of Prolog, and the syntax that you have used is not allowed (see the manual for the syntax allowed).
In particular terms cannot be data structures like lists ([]). To run a program like that of above you need a Prolog interpreter with data structures.
What you can do is define for instance a predicate path, like in the example that you have linked:
path(X,Y):- arc(X,Y).
path(X,Y):- arc(X,Z),path(Z,Y).
and, for instance, ask if a path exists or not, as in:
path(a,g)?
or print all the paths to a certain node with
path(X,g)?
etc.

Prolog with inequalities

I found this inequality solving program from some Internet source.It works well.This is the program.
:-use_module(library(clpq)).
dec_inc(Left,Right):-
copy_term(Left-Right,CopyLeft-CopyRight).
tell_cs(CopyLeft).
max(CopyRight,Right,Leq).
tell_cs(Leq).
max([],[],[]).
max([E=<_|Ps],[_=<P1|P1s],[K=<P1|Ls]):-
sup(E,K),
max(Ps,P1s,Ls).
tell_cs([]).
tell_cs([C|Cs]):-
{C},
tell_cs(Cs).
The problem I have regarding this program is when I run the program using capital letter variable it works.But it doesn't work for simple letter variables.
This is the syntax i used to solve this problem.
eg:-
{2*X+3>=5}.
This works and gives the correct answer.
{2*x+3>=5}.
When i run this, Prolog says
ERROR: Unhandled exception: nf(y,_G3082): argument 1 must be a a numeric expression
I'm using SWI-Prolog version 6.6.0.What is the problem here and how can I solve it.

A tuprolog syntax error.Syntax error at/before line -1

I am new to prolog. I have a .pl file consulting normally on swi-prolog, but when I consult it on tu-prolog, crazy things always happen. Here are parts of my codes.
:- dynamic(assignopT/6).
:- multifile(assignopT/6).
assignopT(30246,30244,30210,30247,+,30248).
When I consulted it on tu-prolog,it said syntax error at/before line 12219,which is the third line above. It work all right on swi-prolog. Then I thought maybe there is something wrong with +, so I changed it to this.
assignopT(30246,30244,30210,30247,'+',30248).
This time,it said syntax error at/before line -1. I really don't get this, what line -1 even suppose to mean. The .pl named swi2tu.pl is on https://drive.google.com/folderview?id=0B4KCEwRVmr_yWjQwOEp3LWpYdk0&usp=sharing
Try instead:
assignopT(30246,30244,30210,30247,(+),30248).
Writing an atom, such as +, between single quotes changes nothing and the error is possibly due to its operator status. Assuming that's the case, writing it between ()'s should fix the possible operator conflict when loading the code in tuProlog (not Turbo Prolog, I assume!).

"NOT EXISTS" in swi-prolog

I'm stuck on a simple problem in prolog.
Let's consider the program
worker(bill).
worker(smitt).
worker(fred).
worker(dany).
worker(john).
car(bmw).
car(mazda).
car(audi).
owner(fred,mazda).
owner(dany,bmw).
owner(john,audi).
I need to add one more predicate no_car(X),that will be true if the worker X has no cars,i.e,if we input a query
?:- no_car(X).
the prolog should answer
X=smitt,
X=bill,
yes
What i have done is
hascar(X):-owner(X,_).
nocar(X):- worker(X),not hascar(X).
But this approach does not work because anonimous variables are avaliable only for queries.
So,i'm really stuck on this.
I know there are "NOT EXISTS" words in SQL which allow to express this logic in a query,but is there something similar to them in prolog?
The following works for me and provides the expected result:
no_car(W):-
worker(W),
\+ owner(W, _).
Now this is close to what you have. For one thing, you can of course use _ in predicates; it is not restricted to queries. I usually use \* for negation, and not gives me a syntax error here!?
EDIT:
Ah! In my, albeit dated, version of Prolog you have to use not(hascar(X)) to make it work, so not/1 needs to be used as a term, not an operator. But the manual also says not is deprecated in favor of \+.

Resources