How can I express next 3 sentences in Prolog?
All summers are warm. If it not summer, then it is winter. Now it is winter.
How can I express next 3 sentences in Prolog?
All summers are warm. If it not summer, then it is winter. Now it is winter.
Nice question. As @larsman (well, @FredFoo now, I think) rightly said, can be a large thema. And his answer is very good indeed.
As your question could be driven by necessity of a custom language (one of main Prolog' uses), here I propose the syntax sugar for a dummy DSL (what that's means it's totally empty now...)
:- op(500, fx, all).
:- op(500, fx, now).
:- op(600, xfx, are).
:- op(700, fx, if).
:- op(399, fx, it).
:- op(398, fx, is).
:- op(397, fx, not).
:- op(701, xfx, then).
all summers are warm.
if it is not summer then it is winter.
now it is winter.
SWI-Prolog is kind enough to make red those op that get stored, i.e. can be queried easily. These are the higher precedence words declared: i.e. are,then,now.
?- now X.
X = it is winter.
How to represent this depends on what inferences you want to make. One of the simplest ways is
warm :- summer.
winter.
The "if not summer then winter" rule does not actually allow you to make any useful inferences, so you could just as well skip it. If you were to include it, it might be something like
winter :- \+ summer.
but since negation in Prolog is negation as failure, this might not do what you think it does if you expect the semantics of vanilla propositional logic.
winter(now).
warm(X) :- summer(X).
summer(X) :- \+ winter(X).
winter(X) :- \+ summer(X).
Would be one of the ways to do this.
In action:
6 ?- summer(now).
false.
7 ?- summer(tomorrow).
ERROR: Out of local stack
8 ?- warm(now).
false.
Here a solution without using negation, instead the universe of seasons is specified.
season(summer).
season(winter).
now(winter).
warm(S) :-
season(S),
S = summer.
Some example queries:
?- now(S).
S = winter ;
false.
?- now(S), warm(S).
false.
?- warm(S).
S = summer ;
false.