(defrule start (initial-fact) => (printout t "Program oblicza pierwiastki rownania kwadratowego: " crlf) (printout t "a*x^2 + b*x + c = 0" crlf crlf) (printout t "Podaj a: ") (bind ?a (read)) (printout t "Podaj b: ") (bind ?b (read)) (printout t "Podaj c: ") (bind ?c (read)) (assert (a ?a) (b ?b) (c ?c))) (defrule licz-delta (a ?a) (b ?b) (c ?c) => (bind ?delta (- (* ?b ?b) (* 4 ?a ?c))) (assert (delta ?delta))) (defrule delta-rowna-zero (delta ?delta) (a ?a) (b ?b) (test (= ?delta 0)) => (bind ?x1 (/ (- 0 ?b) (* 2 ?a))) (bind ?x2 ?x1) (assert (x1 ?x1) (x2 ?x2))) (defrule delta-wieksza-od-zero (delta ?delta) (a ?a) (b ?b) (test (> ?delta 0)) => (bind ?x1 (/ (+ (- ?b) (sqrt ?delta)) (* 2 ?a))) (bind ?x2 (/ (- (- ?b) (sqrt ?delta)) (* 2 ?a))) (assert (x1 ?x1) (x2 ?x2))) (defrule delta-ujemna (delta ?delta) (a ?a) (b ?b) (test (< ?delta 0)) => (bind ?realPart (/ (- ?b) (* 2 ?a))) (bind ?imagPart (/ (sqrt (- ?delta)) (* 2 ?a))) (assert (x1-complex ?realPart ?imagPart) (x2-complex ?realPart (- ?imagPart)))) (defrule pisz-wynik (x1 ?x1) (x2 ?x2) => (printout t "Rozwiazanie: x1 = " ?x1 " x2 = " ?x2 crlf)) (defrule pisz-wynik-zespolony (x1-complex ?realPart1 ?imagPart1) (x2-complex ?realPart2 ?imagPart2) => (printout t "Równanie kwadratowe ma dwa pierwiastki zespolone:" crlf) (printout t "x1 = " ?realPart1 " + " ?imagPart1 "i" crlf) (printout t "x2 = " ?realPart2 " - " ?imagPart2 "i" crlf)) ; Uruchom silnik wnioskujący (run)