I need to OR and AND operator while expression evaluation, but when I use it to CLIPSDOS it give wrong result.
CLIPS (6.31 6/12/19)
CLIPS> ( and 0 1 )
TRUE
CLIPS>
I expect the output FALSE but it give TRUE
What could be wrong?
In C, the integer 0 is false and any other integer is true.
In CLIPS, the symbol FALSE is false and any other value is true.
CLIPS (6.31 6/12/19)
CLIPS> (and 0 1)
TRUE
CLIPS> (and 1 2)
TRUE
CLIPS> (and FALSE TRUE)
FALSE
CLIPS>
Related
I want to understand what and and or represent in Racket when used with lists. When I do something like this -
> (or `(1 2) `(1 3))
'(1 2)
What is the result representing? I thought when we use or with two lists we would get a union of the lists. That is clearly not what is happening here. So, I thought it is interpreted as boolean values and that is why `(1 2) is not a false value. Hence, the result is `(1 2). But what about this? -
> (and `(1 2) `(1 3))
'(1 3)
How can I justify this?
or is looking for the first truthy value, checking arguments from left to right. Every value other than #false is truthy. If any is found, it's returned. In your example, '(1 2) is the first truthy value from the left, so it's returned.
Or called with no arguments returns #false, because no truthy values were found:
> (or)
#f
And checks whether all values are truthy, so it has to examine all of them, going from left to the right, and it can return #false (if any #false is found) or, if all values are truthy, last of them. In your example, '(1 3) is the last truthy value, so it's returned.
And called with no arguments returns #true, because no #false was found:
> (and)
#t
Read also the docs about or and and.
By the way, there is a difference between ' and `. First one is quote, the second one is quasiquote. In this very example, it doesn't matter, but you should know the difference between them.
And if you were really looking for union function, check racket/set library:
(require racket/set)
(set-union (set 1 2) (set 1 3))
=> (set 1 3 2)
I'm in the process of designing an expert system from a decision tree and one of the tests is to check the wildlife score. The user is asked to enter the wildlife score and 3 possible outcomes are decided.
A score of at least 20 rejects the proposal and ends the program.
A score of more than 10 but less than 20 moves on to test 4 but asserts the outcome will be second-best.
A score of no more than 10 simply moves to test 4.
The read line from the previous test:
(defrule wildlife-score(or(energy-level 2)(energy-level 3))
=> (printout t "What is the wildlife impact score?" crlf)
(assert(wildlife-impact(read))))
The following is where I am having trouble in comparing the read value to the outcome values. Any help would be appreciated.
(defrule reject-wildlife
(wildlife-impact ? (> ?wildlife-impact 20))
=> (assert(reject))
(printout t "Reject - completely unsuitable due to wildlife impact." crlf))
The correct syntax for your comparison is (wildlife-impact ?varname&:(> ?varname 20)).
(defrule reject-wildlife
(wildlife-impact ?score&:(> ?score 20))
=>
(assert (reject))
(printout t "Reject - completely unsuitable due to wildlife impact." crlf))
I've been trying to modify one variable from one assert in the antecedent, but I haven't been able to do it.
In the consequent I can modify variables, with bind, assignments, etc. but I'd like to do the following:
(defrule test
?h<-(Currentposition ?x ?y)
(not (Explored (+ ?x 1) ?y))
=> (whatever)
So, the problem is that I have a character moving through a map, and I want to explore unknown cells, so I want to go to them, and in order to do so, I mark them as Explored.
In the example, I want to check if the south cell has been explored, how can I do it? I add 1 to x because I move 1 row below, x-> rows, y-> columns
Thanks
Use =, the return value constraint:
(defrule test
?h <- (Currentposition ?x ?y)
(not =(Explored (+ ?x 1) ?y))
=>)
I'm writing a clips code that goes through for loop , and it print facts .
I wanna know if there is a way to delay execution for 10 seconds , after printing the first fact , then another 10 second at the second iteration ?
so is there a delay function like java?
There's nothing built-in that allows you to sleep the CLIPS process for a fix amount of time, but you can write a function which loops for a specified amount of time before returning:
CLIPS>
(deffunction pause (?delay)
(bind ?start (time))
(while (< (time) (+ ?start ?delay)) do))
CLIPS> (pause 5)
FALSE
CLIPS>
I'm trying to learn Jess and FuzzyJ but am having problems getting a simple program to run. I have looked at it for hours and am no quite sure why it doesn't run. If someone could point me in the right direction it would be very much appreciated.
;;;;;;;;;;;;;;;;;;;;;;;;;
Fuzzy Variables
;;;;;;;;;;;;;;;;;;;;;;;;;;
(defglobal ?*income* =
(new nrc.fuzzy.FuzzyVariable "income" 0.0 230000.00 "dollars"))
(defglobal ?*stability* =
(new nrc.fuzzy.FuzzyVariable "stability" 0.0 1.0 "index"))
(defglobal ?*liquidity* =
(new nrc.fuzzy.FuzzyVariable "liquidity" 0.0 1.0 "index"))
(defrule initial-terms
(declare (salience 100))
=>
(import nrc.fuzzy.*)
(load-package nrc.fuzzy.jess.FuzzyFunctions)
;;;;;;;;;;;;;;;;;;;;;
Primary Terms
;;;;;;;;;;;;;;;;;;;;;;;
(?*income* addTerm "low" (new ZFuzzySet 30000.00 80000.00))
(?*income* addTerm "medium" (new PIFuzzySet 100000.00 60000.00))
(?*income* addTerm "high" (new SFuzzySet 80000.00 190000.00))
(?*stability* addTerm "low" (new ZFuzzySet .3 .5))
(?*stability* addTerm "medium" (new PIFuzzySet .6 .4))
(?*stability* addTerm "high" (new SFuzzySet .7 .9))
(?*liquidity* addTerm "low" (new ZFuzzySet .3 .5))
(?*liquidity* addTerm "medium" (new PIFuzzySet .6 .4))
(?*liquidity* addTerm "high" (new SFuzzySet .7 . 9))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Fuzzy Rules
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defrule rule-1 "low income => liquidity very low"
(theIncome ?x &: (fuzzy-match ?x "low"))
=>
(assert(theLiquidity (new nrc.fuzzy.FuzzyValue ?*liquidity* "very low")))
(defrule rule-2 "high income & high stability => very high liquidity"
(theIncome ?x &: (fuzzy-match ?x "high"))
(theStability ?y (fuzzy-match ?y "high"))
=>
(assert(theLiquidity (new nrc.fuzzy.FuzzyValue ?*liquidity* "very high"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Defuzzification
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defrule defuzzification-and-display-liquidity
(declare (salience -1))
?f <- (theLiquidity ?z)
=>
(printout t (str-cat "Liquidity: " (?z momentDefuzzify)))
retract( ?f)
(halt))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Start up Rule/Fuzzify
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defrule assert-income-and-stability "initialization"
=>
(printout t "Enter the income(ex. 52000): ")
(bind ?income-value (float (readline t)))
(printout t "Enter the stability index(ex. 0.64): ")
(bind ?stability-value (float(readline t)))
(assert(theIncome
(new nrc.fuzzy.FuzzyValue ?*income*
(new nrc.fuzzy.TriangleFuzzySet
(- ?income-value 3000.0)
?income-value
(+ ?income-value 3000.0)))))
(assert(theStability
(new nrc.fuzzy.FuzzyValue ?*stability*
(new nrc.fuzzy.TriangleFuzzySet
(- ?stability-value 3000.0)
?stability-value
(+ ?stability-value 3000.0))))))
(reset)
(run)
There are many small syntax errors in this program; in general the Jess interpreter does a good job of pointing them out. First of all, in each of your comment blocks, you've got the actual text of the comment... not commented. So add a semicolon to the beginning of the lines like "Fuzzy Variables", for instance.
Second, on the line
(?*liquidity* addTerm "high" (new SFuzzySet .7 . 9))
there ought to be no space after that last decimal point.
Third, the rules rule-1 and rule-2 don't have enough close-parentheses at the end. Any decent programmer's editor able to format Lisp code should be able to help you fix that.
Fourth, on the line
(theStability ?y (fuzzy-match ?y "high"))
you're missing the "&:" before the predicate function -- see the previous line.
Finally, I think, the line
retract( ?f)
is malformed -- should be (retract ?f) .