如何在 Clips 中创建可分割性规则?
How to create rules of divisibility in Clips?
我是 Clips Expert System 的新手,我想知道你们中的一些人是否可以帮助实现数字 7、11 和 13 的整除规则。
这是我用来整除 2 的方法,但我不能对 7、11 和 13 做同样的事情
;Facts for divisibility of 2
(deffacts lastnumbers
(firstnum 0)
(secondnum 2)
(thirdnum 4)
(fourthnum 6)
(fifth 8))
我正在尝试像这样出去:
Number 886782 is divisible by 13
提前致谢。
一般来说,您无法仅通过被除数的最后一位数字来判断一个数是否能被另一个数整除。而是查看整数除法的余数,如果它为零,则股息可被除数整除。
CLIPS (6.31 6/12/19)
CLIPS>
(defrule get-dividend
(not (dividend ?))
=>
(printout t "Dividend? ")
(assert (dividend (read))))
CLIPS>
(defrule get-divisor
(dividend ?dividend&:(integerp ?dividend))
(not (divisor ?))
=>
(printout t "Divisor? ")
(assert (divisor (read))))
CLIPS>
(defrule bad-response
(or ?f <- (dividend ?d)
?f <- (divisor ?d))
(test (not (integerp ?d)))
=>
(retract ?f))
CLIPS>
(defrule is-divisible
(dividend ?dividend&:(integerp ?dividend))
(divisor ?divisor&:(integerp ?divisor))
=>
(printout t "Dividend " ?dividend " is"
(if (= (mod ?dividend ?divisor) 0)
then " "
else " not ")
"divisible by " ?divisor crlf))
CLIPS> (reset)
CLIPS> (run)
Dividend? 17
Divisor? 3
Dividend 17 is not divisible by 3
CLIPS> (reset)
CLIPS> (run)
Dividend? 886782
Divisor? 13
Dividend 886782 is divisible by 13
CLIPS>
我是 Clips Expert System 的新手,我想知道你们中的一些人是否可以帮助实现数字 7、11 和 13 的整除规则。
这是我用来整除 2 的方法,但我不能对 7、11 和 13 做同样的事情
;Facts for divisibility of 2
(deffacts lastnumbers
(firstnum 0)
(secondnum 2)
(thirdnum 4)
(fourthnum 6)
(fifth 8))
我正在尝试像这样出去:
Number 886782 is divisible by 13
提前致谢。
一般来说,您无法仅通过被除数的最后一位数字来判断一个数是否能被另一个数整除。而是查看整数除法的余数,如果它为零,则股息可被除数整除。
CLIPS (6.31 6/12/19)
CLIPS>
(defrule get-dividend
(not (dividend ?))
=>
(printout t "Dividend? ")
(assert (dividend (read))))
CLIPS>
(defrule get-divisor
(dividend ?dividend&:(integerp ?dividend))
(not (divisor ?))
=>
(printout t "Divisor? ")
(assert (divisor (read))))
CLIPS>
(defrule bad-response
(or ?f <- (dividend ?d)
?f <- (divisor ?d))
(test (not (integerp ?d)))
=>
(retract ?f))
CLIPS>
(defrule is-divisible
(dividend ?dividend&:(integerp ?dividend))
(divisor ?divisor&:(integerp ?divisor))
=>
(printout t "Dividend " ?dividend " is"
(if (= (mod ?dividend ?divisor) 0)
then " "
else " not ")
"divisible by " ?divisor crlf))
CLIPS> (reset)
CLIPS> (run)
Dividend? 17
Divisor? 3
Dividend 17 is not divisible by 3
CLIPS> (reset)
CLIPS> (run)
Dividend? 886782
Divisor? 13
Dividend 886782 is divisible by 13
CLIPS>