0

I am wondering if perhaps someone would be willing to help me with a problem that I am having with some code that I have written in propositional Prolog. The program is as follows:

:- dynamic superman/0,ironman/0,greenlantern/0,ironmanflies/0,
supermanflies/0,greenlanternflies/0,superheronironman/0,superherosuperman/0,
superherogreenlantern/0,abnormalsuperman/0,abnormalgreenlantern/0,
abnormalironman/0,specialabnormalironman/0,usesIronmanSuit.

ironmanflies:- superheroironman, \+ abnormalironman.
supermanflies:- superherosuperman, \+ abnormalsuperman.
greenlanternflies:- superherogreenlantern, \+ abnormalgreenlantern.
\+ abnormalironman:- specialabnormalironman.
abnormalironman:- \+ specialabnormalironman.
specialabnormalironman:- usesIronmanSuit.
superheroironman:- ironman.
superherosuperman:- superman.
superherogreenlantern:- greenlantern.
superman.

When I attempt to compile it in SWI Prolog, I get the following error:

ERROR: /home/justin/COMP5307/Assignments/assig2/a2q1e1.pl:6:
No permission to modify static procedure `(\+)/1'
Defined at /usr/lib/swi-prolog/boot/init.pl:337

What I am aiming to do is to express the line

\+ abnormalironman:- specialabnormalironman.

in correct syntax. I have seen some examples of possible ways to introduce a negation operator in the consequent, but those were user-defined approaches, and I would feel more comfortable using a built in method. The Prolog documentation is rather vague on this topic, so I would appreciate any help that anyone might be willing to provide.

For those reading this question for the first time, it originally pertained to an insufficient instantiation error which was found to be the result of the first letter of the filename being uppercase. For those using SWI Prolog for the first time, file names should have their first letter in lower case to avoid this error.

  • The code you are showing has no variables, so the error message pertains to some other part of your code. It also says, *Re-run your program in debug mode (`:- debug.`) to get more detail.* Did you try that? `\+ abnormalironman:- specialabnormalironman.` is invalid Prolog syntax. If it hasn't already, it will ultimately yield to an error indicating that you're trying to redefined `\+`. – lurker Mar 17 '18 at 17:02
  • I am not sure of the correct syntax for running in debug mode. – DarthMalloc Mar 17 '18 at 17:47
  • Did you check the documentation? – lurker Mar 17 '18 at 17:56
  • I am not sure of the correct syntax for running in debug mode in the way that the error message describes. I tried checking the documentation, but it gives no information about that. I have tried writing it as "[program_name]:- debug. but that just gives another error message. It looks like you identified the line where the error might be, so I am wondering what the correct syntax would be for the purpose of that line. If you respond with a regular answer, I will be able to upvote it. – DarthMalloc Mar 17 '18 at 18:09
  • The `:-` is the Prolog prompt. You would type `debug.` at the prompt. Then run your program. As I mentioned before, the error message you show doesn't point to any line of code you are currently showing since an instantiation error applies to variables but the code you show has no variables. A variable, in Prolog, begins with a capital letter or with `_`. The error I pointed out with `\+ abnormalironman:- specialabnormalironman.` is a totally separate problem. – lurker Mar 17 '18 at 19:12
  • In that case, it seems strange that I would be getting that error. The syntax error that you pointed out is on line 6, so that leads me to speculate it could be related to the insufficient instantiation error, which is shown to be on line 7. I am guessing that the error in line 6 has to do with the scope of \+. Is that correct? – DarthMalloc Mar 17 '18 at 19:46
  • Is what you typed into your question here exactly what your code looks like, including capitalization? When I enter your code into SWI Prolog, I get exactly the error I mentioned above, which is: `ERROR: user://1:16: No permission to modify static procedure '(\+)/1' Defined at /usr/local/lib/swipl-7.4.2/boot/init.pl:337`. That's an attempt to redefine `\+`. I do not see an instantiation error. – lurker Mar 17 '18 at 23:19
  • I copied and pasted from the file, so the cases should be the same. Based on what you are telling me, I think the correct question to ask would be how to negate the predicate to the left of the :- in Prolog. I have seen a few different methods suggested on line, though I am reluctant to try them, since they are do not seem to be built into the syntax, and might therefore trigger an error. Is there a correct way that is built into the syntax? – DarthMalloc Mar 17 '18 at 23:35
  • You have no variables, and an instantiation error pertains to variables. I just loaded it into SWI Prolog. There is no instantiation error but only the error I showed. – lurker Mar 17 '18 at 23:40
  • You cannot negate the "predicate" to the left. The "predicate" is the entire expression including the "head" (which you are trying to negate), the `:-`, and the "body". That whole thing is a *predicate clause*. You cannot negate the head. I think your question should not be "how to negate a predicate left of the `:-`" which doesn't make sense, but you need to explain what logic you are trying to achieve, then you can get help translating that to Prolog. – lurker Mar 17 '18 at 23:40
  • My apologies. What I am trying to achieve is express a propositional logic formula of the structure p -> ~q in propositional Prolog. The Prolog documentation shows how to add a negation operator in the premise, but is less clear about how to do so in the consequence. – DarthMalloc Mar 18 '18 at 01:49
  • I am, but from what you said, that was likely due to the fact that the filename had the first letter in uppercase. lurker pointed out another problem as well. – DarthMalloc Mar 18 '18 at 03:46

0 Answers0