diff --git a/aq1/aq1.metta b/aq1/aq1.metta new file mode 100644 index 0000000..7900780 --- /dev/null +++ b/aq1/aq1.metta @@ -0,0 +1,2365 @@ + + !(op 700 xfx ..) +; + + + + (= + (data $FILENAME) + ( (clear) + (nl) + (write '===> loading ') + (write $FILENAME) + (nl) + (see $FILENAME) + (repeat) + (read $X) + (or + (, + (= $X end-of-file) + (seen) + (add-symbol &self + (dataset $FILENAME)) + (set-det)) + (, + (process $X) + (fail))))) +; + + + + (= + (process (domaintype $ATTR $D)) + ( (add-symbol &self + (domaintype $ATTR $D)) (set-det))) +; + + (= + (process (valueset $ATTR $VALSET)) + ( (qsort $VALSET $VALS) + (add-symbol &self + (valueset $ATTR $VALS)) + (set-det))) +; + + (= + (process (range $ATTR $LOW $HIGH)) + ( (add-symbol &self + (range $ATTR $LOW $HIGH)) + (add-symbol &self + (subtyp $ATTR integer)) + (set-det))) +; + + (= + (process (order $ATTR $ORD)) + ( (length $ORD $HIGH) + (add-symbol &self + (order $ATTR $ORD)) + (add-symbol &self + (range $ATTR 1 $HIGH)) + (add-symbol &self + (subtyp $ATTR symbolic)) + (set-det))) +; + + (= + (process (structure $ATTR $STRUC)) + ( (explodestruc $ATTR $STRUC) + (add-symbol &self + (structure $ATTR $STRUC)) + (set-det))) +; + + (= + (process (classes $CLIST)) + ( (storeclasses $CLIST) (set-det))) +; + + (= + (process (events $CLASS $EVENTLIST)) + ( (encodeevents $EVENTLIST $ENCODEDEVENTS) + (storeevents $CLASS $ENCODEDEVENTS) + (set-det))) +; + + (= + (process $X) + ( (write '===> Invalid Data: ') + (nl) + (write $X) + (set-det))) +; + + + + (= + (storeclasses $CLIST) + ( (member $CLASSNAME $CLIST) + (add-symbol &self + (class $CLASSNAME)) + (fail))) +; + + (= + (storeclasses $_) True) +; + + + + (= + (storeevents $CLASS $EVENTLIST) + ( (member $EVENT $EVENTLIST) + (add-symbol &self + (event $CLASS $EVENT)) + (fail))) +; + + (= + (storeevents $_ $_) True) +; + + + + (= + (clear) + ( (get-symbols &self + (= + (dataset $X) true)) + (abolish domaintype 2) + (abolish valueset 2) + (abolish range 3) + (abolish order 2) + (abolish structure 2) + (abolish class 1) + (abolish event 2) + (abolish subtyp 2) + (abolish ancest 3) + (nl) + (write '===> Data ') + (write $X) + (write ' deleted.') + (nl) + (abolish dataset 1))) +; + + (= clear True) +; + + + + (= + (listdata) + ( (nl) + (get-symbols &self + (= + (dataset $DATA_SET_NAME) true)) + (write '===> Datenset ') + (write $DATA_SET_NAME) + (write :) + (nl) + (printdomaininfo) + (nl) + (printevents) + (set-det))) +; + + + + (= + (printdomaininfo) + ( (get-symbols &self + (= + (domaintype $VAR $DTYPE) true)) + (write '===> Variable ') + (write $VAR) + (write ' of type ') + (write $DTYPE) + (write .) + (nl) + (fail))) +; + + (= printdomaininfo True) +; + + + + (= + (printevents) + ( (get-symbols &self + (= + (class $CLASS) true)) + (get-symbols &self + (= + (event $CLASS $EVENT) true)) + (printcomplex $EVENT) + (write ::> ) + (write $CLASS) + (nl) + (fail))) +; + + (= printevents True) +; + + + + (= + (start) + ( (nl) + (write '===> Maximal number of Stars in the next run ?') + (nl) + (read $MAX_STAR) + (nl) + (nl) + (repeat) + (write '===> Which mode in the next run ?') + (nl) + (nl) + (write ' ic: Intersecting Covers') + (nl) + (write ' dc: Disjoint Covers') + (nl) + (write ' vl: VL mode (sequential)') + (nl) + (read $MODE) + (nl) + (abolish cover 2) + (nl) + (makecovers $MODE $MAX_STAR) + (showcovers) + (nl) + (nl) + (nl) + (write '===> You wanna try a different mode (yes,no) ?') + (nl) + (read $RETRY) + (nl) + (== $RETRY no) + (write '===> OK') + (nl) + (set-det))) +; + + + + (= + (makecovers ic $MAX_STAR) + ( (get-symbols &self + (= + (class $CLASS) true)) + (posevents $CLASS $EPOS) + (negevents $CLASS $ENEG) + (aq $EPOS $ENEG $EPOS $EPOS $MAX_STAR + (:: Nil) $COVER) + (storecover $CLASS $COVER) + (fail))) +; + + (= + (makecovers ic $_) + (set-det)) +; + + (= + (makecovers dc $MAX_STAR) + ( (get-symbols &self + (= + (class $CLASS) true)) + (posevents $CLASS $EPOS) + (neg-cover-or-events $CLASS $ENEG) + (aq $EPOS $ENEG $EPOS $EPOS $MAX_STAR + (:: Nil) $COVER) + (storecover $CLASS $COVER) + (fail))) +; + + (= + (makecovers dc $_) + (set-det)) +; + + (= + (makecovers vl $MAX_STAR) + ( (get-symbols &self + (= + (class $CLASS) true)) + (posevents $CLASS $EPOS) + (followingevents $CLASS $ENEG) + (aq $EPOS $ENEG $EPOS $EPOS $MAX_STAR + (:: Nil) $COVER) + (storecover $CLASS $COVER) + (fail))) +; + + (= + (makecovers vl $_) + (set-det)) +; + + (= + (makecovers $X $_) + ( (nl) + (write '===> ERROR - only the modes ic, dc or vl') + (write ' are valid !') + (nl) + (fail))) +; + + + + (= + (storecover $CLASS $COVER) + ( (member $COMPLEX $COVER) + (add-symbol &self + (cover $CLASS $COMPLEX)) + (fail))) +; + + (= + (storecover $_ $_) True) +; + + + + (= + (posevents $CLASS $EPOS) + ( (findset $EVENT + (get-symbols &self + (= + (event $CLASS $EVENT) true)) $EPOS) (set-det))) +; + + + + (= + (negevents $CLASS $ENEG) + ( (findset $EVENT + (negevent $CLASS $EVENT) $ENEG) (set-det))) +; + + + + (= + (negevent $CLASS $EVENT) + ( (get-symbols &self + (= + (event $NEG_CLASS $EVENT) true)) (not (= $NEG_CLASS $CLASS)))) +; + + + + (= + (cover-or-event $CLASS $COMP) + (get-symbols &self + (= + (cover $CLASS $COMP) true))) +; + + (= + (cover-or-event $CLASS $COMP) + (get-symbols &self + (= + (event $CLASS $COMP) true))) +; + + + + (= + (neg-cover-or-events $CLASS $NEG_COMPS) + ( (findset $COMP + (negcomp $CLASS $COMP) $NEG_COMPS) (set-det))) +; + + + + (= + (negcomp $CLASS $COMP) + ( (cover-or-event $NEG_CLASS $COMP) (not (= $NEG_CLASS $CLASS)))) +; + + + + (= + (followingevents $CLASS $SEVENTS) + ( (bagof $CLASS_NAME + (get-symbols &self + (= + (class $CLASS_NAME) true)) $CLASSES) + (following $CLASS $CLASSES $FCLASSES) + (findset $EVENT + (followev $FCLASSES $EVENT) $SEVENTS) + (set-det))) +; + + + + (= + (followev $FCLASSES $EVENT) + ( (member $CLASS $FCLASSES) (get-symbols &self (= (event $CLASS $EVENT) true)))) +; + + + + (= + (aq $_ $_ Nil $_ $_ $_ Nil) + (set-det)) +; + + (= + (aq $ELIST $FLIST $UN_COVERED Nil $MAX_STAR $BOUND $RESULT) + ( (write '===> Please wait a moment ...') + (nl) + (set-det) + (aq $ELIST $FLIST $UN_COVERED $UN_COVERED $MAX_STAR $BOUND $RESULT))) +; + + (= + (aq $ELIST $FLIST $UN_COVERED $SEED_LIST $MAX_STAR $BOUND + (Cons $BEST $COVER)) + ( (set-det) + (first $SEED_LIST $SEED) + (star $SEED $FLIST $MAX_STAR + (:: $ELIST $UN_COVERED) $BOUND $STAR) + (lef $LEF) + (selectbest $STAR 1 $LEF + (:: $ELIST $UN_COVERED) + (:: $BEST_COMP)) + (coveredbycomplex $BEST_COMP $UN_COVERED $COVERED_EVENTS) + (trim $BEST_COMP $COVERED_EVENTS $BEST) + (knockout1 $BEST $UN_COVERED $NEW_UN_COVERED) + (knockout $STAR $SEED_LIST $NEW_SEED_LIST) + (aq $ELIST $FLIST $NEW_UN_COVERED $NEW_SEED_LIST $MAX_STAR $BOUND $COVER) + (set-det))) +; + + + + (= + (star $_ Nil $_ $_ $PSTAR $PSTAR) + (set-det)) +; + + (= + (star $E + (Cons $F $FTAIL) $MAX_STAR $LEF_ARGS $PSTAR $NEW_PSTAR) + ( (set-det) + (extendagainst $E $F $ESTAR) + (multiply $PSTAR $ESTAR $F $EP_STAR) + (absorb $EP_STAR $MAX_STAR $AP_STAR) + (lef $LEF) + (selectbest $AP_STAR $MAX_STAR $LEF $LEF_ARGS $REDUCED_STAR) + (star $E $FTAIL $MAX_STAR $LEF_ARGS $REDUCED_STAR $NEW_PSTAR))) +; + + + + (= + (multiply $COM_SET $PSTAR $NEG_EVENT $EP_STAR) + ( (findset $NEW_COMPS + (, + (member $COMP $COM_SET) + (dis-or-mult $COMP $PSTAR $NEG_EVENT $NEW_COMPS)) $EP_LIST) + (appendx $EP_LIST $EP_STAR) + (set-det))) +; + + + + (= + (dis-or-mult $COMP $_ $NEG $ERG) + ( (disjointcomps $COMP $NEG) + (= $ERG + (:: $COMP)) + (set-det))) +; + + (= + (dis-or-mult $COMP $PSTAR $_ $NEW) + ( (findset $A + (, + (member $P $PSTAR) + (product $COMP $P $A)) $NEW) (set-det))) +; + + + + (= + (absorb $STAR $MAX_STAR $ASTAR) + ( (length $STAR $N) + (> $N $MAX_STAR) + (set-det) + (absourbr $STAR Nil $STAR1) + (absourbr $STAR1 Nil $ASTAR))) +; + + (= + (absorb $STAR $_ $STAR) True) +; + + + + (= + (absourbr Nil $S $S) + (set-det)) +; + + (= + (absourbr + (Cons $C $S) $B $AR_STAR) + ( (set-det) + (knockout1 $C $S $RS) + (absourbr $RS + (Cons $C $B) $AR_STAR))) +; + + + + (= + (selectbest $PSTAR $MAX_SIZE $_ $_ $PSTAR) + ( (length $PSTAR $L) + (=< $L $MAX_SIZE) + (set-det))) +; + + (= + (selectbest $PSTAR $MAX_SIZE + (Cons $CT $CTX) $LEF_ARGS $REDUCED_STAR) + ( (set-det) + (reduce $PSTAR $CT $LEF_ARGS $RSTAR) + (selectbest $RSTAR $MAX_SIZE $CTX $LEF_ARGS $REDUCED_STAR))) +; + + (= + (selectbest $PSTAR $MAX_SIZE Nil $_ $RSTAR) + ( (firstn $PSTAR $MAX_SIZE $RSTAR) (set-det))) +; + + + + (= + (reduce $PSTAR + (:: $CRIT_FN $N $D) + (:: $EPLUS $UN_COV_EPLUS) $RSTAR) + ( (=.. $GET_CRIT_FN + (:: $CRIT_FN $COMP $EPLUS $UN_COV_EPLUS $V)) + (findset $VC + (, + (member $COMP $PSTAR) $GET_CRIT_FN + (= $VC + (:: $V $COMP))) $VLIST) + (minmax $VLIST $MIN $MAX) + (is $TOL + (+ $MIN + (/ + (* $N + (- $MAX $MIN)) $D))) + (findset $C + (, + (member + (:: $V $C) $VLIST) + (=< $V $TOL)) $RSTAR) + (set-det))) +; + + + + (= + (minmax + (Cons + (:: $X $_) + (Cons + (:: $Y $_) $R)) $MIN $MAX) + ( (=< $X $Y) + (set-det) + (lohi + (Cons $X + (Cons $Y $R)) $MIN $MAX))) +; + + (= + (minmax + (Cons + (:: $X $_) + (Cons + (:: $Y $_) $R)) $MIN $MAX) + ( (set-det) (lohi (Cons $Y (Cons $X $R)) $MIN $MAX))) +; + + + + (= + (lohi + (Cons $X + (Cons $Y + (Cons + (:: $Z $_) $R))) $MIN $MAX) + ( (set-det) + (min + (:: $X $Z) $A) + (max + (:: $Y $Z) $B) + (lohi + (Cons $A + (Cons $B $R)) $MIN $MAX))) +; + + (= + (lohi + (:: $X $Y) $X $Y) + (set-det)) +; + + + + (= + (numbercovered $COMP $_ $EVENTS $N) + ( (coveredbycomplex $COMP $EVENTS $COVERED_E) + (length $COVERED_E $P) + (is $N + (- $P)) + (set-det))) +; + + + + (= + (numberofselectors $COMP $_ $_ $N) + ( (length $COMP $N) (set-det))) +; + + + + (= + (lef + ( (numbercovered 0 1) (numberofselectors 0 1))) True) +; + + + + (= + (knockout $OUTER_COMPS $INNER_COMPS $UN_COV_COMPS) + ( (set-det) (findset $IN_COMP (call (, (member $IN_COMP $INNER_COMPS) (nonecover $OUTER_COMPS $IN_COMP))) $UN_COV_COMPS))) +; + + + + (= + (nonecover Nil $IN_COMP) + (set-det)) +; + + (= + (nonecover + (Cons $COMP $CX) $IN_COMP) + ( (set-det) + (not (covers $COMP $IN_COMP)) + (nonecover $CX $IN_COMP))) +; + + + + (= + (knockout1 $OUTER_C $INNER_COMPS $UN_COV_COMPS) + ( (set-det) (findset $IN_C (call (, (member $IN_C $INNER_COMPS) (not (covers $OUTER_C $IN_C)))) $UN_COV_COMPS))) +; + + + + (= + (coveredbycomplex $COMPLEX $EVENTS $COVERED_E) + ( (findset $E + (, + (member $E $EVENTS) + (covers $COMPLEX $E)) $COVERED_E) (set-det))) +; + + + + (= + (newselector + (Cons + (= $A1 $V1) $T1) + (= $A1 $V2) + (Cons + (= $A1 $V2) $T1)) + (set-det)) +; + + (= + (newselector + (Cons + (= $A1 $V1) $T1) + (= $A2 $V2) + (Cons + (= $A1 $V1) $T3)) + ( (@< $A1 $A2) + (set-det) + (newselector $T1 + (= $A2 $V2) $T3))) +; + + (= + (newselector + (Cons + (= $A1 $V1) $T1) + (= $A2 $V2) + (Cons + (= $A2 $V2) + (Cons + (= $A1 $V1) $T1))) + ( (@> $A1 $A2) (set-det))) +; + + (= + (newselector Nil $SEL + (:: $SEL)) + (set-det)) +; + + + + (= + (covers + (Cons + (= $A $OUT_VAL) $OUT_C) + (Cons + (= $A $IN_VAL) $IN_C)) + ( (set-det) + (includes + (= $A $OUT_VAL) + (= $A $IN_VAL)) + (covers $OUT_C $IN_C))) +; + + (= + (covers + (Cons + (= $A1 $OUT_V) $OUT_C) + (Cons + (= $A2 $IN_V) $IN_C)) + ( (set-det) + (@< $A2 $A1) + (covers + (Cons + (= $A1 $OUT_V) $OUT_C) $IN_C))) +; + + (= + (covers Nil $_) + (set-det)) +; + + + + (= + (includes + (= $ATTR $OUT_VALS) + (= $ATTR $IN_VALS)) + ( (get-symbols &self + (= + (domaintype $ATTR nominal) true)) + (set-det) + (subset $IN_VALS $OUT_VALS))) +; + + (= + (includes + (= $ATTR $OUT_VALS) + (= $ATTR $IN_VALS)) + ( (get-symbols &self + (= + (domaintype $ATTR linear) true)) + (set-det) + (includeslin $OUT_VALS $IN_VALS))) +; + + (= + (includes + (= $ATTR $OUT_VALS) + (= $ATTR $IN_VALS)) + ( (get-symbols &self + (= + (domaintype $ATTR structured) true)) + (set-det) + (supremum $ATTR $OUT_VALS $IN_VALS))) +; + + + + (= + (disjointcomps + (Cons + (= $A $V1) $T1) + (Cons + (= $A $V2) $T2)) + ( (set-det) (disjointsel (= $A $V1) (= $A $V2)))) +; + + (= + (disjointcomps + (Cons $_ $T1) + (Cons $_ $T2)) + ( (set-det) (disjointcomps $T1 $T2))) +; + + + + (= + (disjointsel + (= $ATTR $VALS1) + (= $ATTR $VALS2)) + ( (get-symbols &self + (= + (domaintype $ATTR nominal) true)) + (set-det) + (disjoint $VALS1 $VALS2))) +; + + (= + (disjointsel + (= $ATTR $VALS1) + (= $ATTR $VALS2)) + ( (get-symbols &self + (= + (domaintype $ATTR linear) true)) + (set-det) + (disjointlin $VALS1 $VALS2))) +; + + (= + (disjointsel + (= $ATTR $VALS1) + (= $ATTR $VALS2)) + ( (get-symbols &self + (= + (domaintype $ATTR structured) true)) + (set-det) + (not (supremum $ATTR $VALS1 $VALS2)) + (not (supremum $ATTR $VALS2 $VALS1)))) +; + + + + (= + (negate $COMPLEX $NEG_COMPS) + ( (findset $NEGC + (, + (member $SEL $COMPLEX) + (negatesel $SEL $NSEL) + (= $NEGC + (:: $NSEL))) $NEG_COMPS) (set-det))) +; + + + + (= + (negatesel + (= $ATTR $VALS) + (= $ATTR $NEG_VALS)) + ( (get-symbols &self + (= + (domaintype $ATTR nominal) true)) + (set-det) + (get-symbols &self + (= + (valueset $ATTR $ALL_VALS) true)) + (difference $ALL_VALS $VALS $NEG_VALS) + (not (= $NEG_VALS Nil)))) +; + + (= + (negatesel + (= $ATTR $VALS) + (= $ATTR $NEG_VALS)) + ( (get-symbols &self + (= + (domaintype $ATTR linear) true)) + (set-det) + (negatelin $ATTR $VALS $NEG_VALS) + (not (= $NEG_VALS Nil)))) +; + + + + (= + (extendagainst + (Cons + (= $A $VP) $P) + (Cons + (= $A $VN) $N) + (Cons + (:: (= $A $VX)) $X)) + ( (extendref + (= $A $VP) + (= $A $VN) + (= $A $VX)) + (set-det) + (extendagainst $P $N $X))) +; + + (= + (extendagainst + (Cons + (= $AP $VP) $P) + (Cons + (= $AN $VN) $N) $X) + ( (@< $AP $AN) + (set-det) + (extendagainst $P + (Cons + (= $AN $VN) $N) $X))) +; + + (= + (extendagainst + (Cons + (= $AP $VP) $P) + (Cons + (= $AN $VN) $N) $X) + ( (set-det) (extendagainst (Cons (= $AP $VP) $P) $N $X))) +; + + (= + (extendagainst Nil $_ Nil) + (set-det)) +; + + (= + (extendagainst $_ Nil Nil) + (set-det)) +; + + + + (= + (extendref + (= $ATTR $POS_VALS) + (= $ATTR $NEG_VALS) + (= $ATTR $EXT_VALS)) + ( (get-symbols &self + (= + (domaintype $ATTR nominal) true)) + (set-det) + (disjoint $POS_VALS $NEG_VALS) + (negatesel + (= $ATTR $NEG_VALS) + (= $ATTR $EXT_VALS)))) +; + + (= + (extendref + (= $ATTR $POS_VALS) + (= $ATTR $NEG_VALS) + (= $ATTR $EXT_VALS)) + ( (get-symbols &self + (= + (domaintype $ATTR linear) true)) + (set-det) + (disjointlin $POS_VALS $NEG_VALS) + (negatelin $ATTR $NEG_VALS $NN_VALS) + (extendedlin $POS_VALS $NN_VALS $EXT_VALS))) +; + + (= + (extendref + (= $ATTR $POS_VAL) + (= $ATTR $NEG_VAL) + (= $ATTR $EXT_VAL)) + ( (get-symbols &self + (= + (domaintype $ATTR structured) true)) + (set-det) + (supremum $ATTR $EXT_VAL $POS_VAL) + (not (supremum $ATTR $EXT_VAL $NEG_VAL)) + (parent $ATTR $EXT_VAL $EXT_PARENT) + (supremum $ATTR $EXT_PARENT $NEG_VAL))) +; + + + + (= + (refunion + (Cons $C1 + (Cons $C2 $T)) $REFU) + ( (set-det) + (refu $C1 $C2 $C3) + (refunion + (Cons $C3 $T) $REFU))) +; + + (= + (refunion + (:: $COMP) $COMP) + (set-det)) +; + + + + (= + (refu + (Cons + (= $A $V1) $C1) + (Cons + (= $A $V2) $C2) + (Cons + (= $A $VU) $CU)) + ( (selunion + (= $A $V1) + (= $A $V2) + (= $A $VU)) + (set-det) + (refu $C1 $C2 $CU))) +; + + (= + (refu + (Cons + (= $A1 $V1) $C1) + (Cons + (= $A2 $V2) $C2) $U) + ( (@< $A1 $A2) + (set-det) + (refu $C1 + (Cons + (= $A2 $V2) $C2) $U))) +; + + (= + (refu + (Cons + (= $A1 $V1) $C1) + (Cons + (= $A2 $V2) $C2) $U) + ( (set-det) (refu (Cons (= $A1 $V1) $C1) $C2 $U))) +; + + (= + (refu Nil $_ Nil) + (set-det)) +; + + (= + (refu $_ Nil Nil) + (set-det)) +; + + + + (= + (selunion + (= $ATTR $VALS1) + (= $ATTR $VALS2) + (= $ATTR $UVALS)) + ( (get-symbols &self + (= + (domaintype $ATTR nominal) true)) + (set-det) + (union $VALS1 $VALS2 $UVALS) + (get-symbols &self + (= + (valueset $ATTR $ALL_VALS) true)) + (not (equals $UVALS $ALL_VALS)))) +; + + (= + (selunion + (= $ATTR $VALS1) + (= $ATTR $VALS2) + (= $ATTR $UVALS)) + ( (get-symbols &self + (= + (domaintype $ATTR linear) true)) + (set-det) + (low $VALS1 $L1) + (low $VALS2 $L2) + (min + (:: $L1 $L2) $LOW) + (highest $VALS1 $H1) + (highest $VALS2 $H2) + (max + (:: $H1 $H2) $HIGH) + (get-symbols &self + (= + (range $ATTR $MIN $MAX) true)) + (not (= $LOW $MIN)) + (not (== $HIGH $MAX)) + (== $UVALS + (:: (.. $LOW $HIGH))) + (set-det))) +; + + (= + (selunion + (= $ATTR $VAL1) + (= $ATTR $VAL2) + (= $ATTR $UV_AL)) + ( (get-symbols &self + (= + (domaintype $ATTR structured) true)) + (supremum $ATTR $UV_AL $VAL1) + (supremum $ATTR $UV_AL $VAL2))) +; + + + + (= + (product + (Cons + (= $A $V1) $T1) + (Cons + (= $A $V2) $T2) + (Cons + (= $A $V3) $T3)) + ( (set-det) + (selproduct + (= $A $V1) + (= $A $V2) + (= $A $V3)) + (set-det) + (product $T1 $T2 $T3))) +; + + (= + (product + (Cons + (= $A1 $V1) $T1) + (Cons + (= $A2 $V2) $T2) + (Cons + (= $A1 $V1) $T3)) + ( (@< $A1 $A2) + (set-det) + (product + (Cons + (= $A2 $V2) $T2) $T1 $T3))) +; + + (= + (product + (Cons + (= $A1 $V1) $T1) + (Cons + (= $A2 $V2) $T2) + (Cons + (= $A2 $V2) $T3)) + ( (set-det) (product (Cons (= $A1 $V1) $T1) $T2 $T3))) +; + + (= + (product $X Nil $X) + (set-det)) +; + + (= + (product Nil $X $X) + (set-det)) +; + + + + (= + (selproduct + (= $ATTR $VALS1) + (= $ATTR $VALS2) + (= $ATTR $PROD_VALS)) + ( (get-symbols &self + (= + (domaintype $ATTR nominal) true)) + (set-det) + (intersection $VALS1 $VALS2 $PROD_VALS) + (not (= $PROD_VALS Nil)))) +; + + (= + (selproduct + (= $ATTR $VALS1) + (= $ATTR $VALS2) + (= $ATTR $PROD_VALS)) + ( (get-symbols &self + (= + (domaintype $ATTR linear) true)) + (set-det) + (productlin $VALS1 $VALS2 $PROD_VALS) + (not (= $PROD_VALS Nil)))) +; + + (= + (selproduct + (= $ATTR $VALS1) + (= $ATTR $VALS2) + (= $ATTR $VALS1)) + ( (get-symbols &self + (= + (domaintype $ATTR structured) true)) + (supremum $ATTR $VALS2 $VALS1) + (set-det))) +; + + (= + (selproduct + (= $ATTR $VALS1) + (= $ATTR $VALS2) + (= $ATTR $VALS2)) + ( (get-symbols &self + (= + (domaintype $ATTR structured) true)) + (supremum $ATTR $VALS1 $VALS2) + (set-det))) +; + + + + (= + (trim $COMP $COVERED_EVENTS $TRIMMED_COMP) + ( (set-det) + (refunion $COVERED_EVENTS $REFU) + (trimcomp $COMP $REFU $TRIMMED_COMP))) +; + + + + (= + (trimcomp + (Cons + (= $A $V1) $C1) + (Cons + (= $A $VU) $CU) + (Cons + (= $A $VT) $CT)) + ( (set-det) + (selproduct + (= $A $V1) + (= $A $VU) + (= $A $VT)) + (trimcomp $C1 $CU $CT))) +; + + (= + (trimcomp + (Cons + (= $A1 $V1) $C1) + (Cons + (= $A2 $VU) $CU) $CT) + ( (@< $A2 $A1) + (set-det) + (trimcomp + (Cons + (= $A1 $V1) $C1) $CU $CT))) +; + + (= + (trimcomp + (Cons + (= $A1 $V1) $C1) + (Cons + (= $A2 $VU) $CU) + (Cons + (= $A1 $V1) $CT)) + ( (set-det) (trimcomp $C1 (Cons (= $A2 $VU) $CU) $CT))) +; + + (= + (trimcomp $X Nil $X) + (set-det)) +; + + (= + (trimcomp Nil $_ Nil) + (set-det)) +; + + + + (= + (encodeevents Nil Nil) + (set-det)) +; + + (= + (encodeevents + (Cons $E $REST) + (Cons $EE $ENCODE_REST)) + ( (set-det) + (encodeevent $E Nil $EE) + (encodeevents $REST $ENCODE_REST))) +; + + + + (= + (encodeevent Nil $EVENT $EVENT) + (set-det)) +; + + (= + (encodeevent + (Cons $SEL $E) $PARTIAL_EV $NEW_PARTIAL_EV) + ( (set-det) + (encodesel $SEL $ENCODED_SEL) + (newselector $PARTIAL_EV $ENCODED_SEL $PPEV) + (encodeevent $E $PPEV $NEW_PARTIAL_EV))) +; + + + + (= + (encodesel + (:: (= $ATTR $VAL)) + (= $ATTR + (:: $VAL))) + ( (get-symbols &self + (= + (domaintype $ATTR nominal) true)) (set-det))) +; + + (= + (encodesel + (:: (= $ATTR $VAL)) + (= $ATTR + (:: (.. $VAL $VAL)))) + ( (get-symbols &self + (= + (domaintype $ATTR linear) true)) + (get-symbols &self + (= + (subtyp $ATTR integer) true)) + (set-det))) +; + + (= + (encodesel + (:: (= $ATTR $SYM)) + (= $ATTR + (:: (.. $ORD $ORD)))) + ( (get-symbols &self + (= + (domaintype $ATTR linear) true)) + (get-symbols &self + (= + (subtyp $ATTR symbolic) true)) + (set-det) + (ord $ATTR $SYM $ORD))) +; + + (= + (encodesel + (:: (= $ATTR $VAL)) + (= $ATTR $VAL)) + ( (get-symbols &self + (= + (domaintype $ATTR structured) true)) (set-det))) +; + + (= + (encodesel $S $_) + ( (write '===> ERROR - unknown selector type: ') (write $S))) +; + + + + (= + (showcovers) + ( (get-symbols &self + (= + (class $CLASS) true)) + (showcover $CLASS) + (fail))) +; + + (= showcovers True) +; + + + + (= + (showcover $CLASS) + ( (nl) + (nl) + (write '===> Cover of class ') + (write $CLASS) + (write :) + (set-det) + (nl) + (get-symbols &self + (= + (cover $CLASS $COVER) true)) + (printcomplex $COVER) + (nl) + (fail))) +; + + (= + (showcover $_) True) +; + + + + (= + (printcomplex $COMPLEX) + ( (member $SELECTOR $COMPLEX) + (printselector $SELECTOR) + (fail))) +; + + (= + (printcomplex $_) + (set-det)) +; + + + + (= + (printselector (= $ATTR $VALS)) + ( (get-symbols &self + (= + (domaintype $ATTR nominal) true)) + (set-det) + (write [) + (write $ATTR) + (write = ) + (prinlist $VALS) + (write ]))) +; + + (= + (printselector (= $ATTR $VALS)) + ( (get-symbols &self + (= + (domaintype $ATTR linear) true)) + (get-symbols &self + (= + (subtyp $ATTR integer) true)) + (set-det) + (write [) + (write $ATTR) + (write = ) + (prinlin $VALS) + (write ]))) +; + + (= + (printselector (= $ATTR $VALS)) + ( (get-symbols &self + (= + (domaintype $ATTR linear) true)) + (get-symbols &self + (= + (subtyp $ATTR symbolic) true)) + (set-det) + (write [) + (write $ATTR) + (write = ) + (prinsym $ATTR $VALS) + (write ]))) +; + + (= + (printselector (= $ATTR $VAL)) + ( (get-symbols &self + (= + (domaintype $ATTR structured) true)) + (set-det) + (write [) + (write $ATTR) + (write = ) + (write $VAL) + (write ]))) +; + + + + (= + (intersection + (Cons $A $B) + (Cons $A $C) + (Cons $A $X)) + ( (set-det) (intersection $B $C $X))) +; + + (= + (intersection + (Cons $A $B) + (Cons $C $D) $X) + ( (@< $A $C) + (set-det) + (intersection + (Cons $C $D) $B $X))) +; + + (= + (intersection + (Cons $A $B) + (Cons $C $D) $X) + ( (set-det) (intersection (Cons $A $B) $D $X))) +; + + (= + (intersection $Y Nil Nil) + (set-det)) +; + + (= + (intersection Nil $Y Nil) + (set-det)) +; + + + + (= + (difference + (Cons $A $B) + (Cons $A $C) $X) + ( (set-det) (difference $B $C $X))) +; + + (= + (difference + (Cons $A $B) + (Cons $C $D) + (Cons $A $X)) + ( (@< $A $C) + (set-det) + (difference $B + (Cons $C $D) $X))) +; + + (= + (difference + (Cons $A $B) + (Cons $C $D) + (Cons $C $X)) + ( (set-det) (difference (Cons $A $B) $D $X))) +; + + (= + (difference $Y Nil $Y) + (set-det)) +; + + (= + (difference Nil $Y Nil) + (set-det)) +; + + + + (= + (union + (Cons $A $B) + (Cons $A $C) + (Cons $A $X)) + ( (set-det) (union $B $C $X))) +; + + (= + (union + (Cons $A $B) + (Cons $C $D) + (Cons $A $X)) + ( (@< $A $C) + (set-det) + (union + (Cons $C $D) $B $X))) +; + + (= + (union + (Cons $A $B) + (Cons $C $D) + (Cons $C $X)) + ( (set-det) (union (Cons $A $B) $D $X))) +; + + (= + (union $Y Nil $Y) + (set-det)) +; + + (= + (union Nil $Y $Y) + (set-det)) +; + + + + (= + (disjoint + (Cons $A $B) + (Cons $C $D)) + ( (@< $A $C) + (set-det) + (disjoint + (Cons $C $D) $B))) +; + + (= + (disjoint + (Cons $A $B) + (Cons $C $D)) + ( (@< $C $A) + (set-det) + (disjoint + (Cons $A $B) $D))) +; + + (= + (disjoint $_ Nil) + (set-det)) +; + + (= + (disjoint Nil $_) + (set-det)) +; + + + + (= + (subset + (Cons $A $B) + (Cons $A $C)) + ( (set-det) (subset $B $C))) +; + + (= + (subset + (Cons $A $B) + (Cons $C $D)) + ( (@> $A $C) + (set-det) + (subset + (Cons $A $B) $D))) +; + + (= + (subset Nil $_) + (set-det)) +; + + + + (= + (equals $X $Y) + ( (= $X $Y) (set-det))) +; + + + + (= + (cardinality $X $N) + ( (set-det) (length $X $N))) +; + + + + (= + (ord $ATTR $SYM $N) + ( (get-symbols &self + (= + (order $ATTR $L) true)) + (at $SYM $L $N 1) + (set-det))) +; + + + + (= + (at $SYM + (Cons $SYM $X) $N $N) True) +; + + (= + (at $SYM + (Cons $_ $X) $N $I) + ( (is $J + (+ $I 1)) + (at $SYM $X $N $J) + (set-det))) +; + + (= + (at $_ $_ $_ $_) + (write '===> ERROR - symbol undeclared')) +; + + + + (= + (low + (Cons + (.. $L $H) $_) $L) True) +; + + + + (= + (highest + ( (.. $L $H)) $H) True) +; + + (= + (highest + (Cons + (.. $L $H) $X) $HIGH) + ( (set-det) (highest $X $HIGH))) +; + + + + (= + (includeslin $_ ()) True) +; + + (= + (includeslin + (Cons + (.. $LO $HO) $XO) + (Cons + (.. $LI $HI) $XI)) + ( (@< $HO $LI) + (set-det) + (includeslin $XO + (Cons + (.. $LI $HI) $XI)))) +; + + (= + (includeslin + (Cons + (.. $LO $HO) $XO) + (Cons + (.. $LI $HI) $XI)) + ( (set-det) + (@=< $LO $LI) + (@>= $HO $HI) + (includeslin + (Cons + (.. $LO $HO) $XO) $XI))) +; + + + + (= + (disjointlin Nil $_) + (set-det)) +; + + (= + (disjointlin $_ Nil) + (set-det)) +; + + (= + (disjointlin + (Cons + (.. $L1 $H1) $X1) + (Cons + (.. $L2 $H2) $X2)) + ( (@< $H1 $L2) + (set-det) + (disjointlin $X1 + (Cons + (.. $L2 $H2) $X2)))) +; + + (= + (disjointlin + (Cons + (.. $L1 $H1) $X1) + (Cons + (.. $L2 $H2) $X2)) + ( (@< $H2 $L1) + (set-det) + (disjointlin $X2 + (Cons + (.. $L1 $H1) $X1)))) +; + + + + (= + (negatelin $ATTR + (Cons + (.. $LP $HP) $XP) $N) + ( (set-det) + (neglinlow $ATTR $LP $LOW) + (neglinmid + (Cons + (.. $LP $HP) $XP) $HI $MID) + (neglinhi $ATTR $HI $HIGH) + (appendx + (:: $LOW $MID $HIGH) $N))) +; + + + + (= + (neglinlow $ATTR $LP Nil) + ( (get-symbols &self + (= + (range $ATTR $LP $_) true)) (set-det))) +; + + (= + (neglinlow $ATTR $LP + (:: (.. $LOW $H))) + ( (set-det) + (get-symbols &self + (= + (range $ATTR $LOW $_) true)) + (is $H + (- $LP 1)))) +; + + + + (= + (neglinmid + (:: (.. $L $H)) $H Nil) + (set-det)) +; + + (= + (neglinmid + (Cons + (.. $L1 $H1) + (Cons + (.. $L2 $H2) $X)) $HI + (:: + (.. $L $H) $N)) + ( (> $L2 + (+ $H1 1)) + (set-det) + (is $L + (+ $H1 1)) + (is $H + (- $L2 1)) + (neglinmid + (Cons + (.. $L2 $H2) $X) $HI $N))) +; + + (= + (neglinmid + (Cons + (.. $L1 $H1) + (Cons + (.. $L2 $H2) $X)) $HI $N) + ( (set-det) (neglinmid $X $HI $N))) +; + + + + (= + (neglinhi $ATTR $HI Nil) + ( (get-symbols &self + (= + (range $ATTR $_ $HI) true)) (set-det))) +; + + (= + (neglinhi $ATTR $HI + (:: (.. $L $HIGH))) + ( (set-det) + (get-symbols &self + (= + (range $ATTR $_ $HIGH) true)) + (is $L + (+ $HI 1)))) +; + + + + (= + (extendedlin $_ Nil Nil) + (set-det)) +; + + (= + (extendedlin Nil $_ Nil) + (set-det)) +; + + (= + (extendedlin + (Cons + (.. $LP $HP) $XP) + (Cons + (.. $LN $HN) $XN) $XVALS) + ( (@< $HN $LP) + (set-det) + (extendedlin + (Cons + (.. $LP $HP) $XP) $XN $XVALS))) +; + + (= + (extendedlin + (Cons + (.. $LP $HP) $XP) + (Cons + (.. $LN $HN) $XN) $XVALS) + ( (@< $HP $LN) + (set-det) + (extendedlin $XP + (Cons + (.. $LN $HN) $XN) $XVALS))) +; + + (= + (extendedlin + (Cons + (.. $LP $HP) $XP) + (Cons + (.. $LN $HN) $XN) + (Cons + (.. $LN $HN) $XVALS)) + ( (set-det) + (@=< $LN $LP) + (@>= $HN $HP) + (extendedlin $XP $XN $XVALS))) +; + + + + (= + (productlin Nil $_ Nil) + (set-det)) +; + + (= + (productlin $_ Nil Nil) + (set-det)) +; + + (= + (productlin + (Cons + (.. $L1 $H1) $X1) + (Cons + (.. $L2 $H2) $X2) $P) + ( (@< $H1 $L2) + (set-det) + (productlin $X1 + (Cons + (.. $L2 $H2) $X2) $P))) +; + + (= + (productlin + (Cons + (.. $L1 $H1) $X1) + (Cons + (.. $L2 $H2) $X2) $P) + ( (@< $H2 $L1) + (set-det) + (productlin $X2 + (Cons + (.. $L1 $H1) $X1) $P))) +; + + (= + (productlin + (Cons + (.. $L1 $H1) $X1) + (Cons + (.. $L2 $H2) $X2) + (Cons + (.. $L $H) $P)) + ( (set-det) + (max + (:: $L1 $L2) $L) + (min + (:: $H1 $H2) $H) + (productlin $X1 $X2 $P))) +; + + + + (= + (prinlin (:: $A)) + ( (set-det) (prinseg $A))) +; + + (= + (prinlin (:: $A $B)) + ( (set-det) + (prinseg $A) + (write ' v ') + (prinlin $B))) +; + + (= + (prinlin Nil) + ( (set-det) (write '===> ERROR - null RHS in linear selector'))) +; + + + + (= + (prinseg (.. $L $H)) + ( (= $L $H) + (write $L) + (set-det))) +; + + (= + (prinseg $A) + ( (write $A) (set-det))) +; + + + + (= + (prinsym $ATTR + (:: $A)) + ( (set-det) (prinsymseg $ATTR $A))) +; + + (= + (prinsym $ATTR + (Cons $A $B)) + ( (set-det) + (prinsymseg $ATTR $A) + (write ,) + (prinsym $ATTR $B))) +; + + (= + (prinsym $_ Nil) + ( (set-det) (write '===> ERROR - null RHS in linear selector'))) +; + + + + (= + (prinsymseg $ATTR + (.. $L $H)) + ( (= $L $H) + (ord $ATTR $SYM $L) + (write $SYM) + (set-det))) +; + + (= + (prinsymseg $ATTR + (.. $L $H)) + ( (ord $ATTR $SYML $L) + (ord $ATTR $SYMH $H) + (write (.. $SYML $SYMH)) + (set-det))) +; + + + + (= + (supremum $ATTR $HI_NODE $LO_NODE) + ( (get-symbols &self + (= + (ancest $ATTR $LO_NODE $ALIST) true)) (member $HI_NODE $ALIST))) +; + + (= + (supremum $ATTR $X $X) True) +; + + + + (= + (parent $ATTR $NODE $PARENT) + (get-symbols &self + (= + (ancest $ATTR $NODE + (Cons $PARENT $_)) true))) +; + + + + (= + (explodestruc $ATTR $STRUCTUR_SPEC) + ( (allnodes $STRUCTUR_SPEC $NODE_LIST) + (member $NODE $NODE_LIST) + (predecessorlist $NODE $STRUCTUR_SPEC $ALIST) + (add-symbol &self + (ancest $ATTR $NODE $ALIST)) + (fail))) +; + + (= + (explodestruc $_ $_) True) +; + + + + (= + (allnodes Nil Nil) + (set-det)) +; + + (= + (allnodes + (Cons + (parent $SIBS $P) $X) $NODE_LIST) + ( (set-det) + (qsort $SIBS $L1) + (union $L1 + (:: $P) $L2) + (allnodes $X $L3) + (union $L2 $L3 $NODE_LIST))) +; + + + + (= + (predecessorlist $NODE $STRUCTUR_SPEC + (Cons $P $X)) + ( (father $NODE $STRUCTUR_SPEC $P) + (set-det) + (predecessorlist $P $STRUCTUR_SPEC $X))) +; + + (= + (predecessorlist $_ $_ Nil) + (set-det)) +; + + + + (= + (father $NODE + (Cons + (parent $SIBS $P) $X) $P) + ( (member $NODE $SIBS) (set-det))) +; + + (= + (father $NODE + (Cons $_ $X) $P) + ( (father $NODE $X $P) (set-det))) +; + + + + (= + (first + (Cons $A $B) $A) + (set-det)) +; + + + + (= + (appendx $X $Y) + ( (findset $A + (, + (member $B $X) + (member $A $B)) $Y) (set-det))) +; + + + + (= + (firstn $_ 0 Nil) + (set-det)) +; + + (= + (firstn + (Cons $A $B) $N + (Cons $A $C)) + ( (set-det) + (is $M + (- $N 1)) + (firstn $B $M $C))) +; + + (= + (firstn Nil $_ Nil) + (set-det)) +; + + + + (= + (following $X + (Cons $X $AFTER_X) $AFTER_X) + (set-det)) +; + + (= + (following $X + (Cons $_ $LIST) $AFTER_X) + ( (set-det) (following $X $LIST $AFTER_X))) +; + + (= + (following $X Nil Nil) + (set-det)) +; + + + + (= + (qsort $L0 $L) + ( (qsort $L0 $L Nil) (set-det))) +; + + + (= + (qsort + (Cons $X $L) $R $R0) + ( (partition $L $X $L0 $L1) + (qsort $L1 $R1 $R0) + (qsort $L0 $R + (Cons $X $R1)))) +; + + (= + (qsort Nil $R $R) + (set-det)) +; + + + + (= + (partition + (Cons $X $L) $Y + (Cons $X $L0) $L1) + ( (@=< $X $Y) + (set-det) + (partition $L $Y $L0 $L1))) +; + + (= + (partition + (Cons $X $L) $Y $L0 + (Cons $X $L1)) + ( (set-det) (partition $L $Y $L0 $L1))) +; + + (= + (partition () $_ () ()) True) +; + + + + (= + (remove $X Nil Nil) + (set-det)) +; + + (= + (remove $X + (Cons $X $B) $C) + ( (set-det) (remove $X $B $C))) +; + + (= + (remove $X + (Cons $A $B) + (Cons $A $C)) + ( (set-det) (remove $X $B $C))) +; + + + + (= + (prinlist (:: $A)) + ( (write $A) (set-det))) +; + + (= + (prinlist (Cons $A $B)) + ( (set-det) + (write $A) + (write ' v ') + (prinlist $B))) +; + + (= + (prinlist Nil) + ( (write '===> Nothing to print') (set-det))) +; + + + + (= + (min + (Cons $X + (Cons $Y $T)) $Z) + ( (@=< $X $Y) + (set-det) + (min + (Cons $X $T) $Z))) +; + + (= + (min + (Cons $X + (Cons $Y $T)) $Z) + ( (set-det) (min (Cons $Y $T) $Z))) +; + + (= + (min + (:: $X) $X) + (set-det)) +; + + + + (= + (max + (Cons $X + (Cons $Y $T)) $Z) + ( (@>= $X $Y) + (set-det) + (max + (Cons $X $T) $Z))) +; + + (= + (max + (Cons $X + (Cons $Y $T)) $Z) + ( (set-det) (max (Cons $Y $T) $Z))) +; + + (= + (max + (:: $X) $X) + (set-det)) +; + + + + (= + (findset $X $G $L) + ( (findall $X $G $ZWERG) (sort $ZWERG $L))) +; + + + + (= + (help) + ( (nl) + (nl) + (write '===> AQ-PROLOG') + (nl) + (write '===> Load data with command: data(fn)') + (nl) + (write '===> Show data with command: listdata') + (nl) + (write '===> Start AQ with command: start') + (nl) + (nl))) +; + + + + !(help *) +; + + diff --git a/aq1/aq1_1.metta b/aq1/aq1_1.metta new file mode 100644 index 0000000..ff4b65d --- /dev/null +++ b/aq1/aq1_1.metta @@ -0,0 +1,63 @@ + + (= + (domaintype color nominal) True) +; + + + (= + (valueset color + (red green blue)) True) +; + + + (= + (domaintype temp linear) True) +; + + + (= + (order temp + (cold warm hot)) True) +; + + + (= + (domaintype shape nominal) True) +; + + + (= + (valueset shape + (square hexagon octagon)) True) +; + + + (= + (classes + (past present future)) True) +; + + + (= + (events past + ( ( ( (= color red)) + ( (= temp warm)) + ( (= shape square))) (((= color green)) ((= temp cold)) ((= shape hexagon))))) True) +; + + (= + (events present + ( ( ( (= color blue)) + ( (= temp warm)) + ( (= shape square))) (((= color red)) ((= temp hot)) ((= shape hexagon))))) True) +; + + (= + (events future + ( ( ( (= color green)) + ( (= temp warm)) + ( (= shape hexagon))) (((= color blue)) ((= temp hot)) ((= shape octagon))))) True) +; + + + diff --git a/aq1/aq1_2.metta b/aq1/aq1_2.metta new file mode 100644 index 0000000..9a45b92 --- /dev/null +++ b/aq1/aq1_2.metta @@ -0,0 +1,81 @@ + + (= + (domaintype color nominal) True) +; + + + (= + (valueset color + (red green blue)) True) +; + + + (= + (domaintype temp linear) True) +; + + + (= + (order temp + (cold warm hot)) True) +; + + + (= + (domaintype shape nominal) True) +; + + + (= + (valueset shape + (square hexagon octagon)) True) +; + + + (= + (classes + (past present future)) True) +; + + + (= + (events past + ( ( ( (= color red)) + ( (= shape square)) + ( (= temp warm))) + ( ( (= color red)) + ( (= shape hexagon)) + ( (= temp hot))) + ( ( (= color green)) + ( (= shape hexagon)) + ( (= temp cold))))) True) +; + + (= + (events present + ( ( ( (= color blue)) + ( (= shape square)) + ( (= temp warm))) + ( ( (= color red)) + ( (= shape hexagon)) + ( (= temp hot))) + ( ( (= color red)) + ( (= shape hexagon)) + ( (= temp hot))))) True) +; + + (= + (events future + ( ( ( (= color green)) + ( (= shape hexagon)) + ( (= temp warm))) + ( ( (= color red)) + ( (= shape hexagon)) + ( (= temp hot))) + ( ( (= color blue)) + ( (= shape octagon)) + ( (= temp hot))))) True) +; + + + diff --git a/arch1/arch1.metta b/arch1/arch1.metta new file mode 100644 index 0000000..79e8116 --- /dev/null +++ b/arch1/arch1.metta @@ -0,0 +1,1347 @@ + + (= + (process-stored-inputs $ConceptName) + ( (or + (remove-symbol &self + (concept $ConceptName $_)) True) + (set-det) + (process-stored-inputs-body $ConceptName))) +; + + + + (= + (process-stored-inputs-body $ConceptName) + ( (msgs (:: nl 'Processing stored inputs for ' $ConceptName ...)) + (input $ID $Type $ConceptName $Input) + (msgs (:: nl 'Input ' $ID : $Type nl $Input)) + (process-example $Type $ConceptName $Input) + (concept $ConceptName $Concept) + (concept-template $Concept $Template) + (concept-constraints $Concept $Constraints) + (msgs (:: nl 'New Concept Definition is:' nl '--- Template:' nl $Template nl '--- Constraints:' nl $Constraints nl)) + (fail))) +; + + (= + (process-stored-inputs-body $_) + (msgs (:: nl 'No more inputs. Done.'))) +; + + + + + (= + (process-example example $ConceptName $Example) + ( (remove-symbol &self + (concept $ConceptName $Definition)) + (set-det) + (generalize $Example $Definition $NewDefinition) + (add-symbol &self + (concept $ConceptName $NewDefinition)) + (set-det))) +; + + (= + (process-example example $ConceptName $Example) + ( (set-det) + (initial-generalization $Example $InitialDefinition) + (add-symbol &self + (concept $ConceptName $InitialDefinition)))) +; + + (= + (process-example near-miss $ConceptName $Example) + ( (remove-symbol &self + (concept $ConceptName $Definition)) + (set-det) + (specialize $Example $Definition $NewDefinition) + (add-symbol &self + (concept $ConceptName $NewDefinition)) + (set-det))) +; + + (= + (process-example near-miss $ConceptName $_) + ( (set-det) (msgs (:: nl 'Cannot process a (near) miss as the first example of ' $ConceptName . nl 'Please begin with a (prototypical) example instead.')))) +; + + + + (= + (specialize $Example $OldConcept $OldConcept) + ( (is-member $Example $OldConcept no) + (set-det) + (msgs (:: nl 'Already excluded.')))) +; + + (= + (specialize $Example $OldConcept $NewConcept) + ( (match $OldConcept $Example Nil $BL $PL $ML $AL) + (find-important-differences-p specialize $PL $ML $AL $DifferenceDescriptions) + (specialize-concept-definition $DifferenceDescriptions $BL $OldConcept $NewConcept) + (set-det))) +; + + (= + (specialize $_ $Definition $Definition) + (msgs (:: nl 'Specialize failed. Ignoring example.'))) +; + + + + + (= + (generalize $Example $OldConcept $OldConcept) + ( (is-member $Example $OldConcept yes) + (set-det) + (msgs (:: nl 'Already included.')))) +; + + (= + (generalize $Example $OldConcept $NewConcept) + ( (match $OldConcept $Example Nil $_ $PL $ML $AL) + (find-important-differences-p generalize $PL $ML $AL $DifferenceDescriptions) + (generalize-concept-definition $DifferenceDescriptions $OldConcept $NewConcept))) +; + + (= + (generalize $_ $Concept $Concept) + (msgs (:: nl 'Generalize failed. Ignoring example.'))) +; + + + + + (= + (find-important-differences-p generalize $PL $ML $_ $DD) + ( (mark-as partial $PL $DD1) + (mark-as missing $ML $DD2) + (append $DD1 $DD2 $DD))) +; + + (= + (find-important-differences-p specialize $_ Nil $AL $DD) + ( (not (= $AL Nil)) + (set-det) + (mark-as addition $AL $DD))) +; + + (= + (find-important-differences-p specialize $_ $ML $_ $DD) + ( (not (= $ML Nil)) + (set-det) + (mark-as missing $ML $DD))) +; + + (= + (find-important-differences-p specialize $PL $_ $_ $DD) + (mark-as partial $PL $DD)) +; + + + + (= + (differences-acceptable-p $Diffs) + ( (length $Diffs 1) (set-det))) +; + + (= + (differences-acceptable-p $Diffs) + ( (same-functor-p $Diffs $_) (set-det))) +; + + + + (= + (same-functor-p Nil $_) + (set-det)) +; + + (= + (same-functor-p + (:: $LastDifference) $Functor) + ( (set-det) (=.. $LastDifference (Cons $Functor $_)))) +; + + (= + (same-functor-p + (Cons $First $Rest) $Functor) + ( (same-functor-p $Rest $Functor) (=.. $First (Cons $Functor $_)))) +; + + + + (= + (mark-as $_ Nil Nil) + (set-det)) +; + + (= + (mark-as $Mark + (Cons $First $Rest) + (Cons $FirstMarked $RestMarked)) + ( (=.. $FirstMarked + (:: $Mark $First)) (mark-as $Mark $Rest $RestMarked))) +; + + + + (= + (concept_p + (concept $_ $_ $_)) True) +; + + + (= + (concept_name + (concept $Name $_ $_) $Name) True) +; + + + (= + (concept_template + (concept $_ $Template $_) $Template) True) +; + + + (= + (concept_constraints + (concept $_ $_ $Constraints) $Constraints) True) +; + + + + (= + (alter_concept_constraints + (concept $N $T $_) $C + (concept $N $T $C)) True) +; + + + (= + (alter_concept_template + (concept $N $_ $C) $T + (concept $N $T $C)) True) +; + + + + (= + (concept-equal-p + (concept $Name $Template1 $Constraints1) + (concept $Name $Template2 $Constraints2)) + ( (set-equal-p $Template1 $Template2) (set-equal-p $Constraints1 $Constraints2))) +; + + + + (= + (print-concept $Concept) + ( (concept-name $Concept $Name) + (or + (= $Name -) True) + (concept-template $Concept $Template) + (concept-constraints $Concept $Constraints) + (msgs (:: nl 'Concept ' $Name : nl 'Template: ' $Template nl 'Constraints: ' $Constraints)) + (set-det))) +; + + + + (= + (print-concepts $Concepts) + ( (member $Concept $Concepts) + (print-concept $Concept) + (fail))) +; + + (= + (print_concepts $_) True) +; + + + + (= + (is-member $Example $Concept $Decision) + ( (match $Concept $Example Nil $_ $PL $ML $_) + (set-det) + (or + (, + (= $ML Nil) + (= $PL Nil) + (set-det) + (= $Decision yes)) + (= $Decision possible)))) +; + + (= + (is_member $_ $_ no) True) +; + + + + (= + (match $Concept $Ex $OldBL $NewBL $PL $ML $AL) + (match $Concept $Ex $OldBL $NewBL $PL $ML $AL t)) +; + + + (= + (match $Concept $Ex $OldBL $NewBL $PL $ML $AL $CheckNecessaryP) + ( (concept-template $Concept $Templ) + (concept-constraints $Concept $Constraints) + (unambiguous-match $Templ $Ex $OldBL $RestTempl1 $RestEx1 $BL1) + (perfect-match $RestTempl1 $RestEx1 $BL1 $RestTempl2 $RestEx2 $BL2 $CheckNecessaryP) + (not (unsatisfied-constraint-p $Constraints $Ex $BL2)) + (partial-match $RestTempl2 $RestEx2 $BL2 $NewBL $PL $ML $AL))) +; + + + + (= + (unambiguous-match $Templ $Ex $OldBL $Templ $Ex $OldBL) + ( (or + (= $Templ Nil) + (= $Ex Nil)) (set-det))) +; + + (= + (unambiguous-match $Templ $Ex $OldBL $RestTempl $RestEx $NewBL) + ( (find-unambiguous-match-p $Templ $Ex $OldBL $RestTempl1 $RestEx1 $NewBL1) + (set-det) + (unambiguous-match $RestTempl1 $RestEx1 $NewBL1 $RestTempl $RestEx $NewBL))) +; + + (= + (unambiguous-match $Templ $Ex $OldBL $Templ $Ex $OldBL) + (set-det)) +; + + + + (= + (find-unambiguous-match-p $Templ $Ex $OldBL $RestTempl $RestEx $NewBL) + ( (enumerate $Templ $Part $RestTempl) + (find-unambiguous-match-p1 $Part $Templ $Ex $OldBL $RestEx $NewBL) + (set-det))) +; + + + + (= + (find-unambiguous-match-p1 $Part $Template $Ex $OldBL $RestEx $NewBL) + ( (enumerate $Ex $ExamplePart $RestEx) + (perfect-match-p $Part $ExamplePart $OldBL $NewBL) + (not (non-unique-match-p $Part $ExamplePart $Template $Ex $OldBL)) + (set-det))) +; + + + + (= + (non-unique-match-p $Part $ExamplePart $Template $Example $BL) + ( (member $Part1 $Template) + (member $ExamplePart1 $Example) + (or + (, + (not (= $Part1 $Part)) + (= $ExamplePart1 $ExamplePart)) + (, + (not (= $ExamplePart1 $ExamplePart)) + (= $Part1 $Part))) + (perfect-match-p $Part1 $ExamplePart1 $BL $_) + (set-det))) +; + + + + (= + (perfect-match $Templ $Ex $OldBL $RestTempl $RestEx $NewBL $CheckNecessaryP) + ( (findbag + (:: $RestTempl1 $RestEx1 $NewBL1) + (, + (perfect-match1 $Templ $Ex $OldBL $RestTempl1 $RestEx1 $NewBL1) + (check-for-unmatched-necessary-constraints-p $RestTempl1 $CheckNecessaryP)) $PerfectMatches) + (remove-duplicates $PerfectMatches $PerfectMatches1 perfect-match-equal-p) + (list-sort $PerfectMatches1 $SortedPerfectMatches perfect-match-better-p) + (get-best $SortedPerfectMatches $BestMatches perfect-match-better-p) + (member + (:: $RestTempl $RestEx $NewBL) $BestMatches))) +; + + + + (= + (perfect-match1 $Templ $Ex $OldBL $Templ $Ex $OldBL) + ( (or + (= $Templ Nil) + (= $Ex Nil)) (set-det))) +; + + (= + (perfect-match1 $Templ $Ex $OldBL $Templ $Ex $OldBL) + ( (not (find-perfect-match-p $Templ $Ex $OldBL $_ $_ $_)) (set-det))) +; + + (= + (perfect-match1 $Templ $Ex $OldBL $RestTempl $RestEx $NewBL) + ( (find-perfect-match-p $Templ $Ex $OldBL $RestTempl1 $RestEx1 $NewBL1) (perfect-match1 $RestTempl1 $RestEx1 $NewBL1 $RestTempl $RestEx $NewBL))) +; + + + + (= + (find-perfect-match-p $Templ $Ex $OldBL $RestTempl $RestEx $NewBL) + ( (enumerate $Templ $Part $RestTempl) (find-perfect-match-p1 $Part $Ex $OldBL $RestEx $NewBL))) +; + + + + (= + (find-perfect-match-p1 $Part $Ex $OldBL $RestEx $NewBL) + ( (enumerate $Ex $ExamplePart $RestEx) (perfect-match-p $Part $ExamplePart $OldBL $NewBL))) +; + + + + (= + (perfect-match-p + (must $Constraint) $Fact $OldBL $NewBL) + (perfect-match-p $Constraint $Fact $OldBL $NewBL)) +; + + (= + (perfect-match-p $Constraint $Fact $OldBL $NewBL) + ( (=.. $Constraint + (Cons $Functor $Args1)) + (=.. $Fact + (Cons $Functor $Args2)) + (count-differences-p $Args1 $Args2 $OldBL $NewBL 0))) +; + + (= + (perfect-match-p $Constraint $Fact $OldBL $NewBL) + ( (infer $Fact $FactDerivation) (perfect-match-p $Constraint $FactDerivation $OldBL $NewBL))) +; + + + + + (= + (perfect-match-better-p + (:: $RestTempl1 $RestEx1 $BL1) + (:: $RestTempl2 $RestEx2 $BL2)) + ( (length $RestTempl1 $L1) + (length $RestTempl2 $L2) + (< $L1 $L2))) +; + + + + (= + (perfect-match-equal-p + (:: $RestTempl1 $RestEx1 $BL1) + (:: $RestTempl2 $RestEx2 $BL2)) + ( (set-equal-p $RestTempl1 $RestTempl2) + (set-equal-p $RestEx1 $RestEx2) + (set-equal-p $BL1 $BL2))) +; + + + + (= + (unsatisfied-constraint-p $Constraints $Ex $BL) + ( (member $Constraint $Constraints) + (member $Fact $Ex) + (or + (= $Constraint + (not $BaseConstraint)) + (= $BaseConstraint $Constraint)) + (perfect-match-p $BaseConstraint $Fact $BL $_) + (set-det))) +; + + + + (= + (check-for-unmatched-necessary-constraints-p $_ nil) + (set-det)) +; + + (= + (check-for-unmatched-necessary-constraints-p $Templ $_) + (not (member (must $_) $Templ))) +; + + + + (= + (partial-match $Templ $Ex $OldBL $NewBL $PL $RestTempl $RestEx) + ( (findbag + (:: $PL1 $RestTempl1 $RestEx1 $NewBL1) + (partial-match1 $Templ $Ex $OldBL $PL1 $RestTempl1 $RestEx1 $NewBL1) $PartialMatches) + (remove-duplicates $PartialMatches $PartialMatches1 partial-match-equal-p) + (list-sort $PartialMatches1 $SortedPartialMatches partial-match-better-p) + (get-best $SortedPartialMatches $BestMatches partial-match-better-p) + (member + (:: $PL $RestTempl $RestEx $NewBL) $BestMatches))) +; + + + + + (= + (partial-match1 $Templ $Ex $OldBL Nil $Templ $Ex $OldBL) + ( (or + (= $Templ Nil) + (= $Ex Nil)) (set-det))) +; + + (= + (partial-match1 $Templ $Ex $OldBL Nil $Templ $Ex $OldBL) + ( (not (find-partial-match-p $Templ $Ex $OldBL $_ $_ $_ $_)) (set-det))) +; + + (= + (partial-match1 $Templ $Ex $OldBL + (Cons $PartialMatch $RestPL) $RestTempl $RestEx $NewBL) + ( (find-partial-match-p $Templ $Ex $OldBL $PartialMatch $RestTempl1 $RestEx1 $NewBL1) + (set-det) + (partial-match1 $RestTempl1 $RestEx1 $NewBL1 $RestPL $RestTempl $RestEx $NewBL))) +; + + + + (= + (find-partial-match-p $Templ $Ex $OldBL $PartialMatch $RestTempl $RestEx $NewBL) + ( (enumerate $Templ $Part $RestTempl) + (find-partial-match-p1 $Part $Ex $OldBL $MatchingFact $RestEx $NewBL) + (= $PartialMatch + (:: $Part $MatchingFact)))) +; + + + + (= + (find-partial-match-p1 $Part $Ex $OldBL $ExamplePart $RestEx $NewBL) + ( (enumerate $Ex $ExamplePart $RestEx) (partial-match-p $Part $ExamplePart $OldBL $NewBL))) +; + + + + (= + (partial-match-p + (must $Constraint) $Fact $OldBL $NewBL) + ( (set-det) (partial-match-p $Constraint $Fact $OldBL $NewBL))) +; + + (= + (partial-match-p $Constraint $Fact $OldBL $NewBL) + ( (=.. $Constraint + (Cons $Functor $Args1)) + (=.. $Fact + (Cons $Functor $Args2)) + (count-differences-p $Args1 $Args2 $OldBL $NewBL 1))) +; + + (= + (partial-match-p $Constraint $Fact $OldBL $NewBL) + ( (infer $Fact $FactDerivation) (partial-match-p $Constraint $FactDerivation $OldBL $NewBL))) +; + + + + + (= + (partial-match-better-p + (:: $PL1 $RestTempl1 $RestEx1 $BL1) + (:: $PL2 $RestTempl2 $RestEx2 $BL2)) + ( (length $RestTempl1 $L1) + (length $RestTempl2 $L2) + (< $L1 $L2))) +; + + + + (= + (partial-match-equal-p + (:: $PL1 $RestTempl1 $RestEx1 $BL1) + (:: $PL2 $RestTempl2 $RestEx2 $BL2)) + ( (set-equal-p $PL1 $PL2) + (set-equal-p $RestTempl1 $RestTempl2) + (set-equal-p $RestEx1 $RestEx2) + (set-equal-p $BL1 $BL2))) +; + + + + (= + (count-differences-p Nil Nil $BL $BL 0) + (set-det)) +; + + (= + (count-differences-p + (Cons $First1 $Rest1) + (Cons $First2 $Rest2) $OldBL $NewBL $RestN) + ( (atom-match-p $First1 $First2 $OldBL $BL) + (set-det) + (count-differences-p $Rest1 $Rest2 $BL $NewBL $RestN))) +; + + (= + (count-differences-p + (Cons $First1 $Rest1) + (Cons $First2 $Rest2) $OldBL $NewBL $N) + ( (set-det) + (not (= $First1 (var $_))) + (not (= $First2 (var $_))) + (count-differences-p $Rest1 $Rest2 $OldBL $NewBL $RestN) + (is $N + (+ $RestN 1)))) +; + + + + (= + (atom-match-p $O1 $O2 $OldBL $NewBL) + ( (atom-match-p1 $O1 $O2 $OldBL $NewBL) (unique-binding-p $NewBL))) +; + + + + (= + (atom-match-p1 + (var $VarName1) + (var $VarName2) $OldBL $NewBL) + ( (set-det) + (get-binding $VarName1 $OldBL $BL $Binding1) + (get-binding $VarName2 $BL $NewBL $Binding2) + (= $Binding1 $Binding2))) +; + + (= + (atom-match-p1 $Const + (var $VarName) $OldBL $NewBL) + ( (set-det) (get-binding $VarName $OldBL $NewBL $Const))) +; + + (= + (atom-match-p1 + (var $VarName) $Const $OldBL $NewBL) + ( (set-det) (get-binding $VarName $OldBL $NewBL $Const))) +; + + (= + (symbol_match_p1 $Const $Const $BL $BL) True) +; + + + + (= + (get-binding $Key Nil + (:: (Cons $Key $Value)) $Value) + (set-det)) +; + + (= + (get-binding $Key $BL $BL $Value1) + ( (= $BL + (Cons + (Cons $Key $Value2) $_)) + (set-det) + (= $Value1 $Value2))) +; + + (= + (get-binding $Key + (Cons $FirstBinding $RestBL) + (Cons $FirstBinding $NewRestBL) $Value) + ( (set-det) (get-binding $Key $RestBL $NewRestBL $Value))) +; + + + + + (= + (get_variable_p $Value + (Cons + (Cons $Variable $Value) $_) $Variable) True) +; + + (= + (get-variable-p $Value + (Cons $_ $RestBL) $Variable) + (get-variable-p $Value $RestBL $Variable)) +; + + + + + (= + (unique_binding_p ()) True) +; + + (= + (unique-binding-p (Cons $FirstBinding $RestBindings)) + ( (unique-binding-p $RestBindings) + (= $FirstBinding + (Cons $_ $Value)) + (not (get-variable-p $Value $RestBindings $_)))) +; + + + + (= + (initial-generalization $Example $InitialConcept) + ( (variabilize-part-facts $Example $VarPartFacts $BL $RestFacts) + (variabilize-facts $RestFacts $BL $VarRestFacts) + (append $VarPartFacts $VarRestFacts $Template) + (concept-template $InitialConcept $Template) + (concept-constraints $InitialConcept Nil) + (set-det))) +; + + + + (= + (variabilize-part-facts Nil Nil Nil Nil) + (set-det)) +; + + (= + (variabilize-part-facts + (Cons + (part $PartName) $Rest) $VarPartFacts $BL $RestFacts) + ( (set-det) + (= $VarPartFacts + (Cons + (part (var $PartName)) $VarRestParts)) + (= $BL + (Cons + (Cons $PartName $PartName) $RestBL)) + (variabilize-part-facts $Rest $VarRestParts $RestBL $RestFacts))) +; + + (= + (variabilize-part-facts + (Cons $First $Rest) $VarRestParts $RestBL + (Cons $First $RestFacts)) + ( (set-det) (variabilize-part-facts $Rest $VarRestParts $RestBL $RestFacts))) +; + + + + (= + (variabilize-facts Nil $_ Nil) + (set-det)) +; + + (= + (variabilize-facts + (Cons $First $Rest) $BL + (Cons $VarFirst $VarRest)) + ( (set-det) + (variabilize-fact $First $BL $VarFirst) + (variabilize-facts $Rest $BL $VarRest))) +; + + + + (= + (specialize-concept-definition Nil $_ $C $C) + (set-det)) +; + + (= + (specialize-concept-definition + (Cons + (addition $ExampleFact) $RestDD) $BL $OldConcept $NewConcept) + ( (set-det) + (variabilize-fact $ExampleFact $BL $NewNecessaryConstraint) + (specialize-concept-definition $RestDD $BL $OldConcept $Concept) + (concept-constraints $Concept $Constraints) + (list-add-if-necessary + (not $NewNecessaryConstraint) $Constraints $NewConstraints) + (alter-concept-constraints $Concept $NewConstraints $NewConcept))) +; + + + (= + (specialize-concept-definition + (Cons + (missing $Part) $RestDD) $BL $OldConcept $NewConcept) + ( (set-det) + (specialize-concept-definition $RestDD $BL $OldConcept $Concept) + (concept-template $Concept $Template) + (list-remove $Part $Template $Template1) + (= $NewTemplate + (Cons + (must $Part) $Template1)) + (alter-concept-template $Concept $NewTemplate $NewConcept))) +; + + + (= + (specialize-concept-definition + (Cons + (partial (:: $Part $_)) $RestDD) $BL $OldConcept $NewConcept) + ( (set-det) + (specialize-concept-definition $RestDD $BL $OldConcept $Concept) + (concept-template $Concept $Template) + (list-remove $Part $Template $Template1) + (= $NewTemplate + (Cons + (must $Part) $Template1)) + (alter-concept-template $Concept $NewTemplate $NewConcept))) +; + + + + (= + (variabilize-fact $Fact $BL $VarFact) + ( (=.. $Fact + (Cons $Functor $Args)) + (variabilize-list $Args $BL $VarArgs) + (=.. $VarFact + (Cons $Functor $VarArgs)))) +; + + + + (= + (variabilize-list Nil $_ Nil) + (set-det)) +; + + (= + (variabilize-list + (Cons $FirstArg $RestArgs) $BL + (Cons + (var $VarFirstArg) $VarRestArgs)) + ( (get-variable-p $FirstArg $BL $VarFirstArg) + (set-det) + (variabilize-list $RestArgs $BL $VarRestArgs))) +; + + (= + (variabilize-list + (Cons $FirstArg $RestArgs) $BL + (Cons $FirstArg $VarRestArgs)) + ( (set-det) (variabilize-list $RestArgs $BL $VarRestArgs))) +; + + + + (= + (generalize-concept-definition Nil $C $C) + (set-det)) +; + + (= + (generalize-concept-definition + (Cons + (partial (:: $Constraint $ExampleFact)) $RestDD) $OldConcept $NewConcept) + ( (set-det) + (generalize-arg $Constraint $ExampleFact $NewConstraint) + (generalize-concept-definition $RestDD $OldConcept $RestConcept) + (concept-template $RestConcept $Template) + (list-remove $Constraint $Template $Template1) + (= $NewTemplate + (Cons $NewConstraint $Template1)) + (alter-concept-template $RestConcept $NewTemplate $NewConcept))) +; + + + (= + (generalize-concept-definition + (Cons + (missing $Constraint) $RestDD) $OldConcept $NewConcept) + ( (set-det) + (generalize-concept-definition $RestDD $OldConcept $RestConcept) + (concept-template $RestConcept $Template) + (list-remove $Constraint $Template $NewTemplate) + (alter-concept-template $RestConcept $NewTemplate $NewConcept))) +; + + + (= + (generalize-concept-definition + (Cons $_ $RestDD) $OldSC $RestSC) + (generalize-concept-definition $RestDD $OldSC $RestSC)) +; + + + + (= + (generalize-arg + (must $Constraint) $ExampleFact + (must $NewConstraint)) + ( (set-det) (generalize-arg $Constraint $ExampleFact $NewConstraint))) +; + + + (= + (generalize-arg $Constraint $ExampleFact $NewConstraint) + ( (=.. $Constraint + (Cons $Functor $Args1)) + (=.. $ExampleFact + (Cons $Functor $Args2)) + (generalize-arg1 $Args1 $Args2 $NewArgs1) + (=.. $NewConstraint + (Cons $Functor $NewArgs1)))) +; + + + + (= + (generalize-arg1 Nil Nil Nil) + (set-det)) +; + + (= + (generalize-arg1 + (Cons $Arg1 $Rest1) + (Cons $Arg2 $Rest2) + (Cons $Arg1 $GenRest)) + ( (or + (= $Arg1 $Arg2) + (= $Arg1 + (var $_))) + (set-det) + (generalize-arg1 $Rest1 $Rest2 $GenRest))) +; + + (= + (generalize-arg1 + (Cons $Arg1 $Rest1) + (Cons $Arg2 $_) + (Cons $GenArg $Rest1)) + ( (set-det) (find-or-create-common-ancestor $Arg1 $Arg2 $GenArg))) +; + + + + (= + (find-or-create-common-ancestor $Class1 $Class2 $Ancestor) + ( (ancestors $Class1 $Ancestors1) + (ancestors $Class2 $Ancestors2) + (smallest-ancestor-p $Ancestors1 $Ancestors2 $Ancestor) + (set-det))) +; + + (= + (find-or-create-common-ancestor $Class1 $Class2 $Ancestor) + ( (set-det) + (concat $Class1 $Class2 $Ancestor) + (add-symbol &self + (ako $Class1 $Ancestor)) + (add-symbol &self + (ako $Class2 $Ancestor)))) +; + + + + (= + (ancestors $Class $Ancestors) + (ancestors1 + (:: $Class) Nil $Ancestors)) +; + + + + (= + (ancestors1 Nil $Ancestors $Ancestors) + (set-det)) +; + + (= + (ancestors1 + (Cons $First $Rest) $Ancestors $ExtendedAncestors) + ( (direct-ancestors $First $FirstAncestors) + (not (= $FirstAncestors Nil)) + (set-det) + (append $FirstAncestors $Rest $NewClassList) + (union $Ancestors $FirstAncestors $NewAncestorList) + (ancestors1 $NewClassList $NewAncestorList $ExtendedAncestors))) +; + + (= + (ancestors1 + (Cons $First $Rest) $Ancestors $ExtendedAncestors) + ( (set-det) + (union + (:: $First) $Ancestors $NewAncestors) + (ancestors1 $Rest $NewAncestors $ExtendedAncestors))) +; + + + + (= + (direct-ancestors $Class $Ancestors) + ( (set-det) (findbag $Ancestor (ako $Class $Ancestor) $Ancestors))) +; + + + + (= + (smallest-ancestor-p + (Cons $First $_) $Ancestors2 $First) + ( (member $First $Ancestors2) (set-det))) +; + + (= + (smallest-ancestor-p + (Cons $_ $Rest) $Ancestors2 $Ancestor) + ( (set-det) (smallest-ancestor-p $Rest $Ancestors2 $Ancestor))) +; + + + + (= + (list-remove $_ Nil Nil) + (set-det)) +; + + (= + (list-remove $Target + (Cons $Target $Rest) $RestRemoved) + ( (set-det) (list-remove $Target $Rest $RestRemoved))) +; + + (= + (list-remove $Target + (Cons $First $Rest) + (Cons $First $RestRemoved)) + (list-remove $Target $Rest $RestRemoved)) +; + + + + (= + (msgs Nil) + (set-det)) +; + + (= + (msgs (Cons $First $Rest)) + ( (msg $First) + (msgs $Rest) + (set-det))) +; + + + + (= + (msg nl) + ( (set-det) (nl))) +; + + (= + (msg (nl $N)) + ( (set-det) (repeat $N nl))) +; + + (= + (msg sp) + ( (set-det) (write ' '))) +; + + (= + (msg (sp $N)) + ( (set-det) (repeat $N (write ' ')))) +; + + (= + (msg (pf $PF $Object)) + ( (set-det) + (=.. $Call + (:: $PF $Object)) + (call $Call))) +; + + (= + (msg $Object) + ( (write $Object) (set-det))) +; + + + + (= + (repeat $N $_) + ( (< $N 1) (set-det))) +; + + (= + (repeat $N $Call) + ($Call + (is $N1 + (- $N 1)) + (repeat $N1 $Call) + (set-det))) +; + + + + (= + (set-equal-p Nil Nil) + (set-det)) +; + + (= + (set-equal-p + (Cons $First $Rest) $Set2) + ( (enumerate $Set2 $First $Rest2) + (set-det) + (set-equal-p $Rest $Rest2))) +; + + + + (= + (remove-duplicates Nil Nil $_) + (set-det)) +; + + (= + (remove-duplicates + (Cons $First $Rest) $Result $EqualP) + ( (remove-duplicates $Rest $RestResult $EqualP) (remove-duplicates-result $First $RestResult $Result $EqualP))) +; + + + + (= + (remove-duplicates-result $First $RestResult $RestResult $EqualP) + ( (member $First $RestResult $EqualP) (set-det))) +; + + (= + (remove_duplicates_result $First $RestResult + (Cons $First $RestResult) $_) True) +; + + + + (= + (list_sort () () $_) True) +; + + (= + (list-sort + (Cons $X $L) $M $O) + ( (list-sort $L $N $O) (list-sort1 $X $N $M $O))) +; + + + + (= + (list-sort1 $X + (Cons $A $L) + (Cons $A $M) $O) + ( (=.. $P + (:: $O $A $X)) + (call $P) + (set-det) + (list-sort1 $X $L $M $O))) +; + + (= + (list_sort1 $X $L + (Cons $X $L) $_) True) +; + + + + (= + (get_best () () $_) True) +; + + (= + (get_best + ($Single) + ($Single) $_) True) +; + + (= + (get-best + (Cons $First + (Cons $Second $_)) + (:: $First) $ComparisonP) + ( (=.. $Call + (:: $ComparisonP $First $Second)) + (call $Call) + (set-det))) +; + + (= + (get-best + (Cons $First + (Cons $Second $Rest)) + (Cons $First $RestBest) $ComparisonP) + ( (set-det) (get-best (Cons $Second $Rest) $RestBest $ComparisonP))) +; + + + + (= + (enumerate + (Cons $Head $Tail) $Head $Tail) True) +; + + (= + (enumerate + (Cons $Head $Tail) $NextHead + (Cons $Head $NextRest)) + (enumerate $Tail $NextHead $NextRest)) +; + + + + (= + (list-add-if-necessary $NewElement $List $List) + ( (member $NewElement $List) (set-det))) +; + + (= + (list-add-if-necessary $NewElement $List $NewList) + ( (= $NewList + (Cons $NewElement $List)) (set-det))) +; + + + + (= + (concat $S1 $S2 $S3) + ( (nonvar $S1) + (nonvar $S2) + (name $S1 $L1) + (name $S2 $L2) + (append $L1 $L2 $L3) + (name $S3 $L3) + (set-det))) +; + + + (= + (concat $S1 $S2 $S3) + ( (nonvar $S1) + (nonvar $S3) + (name $S1 $L1) + (name $S3 $L3) + (append $L1 $L2 $L3) + (name $S2 $L2) + (set-det))) +; + + + (= + (concat $S1 $S2 $S3) + ( (nonvar $S2) + (nonvar $S3) + (name $S2 $L2) + (name $S3 $L3) + (append $L1 $L2 $L3) + (name $S1 $L1) + (set-det))) +; + + + + (= + (member $_ $List $_) + ( (var $List) + (set-det) + (is $List Nil) + (fail))) +; + + (= + (member $E + (Cons $First $_) $EqualP) + ( (=.. $Call + (:: $EqualP $E $First)) (call $Call))) +; + + (= + (member $E + (Cons $_ $R) $EqualP) + (member $E $R $EqualP)) +; + + + + !(dynamic (/ found 1)) +; + + + + (= + (findbag $X $G $_) + ( (add-symbol &self + (found mark)) + (call $G) + (add-symbol &self + (found $X)) + (fail))) +; + + (= + (findbag $_ $_ $L) + (collect-found Nil $L)) +; + + + + (= + (collect-found $L $L1) + ( (getnext $X) (collect-found (Cons $X $L) $L1))) +; + + (= + (collect_found $L $L) True) +; + + +; (error +; (syntax_error operator_expected) +; (file arch1/arch1.pl 1339 30 68638)) + + + + (= + (union () $X $X) True) +; + + (= + (union + (Cons $X $R) $Y $Z) + ( (member $X $Y) + (set-det) + (union $R $Y $Z))) +; + + (= + (union + (Cons $X $R) $Y + (Cons $X $Z)) + (union $R $Y $Z)) +; + + + + (= + (help) + ( (write 'Load data set with command: [Filename].') + (nl) + (write 'Start arch1 with command: process-stored-inputs(ConceptName).') + (nl))) +; + + + + !(help *) +; + + diff --git a/arch1/arch1_1.metta b/arch1/arch1_1.metta new file mode 100644 index 0000000..bbf75ee --- /dev/null +++ b/arch1/arch1_1.metta @@ -0,0 +1,93 @@ + + (= + (input 1 example arch + ( (part part1) + (part part2) + (part part3) + (isa part1 brick) + (isa part2 brick) + (isa part3 brick) + (left_of part2 part1) + (supports part1 part3) + (supports part2 part3))) True) +; + + (= + (input 2 near_miss arch + ( (part part1) + (isa part2 brick) + (part part2) + (left_of part2 part1) + (part part3) + (isa part1 brick) + (isa part3 brick))) True) +; + + (= + (input 3 near_miss arch + ( (part part1) + (part part2) + (part part3) + (isa part1 brick) + (isa part2 brick) + (isa part3 brick) + (left_of part2 part1) + (touches part1 part2) + (supports part1 part3) + (supports part2 part3))) True) +; + + (= + (input 4 example arch + ( (part part1) + (part part2) + (part part3) + (isa part1 brick) + (isa part2 brick) + (isa part3 wedge) + (left_of part2 part1) + (supports part1 part3) + (supports part2 part3))) True) +; + + (= + (input 5 near_miss arch + ( (part part1) + (part part2) + (part part3) + (isa part1 brick) + (isa part2 brick) + (isa part3 cylinder) + (left_of part2 part1) + (supports part1 part3) + (supports part2 part3))) True) +; + + + + (= + (infer + (touch $O1 $O2) + (touch $O2 $O1)) True) +; + + + (= + (infer + (isa $Object $Type1) + (isa $Object $Type2)) + ( (set-det) (ako $Type1 $Type2))) +; + + + + (= + (ako brick parallel_epiphed) True) +; + + (= + (ako wedge parallel_epiphed) True) +; + + + diff --git a/arch2/arch2.metta b/arch2/arch2.metta new file mode 100644 index 0000000..f9e9758 --- /dev/null +++ b/arch2/arch2.metta @@ -0,0 +1,247 @@ + + (= + (learn $Concept) + ( (findbag $X + (example $X) $L) (learn $L $Concept))) +; + + + (= + (learn + (Cons $FirstExample $Examples) $ConceptDesc) + ( (initialize $FirstExample $InitialHypothesis) (process-examples $InitialHypothesis $Examples $ConceptDesc))) +; + + + + (= + (initialize + (+ (object $Parts $Rels)) + (concept $Parts Nil $Rels Nil)) + (namevars $Parts + (:: part1 part2 part3 part4 part5 part6))) +; + + + + (= + (namevars $List $NameList) + (append $List $_ $NameList)) +; + + + + (= + (process_examples $ConceptDesc () $ConceptDesc) True) +; + + (= + (process-examples $CurDesc + (Cons $Example $Examples) $FinDesc) + ( (object-type $Example $Object $Type) + (match $Object $CurDesc $Difference) + (update $Type $Difference $CurDesc $NewDesc) + (process-examples $NewDesc $Examples $FinDesc))) +; + + + + (= + (object_type + (+ $Object) $Object positive) True) +; + + (= + (object_type + (- $Object) $Object negative) True) +; + + + + (= + (match + (object $OParts $ORels) + (concept $CParts $Musts $Rels $MustNots) + (+ $Missing $Extras)) + ( (list-diff $ORels $Musts + (+ Nil $RestRels)) + (short-lists (+ $Missing $Extras)) + (list-diff $OParts $CParts + (+ Nil Nil)) + (list-diff $RestRels $Rels + (+ $Missing $Extras)) + (list-diff $Extras $MustNots + (+ $MustNots $_)))) +; + + + + (= + (list_diff $List () + (+ () $List)) True) +; + + (= + (list-diff $List1 + (Cons $X $List2) + (+ $Miss $Extras)) + ( (delete $List1 $List11 $X $Miss11 $Miss) (list-diff $List11 $List2 (+ $Miss11 $Extras)))) +; + + + + (= + (delete () () $X $Dels + (Cons $X $Dels)) True) +; + + (= + (delete + (Cons $Y $L) $L $X $Dels $Dels) + ( (== $X $Y) (set-det))) +; + + (= + (delete + (Cons $Y $L) $L $X $Dels $Dels) + (= $X $Y)) +; + + (= + (delete + (Cons $Y $L) + (Cons $Y $L1) $X $Dels $Dels1) + (delete $L $L1 $X $Dels $Dels1)) +; + + + + (= + (short-lists (+ $L1 $L2)) + ( (append $L $_ + (:: $_ $_ $_)) (append $L1 $L2 $L))) +; + + + + (= + (update negative + (+ $_ + ($ExtraRelation)) + (concept $Parts $Musts $Rels $MustNots) + (concept $Parts $Musts $Rels + (Cons $ExtraRelation $MustNots))) True) +; + + (= + (update negative + (+ $Missing $_) + (concept $Parts $Musts $Rels $MustNots) + (concept $Parts $NewMusts $NewRels $MustNots)) + ( (= $Missing + (Cons $_ $_)) + (append $Missing $Musts $NewMusts) + (list-diff $Rels $Missing + (+ $_ $NewRels)))) +; + + (= + (update negative + (+ + (:: $MissR) + (:: $ExtraR)) $CurDesc $NewDesc) + ( (update negative + (+ Nil + (:: $ExtraR)) $CurDesc $InterDesc) (update negative (+ (:: $MissR) Nil) $InterDesc $FinDesc))) +; + + (= + (update positive + (+ + (:: (isa $Object $Class1)) + (:: (isa $Object $Class2))) + (concept $Parts $Musts $Rels $MustNots) + (concept $Parts $Musts $NewRels $MustNots)) + ( (climb $Class1 $Class) + (climb $Class2 $Class) + (set-det) + (replace + (isa $Object $Class1) $Rels + (isa $Object $Class) $NewRels))) +; + + + + (= + (replace $Item $List $NewItem + (Cons $NewItem $List1)) + (delete $List $List1 $Item $_ $_)) +; + + + + (= + (climb $Class $Class) True) +; + + (= + (climb $Class $SuperClass) + ( (get-symbols &self + (= + (ako $Class1 $Class) true)) (climb $Class1 $SuperClass))) +; + + + + !(dynamic (/ found 1)) +; + + + + (= + (findbag $X $G $_) + ( (add-symbol &self + (found mark)) + (call $G) + (add-symbol &self + (found $X)) + (fail))) +; + + (= + (findbag $_ $_ $L) + (collect-found Nil $L)) +; + + + + (= + (collect-found $L $L1) + ( (getnext $X) (collect-found (Cons $X $L) $L1))) +; + + (= + (collect_found $L $L) True) +; + + +; (error +; (syntax_error operator_expected) +; (file arch2/arch2.pl 268 30 14766)) + + + + (= + (help) + ( (write 'Load data set with command: [Filename].') + (nl) + (write 'Start arch2 with command: learn(X).') + (nl))) +; + + + + !(help *) +; + + diff --git a/arch2/arch2_1.metta b/arch2/arch2_1.metta new file mode 100644 index 0000000..e5d7262 --- /dev/null +++ b/arch2/arch2_1.metta @@ -0,0 +1,96 @@ + + (= + (example + (+ + (object + ($A $B $C) + ( (support $A $C) + (support $B $C) + (isa $A rectangle) + (isa $B rectangle) + (isa $C rectangle))))) True) +; + + (= + (example + (- + (object + ($A $B $C) + ( (support $A $C) + (support $B $C) + (touch $A $B) + (isa $A rectangle) + (isa $B rectangle) + (isa $C rectangle))))) True) +; + + (= + (example + (- + (object + ($A $B $C) + ( (isa $A rectangle) + (isa $B rectangle) + (isa $C rectangle))))) True) +; + + (= + (example + (+ + (object + ($A $B $C) + ( (support $A $C) + (support $B $C) + (isa $A rectangle) + (isa $B rectangle) + (isa $C triangle))))) True) +; + + + + + (= + (ako figure polygone) True) +; + + (= + (ako figure circle) True) +; + + (= + (ako polygon convex_poly) True) +; + + (= + (ako polygon concave_poly) True) +; + + (= + (ako convex_poly stable_poly) True) +; + + (= + (ako convex_poly unstable_poly) True) +; + + (= + (ako stable_poly triangle) True) +; + + (= + (ako stable_poly rectangle) True) +; + + (= + (ako stable_poly trapezium) True) +; + + (= + (ako unstable_poly unstable_triangle) True) +; + + (= + (ako unstable_poly hexagon) True) +; + + diff --git a/attdsc/attdsc.metta b/attdsc/attdsc.metta new file mode 100644 index 0000000..96f1536 --- /dev/null +++ b/attdsc/attdsc.metta @@ -0,0 +1,216 @@ + + !(op 300 xfx <==) +; + + + !(dynamic (/ <== 2)) +; + + + + (= + (learn $Class) + ( (bagof + (example $ClassX $Obj) + (example $ClassX $Obj) $Examples) + (learn $Examples $Class $Description) + (nl) + (write $Class) + (write <==) + (nl) + (writelist $Description) + (add-symbol &self + (<== $Class $Description)))) +; + + + (= + (learn $Examples $Class Nil) + (not (member (example $Class $_) $Examples))) +; + + (= + (learn $Examples $Class + (Cons $Conj $Conjs)) + ( (learn-conj $Examples $Class $Conj) + (remove $Examples $Conj $RestExamples) + (learn $RestExamples $Class $Conjs))) +; + + + + (= + (learn-conj $Examples $Class Nil) + ( (not (, (member (example $ClassX $_) $Examples) (not (== $ClassX $Class)))) (set-det))) +; + + (= + (learn-conj $Examples $Class + (Cons $Cond $Conds)) + ( (choose-cond $Examples $Class $Cond) + (filter $Examples + (:: $Cond) $Examples1) + (learn-conj $Examples1 $Class $Conds))) +; + + + + (= + (choose-cond $Examples $Class $AttVal) + ( (findall + (/ $AV $Score) + (score $Examples $Class $AV $Score) $AVs) (best $AVs $AttVal))) +; + + + + (= + (best + ( (/ $AttVal $_)) $AttVal) True) +; + + (= + (best + (Cons + (/ $AV0 $S0) + (Cons + (/ $AV1 $S1) $AVSlist)) $AttVal) + (or + (, + (> $S1 $S0) + (set-det) + (best + (Cons + (/ $AV1 $S1) $AVSlist) $AttVal)) + (best + (Cons + (/ $AV0 $S0) $AVSlist) $AttVal))) +; + + + + (= + (score $Examples $Class $AttVal $Score) + ( (candidate $Examples $Class $AttVal) + (filter $Examples + (:: $AttVal) $Examples1) + (length $Examples1 $N1) + (count-pos $Examples1 $Class $NPos1) + (> $NPos1 0) + (is $Score + (- + (* 2 $NPos1) $N1)))) +; + + + + (= + (candidate $Examples $Class + (= $Att $Val)) + ( (get-symbols &self + (= + (attribute $Att $Values) true)) + (member $Val $Values) + (suitable + (= $Att $Val) $Examples $Class))) +; + + + + (= + (suitable $AttVal $Examples $Class) + ( (member + (example $ClassX $ObjX) $Examples) + (not (== $ClassX $Class)) + (not (satisfy $ObjX (:: $AttVal))) + (set-det))) +; + + + + (= + (count_pos () $_ 0) True) +; + + (= + (count-pos + (Cons + (example $ClassX $_) $Examples) $Class $N) + ( (count-pos $Examples $Class $N1) (or (, (= $ClassX $Class) (set-det) (is $N (+ $N1 1))) (= $N $N1)))) +; + + + + (= + (filter $Examples $Cond $Examples1) + (findall + (example $Class $Obj) + (, + (member + (example $Class $Obj) $Examples) + (satisfy $Obj $Cond)) $Examples1)) +; + + + + (= + (remove () $_ ()) True) +; + + (= + (remove + (Cons + (example $Class $Obj) $Es) $Conj $Es1) + ( (satisfy $Obj $Conj) + (set-det) + (remove $Es $Conj $Es1))) +; + + (= + (remove + (Cons $E $Es) $Conj + (Cons $E $Es1)) + (remove $Es $Conj $Es1)) +; + + + + (= + (satisfy $Object $Conj) + (not (, (member (= $Att $Val) $Conj) (member (= $Att $ValX) $Object) (not (== $ValX $Val))))) +; + + + + (= + (match $Object $Description) + ( (member $Conj $Description) (satisfy $Object $Conj))) +; + + + + (= + (writelist ()) True) +; + + (= + (writelist (Cons $X $L)) + ( (tab 2) + (write $X) + (nl) + (writelist $L))) +; + + + + (= + (help) + ( (write 'Load data set and start learning with command: [Filename].') (nl))) +; + + + + !(help *) +; + + diff --git a/attdsc/attdsc_1.metta b/attdsc/attdsc_1.metta new file mode 100644 index 0000000..99e35bf --- /dev/null +++ b/attdsc/attdsc_1.metta @@ -0,0 +1,120 @@ + + (= + (attribute size + (small large)) True) +; + + (= + (attribute shape + (long compact other)) True) +; + + (= + (attribute holes + (none 1 2 3 many)) True) +; + + + + (= + (example nut + ( (= size small) + (= shape compact) + (= holes 1))) True) +; + + (= + (example screw + ( (= size small) + (= shape long) + (= holes none))) True) +; + + (= + (example key + ( (= size small) + (= shape long) + (= holes 1))) True) +; + + (= + (example nut + ( (= size small) + (= shape compact) + (= holes 1))) True) +; + + (= + (example key + ( (= size large) + (= shape long) + (= holes 1))) True) +; + + (= + (example screw + ( (= size small) + (= shape compact) + (= holes none))) True) +; + + (= + (example nut + ( (= size small) + (= shape compact) + (= holes 1))) True) +; + + (= + (example pen + ( (= size large) + (= shape long) + (= holes none))) True) +; + + (= + (example scissors + ( (= size large) + (= shape long) + (= holes 2))) True) +; + + (= + (example pen + ( (= size large) + (= shape long) + (= holes none))) True) +; + + (= + (example scissors + ( (= size large) + (= shape other) + (= holes 2))) True) +; + + (= + (example key + ( (= size small) + (= shape other) + (= holes 2))) True) +; + + + + (= + (?- + (learn nut)) True) +; + + (= + (?- + (learn key)) True) +; + + (= + (?- + (learn scissors)) True) +; + + diff --git a/cobweb/cobweb.metta b/cobweb/cobweb.metta new file mode 100644 index 0000000..b52d8e2 --- /dev/null +++ b/cobweb/cobweb.metta @@ -0,0 +1,1620 @@ + + !(dynamic (/ root 2)) +; + + !(dynamic (/ root 4)) +; + + !(dynamic (/ node 3)) +; + + !(dynamic (/ d-sub 2)) +; + + !(dynamic (/ gensym-counter 2)) +; + + !(dynamic (/ prediction-counter 2)) +; + + !(dynamic (/ features 1)) +; + + !(dynamic (/ case 1)) +; + + !(dynamic (/ acuity 1)) +; + + + + (= + (learn) + ( (initialize) + (get-case $X) + (cobweb $X) + (nl) + (nl) + (show-classes) + (fail))) +; + + (= learn True) +; + + + + (= + (initialize) + ( (abolish node 3) + (abolish d-sub 2) + (abolish root 2) + (abolish root 4) + (abolish prediction-counter 2) + (abolish gensym-counter 2) + (set-det))) +; + + + + (= + (learn-more) + ( (get-case $X) + (cobweb $X) + (fail))) +; + + (= learn_more True) +; + + + + (= + (nmember $E + (Cons $E $L) 1) True) +; + + (= + (nmember $E + (Cons $_ $R) $P1) + ( (nmember $E $R $P) (is $P1 (+ $P 1)))) +; + + + + (= + (nth1 1 + (Cons $X $_) $X) True) +; + + (= + (nth1 $P1 + (Cons $_ $R) $X) + ( (> $P1 1) + (is $P + (- $P1 1)) + (nth1 $P $R $X))) +; + + + + (= + (get-case $CaseID) + ( (case (Cons $CaseID $_)) + (nl) + (nl) + (write ' Processing case ') + (write $CaseID) + (write ...))) +; + + + + (= + (get-case-feature $CaseId $Type + (:: $Feature $Val)) + ( (case (Cons $CaseId $CaseDescription)) + (features $FeatureDescription) + (nmember + (:: $Type $Feature) $FeatureDescription $Pos) + (nth1 $Pos $CaseDescription $Val))) +; + + + + (= + (cobweb $Case) + ( (not (get-node $_)) + (init-node) + (node $Root root 1 1) + (new-node-from-case $Case $Root) + (assert-node $Root) + (msgs (:: nl ' Root initialized with case: ' $Root)) + (set-det))) +; + + (= + (cobweb $Case) + ( (node $OldRoot root 1 1) + (remove-node $OldRoot) + (set-det) + (copy-node-to-new-node $OldRoot $New) + (node $New $_ 1 1) + (assert-node $New) + (msgs (:: nl ' Root node: ' $OldRoot ' used as new terminal node: ' $New)) + (assert-d-sub $OldRoot $New) + (new-node-from-case $Case $New2) + (node $New2 $_ 1 1) + (assert-node $New2) + (msgs (:: nl ' Case ' $Case ' becomes new terminal ' $New2)) + (assert-d-sub $OldRoot $New2) + (incorporate-case-into-node $Case $OldRoot) + (node $NewRoot root 2 $_) + (assert-node $NewRoot) + (msgs (:: nl ' Root changed to: ' $NewRoot)) + (set-det))) +; + + (= + (cobweb $Case) + ( (node-name $OldRoot root) + (remove-node $OldRoot) + (set-det) + (incorporate-case-into-node $Case $OldRoot) + (node-objects $OldRoot $Objects) + (is $NewObjects + (+ $Objects 1)) + (node $NewRoot root $NewObjects $_) + (assert-node $NewRoot) + (msgs (:: nl ' Root changed to: ' $NewRoot)) + (cobweb $NewRoot $Case) + (set-det))) +; + + + (= + (cobweb none $_) True) +; + + (= + (cobweb $Parent $Case) + ( (best-child $Parent $Case $Best $IBest $Next $DoneRest $RestPred $PartSize $IncPrediction) + (set-det) + (new-child $Parent $Case $Best $Next $RestPred $PartSize $New $NewPrediction) + (set-det) + (merge-child $Parent $Case $Best $Next $RestPred $PartSize $Merge $MergePrediction) + (set-det) + (split-child $Parent $Case $Best $IBest $Next $DoneRest $RestPred $PartSize $SplitPrediction) + (set-det) + (max-of + (:: $IncPrediction $NewPrediction $MergePrediction $SplitPrediction) $BestPrediction) + (set-det) + (or + (, + (= $BestPrediction $IncPrediction) + (do-incorp $IBest $Best $Merge $New $Case $NewParent)) + (or + (, + (= $BestPrediction $SplitPrediction) + (do-split $Best $IBest $New $Merge $Parent $NewParent)) + (or + (, + (= $BestPrediction $MergePrediction) + (do-merge $Best $Next $Merge $Parent $IBest $New $NewParent)) + (, + (= $BestPrediction $NewPrediction) + (do-new $Parent $New $IBest $Merge $NewParent))))) + (set-det) + (cobweb $NewParent $Case))) +; + + + + (= + (do-incorp $IBest $Best $Merge $New $Case $NewParent) + ( (msgs (:: nl ' Incorporating case ' $Case ' into node: ' $IBest)) + (move-subs $Best $IBest) + (delete-node $Merge) + (delete-node $New) + (if + (terminal-node $Best) + (, + (ins-node $IBest $Best Nil) + (msgs (:: nl ' using old node: ' $Best ' as terminal node.')) + (new-node-from-case $Case $New2) + (node $New2 $_ 1 1) + (assert-node $New2) + (msgs (:: nl ' New terminal node: ' $New2)) + (ins-node $IBest $New2 Nil) + (= $NewParent none)) + (, + (delete-node $Best) + (= $NewParent $IBest))))) +; + + + + (= + (do-split $Best $IBest $New $Merge $Parent $Parent) + ( (msgs (:: nl ' Case splits node: ' $Best)) + (delete-node $Best) + (delete-node $IBest) + (delete-node $New) + (delete-node $Merge))) +; + + + + (= + (do-merge $Best $Next $Merge $Parent $IBest $New $Merge) + ( (msgs (:: nl ' Case merges nodes: ' $Best ' and ' $Next nl ' into ' $Merge)) + (ins-node $Parent $Merge + (:: $Best $Next)) + (delete-node $IBest) + (delete-node $New))) +; + + + + (= + (do-new $Parent $New $IBest $Merge none) + ( (ins-node $Parent $New Nil) + (msgs (:: nl ' New terminal node: ' $New)) + (delete-node $IBest) + (delete-node $Merge))) +; + + + + (= + (best-child $Parent $Case $Best $IBest $Next $DoneRest $RestPred $PartSize $IncPrediction) + ( (findall $Child + (get-d-sub $Parent $Child) + (Cons $C1 + (Cons $C2 $DoRest))) + (length + (Cons $C1 + (Cons $C2 $DoRest)) $PartSize) + (copy-and-inc $C1 $Case $IC1) + (copy-and-inc $C2 $Case $IC2) + (compare-partitions $C1 $IC1 $C2 $IC2 $DoRest Nil $Parent $First $IFirst $Second $ISecond $FirstRestP) + (set-det) + (best-childs $Parent $Case $DoRest Nil $First $IFirst $Second $ISecond $FirstRestP $Best $IBest $Next $DoneRest $RestPred) + (sum-score + (:: $IBest) + (:: $Next) $Parent $RestPred $IncScore) + (node-prediction $Parent $NormPrediction) + (is $IncPrediction + (/ + (- $IncScore $NormPrediction) $PartSize)))) +; + + + + (= + (best-childs $_ $_ Nil $DoneRest $Best $IBest $Next $INext $RestP $Best $IBest $Next $DoneRest $RestP) + ( (delete-node $INext) (set-det))) +; + + (= + (best-childs $Parent $Case + (Cons $Try $DoRest) $DoneRest $First $IFirst $Second $ISecond $FirstRestP $Best $IBest $Next $NewDoneRest $RestP) + ( (copy-and-inc $Try $Case $ITry) (if (compare-partitions $Second $ISecond $Try $ITry $DoRest (Cons $First $DoneRest) $Parent $Second $ISecond $Try $ITry $_) (, (delete-node $ITry) (best-childs $Parent $Case $DoRest (Cons $Try $DoneRest) $First $IFirst $Second $ISecond $FirstRestP $Best $IBest $Next $NewDoneRest $RestP)) (, (delete-node $ISecond) (compare-partitions $First $IFirst $Try $ITry $DoRest (Cons $Second $DoneRest) $Parent $NFirst $NIFirst $NSecond $NISecond $NFirstRestP) (set-det) (best-childs $Parent $Case $DoRest (Cons $Second $DoneRest) $NFirst $NIFirst $NSecond $NISecond $NFirstRestP $Best $IBest $Next $NewDoneRest $RestP))))) +; + + + + (= + (new-child $Parent $Case $Best $Next $RestPred $PartSize $New $NewPrediction) + ( (new-node-from-case $Case $New) + (node $New $_ 1 1) + (assert-node $New) + (sum-score + (:: $New) + (:: $Best $Next) $Parent $RestPred $NewPredictionSum) + (node-prediction $Parent $NormPrediction) + (is $NewPrediction + (/ + (- $NewPredictionSum $NormPrediction) + (+ $PartSize 1))) + (set-det))) +; + + + + (= + (merge-child $Parent $Case $Best $Next $RestPred 2 $Merge -10000) + ( (new-node $Merge) + (assert-node $Merge) + (set-det))) +; + + (= + (merge-child $Parent $Case $Best $Next $RestPred $PartSize $Merge $MergePrediction) + ( (copy-node-to-new-node $Best $Merge) + (merge-node-into-node $Next $Merge) + (incorporate-case-into-node $Case $Merge) + (node-objects $Best $BestO) + (node-objects $Next $NextO) + (is $MergeObjects + (+ + (+ $BestO $NextO) 1)) + (node-objects $Merge $MergeObjects) + (compute-prediction $Merge) + (assert-node $Merge) + (sum-score + (:: $Merge) Nil $Parent $RestPred $MergePredictionSum) + (node-prediction $Parent $NormPrediction) + (is $MergePrediction + (/ + (- $MergePredictionSum $NormPrediction) + (- $PartSize 1))) + (set-det))) +; + + + + + (= + (split-child $Parent $Case $Best $IBest $Next $DoneRest $RestPred $PartSize -10000) + ( (terminal-node $Best) (set-det))) +; + + (= + (split-child $Parent $Case $Best $IBest $Next $DoneRest $RestPred $PartSize $SplitPrediction) + ( (findall $Child + (get-d-sub $Best $Child) + (Cons $C1 $DoRest)) + (length + (Cons $C1 $DoRest) $CPartSize) + (copy-and-inc $C1 $Case $IC1) + (copy-and-inc $Next $Case $INext) + (compare-partitions $C1 $IC1 $Next $INext $DoRest $DoneRest $Parent $First $IFirst $Second $ISecond $FirstRestP) + (set-det) + (best-childs $Parent $Case $DoRest $DoneRest $First $IFirst $Second $ISecond $FirstRestP $CBest $CIBest $CNext $_ $RPred) + (sum-score + (:: $CIBest) + (:: $CNext) $Parent $RPred $SplitPredictionSum) + (node-prediction $Parent $NormPrediction) + (is $SplitPrediction + (/ + (- $SplitPredictionSum $NormPrediction) + (- + (+ $PartSize $CPartSize) 1))) + (delete-node $CIBest) + (set-det))) +; + + + + (= + (compare-partitions $C1 $IC1 $C2 $IC2 $DoRest $DoneRest $Parent $First $IFirst $Second $ISecond $RestP) + ( (sum-score $DoRest $DoneRest $Parent 0 $RestP) + (sum-score + (:: $C1) + (:: $IC2) $Parent $RestP $IC2_Score) + (sum-score + (:: $IC1) + (:: $C2) $Parent $RestP $IC1_Score) + (det-if-then-else + (> $IC2_Score $IC1_Score) + (, + (= $First $C2) + (= $IFirst $IC2) + (= $Second $C1) + (= $ISecond $IC1)) + (, + (= $First $C1) + (= $IFirst $IC1) + (= $Second $C2) + (= $ISecond $IC2))) + (set-det))) +; + + + + (= + (copy-and-inc $Node $Case $INode) + ( (new-node $INode) + (set-det) + (copy-node-to-new-node $Node $INode) + (incorporate-case-into-node $Case $INode) + (node-objects $Node $Objects) + (is $IObjects + (+ $Objects 1)) + (node-objects $INode $IObjects) + (compute-prediction $INode) + (assert-node $INode) + (set-det))) +; + + + + (= + (merge-node-into-node $Node $MergeNode) + ( (or + (, + (get-node-nominal-attr $Node $Attr $ValuesCounter) + (if + (, + (remove-node-nominal-attr $MergeNode $Attr $MergeValuesCounter) + (sum-value-counter $ValuesCounter $MergeValuesCounter $NewValuesCounter) + (assert-node-nominal-attr $MergeNode $Attr $NewValuesCounter)) fail)) True) + (or + (, + (get-node-numeric-attr $Node $Attr $N $SumXiPow2 $SumXi) + (if + (, + (remove-node-numeric-attr $MergeNode $Attr $MergeN $MergeSumXiPow2 $MergeSumXi) + (is $NewN + (+ $N $MergeN)) + (is $NewSumXiPow2 + (+ $SumXiPow2 $MergeSumXiPow2)) + (is $NewSumXi + (+ $SumXi $MergeSumXi)) + (assert-node-numeric-attr $MergeNode $Attr $NewN $NewSumXiPow2 $NewSumXi)) fail)) True) + (set-det))) +; + + + + (= + (new-node-from-case $Case $Node) + ( (new-node $Node) + (or + (, + (get-case-feature $Case nominal + (:: $Attr $Val)) + (if + (assert-node-nominal-attr $Node $Attr + (:: (- $Val 1))) fail)) True) + (or + (, + (get-case-feature $Case numeric + (:: $Attr $Val)) + (if + (, + (is $SumXiPow2 + (* $Val $Val)) + (assert-node-numeric-attr $Node $Attr 1 $SumXiPow2 $Val)) fail)) True) + (set-det))) +; + + + + (= + (copy-node-to-new-node $Node $NewNode) + ( (new-node $NewNode) + (or + (, + (get-node-nominal-attr $Node $Attr $ValuesCounter) + (if + (assert-node-nominal-attr $NewNode $Attr $ValuesCounter) fail)) True) + (or + (, + (get-node-numeric-attr $Node $Attr $N $SumXiPow2 $SumXi) + (if + (assert-node-numeric-attr $NewNode $Attr $N $SumXiPow2 $SumXi) fail)) True) + (set-det))) +; + + + + (= + (incorporate-case-into-node $Case $Node) + ( (or + (, + (get-case-feature $Case nominal + (:: $Attr $Val)) + (if + (, + (remove-node-nominal-attr $Node $Attr $ValuesCounter) + (sum-value-counter $ValuesCounter + (:: (- $Val 1)) $NewValuesCounter) + (assert-node-nominal-attr $Node $Attr $NewValuesCounter)) fail)) True) + (or + (, + (get-case-feature $Case numeric + (:: $Attr $Val)) + (if + (, + (remove-node-numeric-attr $Node $Attr $N $SumXiPow2 $SumXi) + (is $NewN + (+ $N 1)) + (is $NewSumXiPow2 + (+ $SumXiPow2 + (* $Val $Val))) + (is $NewSumXi + (+ $SumXi $Val)) + (assert-node-numeric-attr $Node $Attr $NewN $NewSumXiPow2 $NewSumXi)) fail)) True) + (set-det))) +; + + + + (= + (sum-value-counter $ValuesCounter Nil $ValuesCounter) + (set-det)) +; + + (= + (sum_value_counter () $ValuesCounter $ValuesCounter) True) +; + + (= + (sum-value-counter + (Cons + (- $Val $C1) $R1) + (Cons + (- $Val $C2) $R2) + (Cons + (- $Val $SumC) $Rest)) + ( (is $SumC + (+ $C1 $C2)) + (set-det) + (sum-value-counter $R1 $R2 $Rest))) +; + + (= + (sum-value-counter + (Cons + (- $Val1 $C1) $R1) + (Cons + (- $Val2 $C2) $R2) + (Cons + (- $Val1 $C1) $Rest)) + ( (@< $Val1 $Val2) + (set-det) + (sum-value-counter $R1 + (Cons + (- $Val2 $C2) $R2) $Rest))) +; + + (= + (sum-value-counter + (Cons + (- $Val1 $C1) $R1) + (Cons + (- $Val2 $C2) $R2) + (Cons + (- $Val2 $C2) $Rest)) + ( (@< $Val2 $Val1) + (set-det) + (sum-value-counter + (Cons + (- $Val1 $C1) $R1) $R2 $Rest))) +; + + + + (= + (sum_score () () $_ $Score $Score) True) +; + + (= + (sum-score Nil + (Cons $Node $Rest) $NormNode $Score $Sum_Score) + ( (node $Node $_ $Objects $Prediction) + (node-objects $NormNode $NormObjects) + (is $ZScore + (+ + (/ + (* $Objects $Prediction) $NormObjects) $Score)) + (set-det) + (sum-score Nil $Rest $NormNode $ZScore $Sum_Score))) +; + + (= + (sum-score + (Cons $Node $Rest) $ToDo $NormNode $Score $Sum_Score) + ( (node $Node $_ $Objects $Prediction) + (node-objects $NormNode $NormObjects) + (is $ZScore + (+ + (/ + (* $Objects $Prediction) $NormObjects) $Score)) + (set-det) + (sum-score $Rest $ToDo $NormNode $ZScore $Sum_Score))) +; + + + + (= + (compute-prediction $Node) + ( (node-objects $Node $Objects) + (add-symbol &self + (prediction_counter 0 0)) + (get-node-nominal-attr $Node $_ $ValuesCounter) + (if + (remove-symbol &self + (prediction_counter $Sum $Count)) True) + (is $NCount + (+ $Count 1)) + (add-symbol &self + (prediction_counter $Sum $NCount)) + (member + (- $_ $C) $ValuesCounter) + (if + (remove-symbol &self + (prediction_counter $NNSum $NCount)) True) + (is $NSum + (+ $NNSum + (/ + (* $C $C) + (* $Objects $Objects)))) + (add-symbol &self + (prediction_counter $NSum $NCount)) + (fail))) +; + + (= + (compute-prediction $Node) + ( (get-node-numeric-attr $Node $_ $N $SumXiPow2 $SumXi) + (if + (remove-symbol &self + (prediction_counter $Sum $Count)) True) + (is $NCount + (+ $Count 1)) + (is $DeviationPow2 + (- + (/ $SumXiPow2 $N) + (/ + (* $SumXi $SumXi) + (* $N $N)))) + (abs $DeviationPow2 $PosDeviationPow2) + (sqrt $PosDeviationPow2 $Deviation) + (is $Pi pi) + (sqrt $Pi $S) + (is $Const + (* + (/ 1 4) $S)) + (get-acuity $Acuity) + (max-of + (:: $Deviation $Acuity $Const) $ScoreDeviation) + (is $NSum + (+ $Sum + (/ $Const $ScoreDeviation))) + (add-symbol &self + (prediction_counter $NSum $NCount)) + (fail))) +; + + (= + (compute-prediction $Node) + ( (remove-symbol &self + (prediction_counter $Prediction $Count)) + (is $NormPrediction + (/ $Prediction $Count)) + (node-prediction $Node $Prediction) + (set-det))) +; + + + + (= + (get-acuity $Accuity) + ( (get-symbols &self + (= + (acuity $Accuity) true)) (set-det))) +; + + (= + (get_acuity 0) True) +; + + + + (= + (init-node) + ( (abolish root 2) + (abolish root 4) + (or + (remove-symbol &self + (gensym_counter node_ $_)) True) + (or + (remove-all-symbols &self + (node root $_ $_)) True) + (or + (remove-all-symbols &self + (d_sub root $_)) True) + (or + (remove-all-symbols &self + (d_sub $_ root)) True) + (set-det))) +; + + + + (= + (new-node (node $Node $_ $_)) + (nonvar $Node)) +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + (= + (new-node (node $Node $_ $_)) + ( (var $Node) + (gensym node- $Node) + (dynamic (/ $Node 2)) + (dynamic (/ $Node 4)) + (abolish $Node 2) + (abolish $Node 4) + (or + (remove-all-symbols &self + (node $Node $_ $_)) True) + (or + (remove-all-symbols &self + (d_sub $Node $_)) True) + (or + (remove-all-symbols &self + (d_sub $_ $Node)) True) + (set-det))) +; + + + + (= + (delete-node $Node) + ( (remove-node $Node) + (node-name $Node $NodeName) + (abolish $NodeName 2) + (abolish $NodeName 4) + (or + (, + (remove-d-sub $Parent $Node) + (remove-d-sub $Node $Child) + (assert-d-sub $Parent $Child) + (fail)) True) + (set-det))) +; + + + + (= + (terminal-node $Node) + (node-objects $Node 1)) +; + + + + (= + (move-subs $Source $Dest) + ( (remove-d-sub $Source $Child) + (assert-d-sub $Dest $Child) + (fail))) +; + + (= + (move-subs $Source $Dest) + ( (remove-d-sub $Parent $Source) + (assert-d-sub $Parent $Dest) + (set-det))) +; + + + + (= + (ins-node $Parent $New Nil) + ( (assert-d-sub $Parent $New) (set-det))) +; + + (= + (ins-node $Parent $New + (Cons $Child $Rest)) + ( (or + (remove-d-sub $Parent $Child) True) + (assert-d-sub $New $Child) + (set-det) + (ins-node $Parent $New $Rest))) +; + + + + (= + (node-name + (node $Name $_ $_) $Name) + ( (nonvar $Name) (set-det))) +; + + + + (= + (node-objects + (node $Name $Objects $_) $Objects) + ( (nonvar $Name) + (if + (var $Objects) + (get-node (node $Name $Objects $_)) True) + (set-det))) +; + + + + (= + (node-prediction + (node $Name $Objects $Pred) $Pred) + ( (nonvar $Name) + (or + (, + (var $Pred) + (get-node (node $Name $Objects $Pred))) True) + (if + (var $Pred) + (compute-prediction (node $Name $Objects $Pred)) True) + (set-det))) +; + + + + (= + (node + (node $Name $Objects $Pred) $Name $Objects $Pred) + ( (nonvar $Name) + (if + (var $Objects) + (get-node (node $Name $Objects $_)) True) + (or + (, + (var $Pred) + (get-node (node $Name $Objects $Pred))) True) + (if + (var $Pred) + (compute-prediction (node $Name $Objects $Pred)) True) + (set-det))) +; + + + + (= + (get-node (node $Node $Objects $Pred)) + (get-symbols &self + (= + (node $Node $Objects $Pred) true))) +; + + + + (= + (assert-node (node $Node $Objects $Pred)) + ( (nonvar $Node) (add-symbol &self (node $Node $Objects $Pred)))) +; + + + + (= + (remove-node (node $Node $Objects $Pred)) + (remove-symbol &self + (node $Node $Objects $Pred))) +; + + + + (= + (get-node-nominal-attr + (node $Node $_ $_) $Attr $ValuesCounter) + ( (nonvar $Node) + (nonvar $Attr) + (=.. $Call + (:: $Node $Attr $ValuesCounter)) + (or + (get-symbols &self + (= $Call true)) + (if + (var $ValuesCounter) + (= $ValuesCounter Nil))) + (set-det))) +; + + (= + (get-node-nominal-attr + (node $Node $_ $_) $Attr $ValuesCounter) + ( (nonvar $Node) + (var $Attr) + (=.. $Call + (:: $Node $Attr $ValuesCounter)) + (get-symbols &self + (= $Call true)))) +; + + + + (= + (assert_node_nominal_attr $_ $_ ()) True) +; + + (= + (assert-node-nominal-attr + (node $Node $_ $_) $Attr $ValuesCounter) + ( (nonvar $Node) + (nonvar $Attr) + (nonvar $ValuesCounter) + (=.. $Call + (:: $Node $Attr $ValuesCounter)) + (add-symbol &self $Call))) +; + + + + (= + (remove-node-nominal-attr + (node $Node $_ $_) $Attr $ValuesCounter) + ( (nonvar $Node) + (nonvar $Attr) + (=.. $Call + (:: $Node $Attr $ValuesCounter)) + (or + (remove-symbol &self $Call) + (if + (var $ValuesCounter) + (= $ValuesCounter Nil))) + (set-det))) +; + + (= + (remove-node-nominal-attr + (node $Node $_ $_) $Attr $ValuesCounter) + ( (nonvar $Node) + (=.. $Call + (:: $Node $Attr $ValuesCounter)) + (remove-symbol &self $Call))) +; + + + + (= + (get-node-numeric-attr + (node $Node $_ $_) $Attr $N $SumXiPow2 $SumXi) + ( (nonvar $Node) + (nonvar $Attr) + (=.. $Call + (:: $Node $Attr $N $SumXiPow2 $SumXi)) + (or + (get-symbols &self + (= $Call true)) + (if + (var $N) + (, + (= $N 0) + (= $SumXiPow2 0) + (= $SumXi 0)))) + (set-det))) +; + + (= + (get-node-numeric-attr + (node $Node $_ $_) $Attr $N $SumXiPow2 $SumXi) + ( (nonvar $Node) + (var $Attr) + (=.. $Call + (:: $Node $Attr $N $SumXiPow2 $SumXi)) + (get-symbols &self + (= $Call true)))) +; + + + + (= + (assert_node_numeric_attr $_ $_ 0 $_ $_) True) +; + + (= + (assert-node-numeric-attr + (node $Node $_ $_) $Attr $N $SumXiPow2 $SumXi) + ( (nonvar $Node) + (nonvar $Attr) + (nonvar $N) + (nonvar $SumXiPow2) + (nonvar $SumXi) + (=.. $Call + (:: $Node $Attr $N $SumXiPow2 $SumXi)) + (add-symbol &self $Call))) +; + + + + (= + (remove-node-numeric-attr + (node $Node $_ $_) $Attr $N $SumXiPow2 $SumXi) + ( (nonvar $Node) + (nonvar $Attr) + (=.. $Call + (:: $Node $Attr $N $SumXiPow2 $SumXi)) + (or + (remove-symbol &self $Call) + (if + (var $N) + (, + (= $N 0) + (= $SumXiPow2 0) + (= $SumXi 0)))) + (set-det))) +; + + (= + (remove-node-numeric-attr + (node $Node $_ $_) $Attr $N $SumXiPow2 $SumXi) + ( (nonvar $Node) + (=.. $Call + (:: $Node $Attr $N $SumXiPow2 $SumXi)) + (remove-symbol &self $Call))) +; + + + + (= + (get-d-sub + (node $SuperNode $_ $_) + (node $SubNode $_ $_)) + (get-symbols &self + (= + (d_sub $SuperNode $SubNode) true))) +; + + + + (= + (assert-d-sub + (node $SuperNode $_ $_) + (node $SubNode $_ $_)) + (add-symbol &self + (d_sub $SuperNode $SubNode))) +; + + + + (= + (remove-d-sub + (node $SuperNode $_ $_) + (node $SubNode $_ $_)) + (remove-symbol &self + (d_sub $SuperNode $SubNode))) +; + + + + (= + (max-of + (Cons $F $R) $Max) + ( (max-of $R $F $Max) (set-det))) +; + + (= + (max_of () $Max $Max) True) +; + + (= + (max-of + (Cons $F $R) $Best $Max) + ( (=< $F $Best) + (set-det) + (max-of $R $Best $Max))) +; + + (= + (max-of + (Cons $F $R) $_ $Max) + (max-of $R $F $Max)) +; + + + + (= + (msgs Nil) + (set-det)) +; + + (= + (msgs (Cons $First $Rest)) + ( (msg $First) (msgs $Rest))) +; + + + + (= + (msg (node $ID $Obj $Pred)) + ( (set-det) + (write $ID) + (write (obj=) + (write $Obj) + (write ',pred=') + (write $Pred) + (write )))) +; + + (= + (msg $Var) + ( (var $Var) + (set-det) + (write $Var))) +; + + (= + (msg nl) + ( (set-det) (nl))) +; + + (= + (msg (nl $N)) + ( (set-det) (msg-repeat $N nl))) +; + + (= + (msg sp) + ( (set-det) (write ' '))) +; + + (= + (msg (sp $N)) + ( (set-det) (msg-repeat $N (outterm ' ')))) +; + + (= + (msg (q- $O)) + ( (set-det) (write $O))) +; + + (= + (msg $X) + ( (set-det) (write $X))) +; + + +; +; + + + (= + (msg-repeat $N $_) + ( (< $N 1) (set-det))) +; + + (= + (msg-repeat $N $Call) + ($Call + (is $N1 + (- $N 1)) + (msg-repeat $N1 $Call))) +; + + + + (= + (save-kb $FN) + ( (concat $FN .pl $Y) + (tell $Y) + (print-kb) + (told) + (set-det))) +; + + + + (= + (load-kb $FN) + ( (clear-kb) + (concat $FN .pl $Y) + (consult $Y) + (set-det))) +; + + + + (= + (print-kb) + ( (if + (= $Call + (d-sub $SuperNode $SubNode)) True) + (get-symbols &self + (= $Call true)) + (if + (, + (writeq $Call) + (write .) + (nl)) fail))) +; + + (= + (print-kb) + ( (get-node $Node) (if (, (writeq $Node) (write .) (nl)) fail))) +; + + (= + (print-kb) + ( (get-node $Node) + (if + (, + (node-name $Node $Name) + (=.. $Call + (:: $Name $Attr $ValuesCounter))) True) + (get-symbols &self + (= $Call true)) + (if + (, + (writeq $Call) + (write .) + (nl)) fail))) +; + + (= + (print-kb) + ( (get-node $Node) + (if + (, + (node-name $Node $Name) + (=.. $Call + (:: $Name $Attr $N $SumXiPow2 $SumXi))) True) + (get-symbols &self + (= $Call true)) + (if + (, + (writeq $Call) + (write .) + (nl)) fail))) +; + + (= print_kb True) +; + + + + (= + (clear-kb) + ( (get-node $Node) (if (, (node-name $Node $Name) (abolish $Name 2) (abolish $Name 4)) fail))) +; + + (= + (clear-kb) + ( (abolish node 3) + (abolish d-sub 2) + (or + (remove-symbol &self + (gensym_counter node_ $_)) True) + (add-symbol &self + (gensym_counter node_ 0)) + (set-det))) +; + + + + (= + (show) + ( (collect-tree root $Tree all) + (display-tree $Tree) + (set-det))) +; + + + + (= + (show-classes) + ( (collect-tree root $Tree classes) + (display-tree $Tree) + (set-det))) +; + + + + (= + (collect_tree () () $_) True) +; + + (= + (collect-tree + (Cons $Node $Nodes) + (Cons $SubTree $SubTrees) $Type) + ( (collect-tree $Node $SubTree $Type) + (set-det) + (collect-tree $Nodes $SubTrees $Type))) +; + + (= + (collect-tree + (Cons $_ $Nodes) $SubTrees classes) + ( (set-det) (collect-tree $Nodes $SubTrees classes))) +; + + (= + (collect-tree $Node + (:: $Node $Obj $SubTrees) $Type) + ( (get-symbols &self + (= + (node $Node $Obj $_) true)) + (or + (setof $Sub + (get-symbols &self + (= + (d_sub $Node $Sub) true)) $Subs) + (, + (= $Type all) + (= $Subs Nil))) + (set-det) + (collect-tree $Subs $SubTrees $Type))) +; + + + + (= + (display-tree (:: $Node $Obj $SubTrees)) + ( (write 'Number of cases processed: ') + (write $Obj) + (nl) + (write $Node) + (name $Node $String) + (length $String $Offset) + (display-tree $SubTrees $Offset))) +; + + + (= + (display-tree + (:: $Node) $Offset) + ( (set-det) (display-tree-node $Node $Offset))) +; + + (= + (display-tree + (Cons $Node $Subtrees) $Offset) + ( (set-det) + (display-tree-node $Node $Offset) + (tab $Offset) + (display-tree $Subtrees $Offset))) +; + + + + (= + (display-tree-node + (:: $Node $Obj Nil) $Offset) + ( (set-det) + (write <-- ) + (write $Node) + (write = ) + (write $Obj) + (nl))) +; + + (= + (display-tree-node + (:: $Node $Obj $Subtree) $Offset) + ( (write <-- ) + (write $Node) + (write = ) + (write $Obj) + (name $Node $String1) + (length $String1 $SLength) + (name $Obj $String2) + (length $String2 $NLength) + (is $NewOffset + (+ + (+ + (+ + (+ $Offset 5) $SLength) 3) $NLength)) + (display-tree $Subtree $NewOffset))) +; + + + + (= + (show-node $Node) + ( (collect-attribute-values $Node $Nominal $Numeric) (display-node $Node $Nominal $Numeric))) +; + + + + (= + (collect-attribute-values $Node $NominalAttValueList $NumericAttValueList) + ( (=.. $NominalAttValues + (:: $Node $NominalAtt $NominalVals)) + (=.. $NumericAttValues + (:: $Node $NumericAtt $Number $X $Y)) + (findall $NominalAttValues + (call $NominalAttValues) $NominalAttValueList) + (findall $NumericAttValues + (call $NumericAttValues) $NumericAttValueList))) +; + + + + (= + (if $Cond $Then) + ( (call $Cond) + (set-det) + (call $Then))) +; + + (= + (if $_ $_) True) +; + + + (= + (if $Cond $Then $Else) + ( (call $Cond) + (set-det) + (calltrue $Then))) +; + + (= + (if $_ $_ $Else) + (calltrue $Else)) +; + + + + (= + (calltrue $Call) + ( (call $Call) (set-det))) +; + + (= + (calltrue $_) True) +; + + + + (= + (count $VAR $X) + ( (remove-symbol &self + (gensym_counter $VAR $N)) + (is $X + (+ $N 1)) + (add-symbol &self + (gensym_counter $VAR $X)) + (set-det))) +; + + (= + (count $VAR 1) + (add-symbol &self + (gensym_counter $VAR 1))) +; + + + + (= + (gensym $SYM) + (gensym $SYM g)) +; + + + (= + (gensym $N $Sym) + ( (count $N $X) + (name $N $S1) + (name $X $S2) + (append $S1 $S2 $S3) + (name $Sym $S3))) +; + + + + (= + (remove-all-symbols &self $HEAD) + ( (var $HEAD) + (set-det) + (fail))) +; + + (= + (remove-all-symbols &self + (:- $HEAD $BODY)) + ( (var $BODY) + (set-det) + (or + (, + (remove-symbol &self + (:- $HEAD true)) + (fail)) True) + (or + (, + (remove-symbol &self + (:- $HEAD $_)) + (fail)) True))) +; + + (= + (remove-all-symbols &self + (:- $HEAD true)) + ( (remove-symbol &self + (:- $HEAD true)) (fail))) +; + + (= + (remove-all-symbols &self + (:- $HEAD $BODY)) + ( (remove-symbol &self + (:- $HEAD $BODY)) (fail))) +; + + (= + (retractall $_) True) +; + + + + (= + (abs $X $Y) + ( (< $X 0) + (is $Y + (* $X -1)) + (set-det))) +; + + (= + (abs $X $X) True) +; + + + + (= + (sqrt $X $Y) + (is $Y + (sqrt $X))) +; + + + + (= + (help) + ( (write ' Load data set : load-kb(Filename).') + (nl) + (write ' Process single file : learn.') + (nl) + (write ' Process multiple files : learn-more.') + (nl) + (write ' Show hierarchy (classes & cases) : show.') + (nl) + (write ' Show hierarchy (classes only) : show-classes.') + (nl) + (write ' Show node (not yet impl.) : show-node(NodeID).') + (nl) + (write ' Print result (cryptical) : print-kb.') + (nl) + (write ' Store result : save-kb(Filename).') + (nl) + (write ' Forget result : clear-kb.') + (nl))) +; + + + + !(help *) +; + + + diff --git a/cobweb/cobweb_1.metta b/cobweb/cobweb_1.metta new file mode 100644 index 0000000..2ae729a --- /dev/null +++ b/cobweb/cobweb_1.metta @@ -0,0 +1,53 @@ + + (= + (features + ( (numeric minPrice) + (nominal tv) + (nominal bar))) True) +; + ; +; + + +; +; + +; +; + +; +; + + + + (= + (case + (sheraton 250.0 y y)) True) +; + + (= + (case + (ritz 223.0 y y)) True) +; + + (= + (case + (kempinski 224.0 y y)) True) +; + + (= + (case + (sonja 40.0 n y)) True) +; + + (= + (case + (ostermann 35 n n)) True) +; + + (= + (case + (zur_gruenen_wiese 50 y n)) True) +; + + diff --git a/cobweb/cobweb_2.metta b/cobweb/cobweb_2.metta new file mode 100644 index 0000000..99d98e0 --- /dev/null +++ b/cobweb/cobweb_2.metta @@ -0,0 +1,51 @@ + + (= + (features + ( (numeric ht) + (numeric wid) + (numeric txt))) True) +; + + +; +; + +; +; + +; +; + + + + (= + (case + (firstInstance 14.0 7.0 8.0)) True) +; + + (= + (case + (secondInstance 12.0 7.0 20.0)) True) +; + + (= + (case + (thirdInstance 25.0 15.0 24.0)) True) +; + + (= + (case + (fourthInstance 28.0 13.0 19.0)) True) +; + + (= + (case + (fifthInstance 41.0 36.0 30.0)) True) +; + + (= + (case + (sixthInstance 12.0 6.0 7.0)) True) +; + + diff --git a/cobweb/cobweb_3.metta b/cobweb/cobweb_3.metta new file mode 100644 index 0000000..a663ca3 --- /dev/null +++ b/cobweb/cobweb_3.metta @@ -0,0 +1,48 @@ + + (= + (features + ( (nominal bodycover) + (nominal heartchamber) + (nominal bodytemp) + (nominal fertilization))) True) +; + + +; +; + +; +; + +; +; + + + + (= + (case + (reptile cornified_skin imperfect_four unregulated internal)) True) +; + + (= + (case + (bird feathers four regulated internal)) True) +; + + (= + (case + (amphipian moist_skin three unregulated external)) True) +; + + (= + (case + (fish scales two unregulated external)) True) +; + + (= + (case + (mammal hair four regulated internal)) True) +; + + + diff --git a/cobweb/cobweb_4.metta b/cobweb/cobweb_4.metta new file mode 100644 index 0000000..52c66ea --- /dev/null +++ b/cobweb/cobweb_4.metta @@ -0,0 +1,42 @@ + + (= + (features + ( (nominal tails) + (nominal color) + (nominal nuclei))) True) +; + + +; +; + +; +; + +; +; + + + + (= + (case + (cell1 one light one)) True) +; + + (= + (case + (cell2 two dark two)) True) +; + + (= + (case + (cell3 two light two)) True) +; + + (= + (case + (cell4 one dark three)) True) +; + + + diff --git a/discr/discr.metta b/discr/discr.metta new file mode 100644 index 0000000..d97e494 --- /dev/null +++ b/discr/discr.metta @@ -0,0 +1,364 @@ + + !(dynamic (/ :: 2)) +; + + + !(op 150 yfx ::) +; + + !(op 145 xfx <-) +; + + !(op 140 xfy &) +; + + !(op 135 xfx :=) +; + + + + (= + (derivation + (<- $P $C) $TYP) + ( (name a1 $NAME) + (add-context $NAME $C) + (generate-goal-ids $P $ID1 1 $I1) + (expand-derivation $P $P2 $ID1 $ID2 + (:: $I1 $ID1) + (:: $I2 $DERIVATION)) + (add-symbol &self + (:: $TYP $DERIVATION)) + (write (:: $TYP $DERIVATION)) + (nl) + (fail))) +; + + (= + (derivation $_ $_) + ( (name a1 + (:: $N1 $N2)) (del-context (:: $N1 $_)))) +; + + + + (= + (add-context + (:: $N1 $N2) + (& $P1 $P2)) + ( (set-det) + (name $C + (:: $N1 $N2)) + (add-symbol &self + (:: $C + (<- $P1 true))) + (is $N3 + (+ $N2 1)) + (add-context + (:: $N1 $N3) $P2))) +; + + (= + (add-context + (:: $N1 $N2) $P1) + ( (name $C + (:: $N1 $N2)) (add-symbol &self (:: $C (<- $P1 true))))) +; + + + + (= + (del-context (:: $N1 $N2)) + ( (:: $C + (<- $P1 True)) + (name $C + (:: $N1 $_)) + (remove-symbol &self + (:: $C + (<- $P1 true))) + (fail))) +; + + (= + (del_context $_) True) +; + + + + (= + (generate-goal-ids + (& $P1 $P2) + (& $I1 $I2) $I1 $I4) + ( (set-det) + (is $I3 + (+ $I1 1)) + (generate-goal-ids $P2 $I2 $I3 $I4))) +; + + (= + (generate-goal-ids $P1 $I1 $I1 $I4) + (is $I4 + (+ $I1 1))) +; + + + + (= + (expand-derivation True True $ID1 $ID1 $D1 $D1) + (set-det)) +; + + (= + (expand-derivation + (& True $P3) $P3 + (& $ID1 $ID3) $ID3 $D1 $D1) + (set-det)) +; + + (= + (expand-derivation + (& $P1 $P3) $P5 + (& $ID1 $ID3) $ID5 $D1 $D3) + ( (expand-derivation- $P1 $P2 $ID1 $ID2 $D1 $D2) + (join-goals + (& $P2 $P3) $P4 + (& $ID2 $ID3) $ID4) + (expand-derivation $P4 $P5 $ID4 $ID5 $D2 $D3))) +; + +; (error +; (syntax_error operator_expected) +; (file discr/discr.pl 201 8 11767)) + + + + (= + (expand-derivation- $P1 $P2 $ID1 $ID2 + (:: $I1 $D1) + (:: $I2 $D2)) + ( (:: $C + (<- $P1 $P2)) + (generate-goal-ids $P2 $ID2 $I1 $I2) + (= $D2 + (:: + (:: $D1 $C) + (<- $ID1 $ID2))))) +; + + + + (= + (join-goals + (& $P1 + (& $P2 $P3)) + (& $P1 $P5) + (& $ID1 + (& $ID3 $ID3)) + (& $ID1 $ID5)) + ( (set-det) (join-goals (& $P2 $P3) $P5 (& $ID2 $ID3) $ID5))) +; + + (= + (join-goals + (& True $P3) $P3 + (& $ID1 $ID3) $ID3) + (set-det)) +; + + (= + (join_goals $P1 $P1 $ID1 $ID1) True) +; + + +; (error +; (syntax_error operator_expected) +; (file discr/discr.pl 248 8 14466)) + + + + (= + (spec $T1 $T2) + ( (ground $T2 1 $_) (= $T1 $T2))) +; + + + + (= + (ground + (skolem-function $N1) $N1 $N2) + ( (set-det) (is $N2 (+ $N1 1)))) +; + + (= + (ground $T $N1 $N2) + ( (=.. $T + (Cons $_ $TS)) + (== $TS Nil) + (set-det))) +; + + (= + (ground $T $N1 $N2) + ( (=.. $T + (Cons $_ $TS)) (grounds $TS $N1 $N2))) +; + + + + (= + (grounds + (Cons $T $TS) $N1 $N3) + ( (ground $T $N1 $N2) (grounds $TS $N1 $N2))) +; + + (= + (grounds () $N1 $N1) True) +; + + + + (= + (generate-discriminants $P $PA $PR) + ( (generate-goal-ids $P $ID 1 $_) + (determine-discriminant + (:: + (:: + (:: $P $ID) $P) $ID) + (:: + (:: + (:: $PA $IA) $PR) $IR)) + (add-symbol &self + (:: disc $PA)) + (write (:: disc $PA)) + (nl) + (fail))) +; + + (= + (generate_discriminants $_ $_ $_) True) +; + + +; (error +; (syntax_error operator_expected) +; (file discr/discr.pl 293 8 16547)) + + + (= + (determine-discriminant + (:: + (:: + (:: + (& True $PA3) + (& $_ $IA3)) + (& True $PR3)) + (& $_ $IR3)) $P3) + ( (set-det) (= $P3 (:: (:: (:: $PA3 $IA3) $PR3) $IR3)))) +; + + (= + (determine-discriminant + (:: + (:: + (:: + (& $PA1 $PA3) + (& $IA1 $IA3)) + (& $PR1 $PR3)) + (& $IR1 $IR3)) $P3) + ( (determine-discriminant + (:: + (:: + (:: $PA1 $IA1) $PR1) $IR1) + (:: + (:: + (:: $PA2 $IA2) $PR2) $IR2)) + (join-goals + (& $PA2 $PA3) $PA5 + (& $IA2 $IA3) $IA5) + (join-goals + (& $PR2 $PR3) $PR5 + (& $IR2 $IR3) $IR5) + (= $P3 + (:: + (:: + (:: $PA5 $IA5) $PR5) $IR5)))) +; + + (= + (determine-discriminant + (:: + (:: + (:: + (& $PA1 $PA3) + (& $IA1 $IA3)) + (& $PR1 $PR3)) + (& $IR1 $IR3)) $P3) + ( (determine-discriminant + (:: + (:: + (:: $PA3 $IA3) $PR3) $IR3) + (:: + (:: + (:: $PA4 $IA4) $PR4) $IR4)) (= $P3 (:: (:: (:: (& $PA1 $PA4) (& $IA1 $IA4)) (& $PR1 $PR4)) (& $IR1 $PR4))))) +; + +; (error +; (syntax_error operator_expected) +; (file discr/discr.pl 305 8 17158)) + + + + (= + (determine-discriminant- $P1 $P3) + ( (= $P1 + (:: + (:: + (:: $PA1 $IA1) $PR1) $IR1)) + (:: $CA + (<- $PA1 $PA2)) + (:: app $DA) + (in-derivation-p + (:: $CA + (<- $IA1 $IA2)) $DA) + (:: $CR + (<- $PR1 $PR2)) + (:: rej $DR) + (in-derivation-p + (:: $CR + (<- $IR1 $IR2)) $DR) + (= $P3 + (:: + (:: + (:: $PA2 $IA2) $PR2) $IR2)))) +; + + + + (= + (in-derivation-p + (:: $X $C) + (:: + (:: $DER $X) $C)) + (set-det)) +; + + (= + (in-derivation-p + (:: $X $C) + (:: $DER $_)) + (in-derivation-p + (:: $X $C) $DER)) +; + + + + (= + (help) + ( (write 'Load data set with command: [Filename].') (nl))) +; + + + + !(help *) +; + + diff --git a/discr/discr_1.metta b/discr/discr_1.metta new file mode 100644 index 0000000..aa01a9a --- /dev/null +++ b/discr/discr_1.metta @@ -0,0 +1,43 @@ + + (= + (ex1) + ( (exc1) + (derivation + (<- q + (& u v)) app) + (derivation + (<- q + (& w v)) rej) + (generate-discriminants q $_ $_))) +; + + + + (= + (exc1) + ( (abolish :: 2) + (add-symbol &self + (:: c1 + (<- q + (& s r)))) + (add-symbol &self + (:: c2 + (<- s t))) + (add-symbol &self + (:: c3 + (<- s w))) + (add-symbol &self + (:: c4 + (<- t u))) + (add-symbol &self + (:: c5 + (<- r v))))) +; + + + + (= + (?- ex1) True) +; + + diff --git a/discr/discr_2.metta b/discr/discr_2.metta new file mode 100644 index 0000000..1086070 --- /dev/null +++ b/discr/discr_2.metta @@ -0,0 +1,96 @@ + + (= + (ex2) + ( (exc2) + (derivation + (<- + (term (:: t1 t2)) + (& + (const t1) + (const t2))) app) + (derivation + (<- + (term (:: t1 t2)) + (& + (termv t1) + (termc t2))) rej) + (generate-discriminants + (term (:: t1 t2)) $_ $_))) +; + + + + (= + (exc2) + ( (abolish :: 2) + (add-symbol &self + (:: c1 + (<- + (term $X) + (& + (:= + (:: $X1 $X2) $X) + (& + (term $X1) + (term $X2)))))) + (add-symbol &self + (:: c2 + (<- + (term $X) + (termc $X)))) + (add-symbol &self + (:: c3 + (<- + (term $X) + (termv $X)))) + (add-symbol &self + (:: c4 + (<- + (termc $X) + (& + (:= + (:: $X1 $X2) $X) + (& + (termc $X1) + (termc $X2)))))) + (add-symbol &self + (:: c5 + (<- + (termc $X) + (const $X)))) + (add-symbol &self + (:: c6 + (<- + (termv $X) + (& + (:= + (:: $X1 $X2) $X) + (termv $X1))))) + (add-symbol &self + (:: c7 + (<- + (termv $X) + (& + (:= + (:: $X1 $X2) $X) + (termv $X2))))) + (add-symbol &self + (:: c8 + (<- + (termv $X) + (var $X)))) + (add-symbol &self + (:- + (:: c9 + (<- + (:= $X1 $X2) true)) + (:= $X1 $X2))))) +; + + + + (= + (?- ex2) True) +; + + diff --git a/ebg/ebg.metta b/ebg/ebg.metta new file mode 100644 index 0000000..429a5fe --- /dev/null +++ b/ebg/ebg.metta @@ -0,0 +1,237 @@ + + (= + (prove-1 (, $HEAD $REST)) + ( (set-det) + (prove-1 $HEAD) + (prove-1 $REST))) +; + + (= + (prove-1 $FACT) + (get-symbols &self + (= $FACT true))) +; + + (= + (prove-1 $GOAL) + ( (get-symbols &self + (= $GOAL $PREMISSES)) (prove-1 $PREMISSES))) +; + + (= + (prove-1 $GOAL) + (call $GOAL)) +; + + + + (= + (prove-2 + (, $HEAD $REST) $PROOF) + ( (set-det) + (prove-2 $HEAD $HEAD_PROOF) + (prove-2 $REST $REST_PROOF) + (append $HEAD_PROOF $REST_PROOF $PROOF))) +; + + (= + (prove-2 $FACT + (:: $FACT)) + (get-symbols &self + (= $FACT true))) +; + + (= + (prove-2 $GOAL $PROOF) + ( (get-symbols &self + (= $GOAL $PREMISSES)) + (not (== $PREMISSES True)) + (prove-2 $PREMISSES $PREM_PROOF) + (append + (:: $GOAL) + (:: $PREM_PROOF) $PROOF))) +; + + (= + (prove-2 $GOAL + (:: $GOAL)) + (call $GOAL)) +; + + + + (= + (prove-3 + (, $HEAD $REST) $PROOF) + ( (set-det) + (prove-3 $HEAD $HEAD_PROOF) + (prove-3 $REST $REST_PROOF) + (append $HEAD_PROOF $REST_PROOF $PROOF))) +; + +; (error +; (syntax_error operator_expected) +; (file ebg/ebg.pl 124 8 6850)) + + (= + (prove-3 $GOAL $PROOF) + ( (get-symbols &self + (= $GOAL $PREMISSES)) + (not (== $PREMISSES True)) + (prove-3 $PREMISSES $PREM_PROOF) + (append + (:: $GOAL) + (:: $PREM_PROOF) $PROOF))) +; + + (= + (prove_3 $GOAL + ($GOAL)) True) +; + + + + (= + (prove-4 + (or $HEAD $REST) $PROOF) + ( (set-det) (or (prove-4 $HEAD $PROOF) (prove-4 $REST $PROOF)))) +; + + (= + (prove-4 + (, $HEAD $REST) $PROOF) + ( (set-det) + (prove-4 $HEAD $HEAD_PROOF) + (prove-4 $REST $REST_PROOF) + (append $HEAD_PROOF $REST_PROOF $PROOF))) +; + +; (error +; (syntax_error operator_expected) +; (file ebg/ebg.pl 155 8 8557)) + +; (error +; (syntax_error operator_expected) +; (file ebg/ebg.pl 157 8 8632)) + + (= + (prove_4 $GOAL + ($GOAL)) True) +; + + + + (= + (prove-5 + (, $HEAD $REST) + (Cons $PROOF_HEAD $PROOF_REST) $LIST) + ( (set-det) + (prove-5 $HEAD $PROOF_HEAD $PROOF_LIST1) + (prove-5 $REST $PROOF_REST $PROOF_LIST2) + (append $PROOF_LIST1 $PROOF_LIST2 $LIST))) +; + +; (error +; (syntax_error operator_expected) +; (file ebg/ebg.pl 187 8 10387)) + + (= + (prove-5 $GOAL + (:: $GOAL $PROOF) $LIST) + ( (get-symbols &self + (= $GOAL $PREMISSES)) + (not (== $PREMISSES True)) + (prove-5 $PREMISSES $PROOF $LIST))) +; + + (= + (prove_5 $GOAL + ($GOAL) + ($GOAL)) True) +; + + + + (= + (prove-6 + (, $HEAD $REST) + (, $GEN_HEAD $GEN_REST) $LIST) + ( (set-det) + (prove-6 $HEAD $GEN_HEAD $LIST1) + (prove-6 $REST $GEN_REST $LIST2) + (append $LIST1 $LIST2 $LIST))) +; + + (= + (prove-6 $GOAL $GEN_GOAL + (:: $GEN_GOAL)) + ( (operational $GOAL) (set-det))) +; + +; (error +; (syntax_error operator_expected) +; (file ebg/ebg.pl 218 8 12142)) + + + + (= + (listify + ($H) $H) True) +; + + (= + (listify + (Cons $H $R) + (, $H $S)) + (listify $R $S)) +; + + + + (= + (copy $TERM1 $TERM2) + ( (add-symbol &self + (internal $TERM1)) + (remove-symbol &self + (internal $TERM2)) + (set-det))) +; + + + + (= + (operational $A) + (get-symbols &self + (= $A true))) +; + +; (error +; (syntax_error operator_expected) +; (file ebg/ebg.pl 277 8 15501)) + + + + (= + (ebg $GOAL $RULE) + ( (functor $GOAL $F $N) + (functor $COPY $F $N) + (call $GOAL) + (prove-6 $GOAL $COPY $ZWERG1) + (listify $ZWERG1 $ZWERG2) + (= $RULE + (= $COPY $ZWERG2)))) +; + + + + (= + (help) + ( (write 'Load example theories and start EBG with command: [Filename].') (nl))) +; + + + + !(help *) +; + + diff --git a/ebg/ebg_1.metta b/ebg/ebg_1.metta new file mode 100644 index 0000000..c6d2487 --- /dev/null +++ b/ebg/ebg_1.metta @@ -0,0 +1,56 @@ + + (= + (depressed john) True) +; + + + (= + (buy john gun1) True) +; + + + (= + (gun gun1) True) +; + + + + (= + (kill $A $B) + ( (hate $A $B) + (possess $A $C) + (weapon $C))) +; + + + (= + (hate $W $W) + (depressed $W)) +; + + + (= + (possess $U $V) + (buy $U $V)) +; + + + (= + (weapon $Z) + (gun $Z)) +; + + + + (= + (?- + (; + (, + (ebg + (kill john john) $L) + (, + (write $L) fail)) true)) True) +; + + + diff --git a/ebg/ebg_2.metta b/ebg/ebg_2.metta new file mode 100644 index 0000000..e6fd1d4 --- /dev/null +++ b/ebg/ebg_2.metta @@ -0,0 +1,92 @@ + + (= + (on o1 o2) True) +; + + + (= + (isa o1 box) True) +; + + (= + (isa o2 endtable) True) +; + + + (= + (color o1 red) True) +; + + (= + (color o2 blue) True) +; + + + (= + (volume o1 1) True) +; + + + (= + (density o1 2) True) +; + + + (= + (isa o3 box) True) +; + + + (= + (volume o3 6) True) +; + + + (= + (density o3 2) True) +; + + + + (= + (save-to-stack $X $Y) + (lighter $X $Y)) +; + + + (= + (weight $O $W) + ( (volume $O $V) + (density $O $D) + (is $W + (* $V $D)))) +; + + + (= + (lighter $O1 $O2) + ( (weight $O1 $W1) + (weight $O2 $W2) + (< $W1 $W2))) +; + + + (= + (weight $O 5) + (isa $O endtable)) +; + + + + (= + (?- + (; + (, + (ebg + (save_to_stack o1 o2) $L) + (, + (write $L) fail)) true)) True) +; + + + diff --git a/foil/foil.metta b/foil/foil.metta new file mode 100644 index 0000000..81dbbda --- /dev/null +++ b/foil/foil.metta @@ -0,0 +1,787 @@ + + !(ensure-loaded (library occurs)) +; + + !(ensure-loaded (library basics)) +; + + !(ensure-loaded (library lists)) +; + + !(ensure-loaded (library between)) +; + + !(ensure-loaded (library math)) +; + + !(use-module + (library ordsets) + (:: (/ ord-add-element 3))) +; + + +; +; + +; +; + + + (= + (foil $Goal) + ( (foil $Goal $Clauses) + (format "~n~nFOUND DEFINITION:~n~n" Nil) + (portray-clauses $Clauses))) +; + + +; +; + + + (= + (portray-clauses Nil) + (nl)) +; + + (= + (portray-clauses (Cons $H $T)) + ( (portray-clause $H) (portray-clauses $T))) +; + + +; +; + + + (= + (foil-time $Goal) + ( (statistics runtime + (Cons $T0 $_)) + (foil $Goal) + (statistics runtime + (Cons $T1 $_)) + (is $T + (- $T1 $T0)) + (format "~nRun Time = ~3d sec.~n" + (:: $T)))) +; + + +; +; + +; +; + + + (= + (get-examples $Goal $Pos $Neg) + ( (findall $Goal + (with_self + (foil-input *) $Goal) $Pos) (create-negatives $Pos $Neg))) +; + + +; +; + +; +; + + + (= + (foil $Goal $Clauses) + ( (get-examples $Goal $Positives $Negatives) (foil-loop $Positives $Goal $Negatives Nil $Clauses))) +; + + +; +; + + (= + (foil $Goal $Negatives $Clauses) + ( (findall $Goal + (with_self + (foil-input *) $Goal) $Positives) (foil-loop $Positives $Goal $Negatives Nil $Clauses))) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (foil-loop $Pos $Goal $Neg $Clauses0 $Clauses) + (det-if-then-else + (= $Pos Nil) + (= $Clauses $Clauses0) + (, + (format "~nUncovered positives adding a clause~n~w~n" + (:: $Pos)) + (extend-clause-loop $Neg $Pos + (= $Goal True) $Clause) + (format "~n~nClause Found: ~n" Nil) + (portray-clause $Clause) + (uncovered-examples $Clause $Pos $Pos1) + (foil-loop $Pos1 $Goal $Neg + (Cons $Clause $Clauses0) $Clauses)))) +; + + +; +; + +; +; + + + (= + (extend-clause-loop $Nxs0 $Pxs0 $Clause0 $Clause) + (det-if-then-else + (= $Nxs0 Nil) + (= $Clause $Clause0) + (, + (format "~n Current Clause: ~w ~n --Specializing~n" + (:: $Clause0)) + (format "covered negatives~n~w~n" + (:: $Nxs0)) + (format "covered positives~n~w~n" + (:: $Pxs0)) + (generate-possible-extensions $Clause0 $Ls) + (info-value $Clause0 $Pxs0 $Nxs0 $Info) + (best-next-clause $Ls $Nxs0 $Pxs0 $Clause0 $Info 0 $Clause0 $Clause1) + (det-if-then-else + (== $Clause0 $Clause1) + (, + (foil-det-lit-bound $DLB) + (format "No Improvement -- Trying Determinate Literals~n" Nil) + (bounded-determinate-literals $DLB $Ls $Clause0 $Pxs0 $Nxs0 $Ds) + (det-if-then-else + (= $Ds Nil) + (, + (format "No Determinate Literals Found~n" Nil) + (covered-examples $Clause1 $Nxs0 $Nxs1) + (format "WARINING--clause covers negatives~n~w~n" + (:: $Nxs1)) + (= $Clause $Clause1)) + (, + (format "Adding Determinate Literals: ~w~n" + (:: $Ds)) + (add-literals $Ds $Clause0 $Clause2) + (covered-examples $Clause2 $Nxs0 $Nxs1) + (extend-clause-loop $Nxs1 $Pxs0 $Clause2 $Clause)))) + (, + (covered-examples $Clause1 $Pxs0 $Pxs1) + (covered-examples $Clause1 $Nxs0 $Nxs1) + (extend-clause-loop $Nxs1 $Pxs1 $Clause1 $Clause)))))) +; + + +; +; + +; +; + + + (= + (best_next_clause () $_ $_ $_ $_ $_ $Clause $Clause) True) +; + + (= + (best-next-clause + (Cons $L $Ls) $Nxs $Pxs $Clause $Info $Gain0 $Best0 $Best) + ( (add-literal $L $Clause $Best1) + (compute-gain $Nxs $Pxs $Info $Best1 $Gain1) + (det-if-then-else + (> $Gain1 $Gain0) + (best-next-clause $Ls $Nxs $Pxs $Clause $Info $Gain1 $Best1 $Best) + (det-if-then-else + (=:= $Gain1 $Gain0) + (, + (choose-tie-clause $Best0 $Best1 $Best2) + (best-next-clause $Ls $Nxs $Pxs $Clause $Info $Gain0 $Best2 $Best)) + (best-next-clause $Ls $Nxs $Pxs $Clause $Info $Gain0 $Best0 $Best))))) +; + + + + (= + (choose-tie-clause + (= $A1 $B1) + (= $A2 $B2) $C) + ( (variables-in $B1 $V1) + (length $V1 $N1) + (variables-in $B2 $V2) + (length $V2 $N2) + (det-if-then-else + (< $N2 $N1) + (= $C + (= $A2 $B2)) + (= $C + (= $A1 $B1))))) +; + + +; +; + +; +; + +; +; + + + (= + (compute-gain $Nxs $Pxs $Info $Clause $Gain) + ( (covered-examples $Clause $Pxs $Retained) + (length $Retained $R) + (det-if-then-else + (=:= $R 0) + (= $Gain 0) + (, + (info-value $Clause $Pxs $Nxs $Info1) + (is $Gain + (* $R + (- $Info $Info1))))))) +; + + +; +; + +; +; + + + (= + (info-value $Clause $Pxs $Nxs $Value) + ( (tuples $Clause $Pxs $Ptuples) + (length $Ptuples $P) + (det-if-then-else + (=:= $P 0) + (= $Value 0) + (, + (tuples $Clause $Nxs $Ntuples) + (length $Ntuples $N) + (is $Temp + (/ $P + (+ $P $N))) + (log $Temp $Temp1) + (is $Value + (* $Temp1 -1.442695)))))) +; + + +; +; + + + (= + (add-literal $L + (= $A $B) + (= $A $B1)) + (det-if-then-else + (= $B True) + (= $B1 $L) + (= $B1 + (, $B $L)))) +; + + + + (= + (add-literals $Ls $Clause0 $Clause) + (det-if-then-else + (= $Ls Nil) + (= $Clause $Clause0) + (, + (= $Ls + (Cons $L $Ls1)) + (add-literal $L $Clause0 $Clause1) + (add-literals $Ls1 $Clause1 $Clause)))) +; + + + +; +; + + + (= + (variables-in $A $Vs) + (variables-in $A Nil $Vs)) +; + + + (= + (variables-in $A $V0 $V) + ( (var $A) + (set-det) + (ord-add-element $V0 $A $V))) +; + + (= + (variables-in $A $V0 $V) + ( (ground $A) + (set-det) + (= $V $V0))) +; + + (= + (variables-in $Term $V0 $V) + ( (functor $Term $_ $N) (variables-in-args $N $Term $V0 $V))) +; + + + + (= + (variables-in-args $N $Term $V0 $V) + (det-if-then-else + (=:= $N 0) + (= $V $V0) + (, + (arg $N $Term $Arg) + (variables-in $Arg $V0 $V1) + (is $N1 + (- $N 1)) + (variables-in-args $N1 $Term $V1 $V)))) +; + + +; +; + +; +; + +; +; + + + (= + (tuples + (= $A $B) $Xs $Tuples) + ( (variables-in + (= $A $B) $Vars) + (variables-in $A $HeadVars) + (length $HeadVars $N1) + (length $Vars $N2) + (det-if-then-else + (=:= $N1 $N2) + (findall $Vars + (, + (member $A $Xs) + (not (not (with_self (foil-input *) $B)))) $Tuples) + (findall $Vars + (, + (member $A $Xs) + (with_self + (foil-input *) $B)) $Tuples)))) +; + + +; +; + + + (= + (covered-examples + (= $A $B) $Xs $Xs1) + (findall $A + (, + (member $A $Xs) + (not (not (with_self (foil-input *) $B)))) $Xs1)) +; + + +; +; + + + (= + (uncovered-examples + (= $A $B) $Xs $Xs1) + (findall $A + (, + (member $A $Xs) + (not (with_self (foil-input *) $B))) $Xs1)) +; + + +; +; + +; +; + + + + (= + (generate-possible-extensions + (= $A $B) $Extensions) + ( (variables-in + (= $A $B) $OldVars) (bagof $L (candidate-literal $A $OldVars $L) $Extensions))) +; + + + + (= + (possible_unification () () ()) True) +; + + (= + (possible-unification + (Cons $H $T) + (Cons $H $Result) + (Cons $H $Vars)) + (possible-unification $T $Result $Vars)) +; + + (= + (possible-unification + (Cons $H $T) + (Cons $H $T1) $Vs) + ( (possible-unification $T $T1 $Vs) + (member $V $Vs) + (= $H $V))) +; + + + + (= + (list-of-n-from $Elements $N $List0 $List) + (det-if-then-else + (is $N 0) + (= $List $List0) + (, + (is $N1 + (- $N 1)) + (member $E $Elements) + (list-of-n-from $Elements $N1 + (Cons $E $List0) $List)))) +; + + + + (= + (possible_new_vars true $_ ()) True) +; + + (= + (possible-new-vars False $N $L) + (length $L $N)) +; + + (= + (possible-new-vars False $N $L) + ( (> $N 0) + (is $N1 + (- $N 1)) + (possible-new-vars False $N1 $L))) +; + + + + (= + (bind-vars $Lit $Vars $Index) + (det-if-then-else + (= $Vars Nil) True + (, + (= $Vars + (Cons $H $T)) + (arg $Index $Lit $H) + (is $Index1 + (+ $Index 1)) + (bind-vars $Lit $T $Index1)))) +; + + + + (= + (recursion-check $G $Pred $Arity $Flag) + (det-if-then-else + (functor $G $Pred $Arity) + (= $Flag True) + (= $Flag False))) +; + + + + (= + (candidate-literal $Goal $OldVars $Lit) + ( (foil-predicates $Preds) + (member + (/ $Pred $Arity) $Preds) + (functor $L $Pred $Arity) + (recursion-check $Goal $Pred $Arity $RecursionFlag) + (is $MaxNewVars + (- $Arity 1)) + (possible-new-vars $RecursionFlag $MaxNewVars $NewVars) + (length $NewVars $NewVarPositions) + (is $OldVarPositions + (- $Arity $NewVarPositions)) + (list-of-n-from $OldVars $OldVarPositions Nil $OldVarSeq) + (recursion-safe $RecursionFlag $Goal $OldVarSeq) + (possible-unification $NewVars $NewVarSeq $_) + (subseq $VarSeq $OldVarSeq $NewVarSeq) + (bind-vars $L $VarSeq 1) + (or + (= $Lit $L) + (, + (foil-use-negations True) + (= $Lit + (not $L)))))) +; + + + + (= + (recursion-safe $RecursionFlag $Goal $OldVarSeq) + (det-if-then-else + (= $RecursionFlag True) + (not (, (numbervars $Goal 0 $_) (ground $OldVarSeq))) True)) +; + +; +; + +; +; + + + + (= + (create-universe $Universe) + (setof $Term + (term-of-ext-def $Term) $Universe)) +; + + + + (= + (term-of-ext-def $Term) + ( (foil-predicates $PredSpecs) + (member + (/ $Pred $Arity) $PredSpecs) + (functor $Goal $Pred $Arity) + (with_self + (foil-input *) $Goal) + (between 1 $Arity $ArgPos) + (arg $ArgPos $Goal $Term))) +; + + + + (= + (create-negatives + (Cons $P $Ps) $Negatives) + ( (functor $P $F $N) + (functor $Template $F $N) + (create-universe $Universe) + (setof $Template + (, + (arguments-are-members $Template $N $Universe) + (not (member $Template (Cons $P $Ps)))) $Negatives))) +; + + + + (= + (arguments-are-members $Term $N $Universe) + (det-if-then-else + (> $N 0) + (, + (arg $N $Term $Arg) + (member $Arg $Universe) + (is $N1 + (- $N 1)) + (arguments-are-members $Term $N1 $Universe)) True)) +; + + +; +; + +; +; + + + + (= + (determinate $L $Vars $PTuples $NTuples) + ( (binds-new-var $L $Vars) + (determ-cover $PTuples $L $Vars) + (determ-partial-cover $NTuples $L $Vars))) +; + + + + (= + (binds-new-var + (not $_) $_) + ( (set-det) (fail))) +; + + (= + (binds-new-var $L $Vars) + ( (variables-in $L $LVars) + (member $V $LVars) + (not (contains-var $V $Vars)) + (set-det))) +; + + + + (= + (determ_cover () $_ $_) True) +; + + (= + (determ-cover + (Cons $T $Ts) $Lit $Vars) + ( (findall $Lit + (, + (= $Vars $T) + (with_self + (foil-input *) $Lit)) + (:: $_)) (determ-cover $Ts $Lit $Vars))) +; + + + + (= + (determ_partial_cover () $_ $_) True) +; + + (= + (determ-partial-cover + (Cons $T $Ts) $Lit $Vars) + ( (findall $Lit + (, + (= $Vars $T) + (with_self + (foil-input *) $Lit)) $Xs) + (or + (= $Xs Nil) + (= $Xs + (:: $_))) + (determ-partial-cover $Ts $Lit $Vars))) +; + + + + (= + (determinate-literals1 $Cands $Body $Vars $PTuples $NTuples $DLits) + (bagof $X + (, + (member $X $Cands) + (determinate $X $Vars $PTuples $NTuples) + (not (, (numbervars $Vars 0 $_) (ante-memberchk $X $Body)))) $DLits)) +; + + + + (= + (determinate-literals $Cands $Clause $Pxs $Nxs $DLits) + ( (variables-in $Clause $Vars) + (tuples $Clause $Pxs $PTuples) + (tuples $Clause $Nxs $NTuples) + (= $Clause + (= $_ $Body)) + (determinate-literals1 $Cands $Body $Vars $PTuples $NTuples $DLits))) +; + + + + (= + (bounded-determinate-literals 0 $_ $_ $_ $_ Nil) + (set-det)) +; + + (= + (bounded-determinate-literals $Bound $Cands + (= $A $B) $Pxs $Nxs $DLits) + ( (determinate-literals $Cands + (= $A $B) $Pxs $Nxs $DLits0) (reachable-antes $Bound $A $DLits0 $DLits))) +; + + + + (= + (ante-memberchk $A $A) + (set-det)) +; + + (= + (ante-memberchk $A + (, $B $C)) + (det-if-then-else + (ante-memberchk $A $B) True + (ante-memberchk $A $C))) +; + + + + (= + (reachable-antes $Bound $H $Cands $Antes) + ( (variables-in $H $Vs) (expand-by-var-chain $Bound $Cands $Vs Nil $Antes))) +; + + + + (= + (expand-by-var-chain $Bound $Cands $Vars $As0 $As) + (det-if-then-else + (=:= $Bound 0) + (= $As $As0) + (, + (partition-on-vars $Cands $Vars $Haves $Havenots) + (det-if-then-else + (= $Haves Nil) + (= $As $As0) + (, + (append $As0 $Haves $As1) + (variables-in $As1 $Vars1) + (is $Bound1 + (- $Bound 1)) + (expand-by-var-chain $Bound1 $Havenots $Vars1 $As1 $As)))))) +; + + + + (= + (partition_on_vars () $_ () ()) True) +; + + (= + (partition-on-vars + (Cons $C $Cs) $Vars $Hs $Hnots) + ( (det-if-then-else + (, + (member $V $Vars) + (contains-var $V $C)) + (, + (= $Hs + (Cons $C $Hs1)) + (= $Hnots $Hnots1)) + (, + (= $Hs $Hs1) + (= $Hnots + (Cons $C $Hnots1)))) (partition-on-vars $Cs $Vars $Hs1 $Hnots1))) +; + + + + diff --git a/idt/idt1.metta b/idt/idt1.metta new file mode 100644 index 0000000..18a3da7 --- /dev/null +++ b/idt/idt1.metta @@ -0,0 +1,764 @@ + + !(dynamic (/ node 3)) +; + + !(dynamic (/ decision-tree 1)) +; + + !(dynamic (/ example 3)) +; + + !(dynamic (/ attributes 1)) +; + + !(dynamic (/ classes 1)) +; + + !(dynamic (/ current-node 1)) +; + +; (error +; (syntax_error operator_expected) +; (file idt/idt1.pl 69 17 3862)) + + !(dynamic (/ found 1)) +; + + +; +; + + + (= + (log $X $Y) + (is $Y + (log $X))) +; + + + + (= + (idt) + ( (repeat) + (nl) + (write 'Which file to use ? ') + (read $FileName) + (nl) + (initialize-kb) + (readfile $FileName) + (build-decision-tree) + (show-decision-tree) + (nl) + (write 'Quit (y/n) ? ') + (read y))) +; + + + + (= + (initialize-kb) + ( (abolish node 3) + (abolish decision-tree 1) + (abolish example 3) + (abolish attributes 1) + (abolish classes 1) + (abolish current-node 1) + (set-det))) +; + + + + (= + (readfile $FileName) + ( (concat $FileName .pl $File) + (see $File) + (repeat) + (read $Term) + (det-if-then-else + (= $Term end-of-file) + (, + (set-det) + (seen)) + (, + (add-symbol &self $Term) + (fail))))) +; + + + + (= + (build-decision-tree) + ( (generate-node-id $_) + (get-symbols &self + (= + (attributes $Attributes) true)) + (findbag $Ex + (get-symbols &self + (= + (example $Ex $_ $_) true)) $Exs) + (idt $Exs $Attributes $Node) + (add-symbol &self + (decision_tree $Node)) + (set-det))) +; + + + + (= + (generate-node-id $Y) + ( (get-symbols &self + (= + (current_node $X) true)) + (set-det) + (remove-symbol &self + (current_node $X)) + (is $Y + (+ $X 1)) + (add-symbol &self + (current_node $Y)))) +; + + (= + (generate-node-id 0) + (add-symbol &self + (current_node 0))) +; + + + + (= + (idt () $_ ()) True) +; + + (= + (idt $Exs $_ + (:: (leaf $Class))) + (termination-criterion $Exs $Class)) +; + + (= + (idt $Exs $Attributes $ID) + ( (get-best-attribute $Attributes $Exs $BestAttribute) + (split-values $BestAttribute $Exs $DividedValues) + (delete $BestAttribute $Attributes $NewAttributes) + (generate-subtrees $DividedValues $NewAttributes $SubtreeIDs) + (generate-node-id $ID) + (add-symbol &self + (node $ID $BestAttribute $SubtreeIDs)))) +; + + + + (= + (termination-criterion + (Cons $Ex $Exs) $Class) + ( (get-symbols &self + (= + (example $Ex $Class $_) true)) + (set-det) + (all-in-same-class $Exs $Class))) +; + + + + (= + (all_in_same_class () $_) True) +; + + (= + (all-in-same-class + (Cons $Ex $Exs) $C) + ( (get-symbols &self + (= + (example $Ex $C $_) true)) + (set-det) + (all-in-same-class $Exs $C))) +; + + + + (= + (get-best-attribute $Attributes $Exs $BestAttribute) + ( (construct-contingency-table $Attributes $Exs) + (common-calculations $MC $N) + (calculate-parameter-classification $Attributes $MC $N $Values) + (get-best $Attributes $Values $BestAttribute))) +; + + + + (= + (construct-contingency-table $Attributes $Exs) + ( (get-symbols &self + (= + (classes $Lc) true)) + (length $Lc $NroColTab) + (abolish table 3) + (create-list-of-zeros $NroColTab $List) + (initialize-contingency-tables $Attributes $List) + (construct-contingency-tables $Attributes $Exs))) +; + + + + (= + (initialize_contingency_tables () $_) True) +; + + (= + (initialize-contingency-tables + (Cons $A $As) $List) + ( (add-symbol &self + (table $A () $List)) (initialize-contingency-tables $As $List))) +; + + + + (= + (create_list_of_zeros 0 ()) True) +; + + (= + (create-list-of-zeros $N + (Cons 0 $R)) + ( (> $N 0) + (is $N1 + (- $N 1)) + (create-list-of-zeros $N1 $R))) +; + + + + (= + (construct_contingency_tables () $_) True) +; + + (= + (construct-contingency-tables + (Cons $Attribute $Attributes) $ExampleList) + ( (contingency-table $Attribute $ExampleList) + (set-det) + (construct-contingency-tables $Attributes $ExampleList))) +; + + + + (= + (contingency_table $_ ()) True) +; + + (= + (contingency-table $Attribute + (Cons $Ex $Exs)) + ( (value $Attribute $Ex $V) + (position-of-class $Ex $Pc) + (update-table $Attribute $V $Pc) + (set-det) + (contingency-table $Attribute $Exs))) +; + + + + (= + (value $A + (Cons + (= $A $V) $_) $V) + (set-det)) +; + + (= + (value $A + (Cons $_ $Sels) $V) + (value $A $Sels $V)) +; + + (= + (value $A $No $V) + ( (get-symbols &self + (= + (example $No $_ $Ex) true)) (value $A $Ex $V))) +; + + + + (= + (position-of-class $Ex $Pc) + ( (get-symbols &self + (= + (example $Ex $C $_) true)) + (get-symbols &self + (= + (classes $Classes) true)) + (position $C $Classes $Pc))) +; + + + + (= + (position $X $L $P) + (position $X 1 $L $P)) +; + + + (= + (position $X $P + (Cons $X $_) $P) True) +; + + (= + (position $X $N + (Cons $_ $R) $P) + ( (is $N1 + (+ $N 1)) (position $X $N1 $R $P))) +; + + + + (= + (update-table $Attribute $V $Pc) + ( (remove-symbol &self + (table $Attribute $TabLines $TotClass)) + (modify-table $TabLines $V $Pc $NewLines) + (increment-position-list 1 $Pc $TotClass $NewTotal) + (add-symbol &self + (table $Attribute $NewLines $NewTotal)))) +; + + + + (= + (modify-table Nil $V $Pc + (:: (, $V $Values 1))) + ( (get-symbols &self + (= + (classes $Classes) true)) + (length $Classes $NoOfColums) + (create-list-of-zeros $NoOfColums $L) + (increment-position-list 1 $Pc $L $Values))) +; + + (= + (modify-table + (Cons + (, $V $Nums $Tot) $Rest) $V $Pc + (Cons + (, $V $NewNums $NewTot) $Rest)) + ( (is $NewTot + (+ $Tot 1)) (increment-position-list 1 $Pc $Nums $NewNums))) +; + + (= + (modify-table + (Cons $X $Rest1) $V $Pc + (Cons $X $Rest2)) + (modify-table $Rest1 $V $Pc $Rest2)) +; + + + + (= + (increment-position-list $N $N + (Cons $X $R) + (Cons $Y $R)) + (is $Y + (+ $X 1))) +; + + (= + (increment-position-list $N1 $N + (Cons $X $R1) + (Cons $X $R2)) + ( (is $N2 + (+ $N1 1)) (increment-position-list $N2 $N $R1 $R2))) +; + + + + (= + (common-calculations $MC $N) + ( (get-symbols &self + (= + (table $_ $_ $Xjs) true)) (common-calculations $Xjs 0 0 $MC $N))) +; + + + (= + (common-calculations Nil $TotalSum $N $MC $N) + ( (log $N $NLog) (is $MC (* (/ -1 $N) (- $TotalSum (* $N $NLog)))))) +; + + (= + (common-calculations + (:: 0) $S $N $S $N) + (set-det)) +; + + (= + (common-calculations + (Cons $Xj $Xjs) $Ac1 $Ac2 $MC $N) + ( (log $Xj $XjLog) + (is $NAc1 + (+ $Ac1 + (* $Xj $XjLog))) + (is $NAc2 + (+ $Ac2 $Xj)) + (common-calculations $Xjs $NAc1 $NAc2 $MC $N))) +; + + + + (= + (calculate_parameter_classification () $_ $_ ()) True) +; + + (= + (calculate-parameter-classification + (Cons $A $As) $MC $N + (Cons $V $Vs)) + ( (gain-ratio $A $MC $N $V) (calculate-parameter-classification $As $MC $N $Vs))) +; + + + + (= + (gain-ratio $A $MC $N $GR) + ( (get-symbols &self + (= + (table $A $Lines $_) true)) + (calculate-factors-B-and-IV $Lines $N 0 0 $B $IV) + (is $IM + (- $MC $B)) + (det-if-then-else + (> $IV 0) + (is $GR + (/ $IM $IV)) + (= $GR 1)))) +; + + + + (= + (calculate-factors-B-and-IV Nil $N $Sum1 $Sum2 $B $IV) + ( (log $N $NLog) + (is $B + (* + (/ -1 $N) + (- $Sum1 $Sum2))) + (is $IV + (* + (/ -1 $N) + (- $Sum2 + (* $N $NLog)))))) +; + + (= + (calculate-factors-B-and-IV + (Cons + (, $_ $L $TotL) $Rest) $N $Ac1 $Ac2 $B $IV) + ( (sum-of-lines $L 0 $SL) + (log $TotL $TotLog) + (is $NAc1 + (+ $Ac1 $SL)) + (is $NAc2 + (+ $Ac2 + (* $TotL $TotLog))) + (calculate-factors-B-and-IV $Rest $N $NAc1 $NAc2 $B $IV))) +; + + + + (= + (sum_of_lines () $X $X) True) +; + + (= + (sum-of-lines + (Cons 0 $Ns) $Ac $Tot) + (sum-of-lines $Ns $Ac $Tot)) +; + + (= + (sum-of-lines + (Cons $N $Ns) $Ac $Tot) + ( (log $N $NLog) + (is $Nac + (+ $Ac + (* $N $NLog))) + (sum-of-lines $Ns $Nac $Tot))) +; + + + + (= + (get-best + (Cons $A $As) + (Cons $V $Vs) $Result) + (best-value $As $Vs + (, $A $V) $Result)) +; + + + + (= + (best_value () () + (, $A $_) $A) True) +; + + (= + (best-value + (Cons $A $As) + (Cons $V $Vs) + (, $_ $TV) $Result) + ( (> $V $TV) (best-value $As $Vs (, $A $V) $Result))) +; + + (= + (best-value + (Cons $_ $As) + (Cons $_ $Vs) + (, $TA $TV) $Result) + (best-value $As $Vs + (, $TA $TV) $Result)) +; + + + + (= + (split-values $Attribute $Exs $Result) + ( (get-values $Attribute $Exs $Values) (split-examples $Attribute $Values $Exs $Result))) +; + + + + (= + (get-values $Attribute $Exs $Vals) + ( (findbag $V + (, + (member $Ex $Exs) + (value $Attribute $Ex $V)) $Vs) (remove-duplicates $Vs $Vals))) +; + + + + (= + (split_examples $_ + ($V) $Exs + ( (, $V $Exs))) True) +; + + (= + (split-examples $A + (Cons $V $Vs) $Exs + (Cons + (, $V $VExs) $Rest)) + ( (findbag $Ex + (, + (member $Ex $Exs) + (value $A $Ex $V)) $VExs) + (difference $VExs $Exs $RestEx) + (split-examples $A $Vs $RestEx $Rest))) +; + + + + (= + (generate_subtrees () $_ ()) True) +; + + (= + (generate-subtrees + (Cons + (, $Value $Exs) $Rest1) $Attributes + (Cons + (, $Value $Id) $Rest2)) + ( (idt $Exs $Attributes $Id) + (set-det) + (generate-subtrees $Rest1 $Attributes $Rest2))) +; + + + + (= + (show-decision-tree) + ( (nl) + (get-symbols &self + (= + (decision_tree $Node) true)) + (show-subtree $Node 0) + (set-det))) +; + + + + (= + (show-subtree $NodeNo $Indent) + ( (get-symbols &self + (= + (node $NodeNo $Attribute $SubtreeList) true)) (show-subtrees $SubtreeList $Attribute $Indent))) +; + + + + (= + (show-subtrees Nil $_ $_) + (nl)) +; + + (= + (show-subtrees + (Cons + (, $Value + (leaf $X)) $Brothers) $Attribute $Indent) + ( (write (= $Attribute $Value)) + (write ' ') + (write ==> ) + (write (= class $X)) + (nl) + (space $Indent) + (show-subtrees $Brothers $Attribute $Indent))) +; + + (= + (show-subtrees + (Cons + (, $Value $NodeNo) $Brothers) $Attribute $Indent) + ( (name $Attribute $List1) + (length $List1 $N1) + (name $Value $List2) + (length $List2 $N2) + (write (= $Attribute $Value)) + (write ' and ') + (is $Offset + (+ + (+ + (+ + (+ $Indent $N1) 3) $N2) 5)) + (show-subtree $NodeNo $Offset) + (space $Indent) + (show-subtrees $Brothers $Attribute $Indent))) +; + + + + (= + (space 0) True) +; + + (= + (space $N) + ( (> $N 0) + (write ' ') + (is $N1 + (- $N 1)) + (space $N1))) +; + + + + (= + (remove_duplicates () ()) True) +; + + (= + (remove-duplicates + (Cons $X $Xs) $Ys) + ( (member $X $Xs) (remove-duplicates $Xs $Ys))) +; + + (= + (remove-duplicates + (Cons $X $Xs) + (Cons $X $Ys)) + (remove-duplicates $Xs $Ys)) +; + + +; +; + +; +; + +; +; + +; +; + + + + (= + (delete $X + (Cons $X $Xs) $Xs) True) +; + + (= + (delete $X + (Cons $Y $Ys) + (Cons $Y $Zs)) + (delete $X $Ys $Zs)) +; + + + + (= + (difference $L1 $L2 $L3) + (findbag $N + (, + (member $N $L2) + (not (member $N $L1))) $L3)) +; + + + + (= + (findbag $X $G $_) + ( (add-symbol &self + (found mark)) + (call $G) + (add-symbol &self + (found $X)) + (fail))) +; + + (= + (findbag $_ $_ $L) + (collect-found Nil $L)) +; + + + + (= + (collect-found $L $L1) + ( (getnext $X) (collect-found (Cons $X $L) $L1))) +; + + (= + (collect_found $L $L) True) +; + + + + (= + (getnext $X) + ( (remove-symbol &self + (found $X)) + (set-det) + (not (== $X mark)))) +; + + + + (= + (help) + ( (write 'Start IDT with command: idt.') (nl))) +; + + + + !(help *) +; + + + + diff --git a/idt/idt1_1.metta b/idt/idt1_1.metta new file mode 100644 index 0000000..bf8fabc --- /dev/null +++ b/idt/idt1_1.metta @@ -0,0 +1,64 @@ + + (= + (classes + (x y)) True) +; + + + (= + (attributes + (a b c)) True) +; + + + (= + (example 1 x + ( (= a 1) + (= b 1) + (= c 1))) True) +; + + (= + (example 2 y + ( (= a 1) + (= b 2) + (= c 2))) True) +; + + (= + (example 3 y + ( (= a 2) + (= b 3) + (= c 2))) True) +; + + (= + (example 4 x + ( (= a 2) + (= b 3) + (= c 1))) True) +; + + (= + (example 5 y + ( (= a 1) + (= b 2) + (= c 2))) True) +; + + (= + (example 6 x + ( (= a 1) + (= b 1) + (= c 2))) True) +; + + (= + (example 7 x + ( (= a 1) + (= b 1) + (= c 1))) True) +; + + + diff --git a/idt/idt1_2.metta b/idt/idt1_2.metta new file mode 100644 index 0000000..835068b --- /dev/null +++ b/idt/idt1_2.metta @@ -0,0 +1,79 @@ + + (= + (classes + (accept reject)) True) +; + + + (= + (attributes + (account cash employed credits)) True) +; + + + (= + (example 1 accept + ( (= account bank) + (= cash 700) + (= employed yes) + (= credits 200))) True) +; + + (= + (example 2 reject + ( (= account bank) + (= cash 300) + (= employed yes) + (= credits 600))) True) +; + + (= + (example 3 reject + ( (= account none) + (= cash 0) + (= employed yes) + (= credits 400))) True) +; + + (= + (example 4 accept + ( (= account others) + (= cash 1200) + (= employed yes) + (= credits 600))) True) +; + + (= + (example 5 reject + ( (= account others) + (= cash 800) + (= employed yes) + (= credits 600))) True) +; + + (= + (example 6 accept + ( (= account others) + (= cash 1600) + (= employed yes) + (= credits 200))) True) +; + + (= + (example 7 accept + ( (= account bank) + (= cash 3000) + (= employed no) + (= credits 300))) True) +; + + (= + (example 8 reject + ( (= account none) + (= cash 0) + (= employed no) + (= credits 200))) True) +; + + + diff --git a/idt/idt1_3.metta b/idt/idt1_3.metta new file mode 100644 index 0000000..13bbd06 --- /dev/null +++ b/idt/idt1_3.metta @@ -0,0 +1,98 @@ + + (= + (classes + (accept reject)) True) +; + + + (= + (attributes + (account cash employed)) True) +; + + + (= + (example 1 accept + ( (= account bank) + (= employed yes) + (= cash 300))) True) +; + + (= + (example 2 accept + ( (= account bank) + (= employed yes) + (= cash 300))) True) +; + + (= + (example 3 reject + ( (= account bank) + (= employed no) + (= cash 300))) True) +; + + (= + (example 4 accept + ( (= account bank) + (= employed no) + (= cash 4000))) True) +; + + (= + (example 5 accept + ( (= account none) + (= employed yes) + (= cash 4000))) True) +; + + (= + (example 6 reject + ( (= account none) + (= employed yes) + (= cash 300))) True) +; + + (= + (example 7 reject + ( (= account none) + (= employed no) + (= cash 300))) True) +; + + (= + (example 8 reject + ( (= account none) + (= employed no) + (= cash 4000))) True) +; + + (= + (example 9 reject + ( (= account none) + (= employed no) + (= cash 4000))) True) +; + + (= + (example 10 reject + ( (= account others) + (= employed no) + (= cash 300))) True) +; + + (= + (example 11 accept + ( (= account others) + (= employed no) + (= cash 4000))) True) +; + + (= + (example 12 reject + ( (= account others) + (= employed no) + (= cash 300))) True) +; + + diff --git a/idt/idt1_4.metta b/idt/idt1_4.metta new file mode 100644 index 0000000..adcaebc --- /dev/null +++ b/idt/idt1_4.metta @@ -0,0 +1,98 @@ + + (= + (classes + (accept reject ask)) True) +; + + + (= + (attributes + (account cash employed)) True) +; + + + (= + (example 1 accept + ( (= account bank) + (= employed yes) + (= cash 300))) True) +; + + (= + (example 2 accept + ( (= account bank) + (= employed yes) + (= cash 300))) True) +; + + (= + (example 3 accept + ( (= account bank) + (= employed no) + (= cash 300))) True) +; + + (= + (example 4 accept + ( (= account bank) + (= employed no) + (= cash 4000))) True) +; + + (= + (example 5 accept + ( (= account none) + (= employed yes) + (= cash 4000))) True) +; + + (= + (example 6 reject + ( (= account none) + (= employed yes) + (= cash 300))) True) +; + + (= + (example 7 reject + ( (= account none) + (= employed no) + (= cash 300))) True) +; + + (= + (example 8 reject + ( (= account none) + (= employed no) + (= cash 4000))) True) +; + + (= + (example 9 reject + ( (= account none) + (= employed no) + (= cash 4000))) True) +; + + (= + (example 10 ask + ( (= account others) + (= employed no) + (= cash 300))) True) +; + + (= + (example 11 ask + ( (= account others) + (= employed no) + (= cash 4000))) True) +; + + (= + (example 12 ask + ( (= account others) + (= employed no) + (= cash 300))) True) +; + + diff --git a/idt/idt1_5.metta b/idt/idt1_5.metta new file mode 100644 index 0000000..3457108 --- /dev/null +++ b/idt/idt1_5.metta @@ -0,0 +1,94 @@ + + (= + (classes + (yes no)) True) +; + + + (= + (attributes + (season weather temp work)) True) +; + + + (= + (example 1 yes + ( (= season spring) + (= weather sunny) + (= temp warm) + (= work few))) True) +; + + (= + (example 2 yes + ( (= season summer) + (= weather cloudy) + (= temp hot) + (= work few))) True) +; + + (= + (example 3 no + ( (= season summer) + (= weather rain) + (= temp cold) + (= work few))) True) +; + + (= + (example 4 yes + ( (= season winter) + (= weather cloudy) + (= temp cold) + (= work plenty))) True) +; + + (= + (example 5 no + ( (= season winter) + (= weather cloudy) + (= temp cold) + (= work few))) True) +; + + (= + (example 6 yes + ( (= season autumn) + (= weather sunny) + (= temp hot) + (= work plenty))) True) +; + + (= + (example 7 yes + ( (= season winter) + (= weather sunny) + (= temp warm) + (= work few))) True) +; + + (= + (example 8 no + ( (= season autumn) + (= weather cloudy) + (= temp warm) + (= work few))) True) +; + + (= + (example 9 no + ( (= season summer) + (= weather cloudy) + (= temp hot) + (= work plenty))) True) +; + + (= + (example 10 no + ( (= season winter) + (= weather cloudy) + (= temp hot) + (= work few))) True) +; + + diff --git a/idt/idt1_6.metta b/idt/idt1_6.metta new file mode 100644 index 0000000..451c690 --- /dev/null +++ b/idt/idt1_6.metta @@ -0,0 +1,127 @@ + + (= + (classes + (n p)) True) +; + + + (= + (attributes + (outlook temperature humidity windy)) True) +; + + + (= + (example 1 n + ( (= outlook sunny) + (= temperature hot) + (= humidity high) + (= windy false))) True) +; + + (= + (example 2 n + ( (= outlook sunny) + (= temperature hot) + (= humidity high) + (= windy true))) True) +; + + (= + (example 3 p + ( (= outlook overcast) + (= temperature hot) + (= humidity high) + (= windy false))) True) +; + + (= + (example 4 p + ( (= outlook rain) + (= temperature mild) + (= humidity high) + (= windy false))) True) +; + + (= + (example 5 p + ( (= outlook rain) + (= temperature cool) + (= humidity normal) + (= windy false))) True) +; + + (= + (example 6 n + ( (= outlook rain) + (= temperature cool) + (= humidity normal) + (= windy true))) True) +; + + (= + (example 7 p + ( (= outlook overcast) + (= temperature cool) + (= humidity normal) + (= windy true))) True) +; + + (= + (example 8 n + ( (= outlook sunny) + (= temperature mild) + (= humidity high) + (= windy false))) True) +; + + (= + (example 9 p + ( (= outlook sunny) + (= temperature cool) + (= humidity normal) + (= windy false))) True) +; + + (= + (example 10 p + ( (= outlook rain) + (= temperature mild) + (= humidity normal) + (= windy false))) True) +; + + (= + (example 11 p + ( (= outlook sunny) + (= temperature mild) + (= humidity normal) + (= windy true))) True) +; + + (= + (example 12 p + ( (= outlook overcast) + (= temperature mild) + (= humidity high) + (= windy true))) True) +; + + (= + (example 13 p + ( (= outlook overcast) + (= temperature hot) + (= humidity normal) + (= windy false))) True) +; + + (= + (example 14 n + ( (= outlook rain) + (= temperature mild) + (= humidity high) + (= windy true))) True) +; + + + diff --git a/index/char.metta b/index/char.metta new file mode 100644 index 0000000..d9d1bd2 --- /dev/null +++ b/index/char.metta @@ -0,0 +1,277 @@ + + (= + (char $InICs $PosIn $NegIn $OutICs $PosOut $NegOut) + ( (char1 $InICs $PosIn $NegIn Nil $TmpICs $PosOut $NegOut) (cleanup $TmpICs Nil $OutICs))) +; + + + + (= + (char1 () $P $N $Out $Out $P $N) True) +; + + (= + (char1 + (Cons $IC $ICs) $P0 $N0 $Acc $Out $P $N) + ( (write-debug (:: 'evaluating ' $IC)) + (evaluate $P0 $N0 $IC $Tuples $P1 $N1 $Answer) + (det-if-then-else + (= $Answer refine) + (, + (refinements $IC $Tuples $Spec) + (append $ICs $Spec $NewICs) + (= $NewAcc $Acc)) + (det-if-then-else + (= $Answer keep) + (, + (= $NewICs $ICs) + (= $NewAcc + (Cons $IC $Acc))) + (det-if-then-else + (= $Answer + (ignore $E)) + (, + (= $NewICs $ICs) + (= $NewAcc $Acc)) + (det-if-then + (= $Answer + (keep $E)) + (, + (= $NewICs $ICs) + (insert-ic $Acc $IC $E $NewAcc)))))) + (write-debug (:: ' result: ' $Answer)) + (set-det) + (char1 $NewICs $P1 $N1 $NewAcc $Out $P $N))) +; + + + + (= + (evaluate $P0 $N0 $IC $Tuples $P $N $Answer) + (det-if-then-else + (evaluate1 $P0 $IC $Answer) + (, + (= $P $P0) + (= $N $N0) + (= $Tuples Nil)) + (det-if-then otherwise + (, + (contr $P0 $N0 $IC $T $A) + (det-if-then-else + (= $A yes) + (, + (= $Answer refine) + (= $P $P0) + (= $N $N0) + (= $Tuples $T)) + (det-if-then-else + (= $A no) + (, + (= $Answer keep) + (= $P $P0) + (= $N $N0) + (= $Tuples $T)) + (det-if-then + (= $A possibly) + (, + (queries $P0 $N0 $T $P1 $N1) + (evaluate $P1 $N1 $IC $Tuples $P $N $Answer))))))))) +; + + + + (= + (contr $P $N $IC $Tuples $Answer) + ( (horn $IC $HornIC) (incons $HornIC $P $N $Tuples $Answer))) +; + + + + (= + (queries $P $N () $P $N) True) +; + + (= + (queries $P $N + (Cons $T $Ts) $P1 $N1) + ( (query $P $N $T $P2 $N2) (queries $P2 $N2 $Ts $P1 $N1))) +; + + +; (error +; (syntax_error operator_expected) +; (file index/char.pl 41 4 1180)) + +; (error +; (syntax_error operator_expected) +; (file index/char.pl 43 4 1267)) + + + (= + (query $P $N + (- $T) $P + (Cons $T $N)) + ( (switched-on cwa) + (write (- $T)) + (nl))) +; + + (= + (query $P $N + (+ $T) $P $N) True) +; + + + + (= + (cleanup + (Cons $X $In) $Acc $Out) + ( (member $IC $In) + (subsumed $X $IC) + (set-det) + (cleanup $In $Acc $Out))) +; + + (= + (cleanup + (Cons $X $In) $Acc $Out) + ( (member $IC $Acc) + (subsumed $X $IC) + (set-det) + (cleanup $In $Acc $Out))) +; + + (= + (cleanup + (Cons $X $In) $Acc $Out) + (cleanup $In + (Cons $X $Acc) $Out)) +; + + (= + (cleanup () $Out $Out) True) +; + + + + (= + (incons + (= $Head $Body) $P $N $Tuples $Answer) + ( (satisfied $Body $P $N $TuplesB) + (falsified $Head $P $N $TuplesH) + (set-det) + (= $Answer yes) + (append $TuplesB $TuplesH $Tuples))) +; + + (= + (incons + (= $Head $Body) $P $N $Tuples $Answer) + ( (satisfied $Body $P $N $TuplesB) + (unsatisfied $Head $P $N $TuplesH) + (set-det) + (= $Answer possibly) + (append $TuplesB $TuplesH $Tuples))) +; + + (= + (incons + (= $Head $Body) $P $N Nil $Answer) + (= $Answer no)) +; + + + + (= + (satisfied + (, $A $B) $P $N $Tuples) + ( (satisfied $A $P $N $TuplesA) + (satisfied $B $P $N $TuplesB) + (append $TuplesA $TuplesB $Tuples))) +; + + (= + (satisfied + (or $A $B) $P $N $Tuples) + (or + (satisfied $A $P $N $Tuples) + (satisfied $B $P $N $Tuples))) +; + + (= + (satisfied $A $P $N + (:: (+ $A))) + (member $A $P)) +; + + (= + (satisfied + (= $A $A) $P $N ()) True) +; + ; +; + + (= + (satisfied $A $P $N Nil) + ( (proc $Rel $Proc) (exec-proc $A $Proc))) +; + + + + (= + (exec-proc $Goal + (, $P1 $P2)) + (or + (exec-proc $Goal $P1) + (exec-proc $Goal $P2))) +; + + (= + (exec-proc $Goal + (= $Goal $Body)) + (call $Body)) +; + + + + (= + (falsified + (, $A $B) $P $N $Tuples) + (or + (, + (set-det) + (falsified $A $P $N $Tuples)) + (falsified $B $P $N $Tuples))) +; + + (= + (falsified $A $P $N + (:: (- $A))) + (member $A $N)) +; + + (= + (falsified + (= $A $B) $P $N Nil) + (\= $A $B)) +; + + + + (= + (unsatisfied + (, $A $B) $P $N $Tuples) + (or + (, + (set-det) + (unsatisfied $A $P $N $Tuples)) + (unsatisfied $B $P $N $Tuples))) +; + + (= + (unsatisfied $A $P $N + (:: (- $A))) + ( (not (satisfied $A $P $N $_)) (not (falsified $A $P $N $_)))) +; + + diff --git a/index/commands.metta b/index/commands.metta new file mode 100644 index 0000000..3d070be --- /dev/null +++ b/index/commands.metta @@ -0,0 +1,728 @@ + + (= + (keyword1 save ' save in Prolog database') True) +; + + (= + (keyword1 get ' get from Prolog database') True) +; + + (= + (keyword1 show ' show current') True) +; + + (= + (keyword1 count ' count current') True) +; + + (= + (keyword1 del ' delete') True) +; + + (= + (keyword1 add ' add new') True) +; + + (= + (keyword1 init ' initialise constraints') True) +; + + (= + (keyword1 find ' find constraints') True) +; + + (= + (keyword1 check ' check validity') True) +; + + (= + (keyword1 decomp ' decompose relation') True) +; + + (= + (keyword1 comp ' compose relations') True) +; + + (= + (keyword1 switch ' switch on or off') True) +; + + (= + (keyword1 set ' set level') True) +; + + (= + (keyword1 help ' get help') True) +; + + + + (= + (keyword2 pos ' positive tuples') True) +; + + (= + (keyword2 neg ' negative tuples') True) +; + + (= + (keyword2 ics ' integrity constraints') True) +; + + (= + (keyword2 calc ' calculated relations') True) +; + + + + (= + (switch cwa ' Closed-World Assumption') True) +; + + (= + (switch horn ' display in Horn form') True) +; + + (= + (switch eval ' evaluate constraints') True) +; + + (= + (switch debug ' show debugging information') True) +; + + + + (= + (level conf ' confirmation level of constraint') True) +; + + (= + (level acc ' accuracy of constraint') True) +; + + (= + (level split ' splitting level of constraint') True) +; + + + + !(forall + (^ $T + (keyword1 $W $T)) + (op 1200 fx $W)) +; + + !(forall + (^ $T + (keyword2 $W $T)) + (op 1100 fx $W)) +; + + !(forall + (^ $T + (level $W $T)) + (op 1100 fx $W)) +; + + + + (= + (commands $InICs $PosIn $NegIn) + ( (prompt-read '' $Command) + (do-command $Command $InICs $PosIn $NegIn $OutICs $PosOut $NegOut) + (set-det) + (commands $OutICs $PosOut $NegOut))) +; + + (= + (commands $InICs $PosIn $NegIn) + ( (write no) + (nl) + (set-det) + (commands $InICs $PosIn $NegIn))) +; + + + + (= + (do-command + (save $X) $ICs $Pos $Neg $ICs $Pos $Neg) + ( (set-det) (save-command $X $ICs $Pos $Neg))) +; + + (= + (do-command + (get $X) $InICs $PosIn $NegIn $OutICs $PosOut $NegOut) + ( (set-det) (get-command $X $InICs $PosIn $NegIn $OutICs $PosOut $NegOut))) +; + + (= + (do-command + (show $X) $ICs $Pos $Neg $ICs $Pos $Neg) + ( (set-det) (show-command $X $ICs $Pos $Neg))) +; + + (= + (do-command + (count $X) $ICs $Pos $Neg $ICs $Pos $Neg) + ( (set-det) (count-command $X $ICs $Pos $Neg))) +; + + (= + (do-command + (del $X) $InICs $PosIn $NegIn $OutICs $PosOut $NegOut) + ( (set-det) (del-command $X $InICs $PosIn $NegIn $OutICs $PosOut $NegOut))) +; + + (= + (do-command + (add $X) $InICs $PosIn $NegIn $OutICs $PosOut $NegOut) + ( (set-det) (add-command $X $InICs $PosIn $NegIn $OutICs $PosOut $NegOut))) +; + + (= + (do-command + (init $X) $InICs $Pos $Neg $OutICs $Pos $Neg) + ( (set-det) (init-command $X $InICs $OutICs))) +; + + (= + (do-command + (find $X) $InICs $PosIn $NegIn $OutICs $PosOut $NegOut) + ( (set-det) (find-command $X $InICs $PosIn $NegIn $OutICs $PosOut $NegOut))) +; + + (= + (do-command + (check $X) $ICs $Pos $Neg $ICs $Pos $Neg) + ( (set-det) (check-command $X $ICs $Pos $Neg))) +; + + (= + (do-command + (decomp $IC) $InICs $PosIn $Neg $OutICs $PosOut $Neg) + ( (set-det) (decompose $IC $PosIn $PosOut $InICs $OutICs))) +; + + (= + (do-command + (comp $Rule) $ICs $PosIn $Neg $ICs $PosOut $Neg) + ( (set-det) + (exec-rule $Rule $PosIn $PosNew) + (append $PosIn $PosNew $PosOut))) +; + + (= + (do-command + (switch $X) $ICs $Pos $Neg $ICs $Pos $Neg) + ( (set-det) (switch $X))) +; + + (= + (do-command + (set $X) $ICs $Pos $Neg $ICs $Pos $Neg) + ( (set-det) (set $X))) +; + + (= + (do-command + (help $Topic) $ICs $Pos $Neg $ICs $Pos $Neg) + ( (set-det) (help-command $Topic))) +; + + (= + (do-command $Command $ICs $Pos $Neg $ICs $Pos $Neg) + (call $Command)) +; + + (= + (do-command $Command $ICs $Pos $Neg $ICs $Pos $Neg) + (write ?)) +; + + + + (= + (save-command + (pos $Rel) $ICs $Pos $Neg) + (save-pos $Rel $Pos)) +; + + (= + (save-command + (neg $Rel) $ICs $Pos $Neg) + (save-neg $Rel $Neg)) +; + + (= + (save-command + (ics $T) $ICs $Pos $Neg) + (save-ics $T $ICs)) +; + + + + (= + (get-command + (pos $Rel) $ICs $PosIn $Neg $ICs $PosOut $Neg) + ( (get-pos $Rel $Pos) (append $PosIn $Pos $PosOut))) +; + + (= + (get-command + (neg $Rel) $ICs $Pos $NegIn $ICs $Pos $NegOut) + ( (get-neg $Rel $Neg) (append $NegIn $Neg $NegOut))) +; + + (= + (get-command + (ics $T) $InICs $Pos $Neg $OutICs $Pos $Neg) + ( (get-ics $T $ICs) (append $InICs $ICs $OutICs))) +; + + + + (= + (show-command all $ICs $Pos $Neg) + ( (set-det) + (show-list 'positive tuples' $Pos) + (show-list 'negative tuples' $Neg) + (show-list 'integrity constraints' $ICs))) +; + + (= + (show-command rel $ICs $Pos $Neg) + ( (set-det) + (bagof0 $R + (^ $A + (rel $R $A)) $Rels) + (show-list relations $Rels))) +; + + (= + (show-command $Other $ICs $Pos $Neg) + ( (get-list $Other $ICs $Pos $Neg $List $Text) + (set-det) + (show-list $Text $List))) +; + + (= + (show-command $Wrong $ICs $Pos $Neg) + (show-list choices + (:: 'show all' 'show rel' 'show pos all' 'show pos Rel' 'show neg all' 'show neg Rel' 'show ics all' 'show ics Rel'))) +; + + + + (= + (count-command $Filter $ICs $Pos $Neg) + ( (get-list $Filter $ICs $Pos $Neg $List $Text) + (length $List $N) + (write-list (:: 'There are ' $N ' ' $Text .)) + (nl))) +; + + + + (= + (del_command all $ICs $Pos $Neg () () ()) True) +; + + (= + (del-command + (ics $F) $InICs $Pos $Neg $OutICs $Pos $Neg) + (filter $InICs $F $Deleted $OutICs)) +; + + (= + (del-command + (pos $Rel) $ICs $PosIn $Neg $ICs $PosOut $Neg) + (filter $PosIn $Rel $Deleted $PosOut)) +; + + (= + (del-command + (neg $Rel) $ICs $Pos $NegIn $ICs $Pos $NegOut) + (filter $NegIn $Rel $Deleted $NegOut)) +; + + (= + (del-command + (rel $R) $ICs $PosIn $NegIn $ICs $PosOut $NegOut) + ( (remove-symbol &self + (rel $R $AList)) + (filter $PosIn $Rel $_ $PosOut) + (filter $NegIn $Rel $_ $NegOut))) +; + + (= + (del-command + (calc $Rel) $InICs $Pos $Neg $OutICs $Pos $Neg) + ( (remove-all-symbols &self + (proc $Rel $Proc)) (remove (proc $Rel) $InICs $OutICs))) +; + + + + (= + (add-command + (ics $DisplayIC) $ICs $Pos $Neg + (Cons $IC $ICs) $Pos $Neg) + (display $IC $DisplayIC)) +; + + (= + (add_command + (pos $Tuple) $ICs $Pos $Neg $ICs + (Cons $Tuple $Pos) $Neg) True) +; + + (= + (add_command + (neg $Tuple) $ICs $Pos $Neg $ICs $Pos + (Cons $Tuple $Neg)) True) +; + + (= + (add-command + (rel $R $AList) $ICs $Pos $Neg $ICs $Pos $Neg) + (new-rel $R $AList)) +; + + (= + (add-command + (calc $Rel) $InICs $PosIn $Neg + (Cons + (proc $Rel) $OutICs) $PosOut $Neg) + ( (ask-proc $Rel) + (filter $PosIn $Rel $RelTuples $_) + (setof0 $T + (, + (member $T $RelTuples) + (satisfied $T Nil Nil Nil)) $SatTuples) + (listdiff $PosIn $SatTuples $PosOut) + (remove + (proc $Rel) $InICs $OutICs))) +; + + + + + (= + (init-command + (ics $Rel) $InICs $OutICs) + ( (init-ICs $Rel $ICs) (append $InICs $ICs $OutICs))) +; + + + + (= + (find-command ics $InICs $PosIn $NegIn $OutICs $PosOut $NegOut) + (char $InICs $PosIn $NegIn $OutICs $PosOut $NegOut)) +; + + + + (= + (check-command + (ics $DisplayIC) $ICs $Pos $Neg) + ( (display $IC $DisplayIC) (check-ics $IC $Pos $Neg))) +; + + (= + (check-command + (pos $Tuple) $ICs $Pos $Neg) + ( (set-det) (forall (member $IC $ICs) (check-ics $IC (Cons $Tuple $Pos) $Neg)))) +; + + + + (= + (help-command commands) + ( (set-det) + (bagof0 + (with_self $W $T) + (keyword1 $W $T) $L) + (show-list Commands $L))) +; + + (= + (help-command filters) + ( (set-det) + (bagof0 + (with_self $W $T) + (keyword2 $W $T) $L) + (show-list Filters $L))) +; + + (= + (help-command switches) + ( (set-det) + (bagof0 + (with_self $W $T) + (switch $W $T) $L) + (show-list Switches $L))) +; + + (= + (help-command levels) + ( (set-det) + (bagof0 + (with_self $W $T) + (level $W $T) $L) + (show-list Levels $L))) +; + + (= + (help-command $_) + ( (help-command commands) + (help-command filters) + (help-command switches) + (help-command levels))) +; + + + + (= + (get-list + (pos $Filter) $ICs $Pos $Neg $List 'positive tuples') + (filter $Pos $Filter $List)) +; + + (= + (get-list + (neg $Filter) $ICs $Pos $Neg $List 'negative tuples') + (filter $Neg $Filter $List)) +; + + (= + (get-list + (ics $Filter) $ICs $Pos $Neg $List 'integrity constraints') + ( (filter $ICs $Filter $Tmp) (compress $Tmp $List))) +; + + + + (= + (filter $In $F $Out) + ( (template $F $Template) (setof0 $Template (member $Template $In) $Out))) +; + + + (= + (filter $In $F $Out $Rest) + ( (filter $In $F $Out) (listdiff $In $Out $Rest))) +; + + + + (= + (new-rel $R $Attrs) + ( (rel $R $Attrs) (set-det))) +; + + (= + (new-rel $R $Attrs) + ( (rel $R $A) + (set-det) + (write 'Error: relation name already in use') + (nl) + (fail))) +; + + (= + (new-rel $R $Attrs) + (add-symbol &self + (rel $R $Attrs))) +; + + + + (= + (ask-proc $Rel) + ( (prompt-read clause $Clause) + (add-symbol &self + (proc $Rel $Clause)) + (set-det) + (ask-proc $Rel))) +; + + (= + (ask_proc $Rel) True) +; + + + + (= + (get-pos $Rel $Pos) + ( (template $Rel $Tuple) (bagof0 $Tuple (pos-tuple $Tuple) $Pos))) +; + + + + (= + (get-neg $Rel $Neg) + ( (template $Rel $Tuple) (bagof0 $Tuple (neg-tuple $Tuple) $Neg))) +; + + + + (= + (get-ics $T $ICs) + ( (template $T $Templ) (bagof0 $Templ (constraint $Templ) $ICs))) +; + + + + (= + (save-pos $Rel $Pos) + ( (template $Rel $T) (forall (member $T $Pos) (myassert (pos-tuple $T))))) +; + + + + (= + (save-neg $Rel $Neg) + ( (template $Rel $T) (forall (member $T $Neg) (myassert (neg-tuple $T))))) +; + + + + (= + (save-ics $T $ICs) + ( (template $T $Templ) (forall (member $Templ $ICs) (myassert (constraint $Templ))))) +; + + + + (= + (check-ics $IC $Pos $Neg) + ( (display $IC $DisplayIC) + (evaluate $Pos $Neg $IC $Tuples $PosOut $NegOut $Answer) + (write $DisplayIC) + (det-if-then-else + (= $Answer refine) + (show-list ' is contradicted by' $Tuples) + (det-if-then-else + (= $Answer keep) + (, + (write ' is satisfied') + (nl)) + (det-if-then-else + (= $Answer + (keep $E)) + (, + (write-list (:: ' looks promising: ' $E)) + (nl)) + (det-if-then + (= $Answer + (ignore $E)) + (, + (write-list (:: ' has low confirmation: ' $E)) + (nl)))))))) +; + + + + (= + (switch $X) + ( (switch $X $T) + (remove-symbol &self + (switched_on $X)) + (set-det) + (write-list (:: $X ' is now off.')) + (nl))) +; + + (= + (switch $X) + ( (switch $X $T) + (set-det) + (add-symbol &self + (switched_on $X)) + (write-list (:: $X ' is now on.')) + (nl))) +; + +; (error +; (syntax_error operator_expected) +; (file index/commands.pl 251 28 7757)) + + + + (= + (set $X) + ( (=.. $X + (Cons $Level $Rest)) + (level $Level $T) + (set-det) + (det-if-then-else + (= $Rest + (:: $Value)) + (, + (or + (, + (remove-symbol &self + (level_set $Level $V)) + (set-det)) True) + (add-symbol &self + (level_set $Level $Value))) + (det-if-then + (= $Rest Nil) + (, + (get-level $Level $L) + (write (= $Level $L)) + (nl)))))) +; + + (= + (set $_) + ( (setof0 + (= $L $V) + (^ $T + (, + (level $L $T) + (get-level $L $V))) $L) (show-list levels $L))) +; + + + + (= + (get-level $Level $Value) + ( (level $Level $T) (or (, (level-set $Level $Value) (set-det)) (= $Value 0)))) +; + + + + (= + (compare $X) + ( (=.. $X + (:: $Level $Value)) + (get-level $Level $L) + (det-if-then-else + (= $L + (+ $V)) + (>= $Value $V) + (det-if-then-else + (= $L + (- $V)) + (=< $Value $V) + (det-if-then-else + (= $L + (/ $V $A)) + (, + (is $Upper + (+ $V $A)) + (=< $Value $Upper) + (is $Lower + (- $V $A)) + (>= $Value $Lower)) + (det-if-then otherwise + (, + (write-list (:: 'Wrong level: ' (= $Level $L))) + (nl) + (break)))))))) +; + + diff --git a/index/decomp.metta b/index/decomp.metta new file mode 100644 index 0000000..0f897b3 --- /dev/null +++ b/index/decomp.metta @@ -0,0 +1,279 @@ + + (= + (decompose $DisplayIC $PosIn $PosOut $InICs $OutICs) + ( (display $IC $DisplayIC) + (contr $PosIn Nil $IC $Tuples $Answer) + (det-if-then-else + (= $Answer no) + (split $IC $PosIn $PosOut $InICs $OutICs) + (det-if-then otherwise + (divide $PosIn $IC $PosOut $InICs $OutICs))))) +; + + + + (= + (split $Dep $PosIn $PosOut $ICs + (Cons $Join $ICs)) + ( (dep $Dep $Type $Rel $From $To) (split1 $Rel $From $To $PosIn $PosOut $Join))) +; + + + + (= + (split1 $Rel $From $To $PosIn $PosOut + (join $Rel $R1 $R2)) + ( (append $From $To $In1) + (new-name $In1 $Out1 $R1) + (rel $Rel $AttrList) + (listdiff $AttrList $To $In2) + (new-name $In2 $Out2 $R2) + (splits $Rel $R1 $R2 $Out1 $Out2 $PosIn $PosTmp) + (remove-dups $PosTmp $PosOut))) +; + + + + (= + (splits $Rel $R1 $R2 $AList1 $AList2 () ()) True) +; + + (= + (splits $Rel $R1 $R2 $AList1 $AList2 + (Cons $T $Ts) + (Cons $T1 + (Cons $T2 $Rest))) + ( (values $Rel $AList1 $ValueList1 $T) + (set-det) + (=.. $T1 + (Cons $R1 $ValueList1)) + (values $Rel $AList2 $ValueList2 $T) + (=.. $T2 + (Cons $R2 $ValueList2)) + (splits $Rel $R1 $R2 $AList1 $AList2 $Ts $Rest))) +; + + (= + (splits $Rel $R1 $R2 $AList1 $AList2 + (Cons $T $Ts) + (Cons $T $Rest)) + (splits $Rel $R1 $R2 $AList1 $AList2 $Ts $Rest)) +; + + + + (= + (new-name $AListIn $AListOut $R) + ( (show-list attributes $AListIn) + (prompt-read 'relation name' $Answer) + (det-if-then-else + (= $Answer -) + (, + (concat-atom $AListIn $R) + (= $AListOut $AListIn)) + (det-if-then-else + (= $Answer +) + (, + (prompt-read 'rel(Name,AttrList)' + (rel $R $AListOut)) + (permutation $AListOut $AListIn)) + (det-if-then otherwise + (, + (= $R $Answer) + (= $AListOut $AListIn))))) + (new-rel $R $AListOut))) +; + + + + (= + (exec-rule $DisplayRule $PosIn $PosOut) + ( (display $Rule $DisplayRule) + (horn $Rule + (= $Tuple $Body)) + (setof0 $Tuple + (^ $Ts + (satisfied $Body $PosIn Nil $Ts)) $PosOut))) +; + + + + (= + (divide $PosIn $Dep $PosOut $InICs + (Cons + (plus $Rel $Names) $OutICs)) + ( (dep $Dep $Type $Rel $From $To) + (filter $PosIn $Rel $PosFiltered $Rest) + (splitsort $PosFiltered $Dep $SplitPos) + (joinsort $SplitPos $Dep $NotContr $Contr) + (find-division $Rel $NotContr $Contr $Numbers $NewPos1) + (new-preds $Rel $NewPos1 Nil $PosTmp1 Nil $Names) + (append $PosTmp1 $Rest $PosTmp2) + (decomp-again $Names $Dep $PosTmp2 $PosOut $InICs $OutICs))) +; + + + + (= + (decomp_again () $Dep $Pos $Pos $ICs $ICs) True) +; + + (= + (decomp-again + (Cons $Name $Names) $Dep $PosIn $PosOut $InICs $OutICs) + ( (det-if-then-else + (yesno (:: 'Decompose ' $Name ? )) + (, + (dep $Dep $Type $R $From $To) + (dep $NewDep $Type $Name $From $To) + (display $NewDep $DDep) + (decompose $DDep $PosIn $PosTmp $InICs $TmpICs)) + (det-if-then otherwise + (, + (= $PosTmp $PosIn) + (= $TmpICs $InICs)))) (decomp-again $Names $Dep $PosTmp $PosOut $TmpICs $OutICs))) +; + + + + (= + (divides () $Dep () ()) True) +; + + (= + (divides + (Cons $H $T) $Dep + (Cons $NewH $NewT) + (Cons $NsH $NsT)) + ( (length $H $LH) + (divide1 $H $LH $_ Nil 0 $_ $Dep $NewH $NsH) + (set-det) + (divides $T $Dep $NewT $NsT))) +; + + + + (= + (divide1 $Pos1 $Pos2 $IC $PosOut) + (divide1 $Pos1 0 $_ $Pos2 0 $_ $IC $PosOut $_)) +; + + + (= + (divide1 Nil $K $K Nil $L $L $IC Nil Nil) + (set-det)) +; + + (= + (divide1 $Pos1 $K0 $K $Pos2 $L0 $L $IC $PosOut $M) + ( (contr $Pos1 Nil $IC $Tuples $Answer) + (det-if-then-else + (or + (= $Answer yes) + (= $Answer possibly)) + (, + (= $Tuples + (Cons + (+ $T1) + (Cons + (+ $T2) $N))) + (remove $T2 $Pos1 $NewPos1) + (is $K1 + (- $K0 1)) + (= $NewPos2 + (Cons $T2 $Pos2)) + (is $L1 + (+ $L0 1)) + (= $PosOut $NewPosOut) + (= $M $NewM)) + (det-if-then + (= $Answer no) + (, + (= $NewPos1 $Pos2) + (= $K1 $L0) + (= $NewPos2 Nil) + (= $L1 0) + (= $PosOut + (Cons $Pos1 $NewPosOut)) + (= $M + (Cons $K0 $NewM))))) + (set-det) + (divide1 $NewPos1 $K1 $K $NewPos2 $L1 $L $IC $NewPosOut $NewM))) +; + + + + (= + (find-division $Rel $NotContr $Contr $Numbers $NewPos) + ( (det-if-then-else + (= $NotContr Nil) + (= $NewPos $Contr) + (det-if-then otherwise + (= $NewPos + (Cons + (:: $NotContr) $Contr)))) + (show-lists $Rel + (:: segment part) $NewPos) + (yesno (:: 'Proceed? ')))) +; + + + + (= + (new_preds $Rel () $New $New $Names $Names) True) +; + + (= + (new-preds $Rel + (Cons $H $T) $New0 $New $Names0 $Names) + ( (new-preds1 $Rel $H $New0 $New1 $Names0 $Names1) (new-preds $Rel $T $New1 $New $Names1 $Names))) +; + + + + (= + (new_preds1 $Rel () $New $New $Names $Names) True) +; + + (= + (new-preds1 $Rel + (Cons $R $Rs) $New0 $New $Names0 $Names) + ( (show-list $Rel 'partial relation' $R) + (prompt-read 'relation name' $N) + (rel $Rel $Attrs) + (new-rel $N $Attrs) + (new-relation $Rel $R $N $NewR) + (append $New0 $NewR $New1) + (add-if $N $Names0 $Names1) + (new-preds1 $Rel $Rs $New1 $New $Names1 $Names))) +; + + + + (= + (new-relation $Rel $R $N $NewR) + (bagof0 $NewT + (^ $T + (, + (member $T $R) + (new-tuple $Rel $T $N $NewT))) $NewR)) +; + + + + (= + (new-tuple $Rel $T $N $NewT) + ( (=.. $T + (Cons $Rel $Args)) + (set-det) + (=.. $NewT + (Cons $N $Args)))) +; + + (= + (new_tuple $Rel $T $N $T) True) +; + ; +; + + diff --git a/index/eval.metta b/index/eval.metta new file mode 100644 index 0000000..cf469aa --- /dev/null +++ b/index/eval.metta @@ -0,0 +1,93 @@ + + (= + (evaluate1 $P $IC $Answer) + ( (switched-on eval) + (dep $IC $Type $Rel $From $To) + (filter $P $Rel $P1 $Rest) + (splitsort $P1 $IC $SplitP $NumbersC) + (calc-conf $NumbersC $Conf) + (det-if-then-else + (compare (conf $Conf)) + (, + (divides $SplitP $IC $NewP $NumbersA) + (calc-acc $NumbersA $Acc) + (det-if-then-else + (compare (acc $Acc)) + (= $Answer + (keep (acc $Acc))) + (det-if-then + (compare (split $Acc)) + (= $Answer + (keep (split $Acc)))))) + (det-if-then otherwise + (= $Answer + (ignore (conf $Conf))))))) +; + + + + (= + (calc-conf + (, $NDivs $NTuples) $Confirmation) + (is $Confirmation + (/ $NTuples $NDivs))) +; + + + + (= + (calc-acc $Numbers $Accuracy) + ( (calc-acc1 $Numbers 0 $NTuples 0 $NLarge 0 $MaxNP) (is $Accuracy (- 1 (/ (* (- $MaxNP 1) (- $NTuples $NLarge)) $NTuples))))) +; + + + + (= + (calc_acc1 () $NT $NT $NL $NL $MaxNP $MaxNP) True) +; + + (= + (calc-acc1 + (Cons $D $Ds) $NT0 $NT $NL0 $NL $MaxNP0 $MaxNP) + ( (eval2 $D 0 $Sum 0 $Largest 0 $NParts) + (is $NT1 + (+ $NT0 $Sum)) + (is $NL1 + (+ $NL0 $Largest)) + (det-if-then-else + (> $NParts $MaxNP0) + (= $MaxNP1 $NParts) + (det-if-then otherwise + (= $MaxNP1 $MaxNP0))) + (calc-acc1 $Ds $NT1 $NT $NL1 $NL $MaxNP1 $MaxNP))) +; + + + + (= + (eval2 () $S $S $L $L $M $M) True) +; + + (= + (eval2 + (Cons $N $Ns) $S0 $S $L0 $L $M0 $M) + ( (is $S1 + (+ $S0 $N)) + (det-if-then-else + (> $N $L0) + (= $L1 $N) + (det-if-then otherwise + (= $L1 $L0))) + (is $M1 + (+ $M0 1)) + (eval2 $Ns $S1 $S $L1 $L $M1 $M))) +; + + + + (= + (insert_ic $L $IC $E + (Cons $IC $L)) True) +; + + diff --git a/index/hooks.metta b/index/hooks.metta new file mode 100644 index 0000000..bb41cad --- /dev/null +++ b/index/hooks.metta @@ -0,0 +1,365 @@ + + !(op 900 xfx :) +; + + !(op 800 xfx -->) +; + + !(op 800 xfx ->->) +; + + !(op 800 xfx ><) +; + + !(op 800 xfx <) +; + + + + (= + (init-ICs $Rel $ICs) + ( (rel $Rel $AList) + (choose-list 'Which dependencies' $AList $AttrList) + (bagof0 + (mvd $Rel Nil + (:: $A)) + (member $A $AttrList) $IC1) + (bagof0 + (fd $Rel Nil + (:: $A)) + (member $A $AttrList) $IC2) + (append $IC1 $IC2 $ICs))) +; + + + + (= + (horn + (fd $Rel $FromList + (:: $To)) + (= + (= $A1 $A2) + ($Tuple1 $Tuple2))) + ( (values $Rel $FromList $ValueList $Tuple1) + (values $Rel $FromList $ValueList $Tuple2) + (value $Rel $To $A1 $Tuple1) + (value $Rel $To $A2 $Tuple2))) +; + + (= + (horn + (mvd $Rel $FromList $ToList) + (= $Tuple1 + ($Tuple2 $Tuple3))) + ( (rel $Rel $AttrList) + (listdiff $AttrList $FromList $List) + (listdiff $List $ToList $RestList) + (values $Rel $FromList $FromValues $Tuple1) + (values $Rel $FromList $FromValues $Tuple2) + (values $Rel $FromList $FromValues $Tuple3) + (values $Rel $ToList $ToValues $Tuple1) + (values $Rel $ToList $ToValues $Tuple2) + (values $Rel $RestList $RestValues $Tuple1) + (values $Rel $RestList $RestValues $Tuple3))) +; + + (= + (horn + (join $Rel $R1 $R2) + (= $Tuple1 + ($Tuple2 $Tuple3))) + ( (rel $R1 $R1Attrs) + (rel $R2 $R2Attrs) + (values $Rel $R1Attrs $R1Values $Tuple1) + (values $Rel $R2Attrs $R2Values $Tuple1) + (values $R1 $R1Attrs $R1Values $Tuple2) + (values $R2 $R2Attrs $R2Values $Tuple3))) +; + + (= + (horn + (plus $Rel $List) + (= $Tuple $Body)) + ( (rel $Rel $RelAttrs) + (values $Rel $RelAttrs $Values $Tuple) + (make-body $List $Values $Body))) +; + + (= + (horn + (proc $Rel) $Proc) + (proc $Rel $Proc)) +; + ; +; + + + + (= + (make-body + (:: $R) $Values $L) + ( (set-det) + (rel $R $Attrs) + (values $R $Attrs $Values $L))) +; + + (= + (make-body + (Cons $R $Rs) $Values + (or $L $Ls)) + ( (rel $R $Attrs) + (values $R $Attrs $Values $L) + (make-body $Rs $Values $Ls))) +; + + + + (= + (refinements + (fd $Rel $From + (:: $To)) + (:: + (+ $T1) + (+ $T2)) $ICs) + ( (set-det) + (diff $T1 $T2 $Diff) + (bagof0 + (fd $Rel + (Cons $Attr $From) + (:: $To)) + (fd-spec $To $Diff $Attr) $ICs))) +; + + (= + (refinements + (mvd $Rel $From $To) + (:: + (+ $T1) + (+ $T2) + (- $T3)) $ICs) + ( (set-det) + (diff $T1 $T3 $D13) + (diff $T2 $T3 $D23) + (bagof0 + (mvd $Rel + (Cons $Attr $From) $ST) + (mvd-spec $Rel $From $To $D13 $D23 $Attr $ST) $ICs))) +; + + (= + (refinements $IC $Tuples $ICs) + ( (display $IC $DisplayIC) + (write $DisplayIC) + (show-list ' is contradicted by' $Tuples) + (ic-spec $IC $ICs))) +; + + + + (= + (fd-spec $To $Diff $Attr) + ( (member $Attr $Diff) (\= $Attr $To))) +; + + + + (= + (mvd-spec $Rel $From $To $Diff $_ $Attr $ST) + ( (member $Attr $Diff) + (remove $Attr $To $ST) + (\= $ST Nil) + (compl + (mvd $Rel + (Cons $Attr $From) $ST) + (mvd $Rel + (Cons $Attr $From) $SCT)) + (\= $SCT Nil))) +; + + (= + (mvd-spec $Rel $From $To $_ $Diff $Attr $ST) + ( (member $Attr $Diff) + (remove $Attr $To $ST) + (\= $ST Nil) + (compl + (mvd $Rel + (Cons $Attr $From) $ST) + (mvd $Rel + (Cons $Attr $From) $SCT)) + (\= $SCT Nil))) +; + + + + (= + (ic-spec $IC + (Cons $R $Rs)) + ( (prompt-read refinement $DR) + (set-det) + (display $R $DR) + (ic-spec $IC $Rs))) +; + + (= + (ic_spec $IC ()) True) +; + + + + (= + (subsumed + (fd $Rel $From1 $To) + (fd $Rel $From2 $To)) + (subset $From2 $From1)) +; + + (= + (subsumed + (mvd $Rel $From1 $To) + (mvd $Rel $From2 $To)) + ( (set-det) (subset $From2 $From1))) +; + + (= + (subsumed + (mvd $Rel $From1 $To1) + (mvd $Rel $From2 $To2)) + ( (subset $From2 $From1) (compl (mvd $Rel $From1 $To1) (mvd $Rel $From1 $To2)))) +; + + + + (= + (compl + (mvd $Rel $From $To) + (mvd $Rel $From $CTo)) + ( (rel $Rel $AttrList) + (listdiff $AttrList $From $AL1) + (listdiff $AL1 $To $CTo))) +; + + + + (= + (compress $In $Out) + ( (select + (fd $Rel $From $To1) $In $In1) + (select + (fd $Rel $From $To2) $In1 $In2) + (set-det) + (append $To1 $To2 $To) + (compress + (Cons + (fd $Rel $From $To) $In2) $Out))) +; + + (= + (compress $ICs $ICs) True) +; + + + + (= + (dep + (fd $Rel $From $To) fd $Rel $From $To) True) +; + + (= + (dep + (mvd $Rel $From $To) mvd $Rel $From $To) True) +; + + + + (= + (display + (fd $Rel $From $To) + (with_self $Rel + (--> $From $To))) + (set-det)) +; + + (= + (display + (mvd $Rel $From $To) + (with_self $Rel + (->-> $From $To))) + (set-det)) +; + + (= + (display + (join $Rel $R1 $R2) + (>< + (= $Rel $R1) $R2)) + (set-det)) +; + + (= + (display + (plus $Rel $List) + (= $Rel $List)) + (set-det)) +; + + (= + (display + (proc $Rel) + (with_self + (calculated *) $Rel)) + (set-det)) +; + + (= + (display $X $X) True) +; + + + + (= + (template all $X) + (set-det)) +; + + (= + (template fd + (fd $Rel $From $To)) + (set-det)) +; + + (= + (template mvd + (mvd $Rel $From $To)) + (set-det)) +; + + (= + (template join + (join $Rel $R1 $R2)) + (set-det)) +; + + (= + (template plus + (plus $Rel $List)) + (set-det)) +; + + (= + (template proc + (proc $Rel)) + (set-det)) +; + + (= + (template $R $Tuple) + ( (rel $R $A) + (set-det) + (values $R $A $V $Tuple))) +; + + (= + (template $X $X) True) +; + + diff --git a/index/index.metta b/index/index.metta new file mode 100644 index 0000000..db47de4 --- /dev/null +++ b/index/index.metta @@ -0,0 +1,2403 @@ + + !(unknown $_ fail) +; + + !(no-style-check all) +; + + + !(compile (library basics)) +; + + !(compile (library lists)) +; + + !(compile (library sets)) +; + + !(compile (library not)) +; + +; +; + + + !(dynamic (/ switched-on 1)) +; + + !(dynamic (/ level-set 2)) +; + + + + (= + (switched_on cwa) True) +; + + (= + (switched_on eval) True) +; + + (= + (switched_on debug) True) +; + + + + (= + (level_set acc + (+ 0.8)) True) +; + + (= + (level_set conf + (+ 2)) True) +; + + (= + (level_set split + (/ 0.5 0.1)) True) +; + + + + (= + (run) + (commands Nil Nil Nil)) +; + + + + + (= + (listdiff $L () $L) True) +; + + (= + (listdiff $L + (Cons $H $T) $V) + ( (remove $H $L $L1) (listdiff $L1 $T $V))) +; + + + + (= + (remove $_ () ()) True) +; + + (= + (remove $H + (Cons $H $T) $L) + (remove $H $T $L)) +; + + (= + (remove $X + (Cons $H $T) + (Cons $H $L)) + ( (remove $X $T $L) (\= $X $H))) +; + + + + (= + (select-two + (Cons $H $T) $H $Y) + (member $Y $T)) +; + + (= + (select-two + (Cons $H $T) $X $Y) + (select-two $T $X $Y)) +; + + + + (= + (forall $Goal $Condition) + ( (bagof0 $Condition $Goal $List) (forall1 $List))) +; + + + + (= + (forall1 ()) True) +; + + (= + (forall1 (Cons $H $T)) + ( (call $H) (forall1 $T))) +; + + + + (= + (bagof0 $T $G $L) + ( (bagof $T $G $L) (set-det))) +; + + (= + (bagof0 $T $G ()) True) +; + + + + (= + (setof0 $T $G $L) + ( (setof $T $G $L) (set-det))) +; + + (= + (setof0 $T $G ()) True) +; + + +; (error +; (syntax_error operator_expected) +; (file index/index.pl 67 4 1074)) + + + + (= + (add-if $X $Ys $Ys) + ( (member $X $Ys) (set-det))) +; + + (= + (add_if $X $Ys + (Cons $X $Ys)) True) +; + + + + (= + (flatten $Xs $Ys) + (flatten-dl $Xs Nil $Ys)) +; + + + + (= + (flatten-dl Nil $Ys $Ys) + (set-det)) +; + + (= + (flatten-dl + (Cons $X $Xs) $Ys0 $Ys) + ( (set-det) + (flatten-dl $Xs $Ys0 $Ys1) + (flatten-dl $X $Ys1 $Ys))) +; + + (= + (flatten_dl $X $Xs + (Cons $X $Xs)) True) +; + + + (= + (char $InICs $PosIn $NegIn $OutICs $PosOut $NegOut) + ( (char1 $InICs $PosIn $NegIn Nil $TmpICs $PosOut $NegOut) (cleanup $TmpICs Nil $OutICs))) +; + + + + (= + (char1 () $P $N $Out $Out $P $N) True) +; + + (= + (char1 + (Cons $IC $ICs) $P0 $N0 $Acc $Out $P $N) + ( (write-debug (:: 'evaluating ' $IC)) + (evaluate $P0 $N0 $IC $Tuples $P1 $N1 $Answer) + (det-if-then-else + (= $Answer refine) + (, + (refinements $IC $Tuples $Spec) + (append $ICs $Spec $NewICs) + (= $NewAcc $Acc)) + (det-if-then-else + (= $Answer keep) + (, + (= $NewICs $ICs) + (= $NewAcc + (Cons $IC $Acc))) + (det-if-then-else + (= $Answer + (ignore $E)) + (, + (= $NewICs $ICs) + (= $NewAcc $Acc)) + (det-if-then + (= $Answer + (keep $E)) + (, + (= $NewICs $ICs) + (insert-ic $Acc $IC $E $NewAcc)))))) + (write-debug (:: ' result: ' $Answer)) + (set-det) + (char1 $NewICs $P1 $N1 $NewAcc $Out $P $N))) +; + + + + (= + (evaluate $P0 $N0 $IC $Tuples $P $N $Answer) + (det-if-then-else + (evaluate1 $P0 $IC $Answer) + (, + (= $P $P0) + (= $N $N0) + (= $Tuples Nil)) + (det-if-then otherwise + (, + (contr $P0 $N0 $IC $T $A) + (det-if-then-else + (= $A yes) + (, + (= $Answer refine) + (= $P $P0) + (= $N $N0) + (= $Tuples $T)) + (det-if-then-else + (= $A no) + (, + (= $Answer keep) + (= $P $P0) + (= $N $N0) + (= $Tuples $T)) + (det-if-then + (= $A possibly) + (, + (queries $P0 $N0 $T $P1 $N1) + (evaluate $P1 $N1 $IC $Tuples $P $N $Answer))))))))) +; + + + + (= + (contr $P $N $IC $Tuples $Answer) + ( (horn $IC $HornIC) (incons $HornIC $P $N $Tuples $Answer))) +; + + + + (= + (queries $P $N () $P $N) True) +; + + (= + (queries $P $N + (Cons $T $Ts) $P1 $N1) + ( (query $P $N $T $P2 $N2) (queries $P2 $N2 $Ts $P1 $N1))) +; + + +; (error +; (syntax_error operator_expected) +; (file index/index.pl 122 4 2503)) + +; (error +; (syntax_error operator_expected) +; (file index/index.pl 124 4 2590)) + + + (= + (query $P $N + (- $T) $P + (Cons $T $N)) + ( (switched-on cwa) + (write (- $T)) + (nl))) +; + + (= + (query $P $N + (+ $T) $P $N) True) +; + + + + (= + (cleanup + (Cons $X $In) $Acc $Out) + ( (member $IC $In) + (subsumed $X $IC) + (set-det) + (cleanup $In $Acc $Out))) +; + + (= + (cleanup + (Cons $X $In) $Acc $Out) + ( (member $IC $Acc) + (subsumed $X $IC) + (set-det) + (cleanup $In $Acc $Out))) +; + + (= + (cleanup + (Cons $X $In) $Acc $Out) + (cleanup $In + (Cons $X $Acc) $Out)) +; + + (= + (cleanup () $Out $Out) True) +; + + + + (= + (incons + (= $Head $Body) $P $N $Tuples $Answer) + ( (satisfied $Body $P $N $TuplesB) + (falsified $Head $P $N $TuplesH) + (set-det) + (= $Answer yes) + (append $TuplesB $TuplesH $Tuples))) +; + + (= + (incons + (= $Head $Body) $P $N $Tuples $Answer) + ( (satisfied $Body $P $N $TuplesB) + (unsatisfied $Head $P $N $TuplesH) + (set-det) + (= $Answer possibly) + (append $TuplesB $TuplesH $Tuples))) +; + + (= + (incons + (= $Head $Body) $P $N Nil $Answer) + (= $Answer no)) +; + + + + (= + (satisfied + (, $A $B) $P $N $Tuples) + ( (satisfied $A $P $N $TuplesA) + (satisfied $B $P $N $TuplesB) + (append $TuplesA $TuplesB $Tuples))) +; + + (= + (satisfied + (or $A $B) $P $N $Tuples) + (or + (satisfied $A $P $N $Tuples) + (satisfied $B $P $N $Tuples))) +; + + (= + (satisfied $A $P $N + (:: (+ $A))) + (member $A $P)) +; + + (= + (satisfied + (= $A $A) $P $N ()) True) +; + ; +; + + (= + (satisfied $A $P $N Nil) + ( (proc $Rel $Proc) (exec-proc $A $Proc))) +; + + + + (= + (exec-proc $Goal + (, $P1 $P2)) + (or + (exec-proc $Goal $P1) + (exec-proc $Goal $P2))) +; + + (= + (exec-proc $Goal + (= $Goal $Body)) + (call $Body)) +; + + + + (= + (falsified + (, $A $B) $P $N $Tuples) + (or + (, + (set-det) + (falsified $A $P $N $Tuples)) + (falsified $B $P $N $Tuples))) +; + + (= + (falsified $A $P $N + (:: (- $A))) + (member $A $N)) +; + + (= + (falsified + (= $A $B) $P $N Nil) + (\= $A $B)) +; + + + + (= + (unsatisfied + (, $A $B) $P $N $Tuples) + (or + (, + (set-det) + (unsatisfied $A $P $N $Tuples)) + (unsatisfied $B $P $N $Tuples))) +; + + (= + (unsatisfied $A $P $N + (:: (- $A))) + ( (not (satisfied $A $P $N $_)) (not (falsified $A $P $N $_)))) +; + + + (= + (evaluate1 $P $IC $Answer) + ( (switched-on eval) + (dep $IC $Type $Rel $From $To) + (filter $P $Rel $P1 $Rest) + (splitsort $P1 $IC $SplitP $NumbersC) + (calc-conf $NumbersC $Conf) + (det-if-then-else + (compare (conf $Conf)) + (, + (divides $SplitP $IC $NewP $NumbersA) + (calc-acc $NumbersA $Acc) + (det-if-then-else + (compare (acc $Acc)) + (= $Answer + (keep (acc $Acc))) + (det-if-then + (compare (split $Acc)) + (= $Answer + (keep (split $Acc)))))) + (det-if-then otherwise + (= $Answer + (ignore (conf $Conf))))))) +; + + + + (= + (calc-conf + (, $NDivs $NTuples) $Confirmation) + (is $Confirmation + (/ $NTuples $NDivs))) +; + + + + (= + (calc-acc $Numbers $Accuracy) + ( (calc-acc1 $Numbers 0 $NTuples 0 $NLarge 0 $MaxNP) (is $Accuracy (- 1 (/ (* (- $MaxNP 1) (- $NTuples $NLarge)) $NTuples))))) +; + + + + (= + (calc_acc1 () $NT $NT $NL $NL $MaxNP $MaxNP) True) +; + + (= + (calc-acc1 + (Cons $D $Ds) $NT0 $NT $NL0 $NL $MaxNP0 $MaxNP) + ( (eval2 $D 0 $Sum 0 $Largest 0 $NParts) + (is $NT1 + (+ $NT0 $Sum)) + (is $NL1 + (+ $NL0 $Largest)) + (det-if-then-else + (> $NParts $MaxNP0) + (= $MaxNP1 $NParts) + (det-if-then otherwise + (= $MaxNP1 $MaxNP0))) + (calc-acc1 $Ds $NT1 $NT $NL1 $NL $MaxNP1 $MaxNP))) +; + + + + (= + (eval2 () $S $S $L $L $M $M) True) +; + + (= + (eval2 + (Cons $N $Ns) $S0 $S $L0 $L $M0 $M) + ( (is $S1 + (+ $S0 $N)) + (det-if-then-else + (> $N $L0) + (= $L1 $N) + (det-if-then otherwise + (= $L1 $L0))) + (is $M1 + (+ $M0 1)) + (eval2 $Ns $S1 $S $L1 $L $M1 $M))) +; + + + + (= + (insert_ic $L $IC $E + (Cons $IC $L)) True) +; + + + !(op 900 xfx :) +; + + !(op 800 xfx -->) +; + + !(op 800 xfx ->->) +; + + !(op 800 xfx ><) +; + + !(op 800 xfx <) +; + + + + (= + (init-ICs $Rel $ICs) + ( (rel $Rel $AList) + (choose-list 'Which dependencies' $AList $AttrList) + (bagof0 + (mvd $Rel Nil + (:: $A)) + (member $A $AttrList) $IC1) + (bagof0 + (fd $Rel Nil + (:: $A)) + (member $A $AttrList) $IC2) + (append $IC1 $IC2 $ICs))) +; + + + + (= + (horn + (fd $Rel $FromList + (:: $To)) + (= + (= $A1 $A2) + ($Tuple1 $Tuple2))) + ( (values $Rel $FromList $ValueList $Tuple1) + (values $Rel $FromList $ValueList $Tuple2) + (value $Rel $To $A1 $Tuple1) + (value $Rel $To $A2 $Tuple2))) +; + + (= + (horn + (mvd $Rel $FromList $ToList) + (= $Tuple1 + ($Tuple2 $Tuple3))) + ( (rel $Rel $AttrList) + (listdiff $AttrList $FromList $List) + (listdiff $List $ToList $RestList) + (values $Rel $FromList $FromValues $Tuple1) + (values $Rel $FromList $FromValues $Tuple2) + (values $Rel $FromList $FromValues $Tuple3) + (values $Rel $ToList $ToValues $Tuple1) + (values $Rel $ToList $ToValues $Tuple2) + (values $Rel $RestList $RestValues $Tuple1) + (values $Rel $RestList $RestValues $Tuple3))) +; + + (= + (horn + (join $Rel $R1 $R2) + (= $Tuple1 + ($Tuple2 $Tuple3))) + ( (rel $R1 $R1Attrs) + (rel $R2 $R2Attrs) + (values $Rel $R1Attrs $R1Values $Tuple1) + (values $Rel $R2Attrs $R2Values $Tuple1) + (values $R1 $R1Attrs $R1Values $Tuple2) + (values $R2 $R2Attrs $R2Values $Tuple3))) +; + + (= + (horn + (plus $Rel $List) + (= $Tuple $Body)) + ( (rel $Rel $RelAttrs) + (values $Rel $RelAttrs $Values $Tuple) + (make-body $List $Values $Body))) +; + + (= + (horn + (proc $Rel) $Proc) + (proc $Rel $Proc)) +; + ; +; + + + + (= + (make-body + (:: $R) $Values $L) + ( (set-det) + (rel $R $Attrs) + (values $R $Attrs $Values $L))) +; + + (= + (make-body + (Cons $R $Rs) $Values + (or $L $Ls)) + ( (rel $R $Attrs) + (values $R $Attrs $Values $L) + (make-body $Rs $Values $Ls))) +; + + + + (= + (refinements + (fd $Rel $From + (:: $To)) + (:: + (+ $T1) + (+ $T2)) $ICs) + ( (set-det) + (diff $T1 $T2 $Diff) + (bagof0 + (fd $Rel + (Cons $Attr $From) + (:: $To)) + (fd-spec $To $Diff $Attr) $ICs))) +; + + (= + (refinements + (mvd $Rel $From $To) + (:: + (+ $T1) + (+ $T2) + (- $T3)) $ICs) + ( (set-det) + (diff $T1 $T3 $D13) + (diff $T2 $T3 $D23) + (bagof0 + (mvd $Rel + (Cons $Attr $From) $ST) + (mvd-spec $Rel $From $To $D13 $D23 $Attr $ST) $ICs))) +; + + (= + (refinements $IC $Tuples $ICs) + ( (display $IC $DisplayIC) + (write $DisplayIC) + (show-list ' is contradicted by' $Tuples) + (ic-spec $IC $ICs))) +; + + + + (= + (fd-spec $To $Diff $Attr) + ( (member $Attr $Diff) (\= $Attr $To))) +; + + + + (= + (mvd-spec $Rel $From $To $Diff $_ $Attr $ST) + ( (member $Attr $Diff) + (remove $Attr $To $ST) + (\= $ST Nil) + (compl + (mvd $Rel + (Cons $Attr $From) $ST) + (mvd $Rel + (Cons $Attr $From) $SCT)) + (\= $SCT Nil))) +; + + (= + (mvd-spec $Rel $From $To $_ $Diff $Attr $ST) + ( (member $Attr $Diff) + (remove $Attr $To $ST) + (\= $ST Nil) + (compl + (mvd $Rel + (Cons $Attr $From) $ST) + (mvd $Rel + (Cons $Attr $From) $SCT)) + (\= $SCT Nil))) +; + + + + (= + (ic-spec $IC + (Cons $R $Rs)) + ( (prompt-read refinement $DR) + (set-det) + (display $R $DR) + (ic-spec $IC $Rs))) +; + + (= + (ic_spec $IC ()) True) +; + + + + (= + (subsumed + (fd $Rel $From1 $To) + (fd $Rel $From2 $To)) + (subset $From2 $From1)) +; + + (= + (subsumed + (mvd $Rel $From1 $To) + (mvd $Rel $From2 $To)) + ( (set-det) (subset $From2 $From1))) +; + + (= + (subsumed + (mvd $Rel $From1 $To1) + (mvd $Rel $From2 $To2)) + ( (subset $From2 $From1) (compl (mvd $Rel $From1 $To1) (mvd $Rel $From1 $To2)))) +; + + + + (= + (compl + (mvd $Rel $From $To) + (mvd $Rel $From $CTo)) + ( (rel $Rel $AttrList) + (listdiff $AttrList $From $AL1) + (listdiff $AL1 $To $CTo))) +; + + + + (= + (compress $In $Out) + ( (select + (fd $Rel $From $To1) $In $In1) + (select + (fd $Rel $From $To2) $In1 $In2) + (set-det) + (append $To1 $To2 $To) + (compress + (Cons + (fd $Rel $From $To) $In2) $Out))) +; + + (= + (compress $ICs $ICs) True) +; + + + + (= + (dep + (fd $Rel $From $To) fd $Rel $From $To) True) +; + + (= + (dep + (mvd $Rel $From $To) mvd $Rel $From $To) True) +; + + + + (= + (display + (fd $Rel $From $To) + (with_self $Rel + (--> $From $To))) + (set-det)) +; + + (= + (display + (mvd $Rel $From $To) + (with_self $Rel + (->-> $From $To))) + (set-det)) +; + + (= + (display + (join $Rel $R1 $R2) + (>< + (= $Rel $R1) $R2)) + (set-det)) +; + + (= + (display + (plus $Rel $List) + (= $Rel $List)) + (set-det)) +; + + (= + (display + (proc $Rel) + (with_self + (calculated *) $Rel)) + (set-det)) +; + + (= + (display $X $X) True) +; + + + + (= + (template all $X) + (set-det)) +; + + (= + (template fd + (fd $Rel $From $To)) + (set-det)) +; + + (= + (template mvd + (mvd $Rel $From $To)) + (set-det)) +; + + (= + (template join + (join $Rel $R1 $R2)) + (set-det)) +; + + (= + (template plus + (plus $Rel $List)) + (set-det)) +; + + (= + (template proc + (proc $Rel)) + (set-det)) +; + + (= + (template $R $Tuple) + ( (rel $R $A) + (set-det) + (values $R $A $V $Tuple))) +; + + (= + (template $X $X) True) +; + + + (= + (diff $Tuple1 $Tuple2 $Diff) + (diff $Tuple1 $Tuple2 $Rel $Equal $Diff)) +; + + + (= + (diff $Tuple1 $Tuple2 $Rel $Equal $Diff) + ( (=.. $Tuple1 + (Cons $Rel $Values1)) + (=.. $Tuple2 + (Cons $Rel $Values2)) + (rel $Rel $AttrList) + (diff1 $Values1 $Values2 $AttrList $Equal $Diff))) +; + + + + (= + (diff1 () () () () ()) True) +; + ; +; + + (= + (diff1 + (Cons $V $Values1) + (Cons $V $Values2) + (Cons $A $AttrList) + (Cons $A $Equal) $Diff) + (diff1 $Values1 $Values2 $AttrList $Equal $Diff)) +; + + (= + (diff1 + (Cons $V1 $Values1) + (Cons $V2 $Values2) + (Cons $A $AttrList) $Equal + (Cons $A $Diff)) + ( (\= $V1 $V2) (diff1 $Values1 $Values2 $AttrList $Equal $Diff))) +; + + + + (= + (values $_ () () $_) True) +; + + (= + (values $Rel + (Cons $Attr $AttrList) + (Cons $Value $ValueList) $Tuple) + ( (value $Rel $Attr $Value $Tuple) (values $Rel $AttrList $ValueList $Tuple))) +; + + + + (= + (value $Rel $Attr $Value $Tuple) + ( (rel $Rel $AttrList) + (al2vl $Attr $AttrList $Value $ValueList) + (=.. $Tuple + (Cons $Rel $ValueList)))) +; + + + + (= + (al2vl $_ () $_ ()) True) +; + + (= + (al2vl $Attr + (Cons $Attr $AttrList) $Value + (Cons $Value $ValueList)) + (al2vl $Attr $AttrList $Value $ValueList)) +; + + (= + (al2vl $Attr + (Cons $A $AttrList) $Value + (Cons $V $ValueList)) + ( (or + (\= $Attr $A) + (\= $Value $V)) (al2vl $Attr $AttrList $Value $ValueList))) +; + + + (= + (my-sort $Rel $SortAttrs $Tuples $Sorted) + ( (rel $Rel $Attrs) + (listdiff $Attrs $SortAttrs $RestAttrs) + (append $SortAttrs $RestAttrs $NewAttrs) + (reorder $Tuples $NewAttrs $NewTuples) + (setof0 $T + (member $T $NewTuples) $TmpSorted) + (reorder $TmpSorted $Attrs $Sorted))) +; + + + + (= + (reorder () $Attrs ()) True) +; + + (= + (reorder + (Cons $T $Ts) $Attrs + (Cons $NewT $NewTs)) + ( (values $Rel $Attrs $Values $T) + (=.. $NewT + (Cons $Rel $Values)) + (reorder $Ts $Attrs $NewTs))) +; + + + + (= + (splitsort $Ts $Dep $SortedTs) + (splitsort $Ts $Dep $SortedTs 0 $N 0 $M)) +; + + + (= + (splitsort $Ts $Dep $SortedTs + (, $N $M)) + (splitsort $Ts $Dep $SortedTs 0 $N 0 $M)) +; + + + (= + (splitsort () $Dep () $N $N $M $M) True) +; + + (= + (splitsort + (Cons $Tuple $Tuples) $Dep + (Cons $Equals $SortedUnEquals) $N0 $N $M0 $M) + ( (partition $Tuples $Tuple $Dep $Equals $UnEquals $M0 $M1) + (is $N1 + (+ $N0 1)) + (set-det) + (splitsort $UnEquals $Dep $SortedUnEquals $N1 $N $M1 $M))) +; + + + + (= + (partition Nil $Tuple $Dep + (:: $Tuple) Nil $M0 $M) + (is $M + (+ $M0 1))) +; + + (= + (partition + (Cons $T $Ts) $Tuple $Dep $Es $UnEs $M0 $M) + ( (horn $Dep + (= $Head + ($Tuple $Tuple2))) + (det-if-then-else + (= $Tuple2 $T) + (, + (= $Es + (Cons $T $Es1)) + (= $UnEs $UnEs1) + (is $M1 + (+ $M0 1))) + (det-if-then otherwise + (, + (= $Es $Es1) + (= $UnEs + (Cons $T $UnEs1)) + (= $M1 $M0)))) + (set-det) + (partition $Ts $Tuple $Dep $Es1 $UnEs1 $M1 $M))) +; + + + + (= + (joinsort $Parts $Dep $NotContr $Contr) + (joinsort $Parts $Dep Nil $NotContr Nil $Contr)) +; + + + (= + (joinsort () $Dep $NotContr $NotContr $Contr $Contr) True) +; + + (= + (joinsort + (Cons $Part $Parts) $Dep $NC0 $NC $C0 $C) + ( (contr $Part Nil $Dep $Tuples $Answer) + (det-if-then-else + (= $Answer no) + (, + (append $NC0 $Part $NC1) + (= $C1 $C0)) + (det-if-then otherwise + (, + (= $NC1 $NC0) + (divide1 $Part Nil $Dep $DPart) + (= $C1 + (Cons $DPart $C0))))) + (set-det) + (joinsort $Parts $Dep $NC1 $NC $C1 $C))) +; + + + (= + (decompose $DisplayIC $PosIn $PosOut $InICs $OutICs) + ( (display $IC $DisplayIC) + (contr $PosIn Nil $IC $Tuples $Answer) + (det-if-then-else + (= $Answer no) + (split $IC $PosIn $PosOut $InICs $OutICs) + (det-if-then otherwise + (divide $PosIn $IC $PosOut $InICs $OutICs))))) +; + + + + (= + (split $Dep $PosIn $PosOut $ICs + (Cons $Join $ICs)) + ( (dep $Dep $Type $Rel $From $To) (split1 $Rel $From $To $PosIn $PosOut $Join))) +; + + + + (= + (split1 $Rel $From $To $PosIn $PosOut + (join $Rel $R1 $R2)) + ( (append $From $To $In1) + (new-name $In1 $Out1 $R1) + (rel $Rel $AttrList) + (listdiff $AttrList $To $In2) + (new-name $In2 $Out2 $R2) + (splits $Rel $R1 $R2 $Out1 $Out2 $PosIn $PosTmp) + (remove-dups $PosTmp $PosOut))) +; + + + + (= + (splits $Rel $R1 $R2 $AList1 $AList2 () ()) True) +; + + (= + (splits $Rel $R1 $R2 $AList1 $AList2 + (Cons $T $Ts) + (Cons $T1 + (Cons $T2 $Rest))) + ( (values $Rel $AList1 $ValueList1 $T) + (set-det) + (=.. $T1 + (Cons $R1 $ValueList1)) + (values $Rel $AList2 $ValueList2 $T) + (=.. $T2 + (Cons $R2 $ValueList2)) + (splits $Rel $R1 $R2 $AList1 $AList2 $Ts $Rest))) +; + + (= + (splits $Rel $R1 $R2 $AList1 $AList2 + (Cons $T $Ts) + (Cons $T $Rest)) + (splits $Rel $R1 $R2 $AList1 $AList2 $Ts $Rest)) +; + + + + (= + (new-name $AListIn $AListOut $R) + ( (show-list attributes $AListIn) + (prompt-read 'relation name' $Answer) + (det-if-then-else + (= $Answer -) + (, + (concat-atom $AListIn $R) + (= $AListOut $AListIn)) + (det-if-then-else + (= $Answer +) + (, + (prompt-read 'rel(Name,AttrList)' + (rel $R $AListOut)) + (permutation $AListOut $AListIn)) + (det-if-then otherwise + (, + (= $R $Answer) + (= $AListOut $AListIn))))) + (new-rel $R $AListOut))) +; + + + + (= + (exec-rule $DisplayRule $PosIn $PosOut) + ( (display $Rule $DisplayRule) + (horn $Rule + (= $Tuple $Body)) + (setof0 $Tuple + (^ $Ts + (satisfied $Body $PosIn Nil $Ts)) $PosOut))) +; + + + + (= + (divide $PosIn $Dep $PosOut $InICs + (Cons + (plus $Rel $Names) $OutICs)) + ( (dep $Dep $Type $Rel $From $To) + (filter $PosIn $Rel $PosFiltered $Rest) + (splitsort $PosFiltered $Dep $SplitPos) + (joinsort $SplitPos $Dep $NotContr $Contr) + (find-division $Rel $NotContr $Contr $Numbers $NewPos1) + (new-preds $Rel $NewPos1 Nil $PosTmp1 Nil $Names) + (append $PosTmp1 $Rest $PosTmp2) + (decomp-again $Names $Dep $PosTmp2 $PosOut $InICs $OutICs))) +; + + + + (= + (decomp_again () $Dep $Pos $Pos $ICs $ICs) True) +; + + (= + (decomp-again + (Cons $Name $Names) $Dep $PosIn $PosOut $InICs $OutICs) + ( (det-if-then-else + (yesno (:: 'Decompose ' $Name ? )) + (, + (dep $Dep $Type $R $From $To) + (dep $NewDep $Type $Name $From $To) + (display $NewDep $DDep) + (decompose $DDep $PosIn $PosTmp $InICs $TmpICs)) + (det-if-then otherwise + (, + (= $PosTmp $PosIn) + (= $TmpICs $InICs)))) (decomp-again $Names $Dep $PosTmp $PosOut $TmpICs $OutICs))) +; + + + + (= + (divides () $Dep () ()) True) +; + + (= + (divides + (Cons $H $T) $Dep + (Cons $NewH $NewT) + (Cons $NsH $NsT)) + ( (length $H $LH) + (divide1 $H $LH $_ Nil 0 $_ $Dep $NewH $NsH) + (set-det) + (divides $T $Dep $NewT $NsT))) +; + + + + (= + (divide1 $Pos1 $Pos2 $IC $PosOut) + (divide1 $Pos1 0 $_ $Pos2 0 $_ $IC $PosOut $_)) +; + + + (= + (divide1 Nil $K $K Nil $L $L $IC Nil Nil) + (set-det)) +; + + (= + (divide1 $Pos1 $K0 $K $Pos2 $L0 $L $IC $PosOut $M) + ( (contr $Pos1 Nil $IC $Tuples $Answer) + (det-if-then-else + (or + (= $Answer yes) + (= $Answer possibly)) + (, + (= $Tuples + (Cons + (+ $T1) + (Cons + (+ $T2) $N))) + (remove $T2 $Pos1 $NewPos1) + (is $K1 + (- $K0 1)) + (= $NewPos2 + (Cons $T2 $Pos2)) + (is $L1 + (+ $L0 1)) + (= $PosOut $NewPosOut) + (= $M $NewM)) + (det-if-then + (= $Answer no) + (, + (= $NewPos1 $Pos2) + (= $K1 $L0) + (= $NewPos2 Nil) + (= $L1 0) + (= $PosOut + (Cons $Pos1 $NewPosOut)) + (= $M + (Cons $K0 $NewM))))) + (set-det) + (divide1 $NewPos1 $K1 $K $NewPos2 $L1 $L $IC $NewPosOut $NewM))) +; + + + + (= + (find-division $Rel $NotContr $Contr $Numbers $NewPos) + ( (det-if-then-else + (= $NotContr Nil) + (= $NewPos $Contr) + (det-if-then otherwise + (= $NewPos + (Cons + (:: $NotContr) $Contr)))) + (show-lists $Rel + (:: segment part) $NewPos) + (yesno (:: 'Proceed? ')))) +; + + + + (= + (new_preds $Rel () $New $New $Names $Names) True) +; + + (= + (new-preds $Rel + (Cons $H $T) $New0 $New $Names0 $Names) + ( (new-preds1 $Rel $H $New0 $New1 $Names0 $Names1) (new-preds $Rel $T $New1 $New $Names1 $Names))) +; + + + + (= + (new_preds1 $Rel () $New $New $Names $Names) True) +; + + (= + (new-preds1 $Rel + (Cons $R $Rs) $New0 $New $Names0 $Names) + ( (show-list $Rel 'partial relation' $R) + (prompt-read 'relation name' $N) + (rel $Rel $Attrs) + (new-rel $N $Attrs) + (new-relation $Rel $R $N $NewR) + (append $New0 $NewR $New1) + (add-if $N $Names0 $Names1) + (new-preds1 $Rel $Rs $New1 $New $Names1 $Names))) +; + + + + (= + (new-relation $Rel $R $N $NewR) + (bagof0 $NewT + (^ $T + (, + (member $T $R) + (new-tuple $Rel $T $N $NewT))) $NewR)) +; + + + + (= + (new-tuple $Rel $T $N $NewT) + ( (=.. $T + (Cons $Rel $Args)) + (set-det) + (=.. $NewT + (Cons $N $Args)))) +; + + (= + (new_tuple $Rel $T $N $T) True) +; + ; +; + + + (= + (show-lists $Filter $Texts $Lists) + (show-lists $Filter $Texts 1 Nil $Lists)) +; + + + (= + (show_lists $Filter $Words $N $Text ()) True) +; + + (= + (show-lists $Filter Nil $N $Text + (Cons $H $T)) + (show-list $Filter $Text + (Cons $H $T))) +; + + (= + (show-lists $Filter + (Cons $Word $Words) 1 $Text + (:: $H)) + ( (set-det) (show-lists $Filter $Words 1 $Text $H))) +; + + (= + (show-lists $Filter + (Cons $Word $Words) $N $Text + (Cons $H $T)) + ( (append $Text + (:: $Word $N --- ) $NewText) + (show-lists $Filter $Words 1 $NewText $H) + (is $N1 + (+ $N 1)) + (show-lists $Filter + (Cons $Word $Words) $N1 $Text $T))) +; + + + + (= + (show-list $Filter $Text $List) + ( (filter $List $Filter $Filtered) (show-list $Text $Filtered))) +; + + + (= + (show-list $Text Nil) + ( (set-det) + (write-list (:: 'There are no ' $Text .)) + (nl))) +; + + (= + (show-list $Text $List) + ( (write-list (:: $Text :)) + (display-list $List $List1) + (show-items $List1) + (nl))) +; + + + + (= + (choose-list $Text $List $Sel) + ( (display-list $List $List1) + (choose-items 1 $List1) + (write-list (:: $Text ? )) + (read $Ns) + (det-if-then-else + (nths $List $Ns Nil $Sel) True + (det-if-then otherwise + (, + (write 'Wrong number! Try again.') + (nl) + (choose-list $Text $List $Sel)))))) +; + + + + (= + (nths $List all Nil $List) + (set-det)) +; + + (= + (nths $In + (- $A $A) $Tmp $Out) + ( (set-det) (nths $In $A $Tmp $Out))) +; + + (= + (nths $In + (- $A $B) $Tmp $Out) + ( (set-det) + (< $A $B) + (is $A1 + (+ $A 1)) + (nths $In $A $Tmp $Tmp1) + (nths $In + (- $A1 $B) $Tmp1 $Out))) +; + + (= + (nths $In + (, $N $Ns) $Tmp $Out) + ( (set-det) + (nths $In $N $Tmp $Tmp1) + (nths $In $Ns $Tmp1 $Out))) +; + +; +; + +; +; + + (= + (nths + (Cons $X $R) 1 $Tmp + (Cons $X $Tmp)) + (set-det)) +; + + (= + (nths + (Cons $X $R) $N $Tmp $Out) + ( (is $N1 + (- $N 1)) (nths $R $N1 $Tmp $Out))) +; + + +; (error +; (syntax_error operator_expected) +; (file index/index.pl 607 6 16533)) + +; (error +; (syntax_error operator_expected) +; (file index/index.pl 611 6 16631)) + + + + (= + (choose-items $N Nil) + (nl)) +; + + (= + (choose-items $N + (Cons $H $T)) + ( (nl) + (write-list (:: $N . $H)) + (is $N1 + (+ $N 1)) + (choose-items $N1 $T))) +; + + + + (= + (display_list () ()) True) +; + + (= + (display-list + (Cons $H $T) + (Cons $DH $DT)) + ( (det-if-then-else + (switched-on horn) + (displayhorn $H $DH) + (det-if-then otherwise + (display $H $DH))) (display-list $T $DT))) +; + + + + (= + (displayhorn $X $HX) + ( (horn $X $HX) (set-det))) +; + + (= + (displayhorn $X $X) True) +; + + + + (= + (prompt-read $Question $Answer) + ( (write-list (:: $Question ? )) + (read $Answer) + (det-if-then-else + (= $Answer stop) fail + (det-if-then otherwise True)))) +; + + + + (= + (yesno $Question) + ( (write-list $Question) + (read $Answer) + (det-if-then-else + (= $Answer yes) True + (det-if-then-else + (= $Answer no) fail + (det-if-then otherwise + (, + (call $Answer) + (yesno $Question))))))) +; + + +; (error +; (syntax_error operator_expected) +; (file index/index.pl 647 4 17368)) + + + (= + (write-debug $Message) + ( (switched-on debug) + (write | ) + (write-list $Message) + (nl))) +; + + + + (= + (write-list $List) + ( (flatten $List $FList) (write-list1 $FList))) +; + + + + (= + (write_list1 ()) True) +; + + (= + (write-list1 (Cons $H $T)) + ( (write $H) (write-list1 $T))) +; + + + + (= + (quit) + (abort)) +; + + + (= + (keyword1 save ' save in Prolog database') True) +; + + (= + (keyword1 get ' get from Prolog database') True) +; + + (= + (keyword1 show ' show current') True) +; + + (= + (keyword1 count ' count current') True) +; + + (= + (keyword1 del ' delete') True) +; + + (= + (keyword1 add ' add new') True) +; + + (= + (keyword1 init ' initialise constraints') True) +; + + (= + (keyword1 find ' find constraints') True) +; + + (= + (keyword1 check ' check validity') True) +; + + (= + (keyword1 decomp ' decompose relation') True) +; + + (= + (keyword1 comp ' compose relations') True) +; + + (= + (keyword1 switch ' switch on or off') True) +; + + (= + (keyword1 set ' set level') True) +; + + (= + (keyword1 help ' get help') True) +; + + + + (= + (keyword2 pos ' positive tuples') True) +; + + (= + (keyword2 neg ' negative tuples') True) +; + + (= + (keyword2 ics ' integrity constraints') True) +; + + (= + (keyword2 calc ' calculated relations') True) +; + + + + (= + (switch cwa ' Closed-World Assumption') True) +; + + (= + (switch horn ' display in Horn form') True) +; + + (= + (switch eval ' evaluate constraints') True) +; + + (= + (switch debug ' show debugging information') True) +; + + + + (= + (level conf ' confirmation level of constraint') True) +; + + (= + (level acc ' accuracy of constraint') True) +; + + (= + (level split ' splitting level of constraint') True) +; + + + + !(forall + (^ $T + (keyword1 $W $T)) + (op 1200 fx $W)) +; + + !(forall + (^ $T + (keyword2 $W $T)) + (op 1100 fx $W)) +; + + !(forall + (^ $T + (level $W $T)) + (op 1100 fx $W)) +; + + + + (= + (commands $InICs $PosIn $NegIn) + ( (prompt-read '' $Command) + (do-command $Command $InICs $PosIn $NegIn $OutICs $PosOut $NegOut) + (set-det) + (commands $OutICs $PosOut $NegOut))) +; + + (= + (commands $InICs $PosIn $NegIn) + ( (write no) + (nl) + (set-det) + (commands $InICs $PosIn $NegIn))) +; + + + + (= + (do-command + (save $X) $ICs $Pos $Neg $ICs $Pos $Neg) + ( (set-det) (save-command $X $ICs $Pos $Neg))) +; + + (= + (do-command + (get $X) $InICs $PosIn $NegIn $OutICs $PosOut $NegOut) + ( (set-det) (get-command $X $InICs $PosIn $NegIn $OutICs $PosOut $NegOut))) +; + + (= + (do-command + (show $X) $ICs $Pos $Neg $ICs $Pos $Neg) + ( (set-det) (show-command $X $ICs $Pos $Neg))) +; + + (= + (do-command + (count $X) $ICs $Pos $Neg $ICs $Pos $Neg) + ( (set-det) (count-command $X $ICs $Pos $Neg))) +; + + (= + (do-command + (del $X) $InICs $PosIn $NegIn $OutICs $PosOut $NegOut) + ( (set-det) (del-command $X $InICs $PosIn $NegIn $OutICs $PosOut $NegOut))) +; + + (= + (do-command + (add $X) $InICs $PosIn $NegIn $OutICs $PosOut $NegOut) + ( (set-det) (add-command $X $InICs $PosIn $NegIn $OutICs $PosOut $NegOut))) +; + + (= + (do-command + (init $X) $InICs $Pos $Neg $OutICs $Pos $Neg) + ( (set-det) (init-command $X $InICs $OutICs))) +; + + (= + (do-command + (find $X) $InICs $PosIn $NegIn $OutICs $PosOut $NegOut) + ( (set-det) (find-command $X $InICs $PosIn $NegIn $OutICs $PosOut $NegOut))) +; + + (= + (do-command + (check $X) $ICs $Pos $Neg $ICs $Pos $Neg) + ( (set-det) (check-command $X $ICs $Pos $Neg))) +; + + (= + (do-command + (decomp $IC) $InICs $PosIn $Neg $OutICs $PosOut $Neg) + ( (set-det) (decompose $IC $PosIn $PosOut $InICs $OutICs))) +; + + (= + (do-command + (comp $Rule) $ICs $PosIn $Neg $ICs $PosOut $Neg) + ( (set-det) + (exec-rule $Rule $PosIn $PosNew) + (append $PosIn $PosNew $PosOut))) +; + + (= + (do-command + (switch $X) $ICs $Pos $Neg $ICs $Pos $Neg) + ( (set-det) (switch $X))) +; + + (= + (do-command + (set $X) $ICs $Pos $Neg $ICs $Pos $Neg) + ( (set-det) (set $X))) +; + + (= + (do-command + (help $Topic) $ICs $Pos $Neg $ICs $Pos $Neg) + ( (set-det) (help-command $Topic))) +; + + (= + (do-command $Command $ICs $Pos $Neg $ICs $Pos $Neg) + (call $Command)) +; + + (= + (do-command $Command $ICs $Pos $Neg $ICs $Pos $Neg) + (write ?)) +; + + + + (= + (save-command + (pos $Rel) $ICs $Pos $Neg) + (save-pos $Rel $Pos)) +; + + (= + (save-command + (neg $Rel) $ICs $Pos $Neg) + (save-neg $Rel $Neg)) +; + + (= + (save-command + (ics $T) $ICs $Pos $Neg) + (save-ics $T $ICs)) +; + + + + (= + (get-command + (pos $Rel) $ICs $PosIn $Neg $ICs $PosOut $Neg) + ( (get-pos $Rel $Pos) (append $PosIn $Pos $PosOut))) +; + + (= + (get-command + (neg $Rel) $ICs $Pos $NegIn $ICs $Pos $NegOut) + ( (get-neg $Rel $Neg) (append $NegIn $Neg $NegOut))) +; + + (= + (get-command + (ics $T) $InICs $Pos $Neg $OutICs $Pos $Neg) + ( (get-ics $T $ICs) (append $InICs $ICs $OutICs))) +; + + + + (= + (show-command all $ICs $Pos $Neg) + ( (set-det) + (show-list 'positive tuples' $Pos) + (show-list 'negative tuples' $Neg) + (show-list 'integrity constraints' $ICs))) +; + + (= + (show-command rel $ICs $Pos $Neg) + ( (set-det) + (bagof0 $R + (^ $A + (rel $R $A)) $Rels) + (show-list relations $Rels))) +; + + (= + (show-command $Other $ICs $Pos $Neg) + ( (get-list $Other $ICs $Pos $Neg $List $Text) + (set-det) + (show-list $Text $List))) +; + + (= + (show-command $Wrong $ICs $Pos $Neg) + (show-list choices + (:: 'show all' 'show rel' 'show pos all' 'show pos Rel' 'show neg all' 'show neg Rel' 'show ics all' 'show ics Rel'))) +; + + + + (= + (count-command $Filter $ICs $Pos $Neg) + ( (get-list $Filter $ICs $Pos $Neg $List $Text) + (length $List $N) + (write-list (:: 'There are ' $N ' ' $Text .)) + (nl))) +; + + + + (= + (del_command all $ICs $Pos $Neg () () ()) True) +; + + (= + (del-command + (ics $F) $InICs $Pos $Neg $OutICs $Pos $Neg) + (filter $InICs $F $Deleted $OutICs)) +; + + (= + (del-command + (pos $Rel) $ICs $PosIn $Neg $ICs $PosOut $Neg) + (filter $PosIn $Rel $Deleted $PosOut)) +; + + (= + (del-command + (neg $Rel) $ICs $Pos $NegIn $ICs $Pos $NegOut) + (filter $NegIn $Rel $Deleted $NegOut)) +; + + (= + (del-command + (rel $R) $ICs $PosIn $NegIn $ICs $PosOut $NegOut) + ( (remove-symbol &self + (rel $R $AList)) + (filter $PosIn $Rel $_ $PosOut) + (filter $NegIn $Rel $_ $NegOut))) +; + + (= + (del-command + (calc $Rel) $InICs $Pos $Neg $OutICs $Pos $Neg) + ( (remove-all-symbols &self + (proc $Rel $Proc)) (remove (proc $Rel) $InICs $OutICs))) +; + + + + (= + (add-command + (ics $DisplayIC) $ICs $Pos $Neg + (Cons $IC $ICs) $Pos $Neg) + (display $IC $DisplayIC)) +; + + (= + (add_command + (pos $Tuple) $ICs $Pos $Neg $ICs + (Cons $Tuple $Pos) $Neg) True) +; + + (= + (add_command + (neg $Tuple) $ICs $Pos $Neg $ICs $Pos + (Cons $Tuple $Neg)) True) +; + + (= + (add-command + (rel $R $AList) $ICs $Pos $Neg $ICs $Pos $Neg) + (new-rel $R $AList)) +; + + (= + (add-command + (calc $Rel) $InICs $PosIn $Neg + (Cons + (proc $Rel) $OutICs) $PosOut $Neg) + ( (ask-proc $Rel) + (filter $PosIn $Rel $RelTuples $_) + (setof0 $T + (, + (member $T $RelTuples) + (satisfied $T Nil Nil Nil)) $SatTuples) + (listdiff $PosIn $SatTuples $PosOut) + (remove + (proc $Rel) $InICs $OutICs))) +; + + + + + (= + (init-command + (ics $Rel) $InICs $OutICs) + ( (init-ICs $Rel $ICs) (append $InICs $ICs $OutICs))) +; + + + + (= + (find-command ics $InICs $PosIn $NegIn $OutICs $PosOut $NegOut) + (char $InICs $PosIn $NegIn $OutICs $PosOut $NegOut)) +; + + + + (= + (check-command + (ics $DisplayIC) $ICs $Pos $Neg) + ( (display $IC $DisplayIC) (check-ics $IC $Pos $Neg))) +; + + (= + (check-command + (pos $Tuple) $ICs $Pos $Neg) + ( (set-det) (forall (member $IC $ICs) (check-ics $IC (Cons $Tuple $Pos) $Neg)))) +; + + + + (= + (help-command commands) + ( (set-det) + (bagof0 + (with_self $W $T) + (keyword1 $W $T) $L) + (show-list Commands $L))) +; + + (= + (help-command filters) + ( (set-det) + (bagof0 + (with_self $W $T) + (keyword2 $W $T) $L) + (show-list Filters $L))) +; + + (= + (help-command switches) + ( (set-det) + (bagof0 + (with_self $W $T) + (switch $W $T) $L) + (show-list Switches $L))) +; + + (= + (help-command levels) + ( (set-det) + (bagof0 + (with_self $W $T) + (level $W $T) $L) + (show-list Levels $L))) +; + + (= + (help-command $_) + ( (help-command commands) + (help-command filters) + (help-command switches) + (help-command levels))) +; + + + + (= + (get-list + (pos $Filter) $ICs $Pos $Neg $List 'positive tuples') + (filter $Pos $Filter $List)) +; + + (= + (get-list + (neg $Filter) $ICs $Pos $Neg $List 'negative tuples') + (filter $Neg $Filter $List)) +; + + (= + (get-list + (ics $Filter) $ICs $Pos $Neg $List 'integrity constraints') + ( (filter $ICs $Filter $Tmp) (compress $Tmp $List))) +; + + + + (= + (filter $In $F $Out) + ( (template $F $Template) (setof0 $Template (member $Template $In) $Out))) +; + + + (= + (filter $In $F $Out $Rest) + ( (filter $In $F $Out) (listdiff $In $Out $Rest))) +; + + + + (= + (new-rel $R $Attrs) + ( (rel $R $Attrs) (set-det))) +; + + (= + (new-rel $R $Attrs) + ( (rel $R $A) + (set-det) + (write 'Error: relation name already in use') + (nl) + (fail))) +; + + (= + (new-rel $R $Attrs) + (add-symbol &self + (rel $R $Attrs))) +; + + + + (= + (ask-proc $Rel) + ( (prompt-read clause $Clause) + (add-symbol &self + (proc $Rel $Clause)) + (set-det) + (ask-proc $Rel))) +; + + (= + (ask_proc $Rel) True) +; + + + + (= + (get-pos $Rel $Pos) + ( (template $Rel $Tuple) (bagof0 $Tuple (pos-tuple $Tuple) $Pos))) +; + + + + (= + (get-neg $Rel $Neg) + ( (template $Rel $Tuple) (bagof0 $Tuple (neg-tuple $Tuple) $Neg))) +; + + + + (= + (get-ics $T $ICs) + ( (template $T $Templ) (bagof0 $Templ (constraint $Templ) $ICs))) +; + + + + (= + (save-pos $Rel $Pos) + ( (template $Rel $T) (forall (member $T $Pos) (myassert (pos-tuple $T))))) +; + + + + (= + (save-neg $Rel $Neg) + ( (template $Rel $T) (forall (member $T $Neg) (myassert (neg-tuple $T))))) +; + + + + (= + (save-ics $T $ICs) + ( (template $T $Templ) (forall (member $Templ $ICs) (myassert (constraint $Templ))))) +; + + + + (= + (check-ics $IC $Pos $Neg) + ( (display $IC $DisplayIC) + (evaluate $Pos $Neg $IC $Tuples $PosOut $NegOut $Answer) + (write $DisplayIC) + (det-if-then-else + (= $Answer refine) + (show-list ' is contradicted by' $Tuples) + (det-if-then-else + (= $Answer keep) + (, + (write ' is satisfied') + (nl)) + (det-if-then-else + (= $Answer + (keep $E)) + (, + (write-list (:: ' looks promising: ' $E)) + (nl)) + (det-if-then + (= $Answer + (ignore $E)) + (, + (write-list (:: ' has low confirmation: ' $E)) + (nl)))))))) +; + + + + (= + (switch $X) + ( (switch $X $T) + (remove-symbol &self + (switched_on $X)) + (set-det) + (write-list (:: $X ' is now off.')) + (nl))) +; + + (= + (switch $X) + ( (switch $X $T) + (set-det) + (add-symbol &self + (switched_on $X)) + (write-list (:: $X ' is now on.')) + (nl))) +; + +; (error +; (syntax_error operator_expected) +; (file index/index.pl 912 28 25372)) + + + + (= + (set $X) + ( (=.. $X + (Cons $Level $Rest)) + (level $Level $T) + (set-det) + (det-if-then-else + (= $Rest + (:: $Value)) + (, + (or + (, + (remove-symbol &self + (level_set $Level $V)) + (set-det)) True) + (add-symbol &self + (level_set $Level $Value))) + (det-if-then + (= $Rest Nil) + (, + (get-level $Level $L) + (write (= $Level $L)) + (nl)))))) +; + + (= + (set $_) + ( (setof0 + (= $L $V) + (^ $T + (, + (level $L $T) + (get-level $L $V))) $L) (show-list levels $L))) +; + + + + (= + (get-level $Level $Value) + ( (level $Level $T) (or (, (level-set $Level $Value) (set-det)) (= $Value 0)))) +; + + + + (= + (compare $X) + ( (=.. $X + (:: $Level $Value)) + (get-level $Level $L) + (det-if-then-else + (= $L + (+ $V)) + (>= $Value $V) + (det-if-then-else + (= $L + (- $V)) + (=< $Value $V) + (det-if-then-else + (= $L + (/ $V $A)) + (, + (is $Upper + (+ $V $A)) + (=< $Value $Upper) + (is $Lower + (- $V $A)) + (>= $Value $Lower)) + (det-if-then otherwise + (, + (write-list (:: 'Wrong level: ' (= $Level $L))) + (nl) + (break)))))))) +; + + + + + !(run *) +; + + diff --git a/index/inter.metta b/index/inter.metta new file mode 100644 index 0000000..5d14144 --- /dev/null +++ b/index/inter.metta @@ -0,0 +1,252 @@ + + (= + (show-lists $Filter $Texts $Lists) + (show-lists $Filter $Texts 1 Nil $Lists)) +; + + + (= + (show_lists $Filter $Words $N $Text ()) True) +; + + (= + (show-lists $Filter Nil $N $Text + (Cons $H $T)) + (show-list $Filter $Text + (Cons $H $T))) +; + + (= + (show-lists $Filter + (Cons $Word $Words) 1 $Text + (:: $H)) + ( (set-det) (show-lists $Filter $Words 1 $Text $H))) +; + + (= + (show-lists $Filter + (Cons $Word $Words) $N $Text + (Cons $H $T)) + ( (append $Text + (:: $Word $N --- ) $NewText) + (show-lists $Filter $Words 1 $NewText $H) + (is $N1 + (+ $N 1)) + (show-lists $Filter + (Cons $Word $Words) $N1 $Text $T))) +; + + + + (= + (show-list $Filter $Text $List) + ( (filter $List $Filter $Filtered) (show-list $Text $Filtered))) +; + + + (= + (show-list $Text Nil) + ( (set-det) + (write-list (:: 'There are no ' $Text .)) + (nl))) +; + + (= + (show-list $Text $List) + ( (write-list (:: $Text :)) + (display-list $List $List1) + (show-items $List1) + (nl))) +; + + + + (= + (choose-list $Text $List $Sel) + ( (display-list $List $List1) + (choose-items 1 $List1) + (write-list (:: $Text ? )) + (read $Ns) + (det-if-then-else + (nths $List $Ns Nil $Sel) True + (det-if-then otherwise + (, + (write 'Wrong number! Try again.') + (nl) + (choose-list $Text $List $Sel)))))) +; + + + + (= + (nths $List all Nil $List) + (set-det)) +; + + (= + (nths $In + (- $A $A) $Tmp $Out) + ( (set-det) (nths $In $A $Tmp $Out))) +; + + (= + (nths $In + (- $A $B) $Tmp $Out) + ( (set-det) + (< $A $B) + (is $A1 + (+ $A 1)) + (nths $In $A $Tmp $Tmp1) + (nths $In + (- $A1 $B) $Tmp1 $Out))) +; + + (= + (nths $In + (, $N $Ns) $Tmp $Out) + ( (set-det) + (nths $In $N $Tmp $Tmp1) + (nths $In $Ns $Tmp1 $Out))) +; + +; +; + +; +; + + (= + (nths + (Cons $X $R) 1 $Tmp + (Cons $X $Tmp)) + (set-det)) +; + + (= + (nths + (Cons $X $R) $N $Tmp $Out) + ( (is $N1 + (- $N 1)) (nths $R $N1 $Tmp $Out))) +; + + +; (error +; (syntax_error operator_expected) +; (file index/inter.pl 56 6 1401)) + +; (error +; (syntax_error operator_expected) +; (file index/inter.pl 60 6 1499)) + + + + (= + (choose-items $N Nil) + (nl)) +; + + (= + (choose-items $N + (Cons $H $T)) + ( (nl) + (write-list (:: $N . $H)) + (is $N1 + (+ $N 1)) + (choose-items $N1 $T))) +; + + + + (= + (display_list () ()) True) +; + + (= + (display-list + (Cons $H $T) + (Cons $DH $DT)) + ( (det-if-then-else + (switched-on horn) + (displayhorn $H $DH) + (det-if-then otherwise + (display $H $DH))) (display-list $T $DT))) +; + + + + (= + (displayhorn $X $HX) + ( (horn $X $HX) (set-det))) +; + + (= + (displayhorn $X $X) True) +; + + + + (= + (prompt-read $Question $Answer) + ( (write-list (:: $Question ? )) + (read $Answer) + (det-if-then-else + (= $Answer stop) fail + (det-if-then otherwise True)))) +; + + + + (= + (yesno $Question) + ( (write-list $Question) + (read $Answer) + (det-if-then-else + (= $Answer yes) True + (det-if-then-else + (= $Answer no) fail + (det-if-then otherwise + (, + (call $Answer) + (yesno $Question))))))) +; + + +; (error +; (syntax_error operator_expected) +; (file index/inter.pl 96 4 2236)) + + + (= + (write-debug $Message) + ( (switched-on debug) + (write | ) + (write-list $Message) + (nl))) +; + + + + (= + (write-list $List) + ( (flatten $List $FList) (write-list1 $FList))) +; + + + + (= + (write_list1 ()) True) +; + + (= + (write-list1 (Cons $H $T)) + ( (write $H) (write-list1 $T))) +; + + + + (= + (quit) + (abort)) +; + + diff --git a/index/main.metta b/index/main.metta new file mode 100644 index 0000000..c4ddfc5 --- /dev/null +++ b/index/main.metta @@ -0,0 +1,88 @@ + + !(unknown $_ fail) +; + + !(no-style-check all) +; + + + !(compile (library basics)) +; + + !(compile (library lists)) +; + + !(compile (library sets)) +; + + !(compile (library not)) +; + +; +; + + + !(dynamic (/ switched-on 1)) +; + + !(dynamic (/ level-set 2)) +; + + + + (= + (switched_on cwa) True) +; + + (= + (switched_on eval) True) +; + + (= + (switched_on debug) True) +; + + + + (= + (level_set acc + (+ 0.8)) True) +; + + (= + (level_set conf + (+ 2)) True) +; + + (= + (level_set split + (/ 0.5 0.1)) True) +; + + + + !((compile utils) + (compile char) + (compile eval) + (compile hooks) + (compile object) + (compile sort) + (compile decomp)) +; + + !((compile inter) (compile commands)) +; + + + + (= + (run) + (commands Nil Nil Nil)) +; + + + + !(run *) +; + + diff --git a/index/object.metta b/index/object.metta new file mode 100644 index 0000000..1f83426 --- /dev/null +++ b/index/object.metta @@ -0,0 +1,89 @@ + + (= + (diff $Tuple1 $Tuple2 $Diff) + (diff $Tuple1 $Tuple2 $Rel $Equal $Diff)) +; + + + (= + (diff $Tuple1 $Tuple2 $Rel $Equal $Diff) + ( (=.. $Tuple1 + (Cons $Rel $Values1)) + (=.. $Tuple2 + (Cons $Rel $Values2)) + (rel $Rel $AttrList) + (diff1 $Values1 $Values2 $AttrList $Equal $Diff))) +; + + + + (= + (diff1 () () () () ()) True) +; + ; +; + + (= + (diff1 + (Cons $V $Values1) + (Cons $V $Values2) + (Cons $A $AttrList) + (Cons $A $Equal) $Diff) + (diff1 $Values1 $Values2 $AttrList $Equal $Diff)) +; + + (= + (diff1 + (Cons $V1 $Values1) + (Cons $V2 $Values2) + (Cons $A $AttrList) $Equal + (Cons $A $Diff)) + ( (\= $V1 $V2) (diff1 $Values1 $Values2 $AttrList $Equal $Diff))) +; + + + + (= + (values $_ () () $_) True) +; + + (= + (values $Rel + (Cons $Attr $AttrList) + (Cons $Value $ValueList) $Tuple) + ( (value $Rel $Attr $Value $Tuple) (values $Rel $AttrList $ValueList $Tuple))) +; + + + + (= + (value $Rel $Attr $Value $Tuple) + ( (rel $Rel $AttrList) + (al2vl $Attr $AttrList $Value $ValueList) + (=.. $Tuple + (Cons $Rel $ValueList)))) +; + + + + (= + (al2vl $_ () $_ ()) True) +; + + (= + (al2vl $Attr + (Cons $Attr $AttrList) $Value + (Cons $Value $ValueList)) + (al2vl $Attr $AttrList $Value $ValueList)) +; + + (= + (al2vl $Attr + (Cons $A $AttrList) $Value + (Cons $V $ValueList)) + ( (or + (\= $Attr $A) + (\= $Value $V)) (al2vl $Attr $AttrList $Value $ValueList))) +; + + diff --git a/index/sort.metta b/index/sort.metta new file mode 100644 index 0000000..fe4724b --- /dev/null +++ b/index/sort.metta @@ -0,0 +1,123 @@ + + (= + (my-sort $Rel $SortAttrs $Tuples $Sorted) + ( (rel $Rel $Attrs) + (listdiff $Attrs $SortAttrs $RestAttrs) + (append $SortAttrs $RestAttrs $NewAttrs) + (reorder $Tuples $NewAttrs $NewTuples) + (setof0 $T + (member $T $NewTuples) $TmpSorted) + (reorder $TmpSorted $Attrs $Sorted))) +; + + + + (= + (reorder () $Attrs ()) True) +; + + (= + (reorder + (Cons $T $Ts) $Attrs + (Cons $NewT $NewTs)) + ( (values $Rel $Attrs $Values $T) + (=.. $NewT + (Cons $Rel $Values)) + (reorder $Ts $Attrs $NewTs))) +; + + + + (= + (splitsort $Ts $Dep $SortedTs) + (splitsort $Ts $Dep $SortedTs 0 $N 0 $M)) +; + + + (= + (splitsort $Ts $Dep $SortedTs + (, $N $M)) + (splitsort $Ts $Dep $SortedTs 0 $N 0 $M)) +; + + + (= + (splitsort () $Dep () $N $N $M $M) True) +; + + (= + (splitsort + (Cons $Tuple $Tuples) $Dep + (Cons $Equals $SortedUnEquals) $N0 $N $M0 $M) + ( (partition $Tuples $Tuple $Dep $Equals $UnEquals $M0 $M1) + (is $N1 + (+ $N0 1)) + (set-det) + (splitsort $UnEquals $Dep $SortedUnEquals $N1 $N $M1 $M))) +; + + + + (= + (partition Nil $Tuple $Dep + (:: $Tuple) Nil $M0 $M) + (is $M + (+ $M0 1))) +; + + (= + (partition + (Cons $T $Ts) $Tuple $Dep $Es $UnEs $M0 $M) + ( (horn $Dep + (= $Head + ($Tuple $Tuple2))) + (det-if-then-else + (= $Tuple2 $T) + (, + (= $Es + (Cons $T $Es1)) + (= $UnEs $UnEs1) + (is $M1 + (+ $M0 1))) + (det-if-then otherwise + (, + (= $Es $Es1) + (= $UnEs + (Cons $T $UnEs1)) + (= $M1 $M0)))) + (set-det) + (partition $Ts $Tuple $Dep $Es1 $UnEs1 $M1 $M))) +; + + + + (= + (joinsort $Parts $Dep $NotContr $Contr) + (joinsort $Parts $Dep Nil $NotContr Nil $Contr)) +; + + + (= + (joinsort () $Dep $NotContr $NotContr $Contr $Contr) True) +; + + (= + (joinsort + (Cons $Part $Parts) $Dep $NC0 $NC $C0 $C) + ( (contr $Part Nil $Dep $Tuples $Answer) + (det-if-then-else + (= $Answer no) + (, + (append $NC0 $Part $NC1) + (= $C1 $C0)) + (det-if-then otherwise + (, + (= $NC1 $NC0) + (divide1 $Part Nil $Dep $DPart) + (= $C1 + (Cons $DPart $C0))))) + (set-det) + (joinsort $Parts $Dep $NC1 $NC $C1 $C))) +; + + diff --git a/index/train.metta b/index/train.metta new file mode 100644 index 0000000..ccbbe2d --- /dev/null +++ b/index/train.metta @@ -0,0 +1,193 @@ + + !(dynamic (/ rel 2)) +; + + !(dynamic (/ pos-tuple 1)) +; + + !(dynamic (/ neg-tuple 1)) +; + + + + (= + (rel train + (direction hour minutes stop1)) True) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (pos-tuple (train $Direction $Hour $Minutes $Stop1)) + (normaltrain $Direction $Hour $Minutes $Stop1)) +; + + (= + (pos-tuple (train $Direction $Hour $Minutes $Stop1)) + (specialtrain $Direction $Hour $Minutes $Stop1)) +; + + + + (= + (normaltrain $Direction $Hour $Minutes $Stop1) + ( (hour $Hour) (fasttrain $Direction $Minutes $Stop1))) +; + + (= + (normaltrain $Direction $Hour $Minutes $Stop1) + ( (hour $Hour) (slowtrain $Direction $Minutes $Stop1))) +; + + + + (= + (fasttrain $Direction $Minutes $Stop1) + ( (fasttrain $Direction $Minutes) (fasttrain-stop1 $Direction $Stop1))) +; + + + + (= + (slowtrain $Direction $Minutes $Stop1) + ( (slowtrain $Direction $Minutes) (slowtrain-stop1 $Direction $Stop1))) +; + + (= + (slowtrain $Direction $Minutes $Stop1) + ( (slowtrain $Direction $Minutes1) + (is $Minutes + (+ $Minutes1 30)) + (slowtrain-stop1 $Direction $Stop1))) +; + + + + (= + (fasttrain utrecht 8) True) +; + + (= + (fasttrain tilburg 10) True) +; + + (= + (fasttrain maastricht 10) True) +; + + (= + (fasttrain utrecht 25) True) +; + + + + (= + (fasttrain_stop1 utrecht + (- den bosch)) True) +; + + (= + (fasttrain_stop1 tilburg tilburg) True) +; + + (= + (fasttrain_stop1 maastricht weert) True) +; + + + + (= + (slowtrain utrecht 13) True) +; + + (= + (slowtrain tilburg 17) True) +; + + + + (= + (slowtrain_stop1 utrecht + (- eindhoven bkln)) True) +; + + (= + (slowtrain_stop1 tilburg + (- eindhoven bkln)) True) +; + + + + (= + (specialtrain utrecht 8 31 utrecht) True) +; + + + + (= + (hour 8) True) +; + + (= + (hour 9) True) +; + +; +; + +; +; + + diff --git a/index/utils.metta b/index/utils.metta new file mode 100644 index 0000000..3511cad --- /dev/null +++ b/index/utils.metta @@ -0,0 +1,129 @@ + + (= + (listdiff $L () $L) True) +; + + (= + (listdiff $L + (Cons $H $T) $V) + ( (remove $H $L $L1) (listdiff $L1 $T $V))) +; + + + + (= + (remove $_ () ()) True) +; + + (= + (remove $H + (Cons $H $T) $L) + (remove $H $T $L)) +; + + (= + (remove $X + (Cons $H $T) + (Cons $H $L)) + ( (remove $X $T $L) (\= $X $H))) +; + + + + (= + (select-two + (Cons $H $T) $H $Y) + (member $Y $T)) +; + + (= + (select-two + (Cons $H $T) $X $Y) + (select-two $T $X $Y)) +; + + + + (= + (forall $Goal $Condition) + ( (bagof0 $Condition $Goal $List) (forall1 $List))) +; + + + + (= + (forall1 ()) True) +; + + (= + (forall1 (Cons $H $T)) + ( (call $H) (forall1 $T))) +; + + + + (= + (bagof0 $T $G $L) + ( (bagof $T $G $L) (set-det))) +; + + (= + (bagof0 $T $G ()) True) +; + + + + (= + (setof0 $T $G $L) + ( (setof $T $G $L) (set-det))) +; + + (= + (setof0 $T $G ()) True) +; + + +; (error +; (syntax_error operator_expected) +; (file index/utils.pl 37 4 521)) + + + + (= + (add-if $X $Ys $Ys) + ( (member $X $Ys) (set-det))) +; + + (= + (add_if $X $Ys + (Cons $X $Ys)) True) +; + + + + (= + (flatten $Xs $Ys) + (flatten-dl $Xs Nil $Ys)) +; + + + + (= + (flatten-dl Nil $Ys $Ys) + (set-det)) +; + + (= + (flatten-dl + (Cons $X $Xs) $Ys0 $Ys) + ( (set-det) + (flatten-dl $Xs $Ys0 $Ys1) + (flatten-dl $X $Ys1 $Ys))) +; + + (= + (flatten_dl $X $Xs + (Cons $X $Xs)) True) +; + + diff --git a/invers/invers.metta b/invers/invers.metta new file mode 100644 index 0000000..cf3f784 --- /dev/null +++ b/invers/invers.metta @@ -0,0 +1,1011 @@ + + !(dynamic (/ flat 1)) +; + + !(dynamic (/ internal 1)) +; + + +; +; + +; +; + +; +; + + + + (= + (dynamic $N $A) + (dynamic (/ $N $A))) +; + + +; +; + +; +; + + +; +; + +; +; + + +; +; + +; +; + + + + (= + (numbervars $T $Min $Max) + (numbervars $T %VAR $Min $Max)) +; + + + + !(:: (logic *)) +; + + + + (= + (absorption1 $Clause $Resolvent $InducedClause) + ( (split $Clause $ClauseHead $ClauseBody) + (split $Resolvent $ResolventHead $ResolventBody) + (step-1 $ClauseBody $ResolventBody $RestClauseBody $Subst_2) + (subst + (:: $ClauseHead) $Subst_2 + (:: $NewClauseHead)) + (step-2 $NewClauseHead $RestClauseBody $IntermediaryBody) + (join $ResolventHead $IntermediaryBody $IntermediaryClause) + (copy $IntermediaryClause $InducedClause))) +; + + + + (= + (split + (= $Head True) $Head Nil) + (set-det)) +; + + (= + (split + (= $Head $Body) $Head $BodyList) + ( (split $Body $_ $BodyList) (set-det))) +; + + (= + (split + (, $Prem $Prems) $_ + (Cons $Prem $RestPrems)) + ( (split $Prems $_ $RestPrems) (set-det))) +; + + (= + (split $Prem $_ + ($Prem)) True) +; + + + + (= + (join $Head $PremList + (= $Head $Prems)) + (join $PremList $Prems)) +; + + + (= + (join + (:: $Prem) $Prem) + (set-det)) +; + + (= + (join + (Cons $Prem $Prems) + (, $Prem $RestPrems)) + (join $Prems $RestPrems)) +; + + + + (= + (step-1 $ClauseBody $ResolventBody $ResolventRest $Subst) + ( (choose-common-parts $ResolventBody $ClauseBody $Beta1 $Beta2) + (not (not (subset $Beta1 $ClauseBody))) + (substitution $ClauseBody $Beta1 $Subst) + (subtract-v $Beta1 $ResolventBody $ResolventRest))) +; + + + + (= + (choose-common-parts $List1 $List2 $Sublist1 $Sublist2) + ( (findbag $MGT + (, + (member $Pred $List1) + (functor $Pred $N $A) + (functor $MGT $N $A)) $MGTS1) + (findbag $MGT + (, + (member $Pred $List2) + (functor $Pred $N $A) + (functor $MGT $N $A)) $MGTS2) + (set-det) + (dropping-condition-intersection $MGTS1 $MGTS2 $MGTS) + (copy $MGTS $Sublist1) + (copy $MGTS $Sublist2) + (subset $Sublist1 $List1) + (subset $Sublist2 $List2))) +; + + + + (= + (dropping_condition_intersection () $_ ()) True) +; + + (= + (dropping-condition-intersection + (Cons $X $R) $Y + (Cons $X $Z)) + ( (member $X1 $Y) + (not (not (= $X $X1))) + (set-det) + (dropping-condition-delete $X $Y $Y1) + (dropping-condition-intersection $R $Y1 $Z))) +; + + (= + (dropping-condition-intersection + (Cons $X $R) $Y $Z) + (dropping-condition-intersection $R $Y $Z)) +; + + + + (= + (dropping-condition-delete $X + (Cons $Y $Ys) $Ys) + ( (not (not (= $X $Y))) (set-det))) +; + + (= + (dropping-condition-delete $X + (Cons $Y $Ys) + (Cons $Y $Zs)) + (dropping-condition-delete $X $Ys $Zs)) +; + + + + (= + (step-2 $ClauseHead $RestClauseBody $IntermediaryBody) + (union-v + (:: $ClauseHead) $RestClauseBody $IntermediaryBody)) +; + + + + (= + (absorption2 $Clause $Resolvent $InducedClause) + ( (flatten $Clause $ClauseHead $ClauseBody) + (flatten $Resolvent $ResolventHead $ResolventBody) + (step-1 $ClauseBody $ResolventBody $RestClauseBody $Subst_2) + (subst + (:: $ClauseHead) $Subst_2 + (:: $NewClauseHead)) + (step-2 $NewClauseHead $RestClauseBody $IntermediaryBody) + (unflatten + (:: $ResolventHead) $IntermediaryBody $IntermediaryClause) + (copy $IntermediaryClause $InducedClause))) +; + + + + (= + (flatten + (= $Conclusion $Conjunction) $NewConclusion $NewPremisses) + ( (flatten $Conclusion + (:: $NewConclusion) $FunctionPrems1 $Dictionary) + (flatten $Conjunction $Prems $FunctionPrems2 $Dictionary) + (union-v $FunctionPrems1 $FunctionPrems2 $FunctionPrems) + (union-v $FunctionPrems $Prems $NewPremisses) + (set-det))) +; + + + (= + (flatten + (, $Prem $Prems) $NewPremisses $FunctionPrems $Dictionary) + ( (flatten $Prem $NewPrem $FunctionPrems1 $Dictionary) + (flatten $Prems $NewPrems $FunctionPrems2 $Dictionary) + (union-v $NewPrem $NewPrems $NewPremisses) + (union-v $FunctionPrems1 $FunctionPrems2 $FunctionPrems) + (set-det))) +; + + + (= + (flatten () () () $_) True) +; + + (= + (flatten + (Cons $Const $Terms) + (Cons $Var $NewVars) $ResultPrems $Dictionary) + ( (atomic $Const) + (lookup $Const $Dictionary $Var) + (conc $Const -p $NewName) + (flat-assertion $NewName $Const) + (=.. $Pred + (:: $NewName $Var)) + (flatten $Terms $NewVars $NewPrems $Dictionary) + (set-det) + (union-v + (:: $Pred) $NewPrems $ResultPrems))) +; + + (= + (flatten + (Cons $Term $Terms) + (Cons $Term $NewVars) $NewPrems $Dictionary) + ( (var $Term) + (set-det) + (flatten $Terms $NewVars $NewPrems $Dictionary))) +; + + (= + (flatten + (Cons $Term $Terms) + (Cons $NewVar $NewVars) $NewPrems $Dictionary) + ( (=.. $Term + (Cons $N $Args)) + (conc $N -p $NN) + (flatten $Args $NewTerms $Prems $Dictionary) + (append $NewTerms + (:: $NewVar) $NewArgs) + (=.. $NewTerm + (Cons $NN $NewArgs)) + (flat-assertion $NN $NewTerms $N $NewTerms) + (flatten $Terms $NewVars $NP $Dictionary) + (set-det) + (union-v + (:: $NewTerm) $NP $ERG) + (union-v $Prems $ERG $NewPrems))) +; + + + (= + (flatten True Nil Nil $_) + (set-det)) +; + + (= + (flatten False Nil Nil $_) + (set-det)) +; + + (= + (flatten + (not $Pred) + (:: (not $NewPred)) $NewPrems $Dictionary) + ( (set-det) (flatten $Pred (:: $NewPred) $NewPrems $Dictionary))) +; + + (= + (flatten $Pred + (:: $Pred) Nil $Dictionary) + ( (atomic $Pred) (set-det))) +; + + (= + (flatten $Pred + (:: $NewPred) $NewPrems $Dictionary) + ( (set-det) + (=.. $Pred + (Cons $N $Args)) + (flatten $Args $NewArgs $NewPrems $Dictionary) + (=.. $NewPred + (Cons $N $NewArgs)))) +; + + + + (= + (flat-assertion $Name $Term) + ( (=.. $NewRelation + (:: $Name $Term)) + (copy $NewRelation $NR) + (skolemize + (:: $NR) 0 $_) + (get-symbols &self + (= + (flat $NR) true)) + (get-symbols &self + (= + (flat $NewRelation) true)) + (set-det))) +; + + (= + (flat-assertion $Name $Term) + ( (=.. $NewRelation + (:: $Name $Term)) + (add-symbol &self + (flat $NewRelation)) + (set-det))) +; + + + (= + (flat-assertion $Name1 $Args $Name2 $Terms) + ( (=.. $OldTerm + (Cons $Name2 $Terms)) + (append $Args + (:: $OldTerm) $NewArgs) + (=.. $NewRelation + (Cons $Name1 $NewArgs)) + (copy $NewRelation $NR) + (skolemize + (:: $NR) 0 $_) + (get-symbols &self + (= + (flat $NR) true)) + (get-symbols &self + (= + (flat $NewRelation) true)) + (set-det))) +; + + (= + (flat-assertion $Name1 $Args $Name2 $Terms) + ( (=.. $OldTerm + (Cons $Name2 $Terms)) + (append $Args + (:: $OldTerm) $NewArgs) + (=.. $NewRelation + (Cons $Name1 $NewArgs)) + (add-symbol &self + (flat $NewRelation)))) +; + + + + (= + (unflatten + (:: $Head) $BodyList + (= $Head $Body)) + ( (unflatten $BodyList $Body) (set-det))) +; + + + (= + (unflatten () true) True) +; + + (= + (unflatten + (:: $Prem) $Prem) + ( (functor $Prem $N $A) + (functor $P $N $A) + (not (get-symbols &self (= (flat $P) true))) + (set-det) + (not (get-symbols &self (= (flat $Prem) true))) + (set-det))) +; + + (= + (unflatten + (Cons $Prem $Prems) + (, $Prem $RestPrems)) + ( (functor $Prem $N $A) + (functor $P $N $A) + (not (get-symbols &self (= (flat $P) true))) + (set-det) + (not (get-symbols &self (= (flat $Prem) true))) + (unflatten $Prems $RestPrems) + (set-det))) +; + + (= + (unflatten + (Cons $Prem $Prems) $RestPrems) + ( (get-symbols &self + (= + (flat $Prem) true)) (unflatten $Prems $RestPrems))) +; + + + + (= + (intra-construction1 $Resolvent1 $Resolvent2 $InducedRules) + ( (split $Resolvent1 $Resolvent1Head $Resolvent1Body) + (split $Resolvent2 $Resolvent2Head $Resolvent2Body) + (step-1 $Resolvent1Head $Resolvent1Body $Resolvent2Head $Resolvent2Body $ClauseHead $Alpha $Resolvent1BodyRest $Resolvent2BodyRest $Subst1 $Subst2) + (step-2 $ClauseHead $Alpha $Resolvent1BodyRest $Subst1 $Resolvent2BodyRest $Subst2 $Vars) + (step-3-1 $ClauseHead $Vars $Alpha $Resolvent1BodyRest $Subst1 $Resolvent2BodyRest $Subst2 $InducedRules))) +; + + + + (= + (step-1 $Resolvent1Head $Resolvent1Body $Resolvent2Head $Resolvent2Body + (:: $ClauseHead) $Alpha $Resolvent1BodyRest $Resolvent2BodyRest $Subst1 $Subst2) + ( (choose-common-parts $Resolvent1Body $Resolvent2Body $AlphaTheta1 $AlphaTheta2) + (length $AlphaTheta1 $X) + (length $AlphaTheta2 $X) + (> $X 0) + (subtract-v $AlphaTheta1 $Resolvent1Body $Resolvent1BodyRest) + (subtract-v $AlphaTheta2 $Resolvent2Body $Resolvent2BodyRest) + (lgg + (:: $Resolvent1Head $AlphaTheta1) + (:: $Resolvent2Head $AlphaTheta2) + (:: $ClauseHead $Alpha)) + (substitution + (:: $ClauseHead $Alpha) + (:: $Resolvent1Head $AlphaTheta1) $Subst1) + (substitution + (:: $ClauseHead $Alpha) + (:: $Resolvent2Head $AlphaTheta2) $Subst2))) +; + + + + (= + (step-2 $ClauseHead $Alpha $Resolvent1BodyRest $Subst1 $Resolvent2BodyRest $Subst2 $Vars) + ( (varlist $Resolvent1BodyRest $RBR1Vars) + (varlist $Resolvent2BodyRest $RBR2Vars) + (varlist $ClauseHead $CHVars) + (varlist $Alpha $AVars) + (inv-subst $RBR1 $Subst1 $RBR1Vars) + (inv-subst $RBR2 $Subst2 $RBR2Vars) + (or + (= $CHVars Nil) + (, + (intersection-v $CHVars $AVars $XI) + (not (== $XI Nil)))) + (union-v $CHVars $AVars $Xs) + (union-v $RBR1 $RBR2 $RBRU) + (intersection-v $RBRU $Xs $Vars) + (set-det))) +; + + + + (= + (step-3-1 + (:: $ClauseHead) $Vars $Alpha $Resolvent1BodyRest $Subst1 $Resolvent2BodyRest $Subst2 + (:: $R1 $R2 $R3)) + ( (gensym $Name P) + (=.. $X + (Cons $Name $Vars)) + (subst + (:: $X) $Subst1 + (:: $X1)) + (subst + (:: $X) $Subst2 + (:: $X2)) + (join $X1 $Resolvent1BodyRest $QR1) + (join $X2 $Resolvent2BodyRest $QR2) + (copy $QR1 $NQR1) + (copy $QR2 $NQR2) + (numbervars $NQR1 0 $_) + (numbervars $NQR2 0 $_) + (nl) + (write ' Predicate invention') + (nl) + (nl) + (tab 3) + (write $NQR1) + (nl) + (tab 3) + (write $NQR2) + (nl) + (nl) + (write ' Has this predicate a meaning (y/n)? ') + (read $Answer) + (nl) + (or + (, + (= $Answer n) + (set-det) + (fail)) + (, + (= $Answer y) + (set-det))) + (write ' How shall I name the predicate ? ') + (read $NewName) + (nl) + (=.. $NP + (Cons $NewName $Vars)) + (subst + (:: $NP) $Subst1 + (:: $NP1)) + (subst + (:: $NP) $Subst2 + (:: $NP2)) + (join $NP1 $Resolvent1BodyRest $R1) + (join $NP2 $Resolvent2BodyRest $R2) + (append + (:: $NP) $Alpha $ClauseBody) + (join $ClauseHead $ClauseBody $R3) + (set-det))) +; + + + + (= + (intra-construction2 $Resolvent1 $Resolvent2 $InducedClauses) + ( (flatten $Resolvent1 $Resolvent1Head $Resolvent1Body) + (flatten $Resolvent2 $Resolvent2Head $Resolvent2Body) + (step-1 $Resolvent1Head $Resolvent1Body $Resolvent2Head $Resolvent2Body $ClauseHead $Alpha $Resolvent1BodyRest $Resolvent2BodyRest $Subst1 $Subst2) + (step-2 $ClauseHead $Alpha $Resolvent1BodyRest $Subst1 $Resolvent2BodyRest $Subst2 $Vars) + (step-3-2 $ClauseHead $Vars $Alpha $Resolvent1BodyRest $Subst1 $Resolvent2BodyRest $Subst2 $InducedClauses))) +; + + + + (= + (step-3-2 $ClauseHead $Vars $Alpha $Resolvent1BodyRest $Subst1 $Resolvent2BodyRest $Subst2 + (:: $R1 $R2 $R3)) + ( (gensym $Name P) + (=.. $X + (Cons $Name $Vars)) + (subst + (:: $X) $Subst1 $X1) + (subst + (:: $X) $Subst2 $X2) + (unflatten $X1 $Resolvent1BodyRest $QR1) + (unflatten $X2 $Resolvent2BodyRest $QR2) + (copy $QR1 $NQR1) + (copy $QR2 $NQR2) + (numbervars $NQR1 0 $_) + (numbervars $NQR2 0 $_) + (nl) + (write ' Predicate invention') + (nl) + (nl) + (tab 3) + (write $NQR1) + (nl) + (tab 3) + (write $NQR2) + (nl) + (nl) + (write ' Has this predicate a meaning (y/n)? ') + (read $Answer) + (nl) + (or + (, + (= $Answer n) + (set-det) + (fail)) + (, + (= $Answer y) + (set-det))) + (write ' How shall I name the predicate ? ') + (read $NewName) + (nl) + (=.. $NP + (Cons $NewName $Vars)) + (subst + (:: $NP) $Subst1 $NP1) + (subst + (:: $NP) $Subst2 $NP2) + (unflatten $NP1 $Resolvent1BodyRest $R1) + (unflatten $NP2 $Resolvent2BodyRest $R2) + (append + (:: $NP) $Alpha $ClauseBody) + (unflatten $ClauseHead $ClauseBody $R3) + (set-det))) +; + + + + (= + (subst () $_ ()) True) +; + + (= + (subst + (Cons $X $Xs) $Subst + (Cons $Y $Ys)) + ( (member + (/ $U $V) $Subst) + (== $X $U) + (= $Y $V) + (subst $Xs $Subst $Ys) + (set-det))) +; + + (= + (subst + (Cons $Prem $Prems) $Subst + (Cons $NewPrem $NewPrems)) + ( (=.. $Prem + (Cons $F $Args)) + (subst $Args $Subst $NewArgs) + (=.. $NewPrem + (Cons $F $NewArgs)) + (subst $Prems $Subst $NewPrems) + (set-det))) +; + + (= + (subst + (Cons $X $Xs) $Subst + (Cons $X $Ys)) + (subst $Xs $Subst $Ys)) +; + + + + (= + (inv_subst () $_ ()) True) +; + + (= + (inv-subst + (Cons $X $Xs) $Subst + (Cons $Y $Ys)) + ( (member + (/ $U $V) $Subst) + (== $Y $V) + (= $X $U) + (inv-subst $Xs $Subst $Ys) + (set-det))) +; + + (= + (inv-subst + (Cons $Prem $Prems) $Subst + (Cons $NewPrem $NewPrems)) + ( (=.. $NewPrem + (Cons $F $NewArgs)) + (inv-subst $Args $Subst $NewArgs) + (=.. $Prem + (Cons $F $Args)) + (inv-subst $Prems $Subst $NewPrems) + (set-det))) +; + + (= + (inv-subst + (Cons $X $Xs) $Subst + (Cons $X $Ys)) + (inv-subst $Xs $Subst $Ys)) +; + + + + (= + (union_v () $X $X) True) +; + + (= + (union-v + (Cons $X $R) $Y $Z) + ( (member $U $Y) + (== $U $X) + (set-det) + (union-v $R $Y $Z))) +; + + (= + (union-v + (Cons $X $R) $Y + (Cons $X $Z)) + (union-v $R $Y $Z)) +; + + + + (= + (intersection_v () $_ ()) True) +; + + (= + (intersection-v + (Cons $X $R) $Y + (Cons $X $Z)) + ( (member $U $Y) + (== $U $X) + (set-det) + (intersection-v $R $Y $Z))) +; + + (= + (intersection-v + (Cons $X $R) $Y $Z) + (intersection-v $R $Y $Z)) +; + + + + (= + (subset () ()) True) +; + + (= + (subset + (Cons $X $Subset) + (Cons $X $List)) + (subset $Subset $List)) +; + + (= + (subset $Subset + (Cons $_ $List)) + (subset $Subset $List)) +; + + + + (= + (subtract-v + (Cons $X $Xs) $Ys $Zs) + ( (member $Y $Ys) + (== $X $Y) + (delete-v $X $Ys $Y1s) + (subtract-v $Xs $Y1s $Zs) + (set-det))) +; + + (= + (subtract-v + (Cons $X $Xs) $Ys $Zs) + (subtract-v $Xs $Ys $Zs)) +; + + (= + (subtract_v () $Xs $Xs) True) +; + + + + (= + (delete-v $X + (Cons $Y $Ys) $Ys) + ( (== $X $Y) (set-det))) +; + + (= + (delete-v $X + (Cons $Y $Ys) + (Cons $Y $Zs)) + (delete-v $X $Ys $Zs)) +; + + + + (= + (count $VAR $X) + ( (dynamic $VAR 1) + (=.. $P1 + (:: $VAR $N)) + (remove-symbol &self $P1) + (is $X + (+ $N 1)) + (=.. $P2 + (:: $VAR $X)) + (add-symbol &self $P2) + (set-det))) +; + + (= + (count $VAR 1) + ( (dynamic $VAR 1) + (=.. $P + (:: $VAR 1)) + (add-symbol &self $P))) +; + + + + (= + (gensym $SYM $N) + ( (count $N $X) (conc $N $X $SYM))) +; + + + + (= + (copy $A $B) + (or + (, + (add-symbol &self + (internal $A)) + (remove-symbol &self + (internal $B)) + (set-det)) + (, + (remove-symbol &self + (internal $_)) + (fail)))) +; + + + + (= + (lookup $Key + (d $Key $X $Left $Right) $Value) + ( (set-det) (= $X $Value))) +; + + (= + (lookup $Key + (d $Key1 $X $Left $Right) $Value) + ( (@< $Key $Key1) (lookup $Key $Left $Value))) +; + + (= + (lookup $Key + (d $Key1 $X $Left $Right) $Value) + ( (@> $Key $Key1) (lookup $Key $Right $Value))) +; + + + + (= + (conc $STR1 $STR2 $STR3) + ( (nonvar $STR1) + (nonvar $STR2) + (name $STR1 $S1) + (name $STR2 $S2) + (append $S1 $S2 $S3) + (name $STR3 $S3))) +; + + (= + (conc $STR1 $STR2 $STR3) + ( (nonvar $STR1) + (nonvar $STR3) + (name $STR1 $S1) + (name $STR3 $S3) + (append $S1 $S2 $S3) + (name $STR2 $S2))) +; + + (= + (conc $STR1 $STR2 $STR3) + ( (nonvar $STR2) + (nonvar $STR3) + (name $STR2 $S2) + (name $STR3 $S3) + (append $S1 $S2 $S3) + (name $STR1 $S1))) +; + + + + (= + (varlist $X $L) + ( (varlist $X Nil $L) (set-det))) +; + + + (= + (varlist $T $L $LO) + ( (nonvar $T) + (=.. $T + (Cons $F $A)) + (set-det) + (varlist1 $A $L $LO))) +; + + (= + (varlist $X $L $L) + ( (var $X) + (element-v $X $L) + (set-det))) +; + + (= + (varlist $X $L + (Cons $X $L)) + ( (var $X) (set-det))) +; + + + + (= + (varlist1 + (Cons $T $A) $L $LO) + ( (varlist1 $A $L $L1) + (set-det) + (varlist $T $L1 $LO))) +; + + (= + (varlist1 () $L $L) True) +; + + + + (= + (element-v $Element1 + (Cons $Element2 $Tail)) + (== $Element1 $Element2)) +; + + (= + (element-v $Element + (Cons $_ $Tail)) + (element-v $Element $Tail)) +; + + + + (= + (findbag $X $G $_) + ( (add-symbol &self + (yk_found mark)) + (call $G) + (add-symbol &self + (yk_found $X)) + (fail))) +; + + (= + (findbag $_ $_ $L) + (yk-collect-found Nil $L)) +; + + + + (= + (yk-collect-found $Acc $L) + ( (yk-getnext $X) (yk-collect-found (Cons $X $Acc) $L))) +; + + (= + (yk_collect_found $X $X) True) +; + + +; (error +; (syntax_error operator_expected) +; (file invers/invers.pl 614 33 26398)) + + + + (= + (help) + ( (write 'Load example calls with command: [Filename].') + (nl) + (write 'Run example with command: test1(X).') + (nl) + (write 'Run example with command: test2(X).') + (nl) + (write 'Run example with command: test3(X).') + (nl) + (write 'Run example with command: test4(X).') + (nl) + (write 'Run example with command: test5(X).') + (nl) + (write 'Run example with command: test6(X).') + (nl) + (write 'Run example with command: test7(X).') + (nl) + (write 'Run example with command: test8(X).') + (nl))) +; + + + + !(help *) +; + + diff --git a/invers/invers_1.metta b/invers/invers_1.metta new file mode 100644 index 0000000..510434d --- /dev/null +++ b/invers/invers_1.metta @@ -0,0 +1,201 @@ + + (= + (test1) + ( (split + (= + (< $A + (succ (succ $A))) + (< $B + (succ $B))) $Head $BodyList) (join $Head $BodyList $Rule))) +; + + + + (= + (test2) + ( (flatten + (= + (< $B + (succ $B)) True) $K $L) (flatten (= (< $A (succ (succ $A))) True) $U $V))) +; + + + + (= + (test1 $Q) + ( (= $X + (= + (mother $A $B) + ( (sex $A female) (parent $A $B)))) + (write 'Clause: ') + (write $X) + (nl) + (= $Y + (= + (grandfather $D $F) + ( (father $D $E) + (sex $E female) + (parent $E $F)))) + (write 'Resolvent: ') + (write $Y) + (nl) + (absorption1 $X $Y $Q))) +; + + + + (= + (test2 $Q) + ( (= $X + (= + (< $B $C) + (succ $B $C))) + (write 'Clause: ') + (write $X) + (nl) + (= $Y + (= + (< $A $D) + ( (succ $A $E) (succ $E $D)))) + (write 'Resolvent: ') + (write $Y) + (nl) + (absorption1 $X $Y $Q))) +; + + + + (= + (test3 $Q) + ( (= $X + (= + (mother $A $B) + ( (sex $A female) (daugther $B $A)))) + (write 'Clause: ') + (write $X) + (nl) + (= $Y + (= + (grandfather a c) + ( (father a m) + (sex m female) + (daugther c m)))) + (write 'Resolvent: ') + (write $Y) + (nl) + (absorption2 $X $Y $Q))) +; + + + + (= + (test4 $Q) + ( (= $X + (= + (< $B + (succ $B)) True)) + (write 'Clause: ') + (write $X) + (nl) + (= $Y + (= + (< $A + (succ + (succ $A))) True)) + (write 'Resolvent: ') + (write $Y) + (nl) + (absorption2 $X $Y $Q))) +; + + + + (= + (test5 $Q) + ( (= $X + (= + (grandfather $D $E) + ( (father $D $F) (mother $F $E)))) + (write 'Resolvent: ') + (write $X) + (nl) + (= $Y + (= + (grandfather $A $B) + ( (father $A $C) (father $C $B)))) + (write 'Resolvent: ') + (write $Y) + (nl) + (intra-construction1 $X $Y $Q))) +; + + + + (= + (test6 $Q) + ( (= $X + (= + (grandfather $D $E) + ( (father $D $F) (mother $F $E)))) + (write 'Resolvent: ') + (write $X) + (nl) + (= $Y + (= + (grandfather $A $B) + ( (father $A $C) (father $C $B)))) + (write 'Resolvent: ') + (write $Y) + (nl) + (intra-construction2 $X $Y $Q))) +; + + + + (= + (test7 $Q) + ( (= $X + (= + (min $D + (Cons + (succ $D) $E)) + (min $D $E))) + (write 'Resolvent: ') + (write $X) + (nl) + (= $Y + (= + (min $F + (Cons + (succ (succ $F)) $G)) + (min $F $G))) + (write 'Resolvent: ') + (write $Y) + (nl) + (intra-construction2 $X $Y $Q))) +; + + + + (= + (test8 $Q) + ( (= $X + (= + (< $B + (succ $B)) True)) + (write 'Resolvent: ') + (write $X) + (nl) + (= $Y + (= + (< $A + (succ + (succ $A))) True)) + (write 'Resolvent: ') + (write $Y) + (nl) + (intra-construction2 $X $Y $Q))) +; + + + diff --git a/invers/logic.metta b/invers/logic.metta new file mode 100644 index 0000000..a95a5f1 --- /dev/null +++ b/invers/logic.metta @@ -0,0 +1,322 @@ + + (= + (substitution $Term1 $Term2 $Sub_List) + ( (implies $Term1 $Term2) + (substitute + (:: $Term1) + (:: $Term2) $Subst1) + (sort $Subst1 $Subst2) + (remove-id $Subst2 $Sub_List) + (set-det))) +; + + +; (error +; (syntax_error operator_expected) +; (file invers/logic.pl 95 8 5563)) + + + + (= + (skolemize () $N $N) True) +; + + (= + (skolemize + (Cons $Head $Tail) $N $M) + ( (= $Head + ($var $N)) + (skolemize $Tail + (s $N) $M) + (set-det))) +; + + (= + (skolemize + (Cons $Head $Tail) $N $M) + ( (=.. $Head + (Cons $F $Tail1)) + (skolemize $Tail1 $N $O) + (skolemize $Tail $O $M))) +; + + + + (= + (substitute Nil Nil Nil) + (set-det)) +; + + (= + (substitute + (Cons $Head1 $Tail1) + (Cons $Head2 $Tail2) + (Cons + (/ $Head1 $Head2) $Tail3)) + ( (var $Head1) + (substitute $Tail1 $Tail2 $Tail3) + (set-det))) +; + + (= + (substitute + (Cons $Head1 $Tail1) + (Cons $Head2 $Tail2) $Subst) + ( (=.. $Head1 + (Cons $F1 $Tail11)) + (=.. $Head2 + (Cons $F1 $Tail22)) + (substitute $Tail11 $Tail22 $Tail33) + (substitute $Tail1 $Tail2 $Tail4) + (append $Tail33 $Tail4 $Subst) + (set-det))) +; + + + + (= + (remove-id Nil Nil) + (set-det)) +; + + (= + (remove-id + (:: $X) + (:: $X)) + (set-det)) +; + + (= + (remove-id + (Cons $A + (Cons $B $Tail)) $List) + ( (== $A $B) + (remove-id + (Cons $A $Tail) $List) + (set-det))) +; + + (= + (remove-id + (Cons $Head1 $Tail1) + (Cons $Head1 $Tail2)) + ( (remove-id $Tail1 $Tail2) (set-det))) +; + + + + (= + (lgg $Term1 $Term2 $Term3) + ( (lgg1 + (:: $Term1) + (:: $Term2) + (:: $Term3) Nil $Subst) (set-det))) +; + + + + (= + (lgg1 () () () $Subst $Subst) True) +; + + (= + (lgg1 + (Cons $Head1 $Tail1) + (Cons $Head2 $Tail2) + (Cons $Head3 $Tail3) $Subst1 $Subst3) + ( (=.. $Head1 + (Cons $F $Tail11)) + (=.. $Head2 + (Cons $F $Tail22)) + (lgg1 $Tail11 $Tail22 $Tail33 $Subst1 $Subst2) + (=.. $Head3 + (Cons $F $Tail33)) + (lgg1 $Tail1 $Tail2 $Tail3 $Subst2 $Subst3) + (set-det))) +; + + (= + (lgg1 + (Cons $Head1 $Tail1) + (Cons $Head2 $Tail2) + (Cons $Head3 $Tail3) $Subst1 $Subst2) + ( (subst-member + (/ $Head3 + (, $Head1 $Head2)) $Subst1) + (lgg1 $Tail1 $Tail2 $Tail3 $Subst1 $Subst2) + (set-det))) +; + + (= + (lgg1 + (Cons $Head1 $Tail1) + (Cons $Head2 $Tail2) + (Cons $Head3 $Tail3) $Subst1 $Subst2) + ( (lgg1 $Tail1 $Tail2 $Tail3 + (Cons + (/ $Head3 + (, $Head1 $Head2)) $Subst1) $Subst2) (set-det))) +; + + + + (= + (subst-member + (/ $A $B) + (Cons + (/ $A $C) $_)) + ( (== $B $C) (set-det))) +; + + (= + (subst-member $A + (Cons $_ $B)) + ( (subst-member $A $B) (set-det))) +; + + + + (= + (covers () $_) True) +; + + (= + (covers + (Cons $H1 $T1) $P) + ( (member $C1 $P) + (copy $C1 + (= $H1 $B1)) + (covers-body $B1 $P) + (covers $T1 $P))) +; + + + + (= + (covers_body true $_) True) +; + + (= + (covers-body + (, $H $B) $P) + ( (set-det) + (covers + (:: $H) $P) + (covers-body $B $P))) +; + + (= + (covers-body $H $P) + (covers + (:: $H) $P)) +; + + + + (= + (copy $A $B) + (or + (, + (add-symbol &self + (yap_inst $A)) + (remove-symbol &self + (yap_inst $B)) + (set-det)) + (, + (remove-symbol &self + (yap_inst $_)) + (fail)))) +; + + + + (= + (psubsumes $_ Nil) + (set-det)) +; + + (= + (psubsumes $P + (Cons $C $T)) + ( (bsubsumes $P $C) + (psubsumes $P $T) + (set-det))) +; + + +; (error +; (syntax_error operator_expected) +; (file invers/logic.pl 229 7 11814)) + + + + (= + (body-units True Nil) + (set-det)) +; + + (= + (body-units + (, $Head1 $Tail1) + (Cons + (= $Head1 True) $Tail2)) + ( (body-units $Tail1 $Tail2) (set-det))) +; + + (= + (body_units $Head + ( (:- $Head true))) True) +; + + + + (= + (goal_units () ()) True) +; + + (= + (goal-units + (Cons $Head1 $Tail1) + (Cons + (= $Head1 True) $Tail2)) + ( (goal-units $Tail1 $Tail2) (set-det))) +; + + + + (= + (p-subsumes $ClauseSet1 $Theory $ClauseSet2) + ( (append $ClauseSet1 $Theory $Program) (psubsumes $Program $ClauseSet2))) +; + + + + (= + (p-equivalent $ClauseSet1 $Theory $ClauseSet2) + ( (append $ClauseSet1 $Theory $Program1) + (psubsumes $Program1 $ClauseSet2) + (append $ClauseSet2 $Theory $Program2) + (psubsumes $Program2 $ClauseSet1))) +; + + + + + (= + (help) + ( (write 'Load example calls with command: [Filename].') + (nl) + (write 'Call examples with: test1, test2, test3a, test3b,') + (nl) + (write ' test4a, test4b, test4c, test4d, test5') + (nl))) +; + + + + !(help *) +; + + + + diff --git a/logic/logic.metta b/logic/logic.metta new file mode 100644 index 0000000..5c2af95 --- /dev/null +++ b/logic/logic.metta @@ -0,0 +1,322 @@ + + (= + (substitution $Term1 $Term2 $Sub_List) + ( (implies $Term1 $Term2) + (substitute + (:: $Term1) + (:: $Term2) $Subst1) + (sort $Subst1 $Subst2) + (remove-id $Subst2 $Sub_List) + (set-det))) +; + + +; (error +; (syntax_error operator_expected) +; (file logic/logic.pl 95 8 5563)) + + + + (= + (skolemize () $N $N) True) +; + + (= + (skolemize + (Cons $Head $Tail) $N $M) + ( (= $Head + ($var $N)) + (skolemize $Tail + (s $N) $M) + (set-det))) +; + + (= + (skolemize + (Cons $Head $Tail) $N $M) + ( (=.. $Head + (Cons $F $Tail1)) + (skolemize $Tail1 $N $O) + (skolemize $Tail $O $M))) +; + + + + (= + (substitute Nil Nil Nil) + (set-det)) +; + + (= + (substitute + (Cons $Head1 $Tail1) + (Cons $Head2 $Tail2) + (Cons + (/ $Head1 $Head2) $Tail3)) + ( (var $Head1) + (substitute $Tail1 $Tail2 $Tail3) + (set-det))) +; + + (= + (substitute + (Cons $Head1 $Tail1) + (Cons $Head2 $Tail2) $Subst) + ( (=.. $Head1 + (Cons $F1 $Tail11)) + (=.. $Head2 + (Cons $F1 $Tail22)) + (substitute $Tail11 $Tail22 $Tail33) + (substitute $Tail1 $Tail2 $Tail4) + (append $Tail33 $Tail4 $Subst) + (set-det))) +; + + + + (= + (remove-id Nil Nil) + (set-det)) +; + + (= + (remove-id + (:: $X) + (:: $X)) + (set-det)) +; + + (= + (remove-id + (Cons $A + (Cons $B $Tail)) $List) + ( (== $A $B) + (remove-id + (Cons $A $Tail) $List) + (set-det))) +; + + (= + (remove-id + (Cons $Head1 $Tail1) + (Cons $Head1 $Tail2)) + ( (remove-id $Tail1 $Tail2) (set-det))) +; + + + + (= + (lgg $Term1 $Term2 $Term3) + ( (lgg1 + (:: $Term1) + (:: $Term2) + (:: $Term3) Nil $Subst) (set-det))) +; + + + + (= + (lgg1 () () () $Subst $Subst) True) +; + + (= + (lgg1 + (Cons $Head1 $Tail1) + (Cons $Head2 $Tail2) + (Cons $Head3 $Tail3) $Subst1 $Subst3) + ( (=.. $Head1 + (Cons $F $Tail11)) + (=.. $Head2 + (Cons $F $Tail22)) + (lgg1 $Tail11 $Tail22 $Tail33 $Subst1 $Subst2) + (=.. $Head3 + (Cons $F $Tail33)) + (lgg1 $Tail1 $Tail2 $Tail3 $Subst2 $Subst3) + (set-det))) +; + + (= + (lgg1 + (Cons $Head1 $Tail1) + (Cons $Head2 $Tail2) + (Cons $Head3 $Tail3) $Subst1 $Subst2) + ( (subst-member + (/ $Head3 + (, $Head1 $Head2)) $Subst1) + (lgg1 $Tail1 $Tail2 $Tail3 $Subst1 $Subst2) + (set-det))) +; + + (= + (lgg1 + (Cons $Head1 $Tail1) + (Cons $Head2 $Tail2) + (Cons $Head3 $Tail3) $Subst1 $Subst2) + ( (lgg1 $Tail1 $Tail2 $Tail3 + (Cons + (/ $Head3 + (, $Head1 $Head2)) $Subst1) $Subst2) (set-det))) +; + + + + (= + (subst-member + (/ $A $B) + (Cons + (/ $A $C) $_)) + ( (== $B $C) (set-det))) +; + + (= + (subst-member $A + (Cons $_ $B)) + ( (subst-member $A $B) (set-det))) +; + + + + (= + (covers () $_) True) +; + + (= + (covers + (Cons $H1 $T1) $P) + ( (member $C1 $P) + (copy $C1 + (= $H1 $B1)) + (covers-body $B1 $P) + (covers $T1 $P))) +; + + + + (= + (covers_body true $_) True) +; + + (= + (covers-body + (, $H $B) $P) + ( (set-det) + (covers + (:: $H) $P) + (covers-body $B $P))) +; + + (= + (covers-body $H $P) + (covers + (:: $H) $P)) +; + + + + (= + (copy $A $B) + (or + (, + (add-symbol &self + (yap_inst $A)) + (remove-symbol &self + (yap_inst $B)) + (set-det)) + (, + (remove-symbol &self + (yap_inst $_)) + (fail)))) +; + + + + (= + (psubsumes $_ Nil) + (set-det)) +; + + (= + (psubsumes $P + (Cons $C $T)) + ( (bsubsumes $P $C) + (psubsumes $P $T) + (set-det))) +; + + +; (error +; (syntax_error operator_expected) +; (file logic/logic.pl 229 7 11814)) + + + + (= + (body-units True Nil) + (set-det)) +; + + (= + (body-units + (, $Head1 $Tail1) + (Cons + (= $Head1 True) $Tail2)) + ( (body-units $Tail1 $Tail2) (set-det))) +; + + (= + (body_units $Head + ( (:- $Head true))) True) +; + + + + (= + (goal_units () ()) True) +; + + (= + (goal-units + (Cons $Head1 $Tail1) + (Cons + (= $Head1 True) $Tail2)) + ( (goal-units $Tail1 $Tail2) (set-det))) +; + + + + (= + (p-subsumes $ClauseSet1 $Theory $ClauseSet2) + ( (append $ClauseSet1 $Theory $Program) (psubsumes $Program $ClauseSet2))) +; + + + + (= + (p-equivalent $ClauseSet1 $Theory $ClauseSet2) + ( (append $ClauseSet1 $Theory $Program1) + (psubsumes $Program1 $ClauseSet2) + (append $ClauseSet2 $Theory $Program2) + (psubsumes $Program2 $ClauseSet1))) +; + + + + + (= + (help) + ( (write 'Load example calls with command: [Filename].') + (nl) + (write 'Call examples with: test1, test2, test3a, test3b,') + (nl) + (write ' test4a, test4b, test4c, test4d, test5') + (nl))) +; + + + + !(help *) +; + + + + diff --git a/logic/logic_1.metta b/logic/logic_1.metta new file mode 100644 index 0000000..1a58963 --- /dev/null +++ b/logic/logic_1.metta @@ -0,0 +1,157 @@ + + (= + (test1) + ( (substitution + (f + (g $A) $B) + (f + (g (h a)) + (i b)) $ERG) + (write $ERG) + (nl))) +; + + + + (= + (test2) + ( (lgg + (f + (g 3) 3 + (j 6)) + (f + (g 2) 2 + (j (h 6))) $ERG) + (write $ERG) + (nl))) +; + + + + (= + (test3a) + (covers + (:: (mem 3 (:: 4 3))) + (:: + (= + (mem $A + (Cons $A $_)) True) + (= + (mem $A + (Cons $_ $B)) + (mem $A $B))))) +; + + + + (= + (test3b) + (covers + (:: (mem 3 (:: 4 5))) + (:: + (= + (mem $A + (Cons $A $_)) True) + (= + (mem $A + (Cons $_ $B)) + (mem $A $B))))) +; + + + + (= + (test4a) + (psubsumes + (:: + (= + (mem $A + (Cons $A $_)) True) + (= + (mem $B + (Cons $_ $C)) + (mem $B $C))) + (:: (= (mem $D (Cons $_ (Cons $_ $E))) (mem $D $E))))) +; + + + + (= + (test4b) + (psubsumes + (:: + (= + (mem $A + (Cons $A $_)) True) + (= + (mem $B + (Cons $_ $C)) + (mem $B $C))) + (:: + (= + (mem $D + (Cons $_ + (Cons $_ $E))) + (mem $D $E)) + (= + (mem $D + (Cons $_ + (Cons $_ + (Cons $_ $E)))) + (mem $D $E))))) +; + + + + (= + (test4c) + (psubsumes + (:: + (= + (mem $A + (Cons $A $_)) True) + (= + (mem $B + (Cons $_ $C)) + (mem $B $C))) + (:: (= (mem $D (Cons $_ (Cons $_ $E))) (mem $X $E))))) +; + + + + (= + (test4d) + (psubsumes + (:: (= (mem $B (Cons $_ $C)) (mem $B $C))) + (:: (= (mem $D (Cons $_ (Cons $_ $E))) (mem $D $E))))) +; + + + + (= + (test5) + (p-subsumes + (:: (= (cuddly-pet $X) ((small $X) (fluffy $X) (pet $X)))) + (:: + (= + (pet $X) + (cat $X)) + (= + (pet $X) + (dog $X)) + (= + (small $X) + (cat $X))) + (:: + (= + (cuddly-pet $X) + ( (small $X) + (fluffy $X) + (dog $X))) + (= + (cuddly-pet $X) + ( (fluffy $X) (cat $X)))))) +; + + + diff --git a/metagame/comms/chesstalk.metta b/metagame/comms/chesstalk.metta new file mode 100644 index 0000000..e41a8b0 --- /dev/null +++ b/metagame/comms/chesstalk.metta @@ -0,0 +1,864 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + +; +; + + + + !(ensure-loaded (library pipes)) +; + + + + (= + (create) + ( (global chessprog $Prog) (create $Prog))) +; + + + + (= + (create $Player) + ( (player-command $Player $Command) (talk-interface $Command))) +; + + + + (= + (player-command gnu $Command) + (gnu-command $Command)) +; + + (= + (player-command morph $Command) + (morph-command $Command)) +; + + + + (= + (gnu-command $Command) + (command-from-args + (:: nice -10 gnuchess) $Command)) +; + + + + (= + (morph-command $Command) + ( (morph-setup-file $File) (command-from-args (:: '( cd ~/Morph/ ; nice -5 morph -q -wh -f' $File )) $Command))) +; + + + + (= + (tellm $S) + (tell-chess $S)) +; + + + (= + (seem) + (see-chess)) +; + + + + (= + (tell-chess $Statement) + (tell-outstream $Statement)) +; + + + + (= + (see-chess) + ( (global instream $I) (set-input $I))) +; + + + + (= + (morph-setup-file $File) + ( (global handicap $File) (set-det))) +; + + (= + (morph_setup_file morphstart) True) +; + + + +; +; + +; +; + + + (= + (chess-choose $Player $Move $SIn $SOut) + ( (victor-move $Move $SIn $SOut) + (set-det) + (format "King is in check; Game over!~n" Nil))) +; + + (= + (chess-choose $Player $Move $SIn $SOut) + (chess-choose-real $Player $Move $SIn $SOut)) +; + + + + (= + (chess-choose-real $Player $Move $SIn $SOut) + ( (update-chess $Player $SIn) + (current-input $OldStream) + (global instream $I) + (set-input $I) + (det-if-then-else + (chess-move $Player $_ $MoveString) + (, + (set-input $OldStream) + (det-if-then-else + (completed-move $MoveString $Move $SIn $SOut) + (print-choice $Move $SIn $SOut) + (, + (format "Strange string: ~w~n" + (:: $MoveString)) + (fail)))) + (, + (set-input $OldStream) + (fail))))) +; + + + + + (= + (init-chess-if $Role $SIn) + ( (should-init $Role $SIn) + (set-det) + (init-chess $Role $SIn))) +; + + (= + (init_chess_if $Role $SIn) True) +; + + + +; +; + +; +; + + + (= + (should-init $Role $SIn) + ( (move-count $N $SIn) (< $N 2))) +; + + (= + (should-init $Role $SIn) + ( (global setup yes) (setg setup no))) +; + + + + + (= + (init-chess $Role $SIn) + ( (global chessprog $Prog) (init-prog $Prog $Role $SIn))) +; + + + + + (= + (update-chess $Role $SIn) + ( (init-chess-if $Role $SIn) + (det-if-then-else + (last-move $Move) + (, + (meta-to-chess $Move $ChMove) + (format "To Chess: I played ~w~n" + (:: $ChMove)) + (= $ChMove $TellMove) + (tell-chess (:: $TellMove))) True) + (tell-chess-move))) +; + + + + (= tell_chess_move True) +; + + + + (= + (flush-chess) + ( (global chessprog $Prog) (flush-prog $Prog))) +; + + + + (= + (flush-prog gnu) + (tell-chess (:: bd))) +; + + (= + (flush_prog morph) True) +; + + + +; +; + +; +; + +; +; + + + (= + (chess-prompt $Player) + (flush-chess)) +; + +; +; + +; +; + + + + + (= + (meta-to-chess $Move $ChMove) + ( (chess-notation $Move $String) (concat-list $String $ChMove))) +; + + + + + (= + (chess-move $Player $Number $Move) + ( (chess-prompt $Player) + (chess-read $Number $FullMove) + (set-det) + (format "~s" + (:: $FullMove)) + (player-indent $Player $Indent) + (append $Indent $Move0 $FullMove) + (chess-to-meta $Move0 $Move))) +; + + + + (= + (chess-header-string $Pattern) + (append-list + (:: "My move is: ") $Pattern)) +; + + + + + (= + (chess-read $Number $Move) + ( (chess-header-string $String) + (read-until-string $String) + (read-template $Move))) +; + + + + (= + (read-template $Move) + ( (global chessprog $Prog) (read-template $Prog $Move))) +; + + + (= + (read-template gnu $Move) + (read-four $Move)) +; + + (= + (read-template morph $Move) + (read-five $Move)) +; + + + + (= + (read-four (:: $A $B $C $D)) + ( (get0 $A) + (get0 $B) + (get0 $C) + (get0 $D))) +; + + + (= + (read-five (:: $A $B $C $D)) + ( (get0 $A) + (get0 $B) + (get0 $_) + (get0 $C) + (get0 $D))) +; + + + + (= + (player_indent $_ "") True) +; + + + + (= + (chess-to-meta $A $B) + (chess-to-meta $B $A Nil)) +; + + + + (= + (--> + (chess_to_meta ()) ()) True) +; + + (= + (--> + (chess_to_meta + (Cons $XM + (Cons $YM $Sqs))) + (, + ($X) + (, + ($Y) + (, + { (chess_conv_square $X $Y $XM $YM) } + (chess_rest $Sqs))))) True) +; + + + (= + (--> + (chess_rest ()) ()) True) +; + + (= + (--> + (chess_rest $Sqs) + (, () + (chess_to_meta $Sqs))) True) +; + + + + + (= + (chess-conv-square $X $Y $XM $YM) + ( (name $XM + (:: $X)) (name $YM (:: $Y)))) +; + + + + + (= + (conv-x $X $XM) + (is $XM + (+ + (- "h" $X) "a"))) +; + + + (= + (conv-y $Y $YM) + (is $YM + (+ + (- "8" $Y) "1"))) +; + + + +; +; + + +; +; + + + (= + (chess-notation $ComplexMove $Notation) + ( (det-if-then-else + (var $ComplexMove) set-parsing-mode True) (chess-notation $ComplexMove $Notation Nil))) +; + + + + + (= + (--> + (chess_notation $M) + (, + (prelims $M $Pre) + (chess_main $Pre ()))) True) +; + + + +; +; + + (= + (--> + (chess_consider_promote + (Cons $T $Sel) $Rest) + (, + (chess_attempt_promote $T) + (chess_select_promote $Sel $Rest))) True) +; + + + + (= + (--> + (chess_select_promote + (Cons + (promote_select $Square $OldPiece $OldPiece) $Rest) $Rest) ()) True) +; + + (= + (--> + (chess_select_promote + (Cons + (promote_select $Square $OldPiece $NewPiece) $Rest) $Rest) + (, + { (, + (\== $OldPiece $NewPiece) + (, + (piece_struct_name $NewPiece $Name) + (, + (name $Name + (Cons $NewC $_)) + (name $NewL + ($NewC))))) } + ($NewL))) True) +; + + (= + (--> + (chess_select_promote $Rest $Rest) ()) True) +; + + + + +; +; + +; +; + +; +; + +; +; + + (= + (--> + (chess_attempt_promote + (try_promote $Square $OldPiece ())) ()) True) +; + + (= + (--> + (chess_attempt_promote + (try_promote $Square $OldPiece $OldPiece)) ()) True) +; + + + +; +; + +; +; + + (= + (--> + (chess_main $In $Out) + (, + (chess_first_transfer $In $First) + (, + (chess_continued_transfers $First $T) + (chess_consider_promote $T $Out)))) True) +; + + + +; +; + + (= + (--> + (chess_transfers $In $Out) + (, + (chess_transfer $In $T) + (chess_continued_transfers $T $Out))) True) +; + + +; +; + +; +; + +; +; + + (= + (--> + (chess_continued_transfers $In $In) ()) True) +; + + (= + (--> + (chess_continued_transfers + (Cons end_continues $Rest) $Rest) ()) True) +; + + (= + (--> + (chess_continued_transfers $In $Out) + (chess_transfers $In $Out)) True) +; + + + +; +; + +; +; + +; +; + +; +; + + (= + (--> + (chess_transfer + (Cons $Move $Capture) $Rest) + (, + (chess_moving $Move) + (chess_capture $Capture $Rest))) True) +; + + + (= + (--> + (chess_first_transfer + (Cons $Move $Capture) $Rest) + (, + (chess_first_moving $Move) + (chess_capture $Capture $Rest))) True) +; + + + +; +; + +; +; + +; +; + + (= + (--> + (chess_first_moving + (move $Piece $Player $From $To)) + (, + (chess_square $From) + (chess_square $To))) True) +; + + + (= + (--> + (chess_moving + (move $Piece $Player $From $To)) + (chess_square $To)) True) +; + + + + + (= + (--> + (chess_capture $In $Out) + (chess_null_capture $In $Out)) True) +; + + (= + (--> + (chess_capture $In $Out) + (chess_real_capture $In $Out)) True) +; + + + (= + (--> + (chess_null_capture $X $X) ()) True) +; + + + (= + (--> + (chess_real_capture + (Cons $C $Cs) $Rest) + (, + (chess_simp_capture $C) + (chess_capture $Cs $Rest))) True) +; + + + (= + (--> + (chess_simp_capture $M) + (chess_remove $M)) True) +; + + (= + (--> + (chess_simp_capture $M) + (chess_possess $M)) True) +; + + +; +; + + (= + (--> + (chess_remove + (capture remove $Caps)) ()) True) +; + + +; +; + + (= + (--> + (chess_possess + (capture + (possess $Player) $Caps)) ()) True) +; + + + + (= + (--> + (chess_square $Sq) + (, + { (square $Sq $X $Y) } + (, + ($Col) + (, + { (nth_letter $X $Col) } + (number $Y))))) True) +; + + + +; +; + +; +; + +; +; + + + + + (= + (create-top) + (create)) +; + + + + + + (= + (square-chess-name $Player $Sq $Name) + (square-chess-name $Player $Sq $Name $S)) +; + + + (= + (square-chess-name $Player $Sq $Name $S) + ( (player-role $Player) + (det-if-then-else + (var $S) + (checkpoint init $S) True) + (on $Piece $Sq $S) + (piece-struct-name $Piece $PName) + (piece-struct-owner $Piece $Player) + (player-piece-print-name $Player $PName $ChessName) + (chess-square $Sq $ChessSq Nil) + (concat-list + (Cons $ChessName $ChessSq) $Name))) +; + + + + + (= + (setup-gnu $S) + ( (tell-chess (:: edit)) + (tell-chess (:: #)) + (whenever + (square-chess-name player $_ $Name $S) + (tell-chess (:: $Name))) + (tell-chess (:: c)) + (whenever + (square-chess-name opponent $_ $Name $S) + (tell-chess (:: $Name))) + (tell-chess (:: .)))) +; + + + + (= + (init_prog morph $Role $SIn) True) +; + + +; +; + +; +; + + (= + (init-prog gnu $Role $S) + ( (global handicap $H) + (> $H 0) + (set-det) + (tell-chess (:: 1)) + (tell-chess (:: new)) + (setup-gnu $S) + (set-gnu-depth) + (init-gnu-role $Role))) +; + + + + + (= + (set-gnu-depth) + (det-if-then-else + (global depth $D) + (set-gnu-depth $D) True)) +; + + + (= + (set-gnu-depth $DNum) + ( (number-chars $DNum $Chars) + (atom-chars $D $Chars) + (tell-chess (:: depth)) + (tell-chess (:: $D)))) +; + + + + + + + (= + (init-gnu-role $Role) + ( (player-color $Role $Color) (tell-chess (:: $Color)))) +; + +; +; + +; +; + + + + + + (= + (tell-com $_ $_ $_ $X) + (tell-chess $X)) +; + + + (= + (tell-top $X) + (tell-chess $X)) +; + + + + (= + (depth-com $_ $_ $_ $X) + (set-gnu-depth $X)) +; + + + (= + (depth-top $X) + (set-gnu-depth $X)) +; + + + diff --git a/metagame/comms/chinook.metta b/metagame/comms/chinook.metta new file mode 100644 index 0000000..884757d --- /dev/null +++ b/metagame/comms/chinook.metta @@ -0,0 +1,549 @@ +; +; + +; +; + +; +; + +; +; + + + + !(ensure-loaded (library pipes)) +; + + + + (= + (create-chinook) + ( (command-from-args + (:: nice -10 chinook) $Command) (interface-record-streams $Command $InStream $OutStream))) +; + + + + (= + (tell-chinook $Statement) + (tell-outstream $Statement)) +; + + + + (= + (tellc $S) + (tell-chinook $S)) +; + + + + (= + (seem) + ( (global instream $I) (set-input $I))) +; + + + + +; +; + + + + (= + (chinook-quit) + ( (tell-chinook (:: q)) (interface-close-streams))) +; + + + + (= + (chinook-choose $Player $Move $SIn $SOut) + ( (update-chinook $Player $SIn) + (current-input $OldStream) + (global instream $I) + (set-input $I) + (det-if-then-else + (chinook-move $Player $_ $MoveString) + (, + (set-input $OldStream) + (completed-move $MoveString $Move $SIn $SOut) + (print-choice $Move $SIn $SOut)) + (, + (set-input $OldStream) + (tell-chinook (:: O)) + (chinook-choose $Player $Move $SIn $SOut))))) +; + + + + !(add-global handicap 0) +; + + + + (= + (setup-chinook) + ( (global handicap $H) + (tell-chinook (:: i)) + (config $H))) +; + + + +; +; + + + + + (= + (config 0) True) +; + + (= + (config 1) + (tell-chinook rb6)) +; + + (= + (config 2) + (tell-chinook rb6rd6)) +; + + (= + (config 3) + (tell-chinook rb6rd6rf6)) +; + + (= + (config 4) + (tell-chinook rb6rd6rf6rh6)) +; + + (= + (config 8) + ( (tell-chinook rb6rd6rf6rh6) (tell-chinook ra7rc7re7rg7))) +; + + + + + + (= + (update-chinook $Role $SIn) + ( (move-count $N $SIn) + (det-if-then-else + (< $N 2) setup-chinook True) + (det-if-then-else + (last-move $Move) + (, + (meta-to-ch $Move $ChMove) + (format "To Chinook: I played ~w~n" + (:: $ChMove)) + (concat m $ChMove $TellMove) + (tell-chinook (:: $TellMove))) True) + (tell-chinook-move))) +; + + + + (= + (tell-chinook-move) + (tell-chinook (:: g))) +; + + + + + (= + (meta-to-ch $Move $ChMove) + ( (ch-notation $Move $String) (concat-list $String $ChMove))) +; + + + + + (= + (chinook-move $Player $Number $Move) + ( (chinook-read $Number $FullMove) + (set-det) + (format $FullMove Nil) + (player-indent $Player $Indent) + (append $Indent $Move0 $FullMove) + (ch-to-meta $Move0 $Move))) +; + +; +; + +; +; + + + + + + (= + (chinook-read $Number $Move) + ( (append-list + (:: "I move") $Pattern) + (format "Looking for pattern: ~w~n" + (:: $Pattern)) + (found $Pattern) + (read-keyboard-tokens (:: $Number $_)) + (read-line $Move))) +; + + + + (= + (player_indent player " ") True) +; + + (= + (player_indent opponent " ... ") True) +; + + + +; +; + +; +; + + + + + (= + (ch_to_meta () ()) True) +; + + (= + (ch-to-meta + (Cons $X + (Cons $Y $Rest)) + (Cons $XM + (Cons $YM $RestM))) + ( (conv-square $X $Y $XM $YM) (ch-to-meta $Rest $RestM))) +; + + + + (= + (conv-square $X $Y $XM $YM) + ( (conv-x $X $XM1) + (conv-y $Y $YM1) + (name $XM + (:: $XM1)) + (name $YM + (:: $YM1)))) +; + + + + + (= + (conv-x $X $XM) + (is $XM + (+ + (- "h" $X) "a"))) +; + + + (= + (conv-y $Y $YM) + (is $YM + (+ + (- "8" $Y) "1"))) +; + + + + + +; +; + + +; +; + + + (= + (ch-notation $ComplexMove $Notation) + ( (det-if-then-else + (var $ComplexMove) set-parsing-mode True) (ch-notation $ComplexMove $Notation Nil))) +; + + + + + (= + (--> + (ch_notation $M) + (, + (prelims $M $Pre) + (ch_main $Pre ()))) True) +; + + + +; +; + + (= + (--> + (ch_consider_promote + (Cons $T $Sel) $Rest) + (, + (ch_attempt_promote $T) + (ch_select_promote $Sel $Rest))) True) +; + + + (= + (--> + (ch_select_promote + (Cons + (promote_select $_ $_ $_) $Rest) $Rest) ()) True) +; + + (= + (--> + (ch_select_promote $Rest $Rest) ()) True) +; + + + + +; +; + +; +; + +; +; + +; +; + + (= + (--> + (ch_attempt_promote + (try_promote $Square $OldPiece ())) ()) True) +; + + (= + (--> + (ch_attempt_promote + (try_promote $Square $OldPiece $NewPiece)) ()) True) +; + + + +; +; + +; +; + + (= + (--> + (ch_main $In $Out) + (, + (ch_first_transfer $In $First) + (, + (ch_continued_transfers $First $T) + (ch_consider_promote $T $Out)))) True) +; + + + +; +; + + (= + (--> + (ch_transfers $In $Out) + (, + (ch_transfer $In $T) + (ch_continued_transfers $T $Out))) True) +; + + +; +; + +; +; + +; +; + + (= + (--> + (ch_continued_transfers $In $In) ()) True) +; + + (= + (--> + (ch_continued_transfers + (Cons end_continues $Rest) $Rest) ()) True) +; + + (= + (--> + (ch_continued_transfers $In $Out) + (ch_transfers $In $Out)) True) +; + + + +; +; + +; +; + +; +; + +; +; + + (= + (--> + (ch_transfer + (Cons $Move $Capture) $Rest) + (, + (ch_moving $Move) + (ch_capture $Capture $Rest))) True) +; + + + (= + (--> + (ch_first_transfer + (Cons $Move $Capture) $Rest) + (, + (ch_first_moving $Move) + (ch_capture $Capture $Rest))) True) +; + + + +; +; + +; +; + +; +; + + (= + (--> + (ch_first_moving + (move $Piece $Player $From $To)) + (, + (ch_square $From) + (ch_square $To))) True) +; + + + (= + (--> + (ch_moving + (move $Piece $Player $From $To)) + (ch_square $To)) True) +; + + + + + (= + (--> + (ch_capture $In $Out) + (ch_null_capture $In $Out)) True) +; + + (= + (--> + (ch_capture $In $Out) + (ch_real_capture $In $Out)) True) +; + + + (= + (--> + (ch_null_capture $X $X) ()) True) +; + + + (= + (--> + (ch_real_capture + (Cons $C $Cs) $Rest) + (, + (ch_simp_capture $C) + (ch_capture $Cs $Rest))) True) +; + + + (= + (--> + (ch_simp_capture $M) + (ch_remove $M)) True) +; + + (= + (--> + (ch_simp_capture $M) + (ch_possess $M)) True) +; + + +; +; + + (= + (--> + (ch_remove + (capture remove $Caps)) ()) True) +; + + +; +; + + (= + (--> + (ch_possess + (capture + (possess $Player) $Caps)) ()) True) +; + + + + (= + (--> + (ch_square $Sq) + (, + { (, + (invert $Sq $Sq1) + (square $Sq1 $X $Y)) } + (, + ($Col) + (, + { (nth_letter $X $Col) } + (number $Y))))) True) +; + + + + diff --git a/metagame/comms/comms.metta b/metagame/comms/comms.metta new file mode 100644 index 0000000..3887200 --- /dev/null +++ b/metagame/comms/comms.metta @@ -0,0 +1,207 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + + + + + !(ensure-loaded (library shells)) +; + + + +; +; + +; +; + +; +; + + + + (= + (linda-client-wait (with_self $ServerAddr $PortNum)) + ( (linda-client (with_self $ServerAddr $PortNum)) (set-det))) +; + + (= + (linda-client-wait (with_self $ServerAddr $PortNum)) + (linda-client-wait (with_self $ServerAddr $PortNum))) +; + + + + + (= + (in-wait $Pattern) + ( (format "~nWaiting to receive pattern: ~w~n" + (:: $Pattern)) + (in-wait-loop $Pattern) + (set-det) + (format "~nReceived pattern: ~w~n" + (:: $Pattern)))) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (in-wait-loop $Pattern) + ( (in-noblock $Pattern) (set-det))) +; + + (= + (in-wait-loop $Pattern) + (in-wait-loop $Pattern)) +; + + + + + (= + (rd-wait $Pattern) + ( (format "~nWaiting to observe pattern: ~w~n" + (:: $Pattern)) + (rd-wait-loop $Pattern) + (set-det) + (format "~nObserved pattern: ~w~n" + (:: $Pattern)))) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (rd-wait-loop $Pattern) + ( (rd-noblock $Pattern) (set-det))) +; + + (= + (rd-wait-loop $Pattern) + (rd-wait-loop $Pattern)) +; + + +; +; + + + + (= + (remote-metagame $Addr $Args $Title) + (shell-rsh $Addr /homes/bdp/prolog/play/metagame $Args $Title)) +; + + +; +; + + + +; +; + +; +; + +; +; + + + + (= + (human_file /homes/bdp/prolog/play/humanist) True) +; + + + (= + (random_file /homes/bdp/prolog/play/randomist) True) +; + + + (= + (instant_file /homes/bdp/prolog/play/instantist) True) +; + + + + + (= + (play-human-match $Server $P1 $P2) + ( (human-file $F) (play-match $Server $P1 $F $P2 $F))) +; + + + + (= + (play-match $Server $Player1 $Info1 $Player2 $Info2) + (make-server $Server $Player1 $Info1 $Player2 $Info2)) +; + + + + (= + (make-server $Server $Player1 $Info1 $Player2 $Info2) + ( (command-from-args + (:: server $Server : $Player1 vs $Player2) - $Title) (remote-metagame $Server (:: file /homes/bdp/prolog/play/serve-tourney player1-name $Player1 player1-info $Info1 player2-name $Player2 player2-info $Info2) $Title))) +; + + + + (= + (port-number $P $N) + (atom-to-number $P $N)) +; + + + + (= + (atom-to-number $A $N) + ( (name $A $N1) (number-chars $N $N1))) +; + + + + + + + diff --git a/metagame/comms/humanist.metta b/metagame/comms/humanist.metta new file mode 100644 index 0000000..2bb4403 --- /dev/null +++ b/metagame/comms/humanist.metta @@ -0,0 +1,27 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + + + (= + (move $Role $Move $SIn $SOut) + ( (my-name $Me) + (format "~nPlayer ~p, as ~p, wants your help to select his move.~n" + (:: $Me $Role)) + (human-choose $Role $Move $SIn $SOut))) +; + + diff --git a/metagame/comms/instantist.metta b/metagame/comms/instantist.metta new file mode 100644 index 0000000..684a59d --- /dev/null +++ b/metagame/comms/instantist.metta @@ -0,0 +1,26 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + + (= + (move $Role $Move $SIn $SOut) + ( (my-name $Me) + (format "~nPlayer ~p, as ~p, will select an INSTANT move.~n" + (:: $Me $Role)) + (instant-choose $Role $Move $SIn $SOut))) +; + + diff --git a/metagame/comms/pipes.metta b/metagame/comms/pipes.metta new file mode 100644 index 0000000..ecedb93 --- /dev/null +++ b/metagame/comms/pipes.metta @@ -0,0 +1,316 @@ +; +; + +; +; + +; +; + +; +; + + + +; +; + + + + (= + (talk-interface $Command) + (interface-record-streams $Command $_ $_)) +; + + + + + (= + (interface-record-streams $Command $InStream $OutStream) + ( (connect-pipes $Command $InStream $PipeIn $OutStream $PipeOut) + (add-global instream $InStream) + (add-global outstream $OutStream) + (add-global inpipe $PipeIn) + (add-global outpipe $PipeOut))) +; + + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (connect-pipes $Command $InStream $PIn $OutStream $POut) + ( (open-new-pipe read $PIn $InStream) + (open-new-pipe write $POut $OutStream) + (shell (:: $Command > $PIn < $POut &)))) +; + + + + + + + + (= + (mode_arrow read <) True) +; + + (= + (mode_arrow write >) True) +; + + + + (= + (open-pipe $Pipe $Mode $Stream) + ( (mode-arrow $Mode $Arrow) + (command-from-args + (:: cat $Arrow $Pipe) $Command) + (unix (popen $Command $Mode $Stream)))) +; + + + + (= + (open-new-pipe $Mode $Pipe $Stream) + ( (new-pipe-file $Pipe) (open-pipe $Pipe $Mode $Stream))) +; + + + + (= + (new-pipe-file $Pipe) + ( (gensym pipe $P) + (concat-list + (:: /tmp/ $P XXXXXX) $Template) + (mktemp $Template $Pipe) + (shell (:: mknod $Pipe p)))) +; + + + + +; +; + +; +; + +; +; + +; +; + + + (= + (reconnect-pipes) + ( (reconnect-inpipe) (reconnect-outpipe))) +; + + + + (= + (reconnect-inpipe) + ( (global inpipe $PIn) + (open-pipe $PIn read $InStream) + (add-global instream $InStream))) +; + + + + (= + (reconnect-outpipe) + ( (global outpipe $POut) + (open-pipe $POut write $OutStream) + (add-global outstream $OutStream))) +; + + + + + (= + (close-int) + (interface-close)) +; + + + + (= + (interface-close) + ( (interface-close-streams) (interface-close-pipes))) +; + + + + (= + (close-streams) + (interface-close-streams)) +; + + + + (= + (interface-close-streams) + ( (global instream $InStream) + (close $InStream) + (global outstream $OutStream) + (close $OutStream))) +; + + + + (= + (close-pipes) + (interface-close-pipes)) +; + + + + (= + (interface-close-pipes) + ( (rm-gpipe inpipe) (rm-gpipe outpipe))) +; + + + + (= + (rm-gpipe $P) + ( (global $P $Pipe) (shell (:: rm $Pipe)))) +; + + + + +; +; + +; +; + + + (= + (tell-outstream $Statement) + ( (tracing-format tellmove "Telling : ~p~n" + (:: $Statement)) + (current-output $OldStream) + (global outstream $O) + (command-from-args $Statement $String) + (format $O $String Nil) + (format $O "~n" Nil) + (flush-output $O) + (set-output $OldStream))) +; + + + +; +; + +; +; + +; +; + + + + !((abolish (/ found 1)) (abolish (/ found1 1))) +; + + +; +; + +; +; + + + (= + (read-until-string $Pattern) + ( (tracing-format readmove "Looking for pattern: ~s~n" + (:: $Pattern)) + (found $Pattern) + (tracing-format readmove "~nPattern found: ~s~n" + (:: $Pattern)))) +; + + + +; +; + +; +; + +; +; + +; +; + + + + (= + (found $Symbol) + (found1 $Symbol)) +; + + +; +; + + + (= + (found1 + (, $_ ())) True) +; + + (= + (found1 $SymbInfo) + ( (get0 $C) + (tracing-format readmove "~s" + (:: (:: $C))) + (new $C $SymbInfo $SymbInfoNew) + (found1 $SymbInfoNew))) +; + + +; +; + + +; +; + +; +; + +; +; + + + diff --git a/metagame/comms/player.metta b/metagame/comms/player.metta new file mode 100644 index 0000000..502792c --- /dev/null +++ b/metagame/comms/player.metta @@ -0,0 +1,635 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + + + + + !(prolog-flag redefine-warnings $_ off) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + +; +; + + + (= + (metagame) + (start-player)) +; + + + + (= + (start-player) + ( (find-my-name $Name) + (add-symbol &self + (my_name $Name)) + (find-server $Addr $Port) + (play $Addr $Port $Name))) +; + + + + (= + (find-my-name $N) + (parameter player1-name $N)) +; + + + + (= + (find-server $S $P) + ( (parameter server-name $S) (parameter server-port $P))) +; + + + + (= + (play $ServerAddr $Port $Player) + ( (use-module (library linda/client)) + (port-number $Port $PortNum) + (format "Server address is ~q:~q~n" + (:: $ServerAddr $PortNum)) + (linda-client-wait (with_self $ServerAddr $PortNum)) + (greet-ref $Player) + (start-controller))) +; + + + + (= + (greet-ref $Player) + (format "~nHello, I'm player: ~w" + (:: $Player))) +; + + + + + + +; +; + +; +; + + + +; +; + +; +; + + + (= + (in-wait-personal $Pattern) + ( (my-name $Me) (in-wait (message $Me $Pattern)))) +; + + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (get-move $Player $Move) + ( (in-wait-personal legal) (in-wait (moved $Player $Move)))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (communicate-move $Player $Move) + (out (moved $Player $Move))) +; + + +; +; + + + (= + (receive-players $White $Black) + (in-wait-personal (players $White $Black))) +; + + + + (= + (process-game $GameName) + ( (atom $GameName) + (set-det) + (file-make-test-game $GameName))) +; + + (= + (process-game $GameString) + (string-make-test-game $GameString)) +; + + + +; +; + +; +; + +; +; + + + + (= + (get-players $White $Black) + ( (receive-players $White $Black) + (my-name $Me) + (find-opponent $White $Black $Me $Opponent) + (remove-all-symbols &self + (my_opponent $_)) + (add-symbol &self + (my_opponent $Opponent)))) +; + + + + (= + (find_opponent $White $Black $White $Black) True) +; + + (= + (find_opponent $White $Black $Black $White) True) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (get-current-game) + ( (receive-game-name $GameName) (load-game $GameName))) +; + + + + (= + (receive-game-name $G) + (in-wait-personal (game-name $G))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (get-random-assignment $Assignment) + ( (format "~nRequesting Random Assignment~n" Nil) + (get-init-state $AssignmentString) + (assignments-string $Assignment $AssignmentString) + (format "~nReceived random assignment: ~w~n" + (:: $Assignment)))) +; + + + +; +; + +; +; + +; +; + + + (= + (get-init-state $Assignment) + (in-wait-personal (init-state $Assignment))) +; + + + +; +; + +; +; + +; +; + +; +; + + + + + (= + (terminate-game $SIn) + ( (format "~nI'm finished playing the game.~n" Nil) + (analyze-game $SIn) + (restart-or-end))) +; + + +; +; + + + (= + (analyze_game $_) True) +; + + + + + (= + (restart-or-end) + ( (in-wait-personal (reset $R)) + (set-det) + (restart-if $R))) +; + + + + (= + (restart-if new) + ( (format "~nStarting again!~n" Nil) (start-controller))) +; + + (= + (restart-if end) + ( (format "~nTournament is finished. Bye!~n" Nil) (close-player))) +; + + + + (= close_player True) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (should-continue $_) + ( (continuous) + (set-det) + (not-abort))) +; + + (= + (should-continue $_) + (ask-continue y)) +; + + + +; +; + +; +; + + + (= + (not-abort) + ( (rd-noblock abort) + (set-det) + (format "~nUser chose to abort!~n") + (fail))) +; + + (= not_abort True) +; + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (choose $Me $Role $SIn $SOut) + ( (my-name $Me) + (set-det) + (my-choice $Role $SIn $SOut))) +; + + (= + (choose $Other $Role $SIn $SOut) + (other-choice $Role $SIn $SOut)) +; + + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (my-choice $Role $SIn $SOut) + ( (my-name $Me) + (move $Role $Move $SIn $SOut) + (move-notation-string $Move $MoveString) + (communicate-move $Me $MoveString))) +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (other-choice $Role $SIn $SOut) + ( (my-opponent $Player) + (get-move $Player $MoveString) + (nl) + (format "Received: ~s" + (:: $MoveString)) + (nl) + (find-correct-interpretation $Player $Role $MoveString $SIn $SOut))) +; + + + + + (= + (find-correct-interpretation $Player $Role $MoveString $SIn $SOut) + ( (move-notation-string $Move $MoveString) + (check-legality $Player $Role $Move $SIn $SOut) + (set-det))) +; + + (= + (find-correct-interpretation $Player $Role $MoveString $SIn $SOut) + ( (format "~nCouldn't interpret the move, ~s, of player ~w, as ~w~n" + (:: $MoveString $Player $Role)) + (add-symbol &self + (checkpoints $Player $Role $MoveString $SIn $SOut)) + (break))) +; + + + + (= + (check-legality $Player $Role $Move $SIn $SOut) + ( (format "~nVerifying legality of move by Player ~w, as ~w:~w~n" + (:: $Player $Role $Move)) + (legal $Move $SIn $SOut) + (format "~nMove ~w passed legality check!~n" + (:: $Move)) + (print-state $SOut) + (print-notation $Move))) +; + + + + diff --git a/metagame/comms/randomist.metta b/metagame/comms/randomist.metta new file mode 100644 index 0000000..58a9a10 --- /dev/null +++ b/metagame/comms/randomist.metta @@ -0,0 +1,29 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + + + (= + (move $Role $Move $SIn $SOut) + ( (my-name $Me) + (format "~nPlayer ~p, as ~p, will select a RANDOM move.~n" + (:: $Me $Role)) + (random-choose $Role $Move $SIn $SOut) + (verbosely-format "~nPlayer ~p, as ~p, has chosen RANDOM move: ~p.~n" + (:: $Me $Role $Move)))) +; + + diff --git a/metagame/comms/referee.metta b/metagame/comms/referee.metta new file mode 100644 index 0000000..a5e2c5f --- /dev/null +++ b/metagame/comms/referee.metta @@ -0,0 +1,748 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + + + + !(prolog-flag redefine-warnings $_ off) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + + + (= + (metagame) + (start-ref)) +; + + + + (= + (start-ref) + ( (find-server $Server $Port) + (find-players $Player1 $Player2) + (referee $Server $Port $Player1 $Player2))) +; + + + + (= + (find-server $S $P) + ( (parameter server-name $S) (parameter server-port $P))) +; + + + + + (= + (find-players $Player1 $Player2) + ( (parameter player1-name $Player1) (parameter player2-name $Player2))) +; + + + + + + (= + (referee $ServerAddr $Port $Player1 $Player2) + ( (use-module (library linda/client)) + (port-number $Port $PortNum) + (linda-client-wait (with_self $ServerAddr $PortNum)) + (greet-players $Player1 $Player2) + (format "~nI'm your referee!~n" Nil) + (add-symbol &self + (players $Player1 $Player2)) + (start-controller))) +; + + + + (= + (greet-players $P1 $P2) + (format "~nHello, player1: ~w, player2: ~w~n" + (:: $P1 $P2))) +; + + + +; +; + + + +; +; + +; +; + + + + (= + (referee-game-contests $P1 $P2 $G 0) + ( (set-det) (record-statistics))) +; + + (= + (referee-game-contests $P1 $P2 $G $Contests) + ( (> $Contests 0) + (referee-contest $P1 $P2 $G) + (is $C1 + (- $Contests 1)) + (referee-game-contests $P1 $P2 $G $C1))) +; + + + +; +; + +; +; + + + + (= + (close-match $P1 $P2) + ( (close-players $P1 $P2) + (close-server) + (record-statistics) + (close-client))) +; + + + + (= + (close-server) + (with_self + (linda *) + (linda-call halt))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (call-for-players $PlayerCall) + ( (players $Player1 $Player2) (call-for-players $Player1 $Player2 $PlayerCall))) +; + + + (= + (call-for-players $Player1 $Player2 $PlayerCall) + ( (call-for-player $Player1 $PlayerCall) (call-for-player $Player2 $PlayerCall))) +; + + + + (= + (call-for-player $Name + (^ $Player $Call)) + (verify (, (= $Player $Name) (call $Call)))) +; + + +; +; + +; +; + + + (= + (out-to-players $Pattern) + (call-for-players (^ $P (out-personal $P $Pattern)))) +; + + + +; +; + +; +; + + + (= + (out-personal $Player $Pattern) + (out1 (message $Player $Pattern))) +; + + + + (= + (out1 $Pattern) + ( (format "~nSending pattern: ~w~n" + (:: $Pattern)) (out $Pattern))) +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + + + (= + (get-players $White $Black) + ( (next-players $White $Black) (set-players $White $Black))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (next-players $White $Black) + ( (remove-symbol &self + (players $Black $White)) (add-symbol &self (players $White $Black)))) +; + + + +; +; + +; +; + + + (= + (set-players $White $Black) + (out-to-players (players $White $Black))) +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (get-current-game) + ( (select-next-game $GameName) + (load-game $GameName) + (send-game-name-to-players $GameName))) +; + + + + (= + (send-game-name-to-players $GameName) + (out-to-players (game-name $GameName))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (select-next-game $GameName) + ( (next-alternate-game $GameName) (set-det))) +; + + (= + (select_next_game chess) True) +; + + + + (= + (next-alternate-game $GameName) + ( (player-current-game-name $OldGame) + (set-det) + (game-follows $OldGame $GameName))) +; + + + + (= + (player-current-game-name $Name) + ( (player-current-game $G) (game-name $G $Name))) +; + + + + (= + (game_follows chess checkers) True) +; + + (= + (game_follows checkers shogi) True) +; + + (= + (game_follows shogi turncoat_chess) True) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (get-random-assignment $Assignment) + ( (game-assignments $Game $As) + (assignment-decision $As random $PieceNames $Squares) + (generate-random-assignment $PieceNames $Squares $Assignment) + (send-assignment $Assignment))) +; + + + +; +; + + + (= + (generate-random-assignment $PieceNames $Squares $Assignment) + ( (format "~nGenerating Random Assignment~n" Nil) (assign-pieces-to-squares $PieceNames $Squares $Assignment))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (send-assignment $Assignment) + ( (assignments-string $Assignment $AssignmentString) + (format "~nSending random assignment: ~w~n" + (:: $Assignment)) + (out-to-players (init-state $AssignmentString)))) +; + + + + +; +; + +; +; + +; +; + +; +; + + + + (= + (terminate-game $SIn) + ( (format "~nThe game has finished~n" Nil) + (process-results $SIn) + (restart-or-end))) +; + + +; +; + + + (= + (process_results $SIn) True) +; + + + + (= + (restart-or-end) + (det-if-then-else + (next-alternate-game $GameName) restart goodbye-players)) +; + + + + (= + (restart) + ( (out-to-players (reset new)) (start-controller))) +; + + + + (= + (goodbye-players) + ( (out-to-players (reset end)) (format "~nTournament is finished. Bye!~n" Nil))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + + + (= + (should-continue $SIn) + ( (continuous) + (set-det) + (not-abort))) +; + + (= + (should-continue $SIn) + (ask-continue y)) +; + + +; +; + +; +; + + + (= + (not-abort) + ( (rd-noblock abort) + (set-det) + (format "~nUser chose to abort!~n") + (fail))) +; + + (= not_abort True) +; + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (choose $Player $Role $SIn $SOut) + (observe-choice $Player $Role $SIn $SOut)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (observe-choice $Player $Role $SIn $SOut) + ( (format "~nPlayer ~w, as ~w, must select his move.~n" + (:: $Player $Role)) + (observe-move $Player $MoveString) + (nl) + (format "Observed: ~s" + (:: $MoveString)) + (nl) + (find-correct-interpretation $Player $Role $MoveString $SIn $SOut) + (other-player $Player $Other) + (out-personal $Other legal) + (format "~nPlayer ~w, as ~w, has selected his move.~n" + (:: $Player $Role)))) +; + + + + (= + (find-correct-interpretation $Player $Role $MoveString $SIn $SOut) + ( (move-notation-string $Move $MoveString) + (check-legality $Player $Role $Move $SIn $SOut) + (set-det))) +; + + (= + (find-correct-interpretation $Player $Role $MoveString $SIn $SOut) + ( (format "~nCouldn't interpret the move, ~s, of player ~w, as ~w~n" + (:: $MoveString $Player $Role)) + (add-symbol &self + (checkpoints $Player $Role $MoveString $SIn $SOut)) + (break))) +; + + + + (= + (check-legality $Player $Role $Move $SIn $SOut) + ( (format "~nVerifying legality of move by Player ~w, as ~w:~w~n" + (:: $Player $Role $Move)) + (legal $Move $SIn $SOut) + (format "~nMove ~w passed legality check!~n" + (:: $Move)) + (print-state $SOut) + (print-notation $Move))) +; + + + + + + (= + (observe-choice $Player $Role $SIn $SOut) + ( (format "~nPlayer ~w, as ~w, selected an illegal move!!!~n" + (:: $Player $Role)) + (set-det) + (fail))) +; + + + + (= + (observe-move $Player $Move) + (rd-wait (moved $Player $Move))) +; + + + + (= + (role_player player $White $_ $White) True) +; + + (= + (role_player opponent $_ $Black $Black) True) +; + + + + (= + (other-player $Player $Other) + (players $Player $Other)) +; + + (= + (other-player $Player $Other) + (players $Other $Player)) +; + + + + diff --git a/metagame/comms/serve_tourney.metta b/metagame/comms/serve_tourney.metta new file mode 100644 index 0000000..90f06ea --- /dev/null +++ b/metagame/comms/serve_tourney.metta @@ -0,0 +1,158 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + + + !(prolog-flag redefine-warnings $_ off) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + + + + (= + (metagame) + (serve-tourney)) +; + + + + (= + (serve-tourney) + ( (find-players $Player1 $Info1 $Player2 $Info2) (serve-tourney $Player1 $Info1 $Player2 $Info2))) +; + + + + (= + (find-players $Player1 $Info1 $Player2 $Info2) + ( (parameter player1-name $Player1) + (parameter player1-info $Info1) + (parameter player2-name $Player2) + (parameter player2-info $Info2))) +; + + + + (= + (serve-tourney $Player1 $Info1 $Player2 $Info2) + ( (use-module (library linda/server)) + (greet-players $Player1 $Player2) + (nl) + (write ' I am your friendly Linda Server!') + (nl) + (linda (- $Addr (create-tourney $Addr $Player1 $Info1 $Player2 $Info2))))) +; + + + + (= + (greet-players $P1 $P2) + (format "~nHello, player1: ~w, player2: ~w~n" + (:: $P1 $P2))) +; + + + + + (= + (create-tourney $Addr $Player1 $Info1 $Player2 $Info2) + ( (format "Server address is ~q~n" + (:: $Addr)) + (start-player $Addr $Player1 $Info1) + (wait-msecs 45000) + (start-ref $Addr $Player1 $Player2) + (wait-msecs 45000) + (start-player $Addr $Player2 $Info2))) +; + + + +; +; + + + (= + (good_addr shoveller) True) +; + + + + + (= + (start-ref + (with_self $ServerAddr $Port) $Player1 $Player2) + ( (good-addr $Slave) + (command-from-args + (:: ref $ServerAddr : $Player1 vs $Player2) - $Title) + (remote-metagame $Slave + (:: server-name $ServerAddr server-port $Port player1-name $Player1 player2-name $Player2 file ~/prolog/play/referee) $Title))) +; + + + + (= + (start-player + (with_self $ServerAddr $Port) $Player $MoveFile) + ( (good-addr $Slave) + (command-from-args + (:: $ServerAddr : $Player $MoveFile) - $Title) + (remote-metagame $Slave + (:: server-name $ServerAddr server-port $Port player1-name $Player file $MoveFile file ~/prolog/play/player) $Title))) +; + + + + + + + diff --git a/metagame/generator/gen.metta b/metagame/generator/gen.metta new file mode 100644 index 0000000..79e37fa --- /dev/null +++ b/metagame/generator/gen.metta @@ -0,0 +1,2918 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + + + + !(my-ensure-loaded (library piece-names)) +; + + !(my-ensure-loaded (library genstructs)) +; + + +; +; + +; +; + +; +; + + + + (= + (generate-game (game $Name $Board $PieceDefs $Goal $Constraints)) + ( (record-seed) + (new-game-name $Name) + (generate-board $Board) + (write 'Generated Board') + (nl) + (generate-pieces $Board $PieceDefs) + (write 'Generated Pieces') + (nl) + (generate-global-constraints $Constraints) + (write 'Generated Global Constraints') + (nl) + (generate-goal $Board $Goal) + (write 'Generated Goal ... And Game.') + (nl))) +; + + + + (= + (new-game-name $Name) + (gensym game $Name)) +; + + + + (= + (reset-game-name) + (reset-gensym game)) +; + + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + +; +; + +; +; + + + + (= + (generate-board $B) + ( (board $B) + (board-size $B $Size) + (board-type $B $Type) + (board-inversion $B $Inversion) + (board-promote-rows $B $PromoteRow) + (board-array-rows $B $MaxRow) + (board-piece-types $B $UniquePieces) + (board-placed-pieces $B $UniquePlacedPieces) + (board-assignments $B $Assignments) + (choose-board-size $Size) + (size $Size $XMax $YMax) + (choose-board-type $Type) + (choose-board-inversion $Inversion) + (choose-board-crowding $Crowd) + (choose-initial-array-rows $YMax $Crowd $MaxRow) + (choose-promotion-regions $MaxRow $MinRow) + (is $PromoteRow + (- $YMax $MinRow)) + (array-squares $XMax $MaxRow $ArSquares) + (placeable-pieces $ArSquares $UniquePlacedPieces $PlacedPieceSet) + (place-pieces-if-arbitrary $ArSquares $PlacedPieceSet $Assignments) + (promote-only-pieces $UniquePlacedPieces $PromotePieces) + (append $UniquePlacedPieces $PromotePieces $UniquePieces))) +; + + + + +; +; + + + (= + (array-squares $MaxCol $MaxRow $Squares) + ( (squares-in-rows 1 $MaxRow $MaxCol $Squares1) (reverse $Squares1 $Squares))) +; + + +; +; + +; +; + + + + (= + (squares-in-rows $Min $Max $Size $Squares) + ( (is $Min1 + (- $Min 1)) (squares-in-rows $Max $Min1 $Max $Size $Squares))) +; + + + (= + (squares-in-rows $Min $Min $Max $Size Nil) + (set-det)) +; + + (= + (squares-in-rows $_ $_ $_ 0 Nil) + (set-det)) +; + + (= + (squares-in-rows $Row $Min $Max $Size $Squares) + ( (squares-in-row $Row $Size $RowSquares) + (is $Row1 + (- $Row 1)) + (squares-in-rows $Row1 $Min $Max $Size $RestRows) + (append $RowSquares $RestRows $Squares))) +; + + + + + (= + (squares-in-row $Row 0 Nil) + (set-det)) +; + + (= + (squares-in-row $Row $Size + (Cons $Square $Squares)) + ( (is $Size1 + (- $Size 1)) + (square $Square $Size $Row) + (squares-in-row $Row $Size1 $Squares))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (place-pieces-if-arbitrary $ArSquares $PieceSet $Assignments) + ( (choose-placement-method $Method) (placement-for-method $Method $PieceSet $ArSquares $Assignments))) +; + + + + (= + (placement-for-method arbitrary $PieceSet $ArSquares $Assignments) + ( (set-det) (assign-pieces-to-squares $PieceSet $ArSquares $Assignments))) +; + + (= + (placement-for-method $Method $PieceSet $ArSquares $Assignments) + (decision $Assignments $Method $PieceSet $ArSquares)) +; + + + + (= + (assign-pieces-to-squares $Pieces $Squares $Assignments) + ( (randomly-pair $Pieces $Squares $Assignments1) (collect-placements $Assignments1 $Assignments))) +; + + + + (= + (collect-placements $In $Out) + (collect-placements $In Nil $Out)) +; + + + (= + (collect_placements () $X $X) True) +; + + (= + (collect-placements + (Cons + (= $A $Elt) $Rest) $Current $New) + ( (collapse + (= $A $Elt) $Current $New1) (collect-placements $Rest $New1 $New))) +; + + + + (= + (collapse + (= $A $Elt) Nil + (:: (= $A (:: $Elt)))) + (set-det)) +; + + (= + (collapse + (= $A $Elt) + (Cons + (= $A $Elts) $Rest) + (Cons + (= $A + (Cons $Elt $Elts)) $Rest)) + (set-det)) +; + + (= + (collapse + (= $A $Elt) + (Cons $H $Rest) + (Cons $H $Out)) + (collapse + (= $A $Elt) $Rest $Out)) +; + +; +; + + + + (= + (uncollect () ()) True) +; + + (= + (uncollect + (Cons + (= $A $Elts) $Rest) $Out) + ( (uncollapse $A $Elts $As) + (uncollect $Rest $R) + (append $As $R $Out))) +; + + + + (= + (uncollapse $_ () ()) True) +; + + (= + (uncollapse $A + (Cons $H $T) + (Cons + (= $A $H) $Ts)) + (uncollapse $A $T $Ts)) +; + + + + (= + (unpair () ()) True) +; + + (= + (unpair + (Cons + (= $Piece $Sq) $Rest) + (Cons $Sq $Squares)) + (unpair $Rest $Squares)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (placeable-pieces $ArSquares $UniquePieces $PieceSet) + ( (length $ArSquares $Possible) + (unique-piece-size $Possible $UniqueNum $SetSize) + (tracing-gen-format pieces "Out of <~p> max possible types, chose <~p>, <~p> unique~n" + (:: $Possible $SetSize $UniqueNum)) + (n-piece-names $UniqueNum $UniquePieces) + (duplicate-pieces $UniquePieces $SetSize $PieceSet) + (tracing-gen-format pieces "Unique: ~p~n Resulting set: ~p~n" + (:: $UniquePieces $PieceSet)))) +; + + + + (= + (unique-piece-size $Possible $UniqueNum $SetSize) + ( (piece-set-size $Possible $SetSize) + (choose-parameter piece-variety $Variety_Factor) + (is $UniqueNum1 + (integer (* $SetSize $Variety_Factor))) + (max $UniqueNum1 1 $UniqueNum))) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (piece-set-size $Possible $SetSize) + ( (choose-parameter row-crowding $Crowding) + (is $Size + (integer (* $Crowding $Possible))) + (max $Size 1 $SetSize))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (promote-only-pieces $PlacedPieces $Pieces) + ( (choose-parameter promote-only-pieces $N) + (length $PlacedPieces $Used) + (is $Next + (+ $Used 1)) + (is $Last1 + (+ $Next $N)) + (min $Last1 26 $Last) + (n-piece-names $Next $Last $Pieces))) +; + + + + +; +; + +; +; + +; +; + + + (= + (duplicate-pieces $UniquePieces $SetSize $PieceSet) + ( (duplicate-elements $UniquePieces $SetSize $PieceSet1) (stable-sort $PieceSet1 $PieceSet))) +; + + + + (= + (duplicate-elements $UniqueElements $SetSize $Elementset) + ( (length $UniqueElements $L) + (duplicate-elements $UniqueElements $L $SetSize $DuplicateSet) + (append $UniqueElements $DuplicateSet $Elementset))) +; + + + (= + (duplicate-elements $Types $Size $Size Nil) + (set-det)) +; + + (= + (duplicate-elements $Types $Size $Target + (Cons $E $Elements)) + ( (random-element $Types $E) + (is $Size1 + (+ $Size 1)) + (duplicate-elements $Types $Size1 $Target $Elements))) +; + + + +; +; + +; +; + +; +; + + + + + (= + (n-piece-names $N $Pieces) + (n-piece-names 1 $N $Pieces)) +; + + + + (= + (n-piece-names $N $Max Nil) + ( (> $N $Max) (set-det))) +; + + (= + (n-piece-names $N $Max + (Cons $P $Pieces)) + ( (new-piece-name $N $P) + (is $N1 + (+ $N 1)) + (n-piece-names $N1 $Max $Pieces))) +; + + + + + + (= + (new-piece-name $Index $Name) + (random-success (possible-index-piece $Index $Name))) +; + + + + + (= + (possible-index-piece $I $Name) + ( (indexed-names $I $Names) (member $Name $Names))) +; + + + +; +; + + + + (= + (choose-board-size $Size) + ( (choose-parameter board-size $XMax) + (choose-parameter board-size $YMax) + (size $Size $XMax $YMax))) +; + + + + (= + (choose-board-type $Type) + (choose-parameter board-type $Type)) +; + + + + (= + (choose-board-inversion $Type) + (choose-parameter board-inversion $Type)) +; + + + + + (= + (choose-board-crowding $Crowd) + (choose-parameter board-crowding $Crowd)) +; + + + + (= + (choose-initial-array-rows $Size $Crowding $MaxRow) + ( (is $MaxRow1 + (integer (/ (* $Size $Crowding) 2))) (max 1 $MaxRow1 $MaxRow))) +; + + + + (= + (choose-promotion-regions $MaxRow $MinRow) + ( (choose-promotion-fraction $D) (is $MinRow (integer (* $MaxRow $D))))) +; + + + + (= + (choose-promotion-fraction $D) + (choose-parameter promotion-fraction $D)) +; + + + + + (= + (choose-placement-method $M) + (choose-parameter placement-method $M)) +; + + + +; +; + +; +; + +; +; + + + + (= + (generate-pieces $Board $PieceDefs) + ( (board-piece-types $Board $Types) + (generate-pieces $Types $Board $PieceDefs1) + (sort $PieceDefs1 $PieceDefs))) +; + + + +; +; + + (= + (generate_pieces () $_ ()) True) +; + + (= + (generate-pieces + (Cons $P $Ps) $Board + (Cons $Def $Defs)) + ( (generate-piece $P $Board $Def) (generate-pieces $Ps $Board $Defs))) +; + + + + + (= + (generate-piece $Name $Board $Piece) + ( (piece $Piece) + (piece-name $Piece $Name) + (assign-movement-power $Piece $Board) + (assign-capture-power $Piece $Board) + (assign-promotion-power $Piece $Board) + (assign-piece-constraints $Piece $Board))) +; + + + +; +; + +; +; + +; +; + + + + + (= + (assign-movement-power $Piece $Board) + ( (create-complex-movement $Board $Movement) (piece-movement $Piece $Movement))) +; + + + + (= + (create-complex-movement $Board $Movement) + ( (create-movement $Board $M1) (complexify-movement $Board $M1 $Movement))) +; + + + + (= + (complexify-movement $Board $MIn + (Cons $MIn $MOut)) + ( (choose-parameter movement-complexity) + (set-det) + (create-complex-movement $Board $MOut))) +; + + (= + (complexify_movement $_ $X + ($X)) True) +; + + + + + + (= + (create-movement $Board $Movement) + ( (movement $Movement) + (choose-direction $Board $Dir) + (movement-dir $Movement $Dir) + (choose-symmetries $Syms) + (movement-sym $Movement $Syms) + (choose-movement-type $Type) + (constrain-movement $Type $Dir $Board $Movement))) +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (choose-direction $Board $Dir) + ( (choose-locality $L) + (board-size $Board $X $Y) + (is $XMax1 + (integer (* (- $X 1) $L))) + (is $YMax1 + (integer (* (- $Y 1) $L))) + (max 1 $XMax1 $XMax) + (max 1 $YMax1 $YMax) + (choose-dir $XMax $YMax $Dir))) +; + + + + (= + (choose-dir $XMax $YMax $Dir) + ( (choose-delta $XMax $Dx) + (choose-delta $YMax $Dy) + (legal-dir $XMax $YMax $Dx $Dy $Dir))) +; + + +; +; + +; +; + + + (= + (legal-dir $XMax $YMax 0 0 $Dir) + ( (set-det) (choose-dir $XMax $YMax $Dir))) +; + + (= + (legal-dir $_ $_ $Dx $Dy $Dir) + (direction $Dir $Dx $Dy)) +; + + +; +; + + + (= + (choose-delta $Max $Delta) + ( (is $M + (+ $Max 1)) (random 0 $M $Delta))) +; + + + + (= + (max-delta $Dir $D) + ( (direction $Dir $X $Y) (max $X $Y $D))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (choose-symmetries $Sym) + ( (symmetry $Sym) + (choose-parameter + (symmetry rotation) $R) + (choose-parameter + (symmetry forward) $F) + (choose-parameter + (symmetry side) $S) + (sym-forward $Sym $F) + (sym-side $Sym $S) + (sym-rotation $Sym $R))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (choose-locality $L) + (choose-parameter locality $L)) +; + + + + (= + (choose-movement-type $T) + (choose-parameter movement-type $T)) +; + + + + (= + (constrain-movement leaper $_ $Board $Movement) + ( (set-det) + (leaper $L) + (movement-type $Movement $L))) +; + + (= + (constrain-movement rider $Dir $Board $Movement) + ( (set-det) + (rider $Rider) + (choose-must-ride $Rider) + (choose-min-ride $Board $Dir $Rider) + (choose-max-ride $Board $Dir $Rider) + (movement-type $Movement $Rider))) +; + + (= + (constrain-movement hopper $Dir $Board $Movement) + ( (set-det) + (hopper $Hopper) + (choose-hopper-type $Board $R) + (hopper-type $Hopper $R) + (choose-before $Hopper $Board) + (choose-over $Hopper $Board) + (choose-after $Hopper $Board) + (valid-hopper $Hopper $Dir $Board $Movement))) +; + + + +; +; + +; +; + +; +; + + + + (= + (choose-must-ride $Rider) + ( (choose-parameter must-ride $Must) (rider-must $Rider $Must))) +; + + + + (= + (choose-min-ride $Board $Dir $Rider) + (rider-min $Rider 1)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (choose-max-ride $Board $Dir $Rider) + ( (choose-locality $L) + (board-max-size $Board $Size) + (max-delta $Dir $D) + (is $Rides + (integer (/ (* $L $Size) $D))) + (set-max-rides $Rider $Rides))) +; + + + + + (= + (set-max-rides $Rider $Rides) + ( (> $Rides 1) + (set-det) + (rider-max $Rider $Rides))) +; + + (= + (set-max-rides $Rider $_) + (rider-max $Rider any)) +; + + + +; +; + +; +; + +; +; + + + + (= + (choose-before $Hopper $Board) + (constrain-hopper before $Board $Hopper)) +; + + + + (= + (choose-over $Hopper $Board) + (constrain-hopper over $Board $Hopper)) +; + + + + (= + (choose-after $Hopper $Board) + (constrain-hopper after $Board $Hopper)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (constrain-hopper $Type $Board $Hopper) + (det-if-then-else + (choose-parameter (constrain (hopper $Type $_))) + (hopper-equation $Type $Board $Hopper) + (hopper-any $Type $Hopper))) +; + + +; +; + +; +; + +; +; + + + (= + (hopper-equation $Type $Board $Hopper) + ( (board-max-size $Board $Dist) + (hopper-component $Type $Hopper $Comp) + (choose-parameter + (hopper $Type $Dist) $P) + (choose-equation $P $Comp))) +; + + +; +; + + + (= + (hopper-any over $Hopper) + ( (set-det) + (comparison $C geq 1) + (hopper-component over $Hopper $C))) +; + + (= + (hopper-any $Type $Hopper) + ( (comparison $C geq 0) (hopper-component $Type $Hopper $C))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (choose-hopper-type $Board $C) + (choose-piece-description $Board $C)) +; + + + + (= + (hopper-component before $Hopper $X) + (hopper-before $Hopper $X)) +; + + (= + (hopper-component over $Hopper $X) + (hopper-over $Hopper $X)) +; + + (= + (hopper-component after $Hopper $X) + (hopper-after $Hopper $X)) +; + + + + +; +; + + + (= + (valid-hopper $Hopper $Dir $Board $Movement) + ( (hopper-can-move $Hopper $Dir $Board) + (set-det) + (movement-type $Movement $Hopper))) +; + + (= + (valid-hopper $Hopper $Dir $Board $Movement) + (constrain-movement hopper $Dir $Board $Movement)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (hopper-can-move $Hopper $Dir $Board) + ( (hopper-min-rides $Hopper $Rides) + (board-size $Board $BX $BY) + (direction $Dir $DX $DY) + (< + (* $Rides $DX) $BX) + (< + (* $Rides $DY) $BY))) +; + + + + + (= + (valid-hopper-max-dir $Dx $Dy $Max) + ( (current-board-size $Bx $By) + (is $XMax + (// $Bx $Dx)) + (is $YMax + (// $By $Dy)) + (min $XMax $YMax $Max))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (hopper-min-rides $H $Min) + ( (component-min $H before $Min1) + (component-min $H over $Min2) + (component-min $H after $Min3) + (is $Min + (+ + (+ + (+ $Min1 $Min2) $Min3) 1)))) +; + + + + (= + (component-min $H $T $Min) + ( (hopper-component $T $H $Eq) (min-rides $Eq $Min))) +; + + + + (= + (min-rides $Eq $Min) + ( (comparison $Eq geq $Min) (set-det))) +; + + (= + (min-rides $Eq $Min) + ( (comparison $Eq eq $Min) (set-det))) +; + + (= + (min_rides $Eq 0) True) +; + + + + + + (= + (choose-equation $Num $Eq) + ( (choose-parameter comparative $C) (comparison $Eq $C $Num))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (choose-piece-description $Board $Desc) + ( (player-generalization $Board $Player) + (piece-generalization $Board $Pieces) + (piece-description $Desc $Player $Pieces))) +; + + + + (= + (piece-generalization $Board $Gen) + ( (choose-piece-generalization-level $L) (generalize-piece $L $Board $Gen))) +; + + + + (= + (generalize-piece specific $Board $Pieces) + (choose-general-piece-set $Board $Pieces)) +; + + (= + (generalize_piece any $Board any_piece) True) +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + + + (= + (choose-general-piece-set $Board $Pieces) + ( (board-piece-types $Board $General) (choose-set-by-param $General more-general-pieces $Pieces))) +; + + +; +; + +; +; + + + (= + (choose-unplaced-piece-set $Board $Pieces) + ( (board-unplaced-pieces $Board $Unplaced) (choose-set-by-param $Unplaced more-arrival-pieces $Pieces))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (choose-set-by-param $Set $Param $Items) + ( (= $Goal + (choose-parameter $Param)) (choose-conditionally-from-set $Set $Goal $Items))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (choose-conditionally-from-set $Set $Goal $Items) + ( (random-permute $Set $Set1) + (choose-conditionally-from-set1 $Set1 $Goal $Items1) + (sort $Items1 $Items))) +; + + + + (= + (choose_conditionally_from_set1 () $_ ()) True) +; + + (= + (choose-conditionally-from-set1 + (Cons $Item $Rest) $Goal + (Cons $Item $Items)) + (det-if-then-else + (call $Goal) + (choose-conditionally-from-set $Rest $Goal $Items) + (= $Items Nil))) +; + + + + (= + (player-generalization $Board $Gen) + ( (choose-player-generalization-level $L) (generalize-player $L $Board $Gen))) +; + + +; +; + + + (= + (generalize-player specific $Board $Player) + ( (set-det) (random-player $Board $Player))) +; + + (= + (generalize_player any $Board any_player) True) +; + + + + (= + (random-player $Board $Player) + ( (players $Players) (random-element $Players $Player))) +; + + + + (= + (players + (player opponent)) True) +; + + + + + (= + (random-piece $Board $Piece) + ( (board-piece-types $Board $Types) (random-element $Types $Piece))) +; + + + + (= + (random-square $Board $Sq) + ( (board-size $Board $XMax $YMax) + (random $XMax $X) + (random $YMax $Y) + (square $Sq $X $Y))) +; + + + + (= + (choose-player-generalization-level $L) + (choose-parameter player-generalization-level $L)) +; + + + + (= + (choose-piece-generalization-level $L) + (choose-parameter piece-generalization-level $L)) +; + + +; +; + +; +; + +; +; + + + + (= + (assign-capture-power $Piece $Board) + ( (create-complex-capture $Board $Capture) (piece-capture $Piece $Capture))) +; + + + + (= + (create-complex-capture $Board $Capture) + ( (create-capture $Board $C1) (complexify-capture $Board $C1 $Capture))) +; + + + + (= + (complexify-capture $Board $CIn + (Cons $CIn $C1)) + ( (choose-parameter capture-complexity) + (set-det) + (create-complex-capture $Board $C1))) +; + + (= + (complexify_capture $_ $X + ($X)) True) +; + + + + + + (= + (create-capture $Board $Capture) + ( (choose-capture-movements $Board $Movement) + (capture-movement $Capture $Movement) + (choose-capture-methods $Method) + (capture-methods $Capture $Method) + (choose-capture-type $Board $Restrict) + (capture-type $Capture $Restrict) + (choose-capture-effect $Effect) + (capture-effect $Capture $Effect))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (choose-capture-movements $Board $Movement) + (create-complex-movement $Board $Movement)) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (choose-capture-methods $Methods) + ( (choose-parameter + (capture-method retrieve) $R) + (choose-parameter + (capture-method clobber) $C) + (choose-parameter + (capture-method hop) $H) + (method-retrieve $Methods $R) + (method-clobber $Methods $C) + (method-hop $Methods $H))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (choose-capture-effect $E) + (choose-parameter capture-effect $E)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (choose-capture-type $Board $C) + (choose-piece-description $Board $C)) +; + + +; +; + +; +; + +; +; + + + + (= + (assign-promotion-power $Piece $Board) + ( (choose-promotion $Board $Prom) (piece-promote $Piece $Prom))) +; + + + + (= + (choose-promotion $Board $Prom) + (det-if-then-else + (choose-parameter specific-promotion) + (specific-promotion $Board $Prom) + (promotion-decision $Board $Prom))) +; + + + + (= + (specific-promotion $Board + (promote $Piece)) + (random-piece $Board $Piece)) +; + + + + (= + (promotion-decision $Board $D) + ( (random-player $Player) + (choose-piece-description $Board $Desc) + (decision $D) + (decision-chooser $D $Player) + (decision-options $D $Desc))) +; + + + + (= + (random-player $P) + ( (board-players $_ $Players) (random-element $Players $P))) +; + + + + (= + (board-players $B + (:: player opponent)) + (board $B)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (assign-piece-constraints $Piece $Board) + ( (choose-piece-constraints $Board $Con) (piece-constraints $Piece $Con))) +; + + + + (= + (choose-piece-constraints $Board $Con) + ( (constraint $Con) + (choose-parameter must-capture $Must) + (constraint-must-capture $Con $Must) + (choose-parameter continue-captures $Cont) + (constraint-continue-captures $Con $Cont))) +; + + + + + (= + (piece-must-capture $Piece $Must) + ( (piece-constraints $Piece $Con) (constraint-must-capture $Con $Must))) +; + + + + (= + (piece-continue-captures $Piece $Continue) + ( (piece-constraints $Piece $Con) (constraint-continue-captures $Con $Continue))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (generate-global-constraints $Con) + (choose-game-constraints $Con)) +; + + +; +; + +; +; + + + (= + (choose-game-constraints $Con) + ( (constraint $Con) + (choose-parameter must-capture $Must) + (constraint-must-capture $Con $Must) + (constraint-continue-captures $Con no))) +; + + + + + (= + (game-must-capture $Game $Must) + ( (game-constraints $Game $Con) (constraint-must-capture $Con $Must))) +; + + + + (= + (game-continue-captures $Game $Continue) + ( (game-constraints $Game $Con) (constraint-continue-captures $Con $Continue))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (generate-goal $Board $Goals) + ( (choose-stalemate-goal $Board $Goal1) + (complexify-goal $Board Nil $ComplexGoal) + (tracing-gen-format goals "~n** Simplifying goals ...~n" Nil) + (tracing-gen simplify + (, + (format "Before: ~n" Nil) + (ppl (Cons $Goal1 $ComplexGoal)))) + (simplify-goals + (Cons $Goal1 $ComplexGoal) $Board $Goals) + (tracing-gen-format goals "~n** Done Simplifying.~n" Nil) + (tracing-gen simplify + (, + (format "~nAfter: ~n" Nil) + (ppl $Goals))))) +; + + + + (= + (complexify-goal $Board $GIn $G) + ( (choose-parameter goal-complexity) + (set-det) + (unsubsumed-goal $GIn $Board $GNew) + (complexify-goal $Board + (Cons $GNew $GIn) $G))) +; + + (= + (complexify_goal $_ $X $X) True) +; + + + +; +; + +; +; + + + (= + (unsubsumed-goal $Goals $Board $NewGoal) + ( (create-goal $Board $Goal) (ensure-new-goal $Goals $Board $Goal $NewGoal))) +; + + + + (= + (ensure-new-goal $Goals $Board $Goal $NewGoal) + ( (member $Goal $Goals) + (set-det) + (unsubsumed-goal $Goals $Board $NewGoal))) +; + + (= + (ensure-new-goal $Goals $Board $Goal $NewGoal) + ( (subsumed-goal $Goal $Goals $Board) + (set-det) + (unsubsumed-goal $Goals $Board $NewGoal))) +; + + (= + (ensure_new_goal $Goals $Board $Goal $Goal) True) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (create-goal $Board $Goal) + ( (choose-parameter goal-type $Type) (choose-goal-of-type $Type $Board $Goal))) +; + + + + (= + (choose-goal-of-type arrive $B $Goal) + (choose-arrive-goal $B $Goal)) +; + + (= + (choose-goal-of-type eradicate $B $Goal) + (choose-eradicate-goal $B $Goal)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (choose-stalemate-goal $Board $Stale) + ( (random-player $Board $Player) (stalemate-goal $Stale $Player))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (choose-arrive-goal $Board $Goal) + ( (choose-parameter arrive-goal-player $Player) + (choose-arrive-goal-for-player $Player $Type $Squares $Board) + (piece-description $Desc $Player $Type) + (arrive-goal $Goal $Desc $Squares))) +; + + + + (= + (choose-arrive-goal-for-player player $Type $Squares $Board) + (player-arrive-goal $Type $Squares $Board)) +; + + (= + (choose-arrive-goal-for-player any-player $Type $Squares $Board) + (player-arrive-goal $Type $Squares $Board)) +; + + (= + (choose-arrive-goal-for-player opponent $Type $Squares $Board) + (opponent-arrive-goal $Type $Squares $Board)) +; + + +; +; + + + (= + (player-arrive-goal $Type $Squares $Board) + ( (choose-unplaced-piece-set $Board $Type) + (random-square $Board $Sq) + (= $Squares + (:: $Sq)))) +; + + +; +; + +; +; + +; +; + + + (= + (opponent-arrive-goal $Type $Squares $Board) + ( (piece-generalization $Board $Type) + (opponent-random-free-square $Board $Sq) + (= $Squares + (:: $Sq)))) +; + + + + + (= + (opponent-random-free-square $Board $Sq) + ( (board-size $Board $XMax $YMax) + (array-squares $XMax $YMax $BSquares) + (random-permute $BSquares $RSquares) + (board-player-assigned-squares $Board opponent $Assigned) + (free-different-member $RSquares $Assigned $Sq))) +; + + + + (= + (free-different-member Nil $_ $_) + ( (format "Error: no free squares for opponent arrival goal!~n" Nil) + (set-det) + (fail))) +; + + (= + (free-different-member + (Cons $S $Sqs) $Assigned $Sq) + (det-if-then-else + (member $S $Assigned) + (free-different-member $Sqs $Assigned $Sq) + (= $Sq $S))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (choose-eradicate-goal $Board $Goal) + ( (choose-parameter eradicate-goal-player $Player) + (choose-eradicate-goal-for-player $Player $Type $Board) + (piece-description $Desc $Player $Type) + (eradicate-goal $Goal $Desc))) +; + + + + (= + (choose-eradicate-goal-for-player $Player $PieceGen $Board) + (eradicate-piece-generalization $Board $PieceGen)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (eradicate-piece-generalization $Board $Gen) + ( (choose-eradicate-generalization-level $L) (generalize-eradicate-piece $L $Board $Gen))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (eradicate-piece-set $Board $SortedPieces) + ( (random-placed-piece $Board $Placed) + (board-piece-types $Board $Types) + (select $Placed $Types $Rest) + (choose-set-by-param $Rest more-eradicate-pieces $Pieces) + (sort + (Cons $Placed $Pieces) $SortedPieces))) +; + + + + (= + (random-placed-piece $Board $Piece) + ( (board-placed-pieces $Board $Pieces) (random-element $Pieces $Piece))) +; + + + + (= + (choose-eradicate-generalization-level $L) + (choose-parameter eradicate-generalization-level $L)) +; + + + + (= + (generalize-eradicate-piece specific $Board $Pieces) + (eradicate-piece-set $Board $Pieces)) +; + + (= + (generalize_eradicate_piece any $Board any_piece) True) +; + + + +; +; + +; +; + +; +; + + + +; +; + +; +; + +; +; + + + + (= + (simplify-goals $Complex $Board $Simplified) + ( (remove-duplicates $Complex $Simp1) (remove-subsumed $Simp1 $Board $Simplified))) +; + + + + (= + (remove-subsumed $Goals $Board $Simplified) + (remove-subsumed $Goals $Goals $Board $Simplified)) +; + + +; +; + +; +; + + (= + (remove_subsumed () $_ $_ ()) True) +; + + (= + (remove-subsumed + (Cons $Goal $Goals) $AllGoals $Board $Gs) + ( (subsumed-goal $Goal $AllGoals $Board) + (set-det) + (remove-subsumed $Goals $AllGoals $Board $Gs))) +; + + (= + (remove-subsumed + (Cons $Goal $Goals) $AllGoals $Board + (Cons $Goal $Gs)) + (remove-subsumed $Goals $AllGoals $Board $Gs)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (subsumed-goal $Goal $Goals $Board) + ( (member $Sub $Goals) + (not (= $Sub $Goal)) + (subsumes $Sub $Goal $Board) + (tracing-gen-format subsume "~nSubsumed Goal: ~p~nSubsumed by: ~p~n" + (:: $Goal $Sub)))) +; + + +; +; + +; +; + +; +; + + + (= + (subsumes $Sub $Goal $Board) + (goal-implies $Goal $Sub $Board)) +; + + + + (= + (goal-implies $Erad1 $Erad2 $Board) + ( (eradicate-goal $Erad1 $Player1 $Type1) + (eradicate-goal $Erad2 $Player2 $Type2) + (erad-implies $Player1 $Type1 $Player2 $Type2))) +; + + (= + (goal-implies $Arr1 $Arr2 $Board) + ( (arrive-goal $Arr1 $Player1 $Type1 $Sq1) + (arrive-goal $Arr2 $Player2 $Type2 $Sq2) + (arrive-implies $Player1 $Type1 $Sq1 $Player2 $Type2 $Sq2 $Board))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (erad-implies $Player1 $Type1 $Player2 $Type2) + (type-contains $Type1 $Type2)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (arrive-implies $Player1 $Type1 $Sq1 $Player1 $Type2 $Sq2 $Board) + ( (set-det) (arrive-implies $Type1 $Sq1 $Type2 $Sq2))) +; + + (= + (arrive-implies $Player1 $Type1 $Sq1 $Player2 $Type2 $Sq2 $Board) + ( (invert-board-squares $Board $Sq1 $Sq1Inv) (arrive-implies $Type1 $Sq1Inv $Type2 $Sq2))) +; + + + (= + (arrive-implies $Type1 $Sq1 $Type2 $Sq2) + ( (type-contains $Type2 $Type1) (squares-contains $Sq2 $Sq1))) +; + + + + (= + (squares-contains $Sq1 $Sq2) + (ord-subset $Sq2 $Sq1)) +; + + + + (= + (type_contains any_piece $_) True) +; + + (= + (type-contains $Type1 $Type2) + (ord-subset $Type2 $Type1)) +; + + +; +; + +; +; + +; +; + + +; +; + + + (= + (unplaced-piece-description $Board $Desc) + (not (placed-piece-description $Board $Desc))) +; + + +; +; + + + (= + (placed-piece-description $Board $Desc) + ( (piece-description-piece $Desc $Piece) (contains-placed-piece $Piece $Board))) +; + + + + (= + (contains-placed-piece any-piece $_) + (set-det)) +; + + (= + (contains-placed-piece $Pieces $Board) + ( (board-placed-pieces $Board $Placed) + (member $P $Pieces) + (member $P $Placed) + (set-det))) +; + + +; +; + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + !(my-ensure-loaded (library tracing)) +; + + + + (= + (tracing-gen $Type $Call) + (det-if-then-else + (tracing (gen $Type)) + (call $Call) True)) +; + + +; +; + + + (= + (tracing-gen-format $Type $String $Args) + (det-if-then-else + (tracing (gen $Type)) + (format $String $Args) True)) +; + + + + (= + (tracing-gen-timing $Type $Call) + (trace-timing + (gen $Type) $Call)) +; + + + + (= + (set-gen-verbosity $Level $Status) + (set-tracing + (gen $Level) $Status)) +; + + + + (= + (silent-gen) + (all-gen off)) +; + + + (= + (loud-gen) + (all-gen on)) +; + + + + (= + (all-gen $Status) + ( (set-gen-verbosity goals $Status) + (set-gen-verbosity simplify $Status) + (set-gen-verbosity subsume $Status) + (set-gen-verbosity pieces $Status))) +; + + + + (= + (trace-gen-subsume) + (set-gen-verbosity subsume on)) +; + + + (= + (trace-gen-simplify) + (set-gen-verbosity simplify on)) +; + + + (= + (trace-gen-goals) + (set-gen-verbosity goals on)) +; + + + (= + (trace-gen-pieces) + (set-gen-verbosity pieces on)) +; + + +; +; + +; +; + + + + diff --git a/metagame/generator/gen_parameters.metta b/metagame/generator/gen_parameters.metta new file mode 100644 index 0000000..cbbf65c --- /dev/null +++ b/metagame/generator/gen_parameters.metta @@ -0,0 +1,1004 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + !(dynamic (/ forced-gen-parameter 2)) +; + + !(dynamic (/ gen-parameter 2)) +; + + + + (= + (gen_parameter board_size + (range 5 6)) True) +; + + +; +; + +; +; + +; +; + +; +; + + (= + (gen_parameter board_crowding + (distribution + ( (= 0.5 0.7) + (= 0.3 0.15) + (= 0.7 0.15)))) True) +; + + +; +; + +; +; + + (= + (gen_parameter row_crowding + (distribution + ( (= 1.0 0.7) (= 0.7 0.3)))) True) +; + + + +; +; + +; +; + + (= + (gen_parameter promotion_fraction + (distribution + ( (= 1.0 0.3) + (= 0.8 0.1) + (= 0.6 0.1) + (= 0.4 0.2) + (= 0.2 0.2) + (= 0 0.1)))) True) +; + + +; +; + +; +; + + (= + (gen_parameter piece_variety + (distribution + ( (= 1.0 0.4) + (= 0.8 0.2) + (= 0.6 0.2) + (= 0.4 0.2) + (= 0.2 0.0)))) True) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + (= + (gen_parameter promote_only_pieces + (range 1 3)) True) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (gen_parameter placement_method + (distribution + ( (= random 0.2) + (= arbitrary 0.6) + (= player 0.1) + (= opponent 0.1)))) True) +; + + + +; +; + + (= + (gen_parameter board_type + (distribution + ( (= planar 0.9) (= vertical_cylinder 0.1)))) True) +; + + +; +; + + (= + (gen_parameter board_inversion + (distribution + ( (= forward 0.5) (= diagonal 0.5)))) True) +; + + + + + +; +; + + (= + (gen_parameter + (symmetry rotation) 0.9) True) +; + + (= + (gen_parameter + (symmetry forward) 0.9) True) +; + + (= + (gen_parameter + (symmetry side) 0.9) True) +; + + +; +; + + +; +; + +; +; + + (= + (gen_parameter locality + (range 0.1 0.8)) True) +; + + + + +; +; + + (= + (gen_parameter movement_type + (distribution + ( (= leaper 0.4) + (= rider 0.4) + (= hopper 0.2)))) True) +; + + +; +; + + (= + (gen_parameter must_ride 0.2) True) +; + + +; +; + +; +; + + (= + (gen_parameter + (constrain + (hopper before $_)) 0.5) True) +; + + (= + (gen_parameter + (constrain + (hopper over $_)) 0.5) True) +; + + (= + (gen_parameter + (constrain + (hopper after $_)) 0.5) True) +; + + +; +; + + (= + (gen_parameter + (hopper before $Max) + (range 0 $Max)) True) +; + + +; +; + + (= + (gen_parameter + (hopper over $Max) + (range 1 $Max)) True) +; + + +; +; + + (= + (gen_parameter + (hopper after $Max) + (range 1 $Max)) True) +; + + + +; +; + + (= + (gen_parameter comparative + (distribution + ( (= eq 0.5) + (= geq 0.2) + (= leq 0.3)))) True) +; + + + + +; +; + +; +; + + (= + (gen_parameter movement_complexity 0.2) True) +; + + (= + (gen_parameter capture_complexity 0.2) True) +; + + (= + (gen_parameter goal_complexity 0.6) True) +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (gen_parameter + (capture_method retrieve) 0.2) True) +; + + (= + (gen_parameter + (capture_method clobber) 0.9) True) +; + + (= + (gen_parameter + (capture_method hop) 0.5) True) +; + + + + (= + (gen_parameter capture_effect + (distribution + ( (= remove 0.5) + (= + (possess player) 0.3) + (= + (possess opponent) 0.2)))) True) +; + + + +; +; + +; +; + + + (= + (gen_parameter player_generalization_level + (distribution + ( (= any 0.2) (= specific 0.8)))) True) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (gen_parameter piece_generalization_level + (distribution + ( (= any 0.5) (= specific 0.5)))) True) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (gen_parameter more_pieces 0.8) True) +; + + + (= + (gen_parameter more_general_pieces 0.8) True) +; + + + + +; +; + + + (= + (gen_parameter must_capture 0.3) True) +; + + +; +; + +; +; + + + (= + (gen_parameter continue_captures 0.1) True) +; + + + +; +; + +; +; + + + (= + (gen_parameter goal_type + (distribution + ( (= eradicate 0.5) (= arrive 0.5)))) True) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (gen_parameter arrive_goal_player + (distribution + ( (= player 0.5) (= opponent 0.5)))) True) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (gen_parameter more_arrival_pieces 0.8) True) +; + + + +; +; + +; +; + + (= + (gen_parameter eradicate_goal_player + (distribution + ( (= player 0.2) (= opponent 0.8)))) True) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (gen_parameter more_eradicate_pieces 0.8) True) +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (gen_parameter eradicate_generalization_level + (distribution + ( (= any 0.2) (= specific 0.8)))) True) +; + + + + +; +; + +; +; + + + (= + (gen_parameter specific_promotion 0.4) True) +; + + + +; +; + + + (= + (gen_parameter promotion_method + (distribution + ( (= arbitrary 0.3) + (= player 0.5) + (= opponent 0.1)))) True) +; + + + +; +; + +; +; + +; +; + + + (= + (choose-parameter $Name $Value) + ( (forced-gen-parameter $Name + (distribution $Dist)) + (set-det) + (sample-from-distribution + (distribution $Dist) $Value))) +; + + (= + (choose-parameter $Name $Value) + ( (gen-parameter $Name + (distribution $Dist)) + (set-det) + (sample-from-distribution + (distribution $Dist) $Value))) +; + + (= + (choose-parameter $Name $Value) + ( (gen-parameter $Name + (range $Min $Max)) + (set-det) + (sample-from-range + (range $Min $Max) $Value))) +; + + (= + (choose-parameter $Name $Value) + ( (gen-parameter $Name $Int) + (integer $Int) + (set-det) + (adjust-mean $Int $Value))) +; + + (= + (choose-parameter $Name $Value) + ( (gen-parameter $Name $Prob) (sample-from-distribution (distribution (:: (= yes $Prob) (= no 1))) $Value))) +; + + + + (= + (choose-parameter $Name) + (choose-parameter $Name yes)) +; + + + + + (= + (block-parameter $Name $Items) + ( (block-distribution $Name $Items $Dist) (add-symbol &self (forced_gen_parameter $Name (distribution $Dist))))) +; + + + + (= + (unblock-parameter $Name) + (remove-symbol &self + (forced_gen_parameter $Name + (distribution $Dist)))) +; + + + + (= + (reset-gen-parameters) + (remove-all-symbols &self + (forced_gen_parameter $_ $_))) +; + + + + + (= + (set-gen-parameter $P $V) + (det-if-then-else + (remove-symbol &self + (gen_parameter $P $_)) + (add-symbol &self + (gen_parameter $P $V)) + (det-if-then otherwise + (trace-output 'Unknown generator parameter ~p!~n' + (:: $P))))) +; + + + + +; +; + +; +; + +; +; + + + (= + (block-distribution $Name $Items $Dist) + ( (gen-parameter $Name + (distribution $Dist0)) + (set-det) + (remove-items $Items $Dist0 $Prob $Dist1) + (is $P1 + (/ 1 + (- 1 $Prob))) + (renormalize $Dist1 $P1 $Dist))) +; + + + + (= + (remove_items () $D 0 $D) True) +; + + (= + (remove-items + (Cons $I $Is) $Dist1 $Prob $Dist) + ( (remove-item $I $Dist1 $Prob1 $Dist2) + (remove-items $Is $Dist2 $Prob2 $Dist) + (is $Prob + (+ $Prob1 $Prob2)))) +; + + + + (= + (remove_item $I + (Cons + (= $I $P) $Dist) $P $Dist) True) +; + + (= + (remove-item $I + (Cons $H $T) $P + (Cons $H $Dist)) + (remove-item $I $T $P $Dist)) +; + + + + (= + (renormalize () $_ ()) True) +; + + (= + (renormalize + (Cons + (= $H $P) $Rest) $Ratio + (Cons + (= $H $P1) $Rest1)) + ( (is $P1 + (* $P $Ratio)) (renormalize $Rest $Ratio $Rest1))) +; + + + +; +; + + + (= + (adjust_mean $Int $Int) True) +; + + + +; +; + +; +; + +; +; + + + + (= + (show-gen-parameters) + ( (whenever + (gen-parameter $Name $Val) + (, + (portray-param (gen-parameter $Name $Val)) + (nl))) + (getrand $R) + (format '~nrandom seed = ~p~n' + (:: $R)))) +; + + + + (= + (portray-param (gen-parameter $Name $Val)) + (format "<~p> --> ~p~n" + (:: $Name $Val))) +; + + + + (= + (portray-range (range $Min $Max)) + (format "[~p .. ~p]" + (:: $Min $Max))) +; + + + + (= + (portray-dist (distribution $Pairs)) + (portray-pairs $Pairs)) +; + + + + (= + (portray_pairs ()) True) +; + + (= + (portray-pairs (Cons $Pair $Pairs)) + ( (portray-pair $Pair) (portray-pairs $Pairs))) +; + + + + (= + (portray-pair (= $Event $Val)) + (format "\n ~p: ~p" + (:: $Event $Val))) +; + + + + !(add-portrayals (:: portray-param portray-range portray-dist)) +; + + +; +; + +; +; + +; +; + + + + (= + (change-gen-param $Name) + ( (read-new-gen-value $Name $New) (set-gen-parameter $Name $New))) +; + + + + (= + (read-new-gen-value $Name $New) + ( (gen-parameter $Name $Value) (read-gen-value $Name $Value $New))) +; + + + + (= + (read-gen-value $Name $Value $New) + ( (format "Enter new settings for parameter <~p>:~n" + (:: $Name)) + (format "Old parameter setting: ~p~n" + (:: $Value)) + (read-gen-value $Value $New) + (format "New parameter setting: ~p~n" + (:: $New)))) +; + + + + (= + (read-gen-value + (distribution $Dist) + (distribution $New)) + ( (set-det) (read-dist $Dist $New))) +; + + (= + (read-gen-value + (range $Min1 $Max1) + (range $Min $Max)) + ( (set-det) (read-range $Min1 $Max1 $Min $Max))) +; + + (= + (read-gen-value $Old $New) + (read-new-val new $Old $New)) +; + + + + + (= + (read_dist () ()) True) +; + + (= + (read-dist + (Cons + (= $Event $Prob1) $Rest1) + (Cons + (= $Event $Prob2) $Rest2)) + ( (read-event $Event $Prob1 $Prob2) (read-dist $Rest1 $Rest2))) +; + + + + (= + (read-event $Event $Old $New) + ( (format "Prob for <~p> (~p): " + (:: $Event $Old)) + (read $New1) + (new-event-val $Event $Old $New1 $New))) +; + + + + (= + (new-event-val $Event $Old $New1 $New) + (new-val $Old $New1 $New)) +; + + + + (= + (new-val $Old $New1 $New) + (det-if-then-else + (= $New1 z) + (= $New $Old) + (= $New $New1))) +; + + + + + (= + (read-range $Min1 $Max1 $Min $Max) + ( (read-new-val min $Min1 $Min) (read-new-val max $Max1 $Max))) +; + + + + (= + (read-new-val $Name $Old $New) + ( (format "<~p> value (~p): " + (:: $Name $Old)) + (read $New1) + (new-val $Old $New1 $New))) +; + + + + + + diff --git a/metagame/generator/genstructs.metta b/metagame/generator/genstructs.metta new file mode 100644 index 0000000..ef5b529 --- /dev/null +++ b/metagame/generator/genstructs.metta @@ -0,0 +1,1009 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + + + + !(my-ensure-loaded (library invert)) +; + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + + + (= + (game $X) + (functor $X game 5)) +; + + + (= + (game + (game $N $B $P $G $C) $N $B $P $G $C) True) +; + + + + (= + (game-name $G $X) + (arg 1 $G $X)) +; + + + (= + (game-board $G $X) + (arg 2 $G $X)) +; + + + (= + (game-pieces $G $X) + (arg 3 $G $X)) +; + + + (= + (game-goal $G $X) + (arg 4 $G $X)) +; + + + (= + (game-constraints $G $X) + (arg 5 $G $X)) +; + + +; +; + +; +; + +; +; + + + + (= + (board $B $Size $Type $Inv $R $Arr $K $Types $Set $Ass) + ( (board-size $B $Size) + (board-type $B $Type) + (board-inversion $B $Inv) + (board-promote-rows $B $R) + (board-array-rows $B $Arr) + (board-killed $B $K) + (board-piece-types $B $Types) + (board-placed-pieces $B $Set) + (board-assignments $B $Ass))) +; + + (= + (board $X) + (functor $X board 9)) +; + + + + (= + (board-size $B $X) + (arg 1 $B $X)) +; + + + (= + (board-type $B $X) + (arg 2 $B $X)) +; + + + (= + (board-inversion $B $X) + (arg 3 $B $X)) +; + + + (= + (board-promote-rows $B $X) + (arg 4 $B $X)) +; + + + (= + (board-killed $B $X) + (arg 5 $B $X)) +; + + + (= + (board-piece-types $B $X) + (arg 6 $B $X)) +; + + + (= + (board-placed-pieces $B $X) + (arg 7 $B $X)) +; + + + (= + (board-assignments $B $X) + (arg 8 $B $X)) +; + + + (= + (board-array-rows $B $X) + (arg 9 $B $X)) +; + + + + (= + (board-unplaced-pieces $Board $Set) + ( (board-placed-pieces $Board $Placed) + (board-piece-types $Board $Types) + (ord-subtract $Types $Placed $Set))) +; + + + + + (= + (board-size $B $X $Y) + ( (board-size $B $Size) (size $Size $X $Y))) +; + + + + (= + (board-max-size $B $M) + ( (board-size $B $X $Y) (max $X $Y $M))) +; + + + + + (= + (board-assigned-squares $Board $Squares) + ( (board-assignments $Board $As) (assignments-use-squares $As $Squares))) +; + + + + (= + (board-player-assigned-squares $Board $Player $Squares) + ( (board-assigned-squares $Board $Squares1) (invert-board-squares-player $Player $Board $Squares1 $Squares))) +; + + + + (= + (assignments-use-squares $As $Squares) + ( (decision $As $Player $PieceSet $Squares) (set-det))) +; + + (= + (assignments-use-squares $Assigns $Squares) + (assigned-squares $Assigns $Squares)) +; + + + + (= + (assigned-squares $Assigns $Squares) + ( (uncollect $Assigns $Pairs) (unpair $Pairs $Squares))) +; + + + + (= + (invert_board_squares_player player $Board $Squares $Squares) True) +; + + (= + (invert-board-squares-player opponent $Board $Squares1 $Squares) + (invert-board-squares $Board $Squares1 $Squares)) +; + + + + (= + (invert-board-squares $Board $Squares1 $Squares) + ( (board-size $Board $XN $YN) + (board-inversion $Board $Inv) + (invert-squares-dim $Squares1 $Inv $XN $YN $Squares))) +; + + + + (= + (invert_squares_dim () $Inv $XN $YN ()) True) +; + + (= + (invert-squares-dim + (Cons $Sq $Sqs) $Inv $XN $YN + (Cons $ISq $ISqs)) + ( (invert-square-dim $Inv $XN $YN $Sq $ISq) (invert-squares-dim $Sqs $Inv $XN $YN $ISqs))) +; + + + + (= + (invert-square-on-board $Board $Sq1 $Sq2) + ( (board-size $Board $XN $YN) + (board-inversion $Inv) + (invert-square-dim $Inv $XN $YN $Sq1 $Sq2))) +; + + +; +; + +; +; + +; +; + + + + (= + (size + (size $X $Y) $X $Y) True) +; + + +; +; + +; +; + +; +; + + + + (= + (piece $Def) + (piece-definition $Def)) +; + + + + (= + (piece-definition $Def) + (functor $Def piece 5)) +; + + + (= + (piece-definition $Def $Name $Movement $Capture $Promote $Con) + ( (piece-definition $Def) + (piece-name $Def $Name) + (piece-movement $Def $Movement) + (piece-capture $Def $Capture) + (piece-promote $Def $Promote) + (piece-constraints $Def $Con))) +; + + + + (= + (piece-name $Piece $X) + (arg 1 $Piece $X)) +; + + + (= + (piece-movement $Piece $X) + (arg 2 $Piece $X)) +; + + + (= + (piece-capture $Piece $X) + (arg 3 $Piece $X)) +; + + + (= + (piece-promote $Piece $X) + (arg 4 $Piece $X)) +; + + + (= + (piece-constraints $Piece $X) + (arg 5 $Piece $X)) +; + + +; +; + +; +; + +; +; + + + + (= + (direction + (dir $X $Y) $X $Y) True) +; + + +; +; + +; +; + +; +; + + + + (= + (symmetry $X) + (functor $X symmetry 3)) +; + + + (= + (symmetry + (symmetry $F $S $R) $F $S $R) True) +; + + + + (= + (sym-forward $Sym $F) + (arg 1 $Sym $F)) +; + + + (= + (sym-side $Sym $S) + (arg 2 $Sym $S)) +; + + + (= + (sym-rotation $Sym $R) + (arg 3 $Sym $R)) +; + + + + (= + (forward $Sym) + (sym-forward $Sym yes)) +; + + + (= + (side $Sym) + (sym-side $Sym yes)) +; + + + (= + (rotation $Sym) + (sym-rotation $Sym yes)) +; + + + + + (= + (has-symmetry $Sym forward) + (forward $Sym)) +; + + (= + (has-symmetry $Sym side) + (side $Sym)) +; + + (= + (has-symmetry $Sym rotation) + (rotation $Sym)) +; + + + +; +; + +; +; + +; +; + + + + (= + (leaper leaper) True) +; + + +; +; + +; +; + +; +; + + + + (= + (rider + (rider $Must $Min $Max) $Must $Min $Max) True) +; + + (= + (rider $R) + (functor $R rider 3)) +; + + + + (= + (rider-must $R $Must) + (arg 1 $R $Must)) +; + + + (= + (rider-min $R $Min) + (arg 2 $R $Min)) +; + + + (= + (rider-max $R $Max) + (arg 3 $R $Max)) +; + + + + (= + (rider-must $Rider) + (rider-must $Rider yes)) +; + + +; +; + +; +; + +; +; + + + + (= + (hopper + (hopper $Restr $B $O $A) $Restr $B $O $A) True) +; + + (= + (hopper $H) + (functor $H hopper 4)) +; + + + + (= + (hopper-type $H $X) + ( (hopper $H) (arg 1 $H $X))) +; + + + (= + (hopper-before $H $X) + ( (hopper $H) (arg 2 $H $X))) +; + + + (= + (hopper-over $H $X) + ( (hopper $H) (arg 3 $H $X))) +; + + + (= + (hopper-after $H $X) + ( (hopper $H) (arg 4 $H $X))) +; + + +; +; + +; +; + +; +; + + + + (= + (movement $M) + (functor $M movement 3)) +; + + + + (= + (movement-type $M $X) + (arg 1 $M $X)) +; + + + (= + (movement-dir $M $X) + (arg 2 $M $X)) +; + + + (= + (movement-sym $M $X) + (arg 3 $M $X)) +; + + +; +; + +; +; + +; +; + + + (= + (complex_movement + (or $M1 $M2) $M1 $M2) True) +; + + +; +; + +; +; + +; +; + + + (= + (complex_capture + (or $C1 $C2) $C1 $C2) True) +; + + +; +; + +; +; + +; +; + + + + (= + (capture + (capture $Move $Methods $Restr $Effect) $Move $Methods $Restr $Effect) True) +; + + + (= + (capture $X) + (functor $X capture 4)) +; + + +; +; + + + (= + (capture-movement $H $X) + ( (capture $H) (arg 1 $H $X))) +; + + + (= + (capture-methods $H $X) + ( (capture $H) (arg 2 $H $X))) +; + + + (= + (capture-type $H $X) + ( (capture $H) (arg 3 $H $X))) +; + + + (= + (capture-effect $H $X) + ( (capture $H) (arg 4 $H $X))) +; + + + + +; +; + +; +; + +; +; + + + + (= + (comparison $X) + (functor $X comparison 2)) +; + + (= + (comparison + (comparison $Comp $Num) $Comp $Num) True) +; + + + + (= + (comparison-comp $M $X) + ( (comparison $M) (arg 1 $M $X))) +; + + + (= + (comparison-num $M $X) + ( (comparison $M) (arg 2 $M $X))) +; + +; +; + + +; +; + +; +; + +; +; + + + + (= + (square + (square $X $Y) $X $Y) True) +; + + + +; +; + +; +; + +; +; + + + + (= + (method $X) + (functor $X method 3)) +; + + (= + (method + (method $C $R $H) $C $R $H) True) +; + + + + (= + (method-clobber $M $X) + ( (method $M) (arg 1 $M $X))) +; + + + (= + (method-retrieve $M $X) + ( (method $M) (arg 2 $M $X))) +; + + + (= + (method-hop $M $X) + ( (method $M) (arg 3 $M $X))) +; + + +; +; + +; +; + +; +; + + + + (= + (piece_description + (piece_desc $Player $Piece) $Player $Piece) True) +; + + (= + (piece-description $X) + (functor $X piece-desc 2)) +; + + + + (= + (piece-description-player $M $X) + ( (piece-description $M) (arg 1 $M $X))) +; + + + (= + (piece-description-piece $M $X) + ( (piece-description $M) (arg 2 $M $X))) +; + +; +; + + +; +; + +; +; + +; +; + + + + (= + (constraint + (constraint $Must $Cont) $Must $Cont) True) +; + + (= + (constraint $X) + (functor $X constraint 2)) +; + + + + (= + (constraint-must-capture $M $X) + (arg 1 $M $X)) +; + + + (= + (constraint-continue-captures $M $X) + (arg 2 $M $X)) +; + + + (= + (constraint-continue-captures $M) + ( (constraint $M) (constraint-continue-captures $M yes))) +; + + + (= + (constraint-must-capture $M) + ( (constraint $M) (constraint-must-capture $M yes))) +; + + +; +; + +; +; + +; +; + + + (= + (complex_goal + (or $M1 $M2) $M1 $M2) True) +; + + +; +; + +; +; + +; +; + + +; +; + + + (= + (arrive_goal + (arrive $Desc $Sq) $Desc $Sq) True) +; + + + (= + (arrive-goal + (arrive $Desc $Sq) $Player $Type $Sq) + (piece-description $Desc $Player $Type)) +; + + +; +; + + + (= + (eradicate_goal + (eradicate $Desc) $Desc) True) +; + + + (= + (eradicate-goal + (eradicate $Desc) $Player $Type) + (piece-description $Desc $Player $Type)) +; + + +; +; + + + (= + (stalemate_goal + (stalemate $Player) $Player) True) +; + + + +; +; + +; +; + +; +; + + +; +; + + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + + + (= + (decision $X) + (functor $X decision 3)) +; + + (= + (decision + (decision $C $O $Con) $C $O $Con) True) +; + + + + (= + (decision-chooser $D $C) + (decision $D $C $_ $_)) +; + + + (= + (decision-options $D $O) + (decision $D $_ $O $_)) +; + + + (= + (decision-constraints $D $Con) + (decision $D $_ $_ $Con)) +; + + diff --git a/metagame/generator/grammar.metta b/metagame/generator/grammar.metta new file mode 100644 index 0000000..76f2f7f --- /dev/null +++ b/metagame/generator/grammar.metta @@ -0,0 +1,1817 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (--> + (game $Game) + (, + { (game $Game $Name $Board $Pieces $Goals $Constraints) } + (, + (game) + (, + (game_name $Name) + (, line + (, + (goal_defs $Goals) + (, line + (, + (board $Board) + (, line + (, + (opt_constraints $Constraints) + (, line + (, + (piece_defs $Pieces) + (, + (end game) period))))))))))))) True) +; + + + + (= + (--> + (game_name $Game) + (, + ($Game) + { (is-symbol $Game) })) True) +; + + + (= + (--> + (board $B) + (, + { (, + (board $B) + (, + (board_size $B $XMax $YMax) + (, + (board_type $B $Type) + (, + (board_promote_rows $B $Promote) + (, + (board_inversion $B $Inversion) + (board_assignments $B $Assignments)))))) } + (, + (board_size) + (, + (number $XMax) + (, + (by) + (, + (number $YMax) + (, line + (, + (board_type) + (, + (board_type $Type) + (, line + (, + (opt_inversion $Inversion) + (, + (promote_rank) + (, + (number $Promote) + (, line + (, + (setup) + (, line + (assignment_list $Assignments))))))))))))))))) True) +; + + + (= + (--> + (board_type planar) + (planar)) True) +; + + (= + (--> + (board_type vertical_cylinder) + (vertical_cylinder)) True) +; + + + + (= + (inversion_type forward) True) +; + + (= + (inversion_type diagonal) True) +; + + + + + + (= + (--> + (assignment_list $A) + (| + (assignment_decision $A) + (assignments $A))) True) +; + + + + (= + (--> + (assignments + ($A)) + (assignment $A)) True) +; + + (= + (--> + (assignments + (Cons $A $As)) + (, + (assignment $A) + (, line + (assignments $As)))) True) +; + + + (= + (--> + (assignment + (= $A $S)) + (, + (tab 5) + (, + (piece_name $A) + (, + (at) + (square_list $S))))) True) +; + + + (= + (--> + (assignment_decision $D) + (, + { (, + (decision $D) + (, + (decision_chooser $D $C) + (, + (decision_options $D $O) + (decision_constraints $D $Con)))) } + (, + (tab 3) + (, + (decision) + (, + (assigner $C) + (, + (assigns) + (, + (piece_names $O) + (, line + (, + (tab 5) + (, + (to) + (, + (square_list $Con) + (, line + (, + (tab 3) + (end decision)))))))))))))) True) +; + + + (= + (--> + (assigner $C) + (player $C)) True) +; + + (= + (--> + (assigner random) + (random)) True) +; + + + +; +; + + (= + (--> + (piece_defs ()) ()) True) +; + + (= + (--> + (piece_defs + (Cons $D $Defs)) + (, + (piece_def $D) + (, line + (piece_defs $Defs)))) True) +; + + + + (= + (--> + (piece_def $Def) + (, + { (piece_definition $Def $Name $Movement $Capture $Promote $Con) } + (, + (define) + (, + (piece_name $Name) + (, line + (, + (opt_moving $Movement) + (, + (opt_capturing $Capture) + (, + (opt_promoting $Name $Promote) + (, + (opt_constraints $Con) + (, + (end define) line)))))))))) True) +; + + + + (= + (--> + (opt_moving ()) ()) True) +; + + (= + (--> + (opt_moving $Movement) + (, + (tab 3) + (, + (moving) + (, line + (, + (movement_def $Movement) + (, line + (, + (tab 3) + (, + (end moving) line)))))))) True) +; + + + (= + (--> + (opt_capturing ()) ()) True) +; + + (= + (--> + (opt_capturing $Capture) + (, + (tab 3) + (, + (capturing) + (, line + (, + (capture_def $Capture) + (, line + (, + (tab 3) + (, + (end capturing) line)))))))) True) +; + + +; +; + + (= + (--> + (opt_promoting $Name + (promote $Name)) ()) True) +; + + (= + (--> + (opt_promoting $_ $Promote) + (, + (tab 3) + (, + (promoting) + (, + (promote_def $Promote) + (, line + (, + (tab 3) + (, + (end promoting) line))))))) True) +; + + + + + (= + (--> + (opt_constraints $Constraint) + (, + { (, + (constraint $Constraint) + (, + (constraint_must_capture $Constraint no) + (constraint_continue_captures $Constraint no))) } ())) True) +; + + (= + (--> + (opt_constraints $Constraint) + (, + (tab 3) + (, + (constraints) + (, + (constraint_def $Constraint) line)))) True) +; + + + +; +; + + (= + (--> + (opt_inversion diagonal) ()) True) +; + + (= + (--> + (opt_inversion $Inversion) + (, + (inversion) + (, + (inversion_def $Inversion) line))) True) +; + + + + (= + (--> + (inversion_def $Inversion) + (, + { (inversion_type $Inversion) } + ($Inversion))) True) +; + + + + + (= + (--> + (movement_def + ($M)) + (simple_movement $M)) True) +; + + (= + (--> + (movement_def + (Cons $M $Ms)) + (, + (simple_movement $M) + (, line + (, line + (movement_def $Ms))))) True) +; + + + (= + (--> + (simple_movement $M) + (, + { (, + (movement $M) + (, + (movement_type $M $T) + (, + (movement_dir $M $D) + (movement_sym $M $S)))) } + (, + (tab 15) + (, + (movement) + (, line + (, + (movement_type $T) + (, line + (, + (gdirection $D) + (, + (syms $S) + (, line + (, + (tab 15) + (end movement)))))))))))) True) +; + + + + (= + (--> + (movement_type $T) + (leaper $T)) True) +; + + (= + (--> + (movement_type $T) + (rider $T)) True) +; + + (= + (--> + (movement_type $T) + (hopper $T)) True) +; + + + (= + (--> + (leaper $L) + (, + { (leaper $L) } + (, + (tab 20) + (leap)))) True) +; + + + (= + (--> + (rider $R) + (, + { (, + (rider $R) + (, + (rider_must $R $Must) + (, + (rider_min $R $Min) + (rider_max $R $Max)))) } + (, + (tab 20) + (, + (ride) + (, + (min_dist $Min) + (, + (max_dist $Max) + (longest $Must))))))) True) +; + + + (= + (--> + (min_dist 1) ()) True) +; + + (= + (--> + (min_dist $Min) + (, + (min) + (number $Min))) True) +; + + + (= + (--> + (max_dist any) ()) True) +; + + (= + (--> + (max_dist $N) + (, + (max) + (number $N))) True) +; + + + (= + (--> + (longest no) ()) True) +; + + (= + (--> + (longest yes) + (longest)) True) +; + + + + (= + (--> + (hopper $H) + (, + { (, + (hopper $H) + (, + (hopper_before $H $B) + (, + (hopper_over $H $O) + (, + (hopper_after $H $A) + (hopper_type $H $R))))) } + (, + (tab 20) + (, + (hop) + (, + (before) + (, + (compare_eq $B) + (, + (over) + (, + (compare_eq $O) + (, + (after) + (, + (compare_eq $A) + (, line + (, + (tab 20) + (, + (hop_over) + (description $R)))))))))))))) True) +; + + + +; +; + +; +; + +; +; + + + (= + (--> + (syms $Sym) + (, + { (symmetry $Sym) } + (, + (symmetry) + (symmetry_set $Sym)))) True) +; + + +; +; + + (= + (--> + (symmetry_set $Sym) + (, + { (, + (sym_forward $Sym yes) + (, + (sym_side $Sym yes) + (sym_rotation $Sym yes))) } + (all_symmetry))) True) +; + + (= + (--> + (symmetry_set $Sym) + (, openbrace + (, + (sym_set $Sym) closebrace))) True) +; + + + (= + (--> + (sym_set $Sym) + (, + (forward $Sym) + (, + (side $Sym) + (rotation $Sym)))) True) +; + + + + (= + (--> + (forward $Sym) + (, () + { (sym_forward $Sym no) })) True) +; + + (= + (--> + (forward $Sym) + (, + (forward) + { (sym_forward $Sym yes) })) True) +; + + + (= + (--> + (side $Sym) + (, () + { (sym_side $Sym no) })) True) +; + + (= + (--> + (side $Sym) + (, + (side) + { (sym_side $Sym yes) })) True) +; + + + (= + (--> + (rotation $Sym) + (, + (rotation) + { (sym_rotation $Sym yes) })) True) +; + + (= + (--> + (rotation $Sym) + (, + { (sym_rotation $Sym no) } ())) True) +; + + +; +; + +; +; + +; +; + + +; +; + + + (= + (--> + (compare_eq $C) + (, + { (, + (comparison $C $Comp $Number) + (, + (comparison_comp $C $Comp) + (comparison_num $C $Number))) } + (, openb + (, + (x) + (, + (comparative $Comp) + (, + (delta $Number) closeb)))))) True) +; + + +; +; + + + (= + (--> + (comparative geq) + (>=)) True) +; + + (= + (--> + (comparative eq) + (=)) True) +; + + (= + (--> + (comparative leq) + (<=)) True) +; + + + +; +; + +; +; + +; +; + + + (= + (--> + (gdirection $Dir) + (, + { (direction $Dir $X $Y) } + (, + (tab 20) + (, + (<) + (, + (delta $X) + (, comma + (, + (delta $Y) + (>)))))))) True) +; + + + (= + (--> + (square_list $Squares) + (, openbrace + (, + (squares $Squares) closebrace))) True) +; + + + (= + (--> + (squares + ($H)) + (gsquare $H)) True) +; + + (= + (--> + (squares + (Cons $H $T)) + (, + (gsquare $H) + (squares $T))) True) +; + + + (= + (--> + (gsquare $Sq) + (, + { (, + (square $Sq $X $Y) + (alpha_squares_mode on)) } + (, + (() + (, + ($Col) + (, + { (nth_letter $X $Col) } + (, comma + (, + (number $Y) + ())))))))) True) +; + + + (= + (--> + (gsquare $Sq) + (, + { (, + (square $Sq $X $Y) + (alpha_squares_mode off)) } + (, + (() + (, + (number $X) + (, comma + (, + (number $Y) + ()))))))) True) +; + + + + (= + (--> + (delta $Delta) + (number $Delta)) True) +; + + + (= + (--> + (number $N) + (, + ($N) + { (number $N) })) True) +; + + + +; +; + +; +; + +; +; + + + (= + (--> + (capture_def + ($C)) + (simple_capture $C)) True) +; + + (= + (--> + (capture_def + (Cons $C $Cs)) + (, + (simple_capture $C) + (, line + (, line + (capture_def $Cs))))) True) +; + + + (= + (--> + (simple_capture $C) + (, + { (, + (capture $C) + (, + (capture_movement $C $M) + (, + (capture_methods $C $T) + (, + (capture_type $C $R) + (capture_effect $C $E))))) } + (, + (tab 5) + (, + (capture by) + (, + (capture_methods $T) + (, line + (, + (tab 14) + (, + (type) + (, + (description $R) + (, line + (, + (tab 14) + (, + (effect) + (, + (effect $E) + (, line + (, + (movement_def $M) + (, line + (, + (tab 5) + (end capture)))))))))))))))))) True) +; + + + (= + (--> + (capture_methods $M) + (, + { (method $M) } + (, openbrace + (, + (retrieve $M) + (, + (clobber $M) + (, + (hop $M) closebrace)))))) True) +; + + + + (= + (--> + (retrieve $Method) + (, () + { (method_retrieve $Method no) })) True) +; + + (= + (--> + (retrieve $Method) + (, + (retrieve) + { (method_retrieve $Method yes) })) True) +; + + + (= + (--> + (clobber $Method) + (, () + { (method_clobber $Method no) })) True) +; + + (= + (--> + (clobber $Method) + (, + (clobber) + { (method_clobber $Method yes) })) True) +; + + + (= + (--> + (hop $Method) + (, + (hop) + { (method_hop $Method yes) })) True) +; + + (= + (--> + (hop $Method) + (, + { (method_hop $Method no) } ())) True) +; + + + +; +; + +; +; + + (= + (--> + (effect remove) + (remove)) True) +; + + (= + (--> + (effect + (possess $Player)) + ($Player possesses)) True) +; + +; +; + +; +; + +; +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (--> + (goal_defs $Goals) + (, + (goals) + (goals $Goals))) True) +; + + + (= + (--> + (goals ()) ()) True) +; + + (= + (--> + (goals + (Cons $G $Goals)) + (, + (simple_goal $G) + (, line + (, + (tab 5) + (goals $Goals))))) True) +; + + + (= + (--> + (simple_goal $Arrive) + (, + { (arrive_goal $Arrive $Desc $Squares) } + (, + (arrive) + (, + (description $Desc) + (, + (at) + (square_list $Squares)))))) True) +; + + + (= + (--> + (simple_goal $Eradicate) + (, + { (eradicate_goal $Eradicate $Desc) } + (, + (eradicate) + (description $Desc)))) True) +; + + + (= + (--> + (simple_goal $Stalemate) + (, + { (stalemate_goal $Stalemate $Player) } + (, + (stalemate) + (player $Player)))) True) +; + + +; +; + +; +; + +; +; + + + (= + (--> + (description $Desc) + (, + { (piece_description $Desc $Player $Pieces) } + (, openb + (, + (player_gen $Player) + (, + (piece_names $Pieces) closeb))))) True) +; + + + (= + (--> + (piece_names any_piece) + (any_piece)) True) +; + + (= + (--> + (piece_names $Pieces) + (, openbrace + (, + (identifiers $Pieces) closebrace))) True) +; + + + (= + (--> + (identifiers + ($Piece)) + (piece_name $Piece)) True) +; + + (= + (--> + (identifiers + (Cons $P $Pieces)) + (, + (piece_name $P) + (identifiers $Pieces))) True) +; + + + + (= + (--> + (piece_name $Piece) + (, + ($Piece) + { (is-symbol $Piece) })) True) +; + + + + (= + (--> + (player_gen $Player) + (, openbrace + (, + (player $Player) closebrace))) True) +; + + (= + (--> + (player_gen any_player) + (any_player)) True) +; + + + (= + (--> + (player player) + (player)) True) +; + + (= + (--> + (player opponent) + (opponent)) True) +; + + + + (= + (player player) True) +; + + (= + (player opponent) True) +; + + + +; +; + +; +; + +; +; + + + + (= + (--> + (constraint_defs $Constraint) + (, + { (, + (constraint $Constraint) + (, + (constraint_must_capture $Constraint no) + (constraint_continue_captures $Constraint no))) } ())) True) +; + + (= + (--> + (constraint_defs $Constraint) + (, + (constraints) + (constraint_def $Constraint))) True) +; + + + + + (= + (--> + (constraint_def $Constraint) + (, + { (constraint $Constraint) } + (, + (must_capture $Constraint) + (continue_captures $Constraint)))) True) +; + + + (= + (--> + (must_capture $Constraint) + (, + { (constraint_must_capture $Constraint no) } ())) True) +; + + (= + (--> + (must_capture $Constraint) + (, + (must_capture) + { (constraint_must_capture $Constraint yes) })) True) +; + + + (= + (--> + (continue_captures $Constraint) + (, () + { (constraint_continue_captures $Constraint no) })) True) +; + + (= + (--> + (continue_captures $Constraint) + (, + { (constraint_continue_captures $Constraint yes) } + (continue_captures))) True) +; + + + + +; +; + +; +; + + + (= + (--> + (promote_def $Prom) + (, + { (decision $Prom) } + (promotion_decision $Prom))) True) +; + + (= + (--> + (promote_def + (promote $Prom)) + (, + (promote_to) + (piece_name $Prom))) True) +; + + + +; +; + +; +; + + + (= + (--> + (promotion_decision $D) + (, + { (, + (decision $D) + (, + (decision_chooser $D $C) + (decision_options $D $O))) } + (, + (decision) + (, + (player $C) + (, line + (, + (tab 10) + (, + (options) + (description $O)))))))) True) +; + + + + + (= + (--> line + (, + { (parsing_mode printing) } + (line))) True) +; + + (= + (--> line + (, + { (parsing_mode parsing) } ())) True) +; + + + (= + (--> + (tab $T) + (, + { (parsing_mode printing) } + ( (tab $T)))) True) +; + + (= + (--> + (tab $T) + (, + { (parsing_mode parsing) } ())) True) +; + + + (= + (--> + (true any) ()) True) +; + + + + (= + (--> semi + (;)) True) +; + + + (= + (--> colon + (:)) True) +; + + + (= + (--> comma + (,)) True) +; + + + (= + (--> openp + (()) True) +; + + + (= + (--> closep + ())) True) +; + + + (= + (--> openb + ([)) True) +; + + + (= + (--> closeb + (])) True) +; + + + (= + (--> openbrace + ({)) True) +; + + + (= + (--> closebrace + (})) True) +; + + + (= + (--> period + (.)) True) +; + + + + (= + (--> identifier + (, + ($X) + { (is-symbol $X) })) True) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (assignments-string $Assignment $String) + ( (var $String) + (set-det) + (assignments $Assignment $Tokens + (Cons . $Rest)) + (print-tokens-to-string $Tokens $String))) +; + + (= + (assignments-string $Assignment $String) + ( (var $Assignment) + (read-tokens-from-string $String $Tokens) + (assignments $Assignment $Tokens + (Cons . $Rest)))) +; + + +; +; + +; +; + +; +; + +; +; + + + + (= + (portray-square (square $X $Y)) + ( (with-alpha-squares (gsquare (square $X $Y) $S Nil)) (print-tokens $S))) +; + + + + (= + (portray-player player) + (write white)) +; + + (= + (portray-player opponent) + (write black)) +; + + + + (= + (portray-piece (piece $A $B)) + ( (piece + (piece $A $B) $S Nil) (print-tokens $S))) +; + + + + (= + (portray-moving (move $Piece $Player $From $To)) + ( (moving + (move $Piece $Player $From $To) $S Nil) (print-tokens $S))) +; + + + + (= + (portray-game (game $Name $Board $Pieces $Goals $Constraints)) + (format "" + (:: $Name))) +; + + +; +; + +; +; + +; +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (gen $L) + ( (generate-game $G) (game $G $L $_))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (random-game-to-file $File) + (print-gen-game-to-file $File)) +; + + + + + (= + (print-gen-game) + ( (record-seed) + (gen $G) + (print-tokens $G))) +; + + + + (= + (print-gen-game-to-file $File) + ( (record-seed) + (generate-game $G) + (set-printing-mode) + (game $G $GameList $_) + (print-game-to-file $GameList $File) + (set-parsing-mode))) +; + + + + (= + (print-game-struct $G) + ( (set-printing-mode) + (game $G $GameList $_) + (set-parsing-mode) + (print-tokens $GameList))) +; + + + + + (= + (prettify-game $GameList $Pretty) + ( (set-parsing-mode) + (game $G $GameList $_) + (set-printing-mode) + (game $G $Pretty) + (set-parsing-mode))) +; + + + + (= + (pretty-print-game-to-file $GameList $File) + ( (prettify-game $GameList $Pretty) (print-game-to-file $Pretty $File))) +; + + + +; +; + +; +; + + + (= + (print-game-to-file $Game $File) + ( (sys-suffixed-filename $File game $GameFile) + (format "~nWriting game to file: ~w~n" + (:: $GameFile)) + (tell $GameFile) + (write-old-seed) + (print-tokens $Game) + (told))) +; + + +; +; + +; +; + + + (= + (write-old-seed) + ( (old-seed $Seed) + (set-det) + (nl) + (write '% seed: ') + (write $Seed) + (nl))) +; + + (= write_old_seed True) +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (print-read-game $File) + ( (format "~nReading game from file~n" Nil) + (read-game-from-file-to-list $File $Game) + (format "~nRead game from file~n" Nil) + (set-parsing-mode) + (format "~nParsing game in parse mode~n" Nil) + (game $G $Game Nil) + (set-printing-mode) + (format "~nParsing game in print mode~n" Nil) + (game $G $Game1 Nil) + (format "~nPrinting game~n" Nil) + (print-tokens $Game1))) +; + + + + + (= + (read-game-from-file-to-list $File $Game) + ( (format "~nReading game from file: ~w~n" + (:: $File)) (read-tokens-from-file $File $Game))) +; + + + + (= + (read-game-from-string-to-list $String $Game) + ( (format "~nReading game from string. ~n" Nil) (read-tokens-from-string $String $Game))) +; + + + + + (= + (read-game-to-list $Game) + (read-tokens $Game)) +; + + + + diff --git a/metagame/generator/piece_names.metta b/metagame/generator/piece_names.metta new file mode 100644 index 0000000..789a3fa --- /dev/null +++ b/metagame/generator/piece_names.metta @@ -0,0 +1,164 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (indexed_names 1 + (ant apple artist archer albino aardvark asimov acorn andover avenger)) True) +; + + (= + (indexed_names 2 + (bear badger burgler boy bandit blaster bouncer blanket berkeley bishop barney bush budda)) True) +; + + (= + (indexed_names 3 + (cat coyote camel condor cambridge casket climber changer cleric clinton christ cheeseman)) True) +; + + (= + (indexed_names 4 + (dog dragger digger dumbo duke duchess drainer destroyer death)) True) +; + + (= + (indexed_names 5 + (friend fanatic flier fungus fool frenchman ferdi firefly fairy)) True) +; + + (= + (indexed_names 6 + (handler heaven hooter hoover honey hitchcock hoyle)) True) +; + + (= + (indexed_names 7 + (jerk jupiter jello jammer jester jouster)) True) +; + + (= + (indexed_names 8 + (lance lover loner lord laster liver llama)) True) +; + + (= + (indexed_names 9 + (man mango master monster mortal machine machete maimer mercury mohammed minsky morph)) True) +; + + (= + (indexed_names 10 + (popper pealer pot potato perot plato)) True) +; + + (= + (indexed_names 11 + (queen quester quelcher quagmire quayle)) True) +; + + (= + (indexed_names 12 + (rat robber raccoon rabbi roach railroad raster rama)) True) +; + + (= + (indexed_names 13 + (sleeper slug siren soarer screen slipper sapling squid shiva schank simon)) True) +; + + (= + (indexed_names 14 + (termite twister tusker torch totem taboo tamer thatcher)) True) +; + + (= + (indexed_names 15 + (umbrella user uranus)) True) +; + + (= + (indexed_names 16 + (violet venus volcano victor vishnu)) True) +; + + (= + (indexed_names 17 + (wheelie william welcomer warden wilkins)) True) +; + + (= + (indexed_names 18 + (xenon xylem xerox)) True) +; + + (= + (indexed_names 19 + (youth yellow yard)) True) +; + + (= + (indexed_names 20 + (zebra zero zaire zoo zeus)) True) +; + + (= + (indexed_names 21 + (elephant emu eskimo earth epstein elvis)) True) +; + + (= + (indexed_names 22 + (guru girl giraffe gasper ghandi)) True) +; + + (= + (indexed_names 23 + (igloo iceman icarus)) True) +; + + (= + (indexed_names 24 + (king kangaroo killer krishna korf kant)) True) +; + + (= + (indexed_names 25 + (necromancer nasty night nicko)) True) +; + + (= + (indexed_names 26 + (ostrich oak oven oscar opener)) True) +; + + diff --git a/metagame/generator/tokenizer.metta b/metagame/generator/tokenizer.metta new file mode 100644 index 0000000..5adc056 --- /dev/null +++ b/metagame/generator/tokenizer.metta @@ -0,0 +1,1165 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + + + (= + (read-tokens-from-file $File $Tokens) + ( (see $File) + (read-tokens $Tokens) + (set-det) + (seen))) +; + + (= + (read-tokens-from-file $File $Tokens) + ( (format "~nError: Couldn't read tokens from file ~w~n" + (:: $File)) + (seen) + (fail))) +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (read-tokens $Tokens) + ( (read-chars $Chars) (tokenize-chars $Chars $Tokens))) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (read-keyboard-tokens $Tokens) + ( (read-chars-period-include $Chars) (tokenize-chars $Chars $Tokens))) +; + + + +; +; + +; +; + +; +; + + + (= + (read-chars $Chars) + (read-chars -1 n $Chars)) +; + + +; +; + +; +; + +; +; + + + (= + (read-line $Chars) + (read-chars 10 n $Chars)) +; + + + +; +; + +; +; + +; +; + + + (= + (read-chars-period-include $Chars) + (read-chars 46 y $Chars)) +; + + +; +; + +; +; + +; +; + + + (= + (read-chars-period $Chars) + (read-chars 46 n $Chars)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (read-chars $End $Include $Chars) + (read-chars $End n n $Include $Chars)) +; + + + (= + (read-chars $End $Quote $Comment $Include $Chars) + ( (read-char $C) (read-chars $C $End $Quote $Comment $Include $Chars))) +; + + + (= + (read-chars $End $End n n y + (:: $End)) + (set-det)) +; + + (= + (read-chars $End $End n n n Nil) + (set-det)) +; + + (= + (read-chars -1 $_ $_ $_ $_ Nil) + (set-det)) +; + + (= + (read-chars $C $End $Quote1 $Comment1 $Include + (Cons $C $Cs)) + ( (toggle-contexts $C $Quote1 $Comment1 $Quote $Comment) (read-chars $End $Quote $Comment $Include $Cs))) +; + + + + (= + (toggle-contexts $C $Quote1 $Comment1 $Quote $Comment) + ( (toggle-quote $C $Quote1 $Quote) (toggle-comment $C $Comment1 $Comment))) +; + + +; +; + +; +; + + + (= + (toggle_quote 39 n y) True) +; + + (= + (toggle_quote 39 y n) True) +; + + (= + (toggle_quote $_ $Q $Q) True) +; + + +; +; + +; +; + +; +; + + + (= + (toggle_comment 37 n y) True) +; + + (= + (toggle_comment 10 y n) True) +; + + (= + (toggle_comment $_ $C $C) True) +; + + +; +; + + + (= + (read-char $Char) + (get0 $Char)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (read-tokens-from-string $String $Tokens) + (tokenize-chars $String $Tokens)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (tokenize-chars $Chars $Tokens) + (tokens $Tokens Nil $Chars $_)) +; + + + +; +; + +; +; + + + + (= + (--> + (tokens + (.) ()) + (46)) True) +; + + (= + (--> + (tokens $In $Out) + (, + (token $In $S) + (tokens $S $Out))) True) +; + + + + (= + (--> + (token + (Cons $C $Rest) $Rest) + (, + (identifier $C) !)) True) +; + + (= + (--> + (token $Rest $Rest) + (, + (layout_string $C) !)) True) +; + + (= + (--> + (token $Rest $Rest) + (, + (comment $C) !)) True) +; + + (= + (--> + (token + (Cons $C $Rest) $Rest) + (operator $C)) True) +; + + (= + (--> + (token + (Cons $C $Rest) $Rest) + (quote_symbol $C)) True) +; + + + +; +; + +; +; + +; +; + + + (= + (--> + (quote_symbol $C) + (, + (quote_char $_) + (, + (non_quote_chars $Cs) + (, + (quote_char $_) + { (string_chars $Cs $C) })))) True) +; + + + (= + (--> + (non_quote_chars ()) ()) True) +; + + (= + (--> + (non_quote_chars + (Cons $C $Cs)) + (, + (non_quote_char $C) + (more_non_quote_chars $Cs))) True) +; + + + (= + (--> + (more_non_quote_chars $Cs) + (non_quote_chars $Cs)) True) +; + + (= + (--> + (more_non_quote_chars ()) ()) True) +; + + + (= + (--> + (non_quote_char $C) + (, + (quote_char $C) + (, ! + {fail }))) True) +; + + (= + (--> + (non_quote_char $C) + ($C)) True) +; + + + (= + (--> + (quote_char 39) + (39)) True) +; + + +; +; + +; +; + +; +; + + + + (= + (--> + (comment $C) + (, + (37) + (, + (non_lf_chars $Cs) + (, + (linefeed $_) + { (string_chars $Cs $C) })))) True) +; + + + (= + (--> + (non_lf_chars ()) ()) True) +; + + (= + (--> + (non_lf_chars + (Cons $C $Cs)) + (, + (non_lf_char $C) + (more_non_lf_chars $Cs))) True) +; + + + (= + (--> + (more_non_lf_chars $Cs) + (non_lf_chars $Cs)) True) +; + + (= + (--> + (more_non_lf_chars ()) ()) True) +; + + + (= + (--> + (non_lf_char $C) + (, + (linefeed $C) + (, ! + {fail }))) True) +; + + (= + (--> + (non_lf_char $C) + ($C)) True) +; + + + (= + (--> + (linefeed 10) + (10)) True) +; + + +; +; + +; +; + +; +; + + + + (= + (--> + (operator $X) + (, + (comparison_operator $X) !)) True) +; + + (= + (--> + (operator $X) + (, + (transfer_operator $X) !)) True) +; + + (= + (--> + (operator $X) + (, + ($Y) + { (terminal_char $Y $X) })) True) +; + + + (= + (--> + (comparison_operator >=) + (, + (62) + (61))) True) +; + + (= + (--> + (comparison_operator <=) + (, + (60) + (61))) True) +; + + + (= + (--> + (transfer_operator ->) + (45 62)) True) +; + + + + + (= + (terminal-char $X $Y) + ( (terminal $X) (name $Y (:: $X)))) +; + + +; +; + + + (= + (terminal 123) True) +; + + (= + (terminal 125) True) +; + + (= + (terminal 44) True) +; + + (= + (terminal 60) True) +; + + (= + (terminal 62) True) +; + + (= + (terminal 91) True) +; + + (= + (terminal 93) True) +; + + (= + (terminal 40) True) +; + + (= + (terminal 41) True) +; + + (= + (terminal 61) True) +; + + + (= + (terminal 45) True) +; + + (= + (terminal 47) True) +; + + (= + (terminal 59) True) +; + + +; +; + +; +; + +; +; + + + + (= + (--> + (layout_string + (Cons $X $Xs)) + (, + (layout_char $X) + (more_layout_chars $Xs))) True) +; + + (= + (--> + (more_layout_chars $Xs) + (, + (layout_string $Xs) !)) True) +; + + (= + (--> + (more_layout_chars ()) ()) True) +; + + + + (= + (--> + (layout_char $X) + (, + ($X) + { (layout_char $X) })) True) +; + + + + (= + (layout_char 9) True) +; + + (= + (layout_char 10) True) +; + + (= + (layout_char 32) True) +; + + + +; +; + +; +; + +; +; + + + + (= + (--> + (identifier $Id) + (, + (alphanumchars $Chars) + { (string_chars $Chars $Id) })) True) +; + + + + + (= + (string-chars $Chars $Id) + (name $Id $Chars)) +; + + + + (= + (chars_to_nums () ()) True) +; + + (= + (chars-to-nums + (Cons $H $T) + (Cons $NH $NT)) + ( (name $H + (:: $NH)) (chars-to-nums $T $NT))) +; + + + + (= + (--> + (alphanumchars + (Cons $X $Xs)) + (, + (alphanumchar $X) + (more_alphanumchars $Xs))) True) +; + + + (= + (--> + (more_alphanumchars $X) + (, + (alphanumchars $X) !)) True) +; + + (= + (--> + (more_alphanumchars ()) ()) True) +; + + + (= + (--> + (alphanumchar $Y) + (, + ($X) + { (alphanumchar $X $Y) })) True) +; + + +; +; + + + (= + (alphanumchar $X $X) + ( (>= $X 97) (=< $X 122))) +; + + (= + (alphanumchar $X $X) + ( (>= $X 48) (=< $X 57))) +; + + (= + (alphanumchar $X $Y) + ( (>= $X 65) + (=< $X 90) + (downcase-char $X $Y))) +; + + (= + (alphanumchar 95 95) True) +; + + + + + (= + (downcase-char $Upper $Lower) + (downcase-char-num $Upper $Lower)) +; + + + + (= + (downcase-char-num $Upper $Lower) + ( (uppercase $Upper) + (set-det) + (is $Lower + (- + (+ $Upper "a") "A")))) +; + + (= + (downcase_char_num $X $X) True) +; + + + + (= + (uppercase $N) + ( (>= $N "A") (=< $N "Z"))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (parsing-mode $M) + (parameter parsing-mode $M)) +; + + +; +; + + + (= + (set-parsing-mode $Mode) + (set-parameter parsing-mode $Mode)) +; + + + (= + (set-parsing-mode) + (set-parsing-mode parsing)) +; + + + (= + (set-printing-mode) + (set-parsing-mode printing)) +; + + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (set-alpha-squares-mode $M) + (set-parameter alpha-squares-mode $M)) +; + + + + (= + (alpha-squares-mode $M) + (parameter alpha-squares-mode $M)) +; + + + +; +; + +; +; + +; +; + +; +; + + + + (= + (with-alpha-squares $Goal) + ( (alpha-squares-mode $Mode) + (set-alpha-squares-mode on) + (with-alpha-squares $Goal $Mode))) +; + + + (= + (with-alpha-squares $Goal $Mode) + ( (call $Goal) + (set-det) + (set-alpha-squares-mode $Mode))) +; + + (= + (with-alpha-squares $Goal $Mode) + ( (set-alpha-squares-mode $Mode) (fail))) +; + + + + (= + (recover-grammar) + (add-parameter alpha-squares-mode off)) +; + + +; +; + + + + + + + (= + (print-token line) + ( (set-det) (nl))) +; + + (= + (print-token (tab $T)) + ( (set-det) (tab $T))) +; + + (= + (print-token $X) + ( (write $X) (tab 1))) +; + + + + (= + (print_tokens ()) True) +; + + (= + (print-tokens (Cons $H $T)) + ( (print-token $H) (print-tokens $T))) +; + + + + (= + (print-tokens-to-file $Tokens $File) + ( (set-printing-mode) + (tell $File) + (print-tokens $Tokens) + (told))) +; + + + + + (= + (print-token-to-string line Nil) + (set-det)) +; + + (= + (print-token-to-string + (tab $T) Nil) + (set-det)) +; + + (= + (print-token-to-string $X $String) + (name $X $String)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + + (= + (print_tokens_to_string () ()) True) +; + + (= + (print-tokens-to-string + (Cons $H $T) $String) + ( (print-token-to-string $H $StrH) + (print-tokens-to-string $T $StrT) + (append $StrH + (Cons 32 $StrT) $String))) +; + + + + diff --git a/metagame/learning/analysis.metta b/metagame/learning/analysis.metta new file mode 100644 index 0000000..131b512 --- /dev/null +++ b/metagame/learning/analysis.metta @@ -0,0 +1,1184 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + + + (= + (build-transition-matrix) + ( (new-empty-state $State) (build-transition-matrix $Matrix $State))) +; + + + + (= + (build-transition-matrix $Matrix $State) + (map-piece-table transition-matrix + (:: $State) $Matrix)) +; + + + + (= + (print-transition-matrix) + (print-transition-matrix $Sq $Piece $SqT)) +; + + + (= + (print-transition-matrix $Sq $Piece $SqT) + ( (format "Piece Square Transition Matrix:~n" Nil) (or (, (square-piece-transition $Sq $Piece $SqT) (format "~p: ~p -> ~p~n" (:: $Piece $Sq $SqT)) (fail)) True))) +; + + + + + (= + (spt $S $P $V) + (square-piece-transition $S $P $V)) +; + + +; +; + +; +; + +; +; + + + (= + (square-piece-transition $Sq $Piece $SqT) + ( (advice-tables $Tables) (square-piece-transition $Sq $Piece $SqT $Tables))) +; + + +; +; + +; +; + +; +; + + (= + (square-piece-transition $Sq $Piece $SqT $Tables) + (square-piece-transition $Sq $SqI $Piece $PieceI $SqT $SqTI $Tables)) +; + + + (= + (square-piece-transition $Sq $SqI $Piece $PieceI $SqT $SqTI $Tables) + ( (piece-index $Piece $PieceI) + (square-index $Sq $SqI) + (square-piece-sq $SqI $PieceI $SqTI $Tables) + (square-index $SqT $SqTI))) +; + + + + (= + (square-piece-sq $SqI $PieceI $SqTI $Tables) + ( (transition-matrix $Tables $M) (square-piece-sq1 $SqI $PieceI $SqTI $M))) +; + + + + (= + (square-piece-sq1 $SqI $PieceI $SqTI $M) + ( (piece-table-entry $_ $PieceI $M $Entry) + (member1-pair + (- $SqI $Ts) $Entry) + (member $SqTI $Ts))) +; + + + + (= + (square-piece-sqs $SqI $PieceI $TIs) + ( (transition-matrix $M) (square-piece-sqs $SqI $PieceI $TIs $M))) +; + + + (= + (square-piece-sqs $SqI $PieceI $TIs $M) + ( (piece-table-entry $_ $PieceI $M $Entry) (member1-pair (- $SqI $TIs) $Entry))) +; + + + +; +; + +; +; + + + (= + (transition-matrix $Piece $PieceIndex $State $Matrix) + ( (piece-index $Piece $PieceIndex) + (setof + (- $SqIndex $SqTIndices) + (^ $Sq + (safe-transitions-type $Piece $PieceIndex $Sq $SqIndex moving $SqTIndices $State)) $Matrix) + (tracing-anal-format tables "Built transition matrix for <~p>~n" + (:: $Piece)))) +; + + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (build-mobility-matrix $Matrix) + ( (transition-matrix $Trans) (build-mobility-matrix $Trans $Matrix))) +; + + +; +; + + (= + (build-mobility-matrix $Trans $Matrix) + (map-piece-table mobility-matrix + (:: $Trans) $Matrix)) +; + + + + (= + (mobility-matrix $Piece $PieceIndex $Matrix) + ( (transition-matrix $Trans) (mobility-matrix $Piece $PieceIndex $Trans $Matrix))) +; + + + (= + (mobility-matrix $Piece $PieceIndex $Trans $Matrix) + ( (piece-index $Piece $PieceIndex) + (map-square-table square-p-mob + (:: $Piece $PieceIndex $Trans) $Matrix) + (tracing-anal-format tables "Built mobility table for <~p>~n" + (:: $Piece)))) +; + + + + (= + (square-p-mob $Sq $SqIndex $Piece $PieceIndex $Trans $Value) + (piece-square-mob $Piece $PieceIndex $Sq $SqIndex $Trans $Value)) +; + + + + (= + (square-piece-mob $SqI $PieceI $Val) + ( (advice-tables $Tables) (square-piece-mob $SqI $PieceI $Val $Tables))) +; + + + (= + (square-piece-mob $SqI $PieceI $Val $Tables) + ( (mobility-matrix $Tables $M) + (pindex-table-entry $PieceI $M $Entry) + (sindex-table-entry $SqI $Entry $Val))) +; + + + + (= + (spm $S $P $V) + (square-piece-mobility $S $P $V)) +; + + +; +; + +; +; + +; +; + + + (= + (square-piece-mobility $Sq $Piece $Value) + ( (advice-tables $Tables) (square-piece-mobility $Sq $Piece $Value $Tables))) +; + + +; +; + +; +; + +; +; + + (= + (square-piece-mobility $Sq $Piece $Value $Tables) + ( (piece-index $Piece $PieceI) + (square-index $Sq $SqI) + (square-piece-mob $SqI $PieceI $Value $Tables))) +; + + + + + (= + (piece-square-mob $Piece $Sq $Value) + ( (transition-matrix $TransMatrix) (piece-square-mob $Piece $Sq $TransMatrix $Value))) +; + + + (= + (piece-square-mob $Piece $Sq $TransMatrix $Value) + (piece-square-mob $Piece $PieceIndex $Sq $SquareIndex $TransMatrix $Value)) +; + + + (= + (piece-square-mob $Piece $PieceIndex $Sq $SquareIndex $TransMatrix $Value) + ( (piece-index $Piece $PieceIndex) + (trace-timing + (anal mob-count) + (mob-count $PieceIndex $SquareIndex $TransMatrix $Value)) + (tracing-anal-format detailed "~p: ~p -> ~p~n" + (:: $Piece $Sq $Value)))) +; + + + + (= + (mob-count $Piece $Sq $Trans $Value) + ( (square-piece-sqs $Sq $Piece $Moves $Trans) (length $Moves $Value))) +; + + +; +; + +; +; + + + (= + (print-mobility-matrix) + (print-mobility-matrix $_ $_)) +; + + + (= + (print-mobility-matrix $Sq $Piece) + ( (format "Square Piece Mobility Matrix:~n" Nil) (or (, (square-piece-mobility $Sq $Piece $Value) (format "matrix[~p][~p] = ~p~n" (:: $Sq $Piece $Value)) (fail)) True))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (build-eventual-matrix $Matrix) + ( (distance-matrix $Dist) (build-eventual-matrix $Dist $Matrix))) +; + + +; +; + + (= + (build-eventual-matrix $Dist $Matrix) + (map-piece-table eventual-matrix + (:: $Dist) $Matrix)) +; + + + + (= + (eventual-matrix $Piece $PieceIndex $Matrix) + ( (distance-matrix $Dist) (eventual-matrix $Piece $PieceIndex $Dist $Matrix))) +; + + +; +; + + (= + (eventual-matrix $Piece $PieceIndex $DistMatrix $Matrix) + ( (= $Distance 4) + (piece-indist-matrix $Piece $PieceIndex $Distance $DistMatrix $Matrix) + (tracing-anal-format tables "Built eventual table for <~p>~n" + (:: $Piece)))) +; + + + +; +; + +; +; + +; +; + + + (= + (square-piece-reachability $Sq $Piece $Value) + ( (advice-tables $Tables) (square-piece-reachability $Sq $Piece $Value $Tables))) +; + + +; +; + +; +; + +; +; + + (= + (square-piece-reachability $Sq $Piece $Value $Tables) + ( (piece-index $Piece $PieceI) + (square-index $Sq $SqI) + (square-piece-reach $SqI $PieceI $Value $Tables))) +; + + + + + (= + (square-piece-reach $SqI $PieceI $Val $Tables) + ( (eventual-matrix $Tables $M) + (pindex-table-entry $PieceI $M $Entry) + (sindex-table-entry $SqI $Entry $Val))) +; + + + +; +; + +; +; + + + (= + (print-eventual-matrix) + (print-eventual-matrix $_ $_)) +; + + + (= + (print-eventual-matrix $Sq $Piece) + ( (format "Square Piece Eventual Matrix:~n" Nil) (or (, (square-piece-reachability $Sq $Piece $Value) (format "matrix[~p][~p] = ~p~n" (:: $Sq $Piece $Value)) (fail)) True))) +; + + +; +; + +; +; + +; +; + + +; +; + + + (= + (build-distance-matrix $Trans $Matrix) + (map-piece-table distance-matrix + (:: $Trans) $Matrix)) +; + + + + + (= + (build-distance-table) + ( (distance-matrix $M) (build-distance-table $M $_))) +; + + + +; +; + + (= + (build-distance-table $Trans $Matrix) + (map-piece-table distance-table + (:: $Trans) $Matrix)) +; + + + + + (= + (distance-matrix $Piece $PieceIndex $Matrix) + ( (transition-matrix $Trans) (distance-matrix $Piece $PieceIndex $Trans $Matrix))) +; + + + (= + (distance-matrix $Piece $PieceIndex $Trans $Matrix) + ( (piece-table-entry $Piece $PieceIndex $Trans $Matrix1) + (s-floyd $Matrix1 $Matrix) + (tracing-anal-format tables "Built distance matrix for <~p>~n" + (:: $Piece)))) +; + + + + + (= + (distance-table $Piece $PieceIndex $Table) + ( (distance-matrix $Matrix) (distance-table $Piece $PieceIndex $Matrix $Table))) +; + + + (= + (distance-table $Piece $PieceIndex $Dist $Table) + ( (piece-table-entry $Piece $PieceIndex $Dist $Matrix) + (matrix-to-square-table $Matrix $Table) + (tracing-anal-format tables "Built distance table for <~p>~n" + (:: $Piece)))) +; + + + + + + (= + (square-piece-sq-dist $SqI $PieceI $SqTI $Dist $Tables) + ( (distance-table $Tables $Table) (square-piece-sq-dist1 $SqI $PieceI $SqTI $Table $Dist))) +; + + +; +; + + + (= + (square-piece-sq-dist1 $SqI $PieceI $SqTI $Table $Dist) + ( (piece-table-entry $_ $PieceI $Table $Entry) + (square-table-distance $SqI $SqTI $Entry $Dist) + (set-det))) +; + + +; +; + + + (= + (square-piece-sq-dist-max $SqI $PieceI $SqTI $DTable $Dist) + (det-if-then-else + (square-piece-sq-dist1 $SqI $PieceI $SqTI $DTable $Dist) True + (= $Dist 10000))) +; + + + + (= + (square-piece-list-dist $SqI $PieceI $SqTI $Dist) + ( (distance-matrix $Matrix) (square-piece-list-dist $SqI $PieceI $SqTI $Matrix $Dist))) +; + + + (= + (square-piece-list-dist $SqI $PieceI $SqTI $Table $Dist) + ( (piece-table-entry $_ $PieceI $Table $Entry) (square-matrix-distance $SqI $SqTI $Entry $Dist))) +; + + + + (= + (square-piece-list-distance $SqI $PieceI $SqTI $Dist) + ( (distance-matrix $Matrix) (square-piece-list-distance $SqI $PieceI $SqTI $Matrix $Dist))) +; + + + (= + (square-piece-list-distance $SqI $PieceI $SqTI $Table $Dist) + ( (piece-table-entry $_ $PieceI $Table $Entry) (square-matrix-distance $SqI $SqTI $Entry $Dist))) +; + + + + + + (= + (print-distance-matrix) + (print-distance-matrix $_ $_ $_)) +; + + + + (= + (print-distance-matrix $Sq $Piece $SqT) + ( (format "Square Piece Distance Matrix:~n" Nil) (or (, (square-piece-list-distance $Sq $Piece $SqT $Dist) (format "~p: ~p -> ~p <~p>~n" (:: $Piece $Sq $SqT $Dist)) (fail)) True))) +; + + + + + (= + (print-distance-table) + (print-distance-table $_ $_ $_)) +; + + + + (= + (print-distance-table $Sq $Piece $SqT) + ( (format "Square Piece Distance Table:~n" Nil) (or (, (square-piece-distance $Sq $Piece $SqT $Dist) (format "~p: ~p -> ~p <~p>~n" (:: $Piece $Sq $SqT $Dist)) (fail)) True))) +; + + + + + (= + (piece-distance-table $Piece $Table) + ( (distance-table $D) (piece-table-entry $Piece $_ $D $Table))) +; + + + + + (= + (spd $S $P $SqT $V) + (square-piece-distance $S $P $SqT $V)) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (square-piece-distance $Sq $Piece $SqT $Dist) + ( (advice-tables $Tables) (square-piece-distance $Sq $Piece $SqT $Dist $Tables))) +; + + +; +; + +; +; + +; +; + +; +; + + (= + (square-piece-distance $Sq $Piece $SqT $Dist $Tables) + (square-piece-distance $Sq $SqI $Piece $PieceI $SqT $SqTI $Dist $Tables)) +; + + + (= + (square-piece-distance $Sq $SqI $Piece $PieceI $SqT $SqTI $Dist $Tables) + ( (piece-index $Piece $PieceI) + (square-index $Sq $SqI) + (square-index $SqT $SqTI) + (square-piece-sq-dist $SqI $PieceI $SqTI $Dist $Tables))) +; + + + + +; +; + +; +; + +; +; + + + + (= + (square-piece-reaches $Sq $Piece $Squares) + ( (transition-matrix $Trans) + (piece-table-entry $Piece $_ $Trans $PTrans) + (square-piece-reaches $Sq $SqIndex $PTrans $Squares))) +; + + + (= + (square-piece-reaches $Sq $SqIndex $Trans $Squares) + ( (square-index $Sq $SqIndex) (sq-piece-reaches $SqIndex $Trans $Squares))) +; + + + + (= + (sq-piece-reaches $Sq $Trans $Squares) + (reachable $Sq $Trans $Squares)) +; + + + + + (= + (indist-set $Piece $Sq $SqT $Dist $Set) + (setof $SqT + (indist $Piece $Sq $SqT $Dist) $Set)) +; + + + + (= + (indist-set2 $Piece $Sq $SqT $Dist $Set) + (setof $SqT + (indist $Piece $Sq $SqT $Dist) $Set)) +; + + + + + (= + (indist $Piece $Sq $SqT $Dist) + ( (distance-table $Table) (piece-square-within-distance $Piece $_ $Sq $SqI $SqT $SqTI $Dist $Table))) +; + + + + + (= + (piece-square-at-distance $Piece $PieceI $Sq $SqI $SqT $SqTI $Dist $Table) + ( (piece-table-entry $Piece $PieceI $Table $T) + (square-index $Sq $SqI) + (square-index $SqT $SqTI) + (square-table-distance $SqI $SqTI $T $D) + (=< $D $Dist))) +; + + +; +; + + + (= + (piece-dist-squares-matrix $P $PI $Sq $SqI $Squares) + ( (distance-matrix $D) (piece-dist-squares-matrix $P $PI $Sq $SqI $D $Squares))) +; + + + + (= + (piece-dist-squares-matrix $P $PI $Sq $SqI $DistMatrix $Squares) + ( (piece-table-entry $P $PI $DistMatrix $Matrix) + (member1-pair + (- $SqI $Dist) $Matrix) + (p-transpose $Dist $New) + (p-to-s-graph $New $Squares))) +; + + + + (= + (piece-dist-squares $P $PI $Sq $SqI $Distance $Squares) + ( (distance-matrix $DistMatrix) (piece-dist-squares $P $PI $Sq $SqI $Distance $DistMatrix $Squares))) +; + + + (= + (piece-dist-squares $P $PI $Sq $SqI $Distance $DistMatrix $Squares) + ( (piece-dist-squares-matrix $P $PI $Sq $SqI $DistMatrix $Matrix) (member1-pair (- $Distance $Squares) $Matrix))) +; + + + + (= + (piece-dist-count $P $Sq $Distance $Count) + ( (piece-index $P $PI) + (square-index $Sq $SqI) + (piece-dist-count $P $PI $Sq $SqI $Distance $Count))) +; + + + (= + (piece-dist-count $P $PI $Sq $SqI $Distance $Count) + ( (distance-matrix $DistMatrix) (piece-dist-count $P $PI $Sq $SqI $Distance $DistMatrix $Count))) +; + + + (= + (piece-dist-count $P $PI $Sq $SqI $Distance $DistMatrix $Count) + ( (piece-dist-squares $P $PI $Sq $SqI $Distance $DistMatrix $Squares) (length $Squares $Count))) +; + + + + + (= + (piece-indist-sum $Piece $PieceI $Sq $SqI $Distance $Count) + ( (distance-matrix $DistMatrix) (piece-indist-sum $Piece $PieceI $Sq $SqI $Distance $DistMatrix $Count))) +; + + + (= + (piece-indist-sum $Piece $PieceI $Sq $SqI $Distance $DistMatrix $Count) + ( (bagof $Count1 + (piece-indist-count $Piece $PieceI $Sq $SqI $Distance $DistMatrix $Count1) $Counts) + (square-index $Sq $SqI) + (sumlist $Counts $Count))) +; + + + + (= + (piece-indist-count $Piece $PieceI $Sq $SqI $Distance $Count) + ( (distance-matrix $DistMatrix) (piece-indist-count $Piece $PieceI $Sq $SqI $Distance $DistMatrix $Count))) +; + + + (= + (piece-indist-count $Piece $PieceI $Sq $SqI $Distance $DistMatrix $Count) + ( (piece-dist-count $Piece $PieceI $Sq $SqI $Dist1 $DistMatrix $Count) (=< $Dist1 $Distance))) +; + + + + + (= + (piece-indist-crunchsum $P $PI $Sq $SqI $Distance $Count) + ( (distance-matrix $DistMatrix) (piece-indist-crunchsum $P $PI $Sq $SqI $Distance $DistMatrix $Count))) +; + + + (= + (piece-indist-crunchsum $P $PI $Sq $SqI $Distance $DistMatrix $Count) + ( (piece-dist-squares-matrix $P $PI $Sq $SqI $DistMatrix $Squares) + (crunch-ds $Squares $S) + (count-less $S $Distance $Count))) +; + + + + + + (= + (piece-discounted-sum $P $PI $Sq $SqI $Distance $Count) + ( (distance-matrix $DistMatrix) (piece-discounted-sum $P $PI $Sq $SqI $Distance $DistMatrix $Count))) +; + + + (= + (piece-discounted-sum $P $PI $Sq $SqI $Distance $DistMatrix $Count) + ( (piece-dist-squares-matrix $P $PI $Sq $SqI $DistMatrix $Squares) + (crunch-ds $Squares $Series) + (discounted-sum $Series $Distance $Count))) +; + + + + + + (= + (piece-indist-matrix $P $PI $Distance $Matrix) + ( (distance-matrix $DistMatrix) (piece-indist-matrix $P $PI $Distance $DistMatrix $Matrix))) +; + + + (= + (piece-indist-matrix $P $PI $Distance $DistMatrix $Matrix) + ( (piece-index $P $PI) (map-square-table sq-piece-indist-crunchsum (:: $P $PI $Distance $DistMatrix) $Matrix))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (sq-piece-indist-crunchsum $Sq $SqI $P $PI $Distance $DistMatrix $Count) + (piece-discounted-sum $P $PI $_ $SqI $Distance $DistMatrix $Count)) +; + + + + + + + (= + (crunch-invert $SqDs $DSqs) + ( (p-transpose $SqDs $New) (p-to-s-graph $New $DSqs))) +; + + + + + (= + (crunchtop () ()) True) +; + + (= + (crunchtop + (Cons + (- $Sq $Sqs) $G) + (Cons + (- $Sq $Ds) $GRest)) + ( (crunch-invert $Sqs $DSqs) + (crunch-ds $DSqs $Ds) + (crunchtop $G $GRest))) +; + + +; +; + +; +; + +; +; + + + (= + (crunch_ds () ()) True) +; + + (= + (crunch-ds + (Cons + (- $D $Sqs) $G) + (Cons + (- $D $Count) $Rest)) + ( (length $Sqs $Count) (crunch-ds $G $Rest))) +; + + + + (= + (count_less () $_ 0) True) +; + + (= + (count-less + (Cons + (- $Dist $_) $_) $Max 0) + ( (< $Max $Dist) (set-det))) +; + + (= + (count-less + (Cons + (- $Dist $C1) $As) $Max $Count) + ( (count-less $As $Max $CRest) (is $Count (+ $C1 $CRest)))) +; + + +; +; + + + (= + (discounted-sum $Series $Discount $Sum) + (discounted-sum $Series $Discount 0 $Sum)) +; + + + (= + (discounted_sum () $_ $Count $Count) True) +; + + (= + (discounted-sum + (Cons + (- $Dist $C1) $Rest) $Discount $Sum1 $Sum) + ( (discount-value $Dist $C1 $Discount $Val) + (is $Sum2 + (+ $Sum1 $Val)) + (discounted-sum $Rest $Discount $Sum2 $Sum))) +; + + + + (= + (discount-value $Distance $Count $Discount $Val) + ( (distance-value $Distance $V) (is $Val (* $Count $V)))) +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (rev-transition-matrix $Piece $PieceIndex $Matrix $State) + ( (transition-matrix $Piece $PieceIndex $Matrix1 $State) (s-transpose $Matrix1 $Matrix))) +; + + + + (= + (rev-distance-matrix $Piece $PieceIndex $Matrix $State) + ( (rev-transition-matrix $Piece $PieceIndex $Matrix1 $State) (s-floyd $Matrix1 $Matrix))) +; + + + + (= + (rev-distance-table $Piece $PieceIndex $Table $State) + ( (rev-distance-matrix $Piece $PieceIndex $Matrix $State) (d-to-array $Matrix $Table))) +; + + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + !(my-ensure-loaded (library tracing)) +; + + + + (= + (tracing-anal $Type $Call) + (det-if-then-else + (tracing (anal $Type)) + (call $Call) True)) +; + + +; +; + + + (= + (tracing-anal-format $Type $String $Args) + (det-if-then-else + (tracing (anal $Type)) + (format $String $Args) True)) +; + + + + (= + (tracing-anal-timing $Type $Call) + (trace-timing + (anal $Type) $Call)) +; + + + + (= + (set-anal-verbosity $Level $Status) + (set-tracing + (anal $Level) $Status)) +; + + + + (= + (silent-anal) + (all-anal off)) +; + + + (= + (loud-anal) + (all-anal on)) +; + + + + (= + (all-anal $Status) + ( (set-anal-verbosity index $Status) + (set-anal-verbosity simplify $Status) + (set-anal-verbosity subsume $Status) + (set-anal-verbosity pieces $Status))) +; + + + + (= + (trace-anal-tables) + (set-anal-verbosity tables on)) +; + + + (= + (trace-anal-index) + (set-anal-verbosity index on)) +; + + + (= + (trace-anal-subsume) + (set-anal-verbosity subsume on)) +; + + + (= + (trace-anal-simplify) + (set-anal-verbosity simplify on)) +; + + + (= + (trace-anal-pieces) + (set-anal-verbosity pieces on)) +; + + + + !(trace-anal-tables *) +; + +; +; + + + + + + diff --git a/metagame/learning/arrive.metta b/metagame/learning/arrive.metta new file mode 100644 index 0000000..c407634 --- /dev/null +++ b/metagame/learning/arrive.metta @@ -0,0 +1,285 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (arrive-value $Piece $Sq $SqT $Goal $Value $Pos $Tables) + ( (owns $Piece $Player) + (game-player-has-goal $_ $Player $Goal) + (arrive-goal $Goal $Player $Type $Sqs) + (arrive-goal $Goal $Descr $Squares) + (arrive-distance $Piece $Sq $SqT $Descr $Squares $SqDist $Tables) + (clear-path-cost $Piece $Player $Sq $SqT $SqDist $PathCost $Pos) + (arrive-likelihood $PathCost $Prob) + (reasonable-likelihood $Prob) + (arrive-goal-value $Piece $IValue) + (expected-value $Prob $IValue $AbsVal) + (negate-for-player $Player $AbsVal $Value))) +; + + + + (= + (arrive-distance $Piece $Sq $SqT + (arrive $Descr $Squares) $Dist $Tables) + (arrive-distance $Piece $Sq $SqT $Descr $Squares $Dist $Tables)) +; + + +; +; + +; +; + + + (= + (arrive-distance $Piece $Sq $SqT $Descr $Squares $Dist $Tables) + ( (matches $Descr $Piece) + (member $SqT $Squares) + (approx-path-distance $Sq $Piece $SqT $Dist $Tables))) +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (arrive_goal_value $Piece 1) True) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (arrive-likelihood $Distance $Prob) + (distance-value $Distance $Prob)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (distance-value $Distance $Value) + ( (parameter discount $D) (discount-fn $D $Distance $Value))) +; + + + + (= + (discount-fn inverse $Distance $Value) + (is $Value + (/ 1 + (+ 1 $Distance)))) +; + + (= + (discount-fn exponent $Distance $Value) + (is $Value + (/ 1 + (<< 1 $Distance)))) +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (approx-path-distance $Sq $Piece $SqT $Dist $Tables) + ( (square-piece-distance $Sq $Piece $SqT $Dist $Tables) (set-det))) +; + + (= + (approx_path_distance $Sq $Piece $SqT 10 $Tables) True) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (clear-path-cost $Piece $Player $Sq $SqT $SqDist $PathCost $Pos) + ( (clear-square-cost $SqT $Player $SqClearCost $Pos) + (control-cost $Player $ControlCost $Pos) + (is $PathCost + (+ + (+ $ControlCost $SqDist) $SqClearCost)))) +; + + + + (= + (clear-square-cost $SqT $Player $SqClearCost $Pos) + ( (on $Occupier $SqT $Pos) (clear-occupier $Occupier $Player $SqClearCost))) +; + + +; +; + +; +; + + + (= + (clear_occupier empty $_ 0) True) +; + + (= + (clear-occupier + (piece $Type $Player) $Player 1) + (set-det)) +; + + (= + (clear_occupier + (piece $Type $Player) $Opponent 5) True) +; + + + + + (= + (reasonable-likelihood $Prob) + (> $Prob 0)) +; + + + + (= + (expected-value $Prob $IVal $Value) + (is $Value + (* $Prob $IVal))) +; + + + + + + (= + (test $Sq $SqT $Value) + (arrive-value + (piece slug player) $Sq $SqT + (piece-desc any-player any-piece) + (:: $SqT) $Value)) +; + + + + + diff --git a/metagame/learning/dominate.metta b/metagame/learning/dominate.metta new file mode 100644 index 0000000..7c73204 --- /dev/null +++ b/metagame/learning/dominate.metta @@ -0,0 +1,313 @@ +; +; + +; +; + +; +; + +; +; + + + + (= + (attacks-i $PieceAI $SqAI $SqTI $PieceVI $SqVI $S) + ( (attacks $PieceA $SqA $SqT $PieceV $SqV $S) + (piece-index $PieceA $PieceAI) + (piece-index $PieceV $PieceVI) + (square-index $SqA $SqAI) + (square-index $SqV $SqVI))) +; + + + + + + (= + (attacks $PieceA $SqA $SqT $PieceV $SqV $S) + ( (det-if-then-else + (or + (nonvar $SqA) + (nonvar $SqT)) True + (board-square $SqA)) (attacks1 $PieceA $SqA $SqT $PieceV $SqV $S))) +; + + + +; +; + +; +; + +; +; + + + + (= + (attacks0 $PieceA $SqA $SqT $PieceV $SqV $S) + ( (blank-state $S) + (player-role $Player) + (control $Player $S) + (owns $PieceA $Player) + (on $PieceA $SqA $S) + (captures $PieceA $Player $SqA $SqT $Effect $Captured $S) + (captured-piece $PieceV $SqV $Captured))) +; + + + + (= + (attacks1 $PieceA $SqA $SqT $PieceV $SqV $S) + ( (blank-state-if $S) + (player-role $Player) + (put-control $Player $S $S1) + (owns $PieceA $Player) + (captures $PieceA $Player $SqA $SqT $Effect $Captured $S1) + (captured-piece $PieceV $SqV $Captured))) +; + + +; +; + +; +; + +; +; + + + (= + (attackshow $PieceA $SqA $SqT $PieceV $SqV $S) + ( (attacks $PieceA $SqA $SqT $PieceV $SqV $S) (on $PieceA $SqA $S))) +; + + + + + (= + (blank-state-if $S) + (det-if-then-else + (var $S) + (blank-state $S) True)) +; + + + + + (= + (blank-state $S) + (blank-state $Player $Stage 0 $S)) +; + + + (= + (blank-state $Player $Stage $Move $S) + ( (new-state $S0) (initialize-state-properties $Stage $Player $Move $S0 $S))) +; + + + +; +; + +; +; + +; +; + + + (= + (attack-distance $PA $SqA $SqI $PV $SqV $Dist $State) + ( (attacks $PA $SqI $SqT $PV $SqV $State) (square-piece-distance $SqA $PA $SqI $Dist))) +; + + + + (= + (closest-attack $PA $SqA $SqI $PV $SqV $Dist $State $Tables) + ( (setof + (- + (- $Dist1 $SqI) $State) + (attack-distance $PA $SqA $SqI $PV $SqV $Dist1 $State) $Places) (= $Places (Cons (- (- $Dist $SqI) $State) $Rest)))) +; + + + + + + (= + (testa $Dist $State) + (attack-distance + (piece king player) + (square 5 3) $SqI + (piece man opponent) + (square 2 2) $Dist $State)) +; + + + + + (= + (dominate-value $PieceA $SqA $PieceV $SqV $Goal $Value $Pos $Tables) + ( (blank-state-if $Pos) + (game-player-has-goal $_ $Player $Goal) + (opposite-role $Player $Opponent) + (eradicate-goal $Goal $Opponent $Type) + (eradicate-goal $Goal $Descr) + (weighted-dominate $Descr $PieceA $Player $SqA $PieceV $SqV $Value $Pos $Tables))) +; + + +; (error +; (syntax_error operator_expected) +; (file metagame/learning/dominate.pl 158 13 5055)) + + +; (error +; (syntax_error operator_expected) +; (file metagame/learning/dominate.pl 163 13 5214)) + + + + + (= + (dominate-val1 $PieceA $Player $SqA $PieceV $SqV $Value $Pos $Tables) + ( (blank-state-if $Pos) + (closest-attack $PieceA $SqA $SqI $PieceV $SqV $Dist $State $Tables) + (distance-value $Dist $Val) + (negate-for-player $Player $Val $Value))) +; + + + + + + (= + (matching-square $Piece $Sq $Descr $Pos) + ( (on $Piece $_ $Sq $Pos) (matches $Descr $Piece))) +; + + + + + (= + (enough-target-urgency $Targets $Weight) + ( (length $Targets $Length) + (< $Length 4) + (is $Weight + (/ 1 $Length)))) +; + + + + + + (= + (test2 $PV $SV $Val $S) + ( (checkpoint test $S) (dominate-value (piece king player) (square 4 2) $PV $SV $Goal $Val $S))) +; + + + + (= + (test3) + ( (setof + (, $A $B $C $D $E) + (^ $S + (attacks $A $B $C $D $E $S)) $Sets) (ppl $Sets))) +; + + + + (= + (test4) + ( (setof + (, $D $A $E $B) + (^ + (, $C $S) + (attacks $A $B $C $D $E $S)) $Sets) (ppl $Sets))) +; + + + + + (= + (test5) + ( (setof + (, $D $A $E $B) + (^ + (, $C $S) + (attacks-i $A $B $C $D $E $S)) $Sets) (ppl $Sets))) +; + + + + (= + (attackset $Attacks $State) + (setof + (^ $PieceV + (^ $PieceA + (^ $SqV $SqA))) + (^ + (, $SqT $State) + (attacks-i $PieceA $SqA $SqT $PieceV $SqV $State)) $Attacks)) +; + + + +; +; + + + (= + (dom-table $DomTable $State) + ( (attackset $Attacks $State) + (do-graph $Attacks $GroupedTargs) + (group-attacks $GroupedTargs $DomTable))) +; + + +; +; + + + + (= + (group_attacks () ()) True) +; + + (= + (group-attacks + (Cons + (- $T $As) $Rest) + (Cons + (- $T $GroupedAs) $GRest)) + ( (do-graph $As $Grouped1) + (group-targsq $Grouped1 $GroupedAs) + (group-attacks $Rest $GRest))) +; + + + + (= + (group_targsq () ()) True) +; + + (= + (group-targsq + (Cons + (- $A $Sqs) $Rest) + (Cons + (- $A $GroupedSqs) $GRest)) + ( (do-graph $Sqs $GroupedSqs) (group-targsq $Rest $GRest))) +; + + + + diff --git a/metagame/learning/exclude.metta b/metagame/learning/exclude.metta new file mode 100644 index 0000000..f06ceac --- /dev/null +++ b/metagame/learning/exclude.metta @@ -0,0 +1,245 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + + +; +; + +; +; + + + (= + (goal-square $Piece $Sq $Player $Goal) + ( (game-player-has-goal $_ $Player $Goal) + (arrive-goal $Goal $Descr $Squares) + (matches $Descr $Piece) + (member1 $Sq $Squares))) +; + + + + + + (= + (safe-transitions-type $Piece $PieceIndex $Sq $SqIndex $Type $SqTIndices $State) + ( (square-index $Sq $SqIndex) (det-if-then-else (setof $SqTIndex (^ $SqT (safe-transition-type $Piece $PieceIndex $Sq $SqIndex $SqT $SqTIndex $Type $State)) $SqTIndices) True (= $SqTIndices Nil)))) +; + + + + (= + (safe-transition $Piece $Sq $SqT $State) + (safe-transition $Piece $PieceIndex $Sq $SquareIndex $SqT $SqTIndex $State)) +; + + + (= + (safe-transition $Piece $PieceIndex $Sq $SquareIndex $SqT $SqTIndex $State) + (safe-transition-type $Piece $PieceIndex $Sq $SquareIndex $SqT $SqTIndex moving $State)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (safe-transition-type $Piece $PieceIndex $Sq $SquareIndex $SqT $SqTIndex $Type $State) + ( (square-index $Sq $SquareIndex) + (piece-index $Piece $PieceIndex) + (not (excluded-from $Piece $Sq)) + (piece-move-for-type $Type $Piece $Sq $SqT $State) + (not (excluded-to $Piece $SqT)) + (square-index $SqT $SqTIndex) + (tracing-anal-format detailed "~p: ~p -> ~p~n" + (:: $Piece $Sq $SqT)))) +; + + + + +; +; + +; +; + + + (= + (excluded-from $Piece $Sq) + (goal-square $Piece $Sq $Player $Goal)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (excluded-to $Piece $SqT) + ( (owns $Piece $Player) + (goal-square $Piece $SqT $Opp $_) + (opposite-role $Player $Opp) + (not (goal-square $Piece $SqT $Player $_)) + (not (safe-promotion $Piece $Player $SqT)) + (tracing-anal-format filter "Filter: <~p> can't safely move to ~p~n" + (:: $Piece $SqT)))) +; + + (= + (excluded-to $Piece $SqT) + ( (owns $Piece $Player) + (player-promotion-square $Player $SqT) + (not (safe-prom1 $Piece $Player $SqT)) + (tracing-anal-format filter "Filter: <~p> can't safely promote on ~p~n" + (:: $Piece $SqT)))) +; + + + +; +; + +; +; + +; +; + + + + (= + (safe-promotion $Piece $Player $SqT) + ( (owns $Piece $Player) + (player-promotion-square $Player $SqT) + (safe-prom1 $Piece $Player $SqT))) +; + + +; +; + +; +; + + + (= + (safe-prom1 $Piece $Player $SqT) + (player-safe-prom $Piece $Player $SqT)) +; + + (= + (safe-prom1 $Piece $Player $SqT) + (opponent-safe-prom $Piece $Player $SqT)) +; + + + + + (= + (player-safe-prom $Piece $Player $SqT) + ( (promotes-into $Piece $PieceT $Player $Player) + (opposite-role $Player $Opp) + (not (goal-square $PieceT $SqT $Opp $_)))) +; + + + + + (= + (opponent-safe-prom $Piece $Player $SqT) + ( (opponent-promotes $Piece) (not (opponent-wins-prom $Piece $Player $SqT)))) +; + + + + (= + (opponent-wins-prom $Piece $Player $SqT) + ( (promotes-into $Piece $PieceT $Player $Opp) + (opposite-role $Player $Opp) + (goal-square $PieceT $SqT $Opp $_))) +; + + + + + +; +; + +; +; + +; +; + +; +; + + diff --git a/metagame/learning/flight.metta b/metagame/learning/flight.metta new file mode 100644 index 0000000..27d0f0c --- /dev/null +++ b/metagame/learning/flight.metta @@ -0,0 +1,324 @@ +; +; + +; +; + +; +; + +; +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (safe-flight-square $Piece $Player $SqF $SqT $Pos $Tables) + ( (opposite-role $Player $Opp) + (flight-square $Piece $Player $SqF $SqT $Pos $PosOut $Tables) + (not (threatens $PieceA $Opp $SqA $SqTA $Piece $SqT $Effect $PosOut)))) +; + + + +; +; + + + (= + (flight-square $Piece $Player $SqF $SqT $Pos $PosOut $Tables) + ( (blank-state-if $Pos) + (on $Piece $SqF $Pos) + (piece-index $Piece $_) + (general-move $Piece $Player $SqF $SqT $Pos $PosOut $Tables))) +; + + + + + (= + (general-move $Piece $Player $SqF $SqT $Pos $PosOut $Tables) + (done-move-threat $Piece $Player $SqF $SqT $Pos $PosOut $Tables)) +; + + (= + (general-move $Piece $Player $SqF $SqT $Pos $PosOut $Tables) + (done-capture-threat $Piece $Player $SqF $SqT $PieceV $SqV $Effect $Pos $PosOut $Tables)) +; + + + + + (= + (testflight) + ( (checkpoint cap $Pos) + (flight-square $Piece player $SqF $SqT $Pos $ZOut $Tables) + (format "~p->~p~n" + (:: $SqF $SqT)))) +; + + + + + +; +; + +; +; + +; +; + + + + + (= + (flight-square $Piece $Player $SqF $SqT $Pos $Tables) + ( (blank-state-if $Pos) + (on $Piece $SqF $Pos) + (piece-index $Piece $_) + (general-move $Piece $Player $SqF $SqT $Pos $Tables))) +; + + + +; +; + + + (= + (general-move $Piece $Player $SqF $SqT $Pos $Tables) + (move-threat $Piece $Player $SqF $SqT $Tables)) +; + + (= + (general-move $PieceA $Player $SqA $SqT $Pos $Tables) + (capture-threat $PieceA $Player $SqA $SqT $PieceV $SqV $Effect $Tables)) +; + + + +; +; + +; +; + +; +; + + + + (= + (eradicate-safety $Player $Piece $Sq $Goal $Value $Pos $Tables) + ( (opposite-role $Player $Opponent) + (game-player-has-goal $_ $Opponent $Goal) + (eradicate-goal $Goal $Player $Type) + (eradicate-goal $Goal $Descr) + (owns $Piece $Player) + (weighted-dominate $Descr $Player $Piece $Sq $Value $Pos $Tables))) +; + + +; (error +; (syntax_error operator_expected) +; (file metagame/learning/flight.pl 105 12 3822)) + + +; (error +; (syntax_error operator_expected) +; (file metagame/learning/flight.pl 110 13 3967)) + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (dominate-val1 $Player $Piece $SqF $Value $Pos $Tables) + ( (blank-state-if $Pos) + (safe-flight-square $Piece $Player $SqF $SqT $Pos $Tables) + (eventual-piece-mobility $Piece $SqT $Val $Pos $Tables) + (negate-for-player $Player $Val $Value))) +; + + + + + + (= + (matching-square $Piece $Sq $Descr $Pos) + ( (on $Piece $_ $Sq $Pos) (matches $Descr $Piece))) +; + + + +; +; + +; +; + + + (= + (enough-target-urgency $Targets $Weight) + ( (parameter vital-number $N) + (length $Targets $Length) + (=< $Length $N) + (is $Weight + (/ 1 $Length)))) +; + + + +; (error +; (syntax_error operator_expected) +; (file metagame/learning/flight.pl 150 12 5319)) + + + + + (= + (eradicate-goal-targets $Player $Goal $Targets $Pos) + ( (opposite-role $Player $Opponent) + (game-player-has-goal $_ $Player $Goal) + (eradicate-goal $Goal $Opponent $Type) + (eradicate-goal $Goal $Descr) + (dominate-targets $Descr $Targets $Pos))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (threatened-vital-piece $Piece $Sq $Player $Goal $Value $Pos $Tables) + ( (opposite-role $Player $Opponent) + (vital-piece $Piece $Sq $Player $Goal $Weight $Pos $Tables) + (det-if-then + (capture-threat $PieceA $Opponent $SqA $SqT $Piece $Sq $Effect $Tables) True) + (negate-for-player $Opponent $Weight $Value))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (threatened-vital-piece-value $Piece $Sq $Player $Goal $Value $Pos $Tables) + ( (not (still-assigning $Pos)) + (threatened-vital-piece $Piece $Sq $Player $Goal $Val1 $Pos $Tables) + (det-if-then-else + (or + (control $Player $Pos) + (< + (abs $Val1) 1)) + (= $Value $Val1) + (is $Value + (* 10000 $Val1))))) +; + + + + + diff --git a/metagame/learning/global.metta b/metagame/learning/global.metta new file mode 100644 index 0000000..cf888fd --- /dev/null +++ b/metagame/learning/global.metta @@ -0,0 +1,731 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + + + (= + (move-threat $Piece $Player $SqF $SqT $Tables) + ( (moving-table $Tables $MTable) (member (move $Piece $Player $SqF $SqT) $MTable))) +; + + + + (= + (capture-threat $PieceA $Player $SqA $SqT $PieceV $SqV $Effect $Tables) + ( (capturing-table $Tables $MTable) (member (threat $PieceA $Player $SqA $SqT $PieceV $SqV $Effect) $MTable))) +; + + + +; +; + + + (= + (done-move-threat $Piece $Player $SqF $SqT $Pos $PosOut $Tables) + ( (move-threat $Piece $Player $SqF $SqT $Tables) (do-move $Piece $SqF $SqT $Pos $PosOut))) +; + + + + (= + (done-capture-threat $PieceA $Player $SqA $SqT $PieceV $SqV $Effect $Pos $PosOut $Tables) + ( (capture-threat $PieceA $Player $SqA $SqT $PieceV $SqV $Effect $Tables) (do-capture $PieceA $SqA $SqT $PieceV $SqV $Pos $PosOut))) +; + + + + + + (= + (do-move $Piece $SqF $SqT $Pos $PosOut) + ( (lift-piece $Piece $SqF $Pos $Pos1) (place-piece $Piece $SqT $Pos1 $PosOut))) +; + + + + + (= + (do-capture $Piece $SqF $SqT $PieceV $SqV $Pos $PosOut) + ( (lift-piece $Piece $SqF $Pos $Pos1) + (det-if-then-else + (\== $SqV $SqT) + (lift-piece $PieceV $SqV $Pos1 $Pos2) + (= $Pos1 $Pos2)) + (place-piece $Piece $SqT $Pos2 $PosOut))) +; + + + + + +; +; + +; +; + +; +; + + + +; +; + +; +; + + + (= + (capture-table $Table $S) + ( (findall + (threat $PieceA $Player $SqA $SqT $PieceV $SqV $Effect) + (threatens $PieceA $Player $SqA $SqT $PieceV $SqV $Effect $S) $Table1) (remove-duplicates $Table1 $Table))) +; + + + + (= + (unique-threats $Threats $Unique) + ( (findall + (target $Player $PieceV $SqV $Effect) + (member + (threat $PieceA $Player $SqA $SqT $PieceV $SqV $Effect) $Threats) $Squares) (remove-duplicates $Squares $Unique))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (unique-threats $Player $Threats $Unique) + ( (player-role $Player) + (findall + (target $Player $PieceV $SqV $Effect) + (member + (threat $PieceA $Player $SqA $SqT $PieceV $SqV $Effect) $Threats) $Squares) + (remove-duplicates $Squares $Unique))) +; + + + + + (= + (player-threats $Player $Threats $PThreats) + ( (player-role $Player) (findall (threat $PieceA $Player $SqA $SqT $PieceV $SqV $Effect) (member (threat $PieceA $Player $SqA $SqT $PieceV $SqV $Effect) $Threats) $PThreats))) +; + + + +; +; + +; +; + + + (= + (threatens $PieceA $Player $SqA $SqT $PieceV $SqV $Effect $S) + ( (on $PieceA $SqA $S) + (owns $PieceA $Player) + (put-control-if $Player $S $S1) + (captures $PieceA $Player $SqA $SqT $Effect $Captured $S1) + (not (excluded-to $PieceA $SqT)) + (captured-piece $PieceV $SqV $Captured))) +; + + + +; +; + +; +; + +; +; + + + + (= + (gthreat $Player $Value $Position $Tables) + ( (capturing-table $Tables $MTable) + (unique-threats $Player $MTable $Unique) + (\== $Unique Nil) + (eval-threats $Unique $Player $Evaled $Position $Tables) + (keysort-for-player $Player $Evaled $Ordered) + (threat-outcome $Player $Ordered $Value $Position $Tables))) +; + + + + (= + (eval-threats $Unique $Player $Evaled $Position $Tables) + (findall + (- $Val $Threat) + (, + (member $Threat $Unique) + (= $Threat + (target $Player $PieceV $SqV $Effect)) + (effect-threat-evaluation $Effect $Player $PieceV $SqV $Val $Position $Tables) + (tracing-anal-format gthreat "Threatened: <~p> can capture <~p> ~p (~p) [~p]~n" + (:: $Player $PieceV $SqV $Effect $Val))) $Evaled)) +; + + + +; +; + +; +; + + + (= + (local-threat-evaluation $Victim $SqV $Val $S $Tables) + ( (shutdown-advisor threat $Tables) + (= $S1 $S) + (local-evaluation $Victim $SqV $Val $S1 $Tables))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (effect-threat-evaluation $Effect $Player $PieceV $SqV $Value $Position $Tables) + ( (local-threat-evaluation $PieceV $SqV $LVal $Position $Tables) + (is $RemVal + (- $LVal)) + (effect-val $Effect $Player $PieceV $LVal $EVal $Position $Tables) + (is $Value + (+ $RemVal $EVal)) + (favorable-to-owner $Player $Value))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (effect_val remove $Player $PieceV $Val 0 $Position $Tables) True) +; + + (= + (effect-val + (possess $Possessor) $Player $PieceV $LVal $EValue $Position $Tables) + (estimate-possess-value $Possessor $PieceV $LVal $EValue $Position $Tables)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (threat-outcome $Player $Ordered $Value $Position $Tables) + (det-if-then-else + (control $Player $Position) + (, + (= $Ordered + (Cons + (- $Val1 $Threat1) $Rest)) + (favor-control $Player $Val1 $Value $Position)) + (, + (length $Ordered $Num) + (det-if-then-else + (> $Num 1) + (, + (nth 2 $Ordered + (- $Val1 $Threat1)) + (favor-control $Player $Val1 $Value $Position)) + (, + (= $Ordered + (Cons + (- $Val1 $Threat1) $Rest)) + (favor-control $Player $Val1 $Val2 $Position) + (favor-control $Player $Val2 $Value $Position)))))) +; + + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (local-threat-value $Piece $Square $PieceV $SqV $Value $Pos $Tables) + ( (owns $Piece $Player) + (capture-threat $Piece $Player $Square $SqT $PieceV $SqV $Effect $Tables) + (local-threat-value $Player $Piece $Square $SqT $PieceV $SqV $Effect $Value $Pos $Tables))) +; + + + (= + (local-threat-value $Player $Piece $Square $SqT $Victim $SqV $Effect $Value $S $Tables) + ( (effect-threat-evaluation $Effect $Player $Victim $SqV $Val $S $Tables) + (favor-control $Player $Val $Value $S) + (tracing-anal-format lthreat "<~p>: ~p -> ~p x ~p ~p (~p) [~p]~n" + (:: $Piece $Square $SqT $Victim $SqV $Effect $Value)))) +; + + + +; +; + +; +; + +; +; + + + + + + (= + (put-control-if $P $S $S1) + (det-if-then-else + (control $P $S) + (= $S $S1) + (put-control $P $S $S1))) +; + + + + + +; +; + +; +; + + + (= + (move-table $Table $S) + ( (findall + (move $PieceA $Player $SqA $SqT) + (could-move $PieceA $Player $SqA $SqT $S) $Table1) (remove-duplicates $Table1 $Table))) +; + + + + (= + (unique-moves $Moves $Unique) + ( (findall + (target $Player $PieceA $SqA $SqT) + (member + (move $PieceA $Player $SqA $SqT) $Moves) $Squares) (remove-duplicates $Squares $Unique))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (unique-moves $Player $Moves $Targets) + ( (player-role $Player) (unique-moves $Player $PieceA $SqA $SqT $Moves $Targets))) +; + + + (= + (unique-moves $Player $PieceA $SqA $SqT $Moves $Targets) + (findall + (target $Player $PieceA $SqA $SqT) + (member + (move $PieceA $Player $SqA $SqT) $Moves) $Targets)) +; + + + +; +; + +; +; + + + (= + (could-move $PieceA $Player $SqA $SqT $S) + ( (on $PieceA $SqA $S) + (owns $PieceA $Player) + (put-control-if $Player $S $S1) + (moves $PieceA $Player $SqA $SqT $S1) + (not (excluded-to $PieceA $SqT)))) +; + + + + +; +; + +; +; + +; +; + +; +; + + + + (= + (gmobility $Player $Val $Position $Tables) + ( (moving-table $Tables $MTable) + (unique-moves $Player $MTable $Moves) + (length $Moves $Val))) +; + + +; +; + +; +; + +; +; + + + (= + (gcapmobility $Player $Val $Position $Tables) + ( (capturing-table $Tables $MTable) + (player-threats $Player $MTable $Moves) + (length $Moves $Val))) +; + + + + + + +; +; + + + + (= + (add-dynamic-tables-if $S $Tables) + (det-if-then-else + (or + (, + (capturing-table $Tables $Table) + (var $Table)) + (, + (moving-table $Tables $Table) + (var $Table))) + (add-dynamic-tables $S $Tables) True)) +; + + + +; +; + + + (= + (add-dynamic-tables $S $Tables) + ( (det-if-then-else movtable + (add-moving-table-if $S $Tables) True) (det-if-then-else captable (add-capturing-table-if $S $Tables) True))) +; + + + + + (= + (add-capturing-table-if $S $Tables) + (det-if-then-else + (, + (capturing-table $Tables $Table) + (var $Table)) + (, + (tracing-anal-format dynamic "Building table ...~n" Nil) + (tracing-anal-timing dynamic + (add-capturing-table $S $Tables))) True)) +; + + + + + (= + (add-moving-table-if $S $Tables) + (det-if-then-else + (, + (moving-table $Tables $Table) + (var $Table)) + (, + (tracing-anal-format dynamic "Building table ...~n" Nil) + (tracing-anal-timing dynamic + (add-moving-table $S $Tables))) True)) +; + + + + (= + (add-moving-table $S $Tables) + ( (move-table $Table $S) (moving-table $Tables $Table))) +; + + + + (= + (add-capturing-table $S $Tables) + ( (capture-table $Table $S) (capturing-table $Tables $Table))) +; + + + + + + diff --git a/metagame/learning/group.metta b/metagame/learning/group.metta new file mode 100644 index 0000000..6bf6e8d --- /dev/null +++ b/metagame/learning/group.metta @@ -0,0 +1,71 @@ +; +; + +; +; + +; +; + +; +; + + + + + (= + (do-graph $P_Graph $S_Graph) + ( (sort $P_Graph $EdgeSet) + (do-vertices $EdgeSet $VertexBag) + (sort $VertexBag $VertexSet) + (do-group $VertexSet $EdgeSet $S_Graph))) +; + + + + + (= + (do-vertices Nil Nil) + (set-det)) +; + + (= + (do-vertices + (Cons + (^ $A $Z) $Edges) + (Cons $A $Vertices)) + (do-vertices $Edges $Vertices)) +; + + + + + (= + (do-group Nil $_ Nil) + (set-det)) +; + + (= + (do-group + (Cons $Vertex $Vertices) $EdgeSet + (Cons + (- $Vertex $Neibs) $G)) + ( (do-group $EdgeSet $Vertex $Neibs $RestEdges) (do-group $Vertices $RestEdges $G))) +; + + + + (= + (do-group + (Cons + (^ $V $X) $Edges) $V + (Cons $X $Neibs) $RestEdges) + ( (set-det) (do-group $Edges $V $Neibs $RestEdges))) +; + + (= + (do_group $Edges $_ () $Edges) True) +; + + + diff --git a/metagame/learning/paths.metta b/metagame/learning/paths.metta new file mode 100644 index 0000000..a4cff3c --- /dev/null +++ b/metagame/learning/paths.metta @@ -0,0 +1,293 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + + + + (= + (path-dist $Piece $Player $SqF $SqT 0 0) + (set-det)) +; + + (= + (path-dist $Piece $Player $SqF $SqT $Max $N) + ( (reaches $Piece $Player $SqF $SqT $In) (path-dist $Piece $Player $SqF $SqF 0 $S))) +; + + (= + (path-dist $Piece $Player $SqF $SqT $N $S) + ( (reaches $Piece $Player $SqF $Sq1 $S) + (path-dist $Piece $Player $Sq1 $SqT $N1 $S) + (is $N + (+ $N1 1)))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (path-dist $Type $Player $SqF $SqT $Dist $Max $S0) + ( (det-if-then-else + (piece-struct $Type $T $Player) + (= $Piece $Type) + (piece-struct $Piece $Type $Player)) + (put-control $Player $S0 $S) + (path-dist0 $Piece $Player $SqF $SqT $Dist $Max $S) + (tracing-path-format squares "<~p>: ~p -> ~p in ~p moves~n" + (:: $Piece $SqF $SqT $Dist)))) +; + + + + (= + (path-dist0 $Piece $Player $SqF $SqT $N $Max $S) + ( (path-dist1 $Piece $Player $SqF $SqT $N $Max $S) (> $N 0))) +; + + + + (= + (path_dist1 $Piece $Player $SqF $SqF 0 $Left $S) True) +; + + (= + (path-dist1 $Piece $Player $SqF $SqT $N $Max $S) + ( (> $Max 0) + (\== $SqF $SqT) + (reaches $Piece $Player $SqF $Sq1 $S) + (is $Max1 + (- $Max 1)) + (path-dist1 $Piece $Player $Sq1 $SqT $N1 $Max1 $S) + (is $N + (+ $N1 1)))) +; + + + + + (= + (new-empty-state $S) + ( (new-state $S1) (make-empty-board $S1 $S))) +; + + + + (= + (new-state-of-type empty $S) + (new-empty-state $S)) +; + + (= + (new-state-of-type any $S) + (new-state $S)) +; + + + + (= + (piece-moves-empty $Piece $Sq $SqT) + ( (new-empty-state $State) (piece-moves $Piece $Sq $SqT $State))) +; + + + + (= + (piece-moves-any $Piece $Sq $SqT) + ( (new-state $State) (piece-moves $Piece $Sq $SqT $State))) +; + + + + (= + (piece-moves $Piece $Sq $SqT $State) + ( (board-square $Sq) + (piece-index $Piece $_) + (moves $Piece $Player $Sq $SqT $State) + (tracing-path-format moves "<~p>: ~p -> ~p~n" + (:: $Piece $Sq $SqT)))) +; + + + + (= + (piece-move $Piece $Sq $SqT $MoveType $StateType) + ( (new-state-of-type $StateType $S) (piece-move-for-type $MoveType $Piece $Sq $SqT $S))) +; + + +; +; + +; +; + + + (= + (piece-move-for-type $MoveType $Piece $Sq $SqT $S) + ( (board-square $Sq) + (piece-index $Piece $_) + (owns $Piece $Player) + (put-control $Player $S $S1) + (move-for-type $MoveType $Piece $Sq $SqT $S1))) +; + + + + (= + (move-for-type moving $Piece $Sq $SqT $State) + ( (moves $Piece $Player $Sq $SqT $State) (tracing-path-format moves "<~p>: ~p -> ~p~n" (:: $Piece $Sq $SqT)))) +; + + (= + (move-for-type capturing $Piece $Sq $SqT $State) + ( (captures $Piece $Player $Sq $SqT $State) (tracing-path-format moves "<~p>: ~p -> ~p~n" (:: $Piece $Sq $SqT)))) +; + + (= + (move-for-type capturing-specific $Piece $Sq $SqT $State) + ( (captures $Piece $Player $Sq $SqT $Effect $Captured $State) (tracing-path-format moves "<~p>: ~p -> ~p x ~p (~p)~n" (:: $Piece $Sq $SqT $Captured $Effect)))) +; + + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + !(my-ensure-loaded (library tracing)) +; + + + + (= + (tracing-path $Type $Call) + (det-if-then-else + (tracing (path $Type)) + (call $Call) True)) +; + + +; +; + + + (= + (tracing-path-format $Type $String $Args) + (det-if-then-else + (tracing (path $Type)) + (format $String $Args) True)) +; + + + + (= + (tracing-path-timing $Type $Call) + (trace-timing + (path $Type) $Call)) +; + + + + (= + (set-path-verbosity $Level $Status) + (set-tracing + (path $Level) $Status)) +; + + + + (= + (silent-path) + ( (set-path-verbosity ordering off) + (set-path-verbosity value off) + (set-path-verbosity resources off) + (set-path-verbosity timing off) + (set-path-verbosity iteration off))) +; + + + + (= + (trace-path-squares) + (set-path-verbosity squares on)) +; + + + (= + (trace-path-ordering) + (set-path-verbosity ordering on)) +; + + + + !(silent-path *) +; + +; +; + + + +; + diff --git a/metagame/learning/possess.metta b/metagame/learning/possess.metta new file mode 100644 index 0000000..68b882f --- /dev/null +++ b/metagame/learning/possess.metta @@ -0,0 +1,230 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (possess-value $Piece $Player + (advice possess $Sq $Value) $Position $Tables) + ( (total-square-count $Total) + (empty $Sq $Position) + (local-evaluation $Piece $Sq $LVal $Position $Tables) + (is $Value + (/ $LVal $Total)))) +; + + + + + (= + (initprom-value + (advice initprom + (best $OldPiece $NewPiece) $Value) $Position $Tables) + ( (opponent-promotes $OldPiece $Sq $Position) + (control $Player $Position) + (best-choice $OldPiece $Player $Sq $NewPiece $Value $Position $Tables))) +; + + + + (= + (best-choice $OldPiece $Player $Sq $NewPiece $Value $Position $Tables) + ( (findall + (- $NewVal $NewPiece) + (initprom-value $OldPiece $Sq $Player $NewPiece $NewVal $Position $Tables) $Pairs) (best-player-choice $Player $Pairs $NewPiece $Value))) +; + + + + (= + (best-player-choice $Player $Pairs $NewPiece $Value) + ( (keysort-for-player $Player $Pairs $Ordered) (= $Ordered (Cons (- $Value $NewPiece) $Rest)))) +; + + + +; +; + +; +; + +; +; + + + (= + (keysort-for-player $Player $Pairs $Ordered) + ( (keysort $Pairs $Sorted) (reverse-for-player $Player $Sorted $Ordered))) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (reverse_for_player opponent $Sorted $Sorted) True) +; + + (= + (reverse-for-player player $Sorted $Ordered) + (reverse $Sorted $Ordered)) +; + + + +; +; + +; +; + + + (= + (initprom-value $OldPiece $Sq $Player $NewPiece $NewVal $Position $Tables) + ( (init-promote-option $OldPiece $Player $NewPiece $Position) (local-evaluation $NewPiece $Sq $NewVal $Position $Tables))) +; + + + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (possess-offset $N) + (parameter possess-offset $N)) +; + + + + + (= + (favor-possess $Player $Val1 $Value $Position) + ( (possess-offset $Offset) (is $Value (* $Val1 $Offset)))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (estimate-possess-value $Possessor $Piece $LVal $EVal $Position $Tables) + (det-if-then-else + (owns $Piece $Possessor) + (= $EVal $LVal) + (is $EVal + (- $LVal)))) +; + + + diff --git a/metagame/learning/potent.metta b/metagame/learning/potent.metta new file mode 100644 index 0000000..735d49f --- /dev/null +++ b/metagame/learning/potent.metta @@ -0,0 +1,548 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + + + (= + (pthreat $Player $Value $Pos $Tables) + ( (control $Player $Pos) + (potent-threats $Player $Evaled $Pos $Tables) + (pair-list $Vals $Threats $Evaled) + (max-for-player $Player $Vals $Value))) +; + + + + (= + (potent-threats $Player $Evaled $Pos $Tables) + (findall + (- $Val $Threat) + (, + (potent-threat-mover $Player $Piece $Square $SqT $Victim $SqV $Effect $Val $Pos $Tables) + (= $Threat + (potent $Piece $Square $SqT $Victim $SqV $Effect $Val))) $Evaled)) +; + + +; +; + +; +; + +; +; + + + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (potent-threat-mover $Piece $Square $PieceV $SqV $Value $Pos $Tables) + ( (blank-state-if $Pos) + (find-advice-tables-if $Tables) + (add-capturing-table-if $Pos $Tables) + (control $Player $Pos) + (potent-threat-mover $Player $Piece $Square $SqT $PieceV $SqV $Effect $Value $Pos $Tables))) +; + + +; +; + +; +; + + (= + (potent-threat-mover $Player $Piece $Square $SqT $Victim $SqV $Effect $Value $S $Tables) + ( (capture-threat $Piece $Player $Square $SqT $Victim $SqV $Effect $Tables) + (effect-threat-evaluation $Effect $Player $Victim $SqV $Val $S $Tables) + (potency-value $Player $Piece $Square $SqT $Victim $SqV $Val $Value $S $Tables) + (tracing-anal-format pthreat "<~p>: ~p -> ~p x ~p ~p (~p) [~p]~n" + (:: $Piece $Square $SqT $Victim $SqV $Effect $Value)))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (potency-value $Player $Piece $Square $SqT $Victim $SqV $ValV $Value $S $Tables) + (det-if-then-else + (, + (defended $Player $Piece $Square $SqT $Victim $SqV $Effect $S $Tables) + (\== $Effect + (possess $Player))) + (, + (local-threat-evaluation $Piece $Square $ValA $S $Tables) + (is $Net + (- $ValV $ValA)) + (min-for-player $Player + (:: $ValV $Net) $Value) + (favorable-to-owner $Player $Value)) + (= $Value $ValV))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (defended $Player $PieceA $SqA $SqT $PieceV $SqV $Effect $S $Tables) + ( (opposite-role $Player $Opp) + (do-capture $PieceA $SqA $SqT $PieceV $SqV $S $PosOut) + (on $PieceD $Opp $SqD $PosOut) + (target-capture $PieceD $SqD $PieceA $SqT $Capture $Movement $Dir $Effect $PosOut $Tables))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (target-capture $PieceA $SqA $PieceV $SqV $Capture $Movement $Dir $Effect $Pos $Tables) + ( (owns $PieceA $Player) + (potential-capture $PieceA $SqA $PieceV $SqV $Capture $Movement $Dir $Effect $Pos $Tables) + (capturing-movement-for-piece $PieceA $SqA $SqT $Player $Dir $Movement $Capture $Captured $Pos) + (captured-piece $PieceV $SqV $Captured))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (potential-capture $PieceA $SqA $PieceT $SqT $Effect $Pos $Tables) + (potential-capture $PieceA $SqA $PieceT $SqT $Capture $Movement $Dir $Effect $Pos $Tables)) +; + + + (= + (potential-capture $PieceA $SqA $PieceT $SqT $Capture $Movement $Dir $Effect $Pos $Tables) + ( (threat-piece-victim $PieceA $Player $PieceT $VPlayer $Effect $Capture) + (opposite-role $Player $VPlayer) + (capture-has-movement $Capture $Movement) + (movement-sym-dir $Movement $Dir) + (capture-aligned $Capture $Movement $SqA $SqT $Dir))) +; + + + + (= + (capture-aligned $Capture $Movement $SqA $SqT $Dir) + ( (capture-has-method $Capture $Method) (det-if-then (method-aligned $Method $Movement $SqA $SqT $Dir) True))) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (method-aligned clobber $Movement $SqA $SqT $Dir) + (aligned $SqA $SqT $Dir)) +; + + (= + (method-aligned hop $Movement $SqA $SqT $Dir) + (aligned $SqA $SqT $Dir)) +; + + (= + (method-aligned retrieve $Movement $SqA $SqT $Dir) + (connected $SqT $SqA $Dir)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (aligned $S1 $S2 $Dir) + ( (square $S1 $Xf $Yf) + (square $S2 $Xt $Yt) + (direction $Dir $DX $DY) + (current-board-type $T) + (x-given-y-leaps $T $Yf $Yt $DY $Xf $Xt $DX))) +; + + + + (= + (x-given-y-leaps $T $Yf $Yt $DY $Xf $Xt $DX) + ( (is $DiffY + (- $Yt $Yf)) + (same-sign $DiffY $DY) + (det-if-then-else + (\== $DY 0) + (, + (is 0 + (mod $DiffY + (abs $DY))) + (is $Leaps + (// $DiffY $DY)) + (is $XNew + (+ $Xf + (* $Leaps $DX))) + (align-for-type $T $XNew $Xt)) + (det-if-then-else + (\== $T vertical-cylinder) + (, + (is $DiffX + (- $Xt $Xf)) + (same-sign $DiffX $DX) + (is 0 + (mod + (- $Xt $Xf) + (abs $DX)))) + (, + (valid-max-dir $DX 0 $Max1) + (is $Max + (abs $Max1)) + (some-reaches $Max $T $DX $Xf $Xt)))))) +; + + + + (= + (some-reaches $Leaps $T $DX $Xf $Xt) + ( (> $Leaps 0) + (is $XNew + (+ $Xf + (* $Leaps $DX))) + (align-for-type $T $XNew $Xt))) +; + + (= + (some-reaches $Leaps $T $DX $Xf $Xt) + ( (> $Leaps 1) + (is $L1 + (- $Leaps 1)) + (some-reaches $L1 $T $DX $Xf $Xt))) +; + + + + + + + + (= + (y-leaps $Yf $Yt $DY $Leaps) + ( (is $DiffY + (- $Yt $Yf)) + (same-sign $DiffY $DY) + (is 0 + (mod $DiffY + (abs $DY))) + (is $Leaps + (// $DiffY $DY)))) +; + + + + + (= + (align_for_type planar $X $X) True) +; + + (= + (align-for-type vertical-cylinder $X1 $X) + ( (current-board-size $XN $YN) (is $X (+ (mod (- (+ $X1 $XN) 1) $XN) 1)))) +; + + + + + + (= + (sign $X $Sign) + (det-if-then-else + (< $X 0) + (= $Sign -1) + (det-if-then-else + (> $X 0) + (= $Sign 1) + (det-if-then otherwise + (= $Sign 0))))) +; + + + + + (= + (same-sign $X1 $X2) + ( (sign $X1 $S) (sign $X2 $S))) +; + + + + + (= + (test-potential-capture $PieceA $SqA $PieceT $SqT $Capture $Movement $Dir $Effect $S $Tables) + ( (checkpoint init $S) + (on $PieceA $_ $SqA $S) + (on $PieceT $_ $SqT $S) + (potential-capture $PieceA $SqA $PieceT $SqT $Capture $Movement $Dir $Effect $Pos $Tables))) +; + + + + (= + (test-target-capture $PieceA $SqA $PieceV $SqV $Capture $Movement $Dir $Effect $S $Tables) + ( (on $PieceA $_ $SqA $S) + (on $PieceV $_ $SqV $S) + (target-capture $PieceA $SqA $PieceV $SqV $Capture $Movement $Dir $Effect $S $Tables))) +; + + + diff --git a/metagame/learning/prom.metta b/metagame/learning/prom.metta new file mode 100644 index 0000000..6cdae91 --- /dev/null +++ b/metagame/learning/prom.metta @@ -0,0 +1,958 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (prom-value $Piece $Sq $SqT $Value $Pos $Tables) + ( (owns $Piece $Player) + (useful-promotes $Piece $Player $Tables) + (focussed-promsq-cost $Piece $Player $Sq $SqT $PathCost $Pos $Tables) + (best-promotion-choice-value $Piece $Player $SqT $PathCost $PieceT $Value $Pos $Tables))) +; + + + + + + (= + (best-promotion-choice-value $Piece $Player $SqT $PathCost $BestPiece $BestValue $Pos $Tables) + ( (findall + (- $Value $PieceT) + (promotion-choice-value $Piece $Player $SqT $PathCost $PieceT $Value $Pos $Tables) $Pairs) (best-player-choice $Player $Pairs $BestPiece $BestValue))) +; + + + + (= + (promotion-choice-value $Piece $Player $SqT $PathCost $PieceT $Value $Pos $Tables) + ( (piece-player-prom-distance $Piece $Player $PieceT $PromDist $Tables) + (\== $PieceT $Piece) + (intrinsic-value $PieceT $SqT $IVal $Pos $Tables) + (prom-likelihood $PromDist $PathCost $Prob) + (reasonable-likelihood $Prob) + (expected-value $Prob $IVal $Value) + (favorable-to-owner $Player $Value))) +; + + + + + + (= + (useful-promotes $Piece $Player $Tables) + (det-if-then + (player-safe-new-prom $Piece $Player $PieceT $SqT $Tables) True)) +; + + + +; +; + +; +; + + + (= + (player-safe-new-prom $Piece $Player $PieceT $SqT $Tables) + ( (piece-player-promotion $Piece $Player $PieceT $Tables) + (\== $Piece $PieceT) + (opposite-role $Player $Opp) + (player-promotion-square $Player $SqT) + (not (goal-square $PieceT $SqT $Opp $_)))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (focussed-promsq-cost $Piece $Player $Sq $SqT $Cost $Pos $Tables) + ( (square-index $Sq $SqI) + (piece-index $Piece $PieceI) + (square-piece-psqs $SqI $PieceI $SqTIs $Dist $Tables) + (cheapest-destination $Piece $Player $Sq $SqTIs $Dist $SqT $Cost $Pos $Tables))) +; + + +; +; + +; +; + + + (= + (cheapest-destination $Piece $Player $Sq $SqTIs $Dist $SqT $Cost $Pos $Tables) + ( (findall + (- $Cost1 $SqT1) + (, + (member $SqTI1 $SqTIs) + (square-index $SqT1 $SqTI1) + (cost-to-promsq $Piece $Player $Sq $SqT1 $Dist $Cost1 $Pos $Tables)) $Dests) (sort $Dests (Cons (- $Cost $SqT) $_)))) +; + + + + + (= + (cost-to-promsq $Piece $Player $Sq $SqT $SqDist $PathCost $Pos $Tables) + (clear-path-cost $Piece $Player $Sq $SqT $SqDist $PathCost $Pos)) +; + + + + + (= + (distance-to-promsq $Piece $Sq $SqT $SqDist $Tables) + (square-piece-promsq $Sq $Piece $SqT $SqDist $Tables)) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (prom-likelihood $PromDist $PathCost $Prob) + ( (is $MinMoves + (- + (+ $PromDist $PathCost) 1)) (distance-value $MinMoves $Prob))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (intrinsic-value $Piece $Sq $Val $Pos $Tables) + ( (shutdown-advisor threat $Tables) + (shutdown-advisor prom $Tables) + (shutdown-advisor dynamic-mobility $Tables) + (local-evaluation $Piece $Sq $Val $Pos $Tables))) +; + + + + + (= + (testp) + ( (checkpoint init $S) + (get-advices $A $S) + (ppl $A))) +; + + + + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (promotes-into $Piece $PieceI $Prom $PromI $Player $Chooser) + ( (promotes-into $Piece $Prom $Player $Chooser) + (piece-index $Piece $PieceI) + (piece-index $Prom $PromI))) +; + + + + + (= + (opponent-promotes $Piece) + ( (promotes-into $Piece $_ $Player $Chooser) (opposite-role $Player $Chooser))) +; + + + + + (= + (promotes-into $OrigPiece $PromPiece $Player $Chooser) + ( (owns $OrigPiece $Player) + (current-game-for-player $Player $Game) + (game-piece-promoting $OrigPiece $Promoting $Game) + (promote-choice $Promoting $Player $Chooser $PromPiece))) +; + + + + (= + (promote-choice $Promoting $Player $Player $PromPiece) + (simple-promote $Promoting $Player $PromPiece)) +; + + (= + (promote-choice $Promoting $Player $Chooser $PromPiece) + ( (= $Promoting + (promote $Chooser $Descr)) (matches $Descr $PromPiece))) +; + + + + + (= + (forced-promote $Player $PlI $Piece $PieceI $Prom $PromI) + ( (player-index $Player $PlI) (forced-promote $Player $Piece $PieceI $Prom $PromI))) +; + + + (= + (forced-promote $Player $Piece $PieceI $Prom $PromI) + (promotes-into $Piece $PieceI $Prom $PromI $Player $Player)) +; + + + +; +; + +; +; + +; +; + + + + (= + (build-promotion-matrix $Matrix) + (map-player-table promotion-matrix Nil $Matrix)) +; + + + + (= + (print-promotion-matrix) + (print-promotion-matrix $Piece $Player $PieceT)) +; + + + (= + (print-promotion-matrix $Piece $Player $PieceT) + ( (format "Player Piece Promotion Matrix:~n" Nil) (or (, (piece-player-promotion $Piece $Player $PieceT) (format "~p: ~p -> ~p~n" (:: $Player $Piece $PieceT)) (fail)) True))) +; + + + + (= + (ppp $Player $Piece $PieceT) + (piece-player-promotion $Piece $Player $PieceT)) +; + + +; +; + +; +; + +; +; + + + (= + (piece-player-promotion $Piece $Player $PieceT) + ( (advice-tables $Tables) (piece-player-promotion $Piece $Player $PieceT $Tables))) +; + + +; +; + +; +; + +; +; + + (= + (piece-player-promotion $Piece $Player $PieceT $Tables) + (piece-player-promotion $Piece $PieceI $Player $PlayerI $PieceT $PieceTI $Tables)) +; + + + (= + (piece-player-promotion $Piece $PieceI $Player $PlayerI $PieceT $PieceTI $Tables) + ( (player-index $Player $PlayerI) + (piece-index $Piece $PieceI) + (piece-player-piece $PieceI $PlayerI $PieceTI $Tables) + (piece-index $PieceT $PieceTI))) +; + + + + (= + (piece-player-piece $PieceI $PlayerI $PieceTI $Tables) + ( (promotion-matrix $Tables $M) (piece-player-piece1 $PieceI $PlayerI $PieceTI $M))) +; + + + + (= + (piece-player-piece1 $PieceI $PlayerI $PieceTI $M) + ( (player-table-entry $_ $PlayerI $M $Entry) + (member1-pair + (- $PieceI $Ts) $Entry) + (member $PieceTI $Ts))) +; + + + + (= + (piece-player-pieces $PieceI $PlayerI $TIs $Tables) + ( (promotion-matrix $Tables $M) (piece-player-pieces $PieceI $PlayerI $TIs $M))) +; + + + + (= + (piece-player-pieces1 $PieceI $PlayerI $TIs $M) + ( (player-table-entry $_ $PlayerI $M $Entry) (member1-pair (- $PieceI $TIs) $Entry))) +; + + + +; +; + +; +; + + + (= + (promotion-matrix $Player $PlIndex $Matrix) + ( (player-index $Player $PlIndex) + (setof + (- $PieceIndex $PieceTIndices) + (^ $Piece + (player-pieces $Player $PlIndex $Piece $PieceIndex $PieceTIndices)) $Matrix) + (tracing-anal-format tables "Built promotion matrix for <~p>~n" + (:: $Player)))) +; + + + + + (= + (player-pieces $Player $PlIndex $Piece $PieceIndex $PieceTIndices) + ( (piece-index $Piece $PieceIndex) (det-if-then-else (setof $PieceTIndex (^ $PieceT (player-piece-piece $Player $PlIndex $Piece $PieceIndex $PieceT $PieceTIndex)) $PieceTIndices) True (= $PieceTIndices Nil)))) +; + + + + (= + (player-piece-piece $Player $Piece $PieceT) + (player-piece-piece $Player $PlIndex $Piece $PieceIndex $PieceT $PieceTIndex)) +; + + + (= + (player-piece-piece $Player $PlI $Piece $PieceI $PieceT $PieceTI) + ( (piece-index $Piece $PieceI) + (player-index $Player $PlI) + (forced-promote $Player $PlI $Piece $PieceI $PieceT $PieceTI) + (piece-index $PieceT $PieceTI) + (tracing-anal-format detailed "~p: ~p -> ~p~n" + (:: $Player $Piece $PieceT)))) +; + + + + +; +; + +; +; + +; +; + + +; +; + + + (= + (build-prom-distance-matrix $Trans $Matrix) + (map-player-table prom-distance-matrix + (:: $Trans) $Matrix)) +; + + + + + + (= + (prom-distance-matrix $Player $PlayerIndex $Matrix) + ( (promotion-matrix $Trans) (prom-distance-matrix $Player $PlayerIndex $Trans $Matrix))) +; + + + (= + (prom-distance-matrix $Player $PlayerIndex $Trans $Matrix) + ( (player-table-entry $Player $PlayerIndex $Trans $Matrix1) + (s-floyd $Matrix1 $Matrix) + (tracing-anal-format tables "Built prom_distance matrix for <~p>~n" + (:: $Player)))) +; + + + + + (= + (piece-player-list-dist $PieceI $PlayerI $PieceTI $Dist $Tables) + ( (prom-distance-matrix $Tables $Matrix) (piece-player-list-dist1 $PieceI $PlayerI $PieceTI $Matrix $Dist))) +; + + + + (= + (piece-player-list-dist1 $PieceI $PlayerI $PieceTI $Table $Dist) + ( (player-table-entry $_ $PlayerI $Table $Entry) (piece-matrix-distance $PieceI $PieceTI $Entry $Dist))) +; + + + + (= + (piece-player-list-prom-distance $PieceI $PlayerI $PieceTI $Dist $Tables) + ( (prom-distance-matrix $Tables $Matrix) (piece-player-list-prom-distance1 $PieceI $PlayerI $PieceTI $Matrix $Dist))) +; + + + + (= + (piece-player-list-prom-distance1 $PieceI $PlayerI $PieceTI $Table $Dist) + ( (player-table-entry $_ $PlayerI $Table $Entry) (piece-matrix-distance $PieceI $PieceTI $Entry $Dist))) +; + + + + + + (= + (print-prom-distance-matrix) + (print-prom-distance-matrix $_ $_ $_)) +; + + + (= + (print-prom-distance-matrix $Piece $Player $PieceT) + ( (format "Piece Player Prom_distance Matrix:~n" Nil) (or (, (piece-player-prom-distance $Piece $Player $PieceT $Dist) (format "~p: ~p -> ~p <~p>~n" (:: $Player $Piece $PieceT $Dist)) (fail)) True))) +; + + + + + (= + (ppd $P $Pl $PieceT $V) + (piece-player-prom-distance $P $Pl $PieceT $V)) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (piece-player-prom-distance $Piece $Player $PieceT $Dist) + ( (advice-tables $Tables) (piece-player-prom-distance $Piece $Player $PieceT $Dist $Tables))) +; + + +; +; + +; +; + +; +; + +; +; + + (= + (piece-player-prom-distance $Piece $Player $PieceT $Dist $Tables) + ( (player-index $Player $PlayerI) + (piece-index $Piece $PieceI) + (piece-index $PieceT $PieceTI) + (piece-player-list-prom-distance $PieceI $PlayerI $PieceTI $Dist $Tables))) +; + + + + +; +; + +; +; + +; +; + +; +; + + + + (= + (build-promsq-matrix $Matrix) + ( (distance-table $DTable) (build-promsq-matrix $DTable $Matrix))) +; + + +; +; + + (= + (build-promsq-matrix $DTable $Matrix) + (map-piece-table promsq-matrix + (:: $DTable) $Matrix)) +; + + + + (= + (promsq-matrix $Piece $PieceIndex $Matrix) + ( (distance-table $DTable) (promsq-matrix $Piece $PieceIndex $DTable $Matrix))) +; + + + (= + (promsq-matrix $Piece $PieceIndex $DTable $Matrix) + ( (piece-index $Piece $PieceIndex) + (map-square-table square-promsq + (:: $Piece $PieceIndex $DTable) $Matrix) + (tracing-anal-format tables "Built promsq table for <~p>~n" + (:: $Piece)))) +; + + + + +; +; + + + (= + (square-promsq $Sq $SqI $Piece $PieceI $DTable + (/ $SqTIs $Dist)) + ( (nearest-promotion-squares $Piece $PieceI $Player $Sq $SqI $SqTs $SqTIs $DTable $Dist) (set-det))) +; + + (= + (square_promsq $Sq $SqI $Piece $PieceI $DTable $Ignore) True) +; + + + + + +; +; + + + (= + (square-piece-psqs $SqI $PieceI $SqTIs $Dist $Tables) + ( (promsq-matrix $Tables $M) + (pindex-table-entry $PieceI $M $Entry) + (slindex-table-entries $SqI $Entry $SqTIs $Dist))) +; + + + +; +; + + + (= + (square-piece-psq $SqI $PieceI $SqTI $Dist $Tables) + ( (promsq-matrix $Tables $M) + (pindex-table-entry $PieceI $M $Entry) + (slindex-table-entry $SqI $Entry $SqTI $Dist))) +; + + + + + + (= + (spq $S $P $SqT $D) + (square-piece-promsq $S $P $SqT $D)) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (square-piece-promsq $Sq $Piece $SqT $Dist) + ( (advice-tables $Tables) (square-piece-promsq $Sq $Piece $SqT $Dist $Tables))) +; + + +; +; + +; +; + +; +; + + (= + (square-piece-promsq $Sq $Piece $SqT $Dist $Tables) + ( (piece-index $Piece $PieceI) + (square-index $Sq $SqI) + (square-piece-psq $SqI $PieceI $SqTI $Dist $Tables) + (square-index $SqT $SqTI))) +; + + + + + +; +; + +; +; + + + (= + (print-promsq-matrix) + (print-promsq-matrix $_ $_)) +; + + + (= + (print-promsq-matrix $Sq $Piece) + ( (format "Square Piece Promsq Matrix:~n" Nil) (or (, (square-piece-promsq $Sq $Piece $SqT $Dist) (format "matrix[~p][~p] = ~p (~p)~n" (:: $Sq $Piece $SqT $Dist)) (fail)) True))) +; + + + + +; +; + + + (= + (nearest-promotion-squares $Piece $Player $Sq $SqTs $Dist) + (nearest-promotion-squares $Piece $PieceI $Player $Sq $SqI $SqTs $SqTIs $Dist)) +; + + + (= + (nearest-promotion-squares $Piece $PieceI $Player $Sq $SqI $SqTs $SqTIs $Dist) + ( (distance-table $DTable) (nearest-promotion-squares $Piece $PieceI $Player $Sq $SqI $SqTs $SqTIs $DTable $Dist))) +; + + + (= + (nearest-promotion-squares $Piece $PieceI $Player $Sq $SqI $SqTs $SqTIs $DTable $Dist) + ( (piece-index $Piece $PieceI) + (square-index $Sq $SqI) + (owns $Piece $Player) + (prom-square-indices $Player $PromSquares) + (nearest-squares $PromSquares $PieceI $SqI $SqTs $SqTIs $DTable $Dist))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (nearest-squares $Squares $PieceI $SqI $SqTs $SqTIs $DTable $Dist) + ( (square-distances $Squares $PieceI $SqI $DTable $AllDists) + (closest-dists $AllDists $Dist $SqTIs) + (maplist square-index $SqTs $SqTIs))) +; + + + + + (= + (square-distances $Squares $PieceI $SqI $DTable $AllDists) + (findall + (- $Dist $SqTI) + (, + (member $SqTI $Squares) + (\== $SqTI $SqI) + (square-piece-sq-dist1 $SqI $PieceI $SqTI $DTable $Dist)) $AllDists)) +; + + + + (= + (closest-dists $AllDists $V $Es) + ( (p-to-s-graph $AllDists $Graph) (first-connected $Graph (- $V $Es)))) +; + + + + (= + (first-connected + (Cons $H $Rest) $First) + (first1 $H $Rest $First)) +; + + + + (= + (first1 + (- $V $Es) $Rest $First) + (det-if-then-else + (= $Es Nil) + (first-connected $Rest $First) + (= $First + (- $V $Es)))) +; + + + diff --git a/metagame/learning/step.metta b/metagame/learning/step.metta new file mode 100644 index 0000000..500db36 --- /dev/null +++ b/metagame/learning/step.metta @@ -0,0 +1,857 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (ind-advice $Player $Piece + (advice victims $Piece $Value) $Tables) + (victim-counts $Piece $Value)) +; + + (= + (ind-advice $Player $Piece + (advice immunity $Piece $Value) $Tables) + (immunity-value $Player $Piece $Value)) +; + + (= + (ind-advice $Player $Piece + (advice giveaway $Piece $Value) $Tables) + (giveaway-value $Player $Piece $Value)) +; + + (= + (ind-advice $Player $Piece + (advice max-static-mob $Piece $Value) $Tables) + (max-static-mob $Piece $Value $Tables)) +; + + (= + (ind-advice $Player $Piece + (advice max-eventual-mob $Piece $Value) $Tables) + (max-eventual-mob $Piece $Value $Tables)) +; + + (= + (ind-advice $Player $Piece + (advice avg-static-mob $Piece $Value) $Tables) + (average-static-mob $Piece $Value $Tables)) +; + + (= + (ind-advice $Player $Piece + (advice avg-eventual-mob $Piece $Value) $Tables) + (average-eventual-mob $Piece $Value $Tables)) +; + + (= + (ind-advice $Player $Piece + (advice eradicate + (- $Player $Piece) $Value) $Tables) + ( (player-eradicate-target $Player $Piece) (= $Value -1))) +; + + (= + (ind-advice $Player $Piece + (advice eradicate + (- $Opp $Piece) $Value) $Tables) + ( (opposite-role $Player $Opp) + (player-eradicate-target $Opp $Piece) + (= $Value 1))) +; + + (= + (ind-advice $Player $Piece + (advice stalemate $Player $Value) $Tables) + ( (player-stalemate-target $Player $Piece) (= $Value -1))) +; + + (= + (ind-advice $Player $Piece + (advice stalemate $Opp $Value) $Tables) + ( (opposite-role $Player $Opp) + (player-stalemate-target $Opp $Piece) + (= $Value 1))) +; + + (= + (ind-advice $Player $Piece + (advice arrive + (- $Player $Piece) $Value) $Tables) + ( (player-arrive-generator $Player $Piece $Dist $Tables) (is $Value (/ 1 (+ 1 $Dist))))) +; + + (= + (ind-advice $Player $Piece + (advice arrive + (- + (- $Opp $Piece) $Dist) $Value) $Tables) + ( (opposite-role $Player $Opp) + (player-arrive-generator $Opp $Piece $Dist $Tables) + (is $Value + (/ -1 + (+ 1 $Dist))))) +; + + + + (= + (ind-advice $Player $Piece $Value) + ( (advice-tables $Tables) (ind-advice $Player $Piece $Value $Tables))) +; + + + + + (= + (independent-advice $Player $Piece $Value $Tables) + ( (owns $Piece $Player) + (piece-index $Piece $_) + (ind-advice $Player $Piece $Val1 $Tables) + (negate-advice-for-player $Player $Val1 $Value))) +; + + + (= + (independent-advice $Player $Piece $Value) + ( (advice-tables $Tables) (independent-advice $Player $Piece $Value $Tables))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (static-evaluation $Piece $Sq $Value $Position $Tables) + ( (get-static-advices $Piece $Sq $Advice $Position $Tables) (mediate-advices $Advice $Value $Tables))) +; + + + + + (= + (get-static-advices $Piece $Sq $Advices $Position $Tables) + ( (piece-index $Piece $_) (findall $Advice (independent-advice $Player $Piece $Advice $Tables) $Advices))) +; + + + (= + (get-static-advices $Piece $Advices) + ( (find-advice-tables $Tables) (get-static-advices $Piece $Sq $Advices $Position $Tables))) +; + + + + (= + (show-static-advices $Piece) + ( (get-static-advices $Piece $As) (ppl $As))) +; + + + + + (= + (show-static-advices-total $Piece) + ( (get-static-advices $Piece $As) + (ppl $As) + (mediate-advices $As $Total $_) + (format "Total (Mediated) for <~p>: ~p~n" + (:: $Piece $Total)))) +; + + + + + (= + (advice-top $Color $Type) + ( (piece $Piece + (:: $Color $Type) Nil) (show-static-advices-total $Piece))) +; + + + + (= + (adviceold-top $Color $Type) + ( (piece $Piece + (:: $Color $Type) Nil) (show-static-advices $Piece))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (cap-value $Piece $Player $Victim $Value $Tables) + ( (find-advice-tables-if $Tables) + (piece-victim $Piece $Player $Victim $VPlayer $Effect) + (victim-value $Player $Victim $VPlayer $Value $Tables))) +; + + + (= + (cap-value $Piece $Player $Victim $Value) + ( (advice-tables $Tables) (cap-value $Piece $Player $Victim $Value $Tables))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (victim-value $Player $Piece $VPlayer $Value $Tables) + ( (independent-advice $VPlayer $Piece $Advice $Tables) + (advice-victim-value $Advice $Val1 $Tables) + (remove-option-value $Player $VPlayer $Val1 $Value))) +; + + + + (= + (advice-victim-value $Advice $Val $Tables) + (weigh-advice $Advice $Val $Tables)) +; + + + +; +; + +; +; + +; +; + + + (= + (remove-option-value $Player $Owner $Val1 $Value) + (det-if-then-else + (forced-remove $Player $Owner) + (forced-remove-value $Player $Val1 $Value) + (optional-remove-value $Player $Val1 $Value))) +; + + +; +; + +; +; + +; +; + + + (= + (forced-remove $Player $Owner) + ( (current-game-must-capture) (\== $Player $Owner))) +; + + +; +; + + + (= + (forced-remove-value $Player $Val1 $Value) + (is $Value + (- $Val1))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (optional-remove-value $Player $Val1 $Value) + ( (is $RemoveVal + (- $Val1)) + (negate-for-player $Player $RemoveVal $PVal) + (max 0 $PVal $OptVal) + (negate-for-player $Player $OptVal $Value))) +; + + + + + + (= + (piece-victim $Piece $Victim) + (piece-victim $Piece $Victim $Effect)) +; + + + (= + (piece-victim $Piece $Victim $Effect) + (piece-victim $Piece $Player $Victim $VPlayer $Effect)) +; + + + (= + (piece-victim $Piece $Player $Victim $VPlayer $Effect) + (piece-victim $Piece $Player $Victim $VPlayer $Effect $Capture)) +; + + + (= + (piece-victim $Piece $Player $Victim $VPlayer $Effect $Capture) + ( (piece-index $Piece $PI) + (owns $Piece $Player) + (owns $Victim $VPlayer) + (current-game-for-player $Player $Game) + (game-piece-has-capture $Piece $Capture $Game) + (capture-type $Capture $Type) + (capture-effect $Capture $Effect) + (matches $Type $Victim))) +; + + + + +; +; + + + (= + (threat-piece-victim $Piece $Player $Victim $VPlayer $Effect $Capture) + ( (piece-victim $Piece $Player $Victim $VPlayer $Effect $Capture) (not (, (opposite-role $Player $VPlayer) (= $Effect (possess $VPlayer)))))) +; + + + + + (= + (victim-counts $Piece $VCount) + ( (unique-victims $Piece $Unique) (length $Unique $VCount))) +; + + + + + (= + (unique-victims $Piece $Unique) + (unique-victims $Piece $Player $Victim $VPlayer $Effect $Unique)) +; + + + (= + (unique-victims $Piece $Player $Victim $VPlayer $Effect $Unique) + ( (findall $Victim + (threat-piece-victim $Piece $Player $Victim $VPlayer $Effect $Cap) $Victims) (remove-duplicates $Victims $Unique))) +; + + + + + (= + (unique-victimizers $Piece $Unique) + (unique-victimizers $Piece $Player $Victim $VPlayer $Effect $Unique)) +; + + + (= + (unique-victimizers $Piece $Player $Victim $VPlayer $Effect $Unique) + ( (findall $Piece + (threat-piece-victim $Piece $Player $Victim $VPlayer $Effect $Cap) $Victims) (remove-duplicates $Victims $Unique))) +; + + + + + + (= + (giveaway-value $Player $Piece $Value) + ( (unique-victimizers $CapPiece $Player $Piece $Player $Effect $Unique) + (length $Unique $VCount) + (is $Value $VCount))) +; + + + + + (= + (immunity-value $Player $Piece $Value) + ( (piece-type-count $Count) + (opposite-role $Player $Opp) + (unique-victimizers $CapPiece $Opp $Piece $Player $Effect $Unique) + (length $Unique $VCount) + (is $Value + (- $Count $VCount)))) +; + + + + +; +; + + + (= + (player-eradicate-target $Player $Piece) + ( (game-player-has-goal $_ $Player $Goal) + (eradicate-goal $Goal $Descr) + (matches $Descr $Piece))) +; + + +; +; + +; +; + + + (= + (player-stalemate-target $Player $Piece) + ( (game-player-has-goal $_ $Player $Goal) + (stalemate-goal $Goal $Owner) + (owns $Piece $Owner))) +; + + + +; +; + +; +; + + + (= + (player-arrive-generator $Player $Piece $Dist $Tables) + ( (game-player-has-goal $_ $Player $Goal) + (arrive-goal $Goal $Descr $Squares) + (piece-player-prom-distance $Piece $Player $PieceT $Dist $Tables) + (matches $Descr $PieceT))) +; + + + + + + + + + (= + (max-static-mob $Piece $Val $Tables) + ( (findall $Val1 + (square-piece-mobility $Sq $Piece $Val1 $Tables) $Mobs) (max $Mobs $Val))) +; + + + + + + (= + (max-eventual-mob $Piece $Val $Tables) + ( (findall $Val1 + (square-piece-reachability $Sq $Piece $Val1 $Tables) $Mobs) (max $Mobs $Val))) +; + + + + + + + (= + (average-static-mob $Piece $Val $Tables) + ( (findall $Val1 + (square-piece-mobility $Sq $Piece $Val1 $Tables) $Mobs) (average $Mobs $Val))) +; + + + + + + (= + (average-eventual-mob $Piece $Val $Tables) + ( (findall $Val1 + (square-piece-reachability $Sq $Piece $Val1 $Tables) $Mobs) (average $Mobs $Val))) +; + + + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (capture-evaluation $Piece $Sq $Value $Position $Tables) + ( (get-capture-advices $Piece $Sq $Advice $Position $Tables) (mediate-capture-advices $Advice $Value $Tables))) +; + + + + (= + (mediate-capture-advices $Advice $Value $Tables) + (sumlist $Advice $Value)) +; + + + + + (= + (get-capture-advices $Piece $Sq $Advices $Position $Tables) + ( (piece-index $Piece $_) (findall $Advice (cap-value $Piece $Player $Victim $Advice $Tables) $Advices))) +; + + + (= + (get-capture-advices $Piece $Advices) + ( (find-advice-tables $Tables) (get-capture-advices $Piece $Sq $Advices $Position $Tables))) +; + + + + (= + (show-capture-advices $Piece) + ( (get-capture-advices $Piece $As) (ppl $As))) +; + + + + + + +; +; + +; +; + +; +; + + + + (= + (build-static-matrix $Matrix) + (map-piece-table static-matrix Nil $Matrix)) +; + + + (= + (build-static-matrix $Matrix $Tables) + (map-piece-table static-matrix + (:: $Tables) $Matrix)) +; + + + + + (= + (print-static-matrix) + (print-static-matrix $Piece $Player $StatVal)) +; + + + (= + (print-static-matrix $Piece $Player $StatVal) + ( (format "Player Piece Static Matrix:~n" Nil) (or (, (piece-player-static $Piece $Player $StatVal) (format "~p: ~p -> ~p~n" (:: $Player $Piece $StatVal)) (fail)) True))) +; + + + + (= + (pps $Player $Piece $StatVal) + (piece-player-static $Piece $Player $StatVal)) +; + + +; +; + +; +; + + + (= + (piece-player-static $Piece $Player $StatVal) + ( (advice-tables $Tables) (piece-player-static $Piece $Player $StatVal $Tables))) +; + + +; +; + +; +; + + (= + (piece-player-static $Piece $Player $StatVal $Tables) + (piece-player-static $Piece $PieceI $Player $PlayerI $StatVal $Tables)) +; + + + (= + (piece-player-static $Piece $PieceI $Player $PlayerI $StatVal $Tables) + ( (piece-index $Piece $PieceI) + (owns $Piece $Player) + (piece-static-value $PieceI $StatVal $Tables))) +; + + + + (= + (piece-static-value $PieceI $StatVal $Tables) + ( (static-matrix $Tables $M) (piece-static-val1 $PieceI $StatVal $M))) +; + + + + (= + (piece-static-val1 $PieceI $StatVal $M) + (pindex-table-entry $PieceI $M $StatVal)) +; + + + + + (= + (static-matrix $Piece $PIndex $Value) + ( (find-advice-tables $Tables) (static-matrix $Piece $PIndex $Value $Tables))) +; + + +; +; + + (= + (static-matrix $Piece $PIndex $Tables $Value) + ( (piece-index $Piece $PIndex) + (static-evaluation $Piece $Sq $Value $Position $Tables) + (tracing-anal-format tables "Built independent matrix for <~p>~n" + (:: $Piece)))) +; + + + diff --git a/metagame/learning/struct.metta b/metagame/learning/struct.metta new file mode 100644 index 0000000..4b7ad78 --- /dev/null +++ b/metagame/learning/struct.metta @@ -0,0 +1,457 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + + + (= + (build-tables) + ( (new-empty-state $State) (build-tables $State))) +; + + + (= + (build-tables $State) + (runtime (build-tables $State $Tables))) +; + + + (= + (build-tables $State $T) + ( (anal-table $T) + (promsq-matrix $T $PromSqMatrix) + (promotion-matrix $T $PromMatrix) + (prom-distance-matrix $T $PromDistMatrix) + (transition-matrix $T $TransMatrix) + (mobility-matrix $T $MobMatrix) + (eventual-matrix $T $EventualMatrix) + (distance-matrix $T $DistMatrix) + (distance-table $T $DistTable) + (active-advisor-table $T $Advisors) + (static-matrix $T $StatMatrix) + (compile-basic-tables) + (tracing-anal-format tables "Building tables ...~n" Nil) + (tracing-anal-timing tables + (build-advisor-table $Advisors)) + (tracing-anal-format tables "Building tables ...~n" Nil) + (tracing-anal-timing tables + (build-promotion-matrix $PromMatrix)) + (tracing-anal-format tables "Building tables ...~n" Nil) + (tracing-anal-timing tables + (build-prom-distance-matrix $PromMatrix $PromDistMatrix)) + (tracing-anal-format tables "Building tables ...~n" Nil) + (tracing-anal-timing tables + (build-transition-matrix $TransMatrix $State)) + (tracing-anal-format tables "Building tables ...~n" Nil) + (tracing-anal-timing tables + (build-mobility-matrix $TransMatrix $MobMatrix)) + (tracing-anal-format tables "Building matrices ...~n" Nil) + (tracing-anal-timing tables + (build-distance-matrix $TransMatrix $DistMatrix)) + (tracing-anal-format tables "Building tables ...~n" Nil) + (tracing-anal-timing tables + (build-distance-table $DistMatrix $DistTable)) + (tracing-anal-format tables "Building tables ...~n" Nil) + (tracing-anal-timing tables + (build-eventual-matrix $DistMatrix $EventualMatrix)) + (tracing-anal-format tables "Building tables ...~n" Nil) + (tracing-anal-timing tables + (build-promsq-matrix $DistTable $PromSqMatrix)) + (tracing-anal-format tables "Building tables ...~n" Nil) + (tracing-anal-timing tables + (build-static-matrix $StatMatrix $T)) + (tracing-anal-format tables "Tables completed!~n" Nil) + (save-tables $T))) +; + + + + + + + (= + (clear-tables) + (remove-all-symbols &self + (advice_tables $_))) +; + + + + (= + (save-tables $Tables) + ( (clear-tables) (add-symbol &self (advice_tables $Tables)))) +; + + + + (= + (dump-tables $File) + (with-output-file $File write dump-tables)) +; + + + (= + (dump-tables) + (listing (/ advice-tables 1))) +; + + + + (= + (load-tables) + ( (read (advice-tables $Tables)) (save-tables $Tables))) +; + + + (= + (load-tables $File) + ( (see $File) + (load-tables) + (seen))) +; + + + + (= + (find-advice-tables-if $T) + (det-if-then-else + (var $T) + (find-advice-tables $T) True)) +; + + + + + (= + (find-advice-tables $T) + (det-if-then-else + (current-predicate advice-tables + (advice-tables $_)) + (advice-tables $T) + (= $T none))) +; + + + +; +; + +; +; + + + + (= + (build-dummy-tables) + (build-dummy-tables $State $Tables)) +; + + + (= + (build-dummy-tables $State $Tables) + ( (anal-table $T) + (active-advisor-table $T $Advisors) + (compile-basic-tables) + (tracing-anal-format tables "Building tables ...~n" Nil) + (tracing-anal-timing tables + (build-advisor-table $Advisors)) + (save-tables $T))) +; + + + + +; +; + +; +; + +; +; + + +; +; + + + (= + (anal-table $N) + (functor $N tables 15)) +; + + + + (= + (promsq-matrix $T $M) + (arg 1 $T $M)) +; + + + (= + (promotion-matrix $T $M) + (arg 2 $T $M)) +; + + + (= + (prom-distance-matrix $T $M) + (arg 3 $T $M)) +; + + + (= + (transition-matrix $T $M) + (arg 4 $T $M)) +; + + + (= + (mobility-matrix $T $M) + (arg 5 $T $M)) +; + + + (= + (eventual-matrix $T $M) + (arg 6 $T $M)) +; + + + (= + (distance-matrix $T $M) + (arg 7 $T $M)) +; + + + (= + (distance-table $T $M) + (arg 8 $T $M)) +; + + + + (= + (piece-value-table $T $M) + (arg 9 $T $M)) +; + + + (= + (piece-square-table $T $M) + (arg 10 $T $M)) +; + + + + (= + (active-advisor-table $T $M) + (arg 11 $T $M)) +; + + + + (= + (capturing-table $T $M) + (arg 12 $T $M)) +; + + + (= + (moving-table $T $M) + (arg 13 $T $M)) +; + + + (= + (static-matrix $T $M) + (arg 14 $T $M)) +; + + + + + + (= + (promsq-matrix $M) + ( (advice-tables $T) (promsq-matrix $T $M))) +; + + + (= + (promotion-matrix $M) + ( (advice-tables $T) (promotion-matrix $T $M))) +; + + + (= + (prom-distance-matrix $M) + ( (advice-tables $T) (prom-distance-matrix $T $M))) +; + + + (= + (transition-matrix $M) + ( (advice-tables $T) (transition-matrix $T $M))) +; + + + (= + (mobility-matrix $M) + ( (advice-tables $T) (mobility-matrix $T $M))) +; + + + (= + (eventual-matrix $M) + ( (advice-tables $T) (eventual-matrix $T $M))) +; + + + (= + (distance-matrix $M) + ( (advice-tables $T) (distance-matrix $T $M))) +; + + + (= + (distance-table $M) + ( (advice-tables $T) (distance-table $T $M))) +; + + + + (= + (piece-value-table $M) + ( (advice-tables $T) (piece-value-table $T $M))) +; + + + (= + (piece-square-table $M) + ( (advice-tables $T) (piece-square-table $T $M))) +; + + + (= + (active-advisor-table $M) + ( (advice-tables $T) (active-advisor-table $T $M))) +; + + + (= + (static-matrix $M) + ( (advice-tables $T) (static-matrix $T $M))) +; + + + + + (= + (add-portray-anal-table) + ( (anal-table $T) (add-symbol &self (:- (portray $T) (portray_anal_table $T))))) +; + + + + (= + (portray-anal-table $T) + (format "" Nil)) +; + + +; +; + +; +; + +; +; + + + + (= + (shutdown-advisor $Advisor $Table) + ( (active-advisor-table $Table $M) + (advisor-number $Advisor $Number) + (arg $Number $M off))) +; + + + + (= + (active-advisor $Advisor $Table) + ( (active-advisor-table $Table $M) + (advisor-number $Advisor $Number) + (arg $Number $M $Status) + (\== $Status off))) +; + + + + (= + (advisor_number threat 1) True) +; + + (= + (advisor_number prom 2) True) +; + + (= + (advisor_number dynamic_mobility 3) True) +; + + + + (= + (number_of_advisors 3) True) +; + + + + (= + (build-advisor-table $T) + ( (number-of-advisors $N) (functor $T active-advisors $N))) +; + + + + +; +; + +; +; + +; +; + + + + (= + (build-top) + (build-tables)) +; + + + + (= + (showstatic-top) + (print-static-matrix)) +; + + + diff --git a/metagame/learning/tables.metta b/metagame/learning/tables.metta new file mode 100644 index 0000000..a755646 --- /dev/null +++ b/metagame/learning/tables.metta @@ -0,0 +1,1400 @@ +; +; + +; +; + +; +; + +; +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (matrix-to-square-table Nil $A) + ( (set-det) (new-square-table $A))) +; + + (= + (matrix-to-square-table + (Cons + (- $V $E) $D) $A) + ( (matrix-to-square-table $D $A) + (pairs-to-square-table $E $A2) + (arg $V $A $A2))) +; + + + + (= + (pairs-to-square-table Nil $A) + ( (set-det) (new-square-table $A))) +; + + (= + (pairs-to-square-table + (Cons + (- $V $W) $D) $A) + ( (pairs-to-square-table $D $A) (arg $V $A $W))) +; + + + + (= + (square-table-to-matrix $A $D) + ( (square-table-to-list $A $List) (square-tables-to-matrix $List $D))) +; + + + + (= + (square_tables_to_matrix () ()) True) +; + + (= + (square-tables-to-matrix + (Cons + (- $I $A) $ARest) + (Cons + (- $I $D) $DRest)) + ( (square-table-to-list $A $D) (square-tables-to-matrix $ARest $DRest))) +; + + +; +; + +; +; + +; +; + + + + (= + (d-to-array Nil $A) + ( (set-det) (new-array $A))) +; + + (= + (d-to-array + (Cons + (- $V $E) $D) $A) + ( (d-to-array $D $A1) + (pairs-to-array $E $A2) + (aset $V $A1 $A2 $A))) +; + + + + (= + (pairs-to-array Nil $A) + ( (set-det) (new-array $A))) +; + + (= + (pairs-to-array + (Cons + (- $V $W) $D) $A) + ( (pairs-to-array $D $A1) (aset $V $A1 $W $A))) +; + + + + (= + (array-to-d $A $D) + ( (alist $A $List) (arrays-to-d $List $D))) +; + + + + (= + (arrays_to_d () ()) True) +; + + (= + (arrays-to-d + (Cons + (- $I $A) $ARest) + (Cons + (- $I $D) $DRest)) + ( (alist $A $D) (arrays-to-d $ARest $DRest))) +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (compile-basic-tables) + (with-temp-file basic $File + (, + (compile-basic-tables-to-file $File) + (compile $File)))) +; + + + + + (= + (compile-basic-tables-to-file $File) + ( (format "~nCompiling Basic Tables to file: ~w~n" + (:: $File)) + (make-basic-tables) + (with-output-file $File write list-basic-tables))) +; + + + + (= + (list-basic-tables) + (whenever + (basic-table-pred $Pred) + (listing $Pred))) +; + + + + + (= + (make-basic-tables) + ( (assert-square-indices) + (assert-piece-indices) + (assert-prom-square-indices))) +; + + + + (= + (basic_table_pred + (/ opponent_prom_sq 1)) True) +; + + (= + (basic_table_pred + (/ player_prom_sq 1)) True) +; + + (= + (basic_table_pred + (/ prom_square_indices 2)) True) +; + + + (= + (basic_table_pred + (/ piece_type_index 2)) True) +; + + (= + (basic_table_pred + (/ piece_type_count 1)) True) +; + + (= + (basic_table_pred + (/ index_to_piece 2)) True) +; + + (= + (basic_table_pred + (/ total_piece_count 1)) True) +; + + + (= + (basic_table_pred + (/ index_to_square 2)) True) +; + + (= + (basic_table_pred + (/ total_square_count 1)) True) +; + + (= + (basic_table_pred + (/ board_dim 1)) True) +; + + + + + +; +; + +; +; + +; +; + + + + (= + (new-square-table $A) + (square-table $A)) +; + + + + (= + (square-table-distance $Item1 $Item2 $Table $Distance) + ( (arg $Item1 $Table $Sub) + (arg $Item2 $Sub $Distance1) + (interpret-distance $Distance1 $Distance))) +; + + + + (= + (square-matrix-distance $Item1 $Item2 $Table $Distance) + ( (member1-pair + (- $Item1 $Sub) $Table) + (member1-pair + (- $Item2 $Distance1) $Sub) + (interpret-distance $Distance1 $Distance))) +; + + + + +; +; + + + (= + (interpret-distance $Distance $Distance) + (nonvar $Distance)) +; + + + + + (= + (square-table-to-list $A $List) + ( (functor $A square-table $N) (sqtl 1 $N $A $List))) +; + + + + (= + (sqtl $N1 $N $A Nil) + ( (> $N1 $N) (set-det))) +; + + (= + (sqtl $N $Max $A + (Cons + (- $N $I) $In)) + ( (arg $N $A $I) + (is $N1 + (+ $N 1)) + (sqtl $N1 $Max $A $In))) +; + + + + + (= + (square-table $Table) + ( (total-square-count $Count) (functor $Table square-table $Count))) +; + + + + (= + (sindex-table-entry $Index $Table $Entry) + (arg $Index $Table $Entry)) +; + + +; +; + +; +; + + + (= + (slindex-table-entries $Index $Table $List $Data) + ( (arg $Index $Table $Val) + (nonvar $Val) + (= $Val + (/ $List $Data)))) +; + + +; +; + + + (= + (slindex-table-entry $Index $Table $Entry $Data) + ( (slindex-table-entries $Index $Table $List $Data) (member $Entry $List))) +; + + + + + + + + (= + (square-table-entry $Square $Index $Table $Entry) + ( (square-index $Square $Index) (sindex-table-entry $Index $Table $Entry))) +; + + + + (= + (square-indices $Is) + (setof $I + (^ $P + (square-index $P $I)) $Is)) +; + + + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (map-square-table $Pred $Table) + (map-square-table $Pred Nil $Table)) +; + + + (= + (map-square-table $Pred $Args $Table) + ( (square-table $Table) + (square-indices $Indices) + (map-for-squares $Indices $Pred $Args $Table))) +; + + + + (= + (map_for_squares () $_ $_ $_) True) +; + + (= + (map-for-squares + (Cons $S $Ss) $Pred $Args $Table) + ( (square-table-entry $Square $S $Table $Entry) + (append + (Cons $Pred + (Cons $Square + (Cons $S $Args))) + (:: $Entry) $GoalList) + (=.. $Goal $GoalList) + (call $Goal) + (map-for-squares $Ss $Pred $Args $Table))) +; + + + + + +; +; + +; +; + +; +; + + + + (= + (maps-square-table $Pred $Table1 $Table2) + (maps-square-table $Pred Nil $Table1 $Table2)) +; + + + (= + (maps-square-table $Pred $Args $Table1 $Table2) + ( (square-table $Table1) + (square-table $Table2) + (square-indices $Indices) + (maps-for-squares $Indices $Pred $Args $Table1 $Table2))) +; + + + + (= + (maps_for_squares () $_ $_ $_ $_) True) +; + + (= + (maps-for-squares + (Cons $S $Ss) $Pred $Args $Table1 $Table2) + ( (square-table-entry $Square $S $Table1 $Entry1) + (square-table-entry $Square $S $Table2 $Entry2) + (append + (Cons $Pred + (Cons $Square + (Cons $S $Args))) + (:: $Entry1 $Entry2) $GoalList) + (=.. $Goal $GoalList) + (call $Goal) + (maps-for-squares $Ss $Pred $Args $Table1 $Table2))) +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (count-bagof-squares $Sq $Goal $Squares) + (count-bagof $Sq + (^ + (, $X $Y) + (, + (square-to-index $X $Y $Sq) $Goal)) $Squares)) +; + + + + + (= + (add-portray-square-table) + ( (new-square-table $T) (add-symbol &self (:- (portray $T) (portray_square_table $T))))) +; + + + + (= + (portray-square-table $T) + (format "" Nil)) +; + + + + +; +; + +; +; + +; +; + + + + (= + (new-piece-table $A) + (piece-table $A)) +; + + + + + (= + (piece-table $Table) + ( (total-piece-count $Count) (functor $Table piece-table $Count))) +; + + + + (= + (pindex-table-entry $Index $Table $Entry) + (arg $Index $Table $Entry)) +; + + + + (= + (piece-table-entry $Piece $Index $Table $Entry) + ( (piece-index $Piece $Index) (pindex-table-entry $Index $Table $Entry))) +; + + + + (= + (piece-matrix-distance $Item1 $Item2 $Table $Distance) + ( (member1-pair + (- $Item1 $Sub) $Table) + (member1-pair + (- $Item2 $Distance1) $Sub) + (interpret-distance $Distance1 $Distance))) +; + + + + + + + (= + (piece-indices $Is) + (setof $I + (^ $P + (piece-index $P $I)) $Is)) +; + + + + (= + (add-portray-piece-table) + ( (new-piece-table $T) (add-symbol &self (:- (portray $T) (portray_piece_table $T))))) +; + + + + (= + (portray-piece-table $T) + (format "" Nil)) +; + + + + (= + (portray-tables) + ( (add-portray-piece-table) (add-portray-square-table))) +; + + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (map-piece-table $Pred $Table) + (map-piece-table $Pred Nil $Table)) +; + + + (= + (map-piece-table $Pred $Args $Table) + ( (piece-table $Table) + (piece-indices $Indices) + (map-for-pieces $Indices $Pred $Args $Table))) +; + + + + (= + (map_for_pieces () $_ $_ $_) True) +; + + (= + (map-for-pieces + (Cons $P $Ps) $Pred $Args $Table) + ( (piece-table-entry $Piece $P $Table $Entry) + (append + (Cons $Pred + (Cons $Piece + (Cons $P $Args))) + (:: $Entry) $GoalList) + (=.. $Goal $GoalList) + (call $Goal) + (map-for-pieces $Ps $Pred $Args $Table))) +; + + + + + +; +; + +; +; + +; +; + + + + (= + (maps-piece-table $Pred $Table1 $Table2) + (maps-piece-table $Pred Nil $Table1 $Table2)) +; + + + (= + (maps-piece-table $Pred $Args $Table1 $Table2) + ( (piece-table $Table1) + (piece-table $Table2) + (piece-indices $Indices) + (maps-for-pieces $Indices $Pred $Args $Table1 $Table2))) +; + + + + (= + (maps_for_pieces () $_ $_ $_ $_) True) +; + + (= + (maps-for-pieces + (Cons $P $Ps) $Pred $Args $Table1 $Table2) + ( (piece-table-entry $Piece $P $Table1 $Entry1) + (piece-table-entry $Piece $P $Table2 $Entry2) + (append + (Cons $Pred + (Cons $Piece + (Cons $P $Args))) + (:: $Entry1 $Entry2) $GoalList) + (=.. $Goal $GoalList) + (call $Goal) + (maps-for-pieces $Ps $Pred $Args $Table1 $Table2))) +; + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (square-index $Square $Index) + (det-if-then-else + (var $Index) + (square-to-index $Square $Index) + (index-to-square $Index $Square))) +; + + + + + (= + (current-board-dim $Dim) + (current-board-size $Dim $Y)) +; + + +; +; + + + (= + (set-board-dim) + ( (abolish (/ board-dim 1)) + (current-board-dim $Dim) + (add-symbol &self + (board_dim $Dim)))) +; + + +; +; + + + (= + (set-square-count) + ( (set-board-dim) + (abolish (/ total-square-count 1)) + (current-board-size $X $Y) + (is $Total + (* $X $Y)) + (add-symbol &self + (total_square_count $Total)))) +; + + + +; +; + + + (= + (assert-square-indices) + ( (abolish (/ index-to-square 2)) + (set-square-count) + (whenever + (square-to-index $Square $Key) + (assert-square-index $Square $Key)) + (tracing-anal index print-square-indices))) +; + + + + (= + (assert-square-index $Square $Index) + (add-symbol &self + (index_to_square $Index $Square))) +; + + + + (= + (print-square-indices) + ( (format "Square Index Table:~n" Nil) (or (, (index-to-square $I $P) (format "~p --> ~p~n" (:: $I $P)) (fail)) True))) +; + + + + (= + (square-to-index + (square $X $Y) $Index) + ( (board-square $X $Y) + (board-dim $Dim) + (is $Index + (+ + (* $Dim + (- $Y 1)) $X)))) +; + + + (= + (square-to-index $X $Y $Index) + ( (board-square $X $Y) + (board-dim $Dim) + (is $Index + (+ + (* $Dim + (- $Y 1)) $X)))) +; + + + + (= + (board-square (square $X $Y)) + (board-square $X $Y)) +; + + +; +; + + (= + (board-square $X $Y) + ( (current-board-size $XMax $YMax) + (between 1 $YMax $Y) + (between 1 $XMax $X))) +; + + + + + (= + (piece-index $Piece $Index) + (det-if-then-else + (var $Index) + (piece-to-index $Piece $Index) + (index-to-piece $Index $Piece))) +; + + + + (= + (current-game-piece-count $Count) + ( (player-current-game $Game) (game-piece-count $Count $Game))) +; + + + + (= + (game-piece-count $Count $Game) + ( (game-piece-names $Game $Names) (length $Names $Count))) +; + + + + (= + (nth-piece-name $N $P) + ( (player-current-game $G) + (game-piece-names $G $Names) + (nth $N $Names $P))) +; + + +; +; + + + (= + (assert-piece-indices) + ( (assert-piece-type-indices) + (abolish (/ index-to-piece 2)) + (whenever + (piece-to-index $Piece $Key) + (assert-piece-index $Piece $Key)) + (tracing-anal index print-piece-indices))) +; + + + + (= + (assert-piece-type-indices) + ( (abolish (/ piece-type-index 2)) + (set-piece-type-count) + (whenever + (nth-piece-name $N $P) + (assert-piece-type-index $P $N)))) +; + + +; +; + +; +; + + + (= + (set-piece-type-count) + ( (abolish (/ piece-type-count 1)) + (abolish (/ total-piece-count 1)) + (current-game-piece-count $Count) + (add-symbol &self + (piece_type_count $Count)) + (is $Total + (* $Count 2)) + (add-symbol &self + (total_piece_count $Total)))) +; + + + + + (= + (assert-piece-type-index $Piece $Index) + (add-symbol &self + (piece_type_index $Piece $Index))) +; + + + + (= + (assert-piece-index $Piece $Index) + (add-symbol &self + (index_to_piece $Index $Piece))) +; + + + + (= + (print-piece-type-indices) + (or + (, + (piece-type-index $P $I) + (format "~p --> ~p~n" + (:: $I $P)) + (fail)) True)) +; + + + + (= + (print-piece-indices) + ( (format "Piece Index Table:~n" Nil) (or (, (index-to-piece $I $P) (format "~p --> ~p~n" (:: $I $P)) (fail)) True))) +; + + + + + (= + (piece-to-index + (piece $Name $Player) $Key) + ( (piece-player-mult $Player $Mult) + (piece-type-index $Name $Y) + (piece-type-count $Count) + (is $Key + (+ + (* $Count $Mult) $Y)))) +; + + + + (= + (piece_player_mult player 0) True) +; + + (= + (piece_player_mult opponent 1) True) +; + + + + +; +; + +; +; + +; +; + + + + (= + (total_player_count 2) True) +; + + + + (= + (player_index player 1) True) +; + + (= + (player_index opponent 2) True) +; + + + + (= + (player-table $Table) + ( (total-player-count $Count) (functor $Table player-table $Count))) +; + + + + (= + (player-table-entry $Player $Index $Table $Entry) + ( (player-index $Player $Index) (pindex-table-entry $Index $Table $Entry))) +; + + + + (= + (player-indices $Is) + (setof $I + (^ $P + (player-index $P $I)) $Is)) +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (map-player-table $Pred $Table) + (map-player-table $Pred Nil $Table)) +; + + + (= + (map-player-table $Pred $Args $Table) + ( (player-table $Table) + (player-indices $Indices) + (map-for-players $Indices $Pred $Args $Table))) +; + + + + (= + (map_for_players () $_ $_ $_) True) +; + + (= + (map-for-players + (Cons $P $Ps) $Pred $Args $Table) + ( (player-table-entry $Player $P $Table $Entry) + (append + (Cons $Pred + (Cons $Player + (Cons $P $Args))) + (:: $Entry) $GoalList) + (=.. $Goal $GoalList) + (call $Goal) + (map-for-players $Ps $Pred $Args $Table))) +; + + + + + +; +; + +; +; + +; +; + + + + (= + (maps-player-table $Pred $Table1 $Table2) + (maps-player-table $Pred Nil $Table1 $Table2)) +; + + + (= + (maps-player-table $Pred $Args $Table1 $Table2) + ( (player-table $Table1) + (player-table $Table2) + (player-indices $Indices) + (maps-for-players $Indices $Pred $Args $Table1 $Table2))) +; + + + + (= + (maps_for_players () $_ $_ $_ $_) True) +; + + (= + (maps-for-players + (Cons $P $Ps) $Pred $Args $Table1 $Table2) + ( (player-table-entry $Player $P $Table1 $Entry1) + (player-table-entry $Player $P $Table2 $Entry2) + (append + (Cons $Pred + (Cons $Player + (Cons $P $Args))) + (:: $Entry1 $Entry2) $GoalList) + (=.. $Goal $GoalList) + (call $Goal) + (maps-for-players $Ps $Pred $Args $Table1 $Table2))) +; + + + +; +; + +; +; + +; +; + + + + (= + (assert-prom-square-indices) + ( (abolish (/ prom-square-indices 2)) + (assert-prom-square-indices player) + (assert-prom-square-indices opponent))) +; + + + (= + (assert-prom-square-indices $Player) + ( (find-prom-square-indices $Player $SqIs) + (add-symbol &self + (prom_square_indices $Player $SqIs)) + (assert-player-prom-sqs $Player $SqIs))) +; + + + + (= + (assert-player-prom-sqs player $SqIs) + ( (abolish (/ player-prom-sq 1)) (whenever (member $Sq $SqIs) (add-symbol &self (player_prom_sq $Sq))))) +; + + (= + (assert-player-prom-sqs opponent $SqIs) + ( (abolish (/ opponent-prom-sq 1)) (whenever (member $Sq $SqIs) (add-symbol &self (opponent_prom_sq $Sq))))) +; + + + + (= + (player_prom_pred player $Sq + (player_prom_sq $Sq)) True) +; + + (= + (player_prom_pred opponent $Sq + (opponent_prom_sq $Sq)) True) +; + + + + + (= + (find-prom-square-indices $Player $SqIs) + (prom-sqs $Player $_ $SqIs)) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (player-promotion-square $Player $PlI $Sq $SqI) + ( (player-index $Player $PlI) + (square-index $Sq $SqI) + (prom-square-for-player $Player $SqI))) +; + + + (= + (player-promotion-square $Player $Sq) + (player-promotion-square $Player $PlI $Sq $SqI)) +; + + + + (= + (prom-square-for-player player $Sq) + (player-prom-sq $Sq)) +; + + (= + (prom-square-for-player opponent $Sq) + (opponent-prom-sq $Sq)) +; + + + + (= + (in-promote-region $Sq $Player) + (player-promotion-square $Player $Sq)) +; + + + +; +; + + + (= + (prom-sqs $Player $Sqs $SqIs) + ( (setof + (- $Sq $SqI) + (prom-sq $Player $Sq $SqI) $Pairs) (pair-list $Sqs $SqIs $Pairs))) +; + + + + + (= + (prom-sq $Player $Sq $SqI) + ( (square-index $Sq $SqI) (prom-sq $Player $Sq))) +; + + + (= + (prom-sq $Player $Sq) + ( (current-game-for-player $Player $Game) + (game-promote-rank $Game $Rank) + (invert $Sq $Player $Sq1) + (square $Sq1 $X $Y) + (>= $Y $Rank))) +; + + + + + +; + diff --git a/metagame/learning/tourney.metta b/metagame/learning/tourney.metta new file mode 100644 index 0000000..a630aa5 --- /dev/null +++ b/metagame/learning/tourney.metta @@ -0,0 +1,957 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (hosttime-randomize) + ( (hosttime-random-count-mod $X) (dotimes $X (not (, (random $_) (fail)))))) +; + + + + (= + (hosttime-random-count $Count) + ( (realtime-seconds $S) + (shell + (:: 'echo %%') $Process) + (is $Sum + (+ $S $Process)) + (random 1 $Sum $Count))) +; + + + + (= + (hosttime-random-count-mod $X) + ( (hosttime-random-count $Count) (is $X (mod $Count 200)))) +; + + + + + + + + + (= + (do-tourney $Name $File) + ( (tourney-setting $Name $Set) (tourney-to-file $File $Set))) +; + + + +; +; + +; +; + + + (= + (tourney-to-file $File $GameMatches) + ( (hosttime-randomize) + (with-output-file $File append + (tourney $GameMatches $LogFile)) + (format "Tourney Done!~n" Nil))) +; + + +; +; + + + (= + (tourney Nil $_) + ( (format "Tourney done!~n" Nil) + (current-output $O) + (flush-output $O))) +; + + (= + (tourney + (Cons + (- $Game $Matches) $Rest) $File) + ( (game-matches $Game $Matches $File) (tourney $Rest $File))) +; + + + + (= + (game-matches $Game $Matches $File) + ( (setup-game $Game) (play-matches $Matches))) +; + + + + (= + (setup-game $Game) + ( (load-game $Game) + (evalfile-top static) + (build-tables))) +; + + + + + + (= + (play_matches ()) True) +; + + (= + (play-matches (Cons $M $Matches)) + ( (play-match $M) (play-matches $Matches))) +; + + + + + (= + (play-match (match $White $Black $Number)) + ( (load-player player $White) + (load-player opponent $Black) + (dotimes $Number + (contest $White $Black)))) +; + + + +; +; + + + (= + (load-player $Role $Name) + ( (player-setting $Name $Search $Params) + (set-role-file $Role $Params) + (player-color $Role $Color) + (player-top $Color $Search))) +; + + + + (= + (contest $White $Black) + ( (format "<~p> vs. <~p>~n" + (:: $White $Black)) + (record-seed) + (write-old-seed %%) + (start) + (process-contest-outcome $White $Black))) +; + + + + (= + (process-contest-outcome $White $Black) + ( (player-current-game $G) + (game-name $G $GameName) + (det-if-then-else + (recorded-game-outcome $Role) + (, + (process-contest-outcome $Role $White $Black $Outcome) + (format "Outcome of <~p> -- <~p> vs. <~p>: <~p>~n" + (:: $GameName $White $Black $Outcome))) + (format "Outcome of <~p> -- <~p> vs. <~p>: <~p>~n" + (:: $GameName $White $Black NOTHING))))) +; + + + (= + (process_contest_outcome player $White $Black $White) True) +; + + (= + (process_contest_outcome opponent $White $Black $Black) True) +; + + (= + (process_contest_outcome draw $_ $_ draw) True) +; + + + + + + + + (= + (tourney-test) + ( (tourney-setting test $Set) (tourney $Set))) +; + + + + + (= + (tourney_details g1 game1 thesis) True) +; + + (= + (tourney_details g2 game2 thesis) True) +; + + (= + (tourney_details g3 game3 thesis) True) +; + + (= + (tourney_details g4 game4 thesis) True) +; + + (= + (tourney_details g5 game5 thesis) True) +; + + + (= + (tourney_details g123 game1 23) True) +; + + (= + (tourney_details g124 game1 24) True) +; + + (= + (tourney_details g134 game1 34) True) +; + + + + (= + (tourney_details g101 game1 1) True) +; + + (= + (tourney_details g102 game1 2) True) +; + + (= + (tourney_details g103 game1 3) True) +; + + (= + (tourney_details g104 game1 4) True) +; + + + (= + (tourney_details g201 game2 1) True) +; + + (= + (tourney_details g202 game2 2) True) +; + + (= + (tourney_details g203 game2 3) True) +; + + (= + (tourney_details g204 game2 4) True) +; + + + (= + (tourney_details g301 game3 1) True) +; + + (= + (tourney_details g302 game3 2) True) +; + + (= + (tourney_details g303 game3 3) True) +; + + (= + (tourney_details g304 game3 4) True) +; + + + (= + (tourney_details g401 game4 1) True) +; + + (= + (tourney_details g402 game4 2) True) +; + + (= + (tourney_details g403 game4 3) True) +; + + (= + (tourney_details g404 game4 4) True) +; + + + + (= + (tourney_details g501 game5 1) True) +; + + (= + (tourney_details g502 game5 2) True) +; + + (= + (tourney_details g503 game5 3) True) +; + + (= + (tourney_details g504 game5 4) True) +; + + + + + (= + (tourney_details g423 game4 23) True) +; + + (= + (tourney_details g424 game4 24) True) +; + + (= + (tourney_details g434 game4 34) True) +; + + + + +; +; + +; +; + + (= + (tourney_details g1r0 game1 r0) True) +; + + (= + (tourney_details g1r1 game1 r1) True) +; + + (= + (tourney_details g1r2 game1 r2) True) +; + + (= + (tourney_details g1r3 game1 r3) True) +; + + (= + (tourney_details g1r4 game1 r4) True) +; + + + (= + (tourney_details g2r0 game2 r0) True) +; + + (= + (tourney_details g2r1 game2 r1) True) +; + + (= + (tourney_details g2r2 game2 r2) True) +; + + (= + (tourney_details g2r3 game2 r3) True) +; + + (= + (tourney_details g2r4 game2 r4) True) +; + + + (= + (tourney_details g3r0 game3 r0) True) +; + + (= + (tourney_details g3r1 game3 r1) True) +; + + (= + (tourney_details g3r2 game3 r2) True) +; + + (= + (tourney_details g3r3 game3 r3) True) +; + + (= + (tourney_details g3r4 game3 r4) True) +; + + + (= + (tourney_details g4r0 game4 r0) True) +; + + (= + (tourney_details g4r1 game4 r1) True) +; + + (= + (tourney_details g4r2 game4 r2) True) +; + + (= + (tourney_details g4r3 game4 r3) True) +; + + (= + (tourney_details g4r4 game4 r4) True) +; + + + (= + (tourney_details g5r0 game5 r0) True) +; + + (= + (tourney_details g5r1 game5 r1) True) +; + + (= + (tourney_details g5r2 game5 r2) True) +; + + (= + (tourney_details g5r3 game5 r3) True) +; + + (= + (tourney_details g5r4 game5 r4) True) +; + + + + (= + (tourney_details g1r0a game1 r0a) True) +; + + + (= + (tourney_details g1r1a game1 r1a) True) +; + + + (= + (tourney_details g1r2a game1 r2a) True) +; + + + (= + (tourney_details g1r3a game1 r3a) True) +; + + + (= + (tourney_details g1r4a game1 r4a) True) +; + + + (= + (tourney_details g2r02 game1 r02) True) +; + + + (= + (tourney_details g3r4a game3 r4a) True) +; + + + (= + (tourney_details g5a game5 thesis2) True) +; + + + + + + (= + (matches_for_setting r02 + ( (match r 0 2))) True) +; + + + + (= + (matches_for_setting r0a + ( (match r 0 10))) True) +; + + + (= + (matches_for_setting r1a + ( (match r 1 10))) True) +; + + + (= + (matches_for_setting 1 + ( (match 0 1 10))) True) +; + + (= + (matches_for_setting 2 + ( (match 0 2 10))) True) +; + + (= + (matches_for_setting 3 + ( (match 0 3 10))) True) +; + + (= + (matches_for_setting 4 + ( (match 0 4 10))) True) +; + + + + (= + (matches_for_setting r2a + ( (match r 2 10))) True) +; + + + + (= + (matches_for_setting r3a + ( (match r 3 10))) True) +; + + + + (= + (matches_for_setting r4a + ( (match r 4 10))) True) +; + + + + (= + (matches_for_setting thesis + ( (match 0 1 1) + (match 1 0 1) + (match 0 2 1) + (match 2 0 1) + (match 0 3 1) + (match 3 0 1) + (match 0 4 1) + (match 4 0 1) + (match 1 2 1) + (match 2 1 1) + (match 1 3 1) + (match 3 1 1) + (match 1 4 1) + (match 4 1 1) + (match 2 3 1) + (match 3 2 1) + (match 2 4 1) + (match 4 2 1) + (match 3 4 1) + (match 4 3 1) + (match 0 0 2))) True) +; + + + + (= + (matches_for_setting thesis2 + ( (match 4 3 1) + (match 3 4 1) + (match 4 2 1) + (match 2 4 1) + (match 2 3 1) + (match 3 2 1) + (match 4 1 1) + (match 1 4 1))) True) +; + + + + (= + (matches_for_setting 23 + ( (match 2 3 2) (match 3 2 2))) True) +; + + + (= + (matches_for_setting 24 + ( (match 2 4 2) (match 4 2 2))) True) +; + + + + (= + (matches_for_setting 34 + ( (match 3 4 2) (match 4 3 2))) True) +; + + + + (= + (matches_for_setting r0 + ( (match 0 r 10) (match r 0 10))) True) +; + + + (= + (matches_for_setting r1 + ( (match 1 r 10) (match r 1 10))) True) +; + + + (= + (matches_for_setting r2 + ( (match 2 r 10) (match r 2 10))) True) +; + + + (= + (matches_for_setting r3 + ( (match 3 r 10) (match r 3 10))) True) +; + + + (= + (matches_for_setting r4 + ( (match 4 r 10) (match r 4 10))) True) +; + + + + + + (= + (tourney-setting $Tourney + (:: (- $Game $Matches))) + ( (tourney-details $Tourney $Game $MatchName) + (set-det) + (matches-for-setting $MatchName $Matches))) +; + + + (= + (tourney_setting test + ( (- checkers + ( (match 1 0 1) (match 0 0 1))) (- turncoat_chess ((match 0 0 1))))) True) +; + + + + +; +; + + + (= + (player_setting r random ()) True) +; + + + +; +; + + (= + (player_setting 0 random_aggressive ()) True) +; + + + +; +; + + (= + (player_setting 1 iterate + ( (- gmovmob 1) + (- gcapmob 1) + (- pthreat 1) + (- gthreat 0) + (- initprom 1) + (- possess 1) + (- arrive_distance 100) + (- promote_distance 1) + (- eventual_mobility 1) + (- static 1) + (- vital 1) + (- max_static_mob 1) + (- max_eventual_mob 1) + (- eradicate 1) + (- victims 1) + (- immunity 1) + (- giveaway 1) + (- eradicate 1) + (- stalemate 1) + (- arrive 1))) True) +; + + + + +; +; + + (= + (player_setting 2 iterate + ( (- gmovmob 0) + (- gcapmob 0) + (- pthreat 0) + (- gthreat 0) + (- lthreat 0) + (- vital 0) + (- initprom 1) + (- possess 1) + (- arrive_distance 100) + (- promote_distance 1) + (- eventual_mobility 1) + (- static 1) + (- max_static_mob 1) + (- max_eventual_mob 1) + (- eradicate 1) + (- victims 1) + (- immunity 1) + (- giveaway 1) + (- eradicate 1) + (- stalemate 1) + (- arrive 1))) True) +; + + + + +; +; + + (= + (player_setting 3 iterate + ( (- gmovmob 0) + (- gcapmob 0) + (- pthreat 0) + (- gthreat 0) + (- lthreat 0) + (- vital 0) + (- initprom 0) + (- possess 0) + (- arrive_distance 0) + (- promote_distance 0) + (- eventual_mobility 1) + (- static 1) + (- max_static_mob 1) + (- max_eventual_mob 1) + (- eradicate 1) + (- victims 1) + (- immunity 1) + (- giveaway 1) + (- eradicate 1) + (- stalemate 1) + (- arrive 1))) True) +; + + + + +; +; + + (= + (player_setting 4 iterate + ( (- gmovmob 0) + (- gcapmob 0) + (- pthreat 0) + (- gthreat 0) + (- lthreat 0) + (- vital 0) + (- initprom 0) + (- possess 0) + (- arrive_distance 100) + (- promote_distance 1) + (- eventual_mobility 0) + (- static 0) + (- max_static_mob 1) + (- max_eventual_mob 1) + (- eradicate 1) + (- victims 1) + (- immunity 1) + (- giveaway 1) + (- eradicate 1) + (- stalemate 1) + (- arrive 1))) True) +; + + + + +; +; + + (= + (player_setting 5 iterate + ( (- gmovmob 1) + (- gcapmob 0) + (- pthreat 0) + (- gthreat 0) + (- lthreat 0) + (- vital 0) + (- initprom 0) + (- possess 0) + (- arrive_distance 0) + (- promote_distance 0) + (- eventual_mobility 0) + (- static 0) + (- max_static_mob 1) + (- max_eventual_mob 1) + (- eradicate 1) + (- victims 1) + (- immunity 1) + (- giveaway 1) + (- eradicate 1) + (- stalemate 1) + (- arrive 1))) True) +; + + + + + +; +; + + (= + (player_setting 6 iterate + ( (- gmovmob 1) + (- gcapmob 1) + (- pthreat 0) + (- gthreat 1) + (- initprom 1) + (- possess 1) + (- arrive_distance 100) + (- promote_distance 1) + (- eventual_mobility 1) + (- static 1) + (- vital 1) + (- max_static_mob 1) + (- max_eventual_mob 1) + (- eradicate 1) + (- victims 1) + (- immunity 1) + (- giveaway 1) + (- eradicate 1) + (- stalemate 1) + (- arrive 1))) True) +; + + + +; +; + + (= + (player_setting 7 iterate + ( (- gmovmob 1) + (- gcapmob 1) + (- pthreat 0) + (- gthreat 0) + (- lthreat 1) + (- initprom 1) + (- possess 1) + (- arrive_distance 100) + (- promote_distance 1) + (- eventual_mobility 1) + (- static 1) + (- vital 1) + (- max_static_mob 1) + (- max_eventual_mob 1) + (- eradicate 1) + (- victims 1) + (- immunity 1) + (- giveaway 1) + (- eradicate 1) + (- stalemate 1) + (- arrive 1))) True) +; + + + +; +; + +; +; + +; +; + + + + (= + (playernum-top $Color $Name) + ( (player-color $Role $Color) (load-player $Role $Name))) +; + + + + (= + (playernums-top $Player $Opp) + ( (playernum-top white $Player) (playernum-top black $Opp))) +; + + diff --git a/metagame/misc/args.metta b/metagame/misc/args.metta new file mode 100644 index 0000000..5555fb9 --- /dev/null +++ b/metagame/misc/args.metta @@ -0,0 +1,236 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + + +; +; + +; +; + +; +; + + + (= + (same-functor $T1 $T2) + (det-if-then-else + (nonvar $T1) + (, + (functor $T1 $F $A) + (functor $T2 $F $A)) + (det-if-then-else + (nonvar $T2) + (, + (functor $T2 $F $A) + (functor $T1 $F $A)) + (, + (format "Error in same_functor: Both terms variables!~n" Nil) + (fail))))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + (= + (same-functor $T1 $T2 $A) + (det-if-then-else + (nonvar $T1) + (, + (functor $T1 $F $A) + (functor $T2 $F $A)) + (det-if-then-else + (nonvar $T2) + (, + (functor $T2 $F $A) + (functor $T1 $F $A)) + (, + (format "Error in same_functor: Both terms variables!~n" Nil) + (fail))))) +; + + + +; +; + +; +; + + + (= + (same-arg $N $T1 $T2) + ( (arg $N $T1 $Item) (arg $N $T2 $Item))) +; + + +; +; + +; +; + + (= + (same-arg $N $T1 $T2 $Item) + ( (arg $N $T1 $Item) (arg $N $T2 $Item))) +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (corresponding-arg $N $T1 $Item1 $T2 $Item2) + ( (arg $N $T1 $Item1) (arg $N $T2 $Item2))) +; + + + +; +; + + +; +; + +; +; + + + + (= + (genarg $N $Term $Arg) + ( (integer $N) + (nonvar $Term) + (set-det) + (arg $N $Term $Arg))) +; + + (= + (genarg $N $Term $Arg) + ( (var $N) + (nonvar $Term) + (set-det) + (functor $Term $_ $Arity) + (genarg $Arity $Term $Arg $N))) +; + + + (= + (genarg 1 $Term $Arg 1) + ( (set-det) (arg 1 $Term $Arg))) +; + + (= + (genarg $N $Term $Arg $N) + (arg $N $Term $Arg)) +; + + (= + (genarg $K $Term $Arg $N) + ( (> $K 1) + (is $J + (- $K 1)) + (genarg $J $Term $Arg $N))) +; + + + +; +; + +; +; + +; +; + +; +; + + + + (= + (path-arg $Path $Term $SubTerm) + ( (var $Term) + (set-det) + (det-if-then-else + (== $Path Nil) + (= $SubTerm $Term) + (det-if-then-else + (not (= $Path (Cons $_ $_))) fail + (, + (format user-error '~N! Instantiation fault in argument ~w of ~q/~w~n! Goal: ~p~n' + (:: 2 path-arg 3 + (path-arg $Path $Term $SubTerm))) + (fail)))))) +; + + (= + (path_arg () $Term $Term) True) +; + + (= + (path-arg + (Cons $Head $Tail) $Term $SubTerm) + (det-if-then-else + (integer $Head) + (, + (arg $Head $Term $Arg) + (path-arg $Tail $Arg $SubTerm)) + (det-if-then-else + (var $Head) + (, + (functor $Term $_ $Arity) + (genarg $Arity $Term $Arg $Head) + (path-arg $Tail $Arg $SubTerm)) + (, + (format user-error '~N! Type failure in argument ~w of ~q/~w~n! Goal: ~p~n' + (:: 1 path-arg 3 + (path-arg + (Cons $Head $Tail) $Term $SubTerm))) + (fail))))) +; + + + diff --git a/metagame/misc/aux.metta b/metagame/misc/aux.metta new file mode 100644 index 0000000..73e171d --- /dev/null +++ b/metagame/misc/aux.metta @@ -0,0 +1,1660 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + + + + + !(my-use-module (library lists)) +; + + !(use-module (library ordsets)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + + + + (= + (mnl 1) + (nl)) +; + + (= + (mnl $N) + ( (> $N 1) + (nl) + (is $N1 + (- $N 1)) + (mnl $N1))) +; + + + +; +; + +; +; + + + + (= + (ppl $L) + (ppl $L 3)) +; + + (= + (ppl () $Ind) True) +; + + (= + (ppl + (Cons + (Cons $H $T) $L) $Ind) + ( (is $Ind1 + (+ $Ind 3)) + (ppl + (Cons $H $T) $Ind1) + (ppl $L $Ind) + (set-det))) +; + + (= + (ppl + (Cons $H $L) $Ind) + ( (space $Ind) + (print $H) + (nl) + (ppl $L $Ind) + (set-det))) +; + + (= + (ppl $A $Ind) + ( (space $Ind) + (print $A) + (nl))) +; + + + +; +; + +; +; + + + + (= + (pwl $L) + (pwl $L 3)) +; + + (= + (pwl () $Ind) True) +; + + (= + (pwl + (Cons + (Cons $H $T) $L) $Ind) + ( (is $Ind1 + (+ $Ind 3)) + (pwl + (Cons $H $T) $Ind1) + (pwl $L $Ind) + (set-det))) +; + + (= + (pwl + (Cons $H $L) $Ind) + ( (space $Ind) + (write $H) + (nl) + (pwl $L $Ind) + (set-det))) +; + + (= + (pwl $A $Ind) + ( (space $Ind) + (write $A) + (nl))) +; + + + + +; +; + +; +; + + + + (= + (space) + (write ' ')) +; + + (= + (space 0) True) +; + + (= + (space 1) + (space)) +; + + (= + (space $N) + ( (> $N 1) + (space) + (is $N1 + (- $N 1)) + (space $N1))) +; + + +; +; + + + + (= + (cons $E () + ($E)) True) +; + + (= + (cons $E + (Cons $H $T) + (Cons $E + (Cons $H $T))) True) +; + + +; +; + + + + (= + (snoc $E () + ($E)) True) +; + + (= + (snoc $E $L0 $L1) + ( (reverse $L0 $Lr) + (cons $E $Lr $Lr1) + (reverse $Lr1 $L1))) +; + + +; +; + + + + (= + (f_cons () $L $L) True) +; + + (= + (f_cons $E + (Cons $H $T) + (Cons $E + (Cons $H $T))) True) +; + + + + + +; +; + + + + (= + (rev_append () $L $L) True) +; + + (= + (rev-append + (Cons $H $T) $L $R) + (rev-append $T + (Cons $H $L) $R)) +; + + + +; +; + +; +; + + + + (= + (extract $Elt + (Cons $Elt $Tail) $Tail) True) +; + + (= + (extract $Elt + (Cons $Head $Tail) + (Cons $Head $List)) + (extract $Elt $Tail $List)) +; + + +; +; + +; +; + + + + (= + (cull $Pattern () () ()) True) +; + + (= + (cull $Pattern + (Cons $Pattern $T0) + (Cons $Pattern $T1) $R) + (cull $Pattern $T0 $T1 $R)) +; + + (= + (cull $Pattern + (Cons $H $T0) $C + (Cons $H $T1)) + (cull $Pattern $T0 $C $T1)) +; + + +; +; + +; +; + + + + (= + (cull_funct $Funct () () ()) True) +; + + (= + (cull-funct $Funct + (Cons $H0 $T0) + (Cons $H0 $T1) $R) + ( (functor $H0 $Funct $_) (cull-funct $Funct $T0 $T1 $R))) +; + + (= + (cull-funct $Funct + (Cons $H0 $T0) $C + (Cons $H0 $T1)) + (cull-funct $Funct $T0 $C $T1)) +; + + +; +; + +; +; + +; +; + + + + (= + (split_list $Elt + (Cons $Elt $Tail) () $Tail) True) +; + + (= + (split-list $Elt + (Cons $Head $Tail0) + (Cons $Head $Tail1) $Tail) + (split-list $Elt $Tail0 $Tail1 $Tail)) +; + + +; +; + +; +; + + + + (= + (split-list-funct $Funct + (Cons $Elt $Tail) Nil $Tail) + (functor $Elt $Funct $_)) +; + + (= + (split-list-funct $Funct + (Cons $H0 $T0) + (Cons $H0 $T1) $T) + (split-list-funct $Funct $T0 $T1 $T)) +; + + + +; +; + + + + (= + (get_nth 1 + (Cons $Head $_) $Head) True) +; + + (= + (get-nth $P + (Cons $_ $Tail) $Elt) + ( (get-nth $P1 $Tail $Elt) (is $P (+ $P1 1)))) +; + + + +; +; + + + + (= + (nth-letter $N $Letter) + ( (nth-letter-after $N a $Letter) + (> $N 0) + (=< $N 26))) +; + + +; +; + + + + (= + (nth-letter-after $N $Letter0 $Letter) + ( (atom $Letter) + (set-det) + (name $Letter0 + (:: $A)) + (name $Letter + (:: $L)) + (is $N + (+ + (- $L $A) 1)))) +; + + (= + (nth-letter-after $N $Letter0 $Letter) + ( (integer $N) + (name $Letter0 + (:: $A)) + (is $L + (- + (+ $N $A) 1)) + (name $Letter + (:: $L)))) +; + + + +; +; + + + + (= + (percolate $M $L1 $L2) + (perc2 $M $L1 Nil $L2)) +; + + + + (= + (perc2 $M + (Cons $M $Lt) $Lp + (Cons $M $L)) + ( (reverse $Lp $Lpr) (append $Lpr $Lt $L))) +; + + (= + (perc2 $M + (Cons $Lh $Lt) $Lp $L) + (perc2 $M $Lt + (Cons $Lh $Lp) $L)) +; + + +; +; + +; +; + + + + (= + (mesh () $L $L) True) +; + + (= + (mesh $L () $L) True) +; + + (= + (mesh + (Cons $A $As) + (Cons $B $Bs) + (Cons $A $Rest)) + (mesh $As + (Cons $B $Bs) $Rest)) +; + + (= + (mesh + (Cons $A $As) + (Cons $B $Bs) + (Cons $B $Rest)) + (mesh + (Cons $A $As) $Bs $Rest)) +; + + + +; +; + +; +; + +; +; + + + (= + (flatten $Tree $List) + (flatten $Tree $List Nil)) +; + + + + (= + (--> + (flatten ()) !) True) +; + + (= + (--> + (flatten + (Cons $Head $Tail)) + (, ! + (, + (flatten $Head) + (flatten $Tail)))) True) +; + + (= + (--> + (flatten $Other) + ($Other)) True) +; + + + + +; +; + + + + (= + (gensym $Prefix $V) + ( (var $V) + (atomic $Prefix) + (lastsuffix $Prefix $M) + (is $N + (+ $M 1)) + (add-symbol &self + (flag + (gensym $Prefix) $N)) + (concat $Prefix $N $V) + (set-det))) +; + + +; +; + + + + (= + (cgensym $Prefix $V) + ( (var $V) + (set-det) + (gensym $Prefix $V))) +; + + (= + (cgensym $_ $_) True) +; + + + + + (= + (lastsuffix $Prefix $M) + ( (remove-symbol &self + (flag + (gensym $Prefix) $M)) (set-det))) +; + + (= + (lastsuffix $Prefix 0) True) +; + + + +; +; + + + + (= + (reset-gensym) + (remove-all-symbols &self + (flag + (gensym $Prefix) $M))) +; + + + (= + (reset-gensym $Prefix) + (remove-all-symbols &self + (flag + (gensym $Prefix) $M))) +; + + + +; +; + +; +; + +; +; + +; +; + + + + (= + (bi-name $Atom $List) + (when + (or + (ground $Atom) + (ground $List)) + (name $Atom $List))) +; + + + +; +; + + + + (= + (concat $N1 $N2 $N3) + ( (name $N1 $Ls1) + (name $N2 $Ls2) + (append $Ls1 $Ls2 $Ls3) + (name $N3 $Ls3))) +; + + + + (= + (concat-list + (:: $A) $A) + (set-det)) +; + + (= + (concat-list + (Cons $A $Bs) $C) + ( (concat-list $Bs $Bconc) (concat $A $Bconc $C))) +; + + + + + (= + (append-list + (:: $A) $A) + (set-det)) +; + + (= + (append-list + (Cons $A $Bs) $C) + ( (append-list $Bs $Bconc) (append $A $Bconc $C))) +; + + + +; +; + +; +; + +; +; + + + (= + (bi-concat $N1 $N2 $N3) + (det-if-then-else + (atom $N3) + (, + (name $N3 $L3) + (append $L1 $L2 $L3) + (name $N2 $L2) + (name $N1 $L1)) + (det-if-then-else + (atom $N1) + (concat $N1 $N2 $N3) + (, + (format "Error, uninstantiated args in bi_concat~n" Nil) + (fail))))) +; + + + + (= + (bi-concat-list + (:: $A) $A) + (set-det)) +; + + (= + (bi-concat-list + (Cons $A $Bs) $C) + ( (bi-concat-list $Bs $Bconc) (bi-concat $A $Bconc $C))) +; + + + +; +; + + + + (= + (ynp y y $Goal) + (set-det)) +; + + (= + (ynp yes y $Goal) + (set-det)) +; + + (= + (ynp n n $Goal) + (set-det)) +; + + (= + (ynp no n $Goal) + (set-det)) +; + + (= + (ynp $Resp $RespVal $Goal) + ( (write 'Please respond with y or n.') + (nl) + (call $Goal))) +; + + + +; +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (count-bagof $A $B $C) + (det-if-then-else + (bagof $A $B $C1) + (length $C1 $C) + (= $C 0))) +; + + + + (= + (count-setof $A $B $C) + (det-if-then-else + (setof $A $B $C1) + (length $C1 $C) + (= $C 0))) +; + + + + (= + (count-findall $A $B $C) + ( (findall $A $B $C1) (length $C1 $C))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (maplist $_ () ()) True) +; + + (= + (maplist $P + (Cons $X $L) + (Cons $Y $M)) + ( (=.. $Q + (:: $P $X $Y)) + (call $Q) + (maplist $P $L $M))) +; + + + + +; +; + + + + (= + (whenever $Generator $Goal) + (or + (, + (call $Generator) + (call $Goal) + (fail)) True)) +; + + + + + + (= + (verify $Goal) + (not (not $Goal))) +; + + + + + (= + (remove-test-duplicates $List $Test $Clean) + (remove-test-duplicates $List $Test Nil $Clean)) +; + + + (= + (remove_test_duplicates () $_ $_ ()) True) +; + + (= + (remove-test-duplicates + (Cons $H $T) $Test_Call $Seen $Clean) + ( (= $Test_Call + (test $Test $Pattern1 $Pattern2)) + (member $Pattern2 $Seen) + (= $H $Pattern1) + (call $Test) + (set-det) + (remove-test-duplicates $T $Test_Call $Seen $Clean))) +; + + (= + (remove-test-duplicates + (Cons $H $T) $Test_Call $Seen + (Cons $H $Clean)) + (remove-test-duplicates $T $Test_Call + (Cons $H $Seen) $Clean)) +; + + +; +; + + + +; +; + + + + (= + (average $List $Avg) + ( (length $List $N) (det-if-then-else (> $N 0) (, (sum-list $List $Sum) (is $Avg (/ $Sum $N))) (= $Avg 0)))) +; + + +; +; + + + + (= + (max + (Cons $A $Rest) $Val) + (max1 $Rest $A $Val)) +; + + + + (= + (max1 () $A $A) True) +; + + (= + (max1 + (Cons $H $T) $Old $Val) + ( (max $H $Old $New) (max1 $T $New $Val))) +; + + +; +; + + + (= + (max $A $B $A) + ( (> $A $B) (set-det))) +; + + (= + (max $A $B $B) True) +; + + + +; +; + + + (= + (min + (Cons $A $Rest) $Val) + (min1 $Rest $A $Val)) +; + + + + (= + (min1 () $A $A) True) +; + + (= + (min1 + (Cons $H $T) $Old $Val) + ( (min $H $Old $New) (min1 $T $New $Val))) +; + + +; +; + + + (= + (min $A $B $A) + ( (< $A $B) (set-det))) +; + + (= + (min $A $B $B) True) +; + + + +; +; + + + + (= + (writeln $Arg) + ( (write $Arg) (nl))) +; + + + +; +; + + + (= + (reduce-list + (Cons $A $B) $R) + ( (set-det) + (reduce-list $A $A1) + (reduce-list $B $B1) + (append $A1 $B1 $R))) +; + + (= + (reduce-list Nil Nil) + (set-det)) +; + + (= + (reduce_list $X + ($X)) True) +; + + + +; +; + + + + (= + (increase-term-arity $TermIn $NewArg $TermOut) + ( (functor $TermIn $Func $N) + (is $N1 + (+ $N 1)) + (functor $TermOut $Func $N1) + (arg $N1 $TermOut $NewArg) + (copy-args $N $TermIn $TermOut))) +; + + + + (= + (copy-args 0 $TermIn $TermOut) + (set-det)) +; + + (= + (copy-args $N $TermIn $TermOut) + ( (arg $N $TermIn $Arg) + (arg $N $TermOut $Arg) + (is $N1 + (- $N 1)) + (copy-args $N1 $TermIn $TermOut))) +; + + + +; +; + + + + (= + (portray-clauses $Clauses) + (whenever + (member $C $Clauses) + (portray-clause $C))) +; + + +; +; + + + + (= + (dotimes 0 $_) + (set-det)) +; + + (= + (dotimes $N $Call) + ($Call + (is $N1 + (- $N 1)) + (dotimes $N1 $Call))) +; + + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (stable-sort $In $Out) + ( (pair-list $In $_ $Keyed) + (keysort $Keyed $SortKeyed) + (pair-list $Out $_ $SortKeyed))) +; + + +; +; + +; +; + +; +; + + + (= + (pair_list () () ()) True) +; + + (= + (pair-list + (Cons $A $As) + (Cons $B $Bs) + (Cons + (- $A $B) $Rest)) + (pair-list $As $Bs $Rest)) +; + + + + (= + (rev_pair_list () ()) True) +; + + (= + (rev-pair-list + (Cons + (- $A $AV) $RestA) + (Cons + (- $AV $A) $RestB)) + (rev-pair-list $RestA $RestB)) +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (contains $Symbol $Text) + (con $Text $Symbol)) +; + + + + (= + (con $_ + (, $_ ())) True) +; + + (= + (con + (Cons $C $Rtext) $SymbInfo) + ( (new $C $SymbInfo $SymbInfoNew) (con $Rtext $SymbInfoNew))) +; + + + + (= + (new $C + (, $Prefix $C $RestPostfix) + (, $PrefixNew $RestPostfix)) + (append $Prefix + (:: $C) $PrefixNew)) +; + + (= + (new $C + (, $Prefix $D $RestPostfix) + (, $PrefixNew $PostfixNew)) + ( (\== $C $D) + (append $Prefix + (:: $C) $H) + (append $PrefixNew $Rest $Prefix) + (append $_ $PrefixNew $H) + (append $Rest + (Cons $D $RestPostfix) $PostfixNew))) +; + + + +; +; + +; +; + +; +; + +; +; + + + + (= + (found $Symbol) + (found1 $Symbol)) +; + + + + (= + (found1 + (, $_ ())) True) +; + + (= + (found1 $SymbInfo) + ( (get0 $C) + (new $C $SymbInfo $SymbInfoNew) + (found1 $SymbInfoNew))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (between $Lower $Upper $Point) + ( (integer $Lower) + (integer $Upper) + (or + (, + (integer $Point) + (set-det) + (=< $Lower $Point) + (=< $Point $Upper)) + (, + (var $Point) + (set-det) + (=< $Lower $Upper) + (between1 $Lower $Upper $Point))))) +; + + +; +; + +; +; + +; +; + +; +; + + + + (= + (between1 $L $L $L) + (set-det)) +; + + (= + (between1 $L $_ $L) True) +; + ; +; + + (= + (between1 $L $U $N) + ( (is $M + (+ $L 1)) (between1 $M $U $N))) +; + ; +; + +; +; + + + + + (= + (numlist $Min $Max Nil) + ( (> $Min $Max) (set-det))) +; + + (= + (numlist $Min $Max + (Cons $Min $Rest)) + ( (is $Min1 + (+ $Min 1)) (numlist $Min1 $Max $Rest))) +; + + + + +; +; + +; +; + + + (= + (member1 $A $B) + (det-if-then-else + (var $A) + (member $A $B) + (memberchk $A $B))) +; + + +; +; + +; +; + +; +; + + + + (= + (member1-pair + (- $H $T) $B) + (det-if-then-else + (var $H) + (member + (- $H $T) $B) + (memberchk + (- $H $T) $B))) +; + + + + + (= + (assoc $List $Prop $Val) + (member1-pair + (- $Prop $Val) $List)) +; + + + + (= + (set-assoc $List1 $Param $Val $New) + ( (ensure-list $List1 $List2) + (delete-all-assoc $Param $List2 $List) + (cons + (- $Param $Val) $List $New))) +; + + + + (= + (ensure-list $List1 $List1) + ( (is-list $List1) (set-det))) +; + + (= + (ensure_list $_ ()) True) +; + + + + (= + (delete-all-assoc $P $L $L2) + ( (member + (- $P $V1) $L) + (set-det) + (delete $L + (- $P $V1) $L1) + (delete-all-assoc $P $L1 $L2))) +; + + (= + (delete_all_assoc $_ $L $L) True) +; + + +; +; + +; +; + +; +; + + +; +; + + + (= + (in-region + (:: (- $Choice $Prob)) $_ $Choice) + (set-det)) +; + + (= + (in-region + (Cons + (- $C $P) $Choices) $Prob $C) + ( (< $Prob $P) (set-det))) +; + + (= + (in-region + (Cons + (- $C $P) $Choices) $Prob $Choice) + ( (is $PRest + (- $Prob $P)) (in-region $Choices $PRest $Choice))) +; + + + + diff --git a/metagame/misc/dynamic_load.metta b/metagame/misc/dynamic_load.metta new file mode 100644 index 0000000..5790c8b --- /dev/null +++ b/metagame/misc/dynamic_load.metta @@ -0,0 +1,88 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (dl Nil) + (set-det)) +; + + (= + (dl (Cons $F $Files)) + ( (set-det) + (dl $F) + (dl $Files))) +; + + (= + (dl $Filename) + (dynamic-load $Filename)) +; + + + + (= + (dynamic-load $Filename) + ( (open $Filename read $Stream) + (format "Loading theory file: ~w~n" + (:: $Filename)) + (dynamic-load-stream $Stream) + (format " Finished loading Theory file: ~w~n" + (:: $Filename)) + (close $Stream))) +; + + + + (= + (dynamic-load-stream $Stream) + (det-if-then-else + (, + (read $Stream $Term) + (\== $Term end-of-file)) + (, + (process-term $Term) + (dynamic-load-stream $Stream)) True)) +; + + +; +; + + + (= + (process-term $Term) + (theory-assert $Term)) +; + + + diff --git a/metagame/misc/floyd.metta b/metagame/misc/floyd.metta new file mode 100644 index 0000000..638b8da --- /dev/null +++ b/metagame/misc/floyd.metta @@ -0,0 +1,325 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + + + (= + (s-to-d-graph Nil Nil) + (set-det)) +; + + (= + (s-to-d-graph + (Cons + (- $Vertex $Neibs1) $G) + (Cons + (- $Vertex $Neibs2) $D)) + ( (init-dists $Neibs1 $Neibs2) (s-to-d-graph $G $D))) +; + + + + (= + (init_dists () ()) True) +; + + (= + (init-dists + (Cons $H $T) + (Cons + (- $H 1) $Ts)) + (init-dists $T $Ts)) +; + + + + (= + (d-to-s-graph Nil Nil) + (set-det)) +; + + (= + (d-to-s-graph + (Cons + (- $Vertex $Neibs1) $G) + (Cons + (- $Vertex $Neibs2) $D)) + ( (strip-dists $Neibs1 $Neibs2) (d-to-s-graph $G $D))) +; + + + + (= + (strip_dists () ()) True) +; + + (= + (strip-dists + (Cons + (- $H $_) $T) + (Cons $H $Ts)) + (strip-dists $T $Ts)) +; + + + + + (= + (s-floyd $S_Graph $Closure) + ( (s-to-d-graph $S_Graph $Graph) (floyd $Graph $Closure))) +; + + +; +; + + + (= + (zero-self-d-graph Nil Nil) + (set-det)) +; + + (= + (zero-self-d-graph + (Cons + (- $Vertex $Neibs1) $G) + (Cons + (- $Vertex $Neibs2) $D)) + ( (ord-min-union + (:: (- $Vertex 0)) $Neibs1 $Neibs2) (zero-self-d-graph $G $D))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (floyd $Graph $Closure) + ( (zero-self-d-graph $Graph $Init) (floyd $Init $Init $Closure))) +; + + + (= + (floyd Nil $Closure $Closure) + (set-det)) +; + + (= + (floyd + (Cons + (- $V $_) $G) $E $Closure) + ( (memberchk + (- $V $Y) $E) + (floyd $E $V $Y $NewE) + (floyd $G $NewE $Closure))) +; + + + (= + (floyd + (Cons + (- $X $Neibs) $G) $V $Y + (Cons + (- $X $NewNeibs) $NewG)) + ( (memberchk + (- $V $VDist) $Neibs) + (set-det) + (increment-dists $Y $VDist $YInc) + (ord-min-union $Neibs $YInc $NewNeibs) + (floyd $G $V $Y $NewG))) +; + + (= + (floyd + (Cons + (- $X $Neibs) $G) $V $Y + (Cons + (- $X $Neibs) $NewG)) + ( (set-det) (floyd $G $V $Y $NewG))) +; + + (= + (floyd () $_ $_ ()) True) +; + + + + (= + (increment_dists () $_ ()) True) +; + + (= + (increment-dists + (Cons + (- $H $D) $T) $N + (Cons + (- $H $D1) $T1)) + ( (is $D1 + (+ $D $N)) (increment-dists $T $N $T1))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (ord_min_union () $Set2 $Set2) True) +; + + (= + (ord-min-union + (Cons $Head1 $Tail1) $Set2 $Union) + (ord-min-union-1 $Set2 $Head1 $Tail1 $Union)) +; + + + + (= + (ord_min_union_1 () $Head1 $Tail1 + (Cons $Head1 $Tail1)) True) +; + + (= + (ord-min-union-1 + (Cons $Head2 $Tail2) $Head1 $Tail1 $Union) + ( (weighted-compare $Order $Head1 $Head2) (ord-min-union-1 $Order $Head1 $Tail1 $Head2 $Tail2 $Union))) +; + + + (= + (ord-min-union-1 < $Head1 $Tail1 $Head2 $Tail2 + (Cons $Head1 $Union)) + (ord-min-union-1 $Tail1 $Head2 $Tail2 $Union)) +; + + (= + (ord-min-union-1 > $Head1 $Tail1 $Head2 $Tail2 + (Cons $Head2 $Union)) + (ord-min-union-1 $Tail2 $Head1 $Tail1 $Union)) +; + + (= + (ord-min-union-1 = + (- $Head1 $N1) $Tail1 + (- $Head1 $N2) $Tail2 + (Cons + (- $Head1 $N) $Union)) + ( (min $N1 $N2 $N) (ord-min-union $Tail1 $Tail2 $Union))) +; + + + + (= + (weighted-compare $Order + (- $Head1 $N1) + (- $Head2 $N2)) + (compare $Order $Head1 $Head2)) +; + + + + + + (= + (time-floyd $P $N) + ( (random-graph $P $N $G) + (s-to-d-graph $G $Z) + (runtime (floyd $Z $ZLast)))) +; + + + diff --git a/metagame/misc/menus.metta b/metagame/misc/menus.metta new file mode 100644 index 0000000..9b1a7ec --- /dev/null +++ b/metagame/misc/menus.metta @@ -0,0 +1,216 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + +; +; + + + + !(my-ensure-loaded (library aux)) +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (process-command $String $Suffix $Args) + (det-if-then + (, + (append + (Cons $Command1 $Options) + (:: .) $String) + (concat - $Suffix $Suff) + (concat $Command1 $Suff $Command) + (append + (Cons $Command $Args) $Options $G) + (=.. $Goal $G) + (current-predicate $_ $Goal)) + (det-if-then-else + (call $Goal) True True))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (menu-command $FormatString $FormatArgs $Suffix $Args) + ( (format $FormatString $FormatArgs) (menu-command $Suffix $Args))) +; + + + (= + (menu-command $FormatString $Suffix $Args) + (menu-command $FormatString Nil $Suffix $Args)) +; + + + (= + (menu-command $Suffix $Args) + ( (read-keyboard-tokens $String) (process-command $String $Suffix $Args))) +; + + + + diff --git a/metagame/misc/mygraphs.metta b/metagame/misc/mygraphs.metta new file mode 100644 index 0000000..24e8f37 --- /dev/null +++ b/metagame/misc/mygraphs.metta @@ -0,0 +1,479 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + + + !(public (, (/ p-to-s-graph 2) (/ s-to-p-graph 2) (/ s-to-p-trans 2) (/ p-member 3) (/ s-member 3) (/ p-transpose 2) (/ s-transpose 2) (/ compose 3) (/ top-sort 2) (/ vertices 2) (/ warshall 2))) +; + + + !(mode (, (vertices + -) (p-to-s-graph + -) (p-to-s-vertices + -) (p-to-s-group + + -) (p-to-s-group + + - -) (s-to-p-graph + -) (s-to-p-graph + + - -) (s-to-p-trans + -) (s-to-p-trans + + - -) (p-member ? ? +) (s-member ? ? +) (p-transpose + -) (s-transpose + -) (s-transpose + - ? -) (transpose-s + + + -) (compose + + -) (compose + + + -) (compose1 + + + -) (compose1 + + + + + + + -) (top-sort + -) (vertices-and-zeros + - ?) (count-edges + + + -) (incr-list + + + -) (select-zeros + + -) (top-sort + - + + +) (decr-list + + + - + -) (warshall + -) (warshall + + -) (warshall + + + -))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (vertices Nil Nil) + (set-det)) +; + + (= + (vertices + (Cons + (- $Vertex $Neighbours) $Graph) + (Cons $Vertex $Vertices)) + (vertices $Graph $Vertices)) +; + + + + + + (= + (p-to-s-graph $P_Graph $S_Graph) + ( (sort $P_Graph $EdgeSet) + (p-to-s-vertices $EdgeSet $VertexBag) + (sort $VertexBag $VertexSet) + (p-to-s-group $VertexSet $EdgeSet $S_Graph))) +; + + + + + (= + (p-to-s-vertices Nil Nil) + (set-det)) +; + + (= + (p-to-s-vertices + (Cons + (- $A $Z) $Edges) + (Cons $A + (Cons $Z $Vertices))) + (p-to-s-vertices $Edges $Vertices)) +; + + + + + (= + (p-to-s-group Nil $_ Nil) + (set-det)) +; + + (= + (p-to-s-group + (Cons $Vertex $Vertices) $EdgeSet + (Cons + (- $Vertex $Neibs) $G)) + ( (p-to-s-group $EdgeSet $Vertex $Neibs $RestEdges) (p-to-s-group $Vertices $RestEdges $G))) +; + + + + (= + (p-to-s-group + (Cons + (- $V $X) $Edges) $V + (Cons $X $Neibs) $RestEdges) + ( (set-det) (p-to-s-group $Edges $V $Neibs $RestEdges))) +; + + (= + (p_to_s_group $Edges $_ () $Edges) True) +; + + + + + + (= + (s-to-p-graph Nil Nil) + (set-det)) +; + + (= + (s-to-p-graph + (Cons + (- $Vertex $Neibs) $G) $P_Graph) + ( (s-to-p-graph $Neibs $Vertex $P_Graph $Rest_P_Graph) (s-to-p-graph $G $Rest_P_Graph))) +; + + + + (= + (s-to-p-graph Nil $_ $P_Graph $P_Graph) + (set-det)) +; + + (= + (s-to-p-graph + (Cons $Neib $Neibs) $Vertex + (Cons + (- $Vertex $Neib) $P) $Rest_P) + (s-to-p-graph $Neibs $Vertex $P $Rest_P)) +; + + + + + + (= + (s-to-p-trans Nil Nil) + (set-det)) +; + + (= + (s-to-p-trans + (Cons + (- $Vertex $Neibs) $G) $P_Graph) + ( (s-to-p-trans $Neibs $Vertex $P_Graph $Rest_P_Graph) (s-to-p-trans $G $Rest_P_Graph))) +; + + + + (= + (s-to-p-trans Nil $_ $P_Graph $P_Graph) + (set-det)) +; + + (= + (s-to-p-trans + (Cons $Neib $Neibs) $Vertex + (Cons + (- $Neib $Vertex) $P) $Rest_P) + (s-to-p-trans $Neibs $Vertex $P $Rest_P)) +; + + + + + + (= + (warshall $Graph $Closure) + (warshall $Graph $Graph $Closure)) +; + + + + (= + (warshall Nil $Closure $Closure) + (set-det)) +; + + (= + (warshall + (Cons + (- $V $_) $G) $E $Closure) + ( (memberchk + (- $V $Y) $E) + (warshall $E $V $Y $NewE) + (warshall $G $NewE $Closure))) +; + + + + (= + (warshall + (Cons + (- $X $Neibs) $G) $V $Y + (Cons + (- $X $NewNeibs) $NewG)) + ( (memberchk $V $Neibs) + (set-det) + (ord-union $Neibs $Y $NewNeibs) + (warshall $G $V $Y $NewG))) +; + + (= + (warshall + (Cons + (- $X $Neibs) $G) $V $Y + (Cons + (- $X $Neibs) $NewG)) + ( (set-det) (warshall $G $V $Y $NewG))) +; + + (= + (warshall () $_ $_ ()) True) +; + + + + + + (= + (p-transpose Nil Nil) + (set-det)) +; + + (= + (p-transpose + (Cons + (- $From $To) $Edges) + (Cons + (- $To $From) $Transpose)) + (p-transpose $Edges $Transpose)) +; + + + + + + (= + (s-transpose $S_Graph $Transpose) + (s-transpose $S_Graph $Base $Base $Transpose)) +; + + + (= + (s-transpose Nil Nil $Base $Base) + (set-det)) +; + + (= + (s-transpose + (Cons + (- $Vertex $Neibs) $Graph) + (Cons + (- $Vertex Nil) $RestBase) $Base $Transpose) + ( (s-transpose $Graph $RestBase $Base $SoFar) (transpose-s $SoFar $Neibs $Vertex $Transpose))) +; + + + + (= + (transpose-s + (Cons + (- $Neib $Trans) $SoFar) + (Cons $Neib $Neibs) $Vertex + (Cons + (- $Neib + (Cons $Vertex $Trans)) $Transpose)) + ( (set-det) (transpose-s $SoFar $Neibs $Vertex $Transpose))) +; + + (= + (transpose-s + (Cons $Head $SoFar) $Neibs $Vertex + (Cons $Head $Transpose)) + ( (set-det) (transpose-s $SoFar $Neibs $Vertex $Transpose))) +; + + (= + (transpose_s () () $_ ()) True) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (p-member $X $Y $P_Graph) + ( (nonvar $X) + (nonvar $Y) + (set-det) + (memberchk + (- $X $Y) $P_Graph))) +; + + (= + (p-member $X $Y $P_Graph) + (member + (- $X $Y) $P_Graph)) +; + + +; +; + +; +; + +; +; + +; +; + + + + (= + (s-member $X $Y $S_Graph) + ( (var $X) + (var $Y) + (set-det) + (member + (- $X $Neibs) $S_Graph) + (member $Y $Neibs))) +; + + (= + (s-member $X $Y $S_Graph) + ( (var $X) + (set-det) + (member + (- $X $Neibs) $S_Graph) + (memberchk $Y $Neibs))) +; + + (= + (s-member $X $Y $S_Graph) + ( (var $Y) + (set-det) + (memberchk + (- $X $Neibs) $S_Graph) + (member $Y $Neibs))) +; + + (= + (s-member $X $Y $S_Graph) + ( (memberchk + (- $X $Neibs) $S_Graph) (memberchk $Y $Neibs))) +; + + + +; +; + +; +; + +; +; + + + + (= + (compose $G1 $G2 $Composition) + ( (vertices $G1 $V1) + (vertices $G2 $V2) + (ord-union $V1 $V2 $V) + (compose $V $G1 $G2 $Composition))) +; + + + + (= + (compose Nil $_ $_ Nil) + (set-det)) +; + + (= + (compose + (Cons $Vertex $Vertices) + (Cons + (- $Vertex $Neibs) $G1) $G2 + (Cons + (- $Vertex $Comp) $Composition)) + ( (set-det) + (compose1 $Neibs $G2 Nil $Comp) + (compose $Vertices $G1 $G2 $Composition))) +; + + (= + (compose + (Cons $Vertex $Vertices) $G1 $G2 + (Cons + (- $Vertex Nil) $Composition)) + (compose $Vertices $G1 $G2 $Composition)) +; + + + + + (= + (compose1 + (Cons $V1 $Vs1) + (Cons + (- $V2 $N2) $G2) $SoFar $Comp) + ( (compare $Rel $V1 $V2) + (set-det) + (compose1 $Rel $V1 $Vs1 $V2 $N2 $G2 $SoFar $Comp))) +; + + (= + (compose1 $_ $_ $Comp $Comp) True) +; + + + + (= + (compose1 < $_ $Vs1 $V2 $N2 $G2 $SoFar $Comp) + ( (set-det) (compose1 $Vs1 (Cons (- $V2 $N2) $G2) $SoFar $Comp))) +; + + (= + (compose1 > $V1 $Vs1 $_ $_ $G2 $SoFar $Comp) + ( (set-det) (compose1 (Cons $V1 $Vs1) $G2 $SoFar $Comp))) +; + + (= + (compose1 = $V1 $Vs1 $V1 $N2 $G2 $SoFar $Comp) + ( (ord-union $N2 $SoFar $Next) (compose1 $Vs1 $G2 $Next $Comp))) +; + + + +; (error +; (syntax_error end_of_file_in_block_comment) +; (stream (0x5562812ce500) 0 1 0)) + diff --git a/metagame/misc/randoms.metta b/metagame/misc/randoms.metta new file mode 100644 index 0000000..8f1f082 --- /dev/null +++ b/metagame/misc/randoms.metta @@ -0,0 +1,763 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + !(my-use-module (library random)) +; + + + + !(dynamic (/ old-seed 1)) +; + + + + (= + (seed $S) + (getrand $S)) +; + + + + +; +; + +; +; + +; +; + + + (= + (reset-random $S) + (setrand $S)) +; + + +; +; + +; +; + + (= + (reset-random) + (random $_)) +; + + + +; +; + +; +; + +; +; + + + + (= + (record-seed) + ( (seed $S) + (remove-all-symbols &self + (old_seed $_)) + (add-symbol &self + (old_seed $S)))) +; + + + +; +; + +; +; + + + (= + (recover-random) + ( (old-seed $S) (reset-random $S))) +; + + +; +; + + + (= + (write-old-seed $CommentChar) + ( (old-seed $Seed) + (set-det) + (format "~n~w RANDOM SEED: ~w~n" + (:: $CommentChar $Seed)))) +; + + (= write_old_seed True) +; + + + + +; +; + +; +; + +; +; + + + + (= + (random-include $L $U $R) + ( (integer $L) + (integer $U) + (set-det) + (is $U1 + (+ $U 1)) + (random $L $U1 $R))) +; + + (= + (random-include $L $U $R) + (random $L $U $R)) +; + + + + +; +; + +; +; + + + (= + (random $R $N) + ( (is $R1 + (+ $R 1)) (random 1 $R1 $N))) +; + + + + +; +; + +; +; + + + + (= + (random-element $Set $Element) + ( (length $Set $Length) + (random $Length $R) + (nth $R $Set $Element))) +; + + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (random-permute Nil Nil) + (set-det)) +; + + (= + (random-permute $List1 + (Cons $Item $Rest)) + ( (random-select $Item $List1 $List) (random-permute $List $Rest))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (random-bagof $A $B $C) + ( (bagof $A $B $C1) (random-permute $C1 $C))) +; + + + + (= + (random-setof $A $B $C) + ( (setof $A $B $C1) (random-permute $C1 $C))) +; + + + + (= + (random-findall $A $B $C) + ( (findall $A $B $C1) (random-permute $C1 $C))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (random-arg $Term $Element) + ( (functor $Term $Args $Arity) + (random $Arity $R) + (arg $R $Term $Element))) +; + + + +; +; + +; +; + +; +; + + + + (= + (random-success $Call) + ( (bagof $Call + (^ $Call + (call $Call)) $Calls) (random-element $Calls $Call))) +; + + + + + + +; +; + +; +; + +; +; + +; +; + + + (= + (randomly-pair Nil $_ Nil) + (set-det)) +; + + (= + (randomly-pair $_ Nil Nil) + (set-det)) +; + + (= + (randomly-pair + (Cons $A $As) $Set + (Cons + (= $A $Elt) $Pairs)) + ( (random-element $Set $Elt) + (extract $Elt $Set $Set1) + (randomly-pair $As $Set1 $Pairs))) +; + + + + +; +; + +; +; + + + (= + (random-subsets 0 $_ $_ Nil) + (set-det)) +; + + (= + (random-subsets $N $Size $Set + (Cons $Elt $Rest)) + ( (random-subset $Size $Set $Elt) + (is $N1 + (- $N 1)) + (random-subsets $N1 $Size $Set $Rest))) +; + + +; +; + +; +; + + + (= + (random-subset 0 $_ Nil) + (set-det)) +; + + (= + (random-subset $Size $Set + (Cons $Elt $Rest)) + ( (random-element $Set $Elt) + (extract $Elt $Set $Set1) + (is $Size1 + (- $Size 1)) + (random-subset $Size1 $Set1 $Rest))) +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (random-different-args $Term $Arg1 $Arg2) + ( (random-arg $Term $Arg1) (random-different-arg $Term $Arg1 $Arg2))) +; + + + + + (= + (random-different-arg $Term $ArgA $ArgB) + (random-different-arg $Term $ArgA $ArgA $ArgB)) +; + + + (= + (random-different-arg $Term $ArgA $ArgB $ArgB) + ( (\== $ArgA $ArgB) (set-det))) +; + + (= + (random-different-arg $Term $ArgA $ArgA $ArgB) + ( (random-arg $Term $Arg1) (random-different-arg $Term $ArgA $Arg1 $ArgB))) +; + + + +; +; + +; +; + +; +; + + + (= + (random-test $R $N $Ratio) + (random-test $R $N 0 0 100 $Ratio)) +; + + +; +; + +; +; + +; +; + + (= + (random-test $R $N $SampleSize $Ratio) + (random-test $R $N 0 0 $SampleSize $Ratio)) +; + + + (= + (random-test $R $N $Tried $Found $Tried $Ratio) + ( (is $Ratio + (/ $Found $Tried)) (set-det))) +; + + (= + (random-test $R $N $Tried $Found $Total $Ratio) + ( (random $R $N1) + (det-if-then-else + (= $N $N1) + (is $Found1 + (+ $Found 1)) + (= $Found1 $Found)) + (is $Tried1 + (+ $Tried 1)) + (random-test $R $N $Tried1 $Found1 $Total $Ratio))) +; + + + + (= + (sample-from-distribution $Dist $Choice) + ( (distribution $Dist $Options) + (random $R) + (in-prob-region $Options $R $Choice1) + (= $Choice1 $Choice))) +; + + + + (= + (distribution + (distribution $Choices) $Choices) True) +; + + +; +; + + + (= + (in-prob-region + (:: (= $Choice $Prob)) $_ $Choice) + (set-det)) +; + + (= + (in-prob-region + (Cons + (= $C $P) $Choices) $Prob $C) + ( (< $Prob $P) (set-det))) +; + + (= + (in-prob-region + (Cons + (= $C $P) $Choices) $Prob $Choice) + ( (is $PRest + (- $Prob $P)) (in-prob-region $Choices $PRest $Choice))) +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (sample-from-range $Range $Choice) + ( (range $Range $Min $Max) (random-include $Min $Max $Choice))) +; + + + + (= + (range + (range $Min $Max) $Min $Max) True) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (sample $Dist $Choice) + ( (pair-list $Choices $Weights $Dist) + (sum-list $Weights $Total) + (random 0.0 $Total $R) + (in-region $Dist $R $Choice1) + (= $Choice1 $Choice))) +; + + +; +; + +; +; + + (= + (sample 0 $_ Nil) + (set-det)) +; + + (= + (sample $N $Dist + (Cons $S $Samples)) + ( (> $N 0) + (is $N1 + (- $N 1)) + (sample $Dist $S) + (sample $N1 $Dist $Samples))) +; + + +; +; + +; +; + +; +; + + + (= + (sample-subsets 0 $_ $_ Nil) + (set-det)) +; + + (= + (sample-subsets $N $Size $Dist + (Cons $Elt $Rest)) + ( (sample $Size $Dist $Elt) + (is $N1 + (- $N 1)) + (sample-subsets $N1 $Size $Dist $Rest))) +; + + + + + + (= + (test-sample) + ( (repeat) + (sample + (:: + (- a 5) + (- b 10) + (- d 15)) $Choice) + (write $Choice) + (nl) + (fail))) +; + + + +; +; + +; +; + +; +; + + + + (= + (randomize $N) + ( (format 'Using random seed #~p.~n' + (:: $N)) (randomize0 $N))) +; + + + + (= + (randomize0 1) + (setrand (random 2260 5202 18078 -111865839))) +; + + (= + (randomize0 2) + (setrand (random 1676 2152 14938 -111865839))) +; + + (= + (randomize0 3) + (setrand (random 14918 9840 11226 -111865839))) +; + + (= + (randomize0 4) + (setrand (random 11477 9180 488 -111865839))) +; + + (= + (randomize0 5) + (setrand (random 27112 8989 12856 -111865839))) +; + + (= + (randomize0 6) + (setrand (random 27949 24755 16306 -111865839))) +; + + (= + (randomize0 7) + (setrand (random 3126 20129 24910 -111865839))) +; + + (= + (randomize0 8) + (setrand (random 21946 18049 2077 -111865839))) +; + + (= + (randomize0 9) + (setrand (random 26016 4946 13012 -111865839))) +; + + (= + (randomize0 10) + (setrand (random 18553 19429 25736 -111865839))) +; + + (= + (randomize0 test) + (setrand (random 1734 10872 10679 -111865839))) +; + + diff --git a/metagame/misc/shells.metta b/metagame/misc/shells.metta new file mode 100644 index 0000000..753868f --- /dev/null +++ b/metagame/misc/shells.metta @@ -0,0 +1,601 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + + + + !(ensure-loaded (library aux)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (shell $Tree) + ( (command-from-args $Tree $Command) (unix (shell $Command)))) +; + + +; +; + +; +; + +; +; + + (= + (shell $Command $Value) + (shell $Command /tmp/shelltmp $Value)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + (= + (shell $Command $TmpFile $Value) + ( (shell (:: $Command > $TmpFile ' ; echo ' . ' >> ' $TmpFile)) + (see $TmpFile) + (read $Value) + (seen) + (shell (:: rm $TmpFile)))) +; + + +; +; + +; +; + + + (= + (shell-out $Command $File) + (shell (:: $Command > $File))) +; + + +; +; + +; +; + +; +; + + + (= + (writep $Command $File) + (shell-out + (:: echo $Command) $File)) +; + + + + + (= + (command-from-args $Tree $Command) + (command-from-args $Tree ' ' $Command)) +; + + + (= + (command-from-args $Tree $Space $Command) + ( (flatten $Tree $List) + (interleave-list $List $Space $SpacedList) + (concat-list $SpacedList $Command))) +; + + + + + (= + (interleave-list Nil $_ Nil) + (set-det)) +; + + (= + (interleave-list + (:: $H) $_ + (:: $H)) + (set-det)) +; + + (= + (interleave-list + (Cons $H $T) $Sym + (Cons $H + (Cons $Sym $TT))) + (interleave-list $T $Sym $TT)) +; + + + + + (= + (spacify_list () ()) True) +; + + (= + (spacify-list + (Cons $H $T) + (Cons $H + (Cons ' ' $TT))) + (spacify-list $T $TT)) +; + + + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (unloaded-host $Addr) + (shell + (:: rsh ely /usr/etc/resman dbank) $Addr)) +; + + + +; +; + +; +; + + + (= + (shell-rsh $Program $Args) + ( (current-host $Addr) (shell-rsh $Addr $Program $Args))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (shell-rsh any $Program $Args) + ( (set-det) + (unloaded-host $Addr) + (shell-rsh $Addr $Program $Args))) +; + + (= + (shell-rsh $Addr $Program $Args) + (shell-rsh $Addr $Program $Args $Addr)) +; + + + +; +; + +; +; + +; +; + +; +; + + (= + (shell-rsh any $Program $Args $Title) + ( (set-det) + (unloaded-host $Addr) + (shell-rsh $Addr $Program $Args $Title))) +; + + (= + (shell-rsh $Addr $Program $Args $Title) + (shell (:: %HOME/Bin/xrsh $Addr 'xterm ' -sb -name $Title -title $Title -e $Program $Args &))) +; + + + + + +; +; + +; +; + +; +; + + + + (= + (start-sicstus-shell $Host $Args) + (shell-rsh $Host sicstus $Args)) +; + + + (= + (start-sicstus-shell $Args) + (shell-rsh sicstus $Args)) +; + + + + + +; +; + +; +; + +; +; + + + + (= + (find-architecture $Arch) + ( (shell arch $Arch) (add-symbol &self (found_current_architecture $Arch)))) +; + + + + (= + (current-architecture $Arch) + ( (get-current-architecture $Arch1) (= $Arch $Arch1))) +; + + + + (= + (get-current-architecture $Arch) + ( (environment-variable %ARCH $Arch) (set-det))) +; + + (= + (get-current-architecture $Arch) + (det-if-then-else + (current-predicate found-current-architecture $_) + (found-current-architecture $Arch) + (find-architecture $Arch))) +; + + + + + (= + (bin-directory $D) + ( (current-architecture $Arch) (concat-list (:: ~/prolog/bin/ $Arch /) $D))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (arch-path-name $Arch $Path $Name) + ( (current-architecture $Arch) (concat-list $Path $Name))) +; + + + + + (= + (add-bin-library) + ( (bin-directory $D) (add-symbol &self (library_directory $D)))) +; + + + + (= + (current-directory $X) + (absolute-file-name . $X)) +; + + + + (= + (file-exists $X) + (unix (access $X 0))) +; + + + +; +; + +; +; + +; +; + + + (= + (environment-variable $Name $Value) + (shell + (:: echo $Name) $Value)) +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (with-output-file $File $Mode $Goal) + ( (switch-output-to-file $File $Mode $Old $New) + (call $Goal) + (close $New) + (set-output $Old))) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (with-input-file $File $Goal) + ( (switch-input-to-file $File $Old $New) + (call $Goal) + (close $New) + (set-input $Old))) +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (switch-output-to-file $File $Mode $Old $New) + ( (current-output $Old) + (open $File $Mode $New) + (set-output $New))) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (switch-input-to-file $File $Old $New) + ( (current-input $Old) + (open $File read $New) + (set-input $New))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (with-temp-file $Template $File $Goal) + ( (gensym $Template $P) + (concat-list + (:: /tmp/ $P XXXXXX) $FullTemplate) + (mktemp $FullTemplate $File) + (call $Goal) + (det-if-then-else + (tracing savetables) True + (shell (:: rm $File))))) +; + + +; +; + + + + +; +; + + + (= + (cd) + (unix cd)) +; + + (= + (cd $X) + (unix (cd $X))) +; + + + (= + (ls) + (unix (shell ls))) +; + + + (= + (lsa) + (unix (shell 'ls -Al'))) +; + + + (= + (pwd) + (unix (shell pwd))) +; + + diff --git a/metagame/misc/theoryl.metta b/metagame/misc/theoryl.metta new file mode 100644 index 0000000..5527ff8 --- /dev/null +++ b/metagame/misc/theoryl.metta @@ -0,0 +1,308 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + + +; +; + + + !(op 1200 xfy ::) +; + + + + (= + (theory-clause $G) + (theory-clause $G True $Id)) +; + + + (= + (theory-clause $G $H) + (theory-clause $G $H $Id)) +; + + +; +; + + + (= + (theory-clause $G $H $Id) + ( (var $Id) + (set-det) + (theory-clause0 $G $H $Id))) +; + + (= + (theory-clause $G $H + (ith-converse $I $Id)) + ( (set-det) + (theory-clause0 $H $Gs $Id) + (ith-and-member $I $G $Gs))) +; + + (= + (theory-clause $G $H $Id) + ( (set-det) (theory-clause0 $G $H $Id))) +; + + + + (= + (theory-clause0 $A $B $Id) + ( (:: $Id $C) (det-if-then-else (= (= $A $B) $C) True (det-if-then otherwise (= (= $A $B) (= $C True)))))) +; + + + + (= + (ith-and-member 0 $A + (, $A $_)) + (set-det)) +; + + (= + (ith-and-member 0 $A $A) + (set-det)) +; + + (= + (ith-and-member $I $A + (, $_ $B)) + ( (> $I 0) + (is $I1 + (- $I 1)) + (ith-and-member $I1 $A $B))) +; + + + + (= + (system-predicate $Goal) + ( (functor $Goal $F $N) + (functor $PredSpec $F $N) + (not (theory-clause $PredSpec $_ $_)))) +; + + + + +; +; + +; +; + + + + !(dynamic (/ next-clause-id 1)) +; + + + (= + (next_clause_id 0) True) +; + + +; +; + +; +; + + + + (= + (theory-assert $Clause) + (theory-assert $Clause $_)) +; + + + +; +; + +; +; + + + (= + (theory-assert $Clause + (new $N)) + ( (clause-parts $Clause $G $H) + (remove-symbol &self + (next_clause_id $N)) + (is $N1 + (+ $N 1)) + (add-symbol &self + (next_clause_id $N1)) + (add-symbol &self + (:: + (new $N) + (:- $G $H))))) +; + + + +; +; + +; +; + +; +; + + + + (= + (theory-assert-az $Clause + (new $N) $AZ) + ( (clause-parts $Clause $G $H) + (remove-symbol &self + (next_clause_id $N)) + (is $N1 + (+ $N 1)) + (add-symbol &self + (next_clause_id $N1)) + (assertaz $AZ + (:: + (new $N) + (= $G $H))))) +; + + + + (= + (assertaz a $C) + (add-symbol &self $C)) +; + + (= + (assertaz z $C) + (add-symbol &self $C)) +; + + + + + (= + (clause-parts + (= $G $H) $G $H) + (set-det)) +; + + (= + (clause-parts $G $G True) + (not (functor $G :- 2))) +; + + +; +; + + + + (= + (new_id + (new $_)) True) +; + + + +; +; + + + + (= + (theory-retract $Clause $Id) + ( (clause-parts $Clause $G $H) (remove-symbol &self (:: $Id (:- $G $H))))) +; + + + (= + (theory-retract $Clause) + (theory-retract $Clause $Id)) +; + + + + (= + (theory-clear) + (remove-all-symbols &self + (:: $Id $Clause))) +; + + + + + (= + (theory-listing) + (whenever + (theory-clause $C) + (portray-clause $C))) +; + + diff --git a/metagame/misc/timing.metta b/metagame/misc/timing.metta new file mode 100644 index 0000000..b58ad10 --- /dev/null +++ b/metagame/misc/timing.metta @@ -0,0 +1,464 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + !(ensure-loaded (library aux)) +; + + !(ensure-loaded (library shells)) +; + + +; +; + +; +; + +; +; + + + (= + (timing $G $Method $Time $Success) + ( (time-stat $Method $T0) + (or + (, + (call $G) + (= $Success yes)) + (= $Success no)) + (time-stat $Method $T1) + (is $Time + (- $T1 $T0)))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + (= + (timing $Goal $Method $Time) + ( (timing $Goal $Method $Time $Success) + (format "Success: ~w~n" + (:: $Success)) + (format 'Time is ~3d sec.~n' + (:: $Time)) + (= $Success yes))) +; + + + + (= + (realtime $G) + (timing $G realtime $_)) +; + + + + (= + (runtime $G) + (timing $G runtime $_)) +; + + + + (= + (runtimes $N $G) + (runtime (dotimes $N $G))) +; + + +; +; + +; +; + +; +; + + + (= + (timing-success $Goal $Method $Time) + ( (time-stat $Method $T0) + (call $Goal) + (set-det) + (time-stat $Method $T1) + (is $Time + (- $T1 $T0)))) +; + + + + (= + (runtime-success $Goal $Time) + (timing-success $Goal runtime $Time)) +; + + + + (= + (realtime-success $Goal $Time) + (timing-success $Goal realtime $Time)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (timing-once $Goal $Method $Time) + ( (timing $Goal $Method $Time $Success) + (set-det) + (format "Success: ~w~n" + (:: $Success)) + (format 'Time is ~3d sec.~n' + (:: $Time)))) +; + + + + (= + (runtime-once $G) + (timing-once $G runtime $_)) +; + + + (= + (realtime-once $G) + (timing-once $G realtime $_)) +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (time-stat realtime $Time) + (realtime-msec $Time)) +; + + (= + (time-stat runtime $Time) + (statistics runtime + (Cons $Time $_))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (real-time $Time) + (shell + (:: date +%H-%M-%S) $Time)) +; + + + + (= + (time-seconds + (- + (- $H $M) $S) $Sec) + (is $Sec + (+ + (+ $S + (* 60 $M)) + (* 3600 $H)))) +; + + + + (= + (time-msec $T $MSec) + ( (time-seconds $T $Sec) (is $MSec (* 1000 $Sec)))) +; + + + + (= + (realtime-seconds $Sec) + ( (real-time $T) (time-seconds $T $Sec))) +; + + + + (= + (realtime-msec $Sec) + ( (real-time $T) (time-msec $T $Sec))) +; + + + + +; +; + +; +; + +; +; + + + (= + (realtime-randomize) + ( (realtime-seconds $S) + (random 10 $S $R) + (is $X + (mod $R 100)) + (or + (dotimes $X + (, + (random $_) + (fail))) True))) +; + + + + +; +; + +; +; + +; +; + + + + (= + (cumulative-time $Tasks) + ( (statistics runtime + (Cons $T0 $_)) (cumulative-time $Tasks $T0 1))) +; + + + (= + (cumulative_time () $_ $_) True) +; + + (= + (cumulative-time + (Cons $Task $Tasks) $T0 $N) + ( (det-if-then-else $Task + (= + (:: $Mark) " ") + (= + (:: $Mark) "*")) + (statistics runtime + (Cons $T $_)) + (is $CTime + (- $T $T0)) + (format ~p~8|~p~c~n + (:: $N $CTime $Mark)) + (is $N1 + (+ $N 1)) + (set-det) + (cumulative-time $Tasks $T0 $N1))) +; + + + +; +; + +; +; + +; +; + + + + (= + (wait-msecs $MSec) + ( (statistics runtime + (Cons $T0 $_)) + (is $T1 + (+ $T0 $MSec)) + (wait-till-time $T1))) +; + + + + (= + (wait-till-time $T1) + ( (statistics runtime + (Cons $TN $_)) (det-if-then-else (>= $TN $T1) True (wait-till-time $T1)))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (timing $Call) + ( (timing) + (set-det) + (runtime $Call))) +; + + (= + (timing $Call) + (call $Call)) +; + + + (= + (timing) + (parameter timing on)) +; + + + + (= + (set-timing) + (set-parameter timing on)) +; + + + (= + (unset-timing) + (set-parameter timing off)) +; + + + diff --git a/metagame/misc/tracing.metta b/metagame/misc/tracing.metta new file mode 100644 index 0000000..4f39118 --- /dev/null +++ b/metagame/misc/tracing.metta @@ -0,0 +1,197 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + + + !(dynamic (/ %tracing 2)) +; + + +; +; + +; +; + +; +; + + + + (= + (tracing $Module $Call) + (det-if-then-else + (tracing $Module) + (call $Call) True)) +; + + +; +; + +; +; + +; +; + + + (= + (tracing-format $Module $String $Args) + (det-if-then-else + (tracing $Module) + (format $String $Args) True)) +; + + +; +; + +; +; + + + (= + (set-tracing $Module $Status) + ( (remove-all-symbols &self + ($tracing $Module $Status1)) (add-symbol &self ($tracing $Module $Status)))) +; + + +; +; + +; +; + +; +; + + (= + (set-tracing $Mod $Component $Status) + ( (functor $Module $Mod 1) + (arg 1 $Module $Component) + (set-tracing $Module $Status))) +; + + + +; +; + +; +; + +; +; + + + (= + (tracing $M) + ( (var $M) + (set-det) + (format "~nError in tracing: Variable Module~n" Nil))) +; + + (= + (tracing (or $M1 $M2)) + (or + (, + (set-det) + (tracing $M1)) + (tracing $M2))) +; + + (= + (tracing (, $M1 $M2)) + ( (set-det) + (tracing $M1) + (tracing $M2))) +; + + (= + (tracing $Module) + (tracing-module $Module)) +; + + + + (= + (tracing-module $Module) + ($tracing $Module on)) +; + + + + (= + (traced-modules $Modules) + ( (setof $M + (tracing-module $M) $Modules) (set-det))) +; + + (= + (traced_modules ()) True) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (trace-timing $Module $Call) + ( (tracing $Module) + (set-det) + (runtime $Call))) +; + + (= + (trace-timing $_ $Call) + (call $Call)) +; + + + diff --git a/metagame/play/advisors.metta b/metagame/play/advisors.metta new file mode 100644 index 0000000..b06e6fa --- /dev/null +++ b/metagame/play/advisors.metta @@ -0,0 +1,494 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (human-choose $Player $Move $SIn $SOut) + ( (control $Player $SIn) (ask-move $Move $SIn $SOut))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (threaten-choose $Role $Move $SIn $SOut) + ( (det-if-then + (move-count $N $SIn) + (=< $N 1)) + (set-det) + (random-choose $Role $Move $SIn $SOut))) +; + + (= + (threaten-choose $_ $Move $SIn $SOut) + ( (timing (threaten-move $Move $SIn $SOut)) + (set-det) + (print-choice $Move $SIn $SOut))) +; + + (= + (threaten-choose $Role $Move $SIn $SOut) + (random-choose $Role $Move $SIn $SOut)) +; + + + +; +; + +; +; + +; +; + + + (= + (instant-choose $Player $Move $SIn $SOut) + ( (control $Player $SIn) + (format "~nThe Instant Moves:~n" Nil) + (instant-move $Move $SIn $SOut) + (print-choice $Move $SIn $SOut))) +; + + +; +; + + + (= + (instant-move $Move $SIn $SOut) + ( (legal $Move $SIn $SOut) (set-det))) +; + + + +; +; + +; +; + +; +; + + + (= + (random-choose $Player $Move $SIn $SOut) + ( (control $Player $SIn) + (timing (random-move $Move $SIn $SOut)) + (set-det) + (print-choice $Move $SIn $SOut))) +; + + +; +; + + + (= + (random-move $M $SIn $SOut) + (random-success (legal $M $SIn $SOut))) +; + + + + +; +; + +; +; + +; +; + + + (= + (cautious-choose $Player $Move $SIn $SOut) + ( (timing (cautious-move $Move $SIn $SOut)) + (set-det) + (print-choice $Move $SIn $SOut))) +; + + + +; +; + +; +; + + + + (= + (cautious-move $Move $SIn $SOut) + ( (safe-move $Move $SIn $SOut) (not (victor-move $M2 $SOut $_)))) +; + + + +; +; + + + + (= + (safe-move $Move $SIn $SOut) + ( (control $Player $SIn) + (opposite-role $Player $Opponent) + (legal $Move $SIn $SOut) + (not (game-outcome $Opponent $SOut)))) +; + + +; +; + +; +; + + + (= + (check-safe-move $Move $SIn $SOut) + ( (control $Player $SIn) + (opposite-role $Player $Opponent) + (not (game-outcome $Opponent $SOut)))) +; + + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + + (= + (random-aggressive-choose $Player $Move $SIn $SOut) + ( (timing (random-aggressive-move $Move $SIn $SOut)) + (set-det) + (print-choice $Move $SIn $SOut))) +; + + + + + (= + (random-aggressive-move $Move $SIn $SOut) + ( (victor-move $Move $SIn $SOut) (set-det))) +; + + (= + (random-aggressive-move $Move $SIn $SOut) + (random-cautious-move $Move $SIn $SOut)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (random-cautious-choose $Player $Move $SIn $SOut) + ( (timing (random-cautious-move $Move $SIn $SOut)) + (set-det) + (print-choice $Move $SIn $SOut))) +; + + + + (= + (random-cautious-move $Move $SIn $SOut) + ( (legal-moves $Moves $SIn) + (random-non-losing $Moves $Move $SIn $SOut) + (set-det))) +; + + (= + (random-cautious-move $Move $SIn $SOut) + ( (print-resign-notice) (random-move $Move $SIn $SOut))) +; + + + + (= + (print-resign-notice) + (format "\nA cautious player would resign now ... \nbut perhaps my opponent won't see it!\n" Nil)) +; + + + + (= + (print-forced-notice) + (format "Forced choice: only 1 legal move~n" Nil)) +; + + + + (= + (print-rushed-notice) + (format "Rushed choice: no time to think!~n" Nil)) +; + + + + (= + (print-forced-or-lost-notice) + (format "Forced choice: only 1 legal move (or all others lose!)~n" Nil)) +; + + + + (= + (random-non-losing + (:: $Move) $Move $SIn $SOut) + ( (set-det) + (print-forced-or-lost-notice) + (legal $Move $SIn $SOut))) +; + + (= + (random-non-losing $Moves $Move $SIn $SOut) + ( (random-select $Move1 $Moves $RestMoves) (nl-or-next $Move1 $RestMoves $Move $SIn $SOut))) +; + + + + (= + (nl-or-next $Move $_ $Move $SIn $SOut) + ( (cautious-move $Move $SIn $SOut) (set-det))) +; + + (= + (nl-or-next $_ $Moves $Move $SIn $SOut) + ( (random-non-losing $Moves $Move $SIn $SOut) (set-det))) +; + + + + (= + (legal-moves $Moves $SIn) + (setof $Move + (^ $S1 + (legal $Move $SIn $S1)) $Moves)) +; + + +; +; + + +; +; + +; +; + + + + (= + (pass-move $SIn $SOut) + ( (control $P1 $SIn) + (transfer-control $_ $SIn $SOut) + (control $P2 $SOut) + (format "Passing, control has now transferred from ~p to ~p~n" + (:: $P1 $P2)))) +; + + + + +; +; + + + (= + (victor-move $Move $SIn $SOut) + ( (control $Player $SIn) + (legal $Move $SIn $SOut) + (game-outcome $Player $SOut))) +; + + +; +; + + + (= + (endgame-move $Move $SIn $SOut) + ( (legal $Move $SIn $SOut) (game-over $SOut))) +; + + + +; +; + +; +; + +; +; + + + (= + (mate-move $Move $SIn $SOut) + ( (legal $Move $SIn $SOut) (not (cautious-move $M2 $SOut $_)))) +; + + + +; +; + +; +; + + + + (= + (threaten-move $Move $SIn $SOut) + ( (legal $Move $SIn $SOut) (det-if-then (transfer-control $_ $SOut $S1) (victor-move $M2 $S1 $_)))) +; + + + +; +; + +; +; + + + + (= + (enough-rope-move $Move $SIn $SOut) + ( (legal $Move $SIn $SOut) + (legal $M2 $SOut $S1) + (victor-move $M3 $S1 $_))) +; + + + diff --git a/metagame/play/alphabeta.metta b/metagame/play/alphabeta.metta new file mode 100644 index 0000000..3c17249 --- /dev/null +++ b/metagame/play/alphabeta.metta @@ -0,0 +1,2198 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (alpha-beta-choose $Player $Move $SIn $SOut) + (toggle-weights-choose alpha-beta-move $Player $Move $SIn $SOut)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (iterate-choose $Player $Move $SIn $SOut) + (toggle-weights-choose iterate-move $Player $Move $SIn $SOut)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (iterate-random-choose $Player $Move $SIn $SOut) + (toggle-weights-choose iterate-random-move $Player $Move $SIn $SOut)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (iterate-fixed-choose $Player $Move $SIn $SOut) + (toggle-weights-choose iterate-fixed-move $Player $Move $SIn $SOut)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (toggle-weights-choose $Type $Player $Move $SIn $SOut) + ( (=.. $Goal + (:: $Type $Move $SIn $SOut)) (det-if-then-else (toggle-alpha-beta-weights $Player $Old) (det-if-then-else (timing $Goal) (, (print-choice $Move $SIn $SOut) (set-parameter weights $Old)) (, (set-parameter weights $Old) (fail))) (det-if-then (timing $Goal) (print-choice $Move $SIn $SOut))))) +; + + + +; +; + +; +; + +; +; + + + + (= + (ab-depth $D) + (parameter depth $D)) +; + + +; +; + + + (= + (bound $B) + (parameter bound $B)) +; + + + + (= + (move-time-limit $T) + (parameter move-time-limit $T)) +; + + + + (= + (move-horizon $T) + (parameter move-horizon $T)) +; + + +; +; + + + (= + (approx-window $A $B) + ( (value-of-outcome player $B) (value-of-outcome opponent $A))) +; + + + + (= + (reset-alpha-params) + ( (set-parameter depth 1) + (set-parameter move-time-limit 10000) + (set-parameter move-horizon 1) + (set-parameter ordering random))) +; + +; +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (search-timeout-time $StartTime $SIn $EndTime) + ( (control $P $SIn) + (game-time-left $P $GameLeft) + (move-time-limit $MoveLimit) + (estimated-moves-remaining $MovesLeft $SIn) + (search-timeout-time $StartTime $GameLeft $MovesLeft $MoveLimit $EndTime))) +; + + + (= + (search-timeout-time $StartTime $GameLeft $MovesLeft $MoveLimit $EndTime) + ( (is $Avg + (/ $GameLeft $MovesLeft)) + (is $TimeAvail + (min $MoveLimit $Avg)) + (is $EndTime + (+ $StartTime $TimeAvail)))) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (estimated-moves-remaining $Horizon $_) + (move-horizon $Horizon)) +; + + + +; +; + +; +; + + + (= + (timeout-for-node $Node $End) + ( (tracing-ab timing + (print-timeout-check $Node)) + (number $End) + (current-time $Time) + (>= $Time $End) + (is $Diff + (- $Time $End)) + (print-timeout-message $Diff))) +; + + + + +; +; + +; +; + + (= + (timeout-for-node + (Cons $Node $Rest) $BestNode $End) + (timeout-for-node $Node $End)) +; + + + + + (= + (print-timeout-check $Node) + ( (format "Testing for timeout~n" Nil) + (node-move $Node $Move) + (print-move $Move))) +; + + + + + (= + (print-timeout-message $Diff) + (tracing-ab-format timing "Out of Time by <~p> msec~n" + (:: $Diff))) +; + + + + + (= + (current-time $T0) + (statistics runtime + (Cons $T0 $_))) +; + + +; +; + + + (= + (search-timeout-time $EndTime) + ( (move-time-limit $Limit) + (current-time $T0) + (is $EndTime + (+ $T0 $Limit)))) +; + + +; +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (iterate-fixed-move $Move $SIn $SOut) + ( (change-parameter ordering $Ord fixed) + (iterate-move $Move $SIn $SOut) + (change-parameter ordering $_ $Ord))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (iterate-random-move $Move $SIn $SOut) + ( (change-parameter ordering $Ord random) + (iterate-move $Move $SIn $SOut) + (change-parameter ordering $_ $Ord))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (iterate-move $Move $SIn $SOut) + ( (current-time $StartTime) + (search-timeout-time $StartTime $SIn $EndTime) + (initialized-start-node $SIn $NodeIn) + (instant-move $M $SIn $SFirst) + (det-if-then-else + (forced-move $M $SIn) + (accept-forced-move $M $SFirst $Move $SOut) + (det-if-then-else + (, + (timing (iterate 1 $StartTime $EndTime $NodeIn $NodeOut)) + (nonvar $NodeOut)) + (initialized-choice-node $SOut $NodeOut $Move) + (accept-rushed-move $M $SFirst $Move $SOut))))) +; + + +; +; + +; +; + + + (= + (accept-forced-move $M $S $M $S) + (print-forced-notice)) +; + ; +; + + + + (= + (accept-rushed-move $M $S $M $S) + (print-rushed-notice)) +; + ; +; + + +; +; + + + (= + (forced-move $Move $SIn) + (not (, (legal $Move2 $SIn $S2) (not (= $Move $Move2))))) +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (iterate $Depth $StartTime $EndTime $NodeIn $NodeOut) + ( (find-advice-tables $Tables) (iterate $Depth $StartTime $EndTime $NodeIn $NodeOut $Tables))) +; + + + + (= + (iterate $Depth $StartTime $EndTime $NodeIn $NodeOut $Tables) + ( (approx-window $Alpha $Beta) + (tracing-ab-timing iteration + (alphabeta $Depth $Counts $EndTime $NodeIn $Alpha $Beta $Node1 $Val $_ $Tables)) + (tracing-ab-format value "Searching at depth <~p>: ~n" + (:: $Depth)) + (tracing-ab-format value "The best move found has a value of: ~p~n" + (:: $Val)) + (tracing-ab resources + (print-resource-consumption $Counts)) + (tracing-ab value + (print-pc-info $NodeIn)) + (iterate-deeper $Depth $StartTime $EndTime $Val $NodeIn $Node1 $NodeOut $Tables))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (iterate-deeper $Depth $StartTime $EndTime $Val $NodeIn $Node1 $Node1 $Tables) + ( (win-detected $Val $Depth) (set-det))) +; + + (= + (iterate-deeper $Depth $StartTime $EndTime $_ $NodeIn $Node1 $Node1 $Tables) + ( (not-enough-time $Depth $StartTime $EndTime) (set-det))) +; + + (= + (iterate-deeper $Depth $StartTime $EndTime $_ $NodeIn $_ $NodeOut $Tables) + ( (node-cont $NodeIn $PC) + (node-state $NodeIn $SIn) + (pc-moves $PC $Moves) + (initialized-start-node $SIn $Node1) + (node-pc $Node1 $Moves) + (is $Depth1 + (+ $Depth 1)) + (iterate $Depth1 $StartTime $EndTime $Node1 $NodeOut $Tables))) +; + + + + (= + (win-detected $Val $Depth) + ( (var $Val) + (set-det) + (tracing-ab-format value "No useful info this iteration.~n" Nil))) +; + + (= + (win-detected $Val $Depth) + ( (player-role $Player) + (value-of-outcome $Player $Val) + (set-det) + (tracing-ab-format value "A win is detected for <~p> in <~p> ply!~n" + (:: $Player $Depth)))) +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (not-enough-time $Depth $StartTime $EndTime) + ( (current-time $Now) (>= $Now $EndTime))) +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + +; +; + +; +; + +; +; + +; +; + + + + (= + (alpha-beta-move $Move $SIn $SOut) + ( (ab-depth $Depth) (alpha-beta-move $Depth $Move $SIn $SOut))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + (= + (alpha-beta-move $Depth $Move $SIn $SOut) + ( (current-time $StartTime) + (search-timeout-time $StartTime $SIn $EndTime) + (initialized-start-node $SIn $NodeIn) + (instant-move $M $SIn $SFirst) + (det-if-then-else + (forced-move $M $SIn) + (accept-forced-move $M $SFirst $Move $SOut) + (det-if-then-else + (, + (timing (alpha-beta-iterate $Depth $StartTime $EndTime $NodeIn $NodeOut)) + (nonvar $NodeOut)) + (initialized-choice-node $SOut $NodeOut $Move) + (accept-rushed-move $M $SFirst $Move $SOut))))) +; + + + + + (= + (alpha-beta-iterate $Depth $StartTime $EndTime $NodeIn $NodeOut) + ( (approx-window $Alpha $Beta) + (tracing-ab-timing iteration + (alphabeta $Depth $Counts $EndTime $NodeIn $Alpha $Beta $NodeOut $Val $_)) + (tracing-ab-format value "Searching at depth <~p>: ~n" + (:: $Depth)) + (tracing-ab-format value "The best move found has a value of: ~p~n" + (:: $Val)) + (tracing-ab resources + (print-resource-consumption $Counts)) + (tracing-ab value + (print-pc-info $NodeIn)))) +; + + + + (= + (pc-moves Nil Nil) + (set-det)) +; + + (= + (pc-moves $Node + (Cons $Move $RestMoves)) + ( (node-move $Node $Move) + (node-cont $Node $Rest) + (pc-moves $Rest $RestMoves))) +; + + +; +; + +; +; + +; +; + + + + (= + (print-pc-info $Node) + ( (node-cont $Node $PC) + (pc-moves $PC $Moves) + (format "The principal continuation here is: ~n" Nil) + (print-moves $Moves) + (nl))) +; + + + + (= + (print_moves ()) True) +; + + (= + (print-moves (Cons $M $Moves)) + ( (print-move $M) (print-moves $Moves))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (alphabeta $MaxDepth $Counts $EndTime $Node $Alpha $Beta $GoodNode $Val $Complete) + ( (find-advice-tables $Tables) (alphabeta $MaxDepth $Counts $EndTime $Node $Alpha $Beta $GoodNode $Val $Complete $Tables))) +; + + + (= + (alphabeta $MaxDepth $Counts $EndTime $Node $Alpha $Beta $GoodNode $Val $Complete $Tables) + (alphabeta 0 $MaxDepth $Counts $EndTime $Node $Alpha $Beta $GoodNode $Val $Complete $Tables)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (alphabeta $_ $_ $Counts $End $Node $Alpha $Beta $GoodNode $Val no $_) + ( (timeout-for-node $Node $End) + (set-det) + (node-complete $Node no) + (zero-counts $Counts))) +; + + + (= + (alphabeta $_ $_ $Counts $End $Node $Alpha $Beta $GoodNode $Val yes $Tables) + ( (terminal-node $Node $Val $Tables) + (set-det) + (node-complete $Node yes) + (node-cont $Node Nil) + (terminal-counts $Counts))) +; + + + (= + (alphabeta $Max $Max $Counts $End $Node $Alpha $Beta $GoodNode $Val yes $Tables) + ( (set-det) + (eval-node $Node $Val $Tables) + (node-complete $Node yes) + (static-counts $Counts))) +; + + +; +; + +; +; + +; +; + + (= + (alphabeta $Depth $MaxDepth $Counts $EndTime $Node $Alpha $Beta $GoodNode $Val $Complete $Tables) + ( (< $Depth $MaxDepth) + (is $Depth1 + (+ $Depth 1)) + (expand-node $Node $NodeList $Tables) + (node-cont $Node $GoodNode) + (boundedbest $Depth1 $MaxDepth $Counts1 $EndTime $NodeList $Alpha $Beta $GoodNode $Val $Complete $Tables) + (close-node $Node $GoodNode $Val $Complete) + (node-complete $Node $Complete) + (add-expansion-counts $Counts1 $Counts))) +; + + + + +; +; + +; +; + +; +; + + + (= + (boundedbest $Depth $Max $Counts $EndTime + (Cons $Node $NodeList) $Alpha $Beta $GoodNode $GoodVal $Complete $Tables) + ( (alphabeta $Depth $Max $Counts1 $EndTime $Node $Alpha $Beta $_ $Val $Comp1 $Tables) + (goodenough $Depth $Max $Counts2 $EndTime $NodeList $Alpha $Beta $Node $Val $GoodNode $GoodVal $Comp1 $Complete $Tables) + (sum-resource-counts $Counts1 $Counts2 $Counts))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (goodenough $_ $_ $Counts $End $NodeList $Alpha $Beta $Node $Val $GoodNode $GoodVal $Comp $Comp $Tables) + ( (seen-enough $NodeList $Alpha $Beta $Node $Val $GoodNode $GoodVal $Comp) + (set-det) + (zero-counts $Counts))) +; + + (= + (goodenough $Depth $Max $Counts $End $NodeList $Alpha $Beta $Node $Val $GoodNode $GoodVal yes $Complete $Tables) + ( (newbounds-node $Alpha $Beta $Node $Val $NewAlpha $NewBeta) + (boundedbest $Depth $Max $Counts $End $NodeList $NewAlpha $NewBeta $Node1 $Val1 $Complete $Tables) + (betterof-node $Complete $Depth $Max $Node $Val $Node1 $Val1 $GoodNode $GoodVal))) +; + + + +; +; + +; +; + +; +; + + + (= + (seen-enough Nil $_ $_ $Node $Val $Node $Val $Comp) + (set-det)) +; + ; +; + + (= + (seen-enough $NodeList $_ $_ $Node $Val $Node $Val no) + (set-det)) +; + ; +; + + (= + (seen-enough $NodeList $Alpha $Beta $Node $Val $Node $Val yes) + ( (or + (, + (min-to-move-node $Node) + (>= $Val $Beta)) + (, + (max-to-move-node $Node) + (=< $Val $Alpha))) (set-det))) +; + + + + + (= + (newbounds-node $Alpha $Beta $Node $Val $NewAlpha $NewBeta) + ( (node-state $Node $Pos) (newbounds $Alpha $Beta $Pos $Val $NewAlpha $NewBeta))) +; + + +; +; + +; +; + + + (= + (newbounds $Alpha $Beta $Pos $Val $Val $Beta) + ( (min-to-move $Pos) + (> $Val $Alpha) + (set-det))) +; + ; +; + + (= + (newbounds $Alpha $Beta $Pos $Val $Alpha $Val) + ( (max-to-move $Pos) + (< $Val $Beta) + (set-det))) +; + ; +; + + (= + (newbounds $Alpha $Beta $_ $_ $Alpha $Beta) True) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (betterof-node no $Depth $Max $Node $Val $Node1 $Val1 $Node $Val) + ( (node-complete $Node1 no) (set-det))) +; + + (= + (betterof-node $Complete $Depth $Max $Node $Val $Node1 $Val1 $NodeB $ValB) + (betterof-node $Node $Val $Node1 $Val1 $NodeB $ValB)) +; + + + (= + (betterof-node $Node $Val $Node1 $Val1 $Node $Val) + (or + (, + (min-to-move-node $Node) + (>= $Val $Val1) + (set-det)) + (, + (max-to-move-node $Node) + (=< $Val $Val1) + (set-det)))) +; + + (= + (betterof_node $_ $_ $Node1 $Val1 $Node1 $Val1) True) +; + + + + (= + (max-to-move-node $Node) + ( (node-state $Node $Pos) (max-to-move $Pos))) +; + + + (= + (min-to-move-node $Node) + ( (node-state $Node $Pos) (min-to-move $Pos))) +; + + + + (= + (max-to-move $Pos) + (control player $Pos)) +; + + + (= + (min-to-move $Pos) + (control opponent $Pos)) +; + + + +; +; + +; +; + +; +; + + +; +; + + + (= + (expand-node $Node $NodeList $Tables) + ( (tracing-ab expand + (, + (format " node from move: " Nil) + (node-move $Node $Move) + (print-move $Move))) (ordered-moves $Node $NodeList $Tables))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (ordered-moves $Node $NodeList $Tables) + ( (successor-nodes $Node $NodeList1 $Tables) + (node-pc $Node $PC) + (det-if-then-else + (, + (nonvar $PC) + (= $PC + (Cons $M $Moves))) + (, + (tracing-ab ordering + (, + (format "Ordering PC highest~n" Nil) + (print-moves $PC))) + (search-node $PCNode) + (node-pc $PCNode $Moves) + (node-move $PCNode $M) + (select $PCNode $NodeList1 $NodeList2) + (= $NodeList + (Cons $PCNode $NodeList2))) + (= $NodeList $NodeList1)))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (successor-nodes $Node $Nodes $Tables) + (det-if-then-else + (parameter ordering random) + (random-findall $Node2 + (successor-node $Node $Node2 $Tables) $Nodes) + (det-if-then-else + (parameter ordering fixed) + (findall $Node2 + (successor-node $Node $Node2 $Tables) $Nodes) + (det-if-then otherwise + (, + (format "Error in successor_nodes/3: Invalid ordering parameter!!~n") + (fail)))))) +; + + + + (= + (successor-node $Node $Node2 $Tables) + ( (node-state $Node $State) + (successor-pos $Move $State $State2 $Tables) + (search-node $Node2) + (node-state $Node2 $State2) + (node-move $Node2 $Move) + (node-parent $Node2 $Node))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + +; +; + + + (= + (moves $State $States) + (bagof $State2 + (^ $Move + (legal $Move $State $State2)) $States)) +; + + + + + (= + (close-node $Node $GoodNode $Val $Complete) + (tracing-ab expand + (, + (format " node from move: " Nil) + (node-move $Node $Move) + (print-move $Move) + (format "Resulting (~p-complete) value <~p> after move:~n" + (:: $Complete $Val)) + (node-move $GoodNode $GoodMove) + (print-move $GoodMove) + (nl)))) +; + + +; +; + +; +; + +; +; + + + + (= + (terminal-node $Node $Val $Tables) + ( (node-state $Node $Pos) + (terminal-pos-value $Pos $Val $Tables) + (tracing-ab eval + (print-eval-info $Node $Val)))) +; + + + + + + (= + (eval-node $Node $Val $Tables) + ( (node-state $Node $Pos) + (staticval $Pos $Val $Tables) + (tracing-ab eval + (print-eval-info $Node $Val)) + (tracing-ab state + (print-state $Pos)) + (tracing-ab advice + (show-advices $Pos $Tables)))) +; + + + + + (= + (print-eval-info $Node $Val) + ( (node-move $Node $Move) + (format "Evaluation <~p> for move: " + (:: $Val)) + (print-move $Move) + (nl))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + + +; +; + +; +; + + + (= + (value_of_outcome draw 0) True) +; + + (= + (value_of_outcome player 100000) True) +; + + (= + (value_of_outcome opponent -100000) True) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + + + +; +; + +; +; + +; +; + + + +; +; + +; +; + +; +; + + + + (= + (primary-choice-node $Node) + ( (node-parent $Node $Parent) (node-parent $Parent Nil))) +; + + + + (= + (initialized-search-nodes $Move $SIn $NodeIn $SOut $NodeOut) + ( (search-node $NodeIn) + (node-state $NodeIn $SIn) + (node-parent $NodeIn Nil) + (search-node $NodeOut) + (node-state $NodeOut $SOut) + (node-move $NodeOut $Move))) +; + + + + (= + (initialized-start-node $SIn $NodeIn) + ( (search-node $NodeIn) + (node-state $NodeIn $SIn) + (node-parent $NodeIn Nil))) +; + ; +; + + + + (= + (initialized-choice-node $SOut $NodeOut $Move) + ( (search-node $NodeOut) + (node-state $NodeOut $SOut) + (node-move $NodeOut $Move))) +; + + + + + (= + (portray-node (node $State $Parent $Move $Cont $PC)) + ( (format "~n" Nil))) +; + + +; +; + + + +; +; + + + + (= + (search_node + (node $State $Parent $Move $Cont $PC $Comp) $State $Parent $Move $Cont $PC $Comp) True) +; + + (= + (search-node $N) + (functor $N node 6)) +; + + + (= + (node-state $N $A) + (arg 1 $N $A)) +; + + + (= + (node-parent $N $A) + (arg 2 $N $A)) +; + + + (= + (node-move $N $A) + (arg 3 $N $A)) +; + + + (= + (node-cont $N $A) + (arg 4 $N $A)) +; + + + (= + (node-pc $N $A) + (arg 5 $N $A)) +; + + + (= + (node-complete $N $A) + (arg 6 $N $A)) +; + + + +; +; + +; +; + +; +; + + + + (= + (search-resource $N) + (functor $N resource 3)) +; + + + (= + (resource-expansions $N $A) + (arg 1 $N $A)) +; + + + (= + (resource-statics $N $A) + (arg 2 $N $A)) +; + + + (= + (resource-terminals $N $A) + (arg 3 $N $A)) +; + + + + + (= + (zero-counts $Counts) + ( (search-resource $Counts) + (resource-expansions $Counts 0) + (resource-statics $Counts 0) + (resource-terminals $Counts 0))) +; + + + + (= + (terminal-counts $Counts) + ( (search-resource $Counts) + (resource-expansions $Counts 0) + (resource-statics $Counts 0) + (resource-terminals $Counts 1))) +; + + + + (= + (static-counts $Counts) + ( (search-resource $Counts) + (resource-expansions $Counts 0) + (resource-statics $Counts 1) + (resource-terminals $Counts 0))) +; + + + + (= + (expansion-counts $Counts) + ( (search-resource $Counts) + (resource-expansions $Counts 1) + (resource-statics $Counts 0) + (resource-terminals $Counts 0))) +; + + + + (= + (add-expansion-counts $Counts1 $Counts) + ( (expansion-counts $Counts0) (sum-resource-counts $Counts0 $Counts1 $Counts))) +; + + + + (= + (sum-resource-counts $Counts1 $Counts2 $Counts) + ( (resource-expansions $Counts1 $Exp1) + (resource-statics $Counts1 $Stat1) + (resource-terminals $Counts1 $Term1) + (resource-expansions $Counts2 $Exp2) + (resource-statics $Counts2 $Stat2) + (resource-terminals $Counts2 $Term2) + (is $Exp + (+ $Exp1 $Exp2)) + (is $Stat + (+ $Stat1 $Stat2)) + (is $Term + (+ $Term1 $Term2)) + (search-resource $Counts) + (resource-expansions $Counts $Exp) + (resource-statics $Counts $Stat) + (resource-terminals $Counts $Term))) +; + + + + (= + (print-resource-consumption $Counts) + ( (resource-expansions $Counts $Exp) + (resource-statics $Counts $Stat) + (resource-terminals $Counts $Term) + (is $Total + (+ + (+ $Exp $Stat) $Term)) + (format "Number of nodes expanded: <~p>~n" + (:: $Exp)) + (format "Number of nodes statically evaluated: <~p>~n" + (:: $Stat)) + (format "Number of terminal nodes encountered: <~p>~n" + (:: $Term)) + (format "Number of terminal node tests: <~p>~n" + (:: $Total)))) +; + + + +; +; + +; +; + +; +; + + + + (= + (search-limit $N) + (functor $N limit 4)) +; + + + (= + (limit-depth $N $A) + ( (search-limit $N) (arg 1 $N $A))) +; + + + (= + (limit-count $N $A) + ( (search-limit $N) (arg 2 $N $A))) +; + + + (= + (limit-timeused $N $A) + ( (search-limit $N) (arg 3 $N $A))) +; + + + (= + (limit-timeleft $N $A) + ( (search-limit $N) (arg 4 $N $A))) +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + !(my-ensure-loaded (library tracing)) +; + + + + (= + (tracing-ab $Type $Call) + (det-if-then-else + (tracing (ab $Type)) + (call $Call) True)) +; + + +; +; + + + (= + (tracing-ab-format $Type $String $Args) + (det-if-then-else + (tracing (ab $Type)) + (format $String $Args) True)) +; + + + + (= + (tracing-ab-timing $Type $Call) + (trace-timing + (ab $Type) $Call)) +; + + + + (= + (set-ab-verbosity $Level $Status) + (set-tracing + (ab $Level) $Status)) +; + + + + (= + (silent-ab) + (all-ab off)) +; + + + (= + (loud-ab) + (all-ab on)) +; + + + + (= + (all-ab $Status) + ( (set-ab-verbosity ordering $Status) + (set-ab-verbosity value $Status) + (set-ab-verbosity eval $Status) + (set-ab-verbosity expand $Status) + (set-ab-verbosity resources $Status) + (set-ab-verbosity timing $Status) + (set-ab-verbosity iteration $Status))) +; + + + + + (= + (trace-ab-expand) + (set-ab-verbosity expand on)) +; + + + (= + (trace-ab-eval) + (set-ab-verbosity eval on)) +; + + + (= + (trace-ab-value) + (set-ab-verbosity value on)) +; + + + (= + (trace-ab-ordering) + (set-ab-verbosity ordering on)) +; + + + (= + (trace-ab-resources) + (set-ab-verbosity resources on)) +; + + + (= + (trace-ab-timing) + (set-ab-verbosity timing on)) +; + + + (= + (trace-ab-iterations) + (set-ab-verbosity iteration on)) +; + + +; +; + +; +; + + +; +; + +; +; + +; +; + + + + (= + (alpha-beta-com $Move $SIn $SOut) + ( (timing (alpha-beta-move $Move $SIn $SOut)) (select-move $Move $SIn $SOut))) +; + + + (= + (alpha-beta-com $Move $SIn $SOut $Depth) + ( (timing (alpha-beta-move $Depth $Move $SIn $SOut)) (select-move $Move $SIn $SOut))) +; + + + + (= + (iterate-com $Move $SIn $SOut) + ( (timing (iterate-move $Move $SIn $SOut)) (select-move $Move $SIn $SOut))) +; + + + + (= + (iterate-random-com $Move $SIn $SOut) + ( (timing (iterate-random-move $Move $SIn $SOut)) (select-move $Move $SIn $SOut))) +; + + + + (= + (iterate-fixed-com $Move $SIn $SOut) + ( (timing (iterate-fixed-move $Move $SIn $SOut)) (select-move $Move $SIn $SOut))) +; + + + diff --git a/metagame/play/controller.metta b/metagame/play/controller.metta new file mode 100644 index 0000000..aa0ee04 --- /dev/null +++ b/metagame/play/controller.metta @@ -0,0 +1,1003 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + +; +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (get-if-random-assignment) + ( (current-random-setup-game) + (set-det) + (get-random-assignment $Assignment) + (set-random-assignment $Assignment))) +; + + (= get_if_random_assignment True) +; + + +; +; + + + (= + (set-random-assignment $Assignment) + ( (remove-all-symbols &self + (random_assignment $_)) (add-symbol &self (random_assignment $Assignment)))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (start) + (start-controller)) +; + + + + (= + (start-top $PosName) + ( (checkpoint $PosName $SIn) + (set-current-pos-name $PosName) + (start-controller $SIn))) +; + + + + + + (= + (start-controller) + ( (get-current-game) + (get-initial-state $SIn) + (initialize-history $SIn) + (start-controller $SIn))) +; + + + + (= + (get-initial-state $SIn) + ( (get-if-random-assignment) (start-game $SIn))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (start-controller $SIn) + ( (format "~nInitial Position:~n" Nil) + (print-state $SIn) + (linebreak) + (reset-clock) + (controller $SIn $_) + (set-det))) +; + + + + + (= + (start-game $Init) + ( (new-state $State) (start-game $State $Init))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (controller $SIn $SIn) + ( (game-ends-in-outcome $SIn $Outcome) + (set-det) + (record-game-outcome $Outcome) + (checkpoint-state final $SIn))) +; + + (= + (controller $SIn $SOut) + ( (tracing-play clock print-clock) + (play-in-control $SIn $S1) + (should-continue $S1) + (set-det) + (cleanup-state $S1 $S2) + (controller $S2 $SOut))) +; + + (= + (controller $SIn $SIn) + (format "The game has been halted prematurely!!" Nil)) +; + + + + +; +; + +; +; + +; +; + +; +; + + + (= + (play-in-control $SIn $SOut) + ( (control $Role $SIn) + (initialize-player-move $Role) + (role-chooser $Role $Chooser) + (choose-or-resign $Chooser $Role $SIn $SOut))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (choose-or-resign $Chooser $Role $SIn $SOut) + ( (realtime-success + (choose $Chooser $Role $Move $SIn $SOut) $Time) + (set-det) + (adjust-player-clock $Role $Time) + (add-state-to-history $Move $SOut) + (restore-parameters))) +; + + (= + (choose-or-resign $Chooser $Role $SIn $_) + ( (opposite-role $Role $OppRole) + (role-chooser $OppRole $OppChooser) + (format "~n~p, as ~p, failed to select a legal move.~nThus, ~p, as ~p, is declared the Winner!~n" + (:: $Chooser $Role $OppChooser $OppRole)) + (checkpoint-state final $SIn) + (restore-parameters) + (fail))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (continuous) + (parameter continuous yes)) +; + + + + (= + (set-continuous) + (set-parameter continuous yes)) +; + + + (= + (set-stepping) + (set-parameter continuous no)) +; + + + + (= + (should-continue $SIn) + ( (continuous) (set-det))) +; + + (= + (should-continue $SIn) + (ask-continue y)) +; + + + + (= + (ask-continue $Answer) + ( (ask-ynp Continue $Answer1) + (set-det) + (= $Answer1 $Answer))) +; + + + + (= + (ask-ynp $Query $Answer) + ( (format "~a? (y or n)~n" + (:: $Query)) + (read $Answer1) + (ynp $Answer1 $Answer + (ask-ynp $Query $Answer)))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (initialize-player-move $Role) + ( (save-parameters) + (role-file $Role $File) + (det-if-then-else + (member $File + (:: none Nil)) True + (load-player-eval $File)))) +; + + +; +; + +; +; + + + (= + (load-player-eval (Cons $P $Ps)) + ( (set-det) (restore-parameters (Cons $P $Ps)))) +; + + (= + (load-player-eval $Name) + (load-player-eval-file $Name)) +; + + + + + (= + (set-com $_ $_ $_ $C $P $V) + (set-color-parameter $C $P $V)) +; + + + + (= + (set-top $C $P $V) + (set-color-parameter $C $P $V)) +; + + + + (= + (unset-top $C) + ( (color-player $C $Role) (clear-player-parameters $Role))) +; + + + + (= + (set-color-parameter $Color $P $V) + ( (color-player $Color $Role) (set-player-parameter $Role $P $V))) +; + + + + (= + (set-player-parameter $Role $Param $Val) + ( (role-file $Role $List1) + (set-assoc $List1 $Param $Val $New) + (set-role-file $Role $New))) +; + + + + (= + (clear-player-parameters $Role) + (set-role-file $Role none)) +; + + + + + + (= + (load-player-eval-file $Name) + ( (find-eval-file $Name $File) + (save-parameters) + (compile $File))) +; + + +; +; + + + (= + (role-chooser $Role $Chooser) + ( (player-method-parameter $Role $Param) (parameter $Param $Chooser))) +; + + + + (= + (player_method_parameter player player_method) True) +; + + (= + (player_method_parameter opponent opponent_method) True) +; + + + + (= + (role-file $Role $File) + ( (player-file-parameter $Role $Param) (parameter $Param $File))) +; + + + + (= + (set-role-file $Role $File) + ( (player-file-parameter $Role $Param) (set-parameter $Param $File))) +; + + + + + (= + (player_file_parameter player player_file) True) +; + + (= + (player_file_parameter opponent opponent_file) True) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (human-mode) + (det-if-then + (role-chooser $Role human) True)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (adjust-player-clock $Player $Time) + ( (remove-symbol &self + (time_used $Player $TOld)) + (is $TNew + (+ $TOld $Time)) + (add-symbol &self + (time_used $Player $TNew)))) +; + + +; +; + +; +; + + + (= + (reset-clock) + ( (reset-player-clock player) (reset-player-clock opponent))) +; + + + + (= + (reset-player-clock $Player) + ( (remove-all-symbols &self + (time_used $Player $_)) (add-symbol &self (time_used $Player 0)))) +; + + + +; +; + +; +; + + + (= + (print-clock) + ( (format "~*c~n" + (:: 40 45)) + (format "Clock times (in seconds):~n" Nil) + (print-player-clock player) + (print-player-clock opponent) + (format "~*c~n" + (:: 40 45)))) +; + + + + (= + (print-player-clock $Player) + ( (time-used $Player $Used) + (game-time-left $Player $Left) + (format "<~p>: \t~3d used, \t~3d left~n" + (:: $Player $Used $Left)))) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (time-out-outcome $Outcome) + ( (player-time-out player $PTime) + (player-time-out opponent $OTime) + (time-out-outcome $PTime $OTime $Outcome))) +; + + + (= + (time-out-outcome yes yes draw) + ( (set-det) (format "Both players are out of time!~n" Nil))) +; + + (= + (time-out-outcome no yes player) + ( (set-det) (format "<~p> is out of time~n" (:: opponent)))) +; + + (= + (time-out-outcome yes no opponent) + ( (set-det) (format "<~p> is out of time~n" (:: player)))) +; + + + +; +; + +; +; + +; +; + + + (= + (player-time-out $Player $Out) + ( (game-time-left $Player $Time) (det-if-then-else (=< $Time 0) (= $Out yes) (= $Out no)))) +; + + + + +; +; + +; +; + + + (= + (game-time-left $Player $Time) + ( (game-time-limit $Limit) + (time-used $Player $Used) + (is $Time + (max + (- $Limit $Used) 0)))) +; + + + + (= + (game-time-limit $Limit) + (parameter game-time-limit $Limit)) +; + + +; +; + + + (= + (clock-unlimit) + ( (set-parameter game-time-limit 99999999) + (set-parameter move-time-limit 99999999) + (set-parameter move-horizon 1) + (reset-clock))) +; + + + +; +; + + + + (= + (game-ends-in-outcome $SIn $Outcome) + ( (game-over $SIn) + (set-det) + (game-outcome $Outcome $SIn))) +; + + (= + (game-ends-in-outcome $SIn $Outcome) + (time-out-outcome $Outcome)) +; + + +; +; + +; +; + + + + (= + (game-over $SIn) + (game-over $SIn $_)) +; + + + + (= + (game-outcome $O $S) + (game-outcome $O $S $_)) +; + + + + + + !(dynamic (/ recorded-game-outcome 1)) +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (record-game-outcome $O) + ( (remove-all-symbols &self + (recorded_game_outcome $O)) + (add-symbol &self + (recorded_game_outcome $O)) + (write-outcome $O))) +; + + + + + (= + (write-outcome draw) + ( (format "~n~nThe game is over. Ends in a draw!~n" Nil) (set-det))) +; + + (= + (write-outcome $Player) + (format "~n~nThe game is over. ~p wins!~n" + (:: $Player))) +; + + +; +; + +; +; + +; +; + + + (= + (cleanup_state $S $S) True) +; + + + diff --git a/metagame/play/gen_menu.metta b/metagame/play/gen_menu.metta new file mode 100644 index 0000000..0679465 --- /dev/null +++ b/metagame/play/gen_menu.metta @@ -0,0 +1,318 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + +; +; + + + (= + (gen-top) + (generate)) +; + + +; +; + +; +; + +; +; + + + + (= + (generate) + ( (menu-command "~nEnter command ('help.' gives more information)~n" gen Nil) + (set-det) + (continue-generate))) +; + + (= + (generate) + ( (format "~nI did not understand your command. Please try again!~n" Nil) (generate))) +; + + +; +; + +; +; + +; +; + +; +; + + + + (= + (continue-generate) + (generate)) +; + + +; +; + +; +; + +; +; + + + + (= + (help-gen) + ( (help-gen1) (help-gen2))) +; + + + + (= + (help-gen1) + (format "\nGenerating a Game:\n------------------------------\ngames_library. => show games in library\ngenerate . => generate (and load) random game, save as .game\ngame . => loads .game as the current game\ncompile {on/off}. => set whether to compile symmetries when loading a game.\nquick. => short form to turn of compiling symmetries. \ndone. => return to top-level menu\n" Nil)) +; + + + + (= + (help-gen2) + (format "\nExamining Game and Changing System State\n-----------------------------------------\npieces. => show the names of the pieces in the current game\ndefine . => print the definition of in the current game\ngoals. => print the goals of the current game\nboard. => print board definition of the current game\nrules. => print the full rules of the current game\nset

. => set generator parameter

to value \nset

. => set generator parameter

('help set.')\nset. => show generator parameter settings\nrandomize => use random seed # (N = 1..10)\n(un)trace {options} => trace some system behavior ('help trace.') \ncd

. => change current directory to ('help cd.')\npwd. => show current directory name\nls. => show contents of current directory\nprolog. (abort) => abort to prolog\nquit. => exit session (back to shell)\n" Nil)) +; + + + + + (= + (done-gen) + (metagame)) +; + + + + (= + (set-gen $P $V) + (set-gen-parameter $P $V)) +; + + + (= + (set-gen $P) + (change-gen-param $P)) +; + + + (= + (set-gen) + (show-gen-parameters)) +; + + + + (= + (randomize-gen $N) + (randomize $N)) +; + + + + (= + (generate-gen $File) + (generate-and-load $File)) +; + + + (= + (generate-gen) + (generate-and-load random)) +; + + + + (= + (game-gen $File) + (load-game $File)) +; + + + + (= + (games-library-gen) + (games-library)) +; + + + + (= + (cd-gen $Dir) + (cd-print $Dir)) +; + + + + (= + (pwd-gen) + (pwd-print)) +; + + + + (= + (ls-gen) + (ls)) +; + + + + (= + (define-gen $PieceName) + (show-piece-definition $PieceName)) +; + + + + (= + (goals-gen) + (show-game-goals)) +; + + + + (= + (rules-gen) + (show-rules)) +; + + + + (= + (pieces-gen) + (show-piece-names)) +; + + + + (= + (board-gen) + (show-board)) +; + + + + (= + (quick-gen) + (set-parameter compile-symmetries off)) +; + + + + (= + (compile-gen $OnOff) + (set-parameter compile-symmetries $OnOff)) +; + + + + + (= + (restart-gen) + ( (format "~nRestarting ...~n" Nil) (metagame))) +; + + + + (= + (quit-gen) + (print-quit)) +; + + + + (= + (prolog-gen) + (print-abort)) +; + + + + (= + (abort-gen) + (print-abort)) +; + + + + (= + (verbose-gen) + (set-verbose)) +; + + + + (= + (quiet-gen) + (set-quiet)) +; + + + +; +; + +; +; + +; +; + + + + (= + (trace-gen $Module) + (set-tracing $Module on)) +; + + (= + (trace-gen $Module $Component) + (set-tracing $Module $Component on)) +; + + + + (= + (untrace-gen $Module) + (set-tracing $Module off)) +; + + (= + (untrace-gen $Module $Component) + (set-tracing $Module $Component off)) +; + + + + (= + (list-tracing-gen) + (list-tracing)) +; + + diff --git a/metagame/play/help.metta b/metagame/play/help.metta new file mode 100644 index 0000000..7b800f6 --- /dev/null +++ b/metagame/play/help.metta @@ -0,0 +1,518 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + + +; +; + +; +; + +; +; + + + + + (= + (help-top) + ( (help-top-general) + (help-tables) + (help-system))) +; + + + + (= + (help-top $F) + ( (help-top-entry $F $G) (call $G))) +; + + (= + (help-top help) + ( (help-top-topics $Topics) + (format "To select a topic, type 'help .'~n" Nil) + (format "Help in this menu is available on the following topics:~n" Nil) + (pwl $Topics))) +; + + + + (= + (help-top-topics $Topics) + ( (findall $Topic + (help-top-entry $Topic $_) $AllTopics) (sort $AllTopics $Topics))) +; + + + +; +; + +; +; + + + (= + (help_top_entry player help_player) True) +; + + (= + (help_top_entry show help_show) True) +; + + (= + (help_top_entry trace help_trace) True) +; + + (= + (help_top_entry cd help_cd) True) +; + + (= + (help_top_entry iterate help_iterate) True) +; + + (= + (help_top_entry weights help_weights) True) +; + + (= + (help_top_entry eval_fn help_eval_fn) True) +; + + (= + (help_top_entry evalfile help_evalfile) True) +; + + (= + (help_top_entry history help_history) True) +; + + (= + (help_top_entry clock help_clock) True) +; + + (= + (help_top_entry tables help_tables) True) +; + + (= + (help_top_entry advisors help_advisors) True) +; + + (= + (help_top_entry playernum help_playernum) True) +; + + + +; +; + + + + (= + (help-top-general) + (format "\nGenerating and Playing a Game:\n------------------------------\ngen. => enters menu for generating random games.\ngames_library. => show games in library\ngame . => loads .game as the current game\nevalfile . => loads .eval as eval tables for current game\nplayer

. => set player

to play color ('help player.')\nplayers . => set player as white, as black.\nplayers. => shows current players. \nstart. => start playing current game from initial position\nstart . => start playing current game from saved position \n\t ('help history')\nclock. => prints current game clock (help clock)\n" Nil)) +; + + + + + (= + (help-tables) + (format "\nConstructing and Using Analysis Tables\n--------------------------------------\nbuild. => builds tables using current advisors. \nshowstatic. => shows the static table values for all pieces.\nadvice

. => shows static advice for piece

of color .\nalladvisors. => shows current weights for all advisors.\nactive. => shows weights for only non-zero weighted advisors\nplayernum . => set numbered player to play color ('help playernum.')\nplayernums . => set numbered player as white, as black.\nhelp advisors. => more info on the advisors and what they do. \n" Nil)) +; + + + + + + + (= + (help-system) + ( (help-game) (help-state))) +; + + + + (= + (help-game) + (format "\nExamining Game\n--------------\npieces. => show the names of the pieces in the current game\ndefine . => print the definition of in the current game\ngoals. => print the goals of the current game\nboard. => print board definition of the current game\nrules. => print the full rules of the current game\n" Nil)) +; + + + + + (= + (help-state) + (format "\t\nChanging System State\n---------------------\nset

. => set parameter

to value (set global default)\nset

. => set parameter

to value , for player only\nunset => clears params specific to player \nset. => show parameter settings\nrandomize => use random seed # (N = 1..10)\nshow {options} => show configuration data ('help show.') \n(un)trace {options} => trace some system behavior ('help trace.') \ncd

. => change current directory to ('help cd.')\npwd. => show current directory name\nls. => show contents of current directory\nprolog. (abort) => abort to prolog\nquit. => exit session (back to shell)\nhelp help. => list of all additional help topics. \n" Nil)) +; + + + + + + (= + (help-playernum) + (format "See the file learning/tourney.pl for more info.~n" Nil)) +; + + + + (= + (help-player) + ( (help-player-color) + (help-player-options) + (help-player-example))) +; + + + + (= + (help-player-color) + (format "\nplayer .\n------------------------\nTells the system how the moves will be chosen for color .\n\n must be one of the following:\n\nwhite => the first player.\nblack => the second player.\n" Nil)) +; + + + + (= + (help-player-options) + ( (help-player-options-simple) (help-player-options-search))) +; + + + + (= + (help-player-options-simple) + (format "\n must be one of the following:\n\nSimple Players\n--------------\nhuman => chosen by a human using this interface.\nrandom => play a random legal move.\ninstant => play first legal move available (faster)\ncautious => plays first non-losing move available (faster)\nrandom_cautious => play random non-losing move \nrandom_aggressive => wins if can, else plays cautiously\n" Nil)) +; + + + + (= + (help-player-options-search) + (format "\nSearching Players\n-----------------\nalpha_beta => does alpha_beta search down to a fixed depth \n (specified by parameter). \n uses principal continuation heuristic.\n Bounded by same time limits and move ordering as\n iterate player.\niterate => iterative deepening alpha-beta search.\n uses either fixed or random ordering based on \n parameter.\n ('help iterate' for more info on this)\niterate_random => iterate player with random move ordering when all equal.\n ('help iterate' for more info on this)\niterate_fixed => iterate player with fixed ordering.\n" Nil)) +; + + + + + (= + (help-player-example) + (format "\nExample:\n\n player white human.\n player black random_aggressive.\n\nBoth players can be specified at once by the command:\n player .\n\n" Nil)) +; + + + + + (= + (help-cd) + (format "\ncd . => change current directory to \n---------\n\n must be an atom or between single quotes:\nExample:\n\n cd mygames.\n cd '~~/metagame/games/'.\n" Nil)) +; + + + +; +; + +; +; + +; +; + + + + (= + (help-com $_ $_ $_) + (help-commands)) +; + + + + (= + (help-com $_ $_ $_ $F) + ( (help-com-entry $F $G) (call $G))) +; + + (= + (help-com $_ $_ $_ help) + ( (help-com-topics $Topics) + (format "To select a topic, type 'help .'~n" Nil) + (format "Help in this menu is available on the following topics:~n" Nil) + (pwl $Topics))) +; + + + + (= + (help-com-topics $Topics) + ( (findall $Topic + (help-com-entry $Topic $_) $AllTopics) (sort $AllTopics $Topics))) +; + + + + (= + (help_com_entry notation help_move) True) +; + + (= + (help_com_entry move help_move) True) +; + + (= + (help_com_entry clock help_clock) True) +; + + (= + (help_com_entry query help_query) True) +; + + (= + (help_com_entry show help_show) True) +; + + (= + (help_com_entry trace help_trace) True) +; + + (= + (help_com_entry cd help_cd) True) +; + + (= + (help_com_entry iterate_random help_iterate) True) +; + + (= + (help_com_entry iterate help_iterate) True) +; + + (= + (help_com_entry advice help_advice) True) +; + + (= + (help_com_entry advisors help_advisors) True) +; + + (= + (help_com_entry weights help_weights) True) +; + + (= + (help_com_entry eval_fn help_eval_fn) True) +; + + (= + (help_com_entry evalfile help_evalfile) True) +; + + (= + (help_com_entry history help_history) True) +; + + + + + + (= + (help-commands) + ( (help-com-entry) + (help-com-selecting) + (help-system) + (help-com-state) + (help-syntax))) +; + + + + (= + (help-com-selecting) + (format "\nSPECIAL MOVE SELECTION METHODS:\n-------------------------------\nselect. => backtrack through available moves\nrandom. => play a random legal move\nrandom_aggressive => play a winning, or random non-losing move, in that order\nvictor. => play a move which wins immediately\nendgame. => play a move which ends the game immediately\ncautious. => play a move which blocks opponent's victory, if threatened\nmate. => play a move which forces a win in 2-ply\nthreaten. => play a move which threatens victory next move\ninstant. => play the first move generated (doesn't ask)\nalpha_beta {}. => does n-ply alpha-beta search (or DEPTH parameter if no n)\niterate. => does iterative-deepening search until timeout. \nadvice. => shows comments used in eval fn on current position (help)\nadvice => shows local advice for piece now at (x,y)\nevaluate. => evaluate current position using current parameters. \n" Nil)) +; + + + + + (= + (help-com-state) + (format "\nEXAMINING AND MODIFYING STATE OF GAME\n-------------------------------------\ndisplay. => print current state\nclock. => prints current game clock (help clock)\nquery. => computes some function on the current position (help query)\nsetup. => enters menu for setting up board positions\npass. => transfer control to the other player (ie null move)\naccess. => access state from a command level\ncheckpoint . => record current state under name (for debugging)\nrestore . => sets current state to that checkpointed as name \nrestart. => abandon current game, choose new game and players\nevalfile .=> loads .eval as eval tables for current game\n (help evalfile)\nnext (prev) => goto next (or previous) th position (help history)\n" Nil)) +; + + + + + (= + (help-com-entry) + (format "\nBASIC MOVE ENTRY: \n-----------------\n => plays move ('help notation' for more information)\n" Nil)) +; + + + + (= + (help-syntax) + (format "\nNote that all keyboard input can contain newlines, and that a period\nsignals the end of the input/command.\n" Nil)) +; + + + + + + (= + (help-move) + ( (help-move-basic) (help-move-completion))) +; + + + + (= + (help-move-basic) + (format "\nBASIC MOVE ENTRY: \n-----------------\nThis follows the grammatical notation for moves, \nillustrated as follows:\n\nBasic Movements, eg:\n white king (5,1) -> (5,2). \n\nBasic Movements with a removal capture, eg:\n white king (5,1) -> (5,2) x black rook (4,1).\n\nPossession captures indicate player who will possess:\n white king (5,1) -> (5,2) x black rook (4,1) (white).\n\nMultiple Captures, eg: (if bug captures <-1,0> by {retrieve clobber})\n white bug (4,1) -> (3,1) x white fish (3,1) black bug (5,1).\n\nContinued Captures, eg:\n white checker (3,3) -> (5,5) x black checker (4,4);\n white checker (5,5) -> (3,7) x black king (4,6).\n\nPlacing a piece from a player's hand, eg:\n white king (white) -> (5,1).\n\nPromoting a piece which moved to or past the promote_rank.\n If player promotes, this happens at end of his turn:\n white pawn (2,7) -> (2,8); promote (2,8) white queen.\n If opponent promotes, this happens at start of his turn:\n promote (2,8) black queen; black queen (2,8) -> (2,5).\n\n" Nil)) +; + + + + (= + (help-move-completion) + (format "\nMOVE COMPLETION: (when COMPLETIONS parameter is ON)\n----------------\nInstead of the full grammatical move notation, you can enter\na sequence of words which occurs in the complete move notation.\nThis will match all moves containing those words in that order,\npossibly with other words in-between.\n\nUnlike the mode for entry of full grammatical move notations,\nsquares are here refered to in a more convenient form:\n\t(X,Y)\nwhere X is the letter for that column, and Y is the number for the row.\n\nSome examples of moves to be completed are:\n\npawn. => completes to moves involving a pawn.\nwhite (c,3) ->. => completes to moves moving a white piece from (c,3).\nx. => completes to moves which capture something.\nx rook. => completes to moves which capture a rook.\npromote. => completes to moves which enter promotion zone.\n. => completes to any legal moves.\n" Nil)) +; + + + + + (= + (help-advice) + (format "\nadvice\n------\nPrints the advice regarding the current position, from all active\nadvisors. This advice will be weighted according to the values of the\nparamters to determine the overall evaluation of the position. \n\nadvice \n------------------\nGives only the local advice for the piece at in the current\nposition. \n\nExample:\n\tadvice f 4. ==> Will give local advice for whatever piece is there.\n advice. ==> Gives all advice, including global advice. \n\nhelp advisors ==> Gives more info on what advisors do. \n" Nil)) +; + + + + + (= + (help-query) + (format "\nquery .\n------------------------\nCalls a querying function on its arguments.\n\n must be one of the following:\n\nmobility => prints number of moves available for each player\nmaterial => prints number of pieces on board for each player\ngoal => prints whether a goal has been achieved \n\nThese functions have an optional argument, a :\n\nplayer => returns value for white only\nopponent => returns value for black only\n\nExample:\n\n query mobility player.\n query material opponent.\n query goal.\n ~n" Nil)) +; + + + + + + (= + (help-show) + (format "\nshow .\n----------------------------\nCalls a showing function on its arguments.\n\n must be one of the following:\n\nweights => prints weight vectors for eval fns\nweights => prints weight vector for eval fn for \n is {player, opponent, or default}\n\nExample:\n\n show weights.\t\n show weights player.\n show weights default.\n ~n" Nil)) +; + + + + + (= + (help-weights) + (format "\nAccessing Evaluation Function Weights\n-------------------------------------\nThe weights used by a particular player can be changed by the\ncommand:\n\tweight

MATERIAL MOBILITY. (negative values must be quoted)\nExample:\n\tweight player 5 1.\n\tweight opponent '-1' 0.\nWould make player value pieces and moves positively, \nwith pieces worth five times the value of each move,\nand would make opponent prefer losing material, and not \ncare about mobility. \n\nNote that if a weight is set to 0, no time is spent in counting\nthat feature in a position.\n\nTo view the weights: \n\tshow weights. ==> shows weights or both players\n\tshow weights . ==> shows weights for \n" Nil)) +; + + + + (= + (help-eval-fn) + (format "\nEVALUATION FUNCTION\n--------------------\nThe default evaluation function is based on\nmaterial difference and mobility difference between the two \nplayers, where PLAYER (white) prefers positive differences,\nand OPPONENT (black) prefers negative differences.\n\nThe function is: \n\tEVAL = EVAL(PLAYER) - EVAL(OPPONENT)\nwhere\n\tEVAL(P) = WEIGHT(P,MATERIAL)*MATERIAL(P)\n - WEIGHT(P,MOBILITY)*MOBILITY(P)\nand\n\tMATERIAL(P) = Number of pieces P has on board\n\tMOBILITY(P) = Number of legal moves P has on board\n\nFor info on viewing and modifying these weights, (help weights)\n" Nil)) +; + + + + + (= + (help-evalfile) + (format "\nEVALUATION FUNCTION TABLES\n--------------------------\nevalfile . => loads .eval as eval tables for current game\n\nSome example tables are found in:\n 'Metagame/games/chess.eval'\n 'Metagame/games/turncoat.eval'\n \nIf you create your own for a specific game, these can be loaded\nin either before starting a game (top-level menu), or\nwhen it is the human's turn to make a move (move command menu).\n\nThe searching players ('help player') make use of whichever table file\nis currently loaded. \n\nThe following parameters are useful with evaluation tables:\n : relative weight to give piece-square tables \n : relative weight to give specific material tables\n : relative weight to give a player for having\n each piece of his color on the board.\n : (not implemented)\n : (not implemented)\n" Nil)) +; + + + + + (= + (help-iterate) + (format "\nThe player\n---------------------------\nThis player performs an iterative deepening alpha-beta search.\nIt uses the principal continuation heuristic. \nMove ordering is determined by the paramer ORDERING:\n\trandom: choose a random move when all evaluated equal.\n fixed: choose the first move found when all evaluated equal. \n\nThe iterative searcher will end the search after it has run out\nof time, based on the parameter: .\nFor example, the command:\n\tset move_time_limit 20000. \nwill force it to stop its search after 20 seconds (20,000 msec).\n\nNote that a player loses the game if it uses more than \nmsecs, so set this with the command:\n\tset game_time_limit 3600000. (for 1 hour time-limit)\n\nMore info is available about the current eval fn (help eval_fn).\n\nSome tracing information is available on this player, (help trace). \n ~n" Nil)) +; + + + + + (= + (help-trace) + ( (help-trace-general) + (help-trace-play) + (help-trace-ab) + (help-trace-gen))) +; + + + + (= + (help-trace-general) + (format "\ntrace {}.\nuntrace {}.\n-------------------------------\nEnables or disables tracing some component of a module.\nIf the module does not have any components, no component\nis needed here.\n\nListing traced Modules\n----------------------\nTo list the modules which are currently being traced, do:\n\tlist_tracing.\n\nTraceable Modules\n-----------------\nCurrently, the following tracing modules might be useful:\n ~n" Nil)) +; + + + + (= + (help-trace-play) + (format "\nVerbosity when playing games (play) \n-----------------------------------\n\tstate: print state as moves are chosen by players.\n move: print move as moves are chosen by players. \n clock: print the clock as moves are played. \n\nThese are all set to ON by default whenever a \nhuman is playing. \n\nExample: \n\ttrace play state. => turns this on\n\tuntrace play clock. => turns this off\n\n" Nil)) +; + + + + + + (= + (help-trace-ab) + (format "\nTracing Alphabeta (ab) Search\n-----------------------------\n\tordering: info regarding move ordering heuristics\n\tvalue: info regarding value of moves found during search\n also traces principal continuations \n\tresources: info regarding resource consumption during search\n timing: info on timeout checks during search\n\titeration: info on time taken by each iteration of the search\n eval: show evaluation of each node evaluated.\n expand: show each node as it is expanded. \n advice: show influence on evals for each node evaluated.\n state: print each state visited. \n\nExample: \n\ttrace ab ordering. => turns this on\n\tuntrace ab value. => turns this off\n\n" Nil)) +; + + + + + (= + (help-trace-gen) + (format "\nTracing Game Generation (gen) \n-----------------------------\n\tgoals: info goal generation\n\tsimplify: info on goal simplification\n subsume: info on goal redundancy checking and elimination\n\tpieces: info on piece generation.\n\nExample: \n\ttrace gen pieces. => turns this on\n\tuntrace gen subsume. => turns this off\n" Nil)) +; + + + +; +; + +; +; + +; +; + + + + (= + (help-accept) + (format "\nYou can accept this choice, backtrack, or abort:\n\nyes. (y) => accept this choice\nnext. (n,no) => reject this choice and consider next (if any)\nabort. => accept no choices, go back to menu\nhelp. => show this list\n" Nil)) +; + + + + diff --git a/metagame/play/help_advisors.metta b/metagame/play/help_advisors.metta new file mode 100644 index 0000000..0dc8188 --- /dev/null +++ b/metagame/play/help_advisors.metta @@ -0,0 +1,204 @@ +; +; + +; +; + +; +; + +; +; + + + + (= + (help-advisors) + (print-advisors)) +; + + + + + (= + (print-advisors) + ( (advisor-herald $H) + (format "~s~n" + (:: $H)) + (whenever + (print-advisor $A) + (format "~n~n" Nil)))) +; + + + + + (= + (advisor_herald "Explanation of ADVISORS\n-----------------------\nFollowing is the list of all advisors with a brief explanation.\nAlso shown (in parens) is the current value for each advisor.\nFor more information, consult the papers or source-code.\n") True) +; + + + + (= + (print-advisor $A) + ( (advisor-weight $A $W) + (advhelp $A $Help) + (format "<~p> (~p) ~n~s" + (:: $A $W $Help)))) +; + + + + + (= + (advhelp gen_material "Gives 1 point for each white piece, -1 for black.") True) +; + + + (= + (advhelp material "Uses user-defined material function if available (help evalfile).") True) +; + + + (= + (advhelp square "Uses user-defined piece-square table if available (help evalfile).") True) +; + + + (= + (advhelp lthreat "Gives points for each enemy piece a piece can capture.") True) +; + + + (= + (advhelp potent "Like lthreat, but reduces each threat value if defended.") True) +; + + + (= + (advhelp gthreat "Value only for best of all lthreats.") True) +; + + + (= + (advhelp pthreat "Value only for best of all potent threats.") True) +; + + + (= + (advhelp vital "Doesn't like leaving pieces attacked when enemy achieves goal \nby removing them. Only sensitive when there are VITAL_NUMBER pieces left.") True) +; + + + (= + (advhelp dynamic_mobility "1 point for each move piece makes in current position.") True) +; + + + (= + (advhelp static_mobility "1 point each move piece makes from square on empty board.") True) +; + + + (= + (advhelp eventual_mobility "Points for each square piece can ever reach from square on empty board,\ndiscounted by how many moves it takes piece to get there from square. The discount\nfunction is controlled by DISCOUNT parameter, either INVERSE or EXPONENT.") True) +; + + + (= + (advhelp gmovmob "Sum of dynamic_mobility for all player's pieces.") True) +; + + + (= + (advhelp gcapmob "1 point for each capturing-move in current position.") True) +; + + + (= + (advhelp arrive_distance "Favors pieces on squares close to achieving arrival goals.") True) +; + + + (= + (advhelp promote_distance "Favors getting pieces close to promotion. \nValue based on cost to get to promotion square, and value of best piece the piece\ncan eventually promote into.") True) +; + + + (= + (advhelp possess "Points for each piece player has in hand. Generally the value\nis the average or max of the values it would have when placed on the board.") True) +; + + + (= + (advhelp initprom "Anticipates points which will follow when player init-promotes a piece\nnext turn. Value will be value of best choice that player can make.") True) +; + + + (= + (advhelp random "Adds a random noise to position value, in range [RANDOM_MIN,RANDOM_MAX].\nNote that this value will be multiplied by the weight \nattached to this advisor [as is the case for all advisors.]") True) +; + + + + (= + (advhelp static "The following advisors are used to build the static tables for each piece. \nThis advisor determines how much to weigh the static values vs. other advisors.") True) +; + + + (= + (advhelp victims "Point for each piece this piece could someday capture.") True) +; + + + (= + (advhelp immunity "Points for each enemy piece which cannot someday capture this piece.") True) +; + + + (= + (advhelp giveaway "Points for each piece we own which can someday capture this piece.") True) +; + + + (= + (advhelp eradicate "Points for pieces which enemy would like to eradicate.") True) +; + + + (= + (advhelp stalemate "Degree to which piece might contribute to stalemate goals.") True) +; + + + (= + (advhelp arrive "Degree to which piece might contribute to arrive goals.") True) +; + + + (= + (advhelp max_static_mob "Maximum static mobility piece has.") True) +; + + + (= + (advhelp max_eventual_mob "Maximum eventual mobility piece has.") True) +; + + + (= + (advhelp avg_static_mob "Average static mobility piece has.") True) +; + + + (= + (advhelp avg_eventual_mob "Average eventual mobility piece has.") True) +; + + + (= + (advhelp dominate "Not used.") True) +; + + + diff --git a/metagame/play/history.metta b/metagame/play/history.metta new file mode 100644 index 0000000..fae9a69 --- /dev/null +++ b/metagame/play/history.metta @@ -0,0 +1,545 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (help-history) + ( (help-history-overview) + (help-history-top) + (help-history-com))) +; + + + + (= + (help-history-overview) + (format "\nGame History Management\n-----------------------\nThese routines allow you to review the history of the current\ngame. To use them, you must set the white player to be human,\notherwise the program will begin playing from the chosen position\nand there will be no chance to review the past game. \n\nIn addition, see the menu: EXAMINING AND MODIFYING STATE OF GAME,\nwhich allows you to save and restore important positions even when in\nthe middle of a game. Note however that these positions will not\nnecessarily be hooked into the history mechanisms discussed here. \n" Nil)) +; + + + + (= + (help-history-top) + (format "\nFrom top menu:\nsave : Save record of current game as .rec\nload : Load record of game .rec as current history. \nstart : Start game in pos checkpointed as \n" Nil)) +; + + + + (= + (help-history-com) + (format "\nFrom move menu: \nnext : Advance positions in current game history.\nprev : Regress positions in current game history.\nnext: next 1.\nprev: prev 1.\nclear history: Delete *all* history entries and saved positions.\n\nNote the playing a new move erases whatever moves may have come after \nin the present game record. \n" Nil)) +; + + + + (= + (next-com $M $SIn $SOut) + (forward-hist 1 $SOut)) +; + + + (= + (next-com $M $SIn $SOut $N) + (forward-hist $N $SOut)) +; + + + + (= + (prev-com $M $SIn $SOut) + (reverse-hist 1 $SOut)) +; + + + (= + (prev-com $M $SIn $SOut $N) + (reverse-hist $N $SOut)) +; + + + + (= + (clear-com $_ $_ $_ history) + (clear-history)) +; + + +; +; + + + + (= + (save-top $Game) + (print-game-record-to-file $Game)) +; + + + + (= + (save-com $_ $_ $_ $Game) + (print-game-record-to-file $Game)) +; + + + + (= + (load-top $Game) + (read-game-record-from-file $Game)) +; + + + + (= + (load-com $_ $_ $_ $Game) + (read-game-record-from-file $Game)) +; + + + +; +; + + + + !(dynamic (, (/ follows 3) (/ current-pos-name 1))) +; + + + + + (= + (forward-hist $N $SOut) + ( (current-pos-name $NameIn) + (forward-name $N $NameIn $NameOut) + (checkpoint $NameOut $SOut) + (set-current-pos-name $NameOut) + (print-state $SOut) + (last-move $LastMove) + (print-notation $LastMove))) +; + + + + (= + (reverse-hist $N $SOut) + ( (current-pos-name $NameIn) + (forward-name $N $NameOut $NameIn) + (checkpoint $NameOut $SOut) + (set-current-pos-name $NameOut) + (print-state $SOut) + (last-move $LastMove) + (print-notation $LastMove))) +; + + + + + (= + (forward_name 0 $NameIn $NameIn) True) +; + + (= + (forward-name $N $NameIn $NameOut) + ( (> $N 0) + (is $N1 + (- $N 1)) + (follows-history $NameIn $Name1) + (forward-name $N1 $Name1 $NameOut))) +; + + + + (= + (follows-history $N1 $N2) + (follows $N1 $_ $N2)) +; + + + (= + (follows-history $N1 $Move $N2) + (follows $N1 $Move $N2)) +; + + + + + (= + (initialize-history $SIn) + ( (checkpoint-state init $SIn) (set-current-pos-name init))) +; + + + +; +; + +; +; + + + (= + (current-position $Pos) + ( (current-pos-name $Name) (checkpoint $Name $Pos))) +; + + +; +; + +; +; + +; +; + + + (= + (last-move $Move) + ( (current-pos-name $Name) (follows-history $_ $Move $Name))) +; + + + + + (= + (set-current-pos-name $Name) + ( (remove-all-symbols &self + (current_pos_name $_)) (add-symbol &self (current_pos_name $Name)))) +; + + + + (= + (change-current-pos-name $Name $Next) + ( (remove-symbol &self + (current_pos_name $Name)) (add-symbol &self (current_pos_name $Next)))) +; + + + + + (= + (set-follows-history $Name $Move $Next) + ( (clear-history-after $Name) (add-symbol &self (follows $Name $Move $Next)))) +; + + + + (= + (add-state-to-history $Move $State) + ( (checkpoint-state-gensym $State $Next) (update-history $Move $Next))) +; + + + + (= + (update-history $Move $Next) + ( (change-current-pos-name $Name $Next) (set-follows-history $Name $Move $Next))) +; + + + + (= + (clear-history) + ( (remove-all-symbols &self + (checkpoint $_ $_)) (remove-all-symbols &self (follows $_ $_ $_)))) +; + + + + (= + (clear-history-visible) + (or + (, + (clear-history-after $Name) + (fail)) True)) +; + + + + (= + (clear-history-after $Name) + (det-if-then-else + (remove-symbol &self + (follows $Name $_ $Next)) + (, + (remove-symbol &self + (checkpoint $Next $_)) + (clear-history-after $Next)) True)) +; + + +; +; + +; +; + + + (= + (history-state $State) + (checkpoint init $State)) +; + + (= + (history-state $State) + ( (follows-history $Name1 $Name2) (checkpoint $Name2 $State))) +; + + + + (= + (restore-state $N $State) + (det-if-then-else + (, + (current-predicate checkpoint $_) + (checkpoint $N $State)) + (, + (checkpoint $N $State) + (format "~nState named: <~w> now current state~n" + (:: $N))) + (format "~nError: No state: <~w> has been is checkpointed~n" + (:: $N)))) +; + + + + + (= + (checkpoint-state $State) + (checkpoint-state-gensym $State $Name)) +; + + + + (= + (checkpoint-state-gensym $State $Name) + ( (gensym checkpoint $Name) (checkpoint-state $Name $State))) +; + + + + (= + (checkpoint-state $Name $State) + ( (remove-all-symbols &self + (checkpoint $Name $_)) + (add-symbol &self + (checkpoint $Name $State)) + (format "~nState checkpointed under index: <~w>~n" + (:: $Name)))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + +; +; + +; +; + + + (= + (move-string $Move $MoveString) + ( (follows-history $Name1 $Name2) + (checkpoint $Name1 $State1) + (checkpoint $Name2 $State2) + (det-if-then + (completed-move $MoveString $Move $State1 $State2) True))) +; + + + + (= + (print-next-move $MoveString) + ( (move-string $Move $MoveString) + (print-tokens $MoveString) + (nl))) +; + + + + + (= + (read-next-move $MoveString) + ( (read-keyboard-tokens $MoveString) + (current-position $State1) + (det-if-then + (completed-move $MoveString $Move $State1 $State2) True) + (add-state-to-history $Move $State2))) +; + + + + (= + (print-game-record) + (or + (, + (print-next-move $_) + (fail)) True)) +; + + + + (= + (get-initialize-history $In) + ( (get-initial-state $In) (initialize-history $In))) +; + + + + + (= + (read-game-record) + ( (get-initialize-history $In) (read-record-moves))) +; + + + + (= + (read-record-moves) + ( (read-next-move $_) + (set-det) + (read-record-moves))) +; + + (= read_record_moves True) +; + + + + +; +; + +; +; + + + (= + (print-game-record-to-file $File) + ( (sys-suffixed-filename $File record $GameFile) + (format "~nWriting game record to file: ~w~n" + (:: $GameFile)) + (with-output-file $GameFile append print-game-record))) +; + + + +; +; + +; +; + + + (= + (read-game-record-from-file $File) + ( (sys-suffixed-filename $File record $GameFile) + (format "~nReading game record from file: ~w~n" + (:: $GameFile)) + (see $GameFile) + (read-game-record) + (seen))) +; + + + + diff --git a/metagame/play/interface.metta b/metagame/play/interface.metta new file mode 100644 index 0000000..765e492 --- /dev/null +++ b/metagame/play/interface.metta @@ -0,0 +1,1289 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + + + !(my-ensure-loaded (library shells)) +; + + !(my-ensure-loaded (library menus)) +; + + + + +; +; + +; +; + +; +; + + + (= + (ask-move $Move $SIn $SOut) + ( (format "~nEnter a move or command (help gives more information)~n" Nil) + (read-keyboard-tokens $String) + (process-move-or-command $String $Move $SIn $S1) + (set-det) + (really-get-move $Move $SIn $S1 $SOut))) +; + + (= + (ask-move $Move $SIn $SOut) + ( (control $Player $SIn) + (format "~n~p failed to select a legal move. Please try again!~n" + (:: $Player)) + (format "~n ('display.' to redisplay board)~n" Nil) + (ask-move $Move $SIn $SOut))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (really-get-move $Move $SIn $S1 $S1) + ( (nonvar $Move) + (nonvar $S1) + (set-det))) +; + + (= + (really-get-move $Move $SIn $S1 $SOut) + ( (nonvar $S1) + (set-det) + (ask-move $Move $S1 $SOut))) +; + + (= + (really-get-move $Move $SIn $S1 $SOut) + (ask-move $Move $SIn $SOut)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (process-move-or-command $MoveString $Move $SIn $SOut) + (process-command $MoveString com + (:: $Move $SIn $SOut))) +; + + (= + (process-move-or-command $MoveString $Move $SIn $SOut) + ( (nl) + (set-parsing-mode) + (move-notation $Move $MoveString) + (set-det) + (verbosely-format "~nTrying Move: ~p~n" + (:: $Move)) + (select-move $Move $SIn $SOut))) +; + + (= + (process-move-or-command $MoveString $Move $SIn $SOut) + ( (format "Attempting to find a completion for move: " Nil) + (print-tokens $MoveString) + (nl) + (parameter completions on) + (choose-completed-move $MoveString $Move $SIn $SOut))) +; + + + + +; +; + +; +; + + + (= + (select-move $Move $SIn $SOut) + ( (legal $Move $SIn $SOut) + (format "~nAfter:~n" Nil) + (print-state $SOut) + (print-notation $Move) + (ask-accept-choice $Answer) + (det-if-then-else + (= $Answer abort) + (, + (set-det) + (fail)) + (= $Answer yes)))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (printing-choose $Method $Move $SIn $SOut) + ( (=.. $Chooser + (:: $Method $Move $SIn $SOut)) (selecting-choice (, (timing $Chooser) (format "~nAfter:~n" Nil) (print-state $SOut) (print-notation $Move))))) +; + + +; +; + +; +; + +; +; + + + (= + (random-printing-choose $Method $Move $SIn $SOut) + ( (=.. $Chooser + (:: $Method $Move $SIn $SOut)) (selecting-choice (, (timing (random-success $Chooser)) (format "~nAfter:~n" Nil) (print-state $SOut) (print-notation $Move))))) +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (compatible $Op $Tokens) + ( (with-alpha-squares (, (move-notation $Op $FullToks) (mesh $Completion $Tokens $FullToks))) (verbosely-format "~nTokens: ~w~nCompletion: ~w~nFull: ~w~n" (:: $Tokens $Completion $FullToks)))) +; + + + + + (= + (completed-move $Tokens $Move $SIn $SOut) + ( (legal $Move $SIn $SOut) + (compatible $Move $Tokens) + (acceptable $Move $SIn $SOut))) +; + + + + (= + (acceptable $Move $SIn $SOut) + (det-if-then-else + (parameter safety on) + (check-safe-move $Move $SIn $SOut) True)) +; + + + + + (= + (choose-completed-move $Tokens $Move $SIn $SOut) + ( (= $Chooser + (completed-move $Tokens $Move $SIn $SOut)) (selecting-choice (, (timing $Chooser) (format "~nAfter:~n" Nil) (print-choice $Move $SIn $SOut))))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (print-choice $Move $SIn $SOut) + ( (current-output $O) + (flush-output $O) + (tracing-play state + (print-state $SOut)) + (tracing-play move + (print-notation $Move)) + (linebreak))) +; + + + + (= + (linebreak) + (format "\n===============================================================\n" Nil)) +; + + + + (= + (print-notation $Op) + ( (set-printing-mode) + (with-alpha-squares (move-notation $Op $Notate)) + (set-det) + (format "Notated Move played: ~n" Nil) + (print-tokens $Notate) + (nl) + (nl) + (verbosely-format "~n~nFull Move played: ~p~n" + (:: $Op)))) +; + + (= + (print-notation $Op) + (format "Move played: ~p~n" + (:: $Op))) +; + + + + + (= + (print-move $Move) + ( (set-printing-mode) + (with-alpha-squares (move-notation $Move $Notate)) + (set-det) + (print-tokens $Notate) + (nl))) +; + + (= + (print-move $Move) + (format "Move: ~p~n" + (:: $Move))) +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + + + (= + (selecting-choice $Goal) + ( (call $Goal) + (ask-accept-choice $Answer) + (det-if-then-else + (= $Answer abort) + (, + (set-det) + (fail)) + (, + (= $Answer yes) + (set-det))))) +; + + + + + + (= + (ask-accept-choice yes) + ( (parameter confirm-choices off) (set-det))) +; + + (= + (ask-accept-choice $Answer) + ( (menu-command "~nAccept this choice? (yes, next, abort, help)~n" accept + (:: $Answer)) (set-det))) +; + + (= + (ask-accept-choice $Answer) + ( (format "~n~p failed to answer appropriately. Please try again!~n" + (:: You)) (ask-accept-choice $Answer))) +; + + +; +; + +; +; + +; +; + + + + (= + (yes-accept yes) + (format "~nChoice accepted.~n" Nil)) +; + + + (= + (y-accept yes) + (yes-accept yes)) +; + + + + (= + (next-accept next) + (format "~nTrying next choice.~n" Nil)) +; + + + (= + (no-accept next) + (next-accept next)) +; + + + (= + (n-accept next) + (next-accept next)) +; + + + + + (= + (abort-accept abort) + (format "~nAttempt aborted!~n" Nil)) +; + + + + (= + (help-accept $Answer) + ( (help-accept) (ask-accept-choice $Answer))) +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + + +; +; + + + +; +; + +; +; + +; +; + + + + (= + (select-com $Move $SIn $SOut) + (select-move $Move $SIn $SOut)) +; + + + + (= + (display-com $Move $SIn $_) + ( (format "~nCurrent State: ~n" Nil) (print-state $SIn))) +; + + + + (= + (restart-com $_ $_ $_) + ( (format "~nRestarting ...~n" Nil) (metagame))) +; + + + + (= + (quit-com $_ $_ $_) + (print-quit)) +; + + + + + (= + (prolog-com $_ $_ $_) + (print-abort)) +; + + + + (= + (abort-com $_ $_ $_) + (print-abort)) +; + + + + (= + (verbose-com $_ $_ $_) + (set-verbose)) +; + + + + (= + (quiet-com $_ $_ $_) + (set-quiet)) +; + + + + + (= + (break-com $_ $_ $_) + (format "~nBreak command not implemented." Nil)) +; + + + + (= + (set-com $_ $_ $_ $P $V) + (set-parameter $P $V)) +; + + + (= + (set-com $_ $_ $_) + (show-parameters)) +; + + +; +; + + + + (= + (setg-com $_ $_ $_ $P $V) + (add-global $P $V)) +; + + + + (= + (showg-com $_ $_ $_) + (showg)) +; + + + + + (= + (randomize-com $_ $_ $_ $N) + (randomize $N)) +; + + + + (= + (pieces-com $_ $_ $_) + (show-piece-names)) +; + + + + (= + (show-piece-names) + ( (player-current-game $Game) + (game-piece-names $Game $Names) + (format "\nThe current game has the following pieces: \n~p\nNote that pieces are displayed on the board by the their first letter. \n" + (:: $Names)))) +; + + + + (= + (game-piece-names $Game $Names) + (setof $Name + (game-piece-name $Game $Name) $Names)) +; + + + + (= + (define-com $_ $_ $_ $PieceName) + (show-piece-definition $PieceName)) +; + + + + (= + (show-piece-definition $PieceName) + ( (player-current-game $G) + (game-piece-def $G $PieceName $Def) + (set-det) + (set-printing-mode) + (piece-def $Def $String Nil) + (set-parsing-mode) + (format "~nPiece <~p> is defined as follows: ~n~n" + (:: $PieceName)) + (print-tokens $String) + (nl) + (nl))) +; + + (= + (show-piece-definition $PieceName) + (format "~nSorry, Piece <~p> is not defined in this game.~n~n" + (:: $PieceName))) +; + + + + + (= + (rules-com $_ $_ $_) + (show-rules)) +; + + + + (= + (board-com $_ $_ $_) + (show-board)) +; + + + + (= + (goals-com $_ $_ $_) + (show-game-goals)) +; + + + + + + (= + (cd-com $_ $_ $_ $Dir) + (cd-print $Dir)) +; + + + + + (= + (pwd-com $_ $_ $_) + (pwd-print)) +; + + + + (= + (ls-com $_ $_ $_) + (ls)) +; + + +; +; + +; +; + +; +; + + +; +; + + + (= + (access-com $Move $SIn $SOut) + ( (format "\nEnter a goal of the form:\n\tSIn^SOut^goal(...,SIn,...,SOut).\nCalling this goal will bind the current state to SOut,\nand return you to the move selection menu.\nTo accept the current state as your move, use the command: accept.\n\n" Nil) + (read (^ $SIn (^ $SOut $Goal))) + (call $Goal))) +; + + +; +; + +; +; + + + (= + (call-com $_ $SIn $SOut) + ( (get-state-goal $Goal) (call-state-goal $Goal $SIn $SOut))) +; + + + + (= + (get-state-goal $Goal) + ( (format "\nEntering a goal of the form:\n\tgoal(a,b,...)\nWill result in the following 'statified' goal being called:\n\tgoal(a,b,...,SIn,SOut)\nIf successful, this goal will bind the current state to SOut,\nand return you to the move selection menu.\nTo accept the current state as your move, use the command: accept.\n\n" Nil) (read $Goal))) +; + + + + (= + (call-state-goal $Goal $SIn $SOut) + ( (=.. $Goal + (Cons $H $Args)) + (append $Args + (:: $SIn $SOut) $NewArgs) + (=.. $SGoal + (Cons $H $NewArgs)) + (det-if-then-else + (current-predicate $_ $SGoal) + (call $SGoal) + (, + (format "*** Unknown_goal: ~w~n" + (:: $SGoal)) + (fail))))) +; + + + + +; +; + +; +; + + + (= + (restore-com $_ $SIn $SOut $Name) + (restore-state $Name $SOut)) +; + + + +; +; + + + (= + (accept-com accept $SIn $SIn) + (format "Current state accepted as chosen move.~n" Nil)) +; + + +; +; + + + (= + (checkpoint-com $_ $SIn $_) + (checkpoint-state $SIn)) +; + + +; +; + + (= + (checkpoint-com $_ $SIn $_ $Name) + (checkpoint-state $Name $SIn)) +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (query-com $_ $SIn $_ goal) + (query-goal $SIn)) +; + + + (= + (query-com $_ $SIn $_ material) + (query-material $SIn)) +; + + (= + (query-com $_ $SIn $_ mobility) + (query-mobility $SIn)) +; + + + (= + (query-com $_ $SIn $_ goal $Player) + (query-goal $SIn $Player)) +; + + (= + (query-com $_ $SIn $_ material $Player) + (query-material $SIn $Player)) +; + + (= + (query-com $_ $SIn $_ mobility $Player) + (query-mobility $SIn $Player)) +; + + + + + (= + (query-goal $SIn) + ( (format "Checking goals ...~n" Nil) (det-if-then-else (timing (game-outcome $O $SIn)) (format "Outcome is ~p~n" (:: $O)) (format "Game is not over yet.~n" Nil)))) +; + + + + (= + (query-goal $SIn $Player) + ( (format "Checking goals for <~p> ...~n" + (:: $Player)) (det-if-then-else (timing (goal-achieved $Player $SIn)) (format "<~p> has achieved a goal!~n" (:: $Player)) (format "<~p> has not achieved a goal.~n" (:: $Player))))) +; + + +; +; + + + (= + (goal-achieved $P $S) + (goal-achieved $P $_ $S $_)) +; + + + + (= + (query-goal-slow-com $_ $SIn $_) + (query-goal-slow $SIn)) +; + + + (= + (query-goal-slow $SIn) + ( (format "Checking goals ...~n" Nil) (det-if-then-else (timing (game-outcome player $SIn)) (format "<~p> has achieved a goal!~n" (:: player)) (format "Player has not won yet.~n" Nil)))) +; + + + + + (= + (query-material $SIn) + ( (query-material $SIn player) (query-material $SIn opponent))) +; + + + (= + (query-material $S $Player) + ( (format "Counting material for <~p> ...~n" + (:: $Player)) + (timing (material $Player $S $Mat)) + (format "<~p> has material count of ~p~n" + (:: $Player $Mat)))) +; + + + + + (= + (query-mobility $SIn) + ( (query-mobility $SIn player) (query-mobility $SIn opponent))) +; + + + (= + (query-mobility $S $Player) + ( (format "Counting mobility for <~p> ...~n" + (:: $Player)) + (timing (mobility $Player $S $Mat)) + (format "<~p> has mobility count of ~p~n" + (:: $Player $Mat)))) +; + + + +; +; + +; +; + +; +; + + + + (= + (trace-com $_ $_ $_ $Module) + (set-tracing $Module on)) +; + + (= + (trace-com $_ $_ $_ $Module $Component) + (set-tracing $Module $Component on)) +; + + + + (= + (untrace-com $_ $_ $_ $Module) + (set-tracing $Module off)) +; + + (= + (untrace-com $_ $_ $_ $Module $Component) + (set-tracing $Module $Component off)) +; + + + + (= + (list-tracing-com $_ $_ $_) + (list-tracing)) +; + + + + (= + (list-tracing) + ( (traced-modules $M) (format "The following modules are being traced: ~n~p~n" (:: $M)))) +; + + +; +; + +; +; + +; +; + +; +; + + + + (= + (pass-com pass $SIn $SOut) + (pass-move $SIn $SOut)) +; + + + + + (= + (random-com $Move $SIn $SOut) + (printing-choose random-move $Move $SIn $SOut)) +; + + + + + (= + (random1-com $Move $SIn $SOut) + (random-printing-choose legal $Move $SIn $SOut)) +; + + + + + (= + (instant-com $Move $SIn $SOut) + (printing-choose instant-move $Move $SIn $SOut)) +; + + + + + (= + (victor-com $Move $SIn $SOut) + (printing-choose victor-move $Move $SIn $SOut)) +; + + + + + (= + (endgame-com $Move $SIn $SOut) + ( (timing (endgame-move $Move $SIn $SOut)) (select-move $Move $SIn $SOut))) +; + + + + + (= + (cautious-com $Move $SIn $SOut) + (printing-choose cautious-move $Move $SIn $SOut)) +; + + + + (= + (random-aggressive-com $Move $SIn $SOut) + (printing-choose random-aggressive-move $Move $SIn $SOut)) +; + + + + + (= + (mate-com $Move $SIn $SOut) + ( (timing (mate-move $Move $SIn $SOut)) (select-move $Move $SIn $SOut))) +; + + + + (= + (threaten-com $Move $SIn $SOut) + ( (timing (threaten-move $Move $SIn $SOut)) (select-move $Move $SIn $SOut))) +; + + + + (= + (enough-rope-com $Move $SIn $SOut) + ( (timing (enough-rope-move $Move $SIn $SOut)) (select-move $Move $SIn $SOut))) +; + + + + + (= + (help-clock) + (format "\n============================================================================\nGame Clock Routines\n-------------------\nclock adjust : increments time player has used this game\nclock reset: resets time used by each player to 0.\nclock print: prints time used and remaining for each player.\nclock unlimit: disables the clock by giving both players unlimited time.\n\nclock: short form for clock print. \n\nExample:\n clock adjust white 2000. : adds 2 secs to time white used.\n clock adjust black '-2500'. : subtracts 2.5 secs from time black used.\n============================================================================\n" Nil)) +; + + + + (= + (clock-com $_ $_ $_ adjust $Color $Time) + ( (player-color $Player $Color) (adjust-player-clock $Player $Time))) +; + + + (= + (clock-com $_ $_ $_) + (print-clock)) +; + + (= + (clock-com $_ $_ $_ print) + (print-clock)) +; + + + (= + (clock-com $_ $_ $_ reset) + (reset-clock)) +; + + + (= + (clock-com $_ $_ $_ unlimit) + (clock-unlimit)) +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + !(my-ensure-loaded (library tracing)) +; + + + + (= + (tracing-play $Type $Call) + (det-if-then-else + (tracing (play $Type)) + (call $Call) True)) +; + + +; +; + + + (= + (tracing-play-format $Type $String $Args) + (det-if-then-else + (tracing (play $Type)) + (format $String $Args) True)) +; + + + + (= + (tracing-play-timing $Type $Call) + (trace-timing + (play $Type) $Call)) +; + + + + (= + (set-play-verbosity $Level $Status) + (set-tracing + (play $Level) $Status)) +; + + + + (= + (silent-play) + (all-play off)) +; + + + (= + (loud-play) + (all-play on)) +; + + + + (= + (all-play $Status) + ( (set-play-verbosity state $Status) + (set-play-verbosity move $Status) + (set-play-verbosity clock $Status))) +; + + + + (= + (trace-play-state) + (set-play-verbosity state on)) +; + + + (= + (trace-play-move) + (set-play-verbosity move on)) +; + + + (= + (trace-play-clock) + (set-play-verbosity clock on)) +; + + + + !(loud-play *) +; + +; +; + + + + diff --git a/metagame/play/local.metta b/metagame/play/local.metta new file mode 100644 index 0000000..fad9e8b --- /dev/null +++ b/metagame/play/local.metta @@ -0,0 +1,286 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + + + + (= + (get-players $White $Black) + ( (get-player-color player $White) + (get-player-color opponent $Black) + (query-accept-players $White $Black) + (set-det))) +; + + (= + (get-players $_ $_) + ( (format "\nPlease use 'player' to select the players.\n'help player' gives more info, and a list of available players.\n" Nil) (fail))) +; + + + + + (= + (get-player-color $Color $Player) + ( (player-method-parameter $Color $Param) (parameter $Param $Player))) +; + + + + + (= + (query-accept-players $White $Black) + ( (human-mode) + (set-det) + (format "\n~p as ~p vs. ~p as ~p?\n(y to accept, n to select new players): " + (:: $White player $Black opponent)) + (read $Answer) + (= $Answer y))) +; + + (= + (query-accept-players $White $Black) + (format "Playing ~p as ~p vs. ~p as ~p?" + (:: $White player $Black opponent))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + + + (= + (get-current-game) + ( (player-current-game $Game) + (query-use-current-game $Game) + (set-det))) +; + + (= + (get-current-game) + ( (format "\nPlease use 'game' to select a game.\n'games_library' will show you a list of available games.\n'generate will generate a new game as .game.\n" Nil) (fail))) +; + + +; +; + + + (= + (query-use-current-game $Game) + ( (human-mode) + (set-det) + (game-name $Game $Name) + (format "~nPlay game ~w? (y to play, n to choose another): " + (:: $Name)) + (read $Answer) + (= $Answer y))) +; + + (= + (query-use-current-game $Game) + ( (game-name $Game $Name) (format "~nPlaying game ~w" (:: $Name)))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (get-random-assignment $Assignment) + ( (game-assignments $Game $As) + (assignment-decision $As random $PieceNames $Squares) + (produce-assignment $PieceNames $Squares $Assignment))) +; + + + + + (= + (produce-assignment $PieceNames $Squares $Assignment) + ( (parameter assignment-method ask) + (set-det) + (ask-random-assignment $PieceNames $Squares $Assignment))) +; + + (= + (produce-assignment $PieceNames $Squares $Assignment) + (generate-random-assignment $PieceNames $Squares $Assignment)) +; + + + + + (= + (generate-random-assignment $PieceNames $Squares $Assignment) + ( (format "~nGenerating Random Assignment~n" Nil) (assign-pieces-to-squares $PieceNames $Squares $Assignment))) +; + ; +; + + +; +; + +; +; + +; +; + + + (= + (ask-random-assignment $PieceNames $Squares $Assignment) + ( (format "~nPlease assign ~w to ~w~nExample syntax: piece1 at {(1,1)} piece2 at {(2,2) (3,3)}.~n(C-d on new line to end)~n|: " + (:: $PieceNames $Squares)) + (read-tokens $AssignmentString) + (nl) + (set-parsing-mode) + (assignments $Assignment $AssignmentString + (Cons . $Rest)))) +; + + + (= + (ask-random-assignment $PieceNames $Squares $Assignment) + ( (format "~nPlease assign ~w to ~w~n('.' for help)~n|: " + (:: $PieceNames $Squares)) + (read-keyboard-tokens $AssignmentString) + (help-or-process-assign $AssignmentString $PieceNames $Squares $Assignment))) +; + + + + (= + (help-or-process-assign + (:: .) $PieceNames $Squares $Assignment) + ( (format "~nExample syntax:~npiece1 at {(1,1)} piece2 at {(2,2) (3,3)}.~n" Nil) (ask-random-assignment $PieceNames $Squares $Assignment))) +; + + + (= + (help-or-process-assign $AssignmentString $_ $_ $Assignment) + ( (nl) + (set-parsing-mode) + (assignments $Assignment $AssignmentString + (Cons . $Rest)))) +; + + + + + (= + (choose $Name $Role $Move $SIn $SOut) + ( (concat $Name -choose $NameChoose) + (=.. $Goal + (:: $NameChoose $Role $Move $SIn $SOut)) + (call $Goal))) +; + + + + + (= + (variable-choose $Role $Move $SIn $SOut) + ( (player-method-parameter $Role $Param) + (parameter $Param $Chooser) + (choose $Chooser $Role $Move $SIn $SOut))) +; + + + diff --git a/metagame/play/mobility.metta b/metagame/play/mobility.metta new file mode 100644 index 0000000..5a25ca5 --- /dev/null +++ b/metagame/play/mobility.metta @@ -0,0 +1,460 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (evaluating-choose $Player $Move $SIn $SOut) + ( (timing (evaluating-move $Move $SIn $SOut)) + (set-det) + (print-choice $Move $SIn $SOut))) +; + + + + + (= + (evaluating-move $Move $SIn $SOut) + ( (victor-move $Move $SIn $SOut) (set-det))) +; + + (= + (evaluating-move $Move $SIn $SOut) + (max-value-move $Move $SIn $SOut)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (evaluated-move $Move $Val $SIn) + ( (legal $Move $SIn $S1) (evaluate $S1 $Val))) +; + + + + + (= + (max-value-move $Move $SIn $SOut) + ( (setof + (- $Val $Move) + (evaluated-move $Move $Val $SIn) $Pairs) + (random-best + (- $Val $Move) $Pairs) + (format "The best move found has a value of: ~p~n" + (:: $Val)) + (legal $Move $SIn $SOut))) +; + + + + (= + (random-best $Best $L) + ( (collect-init $L $BestFew) (random-element $BestFew $Best))) +; + + + + (= + (collect-init + (Cons + (- $V $M) $Rest) + (Cons + (- $V $M) $BestFew)) + (collect-init $Rest $V $BestFew)) +; + + + (= + (collect_init () $V1 ()) True) +; + + (= + (collect-init + (Cons + (- $V2 $_) $_) $V1 Nil) + ( (< $V1 $V2) (set-det))) +; + + (= + (collect-init + (Cons $Pair $Rest) $Threshold + (Cons $Pair $R1)) + (collect-init $Rest $Threshold $R1)) +; + + + + + + (= + (evaluate-com $Move $SIn $_) + ( (timing (evaluate $SIn $Value)) (format "Position's value for player to move: ~p~n" (:: $Value)))) +; + + + + + (= + (evaluate $S $Value) + ( (control $P $S) + (opposite-role $O $P) + (evaluate $P $S $PVal) + (evaluate $O $S $OVal) + (is $Value + (- $PVal $OVal)))) +; + + + + (= + (evaluate $Player $S $Value) + ( (weight-vector $Weights) + (material-weight $Weights $MatW) + (mobility-weight $Weights $MobW) + (weighted-mobility $MobW $Player $S $WMob) + (weighted-material $MatW $Player $S $WMat) + (is $Value + (+ $WMob $WMat)))) +; + + + + (= + (weighted-mobility 0 $_ $_ 0) + (set-det)) +; + + (= + (weighted-mobility $MobW $Player $S $WMob) + ( (mobility $Player $S $Mob) (is $WMob (* $MobW $Mob)))) +; + + + + + (= + (weighted-material 0 $_ $_ 0) + (set-det)) +; + + (= + (weighted-material $MatW $Player $S $WMat) + ( (material $Player $S $Mat) (is $WMat (* $MatW $Mat)))) +; + + + + + + (= + (mobility $Player $S $M) + ( (put-control $Player $S $S1) (count-bagof $Move (^ $S2 (legal-move $Move $Player $S1 $S2)) $M))) +; + + + + + (= + (material $Player $S $M) + (count-bagof $Piece + (^ $Sq + (on + (piece $Piece $Player) $Sq $S)) $M)) +; + + + + +; +; + +; +; + +; +; + + + (= + (evaluate2 $S $Value) + ( (control $P $S) + (opposite-role $O $P) + (evaluate2 $P $O $S $Value))) +; + + + (= + (evaluate2 $Player $Opponent $S $Value) + ( (mobility $Opponent $S $Mob) + (material $Player $S $Mat) + (weight material $WMat) + (weight mobility $WMob) + (is $Value + (- + (* $Mat $WMat) + (* $Mob $WMob))))) +; + + + +; +; + +; +; + +; +; + + + + (= + (toggle-alpha-beta-weights $Player $Old) + ( (weight-vector $Player $Weights) (change-parameter weights $Old $Weights))) +; + + + + + (= + (weight-vector $Player $Weights) + (parameter + (weights $Player) $Weights)) +; + + + (= + (weight-vector $Weights) + (parameter weights $Weights)) +; + + + + + (= + (initialize-weights) + ( (default-alpha-weights $W) (add-parameter weights $W))) +; + + + + (= + (default-alpha-weights (weights $Mat $Mob)) + ( (default-weight material $Mat) (default-weight mobility $Mob))) +; + + +; +; + + + (= + (default_weight material 4) True) +; + + (= + (default_weight mobility 1) True) +; + + +; +; + +; +; + +; +; + + + + + +; +; + +; +; + +; +; + + + + (= + (material_weight + (weights $Mat $Mob) $Mat) True) +; + + + (= + (mobility_weight + (weights $Mat $Mob) $Mob) True) +; + + + + (= + (set-player-weights $Player $Mat $Mob) + ( (material-weight $W $Mat) + (mobility-weight $W $Mob) + (det-if-then-else + (= $Player default) + (add-parameter weights $W) + (add-parameter + (weights $Player) $W)))) +; + + + + + (= + (show-player-weights) + ( (show-player-weights player) (show-player-weights opponent))) +; + + + (= + (show-player-weights $Player) + ( (det-if-then-else + (weight-vector $Player $W) + (= $Default '') + (, + (weight-vector $W) + (= $Default '(by default)'))) + (material-weight $W $Mat) + (mobility-weight $W $Mob) + (format "\n<~p>'s weights are ~w:\n material: ~p\n mobility: ~p\n" + (:: $Player $Default $Mat $Mob)))) +; + + + +; +; + +; +; + +; +; + + +; +; + + + (= + (weight-com $_ $_ $_ $Player $Mat $Mob) + (set-player-weights $Player $Mat $Mob)) +; + + + + (= + (weight-top $Player $Mat $Mob) + (set-player-weights $Player $Mat $Mob)) +; + + + + (= + (show-com $_ $_ $_ weights $Player) + (show-player-weights $Player)) +; + + + (= + (show-com $_ $_ $_ weights) + (show-player-weights)) +; + + + + (= + (show-top weights $Player) + (show-player-weights $Player)) +; + + + (= + (show-top weights) + (show-player-weights)) +; + + +; +; + + + (= + (toggle-com $_ $_ $_ $Player) + (toggle-alpha-beta-weights $Player $Old)) +; + + + + diff --git a/metagame/play/notation.metta b/metagame/play/notation.metta new file mode 100644 index 0000000..8fd10ac --- /dev/null +++ b/metagame/play/notation.metta @@ -0,0 +1,672 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + !(my-ensure-loaded (library tokenizer)) +; + + !(my-ensure-loaded (library grammar)) +; + + +; +; + + + (= + (move-notation $ComplexMove $Notation) + ( (det-if-then-else + (var $ComplexMove) set-parsing-mode True) (move-notation $ComplexMove $Notation Nil))) +; + + + +; +; + + + (= + (--> + (move_notation $M) + (, + (prelims $M $Pre) + (, + (main $Pre ()) period))) True) +; + + + +; +; + +; +; + + (= + (--> + (prelims + (Cons $P $Out) $Out) + (init_promote $P)) True) +; + + (= + (--> + (prelims + (Cons end_assign $Rest) $Rest) ()) True) +; + + (= + (--> + (prelims $Rest $Rest) ()) True) +; + + + +; +; + +; +; + +; +; + + (= + (--> + (init_promote + (opponent_promote () () ())) ()) True) +; + + (= + (--> + (init_promote + (opponent_promote $Sq $OldPiece $NewPiece)) + (, + (promote) + (, + (gsquare $Sq) + (, + (piece $NewPiece) + (, + (;) line))))) True) +; + + + +; +; + + (= + (--> + (consider_promote + (Cons $T $Sel) $Rest) + (, + (attempt_promote $T) + (select_promote $Sel $Rest))) True) +; + + + (= + (--> + (select_promote + (Cons + (promote_select $Square $OldPiece $OldPiece) $Rest) $Rest) ()) True) +; + + (= + (--> + (select_promote + (Cons + (promote_select $Square $OldPiece $NewPiece) $Rest) $Rest) + (, + (;) + (, line + (, + (promote) + (, + (gsquare $Square) + (piece $NewPiece)))))) True) +; + + (= + (--> + (select_promote $Rest $Rest) ()) True) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + (= + (--> + (attempt_promote + (try_promote $Square $OldPiece ())) ()) True) +; + + (= + (--> + (attempt_promote + (try_promote $Square $OldPiece $OldPiece)) ()) True) +; + +; +; + + (= + (--> + (attempt_promote + (try_promote $Square $OldPiece $NewPiece)) + (, + (;) + (, + (promote) + (, + (gsquare $Square) + (piece $NewPiece))))) True) +; + + + +; +; + +; +; + + (= + (--> + (main + (Cons $P $Out) $Out) + (placing $P)) True) +; + + (= + (--> + (main $In $Out) + (, + (transfers $In $T) + (consider_promote $T $Out))) True) +; + + + +; +; + + (= + (--> + (transfers $In $Out) + (, + (transfer $In $T) + (continued_transfers $T $Out))) True) +; + + +; +; + +; +; + +; +; + + (= + (--> + (continued_transfers $In $In) ()) True) +; + + (= + (--> + (continued_transfers + (Cons end_continues $Rest) $Rest) ()) True) +; + + (= + (--> + (continued_transfers $In $Out) + (, + (;) + (, line + (transfers $In $Out)))) True) +; + + + +; +; + +; +; + +; +; + +; +; + + (= + (--> + (transfer + (Cons $Move $Capture) $Rest) + (, + (moving $Move) + (capture $Capture $Rest))) True) +; + + + + (= + (--> + (placing $M) + (, + { (= $M + (place $Piece $Player $Sq)) } + (, + (piece $Piece) + (, + (paren_color_player $Player) + (, + (->) + (gsquare $Sq)))))) True) +; + + (= + (--> + (placing $M) + (, + { (= $M + (assign $Piece $Player $Sq)) } + (, + (piece $Piece) + (, + (paren_color_player $Player) + (, + (->) + (gsquare $Sq)))))) True) +; + + +; +; + +; +; + +; +; + + (= + (--> + (moving + (move $Piece $Player $From $To)) + (, + (piece $Piece) + (, + (gsquare $From) + (, + (->) + (gsquare $To))))) True) +; + + + (= + (--> + (capture $In $Out) + (null_capture $In $Out)) True) +; + + (= + (--> + (capture $In $Out) + (real_capture $In $Out)) True) +; + + + (= + (--> + (null_capture $X $X) ()) True) +; + + + (= + (--> + (real_capture + (Cons $C $Cs) $Rest) + (, + (x) + (, + (simp_capture $C) + (capture $Cs $Rest)))) True) +; + + + (= + (--> + (simp_capture $M) + (remove $M)) True) +; + + (= + (--> + (simp_capture $M) + (possess $M)) True) +; + + +; +; + + (= + (--> + (remove + (capture remove $Caps)) + (capture_effects_list $Caps)) True) +; + + +; +; + + (= + (--> + (possess + (capture + (possess $Player) $Caps)) + (, + (capture_effects_list $Caps) + (, + (/) + (paren_color_player $Player)))) True) +; + + + (= + (--> + (capture_effects_list ()) ()) True) +; + + (= + (--> + (capture_effects_list + (Cons $C $Caps)) + (, + (capture_effect $C) + (capture_effects_list $Caps))) True) +; + + +; +; + +; +; + + (= + (--> + (capture_effect $C) + (, + { (captured $C $Piece $Square) } + (, + (piece $Piece) + (gsquare $Square)))) True) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + (= + (--> + (piece $P) + (, + { (, + (piece_struct_name $P $Name) + (piece_struct_owner $P $O)) } + (, + (color_player $O) + (piece_name $Name)))) True) +; + + + +; +; + +; +; + + (= + (--> + (paren_color_player $P) + (, + (() + (, + (color_player $P) + ())))) True) +; + + + (= + (--> + (color_player player) + (white)) True) +; + + (= + (--> + (color_player opponent) + (black)) True) +; + + +; +; + +; +; + + + + (= + (color_player white player) True) +; + + (= + (color_player black opponent) True) +; + + + + (= + (player_color player white) True) +; + + (= + (player_color opponent black) True) +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + +; +; + +; +; + + + (= + (print-read-move-from-file $File) + ( (format "~nReading move from file~n" Nil) + (read-move-from-file-to-list $File $Move) + (format "~nRead move from file~n" Nil) + (set-parsing-mode) + (format "~nParsing move in parse mode~n" Nil) + (move-notation $ComplexMove $Move Nil) + (set-printing-mode) + (format "~nParsing move in print mode~n" Nil) + (move-notation $ComplexMove $Move1 Nil) + (format "~nPrinting move~n" Nil) + (print-tokens $Move1))) +; + + + + (= + (read-move-from-file-to-list $File $Move) + (read-tokens-from-file $File $Move)) +; + + + +; +; + +; +; + +; +; + + + (= + (move-notation-string $Move $String) + ( (var $String) + (set-det) + (move-notation $Move $Tokens) + (print-tokens-to-string $Tokens $String))) +; + + (= + (move-notation-string $Move $String) + ( (var $Move) + (read-tokens-from-string $String $Tokens) + (move-notation $Move $Tokens))) +; + + + + diff --git a/metagame/play/ops.metta b/metagame/play/ops.metta new file mode 100644 index 0000000..b2bfa2a --- /dev/null +++ b/metagame/play/ops.metta @@ -0,0 +1,25 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + + + !(op 700 xfx @) +; + + + + + diff --git a/metagame/play/param.metta b/metagame/play/param.metta new file mode 100644 index 0000000..02a60f6 --- /dev/null +++ b/metagame/play/param.metta @@ -0,0 +1,643 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + + +; +; + + !(dynamic (/ parameter 2)) +; + + +; +; + +; +; + +; +; + + + + (= + (parameter verbosity 0) True) +; + + +; +; + +; +; + +; +; + + + (= + (parameter timing on) True) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (parameter selection_method ask) True) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (parameter assignment_method random) True) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (parameter continuous yes) True) +; + + + +; +; + +; +; + +; +; + + + (= + (parameter player_method human) True) +; + + +; +; + +; +; + +; +; + + + (= + (parameter opponent_method human) True) +; + + + +; +; + +; +; + +; +; + + + (= + (parameter player_file none) True) +; + + +; +; + +; +; + +; +; + + + (= + (parameter opponent_file none) True) +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (parameter verbose_interp on) True) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (parameter parsing_mode parsing) True) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (parameter alpha_squares_mode off) True) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (parameter confirm_choices on) True) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (parameter completions on) True) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (parameter safety off) True) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (parameter compile_symmetries on) True) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + +; +; + +; +; + +; +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (parameter random_min -1.0) True) +; + + (= + (parameter random_max 1.0) True) +; + + +; +; + +; +; + +; +; + + + (= + (parameter depth 1) True) +; + + +; +; + +; +; + +; +; + +; +; + + +; +; + + (= + (parameter game_time_limit 99999999) True) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (parameter move_time_limit 10000) True) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (parameter move_horizon 1) True) +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (parameter ordering random) True) +; + + + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (parameter discount exponent) True) +; + + +; +; + +; +; + +; +; + + + (= + (parameter vital_number 2) True) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (parameter possess_offset 2) True) +; + + + diff --git a/metagame/play/player_files.metta b/metagame/play/player_files.metta new file mode 100644 index 0000000..c4caf76 --- /dev/null +++ b/metagame/play/player_files.metta @@ -0,0 +1,55 @@ +; +; + + + + (= + (system_files play + (param ops parse1 parse2 controller history help help_advisors interface setup gen_menu start_menu local invert matches notation stat thread statify_theory efficient_state compile_syms mobility alphabeta value advisors)) True) +; + + + (= + (system_files fullplay + (param ops parse1 parse2 controller menus interface start_menu local comms invert matches notation stat compile_state compile_syms index_preds)) True) +; + + + +; +; + + + (= + (system_files generator + (genstructs piece_names gen tokenizer grammar gen_parameters)) True) +; + + + (= + (system_files library + (aux tracing timing dynamic_load shells args randoms theoryl menus)) True) +; + + + (= + (system_files analysis + (struct paths analysis mygraphs floyd tables arrive prom possess exclude dominate group step flight global potent tourney)) True) +; + + +; +; + +; +; + + + + (= + (theory_files + (dynamic_preds parse boards print_boards legal goals)) True) +; + + + diff --git a/metagame/play/setup.metta b/metagame/play/setup.metta new file mode 100644 index 0000000..f6efe6e --- /dev/null +++ b/metagame/play/setup.metta @@ -0,0 +1,340 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + + + (= + (setup-position empty $Squares $SIn $SOut) + ( (set-det) (make-empty $Squares $SIn $SOut))) +; + + (= + (setup-position $Player $Assignments $SIn $SOut) + (place-pieces-on-squares $Assignments $Player $SIn $SOut)) +; + + + + + (= + (setup-com $_ $SIn $SOut) + (setup $SIn $SOut)) +; + + +; +; + +; +; + +; +; + + + + (= + (setup $SIn $SOut) + ( (menu-command "~nEnter command ('help.' gives more information)~n" setup + (:: $Done $SIn $S1)) + (set-det) + (continue-setup $Done $SIn $S1 $SOut))) +; + + (= + (setup $SIn $SOut) + ( (format "~nI did not understand your command. Please try again!~n" Nil) (setup $SIn $SOut))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (continue-setup $Move $SIn $S1 $S1) + ( (nonvar $Move) + (= $Move done) + (set-det))) +; + + (= + (continue-setup $Move $SIn $S1 $Nothing) + ( (nonvar $Move) + (= $Move abort) + (set-det))) +; + + (= + (continue-setup $Move $SIn $S1 $S1) + ( (nonvar $Move) + (nonvar $S1) + (set-det))) +; + + (= + (continue-setup $Move $SIn $S1 $SOut) + ( (nonvar $S1) + (set-det) + (setup $S1 $SOut))) +; + + (= + (continue-setup $Move $SIn $S1 $SOut) + (setup $SIn $SOut)) +; + + + +; +; + +; +; + +; +; + + +; +; + + + (= + (put-setup $_ $SIn $SOut $Row $Col $Color $Type) + ( (piece $Piece + (:: $Color $Type) Nil) + (with-alpha-squares (gsquare $Square (:: ( $Row , $Col )) Nil)) + (place-piece $Piece $Square $SIn $SOut))) +; + + + +; +; + + + (= + (initprom-setup $_ $SIn $SOut $Row $Col $Color $Type) + ( (piece $Piece + (:: $Color $Type) Nil) + (with-alpha-squares (gsquare $Square (:: ( $Row , $Col )) Nil)) + (put-stage init-promote $SIn $S1) + (add-in + (opponent-promotes $Piece $Square) $S1 $SOut))) +; + + + +; +; + + + (= + (hand-setup $_ $SIn $SOut $HandColor $Color $Type) + ( (piece $Piece + (:: $Color $Type) Nil) + (player-color $Player $HandColor) + (put-in-hand $Piece $Player $SIn $SOut))) +; + + +; +; + + + (= + (empty-setup $_ $SIn $SOut $Row $Col) + ( (with-alpha-squares (gsquare $Square (:: ( $Row , $Col )) Nil)) (set-empty $Square $SIn $SOut))) +; + + +; +; + + + (= + (move-setup $_ $SIn $SOut $Row1 $Col1 $Row2 $Col2) + ( (with-alpha-squares (, (gsquare $Square1 (:: ( $Row1 , $Col1 )) Nil) (gsquare $Square2 (:: ( $Row2 , $Col2 )) Nil))) (move-piece $_ $Square1 $Square2 $SIn $SOut))) +; + + + +; +; + + + (= + (stage-setup $_ $SIn $SOut $Stage) + (put-stage $Stage $SIn $SOut)) +; + + +; +; + + + (= + (control-setup $_ $SIn $SOut $Color) + ( (player-color $Player $Color) (put-control $Player $SIn $SOut))) +; + + +; +; + + + (= + (clear-setup $_ $SIn $SOut) + (make-empty-board $SIn $SOut)) +; + + + +; +; + + + (= + (add-setup $_ $SIn $SOut) + ( (format "Enter a property to be added: ~n" Nil) + (read $Prop) + (add-in $Prop $SIn $SOut))) +; + + +; +; + + + (= + (del-setup $_ $SIn $SOut) + ( (format "Enter a property to be deleted: ~n" Nil) + (read $Prop) + (del-in $Prop $SIn $SOut))) +; + + + +; +; + +; +; + + + (= + (restore-setup $_ $SIn $SOut $Name) + (restore-state $Name $SOut)) +; + + +; +; + + + (= + (checkpoint-setup $_ $SIn $_) + (checkpoint-state $SIn)) +; + + +; +; + + (= + (checkpoint-setup $_ $SIn $_ $Name) + (checkpoint-state $Name $SIn)) +; + + + + + +; +; + + + (= + (done_setup done $SIn $SIn) True) +; + + +; +; + + + (= + (abort_setup abort $SIn $_) True) +; + + +; +; + + + (= + (display-setup $Move $SIn $_) + ( (format "~nCurrent State: ~n" Nil) (print-state $SIn))) +; + + + + + (= + (help-setup $_ $_ $_) + (help-setup)) +; + + + (= + (help-setup) + (format "\nModifying Board Setup\n---------------------\nmove => transfer piece to different square\nput => put a piece on square (,)\ninitprom => opponent must promote piece on square\nempty \t\t => empty square (,)\nhand => put piece in 's hand\nclear\t\t\t\t => makes all the square empty\ncontrol \t\t\t => puts player in control\nstage \t\t\t => sets current stage to \nadd/del\t\t\t\t => add or delete a property from state\ndisplay\t\t\t\t => prints the board\ndone\t\t\t\t => exits setup stage with current setup\nabort\t\t\t\t => exits setup stage, abandon changes\ncheckpoint . => record state under name \nrestore . => set state to that checkpointed as \n\nExamples:\n\nmove e 2 e 4.\nput e 2 white king.\nhand white black queen.\ncontrol white.\nstage assign.\ninitprom e 2 black bishop. \ndone.\n" Nil)) +; + + + + diff --git a/metagame/play/start_menu.metta b/metagame/play/start_menu.metta new file mode 100644 index 0000000..a75fdca --- /dev/null +++ b/metagame/play/start_menu.metta @@ -0,0 +1,461 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (metagame) + ( (recover-metagame-state) + (menu-command "~nEnter a command ('help.' gives more information)~n" top Nil) + (set-det) + (metagame))) +; + + (= + (metagame) + ( (format "~nI did not understand your command. Please try again!~n" Nil) (metagame))) +; + + + +; +; + + + (= + (recover-metagame-state) + ( (restore-parameters) (recover-grammar))) +; + + + + (= + (game-top $File) + (load-game $File)) +; + + + + (= + (player-top white $Player) + ( (format "~p moves will now be chosen by: ~p~n" + (:: white $Player)) (set-parameter player-method $Player))) +; + + (= + (player-top black $Player) + ( (set-parameter opponent-method $Player) (format "~p moves will now be chosen by: ~p~n" (:: black $Player)))) +; + + + + (= + (players-top $Player $Opp) + ( (player-top white $Player) (player-top black $Opp))) +; + + + (= + (players-top) + ( (get-player-color player $White) + (get-player-color opponent $Black) + (format "Playing ~p as ~p vs. ~p as ~p.~n" + (:: $White player $Black opponent)))) +; + + + + + + + (= + (show-players-top) + (get-players $_ $_)) +; + + + + + (= + (games-library-top) + (games-library)) +; + + + + + (= + (games-library) + ( (games-library-directory $D) (games-library $D))) +; + + + + (= + (games-library $D) + ( (current-directory $Current) + (absolute-file-name $D $AbsD) + (cd $AbsD) + (= $Games *.game) + (format "~nThe following games are available in directory <~p>:~n~n" + (:: $AbsD)) + (shell (:: ls $Games)) + (cd $Current))) +; + + + + (= + (games-in-directory $D) + (games-library $D)) +; + + + + + (= + (cd-top $Dir) + (cd-print $Dir)) +; + + + + (= + (cd-print $Dir) + ( (format "~nChanging current directory to: ~p~n~n" + (:: $Dir)) (cd $Dir))) +; + + + + (= + (pwd-top) + (pwd-print)) +; + + + + (= + (ls-top) + (ls)) +; + + + + (= + (pwd-print) + ( (current-directory $D) (format "~nCurrent directory is: ~p~n~n" (:: $D)))) +; + + + + + (= + (define-top $PieceName) + (show-piece-definition $PieceName)) +; + + + + (= + (goals-top) + (show-game-goals)) +; + + + + + (= + (show-game-goals) + ( (player-current-game $G) + (game-name $G $GameName) + (game-goal $G $Def) + (set-printing-mode) + (with-alpha-squares (goal-defs $Def $String Nil)) + (set-parsing-mode) + (format "~nGame <~p> has the following goals: ~n~n" + (:: $GameName)) + (print-tokens $String) + (nl) + (nl))) +; + + + + (= + (rules-top) + (show-rules)) +; + + + + (= + (show-rules) + ( (player-current-game $G) + (game-name $G $GameName) + (format "~nGame <~p> is defined as follows: ~n~n" + (:: $GameName)) + (with-alpha-squares (print-game-struct $G)) + (nl) + (nl))) +; + + + + + (= + (pieces-top) + (show-piece-names)) +; + + + + (= + (board-top) + (show-board)) +; + + + + (= + (show-board) + ( (player-current-game $G) + (game-name $G $GameName) + (game-board $G $Def) + (set-printing-mode) + (with-alpha-squares (board $Def $String Nil)) + (set-parsing-mode) + (format "~nGame <~p> has the board information: ~n~n" + (:: $GameName)) + (print-tokens $String) + (nl) + (nl))) +; + + + + + + (= + (set-top $P $V) + (set-parameter $P $V)) +; + + + (= + (set-top) + (show-parameters)) +; + + +; +; + +; +; + + + (= + (setg-top $P $V) + (add-global $P $V)) +; + + + + (= + (showg-top) + (showg)) +; + + + + + (= + (randomize-top $N) + (randomize $N)) +; + + + + (= + (quit-top) + (print-quit)) +; + + + + (= + (print-quit) + ( (format "~nBye!~n" Nil) (halt))) +; + + + + + + (= + (abort-top) + (print-abort)) +; + + + + (= + (prolog-top) + (print-abort)) +; + + + + (= + (print-abort) + ( (format "~nTo return to METAGAME, type: 'metagame.'~n" Nil) (abort))) +; + + + + (= + (play-top) + (start)) +; + + + + (= + (start-top) + (start)) +; + + + + + (= + (generate-top $File) + (generate-and-load $File)) +; + + + (= + (generate-top) + (generate-and-load random)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (clock-top) + (print-clock)) +; + + + (= + (clock-top unlimit) + (clock-unlimit)) +; + + + (= + (clock-top print) + (print-clock)) +; + + + (= + (clock-top reset) + (reset-clock)) +; + + + (= + (clock-top adjust $Color $Time) + ( (player-color $Player $Color) (adjust-player-clock $Player $Time))) +; + + +; +; + +; +; + +; +; + + + + (= + (trace-top $Module) + (set-tracing $Module on)) +; + + (= + (trace-top $Module $Component) + (set-tracing $Module $Component on)) +; + + + + (= + (untrace-top $Module) + (set-tracing $Module off)) +; + + (= + (untrace-top $Module $Component) + (set-tracing $Module $Component off)) +; + + + + (= + (list-tracing-top) + ( (traced-modules $M) (format "The following modules are being traced: ~n~p~n" (:: $M)))) +; + + diff --git a/metagame/play/sysdev.metta b/metagame/play/sysdev.metta new file mode 100644 index 0000000..da76396 --- /dev/null +++ b/metagame/play/sysdev.metta @@ -0,0 +1,778 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (my_absolute_file_name $N $N) True) +; + + + +; +; + +; +; + + + (= + (my-use-module $M) + (det-if-then-else is-profiling + (profiling-load $M) + (use-module $M))) +; + + + + (= + (my-ensure-loaded $M) + (det-if-then-else is-profiling + (profiling-load $M) + (ensure-loaded $M))) +; + + + + (= + (profiling-load $M) + (compile $M)) +; + + +; +; + + + !(my-ensure-loaded ../misc/aux) +; + + + + + (= + (make-library-directory $Path) + ( (my-absolute-file-name $Path $D) (add-symbol &self (library_directory $D)))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (metagame-subpath $Path $Dir) + ( (metagame-directory $Metagame) + (concat $Metagame / $Sub1) + (concat $Sub1 $Path $SubDir) + (my-absolute-file-name $SubDir $Dir))) +; + + + + (= + (make-metagame-subpath $Path) + ( (metagame-subpath $Path $Dir) (make-library-directory $Dir))) +; + + + + (= + (find-index-preds-file) + ( (metagame-subpath state/index-preds.pl $F) + (abolish (/ index-preds-file 1)) + (add-symbol &self + (index_preds_file $F)))) +; + + + + + (= + (find-games-library) + ( (metagame-subpath games $D) + (abolish (/ games-library-directory 1)) + (add-symbol &self + (games_library_directory $D)))) +; + + + + + (= + (find-theory-directory) + ( (metagame-subpath theory $D) + (abolish (/ theory-directory 1)) + (add-symbol &self + (theory_directory $D)))) +; + + + + (= + (find-dynamic-preds-file) + ( (metagame-subpath theory/dynamic-preds.pl $F) + (abolish (/ dynamic-preds-file 1)) + (add-symbol &self + (dynamic_preds_file $F)))) +; + + + + + (= + (bind-environment-paths) + ( (make-metagame-subpath generator) + (make-metagame-subpath misc) + (make-metagame-subpath play) + (make-metagame-subpath games) + (make-metagame-subpath evals) + (make-metagame-subpath state) + (make-metagame-subpath theory) + (make-metagame-subpath comms) + (make-metagame-subpath coding) + (make-metagame-subpath learning) + (find-dynamic-preds-file) + (find-index-preds-file) + (find-games-library) + (find-theory-directory) + (add-symbol &self + (library_directory .)))) +; + + + +; +; + + + + (= + (sys_filename_suffix prolog .pl) True) +; + + (= + (sys_filename_suffix state_compile _stat) True) +; + + (= + (sys_filename_suffix game .game) True) +; + + (= + (sys_filename_suffix eval .eval) True) +; + + (= + (sys_filename_suffix record .rec) True) +; + + + + + (= + (sys-suffixed-filename $File $Sys $Name) + ( (sys-filename-suffix $Sys $Suf) (suffixed-filename $File $Suf $Name))) +; + + + + (= + (suffixed-filename $File $Suf $Name) + (bi-concat $File $Suf $Name)) +; + + + + + (= + (find-suffixed-library-file $Name $Suffix $File) + ( (nofileerrors) + (sys-suffixed-filename $Name $Suffix $File1) + (exists-absolute-file-name + (library $File1) $File) + (set-det) + (fileerrors))) +; + + (= + (find-suffixed-library-file $Name $Suffix $File) + ( (fileerrors) + (format "~nError: Couldn't find file ~w.~p~n" + (:: $Name $Suffix)) + (fail))) +; + + +; +; + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + + + + + (= + (load-main-system-files) + (compile (library player-files))) +; + + + +; +; + +; +; + +; +; + + + (= + (load-metagame) + ( (bind-environment-paths) + (load-main-system-files) + (load-system library) + (load-system generator) + (load-system play) + (load-system analysis) + (compile-and-load-player) + (add-system-portrayals))) +; + + + + + (= + (load-system $System) + ( (system-files $System $Files) (whenever (member $F $Files) (compile (library $F))))) +; + + + + +; +; + +; +; + +; +; + + + +; +; + +; +; + +; +; + + + + (= + (enter-metagame) + ( (metagame-version $V) + (format '~nMETAGAME Game-Playing Workbench ~p~n' + (:: $V)) + (format 'Copyright (c) 1992 Barney D. Pell~n~n' Nil) + (unix (argv $Argv)) + (process-commands $Argv) + (metagame))) +; + + + + (= + (process-commands $Argv) + ( (det-if-then-else + (append $_ + (Cons seed + (Cons $N $_)) $Argv) + (randomize $N) True) + (whenever + (, + (append $_ + (Cons $P + (Cons $V $_)) $Argv) + (parameter $P $_)) + (set-parameter $P $V)) + (whenever + (append $_ + (Cons file + (Cons $D $_)) $Argv) + (compile $D)))) +; + + + +; +; + +; +; + +; +; + + + + (= + (set-parameter $P $V) + (det-if-then-else + (remove-symbol &self + (parameter $P $_)) + (add-symbol &self + (parameter $P $V)) + (det-if-then otherwise + (format 'Unknown parameter <~p>!~n' + (:: $P))))) +; + + + + (= + (setp $P $V) + (set-parameter $P $V)) +; + + +; +; + + + (= + (add-parameter $P $V) + ( (remove-all-symbols &self + (parameter $P $_)) (add-symbol &self (parameter $P $V)))) +; + + + + (= + (change-parameter $P $Old $V) + (det-if-then-else + (remove-symbol &self + (parameter $P $Old)) + (add-symbol &self + (parameter $P $V)) + (det-if-then otherwise + (format 'Unknown parameter <~p>!~n' + (:: $P))))) +; + + + + + (= + (show) + (show-parameters)) +; + + + + (= + (show-parameters) + ( (listing parameter) + (getrand $R) + (format '~nrandom seed = ~p~n' + (:: $R)))) +; + + + + + (= + (save-parameters) + ( (findall + (- $P $V) + (parameter $P $V) $Params) + (remove-all-symbols &self + (saved_parameters $_)) + (add-symbol &self + (saved_parameters $Params)))) +; + + + + (= + (restore-parameters) + (det-if-then-else + (remove-symbol &self + (saved_parameters $Params)) + (restore-parameters $Params) True)) +; + + + (= + (restore_parameters ()) True) +; + + (= + (restore-parameters (Cons (- $P $V) $Rest)) + ( (set-parameter $P $V) (restore-parameters $Rest))) +; + + + +; +; + +; +; + +; +; + + + + (= + (set-global $P $V) + (det-if-then-else + (remove-symbol &self + (global $P $_)) + (add-symbol &self + (global $P $V)) + (det-if-then otherwise + (format 'Unknown global <~p>!~n' + (:: $P))))) +; + + +; +; + + + (= + (add-global $P $V) + ( (remove-all-symbols &self + (global $P $_)) (add-symbol &self (global $P $V)))) +; + + + + (= + (change-global $P $Old $V) + (det-if-then-else + (remove-symbol &self + (global $P $Old)) + (add-symbol &self + (global $P $V)) + (det-if-then otherwise + (format 'Unknown global <~p>!~n' + (:: $P))))) +; + + + + + (= + (setg $P $V) + (set-global $P $V)) +; + + + + (= + (showg) + (show-globals)) +; + + + + (= + (show-globals) + ( (listing global) + (getrand $R) + (format '~nrandom seed = ~p~n' + (:: $R)))) +; + + + + + (= + (save-globals) + ( (findall + (- $P $V) + (global $P $V) $Params) + (remove-all-symbols &self + (saved_globals $_)) + (add-symbol &self + (saved_globals $Params)))) +; + + + + (= + (restore-globals) + (det-if-then-else + (remove-symbol &self + (saved_globals $Params)) + (restore-globals $Params) True)) +; + + + (= + (restore_globals ()) True) +; + + (= + (restore-globals (Cons (- $P $V) $Rest)) + ( (set-global $P $V) (restore-globals $Rest))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (verbosely $Call) + (det-if-then-else verbose + (call $Call) True)) +; + + +; +; + + + (= + (verbosely-format $String $Args) + (verbosely (format $String $Args))) +; + + + + (= + (verbose) + ( (parameter verbosity $X) (> $X 0))) +; + + + + (= + (set-verbose) + (set-parameter verbosity 1)) +; + + + (= + (set-quiet) + (set-parameter verbosity 0)) +; + + + +; +; + +; +; + +; +; + + + + (= + (portray-conj (, $X $Y)) + ( (print $X) + (write ,) + (print $Y))) +; + + + (= + (portray-disj (or $X $Y)) + ( (print $X) + (write ; ) + (print $Y))) +; + + + (= + (portray-if (= $X $Y)) + ( (write () + (writeq $X) + (write :-) + (print $Y) + (write )))) +; + + + (= + (portray-var $N) + ( (put 124) (write $N))) +; + + +; +; + +; +; + + + +; +; + +; +; + +; +; + + + + (= + (portray-state (state $S)) + ( (format "~n" Nil))) +; + + + + (= + (add-portray $Func) + ( (functor $Goal $Func 1) + (arg 1 $Goal $Term) + (add-symbol &self + (:- + (portray $Term) $Goal)))) +; + + + + (= + (system_portrayals + (portray_conj portray_disj portray_if portray_var portray_piece portray_player portray_square portray_moving portray_game portray_state)) True) +; + + + + (= + (add-system-portrayals) + ( (system-portrayals $Ps) (add-portrayals $Ps))) +; + + + + (= + (add-portrayals $Ps) + (whenever + (member $P $Ps) + (add-portray $P))) +; + + + + + diff --git a/metagame/play/value.metta b/metagame/play/value.metta new file mode 100644 index 0000000..e447657 --- /dev/null +++ b/metagame/play/value.metta @@ -0,0 +1,1381 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + + + (= + (load-eval $Name) + ( (find-eval-file $Name $File) (file-make-test-eval $File))) +; + + + + (= + (find-eval-file $Name $File) + (find-suffixed-library-file $Name eval $File)) +; + + +; +; + +; +; + + + (= + (file-make-test-eval $File) + ( (abolish (/ piece-value 2)) + (abolish (/ piece-square-value 2)) + (compile $File))) +; + + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (successor-pos $Move $State $State2 $Tables) + (legal $Move $State $State2)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (terminal-pos-value $Pos $Val $Tables) + (terminal-game-outcome $Pos $Val)) +; + + + +; +; + +; +; + + + (= + (terminal-game-outcome $Pos $Val) + ( (game-outcome $Outcome $Pos) + (value-of-outcome $Outcome $Val) + (set-det))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (staticval $Pos $Val $Tables) + (evaluation $Val $Pos $Tables)) +; + + +; +; + +; +; + +; +; + + (= + (staticval $Pos $Val) + (evaluation $Val $Pos)) +; + + + + +; +; + +; +; + +; +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (evaluation $Value $Position) + ( (find-advice-tables $Tables) (evaluation $Value $Position $Tables))) +; + + + (= + (evaluation $Value $Position $Tables) + ( (get-advices $Advice $Position $Tables) (mediate-advices $Advice $Value $Tables))) +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (local-evaluation $Piece $Sq $Value $Position $Tables) + ( (get-local-advices $Piece $Sq $Advice $Position $Tables) (mediate-advices $Advice $Value $Tables))) +; + + + + + (= + (get-advices $Advices $Position) + ( (find-advice-tables $Tables) (get-advices $Advices $Position $Tables))) +; + + + (= + (get-advices $Advices $Position $Tables) + (findall $Advice + (, + (add-dynamic-tables $Position $Tables) + (value $Advice $Position $Tables)) $Advices)) +; + + + + + (= + (get-local-advices $Piece $Sq $Advices $Position $Tables) + (findall $Advice + (value $Piece $Sq $Advice $Position $Tables) $Advices)) +; + + + + (= + (show-advices-name $PosName) + ( (checkpoint $PosName $Pos) (show-advices $Pos))) +; + + + + + (= + (show-advices $Pos) + ( (get-advices $As $Pos) (ppl $As))) +; + + + (= + (show-advices $Pos $Tables) + ( (get-advices $As $Pos $Tables) (ppl $As))) +; + + + + + (= + (show-local-advices $Piece $Sq $Pos) + ( (find-advice-tables $Tables) (show-local-advices $Piece $Sq $Pos $Tables))) +; + + + + (= + (show-local-advices $Piece $Sq $Pos $Tables) + ( (on $Piece $Sq $Pos) + (get-local-advices $Piece $Sq $Advices $Pos $Tables) + (ppl $Advices))) +; + + + + + + + (= + (mediate-advices $Advices $Value $Tables) + ( (weigh-advices $Advices $Vals $Tables) (sumlist $Vals $Value))) +; + + + + (= + (weigh_advices () () $_) True) +; + + (= + (weigh-advices + (Cons $A $As) + (Cons $V $Vals) $Tables) + ( (weigh-advice $A $V $Tables) (weigh-advices $As $Vals $Tables))) +; + + + + (= + (weigh-advice + (advice $Advisor $Comment $V) $Val $Tables) + ( (advisor-weight $Advisor $Weight $Tables) (is $Val (* $V $Weight)))) +; + + +; +; + + + (= + (advisor-weight $Advisor $Weight $Tables) + (parameter $Advisor $Weight)) +; + + + + + (= + (advisor $A $B) + (dynamic-advisor $A $B)) +; + + (= + (advisor $A $B) + (static-advisor $A $B)) +; + + + + + (= + (dynamic_advisor gen_material 0) True) +; + + (= + (dynamic_advisor material 0) True) +; + + (= + (dynamic_advisor square 0) True) +; + + (= + (dynamic_advisor lthreat 0) True) +; + + (= + (dynamic_advisor potent 0) True) +; + + (= + (dynamic_advisor dynamic_mobility 0) True) +; + + + (= + (dynamic_advisor gmovmob 0) True) +; + + (= + (dynamic_advisor gcapmob 0) True) +; + + (= + (dynamic_advisor gthreat 0) True) +; + + (= + (dynamic_advisor pthreat 0) True) +; + + + (= + (dynamic_advisor static_mobility 0) True) +; + + (= + (dynamic_advisor eventual_mobility 0) True) +; + + (= + (dynamic_advisor arrive_distance 0) True) +; + + (= + (dynamic_advisor promote_distance 0) True) +; + + (= + (dynamic_advisor possess 0) True) +; + + (= + (dynamic_advisor initprom 0) True) +; + +; +; + + (= + (dynamic_advisor eradicate 0) True) +; + + (= + (dynamic_advisor vital 0) True) +; + + + + (= + (static_advisor random 0) True) +; + + (= + (static_advisor static 0) True) +; + + (= + (static_advisor victims 0) True) +; + + (= + (static_advisor max_static_mob 0) True) +; + + (= + (static_advisor max_eventual_mob 0) True) +; + + (= + (static_advisor avg_static_mob 0) True) +; + + (= + (static_advisor avg_eventual_mob 0) True) +; + + (= + (static_advisor eradicate 0) True) +; + + (= + (static_advisor stalemate 0) True) +; + + (= + (static_advisor arrive 0) True) +; + + (= + (static_advisor giveaway 0) True) +; + + (= + (static_advisor immunity 0) True) +; + +; +; + + + + + (= + (initialize-advisors) + ( (whenever + (advisor $Name $Default) + (add-parameter $Name $Default)) (add-symbol &self initialized_advisors))) +; + + + + (= + (active-parameter $P) + ( (advisor $P $_) + (parameter $P $Val) + (\== $Val 0))) +; + + + + !(det-if-then-else + (current-predicate initialized-advisors $_) True initialize-advisors) +; + + + +; +; + +; +; + +; +; + + + + (= + (movtable) + (det-if-then + (, + (needs-movtable $Param) + (active-parameter $Param)) True)) +; + + + + (= + (needs_movtable dynamic_mobility) True) +; + + (= + (needs_movtable gmovmob) True) +; + + + + + (= + (captable) + (det-if-then + (, + (needs-captable $Param) + (active-parameter $Param)) True)) +; + + +; +; + + + (= + (needs_captable gcapmob) True) +; + + (= + (needs_captable vital) True) +; + + (= + (needs_captable gthreat) True) +; + + (= + (needs_captable pthreat) True) +; + + (= + (needs_captable lthreat) True) +; + + (= + (needs_captable gcapmob) True) +; + + (= + (needs_captable eradicate) True) +; + + (= + (needs_captable potent) True) +; + + + +; +; + +; +; + +; +; + + + +; +; + + + (= + (value + (advice gmovmob $Player $Value) $Position $Tables) + ( (active-parameter gmovmob) + (gmobility $Player $Val $Position $Tables) + (negate-for-player $Player $Val $Value))) +; + + + +; +; + + (= + (value + (advice gcapmob $Player $Value) $Position $Tables) + ( (active-parameter gcapmob) + (gcapmobility $Player $Val1 $Position $Tables) + (favor-control $Player $Val1 $Val $Position) + (negate-for-player $Player $Val $Value))) +; + + +; +; + + (= + (value + (advice gthreat $Player $Value) $Position $Tables) + ( (active-parameter gthreat) (gthreat $Player $Value $Position $Tables))) +; + + +; +; + + (= + (value + (advice pthreat $Player $Value) $Position $Tables) + ( (active-parameter pthreat) (pthreat $Player $Value $Position $Tables))) +; + + + +; +; + + (= + (value $Value $Position $Tables) + ( (active-parameter possess) + (in-hand $Piece $Player $Position) + (not (still-assigning $Position)) + (current-predicate possess-value + (possess-value $_ $_ $_ $_ $_)) + (possess-value $Piece $Player $Value $Position $Tables))) +; + + +; +; + +; +; + + (= + (value $Value $Position $Tables) + ( (active-parameter initprom) + (current-predicate initprom-value + (initprom-value $Value $Position $Tables)) + (initprom-value $Value $Position $Tables))) +; + + +; +; + +; +; + +; +; + + (= + (value + (advice vital + (, $Goal + (@ $Piece $Square)) $Value) $Position $Tables) + ( (active-parameter vital) (threatened-vital-piece-value $Piece $Square $Player $Goal $Value $Position $Tables))) +; + + + + +; +; + +; +; + +; +; + + (= + (value + (advice random + (range $Min $Max) $Value) $Position $Tables) + ( (active-parameter random) (random-eval $Min $Max $Value))) +; + + + +; +; + +; +; + + (= + (value $Value $Position $Tables) + ( (on $Piece $Player $Square $Position) (value $Piece $Square $Value $Position $Tables))) +; + + + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + (= + (value $Piece $Sq + (advice gen-material $Type $Val) $Position $Tables) + ( (active-parameter gen-material) (gen-material-value $Piece $Player $Type $Val))) +; + + + + +; +; + +; +; + +; +; + + (= + (value $Piece $Square + (advice static $Piece $Value) $Pos $Tables) + ( (active-parameter static) (piece-player-static $Piece $Player $Value $Tables))) +; + + + +; +; + + (= + (value $Piece $Square + (advice dynamic-mobility + (@ $Piece $Square) $Value) $Position $Tables) + ( (active-parameter dynamic-mobility) + (active-advisor dynamic-mobility $Tables) + (dynamic-piece-mobility $Piece $Square $Value $Position $Tables))) +; + + +; +; + + (= + (value $Piece $Square + (advice static-mobility + (@ $Piece $Square) $Value) $Position $Tables) + ( (active-parameter static-mobility) (static-piece-mobility $Piece $Square $Value $Position $Tables))) +; + + +; +; + + (= + (value $Piece $Square + (advice eventual-mobility + (@ $Piece $Square) $Value) $Position $Tables) + ( (active-parameter eventual-mobility) (eventual-piece-mobility $Piece $Square $Value $Position $Tables))) +; + + +; +; + +; +; + + (= + (value $Piece $Square + (advice lthreat + (captures + (@ $Piece $Square) + (@ $PieceV $SqV)) $Value) $Position $Tables) + ( (active-parameter lthreat) + (active-advisor threat $Tables) + (local-threat-value $Piece $Square $PieceV $SqV $Value $Position $Tables))) +; + + + +; +; + + (= + (value $Piece $Square + (advice potent + (captures + (@ $Piece $Square) + (@ $PieceV $SqV)) $Value) $Position $Tables) + ( (active-parameter potent) + (active-advisor threat $Tables) + (potent-threat-mover $Piece $Square $PieceV $SqV $Value $Position $Tables))) +; + + + + + +; +; + + (= + (value $Piece $Square + (advice arrive-distance + (, $Goal + (@ $Piece $Square) $SqT) $Value) $Position $Tables) + ( (active-parameter arrive-distance) (arrive-value $Piece $Square $SqT $Goal $Value $Position $Tables))) +; + + +; +; + + (= + (value $Piece $Square + (advice promote-distance + (, + (@ $Piece $Square) $SqT) $Value) $Position $Tables) + ( (active-parameter promote-distance) + (active-advisor prom $Tables) + (prom-value $Piece $Square $SqT $Value $Position $Tables))) +; + + + +; +; + + (= + (value $Piece $Square + (advice dominate + (, $Goal + (@ $Piece $Square) + (@ $PieceV $SqV)) $Value) $Position $Tables) + ( (active-parameter dominate) (dominate-value $Piece $Square $PieceV $SqV $Goal $Value $Position $Tables))) +; + + + +; +; + +; +; + + (= + (value $Piece $Square + (advice dominate + (, $Goal + (@ $Piece $Square)) $Value) $Position $Tables) + ( (active-parameter dominate) (eradicate-safety $Player $Piece $Square $Goal $Value $Position $Tables))) +; + + + +; +; + + (= + (value $Piece $Square + (advice material $Piece $Value) $Position $Tables) + ( (active-parameter material) + (current-predicate $_ + (piece-value $_ $_)) + (piece-value $Piece $Value))) +; + + + +; +; + + (= + (value $Piece $Square + (advice square + (@ $Piece $Square) $Value) $Position $Tables) + ( (active-parameter square) (piece-square-value $Piece $Square $Value $Tables))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (random-eval $Min $Max $Value) + ( (parameter random-min $Min) + (parameter random-max $Max) + (random $Min $Max $Value))) +; + + + +; +; + + + (= + (gen-material-value $Piece $Player $Type $Val) + ( (owns $Piece $Player) + (piece-name $Piece $Type) + (negate-for-player $Player 1 $Val))) +; + + + +; +; + +; +; + +; +; + + + (= + (dynamic-piece-mobility $Piece $Square $Value $Position $Tables) + ( (owns $Piece $Player) + (dynamic-piece-mob $Piece $Player $Square $Val $Position $Tables) + (> $Val 0) + (negate-for-player $Player $Val $Value))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (dynamic-piece-mob $Piece $Player $Square $Count $Position $Tables) + ( (moving-table $Tables $Moves) + (unique-moves $Player $Piece $Square $SqT $Moves $Targets) + (length $Targets $Count) + (tracing-path-format moves "Dynamic: <~p>: ~p -> ~p~n" + (:: $Piece $Square $Count)))) +; + + + + + +; +; + + + (= + (static-piece-mobility $Piece $Square $Value $Position $Tables) + ( (owns $Piece $Player) + (static-piece-mob $Piece $Player $Square $Val $Position $Tables) + (negate-for-player $Player $Val $Value))) +; + + + + (= + (static-piece-mob $Piece $Player $Square $Value $Position $Tables) + ( (square-piece-mobility $Square $Piece $Value $Tables) (tracing-path-format static "In 1: <~p>: ~p -> ~p~n" (:: $Piece $Square $Value)))) +; + + + +; +; + + + (= + (eventual-piece-mobility $Piece $Square $Value $Position $Tables) + ( (owns $Piece $Player) + (eventual-piece-mob $Piece $Player $Square $Val $Position $Tables) + (negate-for-player $Player $Val $Value))) +; + + + + + (= + (eventual-piece-mob $Piece $Player $Square $Value $Position $Tables) + ( (square-piece-reachability $Square $Piece $Value $Tables) (tracing-path-format eventual "In 4: <~p>: ~p -> ~p~n" (:: $Piece $Square $Value)))) +; + + + +; +; + +; +; + +; +; + + + + (= + (initiative-offset $Control $Player $Offset) + (det-if-then-else + (= $Control $Player) + (= $Offset 0.9) + (= $Offset 0.7))) +; + + + + + (= + (favor-control $Player $Val1 $Value $Position) + ( (control $Control $Position) + (initiative-offset $Control $Player $Offset) + (is $Value + (* $Val1 $Offset)))) +; + + +; +; + +; +; + + + (= + (favorable-to-owner player $Val) + (> $Val 0)) +; + + (= + (favorable-to-owner opponent $Val) + (< $Val 0)) +; + + + +; +; + +; +; + + + (= + (control-cost $Player $Cost $Position) + ( (control $Control $Position) (det-if-then-else (= $Control $Player) (= $Cost 0) (= $Cost 1)))) +; + + + + + + (= + (negate-if-same $Player1 $Player2 $Val1 $Val) + (det-if-then-else + (\== $Player1 $Player2) + (= $Val1 $Val) + (is $Val + (- $Val1)))) +; + + + + + (= + (negate-if-different $Player1 $Player2 $Val1 $Val) + (det-if-then-else + (= $Player1 $Player2) + (= $Val1 $Val) + (is $Val + (- $Val1)))) +; + + + + (= + (negate_for_player player $Val $Val) True) +; + + (= + (negate-for-player opponent $Val $Val1) + (is $Val1 + (- $Val))) +; + + + + (= + (negate-advice-for-player $Player + (advice $A $C $V) + (advice $A $C $V1)) + (negate-for-player $Player $V $V1)) +; + + + +; +; + + + (= + (max-for-player player $List $Best) + (max $List $Best)) +; + + (= + (max-for-player opponent $List $Best) + (min $List $Best)) +; + + +; +; + + + (= + (min-for-player player $List $Best) + (min $List $Best)) +; + + (= + (min-for-player opponent $List $Best) + (max $List $Best)) +; + + + +; +; + +; +; + +; +; + + + + (= + (evalfile-top $Game) + (load-eval $Game)) +; + + + + (= + (evalfile-com $_ $_ $_ $Game) + (load-eval $Game)) +; + + + + (= + (evaluate-com $Move $SIn $_) + ( (timing (evaluation $Value $SIn)) (format "Position's value (positive favors white): ~p~n" (:: $Value)))) +; + + + + + (= + (advice-com $Move $SIn $_) + ( (timing (get-advices $As $SIn)) (ppl $As))) +; + + + + (= + (advice-com $_ $SIn $SOut $Row $Col) + ( (with-alpha-squares (gsquare $Square (:: ( $Row , $Col )) Nil)) (timing (show-local-advices $Piece $Square $SIn)))) +; + + + + + (= + (advisor-weight $Adv $Weight) + ( (advisor $Adv $_) (advisor-weight $Adv $Weight $_))) +; + + + + (= + (show-advisors) + ( (format "Advisors: ~n" Nil) (whenever (advisor-weight $Adv $Weight) (format "<~p>: ~p~n" (:: $Adv $Weight))))) +; + + + + (= + (alladvisors-com $_ $_ $_) + (show-advisors)) +; + + + (= + (alladvisors-top) + (show-advisors)) +; + + + + + (= + (seta-com $_ $_ $_) + (show-active-advisors)) +; + + + + (= + (seta-top) + (show-active-advisors)) +; + + + + (= + (active-com $_ $_ $_) + (show-active-advisors)) +; + + + + (= + (active-top) + (show-active-advisors)) +; + + + + + (= + (show-active-advisors) + ( (format "Active Advisors: ~n" Nil) (whenever (, (advisor-weight $Adv $Weight) (\== $Weight 0)) (format "<~p>: ~p~n" (:: $Adv $Weight))))) +; + + diff --git a/metagame/state/compile_syms.metta b/metagame/state/compile_syms.metta new file mode 100644 index 0000000..5d831fd --- /dev/null +++ b/metagame/state/compile_syms.metta @@ -0,0 +1,437 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + + + (= + (sym-dir $Dir $Syms $DirOut) + (in-symmetric-closure $Dir $Syms $DirOut)) +; + + + +; +; + +; +; + + + (= + (in-symmetric-closure $Dir $Syms $DirOut) + ( (closure + (:: $Dir) $Syms $Dirs) (member $DirOut $Dirs))) +; + + + + (= + (closure $Set $Transforms $Closure) + (close1 $Set $Transforms $Set $Closure)) +; + + + + (= + (close1 () $_ $T $T) True) +; + + (= + (close1 + (Cons $A $As) $Ts $Table $Close) + ( (close-item $Ts $A $As $Table $NewAs $NewTable) (close1 $NewAs $Ts $NewTable $Close))) +; + + + + (= + (close_item () $_ $As $T $As $T) True) +; + + (= + (close-item + (Cons $T $Ts) $A $As $TIn $NewAs $TOut) + ( (transform-item $A $T $ATrans) + (schedule-if $ATrans $As $TIn $NewAs1 $T1) + (close-item $Ts $A $NewAs1 $T1 $NewAs $TOut))) +; + + + + (= + (schedule-if $Item $As $Table $As $Table) + ( (member $Item $Table) (set-det))) +; + + (= + (schedule_if $Item $As $Table + (Cons $Item $As) + (Cons $Item $Table)) True) +; + + + + + (= + (transform-item $Dir $Sym $NewDir) + (symmetry $Sym $Dir $NewDir)) +; + + + + (= + (symmetry forward + (dir $X $Y) + (dir $X $Y1)) + (negates $Y $Y1)) +; + + (= + (symmetry side + (dir $X $Y) + (dir $X1 $Y)) + (negates $X $X1)) +; + + (= + (symmetry rotation + (dir $X $Y) + (dir $Y $X)) True) +; + + + + + (= + (negates $N $N1) + (| + (det-if-then + (var $N) + (is $N + (* $N1 -1))) + (det-if-then otherwise + (is $N1 + (* $N -1))))) +; + + + +; +; + +; +; + + +; +; + +; +; + +; +; + + + + + (= + (game-movement $Game $Movement) + ( (game-piece-def $Game $_ $Def) (piece-defines-movement $Def $Movement))) +; + + + + (= + (piece-defines-movement $Def $Movement) + ( (piece-movement $Def $CompMovement) (movement-component $CompMovement $Movement))) +; + + (= + (piece-defines-movement $Def $M) + ( (piece-capture $Def $CompCapture) + (capture-component $CompCapture $Capture) + (capture-has-movement $Capture $M))) +; + + + + + (= + (game-syms-dir $Game $Syms $Dir) + ( (game-movement $Game $M) + (movement-dir $M $Dir) + (movement-syms $M $Syms))) +; + + + + (= + (unique-sym-dirs $SymDirs) + (setof + (- + (- $Dir $Syms) $Sym) + (^ $Game + (, + (some-player-game $Game) + (game-sym-dir $Game $Dir $Syms $Sym))) $SymDirs)) +; + + + + (= + (game-sym-dir $Game $Dir $Syms $Sym) + ( (game-syms-dir $Game $Syms $Dir) (in-symmetric-closure $Dir $Syms $Sym))) +; + + + + (= + (some-player-game $Game) + (or + (player-current-game $Game) + (opponent-current-game $Game))) +; + + + + + (= + (index-sym-dirs) + (with-temp-file syms $File + (, + (index-sym-dirs-to-file $File) + (compile $File)))) +; + + + + (= + (index-sym-dirs-to-file $File) + ( (format "~nIndexing Symmetries to file: ~w~n" + (:: $File)) + (assert-sym-indices) + (with-output-file $File write + (, + (print-sym-overwrite) + (listing sym-index) + (overwrite-game))) + (abolish (/ sym-index 3)))) +; + + + + + (= + (assert-sym-indices) + ( (abolish (/ sym-index 3)) + (unique-sym-dirs $Dirs) + (whenever + (member + (- + (- $Dir $Syms) $Sym) $Dirs) + (assert-sym-index $Dir $Syms $Sym)))) +; + + + + (= + (assert-sym-index $Dir $Syms $Sym) + ( (dir-key $Dir $Key) (add-symbol &self (sym_index $Key $Syms $Sym)))) +; + + + + + (= + (print-all-syms) + ( (unique-sym-dirs $L) + (member + (- + (- $Dir $_) $Sym) $L) + (format "~p --> ~p~n" + (:: $Dir $Sym)) + (fail))) +; + + + + (= + (indexed-sym-dir $Dir $Syms $Sym) + ( (dir-key $Dir $Key) (sym-index $Key $Syms $Sym))) +; + + + + + (= + (print-sym-overwrite) + (format "\n% Compiled Symmetry File\n\n:- abolish(sym_dir/3).\n\nsym_dir(Dir,Syms,Sym) :- \n\tindexed_sym_dir(Dir,Syms,Sym).\n\n" Nil)) +; + + + + + (= + (overwrite-game) + ( (print-game-overwrite) + (listing player-current-game) + (listing opponent-current-game))) +; + + + + + (= + (print-game-overwrite) + (format "\n% Compiled Game File\n\n:- abolish(player_current_game/1).\n:- abolish(opponent_current_game/1).\n\n" Nil)) +; + + + + + (= + (dir-key + (dir $X $Y) $Key) + (is $Key + (+ + (* 1000 $X) $Y))) +; + + + + (= + (square-key + (square $X $Y) $Key) + (is $Key + (+ + (* 1000 $X) $Y))) +; + + + +; +; + +; +; + + + + + (= + (time1) + ( (timing (fastsyms $FastS)) + (nl) + (print $FastS) + (timing (slowsyms $SlowS)) + (nl) + (print $SlowS))) +; + + + + (= + (time-sym $N) + ( (timing (dotimes $N (fastsyms $_))) (timing (dotimes $N (slowsyms $_))))) +; + + + + + (= + (fastsyms $SS) + (setof $S + (indexed-sym-dir + (dir 2 1) + (:: forward side rotation) $S) $SS)) +; + + + + (= + (slowsyms $SS) + (setof $S + (in-symmetric-closure + (dir 2 1) + (:: forward side rotation) $S) $SS)) +; + + + + +; + diff --git a/metagame/state/efficient_state.metta b/metagame/state/efficient_state.metta new file mode 100644 index 0000000..95104f7 --- /dev/null +++ b/metagame/state/efficient_state.metta @@ -0,0 +1,910 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + + !(my-ensure-loaded (library aux)) +; + + +; +; + +; +; + + +; +; + + +; +; + +; +; + + +; +; + +; +; + +; +; + + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + +; +; + +; +; + +; +; + + + + (= + (new-state (state $S)) + (initialize-state Nil $S)) +; + + +; +; + + + (= + (initialize-state $SIn $SOut) + ( (setof + (- $P $I) + (pred-index $P $I) $Indices) (initialize-state-indices $Indices $SIn $SOut))) +; + + + + (= + (initialize_state_indices () $SIn $SIn) True) +; + + (= + (initialize-state-indices + (Cons + (- $P $I) $Is) $SIn $SOut) + ( (initialize-state-index $P $I $SIn $S1) (initialize-state-indices $Is $S1 $SOut))) +; + + + +; +; + +; +; + +; +; + +; +; + + +; +; + + + + (= + (initialize-state-index $P $I $SIn + (Cons $Bucket $SIn)) + (init-bucket $P $Bucket)) +; + + + + (= + (is_state + (state $_)) True) +; + + + + (= + (true-in $Pred + (state $State)) + (db-true $Pred $State)) +; + + + + (= + (add-in $Pred + (state $SIn) + (state $SOut)) + (db-add $Pred $SIn $SOut)) +; + + + + (= + (del-in $Pred + (state $SIn) + (state $SOut)) + (db-del $Pred $SIn $SOut)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (db-true $P $SIn) + ( (db-key $P $Key) (in-key $Key $P $SIn))) +; + + + + (= + (db-add $P $SIn $SOut) + ( (db-key $P $Key) (add-key $Key $P $SIn $SOut))) +; + + +; +; + + + (= + (db-del $P $SIn $SOut) + ( (db-key $P $Key) (del-key $Key $P $SIn $SOut))) +; + + + + (= + (db-key $P $Key) + (pred-index $P $Key)) +; + + + + (= + (in-key $Key $P $SIn) + ( (find-bucket $Key $SIn $Bucket) (in-bucket $P $Bucket))) +; + + + + (= + (add-key $Key $P $SIn $SOut) + ( (find-bucket $Key $SIn $Bucket) + (add-bucket $P $Bucket $Bucket1) + (set-bucket $Key $SIn $Bucket1 $SOut))) +; + + + + (= + (del-key $Key $P $SIn $SOut) + ( (find-bucket $Key $SIn $Bucket) + (del-bucket $P $Bucket $Bucket1) + (set-bucket $Key $SIn $Bucket1 $SOut))) +; + + + + (= + (find-bucket $Index $State $Bucket) + (nth-element $Index $State $Bucket)) +; + + + + (= + (set-bucket $Index $SIn $Bucket $SOut) + (set-nth-element $Index $SIn $Bucket $SOut)) +; + + + +; +; + +; +; + + +; +; + +; +; + + +; +; + +; +; + + + +; +; + +; +; + +; +; + + + +; +; + + + + (= + (init-bucket + (on $_ $_) $Bucket) + ( (set-det) (new-game-board $Bucket))) +; + + (= + (init_bucket $_ ()) True) +; + + + + + (= + (empty-row $X $Term) + ( (functor $Term1 row $X) (empty-elements $X $Term1 $Term))) +; + + + + + (= + (empty-elements 0 $Board $Board) + (set-det)) +; + + (= + (empty-elements $N $Board1 $Board) + ( (>= $N 1) + (emptify $N $Board1 $Board2) + (is $N1 + (- $N 1)) + (empty-elements $N1 $Board2 $Board))) +; + + + + (= + (emptify $N $Board1 $Board2) + ( (empty-filler $E) + (arg $N $Board1 $E) + (= $Board1 $Board2))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (empty_filler $_) True) +; + + +; +; + +; +; + +; +; + + + + + (= + (empty-board $X $Y $Term) + ( (functor $Term1 gameboard $Y) (empty-rows $Y $X $Term1 $Term))) +; + + + + (= + (empty-rows 0 $X $Board $Board) + (set-det)) +; + + (= + (empty-rows $N $X $Board1 $Board) + ( (>= $N 1) + (emptify-row $N $X $Board1 $Board2) + (is $N1 + (- $N 1)) + (empty-rows $N1 $X $Board2 $Board))) +; + + + + (= + (emptify-row $N $X $Board1 $Board2) + ( (empty-row $X $Row) + (arg $N $Board1 $Row) + (= $Board1 $Board2))) +; + + + + (= + (new-game-board $Board) + ( (current-board-size $X $Y) (empty-board $X $Y $Board))) +; + + + +; +; + + + + (= + (in-bucket + (on $Piece + (square $X $Y)) $Board) + ( (set-det) (piece-on-square $X $Y $Board $Piece))) +; + + (= + (in-bucket $P $Bucket) + (member-bag $P $Bucket)) +; + + + +; +; + + + + (= + (add-bucket + (on $Piece + (square $X $Y)) $A $A1) + ( (set-det) (change-piece-on-square $X $Y $Piece $A $A1))) +; + + + (= + (add-bucket $P $A $A1) + (add-bag $P $A $A1)) +; + + + + (= + (del-bucket + (on $Piece $Sq) $E $E1) + ( (set-det) (= $E $E1))) +; + + (= + (del-bucket $P $E $E1) + ( (set-det) (del-bag $P $E $E1))) +; + + + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + + + + !(my-use-module (library args)) +; + + + + (= + (piece-on-square $X $Y $Board $Piece) + (path-arg + (:: $Y $X) $Board $Piece)) +; + + + + (= + (change-piece-on-square $X $Y $Piece $Board1 $Board2) + ( (same-functor $Board1 $Board2 $YMax) (change-item-in-column $YMax $Y $X $Board1 $Piece $Board2))) +; + + + + (= + (change-item-in-column $Curr $Curr $X $Board1 $Item $Board2) + ( (set-det) + (corresponding-arg $Curr $Board1 $Row1 $Board2 $Row2) + (same-functor $Row1 $Row2 $XMax) + (change-item-in-row $XMax $X $Row1 $Item $Row2) + (is $Curr1 + (- $Curr 1)) + (copy-columns $Curr1 $Board1 $Board2))) +; + + (= + (change-item-in-column $Curr $Y $X $Board1 $Item $Board2) + ( (same-arg $Curr $Board1 $Board2) + (is $Curr1 + (- $Curr 1)) + (change-item-in-column $Curr1 $Y $X $Board1 $Item $Board2))) +; + + + + (= + (copy-columns 0 $Board1 $Board2) + (set-det)) +; + + (= + (copy-columns $Curr $Board1 $Board2) + ( (same-arg $Curr $Board1 $Board2) + (is $Curr1 + (- $Curr 1)) + (copy-columns $Curr1 $Board1 $Board2))) +; + + + + + (= + (change-item-in-row $Curr $Curr $Row1 $Item $Row2) + ( (set-det) + (corresponding-arg $Curr $Row1 $Old $Row2 $Item) + (is $Curr1 + (- $Curr 1)) + (copy-rows $Curr1 $Row1 $Row2))) +; + + (= + (change-item-in-row $Curr $X $Row1 $Item $Row2) + ( (same-arg $Curr $Row1 $Row2) + (is $Curr1 + (- $Curr 1)) + (change-item-in-row $Curr1 $X $Row1 $Item $Row2))) +; + + + + (= + (copy-rows 0 $Row1 $Row2) + (set-det)) +; + + (= + (copy-rows $Curr $Row1 $Row2) + ( (same-arg $Curr $Row1 $Row2) + (is $Curr1 + (- $Curr 1)) + (copy-rows $Curr1 $Row1 $Row2))) +; + + +; +; + +; +; + +; +; + + +; +; + +; +; + + + + (= + (nth-element 1 + (Cons $H $T) $H) + (set-det)) +; + + (= + (nth-element $N + (Cons $H $T) $Nth) + ( (is $Next + (- $N 1)) (nth-element $Next $T $Nth))) +; + + + + + (= + (nth-element-between $G $G + (Cons $H $Rest) Nil $H $Rest) + (set-det)) +; + + (= + (nth-element-between $Goal $Current + (Cons $H $T) + (Cons $H $Before) $Nth $Rest) + ( (is $Next + (+ $Current 1)) (nth-element-between $Goal $Next $T $Before $Nth $Rest))) +; + + +; +; + +; +; + +; +; + + + + (= + (set-nth-element 1 + (Cons $H $Rest) $Val + (Cons $Val $Rest)) + (set-det)) +; + + (= + (set-nth-element $N + (Cons $H $T) $Nth + (Cons $H $Rest)) + ( (is $Next + (- $N 1)) (set-nth-element $Next $T $Nth $Rest))) +; + + + +; +; + +; +; + +; +; + + +; +; + + + + (= + (member_bag $Elem + (Cons $Elem $Bag)) True) +; + + (= + (member-bag $Elem + (Cons $_ $Rest)) + (member-bag $Elem $Rest)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (add_bag $Elem $Bag + (Cons $Elem $Bag)) True) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + + + + (= + (del-bag $Elem + (Cons $H $T) $Rest) + (det-if-then-else + (= $Elem $H) + (= $Rest $T) + (, + (= $Rest + (Cons $H $Rest1)) + (del-bag $Elem $T $Rest1)))) +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + + + + + (= + (index-dynamic-preds) + ( (index-preds-file $File) + (index-dynamic-preds-to-file $File) + (compile $File))) +; + + + + (= + (index-dynamic-preds-to-file $File) + ( (format "~nIndexing Dynamic Predicates to file: ~w~n" + (:: $File)) + (assert-pred-indices) + (tell $File) + (listing pred-index) + (told) + (remove-all-symbols &self + (pred_index $_ $_)))) +; + + + + (= + (assert-pred-indices) + (or + (, + (abolish (/ pred-index 2)) + (pred-index-slow $Pred $Index) + (add-symbol &self + (pred_index $Pred $Index)) + (fail)) True)) +; + + +; +; + + + (= + (pred-index-slow $Pred $Index) + ( (dynamic-predicates $Preds) (nth $Index $Preds $Pred))) +; + + + diff --git a/metagame/state/stat.metta b/metagame/state/stat.metta new file mode 100644 index 0000000..a64bb51 --- /dev/null +++ b/metagame/state/stat.metta @@ -0,0 +1,454 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + !(my-ensure-loaded (library tracing)) +; + + + !(dynamic (/ stativity 2)) +; + + + + + (= + (stat $A 0) + ( (var $A) + (write "~n Warning: Error in Stat routine, Variable!") + (nl) + (set-det))) +; + + + (= + (stat + (, $A $B) $S) + ( (set-det) + (stat $A $StatA) + (stat $B $StatB) + (max $StatA $StatB $S))) +; + + + (= + (stat + (or $A $B) $S) + ( (set-det) + (stat $A $StatA) + (stat $B $StatB) + (max $StatA $StatB $S))) +; + + + (= + (stat + (if $Cond $Then $Else) $S) + ( (set-det) + (stat $Cond $CondS) + (stat $Then $ThenS) + (stat $Else $ElseS) + (max + (:: $CondS $ThenS $ElseS) $S))) +; + + + (= + (stat + (det-if-then-else $Cond $Then $Else) $S) + ( (set-det) + (stat $Cond $CondS) + (stat $Then $ThenS) + (stat $Else $ElseS) + (max + (:: $CondS $ThenS $ElseS) $S))) +; + + + (= + (stat + (det-if-then $Cond $Then) $S) + ( (set-det) + (stat $Cond $CondS) + (stat $Then $ThenS) + (max + (:: $CondS $ThenS) $S))) +; + + + (= + (stat + (call $Call) $S) + ( (set-det) (stat $Call $S))) +; + + + (= + (stat + (not $Call) $S) + ( (set-det) (stat $Call $S))) +; + + +; +; + +; +; + + (= + (stat + (setof $X $Test $Xs) $S) + ( (set-det) + (stat $Test $TestS) + (min + (:: $TestS 1) $S))) +; + + + (= + (stat + (bagof $X $Test $Xs) $S) + ( (set-det) + (stat $Test $TestS) + (min + (:: $TestS 1) $S))) +; + + + (= + (stat + (^ $X $Test) $Is) + ( (set-det) (stat $Test $Is))) +; + + + (= + (stat $GIn 1) + ( (test-goal $GIn) (set-det))) +; + + + (= + (stat $GIn 2) + ( (change-goal $GIn) (set-det))) +; + + + (= + (stat $GIn $S) + ( (stativity $GIn $S) (set-det))) +; + + + (= + (stat $_ 0) True) +; + + + + + (= + (change_goal + (add $Pred)) True) +; + + (= + (change_goal + (del $Pred)) True) +; + + + + (= + (test_goal + (true $Pred)) True) +; + + + +; +; + +; +; + + + + (= + (stativity-analysis) + ( (initialize-stats 0) (interpret-stativity))) +; + + + +; +; + + + + !(dynamic (/ changed 0)) +; + + + + + (= + (initialize-stats $InitVal) + ( (reset-stat) + (theory-clause $GIn $Body) + (variablized-goal $GIn $VGIn) + (det-if-then-else + (stativity $VGIn $Stat) + (det-if-then-else + (= $Stat $InitVal) True + (format "Error: Some stat entry not reset properly~n" Nil)) + (add-symbol &self + (stativity $VGIn $InitVal))) + (fail))) +; + + (= + (initialize_stats $_) True) +; + + + + (= + (interpret-stativity) + ( (tracing-format + (stat 1) "Starting an iteration of stativity interpretation~n" Nil) + (do-analysis) + (loop-if-changed))) +; + + + + (= + (loop-if-changed) + ( (remove-symbol &self changed) + (set-det) + (interpret-stativity))) +; + + (= + (loop-if-changed) + (tracing-format + (stat 1) "Reached fixed point, interpretation has ended.~n" Nil)) +; + + + + + (= + (do-analysis) + ( (clear-changed) (or (, (analysis-item $Item) (analyze-item $Item) (fail)) True))) +; + + + + (= + (analysis-item (= $Goal $Body)) + (theory-clause $Goal $Body)) +; + + + + (= + (analyze-item (= $Goal $Body)) + ( (stat $Body $Stat) (update-assumption $Goal $Stat))) +; + + +; +; + + + (= + (update-assumption $P $Stat) + ( (stativity $P $StatOld) + (=< $Stat $StatOld) + (set-det))) +; + + (= + (update-assumption $P $Stat) + ( (variablized-goal $P $VP) + (remove-symbol &self + (stativity $VP $StatOld)) + (add-symbol &self + (stativity $VP $Stat)) + (tracing-format + (stat 2) "Procedure <~p> changed stativity from <~p> to <~p>~n" + (:: $P $StatOld $Stat)) + (note-changed))) +; + + + + + + (= + (note-changed) + ( (changed) (set-det))) +; + + (= + (note-changed) + ( (tracing-format + (stat 2) "Initial stativity changed this iteration~n" Nil) (add-symbol &self changed))) +; + + + + (= + (clear-changed) + (remove-all-symbols &self changed)) +; + + + (= + (reset-stat) + (remove-all-symbols &self + (stativity $_ $_))) +; + + + + + (= + (variablized-goal $GoalIn $GoalOut) + ( (functor $GoalIn $F $A) (functor $GoalOut $F $A))) +; + + +; +; + +; +; + + + + (= + (set-stat-verbosity $Level $Status) + (set-tracing + (stat $Level) $Status)) +; + + + (= + (silent-stat) + ( (set-stat-verbosity 1 off) (set-stat-verbosity 2 off))) +; + + + + !(set-stat-verbosity 1 on) +; + + diff --git a/metagame/state/statify_theory.metta b/metagame/state/statify_theory.metta new file mode 100644 index 0000000..66837b0 --- /dev/null +++ b/metagame/state/statify_theory.metta @@ -0,0 +1,406 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + + + !(my-ensure-loaded (library aux)) +; + + !(my-ensure-loaded (library stat)) +; + + +; +; + +; +; + + +; +; + + +; +; + + +; +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (compile-and-load-player) + (state-compile-player)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (state-compile-player) + ( (compile-dynamic-preds) + (index-dynamic-preds) + (player-theory-load) + (player-theory-compile) + (theory-clear))) +; + + + + (= + (player-theory-load) + ( (format "Loading Theory: MetaGame~n" Nil) + (theory-clear) + (player-theory-files $Files) + (dl $Files))) +; + + + + (= + (player-theory-compile) + ( (format "Compiling Theory: MetaGame~n" Nil) + (stativity-analysis) + (compile-player-files))) +; + + + + (= + (compile-player-files) + ( (theory-files $Files) (whenever (member $File $Files) (thcomp $File)))) +; + + + + (= + (player-compiled-files $CompFiles) + ( (theory-files $Files) (bagof $CompFile (^ $File (, (member $File $Files) (theory-statname $File $CompFile))) $CompFiles))) +; + + + + (= + (player-theory-files $CompFiles) + ( (theory-files $Files) (bagof $CompFile (^ $File (, (member $File $Files) (theory-filename $File $CompFile))) $CompFiles))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (load-compiled-play-theory) + ( (player-compiled-files $Fs) (whenever (member $F $Fs) (compile $F)))) +; + + + + + (= + (theory-filename $FileRoot $CompFileName) + ( (sys-suffixed-filename $FileRoot prolog $File) + (theory-directory $TheoryDir) + (concat-list + (:: $TheoryDir / $File) $CompFileName))) +; + + + + (= + (theory-statname $FileRoot $CompFileName) + ( (sys-suffixed-filename $FileRoot state-compile $File) + (theory-directory $TheoryDir) + (concat-list + (:: $TheoryDir / $File) $CompFileName))) +; + + + + + (= + (thcomp $FileRoot) + ( (theory-filename $FileRoot $FileIn) + (theory-statname $FileRoot $FileOut) + (state-compile-file $FileIn $FileOut) + (compile $FileOut))) +; + + + + (= + (state-compile-file $FileIn $FileOut) + ( (format "Compiling theory file: ~w~n" + (:: $FileIn)) + (see $FileIn) + (tell $FileOut) + (compile-clauses) + (set-det) + (seen) + (told) + (format "Wrote compiled file: ~w~n" + (:: $FileOut)))) +; + + + + (= + (compile-clauses) + (det-if-then-else + (, + (read $ClauseIn) + (\== $ClauseIn end-of-file)) + (, + (compile-clause $ClauseIn $ClauseOut) + (portray-clause $ClauseOut) + (compile-clauses)) True)) +; + + + + + (= + (compile-clause $CIn $COut) + ( (clause-parts $CIn $HIn $BIn) (thread-clause $HIn $BIn $COut))) +; + + + + (= + (thread-clause $HeadIn $BodyIn $ClauseOut) + ( (add-state $HeadIn $SIn $SOut $HeadOut) + (thread $BodyIn $SIn $SOut $BodyOut) + (clause-parts $ClauseOut $HeadOut $BodyOut))) +; + + + + + (= + (add-state $GoalIn $Stativity $GoalOut) + (add-state $GoalIn $SIn $SOut $Stativity $GoalOut)) +; + + + (= + (add-state $GoalIn $SIn $SOut $GoalOut) + ( (stat $GoalIn $Stat) (add-state $GoalIn $SIn $SOut $Stat $GoalOut))) +; + + + +; +; + +; +; + +; +; + +; +; + + (= + (add_state $GoalIn $SIn $SIn 0 $GoalIn) True) +; + + (= + (add-state $GoalIn $SIn $SIn 1 $GoalOut) + (thread-in-state $GoalIn $SIn $GoalOut)) +; + + (= + (add-state $GoalIn $SIn $SOut 2 $GoalOut) + ( (thread-in-state $GoalIn $SIn $G1) (thread-in-state $G1 $SOut $GoalOut))) +; + + + + (= + (thread-in-state $GoalIn $SIn $GoalOut) + (increase-term-arity $GoalIn $SIn $GoalOut)) +; + + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (dynamic_predicates + ( (control $Player) + (on $Piece $Square) + (moved_onto $Piece $Sq) + (move_count $L) + (stage $Stage) + (effects $Effect $Captures) + (in_hand $Piece $Player) + (opponent_promotes $OldPiece $Sq))) True) +; + + + + + (= + (compile-dynamic-preds) + ( (dynamic-preds-file $F) (compile-dynamics $F))) +; + + + + + (= + (compile-dynamics $Dest) + ( (format "~nCompiling Dynamic Predicates to theory file: ~w~n" + (:: $Dest)) + (tell $Dest) + (dynamic-predicates $Preds) + (compile-preds $Preds) + (told))) +; + + + + (= + (compile_preds ()) True) +; + + (= + (compile-preds (Cons $H $T)) + ( (make-state $H) (compile-preds $T))) +; + + + + (= + (make-state $Pred) + ( (statify $Pred $Clause) (portray-clause $Clause))) +; + + + + + (= + (statify $PredIn $Clause) + (= $Clause + (= $PredIn + (true $PredIn)))) +; + + + diff --git a/metagame/state/thread.metta b/metagame/state/thread.metta new file mode 100644 index 0000000..5593750 --- /dev/null +++ b/metagame/state/thread.metta @@ -0,0 +1,202 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + + + + (= + (thread + (det-if-then-else $Cond $Then $Else) $SIn $SOut $Answer) + ( (set-det) + (thread $Cond $SIn $S1 $CondOut) + (thread $Then $S1 $S2 $ThenOut) + (thread $Else $SIn $S3 $ElseOut) + (= $Answer + (det-if-then-else $CondOut + (, $ThenOut + (= $SOut $S2)) + (, $ElseOut + (= $SOut $S3)))))) +; + + + (= + (thread + (det-if-then $Cond $Then) $SIn $SOut $Answer) + ( (set-det) + (thread $Cond $SIn $S1 $CondOut) + (thread $Then $S1 $S2 $ThenOut) + (= $Answer + (det-if-then $CondOut + (, $ThenOut + (= $SOut $S2)))))) +; + + + (= + (thread + (if $Cond $Then $Else) $SIn $SOut $Answer) + ( (set-det) + (thread $Cond $SIn $S1 $CondOut) + (thread $Then $S1 $S2 $ThenOut) + (thread $Else $SIn $S3 $ElseOut) + (= $Answer + (if $CondOut + (, $ThenOut + (= $SOut $S2)) + (, $ElseOut + (= $SOut $S3)))))) +; + + + (= + (thread + (, $A $B) $SIn $SOut $Answer) + ( (set-det) + (thread $A $SIn $S1 $AOut) + (thread $B $S1 $SOut $BOut) + (= $Answer + (, $AOut $BOut)))) +; + + + (= + (thread + (or $A $B) $SIn $SOut $Answer) + ( (set-det) + (thread $A $SIn $S1 $AOut) + (thread $B $SIn $S2 $BOut) + (= $Answer + (or + (, $AOut + (= $SOut $S1)) + (, $BOut + (= $SOut $S2)))))) +; + + +; +; + + (= + (thread + (call $Call) $SIn $SOut $Answer) + ( (set-det) (det-if-then-else (var $Call) (, (= $Answer (call $Call)) (= $SIn $SOut)) (, (thread $Call $SIn $SOut $CallOut) (= $Answer (call $CallOut)))))) +; + + + (= + (thread + (not $Call) $SIn $SOut $Answer) + ( (set-det) + (thread $Call $SIn $S1 $CallOut) + (= $Answer + (, + (not $CallOut) + (= $SIn $SOut))))) +; + + + (= + (thread + (setof $X $Test $Xs) $SIn $SIn $Answer) + ( (set-det) + (thread $Test $SIn $S1 $TestOut) + (= $Answer + (setof $X + (^ $S1 $TestOut) $Xs)))) +; + + + (= + (thread + (bagof $X $Test $Xs) $SIn $SIn $Answer) + ( (set-det) + (thread $Test $SIn $S1 $TestOut) + (= $Answer + (bagof $X + (^ $S1 $TestOut) $Xs)))) +; + + + (= + (thread + (^ $X $Test) $SIn $SOut $Answer) + ( (set-det) + (thread $Test $SIn $SOut $TestOut) + (= $Answer + (^ $X $TestOut)))) +; + + + + (= + (thread + !$B $SIn $SOut $Answer) + ( (set-det) + (thread $B $SIn $SOut $BOut) + (= $Answer + !$BOut))) +; + + + (= + (thread + (= $H $B) $SIn $SOut $Answer) + ( (set-det) + (thread $H $SIn $SOut $HOut) + (thread $B $SIn $SOut $BOut) + (= $Answer + (= $HOut $BOut)))) +; + + + (= + (thread + (true $GIn) $SIn $SOut $Answer) + ( (set-det) + (= $SIn $SOut) + (= $Answer + (true-in $GIn $SIn)))) +; + + + (= + (thread + (add $GIn) $SIn $SOut $Answer) + ( (set-det) (= $Answer (add-in $GIn $SIn $SOut)))) +; + + + (= + (thread + (del $GIn) $SIn $SOut $Answer) + ( (set-det) (= $Answer (del-in $GIn $SIn $SOut)))) +; + + + (= + (thread $GIn $SIn $SOut $GOut) + (add-state $GIn $SIn $SOut $GOut)) +; + + + diff --git a/metagame/theory/boards.metta b/metagame/theory/boards.metta new file mode 100644 index 0000000..0ff473d --- /dev/null +++ b/metagame/theory/boards.metta @@ -0,0 +1,811 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (start-game) + (start-game $Game)) +; + + + (= + (start-game $Game) + ( (initialize-state-properties) (create-board-and-setup $Game))) +; + + + + + (= + (default_init_move_count 0) True) +; + + + (= + (default_init_stage assign) True) +; + + + (= + (default_init_control player) True) +; + + +; +; + +; +; + +; +; + +; +; + + + + (= + (initialize-state-properties) + ( (default-init-stage $Stage) + (default-init-control $Player) + (default-init-move-count $Count) + (initialize-state-properties $Stage $Player $Count))) +; + + + (= + (initialize-state-properties $Stage $Player $Count) + ( (put-stage $Stage) + (put-control $Player) + (add (move-count $Count)))) +; + + + + + (= + (create-board-and-setup $Game) + ( (initialize-board $Game) (create-initial-setup $Game))) +; + + + + + (= + (create-initial-setup $Game) + ( (game-has-assignments $Game $Ass) (do-assignments $Ass))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (initialize-board $Game) + (make-empty-board)) +; + + + + (= + (make-empty-board) + ( (current-board $B) + (board-size $B $X $Y) + (array-squares $X $Y $Squares) + (make-empty $Squares))) +; + + + + (= + (make_empty ()) True) +; + + (= + (make-empty (Cons $Sq $Rest)) + ( (set-empty $Sq) (make-empty $Rest))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (do-assignments $As) + ( (arbitrary-assignment $As) + (set-det) + (do-arbitrary-assignment $As))) +; + + (= + (do-assignments $As) + ( (assignment-decision $As $Assigner $PieceNames $Squares) + (player $Assigner) + (set-det) + (invert + (= $Assigner $Squares) opponent + (= $OppAssigner $OppSquares)) + (do-assignments-for-player player $Assigner $PieceNames $Squares) + (do-assignments-for-player opponent $OppAssigner $PieceNames $OppSquares))) +; + + + + (= + (assignment-decision $As $Assigner $PieceNames $Squares) + (decision $As $Assigner $PieceNames $Squares)) +; + + + + + (= + (do-assignments-for-player $Owner $Placer $PieceNames $Squares) + ( (make-assignable-squares $Placer $Squares) (place-pieces-in-hand $PieceNames $Owner $Placer))) +; + + + + (= + (make-assignable-squares $Player $Squares) + ( (det-if-then-else + (remove-symbol &self + (assignable_squares $Player $_)) True True) (add-symbol &self (assignable_squares $Player $Squares)))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (arbitrary_assignment + (Cons $_ $_)) True) +; + +; +; + + + + (= + (do-arbitrary-assignment $As) + (place-pieces-on-squares $As)) +; + + + + (= + (place-pieces-on-squares $Assign) + ( (uncollect $Assign $As) + (place-pieces-on-squares $As player) + (invert $As opponent $IAs) + (place-pieces-on-squares $IAs opponent))) +; + + + (= + (place_pieces_on_squares () $_) True) +; + + (= + (place-pieces-on-squares + (Cons $A $As) $Player) + ( (assign-piece-to-square $A $Player) (place-pieces-on-squares $As $Player))) +; + + + + (= + (assign-piece-to-square + (= $P $Sq) $Player) + ( (piece-struct $Piece $P $Player) (place-piece $Piece $Sq))) +; + + + +; +; + +; +; + +; +; + + + + (= + (place_pieces_in_hand () $Player $Hand) True) +; + + (= + (place-pieces-in-hand + (Cons $P $Ps) $Player $Hand) + ( (place-piece-in-hand $P $Player $Hand) (place-pieces-in-hand $Ps $Player $Hand))) +; + + + + (= + (place-piece-in-hand $P $Player $Hand) + ( (piece-struct-name $Piece $P) + (owns $Piece $Player) + (put-in-hand $Piece $Hand))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (connected $S1 $S2 $Dir) + ( (square $S1 $Xf $Yf) + (square $S2 $Xt $Yt) + (direction $Dir $DX $DY) + (current-board-type $T) + (conn-for-type $T + (, $Xf $Yf) + (, $Xt $Yt) + (, $DX $DY)))) +; + + + + (= + (conn-for-type planar $From $To $Dir) + (conn $From $To $Dir)) +; + + (= + (conn-for-type vertical-cylinder $From $To $Dir) + (conn-cyl $From $To $Dir)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (conn + (, $Xf $Yf) + (, $Xt $Yt) + (, $Dx $Dy)) + (| + (det-if-then + (, + (var $Xf) + (var $Yf)) + (, + (is $Xf + (- $Xt $Dx)) + (is $Yf + (- $Yt $Dy)) + (legal-location (, $Xf $Yf)))) + (| + (det-if-then + (, + (var $Xt) + (var $Yt)) + (, + (is $Xt + (+ $Xf $Dx)) + (is $Yt + (+ $Yf $Dy)) + (legal-location (, $Xt $Yt)))) + (| + (det-if-then + (, + (var $Dx) + (var $Dy)) + (, + (is $Dx + (- $Xt $Xf)) + (is $Dy + (- $Yt $Yf)))) + (det-if-then otherwise + (, + (is $Xf + (- $Xt $Dx)) + (is $Yf + (- $Yt $Dy)))))))) +; + + + +; +; + +; +; + +; +; + + + (= + (legal-location $Sq) + (on-board $Sq)) +; + + + + (= + (on-board (, $X $Y)) + ( (current-board-size $XMax $YMax) + (>= $X 1) + (=< $X $XMax) + (>= $Y 1) + (=< $Y $YMax))) +; + + + +; +; + +; +; + +; +; + + + + + (= + (conn-cyl + (, $Xf $Yf) + (, $Xt $Yt) + (, $Dx $Dy)) + (| + (det-if-then + (, + (var $Xf) + (var $Yf)) + (, + (is $Xf1 + (- $Xt $Dx)) + (is $Yf1 + (- $Yt $Dy)) + (legal-location-cyl + (, $Xf1 $Yf1) + (, $Xf $Yf)))) + (| + (det-if-then + (, + (var $Xt) + (var $Yt)) + (, + (is $Xt1 + (+ $Xf $Dx)) + (is $Yt1 + (+ $Yf $Dy)) + (legal-location-cyl + (, $Xt1 $Yt1) + (, $Xt $Yt)))) + (| + (det-if-then + (, + (var $Dx) + (var $Dy)) + (, + (is $Dx + (- $Xt $Xf)) + (is $Dy + (- $Yt $Yf)))) + (det-if-then otherwise + (, + (is $Xf1 + (- $Xt $Dx)) + (is $Yf1 + (- $Yt $Dy)) + (legal-location-cyl + (, $Xf1 $Yf1) + (, $Xf $Yf)))))))) +; + + + + +; +; + +; +; + +; +; + +; +; + + + (= + (legal-location-cyl + (, $X1 $Y1) + (, $X $Y)) + ( (current-board-size $XN $YN) + (is $X + (+ + (mod + (- + (+ $X1 $XN) 1) $XN) 1)) + (= $Y $Y1) + (on-board (, $X $Y)))) +; + + + + + +; +; + +; +; + +; +; + +; +; + + + + (= + (valid-min $N $N) + ( (number $N) (set-det))) +; + + (= + (valid_min $_ 1) True) +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (valid-max $N $_ $N) + ( (number $N) (set-det))) +; + + (= + (valid-max $_ $Dir $Max) + ( (direction $Dir $Dx $Dy) + (is $XMag + (abs $Dx)) + (is $YMag + (abs $Dy)) + (valid-max-dir $XMag $YMag $Max))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (valid-max-dir 0 0 1) + (set-det)) +; + + (= + (valid-max-dir 0 $Dy $Max) + ( (set-det) + (current-board-size $XMax $YMax) + (is $Max + (// $YMax $Dy)))) +; + + (= + (valid-max-dir $Dx 0 $Max) + ( (set-det) + (current-board-type $Type) + (current-board-size $XMax $YMax) + (max-leaps $Type $XMax $Dx $Max))) +; + + (= + (valid-max-dir $Dx $Dy $Max) + ( (current-board-type vertical-cylinder) + (set-det) + (current-board-size $XMax $YMax) + (is $Max + (// $YMax $Dy)))) +; + + (= + (valid-max-dir $Dx $Dy $Max) + ( (current-board-size $Bx $By) + (is $XMax + (// $Bx $Dx)) + (is $YMax + (// $By $Dy)) + (min $XMax $YMax $Max))) +; + + + + + (= + (max-leaps planar $BMax $Delta $Max) + ( (set-det) (is $Max (// $BMax $Delta)))) +; + + (= + (max-leaps vertical-cylinder $BMax $Delta $Max) + (wrap-leaps $BMax $Delta $Max)) +; + + + + + + (= + (wl $A $B $C) + (wrap-leaps $A $B $C)) +; + + + + (= + (wrap-leaps $Board $D $Max) + ( (gcf $Board $D $F) + (max $Board $D $M) + (is $Max + (// $M $F)))) +; + + +; +; + +; +; + + + (= + (gcf $A 0 $A) + (set-det)) +; + + (= + (gcf $A $B $F) + ( (is $M + (mod $A $B)) (gcf $B $M $F))) +; + + + diff --git a/metagame/theory/goals.metta b/metagame/theory/goals.metta new file mode 100644 index 0000000..5489c7a --- /dev/null +++ b/metagame/theory/goals.metta @@ -0,0 +1,417 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (game-over) + (goal-achieved $Player $Game)) +; + + (= + (game-over) + (exceeded-move-limit $Game)) +; + + (= + (game-over) + (too-many-repetitions $Game)) +; + + + +; +; + +; +; + +; +; + + + + (= + (exceeded-move-limit $Game) + ( (game-move-limit $Game $L) (move-count $L))) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (game_move_limit $Game 200) True) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (move_limit_outcome $Game draw) True) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + + + (= + (game_repetitions $Game 3) True) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (repetition_outcome $Game draw) True) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (too_many_repetitions $Game) + (empty)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (game-outcome $Outcome) + ( (too-many-repetitions $Game) + (set-det) + (repetition-outcome $Game $Outcome))) +; + + (= + (game-outcome $Outcome) + ( (exceeded-move-limit $Game) + (set-det) + (move-limit-outcome $Game $Outcome))) +; + + (= + (game-outcome $Outcome) + ( (player-outcome player $WinP) + (player-outcome opponent $WinO) + (outcome $WinP $WinO $Outcome))) +; + + + +; +; + + + (= + (player-outcome $Player $Outcome) + (det-if-then-else + (goal-achieved $Player $Game) + (= $Outcome yes) + (= $Outcome no))) +; + + + +; +; + +; +; + +; +; + + + (= + (outcome yes yes draw) True) +; + + (= + (outcome yes no player) True) +; + + (= + (outcome no yes opponent) True) +; + + + +; +; + +; +; + + + (= + (goal-achieved $Player $Game) + ( (game-player-has-goal $Game $Player $Goal) + (goal-true $Goal) + (verbosely-format "Goal achieved: ~p achieved goal ~p~n" + (:: $Player $Goal)))) +; + + + +; +; + +; +; + + + (= + (goal-true (arrive $Descr $Squares)) + ( (member $Sq $Squares) + (on $Piece $Sq) + (matches $Descr $Piece))) +; + + +; +; + +; +; + +; +; + +; +; + + (= + (goal-true (eradicate $Descr)) + ( (not still-assigning) (not (exists $Descr)))) +; + + +; +; + +; +; + + (= + (goal-true (stalemate $Player)) + ( (control $Player) (not (legal-move $M $Player)))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (exists $Descr) + ( (on $Piece $Sq) (matches $Descr $Piece))) +; + + + + diff --git a/metagame/theory/invert.metta b/metagame/theory/invert.metta new file mode 100644 index 0000000..61bf866 --- /dev/null +++ b/metagame/theory/invert.metta @@ -0,0 +1,157 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + + +; +; + +; +; + + + (= + (invert $Term $Player $Term2) + (det-if-then-else + (= $Player player) + (= $Term $Term2) + (invert $Term $Term2))) +; + + + + (= + (invert opponent player) + (set-det)) +; + + (= + (invert player opponent) + (set-det)) +; + + (= + (invert $Term $Term2) + (det-if-then-else + (atom $Term) + (= $Term $Term2) + (invert-struct $Term $Term2))) +; + + + +; +; + + + (= + (invert-struct + (square $X1 $Y1) $Sq) + ( (set-det) (invert-square (square $X1 $Y1) $Sq))) +; + + (= + (invert-struct + (dir $X1 $Y1) $Dir) + ( (set-det) (invert-dir (dir $X1 $Y1) $Dir))) +; + + (= + (invert-struct $Pred $PredOut) + ( (functor $Pred $F $N) + (functor $PredOut $F $N) + (invert-args $N $Pred $PredOut))) +; + + + + (= + (invert-args 0 $_ $_) + (set-det)) +; + + (= + (invert-args $N $Pred $PredOut) + ( (arg $N $Pred $A) + (invert $A $A1) + (arg $N $PredOut $A1) + (is $N1 + (- $N 1)) + (invert-args $N1 $Pred $PredOut))) +; + + + + + (= + (invert-square $Sq1 $Sq) + ( (current-board-size $XN $YN) + (current-board-inversion $Inv) + (invert-square-dim $Inv $XN $YN $Sq1 $Sq))) +; + + + + (= + (invert-square-dim diagonal $XN $YN + (square $X1 $Y1) + (square $X2 $Y2)) + ( (is $X2 + (+ + (- $XN $X1) 1)) (is $Y2 (+ (- $YN $Y1) 1)))) +; + + (= + (invert-square-dim forward $XN $YN + (square $X1 $Y1) + (square $X2 $Y2)) + ( (= $X1 $X2) (is $Y2 (+ (- $YN $Y1) 1)))) +; + + + + + (= + (invert-dir + (dir $X1 $Y1) + (dir $X2 $Y2)) + ( (current-board-inversion $Inv) + (inv-negate-dir $Inv x $X1 $X2) + (inv-negate-dir $Inv y $Y1 $Y2))) +; + + + + (= + (inv-negate-dir diagonal $Axis $X $XNeg) + (negates $X $XNeg)) +; + + (= + (inv-negate-dir forward $Axis $X1 $X2) + (det-if-then-else + (= $Axis y) + (negates $X1 $X2) + (= $X1 $X2))) +; + + + diff --git a/metagame/theory/legal.metta b/metagame/theory/legal.metta new file mode 100644 index 0000000..e50b8ff --- /dev/null +++ b/metagame/theory/legal.metta @@ -0,0 +1,2585 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (legal $M) + ( (control $Player) (legal-move $M $Player))) +; + + +; +; + + + (= + (legal-move $Move $Player) + ( (stage $Stage) (legal-move $Move $Stage $Player))) +; + + +; +; + +; +; + + + (= + (legal-move $M $Stage $Player) + ( (increment-move-count) + (legal-move $M $Stage $Player $StageOut $_) + (transfer-stage $Stage $StageOut))) +; + + + + + (= + (legal-move + (Cons $M $Rest) $StageIn $PlayerIn $StageOut $PlayerOut) + ( (pseudo-op $StageIn $M $PlayerIn $Stage1 $Player1) (det-if-then-else (\== $PlayerIn $Player1) (, (= $Player1 $PlayerOut) (= $Stage1 $StageOut)) (legal-move $Rest $Stage1 $Player1 $StageOut $PlayerOut)))) +; + + + + +; +; + +; +; + +; +; + + + + (= + (player_role player) True) +; + + (= + (player_role opponent) True) +; + + + + (= + (opposite_role player opponent) True) +; + + (= + (opposite_role opponent player) True) +; + + + + + + (= + (change $P1 $P2) + ( (del $P1) (add $P2))) +; + + +; +; + + +; +; + + + (= + (empty $Sq) + (on empty $Sq)) +; + + + + (= + (set-empty $Sq) + (add (on empty $Sq))) +; + + +; +; + + + (= + (on $PieceStruct $Player $Square) + ( (piece-struct-owner $PieceStruct $Player) (on $PieceStruct $Square))) +; + + +; +; + + + (= + (piece_struct_name + (piece $Name $Owner) $Name) True) +; + + + (= + (piece_struct_owner + (piece $Name $Owner) $Owner) True) +; + + + + (= + (piece_struct + (piece $Name $Owner) $Name $Owner) True) +; + + + + (= + (owns $Piece $Owner) + (piece-struct-owner $Piece $Owner)) +; + + + + + (= + (add-to-board $Piece $Square) + (place-piece $Piece $Square)) +; + + + + (= + (put-in-hand $Piece $Player) + (add (in-hand $Piece $Player))) +; + + + + + (= + (place-piece-from-hand $Piece $Player $Square) + ( (del (in-hand $Piece $Player)) (place-piece $Piece $Square))) +; + + +; +; + +; +; + + + (= + (lift-piece $Piece $Square) + (change + (on $Piece $Square) + (on empty $Square))) +; + + + + (= + (place-piece $Piece $Square) + (change + (on empty $Square) + (on $Piece $Square))) +; + + + + (= + (remove-piece $Taken $TakenSq) + (lift-piece $Taken $TakenSq)) +; + + + + + (= + (put-control $Player) + ( (det-if-then-else + (control $P) + (del (control $P)) True) (add (control $Player)))) +; + + + +; +; + + + (= + (transfer-control $Player) + (transfer-control $Player $Opp)) +; + + + (= + (transfer-control $Player $Opp) + ( (opposite-role $Player $Opp) (change (control $Player) (control $Opp)))) +; + + + +; +; + +; +; + + + (= + (move-piece-record $Piece $SqF $SqT) + ( (move-piece $Piece $SqF $SqT) (add (moved-onto $Piece $SqT)))) +; + + + + (= + (place-piece-record $Piece $SqT) + (add (moved-onto $Piece $SqT))) +; + + +; +; + + + (= + (move-piece $Piece $SqF $SqT) + ( (on $Piece $SqF) + (lift-piece $Piece $SqF) + (place-piece $Piece $SqT))) +; + + + + + (= + (set-effect $Effect $Captured) + (add (effects $Effect $Captured))) +; + + + + (= + (del-effect $Effect $Captured) + (del (effects $Effect $Captured))) +; + + + + (= + (set-effect $Effect) + (add (effect $Effect))) +; + + + + (= + (del-effect $Effect) + (del (effect $Effect))) +; + + + + (= + (transfer-stage $Stage) + ( (stage $OldStage) (transfer-stage $OldStage $Stage))) +; + + + (= + (transfer-stage $Old $New) + (change + (stage $Old) + (stage $New))) +; + + + + (= + (put-stage $Stage) + ( (det-if-then-else + (stage $OldStage) + (del (stage $OldStage)) True) (add (stage $Stage)))) +; + + + + + (= + (capture-piece $Taken $TakenSq) + (remove-piece $Taken $TakenSq)) +; + + +; +; + +; +; + + + (= + (replace-piece $Old $New $Sq) + (det-if-then-else + (= $Old $New) True + (change + (on $Old $Sq) + (on $New $Sq)))) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (replace-piece-record $Old $New $Sq) + (place-piece $New $Sq)) +; + + + + + (= + (increment-move-count) + ( (move-count $M) + (is $M1 + (+ $M 1)) + (change + (move-count $M) + (move-count $M1)))) +; + + + +; +; + + + (= + (assignable $Square $Player) + ( (assignable-squares $Player $Squares) (member $Square $Squares))) +; + + +; +; + +; +; + + + (= + (still-assigning) + ( (stage assign) (in-hand $Piece $Player))) +; + + + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (pseudo-op assign + (assign $Piece $Player $Square) $Player assign $Opponent) + ( (assign $Piece $Player $Square) (transfer-control $Player $Opponent))) +; + + (= + (pseudo-op assign end-assign $Player move $Player) + (end-assign)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (pseudo-op init-promote + (opponent-promote $Sq $OldPiece $NewPiece) $Player move $Player) + (opponent-promote $Sq $OldPiece $NewPiece $Player)) +; + + + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + (= + (pseudo-op move + (place $Piece $Player $Square) $Player move $Opponent) + (place-op $Piece $Player $Square $Opponent)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (pseudo-op move + (move $Piece $Player $SqF $SqT) $Player $Stage $Player) + (global-or-local-move $Piece $Player $SqF $SqT $Stage)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (pseudo-op capture + (capture $Effect $Captured) $Player continue $Player) + (capture-op $Effect $Captured $Player)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (pseudo-op continue $Move $Player $Stage $Player) + (try-continue-or-end $Move $Player $Stage)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (pseudo-op promote + (try-promote $Square $OldPiece $NewPiece) $Player $Stage $Player2) + (try-promote $Square $OldPiece $NewPiece $Player $Stage $Player2)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (pseudo-op promote-select + (promote-select $Sq $OldPiece $NewPiece) $Player $Stage $Player2) + (promote-select $Sq $OldPiece $NewPiece $Player $Stage $Player2)) +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + + +; +; + + + (= + (assign $Piece $Player $Square) + ( (placeable $Piece $Player $Square) + (assignable $Square $Player) + (place-piece-from-hand $Piece $Player $Square))) +; + + + + (= + (end-assign) + (not (in-hand $Piece $Player))) +; + + + +; +; + +; +; + +; +; + + + (= + (place-op $Piece $Player $Square $Opponent) + ( (placeable $Piece $Player $Square) + (place-piece-from-hand $Piece $Player $Square) + (transfer-control $Player $Opponent))) +; + + + + + (= + (placeable $Piece $Player $Square) + ( (bagof $Piece + (in-hand $Piece $Player) $AllPieces) + (remove-duplicates $AllPieces $Pieces) + (member $Piece $Pieces) + (empty $Square))) +; + + + + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (global-or-local-move $Piece $Player $SqF $SqT $Stage) + (det-if-then-else current-game-must-capture + (global-prefer-capture $Piece $Player $SqF $SqT $Stage) + (local-move $Piece $Player $SqF $SqT $Stage))) +; + + + + (= + (global-prefer-capture $Piece $Player $SqF $SqT $Stage) + ( (global-prefer-capture1 $Piece1 $Player $SqF1 $SqT1 $Stage1) + (= $Piece1 $Piece) + (= $SqF1 $SqF) + (= $SqT1 $SqT) + (= $Stage $Stage1))) +; + + + + (= + (global-prefer-capture1 $Piece $Player $SqF $SqT $Stage) + (if + (, + (moveable $Piece $Player $SqF) + (capturing $Piece $Player $SqF $SqT)) + (= $Stage capture) + (, + (moveable $Piece $Player $SqF) + (moving $Piece $Player $SqF $SqT) + (= $Stage promote)))) +; + + + + + (= + (local-move $Piece $Player $SqF $SqT $Stage) + ( (moveable $Piece $Player $SqF) (local-could-move $Piece $Player $SqF $SqT $Stage))) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (local-could-move $Piece $Player $SqF $SqT $Stage) + (det-if-then-else + (must-capture $Piece) + (local-prefer-capture $Piece $Player $SqF $SqT $Stage) + (general-moving $Piece $Player $SqF $SqT $Stage))) +; + + + + (= + (local-prefer-capture $Piece $Player $SqF $SqT $Stage) + (if + (capturing $Piece $Player $SqF $Sq1) + (, + (= $Sq1 $SqT) + (= $Stage capture)) + (, + (moving $Piece $Player $SqF $SqT) + (= $Stage promote)))) +; + + + + + (= + (general-moving $Piece $Player $SqF $SqT capture) + (capturing $Piece $Player $SqF $SqT)) +; + + (= + (general-moving $Piece $Player $SqF $SqT promote) + (moving $Piece $Player $SqF $SqT)) +; + + + + (= + (must-capture $Piece) + (game--piece-must $Piece)) +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (reaches $Piece $Player $SqF $SqT) + (moves $Piece $Player $SqF $SqT)) +; + + (= + (reaches $Piece $Player $SqF $SqT) + (captures $Piece $Player $SqF $SqT)) +; + + + + +; +; + +; +; + +; +; + +; +; + + + (= + (moving $Piece $Player $SqF $SqT) + ( (game--piece-has-movement $Piece $Move) + (moving-movement-for-piece $Piece $SqF $SqT $Player $Move $Dir $Hop) + (place-piece-record $Piece $SqT))) +; + + + + (= + (moves $Piece $Player $SqF $SqT) + ( (game--piece-has-movement $Piece $Move) (moving-movement-for-piece $Piece $SqF $SqT $Player $Move $Dir $Hop))) +; + + + +; +; + +; +; + +; +; + + + (= + (moving-movement-for-piece $Piece $SqF $SqT $Player $Movement $Dir $Hop) + ( (if + (, + (ride $Movement $Dir $Min $Max $Longest) + (longest $Longest) + (current-board-type planar)) + (longest-moving-ride $SqF $Dir $Min $Max $SqT) + (movement-for-piece $Piece $SqF $SqT $Player $Movement $Dir $Hop)) (valid-movement $SqT))) +; + + +; +; + + + (= + (valid-movement $SqT) + (empty $SqT)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (moveable $Piece $Player $SqF) + ( (on $Piece $Player $SqF) (lift-piece $Piece $SqF))) +; + + + +; +; + +; +; + +; +; + + +; +; + +; +; + + + (= + (movement-for-piece $Piece $SqF $SqT $Player $Movement $Dir Nil) + ( (leap $Movement $Dir) (connected $SqF $SqT $Dir))) +; + + +; +; + +; +; + +; +; + +; +; + + (= + (movement-for-piece $Piece $SqF $SqT $Player $Movement $Dir Nil) + ( (ride $Movement $Dir $Min $Max $Longest) (open-line $SqF $Dir $Min $Max empty $Squares $SqT))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (movement-for-piece $Piece $SqF $SqT $Player $Movement $Dir $Hopped) + ( (hop $Movement $Dir $Before $Over $After $Description) (hoplines $SqF $SqT $Dir $Before $Over $After $Description $Hopped))) +; + + + + (= + (hoplines $SqF $SqT $Dir $Before $Over $After $Description $Hopped) + (det-if-then-else + (var $SqF) + (hoplines-rev $SqF $SqT $Dir $Before $Over $After $Description $Hopped) + (hoplines-fwd $SqF $SqT $Dir $Before $Over $After $Description $Hopped))) +; + + + + (= + (hoplines-fwd $SqF $SqT $Dir $Before $Over $After $Description $Hopped) + ( (hopline $SqF $Before $Dir empty $_ $SqB) + (hopline $SqB $Over $Dir $Description $Hopped $SqO) + (hopline $SqO $After $Dir empty $_ $SqL) + (connected $SqL $SqT $Dir))) +; + + + + (= + (hoplines-rev $SqF $SqT $Dir $Before $Over $After $Description $Hopped) + ( (connected $SqL $SqT $Dir) + (hopline $SqO $After $Dir empty $_ $SqL) + (hopline $SqB $Over $Dir $Description $Hopped $SqO) + (hopline $SqF $Before $Dir empty $_ $SqB))) +; + + + + + (= + (hopline $SqF $Range $Dir $Descr $Squares $SqT) + ( (comparative-interval $Range $Dir $MinB $MaxB) (constrained-line $SqF $Dir $MinB $MaxB $Descr $Squares $SqT))) +; + + +; +; + +; +; + +; +; + +; +; + + +; +; + + + (= + (comparative-interval + (comparison $Comp $X) $Dir $N $MaxLeaps) + (comparative-interval $Comp $X $Dir $N $MaxLeaps)) +; + + + (= + (comparative-interval geq $N $Dir $N $MaxLeaps) + (valid-max $_ $Dir $MaxLeaps)) +; + + (= + (comparative_interval eq $N $_ $N $N) True) +; + + (= + (comparative_interval leq $N $_ 0 $N) True) +; + + +; +; + +; +; + +; +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (open-line $SqF $Dir $Min $Max $Cond $Squares $SqT) + (det-if-then-else + (var $SqF) + (open-line-rev $SqF $Dir $Min $Max $Cond $Squares $SqT) + (open-line-fwd $SqF $Dir $Min $Max $Cond $Squares $SqT))) +; + + + + + (= + (open-line-fwd $SqF $Dir $Min $Max $Cond $Squares $SqT) + ( (is $Min1 + (- $Min 1)) + (is $Max1 + (- $Max 1)) + (constrained-line-fwd $SqF $Dir $Min1 $Max1 $Cond $Squares $Sq1) + (connected $Sq1 $SqT $Dir))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (constrained-line $SqF $Dir $Min $Max $Cond $Squares $SqT) + (det-if-then-else + (var $SqF) + (constrained-line-rev $SqF $Dir $Min $Max $Cond $Squares $SqT) + (constrained-line-fwd $SqF $Dir $Min $Max $Cond $Squares $SqT))) +; + + + + (= + (constrained-line-fwd $SqF $Dir $Min $Max $Cond $Squares $SqT) + (all-sat-fwd $SqF $Dir $Cond 0 $Min $Max $Squares $SqT)) +; + + + + (= + (all-sat-fwd $SqF $Dir $Cond $Count $Min $Max Nil $SqF) + ( (>= $Count $Min) (=< $Count $Max))) +; + + (= + (all-sat-fwd $SqF $Dir $Cond $Count $Min $Max + (Cons $Sq1 $Squares) $SqT) + ( (< $Count $Max) + (connected $SqF $Sq1 $Dir) + (crossable $Cond $Sq1) + (is $Count1 + (+ $Count 1)) + (all-sat-fwd $Sq1 $Dir $Cond $Count1 $Min $Max $Squares $SqT))) +; + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (open-line-rev $SqF $Dir $Min $Max $Cond $Squares $SqT) + ( (is $Min1 + (- $Min 1)) + (is $Max1 + (- $Max 1)) + (connected $Sq1 $SqT $Dir) + (constrained-line-rev $SqF $Dir $Min1 $Max1 $Cond $Squares $Sq1))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (constrained-line-rev $SqF $Dir $Min $Max $Cond $Squares $SqT) + (all-sat-rev $SqF $Dir $Cond 0 $Min $Max $Squares $SqT)) +; + + + + (= + (all-sat-rev $SqF $Dir $Cond $Count $Min $Max Nil $SqF) + ( (>= $Count $Min) (=< $Count $Max))) +; + + (= + (all-sat-rev $SqF $Dir $Cond $Count $Min $Max + (Cons $SqT $Squares) $SqT) + ( (< $Count $Max) + (connected $Sq1 $SqT $Dir) + (crossable $Cond $SqT) + (is $Count1 + (+ $Count 1)) + (all-sat-rev $SqF $Dir $Cond $Count1 $Min $Max $Squares $Sq1))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (crossable $Descr $Sq) + (det-if-then-else + (= $Descr empty) + (empty $Sq) + (, + (on $P $Sq) + (matches $Descr $P)))) +; + + + +; +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (capturing $Piece $Player $SqF $SqT) + ( (captures $Piece $Player $SqF $SqT $Effect $Captured) + (place-piece-record $Piece $SqT) + (set-effect $Effect $Captured))) +; + + +; +; + +; +; + +; +; + + + (= + (captures $Piece $Player $SqF $SqT) + (captures $Piece $Player $SqF $SqT $Effect $Captured)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + (= + (captures $Piece $Player $SqF $SqT $Effect $Captured) + ( (game--piece-has-capture $Piece $Capture) + (capture-has-movement $Capture $Movement) + (capture-effect $Capture $Effect) + (capturing-movement-for-piece $Piece $SqF $SqT $Player $Movement $Capture $Captured))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (capturing-movement-for-piece $Piece $SqF $SqT $Player $Movement $Capture $Captured) + (capturing-movement-for-piece $Piece $SqF $SqT $Player $Dir $Movement $Capture $Captured)) +; + + +; +; + + (= + (capturing-movement-for-piece $Piece $SqF $SqT $Player $Dir $Movement $Capture $Captured) + (if + (, + (ride $Movement $Dir $Min $Max $Longest) + (longest $Longest) + (current-board-type planar)) + (longest-capturing-ride $SqF $Dir $Min $Max $SqT $Capture $Captured) + (, + (movement-for-piece $Piece $SqF $SqT $Player $Movement $Dir $Hopped) + (captured-pieces $SqF $SqT $Capture $Dir $Hopped $Captured)))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (longest-moving-ride $SqF $Dir $Min $Max $SqT) + ( (> $Min $Max) + (set-det) + (fail))) +; + + (= + (longest-moving-ride $SqF $Dir $Min $Max $SqT) + ( (open-line $SqF $Dir $Max $Max empty $Squares $SqT) + (empty $SqT) + (set-det))) +; + + (= + (longest-moving-ride $SqF $Dir $Min $Max $SqT) + ( (is $Max1 + (- $Max 1)) (longest-moving-ride $SqF $Dir $Min $Max1 $SqT))) +; + + + +; +; + + + + (= + (longest-capturing-ride $SqF $Dir $Min $Max $SqT $Capture $_) + ( (> $Min $Max) + (set-det) + (fail))) +; + + (= + (longest-capturing-ride $SqF $Dir $Min $Max $SqT $Capture $Captured) + ( (open-line $SqF $Dir $Max $Max empty $Squares $SqT) + (captured-pieces $SqF $SqT $Capture $Dir Nil $Captured) + (set-det))) +; + + (= + (longest-capturing-ride $SqF $Dir $Min $Max $SqT $Capture $Captured) + ( (is $Max1 + (- $Max 1)) (longest-capturing-ride $SqF $Dir $Min $Max1 $SqT $Capture $Captured))) +; + + +; +; + + + + (= + (captured-pieces $SqF $SqT $Capturing $Dir $Hopped $Captures) + ( (capture-type $Capturing $Type) + (if + (clobbers $SqT $Capturing $Type $Clobs) True + (= $Clobs Nil)) + (if + (retrieves $SqF $Dir $Capturing $Type $Retrs) True + (= $Retrs Nil)) + (det-if-then-else + (hops $Hopped $Capturing $Type $Hops) True + (= $Hops Nil)) + (append $Retrs $Clobs $L1) + (append $Hops $L1 $Captures) + (valid-capture $SqT $Captures))) +; + + +; +; + +; +; + +; +; + + + (= + (valid-capture $Final $Captured) + ( (something-captured $Captured) (will-be-empty $Final $Captured))) +; + + +; +; + + + (= + (something_captured + (Cons $_ $_)) True) +; + + +; +; + + + (= + (will-be-empty $Sq $Captured) + (det-if-then-else + (captured-piece $Piece $Sq $Captured) True + (empty $Sq))) +; + + + + (= + (captured-piece $Victim $SqV $Captured) + ( (captured $Cap $Victim $SqV) (member $Cap $Captured))) +; + + + + + (= + (clobbers $Sq $Capturing $Type + (:: (@ $Piece $Sq))) + ( (capture-has-method $Capturing clobber) + (on $Piece $Sq) + (matches $Type $Piece))) +; + + + + (= + (retrieves $SqF $Dir $Capturing $Type + (:: (@ $Piece $Sq1))) + ( (capture-has-method $Capturing retrieve) + (connected $Sq1 $SqF $Dir) + (on $Piece $Sq1) + (matches $Type $Piece))) +; + + + + (= + (hops $Hopped $Capturing $Type $Hops) + ( (capture-has-method $Capturing hop) (matchers-on-squares $Hopped $Type $Hops))) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (matchers_on_squares () $_ ()) True) +; + + (= + (matchers-on-squares + (Cons $H $Hs) $Type $Caps) + ( (on $P $H) + (det-if-then-else + (matches $Type $P) + (= $Caps + (Cons + (@ $P $H) $Rest)) + (= $Caps $Rest)) + (matchers-on-squares $Hs $Type $Rest))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (capture-op $Effect $Captured $Player) + ( (del-effect $Effect $Captured) (effect-captures $Captured $Effect))) +; + + + + + (= + (effect_captures () $_) True) +; + + (= + (effect-captures + (Cons $Cap $Caps) $Effect) + ( (effect-capture $Effect $Cap) (effect-captures $Caps $Effect))) +; + + + + + (= + (effect-capture remove $Cap) + ( (captured $Cap $Piece $Sq) (lift-piece $Piece $Sq))) +; + + (= + (effect-capture + (possess $Owner) $Cap) + ( (captured $Cap $Piece $Sq) + (lift-piece $Piece $Sq) + (piece-struct $Piece $Type $Player) + (piece-struct $NewPiece $Type $Owner) + (put-in-hand $NewPiece $Owner))) +; + + + + (= + (captured + (@ $Piece $Sq) $Piece $Sq) True) +; + + + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (try-continue-or-end $Move $Player $Stage) + (if + (may-continue $Piece $Sq) + (if + (must-continue $Piece) + (continue-captures $Piece $Player $Sq $SqT $Move $Stage) + (continue-or-end $Piece $Player $Sq $SqT $Move $Stage)) + (discontinue $Move $Stage))) +; + + + + (= + (must-continue $Piece) + (game--piece-must $Piece)) +; + + + + (= + (may-continue $Piece $Sq) + ( (moved-onto $Piece $Sq) (game--piece-continues $Piece))) +; + + + + + (= + (continue-or-end $Piece $Player $Sq $SqT + (move $Piece $Player $Sq $SqT) capture) + ( (del (moved-onto $Piece $Sq)) (capturing $Piece $Player $Sq $SqT))) +; + + (= + (continue-or-end $_ $_ $_ $_ $Move $Stage) + (discontinue $Move $Stage)) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (continue-captures $Piece $Player $Sq $SqT $Move $Stage) + (if + (, + (= $Move + (move $Piece $Player $Sq $SqT)) + (del (moved-onto $Piece $Sq)) + (capturing $Piece $Player $Sq $SqT)) + (= $Stage capture) + (discontinue $Move $Stage))) +; + + + + (= + (discontinue end_continues promote) True) +; + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + + (= + (try-promote $Sq $OldPiece $NewPiece $Player $Stage $Player2) + ( (moved-onto $OldPiece $Sq) + (verbosely (format "Checking for promotion~n" Nil)) + (promote-if $OldPiece $Player $Sq $NewPiece $Stage $Player2))) +; + + + + (= + (promote-if $OldPiece $Player1 $Sq $NewPiece $Stage $Player2) + ( (in-promote-region $Sq $Player1) + (set-det) + (game--piece-promoting $OldPiece $Promoting) + (promote-if1 $OldPiece $Promoting $Player1 $Sq $NewPiece $Stage $Player2))) +; + + +; +; + +; +; + +; +; + + (= + (promote-if $OldPiece $Player1 $Sq Nil $Stage $Player2) + ( (del (moved-onto $OldPiece $Sq)) + (verbosely (format "~n~p is not in promotion territory for ~p~n" (:: $OldPiece $Player1))) + (place-piece $OldPiece $Sq) + (end-promote $Player1 $Stage $Player2))) +; + + + + (= + (promote-if1 $OldPiece $Promoting $Player1 $Sq $NewPiece $Stage $Player2) + ( (simple-promote $Promoting $Player1 $NewPiece) + (verbosely (format "Promoting: ~p on ~p --> ~p~n" (:: $OldPiece $Sq $NewPiece))) + (replace-piece-record $OldPiece $NewPiece $Sq) + (del (moved-onto $OldPiece $Sq)) + (end-promote $Player1 $Stage $Player2))) +; + + + + (= + (promote-if1 $OldPiece $Promoting $Player1 $Sq $NewPiece $Stage $Player2) + ( (promoter $Promoting $Player1 $Promoter) (promote-role $Promoter $Player1 $OldPiece $Sq $Stage $Player2))) +; + + +; +; + +; +; + + + (= + (promote_role $Player $Player $_ $_ promote_select $Player) True) +; + + (= + (promote-role $Opponent $Player $OldPiece $Sq $Stage $Player2) + ( (opposite-role $Player $Opponent) + (add (opponent-promotes $OldPiece $Sq)) + (del (moved-onto $OldPiece $Sq)) + (end-promote $Player $Stage $Player2))) +; + + + + + (= + (simple-promote $Promoting $Player $NewPiece) + ( (promoting-info $Promoting + (promote $Type)) (piece-struct $NewPiece $Type $Player))) +; + + + + (= + (promoter $Promoting $Player $Promoter) + (= $Promoting + (promote $Promoter $Descr))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (in-promote-region $Sq $Player) + ( (game--promote-rank $Rank) + (invert $Sq $Player $Sq1) + (square $Sq1 $X $Y) + (>= $Y $Rank))) +; + + + + +; +; + +; +; + +; +; + + + + (= + (promote-select $Sq $OldPiece $NewPiece $Player $Stage $Player2) + ( (moved-onto $OldPiece $Sq) + (verbosely-format "~p decides on promotion for ~p on ~p~n" + (:: $Player $OldPiece $Sq)) + (game--piece-promoting $OldPiece $Promoting) + (promoting-options $Promoting $Player $Descr) + (matches $Descr $NewPiece) + (replace-piece-record $OldPiece $NewPiece $Sq) + (del (moved-onto $OldPiece $Sq)) + (end-promote $Player $Stage $Player2))) +; + + + +; +; + +; +; + +; +; + +; +; + + + (= + (end-promote $Player $Stage $Player2) + (end-move $Player $Stage $Player2)) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (promoting-options $Promoting $Player $Descr) + ( (= $Promoting + (promote $Actor $Descr1)) (det-if-then-else (opposite-role $Player $Actor) (invert $Descr1 opponent $Descr) (= $Descr $Descr1)))) +; + + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + +; +; + + + + + (= + (opponent-promote $Sq $OldPiece $NewPiece $Player) + (det-if-then-else + (opponent-promotes $OldPiece $Sq) + (, + (del (opponent-promotes $OldPiece $Sq)) + (verbosely-format "~p decides on promotion for ~p on ~p~n" + (:: $Player $OldPiece $Sq)) + (init-promote-option $OldPiece $Player $NewPiece) + (replace-piece-record $OldPiece $NewPiece $Sq)) + (, + (= $Sq Nil) + (= $OldPiece Nil) + (= $NewPiece Nil)))) +; + + +; +; + + + (= + (init-promote-option $OldPiece $Player $NewPiece) + ( (game--piece-promoting $OldPiece $Promoting) + (promoting-options $Promoting $Player $Descr) + (matches $Descr $NewPiece))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (end-move $Player init-promote $Opponent) + ( (verbosely-format "~p finished moving~n" + (:: $Player)) (transfer-control $Player $Opponent))) +; + + + + diff --git a/metagame/theory/matches.metta b/metagame/theory/matches.metta new file mode 100644 index 0000000..79a92bb --- /dev/null +++ b/metagame/theory/matches.metta @@ -0,0 +1,94 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (matches $Descr $Piece) + ( (piece-description $Descr $Player_Gen $Piece_Gen) + (piece-struct $Piece $Name $Player) + (matches-player $Player_Gen $Player) + (matches-name $Piece_Gen $Name))) +; + + + + + (= + (matches-player any-player $Player) + (player-role $Player)) +; + + (= + (matches_player player player) True) +; + + (= + (matches_player opponent opponent) True) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (matches-name any-piece $Name) + (current-game-piece-name $Name)) +; + + (= + (matches-name + (Cons $H $T) $Name) + (member $Name + (Cons $H $T))) +; + + + diff --git a/metagame/theory/parse.metta b/metagame/theory/parse.metta new file mode 100644 index 0000000..b2d470a --- /dev/null +++ b/metagame/theory/parse.metta @@ -0,0 +1,389 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (current-game $Game) + (det-if-then-else + (control $Player) + (current-game-for-player $Player $Game) + (player-current-game $Game))) +; + + +; +; + + +; +; + +; +; + +; +; + +; +; + + + + (= + (game-player-has-goal $Game $Player $Goal) + ( (current-game-for-player $Player $Game) (game-has-goal $Game $Goal))) +; + + + +; +; + + + + (= + (current-board $B) + ( (current-game $G) (game-board $G $B))) +; + + + + (= + (current-board-size $X $Y) + ( (player-current-game $G) + (game-board $G $B) + (board-size $B $X $Y))) +; + + + + (= + (current-board-type $Type) + ( (player-current-game $G) + (game-board $G $B) + (board-type $B $Type))) +; + + + + (= + (current-board-inversion $Type) + ( (player-current-game $G) + (game-board $G $B) + (board-inversion $B $Type))) +; + + + + +; +; + +; +; + + + (= + (game-assignments $Game $Assign) + ( (player-current-game $Game) + (game-board $Game $Board) + (board-assignments $Board $Assign))) +; + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + (= + (game-has-assignments $Game $Assign) + ( (game-assignments $Game $Assign1) (full-assignment-if-random $Assign1 $Assign))) +; + + + + (= + (full-assignment-if-random $As $Assignments) + ( (random-assignment-decision $As) + (set-det) + (random-assignment $Assignments))) +; + + (= + (full_assignment_if_random $As $As) True) +; + + + + +; +; + +; +; + + + (= + (current-random-setup-game) + ( (player-current-game $Game) (random-setup-game $Game))) +; + + + +; +; + +; +; + + + (= + (random-setup-game $Game) + ( (game-assignments $Game $Assign) (random-assignment-decision $Assign))) +; + + + + (= + (random-assignment-decision $AssignmentDef) + ( (assignment-decision $AssignmentDef $Assigner $PieceNames $Squares) (= $Assigner random))) +; + + + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + +; +; + + +; +; + +; +; + +; +; + +; +; + + + + (= + (current-game-piece-struct-def $PieceStruct $Def) + ( (piece-struct-name $PieceStruct $Name) (current-game-piece-def $Game $Name $Def))) +; + + + + (= + (current-game-piece-def $Name $Def) + ( (current-game $Game) (game-piece-def $Game $Name $Def))) +; + + + + (= + (game--piece-has-movement $Piece $Movement) + ( (current-game $Game) (game-piece-has-movement $Piece $Movement $Game))) +; + + + + (= + (game--piece-has-capture $Piece $Capture) + ( (current-game $Game) (game-piece-has-capture $Piece $Capture $Game))) +; + + + + (= + (game--piece-has-constraint $Piece $Constraint) + ( (player-current-game $Game) (game-piece-has-constraint $Piece $Constraint $Game))) +; + + +; +; + + + (= + (game--piece-continues $Piece) + ( (constraint-continue-captures $Con) (game--piece-has-constraint $Piece $Con))) +; + + + + (= + (game--piece-must-capture $Piece) + ( (constraint-must-capture $Con) (game--piece-has-constraint $Piece $Con))) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (game--piece-must $Piece) + (det-if-then-else current-game-must-capture True + (game--piece-must-capture $Piece))) +; + + +; +; + + +; +; + +; +; + +; +; + +; +; + + + + (= + (game--piece-has-promoting $Piece $Promoting) + ( (current-game $Game) (game-piece-has-promoting $Piece $Promoting $Game))) +; + + + + (= + (game--piece-promoting $Piece $Promoting) + ( (current-game $Game) (game-piece-promoting $Piece $Promoting $Game))) +; + + + + (= + (game--promote-rank $Rank) + ( (current-game $Game) (game-promote-rank $Game $Rank))) +; + + + + diff --git a/metagame/theory/parse1.metta b/metagame/theory/parse1.metta new file mode 100644 index 0000000..9692e50 --- /dev/null +++ b/metagame/theory/parse1.metta @@ -0,0 +1,145 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + +; +; + +; +; + + + + (= + (generate-make-test-game) + ( (generate-game $G) (make-test-game $G))) +; + + +; +; + +; +; + +; +; + + + (= + (generate-and-load $File) + ( (random-game-to-file $File) (load-game $File))) +; + + + +; +; + +; +; + +; +; + + + (= + (load-game $Name) + ( (find-game-file $Name $File) (file-make-test-game $File))) +; + + +; +; + + + (= + (find-game-file $Name $File) + (find-suffixed-library-file $Name game $File)) +; + + + +; +; + + + (= + (file-make-test-game $File) + ( (read-game-from-file-to-list $File $Game) (parse-make-test-game $Game))) +; + + +; +; + + + (= + (string-make-test-game $String) + ( (read-game-from-string-to-list $String $Game) (parse-make-test-game $Game))) +; + + + + + (= + (parse-make-test-game $Game) + ( (set-parsing-mode) + (format "~nParsing game.~n" Nil) + (game $G $Game Nil) + (make-test-game $G))) +; + + + + !(dynamic (, (/ player-current-game 1) (/ opponent-current-game 1))) +; + + +; +; + +; +; + + + + (= + (make-test-game $G) + ( (game-name $G $Name) + (format "~nMaking ~w the current test game~n" + (:: $Name)) + (abolish (/ player-current-game 1)) + (abolish (/ opponent-current-game 1)) + (add-symbol &self + (player_current_game $G)) + (invert $G opponent $G1) + (add-symbol &self + (opponent_current_game $G1)) + (maybe-compile-syms))) +; + + + + (= + (maybe-compile-syms) + (det-if-then-else + (parameter compile-symmetries on) index-sym-dirs True)) +; + + + + diff --git a/metagame/theory/parse2.metta b/metagame/theory/parse2.metta new file mode 100644 index 0000000..c64e8ce --- /dev/null +++ b/metagame/theory/parse2.metta @@ -0,0 +1,367 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + +; +; + + + + + (= + (current-game-for-player player $Game) + (player-current-game $Game)) +; + + (= + (current-game-for-player opponent $Game) + (opponent-current-game $Game)) +; + + + + + (= + (current-game-name $GameName) + ( (player-current-game $G) (game-name $G $GameName))) +; + + + + + (= + (current-game-piece-name $Name) + ( (player-current-game $Game) (game-piece-def $Game $Name $_))) +; + + + + + (= + (game-piece-name $Game $Name) + (game-piece-def $Game $Name $_)) +; + + +; +; + + + (= + (game-piece-struct-def $Game $PieceStruct $Def) + ( (piece-struct-name $PieceStruct $Name) (game-piece-def $Game $Name $Def))) +; + + +; +; + + + (= + (game-piece-def $Game $Name $Def) + ( (game-piece-defs $Game $Defs) + (member $Def $Defs) + (piece-name $Def $Name))) +; + + + + (= + (game-piece-defs $G $P) + (game-pieces $G $P)) +; + + + +; +; + + + (= + (game-has-goal $Game $Goal) + ( (game-goal $Game $CompGoal) (goal-component $CompGoal $Goal))) +; + + + + (= + (goal-component $CompGoal $Goal) + (member $Goal $CompGoal)) +; + + +; +; + + + + (= + (game-must-capture $Game) + ( (constraint-must-capture $Con) (game-constraints $Game $Con))) +; + + + + (= + (game-continues $Game) + ( (constraint-continue-captures $Con) (game-constraints $Game $Con))) +; + + + + (= + (current-game-must-capture) + ( (player-current-game $Game) (game-must-capture $Game))) +; + + + + + + +; +; + + + + (= + (game-piece-has-constraint $Piece $Constraint $Game) + ( (game-piece-struct-def $Game $Piece $Def) (piece-constraints $Def $Constraint))) +; + + + +; +; + + + + (= + (game-piece-has-movement $Piece $Movement $Game) + ( (game-piece-struct-def $Game $Piece $Def) + (piece-movement $Def $CompMovement) + (movement-component $CompMovement $Movement))) +; + + + + (= + (movement-component $CompMovement $Movement) + (member $Movement $CompMovement)) +; + + +; +; + +; +; + +; +; + + + + (= + (leap $M $Dir) + ( (movement-type $M $L) + (leaper $L) + (movement-sym-dir $M $Dir))) +; + + +; +; + +; +; + +; +; + +; +; + + + (= + (ride $M $Dir $Min $Max $Longest) + ( (movement-type $M $R) + (rider $R $Longest $Min1 $Max1) + (movement-sym-dir $M $Dir) + (valid-min $Min1 $Min) + (valid-max $Max1 $Dir $Max))) +; + + +; +; + + + (= + (longest yes) True) +; + + + + + (= + (hop $M $Dir $Before $Over $After $Description) + ( (movement-type $M $H) + (hopper $H $Description $Before $Over $After) + (movement-sym-dir $M $Dir))) +; + + + + (= + (movement-sym-dir $M $Dir) + ( (movement-dir $M $D) + (movement-syms $M $Syms) + (sym-dir $D $Syms $Dir))) +; + + +; +; + +; +; + + + + (= + (movement-syms $M $Syms) + ( (movement-sym $M $S) (sym-set $S $Syms Nil))) +; + + + +; +; + + + (= + (game-piece-has-capture $Piece $Capture $Game) + ( (game-piece-struct-def $Game $Piece $Def) + (piece-capture $Def $CompCapture) + (capture-component $CompCapture $Capture))) +; + + + + (= + (capture-has-movement $Capture $M) + ( (capture-movement $Capture $Ms) (member $M $Ms))) +; + + + + (= + (capture-component $CompCapture $Capture) + (member $Capture $CompCapture)) +; + + + + + (= + (capture-has-method $Capture $Method) + ( (capture-methods $Capture $Methods) (component-of-method $Method $Methods))) +; + + + + (= + (component-of-method clobber $M) + (method-clobber $M yes)) +; + + (= + (component-of-method retrieve $M) + (method-retrieve $M yes)) +; + + (= + (component-of-method hop $M) + (method-hop $M yes)) +; + + + + + (= + (capture-methods-list $Capturing $Meths) + (bagof $Meth + (capture-has-method $Capturing $Meth) $Meths)) +; + + + +; +; + +; +; + +; +; + +; +; + + + + (= + (game-piece-has-promoting $Piece $Promoting $Game) + ( (game-piece-struct-def $Game $Piece $Def) (piece-promote $Def $Promoting))) +; + + + + (= + (game-piece-promoting $Piece $Promoting $Game) + ( (game-piece-has-promoting $Piece $Promote $Game) (promoting-info $Promote $Promoting))) +; + + +; +; + + + (= + (promoting_info + (promote $Promote) + (promote $Promote)) True) +; + + (= + (promoting-info $Promote $Promoting) + ( (decision-chooser $Promote $Player) + (decision-options $Promote $Descr) + (= $Promoting + (promote $Player $Descr)))) +; + + + + + (= + (game-promote-rank $Game $Rank) + ( (game-board $Game $Board) (board-promote-rows $Board $Rank))) +; + + + + diff --git a/metagame/theory/print_boards.metta b/metagame/theory/print_boards.metta new file mode 100644 index 0000000..277539d --- /dev/null +++ b/metagame/theory/print_boards.metta @@ -0,0 +1,480 @@ +; +; + +; +; + +; +; + +; +; + + +; +; + + + +; +; + +; +; + +; +; + + + + (= + (print-state) + ( (print-board) + (move-count $Count) + (control $P) + (nl) + (write-pieces-in-hand player) + (write-pieces-in-hand opponent) + (format "~nMove Number: ~d~nControl: ~p~n" + (:: $Count $P)) + (print-stage) + (print-opponent-promotes) + (print-effect) + (print-movement))) +; + + + + (= + (print-stage) + (det-if-then-else + (stage $S) + (verbosely-format "Stage: ~p~n" + (:: $S)) True)) +; + + +; +; + +; +; + +; +; + + + (= + (print-opponent-promotes) + (det-if-then-else + (opponent-promotes $OldPiece $Sq) + (, + (control $O) + (format "~p must promote: ~p on ~p~n" + (:: $O $OldPiece $Sq))) True)) +; + + + + (= + (print-movement) + (det-if-then-else + (moved-onto $Piece $Square) + (format "~p moved onto ~p~n" + (:: $Piece $Square)) True)) +; + + + + (= + (print-effect) + (det-if-then-else + (effects $Effect $Captured) + (, + (real-capture + (:: (captured $Effect $Captured)) Nil $String Nil) + (print-tokens $String)) True)) +; + + + + + (= + (print-captured) + (det-if-then-else + (setof + (@ $C $Sq) + (captured $C $Sq) $Caps) + (format "Captured: ~p~n" + (:: $Caps)) True)) +; + + + + + (= + (pieces-in-hand $Player $Pieces) + (bagof $Piece + (in-hand $Piece $Player) $Pieces)) +; + + + + (= + (write-pieces-in-hand $Player) + (det-if-then-else + (pieces-in-hand $Player $Pieces) + (format "Pieces in ~p's hand: ~p~n" + (:: $Player $Pieces)) True)) +; + + + + (= + (print-board) + ( (current-board-size $X $Y) + (nl) + (print-squares-in-rows 1 $Y $X))) +; + + + + + (= + (print-hline 0) + ( (format "+~n" Nil) (set-det))) +; + + (= + (print-hline $N) + ( (format "+---" Nil) + (is $N1 + (- $N 1)) + (print-hline $N1))) +; + + + + (= + (print-column-labels $Size) + (print-column-labels 1 $Size)) +; + + + (= + (print-column-labels $X $Max) + ( (> $X $Max) + (set-det) + (nl))) +; + + (= + (print-column-labels $C $Max) + ( (write ) + (print-column-label $C) + (write ' ') + (is $C1 + (+ $C 1)) + (print-column-labels $C1 $Max))) +; + + + + (= + (print-column-label $C) + ( (nth-letter $C $Letter) (write $Letter))) +; + + + + + +; +; + +; +; + + + + (= + (print-squares-in-rows $Min $Max $Size) + ( (is $Min1 + (- $Min 1)) + (print-hline $Size) + (print-squares-in-rows $Max $Min1 $Max $Size))) +; + + + (= + (print-squares-in-rows $Min $Min $Max $Size) + ( (set-det) (print-column-labels $Size))) +; + + (= + (print-squares-in-rows $_ $_ $_ 0) + (set-det)) +; + + (= + (print-squares-in-rows $Row $Min $Max $Size) + ( (print-squares-in-row $Row $Size) + (nl) + (print-hline $Size) + (is $Row1 + (- $Row 1)) + (print-squares-in-rows $Row1 $Min $Max $Size))) +; + + + + (= + (print-squares-in-row $Row $Size) + (print-squares-in-row $Row 1 $Size)) +; + + + + + + (= + (print-end-row $Row) + (format "| ~p" + (:: $Row))) +; + + + + (= + (print-squares-in-row $Row $Current $Max) + ( (> $Current $Max) + (set-det) + (print-end-row $Row))) +; + + (= + (print-squares-in-row $Row $Cur $Max) + ( (is $Cur1 + (+ $Cur 1)) + (print-square $Cur $Row) + (print-squares-in-row $Row $Cur1 $Max))) +; + + + + + + (= + (print-square $X $Y) + ( (write |) + (square $Square $X $Y) + (print-piece-on-square $Square))) +; + + + +; +; + +; +; + + + (= + (print-piece-on-square $Square) + ( (on $Piece $Square) + (ground $Piece) + (set-det) + (print-piece-or-empty $Piece $Square))) +; + + (= + (print-piece-on-square $Square) + ( (question-marker $Square $Mark) (write $Mark))) +; + + + + + + (= + (print-piece-or-empty $Piece $Square) + ( (piece-struct-name $Piece $Name) + (set-det) + (piece-struct-owner $Piece $Player) + (print-player-piece $Player $Name))) +; + + (= + (print-piece-or-empty $Piece $Square) + (print-empty-square $Square)) +; + + + + (= + (print-empty-square $Square) + ( (square $Square $X $Y) + (parity $X $Y $Par) + (parity-marker $Par $Mark) + (write $Mark))) +; + + + + + (= + (parity $X $Y $Total) + (is $Total + (mod + (+ $X $Y) 2))) +; + + +; +; + +; +; + + + + (= + (parity_marker 0 ...) True) +; + + (= + (parity_marker 1 ) True) +; + + + + (= + (question_marker $_ ? ) True) +; + + + + + (= + (print-colored player $Name) + (format " ~p " + (:: $Name))) +; + + (= + (print-colored opponent $Name) + (format "*~p*" + (:: $Name))) +; + + + + + (= + (print-player-piece $Player $Piece) + ( (player-piece-print-name $Player $Piece $Name) (print-colored $Player $Name))) +; + + + + (= + (player-piece-print-name $Player $P $Name) + ( (piece-print-name $P $PName) (name-for-player $Player $PName $Name))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + + + (= + (piece-print-name $P $PieceNum) + ( (bi-concat piece $PieceNum $P) + (number-chars $PieceNum $NumChars) + (set-det))) +; + + (= + (piece-print-name $P $PieceNum) + ( (name $P + (Cons $InitChar $Rest)) + (name $Letter + (:: $InitChar)) + (nth-letter $PieceNum $Letter))) +; + + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + +; +; + + + (= + (name-for-player $Player $PieceNum $NewName) + ( (player-offset $Player $Off) + (is $OrdNum + (- + (+ $Off $PieceNum) 1)) + (name $NewName + (:: $OrdNum)))) +; + + + + + + (= + (player-offset player $O) + (name A + (:: $O))) +; + + (= + (player-offset opponent $O) + (name A + (:: $O))) +; + + +; +; + + + + + diff --git a/miles/argument_types.metta b/miles/argument_types.metta index 9d91871..e1d19ed 100644 --- a/miles/argument_types.metta +++ b/miles/argument_types.metta @@ -1,5 +1,6 @@ ; -; MODULE argument_types EXPORTS +; + !(module argument-types (:: @@ -14,10 +15,12 @@ (/ compare-types 3) (/ define-type 0) (/ verify-types 0))) +; + ; -; IMPORTS +; !(use-module (home kb) @@ -28,9 +31,13 @@ (/ store-clause 4) (/ known 6) (/ delete-clause 1))) +; + !(use-module (home lgg) (:: (/ set-lgg 2))) +; + !(use-module (home div-utils) (:: @@ -42,165 +49,185 @@ (/ make-unique 2) (/ shares-var 2) (/ mysetof 3))) +; + !(use-module (home var-utils) (:: (/ only-vars 2))) +; + !(use-module (home td-basic) (:: (/ append-body 3))) +; + !(use-module (home interpreter) (:: (/ t-interpreter 2))) +; + !(use-module (home show-utils) (:: (/ show-kb-types 0))) +; + !(use-module-if-exists (library subsumes) (:: (/ variant 2))) +; + !(use-module-if-exists (library occurs) (:: (/ contains-var 2))) +; + !(use-module-if-exists (library basics) (:: (/ member 2))) +; + !(use-module-if-exists (library strings) (:: (/ gensym 2))) +; + ; -; METAPREDICATES +; ; -; none +; !(dynamic (/ type-restriction 2)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * module: argument_types.pl +; ; -; * +; ; -; * author: I.Stahl date:12/92 +; ; -; * +; ; -; * changed: +; ; -; * +; ; -; * +; ; -; * description: algorithm for determining argument types +; ; -; * results for each predicate p within the pos examples +; ; -; * in a kb entry +; ; -; * type_restriction(p(V1,..,Vn),[type1(V1),...,typen(Vn)]) +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: argument_types/0 +; ; -; * +; ; -; * syntax: - +; ; -; * +; ; -; * args: none +; ; -; * +; ; -; * +; ; -; * description: toplevel predicate for determining argument types +; ; -; * results for each predicate p within the pos examples +; ; -; * in a kb entry +; ; -; * type_restriction(p(V1,..,Vn),[type1(V1),...,typen(Vn)]) +; ; -; * +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -212,22 +239,19 @@ (different-predicates $Elist $Elist1) (argument-types $Elist1) (set-det))) -; ; Elist = [E1,...,En] pos examples - -; ; Elist1 = [[E1,..,Em],...] - -; ; list of lists of pos examples with - -; ; the same predicate symbol - +; (= (argument_types ()) True) +; + (= (argument-types (Cons $E $R)) ( (argument-types $R) (arg-types $E))) +; + (= @@ -236,92 +260,91 @@ (functor $P1 $P $N) (det-if-then-else (type-restriction $P1 $_) True - (add-atom &self + (add-symbol &self (type_restriction $P1 ()))) (arg-types $N (Cons $E $R) $P $N))) -; ; assert a type restriction for the - -; ; predicate if not already present - +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: arg_types/4 +; ; -; * +; ; -; * syntax: arg_types(+Counter,+Examplelist,+Pred_symbol,+Pred_arity) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * +; ; -; * description: +; ; -; * for each argument position (1 to Pred_arity) of the predicate Pred_symbol +; ; -; * the type of the terms occurring at that position is determined. +; ; -; * If the same type occurred already elsewhere, the old definition is taken +; ; -; * in order to avoid duplicate type definitions +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (arg-types 0 $_ $_ $_) (set-det)) +; + (= (arg-types $N $EL $P $M) ( (is $N1 @@ -332,70 +355,72 @@ (arg-type $S Nil Nil $CL $Type) (minimize-cl $CL $Type $Type1) (adapt-type-restriction $M $P $N $Type1))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: arg_type/5 +; ; -; * +; ; -; * syntax: arg_type(+Set_of_Argterms,+Ancestors,+Clause_list,-Clause_list,+Typename) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * +; ; -; * description: +; ; -; * Ancestors are all types calling Typename in their definition. Clauselist +; ; -; * contains all clauses defining Typename +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -406,21 +431,16 @@ (append $CL $CL0 $CL1) (refine-cl $Slist (Cons $T $Ancestors) $CL0 $CL1 $CL2))) -; ; splits the set of Argterms according to - -; ; different functors, Slist = [[T1,..,Tm],..] - -; ; for each set of Argterms in Slist, generate - -; ; a clause head with pred symbol Typename - +; ; -; generate clause bodies +; (= (init_cl () $_ ()) True) +; + (= (init-cl (Cons $EL $R) $T @@ -430,84 +450,88 @@ (set-lgg $EL $E) (=.. $T1 (:: $T $E)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: refine_cl/5 +; ; -; * +; ; -; * syntax: refine_cl(+Slist,+Ancestors,+Clauses,+Clauselist,-Clauselist) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * +; ; -; * description: +; ; -; * for each set of Argterms in Slist and each corresponding clause head +; ; -; * in Clauses and Clauselist, add a body literal for each variable in the +; ; -; * clause head. This body literal may be atom(_),atomic(_),number(_), +; ; -; * typex(_),where typex is in Ancestors, or typez(_), where typez is a +; ; -; * new type (recursive call of the algorithm) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (refine_cl () $_ $_ $CL $CL) True) +; + (= (refine-cl (Cons $S $R) $A @@ -521,89 +545,80 @@ (, (functor $E $_ $N) (ref-cl $N $E $S $Head $A $CL1 $CL2))))) -; ; if the head argument is a variable, test its instantiations - -; ; in S and add the corresponding literal to the body of Head - -; ; if the head argument is no variable, - -; ; decompose it, test the variables it contains - -; ; and add the corresponding literals to the body - -; ; of Head - +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: ref_cl/7 +; ; -; * +; ; -; * syntax: ref_cl(+Counter,+Argument,+Argterms,+Head,+Ancestors, +; ; -; * +Clauselist, -Clauselist) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: decompose the head argument and test the variables it contains; +; ; -; * add the corresponding literals to the body of Head +; ; -; * +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (ref-cl 0 $_ $_ $_ $_ $CL $CL) (set-det)) +; + (= (ref-cl $N $E $S $H $A $CL $CL2) ( (is $N1 @@ -617,86 +632,88 @@ (, (functor $X $_ $M) (ref-cl $M $X $Sn $H $A $CL1 $CL2))))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: test_var_instantiation/6 +; ; -; * +; ; -; * syntax: test_var_instantiations(+Var,+Argterms,+Head,+Ancestors, +; ; -; * +Clauselist,-Clauselist) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * +; ; -; * description: +; ; -; * Argterms are the instantiations of Var. If all instantiations of Var +; ; -; * are atoms/number/atomic, the literal atom(Var)/number(Var)/atomic(Var) is +; ; -; * added to the body of Head in Clauselist. Else if the definition of a typex +; ; -; * in Ancestors covers all instantiations of Var, typex(Var) is added to the +; ; -; * body of Head in Clauselist (recursive definition). Else a new symbol typen +; ; -; * is created, the literal typen(Var) is added to the body of Head in Clauselist +; ; -; * and a definition of typen is induced by a recursive call of arg_type. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -707,6 +724,8 @@ (=.. $Lit (:: is-symbol $X)) (add-literal $CL $H $Lit $CL1))) +; + (= (test-var-instantiations $X $S $H $_ $CL $CL1) @@ -715,6 +734,8 @@ (=.. $Lit (:: number $X)) (add-literal $CL $H $Lit $CL1))) +; + (= (test-var-instantiations $X $S $H $_ $CL $CL1) @@ -723,6 +744,8 @@ (=.. $Lit (:: symbolic $X)) (add-literal $CL $H $Lit $CL1))) +; + (= (test-var-instantiations $X $S $H $A $CL $CL1) @@ -731,6 +754,8 @@ (=.. $Lit (:: $APred $X)) (add-literal $CL $H $Lit $CL1))) +; + (= (test-var-instantiations $X $S $H $A $CL $CL1) @@ -739,6 +764,8 @@ (:: $T $X)) (add-literal $CL $H $Lit $CL0) (arg-type $S $A $CL0 $CL1 $T))) +; + @@ -746,82 +773,88 @@ (test-ancestor $S (Cons $APred $_) $CL $APred) ( (myforall-interpreted $S $APred $CL) (set-det))) +; + (= (test-ancestor $S (Cons $_ $R) $CL $APred) (test-ancestor $S $R $CL $APred)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: myforall_interpreted/3 +; ; -; * +; ; -; * syntax: myforall_interpreted(+Argterms,+Pred,+Clauselist) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * +; ; -; * description: tests for each argument term T in Argterms whether Pred(T) +; ; -; * follows from Clauselist. For that purpose, a special interpreter +; ; -; * t_interpreter is used that works on Clauselist as program instead +; ; -; * of the knowledge base. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (myforall_interpreted () $_ $_) True) +; + (= (myforall-interpreted (Cons $E $R) $Pred $CL) @@ -829,61 +862,63 @@ (:: $Pred $E)) (t-interpreter $C $CL) (myforall-interpreted $R $Pred $CL))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: add_literal/4 +; ; -; * +; ; -; * syntax: add_literal(+Clauselist,+Head,+Lit,-Clauselist1) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: adds literal Lit to the clause (Head:- B) within Clauselist +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -895,103 +930,107 @@ (= $H ($Lit $B)) $R)) ( (== $H $H1) (set-det))) +; + (= (add-literal (Cons $C $R) $H $Lit (Cons $C $R1)) (add-literal $R $H $Lit $R1)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: adapt_type_restriction/4 +; ; -; * +; ; -; * syntax: adapt_type_restriction(+Pred_arity,+Pred_name,+A,+Type) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: +; ; -; * Type is the type of the Ath Argposition of the predicate Pred_name. The +; ; -; * type restriction is type_restriction(p(V1,..,Vn),L). If there is not yet +; ; -; * an entry typex(VA) in L, Type(VA) is added to L. Else let the definition +; ; -; * of typex be typex(Hx1):- Bx1. and of Type be Type(H1):- B1. +; ; -; * ... ... +; ; -; * typex(Hxm):- Bxm. Type(Ho):- Bo. +; ; -; * Then we add a new type Tnew(VA) to L with the definition +; ; -; * Tnew(Hx1):- Bx1. Tnew(H1):- B1. +; ; -; * ... ... +; ; -; * Tnew(Hxm):- Bxm. Tnew(Ho):- Bo. +; ; -; * The definitions of typex and Type remain. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (adapt-type-restriction $M $P $N $T) ( (functor $P1 $P $M) - (remove-atom &self + (remove-symbol &self (type_restriction $P1 $L)) (arg $N $P1 $P1n) (det-if-then-else @@ -1006,16 +1045,18 @@ (:: $Tnew $P1n)) (remove-v (:: $T1) $L $L1) - (add-atom &self + (add-symbol &self (type_restriction $P1 (Cons $D $L1))) (adapt-tr $Tnew $T $T2)) (, (=.. $D (:: $T $P1n)) - (add-atom &self + (add-symbol &self (type_restriction $P1 (Cons $D $L))))))) +; + (= @@ -1036,10 +1077,14 @@ (adapt-tr1 $C3 $Tnew $C4) (make-unique $C4 $C5) (store-clauses $C5 type))) +; + (= (adapt_tr1 () $_ ()) True) +; + (= (adapt-tr1 (Cons @@ -1051,67 +1096,69 @@ (Cons $_ $Arg)) (=.. $H1 (Cons $T $Arg)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: minimize_cl/3 +; ; -; * +; ; -; * syntax: minimize_cl(+CL,+Typename,-Typename) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: CL is the list of clauses defining the type Typename. +; ; -; * If CL contains definitions that occur already in the database, +; ; -; * or if it contains duplicate definitions, it is minimized. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1142,10 +1189,14 @@ (Cons $T $R)))))) $Newt_names) (append $Old_types $CL $Clauses) (minimize-cl $Oldt_names $Newt_names $Clauses $CL $Type $Type1))) +; + (= (minimize-cl Nil $Newt_names $Clauses $CL $Type $Type1) (minim-cl $Newt_names $Clauses $CL $Type $Type1)) +; + (= (minimize-cl (Cons $T $R) $Newt_names $Clauses $CL $Type $Type2) @@ -1162,15 +1213,19 @@ (= $Type1 $T) (= $Type1 $Type)) (minimize-cl $R $Newt_names1 $Clauses $CL2 $Type1 $Type2))) +; + (= (minim-cl Nil $_ $CL $Type $Type) - ( (min-cl $CL $CL1) (store-clauses $CL1 type))) ; -; the remaining (minimized) set of clauses is stored + ( (min-cl $CL $CL1) (store-clauses $CL1 type))) +; + ; +; ; -; in the database +; (= (minim-cl @@ -1188,10 +1243,14 @@ (= $Type1 $T) (= $Type1 $Type)) (minim-cl $R1 $Clauses $CL2 $Type1 $Type2))) +; + (= (min_cl () ()) True) +; + (= (min-cl (Cons @@ -1199,79 +1258,89 @@ (Cons (= $H $B1) $R1)) ( (min-cl $R $R1) (min-cl1 $B $B1))) +; + (= (min-cl1 $A $A) (set-det)) +; + (= (min-cl1 True True) (set-det)) +; + (= (min-cl1 (, $A $B) (, $A $B1)) (min-cl1 $B $B1)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: replace_t/4 +; ; -; * +; ; -; * syntax: replace_t(+CL,+List_of_typenames,+Typename,-CL) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: replaces in CL each occurrence of a typename +; ; -; * in List_of_typenames by Typename +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (replace_t () $_ $_ ()) True) +; + (= (replace-t (Cons @@ -1281,6 +1350,8 @@ (member $T1 $Tlist) (set-det) (replace-t $R $Tlist $T $R1))) +; + (= (replace-t (Cons @@ -1288,6 +1359,8 @@ (Cons (= $H $B1) $R1)) ( (repl-t $B $Tlist $T $B1) (replace-t $R $Tlist $T $R1))) +; + (= @@ -1297,71 +1370,77 @@ ( (set-det) (repl-t $A $Tlist $T $A1) (repl-t $B $Tlist $T $B1))) +; + (= (repl-t $A $Tlist $T $A1) ( (=.. $A (Cons $T1 $R)) (det-if-then-else (member $T1 $Tlist) (=.. $A1 (Cons $T $R)) (= $A1 $A)))) +; + ; -; ***********************************************************************************; +; ; -; * +; ; -; * predicate: type_equal/2 +; ; -; * +; ; -; * syntax: type_equal(+Type_name1,+Type_name2) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: Tests whether the types Type_name1 and Type_name2 are defined +; ; -; * identically +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ********************************************************************************** +; (= (type-equal $T $T) (set-det)) +; + (= (type-equal $T1 $T2) ( (mysetof @@ -1385,10 +1464,14 @@ (append $Clauses1 $Clauses2 $Clauses) (type-equal $T1 $T2 (:: (with_self $T1 $T2)) $Clauses))) +; + (= (type-equal $T $T $_ $_) (set-det)) +; + (= (type-equal $T1 $T2 $Ancestors $Clauses) ( (mysetof @@ -1408,78 +1491,82 @@ (=.. $H (Cons $T2 $R)))) $Clist2) (compare-clauses $Clist1 $Clist2 $Clauses $Ancestors))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: compare_clauses/4 +; ; -; * +; ; -; * syntax: compare_clauses(+Clist1,+Clist2,+Clauses12,+Ancestors) +; ; -; * +; ; -; * args: Clist1 .. clauses defining Type_name1 +; ; -; * Clist2 .. clauses defining Type_name2 +; ; -; * Clauses12 .. all clauses defining Type_name1 and Type_name2 +; ; -; * Ancestors .. types already tested on equality +; ; -; * +; ; -; * description: tests whether Type_name1 and Type_name2 are identically +; ; -; * defined by comparing the defining clauses +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (compare_clauses () () $_ $_) True) +; + (= (compare-clauses (Cons @@ -1490,6 +1577,8 @@ (arg 1 $H2 $E2) (comp-clauses $E1 $E2 $B1 $B2 $Clauses $Ancestors) (compare-clauses $R $CL21 $Clauses $Ancestors))) +; + (= @@ -1503,12 +1592,18 @@ (=.. $L2 (Cons $T2 $_)) (c-clauses $T1 $T2 $C $A))) +; + (= (comp-clauses $E1 $E2 $B1 $B2 $C $A) ( (functor $E1 $_ $N) (comp-clauses $N $E1 $E2 $B1 $B2 $C $A))) +; + (= (comp-clauses 0 $_ $_ $_ $_ $_ $_) (set-det)) +; + (= (comp-clauses $N $E1 $E2 $B1 $B2 $C $A) ( (is $N1 @@ -1517,17 +1612,25 @@ (arg $N $E1 $E1n) (arg $N $E2 $E2n) (comp-clauses $E1n $E2n $B1 $B2 $C $A))) +; + (= (c-clauses is-symbol $L $_ $_) ( (set-det) (= $L is-symbol))) +; + (= (c-clauses number $L $_ $_) ( (set-det) (= $L number))) +; + (= (c-clauses symbolic $L $_ $_) ( (set-det) (= $L symbolic))) +; + (= (c-clauses $_ $L2 $_ $_) ( (or @@ -1537,6 +1640,8 @@ (= $L2 symbolic))) (set-det) (fail))) +; + (= (c-clauses $T1 $T2 $C $A) (det-if-then-else @@ -1548,63 +1653,65 @@ (type-equal $T1 $T2 (Cons (with_self $T1 $T2) $A) $C))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: find_variant_clause/4 +; ; -; * +; ; -; * syntax: find_variant_clause(+CL,+Head,-CL1,-Clause) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: CL1 is CL - Clause, where the head argument of Head and +; ; -; * of the head of Clause are variants +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1616,65 +1723,69 @@ ( (arg 1 $H1 $E1) (arg 1 $H2 $E2) (variant $E1 $E2))) +; + (= (find-variant-clause (Cons $C $R) $H (Cons $C $R1) $C1) (find-variant-clause $R $H $R1 $C1)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: def_literal/3 +; ; -; * +; ; -; * syntax: def_literal(+Var,+Body,-Lit) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: Lit is the literal within Body that defines the type of +; ; -; * Var +; ; -; * +; ; -; * example: def_literal(A,(atom(A),list(B)),atom(A)) +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1682,63 +1793,69 @@ (def-literal $X (, $A $B) $C) ( (set-det) (det-if-then-else (contains-var $X $A) (= $C $A) (def-literal $X $B $C)))) +; + (= (def-literal $X $A $A) ( (contains-var $X $A) (set-det))) +; + (= (def_literal $X $_ (all $X)) True) +; + ; -; ********************************************************************************** +; ; -; * +; ; -; * predicate: type_sub/2 +; ; -; * +; ; -; * syntax: type_sub(+Gen,+Spec) +; ; -; * +; ; -; * args: Gen, Spec: type names or intermediate type definitions +; ; -; * t_int(H):- B (cf. type_of). +; ; -; * +; ; -; * description: succeeds if the type Gen is more general than +; ; -; * the type Spec. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; ********************************************************************************** +; @@ -1748,103 +1865,125 @@ (= $H $B)) (type-sub1 (:: (= $H $B)) $Gen Nil)) +; + (= (type-sub $Gen $Spec) (type-sub $Gen $Spec (:: (with_self $Gen $Spec)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: type_sub/3 +; ; -; * +; ; -; * syntax: type_sub(+Gen,+Spec,+Ancestors) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: +; ; -; * Ancestors contains the types that have been compared already in order to +; ; -; * avoid infinite recursion +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (type-sub all $_ $_) - (set-det)) ; -; all is the most general type + (set-det)) +; + ; +; (= (type-sub $T1 all $_) - ( (set-det) (= $T1 all))) + ( (set-det) (= $T1 all))) +; + (= (type-sub $T $T1 $_) ( (== $T $T1) (set-det))) +; + (= (type-sub symbolic $T $_) ( (set-det) (or (= $T is-symbol) (or (= $T symbolic) (or (= $T number) (, (functor $HT $T 1) (setof (, $HT $B) (^ $ID (^ $CL (get-clause $ID $HT $B $CL type))) $TL) (all-t-in $TL (:: is-symbol number symbolic)))))))) +; + (= (type-sub is-symbol $T $_) - ( (set-det) (or (= $T is-symbol) (, (functor $HT $T 1) (setof (, $HT $B) (^ $ID (^ $CL (get-clause $ID $HT $B $CL type))) $TL) (all-t-in $TL (:: is-symbol)))))) + ( (set-det) (or (= $T is-symbol) (, (functor $HT $T 1) (setof (, $HT $B) (^ $ID (^ $CL (get-clause $ID $HT $B $CL type))) $TL) (all-t-in $TL (:: is-symbol)))))) +; + (= (type-sub number $T $_) ( (set-det) (or (= $T number) (, (functor $HT $T 1) (setof (, $HT $B) (^ $ID (^ $CL (get-clause $ID $HT $B $CL type))) $TL) (all-t-in $TL (:: number)))))) +; + (= (type-sub $T symbolic $_) ( (set-det) (or (= $T symbolic) (or (= $T all) (, (functor $HT $T 1) (setof (, $HT $B) (^ $ID (^ $CL (get-clause $ID $HT $B $CL type))) $TL) (all-t-in $TL (:: symbolic))))))) +; + (= (type-sub $T is-symbol $_) ( (set-det) (or (= $T is-symbol) (or (= $T symbolic) (or (= $T all) (, (functor $HT $T 1) (setof (, $HT $B) (^ $ID (^ $CL (get-clause $ID $HT $B $CL type))) $TL) (all-t-in $TL (:: is-symbol symbolic)))))))) +; + (= (type-sub $T number $_) ( (set-det) (or (= $T number) (or (= $T symbolic) (or (= $T all) (, (functor $HT $T 1) (setof (, $HT $B) (^ $ID (^ $CL (get-clause $ID $HT $B $CL type))) $TL) (all-t-in $TL (:: number symbolic)))))))) +; + (= @@ -1856,68 +1995,72 @@ (^ $CL (get-clause $ID $HTS $BS $CL type))) $CS) (type-sub1 $CS $TG $A))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: type_sub1/3 +; ; -; * +; ; -; * syntax: type_sub1(+SpecClauses,+Gen,+Ancestors) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: +; ; -; * for each clause C in SpecClauses defining the more specific type, +; ; -; * there must be a clause defining Gen that is more general than C +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (type_sub1 () $_ $_) True) +; + (= (type-sub1 (Cons @@ -1938,6 +2081,8 @@ (test-type-def $BG1) (only-vars $Es $EsV) (type-sub2 $EsV $BG1 $B $A))) +; + (= (type-sub1 (Cons @@ -1956,69 +2101,73 @@ (test-type-def $BG1) (only-vars $Es $EsV) (type-sub2 $EsV $BG1 $B $A))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: type_sub2/4 +; ; -; * +; ; -; * syntax: type_sub2(+Varlist,+Genbody,+Specbody,+Ancestors) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: +; ; -; * tests for each variable V in Varlist whether the literal defining V in Genbody +; ; -; * is of a more general type than the literal defining V in Specbody. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (type_sub2 () $_ $_ $_) True) +; + (= (type-sub2 (Cons $X $R) $BG1 $B $A) @@ -2036,67 +2185,69 @@ (type-sub $TG $TS (Cons (with_self $TG $TS) $A))))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: expand_to_type_definition/2 +; ; -; * +; ; -; * syntax: expand_to_type_definition(+Body,-Body1) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: +; ; -; * transform Body to a valid type definition (i.e. each literal is of the +; ; -; * form t(X), were t in atom,atomic,number,typex and X is simple), by expanding +; ; -; * literals containing complex terms +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2105,6 +2256,8 @@ (, $A $B) (, $A $B1)) ( (simple-td $A) (expand-to-type-def $B $B1))) +; + (= (expand-to-type-def (, $A $B) $B1) @@ -2112,130 +2265,140 @@ (get-clause $_ $A $Lits $_ type) (append-body $Lits $B $B0) (expand-to-type-def $B0 $B1))) +; + (= (expand-to-type-def $A $A) (simple-td $A)) +; + (= (expand-to-type-def $A $A1) ( (not (= $A (, $_ $_))) (not (simple-td $A)) (get-clause $_ $A $Lits $_ type) (expand-to-type-def $Lits $A1))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: simple_td/1 +; ; -; * +; ; -; * syntax: simple_td(+Lit) +; ; -; * +; ; -; * args: Lit is a literal within a type definition +; ; -; * +; ; -; * description: succeeds if Lit == true, or Lit = t(X), where X is atomic or +; ; -; * a variable +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (simple-td True) (set-det)) +; + (= (simple-td $A) ( (=.. $A (:: $_ $X)) (simple $X))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: test_type_definition/1 +; ; -; * +; ; -; * syntax: test_type_definition(Body) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: partially evaluates Body. +; ; -; * Fails if body contains invalid ground literals +; ; -; * with predicate symbol atom, number or atomic +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2244,6 +2407,8 @@ ( (set-det) (test-type-def $A) (test-type-def $B))) +; + (= (test-type-def $A) ( (=.. $A @@ -2256,73 +2421,81 @@ (= $T number))) (set-det) (call $A))) +; + (= (test_type_def $_) True) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: is_type_definition/1 +; ; -; * +; ; -; * syntax: is_type_definition(+Clause) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: +; ; -; * succeeds if Clause is a syntactically correct type definition, i.e. only +; ; -; * atom, atomic, number and typex occur as unary predicate in the body, and +; ; -; * every variable of Clause occurs once in the head and once in the body of Clause +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (is-type-definition (= $H $B)) ( (only-vars $H $Vars) (is-type-def $Vars $B))) +; + (= (is_type_def () $_) True) +; + (= (is-type-def (Cons $X $R) $B) @@ -2332,10 +2505,14 @@ (:: $_ $X1)) (== $X $X1) (is-type-def $R $B))) +; + (= (all_t_in () $_) True) +; + (= (all-t-in (Cons @@ -2347,67 +2524,69 @@ (:: $N $X)) (member $N $L) (all-t-in $R $L))) +; + ; -; ********************************************************************************** +; ; -; * +; ; -; * predicate: type_of/3 +; ; -; * +; ; -; * syntax: type_of(+Var,+C,-Type) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: C is a clause or a literal. Returns the most specific type of Var +; ; -; * within C. If Var does not occur in C or if it occurs at +; ; -; * positions with incompatible types, type_of returns fail. If Var +; ; -; * is a term that only partially matches the body of a type +; ; -; * definition, a intermediate type definition t_int(Var):- B is +; ; -; * returned +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * pecularities: +; ; -; * +; ; -; ********************************************************************************** +; @@ -2418,6 +2597,8 @@ (type-of $V $H $Type1) (type-of $V $B $Type2) (compare-types $Type1 $Type2 $Type))) +; + (= (type-of $V (, $A $B) $Type) @@ -2425,6 +2606,8 @@ (type-of $V $A $Type1) (type-of $V $B $Type2) (compare-types $Type1 $Type2 $Type))) +; + (= (type-of $T $Pred $Type) (det-if-then-else @@ -2436,12 +2619,18 @@ (contains-var $T $Ts)) $TsL) (type-of1 $TsL $T $Type)) (= $Type all))) +; + (= (type_of $_ true all) True) +; + (= (type_of1 () $_ all) True) +; + (= (type-of1 (Cons $Ts $R) $T $Type) @@ -2470,129 +2659,135 @@ (=.. $H_int (:: t-int $T)) (with_self - (kb) + (kb *) (body2list $B_int $TsL1)) (compare-types $Type1 (= $H_int $B_int) $Type)) (, (type-of1 $TsL $T $Type2) (compare-types $Type1 $Type2 $Type))))))) +; + ; -; ********************************************************************************** +; ; -; * +; ; -; * predicate: types_of/3 +; ; -; * +; ; -; * syntax: types_of(+Varlist,+C,-Typelist) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: like type_of for each Var in Varlist. +; ; -; * Varlist = [V1,..,Vn] => Typelist = [V1:T1,..,Vn:Tn] +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; ********************************************************************************** +; (= (types_of () $_ ()) True) +; + (= (types-of (Cons $V $R) $C (Cons (with_self $V $T) $R1)) ( (type-of $V $C $T) (types-of $R $C $R1))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: compare_types/3 +; ; -; * +; ; -; * syntax: compare_types(+Type1,+Type2,-Type) +; ; -; * +; ; -; * args: Type1,Type2: types to be compared +; ; -; * Type: the most specific type among type1 and typ2 +; ; -; * +; ; -; * description: returns the more specific type +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2604,63 +2799,67 @@ (det-if-then-else (type-sub $Type2 $Type1) (= $Type $Type1) fail))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: define_type/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: allows to define a type restriction for a predicate +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (define-type) ( (show-kb-types) (read-type-restriction))) +; + (= @@ -2678,11 +2877,15 @@ (=.. $F (Cons $P $Args)) (read-type-restriction $Args 1 $Alist) - (add-atom &self + (add-symbol &self (type_restriction $F $Alist))) fail))) +; + (= (read_type_restriction () $_ ()) True) +; + (= (read-type-restriction (Cons $V $R) $N @@ -2713,58 +2916,60 @@ (is $N1 (+ $N 1)) (read-type-restriction $R $N1 $R1))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: read_type_definition/1 +; ; -; * +; ; -; * syntax: read_type_definition(+TN) +; ; -; * +; ; -; * args: TN.. name of a type +; ; -; * +; ; -; * description: allows to enter clauses defining the type TN +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2784,6 +2989,8 @@ (nl) (write 'Please enter y or n') (read-type-definition $TN)))))) +; + (= @@ -2814,66 +3021,68 @@ (nl) (write 'Please enter a clause or stop') (fail)))))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: verify_types/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: checks for the type restrictions in the kb whether +; ; -; * the contain only defined or built-in types. If not, +; ; -; * the user is asked for replacing or defining the unknown +; ; -; * types. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2882,15 +3091,23 @@ ( (findall (, $M $A) (type-restriction $M $A) $TSet) (verify-types $TSet))) +; + (= (verify_types ()) True) +; + (= (verify-types (Cons (, $M $A) $R)) ( (verify-types $R) (verify-types $A $M $A))) +; + (= (verify_types () $_ $_) True) +; + (= (verify-types (Cons $H $R) $M $A) @@ -2904,7 +3121,7 @@ (:: $T $_)) (known $ID $H1 $B1 $CL $_ $E) (delete-clause $ID) - (add-atom &self + (add-symbol &self (: kb (known $ID $H1 $B1 $CL type $E)))) $Tlist) (det-if-then-else @@ -2937,7 +3154,7 @@ (det-if-then-else (== $An y) (, - (remove-atom &self + (remove-symbol &self (type_restriction $M $A)) (repeat) (nl) @@ -2955,7 +3172,7 @@ (get-clause $_ $H1 $_ $_ $_) (, (vrt $A $T $T1 $A2) - (add-atom &self + (add-symbol &self (type_restriction $M $A2))) (, (nl) @@ -2973,10 +3190,14 @@ (, (write 'Please enter y or n') (fail)))))))) +; + (= (vrt () $_ $_ ()) True) +; + (= (vrt (Cons $H $R) $T $T1 @@ -2989,6 +3210,8 @@ (=.. $H1 (:: $T1 $V)) (= $H1 $H)))) +; + @@ -3005,6 +3228,8 @@ (, (write 'Please enter y or n') (vrt1 $T1)))))) +; + diff --git a/miles/bu_basics.metta b/miles/bu_basics.metta index 983e1c0..bf489b5 100644 --- a/miles/bu_basics.metta +++ b/miles/bu_basics.metta @@ -1,5 +1,5 @@ ; -; MODULE bu_basics EXPORTS +; !(module bu-basics @@ -35,154 +35,170 @@ (/ assert-literals 1) (/ clear-mngr 0) (/ reset-counts 0))) +; + ; -; IMPORTS +; !(use-module (home div-utils) (:: (/ contains-duplicates 1))) +; + !(use-module-if-exists (library basics) (:: (/ member 2))) +; + !(use-module-if-exists (library random) (:: (/ maybe 0))) +; + ; -; METAPREDICATES +; ; -; none +; - !(dynamic (/ head 3)) ; -; head( Literal, {old,new}, Counter) + !(dynamic (/ head 3)) +; + ; +; - !(dynamic (/ body 3)) ; -; body( Literal, {old,new}, Counter) + !(dynamic (/ body 3)) +; + ; +; ; -; the second argument is used to check whether +; ; -; saturation/idev resulted in a new literal at all. +; ; -; the third argument is 0 for new literals that +; ; -; resulted from sat/idev, and \= 0 for literals that +; ; -; have been used for sat/idev +; !(dynamic (/ assumption 3)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * module: bu_utils.pl +; ; -; * +; ; -; * author: B.Jung, M.Mueller, I.Stahl, B.Tausend date:12/92 +; ; -; * +; ; -; * changed: +; ; -; * +; ; -; * description: utilities for bottom-up operators +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: process_new_literals/2 +; ; -; * +; ; -; * syntax: process_new_literals(+[H:Proof|_],-Flag) +; ; -; * +; ; -; * args: H = Lit/M where M is in {new_head,new_body}, or H = [] +; ; -; * Proof = [[Lit,N],..,[],...] where N in {head,body} +; ; -; * +; ; -; * description: asserts all new heads and bodies of matched clauses +; ; -; * via head/3 and body/3 +; ; -; * Flag = 1 if at least one existed +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (process_new_literals () $_) True) +; + (= @@ -190,6 +206,8 @@ (Cons (with_self Nil $Proof) $Rest) $Flag) (process-new-literals $Rest $Flag)) +; + (= (process-new-literals @@ -199,6 +217,8 @@ ( (body $L $_ $_) (set-det) (process-new-literals $Rest $Flag))) +; + (= (process-new-literals @@ -208,6 +228,8 @@ ( (head $L $_ $_) (set-det) (process-new-literals $Rest $Flag))) +; + (= (process-new-literals @@ -217,10 +239,7 @@ ( (contains-duplicates $Proof) (set-det) (process-new-literals $Rest $Flag))) -; ;;eigentlich ein Filter: jedem Literal - -; ;;im Parent entspricht eines in der Resolvente - +; (= @@ -229,173 +248,187 @@ (with_self (/ $L new-head) $Proof) $Rest) 1) ( (set-det) - (add-atom &self + (add-symbol &self (head $L new 0)) (annotate $Proof) (process-new-literals $Rest $_))) +; + (= (process-new-literals (Cons (with_self (/ $L new-body) $Proof) $Rest) 1) - ( (add-atom &self + ( (add-symbol &self (body $L new 0)) (annotate $Proof) (process-new-literals $Rest $_))) +; + ; -; for backtracking +; (= (process-new-literals (Cons (with_self (/ $L new-body) $Proof) $Rest) $Flag) - ( (remove-atom &self + ( (remove-symbol &self (body $L new 0)) (process-new-literals $Rest $Flag))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: annotate/1 +; ; -; * +; ; -; * syntax: annotate(+Proofs) +; ; -; * +; ; -; * args: Proofs = [L1,..,Ln] where Li = [] or Li = [Lit,N] and N in {head,body} +; ; -; * +; ; -; * description: increments counter for each head/body literal in Proofs +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (annotate ()) True) +; + (= (annotate (Cons (:: $L body) $Rest)) - ( (remove-atom &self + ( (remove-symbol &self (body $L $OldNew $I)) (is $J (+ $I 1)) - (add-atom &self + (add-symbol &self (body $L $OldNew $J)) (annotate $Rest))) +; + (= (annotate (Cons (:: $L head) $Rest)) - ( (remove-atom &self + ( (remove-symbol &self (head $L $OldNew $I)) (is $J (+ $I 1)) - (add-atom &self + (add-symbol &self (head $L $OldNew $J)) (annotate $Rest))) +; + (= (annotate (Cons Nil $Rest)) (annotate $Rest)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: abs_process_proofs/2 +; ; -; * +; ; -; * syntax: abs_process_proofs(+Proofs,-Head) +; ; -; * +; ; -; * args: Proofs = [CL1,..,CLn] where CLi is a clause in list notation +; ; -; * Head: a head literal +; ; -; * +; ; -; * description: returns a head literal from one of the CLi, and retracts +; ; -; * the according body literals body(L,_,_) of CLi (destructive +; ; -; * absorption) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -408,6 +441,8 @@ ( (body $Head $_ $_) (set-det) (abs-process-proofs $MoreHeads $NewHead))) +; + (= (abs-process-proofs @@ -416,10 +451,7 @@ ( (contains-duplicates $Proof) (set-det) (abs-process-proofs $MoreHeads $NewHead))) -; ;;eigentlich ein Filter: jedem Literal - -; ;;im Parent entspricht eines in der Resolvente - +; (= @@ -429,9 +461,11 @@ (with_self $Head (p)) $Proof) $MoreHeads) $Head) (retract-body-literals $Proof)) +; + ; -; For Backtracking +; (= (abs-process-proofs @@ -440,68 +474,70 @@ (with_self $Head (p)) $Proof) $MoreHeads) $NewHead) ( (assert-body $Proof) (abs-process-proofs $MoreHeads $NewHead))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: ident_process_proofs/2 +; ; -; * +; ; -; * syntax: ident_process_proofs(+[[H:Proof]|_],-Head) +; ; -; * +; ; -; * args: H = = Lit/M where M is in {new_head,new_body}, or H = [] +; ; -; * Proof = [[Lit,N],..,[],...] where N in {head,body} +; ; -; * Head: a literal +; ; -; * +; ; -; * description: returns a head literal from one of the H:Proof, and retracts +; ; -; * the according literals from Proof from the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -512,8 +548,7 @@ ( (head $Head $_ $_) (set-det) (ident-process-proofs $MoreHeads $NewHead))) -; ; - +; (= @@ -523,10 +558,7 @@ ( (contains-duplicates $Proof) (set-det) (ident-process-proofs $MoreHeads $NewHead))) -; ;;eigentlich ein Filter: jedem Literal - -; ;;im Parent entspricht eines in der Resolvente - +; (= @@ -534,80 +566,81 @@ (Cons (:: (with_self (/ $Head new-head) $Proof)) $MoreHeads) $Head) (retract-literals $Proof)) +; + ; -; for backtracking +; (= (ident-process-proofs (Cons (:: (with_self (/ $Head new-head) $Proof)) $MoreHeads) $NewHead) ( (assert-literals $Proof) (ident-process-proofs $MoreHeads $NewHead))) -; ; write('new kb'),nl,subsume_mngr:show_heads,subsume_mngr:show_bodies,nl, - +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: g1_process_proofs/2 +; ; -; * +; ; -; * syntax: g1_process_proofs(+[[H:Proof]|_],-Lit) +; ; -; * +; ; -; * args: H = = Lit/M where M is in {new_head,new_body}, or H = [] +; ; -; * Proof = [[Lit,N],..,[],...] where N in {head,body} +; ; -; * Lit: a literal and its sign +; ; -; * +; ; -; * description: returns the resolution literal from one of the H:Proof, and retracts +; ; -; * the according literals from Proof from the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -616,6 +649,8 @@ (Cons (with_self Nil $_) $R) $Lit) (g1-process-proofs $R $Lit)) +; + (= (g1-process-proofs @@ -625,6 +660,8 @@ ( (head $Head $_ $_) (set-det) (g1-process-proofs $MoreHeads $Lit))) +; + (= @@ -635,6 +672,8 @@ ( (body $Body $_ $_) (set-det) (g1-process-proofs $MoreHeads $Lit))) +; + (= (g1-process-proofs @@ -644,10 +683,7 @@ ( (contains-duplicates $Proof) (set-det) (g1-process-proofs $MoreHeads $Lit))) -; ;;eigentlich ein Filter: jedem Literal - -; ;;im Parent entspricht eines in der Resolvente - +; (= @@ -660,9 +696,11 @@ (= $S0 new-head) (= $S p) (= $S n)) (retract-literals $Proof))) +; + ; -; for backtracking +; (= (g1-process-proofs @@ -670,70 +708,71 @@ (with_self (/ $_ $_) $Proof) $MoreHeads) $Lit) ( (assert-literals $Proof) (g1-process-proofs $MoreHeads $Lit))) -; ; write('new kb'),nl,subsume_mngr:show_heads,subsume_mngr:show_bodies,nl, - +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: assert_absorptions/2 +; ; -; * +; ; -; * syntax: assert_assorptions(+[CL|_],-Flag) +; ; -; * +; ; -; * args: CL: clause in list notation +; ; -; * +; ; -; * description: asserts heads H of all absorbed clauses, if new, as +; ; -; * body(H,_,_). Flag=1 if at least one existed +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (assert_absorptions () $F) True) +; + (= (assert-absorptions (Cons @@ -743,6 +782,8 @@ ( (body $Head $OldNew $Count) (set-det) (assert-absorptions $MoreHeads $F))) +; + (= (assert-absorptions @@ -750,13 +791,15 @@ (Cons (with_self $Head (p)) $Proof) $MoreHeads) 1) - ( (add-atom &self + ( (add-symbol &self (body $Head new 0)) (annotate-redundancy $Proof) (assert-absorptions $MoreHeads 1))) +; + ; -; For Backtracking +; (= (assert-absorptions @@ -764,1078 +807,1178 @@ (Cons (with_self $Head (p)) $Proof) $MoreHeads) $_) - (remove-atom &self + (remove-symbol &self (body $Head new 0))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: annotate_redundancy/1 +; ; -; * +; ; -; * syntax: annotate_redundancy(+Proof) +; ; -; * +; ; -; * args: Proof: clause in list notation +; ; -; * +; ; -; * description: increments counter for each body literal in Proof +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (annotate_redundancy ()) True) +; + (= (annotate-redundancy (Cons (with_self $L $_) $More)) - ( (remove-atom &self + ( (remove-symbol &self (body $L $OldNew $I)) (is $J (+ $I 1)) - (add-atom &self + (add-symbol &self (body $L $OldNew $J)) (annotate-redundancy $More))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: assert_body_randomly/1 +; ; -; * +; ; -; * syntax: assert_body_randomly(+Clause_list) +; ; -; * +; ; -; * args: +Clause_list ... Clause in list notation +; ; -; * +; ; -; * description: assert body literals in random order +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (assert-body-randomly Nil) (set-det)) +; + (= (assert-body-randomly (Cons (with_self $H (p)) $More)) ( (head $H $_ $_) (set-det) (assert-body-randomly $More))) +; + (= (assert-body-randomly (Cons (with_self $H (p)) $More)) - ( (add-atom &self + ( (add-symbol &self (head $H $_ $_)) (assert-body-randomly $More))) +; + (= (assert-body-randomly (Cons (with_self $L $_) $More)) ( (body $L $_ $_) (set-det) (assert-body-randomly $More))) +; + (= (assert-body-randomly (Cons (with_self $L $_) $More)) ( (maybe) - (add-atom &self + (add-symbol &self (body $L old 0)) (assert-body-randomly $More))) +; + (= (assert-body-randomly (Cons (with_self $L $_) $More)) - ( (add-atom &self + ( (add-symbol &self (body $L old 0)) (assert-body-randomly $More))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: addtolist/1 +; ; -; * +; ; -; * syntax: addtolist(+ToAdd) +; ; -; * +; ; -; * args: ToAdd .. Id or list of Id's +; ; -; * +; ; -; * description: asserts list of Id's +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (addtolist (Cons $L $IST)) - ( (remove-atom &self + ( (remove-symbol &self (id_list $List1)) (append $List1 (Cons $L $IST) $List2) - (add-atom &self + (add-symbol &self (id_list $List2)) (set-det))) +; + (= (addtolist $Id) - ( (remove-atom &self + ( (remove-symbol &self (id_list $List1)) - (add-atom &self + (add-symbol &self (id_list (Cons $Id $List1))) (set-det))) +; + (= (addtolist (Cons $L $IST)) - ( (add-atom &self + ( (add-symbol &self (id_list (Cons $L $IST))) (set-det))) +; + (= (addtolist $Id) - ( (add-atom &self + ( (add-symbol &self (id_list ($Id))) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: getlist/1 +; ; -; * +; ; -; * syntax: getlist(-ID_list) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: retracts the list of id's that has been asserted by +; ; -; * addtolist/1 +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (getlist $List) - (remove-atom &self + (remove-symbol &self (id_list $List))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: cover_assert_assumptions +; ; -; * +; ; -; * syntax: cover_assert_assumptions(+Clause_list) +; ; -; * +; ; -; * args: Clause_list .. clause in list representation +; ; -; * +; ; -; * description: asserts for each literal L in Clause_list assumption(L,_,_) +; ; -; * in the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (cover_assert_assumptions ()) True) +; + (= (cover-assert-assumptions (Cons (with_self $L $_) $More)) - ( (add-atom &self + ( (add-symbol &self (assumption $L $_ $_)) (cover-assert-assumptions $More))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: clear_mngr/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: retracts all head/3 and body/3 within the knowledge base +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (clear-mngr) - ( (remove-all-atoms &self - (head $_ $_ $_)) (remove-all-atoms &self (body $_ $_ $_)))) + ( (remove-all-symbols &self + (head $_ $_ $_)) (remove-all-symbols &self (body $_ $_ $_)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: retract_body_literals/1 +; ; -; * +; ; -; * syntax: retract_body_literals(+CL) +; ; -; * +; ; -; * args: CL: clause in list notation +; ; -; * +; ; -; * description: retracts body(L,_,_) for each L:_ in CL +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (retract-body-literals (Cons (with_self $L $_) $More)) - ( (remove-atom &self + ( (remove-symbol &self (body $L $_ $_)) (retract-body-literals $More))) +; + (= (retract_body_literals ()) True) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: retract_literals/1 +; ; -; * +; ; -; * syntax: retract_literals(+[[Lit,N]|_]) +; ; -; * +; ; -; * args: N in {head,body} +; ; -; * +; ; -; * description: retracts head(Lit,_,_)/body(Lit,_,_) for each [Lit,head]/ +; ; -; * [Lit,body] in the input +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (retract_literals ()) True) +; + (= (retract-literals (Cons (:: $L head) $Rest)) - ( (remove-atom &self + ( (remove-symbol &self (head $L $_ $_)) (set-det) (retract-literals $Rest))) +; + (= (retract-literals (Cons (:: $L body) $Rest)) - ( (remove-atom &self + ( (remove-symbol &self (body $L $_ $_)) (set-det) (retract-literals $Rest))) +; + (= (retract-literals (Cons (:: $_ $_) $Rest)) (retract-literals $Rest)) +; + (= (retract-literals (Cons Nil $Rest)) (retract-literals $Rest)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: assert_literals/1 +; ; -; * +; ; -; * syntax: assert_literals(+[[Lit,N]|_]) +; ; -; * +; ; -; * args: N in {head,body} +; ; -; * +; ; -; * description: asserts each Lit with [Lit,N] in the input as N(Lit,_,_) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (assert_literals ()) True) +; + (= (assert-literals (Cons (:: $L head) $Rest)) - ( (add-atom &self + ( (add-symbol &self (head $L $_ $_)) (set-det) (assert-literals $Rest))) +; + (= (assert-literals (Cons (:: $L body) $Rest)) - ( (add-atom &self + ( (add-symbol &self (body $L $_ $_)) (set-det) (assert-literals $Rest))) +; + (= (assert-literals (Cons (:: $_ $_) $Rest)) (assert-literals $Rest)) +; + (= (assert-literals (Cons Nil $Rest)) (assert-literals $Rest)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: assert_clause/1 +; ; -; * +; ; -; * syntax: assert_clause(+CL) +; ; -; * +; ; -; * args: CL .. clause in list representation +; ; -; * +; ; -; * description: asserts positive literals L in CL as head(L,old,0), +; ; -; * negative and redundant literals as body(L,old,0). +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (assert-clause $C) (assert-clause1 $C)) +; + (= (assert-clause $_) ( (clear-mngr) (set-det) - (fail))) ; -; on backtracking + (fail))) +; + ; +; (= (assert_clause1 ()) True) +; + (= (assert-clause1 (Cons $H $T)) ( (assert-clause1 $H) (assert-clause1 $T))) +; + (= (assert-clause1 (with_self $H (p))) (head $H $_ $_)) +; + (= (assert-clause1 (with_self $H (p))) - (add-atom &self + (add-symbol &self (head $H old 0))) +; + (= (assert-clause1 (with_self $H $S)) ( (member $S (:: n r)) (body $H $_ $_))) +; + (= (assert-clause1 (with_self $H $S)) ( (member $S - (:: n r)) (add-atom &self (body $H old 0)))) + (:: n r)) (add-symbol &self (body $H old 0)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: assert_body/1 +; ; -; * +; ; -; * syntax: assert_body(+CL) +; ; -; * +; ; -; * args: CL ... clause body in list representation (only negative and +; ; -; * redundant literals) +; ; -; * +; ; -; * description: asserts each literal L in CL as body(L,old,0) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (assert_body ()) True) +; + (= (assert-body (Cons $H $T)) ( (assert-body $H) (assert-body $T))) +; + (= (assert-body (with_self $H $S)) ( (member $S - (:: n r)) (add-atom &self (body $H old 0)))) + (:: n r)) (add-symbol &self (body $H old 0)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: assert_body_unique/1 +; ; -; * +; ; -; * syntax: assert_body_unique(+CL) +; ; -; * +; ; -; * args: CL ... clause body in list representation (only negative and +; ; -; * redundant literals) +; ; -; * +; ; -; * description: as assert_body/1, but tests whether body(L,_,_) is already +; ; -; * in the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (assert_body_unique ()) True) +; + (= (assert-body-unique (Cons $H $T)) ( (assert-body-unique $H) (assert-body-unique $T))) +; + (= (assert-body-unique (with_self $H $S)) ( (member $S (:: n r)) (body $H $_ $_))) +; + (= (assert-body-unique (with_self $H $S)) ( (member $S - (:: n r)) (add-atom &self (body $H old 0)))) + (:: n r)) (add-symbol &self (body $H old 0)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: reset_counts/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: for each kb-entry head(Lit,_,Count) and body(Lit,_,Count), +; ; -; * Count is set to 0 +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (reset-counts) - ( (remove-atom &self + ( (remove-symbol &self (body $L $O $_)) - (add-atom &self + (add-symbol &self (body $L $O 0)) (fail))) +; + (= (reset-counts) - ( (remove-atom &self + ( (remove-symbol &self (head $L $O $_)) - (add-atom &self + (add-symbol &self (head $L $O 0)) (fail))) +; + (= reset_counts True) +; + ; -; ********************************************************************** +; ; -; * +; ; -; * predicate: subs_build_clause/1 +; ; -; * +; ; -; * syntax: subs_build_clause(-CL) +; ; -; * +; ; -; * args: CL ... Horn clause in list representation +; ; -; * +; ; -; * description: retracts one entry head(H,_,_) and all entries +; ; -; * body(L,_,_) and builds clause [H:p,..,L:p,...] +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (subs-build-clause (Cons (with_self $H (p)) $Body)) - ( (remove-atom &self + ( (remove-symbol &self (head $H $_ $_)) (subs-build-clause $Body) (set-det))) +; + (= (subs-build-clause (Cons (with_self $L (n)) $Body)) - ( (remove-atom &self + ( (remove-symbol &self (body $L $_ $_)) (subs-build-clause $Body))) +; + (= (subs-build-clause Nil) (set-det)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: sat_build_clause/3 +; ; -; * +; ; -; * syntax: sat_build_clause(+H,+B,-CL) +; ; -; * +; ; -; * args: H ... head +; ; -; * B ... list of body literals +; ; -; * CL ... Horn clause in list representation +; ; -; * +; ; -; * description: build clause CL = [H:p,...,L:M,....] for each L in B. +; ; -; * M is n, if body(L,_,_) is true, else M is r +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1845,9 +1988,13 @@ (with_self $H (p)) $B1)) (sat-build-body $B $B1)) +; + (= (sat_build_body () ()) True) +; + (= (sat-build-body (Cons $L $B) @@ -1857,8 +2004,7 @@ ( (body $L $_ 0) (set-det) (sat-build-body $B $B1))) -; ; nonredundant literal - +; (= (sat-build-body @@ -1867,62 +2013,61 @@ (with_self $L (r)) $B1)) (sat-build-body $B $B1)) -; ; (probably) superfluos literal - +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: msg_build_long_clause/1 +; ; -; * +; ; -; * syntax: msg_build_long_clause(-CL) +; ; -; * +; ; -; * args: CL ... a general clause in list representation +; ; -; * +; ; -; * description: +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1933,141 +2078,147 @@ (msg-build-body $Body) (append $Heads $Body $Clause) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: msg_build_heads/1 +; ; -; * +; ; -; * syntax: msg_build_heads(-CL) +; ; -; * +; ; -; * args: CL ... clause in list representation, consisting only of +; ; -; * positive literals +; ; -; * +; ; -; * description: collects all Literals L such that head(L,_,_) is in kb, +; ; -; * and returns CL = [...,L:p,....] +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (msg-build-heads (Cons (with_self $H (p)) $More)) - ( (remove-atom &self + ( (remove-symbol &self (head $H $F $I)) (msg-build-heads $More) - (add-atom &self + (add-symbol &self (head $H $F $I)))) +; + (= (msg-build-heads Nil) (set-det)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: msg_build_body/1 +; ; -; * +; ; -; * syntax: msg_build_body(-CL) +; ; -; * +; ; -; * args: CL ... clause in list representation, consisting only of +; ; -; * negative and redundant literals +; ; -; * +; ; -; * description: collects all Literals L such that body(L,_,_) is in kb, +; ; -; * and returns CL = [...,L:M,....], M in {n,r} +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (msg-build-body (Cons (with_self $H $Sign) $More)) - ( (remove-atom &self + ( (remove-symbol &self (body $H $F $I)) (det-if-then-else (= $I 0) @@ -2075,135 +2226,138 @@ (= $Sign r)) (msg-build-body $More) (set-det) - (add-atom &self + (add-symbol &self (body $H $F $I)))) +; + (= (msg-build-body Nil) (set-det)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: idev_build_clause1/1 +; ; -; * +; ; -; * syntax: idev_build_clause1(-CL) +; ; -; * +; ; -; * args: CL .. Horn clause in list representation +; ; -; * +; ; -; * description: +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (idev-build-clause1 (Cons (with_self $H (p)) $More)) - ( (remove-atom &self + ( (remove-symbol &self (head $H $F 0)) (set-det) (idev-build-body $More) - (add-atom &self + (add-symbol &self (head $H $F 0)))) -; ; the head is unique ! - +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: idev_build_body/1 +; ; -; * +; ; -; * syntax: idev_build_body(-CL) +; ; -; * +; ; -; * args: CL ... clause in list represenation, only negative and redundant literals +; ; -; * +; ; -; * description: collects all L such that body(L,_,_) is in kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (idev-build-body (Cons (with_self $H $Sign) $More)) - ( (remove-atom &self + ( (remove-symbol &self (body $H $F $I)) (det-if-then-else (= $I 0) @@ -2211,68 +2365,72 @@ (= $Sign r)) (idev-build-body $More) (set-det) - (add-atom &self + (add-symbol &self (body $H $F $I)))) +; + (= (idev-build-body Nil) (set-det)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: idev_build_clause/2 +; ; -; * +; ; -; * syntax: idev_build_clause(+H,-CL) +; ; -; * +; ; -; * args: CL .. clause in list representation +; ; -; * H ... preferred head of CL +; ; -; * +; ; -; * description: as idev_build_clause1/1, but with preferred head in CL +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2284,212 +2442,222 @@ ( (idev-build-head $PrefHead $H) (idev-build-body $More) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: idev_build_head/2 +; ; -; * +; ; -; * syntax: idev_build_head(+PrefH,-H) +; ; -; * +; ; -; * args: PrefH, H .. clause heads +; ; -; * +; ; -; * description: returns H such that head(H,_,_) in kb and PrefH and H +; ; -; * unifiable. If none exists, the first H with head(H,_,_) in kb +; ; -; * is returned. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (idev-build-head $PrefHead $PrefHead) - ( (remove-atom &self + ( (remove-symbol &self (head $PrefHead $F $N)) (set-det) - (add-atom &self + (add-symbol &self (head $PrefHead $F $N)))) +; + (= (idev-build-head $_ $Head) (head $Head $_ $_)) +; + ; -; retract( head(Head,F,N) ), +; ; -; !, +; ; -; asserta( head(H,F,N) ) +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: ident_build_body/1 +; ; -; * +; ; -; * syntax: ident_build_body(-CL) +; ; -; * +; ; -; * args: CL ... clause in list notation, contains only negative literals +; ; -; * +; ; -; * description: CL = [...,L:n,...] for each L such that body(L,_,0) in kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (ident-build-body (Cons (with_self $L (n)) $Rest)) - ( (remove-atom &self + ( (remove-symbol &self (body $L $_ 0)) (set-det) (ident-build-body $Rest) - (add-atom &self - (body $L old 0)))) ; -; for backtracking + (add-symbol &self + (body $L old 0)))) +; + ; +; (= (ident-build-body Nil) (set-det)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: g1_build_clause/2 +; ; -; * +; ; -; * syntax: g1_build_clause(+ResLit,-CL) +; ; -; * +; ; -; * args: CL ... Horn clause in list notation +; ; -; * ResLit ... the resolution literal +; ; -; * +; ; -; * description: CL is the second parent clause for the g1-operator +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2501,6 +2669,8 @@ (with_self $L (p)) $Body)) ( (ident-build-body $Body) (set-det))) +; + (= (g1-build-clause (with_self $L @@ -2512,76 +2682,82 @@ (with_self $L (n)) $Body))) ( (ident-build-body $Body) - (remove-atom &self + (remove-symbol &self (head $H $_ 0)) (set-det) - (add-atom &self - (head $L old 0)))) + (add-symbol &self + (head $L old 0)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: abs_build_body/1 +; ; -; * +; ; -; * syntax: abs_build_body(-CL) +; ; -; * +; ; -; * args: CL .. clause in list representation, contains only negative literals +; ; -; * +; ; -; * description: CL = [...,L:n,....] for each L such that body(L,_,_) in kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (abs-build-body (Cons (with_self $L (n)) $Rest)) - ( (remove-atom &self + ( (remove-symbol &self (body $L $F $I)) (set-det) (abs-build-body $Rest) - (add-atom &self + (add-symbol &self (body $L $F $I)))) +; + (= (abs-build-body Nil) (set-det)) +; + diff --git a/miles/clause_heads.metta b/miles/clause_heads.metta index db88932..1266297 100644 --- a/miles/clause_heads.metta +++ b/miles/clause_heads.metta @@ -1,5 +1,5 @@ ; -; MODULE clause_heads EXPORTS +; @@ -9,9 +9,11 @@ (/ heads 1) (/ heads 2) (/ heads 3))) +; + ; -; IMPORTS +; !(use-module (home div-utils) @@ -23,12 +25,18 @@ (/ split-examples 4) (/ insert-unique 3) (/ remove-v 3))) +; + !(use-module (home var-utils) (:: (/ terms 4))) +; + !(use-module (home interpreter) (:: (/ proof-path 4))) +; + !(use-module (home kb) (:: @@ -36,133 +44,147 @@ (/ get-clause 5) (/ store-clauses 2) (/ delete-clause 1))) +; + !(use-module (home argument-types) (:: (/ type-restriction 2))) +; + !(use-module (home lgg) (:: (/ set-lgg 2))) +; + !(use-module (home evaluation) (:: (/ eval-examples 0))) +; + !(use-module-if-exists (library subsumes) (:: (/ subsumes-chk 2))) +; + !(use-module-if-exists (library basics) (:: (/ member 2))) +; + !(use-module-if-exists (library lists) (:: (/ rev 2))) +; + ; -; METAPREDICATES +; ; -; none +; ; -; ************************************************************************ +; ; -; * +; ; -; * module: clause_heads.pl +; ; -; * +; ; -; * author: Irene Stahl date: 13. 10. 1992 +; ; -; * +; ; -; * changed: +; ; -; * +; ; -; * description: algorithm for determining clause heads +; ; -; * generates database entrys of the form +; ; -; * known(ID,Head,true,CList,head,_) +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: clause_heads/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: determines clause heads covering all positive examples in +; ; -; * the kb and asserts them in the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; @@ -173,131 +195,126 @@ (get-example $I $E +)) $Elist) (different-predicates $Elist $Elist1) (clause-heads $Elist1))) -; ; Elist = [E1,..,En] pos examples - -; ; Elist1 = [[E1,..,Em],...] - -; ; list of lists of pos examples with - -; ; the same predicate symbol - +; ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: heads/1 +; ; -; * +; ; -; * syntax: heads(-HL) +; ; -; * +; ; -; * args: HL list of clause heads +; ; -; * +; ; -; * description: returns list of heads covering all positive examples in +; ; -; * the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; (= (heads $HL) ( (clause-heads) (mysetof $Head (^ $ID (^ $Body (^ $CL (, (get-clause $ID $Head $Body $CL head) (delete-clause $ID))))) $HL))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: heads/2 +; ; -; * +; ; -; * syntax: heads(+Pred,+Arity) +; ; -; * +; ; -; * args: Pred .. predicate symbol (atom), Arity.. an integer +; ; -; * +; ; -; * description: determines clause heads covering all positive examples for +; ; -; * Pred/Arity and asserts them in the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; (= @@ -307,60 +324,62 @@ (^ $I (get-example $I $E +)) $Elist) (clause-heads (:: $Elist)))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: heads/3 +; ; -; * +; ; -; * syntax: heads(+Pred,+Arity,-HL) +; ; -; * +; ; -; * args: Pred .. predicate symbol, Arity .. integer, HL .. list of heads +; ; -; * +; ; -; * description: returns list of heads covering all positive examples for +; ; -; * Pred/Arity +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; (= @@ -378,68 +397,72 @@ (, (get-clause $ID $Head $Body $CL head) (delete-clause $ID))))) $HL))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: clause_heads/1 +; ; -; * +; ; -; * syntax: clause_heads(+ELL) +; ; -; * +; ; -; * args: ELL = [[E1,..,Em],...] list of lists of pos examples with the +; ; -; * same predicate symbol +; ; -; * +; ; -; * description: determines for each [E1,..,Em] in ELL clause heads +; ; -; * and asserts them in the knowledge base +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; (= (clause_heads ()) True) +; + (= (clause-heads (Cons $EL $R)) ( (clause-heads $R) @@ -448,67 +471,69 @@ (minimize-heads $Heads1 $EL $Heads2) (store-clauses $Heads2 head) (eval-examples))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: clause_heads/2 +; ; -; * +; ; -; * syntax: clause_heads(+EL,-Heads) +; ; -; * +; ; -; * args: +EL = [E1,...,Em] positive examples of a predicate p/n +; ; -; * Heads = [H1,..,Hk] heads for p/n covering EL +; ; -; * +; ; -; * description: determines heads for p/n by determining base heads +; ; -; * and heads for non-base examples according to the +; ; -; * differing types +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; (= @@ -530,87 +555,95 @@ (make-unique $Hlist $Hlist1) (best-lgg $Hlist1 (Cons $E $R) $B $Heads))) +; + (= (trivial_tr () ()) True) +; + (= (trivial-tr (Cons $X $R) (Cons $T $R1)) ( (trivial-tr $R $R1) (=.. $T (:: all $X)))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: bases/5 +; ; -; * +; ; -; * syntax: bases(+Count,+E,+P,+Type,-B) +; ; -; * +; ; -; * args: N .. counter +; ; -; * E .. positive examples for p/n +; ; -; * P, Type .. type restriction of the target predicate p/n +; ; -; * B .. base heads for p/n +; ; -; * +; ; -; * description: for each argument position N, +; ; -; * for each base case at b at that position, +; ; -; * add lgg({p(..,b,..)|p(..,b,..) in E}) to B +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; (= (bases 0 $_ $_ $_ ()) True) +; + (= (bases $N $E $P $Type $B) ( (is $N1 @@ -633,10 +666,14 @@ (=.. $T (:: $R $Base)))))) $Bases) (bases1 $Bases $N $E $B1 $B))) +; + (= (bases1 () $_ $_ $B $B) True) +; + (= (bases1 (Cons $B $R) $N $E $B1 @@ -644,10 +681,14 @@ ( (bases1 $R $N $E $B1 $B2) (bases2 $E $N $B $Eb) (set-lgg $Eb $H))) +; + (= (bases2 () $_ $_ ()) True) +; + (= (bases2 (Cons $E $R) $N $B @@ -655,86 +696,94 @@ ( (arg $N $E $B) (set-det) (bases2 $R $N $B $R1))) +; + (= (bases2 (Cons $_ $R) $N $B $R1) (bases2 $R $N $B $R1)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: split_examples_by_types/4 +; ; -; * +; ; -; * syntax: split_examples_by_types(+E,+P,+Type,-Heads) +; ; -; * +; ; -; * args: E ... examles for p/n (without base examples) +; ; -; * P,Type ... type restriction for p/n +; ; -; * Heads ... list [..., H:terms(H),...] of heads for p/n according +; ; -; * to different types +; ; -; * +; ; -; * description: splits examples E according to different argument types +; ; -; * -> ELL list of example lists. For each EL in ELL, lgg(EL) is +; ; -; * added to heads +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; (= (split-examples-by-types $E $P $Types $Heads) ( (split-examples-by-types $Types $P $E Nil $Elist) (construct-heads $Elist $Heads))) +; + (= (split_examples_by_types () $_ $_ $EL $EL) True) +; + (= (split-examples-by-types (Cons $T $R) $P $E $EL $EL3) @@ -746,11 +795,15 @@ (proof-path $Ex $P $T $Ts)) $Elist0) (split-example-list $Elist0 $EL2) (append $EL1 $EL2 $EL3))) +; + (= (split_example_list () ()) True) +; + (= (split-example-list (Cons @@ -758,76 +811,84 @@ (Cons (Cons $E $EL) $R1)) ( (split-elist $R $Ts $EL $R0) (split-example-list $R0 $R1))) +; + (= (split_elist () $_ () ()) True) +; + (= (split-elist (Cons (, $E $Ts) $R) $Ts (Cons $E $R1) $R2) (split-elist $R $Ts $R1 $R2)) +; + (= (split-elist (Cons $E $R) $Ts $R1 (Cons $E $R2)) (split-elist $R $Ts $R1 $R2)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: construct_heads/2 +; ; -; * +; ; -; * syntax: construct_heads(+ELL,-Heads) +; ; -; * +; ; -; * args: ELL ... list of lists of examples +; ; -; * Heads ... list [...,H:terms(H),...] of heads +; ; -; * +; ; -; * description: for each EL in ELL set H:= lgg(EL), terms(H) terms of H +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; @@ -840,80 +901,86 @@ (functor $H $_ $N) (terms $N $H Nil $Vars) (construct-heads $R $R1))) +; + (= (construct_heads () ()) True) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: best_lgg/4 +; ; -; * +; ; -; * syntax: best_lgg(+ToRefine,+E,+Heads,-Heads) +; ; -; * +; ; -; * args: ToRefine ... list [...,H:terms(H),...] of heads +; ; -; * E ... examples +; ; -; * Heads ... resulting heads [...,H,...] +; ; -; * +; ; -; * description: while ToRefine \= [], +; ; -; * add first element H to Heads and +; ; -; * compute all refinements of H that result from unifying +; ; -; * terms within H. Add the refinements to ToRefine. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; (= (best_lgg () $_ $HL $HL) True) +; + (= (best-lgg (Cons @@ -926,86 +993,94 @@ (append $Lp $R $R1) (best-lgg $R1 $E (Cons $H $HL) $HL1)))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: try_to_unify/6 +; ; -; * +; ; -; * syntax: try_to_unify(+H,+Terms,+Terms,+E,+Result,-Result) +; ; -; * +; ; -; * args: H .. head that is to be refined +; ; -; * Terms ... terms(H) +; ; -; * E ... examples +; ; -; * Result ... list [...,H1:terms(H1),...] of refined heads +; ; -; * +; ; -; * description: for each pair X,Y (X \== Y) in terms(H) +; ; -; * if H[X/Y] covers examples E' in E +; ; -; * then add H1:terms(H1) to result where H1 = lgg(E') +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; (= (try_to_unify $_ () $_ $_ $L $L) True) +; + (= (try-to-unify $H (Cons $X $R) $V $E $L $L2) ( (unify-vars $H $X $V $E $L $L1) (try-to-unify $H $R $V $E $L1 $L2))) +; + (= (unify_vars $_ $_ () $_ $L $L) True) +; + (= (unify-vars $H $X (Cons $Y $R) $E $L $L2) @@ -1014,11 +1089,15 @@ (, $H1 $X1 $Y1)) (unify-var $H1 $X1 $Y1 $E $L $L1) (unify-vars $H $X $R $E $L1 $L2))) +; + (= (unify-var $_ $X $Y $_ $L $L) ( (== $X $Y) (set-det))) +; + (= (unify-var $H $X $X $E $L0 $L1) ( (set-det) @@ -1033,70 +1112,67 @@ (Cons (with_self $H1 $Vars1) $L0))) (= $L1 $L0)))) -; ; ( Vars1 == [] -> -; ; L1 = L0 -; ; ; - -; ; ) - +; (= (unify_var $_ $_ $_ $_ $L $L) True) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: remove_base_example/3 +; ; -; * +; ; -; * syntax: remove_base_example(+BHeads,+E,-E) +; ; -; * +; ; -; * args: BHeads ... base heads +; ; -; * E ... examples +; ; -; * +; ; -; * description: removes all examples covered by base heads in BHeads from E +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; @@ -1106,13 +1182,19 @@ ( (is-base-example $E $B) (set-det) (remove-base-examples $B $R $R1))) +; + (= (remove-base-examples $B (Cons $E $R) (Cons $E $R1)) (remove-base-examples $B $R $R1)) +; + (= (remove_base_examples $_ () ()) True) +; + @@ -1120,68 +1202,72 @@ (is-base-example $E (Cons $B $_)) ( (subsumes-chk $B $E) (set-det))) +; + (= (is-base-example $E (Cons $_ $R)) (is-base-example $E $R)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: minimize_heads/3 +; ; -; * +; ; -; * syntax: minimize_heads(+Heads,+Examples,-Heads) +; ; -; * +; ; -; * args: Heads.. list of clause heads +; ; -; * Examples... positive examples to be covered by Heads +; ; -; * +; ; -; * description: minimizes the set of clause heads by first removing general +; ; -; * redundant heads, then specific redundant heads. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; @@ -1191,67 +1277,73 @@ (remove-redundant $H1 $H1 $EL $H2) (rev $H2 $H3) (remove-redundant $H3 $H3 $EL $H4))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: sort_heads_theta/2 +; ; -; * +; ; -; * syntax: sort_heads_theta(+Heads,-Heads) +; ; -; * +; ; -; * args: Heads.. list of clause heads +; ; -; * +; ; -; * description: sorts Heads descendingly according to theta-subsumption +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; (= (sort_heads_theta () ()) True) +; + (= (sort-heads-theta (Cons $H $R) $L) ( (sort-heads-theta $R $L1) (insert-heads-theta $L1 $H $L))) +; + (= @@ -1261,64 +1353,68 @@ ( (subsumes-chk $H1 $H) (set-det) (insert-heads-theta $R $H $R1))) +; + (= (insert_heads_theta $L $H (Cons $H $L)) True) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: remove_redundant/4 +; ; -; * +; ; -; * syntax: remove_redundant(+Heads,+Heads,+Examples,-Heads) +; ; -; * +; ; -; * args: Heads.. list of clause heads +; ; -; * Examples... positive examples to be covered by Heads +; ; -; * +; ; -; * description: removes redundant heads from the list Heads +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; @@ -1327,70 +1423,78 @@ (Cons $H $R) $HL $EL $HL1) ( (remove-v (:: $H) $HL $HL0) (det-if-then-else (heads-cover $HL0 $EL) (remove-redundant $R $HL0 $EL $HL1) (remove-redundant $R $HL $EL $HL1)))) +; + (= (remove_redundant () $HL $_ $HL) True) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: heads_cover/2 +; ; -; * +; ; -; * syntax: heads_cover(+Heads,+Examples) +; ; -; * +; ; -; * args: Heads.. list of clause heads +; ; -; * Examples... positive examples to be covered by Heads +; ; -; * +; ; -; * description: tests whether the heads in Heads cover all examples +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; (= (heads_cover $_ ()) True) +; + (= (heads-cover (Cons $H $R) $E) ( (split-examples $E $H $_ $E1) (heads-cover $R $E1))) +; + diff --git a/miles/div_utils.metta b/miles/div_utils.metta index 1a765c3..dcf4f7c 100644 --- a/miles/div_utils.metta +++ b/miles/div_utils.metta @@ -1,5 +1,5 @@ ; -; MODULE div_utils EXPORTS +; @@ -46,207 +46,231 @@ (/ log2 2) (/ log2nueberk 3) (/ sum-of-logs 3))) +; + ; -; METAPREDICATES +; !(meta-predicate (mysetof + : -)) +; + ; -; IMPORTS +; !(use-module-if-exists (library basics) (:: (/ member 2))) +; + !(use-module-if-exists (library subsumes) (:: (/ variant 2))) +; + !(use-module-if-exists (library occurs) (:: (/ sub-term 2) (/ contains-var 2))) +; + !(use-module-if-exists (library lists) (:: (/ rev 2))) +; + !(use-module-if-exists (library math) (:: (/ log 2))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * module: div_utils.pl +; ; -; * +; ; -; * author: B.Jung, M.Mueller, I.Stahl, B.Tausend date:12/92 +; ; -; * +; ; -; * changed: +; ; -; * +; ; -; * description: small auxiliary procedures +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: remove/3 +; ; -; * +; ; -; * syntax: remove(+I,+L,-L) +; ; -; * +; ; -; * args: I .. number, L ... list of numbers +; ; -; * +; ; -; * description: removes I from L (I occurs at most once in L) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (remove $_ () ()) True) +; + (= (remove $I (Cons $I $R) $R) (set-det)) +; + (= (remove $I (Cons $J $R) (Cons $J $R1)) (remove $I $R $R1)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: sort_by_length/3 +; ; -; * +; ; -; * syntax: sort_by_length(+L,+Accu,-Accu) +; ; -; * +; ; -; * args: L ... list of lists +; ; -; * Accu ... L sorted increasingly according to the length of sublists +; ; -; * +; ; -; * description: sorts a list of lists increasingly according to +; ; -; * the length of sublists +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (sort_by_length () $L $L) True) +; + (= (sort-by-length (Cons $IXS $R) $L $L2) ( (insert-by-length $IXS $L $L1) (sort-by-length $R $L1 $L2))) +; + (= @@ -258,192 +282,204 @@ (> $N $N1) (set-det) (insert-by-length $X $R $R1))) +; + (= (insert_by_length $X $L (Cons $X $L)) True) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: mysetof/3 +; ; -; * +; ; -; * syntax: mysetof(+Template,+Generator,-Set) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: as setof/3, but succeeds with Set = [], if Generator +; ; -; * fails +; ; -; * +; ; -; * example: setof(X, append([1,2,3],X,[4,5]),Set) -> fail +; ; -; * mysetof(X, append([1,2,3],X,[4,5]),Set) -> Set = [] +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (mysetof $A $B $C) ( (setof $A $B $C) (set-det))) +; + (= (mysetof $_ $_ ()) True) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: sum/2 +; ; -; * +; ; -; * syntax: sum(+LN,-S) +; ; -; * +; ; -; * args: LN .. list of numbers, S number +; ; -; * +; ; -; * description: if LN = [I1,..,In], then S = I1 + ... + In +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (sum ($I) $I) True) +; + (= (sum (Cons $I $More) $C) ( (sum $More $J) (is $C (+ $I $J)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: efface/3 (by Clocksin/Mellish) +; ; -; * +; ; -; * syntax: efface(+E,+L,-L) +; ; -; * +; ; -; * args: E .. element of list L +; ; -; * +; ; -; * description: removes the first element of L that is unifiable with E +; ; -; * from L. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -451,194 +487,206 @@ (efface $A (Cons $A $L) $L) (set-det)) +; + (= (efface $A (Cons $B $L) (Cons $B $M)) (efface $A $L $M)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: effaceall/3 +; ; -; * +; ; -; * syntax: effacell(+E,+L,-L) +; ; -; * +; ; -; * args: E .. element of list L +; ; -; * +; ; -; * description: as efface, but allows backtracking +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (effaceall $A (Cons $A $L) $L) True) +; + (= (effaceall $A (Cons $B $L) (Cons $B $M)) (effaceall $A $L $M)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: best/2 +; ; -; * +; ; -; * syntax: best(+List,-Elem) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: returns the first element of List, on backtracking +; ; -; * the second etc. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (best (Cons $X $_) $X) True) +; + (= (best (Cons $_ $R) $X) (best $R $X)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: buildpar2/3 +; ; -; * +; ; -; * syntax: buildpar2(+Lit:M,+CL,-CL1) +; ; -; * +; ; -; * args: Lit .. literal, M in {p,n,r}, CL and CL1 clauses in list representation +; ; -; * +; ; -; * description: if M = p then CL1 = [Lit:p|CL] +; ; -; * else CL1 results from CL by adding Lit:M at the end +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -647,65 +695,69 @@ (: $Elem1 p) $List2 (Cons (: $Elem1 p) $List2)) True) +; + (= (buildpar2 $ResLit $List2 $Parent2) (append $List2 (:: $ResLit) $Parent2)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: neg/2 +; ; -; * +; ; -; * syntax: neg(+Lit:M,-Lit:M1) +; ; -; * +; ; -; * args: Lit .... literal, M in {p,n,r} +; ; -; * +; ; -; * description: switches the mark of the literal, i.e. if M = p then +; ; -; * M1 = n and vice versa +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; @@ -713,252 +765,268 @@ (neg (: $F p) (: $F n)) True) +; + (= (neg (: $F n) (: $F p)) True) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: contains_duplicates/1 +; ; -; * +; ; -; * syntax: contains_duplicates(+L) +; ; -; * +; ; -; * args: L ... list +; ; -; * +; ; -; * description: succeeds if L contains two unifiable elements +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (contains-duplicates (Cons $H $T)) (member $H $T)) +; + (= (contains-duplicates (Cons $_ $T)) (contains-duplicates $T)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: contains_identicals/1 +; ; -; * +; ; -; * syntax: contains_identicals(+L) +; ; -; * +; ; -; * args: L ... list +; ; -; * +; ; -; * description: succeeds if L contains two identical (==) elements +; ; -; * +; ; -; * example: +; ; -; * +; ; -; *********************************************************************** +; (= (contains-identicals (Cons $H $T)) (contains-var $H $T)) +; + (= (contains-identicals (Cons $_ $T)) (contains-identicals $T)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: identical_member/2 +; ; -; * +; ; -; * syntax: identical_member(+Elem,+List) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: succeeds if Elem is identically (==) contained in List +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (identical-member $A (Cons $A1 $_)) - (== $A $A1)) + (== $A $A1)) +; + (= (identical-member $A (Cons $_ $R)) - (identical-member $A $R)) + (identical-member $A $R)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: convert_to_horn_clause/3 +; ; -; * +; ; -; * syntax: convert_to_horn_clause(+PHead,+CL,-HCL) +; ; -; * +; ; -; * args: PHead ... preferred head +; ; -; * CL ... general clause in list representation +; ; -; * HCL ... horn clause in list representation +; ; -; * +; ; -; * description: if CL = [H1:p,..,Hn:p,L1:M1,..,Lm:Mm] where Mi in {p,r} +; ; -; * then HCL = [Hj:p,L1:M1,...,Lm:Mm], where Hj is the first +; ; -; * head in CL unifiable with PHead (if one exists), else +; ; -; * the first head in CL +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -978,75 +1046,72 @@ (Cons (with_self $Head (p)) $Body)))) -; ; if preferred head is among - -; ; candidates, select it. - -; ; Else select first candidate. - +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: extract_body/2 +; ; -; * +; ; -; * syntax: extract_body(+CL,-CL1) +; ; -; * +; ; -; * args: CL .. clause in list representation +; ; -; * CL1 = [...,L:M,...] where M in {p,n} and L in CL +; ; -; * +; ; -; * description: +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (extract_body () ()) True) +; + (= (extract-body (Cons @@ -1056,6 +1121,8 @@ (with_self $L (n)) $Rest1)) (extract-body $Rest $Rest1)) +; + (= (extract-body (Cons @@ -1065,65 +1132,69 @@ (with_self $L (r)) $Rest1)) (extract-body $Rest $Rest1)) +; + (= (extract-body (Cons (with_self $_ (p)) $Rest) $Rest1) (extract-body $Rest $Rest1)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: list_to_struct/2 +; ; -; * +; ; -; * syntax: list_to_struct(+L,-C) +; ; -; * +; ; -; * args: L ... list, C ... conjunction of elements of L +; ; -; * +; ; -; * description: if L = [E1,...,En] then C = (E1,..,En) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1134,69 +1205,75 @@ (, $A $Rest1)) (list-to-struct (Cons $B $Rest) $Rest1)) +; + (= (list_to_struct ($A) $A) True) +; + (= (list_to_struct () true) True) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: clist_to_MeTTa/2 +; ; -; * +; ; -; * syntax: clist_to_MeTTa(+CL,-C) +; ; -; * +; ; -; * args: CL .. Horn clause in list representation +; ; -; * C ... Horn clause in MeTTa format +; ; -; * +; ; -; * description: convert list format to clause format and vice versa +; ; -; * (should use body2list!!) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1208,11 +1285,15 @@ (Cons $B $Rest)) (= $A $Rest1)) ( (set-det) (clist-to-prolog (Cons $B $Rest) $Rest1))) +; + (= (clist-to-prolog (:: (with_self $A (p))) (= $A True)) (set-det)) +; + (= (clist-to-prolog (Cons @@ -1221,10 +1302,14 @@ (Cons $B $Rest)) (, $A $Rest1)) ( (set-det) (clist-to-prolog (Cons $B $Rest) $Rest1))) +; + (= (clist-to-prolog (:: (with_self $A (n))) $A) (set-det)) +; + (= (clist-to-prolog (Cons @@ -1234,129 +1319,139 @@ (, $A $Rest1)) (clist-to-prolog (Cons $B $Rest) $Rest1)) +; + (= (clist_to_prolog ( (: $A r)) $A) True) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: append_all/2 +; ; -; * +; ; -; * syntax: append_all(+LL,-L) +; ; -; * +; ; -; * args: LL .. list of lists, L .. list +; ; -; * +; ; -; * description: appends all lists in LL -> L +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (append_all () ()) True) +; + (= (append-all (Cons $P $R) $R2) ( (append-all $R $R1) (append $P $R1 $R2))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: maximum/2 +; ; -; * +; ; -; * syntax: maximum(+L,-M) +; ; -; * +; ; -; * args: L .. list of numbers, M number +; ; -; * +; ; -; * description: M is the maximum element of L +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (maximum ($I) $I) True) +; + (= (maximum @@ -1364,71 +1459,77 @@ ( (maximum $Rest $J) (>= $I $J) (set-det))) +; + (= (maximum (Cons $_ $Rest) $J) - ( (maximum $Rest $J) (set-det))) + ( (maximum $Rest $J) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: myforall/2 +; ; -; * +; ; -; * syntax: myforall(+E,+Pred) +; ; -; * +; ; -; * args: E ... argument terms, Pred .. type predicate +; ; -; * +; ; -; * description: calls Pred(e) for each e in E, and succeeds only if +; ; -; * every call succeeds +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (myforall () $_) True) +; + (= (myforall (Cons $E $R) $Pred) @@ -1436,340 +1537,366 @@ (:: $Pred $E)) (call $C) (myforall $R $Pred))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: identical_make_unique/2 +; ; -; * +; ; -; * syntax: identical_make_unique(+L,-L1) +; ; -; * +; ; -; * args: L,L1 ... lists +; ; -; * +; ; -; * description: removes all identical duplicates (==) from L +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (identical_make_unique () ()) True) +; + (= (identical-make-unique (Cons $X $R) $R1) ( (contains-var $X $R) (set-det) - (identical-make-unique $R $R1))) + (identical-make-unique $R $R1))) +; + (= (identical-make-unique (Cons $X $R) (Cons $X $R1)) - (identical-make-unique $R $R1)) + (identical-make-unique $R $R1)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: remove_v/3 +; ; -; * +; ; -; * syntax: remove_v(+L0,+L,-L1) +; ; -; * +; ; -; * args: L0,L,L1 lists +; ; -; * +; ; -; * description: removes each E in L0 from L if E is identically (==) +; ; -; * contained in L +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (remove_v $_ () ()) True) +; + (= (remove-v $T (Cons $T1 $R) $R1) ( (identical-member $T1 $T) (set-det) (remove-v $T $R $R1))) +; + (= (remove-v $T (Cons $T1 $R) (Cons $T1 $R1)) (remove-v $T $R $R1)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: remove_variant/3 +; ; -; * +; ; -; * syntax: remove_variant(+L0,+L,-L1) +; ; -; * +; ; -; * args: L0,L,L1 lists +; ; -; * +; ; -; * description: removes each E in L0 from L if E is +; ; -; * contained as variant in L +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (remove_variant $_ () ()) True) +; + (= (remove-variant $T (Cons $T1 $R) $R1) ( (variant-mem $T1 $T) (set-det) (remove-variant $T $R $R1))) +; + (= (remove-variant $T (Cons $T1 $R) (Cons $T1 $R1)) (remove-variant $T $R $R1)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: make_unique/2 +; ; -; * +; ; -; * syntax: make_unique(+L,-L1) +; ; -; * +; ; -; * args: L,L1 .. lists +; ; -; * +; ; -; * description: removes all duplicates (variant) from L +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (make_unique () ()) True) +; + (= (make-unique (Cons $X $R) $R1) ( (variant-mem $X $R) (set-det) (make-unique $R $R1))) +; + (= (make-unique (Cons $X $R) (Cons $X $R1)) (make-unique $R $R1)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: variant_mem/2 +; ; -; * +; ; -; * syntax: variant_mem(+Elem,+List) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: succeeds if an alphabetical variant of Elem is +; ; -; * contained in List +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1777,70 +1904,76 @@ (variant-mem $T (Cons $T1 $_)) ( (variant $T $T1) (set-det))) +; + (= (variant-mem $T (Cons $_ $R)) (variant-mem $T $R)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: different_predicates/2 +; ; -; * +; ; -; * syntax: different_predicates(+L,-LL) +; ; -; * +; ; -; * args: L .. list of terms, LL list of lists of terms +; ; -; * +; ; -; * description: for each functor f/n occuring in L, LL contains a list Lf +; ; -; * consisting of all terms in L with principal functor f/n +; ; -; * +; ; -; * example: L = [f(a,b),f(c,d),h(g)] LL = [[f(a,b),f(c,d)],[h(g)]] +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (different_predicates () ()) True) +; + (= (different-predicates (Cons $E $R) @@ -1849,10 +1982,14 @@ ( (functor $E $F $N) (diff-predicates $R $R1 $Es $F $N) (different-predicates $R1 $R2))) +; + (= (diff_predicates () () () $_ $_) True) +; + (= (diff-predicates (Cons $E $R) $R2 $Es2 $_ 0) @@ -1868,133 +2005,141 @@ (= $R2 (Cons $E $R1)) (= $Es2 $Es1))))) +; + (= (diff-predicates (Cons $E $R) $R2 $Es2 $F $N) ( (diff-predicates $R $R1 $Es1 $F $N) (det-if-then-else (functor $E $F $N) (, (= $R2 $R1) (= $Es2 (Cons $E $Es1))) (, (= $R2 (Cons $E $R1)) (= $Es2 $Es1))))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: nth_arg/3 +; ; -; * +; ; -; * syntax: nth_arg(+E,+N,-Args) +; ; -; * +; ; -; * args: E ... list of terms with principal functor p/n +; ; -; * N =< n argument position +; ; -; * Args ... list of argument terms +; ; -; * +; ; -; * description: Args = {A | arg(N,P,A) and P in E} +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (nth_arg () $_ ()) True) +; + (= (nth-arg (Cons $F $R) $N (Cons $Argn $R1)) ( (arg $N $F $Argn) (nth-arg $R $N $R1))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: split_examples/4 +; ; -; * +; ; -; * syntax: split_examples(+E,+Term,-P,-N) +; ; -; * +; ; -; * args: E,P,N ... list of terms +; ; -; * +; ; -; * description: P = {e in E | Term, e unifiable} +; ; -; * N = E - P +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2005,71 +2150,77 @@ ( (not (= $E1 $Lgg)) (split-examples $R $Lgg $P $M1) (set-det))) +; + (= (split-examples (Cons $E1 $R) $Lgg (Cons $E1 $P) $M1) ( (split-examples $R $Lgg $P $M1) (set-det))) +; + (= (split-examples Nil $_ Nil Nil) (set-det)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: shares_var/2 +; ; -; * +; ; -; * syntax: shares_var(+T,+Ts) +; ; -; * +; ; -; * args: T: a term or a clause,Ts: a list of terms or clauses +; ; -; * +; ; -; * description: tests if T shares at least one variable +; ; -; * with the terms in t +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2078,71 +2229,73 @@ ( (sub-term $V $T) (var $V) (contains-var $V $Ts))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: body2list/2 +; ; -; * +; ; -; * syntax: body2list(?B,?BList) +; ; -; * +; ; -; * args: B: Body of a clause (L1,...,Ln) +; ; -; * BList: [L1:x,...,Ln:x] where x is in {r,n} +; ; -; * +; ; -; * description: transforms a clause body to a list of its literals +; ; -; * where each literal is augmented by :n (i.e. negative clause literal) +; ; -; * or :r (i.e. recursive goal in the clause body). +; ; -; * works in both directions +; ; -; * +; ; -; * example: (p(x,y),q(z,w)),[(p(x,y):r,q(z,w):r] +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2155,10 +2308,14 @@ (arg 1 $B $L1) (arg 2 $B $RestB) (body2list $RestB $RestL))) +; + (= (body2list $B (:: (with_self $B (n)))) (set-det)) +; + (= (body2list $B (Cons @@ -2168,63 +2325,67 @@ (arg 1 $B $L1) (arg 2 $B $RestB) (body2list $RestB $RestL))) +; + (= (body2list $B (:: (with_self $B (r)))) (set-det)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: insert_unique/3 +; ; -; * +; ; -; * syntax: insert_unique(+N,+L,-L1) +; ; -; * +; ; -; * args: N .. number, L,L1 sorted lists of numbers +; ; -; * +; ; -; * description: inserts N uniquely in the ascendingly sorted list L +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2233,6 +2394,8 @@ (Cons $I $R) (Cons $I $R)) (set-det)) +; + (= (insert-unique $I (Cons $J $R) @@ -2240,71 +2403,77 @@ ( (> $I $J) (set-det) (insert-unique $I $R $R1))) +; + (= (insert_unique $I $L (Cons $I $L)) True) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: insert_unique/4 +; ; -; * +; ; -; * syntax: insert_unique(+ID,+A,+L,-L1) +; ; -; * +; ; -; * args: ID,A .. numbers, L,L1 = [...,ID:List,...] +; ; -; * +; ; -; * description: inserts A in the sublist identified by ID in L +; ; -; * +; ; -; * example: insert_unique(2,5,[1:[5,6],2:[4],3:[9,8]], +; ; -; * [1:[5,6],2:[5,4],3:[9,8]]) +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (insert-unique $I $A Nil (:: (with_self $I (:: $A)))) (set-det)) +; + (= (insert-unique $I $A (Cons @@ -2313,66 +2482,70 @@ (with_self $I (Cons $A $A1)) $R)) (set-det)) +; + (= (insert-unique $I $A (Cons $J $R) (Cons $J $R1)) (insert-unique $I $A $R $R1)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: genterm_test/3 +; ; -; * +; ; -; * syntax: genterm_test(+X/T,+Subst) +; ; -; * +; ; -; * args: X/T element of a substitution, Subst substitution +; ; -; * +; ; -; * description: succeeds if Subst contains a tuple Y/T1 such that +; ; -; * T1 == T. In that case, X and Y are unified. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2382,164 +2555,176 @@ (Cons (/ $X $T2) $_)) ( (== $T1 $T2) (set-det))) +; + (= (genterm-test $S (Cons $_ $Rest)) (genterm-test $S $Rest)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: subset_chk/2 +; ; -; * +; ; -; * syntax: subset_chk(+L,+L1) +; ; -; * +; ; -; * args: L, L1 .. lists +; ; -; * +; ; -; * description: succeeds, if L is a subset of L1 (without unification) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; ; -; subset check uses library 'basics' +; (= (subset-chk Nil $_) (set-det)) +; + (= (subset-chk (Cons $Elem1 $Rest1) $List2) ( (identical-member $Elem1 $List2) (set-det) (subset-chk $Rest1 $List2))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: subterm_at_position/4 +; ; -; * +; ; -; * syntax: subterm_at_position(+Term,-Sub,+Pos,-Pos) +; ; -; * +; ; -; * args: Term, Sub: MeTTa terms +; ; -; * Pos: position of Sub within Term (a list of numbers) +; ; -; * +; ; -; * description: returns a subterm of Term and its position, on backtracking +; ; -; * further subterms +; ; -; * +; ; -; * example: ?- subterm_at_position(p(a,[a]),S,[],P). +; ; -; * S = p(a,[a]), P = []; +; ; -; * S = a P = [1]; +; ; -; * S = [a] P = [2]; +; ; -; * S = a P = [2,1]; +; ; -; * S = [] P = [2,2] +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (subterm-at-position $T $T $P $P1) (rev $P $P1)) +; + (= (subterm-at-position $T $S $P $P1) ( (nonvar $T) (functor $T $_ $N) (> $N 0) (subterm-at-position $N $T $S $P $P1))) +; + (= (subterm-at-position $N $T $S $P $P1) @@ -2547,134 +2732,144 @@ (arg $N $T $Tn) (subterm-at-position $Tn $S (Cons $N $P) $P1))) +; + (= (subterm-at-position $N $T $S $P $P1) ( (> $N 0) (is $N1 (- $N 1)) (subterm-at-position $N1 $T $S $P $P1))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: part_of_clause/2 +; ; -; * +; ; -; * syntax: part_of_clause(+Term,+Clause) +; ; -; * +; ; -; * args: Term: a MeTTa term, Clause: a MeTTa clause +; ; -; * +; ; -; * description: succeeds if Term is a literal within clause, a part +; ; -; * of the clause body or the clause itself +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (part-of-clause $S $B) (== $S $B)) +; + (= (part-of-clause $S (= $H $B)) ( (set-det) (det-if-then-else (or (== $S $H) (== $S $B)) True (part-of-clause $S $B)))) +; + (= (part-of-clause $S (, $H $B)) ( (set-det) (det-if-then-else (or (== $S $H) (== $S $B)) True (part-of-clause $S $B)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: several arithmetic predicates +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: arithmetic predicates used in heuristic measures +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2682,6 +2877,8 @@ (= (fak $X 1) ( (=:= $X 0) (set-det))) +; + (= (fak $N $NF) ( (is $N1 @@ -2689,11 +2886,15 @@ (fak $N1 $N1F) (is $NF (* $N1F $N)))) +; + (= (fak1 $N $N 1) (set-det)) +; + (= (fak1 $A $B $C) ( (is $A1 @@ -2701,6 +2902,8 @@ (fak1 $A1 $B $C1) (is $C (* $C1 $A1)))) +; + (= @@ -2711,6 +2914,8 @@ (fak $K $KF) (is $NUK (/ $NKF $KF)))) +; + (= @@ -2719,17 +2924,25 @@ (log 2 $LN2) (is $LX (/ $LNX $LN2)))) +; + (= (log2nueberk $_ 0.0 0.0) (set-det)) +; + (= (log2nueberk $N 1.0 $LN) ( (log2 $N $LN) (set-det))) +; + (= (log2nueberk $N $N 0.0) (set-det)) +; + (= (log2nueberk $N $K $L) ( (is $N1 @@ -2739,11 +2952,15 @@ (sum-of-logs 1.0 $K $L2) (is $L (- $L1 $L2)))) +; + (= (sum-of-logs $O $O $LO) ( (log2 $O $LO) (set-det))) +; + (= (sum-of-logs $U $O $L) ( (< $U $O) @@ -2754,8 +2971,12 @@ (log2 $U $LU) (is $L (+ $L1 $LU)))) +; + (= (sum-of-logs $U $O $_) ( (> $U $O) (set-det) (fail))) +; + diff --git a/miles/dmiles.metta b/miles/dmiles.metta index 1244ed4..7048979 100644 --- a/miles/dmiles.metta +++ b/miles/dmiles.metta @@ -1,8 +1,14 @@ !(use-module (library logicmoo-utils)) +; + !(multifile (/ file-search-path 2)) +; + !(dynamic (/ file-search-path 2)) +; + (= @@ -10,67 +16,86 @@ (det-if-then-else (exists-source $X) (with_self - (system) + (system *) (ensure-loaded $X)) (dmsg (ensure-loaded-if-exists $X)))) +; + (= (use-module-if-exists $X) (det-if-then-else (exists-source $X) (with_self - (system) + (system *) (use-module $X)) (dmsg (use-module-if-exists $X)))) +; + (= (use-module-if-exists $X $Y) (det-if-then-else (exists-source $X) (with_self - (system) + (system *) (use-module $X $Y)) (dmsg (use-module-if-exists $X $Y)))) +; - !((prolog-load-context directory $Dir) (add-atom &self (file_search_path home $Dir))) -; ;;;;set appropriately! + !((prolog-load-context directory $Dir) (add-symbol &self (file_search_path home $Dir))) +; (= (rev $A $B) (rev $A $B Nil)) +; + (= (rev Nil $B $B) (set-det)) +; + (= (rev (Cons $X $A) $B $C) (rev $A $B (Cons $X $C))) +; + (= (nonmember $Arg (Cons $Arg $_)) ( (set-det) (fail))) +; + (= (nonmember $Arg (Cons $_ $Tail)) ( (set-det) (nonmember $Arg $Tail))) +; + (= (nonmember $_ ()) True) +; + ; -; writes Question (using write/1) to the terminal, regardless of the current output stream, and reads an answer. The prompt is followed by ? , so you should not put a question mark in the question yourself. The answer is the first character typed in response; anything following on the same line will be thrown away. If the answer is y or Y, yesno/1 succeeds. If the answer is n or N, yesno/1 fails. Otherwise it repeats the question. The user has to explicitly type a y or n before it will stop. Because the rest of the line is thrown away, the user can type yes, Yes, You'd better not, and so forth with exactly the same effect as a plain y. If the user just presses , that is not taken as yes. +; (= (yesno $Question) (yesno $Question no)) +; + (= (yesno $Question $Default) ( (format '~N~w? (~w): ' @@ -81,20 +106,22 @@ (== $Default yes) (member $YN (:: 121 89))))) +; + ; -; is like yesno/1 except that +; ; -; Default may be an atom (the first character of whose name will be used), a string (whose first character will be used) or an ASCII code, and will be written in brackets before the question mark; and +; ; -; if the user just presses , Default will be used as the answer. +; ; -; For example, yesno('Do you want an extended trace', yes) +; ; -; prints Do you want an extended trace [yes]? _ +; (= @@ -111,46 +138,29 @@ (format "~NPlease enter between ~w and ~w characters.~n" (:: $S $E)) (fail))))) -; /* -; -; ask_chars(+Prompt, +MinLength, +MaxLength, -Answer) -; writes Prompt to the terminal, and reads a line of characters from it. This response must contain between MinLength and MaxLength characters inclusive, otherwise the question will be repeated until an answer of satisfactory length is obtained. Leading and/or trailing layout characters are retained in the result, and are counted when determining the length of the answer. The list of character codes read is unified with Answer. Note that a colon and a space (: ) are added to the Prompt, so don't add such punctuation yourself. The end-user can find out what sort of input is required by typing a line that starts with a question mark. Therefore it is not possible to read such a line as data. See prompted_line/2 in library(prompt). -; Examples: -; -; | ?- ask_chars('Label', 1, 8, Answer). -; Label: 213456789 -; Please enter between 1 and 8 characters. -; Do not add a full stop unless it is part of the answer. -; Label: four -; -; Answer = "four" ; -; | ?- ask_chars('Heading', 1, 30, Answer). -; Heading: ? -; Please enter between 1 and 30 characters. -; Do not add a full stop unless it is part of the answer. -; Heading: three leading spaces -; -; Answer = " three leading spaces" -; -; */ - (= (unify $X $Y) (unify-with-occurs-check $X $Y)) +; + !(use-module-if-exists (library ordsets)) +; + (= (union $X $Y) (ord-union $X $Y)) +; + ; -; subseq(X,Y,Z):- ord_union(X,Y). +; @@ -159,14 +169,20 @@ ( (var $V) (set-det) (fail))) +; + (= - ($list_skel ()) True) + (%list_skel ()) True) +; + (= ($list-skel (Cons $_ $L)) ($list-skel $L)) +; + ; -; subseq(Sequence1, SubSequence2, Complement):- +; (= @@ -174,29 +190,41 @@ ( ($list-skel $AB) (set-det) ($subseq $AB $A $B))) +; + (= (subseq $AB $A $B) ( ($list-skel $A) ($list-skel $B) (set-det) ($subseq $AB $A $B))) +; + (= (subseq $AB $A $B) (throw ('instantiation error' $AB $A))) +; + (= ($subseq () () ()) True) +; + (= ($subseq (Cons $X $AB) $A (Cons $X $B)) ($subseq $AB $A $B)) +; + (= ($subseq (Cons $X $AB) (Cons $X $A) $B) ($subseq $AB $A $B)) +; + (= @@ -204,9 +232,13 @@ ( ($list-skel $AB) (set-det) ($subseq $AB $A $_))) +; + (= (subseq0 $AB $A) (throw ('instantiation error' $AB $A))) +; + (= @@ -215,15 +247,21 @@ (set-det) ($subseq $AB $A $_) (\== $A $AB))) +; + (= (subseq1 $AB $A) (throw ('instantiation error' $AB $A))) +; + (= (string-append $A $B $C) (string-concat $A $B $C)) +; + (= @@ -231,12 +269,14 @@ ( (tell $Filename) (listing $List) (told))) +; + ; -; basics +; ; -; Succeeds when SubSequence and Complement are both subsequences of the list Sequence (the order of corresponding elements being preserved) and every element of Sequence which is not in SubSequence is in the Complement and vice versa. That is, +; @@ -246,10 +286,14 @@ (= (prompt $X) (format '~N~w ' - (:: $X))) + (:: $X))) +; + !(expects-dialect sicstus) +; + (= @@ -259,16 +303,22 @@ (forall (nth-clause do-full-kb1 $Index $_) (do-full-kb $_ $Index)))) +; + (= (do-full-kb $KB $Index) ( (nth-clause do-full-kb1 $Index $Ref) (clause do-full-kb1 $Goal $Ref) (do-full-kb $KB $Index $Goal))) +; + (= (do-full-kb $KB $Index $Goal) (once (, (ignore (, (nonvar $KB) (clear-kb) (init-kb $KB))) (format ~N=================== Nil) (format '~N======= Nth: ~w ~p =======' (:: $Index $Goal)) (format ~N===================~n Nil) (show-kb) (catch (do-full-call-each $Goal) $E (, (dumpST) (throw $E))) (show-kb) (format '~N==== DONE: ~w ========~n~n' (:: $Index))))) +; + (= @@ -276,22 +326,30 @@ ( (set-det) (do-full-call-each $G1) (do-full-call-each $G2))) +; + (= (do-full-call-each (det-if-then $G1 $G2)) ( (not (not (, (wdmsg (do-call (det-if-then $G1 (= $G2 $Vars)))) (my-do-call $G1) (set-det) (term-variables $G2 $Vars) (my-do-call $G2) (set-det) (wdmsg (did-call (+ $Vars)))))) (set-det))) +; + (= (do-full-call-each $G1) ( (= $G2 True) (not (not (, (wdmsg (do-call (det-if-then $G1 (= $G2 $Vars)))) (my-do-call $G1) (set-det) (term-variables $G2 $Vars) (my-do-call $G2) (set-det) (wdmsg (did-call (+ $Vars)))))) (set-det))) +; + ; -; my_do_call(G):- !, must_or_rtrace(G). +; (= (my-do-call $G) (notrace (ignore (catch $G $_ True)))) +; + (= @@ -308,22 +366,9 @@ (fp $A) (refinement $ID $_) (flatten-kb))) -; ;; Antwort: no - -; ;; gibt alle unabgedeckten Bsple zur"uck - -; ;; geht jetzt gut - -; ;; gibt inkorrekte Klausel(n) + ihre Instantiierung(en) zur"uck - -; ;; in der Form [ID:[Instanz]] - -; ;; wobei ID der der inkorrekten Klausel ist -> gibt - -; ;; Spezialisierungen dieser Klausel (in einer Liste) - +; ; -; ; kb funktionsfrei machen +; (= @@ -344,8 +389,7 @@ (show-clause $J) (apply-g2 (:: 4 5 10) $A $BB)))))) -; ;; stellt Fragen - +; (= @@ -364,6 +408,8 @@ (show-kb) (lgg 7 9 $J)) (show-clause $J))) +; + (= (do-full-kb1) @@ -375,6 +421,8 @@ (reduce-complete $CL $CL1) (store-clause $_ $CL1 nrlgg $I) (show-clause $I)))) +; + (= (do-full-kb1) @@ -385,12 +433,16 @@ (show-clause $J) (gti 8 9 $J)) (show-clause $J)))) +; + (= (do-full-kb1) (det-if-then (rlgg 5 6 $J) (show-clause $J))) +; + (= @@ -444,32 +496,31 @@ (show-clauses (:: 14 15 $A $B $C)) (intra-construct2 16 17 $A $B $C)) (show-clauses (:: 16 17 $A $B $C))))))))))))))) -; ; erlaubt backtracking! - +; ; -; ; Sei ID1 der der Klausel: +; ; -; ; app(A,B,C) :- cons_p(D,E,A),x_p(D),cons_p(F,G,E),a_p(F),nil_p(G), +; ; -; ; cons_p(H,I,B),b_p(H),cons_p(J,G,I),c_p(J),cons_p(D,K,C),cons_p(F,B,K), +; ; -; ; ID2 der der Klausel: +; ; -; ; app(A,B,C) :- cons_p(D,E,A),a_p(D),nil_p(E), +; ; -; ; cons_p(F,G,B),b_p(F),cons_p(H,E,G),c_p(H),cons_p(D,B,C), +; ; -; Dann teste: +; (= (do-full-kb1) @@ -487,6 +538,8 @@ (show-clause $J2) (unflatten-kb) (set-det)))))) +; + diff --git a/miles/environment.metta b/miles/environment.metta index 2ec3d89..c744e71 100644 --- a/miles/environment.metta +++ b/miles/environment.metta @@ -1,5 +1,5 @@ ; -; MODULE environment EXPORTS +; @@ -13,10 +13,12 @@ (/ ask-for-ex 1) (/ confirm 2) (/ get-ci 2))) +; + ; -; IMPORTS +; !(use-module (home kb) @@ -29,216 +31,232 @@ (/ store-ex 3) (/ rename 3) (/ delete-all 1))) +; + !(use-module (home show-utils) (:: (/ show-clauses 1) (/ show-names 0))) +; + !(use-module-if-exists (library prompt) (:: (/ prompt 1))) +; + !(use-module-if-exists (library ask) (:: (/ yesno 1) (/ yesno 2) (/ ask-chars 4))) +; + !(use-module-if-exists (library sets) (:: (/ union 3))) +; + !(use-module-if-exists (library subsumes) (:: (/ subsumes-chk 2))) +; + ; -; METAPREDICATES +; ; -; none +; ; -; *********************************************************************** +; ; -; * +; ; -; * module: envirnonment.pl +; ; -; * +; ; -; * author: B.Jung, M.Mueller, I.Stahl, B.Tausend date:12/92 +; ; -; * +; ; -; * changed: +; ; -; * +; ; -; * +; ; -; * description: procedures for oracle interaction +; ; -; * 1. membership queries - oracle/1 +; ; -; * 2. existential queries - oracle/2 +; ; -; * 3. subset queries - oracle/2 +; ; -; * 4. name queries - oracle/2 +; ; -; * 5. general questions with default answers - oracle/3 +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; * +; ; -; *********************************************************************** +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: satisfiable/1 +; ; -; * +; ; -; * syntax: satisfiable(+SG_list) +; ; -; * +; ; -; * args: SG_list ... list of subgoals [...,[ID,Subgoal,Proof],...] +; ; -; * +; ; -; * description: each Subgoal in SG_list is tested on satisfiability. +; ; -; * The oracle is used if the satisfiability of Subgoal can not be +; ; -; * decided on the available knowledge +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (satisfiable ()) True) +; + (= (satisfiable (Cons (:: $_ $H $_) $R)) ( (ask-for $H) (satisfiable $R))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: ask_for/1 +; ; -; * +; ; -; * syntax: ask_for(+Goal) +; ; -; * +; ; -; * args: Goal is a ground atom +; ; -; * +; ; -; * description: succeds if Goal is valid in the kb, or declared to be +; ; -; * valid by the oracle +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -260,62 +278,64 @@ (, (store-ex $Lit - $_) (fail))) fail))) $Lit)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: ask_for_ex/1 +; ; -; * +; ; -; * syntax: ask_for(+Goal) +; ; -; * +; ; -; * args: Goal is an atom +; ; -; * +; ; -; * description: succeds if Goal is valid in the kb, or declared to be +; ; -; * valid by the oracle +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -332,58 +352,60 @@ (det-if-then-else (oracle $Lit $Lit) (store-ex $Lit + $_) fail))) $Lit)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: term_help/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: prompts a help line +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -391,64 +413,66 @@ (= (term-help) (prompt 'Please enter a proper PROLOG-term followed by a full-stop and RETURN')) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: oracle/1 +; ; -; * +; ; -; * syntax: oracle( + Literal) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: membership queries: +; ; -; * "Is the following literal always true?" -> succeeds iff oracle answers yes +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; ; -; ;;oracle(mappend(A,B,C)):- !,append(A,B,C). +; (= @@ -461,67 +485,69 @@ (nl) (set-det) (yesno '> (y/n) '))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: oracle/2 +; ; -; * +; ; -; * syntax: oracle( + List_of_Clause_Ids, - Example_Id) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: subset queries +; ; -; * "Are the following clauses always true?" +; ; -; * If not, the user might supply a counter example. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: fails only if the oracle answers "no" AND does not +; ; -; * supply a counter example +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= @@ -548,73 +574,75 @@ (, (store-ex $Ex - $NegexId) (set-det)))))))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: oracle/2 +; ; -; * +; ; -; * syntax: oracle( + PnameAtom, - NewNameAtom) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * +; ; -; * description: name queries +; ; -; * "How would you like to call predicate pXYZ", where pXYZ is a new predicate. +; ; -; * The oracle may use every atom as answer. However, the atom "list" +; ; -; * causes the system to show every known predicate symbol within the knowledge base +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: the predicate returns the new predicate name, but does not +; ; -; * replace the old name by the new one within the kb. +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= @@ -638,67 +666,69 @@ (, (= $Newname $A2) (set-det))))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: oracle/2 +; ; -; * +; ; -; * syntax: oracle(+Lit, -InstLit) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: existential queries +; ; -; * "Is there a correct instance of the following literal?" +; ; -; * If yes, the oracle supplies an instance -> InstLit +; ; -; * Else, the predicate fails +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= @@ -725,61 +755,63 @@ (, (prompt 'This is no instantiation of the literal!') (fail)))))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: oracle/3 +; ; -; * +; ; -; * syntax: oracle( + QuestionAtom, ? DefaultAtom, - AnswerAtom) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: general questions with default answers +; ; -; * If no default is necessary, use '_' as second argument +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= @@ -806,67 +838,69 @@ (nonvar $Default)) (= $Answer $Default) (atom-chars $Answer $Alist)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: confirm/2 +; ; -; * +; ; -; * syntax: confirm(+Clause_IDs,+Oldterm) +; ; -; * +; ; -; * args: Clause_IDs .. list of clauseIDs, +; ; -; * Oldterm.. term of the predicate to be replaced +; ; -; * +; ; -; * description: confirm new clauses and rename the new predicate (using the oracle) +; ; -; * if oracle refuses the new clauses, delete 'em. +; ; -; * if they are accepted, delete the old ones (see g2_op). +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -878,6 +912,8 @@ (oracle $Oldname $Newname) (rename $Clause_ids $Oldname $Newname) (set-det))) +; + (= (confirm $Clause_ids $_) @@ -885,62 +921,64 @@ (nl) (write 'New clauses deleted.') (fail))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: get_ci/2 +; ; -; * +; ; -; * syntax: get_ci(+L,-L) +; ; -; * +; ; -; * args: L ... list of clauseIDs +; ; -; * +; ; -; * description: reads the IDs of the Ci used for the g2-operator one +; ; -; * by one +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; @@ -957,7 +995,11 @@ (= $Sofarnew $Sofar)) (set-det) (get-ci $Sofarnew $CC))) +; + (= (get-ci $CC $CC) - (set-det)) + (set-det)) +; + diff --git a/miles/evaluation.metta b/miles/evaluation.metta index d4c2cca..b339e34 100644 --- a/miles/evaluation.metta +++ b/miles/evaluation.metta @@ -1,5 +1,5 @@ ; -; MODULE evaluation EXPORTS +; @@ -26,20 +26,11 @@ (/ code-length 2) (/ encoding-length-examples 1) (/ encoding-length-clause 2))) -; ; Compute complete evaluation for all examples - -; ; AND clauses in kb - -; ; Compute evaluation for all pos examples in kb - -; ; check completeness, all pos examples covered? - -; ; check correctness, no neg examples covered? - +; ; -; IMPORTS +; !(use-module (home div-utils) @@ -61,15 +52,21 @@ (/ log2 2) (/ log2nueberk 3) (/ sum-of-logs 3))) +; + !(use-module (home environment) (:: (/ ask-for 1))) +; + !(use-module (home var-utils) (:: (/ term-size 2) (/ vars 2) (/ skolemize 3))) +; + !(use-module (home kb) (:: @@ -82,6 +79,8 @@ (/ delete-example 1) (/ delete-clause 1) (/ get-clause 5))) +; + !(use-module (home interpreter) (:: @@ -91,141 +90,153 @@ (/ solve 3) (/ ip-part1 2) (/ ip-part2 3))) +; + !(use-module-if-exists (library basics) (:: (/ member 2))) +; + !(use-module-if-exists (library subsumes) (:: (/ subsumes-chk 2) (/ variant 2))) +; + !(use-module-if-exists (library occurs) (:: (/ sub-term 2))) +; + !(use-module-if-exists (library math) (:: (/ pow 3))) +; + ; -; METAPREDICATES +; ; -; none +; !(dynamic (/ evaluated 1)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * module: evaluation.pl +; ; -; * +; ; -; * author: B.Jung, M.Mueller, I.Stahl, B.Tausend date:12/92 +; ; -; * +; ; -; * changed: +; ; -; * +; ; -; * description: evaluation of (parts of) the knowledge base +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: ip/1 +; ; -; * +; ; -; * syntax: ip(-UA_List) +; ; -; * +; ; -; * args: -UA_List ... list of ground atoms +; ; -; * +; ; -; * description: Shapiro's algorithm for diagnosing finite failure +; ; -; * ip in our framework. Returns a set of ground atoms that +; ; -; * has to be covered to make all uncovered positive +; ; -; * examples succeed. +; ; -; * Allows backtracking on alternative sets of ground atoms +; ; -; * that make all examples succeed. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -242,81 +253,87 @@ (set-det) (ip-list $Elist Nil $UA_List1) (make-unique $UA_List1 $UA_List))) +; + (= (ip_list () $L $L) True) +; + (= (ip-list (Cons $E $R) $L $L2) ( (ip0 $E $UAs) (append $L $UAs $L1) (ip-list $R $L1 $L2))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: +; ; -; * +; ; -; * syntax: ip(+UA,-UAs) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: UA is an uncovered atom, i.e. both prooftrees(I,fail,Trees) +; ; -; * and ex(I,UA,+) are in the knowledge base. +; ; -; * UAs is a list [A1,...,An] such that a proof of UA would +; ; -; * succeed if A1 through An were covered by the knowledge base. +; ; -; * Cave!: Extensive oracle interaction +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -330,97 +347,99 @@ (set-det) (ip-part2 $Proofs $Goal $UAs0) (make-unique $UAs0 $UAs))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: fp/1 +; ; -; * +; ; -; * syntax: fp(-OR) +; ; -; * +; ; -; * args: OR: +; ; -; * +; ; -; * description: a kind of shapiro's contradiction backtracing that +; ; -; * aims to detect possibly overgeneral clauses. +; ; -; * As it does not use an oracle, all possibly overgeneral +; ; -; * clauses are considered and a minimal combination +; ; -; * such that all negative examples become uncovered is +; ; -; * returned. +; ; -; * Allows backtracking to an alternative set of possibly +; ; -; * overgeneral clauses +; ; -; * OR is a list [I:E,...], where I is the index of a possibly +; ; -; * overgeneral clause and E is the set of wrong (head-)instantiations of +; ; -; * clause I that should be excluded by specializing I. +; ; -; * OR is a minimal selection of possibly overgeneral clauses such +; ; -; * that by specialising them all negative examples become uncovered. +; ; -; * On backtracking, the second selection is returned, and so on. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -442,170 +461,182 @@ (or-subsets $Indices $TList $OR_List) (set-det) (best $OR_List $OR))) +; + (= (fp ()) True) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: fp/3 +; ; -; * +; ; -; * syntax: fp(+Prooftree,+L,-L) +; ; -; * +; ; -; * args: Prooftree is a prooftree for a succeeding negative example +; ; -; * L = [...,ID:[G1,..,Gn],...] where ID is a clause index and +; ; -; * G1,..,Gn are the head instantiations the clause has been applied with +; ; -; * during the proof Prooftree. +; ; -; * +; ; -; * description: collects clauses and goals that have been used during +; ; -; * a successfull proof of a negative example +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (fp (:: sys $_ $_) $L $L) (set-det)) +; + (= (fp (:: $I $A $SG) $L $L2) ( (fp-list $SG $L $L1) (insert-unique $I $A $L1 $L2))) +; + (= (fp_list () $L $L) True) +; + (= (fp-list (Cons $G $R) $L $L2) ( (fp-list $R $L $L1) (fp $G $L1 $L2))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: fp_hyp/1 +; ; -; * +; ; -; * syntax: fp_hyp(-OR) +; ; -; * +; ; -; * args: OR: +; ; -; * +; ; -; * description: as fp/1, but considers only clauses with label 'hypo' as +; ; -; * possibly overgeneral +; ; -; * Allows backtracking to an alternative set of possibly +; ; -; * overgeneral clauses +; ; -; * OR is a list [I:E,...], where I is the index of a possibly +; ; -; * overgeneral clause and E is the set of wrong (head-)instantiations of +; ; -; * clause I that should be excluded by specializing I. +; ; -; * OR is a minimal selection of possibly overgeneral clauses such +; ; -; * that by specialising them all negative examples become uncovered. +; ; -; * On backtracking, the second selection is returned, and so on. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -627,170 +658,182 @@ (or-subsets $Indices $TList $OR_List) (set-det) (best $OR_List $OR))) +; + (= (fp_hyp ()) True) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: fp_hyp/3 +; ; -; * +; ; -; * syntax: fp_hyp(+Prooftree,+L,-L) +; ; -; * +; ; -; * args: Prooftree is a prooftree for a succeeding negative example +; ; -; * L = [...,ID:[G1,..,Gn],...] where ID is a clause index of a clause with +; ; -; * label 'hypo', and +; ; -; * G1,..,Gn are the head instantiations the clause has been applied with +; ; -; * during the proof Prooftree. +; ; -; * +; ; -; * description: collects clauses and goals that have been used during +; ; -; * a successfull proof of a negative example +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (fp-hyp (:: sys $_ $_) $L $L) (set-det)) +; + (= (fp-hyp (:: $I $A $SG) $L $L2) ( (fp-hyp-list $SG $L $L1) (det-if-then-else (get-clause $I $_ $_ $_ hypo) (insert-unique $I $A $L1 $L2) (= $L2 $L1)))) +; + (= (fp_hyp_list () $L $L) True) +; + (= (fp-hyp-list (Cons $G $R) $L $L2) ( (fp-hyp-list $R $L $L1) (fp-hyp $G $L1 $L2))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: fpo/1 +; ; -; * +; ; -; * syntax: fpo(-OR) +; ; -; * +; ; -; * args: OR: +; ; -; * +; ; -; * description: as fp/1, but uses oracle +; ; -; * Allows backtracking to an alternative set of possibly +; ; -; * overgeneral clauses +; ; -; * OR is a list [I:E,...], where I is the index of a possibly +; ; -; * overgeneral clause and E is the set of wrong (head-)instantiations of +; ; -; * clause I that should be excluded by specializing I. +; ; -; * OR is a minimal selection of possibly overgeneral clauses such +; ; -; * that by specialising them all negative examples become uncovered. +; ; -; * On backtracking, the second selection is returned, and so on. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -812,84 +855,90 @@ (or-subsets $Indices $TList $OR_List) (set-det) (best $OR_List $OR))) +; + (= (fpo ()) True) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: fpo/4 +; ; -; * +; ; -; * syntax: fpo(+Prooftree,+L,-L,-M) +; ; -; * +; ; -; * args: Prooftree is a prooftree for a succeeding negative example +; ; -; * L = [...,ID:[G1,..,Gn],...] where ID is a clause index and +; ; -; * G1,..,Gn are the head instantiations the clause has been applied with +; ; -; * during the proof Prooftree. +; ; -; * M indicates whether Prooftree is successful in the oracle-simulation (ok) +; ; -; * or not (not_ok) +; ; -; * +; ; -; * description: collects wrong clauses and goals that have been used during +; ; -; * a successfull proof of a negative example (uses oracle) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (fpo (:: sys $_ $_) $L $L ok) (set-det)) +; + (= (fpo (:: $I $A $SG) $L $L1 $X) @@ -899,167 +948,181 @@ (, (insert-unique $I $A $L $L1) (= $X not-ok)))) +; + (= (fpo_list () $L $L ok) True) +; + (= (fpo-list (Cons $G $R) $L $L2 $X) ( (fpo $G $L $L1 $Xg) (det-if-then-else (= $Xg ok) (fpo-list $R $L1 $L2 $X) (= $X $Xg)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: collect_indices/3 +; ; -; * +; ; -; * syntax: collect_indices(+L,+Accu,-Accu) +; ; -; * +; ; -; * args: L = [[I1:[G11,..,G1n],...,Im:[Gm1,...,Gmn]],...] +; ; -; * Accu = [I1,...,Ik] +; ; -; * +; ; -; * description: given the list of lists produced by fp/3, all indices of +; ; -; * clauses that participated in successful proofs of negative examples +; ; -; * are collected +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (collect_indices () $L $L) True) +; + (= (collect-indices (Cons $X $R) $L $L2) ( (c-indices $X $L $L1) (collect-indices $R $L1 $L2))) +; + (= (c_indices () $L $L) True) +; + (= (c-indices (Cons (with_self $I $_) $R) $L $L2) ( (c-indices $R $L $L1) (det-if-then-else (member $I $L1) (= $L2 $L1) (= $L2 (Cons $I $L1))))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: or_subsets/3 +; ; -; * +; ; -; * syntax: or_subsets(+Indices,+Tlist,-OR_List) +; ; -; * +; ; -; * args: Indices ... list of indices of clauses that participated in successful +; ; -; * proofs of negative examples +; ; -; * Tlist = [[I:[G1,..,Gn],..],..] list of lists produced by fp/3 +; ; -; * OR_List = list of lists [I:E,..] where I is the index of a possibly +; ; -; * overgeneral clause and E is the set of wrong (head-)instantiations of +; ; -; * clause I that should be excluded by specializing I. OR_List is sorted +; ; -; * ascendingly according to the length of the sublists +; ; -; * +; ; -; * description: selects all possible combinations of possibly overgeneral clauses +; ; -; * such that by specialising them all negative examples become uncovered. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1068,172 +1131,172 @@ ( (initialize-or-subsets $IX $IX $TL $TL1) (or-all-subsets $TL1 Nil $TL2) (sort-by-length $TL2 Nil $ORL))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: initialize_or_subsets/4 +; ; -; * +; ; -; * syntax: initialize_or_subsets(+IX,+IX,+TL,-TL1) +; ; -; * +; ; -; * args: IX list of clauseIDs +; ; -; * TL = [[I:CoveredI,J:CoveredJ,...],...] resulting from fp/3. +; ; -; * each sublist in TL corresponds to a successful proof of a negative +; ; -; * example +; ; -; * +; ; -; * description: TL1 contains for each I in IX and entry [I:A]:IX1:TLI, +; ; -; * where IX1 = IX - {I} and TLI results from TL by deleting every +; ; -; * sublist [J:CJ,..,I:CI,...] that contains I:CI, and accumulating +; ; -; * the head instances of I in A. +; ; -; * The set TLI contains all proofs of negative examples that are +; ; -; * still possible if clause I is excluded (e.g. specialised). +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (initialize_or_subsets () $_ $_ ()) True) - (= - (initialize-or-subsets - (Cons $I $R) $IX $TL - (Cons - (with_self - (:: (with_self $I $A)) - (with_self $IX1 $TL1)) $R1)) - ( (initialize-or-subsets $R $IX $TL $R1) - (remove $I $IX $IX1) - (remove-conjuncts $I $TL $TL1 Nil $A))) +; + +; (error +; (syntax_error operator_clash) +; (file miles/evaluation.pl 478 41 15079)) + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: remove_conjuncts/5 +; ; -; * +; ; -; * syntax: remove_conjuncts(+I,+TL,-TLI,+A,-A) +; ; -; * +; ; -; * args: I .. clause Index, TL = [[I:CI,J:CJ,...],...], +; ; -; * A = [G1,..,Gn] head instances of I +; ; -; * +; ; -; * description: removes from TL every sublist containing I:CI, and accumulates +; ; -; * CI in A. Each sublist in TL corresponds to a successful proof of +; ; -; * a negative example. If clause I is assumed to be overgeneral and +; ; -; * therefore excluded, the proof fails and the remaining clauses that +; ; -; * have been used need not be specialised. Therefore, the sublist is +; ; -; * removed from TL. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (remove_conjuncts $_ () () $A $A) True) +; + (= (remove-conjuncts $I (Cons $X $R) $R1 $A $A2) @@ -1243,268 +1306,270 @@ (append $E $A $A0) (identical-make-unique $A0 $A1) (remove-conjuncts $I $R $R1 $A1 $A2))) +; + (= (remove-conjuncts $I (Cons $X $R) (Cons $X $R1) $A $A1) (remove-conjuncts $I $R $R1 $A $A1)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: or_all_subsets/3 +; ; -; * +; ; -; * syntax: or_all_subsets(+TL1,+Accu,-Accu) +; ; -; * +; ; -; * args: TL1 = [IXS:IXR:TLI,...] where IXS = [I:CI,...], IXR the indices not +; ; -; * occurring in IXS, and TLI the remaining proofs of negative examples +; ; -; * Accu = [IXS,...] +; ; -; * +; ; -; * description: tests every combination of clause indices whether all proofs +; ; -; * of negative examples are excluded when the clauses are assumed to be +; ; -; * overgeneral. A combination IXS is successful, if all proofs are excluded, +; ; -; * i.e. TLI = []. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; +; (error +; (syntax_error operator_clash) +; (file miles/evaluation.pl 541 20 17217)) + +; (error +; (syntax_error operator_clash) +; (file miles/evaluation.pl 543 20 17286)) + - (= - (or-all-subsets - (Cons - (with_self $IXS - (with_self $_ Nil)) $R) $L - (Cons $IXS $L1)) - (or-all-subsets $R $L $L1)) - (= - (or-all-subsets - (Cons - (with_self $IXS - (with_self $RI $TL)) $R) $L $L1) - ( (or-asubsets $RI $RI $IXS $TL $R1) - (append $R $R1 $R2) - (or-all-subsets $R2 $L $L1))) (= (or_all_subsets () $L $L) True) +; + (= (or_asubsets () $_ $_ $_ ()) True) - (= - (or-asubsets - (Cons $I $R) $RI $IXS $TL - (Cons - (with_self - (Cons - (with_self $I $A) $IXS) - (with_self $RI1 $TL1)) $R1)) - ( (remove $I $RI $RI1) - (remove-conjuncts $I $TL $TL1 Nil $A) - (or-asubsets $R $RI $IXS $TL $R1))) +; + +; (error +; (syntax_error operator_clash) +; (file miles/evaluation.pl 550 39 17474)) + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: eval_pos_examples/1 +; ; -; * +; ; -; * syntax: eval_pos_examples ( - List_of_Exs ) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: Evaluate (= try to prove) all positive examples, return a list of the +; ; -; * ones which *cannot* be proved (empty list if successful). +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: Output-argument looks like [exID1:Fact1, exID2:Fact2, ...]. +; ; -; * !!! Procedure does not compute evaluation for clauses!! +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (eval-pos-examples $Exlist) - ( (remove-all-atoms &self - (prooftrees $_ $_ $_)) (findall (with_self $I $Fact) (, (ex $I $Fact +) (solve-once $Fact fail $_)) $Exlist))) + ( (remove-all-symbols &self + (prooftrees $_ $_ $_)) (findall (with_self $I $Fact) (, (ex $I $Fact +) (solve-once $Fact fail $_)) $Exlist))) +; + ; -; ****************************************************************************** +; ; -; * +; ; -; * predicate: eval_examples/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: One should use this to compute the evaluation for kb clauses! +; ; -; * - asserts for each example ID prooftrees(ID,Mark,Proofs), where +; ; -; * Mark in {success,fail} and Proofs are the successful/failing +; ; -; * proofs accordingly +; ; -; * - determines the evaluation of each rule in the kb according to +; ; -; * the current examples +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ****************************************************************************** +; (= (eval-examples) ( (evaluated yes) (set-det))) +; + (= (eval-examples) - ( (remove-all-atoms &self + ( (remove-all-symbols &self (prooftrees $_ $_ $_)) (eval-examples1) (set-det) (change-evaluated yes))) +; + (= (eval-examples1) ( (ex $I $Fact $_) (solve $Fact $M $Proofs) - (add-atom &self + (add-symbol &self (prooftrees $I $M $Proofs)) (fail))) +; + (= (eval-examples1) ( (bagof @@ -1518,76 +1583,81 @@ (compute-evaluation $Klist $Plist $Klist1) (assertallz $Klist1) (set-det))) -; ; don't use bagof here! - +; - (= eval_examples1 True) ; -; in case there are no examples + (= eval_examples1 True) +; + ; +; (= (clear-evaluation) - ( (remove-all-atoms &self + ( (remove-all-symbols &self (prooftrees $_ $_ $_)) (change-evaluated no))) +; + (= (change-evaluated $X) - ( (remove-all-atoms &self - (evaluated $_)) (add-atom &self (evaluated $X)))) + ( (remove-all-symbols &self + (evaluated $_)) (add-symbol &self (evaluated $X)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate:correct_chk/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: fails when first *negative* example covered +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: Does not compute evaluation for clauses!! +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1603,63 +1673,65 @@ (, (ex $ID $Fact -) (prooftrees $ID success $_)) fail True))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: complete_chk/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: fails if not all *positive* examples covered +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: Does not compute evaluation for clauses!! +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; * origin: kb.pl (Irene/Markus) +; ; -; * +; ; -; *********************************************************************** +; @@ -1675,115 +1747,119 @@ (, (ex $ID $Fact +) (prooftrees $ID fail $_)) fail True))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate:compute_evaluation/3 +; ; -; * +; ; -; * syntax: compute_evaluation(+Klist,+Plist,-Klist) +; ; -; * +; ; -; * args: Klist ... list of kb-entries [known(I,H,B,Clist,Label,E),...] +; ; -; * where E is the evaluation of clause I +; ; -; * Plist ... list of all successfule Proofs using Klist +; ; -; * = [I:Proofs,...] where prooftrees(I,success,Proofs) in kb +; ; -; * +; ; -; * description: computes for each kb-entry in Klist the evaluation +; ; -; * E = evaluation(RA,NPos,Pos,NNeg,Neg,UNPos,UPos,UNNeg,UNeg), where +; ; -; * RA ... #applications of the clause +; ; -; * NPos ... #definitively positive examples covered by the clause +; ; -; * Pos ... list of definitively positive examples covered by the clause +; ; -; * NNeg ... #definitively negative examples covered by the clause +; ; -; * Neg ... list of definitively negative examples covered by the clause +; ; -; * UNPos ... #probably positive examples covered by the clause +; ; -; * i.e. instantiations of the clause used in successful proofs of positive +; ; -; * examples +; ; -; * UPos ... list of probably positive examples covered by the clause +; ; -; * UNNeg ... #probably negative examples covered by the clause +; ; -; * i.e. instantiations of the clause used in successful proofs of negative +; ; -; * examples +; ; -; * UNeg ... list of probably negative examples covered by the clause +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (compute_evaluation () $_ ()) True) +; + (= (compute-evaluation (Cons @@ -1792,19 +1868,27 @@ (known $I $H $B $Clist $O (evaluation $RA $NPos $Pos $NNeg $Neg $UNPos $UPos $UNNeg $UNeg)) $R1)) ( (compute-evaluation $R $Plist $R1) (compute-eval $Plist $I $RA $NPos $Pos $NNeg $Neg $UNPos $UPos $UNNeg $UNeg))) +; + (= (compute_eval () $_ 0 0 () 0 () 0 () 0 ()) True) +; + (= (compute-eval (Cons (with_self $I $Proofs) $R) $J $RA $NPos $Pos $NNeg $Neg $UNPos $UPos $UNNeg $UNeg) ( (compute-eval $R $J $RA0 $NPos0 $Pos0 $NNeg0 $Neg0 $UNPos0 $UPos0 $UNNeg0 $UNeg0) (det-if-then-else (ex $I $_ -) (, (compute-eval $Proofs t $I $J $RA0 $RA $NNeg0 $NNeg $Neg0 $Neg $UNNeg0 $UNNeg $UNeg0 $UNeg) (= $NPos $NPos0) (= $Pos $Pos0) (= $UNPos $UNPos0) (= $UPos $UPos0)) (, (compute-eval $Proofs t $I $J $RA0 $RA $NPos0 $NPos $Pos0 $Pos $UNPos0 $UNPos $UPos0 $UPos) (= $NNeg $NNeg0) (= $Neg $Neg0) (= $UNNeg $UNNeg0) (= $UNeg $UNeg0))))) +; + (= (compute_eval () $_ $_ $_ $RA $RA $N $N $L $L $UN $UN $UL $UL) True) +; + (= (compute-eval (Cons @@ -1856,58 +1940,60 @@ (= $N3 $N2) (= $UN3 $UN2) (= $UL3 $UL2))))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: covered_pos_examples/1 +; ; -; * +; ; -; * syntax: covered_examples(-CE) +; ; -; * +; ; -; * args: CE ... list of IDs of covered positive examples +; ; -; * +; ; -; * description: returns IDs of all covered positive examples +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1920,58 +2006,60 @@ (get-example $ID $_ +) (prooftrees $ID success $_)) $Bag) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: covered_neg_examples/1 +; ; -; * +; ; -; * syntax: covered_neg_examples(-CE) +; ; -; * +; ; -; * args: CE ... list of IDs of covered negative examples +; ; -; * +; ; -; * description: returns IDs of all covered negative examples +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1984,59 +2072,61 @@ (get-example $ID $_ -) (prooftrees $ID success $_)) $Bag) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: all_covered_examples/1 +; ; -; * +; ; -; * syntax: all_covered_examples(-CE) +; ; -; * +; ; -; * args: CE ... list of IDs of covered negative examples +; ; -; * +; ; -; * description: returns IDs of all covered examples +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2049,68 +2139,70 @@ (get-example $ID $_ $_) (prooftrees $ID success $_)) $Bag) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: complexity/2 +; ; -; * +; ; -; * syntax: complexity(+ClauseID,-Size) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: for kb references +; ; -; * complexity/2 calculates the size of a clause, +; ; -; * defined to be the number of constant and function +; ; -; * symbol occurences in the literals of the clause. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2120,59 +2212,61 @@ (get-clause $I $_ $_ $Clause $_) (compute-complexity $Clause $C) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: complexity/2 +; ; -; * +; ; -; * syntax: complexity(+CL,-Size) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: for clauses in list representation +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= @@ -2183,58 +2277,60 @@ (p)) $_)) (compute-complexity $Clause $C) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: complexity/2 +; ; -; * +; ; -; * syntax: complexity(List_of_ClauseIDs,-Size) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: for a list of kb references +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= @@ -2249,116 +2345,120 @@ (compute-complexity $Clause $Com)) $Bag) (sum $Bag $C) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: complexity/2 +; ; -; * +; ; -; * syntax: complexity(+Term,-Size) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: for arbitrary MeTTa terms ( but not integers) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (complexity $Term $Complexity) ( (term-size $Term $Complexity) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: complexity/2 +; ; -; * +; ; -; * syntax: complexity(+usr,-Size) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: for all clauses with label usr +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= @@ -2369,58 +2469,60 @@ (compute-complexity $Clause $I)) $Bag) (sum $Bag $C) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: complexity/2 +; ; -; * +; ; -; * syntax: complexity(+examples,-Size) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: for all examples +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= @@ -2431,64 +2533,68 @@ (compute-complexity $Clause $I)) $Bag) (sum $Bag $C) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: compute_complexity/2 +; ; -; * +; ; -; * syntax: compute_complexity(+CL,-Size) +; ; -; * +; ; -; * args: CL ... clause in list represenation +; ; -; * +; ; -; * description: complexity for a clause in list representation +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (compute_complexity () 0) True) +; + (= (compute-complexity (Cons @@ -2497,118 +2603,120 @@ (compute-complexity $More $C2) (is $C (+ $C1 $C2)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: ivonTunterE/1 +; ; -; * +; ; -; * syntax: ivonTunterE(-ITE) +; ; -; * +; ; -; * args: ITE... information content of T, given E +; ; -; * (only for funtion-free T and E!!) +; ; -; * +; ; -; * description: Given evidence E for T. Then if T|=E, then +; ; -; * I(T|E) = I(T) + I(E|T). If T = B & H, then T compresses +; ; -; * the examples E if I(T|E) =< I(B & E) +; ; -; * Precondition: B, T, E function-free! +; ; -; * +; ; -; * How to compute I(T) and I(E|T) (for function-free T,E): +; ; -; * - I(E|T) = log2( (|M+(T)| |E+|) ) + log2( (|M-(T)| |E-(T)|) ) +; ; -; * - P(T) .. #Pred. Symbols in T +; ; -; * C(T) .. #Constants in T +; ; -; * V(T) .. max number of vars of any clause in T +; ; -; * a .. max arity of any pred. symbol in T +; ; -; * l .. max cardinality of the body of any clause in T +; ; -; * |T| .. #clauses in T +; ; -; * +; ; -; * |A(T)| =< P(T)*(C(T) + V(T))^a +; ; -; * |CL(T)| =< |A(T)| * (|A(T)| l) +; ; -; * I(T) = log2( (|CL(T)| |T|) ) +; ; -; * where (a b) == (a) = n!/(k!*(n-k)!) +; ; -; * (b) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: L. DeRaedth, S. Muggleton: ILP: Theory and Methods +; ; -; * submitted to Journal of LP +; ; -; * +; ; -; *********************************************************************** +; @@ -2651,6 +2759,8 @@ (ivonEunterT $Predlist $CT $IET) (is $ITE (+ $IT $IET)))) +; + @@ -2678,6 +2788,8 @@ (is $CLT (* $AT $X3)) (log2nueberk $CLT $BT $IT))) +; + (= @@ -2704,72 +2816,74 @@ (log2nueberk $MTM $NLN $LY) (is $IET (+ $LX $LY)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: ivonBundE/1 +; ; -; * +; ; -; * syntax: ivonBundE(-IBE) +; ; -; * +; ; -; * args: ITE... information content of B & E +; ; -; * (only for funtion-free B and E!!) +; ; -; * +; ; -; * description: computes information content of B & E. +; ; -; * If T = B & H, then T compresses +; ; -; * the examples E if I(T|E) =< I(B & E) +; ; -; * Precondition: B, T, E function-free! +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: L. DeRaedth, S. Muggleton: ILP: Theory and Methods +; ; -; * submitted to Journal of LP +; ; -; * +; ; -; *********************************************************************** +; @@ -2825,78 +2939,82 @@ (append $IDL00 $IDL01 $IDL) (length $IDL $BT) (ivonT $PT $CT $VT $A $L $BT $IBE))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: all_atoms/3 +; ; -; * +; ; -; * syntax: all_atoms(+Predlist,+No_constants,-No_atoms) +; ; -; * +; ; -; * args: Predlist = [p1/arity1,...,pn/arityn] list of pred. symbols and +; ; -; * their arities +; ; -; * No_constants.... number c of constants in the current theory +; ; -; * No_atoms = number of atoms that can be built from the preds +; ; -; * in predlist and the c constants +; ; -; * = c^arity1 + .... + c^arityn +; ; -; * +; ; -; * description: +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= - (all_atoms () $_ 0) True) + (all_symbols () $_ 0) True) +; + (= (all-atoms (Cons @@ -2909,87 +3027,97 @@ (pow $CT $A $X) (is $HT (+ $HT0 $X)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: max_arity/2, maxvars/2, maxi/3 +; ; -; * +; ; -; * syntax: max_arity(+Plist,-A), maxvars(+Vlist,-V), maxi(+X,+Y,-Z) +; ; -; * +; ; -; * args: Plist = [_/n1,...,_/nn] for numbers ni, A is the max of the ni +; ; -; * Vlist = [_/n1,...,_/nn] for numbers ni, V is the max of the ni +; ; -; * Z is the max of X and Y +; ; -; * +; ; -; * description: +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (max-arity (:: (/ $_ $A)) $A) - (set-det)) + (set-det)) +; + (= (max-arity (Cons (/ $_ $A) $R) $C) ( (max-arity $R $B) (maxi $A $B $C))) +; + (= (maxvars (:: (/ $A $_)) $A) (set-det)) +; + (= (maxvars (Cons (/ $A $_) $R) $C) ( (maxvars $R $B) (maxi $A $B $C))) +; + (= @@ -2998,60 +3126,62 @@ (>= $A $B) (= $C $A) (= $C $B))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: herbrand_base_ff/1 +; ; -; * +; ; -; * syntax: herbrand_base_ff(-M) +; ; -; * +; ; -; * args: M .. reduced list of atoms entailed by the current +; ; -; * function-free theory +; ; -; * +; ; -; * description: +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -3065,13 +3195,19 @@ (get-clause $ID $_ $B $_ $_) (\== $B True)) $IDlist) (herbrand-base-ff $IDlist $M0 $M))) +; + (= (herbrand-base-ff $IDlist $M $M2) ( (herbrand-base-ff $IDlist $M $M $M1 $Mark) (det-if-then-else (== $Mark changed) (herbrand-base-ff $IDlist $M1 $M2) (= $M2 $M1)))) +; + (= (herbrand_base_ff () $_ $M $M not_changed) True) +; + (= (herbrand-base-ff (Cons $ID $R) $M $M1 $M4 $Mark) @@ -3086,6 +3222,8 @@ (remove-variant $M2 $M4 Nil) (= $Mark $Mark0) (= $Mark changed)))) +; + (= @@ -3095,6 +3233,8 @@ (, $H1 $B1)) (copy-term $M $M1) (match-body $B1 $M1))) +; + (= (match-body @@ -3102,20 +3242,30 @@ ( (set-det) (member $A $M) (match-body $B $M))) +; + (= (match-body $A $M) (member $A $M)) +; + (= (reduce-hb $L $L1) (reduce-hb $L $L $L1)) +; + (= (reduce_hb () $_ ()) True) +; + (= (reduce-hb (Cons $H $R) $L $R2) ( (reduce-hb $R $L $R1) (det-if-then-else (not (sub-contained-in $H $L)) (= $R2 (Cons $H $R1)) (= $R2 $R1)))) +; + (= @@ -3126,80 +3276,86 @@ (\== $H1 $H) (subsumes-chk $H1 $H)) True (sub-contained-in $H $R))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: mTplus/2 +; ; -; * +; ; -; * syntax: mTplus(+No_constants,-MT) +; ; -; * +; ; -; * args: No_constants... number c of constants in T +; ; -; * MT ... size of M+(T) for theory T +; ; -; * +; ; -; * description: determines first the reduced Herbrand base of T, i.e. +; ; -; * a list [A1,...,An] where Ai are atoms that might contain variables. +; ; -; * The size of M+(T) is then +; ; -; * |vars(A1)|^c + .... + |vars(An)|^c +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (mTplus $CT $MT) ( (herbrand-base-ff $M) (hb-plus $M $CT $MT))) +; + (= (hb_plus () $_ 0) True) +; + (= (hb-plus (Cons $T $R) $CT0 $MT) @@ -3213,70 +3369,72 @@ (pow $CT $VN $X) (is $MT (+ $MT1 $X)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: code_length/2 +; ; -; * +; ; -; * syntax: code_length(+Term,-CL) +; ; -; * +; ; -; * args: CL .. code length of Term +; ; -; * +; ; -; * description: code length of a term a la R. Wirth/S. Muggleton: +; ; -; * let sym(Term) be all symbols in Term, and N the number of +; ; -; * all symbol occurrences in Term. Let ps be the relative +; ; -; * frequency of symbol s in Term. Then +; ; -; * code_length(Term)= N * sum_{s in sym(Term)} -ps log2ps +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -3288,10 +3446,14 @@ (code-length1 $SymS1 $L0) (is $L (* $N $L0)))) +; + (= (code_length1 () 0) True) +; + (= (code-length1 (Cons $F $R) $L) @@ -3302,10 +3464,14 @@ (- $LF))) (is $L (+ $L0 $L1)))) +; + (= (relative_frequencies () $N $N ()) True) +; + (= (relative-frequencies (Cons @@ -3317,6 +3483,8 @@ (relative-frequencies $R $N1 $N $R1) (is $RM (/ $M $N)))) +; + (= @@ -3324,15 +3492,21 @@ ( (atomic $X) (set-det) (update-frequency-list $L $X 0 $L1))) +; + (= (symbol-frequencies $X $L $L1) ( (functor $X $F $N) (update-frequency-list $L $F $N $L0) (symbol-frequencies $N $X $L0 $L1))) +; + (= (symbol-frequencies 0 $_ $L $L) (set-det)) +; + (= (symbol-frequencies $N $X $L $L2) ( (is $N1 @@ -3340,12 +3514,16 @@ (symbol-frequencies $N1 $X $L $L1) (arg $N $X $Xn) (symbol-frequencies $Xn $L1 $L2))) +; + (= (update_frequency_list () $F $N ( (/ (/ $F $N) 1))) True) +; + (= (update-frequency-list (Cons @@ -3355,88 +3533,92 @@ (/ (/ $F $N) $M1) $R)) ( (set-det) (is $M1 (+ $M 1)))) +; + (= (update-frequency-list (Cons $X $R) $F $N (Cons $X $R1)) (update-frequency-list $R $F $N $R1)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: encoding_length_examples/1, encoding_length_clause/2 +; ; -; * +; ; -; * syntax: encoding_length_examples(-EE) +; ; -; * encoding_length_clause(+CL,-EC) +; ; -; * +; ; -; * args: EE, EC.. floats +; ; -; * CL... clause in list representation +; ; -; * +; ; -; * description: encoding length a la Quinlan: +; ; -; * for examples: PN.. no of pos ex., NN.. no. of neg ex, U = PN + NN +; ; -; * EE = log2(U) + log2((U PN)) +; ; -; * for clauses: N.. length of Clause, Preds.. no of preds, +; ; -; * A .. no of poss. args +; ; -; * EC = (sum_{i=1}^{N} bits for literal i)/log2(N!) +; ; -; * bits for literali = 1 + log2(Preds) + log2(A) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -3460,6 +3642,8 @@ (log2nueberk $U1 $PN1 $Y) (is $X (+ $LU $Y)))) +; + (= @@ -3478,6 +3662,8 @@ (* $N $LPreds))) (is $EL (/ $Lits $LNF)))) +; + (= @@ -3492,6 +3678,8 @@ (encoding-length-lits $R $Args $M1) (is $M (+ $M1 $LN)))) +; + (= (encoding-length-lits @@ -3506,8 +3694,12 @@ (encoding-length-lits $R $Args3 $M1) (is $M (+ $M0 $M1)))) +; + (= - (encoding_length_lits () $_ 0) True) + (encoding_length_lits () $_ 0) True) +; + diff --git a/miles/examples/ex1.metta b/miles/examples/ex1.metta index 95d6e33..3e83506 100644 --- a/miles/examples/ex1.metta +++ b/miles/examples/ex1.metta @@ -1,5 +1,6 @@ ; -; ;; examples for appending two lists +; + (= @@ -8,122 +9,155 @@ (1 2) (3) (1 2 3)) +) True) +; + (= (ex (app (x a) (b c) (x a b c)) +) True) +; + (= (ex (app (a) (b c) (a b c)) +) True) +; + (= (ex (app () () ()) +) True) +; + (= (ex (app (p) () (p)) +) True) +; + (= (ex (app () (u) (u)) +) True) +; + (= (ex (app () (x y) (x y)) +) True) +; + (= (ex (app (r s) () (r s)) +) True) +; + (= (ex (app (g) (d) (g d)) +) True) +; + (= (ex (app (9 8 7) () (9 8 7)) +) True) +; + (= (ex (app () (6 5 4) (6 5 4)) +) True) +; + (= (ex (app (4 3 5) (8) (4 3 5 8)) +) True) +; + (= (ex (app (r w) (q t s f i) (r w q t s f i)) +) True) +; + (= (ex (app (j k l m) (n o p q r) (j k l m n o p q r)) +) True) +; + (= (ex (app (r s t) (q u v) (t s r q u v)) -) True) +; + (= (ex (app (s t) (q u v) (s r q u v)) -) True) +; + ; ; -; Try for example -; -; | ?- clear_kb, init_kb('examples/ex1.pl'). -; | ?- argument_types. -; | ?- show_kb. -; | ?- complete_chk. ;; Antwort: no -; | ?- ip(A). ;; gibt alle unabgedeckten Bsple zur"uck -; | ?- clause_heads, eval_examples. -; | ?- show_kb. -; | ?- complete_chk. ;; geht jetzt gut -; | ?- correct_chk. -; | ?- fp(A). ;; gibt inkorrekte Klausel(n) + ihre Instantiierung(en) zur"uck -; ;; in der Form [ID:[Instanz]] -; | ?- refinement(ID,_). ;; wobei ID der der inkorrekten Klausel ist -> gibt -; ;; Spezialisierungen dieser Klausel (in einer Liste) -; | ?- flatten_kb. ;; kb funktionsfrei machen -; | ?- show_kb. -; -; ;; Sei ID1 der der Klausel: -; ;; app(A,B,C) :- cons_p(D,E,A),x_p(D),cons_p(F,G,E),a_p(F),nil_p(G), -; ;; cons_p(H,I,B),b_p(H),cons_p(J,G,I),c_p(J),cons_p(D,K,C),cons_p(F,B,K). -; ;; ID2 der der Klausel: -; ;; app(A,B,C) :- cons_p(D,E,A),a_p(D),nil_p(E), -; ;; cons_p(F,G,B),b_p(F),cons_p(H,E,G),c_p(H),cons_p(D,B,C). -; -; Dann teste: -; -; | ?- absorb(ID1,ID2,J), show_clause(J). -; | ?- elem_saturate(ID1,ID2,J1), show_clause(J1). -; | ?- saturate(ID1,J2,5), show_clause(J2). -; | ?- unflatten_kb. -; | ?- show_kb. +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; ; ; diff --git a/miles/examples/ex2.metta b/miles/examples/ex2.metta index c08e242..c410987 100644 --- a/miles/examples/ex2.metta +++ b/miles/examples/ex2.metta @@ -1,5 +1,5 @@ ; -; ;; clauses 1-4 define Rouveirols bg knowledge +; @@ -9,6 +9,8 @@ (standing $X) (is-on $X $Y) (ground $Y))) +; + (= (column $X) @@ -16,11 +18,15 @@ (standing $X) (is-on $X $Y) (column $Y))) +; + (= (same-height $X $Y) ( (ground $X) (ground $Y))) +; + (= (same-height $X $Y) @@ -31,10 +37,12 @@ (is-on $X $X1) (is-on $Y $Y1) (same-height $X1 $Y1))) +; + ; -; the next 2 examples (5+6) show arches of different heights +; @@ -57,6 +65,8 @@ (standing $C) (brick $B) (brick $C))) +; + (= @@ -85,10 +95,12 @@ (is-on $E $G) (ground $G) (ground $F))) +; + ; -; the next 3 examples (7-9) show arches of different colors (-> lgg looks strange) +; (= @@ -112,6 +124,8 @@ (brick $C) (red $B) (green $C))) +; + (= (arch $X) @@ -134,6 +148,8 @@ (brick $C) (green $B) (red $C))) +; + (= (arch $X) @@ -156,10 +172,12 @@ (brick $C) (blue $B) (red $C))) +; + ; -; some clauses (10-12) to test intra-construction +; @@ -169,6 +187,8 @@ (standing $X) (is-on $X $Y) (table $Y))) +; + (= (column $X) @@ -176,6 +196,8 @@ (standing $X) (is-on $X $Y) (ground $Y))) +; + (= (column $X) @@ -183,133 +205,136 @@ (standing $X) (is-on $X $Y) (column $Y))) +; + +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; ; ; ; -; ; ?- do_full_kb('examples/ex2.pl'). -; /* -; -; | ?- clear_kb, init_kb('examples/ex2.pl'). -; | ?- show_kb. -; | ?- intra_construct1(10,11,A,B,C). -; | ?- show_clauses([10,11,13,14,15]). -; | ?- g1_op(5,1,I). -; | ?- g1_op(5,3,I). -; | ?- absorb(5,1,I). -; | ?- elem_saturate(5,1,I). -; | ?- saturate(5,I,10). -; | ?- most_spec_v(5,I,J). -; | ?- inv_derivate(5,J). -; | ?- show_kb. -; | ?- lgg(7,9,J), show_clause(J). -; | ?- nr_lgg(7,9,J), show_clause(J), -; get_clause(J,_,_,CL,_),reduce_complete(CL,CL1), -; store_clause(_,CL1,nrlgg,I), show_clause(I). -; -; | ?- clear_kb, init_kb('examples/ex2.pl'). -; | ?- gen_msg(5,6,J,10),show_clause(J). -; | ?- gti(8,9,J),show_clause(J). -; -; | ?- clear_kb, init_kb('examples/ex2.pl'). -; | ?- rlgg(5,6,J),show_clause(J). -; -; ;X-MILES Protocol: -; -; :- clear_kb. -; ; knowledgebase cleared. -; :- init_kb('examples/ex2.pl'). -; ; file "/tmp_mnt/home/stahl/edl/framework/miles/examples/ex2.pl" consulted. -; :- intra_construct1(10,11,Xmout1,Xmout2,Xmout3). -; ; yes -; ; rule 13 created. -; ; rule 14 created. -; ; rule 15 created. -; :- g1_op(5,1,Xmout1). -; ; yes -; ; rule 16 created. -; :- absorb(5,1,Xmout1). -; ; yes -; ; rule 17 created. -; :- elem_saturate(5,1,Xmout1). -; ; yes -; ; rule 18 created. -; :- saturate(5,Xmout1,5). -; ; yes -; ; rule 19 created. -; :- most_spec_v(5,1,Xmout1). -; ; yes -; ; rule 20 created. -; :- inv_derivate(5,Xmout1). -; ; yes -; ; rule 21 created. -; :- lgg(7,9,Xmout1). -; ; yes -; ; rule 22 created. -; :- nr_lgg(7,9,Xmout1). -; ; yes -; ; rule 23 created. -; :- reduce_complete(23). -; ; yes -; :- delete_clause(1). -; :- delete_clause(2). -; :- delete_clause(3). -; :- delete_clause(4). -; :- delete_clause(5). -; :- delete_clause(6). -; :- delete_clause(7). -; :- delete_clause(8). -; :- delete_clause(9). -; :- delete_clause(10). -; :- delete_clause(11). -; :- delete_clause(12). -; :- delete_clause(13). -; :- delete_clause(14). -; :- delete_clause(15). -; :- delete_clause(16). -; :- delete_clause(17). -; :- delete_clause(18). -; :- delete_clause(19). -; :- delete_clause(20). -; :- delete_clause(21). -; :- delete_clause(22). -; :- delete_clause(23). -; ; all rules deleted. -; ; all examples deleted. -; :- clear_kb. -; ; knowledgebase cleared. -; :- init_kb(/tmp_mnt/home/stahl/edl/framework/miles/examples/ex2.pl). -; ; file "/tmp_mnt/home/stahl/edl/framework/miles/examples/ex2.pl" consulted. -; :- gen_msg(5,6,Xmout1). -; ; yes -; ; rule 15 created. -; :- gti(8,9,Xmout1). -; ; yes -; ; rule 16 created. -; :- delete_clause(1). -; :- delete_clause(2). -; :- delete_clause(3). -; :- delete_clause(4). -; :- delete_clause(7). -; :- delete_clause(10). -; :- delete_clause(11). -; :- delete_clause(12). -; :- delete_clause(15). -; :- delete_clause(5). -; :- delete_clause(6). -; :- delete_clause(8). -; :- delete_clause(9). -; :- delete_clause(16). -; ; all rules deleted. -; ; all examples deleted. -; :- clear_kb. -; ; knowledgebase cleared. -; :- init_kb('examples/ex2.pl'). -; ; file "/tmp_mnt/home/stahl/edl/framework/miles/examples/ex2.pl" consulted. -; :- rlgg(5,6,Xmout1). -; ; yes -; ; rule 13 created. ; ; ; diff --git a/miles/examples/ex3.metta b/miles/examples/ex3.metta index 231647f..c37df22 100644 --- a/miles/examples/ex3.metta +++ b/miles/examples/ex3.metta @@ -1,5 +1,5 @@ ; -; grammar rules +; @@ -14,6 +14,8 @@ (:: susi)) (pn (:: susi) Nil))) +; + (= (s @@ -21,12 +23,16 @@ ( (pn (:: martha schlaeft) (:: schlaeft)) (v-i (:: schlaeft) Nil))) +; + (= (vp $A $B) ( (v-t $A $C) (np $C $B))) +; + (= (vp (:: sieht den mann) Nil) @@ -38,12 +44,16 @@ (:: mann)) (n (:: mann) Nil))) +; + (= (vp (:: hilft karl) Nil) ( (v-t (:: hilft karl) (:: karl)) (pn (:: karl) Nil))) +; + (= @@ -51,22 +61,27 @@ (Cons (s $D) $E)) (min1 $D $E)) +; + (= (min1 $F (Cons (s (s $F)) $G)) (min1 $F $G)) +; + ; ; -; | ?- clear_kb,do_full_kb('examples/ex3.pl'). ; -; Try: -; | ?- clear_kb, init_kb('examples/ex3.pl'). -; | ?- intra_construct1(1,2,A,B,C),show_clauses([1,2,A,B,C]). -; | ?- g2_op(1,2,A,B,C). ;; stellt Fragen -; | ?- show_kb. -; | ?- identify(4,3,J), show_clause(J). -; | ?- identify(5,I,J), show_clause(J). -; | ?- apply_g2([4,5,10],A,BB),show_kb. +; +; +; +; +; +; +; +; +; +; diff --git a/miles/examples/ex4.metta b/miles/examples/ex4.metta index 1d8331c..95d2660 100644 --- a/miles/examples/ex4.metta +++ b/miles/examples/ex4.metta @@ -1,19 +1,19 @@ ; -; diverse +; ; -; index 1 and 2 +; ; -; ;member(2,[1,2]):- member(2,[2]). +; ; -; ;member(c,[a,b,c]):- member(c,[b,c]),member(c,[c]). +; ; -; index 3 and 4 +; (= @@ -25,6 +25,8 @@ (small $Z) (green $Z) (left-of $Y $Z))) +; + (= (scene $X) ( (part-of $X $Y) @@ -34,22 +36,30 @@ (large $Z) (green $Z) (left-of $Y $Z))) +; + ; -; index 5-9 +; (= (pet $X) (cat $X)) +; + (= (pet $X) (dog $X)) +; + (= (small $X) (cat $X)) +; + (= @@ -57,118 +67,137 @@ ( (small $X) (fluffy $X) (dog $X))) +; + (= (cuddly-pet $X) ( (fluffy $X) (cat $X))) +; + (= (ex (cuddly_pet cathy_the_cat) +) True) +; + (= (ex (cuddly_pet rosi_the_rabbit) +) True) +; + (= (ex (cuddly_pet tom_the_turtle) -) True) +; + ; -; index 10-13 +; (= (has_wings p) True) +; + (= (has_beak p) True) +; + (= (has-wings $X) (bird $X)) +; + (= (has-beak $X) (bird $X)) +; + ; -; index 14 and 15 +; ; -; ;min(2,[3,2]):- min(2,[2]). +; ; -; ;min(5,[7,6,5]):- min(5,[6,5]). +; ; -; index 16 and 17 +; ; -; ;min1(D,[s(D)|E]):- min1(D,E). +; ; -; ;min1(F,[s(s(F))|G]):- min1(F,G). +; ; ; -; | ?- clear_kb,do_full_kb('examples/ex4.pl'). ; -; Try: ; ; -; | ?- clear_kb,init_kb('examples/ex4.pl'). -; | ?- show_kb. -; | ?- lgg(1,2,J),show_clause(J). -; | ?- nr_lgg(1,2,J),show_clause(J). -; | ?- lgg(3,4,J),show_clause(J). -; | ?- nr_lgg(3,4,J),show_clause(J). -; | ?- gti(3,4,J),show_clause(J). ; erlaubt backtracking! -; | ?- lgti(3,4,C,_,_). -; | ?- lgg(8,9,J),show_clause(J). -; | ?- rlgg(8,9,J),show_clause(J). -; | ?- rlgg(8,9,cuddly_pet(_),J),show_clause(J). -; | ?- gen_msg(8,9,J),show_clause(J). -; | ?- rlgg(10,11,J),show_clause(J). -; | ?- intra_construct1(14,15,A,B,C),show_clauses([14,15,A,B,C]). -; | ?- intra_construct2(16,17,A,B,C),show_clauses([16,17,A,B,C]). ; ; -; end_of_file. ; -; Try for example ; -; | ?- clear_kb, init_kb('examples/ex1.pl'). -; | ?- argument_types. -; | ?- show_kb. -; | ?- complete_chk. ;; Antwort: no -; | ?- ip(A). ;; gibt alle unabgedeckten Bsple zur"uck -; | ?- clause_heads, eval_examples. -; | ?- show_kb. -; | ?- complete_chk. ;; geht jetzt gut -; | ?- correct_chk. -; | ?- fp(A). ;; gibt inkorrekte Klausel(n) + ihre Instantiierung(en) zur"uck -; ;; in der Form [ID:[Instanz]] -; | ?- refinement(ID,_). ;; wobei ID der der inkorrekten Klausel ist -> gibt -; ;; Spezialisierungen dieser Klausel (in einer Liste) -; | ?- flatten_kb. ;; kb funktionsfrei machen -; | ?- show_kb. ; -; ;; Sei ID1 der der Klausel: -; ;; app(A,B,C) :- cons_p(D,E,A),x_p(D),cons_p(F,G,E),a_p(F),nil_p(G), -; ;; cons_p(H,I,B),b_p(H),cons_p(J,G,I),c_p(J),cons_p(D,K,C),cons_p(F,B,K). -; ;; ID2 der der Klausel: -; ;; app(A,B,C) :- cons_p(D,E,A),a_p(D),nil_p(E), -; ;; cons_p(F,G,B),b_p(F),cons_p(H,E,G),c_p(H),cons_p(D,B,C). ; -; Dann teste: ; -; | ?- absorb(ID1,ID2,J), show_clause(J). -; | ?- elem_saturate(ID1,ID2,J1), show_clause(J1). -; | ?- saturate(ID1,J2,5), show_clause(J2). -; | ?- unflatten_kb. -; | ?- show_kb. +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; ; ; diff --git a/miles/examples/ex5.metta b/miles/examples/ex5.metta index 657c671..bbfb3ff 100644 --- a/miles/examples/ex5.metta +++ b/miles/examples/ex5.metta @@ -1,75 +1,99 @@ ; -; MENDEL +; ; -; parent generation +; (= (ex (colour a red) +) True) +; + (= (ex (colour b yellow) +) True) +; + ; -; f1 +; (= (ex (colour (k a a) red) +) True) +; + (= (ex (colour (k a b) red) +) True) +; + (= (ex (colour (k b b) yellow) +) True) +; + ; -; parent with f1 +; (= (ex (colour (k a (k a a)) red) +) True) +; + (= (ex (colour (k a (k a b)) red) +) True) +; + (= (ex (colour (k a (k b b)) red) +) True) +; + (= (ex (colour (k b (k a a)) red) +) True) +; + (= (ex (colour (k b (k a b)) red) +) True) +; + (= (ex (colour (k b (k a b)) yellow) +) True) +; + (= (ex (colour (k b (k b b)) yellow) +) True) +; + ; -; f2 +; (= (ex @@ -77,111 +101,128 @@ (k (k a a) (k a a)) red) +) True) +; + (= (ex (colour (k (k a a) (k a b)) red) +) True) +; + (= (ex (colour (k (k a a) (k b b)) red) +) True) +; + (= (ex (colour (k (k a b) (k a b)) red) +) True) +; + (= (ex (colour (k (k a b) (k a b)) yellow) +) True) +; + (= (ex (colour (k (k a b) (k b b)) red) +) True) +; + (= (ex (colour (k (k a b) (k b b)) yellow) +) True) +; + (= (ex (colour (k (k b b) (k b b)) yellow) +) True) +; + +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; ; ; -; Try: ; -; | ?- clear_kb, do_full_kb('examples/ex5.pl'). ; -; | ?- clear_kb, init_kb('examples/ex5.pl'). -; | ?- show_kb. -; | ?- lgg(1,2,J),show_clause(J). -; | ?- nr_lgg(1,2,J),show_clause(J). -; | ?- lgg(3,4,J),show_clause(J). -; | ?- nr_lgg(3,4,J),show_clause(J). -; | ?- gti(3,4,J),show_clause(J). ; erlaubt backtracking! -; | ?- lgti(3,4,C,_,_). -; | ?- lgg(8,9,J),show_clause(J). -; | ?- rlgg(8,9,J),show_clause(J). -; | ?- rlgg(8,9,cuddly_pet(_),J),show_clause(J). -; | ?- gen_msg(8,9,J),show_clause(J). -; | ?- rlgg(10,11,J),show_clause(J). -; | ?- intra_construct1(14,15,A,B,C),show_clauses([14,15,A,B,C]). -; | ?- intra_construct2(16,17,A,B,C),show_clauses([16,17,A,B,C]). ; ; -; end_of_file. ; -; Try for example ; -; | ?- clear_kb, init_kb('examples/ex5.pl'). -; | ?- argument_types. -; | ?- show_kb. -; | ?- complete_chk. ;; Antwort: no -; | ?- ip(A). ;; gibt alle unabgedeckten Bsple zur"uck -; | ?- clause_heads, eval_examples. -; | ?- show_kb. -; | ?- complete_chk. ;; geht jetzt gut -; | ?- correct_chk. -; | ?- fp(A). ;; gibt inkorrekte Klausel(n) + ihre Instantiierung(en) zur"uck -; ;; in der Form [ID:[Instanz]] -; | ?- refinement(ID,_). ;; wobei ID der der inkorrekten Klausel ist -> gibt -; ;; Spezialisierungen dieser Klausel (in einer Liste) -; | ?- flatten_kb. ;; kb funktionsfrei machen -; | ?- show_kb. ; -; ;; Sei ID1 der der Klausel: -; ;; app(A,B,C) :- cons_p(D,E,A),x_p(D),cons_p(F,G,E),a_p(F),nil_p(G), -; ;; cons_p(H,I,B),b_p(H),cons_p(J,G,I),c_p(J),cons_p(D,K,C),cons_p(F,B,K). -; ;; ID2 der der Klausel: -; ;; app(A,B,C) :- cons_p(D,E,A),a_p(D),nil_p(E), -; ;; cons_p(F,G,B),b_p(F),cons_p(H,E,G),c_p(H),cons_p(D,B,C). ; -; Dann teste: ; -; | ?- absorb(ID1,ID2,J), show_clause(J). -; | ?- elem_saturate(ID1,ID2,J1), show_clause(J1). -; | ?- saturate(ID1,J2,5), show_clause(J2). -; | ?- unflatten_kb. -; | ?- show_kb. ; ; diff --git a/miles/examples/ex6.metta b/miles/examples/ex6.metta index cb391f1..bb99609 100644 --- a/miles/examples/ex6.metta +++ b/miles/examples/ex6.metta @@ -5,66 +5,79 @@ (= (has-wings $X) (bird $X)) +; + (= (has-beak $X) (bird $X)) +; + (= (bird $X) (vulture $X)) +; + (= (carnivore $X) (vulture $X)) +; + (= (ex (has_wings tweety) +) True) +; + (= (ex (has_beak tweety) +) True) +; + +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; ; ; -; Try for example ; ; -; | ?- clear_kb, do_full_kb('examples/ex6.pl'). ; -; | ?- clear_kb, init_kb('examples/ex6.pl'). -; | ?- argument_types. -; | ?- show_kb. -; | ?- complete_chk. ;; Antwort: no -; | ?- ip(A). ;; gibt alle unabgedeckten Bsple zur"uck -; | ?- clause_heads, eval_examples. -; | ?- show_kb. -; | ?- complete_chk. ;; geht jetzt gut -; | ?- correct_chk. -; | ?- fp(A). ;; gibt inkorrekte Klausel(n) + ihre Instantiierung(en) zur"uck -; ;; in der Form [ID:[Instanz]] -; | ?- refinement(ID,_). ;; wobei ID der der inkorrekten Klausel ist -> gibt -; ;; Spezialisierungen dieser Klausel (in einer Liste) -; | ?- flatten_kb. ;; kb funktionsfrei machen -; | ?- show_kb. ; -; ;; Sei ID1 der der Klausel: -; ;; app(A,B,C) :- cons_p(D,E,A),x_p(D),cons_p(F,G,E),a_p(F),nil_p(G), -; ;; cons_p(H,I,B),b_p(H),cons_p(J,G,I),c_p(J),cons_p(D,K,C),cons_p(F,B,K). -; ;; ID2 der der Klausel: -; ;; app(A,B,C) :- cons_p(D,E,A),a_p(D),nil_p(E), -; ;; cons_p(F,G,B),b_p(F),cons_p(H,E,G),c_p(H),cons_p(D,B,C). ; -; Dann teste: ; -; | ?- absorb(ID1,ID2,J), show_clause(J). -; | ?- elem_saturate(ID1,ID2,J1), show_clause(J1). -; | ?- saturate(ID1,J2,5), show_clause(J2). -; | ?- unflatten_kb. -; | ?- show_kb. ; diff --git a/miles/examples/ex7.metta b/miles/examples/ex7.metta index c2c0c59..c9a7291 100644 --- a/miles/examples/ex7.metta +++ b/miles/examples/ex7.metta @@ -1,6 +1,6 @@ ; -; ;;Examples for truncation ops +; @@ -9,9 +9,13 @@ (member $X (Cons $Y $R)) ( (member $X $R) (member $X (:: $X)))) +; + (= (member $X (Cons $X $_)) True) +; + (= @@ -19,15 +23,21 @@ (x a) (b c) (x a b c)) True) +; + (= (app (a) (b c) (a b c)) True) +; + (= (app () (b c) (b c)) True) +; + (= @@ -36,87 +46,119 @@ (1 2) (3) (1 2 3)) +) True) +; + (= (ex (app (x a) (b c) (x a b c)) +) True) +; + (= (ex (app (a) (b c) (a b c)) +) True) +; + (= (ex (app () () ()) +) True) +; + (= (ex (app (p) () (p)) +) True) +; + (= (ex (app () (u) (u)) +) True) +; + (= (ex (app () (x y) (x y)) +) True) +; + (= (ex (app (r s) () (r s)) +) True) +; + (= (ex (app (g) (d) (g d)) +) True) +; + (= (ex (app (9 8 7) () (9 8 7)) +) True) +; + (= (ex (app () (6 5 4) (6 5 4)) +) True) +; + (= (ex (app (4 3 5) (8) (4 3 5 8)) +) True) +; + (= (ex (app (r w) (q t s f i) (r w q t s f i)) +) True) +; + (= (ex (app (j k l m) (n o p q r) (j k l m n o p q r)) +) True) +; + (= (ex (app (r s t) (q u v) (t s r q u v)) -) True) +; + (= (ex (app (s t) (q u v) (s r q u v)) -) True) +; + @@ -124,6 +166,8 @@ (min $A (Cons $A $B)) ( (min $C $B) (ge $E $F))) +; + (= (p $X) @@ -131,6 +175,8 @@ (r $V1 $V2) (q $V3) (s $V3 $V1))) +; + @@ -140,6 +186,8 @@ (standing $X) (is-on $X $Y) (ground $Y))) +; + (= (column $X) @@ -147,11 +195,15 @@ (standing $X) (is-on $X $Y) (column $Y))) +; + (= (same-height $X $Y) ( (ground $X) (ground $Y))) +; + (= (same-height $X $Y) @@ -162,6 +214,8 @@ (is-on $X $X1) (is-on $Y $Y1) (same-height $X1 $Y1))) +; + @@ -184,6 +238,8 @@ (standing $C) (brick $B) (brick $C))) +; + @@ -191,78 +247,107 @@ (= (ex (p a) +) True) +; + (= (ex (p b) +) True) +; + (= (ex (p c) -) True) +; + (= (q a qa) True) +; + (= (q b qb) True) +; + (= (q c qc) True) +; + (= (r qa x) True) +; + (= (r qb x) True) +; + (= (r qc x) True) +; + (= (s sa qa) True) +; + (= (s sb qb) True) +; + (= (s sc qc) True) +; + (= (q sa) True) +; + (= (q sb) True) +; + +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; ; ; -; Try for example ; -; | ?- clear_kb, do_full_kb('examples/ex7.pl'). ; -; | ?- clear_kb, init_kb('examples/ex7.pl'). -; | ?- argument_types. -; | ?- show_kb. -; | ?- complete_chk. ;; Antwort: no -; | ?- ip(A). ;; gibt alle unabgedeckten Bsple zur"uck -; | ?- clause_heads, eval_examples. -; | ?- show_kb. -; | ?- complete_chk. ;; geht jetzt gut -; | ?- correct_chk. -; | ?- fp(A). ;; gibt inkorrekte Klausel(n) + ihre Instantiierung(en) zur"uck -; ;; in der Form [ID:[Instanz]] -; | ?- refinement(ID,_). ;; wobei ID der der inkorrekten Klausel ist -> gibt -; ;; Spezialisierungen dieser Klausel (in einer Liste) -; | ?- flatten_kb. ;; kb funktionsfrei machen -; | ?- show_kb. ; -; ;; Sei ID1 der der Klausel: -; ;; app(A,B,C) :- cons_p(D,E,A),x_p(D),cons_p(F,G,E),a_p(F),nil_p(G), -; ;; cons_p(H,I,B),b_p(H),cons_p(J,G,I),c_p(J),cons_p(D,K,C),cons_p(F,B,K). -; ;; ID2 der der Klausel: -; ;; app(A,B,C) :- cons_p(D,E,A),a_p(D),nil_p(E), -; ;; cons_p(F,G,B),b_p(F),cons_p(H,E,G),c_p(H),cons_p(D,B,C). ; -; Dann teste: ; -; | ?- absorb(ID1,ID2,J), show_clause(J). -; | ?- elem_saturate(ID1,ID2,J1), show_clause(J1). -; | ?- saturate(ID1,J2,5), show_clause(J2). -; | ?- unflatten_kb. -; | ?- show_kb. ; diff --git a/miles/examples/ex8.metta b/miles/examples/ex8.metta index 293ede2..ef0b46c 100644 --- a/miles/examples/ex8.metta +++ b/miles/examples/ex8.metta @@ -3,140 +3,169 @@ (= (ex (reverse () ()) +) True) +; + (= (ex (reverse (b) (b)) +) True) +; + (= (ex (reverse (d e) (e d)) +) True) +; + (= (ex (reverse (e) (e)) +) True) +; + (= (ex (reverse (1) (1)) +) True) +; + (= (ex (reverse (1 b) (b 1)) +) True) +; + (= (ex (reverse (a b) (b a)) +) True) +; + (= (ex (reverse (c d e) (e d c)) +) True) +; + (= (ex (reverse (c d) (d c)) +) True) +; + (= (ex (reverse (d) (d)) +) True) +; + (= (ex (reverse (1 b) (1)) -) True) +; + (= (ex (reverse (a b) (b 1)) -) True) +; + (= (ex (reverse (a b) (a b)) -) True) +; + (= (ex (reverse (c d e) (d c e)) -) True) +; + ; -; ;reverse([],[]). +; ; -; ;reverse([X|Y],Z):- reverse(Y,Z1). - - -; -; -; try: -; -; | ?- clear_kb, do_full_kb('examples/ex8.pl'). -; -; :- init_kb('examples/ex8.pl'). -; ; file "/tmp_mnt/home/stahl/edl/framework/miles/examples/ex8.pl" consulted. -; :- argument_types. -; ; yes -; :- clause_heads. -; ; yes -; :- complete_chk. -; ; yes -; :- correct_chk. -; ; no -; :- fp(Xmout1). -; ; yes -; ; resulting rules selected -; :- refinement_add_body_literal(18,Xmout1). -; ; yes -; :- eval_examples. -; ; yes -; :- complete_chk. -; ; yes -; :- correct_chk. -; ; no -; :- fp(Xmout1). -; ; yes -; ; resulting rules selected -; :- specialize_with_newpred(18,Xmout1). -; ; yes -; :- store_clause(newp5([e,d],[d,c],e,c),_,user,32). -; ; rule added. -; :- store_clause(newp5([d],[c],d,c),_,user,33). -; ; rule added. -; :- flatten_kb. -; ; yes -; :- absorb(32,33,Xmout1). -; ; yes -; ; rule 53 created. -; :- unflatten_kb. -; ; yes -; :- delete_clause(53). -; :- store_clause(newp5([E|A],[B|C],E,D) :- -; newp5(A,C,B,D),_,user,53). -; ; rule changed. -; :- clause_heads. -; ; yes -; :- delete_clause(32). -; :- delete_clause(33). -; :- delete_clause(55). -; :- delete_clause(56). -; :- delete_clause(57). -; ; selected rules deleted. -; :- eval_examples. -; ; yes -; :- complete_chk. -; ; yes -; :- correct_chk. -; ; yes +; + + +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; diff --git a/miles/examples/ex9.metta b/miles/examples/ex9.metta index dbdfb91..7a67fcb 100644 --- a/miles/examples/ex9.metta +++ b/miles/examples/ex9.metta @@ -3,37 +3,51 @@ (= (lt $A $B) (< $A $B)) +; + (= (type_restriction (lt $A $B) ( (number $A) (number $B))) True) +; + (= (ex (merge () () ()) +) True) +; + (= (ex (merge () (2) - (2)) +) True) + (2)) +) True) +; + (= (ex (merge () (3 4) - (3 4)) +) True) + (3 4)) +) True) +; + (= (ex (merge (5) () - (5)) +) True) + (5)) +) True) +; + (= (ex (merge (2 3) () - (2 3)) +) True) + (2 3)) +) True) +; + @@ -43,18 +57,24 @@ (1) (2) (1 2)) +) True) +; + (= (ex (merge (0 1) (3 4) (0 1 3 4)) +) True) +; + (= (ex (merge (1) (3 4) (1 3 4)) +) True) +; + (= (ex @@ -62,18 +82,24 @@ (5) (4) (4 5)) +) True) +; + (= (ex (merge (6 7) (3 4) (3 4 6 7)) +) True) +; + (= (ex (merge (6 7) (4) (4 6 7)) +) True) +; + (= @@ -81,25 +107,33 @@ (merge (2 3 4 6) (5 7) - (2 3 4 5 6 7)) +) True) + (2 3 4 5 6 7)) +) True) +; + (= (ex (merge (43 55 63) (22 33 44 53) - (22 33 43 44 53 55 63)) +) True) + (22 33 43 44 53 55 63)) +) True) +; + (= (ex (merge (29 39 49 59) (37 79 99) (29 37 39 49 59 79 99)) +) True) +; + (= (ex (merge (2) (4 7) (2 4 7)) +) True) +; + @@ -107,26 +141,36 @@ (ex (merge () () (3)) -) True) +; + (= (ex (merge () (2) - (1 2)) -) True) + (1 2)) -) True) +; + (= (ex (merge () (3 4) - (4 3)) -) True) + (4 3)) -) True) +; + (= (ex (merge (5 6) () - (5)) -) True) + (5)) -) True) +; + (= (ex (merge (2 3) () - (1 2 3)) -) True) + (1 2 3)) -) True) +; + @@ -136,18 +180,24 @@ (1) (2) (2 1)) -) True) +; + (= (ex (merge (0 1) (3 4) (0 1 4)) -) True) +; + (= (ex (merge (1) (3 4) (4 1 1 3)) -) True) +; + (= (ex @@ -155,113 +205,120 @@ (5) (1 4) (4 1 5)) -) True) +; + (= (ex (merge (6 7) (3 4) (3 6 4 7)) -) True) +; + (= (ex (merge (6 7) (4) (6 7 4)) -) True) +; + ; ; -; ;| ?- clear_kb, do_full_kb('examples/ex9.pl'). -; -; ;try: -; :- clear_kb, init_kb('examples/ex9.pl'). -; ; file "/tmp_mnt/home/stahl/edl/framework/miles/examples/ex9.pl" consulted. -; :- store_clause(merge([],[2],[2]),_,user,28). -; ; rule added. -; :- store_clause(merge([5],[],[5]),_,user,29). -; ; rule added. -; :- store_clause(merge([1],[2],[1,2]),_,user,30). -; ; rule added. -; :- store_clause(merge([0,1],[3,4],[0,1,3,4]),_,user,31). -; ; rule added. -; :- store_clause(merge([1],[3,4],[1,3,4]),_,user,32). -; ; rule added. -; :- store_clause(merge([5],[4],[4,5]),_,user,33). -; ; rule added. -; :- store_clause(merge([6,7],[3,4],[3,4,6,7]),_,user,34). -; ; rule added. -; :- store_clause(merge([6,7],[4],[4,6,7]),_,user,35). -; ; rule added. -; :- flatten_rules. -; ; yes -; :- saturate(30,Xmout1,5). -; ; yes -; ; rule 36 created. -; :- saturate(31,Xmout1,5). -; ; yes -; ; rule 37 created. -; :- saturate(33,Xmout1,5). -; ; yes -; ; rule 38 created. -; :- saturate(34,Xmout1,5). -; ; yes -; ; rule 39 created. -; :- unflatten_kb. -; ; yes -; :- lgg(36,37,Xmout1). -; ; yes -; ; rule 40 created. -; :- lgg(38,39,Xmout1). -; ; yes -; ; rule 41 created. -; :- delete_clause(36). -; :- delete_clause(37). -; :- delete_clause(38). -; :- delete_clause(39). -; ; selected rules deleted. -; :- delete_clause(28). -; :- delete_clause(29). -; :- delete_clause(30). -; :- delete_clause(31). -; :- delete_clause(32). -; :- delete_clause(33). -; :- delete_clause(34). -; :- delete_clause(35). -; ; selected rules deleted. -; :- argument_types. -; ; yes -; :- clause_heads. -; ; yes -; :- delete_clause(47). -; :- delete_clause(48). -; ; selected rules deleted. -; :- eval_examples. -; ; yes -; :- complete_chk. -; ; yes -; :- correct_chk. -; ; no -; :- fp(Xmout1). -; ; yes -; ; resulting rules selected -; :- refinement_add_body_literal(40,Xmout1). -; ; yes -; :- eval_examples. -; ; yes -; :- complete_chk. -; ; yes -; :- correct_chk. -; ; no -; :- fp(Xmout1). -; ; yes -; ; resulting rules selected -; :- refinement_add_body_literal(41,Xmout1). -; ; yes -; :- eval_examples. -; ; yes -; :- correct_chk. -; ; yes -; :- complete_chk. -; ; yes +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; +; ; ; diff --git a/miles/filter.metta b/miles/filter.metta index 3bafe10..92c6e00 100644 --- a/miles/filter.metta +++ b/miles/filter.metta @@ -1,5 +1,5 @@ ; -; MODULE filter EXPORTS +; !(module filter @@ -28,14 +28,18 @@ (/ noduplicate-symbol 2) (/ select-var-sharing-lits 2) (/ already-in 3))) +; + ; -; IMPORTS +; !(use-module-if-exists (library not) (:: (/ once 1))) +; + !(use-module-if-exists (library sets) (:: @@ -46,15 +50,21 @@ (/ subtract 3) (/ subset 2) (/ select 3))) +; + !(use-module-if-exists (library strings) (:: (/ string-append 3) (/ substring 4) (/ midstring 6))) +; + !(use-module-if-exists (library basics) (:: (/ member 2))) +; + !(use-module-if-exists (library lists) (:: @@ -62,18 +72,28 @@ (/ rev 2) (/ last 2) (/ nth1 4))) +; + !(use-module-if-exists (library occurs) (:: (/ sub-term 2))) +; + !(use-module-if-exists (library arg) (:: (/ genarg 3))) +; + !(use-module-if-exists (library subsumes) (:: (/ subsumes-chk 2))) +; + !(use-module (home div-utils) (:: (/ shares-var 2))) +; + !(use-module (home var-utils) (:: @@ -83,6 +103,8 @@ (/ deskolemize 3) (/ skolems 2) (/ flagged-contains-vars 3))) +; + !(use-module (home kb) (:: @@ -91,253 +113,269 @@ (/ delete-clause 1) (/ get-fact 4) (/ unflatten-kb 0))) +; + !(use-module (home flatten) (:: (/ flatten-clause 2) (/ unflatten-clause 2))) +; + !(use-module (home evaluation) (:: (/ correct-chk 0))) +; + ; -; METAPREDICATES +; ; -; none +; !(dynamic (/ functional-mode 1)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * module: filter.pl +; ; -; * +; ; -; * author: B.Jung, M.Mueller, I.Stahl, B.Tausend date:12/92 +; ; -; * +; ; -; * changed: +; ; -; * +; ; -; * description: various filters useful for td- and bu-induction +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; ; -; *********************************************************************** +; ; -; * predicate: already_in/3 (optional) +; ; -; * +; ; -; * syntax: already_in(+N,+P,+Y) +; ; -; * +; ; -; * args: N: arity of a literal P +; ; -; * P: literal +; ; -; * Y: term +; ; -; * +; ; -; * description: succeeds if Y is(==) already an argument of P +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (already-in 0 $_ $_) ( (set-det) (fail))) +; + (= (already-in $N $P $Y) ( (arg $N $P $Pn) (det-if-then-else (== $Pn $Y) True (, (is $N1 (- $N 1)) (already-in $N1 $P $Y))))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: select_var_sharing_lits/2 +; ; -; * +; ; -; * syntax: select_var_sharing_lits(+List_of_Clauses,-List_of_Clauses) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: removes all clauses from List_of_Clauses the last +; ; -; * literal of which does not share a variable with +; ; -; * the rest of the clause -> to be used during td-refinement +; ; -; * (not to add unconnected body literals) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (select_var_sharing_lits () ()) True) +; + (= (select-var-sharing-lits (Cons $C $R) $R2) ( (select-var-sharing-lits $R $R1) (det-if-then-else (var-sharing-lit $C Nil) (= $R2 (Cons $C $R1)) (= $R2 $R1)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: var_sharing_lit/2 +; ; -; * +; ; -; * syntax: var_sharing_lit(+Clause,+CAccu) +; ; -; * +; ; -; * args: CAccu contains all literals of clause except the last one +; ; -; * +; ; -; * description: succeeds if the last literal of clause shares (at least) +; ; -; * a variable with the rest of the clause. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -345,65 +383,71 @@ (var-sharing-lit (= $H $B) Nil) ( (set-det) (var-sharing-lit $B (:: $H)))) +; + (= (var-sharing-lit (, $A $B) $C) ( (set-det) (var-sharing-lit $B (Cons $A $C)))) +; + (= (var-sharing-lit $A $C) ( (shares-var $A $C) (set-det))) +; + ; -; *********************************************************************** +; ; -; * predicate: noduplicate_atom/2 +; ; -; * +; ; -; * syntax: noduplicate_atom(+P,+B) +; ; -; * +; ; -; * args: P: literal +; ; -; * B: clause body +; ; -; * +; ; -; * description: tests if P already occurs(==) in B +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -413,58 +457,62 @@ ( (set-det) (\== $P $A) (noduplicate-atom $P $B))) +; + (= (noduplicate-atom $P $A) (\== $P $A)) +; + ; -; *********************************************************************** +; ; -; * predicate: noduplicate_atoms/1 +; ; -; * +; ; -; * syntax: noduplicate_atoms(+Clause) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: tests whether Clause contains duplicate literals +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -473,93 +521,92 @@ ( (set-det) (noduplicate-atom $A $B) (noduplicate-atoms $B))) +; + (= (noduplicate-atoms (, $A $B)) ( (set-det) (noduplicate-atom $A $B) (noduplicate-atoms $B))) +; + (= - (noduplicate_atoms $_) True) + (noduplicate_symbols $_) True) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: connected_vars/4 +; ; -; * +; ; -; * syntax: connected_vars(+ClauseIn,-ClauseOut,-Connected,-Unconnected) +; ; -; * +; ; -; * args: ClauseIn,ClauseOut: clauses in list notation +; ; -; * Connected,Unconnected: list of variables +; ; -; * +; ; -; * description: returns connected & unconnected vars +; ; -; * A variable is connected ( to the head literal ) iff +; ; -; * - it appears in the head, or +; ; -; * - it appears in a literal with a connected variable +; ; -; * A literal is connected iff it's vars are. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: we make a copy of the input clause +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; +; (error +; (syntax_error operator_clash) +; (file miles/filter.pl 242 29 6845)) - (= - (connected-vars $ClauseIn $ClauseOut $Connected $Unconnected) - ( (copy-term $ClauseIn $ClauseIn1) - (skolemize $ClauseIn1 $S $Clause1) - (connected-skolems $Clause1 $C $U) - (deskolemize - (with_self $Clause1 - (with_self $C $U)) $S - (with_self $ClauseOut - (with_self $Connected $Unconnected))))) (= @@ -571,70 +618,72 @@ (= $Uncon Nil) (find-connected-skolems-in-body $Body $Con $Connected $Uncon $Unconnected_tupels) (union $Unconnected_tupels $Unconnected))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: find_connected_skolems_in_body/5 +; ; -; * +; ; -; * syntax: find_connected_skolems_in_body(+Body_list,+Connected,-Connected, +; ; -; * +Unconnected_tuples,-Unconnected_tuples) +; ; -; * +; ; -; * args: Body_list .. clause body in list notation, +; ; -; * Connected .. connected skolem atoms +; ; -; * Unconnected_tuples .. lists of lists of unconnected skolem atoms +; ; -; * +; ; -; * description: separates connected and unconnected skolem atoms +; ; -; * (each corresponds to a variable) within the body +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -655,12 +704,18 @@ (= $U3 (Cons $V1 $U1)))) (find-connected-skolems-in-body $Rest $C3 $C2 $U3 $U2))) +; + (= (find_connected_skolems_in_body () $C $C $U $U) True) +; + (= (connect $V $C $C () ()) True) +; + (= (connect $Vars $C1 $C2 (Cons $Tupel $More) $U2) @@ -669,127 +724,133 @@ (set-det) (union $C1 $Tupel $C3) (connect $Vars $C3 $C2 $More $U2))) +; + (= (connect $Vars $C1 $C2 (Cons $Tupel $More) (Cons $Tupel $U2)) (connect $Vars $C1 $C2 $More $U2)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: is_weakly_generative/1 +; ; -; * +; ; -; * syntax: is_weakly_generative(+Clause) +; ; -; * +; ; -; * args: Clause: clause in list notation +; ; -; * +; ; -; * description: a clause is weakly generative if all vars of its head +; ; -; * appear also in another literal +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: Muggleton,90 +; ; -; * +; ; -; *********************************************************************** +; (= (is-weakly-generative (Cons (with_self $H (p)) $B)) ( (vars $H $Vars) (contains-vars $Vars $B))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: is_stronly_generative/1 +; ; -; * +; ; -; * syntax: is_strongly_generative(+Clause) +; ; -; * +; ; -; * args: Clause: clausew in list notation +; ; -; * +; ; -; * description: a clause is strongly generative if every variable +; ; -; * appears in at least 2 literals +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: Muggleton,90 +; ; -; * +; ; -; *********************************************************************** +; @@ -803,136 +864,146 @@ (flagged-contains-vars $Vars $Rest $Flag)) $Flags) (not (member False $Flags)) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: is_connected/1 +; ; -; * +; ; -; * syntax: is_connected(+Clause) +; ; -; * +; ; -; * args: Clause: clause in list notation +; ; -; * +; ; -; * description: a clause is connected if every variable is connected +; ; -; * to the head. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: Rouveirol,91 +; ; -; * +; ; -; *********************************************************************** +; (= (is-connected $Clause) (connected-vars $Clause $_ $_ Nil)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: is_flat/1, is_unflat/1 +; ; -; * +; ; -; * syntax: is_flat(+Clause), is_unflat(Clause) +; ; -; * +; ; -; * args: clause in list notation [ head:p, b1:n, .. ] +; ; -; * +; ; -; * description: succeeds/fails if Clause contains no function symbols +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: if input is not a clause in list form, is_flat/1 +; ; -; * always succeeds. +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (is-flat $Clause) ( (nonvar $Clause) (not (is-unflat $Clause)))) +; + (= (is-unflat (Cons (with_self $L $_) $Rest)) (is-unflat-literal $L)) +; + (= (is-unflat (Cons $_ $Rest)) - (is-unflat $Rest)) + (is-unflat $Rest)) +; + (= @@ -941,73 +1012,75 @@ (\== $Subterm $L) (nonvar $Subterm) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: truncate/3 +; ; -; * +; ; -; * syntax: truncate(+Strategy,+ClauseIn,-ClauseOut) +; ; -; * +; ; -; * args: Strategy: one of { r, unconnected, unconnecting, +; ; -; * strongly_generative} +; ; -; * ClauseIn,ClauseOut: integers (kb references) +; ; -; * +; ; -; * description: performs truncation operator on ClauseIn +; ; -; * using Strategy. +; ; -; * +; ; -; * The list of possible strategies is to be completed. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1016,78 +1089,88 @@ ( (get-clause $In $_ $_ $C1 $_) (do-truncate $Strategy $C1 $C2) (store-clause $_ $C2 trunc $Out))) +; + (= (do-truncate r $C1 $C2) (truncate-r $C1 $C2)) +; + (= (do-truncate unconnected $C1 $C2) (truncate-unconnected $C1 $C2)) +; + (= (do-truncate strongly-generative $C1 $C2) (truncate-strongly-generative $C1 $C2)) +; + (= (do-truncate unconnecting $C1 $C2) - (truncate-unconnecting $C1 $C2)) + (truncate-unconnecting $C1 $C2)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: truncate_r/2/1 +; ; -; * +; ; -; * syntax: truncate_r(ClauseIn,ClauseOut) +; ; -; * truncate_r(ID) +; ; -; * +; ; -; * args: clauses in list notation +; ; -; * +; ; -; * description: drop all literals with label ':r', +; ; -; * i.e. drop all literals that were used in saturation. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1097,20 +1180,28 @@ (truncate-r $ClauseIn $ClauseOut) (delete-clause $ID) (store-clause $_ $ClauseOut trc $ID))) +; + (= (truncate-r $ClauseIn $ClauseOut) ( (copy-term $ClauseIn $C) (do-truncate-r $C $ClauseOut))) +; + (= (do_truncate_r () ()) True) +; + (= (do-truncate-r (Cons (with_self $L (r)) $Rest) $Rest1) ( (set-det) (do-truncate-r $Rest $Rest1))) +; + (= (do-truncate-r (Cons @@ -1118,67 +1209,69 @@ (Cons (with_self $L $S) $Rest1)) ( (set-det) (do-truncate-r $Rest $Rest1))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: truncate_flat_r/2/1 +; ; -; * +; ; -; * syntax: truncate_flat_r(ClauseIn,ClauseOut) +; ; -; * truncate_flat_r(ID) +; ; -; * +; ; -; * args: clauses in list notation +; ; -; * +; ; -; * description: drop all true literals with label ':r', +; ; -; * i.e. drop all literals that were used in saturation, +; ; -; * but no literals with type information ( suffix '_p'). +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1188,14 +1281,20 @@ (truncate-flat-r $ClauseIn $ClauseOut) (delete-clause $ID) (store-clause $_ $ClauseOut trc $ID))) +; + (= (truncate-flat-r $ClauseIn $ClauseOut) ( (copy-term $ClauseIn $C) (do-truncate-flat-r $C $ClauseOut))) +; + (= (do_truncate_flat_r () ()) True) +; + (= (do-truncate-flat-r (Cons @@ -1206,8 +1305,7 @@ (get-clause $_ $LC $_ $_ usr) (set-det) (do-truncate-flat-r $Rest $Rest1))) -; ; L is bg predicate - +; (= (do-truncate-flat-r @@ -1216,70 +1314,72 @@ (Cons (with_self $L $S) $Rest1)) ( (set-det) (do-truncate-flat-r $Rest $Rest1))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: truncate_unconnected/2 +; ; -; * +; ; -; * syntax: truncate_unconnected(+ClauseIn, -ClauseOut) +; ; -; * +; ; -; * args: ClauseIn,ClauseOut: clauses in list notation +; ; -; * +; ; -; * description: truncate unconnected body literals (see above) +; ; -; * +; ; -; * example: let ClauseIn = [ min(A,[A|B]):p, min(C,B):n, ge(E,F):n ] +; ; -; * then ClauseOut = [ min(A,[A|B]):p, min(C,B):n ] +; ; -; * let ClauseIn = [p(X):n,q(X,V1):n,r(V1,V2):n,q(V3):n,s(V3,V1):n], +; ; -; * then ClauseOut = [p(X):n,q(X,V1):n,r(V1,V2):n,q(V3):n,s(V3,V1):n] +; ; -; * (in contrast to truncate_unconnecting) +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1290,6 +1390,8 @@ (delete-clause $ID) (store-clause $_ $D trc-unconn $ID) (set-det))) +; + @@ -1307,16 +1409,22 @@ (with_self $Head (p)) $BodyOut)) (deskolemize $ClauseOutS $S $ClauseOut))) +; + (= - (truncate_unconnected1 () $_ ()) True) ; -; no literals to drop + (truncate_unconnected1 () $_ ()) True) +; + ; +; (= (truncate-unconnected1 $B Nil $B) - (set-det)) ; -; all vars connected + (set-det)) +; + ; +; (= (truncate-unconnected1 @@ -1329,10 +1437,7 @@ (, (member $A $Uncon) (truncate-unconnected1 $More $Uncon $BodyOut)) fail) (set-det))) -; ; either all or no vars in L are connected - -; ; local cut - +; (= (truncate-unconnected1 @@ -1341,79 +1446,81 @@ (Cons (with_self $L $S) $BodyOut)) ( (truncate-unconnected1 $More $Uncon $BodyOut) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: truncate_unconnecting/1/2 +; ; -; * +; ; -; * syntax: truncate_unconnecting(ClauseIn,ClauseOut) +; ; -; * +; ; -; * args: clauses in list notation +; ; -; * +; ; -; * description: connectivity heuristics for truncation: +; ; -; * Rouveirol: Drop a body literal if all other literals remain +; ; -; * connected. +; ; -; * We added another constraint: the resulting clause must be +; ; -; * weakly generative. +; ; -; * Do not confuse the connectivity with the connectedness +; ; -; * heuristics !! +; ; -; * +; ; -; * example: truncate_unconnecting([p(X):n,q(X,V1):n,r(V1,V2):n,q(V3):n,s(V3,V1):n], +; ; -; * [p(X):n,q(X,V1):n,r(V1,V2):n, s(V3,V1):n], +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: Rouveirol '90; module connectedness.pl +; ; -; * +; ; -; *********************************************************************** +; @@ -1424,6 +1531,8 @@ (delete-clause $ID) (store-clause $_ $D trc-unconn $ID) (set-det))) +; + (= (truncate-unconnecting $ClauseIn $ClauseOut) @@ -1439,67 +1548,66 @@ (p)) $BodyOut)) (connected-vars $ClauseOut1 $ClauseOut $Con Nil) (is-weakly-generative $ClauseOut))) -; ; no unconnected vars - +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: truncate_strongly_generative/2 +; ; -; * +; ; -; * syntax: truncate_strongly_generative(+ClauseIn,-ClauseOut) +; ; -; * +; ; -; * args: clauses in list notation +; ; -; * +; ; -; * description: drop one body literal from a strongly generative +; ; -; * clause s.t. the resulting clause is also strongly +; ; -; * generative. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1510,6 +1618,8 @@ (delete-clause $ID) (store-clause $_ $D trc-unconn $ID) (set-det))) +; + (= (truncate-strongly-generative $ClauseIn $ClauseOut) @@ -1524,70 +1634,72 @@ (with_self $H (p)) $BodyOut)) (is-strongly-generative $ClauseOut))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: truncate_neg_based/1 +; ; -; * +; ; -; * syntax: truncate_neg_based(+ID) +; ; -; * +; ; -; * args: integer, kb reference +; ; -; * +; ; -; * description: truncate as many literals as possible, s.t. the +; ; -; * resulting clause covers no negative examples. +; ; -; * +; ; -; * This only works on unflat clauses; +; ; -; * i.e. it only accounts for dropping condition. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also : Muggleton's negative based reduction +; ; -; * +; ; -; *********************************************************************** +; @@ -1605,12 +1717,16 @@ (= $D (Cons $H $Body)) (length $Body $N) - (truncate-neg-based1 $N $ID $H $Body))) + (truncate-neg-based1 $N $ID $H $Body))) +; + (= (truncate-neg-based1 0 $_ $_ $_) (set-det)) +; + (= (truncate-neg-based1 $N $ID $H $Body) @@ -1630,76 +1746,78 @@ (store-clause $_ (Cons $H $Body) trc $ID) (truncate-neg-based1 $M $ID $H $Body))))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: truncate_flat_neg_based/1 +; ; -; * +; ; -; * syntax: truncate_flat_neg_based(+ID) +; ; -; * +; ; -; * args: integer, kb reference +; ; -; * +; ; -; * description: truncate as many literals as possible, s.t. the +; ; -; * resulting clause covers no negative examples. +; ; -; * +; ; -; * As initial condition, the kb must be unflat. +; ; -; * The truncation is done on the flattened clause, so that +; ; -; * this accounts for the dropping rule & inverse subst. +; ; -; * On exiting, the kb is unflat. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also : Muggleton's negative based reduction +; ; -; * +; ; -; *********************************************************************** +; @@ -1720,6 +1838,8 @@ (, (delete-clause $ID) (store-clause $_ $C $Label $ID))))) +; + (= (truncate-flat-neg-based $ID $H $Nec Nil) @@ -1730,6 +1850,8 @@ (store-clause $_ $E trc $ID) (set-det) (correct-chk))) +; + (= @@ -1746,61 +1868,63 @@ (append $Nec (:: $L) $Nec1)) (truncate-flat-neg-based $ID $H $Nec1 $Maybe))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: truncate_facts/1 +; ; -; * +; ; -; * syntax: truncate_facts(+ID) +; ; -; * +; ; -; * args: integer, kb reference +; ; -; * +; ; -; * description: truncate all body literals unifying with a kb fact +; ; -; * labeled 'usr'. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1812,82 +1936,88 @@ (delete-clause $ID) (store-clause $_ (Cons $H $BodyOut) trc $ID))) +; + (= (truncate_facts1 () ()) True) +; + (= (truncate-facts1 (Cons (with_self $L $S) $Rest) $BodyOut) ( (truncate-facts1 $Rest $Rest1) (det-if-then-else (, (get-fact $_ $L1 $_ usr) (subsumes-chk $L1 $L)) (= $BodyOut $Rest1) (= $BodyOut (Cons (with_self $L $S) $Rest1))))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: truncate_j/2 +; ; -; * +; ; -; * syntax: truncate_j(+ID,J) +; ; -; * +; ; -; * args: ID: kb reference +; ; -; * J : integer = number of allowed new variables per literal +; ; -; * +; ; -; * description: truncate all literals containing more than J variables +; ; -; * not appearing in the head of kb clause ID. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: truncate_j is remotely related to Muggleton's +; ; -; * ij-determination. We take i = 1. +; ; -; * More importantly, we cannot tell in our system, if a +; ; -; * literal is determinate or not, since we have no model. +; ; -; * +; ; -; *********************************************************************** +; @@ -1907,6 +2037,8 @@ (truncate-unconnected $D $E) (delete-clause $ID) (store-clause $_ $E trc-j $ID))) +; + (= @@ -1915,5 +2047,7 @@ (, (member $L $BodyIn) (once (, (skolems $L $VarsL) (subtract $VarsL $Vars $NewVars) (length $NewVars $J1) (=< $J1 $J)))) $BodyOut)) +; + diff --git a/miles/flatten.metta b/miles/flatten.metta index 539c0e0..cf4777b 100644 --- a/miles/flatten.metta +++ b/miles/flatten.metta @@ -1,5 +1,5 @@ ; -; MODULE flatten EXPORTS +; !(module flatten @@ -12,235 +12,247 @@ (/ unflatten-clause 2) (/ flatten-clause 2) (/ unflatten-clause 3))) +; + ; -; IMPORTS +; !(use-module (home div-utils) (:: (/ clist-to-prolog 2) (/ list-to-struct 2))) +; + !(use-module-if-exists (library basics) (:: (/ member 2))) +; + !(use-module-if-exists (library strings) (:: (/ concat-symbol 3) (/ midstring 6) (/ substring 5))) +; + !(use-module-if-exists (library occurs) (:: (/ sub-term 2) (/ contains-var 2))) +; + ; -; METAPREDICATES +; ; -; none +; ; -; *********************************************************************** +; ; -; * +; ; -; * module: flatten.pl +; ; -; * +; ; -; * author: B.Jung, M.Mueller, I.Stahl, B.Tausend date:12/92 +; ; -; * +; ; -; * changed: +; ; -; * +; ; -; * description: Rouveirol's representation change to function free +; ; -; * Horn clauses. +; ; -; * Shared variables are deteced. +; ; -; * Following the later versions of flattening('90,'91) +; ; -; * identical terms are only represented once thru a +; ; -; * new body literal. The older version (1989) introduced +; ; -; * for each occurence of a term a unique new body literal. +; ; -; * ( the newer approach might not always be more adequate) +; ; -; * +; ; -; * peculiarities: In the process of flattening all literals that are +; ; -; * introduced for functions end with the suffix "_p". +; ; -; * In return, when unflattening a clause it is assumed +; ; -; * that every predicate symbol ending in "_p" stems from +; ; -; * a function. This assumption is made because the names +; ; -; * for functions and predicates need to be distinct. +; ; -; * +; ; -; * DON'T FLATTEN ANY CLAUSE CONTAINING LITERALS ENDING IN "_p" !!! +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: flatten_term/7 +; ; -; * +; ; -; * syntax: flatten_term(+Term, +NewVar , +OldSubstituion, +; ; -; * -NewSubstitution,+OldBackground, +; ; -; * -NewBackground, -Literals) +; ; -; * +; ; -; * args: Term: term to be replace by NewVar, e.g. [a,b] +; ; -; * NewVar: new variable +; ; -; * OldSubstitution: list of substitutions that have already +; ; -; * been performed while flattening a clause. +; ; -; * This way shared variables / terms are detected. +; ; -; * e.g. [], [ X/a , Y/[b] ] +; ; -; * NewSubstitution: = OldSubstitution + [ NewVar/Term ] +; ; -; * OldBackground: old list of predicate definitions +; ; -; * NewBackground: new ... +; ; -; * motivation: e.g. let term be "red". +; ; -; * the resulting literal is " red(X) " which is +; ; -; * true iff X=red. Therefore +; ; -; * NewBackground = OldBackground + [ red(red) ] +; ; -; * Literals: list of literals to replace function +; ; -; * +; ; -; * description: +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: can't flatten integers +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (flatten-term $Lin $Lout) (flatten-term $Lin $_ Nil $_ Nil $_ $Lout)) +; + ; -; flatten_term(+,-,+,-,+,-,-) +; ; -; known terms ; change: represent only vars once +; (= (flatten-term $Term $Var $S $S $Bg $Bg Nil) @@ -248,22 +260,23 @@ (/ $Var $Term1) $S) (== $Term $Term1) (set-det))) -; ; var(Term), ; new !!! - +; ; -; Variables +; ; -; flatten_term( X, V, S,[(V/X)|S],[]):- var(X),!. +; (= (flatten-term $X $X $S $S $Bg $Bg Nil) ( (var $X) (set-det))) +; + ; -; empty list +; (= (flatten-term Nil $V $S @@ -273,9 +286,11 @@ (nil-p Nil) $Bg) (:: (nil-p $V))) (set-det)) +; + ; -; other atoms +; (= (flatten-term $A $V $S @@ -291,9 +306,11 @@ (:: $Functor $V)) (=.. $B (:: $Functor $A)))) +; + ; -; integers +; (= (flatten-term $Int $V $S @@ -308,10 +325,12 @@ (:: $PredName $V)) (=.. $B (:: $PredName $Int)))) +; + ; -; list +; (= (flatten-term @@ -330,10 +349,12 @@ (= $Literals (Cons (cons-p $V1 $V2 $V) $Literals3)))) +; + ; -; other functions +; (= (flatten-term $Function $V $S $Snew $Bg @@ -356,14 +377,15 @@ (Cons $NewFunctor $BgArgs)) (= $Literals (Cons $Predicate $Literals1)))) -; ; build new predicate of arity n+1 - +; (= (flatten_args () () $S $S $Bg $Bg ()) True) +; + (= (flatten-args (Cons $A $Args) @@ -371,73 +393,79 @@ ( (flatten-term $A $V $S $Snew1 $Bg $Bg2 $L1) (flatten-args $Args $Vars $Snew1 $Snew $Bg2 $Bg1 $L2) (append $L1 $L2 $Literals))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: flatten_literal/2 +; ; -; * +; ; -; * syntax: flatten_literal(+Lit,-Lit_list) +; ; -; * +; ; -; * args: Lit .. Literal, Lit_list .. list of literals +; ; -; * +; ; -; * description: returns the list of literals Lit has to be replaced with +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (flatten-literal $In $Out) (flatten-literal $In Nil $_ Nil $_ $Out)) +; + ; -; flatten_literal(+,+,-,+,-,-) +; (= (flatten-literal True $S $S $Bg $Bg Nil) (set-det)) +; + (= (flatten-literal $Predicate $S $Snew $Bg $Bg1 $Literals) @@ -448,79 +476,81 @@ (Cons $Functor $Vars)) (= $Literals (Cons $NewPredicate $Literals1)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: flatten_literals/2 +; ; -; * +; ; -; * syntax: flatten_literals(+Body,+OldSubst,-NewSubst, +; ; -; * +OldBackground,-NewBackground,-Literals) +; ; -; * +; ; -; * args: Body.. clause body +; ; -; * OldSubst: list of substitutions that have already +; ; -; * been performed. +; ; -; * NewSubst: = OldSubst + additional substitutions for Body +; ; -; * OldBackground: old list of predicate definitions +; ; -; * NewBackground: new ... +; ; -; * Literals: list of literals to replace Body +; ; -; * +; ; -; * description: flattens clause body +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -531,68 +561,69 @@ (flatten-literal $A $S $Snew1 $Bg $Bg2 $Literals1) (flatten-literals $B $Snew1 $Snew $Bg2 $Bg1 $Literals2) (append $Literals1 $Literals2 $Literals))) -; ; cut, to prevent 2nd clause - +; (= (flatten-literals $A $S $Snew $Bg $Bg1 $Literals) (flatten-literal $A $S $Snew $Bg $Bg1 $Literals)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: flatten_clause/2 +; ; -; * +; ; -; * syntax: flatten_clause(+ClauseIn,-ClauseOut) +; ; -; * +; ; -; * args: clauses in MeTTa notation, i.e. ( head :- body ) +; ; -; * or list notation, i.e. [ head:p , b1:n, b2:n, ... ] +; ; -; * +; ; -; * description: flatten a clause +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -607,13 +638,14 @@ (flatten-clause $F $G) (clist-to-prolog $Out $G) (set-det))) -; ; list notation - +; (= (flatten-clause $In $Out) ( (flatten-clause $In Nil $_ Nil $_ $Out) (set-det))) +; + (= (flatten-clause $Clause $S $Snew $Bg $Bg1 $ClauseOut) @@ -629,92 +661,91 @@ (list-to-struct $Literals $StrucLits) (=.. $ClauseOut (:: :- $NewHead $StrucLits)))) -; ; flatten head - -; ; flatten body - +; ; -; ************************************************************************ +; ; -; * +; ; -; * predicates: substitute_in_literals/4 +; ; -; * substitute_in_literal/4 +; ; -; * substitute_args/4 +; ; -; * syntax: substitute_in_literals(+Var,+Term,+OldLiterals,-NewLiterals) +; ; -; * substitute_in_literal(+Var,+Term,+OldLiteral,-NewLiteral) +; ; -; * substitute_args(+Var,+Term,+OldArgs,-NewArgs) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: replaces all occurences of Var in OldLiterals with Term +; ; -; * and outputs NewLiterals. +; ; -; * Note that also occurences of Var in subterms of args are +; ; -; * detected. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; ; -; substitute all occurences of Var in LiteralIn by Term +; (= (substitute_in_literals $Var $Term () ()) True) +; + (= (substitute-in-literals $Var $Term (Cons $Lit1 $Lits) @@ -722,6 +753,8 @@ ( (set-det) (substitute-in-literal $Var $Term $Lit1 $Lit1new) (substitute-in-literals $Var $Term $Lits $Litsnew))) +; + (= @@ -731,9 +764,11 @@ (substitute-args $Var $Term $Vars $Args) (=.. $LiteralOut (Cons $Functor $Args)))) +; + ; -; substitute variables Vars in argument positions by Term if identical to Var +; (= @@ -743,6 +778,8 @@ ( (== $Var $V) (set-det) (substitute-args $Var $Term $Vs $Args))) +; + (= (substitute-args $Var $Term @@ -756,8 +793,7 @@ (=.. $Arg (Cons $Functor $SubArgs)) (substitute-args $Var $Term $Vs $Args))) -; ; Var is subterm of V - +; (= @@ -765,76 +801,80 @@ (Cons $V $Vs) (Cons $V $Args)) (substitute-args $Var $Term $Vs $Args)) +; + (= (substitute_args $Var $Term () ()) True) +; + ; -; ******************************************************************************* +; ; -; * +; ; -; * predicate: unflatten_clause/2 +; ; -; * +; ; -; * syntax: unflatten_clause(+FlatClause,-UnFlatClause) +; ; -; * +; ; -; * args: FlatClause : flattened clause (either in list or MeTTa notation) +; ; -; * UnFlatClause : unflattened clause +; ; -; * +; ; -; * description: Algorithm for unflattening: (Rouveirol,91.p131) +; ; -; * for each flattened predicate f_p(t1,..,tn,X) in the body of clause C +; ; -; * substitute all occurences of X by the functional term f(t1,..tn) +; ; -; * & drop f_p(t1,...,tn,X) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ******************************************************************************* +; @@ -846,6 +886,8 @@ (unflatten-clause1 $Head Nil $BodyListIn $Head1 $BodyListOut Nil Nil) (list-to-struct $BodyListOut $Body1) (set-det))) +; + (= @@ -859,79 +901,78 @@ (unflatten-clause $F $G) (clist-to-prolog $Out $G) (set-det))) -; ; list notation - +; ; -; ******************************************************************************* +; ; -; * +; ; -; * predicate: unflatten_clause/3 +; ; -; * +; ; -; * syntax: unflatten_clause(+FlatClause,?Bg,-UnFlatClause) +; ; -; * +; ; -; * args: FlatClause = ( Head:-Body) : flattened clause +; ; -; * Bg : optional background facts - not used yet +; ; -; * UnFlatClause : unflattened clause +; ; -; * +; ; -; * description: Algorithm for unflattening: (Rouveirol,91.p131) +; ; -; * for each flattened predicate f_p(t1,..,tn,X) in the body of clause C +; ; -; * substitute all occurences of X by the functional term f(t1,..tn) +; ; -; * & drop f_p(t1,...,tn,X) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ******************************************************************************* +; (= @@ -941,88 +982,90 @@ ( (list-to-struct $BodyListIn $Body) (unflatten-clause1 $Head Nil $BodyListIn $Head1 $BodyListOut Nil $Bg) (list-to-struct $BodyListOut $Body1))) +; + ; -; **************************************************************** +; ; -; * +; ; -; * predicate: unflatten_clause1/7 +; ; -; * +; ; -; * syntax: unflatten_clause1(+HeadIn,+BodyIn1,+BodyIn2,-HeadOut,-BodyOut1, +; ; -; * -BodyOut2,?Bg) +; ; -; * +; ; -; * args: +HeadIn (function free) head of flattened clause +; ; -; * +BodyIn1 +; ; -; * +BodyIn2 difference lists of body literals (flattened) +; ; -; * -HeadOut head of unflattened clause +; ; -; * -BodyOut1 +; ; -; * -BodyOut2 difference lists of body literals (unflattened) +; ; -; * ?Bg optional background knowledge - not used yet +; ; -; * +; ; -; * description: unflattens a clause ; +; ; -; * some variables are replaced by functions & +; ; -; * certain literals are dumped +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; **************************************************************** +; @@ -1041,12 +1084,7 @@ (substitute-in-literals $Var $Function $BodyIn1 $BodyInt1) (substitute-in-literals $Var $Function $Rest $BodyInt2) (unflatten-clause1 $HeadInt $BodyInt1 $BodyInt2 $HeadOut $BodyOut1 $BodyOut2 $Bg))) -; ; Literal was introduced by flattening - -; ; get first n args (Fargs) - -; ; substitute Var by Function in whole clause - +; @@ -1057,75 +1095,83 @@ (append $BodyIn1 (:: $Literal) $BodyInt1) (unflatten-clause1 $HeadIn $BodyInt1 $Rest $HeadOut $BodyOut1 $BodyOut2 $Bg))) +; + (= (unflatten_clause1 $Head $Body () $Head $Body () $Bg) True) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: map_function_to_pred/2 +; ; -; * +; ; -; * syntax: map_function_to_pred(+Function_symbol,-PredName) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: constructs a PredName Function_symbol_p for flattening +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (map-function-to-pred Nil nil-p) - (set-det)) ; -; [] -> nil + (set-det)) +; + ; +; (= (map-function-to-pred . cons-p) - (set-det)) ; -; lists + (set-det)) +; + ; +; (= (map-function-to-pred $Integer $PredName) @@ -1136,10 +1182,7 @@ (concat-atom (:: integer $Atom p) - $PredName) (set-det))) -; ; integers , e.g. 15 -> integer_15_p - -; ; spypoint, - +; (= (map-function-to-pred $Integer $PredName) @@ -1150,8 +1193,7 @@ (number-chars $Integer $List) (integer $Integer) (set-det))) -; ; integer_15_p -> 15 - +; (= (map-function-to-pred $FunctionName $PredName) @@ -1160,8 +1202,7 @@ (concat-atom (:: $FunctionName -p) $PredName) (set-det))) -; ; function symbols - +; (= (map-function-to-pred $FunctionName $PredName) @@ -1169,4 +1210,6 @@ (var $FunctionName) (midstring $PredName -p $FunctionName $_ 2 0) (set-det))) +; + diff --git a/miles/g1_ops.metta b/miles/g1_ops.metta index 90e2e9f..a1002df 100644 --- a/miles/g1_ops.metta +++ b/miles/g1_ops.metta @@ -1,5 +1,5 @@ ; -; MODULE g1_ops EXPORTS +; !(module g1-ops @@ -16,20 +16,19 @@ (/ g1-op 3) (/ g1-op 4) (/ apply-g1 2))) -; ; saturate with default depth - -; ; saturate with given maximum depth - +; ; -; IMPORTS +; !(use-module (home lgg) (:: (/ headed-lgg 3) (/ headed-lgg 4))) +; + !(use-module (home kb) (:: @@ -37,18 +36,24 @@ (/ store-clause 4) (/ delete-clause 1) (/ get-example 3))) +; + !(use-module (home var-utils) (:: (/ skolemize 3) (/ skolemize 4) (/ deskolemize 3))) +; + !(use-module (home div-utils) (:: (/ neg 2) (/ buildpar2 3) (/ efface 3))) +; + !(use-module (home bu-basics) (:: @@ -68,180 +73,190 @@ (/ assert-absorptions 2) (/ body 3) (/ ident-build-body 1))) +; + !(use-module (home show-utils) (:: (/ show-bodies 0))) +; + !(use-module (home interpreter) (:: (/ prove3 2) (/ prove4 3))) +; + !(use-module-if-exists (library basics) (:: (/ member 2))) +; + ; -; METAPREDICATES +; ; -; none +; ; -; *********************************************************************** +; ; -; * +; ; -; * module: g1_ops.pl +; ; -; * +; ; -; * author: B.Jung, M.Mueller, I.Stahl, B.Tausend date:12/92 +; ; -; * +; ; -; * changed: +; ; -; * +; ; -; * +; ; -; * description: - g1-Operator +; ; -; * Implementation of Ruediger Wirth's G1-operator for inverse +; ; -; * resolution corresponding to his 1989 PhD thesis. +; ; -; * - Absorption +; ; -; * All clauses induced by absorption are labelled "abs" in kb +; ; -; * - Rouveirol's saturation, with functions allowed as terms. +; ; -; * *Saturation: Maximum depth: given as input +; ; -; * default: 100 inverse resolution steps +; ; -; * *elementary saturation +; ; -; * - inverse derivate +; ; -; * Muggleton's inverse linear derivation, i.e. the +; ; -; * repeated application of the most specific v +; ; -; * (most specific absorption &most specific identification) +; ; -; * Induced clauses are marked invd +; ; -; * - identification +; ; -; * clauses induced by identification are labelled "idn" in kb +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; ; -; ********************************************************************************; +; ; -; * +; ; -; * predicate: g1_op/3, g1_op/4 +; ; -; * +; ; -; * syntax: g1_op ( +ResolventID, +Parent1ID, -Parent2ID ) +; ; -; * g1_op ( +ResolventID, +Parent1ID, -Parent2ID, + Label ) +; ; -; * +; ; -; * args: ResolventID, Parent1ID, Parent2ID .. clauseIDs +; ; -; * Label for Parent2ID (default: g11) +; ; -; * +; ; -; * description: given a resolvent and one parent clause, the second parent clause +; ; -; * is constructed +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ******************************************************************************** +; (= (g1-op $Res $Par1 $Par2) (g1-op $Res $Par1 $Par2 g11)) +; + (= (g1-op $Res $Par1 $Par2 $Label) ( (det-if-then-else @@ -260,71 +275,62 @@ (g1-build-clause $Reslit $Lpar2Sko) (deskolemize $Lpar2Sko $SS $Lpar2) (store-clause $_ $Lpar2 $Label $Par2))) -; ; clauses in list representation - -; ; not a clause with itself - -; ; skolemize resolvent - -; ; build parent2 - -; ; deskolemize - +; ; -; and store +; ; -; ********************************************************************************; +; ; -; * +; ; -; * predicate: extend_g1/2 +; ; -; * +; ; -; * syntax: extend_g1(+Ai_ID,-A_Id) +; ; -; * +; ; -; * args: clauseIDs +; ; -; * +; ; -; * description: locates suitable V's that are already available in the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ********************************************************************************; +; @@ -344,97 +350,96 @@ (, (delete-clause $A_id) (fail))))) -; ; heuristic - +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: apply_g1/2 +; ; -; * +; ; -; * syntax: apply_g1( + NewClauseId, - List_of_ResultIds ) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: One might want to use apply_g1/2 if a new clause of background +; ; -; * knowledge is added to the kb and the G1-operator is to be applied. +; ; -; * If there already is a suitable "V", it will be extended and the +; ; -; * lgg of two A's will be built. +; ; -; * +; ; -; * A +; ; -; * Bi / \ Bj +; ; -; * \ Ai Aj / +; ; -; * \ / \ / +; ; -; * Ci Cj +; ; -; * +; ; -; * If a clause A can be built as lgg of Ai and Aj (extend_g1/2), +; ; -; * Ai and Aj will be deleted. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -451,8 +456,7 @@ (addtolist $Bag))) (fail) (set-det))) -; ; use new clause as parent1 - +; (= (apply-g1 $Clause $_) @@ -466,93 +470,94 @@ (delete-clause $Par2) (addtolist $Bag))) (fail))) -; ; use new clause as resolvent - +; (= (apply-g1 $_ $List) (getlist $List)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: absorb/3 +; ; -; * +; ; -; * syntax: absorb(+ExID, ?Parent1ID, -NewID) +; ; -; * +; ; -; * args: ExID: ID of example clause +; ; -; * Parent1ID: id of known parent clause +; ; -; * NewID: ID of absorption of example clause +; ; -; * +; ; -; * description: apply one absorption step on input clause ExID; +; ; -; * if Parent1ID is given, it is tried to perform the +; ; -; * absorption step with it as known parent. +; ; -; * Otherwise absorption will be performed with the first +; ; -; * applicable background clause. +; ; -; * It is made sure that no 2 literals of a parent +; ; -; * clause abs_match the same literal in the resolvent. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: no inverse subsitution yet +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; ; -; parent given +; (= @@ -577,11 +582,13 @@ (p)) $Body)) (deskolemize $NewClauseS $S $NewClause) (store-clause $_ $NewClause abs $NewID))) +; + ; -; parent not given +; (= (absorb $ExID $PID $NewID) @@ -605,67 +612,69 @@ (p)) $Body)) (deskolemize $NewClauseS $S $NewClause) (store-clause $_ $NewClause abs $NewID))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: abs_match/3 +; ; -; * +; ; -; * syntax: abs_match(+ExID,-Mark,-Proofs) +; ; -; * +; ; -; * args: ExID: Id of the resolvent +; ; -; * Mark in {success,fail} +; ; -; * Proofs = [CL,...] where CL is a clause in list notation +; ; -; * +; ; -; * description: returns all (instantiated) clauses that can be embedded in the +; ; -; * skolemized example clause (stored in kb with head/3,body/3) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -678,6 +687,8 @@ (, (= $Proofs Nil) (= $Mark fail)))) +; + (= @@ -691,61 +702,63 @@ (p)) $Body) usr) (\== $I $ExId) (prove3 $Body $Proof))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: abs_match1/3 +; ; -; * +; ; -; * syntax: abs_match1(+PID,-Mark,-Proofs) +; ; -; * +; ; -; * args: PID: ID of a parent clause +; ; -; * +; ; -; * description: as abs_match, except for the fixed parent clause that +; ; -; * is embedded in the resolvent +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -758,6 +771,8 @@ (, (= $Proofs Nil) (= $Mark fail)))) +; + (= @@ -769,89 +784,91 @@ (Cons (with_self $Goal (p)) $Body) $_) (prove3 $Body $Proof))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: identify/3 +; ; -; * +; ; -; * syntax: identify(+ExID, ?Parent1ID, -NewID) +; ; -; * +; ; -; * args: ExID: ID of example clause +; ; -; * Parent1ID: id of known parent clause +; ; -; * NewID: ID of identification of example clause +; ; -; * +; ; -; * description: apply one identification step on input clause ExID; +; ; -; * if Parent1ID is given, it is tried to perform the +; ; -; * identification step with it as known parent. +; ; -; * Otherwise identification will be performed with the +; ; -; * first applicable background clause. +; ; -; * It is made sure that no 2 literals of a parent +; ; -; * clause ident_match the same literal in the resolvent. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: no inverse subsitution yet +; ; -; * no backtraking +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; ; -; parent given +; (= @@ -871,11 +888,13 @@ (p)) $Body1)) (deskolemize $NewClauseS $S $NewClause) (store-clause $_ $NewClause idn $NewID))) +; + ; -; parent not given +; (= (identify $ExID $PID $NewID) @@ -893,83 +912,82 @@ (p)) $Body1)) (deskolemize $NewClauseS $S $NewClause) (store-clause $_ $NewClause idn $NewID))) -; ; show_bodies, - +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: ident_match/3 +; ; -; * +; ; -; * syntax: ident_match(+ExID,-Mark,-Proofs) +; ; -; * +; ; -; * args: ExID: ID of the resolvent +; ; -; * Mark in {success,fail} +; ; -; * Proofs = [P1,..,Pm], where Pi=[Uncovered:Proof] and +; ; -; * Uncovered = Lit/M (M in {new_head,new_body}), Proof = [[Lit,N],...] +; ; -; * (N in {head,body} +; ; -; * +; ; -; * description: matches clauses in kb against skolemized resolvent (stored +; ; -; * in kb with head/3,body/3), Uncovered is the resolution +; ; -; * literal that might be positive (new_head) or negative +; ; -; * (new_body) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -982,6 +1000,8 @@ (, (= $Proofs Nil) (= $Mark fail)))) +; + @@ -991,61 +1011,63 @@ ( (get-clause $I $_ $_ $Clause usr) (\== $I $ExId) (prove4 $Clause $Uncovered $Proof))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: ident_match1/3 +; ; -; * +; ; -; * syntax: ident_match1(+PID,-Mark,-Proofs) +; ; -; * +; ; -; * args: PID ...parentID, Mark,Proofs as for ident_match +; ; -; * +; ; -; * description: as ident_match, except for the parent clause to be matched +; ; -; * against the resolvent is given +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1058,6 +1080,8 @@ (, (= $Proofs Nil) (= $Mark fail)))) +; + @@ -1065,103 +1089,105 @@ (ident-match1a $PID (:: (with_self $Uncovered $Proof))) ( (get-clause $PID $_ $_ $Clause $_) (prove4 $Clause $Uncovered $Proof))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicates: inv_derivate/2/3 +; ; -; * +; ; -; * syntax: inv_derivate(+ExID,-NewID) +; ; -; * inv_derivate(+ExID,+PrefHead,-NewID) +; ; -; * +; ; -; * args: ExID : id of example +; ; -; * NewID: id of expanded example +; ; -; * PrefHead: a MeTTa literal +; ; -; * +; ; -; * description: Muggleton's inverse linear derivation +; ; -; * But: +; ; -; * while in intermediate stages several head literals +; ; -; * might appear simultanously, the result will always +; ; -; * be a Horn clause. As head literal we choose the +; ; -; * latest one derived in inv_derivate/2. +; ; -; * inv_derivate/3 takes as additional argument +; ; -; * a literal, which is interpreted as a preferred +; ; -; * head. If it is possible, inv_derivate/3 results +; ; -; * in a Horn clause where the head matches this +; ; -; * literal. +; ; -; * The operator is restricted to finding clauses at most +; ; -; * 100 inverse resolution steps away. +; ; -; * +; ; -; * example: inv_derivate(1, member(A,B), ID) +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1181,6 +1207,8 @@ (deskolemize $Clause1 $S $Clause) (store-clause $_ $Clause invd $NewID) (set-det))) +; + (= @@ -1194,6 +1222,8 @@ (deskolemize $Clause1 $S $Clause) (store-clause $_ $Clause invd $NewID) (set-det))) +; + (= @@ -1212,73 +1242,75 @@ (is $J (+ $I 1)) (inv-derivate1 $ExID $J)) True))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: idev_match0/4 +; ; -; * +; ; -; * syntax: idev_match0(+ExID,-Clause,-Uncovered,-Proof) +; ; -; * +; ; -; * args: ExID: ID of the resolvent +; ; -; * Clause: clause in list notation +; ; -; * Uncovered: Lit/M, where M in {new_head,new_body} +; ; -; * Proof: [[Lit,N],...] where N in {head,body} +; ; -; * +; ; -; * description: matches clause on skolemized resolvent (stored in kb +; ; -; * with head/3, body/3), and returns the instantiation +; ; -; * of clause and the resolution literal (Uncovered) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1287,100 +1319,102 @@ ( (get-clause $ID $_ $_ $Clause $_) (\== $ExID $ID) (prove4 $Clause $Uncovered $Proof))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: most_spec_v/3 +; ; -; * +; ; -; * syntax: most_spec_v(+ExID, ?PID, -NewID) +; ; -; * +; ; -; * args: ExID: id of example (resolvent) +; ; -; * PID: id of known parent +; ; -; * NewID: id of new clause +; ; -; * +; ; -; * description: +; ; -; * Apply one most-spec-v operation to example with parent PID; +; ; -; * If PID is not given, take the first applicable clause +; ; -; * of bg as parent. +; ; -; * The most specific v comprises the most specific absorption +; ; -; * and the most specific identification. +; ; -; * Since we always want Horn clauses as a result, this operator +; ; -; * does not implement the most specific identification as +; ; -; * described by Muggleton: Instead of adding a second head +; ; -; * literal to the old clause, we replace the original head. +; ; -; * I.e. our most specific identification operator is destructive. +; ; -; * The most specific absorption remains nondestructive +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarites: +; ; -; * +; ; -; * see also: inv_derivate/2 where multiple head literals are +; ; -; * allowed om intermediate stages. +; ; -; * +; ; -; *********************************************************************** +; @@ -1402,71 +1436,70 @@ (idev-build-clause $_ $Clause1) (deskolemize $Clause1 $S $Clause) (store-clause $_ $Clause msv $NewID))) -; ; Uncovered \== [], - +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: idev_match1/5 +; ; -; * +; ; -; * syntax: idev_match1(+ExID,-Clause,-Uncovered,-Proof,-ID) +; ; -; * +; ; -; * args: ExID: ID of the resolvent, ID: ID of matched clause +; ; -; * Clause: clause in list notation +; ; -; * Uncovered: Lit/M, where M in {new_head,new_body} +; ; -; * Proof: [[Lit,N],...] where N in {head,body} +; ; -; * +; ; -; * description: is like idev_match0/4, but returns id of absorbed clause +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1475,157 +1508,158 @@ ( (get-clause $ID $_ $_ $Clause $_) (\== $ExID $ID) (prove4 $Clause $Uncovered $Proof))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: saturate/2,saturate/3 +; ; -; * +; ; -; * syntax: saturate(+ExID, -NewID), saturate(+ExID,-NewID,+Bound) +; ; -; * +; ; -; * args: ExID: ID of example clause +; ; -; * NewID: ID of saturation of example clause +; ; -; * +; ; -; * description: apply elementary saturation w.r.t. background +; ; -; * clauses. +; ; -; * It is bounded by at most 100 iterations, if bound is not given +; ; -; * When checking the preconditions for firing one +; ; -; * absorption step, +; ; -; * it is made sure that no 2 literals of a parent +; ; -; * clause subsume the same literal in the resolvent. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (saturate $ExID $GenID) (saturate $ExID $GenID 100)) +; + (= (saturate $ExID $GenID $Bound) ( (saturate1 $ExID $NewClause $Bound) (store-clause $_ $NewClause sat $GenID) (set-det))) -; ; Rouveirol's theorem proving alg. - -; ; write(NewClause),nl, - +; ; -; no backtracking +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: saturate1/3 +; ; -; * +; ; -; * syntax: saturate1(+ExID,-NewClause,+Bound) +; ; -; * +; ; -; * args: ExID .. ID of example clause, NewClause .. MeTTa clause in list notation, +; ; -; * Bound .. bound for interations +; ; -; * +; ; -; * description: saturates example clause w.r.t. background knowledge. +; ; -; * It is bounded by at most Bound interations. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1645,73 +1679,72 @@ (body $A $I $M))) $NewBody1) (sat-build-clause $H $NewBody1 $Clause1) (deskolemize $Clause1 $S1 $NewClause))) -; ; Clause in list notation - +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: saturate1a/5 +; ; -; * +; ; -; * syntax: saturate1a(+HS,+Count,+Bound,+Subst,-Subst) +; ; -; * +; ; -; * args: HS: skolemized head of the example clause, +; ; -; * Count,Bound: integers +; ; -; * Subst: skolem subtitutions +; ; -; * +; ; -; * description: while Count < Bound, all heads following from the saturated +; ; -; * clause so far (stored as body(Lit,_,_)) are asserted as +; ; -; * additional body-literals (via body/3) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1730,66 +1763,70 @@ (+ $I 1)) (saturate1a $HS $J $Bound $S3 $S2)) (= $S2 $S3)))) +; + (= (saturate1a $_ $_ $_ $S $S) (set-det)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: sat_match/3 +; ; -; * +; ; -; * syntax: sat_match(+HS,-M,-Proofs) +; ; -; * +; ; -; * args: HS: skolemized head of the example clause +; ; -; * Proofs = [CL,...] where each CL is a clause in list notation +; ; -; * +; ; -; * description: finds all possible proofs for all possible absorptions +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1803,6 +1840,8 @@ (, (= $Proofs Nil) (= $Mark fail)))) +; + (= @@ -1816,89 +1855,91 @@ (p)) $Body) $_) (prove3 $Body $ProofBody) (\== $Goal $HS))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: elem_saturate/3 +; ; -; * +; ; -; * syntax: elem_saturate( +ExID, ?PID, -NewID) +; ; -; * +; ; -; * args: ExID: id of resolvent +; ; -; * PID : id of parent in bg +; ; -; * NewID: id of new parent +; ; -; * +; ; -; * description: +; ; -; * Add head of parent from bg to body of resolvent. +; ; -; * The Operator is identical to Muggleton's +; ; -; * most-specific-absorption. +; ; -; * When checking the preconditions for firing one +; ; -; * absorption step, +; ; -; * it is made sure that no 2 literals of a parent +; ; -; * clause subsume the same literal in the resolvent. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; ; -; parent given +; (= @@ -1924,10 +1965,12 @@ (sat-build-clause $H $NewBody $Clause1) (deskolemize $Clause1 $S $NewClause) (store-clause $_ $NewClause esat $NewID))) +; + ; -; parent not given +; (= (elem-saturate $ExID $PID $NewID) @@ -1951,58 +1994,60 @@ (sat-build-clause $H $NewBody $Clause1) (deskolemize $Clause1 $S $NewClause) (store-clause $_ $NewClause esat $NewID))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: sat_match1/3 +; ; -; * +; ; -; * syntax: sat_match1(+ExID,-Proof,-ID) +; ; -; * +; ; -; * args: ExID,ID: clauseIDs, Proofs: clause in list notation +; ; -; * +; ; -; * description: is like sat_match0/2, but returns id of absorbed clause +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2017,5 +2062,7 @@ (p)) $Body) $_) (\== $I $Ex) (prove3 $Body $ProofBody))) +; + diff --git a/miles/g2_ops.metta b/miles/g2_ops.metta index a0e73c0..18583f0 100644 --- a/miles/g2_ops.metta +++ b/miles/g2_ops.metta @@ -1,5 +1,5 @@ ; -; MODULE g2_ops EXPORTS +; !(module g2-ops @@ -14,22 +14,11 @@ (/ apply-g2 5) (/ apply-g2 3) (/ apply-g2 2))) -; ; ITOU-like - -; ; give name of new pred - -; ; give name & bound for common generalizations - -; ; CIGOL-like - -; ; give name of new pred - -; ; give name & bound for common generalizations - +; ; -; IMPORTS +; !(use-module (home lgg) @@ -38,8 +27,10 @@ (/ lgg 5) (/ buildlgg 4) (/ gti 5) - (/ lgti 5))) ; -; ;;diese f"ur lgti/6 ersetzen (ohne Bound) + (/ lgti 5))) +; + ; +; !(use-module (home kb) @@ -48,6 +39,8 @@ (/ store-clause 4) (/ delete-clause 1) (/ delete-all 1))) +; + !(use-module (home var-utils) (:: @@ -61,201 +54,223 @@ (/ findargs 3) (/ allarg 4) (/ buildrelterms 6))) +; + !(use-module (home div-utils) (:: (/ effaceall 3) (/ genterm-test 2))) +; + !(use-module (home g1-ops) (:: (/ g1-op 4))) +; + !(use-module (home environment) (:: (/ oracle 2) (/ confirm 2) (/ get-ci 2))) +; + !(use-module (home evaluation) (:: (/ complexity 2))) +; + !(use-module-if-exists (library strings) (:: (/ gensym 2))) +; + !(use-module-if-exists (library basics) (:: (/ member 2))) +; + !(use-module-if-exists (library sets) (:: (/ subtract 3))) +; + !(use-module-if-exists (library not) (:: (/ once 1))) +; + ; -; METAPREDICATES +; ; -; none +; ; -; *********************************************************************** +; ; -; * +; ; -; * module: g2_ops.pl +; ; -; * +; ; -; * author: B.Jung, M.Mueller, I.Stahl, B.Tausend date:12/92 +; ; -; * +; ; -; * changed: +; ; -; * +; ; -; * description: Intra-Construction, G2 +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: intra_construct1/5/6/7 +; ; -; * +; ; -; * syntax: intra_construct1(+C1,+C2,-A,-B1,-B2) +; ; -; * intra_construct1(+C1,+C2,-A,-B1,-B2,PName) +; ; -; * intra_construct1(+C1,+C2,-A,-B1,-B2,PName,Bound) +; ; -; * +; ; -; * args: C1,C2,A,B1,B2: references to clauses in kb +; ; -; * PName: atom - name of invented predicate +; ; -; * Bound: integer +; ; -; * +; ; -; * description: intra-construction where C1,C2 are at bottom of W, +; ; -; * A at the center top, B1,B2 at outside top positions. +; ; -; * S1(A) in C1, S2(A) in C2; the substitutions +; ; -; * between Bi & Ci are empty. +; ; -; * Uses an ITOU-like heursitics for determining relevant +; ; -; * variables for the new predicate +; ; -; * Our intra-construction will only work, if the two +; ; -; * input clauses require the same number of arguments +; ; -; * for the newly invented predicate. +; ; -; * This restriction is not part of the original +; ; -; * definition of intra-construction, but its at least +; ; -; * a very useful heuristics. If the restriction does not +; ; -; * fit your needs, change it in relevant_vars/3, +; ; -; * module "var_utils.pl". +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: backtracking over lgti/6 until the same number +; ; -; * of arguments is reached. +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (intra-construct1 $IDC1 $IDC2 $IDA $IDB1 $IDB2) ( (gensym new-pred $NewPred) (intra-construct1 $IDC1 $IDC2 $IDA $IDB1 $IDB2 $NewPred))) +; + (= (intra-construct1 $IDC1 $IDC2 $IDA $IDB1 $IDB2 $NewPred) - (intra-construct1 $IDC1 $IDC2 $IDA $IDB1 $IDB2 $NewPred 10)) + (intra-construct1 $IDC1 $IDC2 $IDA $IDB1 $IDB2 $NewPred 10)) +; + (= (intra-construct1 $IDC1 $IDC2 $IDA $IDB1 $IDB2 $NewPred $Bound) @@ -265,113 +280,106 @@ (set-det) (lgti $C1 $C2 $G $S1 $S2 $Bound) (once (, (relevant-vars3 $C1 $C2 $G $S1 $S2 $Vars) (=.. $NewLit (Cons $NewPred $Vars)) (append $G (:: (with_self $NewLit (n))) $A) (copy-term (, $C1 $G $S1 $NewLit) (, $C11 $G11 $S11 $NewLit11)) (skolemize (, $C11 $G11 $S11 $NewLit11) $Phi1 (, $C12 $G12 $S12 $NewLit12)) (replace $G12 $S12 $G13 $S12) (replace (:: $NewLit12) $S12 (:: $NewLit13) $S12) (subtract $C12 $G13 $B1BodyS) (= $B1S (Cons (with_self $NewLit13 (p)) $B1BodyS)) (deskolemize $B1S $Phi1 $B1) (copy-term (, $C2 $G $S2 $NewLit) (, $C21 $G21 $S21 $NewLit21)) (skolemize (, $C21 $G21 $S21 $NewLit21) $Phi2 (, $C22 $G22 $S22 $NewLit22)) (replace $G22 $S22 $G23 $S22) (replace (:: $NewLit22) $S22 (:: $NewLit23) $S22) (subtract $C22 $G23 $B2BodyS) (= $B2S (Cons (with_self $NewLit23 (p)) $B2BodyS)) (deskolemize $B2S $Phi2 $B2) (store-clause $_ $A ic $IDA) (store-clause $_ $B1 ic $IDB1) (store-clause $_ $B2 ic $IDB2))))) -; ; G is common generalization - -; ;;; ITOU - like - -; ; build clause in center top - -; ; build clause at top left - -; ; - -; ; build clause at top right - +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: intra_construct2/5/6/7 +; ; -; * +; ; -; * syntax: intra_construct2(+C1,+C2,-A,-B1,-B2) +; ; -; * intra_construct2(+C1,+C2,-A,-B1,-B2,PName) +; ; -; * intra_construct2(+C1,+C2,-A,-B1,-B2,PName,Bound) +; ; -; * +; ; -; * args: C1,C2,A,B1,B2: references to clauses in kb +; ; -; * PName: atom - name of invented predicate +; ; -; * Bound: integer +; ; -; * +; ; -; * description: intra-construction where C1,C2 are at bottom of W, +; ; -; * A at the center top, B1,B2 at outside top positions. +; ; -; * S1(A) in C1, S2(A) in C2; the substitutions +; ; -; * between Bi & Ci are empty. +; ; -; * Uses a CIGOL-like heursitics for determining relevant +; ; -; * variables for the new predicate +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: backtracking over lgti/6 until the same number +; ; -; * of arguments is reached. +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (intra-construct2 $IDC1 $IDC2 $IDA $IDB1 $IDB2) ( (gensym new-pred $NewPred) (intra-construct2 $IDC1 $IDC2 $IDA $IDB1 $IDB2 $NewPred))) +; + (= (intra-construct2 $IDC1 $IDC2 $IDA $IDB1 $IDB2 $NewPred) - (intra-construct2 $IDC1 $IDC2 $IDA $IDB1 $IDB2 $NewPred 10)) + (intra-construct2 $IDC1 $IDC2 $IDA $IDB1 $IDB2 $NewPred 10)) +; + (= (intra-construct2 $IDC1 $IDC2 $IDA $IDB1 $IDB2 $NewPred $Bound) @@ -381,113 +389,102 @@ (set-det) (lgti $C1 $C2 $G $S1 $S2 $Bound) (once (, (relevant-vars2 $C1 $C2 $G $S1 $S2 $Vars) (=.. $NewLit (Cons $NewPred $Vars)) (append $G (:: (with_self $NewLit (n))) $A) (copy-term (, $C1 $G $S1 $NewLit) (, $C11 $G11 $S11 $NewLit11)) (skolemize (, $C11 $G11 $S11 $NewLit11) $Phi1 (, $C12 $G12 $S12 $NewLit12)) (replace $G12 $S12 $G13 $S12) (replace (:: $NewLit12) $S12 (:: $NewLit13) $S12) (subtract $C12 $G13 $B1BodyS) (= $B1S (Cons (with_self $NewLit13 (p)) $B1BodyS)) (deskolemize $B1S $Phi1 $B1) (copy-term (, $C2 $G $S2 $NewLit) (, $C21 $G21 $S21 $NewLit21)) (skolemize (, $C21 $G21 $S21 $NewLit21) $Phi2 (, $C22 $G22 $S22 $NewLit22)) (replace $G22 $S22 $G23 $S22) (replace (:: $NewLit22) $S22 (:: $NewLit23) $S22) (subtract $C22 $G23 $B2BodyS) (= $B2S (Cons (with_self $NewLit23 (p)) $B2BodyS)) (deskolemize $B2S $Phi2 $B2) (store-clause $_ $A ic $IDA) (store-clause $_ $B1 ic $IDB1) (store-clause $_ $B2 ic $IDB2))))) -; ; G is common generalization - -; ;;; CIGOL - like - -; ; build clause in center top - -; ; build clause at top left - -; ; - -; ; build clause at top right - +; ; -; ******************************************************************************** +; ; -; * +; ; -; * predicate: g2_op/5 +; ; -; * +; ; -; * syntax: g2_op ( + C1_ID, + C2_ID, - A_ID, - B1_ID, - B2_ID) +; ; -; * +; ; -; * args: Ci_ID ... IDs of resolvent clauses C1 and C2 to be generalized +; ; -; * A_ID ... ID of common parent clause A +; ; -; * Bi_ID ... IDs of corresponding parent clauses B1 and B2 +; ; -; * +; ; -; * description: Implementation of Ruediger Wirth's G2-operator for inverse +; ; -; * resolution corresponding to his 1989 PhD thesis. +; ; -; * We generalize the Ci using Plotkin's LGG, then build a new +; ; -; * predicate as resolution literal, find the argument terms for the +; ; -; * new predicate (in a heuristic manner) and finally build the Bi +; ; -; * using our well-known G1-operator. +; ; -; * The compression achieved is evaluated thru a simple, though quite +; ; -; * sophisticated complexity heuristic (cf. module 'complexity'). +; ; -; * If the resulting clauses show some compression, the are passed +; ; -; * to the oracle for confirmation and the user gets a chance to +; ; -; * rename the new predicate. +; ; -; * Clauses which become obsolete during the process will be deleted. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: The procedure 'inv_replace' might yield unsatisfying results, +; ; -; * due to the possible ambiguity of inverse substitution. +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ******************************************************************************** +; @@ -521,125 +518,116 @@ (nl) (fail))) (delete-clause $A)))) -; ; Clgg = A\{L} - -; ; heuristic proc. - -; ; Terms = List of Args for L - -; ; L = resolution literal - -; ; Alist = parentclause A - -; ; Bi = parentclauses - +; ; -; ******************************************************************************** +; ; -; * +; ; -; * predicate: apply_g2/3 - tries to apply the G2-operator to a set of clauses Ci. +; ; -; * The output will be a kb reference of the common parent +; ; -; * clause A and a list of id's for parent clauses Bi. +; ; -; * +; ; -; * Bi A Bj +; ; -; * \ / \ / +; ; -; * \ / \ / +; ; -; * Ci Cj +; ; -; * apply_g2/2 - ORACLE is asked to enter the Id's of resolvent clauses +; ; -; * Ci one by one. This continues until oracle says 'stop'. +; ; -; * Doubles and answers which are not a number are ignored. +; ; -; * Finally apply_g2/3 is called. +; ; -; * apply_g2/5 - simply calls g2_op/5 +; ; -; * +; ; -; * syntax: apply_g2( + CC, - A, -BB), apply_g2( - A, -BB), +; ; -; * apply_g2 ( + C1_ID, + C2_ID, - A_ID, - B1_ID, - B2_ID) +; ; -; * +; ; -; * args: CC ... Id-list of resolvent clauses Ci to be generalized +; ; -; * A ... Id of common parent clause A +; ; -; * BB ... Id-list of corresponding parent clauses Bi +; ; -; * C_ID, A_ID, B_ID .. as for g2_op/5 +; ; -; * +; ; -; * description: +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ********************************************************************************; +; (= (apply-g2 $C1 $C2 $A $B1 $B2) ( (g2-op $C1 $C2 $A $B1 $B2) (set-det))) +; + (= @@ -647,6 +635,8 @@ ( (get-ci Nil $CC) (apply-g2 $CC $A $BB) (set-det))) +; + (= @@ -688,6 +678,8 @@ (delete-all $BB) (delete-clause $A) (fail))))) +; + @@ -703,72 +695,61 @@ (setargs $N $T $L) (buildparentA $Clgg $L $Alist) (store-clause $_ $Alist g2 $A))) -; ; Clgg = A\{L} - -; ; T = List of Args for L - -; ; heuristic proc. - -; ; Name = common for all L's - -; ; L = resolution literal - -; ; parentclause A - +; ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: not_unary/1 +; ; -; * +; ; -; * syntax: not_unary(+CL) +; ; -; * +; ; -; * args: CL .. clause in list representation +; ; -; * +; ; -; * description: fails, if CL is a unary clause or a unary goal +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; @@ -778,69 +759,75 @@ (write 'No compression achievable.') (set-det) (fail))) +; + (= - (not-unary (:: (with_self (True) (p)) $_)) + (not-unary (:: (with_self (True *) (p)) $_)) ( (nl) (write 'No compression achievable.') (set-det) (fail))) +; + (= (not_unary $_) True) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: buildreslit/2 +; ; -; * +; ; -; * syntax: buildreslit(+TermList,-Lit) +; ; -; * +; ; -; * args: TermList is the list of relevant argument terms, Lit is the resolution +; ; -; * literal (with a new predicate symbol) +; ; -; * +; ; -; * description: constructs the resolution literal +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; @@ -850,11 +837,15 @@ (gensym new-p $F) (functor $L $F $N) (setargs $N $T $L))) +; + (= (setargs 0 Nil $_) (set-det)) +; + (= (setargs $N (Cons $Arg1 $Rest) $L) @@ -862,67 +853,69 @@ (is $M (- $N 1)) (setargs $M $Rest $L))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: buildparentA/3 +; ; -; * +; ; -; * syntax: buildparentA(+A_L,+Lit,-AL) +; ; -; * +; ; -; * args: A_L ... A\{Lit} the lgg of C1 and C2 +; ; -; * Lit ... the new predicate literal +; ; -; * AL ... A\{Lit} + {Lit} +; ; -; * +; ; -; * description: adds the new predicate literal Lit either as head or +; ; -; * as body literal to A_L +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; @@ -930,71 +923,75 @@ (buildparentA (Cons (with_self - (True) + (True *) (p)) $Rest) $L (Cons (with_self $L (p)) $Rest)) (set-det)) +; + (= (buildparentA $List $L $Alist) ( (append $List (:: (with_self $L (n))) $Alist) (set-det))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: compression_heuristic/2 +; ; -; * +; ; -; * syntax: compression_heuristic(+NewIDs,+OldIDs) +; ; -; * +; ; -; * args: NewIDs, OldIDs ... clauseIDs +; ; -; * +; ; -; * description: succeeds if the size of the clauses NewIDs is smaller +; ; -; * than that of the clauses OldIDs +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; @@ -1007,4 +1004,6 @@ (, (delete-all $New_cl) (fail))))) +; + diff --git a/miles/gencon.metta b/miles/gencon.metta index 498deb7..97c636e 100644 --- a/miles/gencon.metta +++ b/miles/gencon.metta @@ -1,235 +1,243 @@ ; -; MODULE gencon EXPORTS +; !(module gencon (:: (/ gilppi 12) (/ gilppi 14))) +; + ; -; METAPREDICATES +; !(meta-predicate (, (gilppi : : : : : : : : : : : :) (gilppi + + : : : : : : : : : : : :))) +; + ; -; IMPORTS +; !(use-module (home kb) (:: (/ store-clauses 2))) +; + !(use-module (home show-utils) (:: (/ write-list 1) (/ show-kb 0))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * module: gilppi.pl +; ; -; * +; ; -; * author: I.Stahl date:7/93 +; ; -; * +; ; -; * description: generic control for induction a la GENCOL +; ; -; * enhanced with PI capabilties +; ; -; * Given: B, E+, E- +; ; -; * Algorithm: +; ; -; * Partial_Sols := initialize() +; ; -; * Complete_Sols := {} +; ; -; * while not(Stop_C(Complete_Sols)) do +; ; -; * PS := Select(Partial_Sols) +; ; -; * if Quality_C(PS) +; ; -; * then Complete_Sols := Complete_Sols U {PS} +; ; -; * Partial_Sols := Update(Partial_Sols) +; ; -; * else if active(PS) +; ; -; * then One_of(->Partial_Sols := Add(Partial_Sols,Spec(PS)) +; ; -; * ->Partial_Sols := Add(Partial_Sols,Spec(PS))) +; ; -; * all PS in spec(PS) (gen(PS)) marked active +; ; -; * else Partial_Sols := Add(Partial_Sols,L_Newp(PS)) +; ; -; * mark PS as passive +; ; -; * Partial_Sols := Filter(Partial_Sols) +; ; -; * Output(Complete_Sols) +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicates: gilppi/12 +; ; -; * +; ; -; * syntax: gilppi(+Initialize, +Stop_C, +Quality_C, +Update, +Select, +Add, +Filter, +; ; -; * +One_of, +Spec, +Gen, +L_newp, +Output) +; ; -; * +; ; -; * args: Initialize... name of a 1-place predicate that initializes the list +; ; -; * of partial solutions +; ; -; * Stop_C... name of a 1-place predicate that checks whether complete_sols +; ; -; * contains a satisfactory solution +; ; -; * Quality_C... name of a 1-place predicate that checks whether the current +; ; -; * theory PS is satisfactory +; ; -; * Update... name of a 2-place predicate that updates the list of partial +; ; -; * solutions after a satisfactory solution has been found +; ; -; * Select... name of a 4-place predicate that selects a promising partial +; ; -; * solution from partial_sols +; ; -; * Add... name of a 3-place predicate that adds the new partial solutions +; ; -; * to the list partial_sols +; ; -; * Filter... name of a two-place predicate that filters the most promising +; ; -; * among partial_sols +; ; -; * One_of... name of a two-place predicate that decides whether the current +; ; -; * theory PS should be generalised or specialised +; ; -; * Spec... name of a 2-place predicate that determines all specialisations +; ; -; * of the current theory PS wrt the bias +; ; -; * Gen... name of a 2-place predicate that determines all generalisations +; ; -; * of the current theory PS wrt the bias +; ; -; * L_newp... name of a 14-place predicate, the actual PI-module +; ; -; * Output... name of a 1-place predicate that outputs the complete solutions +; ; -; * +; ; -; * +; ; -; * description: implements a generic ILP algorithm (cf GENCOL) with PI capabilities +; ; -; * the actual learning algorithm depends on the implementations of +; ; -; * the argument predicates +; ; -; * +; ; -; * example: +; ; -; * +; ; -; *********************************************************************** +; @@ -238,6 +246,8 @@ (gilppi $Initialize $Stop_C $Quality_C $Update $Select $Add $Filter $One_of $Spec $Gen $L_newp $Output) ( (c-call $Initialize (:: $Partial_Sols)) (gilppi $Partial_Sols Nil $Initialize $Stop_C $Quality_C $Update $Select $Add $Filter $One_of $Spec $Gen $L_newp $Output))) +; + (= @@ -247,11 +257,15 @@ (set-det) (c-call $Output (:: $Complete_Sols)))) +; + (= (gilppi $Partial_Sols $Complete_Sols $Initialize $Stop_C $Quality_C $Update $Select $Add $Filter $One_of $Spec $Gen $L_newp $Output) ( (c-call $Select (:: $Partial_Sols $PS $M $Partial_Sols1)) (det-if-then-else (c-call $Quality_C (:: $PS)) (, (c-call $Update (:: $Partial_Sols1 $Partial_Sols2)) (gilppi $Partial_Sols2 (Cons $PS $Complete_Sols) $Initialize $Stop_C $Quality_C $Update $Select $Add $Filter $One_of $Spec $Gen $L_newp $Output)) (, (det-if-then-else (== $M active) (, (c-call $One_of (:: $PS $GS)) (det-if-then-else (== $GS spec) (, (write Specialising) (nl) (write-list $PS) (nl) (nl) (c-call $Spec (:: $PS $PSL))) (, (write Generalising) (nl) (write-list $PS) (nl) (nl) (c-call $Gen (:: $PS $PSL))))) (c-call $L_newp (:: $PS $PSL $Initialize $Stop_C $Quality_C $Update $Select $Add $Filter $One_of $Spec $Gen $L_newp $Output))) (c-call $Add (:: $Partial_Sols1 $PSL $Partial_Sols2)) (c-call $Filter (:: $Partial_Sols2 $Partial_Sols3)) (gilppi $Partial_Sols3 $Complete_Sols $Initialize $Stop_C $Quality_C $Update $Select $Add $Filter $One_of $Spec $Gen $L_newp $Output))))) +; + @@ -261,14 +275,20 @@ (=.. $Call (Cons $Pred $Arglist)) (call (with_self $M $Call)))) +; + (= (c-mod (with_self $M $Pred) $M $Pred) ( (simple $Pred) (set-det))) +; + (= (c-mod (with_self $_ $P) $M1 $Pred) ( (set-det) (c-mod $P $M1 $Pred))) +; + diff --git a/miles/gencon_instances/constrained_clauses.metta b/miles/gencon_instances/constrained_clauses.metta index 9c20f12..5bd77fc 100644 --- a/miles/gencon_instances/constrained_clauses.metta +++ b/miles/gencon_instances/constrained_clauses.metta @@ -1,18 +1,22 @@ ; -; MODULE constrained_clauses EXPORTS +; !(module constrained-clauses (:: (/ learn-constrained 0))) +; + ; -; METAPREDICATES +; !(meta-predicate (ccl-newp + + : : : : : : : : : : : :)) +; + ; -; IMPORTS +; !(use-module (home kb) @@ -27,24 +31,34 @@ (/ store-ex 3) (/ delete-all 1) (/ known 6))) +; + !(use-module (home gencon) (:: (/ gilppi 12) (/ gilppi 14))) +; + !(use-module (home argument-types) (:: (/ types-of 3) - (/ type-restriction 2))) + (/ type-restriction 2))) +; + !(use-module (home clause-heads) - (:: (/ heads 1))) + (:: (/ heads 1))) +; + !(use-module (home show-utils) (:: (/ show-kb 0) - (/ write-list 1))) + (/ write-list 1))) +; + !(use-module (home evaluation) (:: @@ -56,9 +70,13 @@ (/ covered-neg-examples 1) (/ fp-hyp 1) (/ change-evaluated 1))) +; + !(use-module (home lgg) (:: (/ set-lgg 2))) +; + !(use-module (home div-utils) (:: @@ -67,90 +85,110 @@ (/ mysetof 3) (/ make-unique 2) (/ body2list 2))) +; + !(use-module (home var-utils) (:: (/ only-vars 2) (/ clause-terms 2))) +; + !(use-module (home tdref-it) (:: (/ refinement-add-body-literal 3))) +; + !(use-module (home newpred) (:: (/ specialize-with-newpred 7))) +; + !(use-module (home interpreter) (:: (/ prooftrees 3))) +; + !(use-module-if-exists (library basics) (:: (/ member 2))) +; + !(use-module-if-exists (library strings) (:: (/ gensym 2))) +; + !(use-module-if-exists (library sets) (:: (/ subset 2))) +; + !(use-module-if-exists (library subsumes) (:: (/ variant 2))) +; + ; -; METAPREDICATES +; ; -; none +; ; -; *********************************************************************** +; ; -; * +; ; -; * module: constrained_clauses.pl +; ; -; * +; ; -; * author: I.Stahl date:8/93 +; ; -; * +; ; -; * changed: +; ; -; * +; ; -; * +; ; -; * description: instantiation of gilppi for RUL-programs +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (learn-constrained) (gilppi ccinitialize ccstop-c ccquality-c ccupdate ccselect ccadd ccfilter ccone-of ccspec ccgen ccl-newp ccoutput)) +; + @@ -167,8 +205,10 @@ (delete-clause $ID)) $S1) (findall (, $ID1 $M1 $T1) - (remove-atom &self + (remove-symbol &self (prooftrees $ID1 $M1 $T1)) $S2))) +; + (= @@ -187,13 +227,17 @@ (delete-clause $ID)) $S1) (findall (, $ID1 $M1 $T1) - (remove-atom &self + (remove-symbol &self (prooftrees $ID1 $M1 $T1)) $S2))) +; + (= (ccstop_c ($_)) True) +; + @@ -205,34 +249,50 @@ (, (complete-chk) (correct-chk)) True fail))) +; + (= (ccupdate $L $L) True) +; + (= (sclauses ()) True) +; + (= (sclauses (Cons (, $ID $H $B $CL $E) $R)) - ( (sclauses $R) (add-atom &self (: kb (known $ID $H $B $CL hypo $E))))) + ( (sclauses $R) (add-symbol &self (: kb (known $ID $H $B $CL hypo $E))))) +; + (= (sprooftrees Nil) (change-evaluated yes)) +; + (= (sprooftrees (Cons (, $ID $M $T) $R)) - ( (sprooftrees $R) (add-atom &self (: interpreter (prooftrees $ID $M $T))))) + ( (sprooftrees $R) (add-symbol &self (: interpreter (prooftrees $ID $M $T))))) +; + (= (ccselect $Partial_Sols $PS active $Partial_Sols1) (select-active $Partial_Sols $PS $Partial_Sols1)) +; + (= (ccselect $Partial_Sols $PS passive $Partial_Sols) (select-passive $Partial_Sols $PS)) +; + (= @@ -241,20 +301,28 @@ (, $PS active) $R) $PS (Cons (, $PS passive) $R)) True) +; + (= (select-active (Cons $P $R) $PS (Cons $P $R1)) (select-active $R $PS $R1)) +; + (= (select-passive $Partial_Sols $PS) ( (candidates $Partial_Sols Nil $Partial_Sols1) (best $Partial_Sols1 (- $_ $PS)))) +; + (= (candidates () $PSS $PSS) True) +; + (= (candidates (Cons @@ -280,6 +348,8 @@ (, (get-clause $ID $_ $_ $_ hypo) (delete-clause $ID)) $_))) +; + (= @@ -293,31 +363,45 @@ (set-det) (ccins (- $N $PS) $R $R1))) +; + (= (ccins $X $L (Cons $X $L)) True) +; + (= (ccadd $Partial_Sols $PSL $Partial_Sols1) (append $Partial_Sols $PSL $Partial_Sols1)) +; + (= (ccfilter $Partial_Sols $Partial_Sols1) (ccfilter $Partial_Sols Nil $Partial_Sols1)) +; + (= (ccfilter () $Partial_Sols $Partial_Sols) True) +; + (= (ccfilter (Cons $X $R) $Partial_Sols $Partial_Sols2) ( (ccfilter1 $X $Partial_Sols $Partial_Sols1) (ccfilter $R $Partial_Sols1 $Partial_Sols2))) +; + (= (ccfilter1 $X () ($X)) True) +; + (= (ccfilter1 (, @@ -340,6 +424,8 @@ (, (with_self $PS (with_self $DB $Hist)) $M) $R $R1))) +; + (= @@ -347,6 +433,8 @@ (det-if-then-else complete-chk (= $M spec) (= $M gen))) +; + (= @@ -358,6 +446,8 @@ (findall $ID (get-clause $ID $_ $_ $_ hypo) $IDL) (delete-all $IDL))) +; + (= @@ -384,6 +474,8 @@ (nl) (check-refinements $CL $NIDs $I $Hist (= $H $B) $PSL))) +; + (= @@ -393,9 +485,13 @@ (check-refinements $CL $NIDs $I $Hist $PSL) (store-clause $C $_ hypo $I) (set-det))) +; + (= (check_refinements () $_ $_ $_ ()) True) +; + (= (check-refinements (Cons $C $R) $NID $I $Hist $PSL2) @@ -424,7 +520,7 @@ (get-evaluation $ID $E)) $S1) (findall (, $ID1 $M1 $T1) - (remove-atom &self + (remove-symbol &self (prooftrees $ID1 $M1 $T1)) $S2) (= $PSL2 (Cons @@ -439,6 +535,8 @@ (clear-evaluation))) (delete-clause $I)) (= $PSL2 $PSL1)) (check-refinements $R $NID $I $Hist $PSL1))) +; + @@ -447,6 +545,8 @@ ( (only-vars $H $HV) (only-vars $B $BV) (remove-v $HV $BV Nil))) +; + (= @@ -455,6 +555,8 @@ (Cons (= $H1 $B1) $R) $R2) ( (set-det) (det-if-then-else (, (variant $H $H1) (== $B1 True)) (= $R2 $R) (, (clause-in (= $H True) $R $R1) (= $R2 (Cons (= $H1 $B1) $R1)))))) +; + (= (clause-in (= $H $B) @@ -485,10 +587,14 @@ (= $R2 (Cons (= $H1 $B1) $R1)))))) +; + (= (c_in () ()) True) +; + (= (c-in (Cons $L $R) $B) @@ -496,14 +602,20 @@ (:: $L) $B $B1) (set-det) (c-in $R $B1))) +; + (= (clause_variants () ()) True) +; + (= (clause-variants (Cons $C $R) $CL) ( (clause-in $C $CL $CL1) (clause-variants $R $CL1))) +; + (= @@ -512,6 +624,8 @@ (length $L2 $L2n) (< $L1n $L2n) (subset $L1 $L2))) +; + (= @@ -542,7 +656,7 @@ (get-evaluation $ID2 $E2)) $S1) (findall (, $ID3 $M3 $T3) - (remove-atom &self + (remove-symbol &self (prooftrees $ID3 $M3 $T3)) $S2) (findall (= $H4 $B4) @@ -550,6 +664,8 @@ (get-clause $ID4 $H4 $B4 $_ hypo) (delete-clause $ID4)) $PS) (write-l (:: (, (with_self $PS (with_self (:: $S1 $S2) $Hist)) (active)))))) +; + (= @@ -563,10 +679,14 @@ (body2list $B1 $BL1)) (store-clause (= $H $B) $_ hypo $ID))) +; + (= (ccgen3 () $_ $_ $_ ()) True) +; + (= (ccgen3 (Cons @@ -584,6 +704,8 @@ (Cons (with_self $L $M) $B1)) (= $B $B1)))) +; + @@ -604,7 +726,7 @@ (delete-old-ex $Elist) (store-newp-ex $NPos $NNeg $IDL0) (make-unique $IDL0 $IDL) - (add-atom &self $NType) + (add-symbol &self $NType) (store-clause $NC $_ hypo $I) (ccinitialize-newp $PSL) (gilppi $PSL Nil $Initialize $Stop_C $Quality_C $Update $Select $Add $Filter $One_of $Spec $Gen $L_newp $Output) @@ -624,13 +746,15 @@ (get-evaluation $ID3 $E3)) $S1) (findall (, $ID1 $M1 $T1) - (remove-atom &self + (remove-symbol &self (prooftrees $ID1 $M1 $T1)) $S2) (findall (= $H2 $B2) (, (get-clause $ID2 $H2 $B2 $_ hypo) (delete-clause $ID2)) $PS))) +; + (= @@ -638,29 +762,43 @@ ( (get-example $ID $F $M) (delete-example $ID) (delete-old-ex $R))) +; + (= (delete_old_ex ()) True) +; + (= (store_old_ex ()) True) +; + (= (store-old-ex (Cons (ex $ID $F $M) $R)) ( (store-ex $F $M $ID) (store-old-ex $R))) +; + (= (store_newp_ex () () ()) True) +; + (= (store-newp-ex Nil (Cons $F $R) (Cons $ID $R1)) ( (store-ex $F - $ID) (store-newp-ex Nil $R $R1))) +; + (= (store-newp-ex (Cons $F $R) $L (Cons $ID $R1)) ( (store-ex $F + $ID) (store-newp-ex $R $L $R1))) +; + (= @@ -675,6 +813,8 @@ (nl) (nl) (show-kb))) +; + @@ -683,5 +823,9 @@ ( (write-list $CL) (nl) (write-l $R))) +; + (= (write_l ()) True) +; + diff --git a/miles/gencon_instances/constrained_clauses_ex.metta b/miles/gencon_instances/constrained_clauses_ex.metta index f7e81c2..7900d60 100644 --- a/miles/gencon_instances/constrained_clauses_ex.metta +++ b/miles/gencon_instances/constrained_clauses_ex.metta @@ -2,397 +2,378 @@ (= (type_restriction (male $A) - ( (atom $A))) True) -; /* -; type_restriction((A < B),[number(A),number(B)]). + ( (is-symbol $A))) True) ; -; -; ex(merge([1],[2],[1,2]),'+'). -; ex(merge([6],[4],[4,6]),'+'). -; ex(merge([2,3,4,5],[4,7],[2,3,4,4,5,7]),'+'). -; ex(merge([44,55,66],[22,33,44,55],[22,33,44,44,55,55,66]),'+'). -; ex(merge([],[54,66,77,88,97],[54,66,77,88,97]),'+'). -; ex(merge([],[4],[4]),'+'). -; ex(merge([],[],[]),'+'). -; ex(merge([22,23,24,25],[],[22,23,24,25]),'+'). -; ex(merge([24],[],[24]),'+'). -; ex(merge([29,39,49,59],[37,79,99],[29,37,39,49,59,79,99]),'+'). -; ex(merge([2],[4,7],[2,4,7]),'+'). -; ex(merge([1],[2],[2,1]),'-'). -; ex(merge([6],[4],[6,4]),'-'). -; ex(merge([8],[7],[8]),'-'). -; ex(merge([2,3,4,5],[4,7],[4,3,2,4,5,7]),'-'). -; ex(merge([44,55,66],[22,33,44,55],[22,44,55,33,55,44,66]),'-'). -; ex(merge([29,39,49,59],[37,79,99],[37,39,29,59,79,49,99]),'-'). -; ex(merge([2],[4,7],[4,2]),'-'). -; ex(merge([1,2],[3,4],[1,3,2,4]),'-'). -; -; -; */ - (= (type_restriction (female $A) - ( (atom $A))) True) + ( (is-symbol $A))) True) +; + (= (type_restriction (parent $A $B) - ( (atom $A) (atom $B))) True) + ( (is-symbol $A) (is-symbol $B))) True) +; + (= (ex (father ma b) +) True) +; + (= (ex (father mc d) +) True) +; + (= (ex (father me f) +) True) +; + (= (ex (father mg h) +) True) +; + (= (ex (father mi j) +) True) +; + (= (ex (father mk l) +) True) +; + (= (ex (father fa b) -) True) +; + (= (ex (father fc d) -) True) +; + (= (ex (father fe f) -) True) +; + (= (ex (father fg h) -) True) +; + (= (ex (father fi j) -) True) +; + (= (ex (father fk l) -) True) +; + (= (ex (father b ma) -) True) +; + (= (ex (father d mc) -) True) +; + (= (ex (father f me) -) True) +; + (= (ex (father h mg) -) True) +; + (= (ex (father j mi) -) True) +; + (= (ex (father l mk) -) True) +; + (= (ex (father b fa) -) True) +; + (= (ex (father d fc) -) True) +; + (= (ex (father f fe) -) True) +; + (= (ex (father h fg) -) True) +; + (= (ex (father j fi) -) True) +; + (= (ex (father l fk) -) True) +; + (= (ex (human ma) +) True) +; + (= (ex (human mc) +) True) +; + (= (ex (human me) +) True) +; + (= (ex (human mg) +) True) +; + (= (ex (human mi) +) True) +; + (= (ex (human mk) +) True) +; + (= (ex (human fa) +) True) +; + (= (ex (human fc) +) True) +; + (= (ex (human fe) +) True) +; + (= (ex (human fg) +) True) +; + (= (ex (human fi) +) True) +; + (= (ex (human fk) +) True) +; + (= (ex (human b) +) True) +; + (= (ex (human d) +) True) +; + (= (ex (human f) +) True) +; + (= (ex (human h) +) True) +; + (= (ex (human j) +) True) +; + (= (ex (human l) +) True) +; + (= (ex (human a) -) True) +; + (= (ex (human c) -) True) +; + (= (male ma) True) +; + (= (male mc) True) +; + (= (male me) True) +; + (= (male mg) True) +; + (= (male mi) True) +; + (= (male mk) True) +; + (= (male b) True) +; + (= (male d) True) +; + (= (male f) True) +; + (= (male h) True) +; + (= (male j) True) +; + (= (male l) True) +; + (= (female fa) True) +; + (= (female fc) True) +; + (= (female fe) True) +; + (= (female fg) True) +; + (= (female fi) True) +; + (= (female fk) True) +; + (= (parent ma b) True) +; + (= (parent mc d) True) +; + (= (parent me f) True) +; + (= (parent mg h) True) +; + (= (parent mi j) True) +; + (= (parent mk l) True) +; + (= (parent fa b) True) +; + (= (parent fc d) True) +; + (= (parent fe f) True) +; + (= (parent fg h) True) +; + (= (parent fi j) True) +; + (= (parent fk l) True) +; -; /* -; -; ex(t(nil),+). -; ex(t(tree(nil,0,nil)),+). -; ex(t(tree(nil,0,tree(nil,0,nil))),+). -; ex(t(tree(nil,0,tree(nil,s(0),nil))),+). -; ex(t(tree(nil,0,tree(nil,s(s(0)),nil))),+). -; ex(t(tree(nil,0,tree(nil,s(s(s(0))),nil))),+). -; ex(t(tree(nil,s(0),nil)),+). -; ex(t(tree(nil,s(0),tree(nil,0,nil))),+). -; ex(t(tree(nil,s(0),tree(nil,s(0),nil))),+). -; ex(t(tree(nil,s(0),tree(nil,s(s(0)),nil))),+). -; ex(t(tree(nil,s(0),tree(nil,s(s(s(0))),nil))),+). -; ex(t(tree(nil,s(s(0)),nil)),+). -; ex(t(tree(nil,s(s(0)),tree(nil,0,nil))),+). -; ex(t(tree(nil,s(s(0)),tree(nil,s(0),nil))),+). -; ex(t(tree(nil,s(s(0)),tree(nil,s(s(0)),nil))),+). -; ex(t(tree(nil,s(s(0)),tree(nil,s(s(s(0))),nil))),+). -; ex(t(tree(nil,s(s(s(0))),nil)),+). -; ex(t(tree(nil,s(s(s(0))),tree(nil,0,nil))),+). -; ex(t(tree(nil,s(s(s(0))),tree(nil,s(0),nil))),+). -; ex(t(tree(nil,s(s(s(0))),tree(nil,s(s(0)),nil))),+). -; ex(t(tree(nil,s(s(s(0))),tree(nil,s(s(s(0))),nil))),+). -; ex(t(tree(tree(nil,0,nil),0,nil)),+). -; ex(t(tree(tree(nil,0,nil),0,tree(nil,0,nil))),+). -; ex(t(tree(tree(nil,0,nil),0,tree(nil,s(0),nil))),+). -; ex(t(tree(tree(nil,0,nil),0,tree(nil,s(s(0)),nil))),+). -; ex(t(tree(tree(nil,0,nil),0,tree(nil,s(s(s(0))),nil))),+). -; ex(t(tree(tree(nil,0,nil),s(0),nil)),+). -; ex(t(tree(tree(nil,0,nil),s(0),tree(nil,0,nil))),+). -; ex(t(tree(tree(nil,0,nil),s(0),tree(nil,s(0),nil))),+). -; ex(t(tree(tree(nil,0,nil),s(0),tree(nil,s(s(0)),nil))),+). -; ex(t(tree(tree(nil,0,nil),s(0),tree(nil,s(s(s(0))),nil))),+). -; ex(t(tree(tree(nil,0,nil),s(s(0)),nil)),+). -; ex(t(tree(tree(nil,0,nil),s(s(0)),tree(nil,0,nil))),+). -; ex(t(tree(tree(nil,0,nil),s(s(0)),tree(nil,s(0),nil))),+). -; ex(t(tree(tree(nil,0,nil),s(s(0)),tree(nil,s(s(0)),nil))),+). -; ex(t(tree(tree(nil,0,nil),s(s(0)),tree(nil,s(s(s(0))),nil))),+). -; ex(t(tree(tree(nil,0,nil),s(s(s(0))),nil)),+). -; ex(t(tree(tree(nil,0,nil),s(s(s(0))),tree(nil,0,nil))),+). -; ex(t(tree(tree(nil,0,nil),s(s(s(0))),tree(nil,s(0),nil))),+). -; ex(t(tree(tree(nil,0,nil),s(s(s(0))),tree(nil,s(s(0)),nil))),+). -; ex(t(tree(tree(nil,0,nil),s(s(s(0))),tree(nil,s(s(s(0))),nil))),+). -; ex(t(tree(tree(nil,s(0),nil),0,nil)),+). -; ex(t(tree(tree(nil,s(0),nil),0,tree(nil,0,nil))),+). -; ex(t(tree(tree(nil,s(0),nil),0,tree(nil,s(0),nil))),+). -; ex(t(tree(tree(nil,s(0),nil),0,tree(nil,s(s(0)),nil))),+). -; ex(t(tree(tree(nil,s(0),nil),0,tree(nil,s(s(s(0))),nil))),+). -; ex(t(tree(tree(nil,s(0),nil),s(0),nil)),+). -; ex(t(tree(tree(nil,s(0),nil),s(0),tree(nil,0,nil))),+). -; ex(t(tree(tree(nil,s(0),nil),s(0),tree(nil,s(0),nil))),+). -; ex(t(tree(tree(nil,s(0),nil),s(0),tree(nil,s(s(0)),nil))),+). -; ex(t(tree(tree(nil,s(0),nil),s(0),tree(nil,s(s(s(0))),nil))),+). -; ex(t(tree(tree(nil,s(0),nil),s(s(0)),nil)),+). -; ex(t(tree(tree(nil,s(0),nil),s(s(0)),tree(nil,0,nil))),+). -; ex(t(tree(tree(nil,s(0),nil),s(s(0)),tree(nil,s(0),nil))),+). -; ex(t(tree(tree(nil,s(0),nil),s(s(0)),tree(nil,s(s(0)),nil))),+). -; ex(t(tree(tree(nil,s(0),nil),s(s(0)),tree(nil,s(s(s(0))),nil))),+). -; ex(t(tree(tree(nil,s(0),nil),s(s(s(0))),nil)),+). -; ex(t(tree(tree(nil,s(0),nil),s(s(s(0))),tree(nil,0,nil))),+). -; ex(t(tree(tree(nil,s(0),nil),s(s(s(0))),tree(nil,s(0),nil))),+). -; ex(t(tree(tree(nil,s(0),nil),s(s(s(0))),tree(nil,s(s(0)),nil))),+). -; ex(t(tree(tree(nil,s(0),nil),s(s(s(0))),tree(nil,s(s(s(0))),nil))),+). -; ex(t(tree(tree(nil,s(s(0)),nil),0,nil)),+). -; ex(t(tree(tree(nil,s(s(0)),nil),0,tree(nil,0,nil))),+). -; ex(t(tree(tree(nil,s(s(0)),nil),0,tree(nil,s(0),nil))),+). -; ex(t(tree(tree(nil,s(s(0)),nil),0,tree(nil,s(s(0)),nil))),+). -; ex(t(tree(tree(nil,s(s(0)),nil),0,tree(nil,s(s(s(0))),nil))),+). -; ex(t(tree(tree(nil,s(s(0)),nil),s(0),nil)),+). -; ex(t(tree(tree(nil,s(s(0)),nil),s(0),tree(nil,0,nil))),+). -; ex(t(tree(tree(nil,s(s(0)),nil),s(0),tree(nil,s(0),nil))),+). -; ex(t(tree(tree(nil,s(s(0)),nil),s(0),tree(nil,s(s(0)),nil))),+). -; ex(t(tree(tree(nil,s(s(0)),nil),s(0),tree(nil,s(s(s(0))),nil))),+). -; ex(t(tree(tree(nil,s(s(0)),nil),s(s(0)),nil)),+). -; ex(t(tree(tree(nil,s(s(0)),nil),s(s(0)),tree(nil,0,nil))),+). -; ex(t(tree(tree(nil,s(s(0)),nil),s(s(0)),tree(nil,s(0),nil))),+). -; ex(t(tree(tree(nil,s(s(0)),nil),s(s(0)),tree(nil,s(s(0)),nil))),+). -; ex(t(tree(tree(nil,s(s(0)),nil),s(s(0)),tree(nil,s(s(s(0))),nil))),+). -; ex(t(tree(tree(nil,s(s(0)),nil),s(s(s(0))),nil)),+). -; ex(t(tree(tree(nil,s(s(0)),nil),s(s(s(0))),tree(nil,0,nil))),+). -; ex(t(tree(tree(nil,s(s(0)),nil),s(s(s(0))),tree(nil,s(0),nil))),+). -; ex(t(tree(tree(nil,s(s(0)),nil),s(s(s(0))),tree(nil,s(s(0)),nil))),+). -; ex(t(tree(tree(nil,s(s(0)),nil),s(s(s(0))),tree(nil,s(s(s(0))),nil))),+). -; ex(t(tree(tree(nil,s(s(s(0))),nil),0,nil)),+). -; ex(t(tree(tree(nil,s(s(s(0))),nil),0,tree(nil,0,nil))),+). -; ex(t(tree(tree(nil,s(s(s(0))),nil),0,tree(nil,s(0),nil))),+). -; ex(t(tree(tree(nil,s(s(s(0))),nil),0,tree(nil,s(s(0)),nil))),+). -; ex(t(tree(tree(nil,s(s(s(0))),nil),0,tree(nil,s(s(s(0))),nil))),+). -; ex(t(tree(tree(nil,s(s(s(0))),nil),s(0),nil)),+). -; ex(t(tree(tree(nil,s(s(s(0))),nil),s(0),tree(nil,0,nil))),+). -; ex(t(tree(tree(nil,s(s(s(0))),nil),s(0),tree(nil,s(0),nil))),+). -; ex(t(tree(tree(nil,s(s(s(0))),nil),s(0),tree(nil,s(s(0)),nil))),+). -; ex(t(tree(tree(nil,s(s(s(0))),nil),s(0),tree(nil,s(s(s(0))),nil))),+). -; ex(t(tree(tree(nil,s(s(s(0))),nil),s(s(0)),nil)),+). -; ex(t(tree(tree(nil,s(s(s(0))),nil),s(s(0)),tree(nil,0,nil))),+). -; ex(t(tree(tree(nil,s(s(s(0))),nil),s(s(0)),tree(nil,s(0),nil))),+). -; ex(t(tree(tree(nil,s(s(s(0))),nil),s(s(0)),tree(nil,s(s(0)),nil))),+). -; ex(t(tree(tree(nil,s(s(s(0))),nil),s(s(0)),tree(nil,s(s(s(0))),nil))),+). -; ex(t(tree(tree(nil,s(s(s(0))),nil),s(s(s(0))),nil)),+). -; ex(t(tree(tree(nil,s(s(s(0))),nil),s(s(s(0))),tree(nil,0,nil))),+). -; ex(t(tree(tree(nil,s(s(s(0))),nil),s(s(s(0))),tree(nil,s(0),nil))),+). -; ex(t(tree(tree(nil,s(s(s(0))),nil),s(s(s(0))),tree(nil,s(s(0)),nil))),+). -; ex(t(tree(tree(nil,s(s(s(0))),nil),s(s(s(0))),tree(nil,s(s(s(0))),nil))),+). -; -; ex(t(0),-). -; ex(t(s(0)),-). -; ex(t(s(s(0))),-). -; ex(t(s(s(s(0)))),-). -; ex(t(tree(nil,nil,nil)),-). -; ex(t(tree(nil,tree(nil,0,nil),nil)),-). -; ex(t(tree(0,0,s(0))),-). -; ex(t(tree(s(s(0)),s(0),s(s(s(0))))),-). -; ex(t(tree(nil,0,s(0))),-). -; ex(t(tree(nil,s(0),s(s(s(0))))),-). -; ex(t(tree(0,0,nil)),-). -; ex(t(tree(s(s(s(0))),s(0),nil)),-). -; ex(t(tree(nil,s(nil),nil)),-). -; ex(t(tree(nil,s(s(nil)),nil)),-). -; ex(t(tree(nil,s(tree(nil,0,nil)),nil)),-). -; ex(t(tree(nil,s(s(tree(nil,s(0),nil))),nil)),-). -; ex(t(tree(nil,s(s(s(nil))),nil)),-). -; -; -; ex(p(f([],[])),+). -; ex(p(f([a],[b])),+). -; ex(p(f([a,a],[b,b])),+). -; ex(p(f([a,a,a],[b,b,b])),+). -; ex(p(f([a,a,a,a],[b,b,b,b])),+). -; -; -; ex(p([]),-). -; ex(p([a]),-). -; ex(p([a,a]),-). -; ex(p([a,a,a]),-). -; ex(p([a,a,a,a]),-). -; ex(p([b]),-). -; ex(p([b,b]),-). -; ex(p([b,b,b]),-). -; ex(p([b,b,b,b]),-). -; ex(p(f([a],[])),-). -; ex(p(f([],[b,b])),-). -; ex(p(f([a,a,a],[b,b])),-). -; ex(p(f([a],[b,b,b])),-). -; ex(p(f([a,a,a,a],[b,b,b])),-). -; */ +; diff --git a/miles/gencon_instances/foil.metta b/miles/gencon_instances/foil.metta index 2850cc5..820333f 100644 --- a/miles/gencon_instances/foil.metta +++ b/miles/gencon_instances/foil.metta @@ -1,5 +1,5 @@ ; -; MODULE foil EXPORTS +; @@ -7,10 +7,12 @@ (:: (/ learn-foil 0) (/ infogain 3))) +; + ; -; IMPORTS +; !(use-module @@ -24,6 +26,8 @@ (/ get-clause 5) (/ known 6) (/ store-ex 3))) +; + !(use-module (home evaluation) @@ -31,10 +35,14 @@ (/ eval-examples 0) (/ encoding-length-examples 1) (/ encoding-length-clause 2))) +; + !(use-module (home tdref-it) (:: (/ refinement-add-body-literal 2))) +; + !(use-module (home div-utils) @@ -43,76 +51,88 @@ (/ log2 2) (/ log2nueberk 3) (/ mysetof 3))) +; + !(use-module (home gencon) (:: (/ gilppi 12))) +; + !(use-module (home show-utils) (:: (/ show-kb 0))) +; + ; -; METAPREDICATES +; ; -; none +; ; -; ************************************************************************ +; ; -; * +; ; -; * module: foil.pl +; ; -; * +; ; -; * author: Irene Stahl date: 1. 7. 1993 +; ; -; * +; ; -; * changed: +; ; -; * +; ; -; * description: simple implementation of infogain heuristic +; ; -; * foil as instantiation of the generic algorithm (25. 11. 93) +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; (= (learn-foil) (gilppi initialize stop-c quality-c update select add filter one-of spec gen l-newp output)) +; + !(dynamic (/ el-ex 1)) +; + !(dynamic (/ total-ex 1)) +; + (= (initialize (:: (, (with_self (:: $MGT) 0) (active)))) @@ -126,15 +146,17 @@ (:: (, $P1 $N1))) (functor $MGT $P1 $N1) (encoding-length-examples $X) - (add-atom &self + (add-symbol &self (el_ex $X)) (mysetof $ID1 (^ $F1 (^ $L1 (get-example $ID1 $F1 $L1))) $IDL) (length $IDL $TE) - (add-atom &self + (add-symbol &self (total_ex $TE)))) +; + @@ -146,11 +168,15 @@ (Cons (, (: $C $G) passive) $R)) True) +; + (= (select (Cons $X $R) $C active (Cons $X $R1)) (select $R $C active $R1)) +; + @@ -167,20 +193,26 @@ (remove-covered-ex $Pos)) (, (delete-clause $ID) - (add-atom &self + (add-symbol &self (known $ID $H $B $CL hypo $E)) (set-det) (fail))))) +; + (= (remove_covered_ex ()) True) +; + (= (remove-covered-ex (Cons (with_self $ID $Fact) $R)) ( (delete-example $ID) - (add-atom &self + (add-symbol &self (saved_ex $ID $Fact)) (remove-covered-ex $R))) +; + (= @@ -195,26 +227,38 @@ (:: (, $P1 $N1))) (functor $MGT $P1 $N1) (set-det))) +; + (= (update $_ ()) True) +; + (= (one_of $_ spec) True) +; + (= (spec (:: $C) $PSL) ( (refinement-add-body-literal $C $CL) (infogain $CL $PSL))) +; + (= (add $PS () $PS) True) +; + (= (add $PS (Cons $X $R) $PS1) ( (insert-by-gain $X $PS $PS0) (add $PS0 $R $PS1))) +; + (= @@ -230,6 +274,8 @@ (set-det) (insert-by-gain (with_self $C $G) $R $R1))) +; + (= (insert_by_gain (: $C $G) $L @@ -237,25 +283,35 @@ (, (: ($C) $G) active) $L)) True) +; + (= (filter $L $L) True) +; + (= (stop-c $_) ( (not (get-example $_ $_ +)) (set-det))) +; + (= (stop-c $CL) ( (stop-c1 $CL $N) (el-ex $X) (> $N $X))) +; + (= (stop_c1 () 0) True) +; + (= (stop-c1 (Cons @@ -268,78 +324,84 @@ (p)) $BL) $M1) (is $M (+ $M0 $M1)))) +; + (= (output $_) - ( (remove-atom &self + ( (remove-symbol &self (saved_ex $ID $Fact)) (store-ex $Fact + $ID) (output $_))) +; + (= (output $_) - ( (remove-all-atoms &self + ( (remove-all-symbols &self (total_ex $_)) - (remove-all-atoms &self + (remove-all-symbols &self (el_ex $_)) (show-kb))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: info_gain/3 +; ; -; * +; ; -; * syntax: infogain(+Clause,+Clause_refs,-CL) +; ; -; * +; ; -; * args: Clause.. MeTTa clause that is refined +; ; -; * Clause_refs .. list of MeTTa clauses, refinements of Clause +; ; -; * CL.. list of clauses with their gain: CL = [C1:Gain1,..,Cn:Gainn] +; ; -; * +; ; -; * description: Clause is an overgeneral clause, CL is the +; ; -; * list of refinements of this overgeneral clause, +; ; -; * CL = [C1,...,Cn]. infogain returns a list +; ; -; * CL = [C1:Gain_C1,..], where +; ; -; * Gain is the information gain of Ci in comparison +; ; -; * with the overgeneral clause +; ; -; * +; ; -; ************************************************************************* +; @@ -358,10 +420,14 @@ (is $ITi (- $LNOTi)) (infogain1 $Ref_list $CL $ITi))) +; + (= (infogain1 () () $_) True) +; + (= (infogain1 (Cons $C $R) $R2 $ITi) @@ -402,6 +468,8 @@ (= $R2 (Cons (with_self $C $IG) $R1)))))) +; + (= @@ -417,11 +485,15 @@ (is $ITi (- $LNOTi)) (infogain2 $Ref_list $CL $ITi))) +; + (= (infogain2 () () $_) True) +; + (= (infogain2 (Cons $C $R) $R2 $ITi) @@ -476,6 +548,8 @@ (= $R2 (Cons (with_self $C $IG) $R1)))))) +; + (= @@ -489,4 +563,6 @@ (log2nueberk $U1 $PN1 $Y) (is $X (+ $LU $Y)))) +; + diff --git a/miles/gencon_instances/foil_ex.metta b/miles/gencon_instances/foil_ex.metta index f756079..0047e5d 100644 --- a/miles/gencon_instances/foil_ex.metta +++ b/miles/gencon_instances/foil_ex.metta @@ -3,25 +3,35 @@ (type_restriction (member $A $B) ( (atomic $A) (list $B))) True) +; + (= (type_restriction (components $A $B $C) ( (list $A) (atomic $B) (list $C))) True) +; + (= (list ()) True) +; + (= (list (Cons $A $B)) ( (atomic $A) (list $B))) +; + (= (components (Cons $X $Y) $X $Y) True) +; + @@ -29,192 +39,290 @@ (ex (member e (e o z)) +) True) +; + (= (ex (member o (o z)) +) True) +; + (= (ex (member o (e o z)) +) True) +; + (= (ex (member z (z)) +) True) +; + (= (ex (member z (o z)) +) True) +; + (= (ex (member z (e o z)) +) True) +; + (= (ex (member e e) -) True) +; + (= (ex (member e o) -) True) +; + (= (ex (member e z) -) True) +; + (= (ex (member e ()) -) True) +; + (= (ex (member e (z)) -) True) +; + (= (ex (member e (o z)) -) True) +; + (= (ex (member o e) -) True) +; + (= (ex (member o o) -) True) +; + (= (ex (member o z) -) True) +; + (= (ex (member o ()) -) True) +; + (= (ex (member o (z)) -) True) +; + (= (ex (member z e) -) True) +; + (= (ex (member z o) -) True) +; + (= (ex (member z z) -) True) +; + (= (ex (member z ()) -) True) +; + (= (ex (member () e) -) True) +; + (= (ex (member () o) -) True) +; + (= (ex (member () z) -) True) +; + (= (ex (member () ()) -) True) +; + (= (ex (member () (z)) -) True) +; + (= (ex (member () (o z)) -) True) +; + (= (ex (member () (e o z)) -) True) +; + (= (ex (member (z) e) -) True) +; + (= (ex (member (z) o) -) True) +; + (= (ex (member (z) z) -) True) +; + (= (ex (member (z) ()) -) True) +; + (= (ex (member (z) (z)) -) True) +; + (= (ex (member (z) (o z)) -) True) +; + (= (ex (member (z) (e o z)) -) True) +; + (= (ex (member (o z) e) -) True) +; + (= (ex (member (o z) o) -) True) +; + (= (ex (member (o z) z) -) True) +; + (= (ex (member (o z) ()) -) True) +; + (= (ex (member (o z) (z)) -) True) +; + (= (ex (member (o z) (o z)) -) True) +; + (= (ex (member (o z) (e o z)) -) True) +; + (= (ex (member (e o z) e) -) True) +; + (= (ex (member (e o z) o) -) True) +; + (= (ex (member (e o z) z) -) True) +; + (= (ex (member (e o z) ()) -) True) +; + (= (ex (member (e o z) (z)) -) True) +; + (= (ex (member (e o z) (o z)) -) True) +; + (= (ex (member (e o z) (e o z)) -) True) +; + diff --git a/miles/gencon_instances/rul.metta b/miles/gencon_instances/rul.metta index 90c0e7b..655bd45 100644 --- a/miles/gencon_instances/rul.metta +++ b/miles/gencon_instances/rul.metta @@ -1,13 +1,15 @@ ; -; MODULE rul EXPORTS +; !(module rul (:: (/ learn-rul 0))) +; + ; -; IMPORTS +; !(use-module (home kb) @@ -21,106 +23,132 @@ (/ store-clauses 3) (/ store-clause 4) (/ delete-all 1))) +; + !(use-module (home argument-types) (:: (/ type-sub 2) (/ type-equal 4) - (/ replace-t 4))) + (/ replace-t 4))) +; + !(use-module (home gencon) - (:: (/ gilppi 12))) + (:: (/ gilppi 12))) +; + !(use-module (home show-utils) - (:: (/ show-kb 0))) + (:: (/ show-kb 0))) +; + !(use-module (home evaluation) (:: (/ eval-examples 0) (/ covered-pos-examples 1))) +; + !(use-module (home lgg) (:: (/ set-lgg 2))) +; + !(use-module (home div-utils) (:: (/ different-predicates 2) (/ remove-v 3) (/ mysetof 3))) +; + !(use-module (home var-utils) (:: (/ only-vars 2))) +; + !(use-module (home td-basic) (:: (/ append-body 3))) +; + !(use-module (home newpred) (:: (/ is-newpred 1))) +; + !(use-module-if-exists (library basics) (:: (/ member 2))) +; + !(use-module-if-exists (library strings) (:: (/ gensym 2))) +; + ; -; METAPREDICATES +; ; -; none +; ; -; *********************************************************************** +; ; -; * +; ; -; * module: rul.pl +; ; -; * +; ; -; * author: I.Stahl date:7/93 +; ; -; * +; ; -; * changed: +; ; -; * +; ; -; * +; ; -; * description: instantiation of gilppi for RUL-programs +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (learn-rul) (gilppi initialize stop-c quality-c update select add filter one-of spec gen l-newp output)) +; + @@ -133,10 +161,14 @@ (get-example $I $E +)) $Elist) (different-predicates $Elist $Elist1) (initialize1 $Elist1 $HL))) +; + (= (initialize1 () ()) True) +; + (= (initialize1 (Cons @@ -152,10 +184,14 @@ (different-predicates $Alist $Alist1) (initialize2 $Alist1 $T $HL1) (append $HL1 $HL0 $HL))) +; + (= (initialize2 () $_ ()) True) +; + (= (initialize2 (Cons $A $R) $T @@ -165,34 +201,48 @@ (=.. $H (:: $T $A1)) (initialize2 $R $T $R1))) +; + (= (stop_c ($_)) True) +; + (= (quality_c ()) True) +; + (= (quality-c (Cons (= $H $B) $R)) ( (only-vars $H $HV) (only-vars $B $BV) (remove-v $BV $HV Nil) (quality-c $R))) +; + (= (update $L $L) True) +; + (= (select $Partial_Sols $PS active $Partial_Sols1) (select-active $Partial_Sols $PS $Partial_Sols1)) +; + (= (select $Partial_Sols $PS passive $Partial_Sols) (select-passive $Partial_Sols $PS)) +; + (= @@ -201,22 +251,30 @@ (: $PS active) $R) $PS (Cons (: $PS passive) $R)) True) +; + (= (select-active (Cons $P $R) $PS (Cons $P $R1)) (select-active $R $PS $R1)) +; + (= (select-passive (:: (with_self $PS $_)) $PS) (set-det)) +; + (= (select-passive (Cons (with_self $PS $_) $R) $PS2) ( (select-passive $R $PS1) (most-specific $PS $PS1 $PS2))) +; + (= @@ -225,6 +283,8 @@ (more-specific $PS $PS1) (= $PS2 $PS) (= $PS2 $PS1))) +; + (= @@ -245,18 +305,26 @@ (delete-all $IDA) (set-det) (fail))))) +; + (= (more_spec ()) True) +; + (= (more-spec (Cons (with_self $Spec $Gen) $R)) ( (type-sub $Gen $Spec) (more-spec $R))) +; + (= (normalize () ()) True) +; + (= (normalize (Cons @@ -268,20 +336,28 @@ (only-vars $B $BV) (remove-v $BV $HV $RV) (normalize $RV $B $B1))) +; + (= (normalize (:: $V) True (all $V)) (set-det)) +; + (= (normalize () $B $B) True) +; + (= (normalize (Cons $V $R) $B (, (all $V) $B1)) (normalize $R $B $B1)) +; + (= @@ -295,20 +371,28 @@ (functor $H $Pred 1)))) $Plist) (rename-t $Plist $Tlist) (transform-t $Spec $Spec1 $Tlist))) +; + (= (rename_t () ()) True) +; + (= (rename-t (Cons $P $R) (Cons (with_self $P1 $P) $R1)) ( (rename-t $R $R1) (gensym $P $P1))) +; + (= (transform_t () () $_) True) +; + (= (transform-t (Cons @@ -316,6 +400,8 @@ (Cons (= $H1 $B1) $R1) $Tlist) ( (transform-t $R $R1 $Tlist) (transform-t1 (, $H $B) $Tlist (, $H1 $B1)))) +; + (= @@ -325,13 +411,19 @@ ( (set-det) (transform-t1 $A $Tlist $A1) (transform-t1 $B $Tlist $B1))) +; + (= (transform-t1 True $_ True) (set-det)) +; + (= (transform-t1 $A $Tlist $A1) ( (=.. $A (:: $Pred $Arg)) (det-if-then-else (member (with_self $Pred1 $Pred) $Tlist) (=.. $A1 (:: $Pred1 $Arg)) (= $A1 $A)))) +; + @@ -340,17 +432,25 @@ (= (add $Partial_Sols $PSL $Partial_Sols1) (append $PSL $Partial_Sols $Partial_Sols1)) +; + (= (filter () ()) True) +; + (= (filter (Cons $CL $R) (Cons $CL1 $R2)) ( (filter $R $CL $R1 $CL1) (filter $R1 $R2))) +; + (= (filter () $CL () $CL) True) +; + (= (filter (Cons @@ -382,6 +482,8 @@ (with_self $CL1 $A) $R0)) (filter $R (with_self $CL $B) $R0 $CL2))))) +; + @@ -399,6 +501,8 @@ (= $Pos1 Nil) (= $M spec) (= $M gen)))) +; + @@ -416,6 +520,8 @@ (get-clause $ID0 $H0 $B0 $CL0 $L0) (functor $H0 $P 1))))))) $Predlist) (spec $IDL $Predlist $PSL))) +; + (= (spec Nil $_ Nil) @@ -426,10 +532,14 @@ (, (get-clause $ID1 $H1 $B1 $CL hypo) (delete-clause $ID1)))) $_)) +; + (= (spec (Cons $ID $R) $Preds $PSL) ( (get-clause $ID $H $B $_ $_) (det-if-then-else (specable $H $B $RV) (, (get-evaluation $ID (evaluation $_ $_ $Pos $_ $_ $_ $_ $_ $_)) (remove-other-covered $H $ID $Pos $Pos1) (delete-clause $ID) (spec-c $RV $H $B $Preds $ID $Pos1 $PSL0) (det-if-then-else (\== $PSL0 Nil) (, (= $PSL0 $PSL) (mysetof (= $H1 $B1) (^ $ID1 (^ $CL (, (get-clause $ID1 $H1 $B1 $CL hypo) (delete-clause $ID1)))) $_)) (, (store-clause (= $H $B) $_ hypo $ID) (spec $R $Preds $PSL)))) (spec $R $Preds $PSL)))) +; + @@ -440,6 +550,8 @@ (remove-v $BV $HV $RV) (\== $RV Nil) (set-det))) +; + (= @@ -455,10 +567,14 @@ (:: $ID) $IDL0 $IDL) (rem-other-covered $IDL $Pos $Pos1) (set-det))) +; + (= (rem_other_covered () $Pos $Pos) True) +; + (= (rem-other-covered (Cons $ID $R) $Pos $Pos2) @@ -466,21 +582,29 @@ (get-evaluation $ID (evaluation $_ $_ $P $_ $_ $_ $_ $_ $_)) (remove-v $P $Pos1 $Pos2))) +; + (= (spec_c () $_ $_ $_ $_ $_ ()) True) +; + (= (spec-c (Cons $V $R) $H $B $Predlist $ID $Pos $PSL) ( (spec-c $R $H $B $Predlist $ID $Pos $PSL0) (spec-c1 $Predlist $V $H $B $ID $Pos $PSL1) (append $PSL0 $PSL1 $PSL))) +; + (= (spec_c1 () $_ $_ $_ $_ $_ ()) True) +; + (= (spec-c1 (Cons $Pred $R) $V $H $B $ID $Pos $PSL) @@ -511,6 +635,8 @@ (active)) $PSL0))) (= $PSL $PSL0)) (spec-c1 $R $V $H $B $ID $Pos $PSL0))) +; + @@ -535,6 +661,8 @@ (, (get-clause $ID2 $H2 $B2 $CL2 hypo) (delete-clause $ID2)))) $RestPS))) +; + @@ -549,6 +677,8 @@ (eval-examples) (get-all-clauses $Clist) (correct-with-newp $Clist $Clist1))) +; + (= @@ -561,12 +691,18 @@ (remove-v $BV $HV $RV) (delete-clause $ID) (get-all-clauses $R))) +; + (= (get_all_clauses ()) True) +; + (= (correct_with_newp () ()) True) +; + (= (correct-with-newp (Cons @@ -576,6 +712,8 @@ (Cons (= $H $B) $R1)) ( (set-det) (correct-with-newp $R $R1))) +; + (= (correct-with-newp (Cons @@ -589,10 +727,14 @@ (append (Cons (= $H $B1) $R1) $HL $R2))) +; + (= (c_with_newp () $B $B ()) True) +; + (= (c-with-newp (:: $V) True $New @@ -601,6 +743,8 @@ (gensym newp $Newp) (=.. $New (:: $Newp $V)))) +; + (= (c-with-newp (Cons $V $R) $B @@ -610,15 +754,21 @@ (gensym newp $Newp) (=.. $New (:: $Newp $V)))) +; + (= (instances () $_ $_ ()) True) +; + (= (instances (Cons $New $R) $Pos $H (Cons $NewE $R1)) ( (instances $R $Pos $H $R1) (mysetof $New (^ $I (^ $J (^ $H (, (member (with_self $I $H) $Pos) (store-ex $New + $J))))) $NewE))) +; + (= @@ -636,10 +786,14 @@ (minimize-output $Newpredlist $CL $CL1) (store-clauses $CL1 rul) (show-kb))) +; + (= (minimize_output () $CL $CL) True) +; + (= (minimize-output (Cons $P $R) $CL $CL2) @@ -658,4 +812,6 @@ (delete-all $IDL) (remove-v $P1L $R $R1) (minimize-output $R1 $CL1 $CL2))) +; + diff --git a/miles/gencon_instances/rul_ex.metta b/miles/gencon_instances/rul_ex.metta index a6167e6..f731340 100644 --- a/miles/gencon_instances/rul_ex.metta +++ b/miles/gencon_instances/rul_ex.metta @@ -1,246 +1,55 @@ ; -; ;; use init_kb('gilppi_instances/rul_ex.pl',type) for loading +; ; -; ;; ~~~~~ +; (= (matomic $X) (atomic $X)) +; + (= (matom $X) (atom $X)) +; + (= (mnumber $X) (number $X)) +; + (= (ex (t nil) +) True) -; /* -; ex(app([1,2]),'+'). -; ex(app([a]),'+'). -; ex(app([]),'+'). -; ex(app([p]),'+'). -; ex(app([r,s]),'+'). -; ex(app([g]),'+'). -; ex(app([9,8,7]),'+'). -; ex(app([4,3,5]),'+'). -; ex(app([r,w]),'+'). -; ex(app([j,k,l,m]),'+'). -; -; -; ex(split([3]),'+'). -; ex(split([4]),'+'). -; ex(split([1,2]),'+'). -; ex(split([55,66]),'+'). -; ex(split([7,8,9]),'+'). -; ex(split([11,12,13]),'+'). -; ex(split([14,15,16,17]),'+'). -; ex(split([18,19,20,21]),'+'). -; ex(split([22,23,24,25,26]),'+'). -; ex(split([27,28,29,30,31]),'+'). -; -; -; ex(obti([[],0,[]]),'+'). -; ex(obti([]),'+'). -; ex(obti([[],2,[]]),'+'). -; ex(obti([[[],1,[]],2,[[[],3,[]],4,[]]]),'+'). -; ex(obti([[[],6,[[],7,[]]],8,[[],9,[]]]),'+'). -; ex(obti([[[],89,[]],90,[[],91,[]]]),'+'). -; ex(obti([[[],91,[]],92,[[],93,[]]]),'+'). -; ex(obti([[],50,[[[],51,[]],52,[[],54,[]]]]),'+'). -; ex(obti([[[[],36,[]],37,[[],39,[]]],46,[]]),'+'). -; -; -; ex(plus(0),'+'). -; ex(plus(s(0)),'+'). -; ex(plus(s(s(0))),'+'). -; ex(plus(s(s(s(s(s(s(0))))))),'+'). -; ex(plus(s(s(s(0)))),'+'). -; ex(plus(s(s(s(s(0))))),'+'). -; -; -; -; ex(equiv(not(and([]))),'+'). -; ex(equiv(not(and([a]))),'+'). -; ex(equiv(not(and([b]))),'+'). -; ex(equiv(not(and([x,y]))),'+'). -; ex(equiv(not(and([r,s]))),'+'). -; ex(equiv(not(and([k,l,m]))),'+'). -; ex(equiv(not(and([kk,ll,mm]))),'+'). -; ex(equiv(not(and([h,i,j,k]))),'+'). -; ex(equiv(not(and([hh,ii,jj,kk]))),'+'). -; ex(equiv(not(and([c,d,e,f,g]))),'+'). -; ex(equiv(not(and([cc,dd,ee,ff,gg]))),'+'). -; ex(equiv(not(or([]))),'+'). -; ex(equiv(not(or([a1]))),'+'). -; ex(equiv(not(or([b1]))),'+'). -; ex(equiv(not(or([x1,y1]))),'+'). -; ex(equiv(not(or([r1,s1]))),'+'). -; ex(equiv(not(or([k1,l1,m1]))),'+'). -; ex(equiv(not(or([kk1,ll1,mm1]))),'+'). -; ex(equiv(not(or([h1,i1,j1,k1]))),'+'). -; ex(equiv(not(or([hh1,ii1,jj1,kk1]))),'+'). -; ex(equiv(not(or([c1,d1,e1,f1,g1]))),'+'). -; ex(equiv(not(or([cc1,dd1,ee1,ff1,gg1]))),'+'). -; ex(equiv(or([])),'+'). -; ex(equiv(or([not(a)])),'+'). -; ex(equiv(or([not(b)])),'+'). -; ex(equiv(or([not(x),not(y)])),'+'). -; ex(equiv(or([not(r),not(s)])),'+'). -; ex(equiv(or([not(k),not(l),not(m)])),'+'). -; ex(equiv(or([not(kk),not(ll),not(mm)])),'+'). -; ex(equiv(or([not(h),not(i),not(j),not(k)])),'+'). -; ex(equiv(or([not(hh),not(ii),not(jj),not(kk)])),'+'). -; ex(equiv(or([not(c),not(d),not(e),not(f),not(g)])),'+'). -; ex(equiv(or([not(cc),not(dd),not(ee),not(ff),not(gg)])),'+'). -; ex(equiv(and([])),'+'). -; ex(equiv(and([not(a1)])),'+'). -; ex(equiv(and([not(b1)])),'+'). -; ex(equiv(and([not(x1),not(y1)])),'+'). -; ex(equiv(and([not(r1),not(s1)])),'+'). -; ex(equiv(and([not(k1),not(l1),not(m1)])),'+'). -; ex(equiv(and([not(kk1),not(ll1),not(mm1)])),'+'). -; ex(equiv(and([not(h1),not(i1),not(j1),not(k1)])),'+'). -; ex(equiv(and([not(hh1),not(ii1),not(jj1),not(kk1)])),'+'). -; ex(equiv(and([not(c1),not(d1),not(e1),not(f1),not(g1)])),'+'). -; ex(equiv(and([not(cc1),not(dd1),not(ee1),not(ff1),not(gg1)])),'+'). -; -; -; ex(equiv(not(and([]))),'+'). -; ex(equiv(not(or([]))),'+'). -; ex(equiv(not(and([a]))),'+'). -; ex(equiv(not(or([b]))),'+'). -; ex(equiv(not(and([x,y]))),'+'). -; ex(equiv(not(or([r,s]))),'+'). -; ex(equiv(not(and([k,l,m]))),'+'). -; ex(equiv(not(or([kk,ll,mm]))),'+'). -; ex(equiv(and([])),'+'). -; ex(equiv(or([])),'+'). -; ex(equiv(and([not(a1)])),'+'). -; ex(equiv(or([not(b1)])),'+'). -; ex(equiv(and([not(x1),not(y1)])),'+'). -; ex(equiv(or([not(r1),not(s1)])),'+'). -; ex(equiv(and([not(k1),not(l1),not(m1)])),'+'). -; ex(equiv(or([not(kk1),not(ll1),not(mm1)])),'+'). -; -; -; newp4([A|B]):-matom(A),newp4(B). -; equiv(and(A)):-newp2(A). -; equiv(not A):-newp3(A). -; equiv(or(A)):-newp1(A). -; newp1([]). -; newp1([not A|B]):-matom(A),newp1(B). -; newp2([]). -; newp2([not A|B]):-matom(A),newp1(B). -; newp3(and(A)):-newp5(A). -; newp3(or(A)):-newp4(A). -; newp4([]). -; newp5([]). -; newp5([A|B]). -; -; -; -; ex(t(f(a,f(b,f(c,x)))),'+'). -; ex(t(f(d,f(e,f(f,f(g,x))))),'+'). -; ex(t(f(i,f(j,x))),'+'). -; ex(t(f(h,x)),'+'). -; ex(t(x),'+'). -; ex(t(f(k,g(y))),'+'). -; ex(t(f(m,g(g(y)))),'+'). -; ex(t(f(n,g(g(g(y))))),'+'). -; ex(t(f(o,g(g(g(g(y)))))),'+'). -; ex(t(f(p,y)),'+'). -; -; -; -; -; ex(r(x),'+'). -; ex(r(f(h,x)),'+'). -; ex(r(f(i,g(j,x))),'+'). -; ex(r(f(a,g(b,f(c,x)))),'+'). -; ex(r(f(d,g(e,f(f,g(g,x))))),'+'). -; ex(r(f(q,g(r,f(s,g(t,f(u,x)))))),'+'). -; ex(r(f(k,g(l,f(m,g(n,f(o,g(p,x))))))),'+'). -; ex(r(f(k1,g(l1,f(m1,g(n1,f(o1,g(p1,f(q1,x)))))))),'+'). -; -; -; -; -; ex(s(x),'+'). -; ex(s(f(h,x)),'+'). -; ex(s(f(g(j,x),g(j,x))),'+'). -; ex(s(f(g(b,h(c,x)),g(b,h(c,x)))),'+'). -; ex(s(f(g(e,h(f,f(g,x))),g(e,h(f,f(g,x))))),'+'). -; ex(s(f(g(r,h(s,f(t,g(u,x)))),g(r,h(s,f(t,g(u,x)))))),'+'). -; ex(s(f(g(l,h(m,f(n,g(o,h(p,x))))),g(l,h(m,f(n,g(o,h(p,x))))))),'+'). -; ex(s(f(g(l1,h(m1,f(n1,g(o1,h(p1,f(q1,x)))))),g(l1,h(m1,f(n1,g(o1,h(p1,f(q1,x)))))))),'+'). -; ex(s(f(g(l1,h(m1,f(n1,g(o1,h(p1,f(q1,g(r1,x))))))), -; g(l1,h(m1,f(n1,g(o1,h(p1,f(q1,g(r1,x))))))))),'+'). -; ex(s(f(g(l1,h(m1,f(n1,g(o1,h(p1,f(q1,g(t1,h(u1,x)))))))), -; g(l1,h(m1,f(n1,g(o1,h(p1,f(q1,g(t1,h(u1,x)))))))))),'+'). -; ex(s(f(g(l1,h(m1,f(n1,g(o1,h(p1,f(q1,g(v1,h(w1,f(x1,x))))))))), -; g(l1,h(m1,f(n1,g(o1,h(p1,f(q1,g(v1,h(w1,f(x1,x))))))))))),'+'). -; -; -; ex(i(not(not(and(a,a)))),'+'). -; ex(i(not(and(not(a),not(a)))),'+'). -; ex(i(not(and(not(a),and(a,a)))),'+'). -; ex(i(not(and(and(a,a),not(a)))),'+'). -; ex(i(not(and(and(a,a),and(a,a)))),'+'). -; ex(i(not(not(a))),'+'). -; ex(i(not(and(a,a))),'+'). -; ex(i(not(a)),'+'). -; ex(i(not(not(not(a)))),'+'). -; ex(i(and(not(not(a)),not(a))),'+'). -; ex(i(and(not(not(a)),and(not(a),not(a)))),'+'). -; ex(i(and(not(not(a)),and(not(a),and(a,a)))),'+'). -; ex(i(and(not(not(a)),and(not(a),a))),'+'). -; ex(i(and(not(and(a,a)),not(not(a)))),'+'). -; ex(i(and(not(and(a,a)),not(and(a,a)))),'+'). -; ex(i(and(not(and(a,a)),not(a))),'+'). -; ex(i(and(not(and(a,a)),and(not(a),not(a)))),'+'). -; ex(i(and(not(and(a,a)),and(not(a),and(a,a)))),'+'). -; ex(i(and(not(and(a,a)),and(not(a),a))),'+'). -; ex(i(and(not(not(a)),and(and(a,a),not(a)))),'+'). -; ex(i(and(not(not(a)),and(and(a,a),and(a,a)))),'+'). -; ex(i(and(and(not(a),not(a)),and(a,and(a,a)))),'+'). -; ex(i(and(and(not(a),not(a)),and(a,a))),'+'). -; ex(i(and(and(not(a),not(a)),a)),'+'). -; ex(i(and(and(not(a),and(a,a)),not(not(a)))),'+'). -; ex(i(and(not(a),not(a))),'+'). -; ex(i(and(not(a),and(a,a))),'+'). -; ex(i(and(not(a),a)),'+'). -; ex(i(and(and(a,a),not(a))),'+'). -; ex(i(and(and(a,a),and(a,a))),'+'). -; ex(i(and(and(a,a),a)),'+'). -; ex(i(and(a,not(a))),'+'). -; ex(i(and(a,and(a,a))),'+'). -; ex(i(and(a,a)),'+'). -; ex(i(a),'+'). -; */ - +; (= (ex (t (tree nil 0 nil)) +) True) +; + (= (ex (t (tree nil 0 (tree nil 0 nil))) +) True) +; + (= (ex (t (tree nil 0 (tree nil (s 0) nil))) +) True) +; + (= (ex (t @@ -248,6 +57,8 @@ (tree nil (s (s 0)) nil))) +) True) +; + (= (ex (t @@ -256,17 +67,23 @@ (s (s (s 0))) nil))) +) True) +; + (= (ex (t (tree nil (s 0) nil)) +) True) +; + (= (ex (t (tree nil (s 0) (tree nil 0 nil))) +) True) +; + (= (ex (t @@ -274,6 +91,8 @@ (s 0) (tree nil (s 0) nil))) +) True) +; + (= (ex (t @@ -282,6 +101,8 @@ (tree nil (s (s 0)) nil))) +) True) +; + (= (ex (t @@ -291,12 +112,16 @@ (s (s (s 0))) nil))) +) True) +; + (= (ex (t (tree nil (s (s 0)) nil)) +) True) +; + (= (ex (t @@ -304,6 +129,8 @@ (s (s 0)) (tree nil 0 nil))) +) True) +; + (= (ex (t @@ -312,6 +139,8 @@ (s 0)) (tree nil (s 0) nil))) +) True) +; + (= (ex (t @@ -321,6 +150,8 @@ (tree nil (s (s 0)) nil))) +) True) +; + (= (ex (t @@ -331,6 +162,8 @@ (s (s (s 0))) nil))) +) True) +; + (= (ex (t @@ -338,6 +171,8 @@ (s (s (s 0))) nil)) +) True) +; + (= (ex (t @@ -346,6 +181,8 @@ (s (s 0))) (tree nil 0 nil))) +) True) +; + (= (ex (t @@ -355,6 +192,8 @@ (s 0))) (tree nil (s 0) nil))) +) True) +; + (= (ex (t @@ -365,6 +204,8 @@ (tree nil (s (s 0)) nil))) +) True) +; + (= (ex (t @@ -376,17 +217,23 @@ (s (s (s 0))) nil))) +) True) +; + (= (ex (t (tree (tree nil 0 nil) 0 nil)) +) True) +; + (= (ex (t (tree (tree nil 0 nil) 0 (tree nil 0 nil))) +) True) +; + (= (ex (t @@ -394,6 +241,8 @@ (tree nil 0 nil) 0 (tree nil (s 0) nil))) +) True) +; + (= (ex (t @@ -402,6 +251,8 @@ (tree nil (s (s 0)) nil))) +) True) +; + (= (ex (t @@ -411,12 +262,16 @@ (s (s (s 0))) nil))) +) True) +; + (= (ex (t (tree (tree nil 0 nil) (s 0) nil)) +) True) +; + (= (ex (t @@ -424,6 +279,8 @@ (tree nil 0 nil) (s 0) (tree nil 0 nil))) +) True) +; + (= (ex (t @@ -432,6 +289,8 @@ (s 0) (tree nil (s 0) nil))) +) True) +; + (= (ex (t @@ -441,6 +300,8 @@ (tree nil (s (s 0)) nil))) +) True) +; + (= (ex (t @@ -451,6 +312,8 @@ (s (s (s 0))) nil))) +) True) +; + (= (ex (t @@ -458,6 +321,8 @@ (tree nil 0 nil) (s (s 0)) nil)) +) True) +; + (= (ex (t @@ -466,6 +331,8 @@ (s (s 0)) (tree nil 0 nil))) +) True) +; + (= (ex (t @@ -475,6 +342,8 @@ (s 0)) (tree nil (s 0) nil))) +) True) +; + (= (ex (t @@ -485,6 +354,8 @@ (tree nil (s (s 0)) nil))) +) True) +; + (= (ex (t @@ -496,6 +367,8 @@ (s (s (s 0))) nil))) +) True) +; + (= (ex (t @@ -504,6 +377,8 @@ (s (s (s 0))) nil)) +) True) +; + (= (ex (t @@ -513,6 +388,8 @@ (s (s 0))) (tree nil 0 nil))) +) True) +; + (= (ex (t @@ -523,6 +400,8 @@ (s 0))) (tree nil (s 0) nil))) +) True) +; + (= (ex (t @@ -534,6 +413,8 @@ (tree nil (s (s 0)) nil))) +) True) +; + (= (ex (t @@ -546,12 +427,16 @@ (s (s (s 0))) nil))) +) True) +; + (= (ex (t (tree (tree nil (s 0) nil) 0 nil)) +) True) +; + (= (ex (t @@ -559,6 +444,8 @@ (tree nil (s 0) nil) 0 (tree nil 0 nil))) +) True) +; + (= (ex (t @@ -567,6 +454,8 @@ (s 0) nil) 0 (tree nil (s 0) nil))) +) True) +; + (= (ex (t @@ -576,6 +465,8 @@ (tree nil (s (s 0)) nil))) +) True) +; + (= (ex (t @@ -586,6 +477,8 @@ (s (s (s 0))) nil))) +) True) +; + (= (ex (t @@ -593,6 +486,8 @@ (tree nil (s 0) nil) (s 0) nil)) +) True) +; + (= (ex (t @@ -601,6 +496,8 @@ (s 0) nil) (s 0) (tree nil 0 nil))) +) True) +; + (= (ex (t @@ -610,6 +507,8 @@ (s 0) (tree nil (s 0) nil))) +) True) +; + (= (ex (t @@ -620,6 +519,8 @@ (tree nil (s (s 0)) nil))) +) True) +; + (= (ex (t @@ -631,6 +532,8 @@ (s (s (s 0))) nil))) +) True) +; + (= (ex (t @@ -639,6 +542,8 @@ (s 0) nil) (s (s 0)) nil)) +) True) +; + (= (ex (t @@ -648,6 +553,8 @@ (s (s 0)) (tree nil 0 nil))) +) True) +; + (= (ex (t @@ -658,6 +565,8 @@ (s 0)) (tree nil (s 0) nil))) +) True) +; + (= (ex (t @@ -669,6 +578,8 @@ (tree nil (s (s 0)) nil))) +) True) +; + (= (ex (t @@ -681,6 +592,8 @@ (s (s (s 0))) nil))) +) True) +; + (= (ex (t @@ -690,6 +603,8 @@ (s (s (s 0))) nil)) +) True) +; + (= (ex (t @@ -700,6 +615,8 @@ (s (s 0))) (tree nil 0 nil))) +) True) +; + (= (ex (t @@ -711,6 +628,8 @@ (s 0))) (tree nil (s 0) nil))) +) True) +; + (= (ex (t @@ -723,6 +642,8 @@ (tree nil (s (s 0)) nil))) +) True) +; + (= (ex (t @@ -736,6 +657,8 @@ (s (s (s 0))) nil))) +) True) +; + (= (ex (t @@ -743,6 +666,8 @@ (tree nil (s (s 0)) nil) 0 nil)) +) True) +; + (= (ex (t @@ -751,6 +676,8 @@ (s (s 0)) nil) 0 (tree nil 0 nil))) +) True) +; + (= (ex (t @@ -760,6 +687,8 @@ (s 0)) nil) 0 (tree nil (s 0) nil))) +) True) +; + (= (ex (t @@ -770,6 +699,8 @@ (tree nil (s (s 0)) nil))) +) True) +; + (= (ex (t @@ -781,6 +712,8 @@ (s (s (s 0))) nil))) +) True) +; + (= (ex (t @@ -789,6 +722,8 @@ (s (s 0)) nil) (s 0) nil)) +) True) +; + (= (ex (t @@ -798,6 +733,8 @@ (s 0)) nil) (s 0) (tree nil 0 nil))) +) True) +; + (= (ex (t @@ -808,6 +745,8 @@ (s 0) (tree nil (s 0) nil))) +) True) +; + (= (ex (t @@ -819,6 +758,8 @@ (tree nil (s (s 0)) nil))) +) True) +; + (= (ex (t @@ -831,6 +772,8 @@ (s (s (s 0))) nil))) +) True) +; + (= (ex (t @@ -840,6 +783,8 @@ (s 0)) nil) (s (s 0)) nil)) +) True) +; + (= (ex (t @@ -850,6 +795,8 @@ (s (s 0)) (tree nil 0 nil))) +) True) +; + (= (ex (t @@ -861,6 +808,8 @@ (s 0)) (tree nil (s 0) nil))) +) True) +; + (= (ex (t @@ -873,6 +822,8 @@ (tree nil (s (s 0)) nil))) +) True) +; + (= (ex (t @@ -886,6 +837,8 @@ (s (s (s 0))) nil))) +) True) +; + (= (ex (t @@ -896,6 +849,8 @@ (s (s (s 0))) nil)) +) True) +; + (= (ex (t @@ -907,6 +862,8 @@ (s (s 0))) (tree nil 0 nil))) +) True) +; + (= (ex (t @@ -919,6 +876,8 @@ (s 0))) (tree nil (s 0) nil))) +) True) +; + (= (ex (t @@ -932,6 +891,8 @@ (tree nil (s (s 0)) nil))) +) True) +; + (= (ex (t @@ -946,6 +907,8 @@ (s (s (s 0))) nil))) +) True) +; + (= (ex (t @@ -954,6 +917,8 @@ (s (s (s 0))) nil) 0 nil)) +) True) +; + (= (ex (t @@ -963,6 +928,8 @@ (s (s 0))) nil) 0 (tree nil 0 nil))) +) True) +; + (= (ex (t @@ -973,6 +940,8 @@ (s 0))) nil) 0 (tree nil (s 0) nil))) +) True) +; + (= (ex (t @@ -984,6 +953,8 @@ (tree nil (s (s 0)) nil))) +) True) +; + (= (ex (t @@ -996,6 +967,8 @@ (s (s (s 0))) nil))) +) True) +; + (= (ex (t @@ -1005,6 +978,8 @@ (s (s 0))) nil) (s 0) nil)) +) True) +; + (= (ex (t @@ -1015,6 +990,8 @@ (s 0))) nil) (s 0) (tree nil 0 nil))) +) True) +; + (= (ex (t @@ -1026,6 +1003,8 @@ (s 0) (tree nil (s 0) nil))) +) True) +; + (= (ex (t @@ -1038,6 +1017,8 @@ (tree nil (s (s 0)) nil))) +) True) +; + (= (ex (t @@ -1051,6 +1032,8 @@ (s (s (s 0))) nil))) +) True) +; + (= (ex (t @@ -1061,6 +1044,8 @@ (s 0))) nil) (s (s 0)) nil)) +) True) +; + (= (ex (t @@ -1072,6 +1057,8 @@ (s (s 0)) (tree nil 0 nil))) +) True) +; + (= (ex (t @@ -1084,6 +1071,8 @@ (s 0)) (tree nil (s 0) nil))) +) True) +; + (= (ex (t @@ -1097,6 +1086,8 @@ (tree nil (s (s 0)) nil))) +) True) +; + (= (ex (t @@ -1111,6 +1102,8 @@ (s (s (s 0))) nil))) +) True) +; + (= (ex (t @@ -1122,6 +1115,8 @@ (s (s (s 0))) nil)) +) True) +; + (= (ex (t @@ -1134,6 +1129,8 @@ (s (s 0))) (tree nil 0 nil))) +) True) +; + (= (ex (t @@ -1147,6 +1144,8 @@ (s 0))) (tree nil (s 0) nil))) +) True) +; + (= (ex (t @@ -1161,6 +1160,8 @@ (tree nil (s (s 0)) nil))) +) True) +; + (= (ex (t @@ -1176,4 +1177,6 @@ (s (s (s 0))) nil))) +) True) +; + diff --git a/miles/interpreter.metta b/miles/interpreter.metta index 6a8b884..1e8a7ea 100644 --- a/miles/interpreter.metta +++ b/miles/interpreter.metta @@ -1,6 +1,6 @@ ; -; MODULE interpreter EXPORTS +; !(module interpreter @@ -19,15 +19,19 @@ (/ t-interpreter 2) (/ ip-part1 2) (/ ip-part2 3))) +; + ; -; IMPORTS +; !(use-module (home kb) (:: (/ get-clause 5) (/ interpretable-predicate 1))) +; + !(use-module (home div-utils) (:: @@ -35,158 +39,176 @@ (/ identical-member 2) (/ append-all 2) (/ mysetof 3))) +; + !(use-module (home bu-basics) (:: (/ head 3) (/ body 3) (/ assumption 3))) +; + !(use-module (home environment) (:: (/ satisfiable 1))) +; + !(use-module-if-exists (library basics) (:: (/ member 2))) +; + !(use-module-if-exists (library unify) (:: (/ unify 2))) +; + ; -; METAPREDICATES +; ; -; none +; - !(dynamic (, (/ failed-proof 1) (/ tag 1) (/ prooftrees 3) (/ depth-bound 1) (/ depth-exceeded 0) (/ depth-exceeded 3))) + !(dynamic (, (/ failed-proof 1) (/ tag 1) (/ prooftrees 3) (/ depth-bound 1) (/ depth-exceeded 0) (/ depth-exceeded 3))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * module: interpreter.pl +; ; -; * +; ; -; * author: B.Jung, M.Mueller, I.Stahl, B.Tausend date:12/92 +; ; -; * +; ; -; * changed: +; ; -; * +; ; -; * description: different interpreters working on the knowledge base +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: ip_part1/2 +; ; -; * +; ; -; * syntax: ip_part1(+Goal,-Proof) +; ; -; * +; ; -; * args: Goal: an uncovered positive example +; ; -; * Proof: a failing proof for the positive example +; ; -; * +; ; -; * description: works exactly as the general interpreter solve0/2. The only +; ; -; * difference is that instead of failing when a system goal is failing +; ; -; * or a proof is looping or rules are missing, the interpreter +; ; -; * continues, assuming that the failing goals should be correct +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (ip-part1 $Goal $Proof) - ( (remove-all-atoms &self + ( (remove-all-symbols &self (tag $_)) - (add-atom &self + (add-symbol &self (tag $Goal)) (gen-depth $D $Delta) (ipp1 $Goal $D $Delta $Proof $Proof Nil))) +; + (= (ipp1 True $D $Delta $Proof $Poi $_) ( (set-det) (= $Poi Nil))) +; + (= (ipp1 no-rule $_ $_ $_ $_ $_) (set-det)) +; + (= (ipp1 @@ -197,6 +219,8 @@ (ipp1 $A $D $Delta $Proof (:: $PoiA) $Ancestors) (ipp1 $B $D $Delta $Proof $PoiB $Ancestors))) +; + (= (ipp1 $A $D $Delta $Proof $Poi $Ancestors) @@ -205,7 +229,7 @@ (det-if-then-else (> $D 0) True (, - (add-atom &self + (add-symbol &self (tag $A)) (fail))) (det-if-then-else @@ -220,6 +244,8 @@ (:: (:: $I $A $PoiB))) (ipp1 $B $D1 $Delta $Proof $PoiB (Cons $A $Ancestors)))))) +; + (= (ipp1 $A $D $Delta $Proof $Poi $_) @@ -229,6 +255,8 @@ (:: (:: sys $A Nil))) (= $Poi (:: (:: sys $A fail))))) +; + @@ -236,73 +264,77 @@ (= (ipp1-rule $_ $_ $_ $_ $I $A $B) (get-clause $I $A $B $_ $_)) +; + (= (ipp1-rule $D $Delta $Proof $Poi $_ $A no-rule) (det-if-then-else (get-clause $_ $A $_ $_ $_) fail (= $Poi (:: (:: -1 $A no-rules))))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: ip_part2/3 +; ; -; * +; ; -; * syntax: ip_part2(+Proofs,+Goal,-Uncovered_Atoms) +; ; -; * +; ; -; * args: Proofs: failing proofs determined by ip_part1, +; ; -; * Goal: uncovered positive example Uncovered_Atoms: Atoms that make +; ; -; * Goal succeed, if they were covered by the kb +; ; -; * +; ; -; * description: the satisfiability of each subgoal within failing proof is +; ; -; * determined. For that, the oracle might be necessary. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -310,10 +342,14 @@ (ip-part2 (Cons $P $_) $Goal $UA) (ipp2 $P Nil Nil $UA)) +; + (= (ip-part2 (Cons $_ $R) $Goal $UA) (ip-part2 $R $Goal $UA)) +; + (= @@ -322,6 +358,8 @@ (Cons (with_self $I $H) $L)) (set-det)) +; + (= (ipp2 (:: sys $_ fail) @@ -330,16 +368,22 @@ (Cons (with_self $I $A) $L)) (set-det)) +; + (= (ipp2 (:: $_ $_ Nil) $_ $L $L) (set-det)) +; + (= (ipp2 (:: $_ $H no-rules) $_ $L (Cons (with_self -1 $H) $L)) (set-det)) +; + (= (ipp2 (:: $I $H $SG) $Ancestors $L $L1) @@ -351,82 +395,88 @@ (= $L1 (Cons (with_self $I $H) $L)))) +; + (= (ipp2_list () $_ $L $L) True) +; + (= (ipp2-list (Cons $G $R) $A $L $L2) ( (ipp2 $G $A $L $L1) (ipp2-list $R $A $L1 $L2))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: proof_path/4 +; ; -; * +; ; -; * syntax: proof_path(+Ex,+Pred,+Type,-ClauseIDs) +; ; -; * +; ; -; * args: Ex: example for p/n +; ; -; * Pred = p(X1,..,Xn): most general term of p/n +; ; -; * Type = typei(Xi) for an argument of p/n +; ; -; * ClauseIDs: list of clauseIDs that have beed used for proving +; ; -; * typei(ei) for the ith argument of Ex +; ; -; * +; ; -; * description: simulates the proof of typei(ei) for the ith argument of Ex +; ; -; * and collects the indices of all used clauses +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -435,21 +485,29 @@ ( (copy-term (, $P $T) (, $Ex $T0)) (proof-path $T0 Nil $Ts))) +; + (= (proof-path True $T $T) (set-det)) +; + (= (proof-path (, $A $B) $T $T2) ( (set-det) (proof-path $A $T $T1) (proof-path $B $T1 $T2))) +; + (= (proof-path $A $T $T) ( (=.. $A (Cons all $_)) (set-det))) +; + (= (proof-path $A $T $T) ( (=.. $A @@ -461,79 +519,87 @@ (= $T1 number))) (set-det) (call $A))) +; + (= (proof-path $A $T $T1) ( (get-clause $I $A $B $_ type) (proof-path $B $T $T0) (insert-unique $I $T0 $T1))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: t_interpreter/2 +; ; -; * +; ; -; * syntax: t_interpreter(+Goal,+ClauseList) +; ; -; * +; ; -; * args: Goal: goal type(Arg), Arg ground +; ; -; * ClauseList: List of clauses defining different types +; ; -; * +; ; -; * description: proves type(Arg) from ClauseList as kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (t-interpreter True $_) (set-det)) +; + (= (t-interpreter (, $A $B) $CL) ( (set-det) (t-interpreter $A $CL) (t-interpreter $B $CL))) +; + (= (t-interpreter $C $_) ( (=.. $C @@ -545,101 +611,105 @@ (= $P symbolic))) (set-det) (call $C))) +; + (= (t-interpreter $C $CL) ( (copy-term $CL $CL1) (member (= $C $B) $CL1) (t-interpreter $B $CL))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: solve/3 +; ; -; * +; ; -; * syntax: solve(+Goal,-Mark,-Proofs) +; ; -; * +; ; -; * args: Goal: ground atom or rule with ground head +; ; -; * Mark: success or fail +; ; -; * Proofs: all succeeding/failing proofs according to Mark +; ; -; * +; ; -; * description: format for Proofs: [P1,..,Pn] +; ; -; * where Pi = [ID,Head,PBody] where ID is the ID of the +; ; -; * applied rule (sys for system predicates, -1 if no rule +; ; -; * is applicable), Head is the instantiation of the rule head, +; ; -; * and PBody is the proof of the rule body. PBody is of the form +; ; -; * - [], if Head is true +; ; -; * - fail, if Head is a failing syspred +; ; -; * - looping if the proof is looping on Head +; ; -; * - no_rules if no rules match Head +; ; -; * - depth_exceeded if the proof fails because of depth bound +; ; -; * Maximum depth for proofs: 50 +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; @@ -652,6 +722,8 @@ (, (set-det) (fail)))) +; + (= (solve $Goal $Mark $Proofs) @@ -674,58 +746,60 @@ (= $Proofs0 $Proofs00)))) (append-all $Proofs0 $Proofs1) (proof-close $Proofs1 $Proofs))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: solve_once/3 +; ; -; * +; ; -; * syntax: solve_once(+Goal,-Mark,-Proof) +; ; -; * +; ; -; * args: as solve/3 +; ; -; * +; ; -; * description: proves Goal only once +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -738,6 +812,8 @@ (, (set-det) (fail)))) +; + (= (solve-once $Goal $Mark $Proofs) @@ -753,65 +829,69 @@ (= $Mark fail))) (append-all $Proofs0 $Proofs1) (proof-close $Proofs1 $Proofs))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: proof_close/2 +; ; -; * +; ; -; * syntax: proof_close(+Proofs,-Proofs) +; ; -; * +; ; -; * args: Proofs as for solve/3 +; ; -; * +; ; -; * description: closes the open lists in Proofs +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (proof-close $X Nil) ( (var $X) (set-det))) +; + (= (proof-close (Cons @@ -819,81 +899,89 @@ (Cons (:: $J $H $B2) $R2)) ( (proof-close $B1 $B2) (proof-close $R1 $R2))) +; + (= (proof-close $X $X) ( (atomic $X) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: solve0/2 +; ; -; * +; ; -; * syntax: solve0(+Goal,-Proof) +; ; -; * +; ; -; * args: Goal: ground atom, Proof: one possible proof for Goal +; ; -; * +; ; -; * description: +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (solve0 $Goal $Proof) - ( (remove-all-atoms &self + ( (remove-all-symbols &self (tag $_)) - (remove-all-atoms &self + (remove-all-symbols &self (failed_proof $_)) - (remove-all-atoms &self + (remove-all-symbols &self (depth_exceeded $_ $_ $_)) - (remove-all-atoms &self depth_exceeded) + (remove-all-symbols &self depth_exceeded) (gen-depth $D $Delta) (solve2 $Goal $D $Delta $Proof $Proof Nil))) +; + (= (solve2 True $_ $_ $_ Nil $_) (set-det)) +; + (= @@ -905,6 +993,8 @@ (solve2 $A $D $Delta $Proof (:: $PoiA) $Ancestors) (solve2 $B $D $Delta $Proof $PoiB $Ancestors))) +; + (= @@ -914,9 +1004,9 @@ (det-if-then-else (= $D 0) (, - (add-atom &self + (add-symbol &self (tag $A)) - (add-atom &self + (add-symbol &self (depth_exceeded $A $Proof $Poi)) (fail)) (det-if-then-else @@ -926,7 +1016,7 @@ (:: (:: -1 $A looping))) (det-if-then-else (< $D $Delta) - (add-atom &self + (add-symbol &self (failed_proof $Proof)) True) (fail)) (, @@ -937,8 +1027,7 @@ (:: (:: $I $A $PoiB))) (solve2 $B $D1 $Delta $Proof $PoiB (Cons $A $Ancestors))))))) -; ; A is in KB - +; (= @@ -955,13 +1044,10 @@ (:: (:: sys $A fail))) (det-if-then-else (< $D $Delta) - (add-atom &self + (add-symbol &self (failed_proof $Proof)) True) (fail)))) -; ; A is built-in - -; ; exception handling - +; @@ -970,73 +1056,72 @@ ( (not depth-exceeded) (= $Poi (:: (:: -1 $A no-rules))) - (add-atom &self + (add-symbol &self (failed_proof $Proof)) (fail))) -; ; no rules at all for initial goal - +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: solve_rule/7 +; ; -; * +; ; -; * syntax: solve_rule(+D,+Delta,+Proof,+Proof_Poi,-ID,+Goal,-Body) +; ; -; * +; ; -; * args: D,Delta: depth bounds for iterative deepening +; ; -; * Proof,Proof_Poi: intermediate Proof of the toplevel goal (open list) +; ; -; * Goal: current goal +; ; -; * ID,Body: id and body of a kb-rule matchin Goal (if any) +; ; -; * +; ; -; * description: +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1046,113 +1131,99 @@ (functor $A1 $F $N) (get-clause $I $A1 $B $_ $_) (unify $A $A1))) +; + (= (solve-rule $D $Delta $Proof $Poi $_ $A $_) ( (= $Poi (:: (:: -1 $A no-more-rules))) (det-if-then-else (< $D $Delta) - (add-atom &self + (add-symbol &self (failed_proof $Proof)) True) (fail))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: gen_depth/2 +; ; -; * +; ; -; * syntax: gen_depth(D, Delta) +; ; -; * +; ; -; * args: D,Delta: integers +; ; -; * +; ; -; * description: generates depth bound for the interative deepening +; ; -; * theorem prover. Delta is the difference between D and +; ; -; * the former depth (not to create duplicate proofs) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (gen-depth $D $Delta) ( (depth-bound $N) (det-if-then-else (number $N) (det-if-then-else (>= $N 3) (gen-depth 3 $D 3 $Delta) (gen-depth $N $D $N $Delta)) (gen-depth 3 $D 3 $Delta)))) -; /***** gen_depth without maximum depth***** -; gen_depth(D, Delta) :- -; gen_depth(3, 100, D, Delta). -; -; -; gen_depth(D, Delta, D, Delta). ; -; gen_depth(D0, _, D, Delta) :- -; Delta1 is D0 div 2 + 1, -; D1 is D0 + Delta1, -; ( tag(_) -> -; retractall(tag(_)), -; gen_depth(D1, Delta1, D, Delta) -; ; fail -; ). -; *******/ - -; ; D = new depth for proofs - -; ; Delta = new D - former D - (= (gen_depth $D $D $Delta $Delta) True) +; + (= (gen-depth $D0 $D $_ $Delta) (det-if-then-else (tag $_) (, - (remove-all-atoms &self + (remove-all-symbols &self (tag $_)) (is $Delta1 (+ @@ -1164,12 +1235,14 @@ (number $Max) (det-if-then-else (=< $D1 $Max) - (remove-all-atoms &self + (remove-all-symbols &self (depth_exceeded $_ $_ $_)) (, - (add-atom &self depth_exceeded) + (add-symbol &self depth_exceeded) (fail))) True) (gen-depth $D1 $D $Delta1 $Delta)) fail)) +; + (= @@ -1178,279 +1251,187 @@ (nl) (write 'Speficy maximum depth for theorem prover (number or n for unbound proofs): ') (read $N) - (remove-all-atoms &self + (remove-all-symbols &self (depth_bound $_)) - (add-atom &self + (add-symbol &self (depth_bound $N)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: prove1/2 +; ; -; * +; ; -; * syntax: prove1(+Clause, -Proof) +; ; -; * +; ; -; * args: Clause: clause in list form ( [H:p,L1:n,L2:n,..]) +; ; -; * Proof: list of all literals used to prove clause +; ; -; * +; ; -; * description: +; ; -; * prove1 tries to match Clause against literals in this kb, +; ; -; * use for clause reduction wrt theta-subsumption (Plotkin). +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: Buntine,1988. Plotkin,1970. +; ; -; * +; ; -; *********************************************************************** +; (= (prove1 $CL $SProof) ( (ini-prove1 $CL $CL1) (prove1a $CL1 Nil $SProof))) -; /* -; prove1([H|T],Proof):- -; prove1(H,HProof), -; prove1(T,TProof), -; append(HProof,TProof,Proof). -; prove1([],[]). -; prove1(L:S,[L:S]):- -; member(S,[n,r]), -; body(L,_O,_I). -; prove1(L:p,[L:p]):- -; head(L,_O,_I). -; */ - -; ;*********************************************************************** -; ;* -; ;* predicate: prove1/2 -; ;* -; ;* syntax: prove1(+Clause, -Proof) -; ;* -; ;* args: Clause: clause in list form ( [H:p,L1:n,L2:n,..]) -; ;* Proof: list of all literals used to prove clause -; ;* -; ;* description: -; ;* prove1 tries to match Clause against literals in this kb, -; ;* use for clause reduction wrt theta-subsumption (Plotkin). -; ;* This is a more efficient version for embedding Clause in the kb: -; ;* (IRENE) -; ;* a list CL1 = [Lit:Sign:Litlist|_] is constructed from Clause -; ;* where Litlist is the list of literals in the kb (if Sign = p, literals -; ;* head(L,_,_), else body(L,_,_)) unifiable with Lit. CL1 is sorted -; ;* ascendingly according to the length of Litlist. If there is an -; ;* empty Litlist in CL1, prove1a fails and backtracking occurs. -; ;* Else Lit is unified with a literal in Litlist (backtracking point), -; ;* and the remaining list CL1 is updated. -; ;* -; ;* example: -; ;* -; ;* peculiarities: -; ;* -; ;* see also: Buntine,1988. Plotkin,1970. -; ;* -; ;*********************************************************************** - +; (= (prove1a () $SP $SP) True) - (= - (prove1a $L $_ $_) - ( (member - (with_self $_ - (with_self $_ Nil)) $L) - (set-det) - (fail))) - (= - (prove1a - (Cons - (with_self $Lit - (with_self $S $LitL)) $R) $SProof $SP) - (det-if-then-else - (ground $Lit) - (prove1a $R - (Cons - (with_self $Lit $S) $SProof) $SP) - (, - (member $Lit $LitL) - (adapt-prove1 $R $Lit $S $R1) - (prove1a $R1 - (Cons - (with_self $Lit $S) $SProof) $SP)))) +; + +; (error +; (syntax_error operator_clash) +; (file miles/interpreter.pl 618 26 17908)) + +; (error +; (syntax_error operator_clash) +; (file miles/interpreter.pl 619 13 17937)) + (= (ini_prove1 () ()) True) - (= - (ini-prove1 - (Cons - (with_self $Lit $S) $R) $R2) - ( (ini-prove1 $R $R1) - (det-if-then-else - (= $S p) - (mysetof $H - (^ $M - (^ $O - (, - (head $H $M $O) - (not (not (= $Lit $H)))))) $LitL) - (mysetof $H - (^ $M - (^ $O - (, - (body $H $M $O) - (not (not (= $Lit $H)))))) $LitL)) - (insert-prove1 - (with_self $Lit - (with_self $S $LitL)) $R1 $R2))) - - - (= - (insert-prove1 - (with_self $L - (with_self $S $LL)) - (Cons - (with_self $L1 - (with_self $S1 $LL1)) $R) - (Cons - (with_self $L1 - (with_self $S1 $LL1)) $R1)) - ( (length $LL $LLN) - (length $LL1 $LL1N) - (> $LLN $LL1N) - (set-det) - (insert-prove1 - (with_self $L - (with_self $S $LL)) $R $R1))) +; + +; (error +; (syntax_error operator_clash) +; (file miles/interpreter.pl 634 20 18344)) + + +; (error +; (syntax_error operator_clash) +; (file miles/interpreter.pl 636 16 18376)) + + (= (insert_prove1 $X $L (Cons $X $L)) True) +; + (= (adapt_prove1 () $_ $_ ()) True) - (= - (adapt-prove1 - (Cons - (with_self $Lit - (with_self $S $_)) $R) $Lit1 $S1 $R1) - ( (== $Lit $Lit1) - (== $S $S1) - (set-det) - (adapt-prove1 $R $Lit1 $S1 $R1))) - (= - (adapt-prove1 - (Cons - (with_self $Lit - (with_self $S $LL)) $R) $Lit1 $S1 $R2) - ( (mysetof $X - (, - (member $X $LL) - (not (not (= $Lit $X)))) $LL1) - (adapt-prove1 $R $Lit1 $S1 $R1) - (insert-prove1 - (with_self $Lit - (with_self $S $LL1)) $R1 $R2))) +; + +; (error +; (syntax_error operator_clash) +; (file miles/interpreter.pl 643 18 18567)) + +; (error +; (syntax_error operator_clash) +; (file miles/interpreter.pl 646 18 18664)) + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: prove3/2 +; ; -; * +; ; -; * syntax: prove3(+CL,-CL) +; ; -; * +; ; -; * args: CL: clause body in list notation +; ; -; * +; ; -; * description: embedd CL in skolemized body of an example clause +; ; -; * (body/3 entries in the kb) +; ; -; * used for absorption, saturation +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1459,8 +1440,12 @@ (Cons $A $B) (Cons $ProofA $ProofB)) ( (prove3 $A $ProofA) (prove3 $B $ProofB))) +; + (= (prove3 () ()) True) +; + (= (prove3 @@ -1469,6 +1454,8 @@ (with_self $A (n))) (body $A $_ $_)) +; + (= (prove3 (with_self $A @@ -1476,70 +1463,72 @@ (with_self $A (r))) (body $A $_ $_)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: prove4/3 +; ; -; * +; ; -; * syntax: prove4(+CL,-Uncovered,-Proof) +; ; -; * +; ; -; * args: CL: clause in list notation +; ; -; * Uncovered = H/M, where M in {new_head,new_body} +; ; -; * or Uncovered = [] if all literals are covered +; ; -; * Proof = [[Lit,N],...] where N in {head,body} +; ; -; * +; ; -; * description: embeds CL in skolemized example clause (head/3,body/3 entries) +; ; -; * allows 1 uncovered literal (= the resolution literal) & returns it +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1548,121 +1537,149 @@ (Cons $H $More) $Uncovered (Cons $ProofH $ProofRest)) ( (prove4 $H $Uncovered $ProofH) (prove4 $More $Uncovered $ProofRest))) +; + (= (prove4 Nil Nil Nil) (set-det)) +; + (= (prove4 Nil $_ Nil) (set-det)) +; + (= (prove4 (with_self $H (n)) $_ (:: $H body)) (body $H $_ $_)) +; + (= (prove4 (with_self $H (r)) $_ (:: $H body)) (body $H $_ $_)) +; + (= (prove4 (with_self $H (p)) $_ (:: $H head)) (head $H $_ $_)) +; + (= (prove4 (with_self $H (n)) $Uncovered Nil) ( (var $Uncovered) (= $Uncovered (/ $H new-head)))) +; + (= (prove4 (with_self $H (r)) $Uncovered Nil) ( (var $Uncovered) (= $Uncovered (/ $H new-head)))) +; + (= (prove4 (with_self $H (p)) $Uncovered Nil) ( (var $Uncovered) (= $Uncovered (/ $H new-body)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: prove5/2 +; ; -; * +; ; -; * syntax: prove5(+HS,+RuleIDs) +; ; -; * +; ; -; * args: HS: skolemized clause head, RuleIDs: list of ruleIDs +; ; -; * +; ; -; * description: tries to infer HS from assumptions and the rules in +; ; -; * RuleIDs +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (prove5 $H $_) (assumption $H $_ $_)) +; + (= (prove5 true $_) True) +; + (= (prove5 $H $RULES) ( (get-clause $ID $H True $_ $_) (member $ID $RULES))) +; + (= (prove5 (, $L1 $L2) $RULES) ( (prove5 $L1 $RULES) (prove5 $L2 $RULES))) +; + (= (prove5 $H $RULES) ( (get-clause $ID $H $B $_ $_) (member $ID $RULES) (prove5 $B $RULES))) +; + diff --git a/miles/kb.metta b/miles/kb.metta index 10913c8..8f1d02a 100644 --- a/miles/kb.metta +++ b/miles/kb.metta @@ -1,5 +1,5 @@ ; -; MODULE kb EXPORTS +; !(module kb @@ -52,84 +52,19 @@ (/ ex 3) (/ assertallz 1) (/ interpretable-predicate 1))) -; ; Read, store and evaluate background knowledge - -; ; and examples, label them 'usr' - -; ; same as before, using specified label - -; ; Save knowledge base to qof-file - -; ; Consult qof-file without additional processing - -; ; generates a new kb id - -; ; last generated id - -; ; Store horn-clause or Clist in kb - -; ; Store a list of Clauses in kb - -; ; as store_clauses,but returns clauseIDs - -; ; Store example in kb - -; ; example | - -; ; Retrieve clause | from knowledge base - -; ; fact | - -; ; clause-evaluation| - -; ; Remove everything - -; ; Remove clauses one by one - -; ; Remove examples one by one - -; ; one random pos. example - -; ; 2 random pos. examples - -; ; 2 random uncovered pos. examples - -; ; 2 random examples from given list - -; ; i random pos. examples - -; ; shortest clause - -; ; shortest clause with label - -; ; 2 shortest clauses - -; ; 2 shortest clauses with label - -; ; shortest pos. example - -; ; shortest uncovered pos. example - -; ; shortest ex from list - -; ; 2 shortest pos. examples - -; ; 2 shortest pos. uncovered ex - -; ; list of all shortest pos. examples - -; ; list of all shortest uncovered pos. examples - +; ; -; IMPORTS +; !(use-module (home div-utils) (:: (/ body2list 2) (/ mysetof 3))) +; + !(use-module (home evaluation) (:: @@ -137,339 +72,363 @@ (/ complexity 2) (/ evaluated 1) (/ change-evaluated 1))) +; + !(use-module (home argument-types) (:: (/ type-restriction 2) (/ verify-types 0))) +; + !(use-module (home flatten) (:: (/ flatten-clause 2) (/ unflatten-clause 2))) +; + !(use-module (home interpreter) (:: (/ prooftrees 3))) +; + !(use-module-if-exists (library prompt)) +; + !(use-module-if-exists (library ask) (:: (/ yesno 1))) +; + !(use-module-if-exists (library basics) (:: (/ nonmember 2) (/ member 2))) +; + !(use-module-if-exists (library random) (:: (/ random-select 3))) +; + ; -; METAPREDICATES +; ; -; none +; !(dynamic (, (/ id-count 1) (/ ex 3) (/ known 6))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * module: kb.pl +; ; -; * +; ; -; * author: B.Jung, M.Mueller, I.Stahl, B.Tausend date:12/92 +; ; -; * +; ; -; * changed: +; ; -; * +; ; -; * description: - knowledge base handling +; ; -; * - flatten / unflatten knowledge base ( clauses & examples) +; ; -; * - heuristics to select examples from kb randomly +; ; -; * or according to their complexities. +; ; -; * It is assumed that the examples' current evaluation +; ; -; * corresponds to the current rules. +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: gen_id/1 +; ; -; * +; ; -; * syntax: gen_id(-New) +; ; -; * +; ; -; * args: -New kbID +; ; -; * +; ; -; * description: generates a new kb id +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (gen-id $New) - ( (remove-atom &self + ( (remove-symbol &self (id_count $Old)) (is $New (+ $Old 1)) - (add-atom &self + (add-symbol &self (id_count $New)))) +; + (= (gen-id 1) - (add-atom &self + (add-symbol &self (id_count 1))) +; + ; -; **************************************************************************************** +; ; -; * +; ; -; * predicate: init_kb/1,2 +; ; -; * +; ; -; * syntax: init_kb (+Filename) +; ; -; * init_kb (+Filename, +Label) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: the file Filename may contain Horn clauses "H:-B." and +; ; -; * "H.", examples "ex(Fact,Class)" and comments ";* blabla". +; ; -; * Examples are stored in the kb as "ex(ID, Fact, Class)", +; ; -; * clauses as +; ; -; * "known(ID,Head,Body,Clist,Label,evaluation(1,2,3,4,5,6,7,8,9))". +; ; -; * where ID ... unique kb identifier (a natural number) +; ; -; * Class ... +,-,? +; ; -; * Clist ... clause in list representation +; ; -; * [head:p, body1:n, body2:n, body3:r, ...]. Each literal is +; ; -; * marked p(positiv), n(negativ) or r(negativ + redundant) +; ; -; * Label ... e.g. the generating operator +; ; -; * default used for init_kb/1: usr +; ; -; * evaluation ... of the clauses w.r.t. the examples: +; ; -; * 1... #applications of the clause +; ; -; * 2... #definitively positive examples covered by the clause +; ; -; * 3... list of definitively positive examples covered by the clause +; ; -; * of the form [...exID:Fact........] +; ; -; * 4... #definitively negative examples covered by the clause +; ; -; * 5... list of definitively negative examples covered by the clause +; ; -; * of the form [...exID:Fact........] +; ; -; * 6... #probably positive examples covered by the clause +; ; -; * i.e. instantiations of the clause used in successful +; ; -; * proofs of positive examples +; ; -; * 7... list of probably positive examples covered by the clause +; ; -; * [...exID:Fact........] where exID is the example of which the +; ; -; * proof uses fact as subgoal +; ; -; * 8... #probably negative examples covered by the clause +; ; -; * i.e. instantiations of the clause used in successful +; ; -; * proofs of negative examples +; ; -; * 9... list of probably negative examples covered by the clause +; ; -; * [...exID:Fact........] where exID is the example of which the +; ; -; * proof uses fact as subgoal +; ; -; * +; ; -; * For each example, all possible prooftrees are stored in the kb: +; ; -; * "prooftrees(ID,M,Trees)" where M is success or fail and Trees contains +; ; -; * all successful or failing proofs of example ID. +; ; -; * +; ; -; * init_kb can be used successively for different files +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ***************************************************************************************** +; (= (init-kb $Filename) (init-kb $Filename usr)) +; + (= (init-kb $Filename $Origin) @@ -481,116 +440,120 @@ (set-det) (eval-examples) (verify-types))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: consult_kb/1 +; ; -; * +; ; -; * syntax: consult_kb(+ Filename) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: Restore knowledge base from qof-file which was produced by save_kb/1. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (consult-kb $Filename) ( (clear-kb) $Filename)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: save_kb/1 +; ; -; * +; ; -; * syntax: save_kb(+ Filename) +; ; -; * +; ; -; * args: Filename: name of a file (.qof) +; ; -; * +; ; -; * description: Save snapshot of current knowledge base as compiled file +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: suffix, .qof is recommended for Filename. +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -604,241 +567,252 @@ (/ id-count 1) (/ type-restriction 2) (/ evaluated 1)) $Filename)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: clear_kb/0 +; ; -; * +; ; -; * syntax: - +; ; -; * +; ; -; * args: none +; ; -; * +; ; -; * description: deletes all rules and examples from the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (clear-kb) - ( (remove-all-atoms &self + ( (remove-all-symbols &self (known $_ $_ $_ $_ $_ $_)) - (remove-all-atoms &self + (remove-all-symbols &self (ex $_ $_ $_)) - (remove-all-atoms &self + (remove-all-symbols &self (prooftrees $_ $_ $_)) - (remove-all-atoms &self + (remove-all-symbols &self (id_count $_)) - (remove-all-atoms &self + (remove-all-symbols &self (type_restriction $_ $_)) - (remove-all-atoms &self + (remove-all-symbols &self (evaluated $_)))) -; ;nl,yesno('Delete all knowledge and examples (y/n) '), - +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: store_term/2 +; ; -; * +; ; -; * syntax: store_term(+Term,+Label) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: stores clause Term or example Term read from the +; ; -; * input file during init_kb in the kb using known/6 +; ; -; * or ex/3 +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (store-term end-of-file $_) (set-det)) +; + (= (store-term (ex $F $C) $_) ( (gen-id $ID) - (add-atom &self + (add-symbol &self (ex $ID $F $C)) (set-det) (fail))) +; + (= (store-term (= $H $B) $O) ( (body2list $B $L) (gen-id $ID) - (add-atom &self + (add-symbol &self (known $ID $H $B (Cons (: $H p) $L) $O (evaluation 0 0 () 0 () 0 () 0 ()))) (set-det) (fail))) +; + (= (store-term (type-restriction $M $A) $_) - ( (add-atom &self + ( (add-symbol &self (: argument_types (type_restriction $M $A))) (set-det) (fail))) +; + (= (store-term $H $O) ( (gen-id $ID) - (add-atom &self + (add-symbol &self (known $ID $H true ( (: $H p)) $O (evaluation 0 0 () 0 () 0 () 0 ()))) (set-det) (fail))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: store_clause/4 +; ; -; * +; ; -; * syntax: store_clause (?MeTTa-clause,?clause-list,+label,-ID) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: Store new clause in knowledge base (provide either horn-clause +; ; -; * or clause-list), label it and receive the unique clause-ID. +; ; -; * If store_clause is called with ID instantiated, it will fail if ID is +; ; -; * already in use in the knowledge-base. If not, ID will be used. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -860,6 +834,8 @@ (, (set-det) (fail)) fail))) +; + (= (store-clause (= $H $B) @@ -876,13 +852,15 @@ (det-if-then-else (var $Label) (= $Label usr) True) - (add-atom &self + (add-symbol &self (known $ID $H $B (Cons (: $H p) $L) $Label (evaluation 0 0 () 0 () 0 () 0 ()))) (set-det) (change-evaluated no))) +; + (= (store-clause $H (:: (with_self $H (p))) $Label $ID) @@ -895,196 +873,206 @@ (det-if-then-else (var $Label) (= $Label usr) True) - (add-atom &self + (add-symbol &self (known $ID $H true ( (: $H p)) $Label (evaluation 0 0 () 0 () 0 () 0 ()))) (set-det) (change-evaluated no))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: store_clauses/2 +; ; -; * +; ; -; * syntax: store_clauses(+List_of_Clauses,+Label) +; ; -; * +; ; -; * args: List_of_Clauses ... list of MeTTa clauses +; ; -; * +; ; -; * description: Same as store_clause/4 for a list of clauses +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (store_clauses () $_) True) +; + (= (store-clauses (Cons $C $R) $Label) ( (store-clause $C $_ $Label $_) (store-clauses $R $Label))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: store_clauses/3 +; ; -; * +; ; -; * syntax: store_clauses(+List_of_Clauses,+Label,-IDlist) +; ; -; * +; ; -; * args: List_of_Clauses ... list of MeTTa clauses +; ; -; * IDlist... kb-ids for the clauses +; ; -; * +; ; -; * description: Same as store_clauses/2, but returns IDs of the clauses +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (store_clauses () $_ ()) True) +; + (= (store-clauses (Cons $C $R) $Label (Cons $ID $R1)) ( (store-clause $C $_ $Label $ID) (store-clauses $R $Label $R1))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: store_ex/3 +; ; -; * +; ; -; * syntax: store_ex(?fact,?classification,-ID) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: Store new example in knowledge base and receive the +; ; -; * unique identification number. +; ; -; * If it is called with ID already instantiated: see above. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1095,6 +1083,8 @@ (set-det) (= $Class $Class1) (= $ID $ID1))) +; + (= (store-ex $F $_ $ID) (det-if-then-else @@ -1111,6 +1101,8 @@ (, (set-det) (fail)) fail))) +; + (= (store-ex $Fact $Class $ID) ( (det-if-then-else @@ -1119,234 +1111,254 @@ (, (id-count $Top) (=< $ID $Top))) - (add-atom &self + (add-symbol &self (ex $ID $Fact $Class)) (set-det) (change-evaluated no))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: get_example/3 +; ; -; * get_clause/5 +; ; -; * get_fact/4 +; ; -; * get_evaluation/2 +; ; -; * +; ; -; * syntax: get_example (? ID, ? Example, ? Classification) +; ; -; * get_clause (? ID, ? Head, ? Body, ? Clist, ? Label) +; ; -; * get_fact (? ID, ? Fact, ? Clist, ? Label) +; ; -; * get_evaluation (+ ID, - Evaluation) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: read example/clause/fact or clause evaluation from the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (get-example $ID $F $C) (ex $ID $F $C)) +; + (= (get-clause $ID $H $B $L $O) - (known $ID $H $B $L $O $_)) + (known $ID $H $B $L $O $_)) +; + (= (get-fact $ID $F $L $O) (known $ID $F True $L $O $_)) +; + (= (get-evaluation $ID $Eval) (known $ID $_ $_ $_ $_ $Eval)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: delete_clause/1 , delete_example/1, delete_all/1 +; ; -; * +; ; -; * syntax: delete_clause(+ ID) , delete_example(+ ID), +; ; -; * delete_all(+list_of_clauseIDs) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: delete clause(s)/example(s) with identifier(s) ID(list_of_clauseIDs) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (delete-clause $ID) - ( (remove-atom &self + ( (remove-symbol &self (known $ID $_ $_ $_ $_ $_)) (change-evaluated no))) +; + (= (delete-example $ID) - ( (remove-atom &self + ( (remove-symbol &self (ex $ID $_ $_)) (change-evaluated no))) +; + (= (delete-all Nil) - (set-det)) + (set-det)) +; + (= (delete-all (Cons $Id1 $Rest)) ( (delete-clause $Id1) (set-det) (delete-all $Rest))) +; + (= (delete-all (Cons $Id1 $Rest)) ( (delete-example $Id1) (set-det) (delete-all $Rest))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: interpretable_predicate/1 +; ; -; * +; ; -; * syntax: interpretable_predicate(-Term) +; ; -; * +; ; -; * args: Term .. MeTTa term with principal funtor P/N +; ; -; * +; ; -; * description: succeeds if rules or examples for P/N are in the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1357,130 +1369,138 @@ (or (get-clause $_ $A1 $_ $_ $_) (get-example $_ $A1 $_)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: assertallz/1 +; ; -; * +; ; -; * syntax: assertallz(+List) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: asserts all elements of List at the end of the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (assertallz ()) True) +; + (= (assertallz (Cons $X $R)) - ( (add-atom &self $X) (assertallz $R))) + ( (add-symbol &self $X) (assertallz $R))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: rename_clause/3 +; ; -; * +; ; -; * syntax: rename (+ ID_list,+ Old_name,+ New_name ) +; ; -; * +; ; -; * args: Old_name, New_name ... atoms +; ; -; * +; ; -; * description: rename every occurence of predicate 'Old_name' to 'New_name' +; ; -; * in a set of clauses given as +; ; -; * a list of kb-references (Id-list). 'New_name' should be atomic. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (rename Nil $_ $_) (set-det)) +; + (= (rename (Cons $Id1 $Rest) $Old $New) @@ -1490,67 +1510,71 @@ (store-clause $_ $NewClause $Label $Id1) (set-det) (rename $Rest $Old $New))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: rename_clause/4 +; ; -; * +; ; -; * syntax: rename_clause(+CL,-CL1,+Old,+New) +; ; -; * +; ; -; * args: CL,CL1.. clauses in list representation +; ; -; * Old, New atoms +; ; -; * +; ; -; * description: replaces each literal Old(...) within CL with New(...) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (rename-clause Nil Nil $_ $_) (set-det)) +; + (= (rename-clause (Cons @@ -1565,58 +1589,60 @@ (= $NewLit $Lit)) (set-det) (rename-clause $Rest $NewRest $Old $New))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: random_ex/1 +; ; -; * +; ; -; * syntax: random_ex(-ID) +; ; -; * +; ; -; * args: ID exampleID +; ; -; * +; ; -; * description: chooses randomly an example from the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1624,58 +1650,60 @@ (random-ex $ID1) ( (findall $ID (get-example $ID $_ +) $Bag) (random-select $ID1 $Bag $_))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: two_random_ex/2 +; ; -; * +; ; -; * syntax: two_random_ex(-ID1,-ID2) +; ; -; * +; ; -; * args: ID1,ID2 exampleIDs +; ; -; * +; ; -; * description: chooses randomly two examples from the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1689,14 +1717,18 @@ (or (random-select $ID2 $Residue $_) (select $ID2 $Residue $_)))) +; + ; -; sometimes random_select/3 doesn't work properly +; (= (two-random-ex-from-list $List $ID1 $ID2) ( (random-select $ID1 $List $Residue) (random-select $ID2 $Residue $_))) +; + (= @@ -1704,61 +1736,63 @@ ( (findall $ID (, (with_self - (kb) + (kb *) (prooftrees $ID fail $_)) - (get-example $ID $_ +)) $Uncovered) (two-random-ex-from-list $Uncovered $ID1 $ID2))) + (get-example $ID $_ +)) $Uncovered) (two-random-ex-from-list $Uncovered $ID1 $ID2))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: i_random_ex/2 +; ; -; * +; ; -; * syntax: i_random_ex(+I,-ExIDs) +; ; -; * +; ; -; * args: I .. number +; ; -; * +; ; -; * description: selects randomly I examples from the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1772,9 +1806,13 @@ (=< $J $I) (= $Examples $Bag) (i-random-ex $I $Bag $Examples)))) +; + (= (i-random-ex 0 $_ Nil) (set-det)) +; + (= (i-random-ex $N $Bag (Cons $ID $Rest)) @@ -1782,65 +1820,69 @@ (is $M (- $N 1)) (i-random-ex $M $Residue $Rest))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: shortest_clause/1 +; ; -; * +; ; -; * syntax: shortest_clause(-ID:C) +; ; -; * +; ; -; * args: ID .. clauseID, C ... complexity of the corresponding clause +; ; -; * +; ; -; * description: selects the shortest clause from the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (shortest-clause (with_self $ID1 $C1)) (shortest-clause $_ - (with_self $ID1 $C1))) + (with_self $ID1 $C1))) +; + (= (shortest-clause $Label @@ -1850,58 +1892,60 @@ (, (get-clause $ID $_ $_ $Clause $Label) (complexity $Clause $C)) $Bag) (shortest $Bag (with_self $ID1 $C1) $_))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: two_shortest_clauses/2 +; ; -; * +; ; -; * syntax: two_shortest_clauses(-ID1:CL1,-ID2:CL2) +; ; -; * +; ; -; * args: ID1/2 .. clauseIDs, CL1/2 ... complexities of the corresponding clauses +; ; -; * +; ; -; * description: selects two shortest clauses from kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1912,6 +1956,8 @@ (two-shortest-clauses $_ (with_self $ID1 $C1) (with_self $ID2 $C2))) +; + (= (two-shortest-clauses $Label @@ -1922,59 +1968,61 @@ (, (get-clause $ID $_ $_ $Clause $Label) (complexity $Clause $C)) $Bag) (two-shortest $Bag (with_self $ID1 $C1) (with_self $ID2 $C2)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: shortest_ex/1 +; ; -; * +; ; -; * syntax: shortest_ex(-ID:C) +; ; -; * +; ; -; * args: ID .. exID, C .. complexity of the corresponding example +; ; -; * +; ; -; * description: selects the shortest example from kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1985,58 +2033,60 @@ (, (get-example $ID $Ex +) (complexity $Ex $C)) $Bag) (shortest $Bag (with_self $ID1 $C1) $_))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: two_shortest_ex/2 +; ; -; * +; ; -; * syntax: two_shortest_ex(-ID1:C1,-ID2:C2) +; ; -; * +; ; -; * args: ID1/2 .. exIDs, C1/2 .. complexities of the corresponding examples +; ; -; * +; ; -; * description: selects two shortest example from kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2049,58 +2099,60 @@ (, (get-example $ID $Ex +) (complexity $Ex $C)) $Bag) (two-shortest $Bag (with_self $ID1 $C1) (with_self $ID2 $C2)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: shortest_uncovered_ex/1 +; ; -; * +; ; -; * syntax: shortest_uncovered_ex(-ExID) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: selects the shortest example that is not covered by the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2110,119 +2162,123 @@ (with_self $ID $C) (, (with_self - (kb) + (kb *) (prooftrees $ID fail $_)) (get-example $ID $Ex +) (complexity $Ex $C)) $Uncovered) (shortest $Uncovered (with_self $ID1 $_) $Residue))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: shortest_uncovered_ex/2 +; ; -; * +; ; -; * syntax: shortest_uncovered_ex(+ExIds,-ExId) +; ; -; * +; ; -; * args: ExIds .. list of Ids of uncovered examples +; ; -; * +; ; -; * description: selects the shortest example among ExIds +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (shortest-uncovered-ex $Uncovered $ID1) ( (add-complexities $Uncovered $Bag) (shortest $Bag (with_self $ID1 $_) $Residue))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: two_shortest_uncovered_ex/2 +; ; -; * +; ; -; * syntax: two_shortest_uncovered_ex(-ExID1,-ExID2) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: selects two shortest examples that are not covered by the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2232,120 +2288,124 @@ (with_self $ID $C) (, (with_self - (kb) + (kb *) (prooftrees $ID fail $_)) (get-example $ID $Ex +) (complexity $Ex $C)) $Uncovered) (two-shortest $Uncovered (with_self $ID1 $_) (with_self $ID2 $_)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: all_shortest_ex/1 +; ; -; * +; ; -; * syntax: all_shortest_ex(-ExIds) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: selects all shortest examples from kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (all-shortest-ex $Bag) ( (shortest-ex (with_self $_ $C1)) (findall $ID (, (get-example $ID $Ex +) (complexity $Ex $C1)) $Bag))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: all_shortest_uncovered_ex/1 +; ; -; * +; ; -; * syntax: all_shortest_uncovered_ex(-ExIds) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: selects all shortest uncovered examples from kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2355,7 +2415,7 @@ (with_self $ID $C) (, (with_self - (kb) + (kb *) (prooftrees $ID fail $_)) (get-example $ID $Ex +) (complexity $Ex $C)) $Uncovered) @@ -2364,61 +2424,63 @@ (findall $ID2 (member (with_self $ID2 $C1) $Uncovered) $Bag))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: two_shortest /3 +; ; -; * +; ; -; * syntax: two_shortest(+Bag,-ID1:C1,-ID2:C2) +; ; -; * +; ; -; * args: Bag = [ ID:C, ...] , where ID refers to example with complexity C +; ; -; * ID1/2 ...exampleIDs, C1/2 ... corresponding complexities +; ; -; * +; ; -; * description: +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2431,61 +2493,63 @@ (shortest $Residue (with_self $ID2 $C2) $_) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: shortest/3 +; ; -; * +; ; -; * syntax: shortest(+Bag,-ID:C,-Residue) +; ; -; * +; ; -; * args: Bag, Residue = [ ID:C, ...] , where ID is the complexity of ID +; ; -; * ID ...kbID, C ... corresponding complexity +; ; -; * +; ; -; * description: selects the shortest ID from Bag wrt complexity, Residue is the rest +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2493,6 +2557,8 @@ (shortest ( (: $ID $C)) (: $ID $C) ()) True) +; + (= (shortest (Cons @@ -2515,66 +2581,70 @@ (Cons (with_self $ID1 $C1) $Residue2))))) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate:add_complexities/2 +; ; -; * +; ; -; * syntax: add_complexities(+L,-Pairs) +; ; -; * +; ; -; * args: L = [ID:kb_entry_for_ID,...], +; ; -; * Pairs = [ID:complexity_of_kb_entry_for_ID,...] +; ; -; * +; ; -; * description: +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (add_complexities () ()) True) +; + (= (add-complexities @@ -2583,134 +2653,144 @@ (Cons (with_self $ID $C) $MorePairs)) ( (complexity $Ex $C) (add-complexities $More $MorePairs))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: no_rules/0, no_pos_examples/0, +; ; -; * no_neg_examples/0, no_examples/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: tests kb on the different properties +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (no-rules) (not (get-clause $_ $_ $_ $_ $_))) +; + (= (no-pos-examples) (not (get-example $_ $_ +))) +; + (= (no-neg-examples) (not (get-example $_ $_ -))) +; + (= (no-examples) (not (get-example $_ $_ $_))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: delete_covered_examples/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: deletes examples explained by the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2723,417 +2803,392 @@ (member (with_self $ID $_) $CoveredEx) (delete-example $ID)) $_) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: flatten_rules/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: flattens all clauses in the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; +; (error +; (syntax_error operator_clash) +; (file miles/kb.pl 1086 19 32347)) - (= - (flatten-rules) - ( (findall - (with_self $ID - (with_self $C $Label)) - (, - (get-clause $ID $_ $_ $C $Label) - (delete-clause $ID)) $Bag1) - (store-flat-clauses $Bag1) - (set-det))) ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: flatten_kb/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: flattens all clauses and examples in the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; +; (error +; (syntax_error operator_clash) +; (file miles/kb.pl 1108 19 32926)) - (= - (flatten-kb) - ( (findall - (with_self $ID - (with_self $C $Label)) - (, - (get-clause $ID $_ $_ $C $Label) - (delete-clause $ID)) $Bag1) - (store-flat-clauses $Bag1) - (findall - (with_self $ID - (with_self - (:: (with_self $C (p))) - (ex))) - (get-example $ID $C +) $Bag2) - (store-flat-clauses $Bag2) - (set-det))) ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: unflatten_kb/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: unflattens a flat kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; +; (error +; (syntax_error operator_clash) +; (file miles/kb.pl 1133 19 33588)) - (= - (unflatten-kb) - ( (findall - (with_self $ID - (with_self $C $Label)) - (, - (get-clause $ID $_ $_ $C $Label) - (delete-clause $ID)) $Bag) (store-unflat-clauses $Bag))) ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: store_flat_clauses/1 +; ; -; * +; ; -; * syntax: store_flat_clauses(+CL) +; ; -; * +; ; -; * args: CL = [ID:C:Label,...] where ID is clause- or exampleID, C is the corresponding +; ; -; * clause in list notation and Label is the clause label or "ex" if examples are +; ; -; * flattened +; ; -; * +; ; -; * description: store flat clauses preferably with their old Id. +; ; -; * After flattening, examples become clauses; they get a new Id +; ; -; * while their unflat form remains in the kb. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (store_flat_clauses ()) True) - (= - (store-flat-clauses (Cons (with_self $ID (with_self $C $Label)) $More)) - ( (flatten-clause $C $CFlat) - (or - (store-clause $_ $CFlat $Label $ID) - (store-clause $_ $CFlat $Label $_)) - (store-flat-clauses $More))) +; + +; (error +; (syntax_error operator_clash) +; (file miles/kb.pl 1159 23 34514)) + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: store_unflat_clauses/1 +; ; -; * +; ; -; * syntax: store_unflat_clauses(+CL) +; ; -; * +; ; -; * args: CL = [ID:C:Label,...] where ID is a clause- or exampleID, C is the corresponding +; ; -; * clause in list notation and Label is the clause label or "ex" +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: if Label \= ex, C is unflattened and replaced in the kb by +; ; -; * the unflat version +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (store_unflat_clauses ()) True) - (= - (store-unflat-clauses (Cons (with_self $ID (with_self $C (ex))) $More)) - ( (set-det) (store-unflat-clauses $More))) - (= - (store-unflat-clauses (Cons (with_self $ID (with_self $C $Label)) $More)) - ( (\== $Label ex) - (set-det) - (unflatten-clause $C $CUnFlat) - (store-clause $_ $CUnFlat $Label $ID) - (store-unflat-clauses $More))) +; + +; (error +; (syntax_error operator_clash) +; (file miles/kb.pl 1188 27 35402)) + +; (error +; (syntax_error operator_clash) +; (file miles/kb.pl 1191 25 35490)) + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: get_predlist/1 +; ; -; * +; ; -; * syntax: get_predlist(-Predlist) +; ; -; * +; ; -; * args: Predlist = [P:PVars|_] +; ; -; * +; ; -; * description: selects all predicates with a type restriction from kb +; ; -; * & adapts type restrictions by transfomation in a list [X:Tx,...] +; ; -; * of variables X and types Tx +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -3150,15 +3205,14 @@ (get-clause $I $H $B $CL $L) (\== $L type) (functor $H $P $N))))))) $Plist) (get-pred $Plist $Predlist))) -; ; mysetof(P:PVars, -; ; Vars^( type_restriction(P,Vars), -; ; adapt_v(Vars,PVars)), Predlist). - +; (= (get_pred () ()) True) +; + (= (get-pred (Cons @@ -3174,78 +3228,86 @@ (=.. $P (Cons $_ $Vars)) (adapt-v1 $Vars $PVars))))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: adapt_v/2 +; ; -; * +; ; -; * syntax: adapt_v(+TR,-Vars) +; ; -; * +; ; -; * args: TR: [Tx(X),...] type restrictions for variables X of a predicate +; ; -; * Vars: [X:Tx,...] +; ; -; * +; ; -; * description: transforms a set of type restrictions Tx(X) into +; ; -; * a set X:Tx of variables X and types Tx +; ; -; * +; ; -; * example: adapt_v([list(A),atom(B)],[A:list,B:atom] +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (adapt_v () ()) True) +; + (= (adapt-v (Cons $T $R) (Cons (with_self $X $Tx) $R1)) ( (adapt-v $R $R1) (=.. $T (:: $Tx $X)))) +; + (= (adapt_v1 () ()) True) +; + (= (adapt-v1 (Cons $X $R) @@ -3253,5 +3315,7 @@ (with_self $X (all)) $R1)) (adapt-v1 $R $R1)) +; + diff --git a/miles/lgg.metta b/miles/lgg.metta index 32239c2..163f45a 100644 --- a/miles/lgg.metta +++ b/miles/lgg.metta @@ -1,5 +1,5 @@ ; -; MODULE lgg EXPORTS +; !(module lgg @@ -36,18 +36,11 @@ (/ lgti 3) (/ lgti 5) (/ lgti 6))) -; ; Buntine's most specific generalization - -; ; " with given bound for saturation - -; ; rllg - -; ; rllg with given head literal of preference - +; ; -; IMPORTS +; !(use-module (home kb) @@ -56,6 +49,8 @@ (/ delete-clause 1) (/ store-clause 4) (/ get-example 3))) +; + !(use-module (home bu-basics) (:: @@ -72,6 +67,8 @@ (/ msg-build-long-clause 1) (/ msg-build-heads 1) (/ msg-build-body 1))) +; + !(use-module (home var-utils) (:: @@ -79,6 +76,8 @@ (/ skolemize 4) (/ deskolemize 3) (/ clean-subst 3))) +; + !(use-module (home div-utils) (:: @@ -89,207 +88,233 @@ (/ maximum 2) (/ identical-member 2) (/ identical-make-unique 2))) +; + !(use-module (home interpreter) (:: (/ prove1 2) (/ prove5 2))) +; + !(use-module (home g1-ops) (:: (/ saturate 2) (/ saturate 3) (/ inv-derivate1 2))) +; + !(use-module (home filter) (:: (/ truncate-unconnected 2))) +; + !(use-module (home evaluation) (:: (/ complexity 2))) +; + !(use-module-if-exists (library sets) (:: (/ list-to-set 2) (/ subtract 3))) +; + !(use-module-if-exists (library lists) (:: (/ is-list 1) (/ subseq0 2) (/ nth1 4))) +; + !(use-module-if-exists (library basics) (:: (/ member 2))) +; + !(use-module-if-exists (library random) (:: (/ maybe 0))) +; + !(use-module-if-exists (library not) (:: (/ once 1))) +; + !(use-module-if-exists (library occurs) (:: (/ contains-var 2) (/ free-of-var 2))) +; + !(use-module-if-exists (library subsumes) (:: (/ subsumes-chk 2) (/ variant 2))) +; + ; -; METAPREDICATES +; ; -; none +; !(dynamic (, (/ counter 1) (/ shortsubst 2) (/ iterate 1))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * module: lgg.pl +; ; -; * +; ; -; * author: B.Jung, M.Mueller, I.Stahl, B.Tausend date:12/92 +; ; -; * +; ; -; * changed: +; ; -; * +; ; -; * description: - clause reduction +; ; -; * reduce clause with no repect to background +; ; -; * knowledge (Plotkin,1970) +; ; -; * reduce w.r.t. background knowledge (Buntine,1988) +; ; -; * Since reduction is in both cases NP-complete, +; ; -; * we provide 2 versions for each case: +; ; -; * a correct, but higly inefficient solution +; ; -; * & an approximation. +; ; -; * - clause_subsumption +; ; -; * - Buntine's most specific generalization under +; ; -; * generalized subsumption +; ; -; * - Plotkin's RLGG, with Muggleton's algorithm +; ; -; * - Plotkins least general generalisation (lgg) +; ; -; * under theta subsumption +; ; -; * - least general intersection lgti +; ; -; * +; ; -; * see also: Buntine,88; Muggleton,90; Plotkin, 70; +; ; -; * module lgg.pl for msg +; ; -; * +; ; -; *********************************************************************** +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicates: reduce_complete/2 +; ; -; * +; ; -; * syntax: reduce_complete(+Clause,-ReducedClause) +; ; -; * +; ; -; * args: Clause: input clause in list form +; ; -; * ReducedClause: reduced, minimal clause equivalent to Clause +; ; -; * +; ; -; * description: do not consider bg, i.e. reduction wrt theta subsumption +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -301,6 +326,8 @@ (delete-clause $ID) (store-clause $_ $D reduce $ID) (set-det))) +; + (= @@ -311,67 +338,69 @@ (reduce-complete1 $Clause $S $SReduced0) (list-to-set $SReduced0 $SReduced) (deskolemize $SReduced $S $Reduced) - (set-det))) ; -; No backtracking allowed (solution is unique) + (set-det))) +; + ; +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: reduce_complete1/3 +; ; -; * +; ; -; * syntax: reduce_complete1(+CL,+Subst,-ReducedCL) +; ; -; * +; ; -; * args: CL,ReducedCL: clauses in list notation +; ; -; * Subst: skolem substitution +; ; -; * +; ; -; * description: reduces CL by matching it on the skolemized head and +; ; -; * body literals of the reduced clause in the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -391,14 +420,12 @@ (, (reset-counts) (fail))))) -; ; backtrack, find another proof - +; (= (reduce-complete1 $_ $S $RC) ( (set-det) (subs-build-clause $RC))) -; ; there is no shorter proof, the minimal clause is found. - +; @@ -418,65 +445,67 @@ (subtract $L0 $P0 $D) (set-det) (\== $D Nil))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: reduce_approx/2 +; ; -; * +; ; -; * syntax: reduce_approx(+Clause,-ReducedClause) +; ; -; * +; ; -; * args: Clause: input clause in list form +; ; -; * ReducedClause: reduced, minimal clause equivalent to Clause +; ; -; * +; ; -; * description: as reduce_complete except that the number of single +; ; -; * reduction steps is bound +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -490,6 +519,8 @@ (reduce-get-current-clause $SReduced0) (list-to-set $SReduced0 $SReduced) (deskolemize $SReduced $S $Reduced))) +; + (= @@ -504,67 +535,71 @@ (is $J (+ $Counter 1)) (reduce-approx1 $S $J $Bound))) +; + (= (reduce_approx1 $_ $_ $_) True) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: reduce_get_current_clause/1 +; ; -; * +; ; -; * syntax: reduce_get_current_clause(-CL) +; ; -; * +; ; -; * args: CL: clause in list notation +; ; -; * +; ; -; * description: returns current skolemized clause that is stored via +; ; -; * head/3 and body/3 in the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -579,82 +614,86 @@ (n)) (body $L $_ $_) $Body) (append $Heads $Body $CL))) +; + ; -; ********************************************************************* +; ; -; * +; ; -; * predicate: covered_clause/2 +; ; -; * +; ; -; * syntax: covered_clause(+RULES, +ID) +; ; -; * +; ; -; * args: RULES: list of kb references (integers) +; ; -; * ID: id of clause to be tested +; ; -; * +; ; -; * description: Test, if a clause is a specialization of RULES. +; ; -; * +; ; -; * example: let RULES refer to clauses +; ; -; * member(A,[A|B]). +; ; -; * member(A,[B|C]):- member(A,C). +; ; -; * then +; ; -; * member(3,[1,2,3]):- member(3,[2,3]) +; ; -; * is covered by RULES +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ******************************************************************** +; (= (covered-clause $RULES $ID) ( (nonvar $RULES) (member $ID $RULES))) +; + (= (covered-clause $RULES $ID) ( (nonvar $RULES) - (remove-all-atoms &self + (remove-all-symbols &self (assumption $_ $_ $_)) (get-clause $ID $_ $_ $Clause $_) (skolemize $Clause $_ @@ -664,67 +703,69 @@ (cover-assert-assumptions $Body) (prove5 $H $RULES) (set-det))) +; + ; -; **************************************************************** +; ; -; * +; ; -; * predicate: covered_clauses/4 +; ; -; * +; ; -; * syntax: covered_clauses(+RULES,+ToTest,-Covered,-Uncovered) +; ; -; * +; ; -; * args: RULES: list of kb references (integers) +; ; -; * ToTest: either label of kb entries (lgg, sat, ex ..) +; ; -; * or a list of kb references +; ; -; * description: test if RULES explain all example clauses +; ; -; * denoted by ToTest. +; ; -; * Or: RULES |= clauses(ToTest) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; **************************************************************** +; @@ -735,19 +776,23 @@ (findall $ID (get-clause $ID $_ $_ $_ $LABEL) $ToTest) (covering $RULES $ToTest Nil $Covered Nil $Uncovered))) +; + (= (covered-clauses $RULES $ToTest $Covered $Uncovered) ( (nonvar $RULES) (is-list $ToTest) (covering $RULES $ToTest Nil $Covered Nil $Uncovered))) +; + (= (covering $RULES (Cons $ID $ToTest) $Covered1 $Covered2 $Uncovered1 $Uncovered2) - ( (remove-all-atoms &self + ( (remove-all-symbols &self (assumption $_ $_ $_)) (get-clause $ID $_ $_ $Clause $_) (not (or (member $ID $Covered1) (member $ID $Uncovered1))) @@ -776,95 +821,99 @@ (= $Uncovered3 (Cons $ID $Uncovered1))))) (covering $RULES $ToTest $Covered3 $Covered2 $Uncovered3 $Uncovered2))) +; + (= (covering $_ Nil $Covered $Covered $Uncovered $Uncovered) (set-det)) +; + ; -; *************************************************************** +; ; -; * +; ; -; * predicates: gen_msg/3/4 +; ; -; * +; ; -; * syntax: gen_msg(+ID1,+ID2,-ID) +; ; -; * gen_msg(+ID1,+ID2,-ID,+Bound) +; ; -; * +; ; -; * args: ID1,ID2,ID:integers, references to clauses in kb +; ; -; * Bound :integer, depth bound for saturation +; ; -; * +; ; -; * description: Approximation of Buntine's most specific +; ; -; * generalization. We saturate the 2 input clauses +; ; -; * & build the lgg over them. +; ; -; * Our procedure differs from Buntine's in that +; ; -; * saturation does not construct all generalizing +; ; -; * clauses under generalized subsumption: if some +; ; -; * head literal entailed by the body contains +; ; -; * unbound variables, saturation adds it to the +; ; -; * body as it is, whereas Buntine instead adds all +; ; -; * of its ground instances. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: the resulting clause is not yet reduced +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *************************************************************** +; @@ -879,10 +928,7 @@ (lgti $A $B $ID) (delete-clause $A) (delete-clause $B))) -; ; lgg(A,B,ID), - -; ; changed ! - +; (= @@ -903,94 +949,95 @@ (nr-lgg $A $B $ID) (delete-clause $A) (delete-clause $B))) -; ; lgti(A,B,ID). ; changed ! - +; ; -; *************************************************************** +; ; -; * +; ; -; * predicate: rllg/3/4 +; ; -; * +; ; -; * syntax: rllg(+ID1,+ID2,-ID) +; ; -; * rllg(+ID1,+ID2,+PrefHead,-ID) +; ; -; * +; ; -; * args: ID1,ID2,ID: integers, references to clauses in kb +; ; -; * PrefHead: MeTTa literal +; ; -; * +; ; -; * description: Plotkin's relative leat general generalization. +; ; -; * Implementation thru Muggleton's alg. : +; ; -; * Construct 2 inverse linear derivations, +; ; -; * then build lgg over them. +; ; -; * +; ; -; * If PrefHead is given & it is possible to find +; ; -; * a rllg who's head matches PrefHead, rllg will +; ; -; * construct this clause. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: no reduction yet +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *************************************************************** +; (= (rlgg $ID1 $ID2 $ID) (rlgg $ID1 $ID2 $_ $ID)) +; + (= (rlgg $ID1 $ID2 $PrefHead $ID) @@ -1023,69 +1070,66 @@ (convert-to-horn-clause $PrefHead $D $E) (truncate-unconnected $E $F) (store-clause $_ $F rlgg $ID))) -; ; thru backtracking different - -; ; heads may be obtained - +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: subsumes_list/2 +; ; -; * +; ; -; * syntax: subsumes_list(+General,+Specific) +; ; -; * +; ; -; * args: clauses in list notation +; ; -; * +; ; -; * description: checks for theta subsumption by list matching. +; ; -; * No proofs, no substitutions are returned. +; ; -; * General will not be instantiated. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1095,91 +1139,101 @@ (copy-term $Spec $Spec1) (numbervars $Spec1 1 $_) (subsumes-list1 $Gen1 $Spec1))) +; + (= (subsumes_list1 () $_) True) +; + (= (subsumes-list1 (Cons $L $Rest) $Spec) ( (member $L $Spec) (subsumes-list1 $Rest $Spec))) +; + ; -; ******************************************************************************** +; ; -; * +; ; -; * predicates: lgg_terms/3, lgg_terms/5, lgg_terms/7 +; ; -; * +; ; -; * syntax: lgg_terms( + Term1, + Term2, - GenTerm ) +; ; -; * lgg_terms( + Term1, + Term2, - GenTerm, +; ; -; * - Subst_Term1, - Subst_Term2 ) +; ; -; * lgg_terms( + Term1, + Term2, - GenTerm, +; ; -; * - Subst1, - Subst2, +; ; -; * + Init_Subst1, + Init_Subst2 ) +; ; -; * +; ; -; * args: Term1,Term2,GenTerm: MeTTa terms +; ; -; * Subst_termi: [Var/Fi,..] substitution such that Termi = GenTerm Subst_termi +; ; -; * +; ; -; * description: Plotkins least general generalisation wrt theta-subsumption +; ; -; * on terms +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; ************************************************************************ +; (= (lgg-terms $Term1 $Term2 $GTerm) (lgg-terms $Term1 $Term2 $GTerm $_ $_ Nil Nil)) +; + (= (lgg-terms $Term1 $Term2 $GTerm $Subst1 $Subst2) (lgg-terms $Term1 $Term2 $GTerm $Subst1 $Subst2 Nil Nil)) +; + (= (lgg-terms $Term1 $Term2 $GTerm $S1 $S2 $Accu1 $Accu2) @@ -1212,31 +1266,18 @@ (Cons (/ $NewVar $Term2) $Accu2)) (= $GTerm $NewVar)))))) -; ; if same functor, same arity - -; ; then: build new term by generalizing arguments - -; ; else if same instantiation - -; ; then: no problem - -; ; else if substitution has already been applied - -; ; then: again, no problem - -; ; else if neither is true - -; ; then: substitute with a new variable - +; ; -; generalize argument-terms (loop from position n to position 0) +; (= (generalize-arguments $_ $_ 0 $_ $Ac1 $Ac2 $Ac1 $Ac2) (set-det)) +; + (= (generalize-arguments $Term1 $Term2 $N $GTerm $Ac1 $Ac2 $S1 $S2) ( (arg $N $Term1 $ArgN1) @@ -1246,9 +1287,11 @@ (is $K (- $N 1)) (generalize-arguments $Term1 $Term2 $K $GTerm $Ac1new $Ac2new $S1 $S2))) +; + ; -; test whether two terms at the same position have already a common generalised term +; (= @@ -1260,63 +1303,67 @@ ( (== $T1 $Term1) (== $T2 $Term2) (set-det))) +; + (= (substituted (Cons $_ $Accu1) (Cons $_ $Accu2) $Term1 $Term2 $X) (substituted $Accu1 $Accu2 $Term1 $Term2 $X)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: set_lgg/2 +; ; -; * +; ; -; * syntax: set_lgg(+List_of_Terms,-GenTerm) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: lgg of a list of terms +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; @@ -1324,82 +1371,88 @@ (set-lgg (:: $L) $L) (set-det)) +; + (= (set-lgg (Cons $X (Cons $Y $R)) $Lgg) ( (lgg-terms $X $Y $Lgg0) (set-lgg (Cons $Lgg0 $R) $Lgg))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: headed_lgg/3, headed_lgg/4 +; ; -; * +; ; -; * syntax: headed_lgg(+ID1,+ID2,-IDG) +; ; -; * headed_lgg(+ID1,_ID2,-IDG,?Label) +; ; -; * +; ; -; * args: ID1,ID2,IDG: clauseIDs, Label: atom +; ; -; * +; ; -; * description: returns lgg of clauses ID1 ID2 in IDG, if both clauses +; ; -; * have a compatible head literal (i.e. same pred, same +; ; -; * arity). Fails else. +; ; -; * Default label is hlgg +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; (= (headed-lgg $Id1 $Id2 $IdG) (headed-lgg $Id1 $Id2 $IdG hlgg)) +; + (= (headed-lgg $Id1 $Id2 $IdG $Label) @@ -1418,11 +1471,7 @@ (Cons (with_self $HGr (p)) $BGlistred) $Label $IdG))) -; ; reduce_irene([HG:p|BGlist],[HGr:p|BGlistred]), - -; ; finally reduce lgg-body -; ; reduce_approx([HG:p|BGlist],[HGr:p|BGlistred]),; alternatively (more efficient) - +; @@ -1436,78 +1485,75 @@ (functor $H2 $F $N) (lgg-terms $H1 $H2 $HG $Subst1 $Subst2) (lgg-body $B1list $B2list $BGlist Nil $Subst1 $Subst2 $_ $_))) -; ; if name + arity match for both heads - -; ; generalize heads first, - -; ; then generalize bodies. - +; ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: hnr_lgg/3, hnr_lgg/4 +; ; -; * +; ; -; * syntax: hnr_lgg(+ID1,+ID2,-IDG) +; ; -; * hnr_lgg(+ID1,_ID2,-IDG,?Label) +; ; -; * +; ; -; * args: ID1,ID2,IDG: clauseIDs, Label: atom +; ; -; * +; ; -; * description: same as headed_lgg, except that the resulting generalised +; ; -; * clause is NOT reduced. Default label is hnrlgg +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; (= (hnr-lgg $Id1 $Id2 $IdG) (hnr-lgg $Id1 $Id2 $IdG hnrlgg)) +; + (= (hnr-lgg $Id1 $Id2 $IdG $Label) @@ -1519,76 +1565,80 @@ (Cons (with_self $HG (p)) $BGlist) $Label $IdG))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: lgg/3, lgg/4 +; ; -; * +; ; -; * syntax: lgg(+ID1,+ID2,-IDG) +; ; -; * lgg(+ID1,_ID2,-IDG,?Label) +; ; -; * +; ; -; * args: ID1,ID2,IDG: clauseIDs, Label: atom +; ; -; * +; ; -; * description: returns lgg of clauses ID1 ID2 in IDG. If both clauses +; ; -; * have no compatible head literal, the head literal of IDG +; ; -; * is set to 'true'. +; ; -; * Default label is lgg +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; (= (lgg $Id1 $Id2 $IdG) (lgg $Id1 $Id2 $IdG lgg)) +; + (= (lgg $Id1 $Id2 $IdG $Label) @@ -1607,11 +1657,7 @@ (Cons (with_self $HGr (p)) $BGlistred) $Label $IdG))) -; ; reduce_irene([HG:p|BGlist],[HGr:p|BGlistred]), - -; ; finally reduce lgg-body -; ; reduce_approx([HG:p|BGlist],[HGr:p|BGlistred]), ; alternatively (more efficient) - +; @@ -1632,80 +1678,75 @@ (= $Subst1 Nil) (= $Subst2 Nil))) (lgg-body $B1list $B2list $BGlist Nil $Subst1 $Subst2 $_ $_))) -; ; if name + arity match for both heads - -; ; then generalize heads, - -; ; else use 'true' as head; - -; ; then generalize bodies. - +; ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: nr_lgg/3, nr_lgg/4 +; ; -; * +; ; -; * syntax: nr_lgg(+ID1,+ID2,-IDG) +; ; -; * nr_lgg(+ID1,_ID2,-IDG,?Label) +; ; -; * +; ; -; * args: ID1,ID2,IDG: clauseIDs, Label: atom +; ; -; * +; ; -; * description: same as lgg, except that the resulting generalised +; ; -; * clause is NOT reduced. Default label is nrlgg +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; (= (nr-lgg $Id1 $Id2 $IdG) (nr-lgg $Id1 $Id2 $IdG nrlgg)) +; + (= (nr-lgg $Id1 $Id2 $IdG $Label) @@ -1717,67 +1758,69 @@ (Cons (with_self $HG (p)) $BGlist) $Label $IdG))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: buildlgg/4 +; ; -; * +; ; -; * syntax: build_lgg(+IDs,+IID,-GID,+Label) +; ; -; * +; ; -; * args: IDs: list of clauseIDs, +; ; -; * IID,GID: clauseIDs +; ; -; * Label: atom +; ; -; * +; ; -; * description: returns in GID the ID of the lgg of all clauses in IDs. IID is +; ; -; * the ID of the intermediate result +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1785,6 +1828,8 @@ (buildlgg (:: $C1) $C2 $Clgg $L) ( (lgg $C1 $C2 $Clgg $L) (set-det))) +; + (= (buildlgg @@ -1797,67 +1842,71 @@ (, (delete-clause $Clgg_new1) (fail))))) +; + (= (buildlgg Nil $O $N $L) ( (get-clause $O $_ $_ $Cl $_) (store-clause $_ $Cl $L $N) (set-det))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: lgg/5, nr_lgg/5 +; ; -; * +; ; -; * syntax: (nr_)lgg(+CL1,+CL2,-CLG,-Subst1,-Subst2) +; ; -; * +; ; -; * args: CL1,CL2,CLG: clauses in list notation +; ; -; * Substi: Substitutions such that CLG Substi \subseteq CLi +; ; -; * +; ; -; * description: CLG is (non-reduced) lgg of clauses CL1 and CL2 +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; @@ -1873,13 +1922,10 @@ (Cons $HGr $BGlistred) $SS1 $S1) (clean-subst (Cons $HGr $BGlistred) $SS2 $S2))) -; ;Theta1, Theta2) :- - -; ; reduce_irene([HG|BGlist],[HGr|BGlistred]). - +; ; -; reduce_approx([HG|BGlist],[HGr|BGlistred]), ;;alternatively (more efficient) +; @@ -1905,64 +1951,66 @@ (= $HG True) (= $Subst1 Nil) (= $Subst2 Nil))) (lgg-body $B1list $B2list $BGlist Nil $Subst1 $Subst2 $Theta1 $Theta2))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: headed_lgg/5, hnr_lgg/5 +; ; -; * +; ; -; * syntax: headed_lgg(+CL1,+CL2,-CLG,-Subst1,-Subst2) +; ; -; * hnr_lgg(+CL1,+CL2,-CLG,-Subst1,-Subst2) +; ; -; * +; ; -; * args: CL1,CL2,CLG: clauses in list notation +; ; -; * Substi: Substitutions such that CLG Substi \subseteq CLi +; ; -; * +; ; -; * description: CLG is (non-reduced) headed lgg of clauses CL1 and CL2 +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; @@ -1978,13 +2026,10 @@ (Cons $HGr $BGlistred) $SS1 $S1) (clean-subst (Cons $HGr $BGlistred) $SS2 $S2))) -; ;;;Theta1, Theta2) :- - -; ; reduce_irene([HG|BGlist],[HGr|BGlistred]). - +; ; -; reduce_approx([HG|BGlist],[HGr|BGlistred]), ;;alternatively (more efficient) +; @@ -2003,76 +2048,82 @@ (functor $H2 $F $N) (lgg-terms $H1 $H2 $HG $Subst1 $Subst2) (lgg-body $B1list $B2list $BGlist Nil $Subst1 $Subst2 $Theta1 $Theta2))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: lgg_body/8 +; ; -; * +; ; -; * syntax: lgg_body(+CL1,+CL2,+CLAccu,-CLAccu,+Subst1,+Subst2,-Subst1,-Subst2) +; ; -; * +; ; -; * args: CL1,CL2,CLAccu: clauses bodiesin list representation +; ; -; * Subst..:Substitutions for the variables in CLAccu +; ; -; * +; ; -; * description: CLAccu is the non-reduced lgg of the clause bodies CL1 and +; ; -; * CL2. The generalisation of two redundant literals L1:r, L2:r is +; ; -; * marked as redundant LG:r. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; (= (lgg-body Nil $_ $Accu $Accu $S1 $S2 $S1 $S2) (set-det)) +; + (= (lgg-body $_ Nil $Accu $Accu $S1 $S2 $S1 $S2) (set-det)) +; + (= (lgg-body @@ -2080,76 +2131,82 @@ ( (generalize-elem $List2 $Elem1 $GLelem1 $S1old $S2old $S1new $S2new) (append $AcGL $GLelem1 $AcGLnew) (lgg-body $R1 $List2 $Glist $AcGLnew $S1new $S2new $Theta1 $Theta2))) +; + ; -; *************************************************************** +; ; -; * +; ; -; * predicate: lgg_gen_clause/8 +; ; -; * +; ; -; * syntax: lgg_gen_clause(+CL1,+CL2,+CLAccu,-CLAccu,+Subst1, +; ; -; * +Subst2,-Subst1,-Subst2) +; ; -; * +; ; -; * args: CL1,CL2,CLAccu: general clauses in list representation +; ; -; * Subst..:Substitutions for the variables in CLAccu +; ; -; * +; ; -; * description: CLAccu is the lgg of CL1 and CL2 (non-reduced) +; ; -; * CL1, CL2 might be non Horn +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *************************************************************** +; (= (lgg-gen-clause Nil $_ $Accu $Accu $S1 $S2 $S1 $S2) (set-det)) +; + (= (lgg-gen-clause $_ Nil $Accu $Accu $S1 $S2 $S1 $S2) (set-det)) +; + (= (lgg-gen-clause @@ -2159,79 +2216,83 @@ (with_self $Elem1 $Sign1) $GLelem1 $S1old $S2old $S1new $S2new) (append $AcGL $GLelem1 $AcGLnew) (lgg-gen-clause $R1 $List2 $Glist $AcGLnew $S1new $S2new $Theta1 $Theta2))) +; + ; -; *************************************************************** +; ; -; * +; ; -; * predicate: generalize_elem/7 +; ; -; * +; ; -; * syntax: generalize_elem(+CL,+Lit:Sign,-GCL,+Subst1,+Subst2,-Subst1,-Subst2) +; ; -; * +; ; -; * args: CL,GCL: clauses in list notation +; ; -; * GCL: clause in list notation +; ; -; * Lit:Sign: literal and sign (in {p,n,r}) +; ; -; * Subst..: Sustitutions for the variables in GCL +; ; -; * +; ; -; * description: for each literal L in CL matching Lit:Sign (i.e. same functor, arity +; ; -; * and compatible sign), the lgg of L and Lit is added to GCL, and the +; ; -; * subtitutions are extended accordingly +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *************************************************************** +; (= (generalize-elem Nil $_ Nil $S1 $S2 $S1 $S2) (set-det)) +; + (= (generalize-elem @@ -2267,72 +2328,76 @@ (generalize-elem $R1 (with_self $Literal $Sign2) $RestGL $S11 $S21 $S12 $S22) (set-det))) +; + (= (generalize-elem (Cons $_ $R1) $Literal $RestGL $S1old $S2old $S1new $S2new) (generalize-elem $R1 $Literal $RestGL $S1old $S2old $S1new $S2new)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: gti/3, gti/5 +; ; -; * +; ; -; * syntax: gti(+C1,+C2,-C), gti(+C1,+C2,-C,-S1,-S2) +; ; -; * +; ; -; * args: C1,C2,C: clauses in list notation +; ; -; * S1,S2: substitutions [ V1/Term1 , .... ] +; ; -; * +; ; -; * description: generalization thru intersection +; ; -; * least general intersection +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: the resulting clause might be unconnected +; ; -; * ( see connectedness.pl ) +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; @@ -2340,6 +2405,8 @@ (= (gti $C1 $C2 $C) (gti $C1 $C2 $C $S1 $S2)) +; + (= @@ -2351,6 +2418,8 @@ (get-clause $Id2 $_ $_ $C2 $_) (gti $C1 $C2 $C $S1 $S2) (store-clause $_ $C gti $ID))) +; + (= @@ -2365,12 +2434,16 @@ (with_self $H (p)) $C) $S1 $S2) ( (lgg-terms $H1 $H2 $H $Phi1 $Phi2) (gti $C1 $C2 $C $Phi1 $Phi2 $S1 $S2))) +; + (= (gti () $_ () $S1 $S2 $S1 $S2) True) +; + (= (gti @@ -2391,74 +2464,75 @@ (det-if-then otherwise (= $Sign n))) (gti $Rest1 $Rest2 $Rest $Theta1 $Theta2 $S1 $S2))) -; ; subtract L2 from C2 - +; (= (gti (Cons $_ $Rest1) $C2 $Rest $Phi1 $Phi2 $S1 $S2) - (gti $Rest1 $C2 $Rest $Phi1 $Phi2 $S1 $S2)) + (gti $Rest1 $C2 $Rest $Phi1 $Phi2 $S1 $S2)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: lgti/3, lgti/5, lgti/6 +; ; -; * +; ; -; * syntax: lgti(+C1,+C2,-C,-S1,-S2),lgti(+C1,+C2,-C,-S1,-S2,+Bound) +; ; -; * +; ; -; * args: C1,C2,C,S1,S2: see gti above +; ; -; * Bound : pos. integer +; ; -; * +; ; -; * description: apply gti-operator Bound times ( default: Bound = 10 ). +; ; -; * Return the longest resulting clause & substitutions. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -2473,10 +2547,14 @@ (, (delete-clause $ID) (fail))))) +; + (= (lgti $C1 $C2 $C $S1 $S2) (lgti $C1 $C2 $C $S1 $S2 10)) +; + @@ -2488,6 +2566,8 @@ (get-clause $Id1 $_ $_ $C1 $_) (get-clause $Id2 $_ $_ $C2 $_) (lgti $C1 $C2 $C $S1 $S2 $Bound))) +; + (= @@ -2500,39 +2580,46 @@ (findall $Comp (chart $Comp $_ $_ $_ $_ $_) $Bag) (once (maximum $Bag $MaxComp)) - (once (remove-atom &self (chart $MaxComp $C $C1 $C2 $S1 $S2))))) + (once (remove-symbol &self (chart $MaxComp $C $C1 $C2 $S1 $S2))))) +; + !(dynamic (/ chart 6)) +; + (= (init-chart $C1 $C2 $Bound) - ( (remove-all-atoms &self + ( (remove-all-symbols &self (chart_count $_)) - (add-atom &self + (add-symbol &self (chart_count 1)) - (remove-all-atoms &self + (remove-all-symbols &self (chart $_ $_ $_ $_ $_ $_)) (set-det) (init-chart1 $C1 $C2 $Bound))) +; + (= (init-chart1 $C1 $C2 $Bound) ( (gti $C1 $C2 $C $S1 $S2) - (once (, (complexity $C $Comp) (add-atom &self (chart $Comp $C $C1 $C2 $S1 $S2)) (remove-atom &self (chart_count $I)) (is $J (+ $I 1)) (add-atom &self (chart_count $J)))) + (once (, (complexity $C $Comp) (add-symbol &self (chart $Comp $C $C1 $C2 $S1 $S2)) (remove-symbol &self (chart_count $I)) (is $J (+ $I 1)) (add-symbol &self (chart_count $J)))) (> $J $Bound))) -; ; no backtracking thru this - +; (= (init-chart1 $_ $_ $_) - (set-det)) ; -; if there are less than Bound solutions. + (set-det)) +; + ; +; diff --git a/miles/miles.metta b/miles/miles.metta index f5dd87d..3bd2f50 100644 --- a/miles/miles.metta +++ b/miles/miles.metta @@ -1,36 +1,90 @@ !(ensure-loaded dmiles) +; + !(multifile (/ file-search-path 2)) +; + !(dynamic (/ file-search-path 2)) +; + !(ensure-loaded-if-exists (library prompt)) +; + !(ensure-loaded (home argument-types)) +; + !(ensure-loaded (home bu-basics)) +; + !(ensure-loaded (home clause-heads)) +; + !(ensure-loaded (home div-utils)) +; + !(ensure-loaded (home environment)) +; + !(ensure-loaded (home evaluation)) +; + !(ensure-loaded (home filter)) +; + !(ensure-loaded (home flatten)) +; + !(ensure-loaded (home g1-ops)) +; + !(ensure-loaded (home g2-ops)) +; + !(ensure-loaded (home interpreter)) +; + !(ensure-loaded (home kb)) +; + !(ensure-loaded (home lgg)) +; + !(ensure-loaded (home show-utils)) +; + !(ensure-loaded (home td-basic)) +; + !(ensure-loaded (home tdref-it)) +; + !(ensure-loaded (home var-utils)) +; + !(ensure-loaded (home newpred)) +; + !(ensure-loaded (home gencon)) +; + !(ensure-loaded (home gencon-instances/rul.pl)) +; + !(ensure-loaded (home gencon-instances/constrained-clauses.pl)) +; + !(ensure-loaded (home gencon-instances/foil.pl)) +; + - !((remove-all-atoms &self + !((remove-all-symbols &self (: interpreter - (depth_bound $_))) (add-atom &self (: interpreter (depth_bound 10)))) + (depth_bound $_))) (add-symbol &self (: interpreter (depth_bound 10)))) +; + diff --git a/miles/newpred.metta b/miles/newpred.metta index 7e0ba61..393cdcf 100644 --- a/miles/newpred.metta +++ b/miles/newpred.metta @@ -1,5 +1,5 @@ ; -; MODULE newpred EXPORTS +; !(module newpred (:: @@ -7,10 +7,12 @@ (/ specialize-with-newpred 7) (/ specialize-with-newpred 2) (/ is-newpred 1))) +; + ; -; IMPORTS +; !(use-module (home kb) @@ -20,127 +22,147 @@ (/ delete-clause 1) (/ store-clause 4) (/ store-ex 3))) +; + !(use-module (home var-utils) (:: (/ only-vars 2))) +; + !(use-module (home div-utils) (:: (/ mysetof 3))) +; + !(use-module (home td-basic) (:: (/ append-body 3))) +; + !(use-module (home interpreter) (:: (/ prooftrees 3))) +; + !(use-module (home environment) (:: (/ ask-for-ex 1))) +; + !(use-module (home argument-types) (:: (/ types-of 3) (/ type-restriction 2))) +; + !(use-module-if-exists (library basics) (:: (/ member 2))) +; + !(use-module-if-exists (library sets) (:: (/ intersection 3))) +; + !(use-module-if-exists (library strings) (:: (/ gensym 2))) +; + ; -; METAPREDICATES +; ; -; none +; ; -; *********************************************************************** +; ; -; * +; ; -; * module: newpred.pl +; ; -; * +; ; -; * author: I.Stahl +; ; -; * +; ; -; * changed: +; ; -; * +; ; -; * +; ; -; * description: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: specialize_with_newpred/1 +; ; -; * +; ; -; * syntax: specialize_with_newpred(+ID) +; ; -; * +; ; -; * args: ID .. Clause ID +; ; -; * +; ; -; * description: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -150,55 +172,57 @@ (mysetof (, $NC $Pos $Neg $TR) (specialize-with-newpred $ID $NC $Pos $Neg $TR) $L)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: specialize_with_newpred/5 +; ; -; * +; ; -; * syntax: specialize_with_newpred(+ID,-Newclause,-Pos,-Neg,-Typerestriction) +; ; -; * +; ; -; * args: ID .. Clause ID, Newclause.. specialized clause +; ; -; * Pos.. positive examples for the new predicate +; ; -; * Neg.. negative examples for the new predicate +; ; -; * Typerestriction.. type restriction for the new predicate +; ; -; * +; ; -; * description: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= @@ -230,65 +254,67 @@ (, $Vars1 $TVars $Newp) (, $Vars2 $TVars2 $Newp2)) (make-type-restriction $Vars2 $TVars2 $TR))))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: specialize_with_newpred/7 +; ; -; * +; ; -; * syntax: specialize_with_newpred(+Clause,+CPos,+CNeg,-Newclause, +; ; -; * -Pos,-Neg,-Typerestriction) +; ; -; * +; ; -; * args: Clause.. clause to be specialised with new predicate +; ; -; * CPos,CNeg.. pos./neg. examples covered by the clause +; ; -; * Newclause.. specialized clause +; ; -; * Pos.. positive examples for the new predicate +; ; -; * Neg.. negative examples for the new predicate +; ; -; * Typerestriction.. type restriction for the new predicate +; ; -; * +; ; -; * description: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= @@ -313,67 +339,71 @@ (, $Vars1 $TVars $Newp) (, $Vars2 $TVars2 $Newp2)) (make-type-restriction $Vars2 $TVars2 $TR))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: clause_instances/5 +; ; -; * +; ; -; * syntax: clause_instances(+Covered,+ID,+Head,+Body,+Vars,-Varinstances) +; ; -; * +; ; -; * args: Covered.. examples covered by clause ID +; ; -; * ID .. clauseID +; ; -; * Head,Body.. of clause ID, Vars.. variables of clause ID +; ; -; * Varinstances.. instantiations of the clause variables according +; ; -; * to Covered. If Vars = [V1,..,Vn] and |Covered| = m, then +; ; -; * Varinstances = [[I11,..,I1n],..,[Im1,..,Imn]] +; ; -; * +; ; -; * description: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (clause_instances () $_ $_ $_ $_ ()) True) +; + (= (clause-instances (Cons @@ -388,19 +418,27 @@ (member (:: $IDC $Ex $PBody) $Proofs) $Bodies) (body-instances $Bodies $B1))) +; + (= (body_instances () $_) True) +; + (= (body-instances (Cons $B $R) $B1) ( (body-instances $R $B1) (body-inst $B $B1))) +; + (= (body-inst Nil True) (set-det)) +; + (= (body-inst (Cons @@ -411,82 +449,92 @@ (not (ground $B)) (ask-for-ex $B) True) (body-inst $R $R1))) +; + (= (body-inst (:: (:: $_ $B $_)) $B) (det-if-then-else (not (ground $B)) (ask-for-ex $B) True)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: reduce_newpred_args/7 +; ; -; * +; ; -; * syntax: reduce_newpred_args(+Vars,+Vars,+PCovered,+Ncovered, +; ; -; * -Vars,-PCovered,-NCovered) +; ; -; * +; ; -; * args: Vars.. argument variables of the new predicate, to be +; ; -; * reduced +; ; -; * PCovered,NCovered.. Instantiations of these argument +; ; -; * variables according to the Pos/Neg examples covered +; ; -; * by the clause +; ; -; * +; ; -; * description: discrimination based reduction +; ; -; * +; ; -; * see also: CHAMP/DBC +; ; -; * +; ; -; *********************************************************************** +; (= (reduce_newpred_args () $Vars $PVars $NVars $Vars $PVars $NVars) True) +; + (= (reduce-newpred-args (Cons $X $R) $Vars $P $N $Vars2 $P2 $N2) ( (remove-arg $X $Vars $Vars1 $P $P1 $N $N1) (intersection $P1 $N1 Nil) (reduce-newpred-args $R $Vars1 $P1 $N1 $Vars2 $P2 $N2))) +; + (= (reduce-newpred-args (Cons $_ $R) $Vars $P $N $Vars2 $P2 $N2) (reduce-newpred-args $R $Vars $P $N $Vars2 $P2 $N2)) +; + (= @@ -495,145 +543,165 @@ (set-det) (rem-ins $P $Pos $P1) (rem-ins $N $Pos $N1))) +; + (= (rem-arg $X (Cons $Y $R) $R $Pos $Pos) ( (== $X $Y) (set-det))) +; + (= (rem-arg $X (Cons $Y $R) (Cons $Y $R1) $Pos $Pos1) ( (is $Pos0 (+ $Pos 1)) (rem-arg $X $R $R1 $Pos0 $Pos1))) +; + (= (rem_ins () $_ ()) True) +; + (= (rem-ins (Cons $V $R) $Pos (Cons $V1 $R1)) ( (rem-i $V 1 $Pos $V1) (rem-ins $R $Pos $R1))) +; + (= (rem-i (Cons $_ $R) $P $P $R) (set-det)) +; + (= (rem-i (Cons $X $R) $P $P1 (Cons $X $R1)) ( (is $P0 (+ $P 1)) (rem-i $R $P0 $P1 $R1))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: make_newp_ex/3 +; ; -; * +; ; -; * syntax: make_newp_ex(Varinstances,Newp_name,Newp_examples) +; ; -; * +; ; -; * args: Varinstances.. instantiations of the argument variables +; ; -; * [[I11,..,I1n],..,[Im1,..,Imn]] +; ; -; * Newp_examples [New_name(I11,..,I1n),..,Newp_name(Im1,..,Imn)] +; ; -; * +; ; -; * description: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (make_newp_ex () $_ ()) True) +; + (= (make-newp-ex (Cons $V $R) $X (Cons $N $R1)) ( (=.. $N (Cons $X $V)) (make-newp-ex $R $X $R1))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: make_type_restriction/4 +; ; -; * +; ; -; * syntax: make_type_restriction(+Newpvars,+Typed_clause_vars, +; ; -; * -Type_restriction) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (make_type_restriction () $_ ()) True) +; + (= (make-type-restriction (Cons $X $R) $TVars @@ -642,6 +710,8 @@ (mtr $X $TVars $TN) (=.. $T (:: $TN $X)))) +; + (= @@ -649,50 +719,54 @@ (Cons (with_self $Y $T) $_) $T) ( (== $X $Y) (set-det))) +; + (= (mtr $X (Cons $_ $R) $T) (mtr $X $R $T)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: is_newpred/1 +; ; -; * +; ; -; * syntax: is_newpred(+Pred_Name) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: checks whether Pred_Name is of the form 'newpXX' +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -703,3 +777,5 @@ (Cons $E (Cons $W (Cons $P $_))))) (name newp (:: $N $E $W $P)))) +; + diff --git a/miles/show_utils.metta b/miles/show_utils.metta index 552626d..f5f4aae 100644 --- a/miles/show_utils.metta +++ b/miles/show_utils.metta @@ -1,5 +1,5 @@ ; -; MODULE show_utils EXPORTS +; !(module show-utils @@ -18,131 +18,128 @@ (/ show-bodies 0) (/ pp-clause 1) (/ write-list 1))) -; ; Show all clauses - -; ; Show all examples - -; ; Show one clause - -; ; Show all names of predicates - -; ; Show some clauses - -; ; displays all available types - -; ; Print all clauses to UNIX-file - +; ; -; IMPORTS +; !(use-module (home bu-basics) (:: (/ head 3) (/ body 3))) +; + !(use-module (home div-utils) (:: (/ make-unique 2) (/ mysetof 3))) +; + !(use-module (home kb) (:: (/ get-clause 5) (/ get-example 3))) +; + !(use-module (home argument-types) (:: (/ type-restriction 2))) +; + !(use-module-if-exists (library basics) (:: (/ nonmember 2) (/ member 2))) +; + ; -; METAPREDICATES +; ; -; none +; ; -; *********************************************************************** +; ; -; * +; ; -; * module: show_utils.pl +; ; -; * +; ; -; * author: B.Jung, M.Mueller, I.Stahl, B.Tausend date:12/92 +; ; -; * +; ; -; * changed: +; ; -; * +; ; -; * description: various diplays predicates +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: show_kb/0 +; ; -; * +; ; -; * syntax: - +; ; -; * +; ; -; * args: none +; ; -; * +; ; -; * description: displays all clauses in kb asserted by known +; ; -; * +; ; -; *********************************************************************** +; @@ -151,43 +148,47 @@ ( (get-clause $I $H $B $_ $O) (show-kb-clause $I $H $B $O) (fail))) +; + (= (show-kb) (set-det)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: print_kb/1 +; ; -; * +; ; -; * syntax: print_kb(+ File) +; ; -; * +; ; -; * args: File: name of a file +; ; -; * +; ; -; * description: prints kb to a file +; ; -; * +; ; -; *********************************************************************** +; @@ -196,41 +197,43 @@ ( (tell $Filename) (show-kb) (told))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: show_clause/1 +; ; -; * +; ; -; * syntax: show_clause(+ ID) +; ; -; * +; ; -; * args: ID: the ID of a clause +; ; -; * +; ; -; * description: displays the clause stored with ID +; ; -; * +; ; -; *********************************************************************** +; @@ -244,94 +247,100 @@ (write )) (portray-clause (= $H $B)) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: show_clauses/1 +; ; -; * +; ; -; * syntax: show_clauses(+List_of_clauseIDs) +; ; -; * +; ; -; * args: +List_of_clauseIDs: a list of clause IDs +; ; -; * +; ; -; * description: displays each clause with ID in List_of_clauseIDs +; ; -; * +; ; -; *********************************************************************** +; (= (show-clauses Nil) (set-det)) +; + (= (show-clauses (Cons $Id1 $Rest)) ( (show-clause $Id1) (nl) (show-clauses $Rest))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: show_kb_clause/4 +; ; -; * +; ; -; * syntax: show_kb_clause(+I,+H,+B,+O) +; ; -; * +; ; -; * args: I: an ID in KB +; ; -; * H: the head of a clause +; ; -; * B: the body of a clause +; ; -; * O: the label of a clause +; ; -; * +; ; -; * description: displays a clause H:-B, used for xm +; ; -; * +; ; -; ************************************************************************ +; @@ -341,46 +350,50 @@ (:: $I $O)) (not (not (, (guess-varnames (= $H $B)) (implode-varnames (= $H $B)) (portray-clause (= $H $B))))) (set-det))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate:show_names/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: none +; ; -; * +; ; -; * description: lists all predicate names available in the kb +; ; -; * +; ; -; *********************************************************************** +; (= (show-names) (show-names Nil)) +; + (= (show-names $Accu) ( (get-clause $_ $H $_ $_ $_) @@ -389,45 +402,49 @@ (format "~10|~a~n" $Name) (set-det) (show-names (Cons $Name $Accu)))) +; + (= (show-names $_) (set-det)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: show_kb_part/2 +; ; -; * +; ; -; * syntax: show_kb_part(+From,+To) +; ; -; * +; ; -; * args: From: the min ID of KB entries to be shown +; ; -; * To: the max ID of KB entries to be shown +; ; -; * +; ; -; * description: shows all clauses with From <= ID <= To +; ; -; * +; ; -; ************************************************************************ +; @@ -442,40 +459,42 @@ (get-clause $I $H $B $S $O) (=< $From $I) (>= $To $I)))))) $IDL) (show-clauses $IDL))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: show_ex/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: none +; ; -; * +; ; -; * description: displays all examples in kb +; ; -; * +; ; -; *********************************************************************** +; @@ -490,64 +509,68 @@ (write $C) (nl) (fail))) +; + (= (show-ex) (set-det)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: show_heads/0, show_bodies/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: displays all intermediate heads/bodies stored by absorption, +; ; -; * saturation,... in the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -557,7 +580,11 @@ (write (head $L $Flag $C)) (nl) (fail))) +; + (= show_heads True) +; + (= @@ -566,123 +593,133 @@ (write (body $L $Flag $C)) (nl) (fail))) - (= show_bodies True) +; + + (= show_bodies True) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: pp_clause/1 +; ; -; * +; ; -; * syntax: pp_clause(+CL) +; ; -; * +; ; -; * args: CL .. clause in list notation +; ; -; * +; ; -; * description: displays clause in list notation +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (pp_clause ()) True) +; + (= (pp-clause (Cons (with_self $H $S) $Rest)) ( (write (with_self $H $S)) (nl) (pp-clause $Rest))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: write_list/1 +; ; -; * +; ; -; * syntax: write_list(+List) +; ; -; * +; ; -; * args: List: a list +; ; -; * +; ; -; * description: displays copy of a list after instantiating all terms +; ; -; within the copy by $Var(N) +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (write_list ()) True) +; + (= (write-list (Cons $X0 $R)) ( (copy-term $X0 $X) @@ -690,55 +727,58 @@ (write $X) (nl) (write-list $R))) - (= - (write-list (with_self $PS (with_self $_ $_))) - (write-list $PS)) +; + +; (error +; (syntax_error operator_clash) +; (file miles/show_utils.pl 270 14 7417)) + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: show_kb_types/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: displays definitions of all types in the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; *********************************************************************** +; @@ -760,10 +800,14 @@ (nl) (write 'The following types are defined in the knowledge base:') (nl) - (show-kb-types (Cons (with_self (is-symbol) Nil) (Cons (with_self (number) Nil) (Cons (with_self (symbolic) Nil) $Tlist)))))) + (show-kb-types (Cons (with_self (is-symbol *) Nil) (Cons (with_self (number *) Nil) (Cons (with_self (symbolic *) Nil) $Tlist)))))) +; + (= (show_kb_types ()) True) +; + (= (show-kb-types (Cons (with_self $T $Def) $R)) ( (nl) @@ -772,68 +816,74 @@ (nl) (show-kb-t $Def) (show-kb-types $R))) +; + (= (show_kb_t ()) True) +; + (= (show-kb-t (Cons $C $R)) ( (numbervars $C 0 $_) (write $C) (nl) (show-kb-t $R))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: show_type_restrictions/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: displays all type restrictions in the kb +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -849,4 +899,8 @@ (write $A) (write )) (fail))) +; + (= show_type_restrictions True) +; + diff --git a/miles/td_basic.metta b/miles/td_basic.metta index 7288849..4402456 100644 --- a/miles/td_basic.metta +++ b/miles/td_basic.metta @@ -1,5 +1,5 @@ ; -; MODULE td_basic EXPORTS +; !(module td-basic @@ -8,114 +8,118 @@ (/ vars-of-type 3) (/ enumerate-t 3) (/ append-body 3))) +; + ; -; IMPORTS +; !(use-module (home argument-types) (:: (/ type-sub 2))) +; + ; -; METAPREDICATES +; ; -; none +; ; -; *********************************************************************** +; ; -; * +; ; -; * module: td_basic.pl +; ; -; * +; ; -; * author: I.Stahl date:12/92 +; ; -; * +; ; -; * changed: +; ; -; * +; ; -; * description: basics for top-down induction +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: append_body/3 +; ; -; * +; ; -; * syntax: append_body(+Clause,+Literal,-Clause1) +; ; -; * +; ; -; * args: Clause,Clause1.. MeTTa clauses +; ; -; * +; ; -; * description: adds Literal to the end of the body of Clause +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -124,88 +128,98 @@ (= $H True) $B (= $H $B)) (set-det)) +; + (= (append-body (= $H $B) $C (= $H $B1)) ( (set-det) (append-body $B $C $B1))) +; + (= (append-body (, $A $B) $C (, $A $D)) ( (set-det) (append-body $B $C $D))) +; + (= (append_body $A $B (, $A $B)) True) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: distribute_vars/3 +; ; -; * +; ; -; * syntax: distribute_vars(+PVars,+Terms,-DVars) +; ; -; * +; ; -; * args: PVars = [X:Tx|R]: terms X with types Tx in the new literal P +; ; -; * Terms: all terms with their types in the clause C to be refined +; ; -; * +; ; -; * DVars = [X:Vx,...]: for each X in PVars a list of all type-matching +; ; -; * variables Vx in Terms + an additional new variable +; ; -; * +; ; -; * description: computes DVars +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (distribute_vars () $_ ()) True) +; + (= (distribute-vars (Cons @@ -213,296 +227,312 @@ (Cons (with_self $X $Vx) $R1)) ( (distribute-vars $R $V $R1) (vars-of-type $V $Tx $Vx))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: vars_of_type/3 +; ; -; * +; ; -; * syntax: vars_of_type(+Terms,+Ty,-R2) +; ; -; * +; ; -; * args: Terms= [X:Tx|_]: terms X with types Tx in the clause C to be refined +; ; -; * Ty: type Ty of an argument of the new literal +; ; -; * R2: a list of all terms in C matching type Ty +; ; -; * +; ; -; * description: adds a term X of Terms to R2 if type Ty subsumes type +; ; -; * of X or vice versa +; ; -; * and one new term (last element in R2) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (vars_of_type () $_ ($_)) True) +; + (= (vars-of-type (Cons (with_self $X $Tx) $R) $Ty $R2) ( (vars-of-type $R $Ty $R1) (det-if-then-else (or (type-sub $Ty $Tx) (type-sub $Tx $Ty)) (= $R2 (Cons $X $R1)) (= $R2 $R1)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: enumerate_t/3 +; ; -; * +; ; -; * syntax: enumerate_t(+DVars,+PL,-PL2) +; ; -; * +; ; -; * args: DVars = [X:Vx,...]: all variables X in the new literal +; ; -; * with their type-matching variables in C +; ; -; * PL: initial predicate list +; ; -; * +; ; -; * PL2: predicate list +; ; -; * +; ; -; * description: computes predicates P where variables in Vx are unified to X in P +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (enumerate_t () $PL $PL) True) +; + (= (enumerate-t (Cons (with_self $X $Vx) $R) $PL $PL2) ( (enumerate-t $R $PL $PL1) (et $Vx $X $PL1 $PL2))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: et/4 +; ; -; * +; ; -; * syntax: et(+Vx,+X,+PL,-PL3) +; ; -; * +; ; -; * args: Vx: a list of variables to be unified with X +; ; -; * X: a term of P to be unified by a variable of Vx +; ; -; * PL: initial predicate list +; ; -; * +; ; -; * PL3: predicate list +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (et () $_ $_ ()) True) +; + (= (et (Cons $Y $R) $X $PL $PL3) ( (et $R $X $PL $PL1) (etx $PL $X $Y $PL2) (append $PL2 $PL1 $PL3))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: etx/4 +; ; -; * +; ; -; * syntax: etx(PL,X,Y,R2) +; ; -; * +; ; -; * args: PL: literals of P +; ; -; * X: a term of P to be unified by Y +; ; -; * Y: a term of the clause C to be unfied with X +; ; -; * +; ; -; * R2: predicate list where X and Y are unified +; ; -; * +; ; -; * description: (if Y is not in args(P) then ) "unify" X and Y. This is +; ; -; * done by copying P and replacing X by Y. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (etx () $_ $_ ()) True) +; + (= (etx (Cons $P $R) $X $Y $R2) @@ -512,74 +542,78 @@ (etx1 $N $P $P1 $X $Y) (= $R2 (Cons $P1 $R1)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: etx1/5 +; ; -; * +; ; -; * syntax: etx1(+N,+P,-P1,+X,+Y) +; ; -; * +; ; -; * args: N: arity of literal P +; ; -; * P: literal to be added +; ; -; * X: variable to be replaced by Y +; ; -; * Y: variable +; ; -; * +; ; -; * description: replaces X by Y in the copy P1 of P +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (etx1 0 $_ $_ $_ $_) (set-det)) +; + (= (etx1 $N $P $P1 $X $Y) ( (is $N1 @@ -590,6 +624,8 @@ (== $Pn $X) (arg $N $P1 $Y) (arg $N $P1 $Pn)))) +; + diff --git a/miles/tdref_it.metta b/miles/tdref_it.metta index b23e5c9..1df7036 100644 --- a/miles/tdref_it.metta +++ b/miles/tdref_it.metta @@ -1,5 +1,5 @@ ; -; MODULE tdref_it EXPORTS +; !(module tdref-it @@ -12,10 +12,12 @@ (/ refinement-add-body-literal 2) (/ refinement 2) (/ possible-body-literals 3))) +; + ; -; IMPORTS +; !(use-module (home kb) @@ -23,159 +25,173 @@ (/ get-clause 5) (/ get-evaluation 2) (/ get-predlist 1))) +; + !(use-module (home td-basic) (:: (/ distribute-vars 3) (/ enumerate-t 3) (/ append-body 3))) +; + !(use-module (home filter) (:: (/ noduplicate-symbols 1) (/ noduplicate-symbol 2) (/ select-var-sharing-lits 2))) +; + !(use-module (home div-utils) (:: (/ mysetof 3))) +; + !(use-module (home var-utils) (:: (/ typed-only-vars1 2) (/ clause-terms 2))) +; + !(use-module (home argument-types) (:: (/ compare-types 3) (/ types-of 3))) +; + !(use-module (home show-utils) (:: (/ write-list 1))) +; + ; -; METAPREDICATES +; ; -; none +; ; -; *********************************************************************** +; ; -; * +; ; -; * module: tdref_it.pl +; ; -; * +; ; -; * author: I.Stahl date:12/92 +; ; -; * +; ; -; * changed: comments BT; 11/10/92 +; ; -; * +; ; -; * description: top-down refinement operators for Horn clauses +; ; -; * work iteratively +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; * +; ; -; *********************************************************************** +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicates: refinement_unify_variables/2, +; ; -; * refinement_instantiate_variables/2, +; ; -; * refinement_add_body_literal/2 +; ; -; * +; ; -; * syntax: refinement_...(+ClauseID,-(ClauseID,CL)) +; ; -; * +; ; -; * args: ClauseID ... ID of the clause to be specialized +; ; -; * CL .... list of specialisations of Clause +; ; -; * +; ; -; * description: refines clause by unifying variables/instantiating +; ; -; * variables with terms/adding a body literal. Returns +; ; -; * list of specialised clauses +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -188,6 +204,8 @@ (clause-terms $C $Terms) (types-of $Terms $C $TTerms) (refinement-unify-variables $C $TTerms $CL))) +; + (= @@ -199,6 +217,8 @@ (clause-terms $C $Terms) (types-of $Terms $C $TTerms) (refinement-instantiate-variables $C $TTerms $CL))) +; + (= @@ -211,91 +231,97 @@ (types-of $Terms $C $TTerms) (refinement-add-body-literal $C $TTerms $CL1) (select-var-sharing-lits $CL1 $CL))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicates: refinement_unify_variables/3, +; ; -; * refinement_instantiate_variables/3, +; ; -; * refinement_add_body_literal/3 +; ; -; * +; ; -; * syntax: refinement_...(+Clause,+Terms,-CL) +; ; -; * +; ; -; * args: Clause ... the clause to be specialized +; ; -; * Terms ... the terms that shall be used in refinement +; ; -; * of the form [T:Type,...] +; ; -; * CL .... list of specialisations of Clause +; ; -; * +; ; -; * description: refines clause by unifying variables/instantiating +; ; -; * variables with terms/adding a body literal. Returns +; ; -; * list of specialised clauses +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (refinement-unify-variables $C $T $CL) ( (typed-only-vars1 $T $Vars) (ref-unify-vars $C $Vars $Vars Nil $CL))) +; + (= (refinement-instantiate-variables $C $T $CL) ( (typed-only-vars1 $T $Vars) (ref-instantiate-vars $C $Vars Nil $CL))) +; + (= @@ -306,225 +332,235 @@ (ref-add-body-literal $C $T Nil $CL) (ref-add-body-literal (= $C True) $T Nil $CL))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicates: possible_body_literals/3 +; ; -; * +; ; -; * syntax: possible_body_literals(+Clause,+Terms,-LL) +; ; -; * +; ; -; * args: Clause ... the clause to be specialized +; ; -; * Terms ... the terms that shall be used in refinement +; ; -; * of the form [T:Type,...] +; ; -; * LL .... list of literals that might be added +; ; -; * +; ; -; * description: Returns the list of literals that might be used to refine +; ; -; * Clause +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (possible-body-literals $C $Terms $LL) ( (get-predlist $Predlist) (enumerate-terms $Predlist $Terms $C Nil $LL))) +; + ; -; *********************************************************************** +; ; -; * predicate: ref_unify_vars/5 +; ; -; * syntax: ref_unify_vars(+C,+[X:T|R],+V,+CL,-CL2) +; ; -; * +; ; -; * args: C: the clause to be refined +; ; -; * [X:T|R]: all variables with their types in C +; ; -; * V: all variables X:T in C +; ; -; * +; ; -; * CL: initial clause set +; ; -; * CL2: CL + copies of C where variables are unified +; ; -; * +; ; -; * description: unifies clause variables of the same type +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (ref_unify_vars $_ () $_ $CL $CL) True) +; + (= (ref-unify-vars $C (Cons $X $R) $V $CL $CL2) ( (ref-unify-vars $C $R $V $CL $CL1) (ref-unify-vars1 $C $X $V $CL1 $CL2))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: ref_unify_vars1/5 +; ; -; * +; ; -; * syntax: ref_unify_vars1(+C,+X:Tx,+[Y:Ty|R],+CL,-CL2) +; ; -; * +; ; -; * args: C: the clause to be refined +; ; -; * X:Tx: variable X of type Tx in C +; ; -; * [Y:Ty|R]: all variables Y:Ty in C +; ; -; * +; ; -; * CL: initial clause set +; ; -; * CL2: copies of the clause C where X is unified with each +; ; -; * matching Y +; ; -; * +; ; -; * description: makes copies of the clause C with unified variables +; ; -; * if the type of the variables is can be matched +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (ref_unify_vars1 $_ $_ () $CL $CL) True) +; + (= (ref-unify-vars1 $C (with_self $X $Tx) @@ -532,78 +568,82 @@ (with_self $Y $Ty) $R) $CL $CL2) ( (ref-unify-vars1 $C (with_self $X $Tx) $R $CL $CL1) (det-if-then-else (, (compare-types $Tx $Ty $_) (@< $X $Y)) (, (copy-term (, $C $X $Y) (, $C1 $Z $Z)) (det-if-then-else (noduplicate-atoms $C1) (= $CL2 (Cons $C1 $CL1)) (= $CL2 $CL1))) (= $CL2 $CL1)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: ref_instantiate_vars/4 +; ; -; * +; ; -; * syntax: ref_instantiate_vars(+C,+[X:T|R]+CL,-CL2) +; ; -; * +; ; -; * args: C: the clause to be refined +; ; -; * [X:T|R]: variables X of type T in C +; ; -; * +; ; -; * CL: initial clause set +; ; -; * CL2: CL + copies of C where variables are instantiated +; ; -; * +; ; -; * description: instantiates variables by terms according to the +; ; -; * variables' type +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (ref_instantiate_vars $_ () $CL $CL) True) +; + (= (ref-instantiate-vars $C (Cons @@ -623,93 +663,99 @@ (nonvar $X1)))))) $HL) (ref-inst-vars $HL $H $C $HL1) (append $HL1 $CL1 $CL2))) +; + (= (ref_inst_vars () $_ $_ ()) True) +; + (= (ref-inst-vars (Cons $H1 $R) $H $C $HL2) ( (ref-inst-vars $R $H $C $HL1) (det-if-then-else (, (copy-term (, $H $C) (, $H1 $C1)) (noduplicate-atoms $C1)) (= $HL2 (Cons $C1 $HL1)) (= $HL2 $HL1)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: ref_add_body_literal/4 +; ; -; * +; ; -; * syntax: ref_add_body_literal(+C,+Terms,+CL,-CL1) +; ; -; * +; ; -; * args: C: the clause to be refined +; ; -; * [TT:T|R]: all terms TT and subterms with their types T in C +; ; -; * +; ; -; * CL: initial clause set +; ; -; * CL2: CL + copies of C with additional body literals +; ; -; * +; ; -; * description: adds a body literal to C by +; ; -; * - selecting all predicates with a type restriction contained in the kb +; ; -; * - enumerating literals where (at least one) argument of the new +; ; -; * literal is unfied with terms in the clause +; ; -; * - for each literal L: copy C and L, append the copied +; ; -; * literal to the copy of C and add the resulting clause to CL +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -718,78 +764,82 @@ ( (get-predlist $Predlist) (enumerate-terms $Predlist $Terms $C Nil $L) (add-to-bodies $L $C $CL $CL1))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: add_to_bodies/4 +; ; -; * +; ; -; * syntax: add_to_bodies(+[Lit|R],+C,+CL,-CL1) +; ; -; * +; ; -; * args: [Lit|R]: a set of literals Lit to be added to the body +; ; -; * C: the clause to be refined +; ; -; * +; ; -; * CL: initial clause list +; ; -; * CL1: CL + refined clauses +; ; -; * +; ; -; * description: adds each literal to a copy of C, if it is not +; ; -; * duplicate in C +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (add_to_bodies () $_ $CL $CL) True) +; + (= (add-to-bodies (Cons $Pred $R) $C $CL $CL2) @@ -807,90 +857,94 @@ (= $CL2 (Cons $C2 $CL1))) (= $CL2 $CL1)))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: enumerate_terms/5 +; ; -; * +; ; -; * syntax: enumerate_terms(+[P:PVars|R],+Terms,+C,+L,-L2) +; ; -; * +; ; -; * args: [P:PVars|R]: predicate P & its variables PVars=[PV1:Tpv1,...] +; ; -; * Terms: all terms with types in C +; ; -; * C: clause to be refined +; ; -; * L: initial literal list +; ; -; * +; ; -; * L2: new literal list +; ; -; * +; ; -; * description: builds all literals from all predicates to be added by +; ; -; * - collecting all variables that could be unified with any variable of PVars +; ; -; * - building all literals with these variables replaced +; ; -; * - eliminating all those literals that already occur in C +; ; -; * - appending the literals to L2 +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (enumerate_terms () $_ $_ $L $L) True) +; + (= (enumerate-terms (Cons @@ -900,91 +954,93 @@ (enumerate-t $PVars1 (:: $P) $Plist) (append $Plist $L1 $L2))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: refinement/2 +; ; -; * +; ; -; * syntax: refinement(+ID,-CL) +; ; -; * +; ; -; * args: ID: ID of a clause to be refined +; ; -; * CL: a list with refinements of the clause with ID +; ; -; * +; ; -; * description: shapiro's general refinement operator for a clause +; ; -; * with ID (all terms are eligible for refinement): +; ; -; * if there are covered positive examples: +; ; -; * - prepare for refinement: +; ; -; * a list of all terms and subterms augmented by their types +; ; -; * and a list of all variables in the clause with types +; ; -; * - refine clause by +; ; -; * - unifying variables within the clause +; ; -; * - instantiating variables within the clause to terms +; ; -; * - adding body literals. Only literals sharing at least a +; ; -; * variable with clause ID are allowed. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1012,6 +1068,8 @@ (select-var-sharing-lits $CL2 $CL3) (append $CL0 $CL1 $CL4) (append $CL4 $CL3 $CL))))) +; + (= (refinement @@ -1029,4 +1087,6 @@ (select-var-sharing-lits $CL2 $CL3) (append $CL0 $CL1 $CL4) (append $CL4 $CL3 $CL))) +; + diff --git a/miles/var_utils.metta b/miles/var_utils.metta index 24a6548..f7d6f60 100644 --- a/miles/var_utils.metta +++ b/miles/var_utils.metta @@ -1,5 +1,5 @@ ; -; MODULE var_utils EXPORTS +; !(module var-utils @@ -29,9 +29,11 @@ (/ clean-subst 3) (/ findargs 3) (/ allarg 4))) +; + ; -; IMPORTS +; !(use-module (home div-utils) @@ -44,23 +46,33 @@ (/ best 2) (/ subterm-at-position 4) (/ part-of-clause 2))) +; + !(use-module (home flatten) (:: (/ flatten-clause 2) (/ unflatten-clause 2))) +; + !(use-module (home filter) (:: (/ truncate-unconnected 2))) +; + !(use-module (home lgg) - (:: (/ lgg-terms 7))) + (:: (/ lgg-terms 7))) +; + !(use-module-if-exists (library basics) (:: (/ member 2) (/ nonmember 2) (/ memberchk 2))) +; + !(use-module-if-exists (library sets) (:: @@ -68,141 +80,149 @@ (/ subtract 3) (/ list-to-set 2) (/ intersection 3))) +; + !(use-module-if-exists (library strings) (:: (/ gensym 2) (/ string-append 3) (/ substring 4))) +; + !(use-module-if-exists (library occurs) (:: (/ sub-term 2) (/ contains-var 2))) +; + !(use-module-if-exists (library subsumes) (:: (/ variant 2))) +; + ; -; METAPREDICATES +; ; -; none +; ; -; *********************************************************************** +; ; -; * +; ; -; * module: var_utils.pl +; ; -; * +; ; -; * author: B.Jung, M.Mueller, I.Stahl, B.Tausend date:12/92 +; ; -; * +; ; -; * changed: +; ; -; * +; ; -; * description: - utilities for variable and clause handling +; ; -; * - determine relevant variables for predicate invention. +; ; -; * - inverse_substitution +; ; -; * - skolemization is a special substitution +; ; -; * - replacement +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: vars/2 +; ; -; * +; ; -; * syntax: vars(+Term,-Vars) +; ; -; * +; ; -; * args: Term: any MeTTa term +; ; -; * Vars: list of variables in Term +; ; -; * +; ; -; * description: +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: setof changed to mysetof (IS) +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -212,61 +232,63 @@ (, (sub-term $V $Term) (var $V)) $Vars)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: clause_terms/2 +; ; -; * +; ; -; * syntax: clause_terms(+Clause,-Termlist) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: returns list of all non-ground terms in Clause +; ; -; * +; ; -; * example: clause_terms((p(f(X),a,g(Y,b)):- r(f(X),Y)), +; ; -; * [f(X),X,g(Y,b),Y]) +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -277,9 +299,13 @@ (functor $H $_ $N) (terms $N $H Nil $L0) (clause-terms $B $L0 $L))) +; + (= (clause-terms $H $L) - ( (functor $H $_ $N) (terms $N $H Nil $L))) + ( (functor $H $_ $N) (terms $N $H Nil $L))) +; + (= (clause-terms @@ -287,64 +313,68 @@ ( (set-det) (clause-terms $A $L $L1) (clause-terms $B $L1 $L2))) +; + (= (clause-terms $A $L $L1) ( (functor $A $_ $N) (terms $N $A $L $L1))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: terms/3,4 +; ; -; * +; ; -; * syntax: terms(+Term,+Accu,-Accu) +; ; -; * terms(+Count,+Term,+Accu,-Accu) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: returns all non-ground subterms within Term +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -357,13 +387,19 @@ (= $L1 $L) (= $L1 (Cons $V $L))))) +; + (= (terms $T $L $L1) ( (functor $T $_ $N) (det-if-then-else (or (ground $T) (identical-member $T $L)) (= $L1 $L) (terms $N $T (Cons $T $L) $L1)))) +; + (= (terms 0 $_ $L $L) (set-det)) +; + (= (terms $N $T $L $L2) ( (is $N1 @@ -371,68 +407,74 @@ (terms $N1 $T $L $L1) (arg-quintus $N $T $Tn) (terms $Tn $L1 $L2))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: only_vars/2 +; ; -; * +; ; -; * syntax: only_vars(+Term,-Varlist) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: returns all variables within Term +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (only-vars $T $L) ( (terms $T Nil $L1) (only-vars1 $L1 $L))) +; + (= (only_vars1 () ()) True) +; + (= (only-vars1 (Cons $X $R) @@ -440,73 +482,79 @@ ( (var $X) (set-det) (only-vars1 $R $R1))) +; + (= (only-vars1 (Cons $_ $R) $R1) (only-vars1 $R $R1)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: typed_only_vars1/2 +; ; -; * +; ; -; * syntax: typed_only_vars1(+TypedTermlist,-TypedVarlist) +; ; -; * +; ; -; * args: TypedTermlist: [T:typeT,...] +; ; -; * Vars: [Var:typeVar +; ; -; * +; ; -; * description: extracts each term T that is a variable +; ; -; * from a list TypedTermlist of terms with type definition +; ; -; * +; ; -; * example: only_vars2([X:type16,Y:type14,f(Z):type23],[X:type16,Y:type14]) +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (typed_only_vars1 () ()) True) +; + (= (typed-only-vars1 (Cons @@ -516,75 +564,79 @@ ( (var $X) (set-det) (typed-only-vars1 $R $R1))) +; + (= (typed-only-vars1 (Cons $_ $R) $R1) (typed-only-vars1 $R $R1)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: replace/3 +; ; -; * +; ; -; * syntax: replace(+C1,+S1,-C2,-S2) +; ; -; * +; ; -; * args: C1, C2: clauses in list notation +; ; -; * S1, S2: replacements [ X / Term, .. ] +; ; -; * If all X's are variables, this is actually a +; ; -; * substitution, but we also allow other terms. +; ; -; * +; ; -; * description: C2 is a copy of C1 with S1 applied. +; ; -; * S2 is a copy of S1. +; ; -; * +; ; -; * example: replace( [p(A,B):p], [A/a], [p(a,D):p], [C/a]). +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -593,11 +645,15 @@ ( (copy-term (, $C $S1) (, $E $S2)) (do-replace $E $S2 $D))) +; + (= (do_replace () $_ ()) True) +; + (= (do-replace @@ -606,6 +662,8 @@ ( (do-replace1 $L $S $L1) (set-det) (do-replace $More $S $More1))) +; + (= @@ -624,9 +682,13 @@ (, (functor $T2 $F $N) (do-replace1 $N $T1 $T2 $S)))))) +; + (= (do_replace1 0 $_ $_ $_) True) +; + (= (do-replace1 $N $T1 $T2 $S) @@ -636,72 +698,76 @@ (is $M (- $N 1)) (do-replace1 $M $T1 $T2 $S))) +; + (= (arg-quintus $N $C $E) ( (compound $C) (arg $N $C $E))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: inv_replace/4 +; ; -; * +; ; -; * syntax: inv_replace(+C1,+S1,-C2,-S2) +; ; -; * +; ; -; * args: C1, C2: clauses in list notation +; ; -; * S1, S2: replacements [ X / Term, .. ] +; ; -; * +; ; -; * description: C2 is a copy of C1 with term of S1 replaced by ass. vars +; ; -; * S2 is a copy of S1,s.t. vars(S2) in vars(C2). +; ; -; * +; ; -; * example: inv_replace( [p(a,B):p], [A/a], [p(C,D):p], [C/a]). +; ; -; * +; ; -; * peculiarities: this is not the inverse operation for replacement : +; ; -; * We don't distinguish the between places of terms. +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -711,17 +777,23 @@ ( (copy-term (, $C $S1) (, $E $S2)) (do-inv-replace $E $S2 $D))) +; + (= (do_inv_replace () $_ ()) True) +; + (= (do-inv-replace (Cons $L $More) $S (Cons $L1 $More1)) ( (do-inv-replace1 $L $S $L1) (do-inv-replace $More $S $More1))) +; + (= @@ -740,9 +812,13 @@ (, (functor $T2 $F $N) (do-inv-replace1 $N $T1 $T2 $S)))))) +; + (= (do_inv_replace1 0 $_ $_ $_) True) +; + (= (do-inv-replace1 $N $T1 $T2 $S) @@ -752,73 +828,77 @@ (is $M (- $N 1)) (do-inv-replace1 $M $T1 $T2 $S))) +; + (= (do-inv-replace1 2 (:: $T) $T2 $S) ( (arg-quintus 2 $T2 Nil) (do-inv-replace1 1 (:: $T) $T2 $S))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: term_size/2 +; ; -; * +; ; -; * syntax: term_size(+Term,-Size) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: the folllowing code is a debugged copy from the Quintus library +; ; -; * 'termdepth' +; ; -; * term_size(+Term, ?Size) calculates the Size of a Term, defined +; ; -; * to be the number of constant and function symbol occurrences in it. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -830,12 +910,7 @@ (, (functor $Term $F $Arity) (term-size $Arity $Term 1 $Size)))) -; /* nonvar(Term) */ - -; ; Here was the bug - -; ; " - +; @@ -852,218 +927,230 @@ (is $M (- $N 1)) (term-size $M $NonVar $Accum $Size)))) +; + ; -; *************************************************************************** +; ; -; * +; ; -; * predicate: contains_vars/2 +; ; -; * +; ; -; * syntax: contains_vars(+Term,+Terms) +; ; -; * +; ; -; * args: Term: any MeTTa term +; ; -; * Vars: list of MeTTa terms (also variables) +; ; -; * +; ; -; * description: succeeds if all terms in Terms occur in Term +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (contains_vars () $_) True) +; + (= (contains-vars (Cons $V $Vars) $Term) ( (contains-var $V $Term) (contains-vars $Vars $Term))) +; + ; -; *************************************************************************** +; ; -; * +; ; -; * predicate: flagged_contains_vars/3 +; ; -; * +; ; -; * syntax: flagged_contains_vars(+Term,+Terms,-Flag) +; ; -; * +; ; -; * args: Term: any MeTTa term, Flag in {true,false} +; ; -; * Vars: list of MeTTa terms (also variables) +; ; -; * +; ; -; * description: returns true if all terms in Terms occur in Term, else false +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (flagged-contains-vars $Vars $Term True) ( (contains-vars $Vars $Term) (set-det))) +; + (= (flagged_contains_vars $Vars $Term false) True) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: inverse_substitute/2 +; ; -; * +; ; -; * syntax: inverse_substitute(+ClauseIn,-ClauseOut) +; ; -; * +; ; -; * args: clauses in list notation, i.e. [ head(A):p, b1(A):n, .. ] +; ; -; * +; ; -; * description: replace one term in ClauseIn by a variable. +; ; -; * Thru backtracking all solutions can be obtained. +; ; -; * Implementation: flatten Clause, +; ; -; * truncate one literal, +; ; -; * truncate unconnected literals, +; ; -; * unflatten Clause. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: Since identical terms are represented only once in +; ; -; * our flattening, we cannot tell between different +; ; -; * places the terms appear at. +; ; -; * +; ; -; * see also: Muggleton,1988 +; ; -; * +; ; -; *********************************************************************** +; (= - (inverse_substitute $Clause $Clause) True) ; -; empty inverse substitution + (inverse_substitute $Clause $Clause) True) +; + ; +; (= @@ -1072,70 +1159,72 @@ (remove-type-literal $C1 $C2) (truncate-unconnected $C2 $C3) (unflatten-clause $C3 $ClauseOut))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: remove_type_literal/2 +; ; -; * +; ; -; * syntax: remove_type_literal(+CL,-CL1) +; ; -; * +; ; -; * args: CL,CL1: clause in list notation +; ; -; * +; ; -; * description: drop a "type literal" functor_p(...) +; ; -; * the next rules allow to perform inverse substitutions on several terms, +; ; -; * at the cost of an exploding search space. +; ; -; * A better strategy is to trunacte literals one by one and +; ; -; * only to truncate the promising clauses further. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1145,8 +1234,7 @@ (with_self $L_p (n)) $More) $More) ( (functor $L_p $F $_) (string-append $_ -p $F))) -; ; drop this literal - +; @@ -1158,69 +1246,68 @@ (Cons (with_self $L $S) $More1)) (remove-type-literal $More $More1)) -; ; drop another literal - +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: inverse_substitute1/2 +; ; -; * +; ; -; * syntax: inverse_substitute1(+CL,-CL) +; ; -; * +; ; -; * args: CL,CL1: clauses in list notation +; ; -; * +; ; -; * description: this is an alternative approach without flattening +; ; -; * it replaces terms by variables. +; ; -; * (This does of course not work on flat clauses) +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1240,16 +1327,15 @@ (do-inverse-sub1 $T $Positions $_ $Clause $Clause1) (clist-to-prolog $CLout $Clause1) (not (variant $CLout $CLin)))) -; ; this rule disallows variable renaming to constrain - -; ; search space at the cost of incompleteness - +; (= (isub1_list () ()) True) +; + (= (isub1-list (Cons @@ -1258,102 +1344,116 @@ (with_self $T (Cons $Pos $Pos1)) $R2)) ( (isub1-l $T $R $R1 $Pos1) (isub1-list $R1 $R2))) +; + (= (isub1_l $_ () () ()) True) +; + (= (isub1-l $T (Cons (with_self $T1 $Pos) $R) $R2 $Pos1) ( (isub1-l $T $R $R1 $Pos0) (det-if-then-else (== $T $T1) (, (= $R2 $R1) (= $Pos1 (Cons $Pos $Pos0))) (, (= $R2 (Cons (with_self $T1 $Pos) $R1)) (= $Pos1 $Pos0))))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: do_inverse_substitute1/5 +; ; -; * +; ; -; * syntax: do_inverse_substitute(+Term,+Positions,+Var,+Clause,-Clause) +; ; -; * +; ; -; * args: Clause: MeTTa clause +; ; -; * Term: the term in Clause to be replaced with variable Var +; ; -; * Positions: list of positions of Term within Clause where it might +; ; -; * be replaced. A position is a list of numbers +; ; -; * +; ; -; * description: replaces Term by a Var +; ; -; * preference is to replace all occurrences of Term by Var; +; ; -; * thru backtracking, clauses may be obtained where +; ; -; * only some occurences of term are replaced. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (do_inverse_sub1 $_ () $_ $Clause $Clause) True) +; + (= (do-inverse-sub1 $T (Cons $P $R) $Var $Clause $Clause2) ( (do-inverse-sub1 $T $R $Var $Clause $Clause1) (do-isub1 $T $P $Var $Clause1 $Clause2))) +; + (= (do-inverse-sub1 $T (Cons $_ $R) $Var $Clause $Clause1) (do-inverse-sub1 $T $R $Var $Clause $Clause1)) +; + (= (do_isub1 $_ () $Var $_ $Var) True) +; + (= (do-isub1 $T (Cons $P $R) $V $C $C1) @@ -1363,11 +1463,15 @@ (arg-quintus $P $C1 $C1p) (arg-quintus $P $C $Cp) (do-isub1 $T $R $V $Cp $C1p))) +; + (= (do-isub-copy 0 $_ $_ $_) (set-det)) +; + (= (do-isub-copy $N $P $C $C1) ( (is $N1 @@ -1378,82 +1482,88 @@ (, (arg-quintus $N $C $Cn) (arg-quintus $N $C1 $Cn))))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: skolemize/3, deskolemize/3 +; ; -; * +; ; -; * syntax: skolemize(+Term1,-Subst,-Term2) +; ; -; * +; ; -; * args: Term1,Term2: arbiraty MeTTa terms +; ; -; * Subst : substitution [ V1/t1, V2/t2, .. ] +; ; -; * where Vi are variables, ti skolem atoms +; ; -; * +; ; -; * description: skolemization is a special substitution: all variables +; ; -; * of Term1 are substituted by atoms. One keeps track of +; ; -; * the substitution thru Subst. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: Rouveirol,1991: ITOU. +; ; -; * +; ; -; *********************************************************************** +; (= (skolemize $T1 $S $T2) (skolemize $T1 Nil $S $T2)) +; + (= (skolemize $T1 $S $S $Sk_Atom) ( (var $T1) (already-skolem-covered $T1 $S $Sk_Atom) (set-det))) +; + (= (skolemize $Var $S (Cons @@ -1461,13 +1571,19 @@ ( (var $Var) (set-det) (gensym sk-symbol $Sk_Atom))) +; + (= (skolemize $T1 $S1 $S2 $T2) ( (functor $T1 $F $N) (functor $T2 $F $N) (skolemize $N $T1 $S1 $S2 $T2))) +; + (= (skolemize 0 $_ $S $S $_) True) +; + (= (skolemize $N $T $S1 $S2 $U) ( (arg-quintus $N $T $Tn) @@ -1476,61 +1592,63 @@ (is $M (- $N 1)) (skolemize $M $T $S3 $S2 $U))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: already_skolem_covered/3 +; ; -; * +; ; -; * syntax: already_skolem_covered(+Var,+Subst,-Skolem_atom) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: if Var has already been skolemized, i.e. Var:Skolem_atom in Subst, +; ; -; * the corresponding Skolem_atom is returned +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: alter Name: already_covered +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1539,72 +1657,76 @@ (Cons (/ $Var1 $Sk_Atom) $_) $Sk_Atom) ( (== $Var $Var1) (set-det))) +; + (= (already-skolem-covered $Var (Cons $_ $S) $Sk_Atom) - (already-skolem-covered $Var $S $Sk_Atom)) + (already-skolem-covered $Var $S $Sk_Atom)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: deskolemize/3 +; ; -; * +; ; -; * syntax: deskolemize(+Term1,+Subst,-Term2) +; ; -; * +; ; -; * +; ; -; * args: Term1,Term2: arbiraty MeTTa terms +; ; -; * Subst : substitution [ V1/t1, V2/t2, .. ] +; ; -; * where Vi are variables, ti skolem atoms +; ; -; * description: Deskolemization reverses skolemization, if the +; ; -; * skolem substitution is given as input. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1613,19 +1735,29 @@ ( (atom $Sk_Atom) (skolem-covered $Sk_Atom $S $Var) (set-det))) +; + (= (deskolemize $Atom $_ $Atom) ( (atomic $Atom) (set-det))) +; + (= (deskolemize $Var $S $Var) ( (var $Var) (set-det))) +; + (= (deskolemize $T1 $S $T2) ( (functor $T1 $F $N) (functor $T2 $F $N) (deskolemize $N $T1 $S $T2))) +; + (= (deskolemize 0 $_ $_ $_) True) +; + (= (deskolemize $N $T $S $U) ( (arg-quintus $N $T $Tn) @@ -1634,61 +1766,63 @@ (is $M (- $N 1)) (deskolemize $M $T $S $U))) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: skolem_covered/3 +; ; -; * +; ; -; * syntax: skolem_covered(+Skolem_atom,+Subst,-Var) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: returns the variable that has been skolemized with Skolem_atom, +; ; -; * i.e. Var/Skolem_atom in Subst +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: alter Name: covered +; ; -; * +; ; -; *********************************************************************** +; @@ -1697,62 +1831,66 @@ (Cons (/ $Var $Sk_Atom) $_) $Var) (set-det)) +; + (= (skolem-covered $Sk_Atom (Cons $_ $S) $Var) (skolem-covered $Sk_Atom $S $Var)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: skolems/2 +; ; -; * +; ; -; * syntax: skolems(+Term,-Skolems) +; ; -; * +; ; -; * args: Term: skolemized term, Skolems: all skolem atoms in Term +; ; -; * +; ; -; * description: returns skolem atoms occuring in Term +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; @@ -1765,92 +1903,97 @@ (atom $Skolem) (atom-concat sk-symbol $Rest $Skolem) (atom-length $Rest $Len))) $Skolems) (set-det))) -; ; q_substring(Skolem,sk_atom,0,Len) - +; (= (skolems $_ ()) True) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: relevant_vars2/6 +; ; -; * +; ; -; * syntax: relevant_vars2(+C1,+C2,+Gen,+S1,+S2,-RelVars) +; ; -; * +; ; -; * args: C1,C2,Gen: clauses in list notation. C1,C2 at bottom of W. +; ; -; * S1,S2: substitutions [V1=T1, .. ]. +; ; -; * RelVars: list of vars [ V1, V2, .. ] +; ; -; * +; ; -; * description: determine relevant vars with CIGOL heuristics. +; ; -; * A variable V in Gen is relevant if +; ; -; * one of the terms T1, T2 it is substituted by in S1, S2 +; ; -; * contains a variable that also appears elsewhere +; ; -; * in S1 or S2. +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (relevant-vars2 $_ $_ $C $S1 $S2 $RelVars) ( (vars $C $AllVars) (relevant-vars2 $AllVars $S1 $S2 $RelVars))) +; + (= (relevant_vars2 () $_ $_ ()) True) +; + (= (relevant-vars2 @@ -1879,85 +2022,89 @@ (contains-var $Subterm2 $T2a))) (set-det) (relevant-vars2 $MoreVars $S1 $S2 $RelVars))) +; + (= (relevant-vars2 (Cons $V $MoreVars) $S1 $S2 $RelVars) (relevant-vars2 $MoreVars $S1 $S2 $RelVars)) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: relevant_vars3/6 +; ; -; * +; ; -; * syntax: relevant_vars3(+C1,+C2,+Gen,+S1,+S2,-RelVars) +; ; -; * +; ; -; * args: C1,C2,Gen: clauses in list notation +; ; -; * S1,S2: substititions +; ; -; * RelVars : set of relevant vars +; ; -; * +; ; -; * description: Gen is a common generaliztion of C1,C2 , +; ; -; * s.t. S1(Gen) is a subsetof C1, and analogously for C2. +; ; -; * +; ; -; * A variable is relevant if +; ; -; * it appears in both Gen and ( C1 - Gen ) +; ; -; * or Gen and ( C2 - Gen ). +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: none +; ; -; * +; ; -; * see also: IRES,ITOU +; ; -; * +; ; -; *********************************************************************** +; @@ -1973,6 +2120,8 @@ (== $Len1 $Len2) (union $Vars1 $Vars2 $Vars0) (deskolemize $Vars0 $Phi $Vars))) +; + (= @@ -1983,68 +2132,69 @@ (skolems $Rest1 $Skolems1) (skolems $Gen $Skolems2) (intersection $Skolems1 $Skolems2 $Skolems))) -; ;;changed Irene - +; ; -; *********************************************************************** +; ; -; * +; ; -; * predicate: findargs/3 +; ; -; * +; ; -; * syntax: findargs(+CL,+Accu,-Accu) +; ; -; * +; ; -; * args: CL: clause in list notation, Accu: arguments of the literals in CL +; ; -; * +; ; -; * description: find all arguments of the literals of a given clause +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (findargs Nil $Result $Result) (set-det)) +; + (= (findargs (Cons @@ -2053,14 +2203,15 @@ (allarg $N $Lit1 Nil $Args) (union $Accu $Args $Newaccu) (findargs $Rest $Newaccu $Result))) -; ; set operator - +; (= (allarg 0 $_ $Accu $Accu) (set-det)) +; + (= (allarg $N $Lit $Args $Result) ( (arg-quintus $N $Lit $Arg1) @@ -2071,70 +2222,72 @@ (allarg $M $Lit (Cons $Arg1 $Args) $Result) (allarg $M $Lit $Args $Result)))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: buildrelterms/6 +; ; -; * +; ; -; * syntax: buildrelterms(+CL1,+CL2,+Clgg,+Subst1,+Subst2,-TermList) +; ; -; * +; ; -; * args: CL1, CL2, Clgg .. clauses in list representation +; ; -; * Subst1,Subst2 ... substitutions such that Clgg Subst1 = CL1 +; ; -; * and Clgg Subst2 = CL2 +; ; -; * TermList ... list of relevant terms for the new predicate +; ; -; * +; ; -; * description: determines the relevant terms for the new predicate +; ; -; * as described in R. Wirth's 1989 PhD thesis +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; @@ -2149,12 +2302,7 @@ (, $Terms1 $Terms2) $SS (, $T1 $T2)) (general-terms $T1 $T2 $Terms $S1 $S2))) -; ; Terms1 = RArgs1 != {} - -; ; Terms2 = RArgs2 != {} -; ; union(Terms1,Terms2,TermsS), -; ; deskolemize(TermsS,SS,Terms). ; changed Irene - +; @@ -2167,88 +2315,87 @@ (findargs $SpecG Nil $ArgsG) (findargs $RestSpec Nil $ArgsR) (exists-intersect $ArgsG $ArgsR $RArgsG))) -; ; RestSpec = Ci^r ( Spec - Gen ) - -; ; SpecG = Ci^g - +; ; -; RArgs = relevant argument terms (not []) +; ; -; inv_replace(RArgsG0,SS1,RArgsG,SS1). ; changed (Irene) +; ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: general_terms/5 +; ; -; * +; ; -; * syntax: general_terms(+T1,+T2,-TG,+Subst1,+Subst2) +; ; -; * +; ; -; * args: T1, T2 .. relevant terms in CL1, CL2 (cf. above) +; ; -; * Subst1, Subst2 .. substitutions (cf. above) +; ; -; * TG .. relevant terms in Clgg +; ; -; * +; ; -; * description: determines the relevant terms in Clgg that +; ; -; * correspond to the relevant terms in CL1 and CL2 +; ; -; * here, inv_replace is used!! +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; ; -; * general_terms (like a shotgun wedding between lgg for terms and inverse replacement...) +; (= (general-terms Nil Nil Nil $_ $_) (set-det)) +; + (= (general-terms @@ -2260,6 +2407,8 @@ (inv-replace $T1 $S1 $T $_)) (set-det) (general-terms $R1 Nil $R3 $S1 $_))) +; + (= (general-terms Nil @@ -2271,6 +2420,8 @@ (inv-replace $T2 $S2 $T $_)) (set-det) (general-terms Nil $R2 $R3 $_ $S2))) +; + (= (general-terms @@ -2279,6 +2430,8 @@ ( (gen-term $T1 $L2 $L2Rest $T $S1 $S2) (set-det) (general-terms $R1 $L2Rest $R3 $S1 $S2))) +; + (= @@ -2288,6 +2441,8 @@ (effaceall $T2 $L2 $L2new) (functor $T2 $F $N) (lgg-terms $T1 $T2 $T $_ $_ $S1 $S2))) +; + (= (gen-term $T1 $L2 $L2new $X $S1 $S2) @@ -2297,6 +2452,8 @@ (genterm-test (/ $Y $T2) $S2) (== $X $Y))) +; + (= (gen-term $T1 $L2 $L2 $T $S1 $_) @@ -2304,74 +2461,82 @@ (genterm-test (/ $T $T1) $S1) True (inv-replace $T1 $S1 $T $_))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: exists_intersect/3 +; ; -; * +; ; -; * syntax: exists_intersect(+L1,+L2,-L) +; ; -; * +; ; -; * args: L1,L2,L: lists +; ; -; * +; ; -; * description: if nonempty intersection exists, succeeds and returns +; ; -; * intersection, fails else +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; (= (exists-intersect $X $Y $Z) ( (exi $X $Y $Z $_) (set-det))) +; + (= (exi Nil $_ Nil $Flag) (== $Flag yes)) +; + (= (exi Nil $_ Nil $_) ( (set-det) (fail))) +; + (= (exi (Cons $X $R) $Y @@ -2379,70 +2544,78 @@ ( (memberchk $X $Y) (set-det) (exi $R $Y $Z yes))) +; + (= (exi (Cons $_ $R) $Y $Z $Flag) (exi $R $Y $Z $Flag)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: clean_subst/3 +; ; -; * +; ; -; * syntax: clean_subst(+CL,+Subst,-Subst) +; ; -; * +; ; -; * args: CL: clause in list notation, Subst: a substitution [X/Term,...] +; ; -; * +; ; -; * description: removes all X/T from Subst such that X does not occur in CL +; ; -; * +; ; -; * example: +; ; -; * +; ; -; * peculiarities: +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; ************************************************************************ +; (= (clean_subst $_ () ()) True) +; + (= (clean-subst $CL (Cons (/ $X $T) $R) $R2) ( (clean-subst $CL $R $R1) (det-if-then-else (contains-var $X $CL) (= $R2 (Cons (/ $X $T) $R1)) (= $R2 $R1)))) +; + diff --git a/miles/xm.metta b/miles/xm.metta index b7dd1af..7b96bcd 100644 --- a/miles/xm.metta +++ b/miles/xm.metta @@ -1,126 +1,146 @@ ; -; FILE xm.pl +; !(ensure-loaded dmiles) +; + ; -; IMPORTS +; !(use-module-if-exists (library proxt)) +; + !(use-module-if-exists (library ctypes)) +; + !(use-module-if-exists (library strings)) +; + !(use-module-if-exists (library basics)) +; + !(consult miles) +; + ; -; ;;:- use_module(show_utils). +; !(consult xmiles-functions) +; + ; -; *********************************************************************** +; ; -; * +; ; -; * file: xm.pl +; ; -; * +; ; -; * author: T. Volz +; ; -; * +; ; -; * changed: +; ; -; * +; ; -; * description: X interface for MILES. Load this directly into MeTTa +; ; -; * (NOT qui!!), and call `xm.' to create the interface and start +; ; -; * the event loop. Use the `Quit XMILES'-button to suspend the +; ; -; * event loop, if you want to access the MeTTa-prompt directly. +; ; -; * Calling `xm' again restarts the event loop. +; ; -; * +; ; -; * see also: +; ; -; * +; ; -; *********************************************************************** +; (= (runtime-entry start) (xm)) +; + !(dynamic (, (/ listItems 1) (/ my-exit-loop 1) (/ toplevel 1))) +; + (= (my_exit_loop no) True) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: xm main predicate +; ; -; * +; ; -; * syntax: - +; ; -; * +; ; -; * args: - +; ; -; * +; ; -; * description: Creates the whole xmiles interface. +; ; -; * +; ; -; ************************************************************************ +; @@ -140,7 +160,7 @@ (, (xtToolkitInitialize) (xtInitialize X-MILES xMILES $XMiles) - (add-atom &self + (add-symbol &self (toplevel $XMiles)) (clear-kb) (xmCreateRowColumn $XMiles xMilesRow @@ -168,6 +188,8 @@ (createEditorArea $XMilesColumn2) (createKnowledgeBaseArea $XMilesColumn2) (xtRealizeWidget $XMiles))) (my-main-loop $XMiles))) +; + (= @@ -175,57 +197,59 @@ (det-if-then-else (my-exit-loop yes) (, - (remove-atom &self + (remove-symbol &self (my_exit_loop yes)) - (add-atom &self + (add-symbol &self (my_exit_loop no))) (, (xtNextEvent $Event) (xtDispatchEvent $Event) (my-main-loop $Shell)))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createKnowledgeBaseArea/1 +; ; -; * +; ; -; * syntax: createKnowledgeBaseArea(+Parent) +; ; -; * +; ; -; * args: Parent... specifies the parentwidget of KbRowColumn +; ; -; * +; ; -; * description: Creates the knowledge base area of the X user interface +; ; -; * This area consists of two scrolled windows. One window +; ; -; * is used to browse the rules of the knowledge base, the +; ; -; * other window browses the examples. Used by xm/0. +; ; -; * +; ; -; ************************************************************************ +; @@ -270,49 +294,51 @@ (createRuleArea $KnowledgeBaseRow) (createExampleArea $KnowledgeBaseRow) (createKbButtons $KnowledgeBaseColumn))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createRuleArea/1 +; ; -; * +; ; -; * syntax: createRuleArea(+Parent) +; ; -; * +; ; -; * args: Parent... specifies the parent widget of RuleFrame +; ; -; * +; ; -; * description: Creates the rule browser of the knowledge base. The rule +; ; -; * browser consists of a label, a scrolled rule list and +; ; -; * a refresh button, which looks up for changes of the +; ; -; * knowledge base. Used by createKbRowColumn/1 +; ; -; * +; ; -; ************************************************************************ +; @@ -347,51 +373,53 @@ (createExamineRulesPopup $Examine) (createKnowledgeList $RuleColumn rules) (createKbSubButtons $RuleColumn rules))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createExampleArea/1 +; ; -; * +; ; -; * syntax: createExampleArea(+Parent) +; ; -; * +; ; -; * args: +Parent Widget +; ; -; * +; ; -; * description: Creates the example browser of the knowledge base. The +; ; -; * example browser consists of a label, a scrolled rule list +; ; -; * and a refresh button, which looks up for changes of the +; ; -; * knowledge base. +; ; -; * +; ; -; ************************************************************************ +; @@ -417,46 +445,48 @@ (xtManageChild $ExampleLabel) (createKnowledgeList $ExampleRowColumn examples) (createKbSubButtons $ExampleRowColumn examples))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createKnowledgeList/3 +; ; -; * +; ; -; * syntax: createKnowledgeList(+Parent,-KnowledgeRC,+KindOfKnowledge) +; ; -; * +; ; -; * args: +Parent Widget +; ; -; * -KnowledgeRC Widget +; ; -; * +KindOfKnowledge 'rules' or 'examples' +; ; -; * +; ; -; * description: Creates a List either containing all rules or all examples +; ; -; * +; ; -; ************************************************************************ +; @@ -486,46 +516,48 @@ (:: (xmNbackground $B))) (addKnowledgeListItems $KindOfKnowledge) (xtManageChild $KnowledgeRC))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: addKnowledgeListItems/1 +; ; -; * +; ; -; * syntax: addKnowledgeListItems(+KindOfKnowledge) +; ; -; * +; ; -; * args: +KindOfKnowledge rules or examples +; ; -; * +; ; -; * description: Adds a label for each Rule or Example existing in the kb +; ; -; * to the parent widget stored in +; ; -; * KindOfKnowledge, knowledgeList(X) +; ; -; * +; ; -; ************************************************************************ +; @@ -535,49 +567,55 @@ (get-clause $Id $H $B $S $O) (addRuleItem $Id $H $B $S $O) (fail))) +; + (= (addKnowledgeListItems examples) ( (getNextId $Id) (get-example $Id $F $C) (addExampleItem $Id $F $C) (fail))) +; + (= (addKnowledgeListItems $_) (set-det)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: getNextId/1 +; ; -; * +; ; -; * syntax: getNextId(+Id) +; ; -; * +; ; -; * args: +Id Integer <= id_count(X) +; ; -; * +; ; -; * description: Counts from zero to id_count +; ; -; * +; ; -; ************************************************************************ +; @@ -606,43 +644,45 @@ (erase $Ref2) (set-det) (fail)) otherwise))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: deleteKnowledgeListItems/1 +; ; -; * +; ; -; * syntax: deleteKnowledgeListItems(+KindOfKnowledge) +; ; -; * +; ; -; * args: +KindOfKnowledge rules or examples +; ; -; * +; ; -; * description: Deletes all Labels representing rules or examples +; ; -; * of the knowledgelist. Leaves the knowledgebase unchanged +; ; -; * +; ; -; ************************************************************************ +; @@ -654,6 +694,8 @@ (erase $Ref) (set-det) (deleteKnowledgeListItems rules))) +; + (= (deleteKnowledgeListItems examples) ( (recorded current @@ -662,61 +704,65 @@ (erase $Ref) (set-det) (deleteKnowledgeListItems examples))) +; + (= (deleteKnowledgeListItems $_) (set-det)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: addRuleItem/4 +; ; -; * +; ; -; * syntax: addRuleItem(+I,+H,+B,+O) +; ; -; * +; ; -; * args: +I Integer, spezifies the ID of the rule +; ; -; * +H Head of the rule +; ; -; * +B Body of the rule +; ; -; * +O Label +; ; -; * +; ; -; * description: Creates a label to show the rule spezified by the +; ; -; * arguments. The Label widget is recorded: +; ; -; * recordz(current,clause(I,Label,notselected),_Ref) +; ; -; * If the Label allready exists, then only the text changes. +; ; -; * +; ; -; ************************************************************************ +; @@ -779,57 +825,61 @@ (xtAddEventHandler $Label (:: buttonPressMask) False firstClauseClick rules))) (set-det))) +; + (= (addRuleItem $_ $_ $_ $_ $_) (set-det)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: addExampleItem/3 +; ; -; * +; ; -; * syntax: addExampleItem(+I,+F,+C) +; ; -; * +; ; -; * args: +I Integer, spezifies the ID of the example +; ; -; * +F Example predicate +; ; -; * +C + or -, classification of the example +; ; -; * +; ; -; * description: Creates a label to show the example spezified by the +; ; -; * arguments. The Label widget is recorded: +; ; -; * recordz(current,example(I,Label,notselected),_Ref) +; ; -; * +; ; -; ************************************************************************ +; @@ -898,49 +948,51 @@ (recordz current (example $I $Label notselected) $Ref))) (set-det))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: refreshKnowledgeList/3 CallbackProcedure +; ; -; * +; ; -; * syntax: refreshKnowledgeList(_Widget,+KindOfKnowledge,_Calldata) +; ; -; * +; ; -; * args: _Widget calling Widget +; ; -; * +KindOfKnowledge rules or examples +; ; -; * _Calldata Event +; ; -; * +; ; -; * description: Ensures that the knowledge displayed is the same than +; ; -; * the knowledge in the knowledge base. +; ; -; * +; ; -; ************************************************************************ +; @@ -949,52 +1001,54 @@ ( (deleteKnowledgeListItems $KindOfKnowledge) (addKnowledgeListItems $KindOfKnowledge) (updateEvaluationLabel))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: selectClause/3 CallbackProcedure +; ; -; * +; ; -; * syntax: selectClause(+Widget,+KindOfKnowledge,_Calldata) +; ; -; * +; ; -; * args: +Widget calling Widget +; ; -; * +KindOfKnowledge rules or examples +; ; -; * _Calldata Event +; ; -; * +; ; -; * description: Toggles selection state of the knowledge item specified +; ; -; * by Widget. Visual effect is the exchange of foreground +; ; -; * and background color. +; ; -; * +; ; -; ************************************************************************ +; @@ -1020,6 +1074,8 @@ (det-if-then-else (= $GetState True) (copyId $I 1) otherwise))) +; + (= (selectClause $Widget rules $CallData) @@ -1043,6 +1099,8 @@ (det-if-then-else (= $GetState True) (copyId $I 1) otherwise))) +; + (= (selectClause $Widget examples $CallData) @@ -1066,6 +1124,8 @@ (det-if-then-else (= $GetState True) (copyId $I 1) otherwise))) +; + (= (selectClause $Widget examples $CallData) @@ -1089,55 +1149,57 @@ (det-if-then-else (= $GetState True) (copyId $I 1) otherwise))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: firstClauseClick/3 CallbackProcedure +; ; -; * +; ; -; * syntax: firstClauseClick(+Widget,_ClientData,_Calldata) +; ; -; * +; ; -; * args: +Widget calling Widget +; ; -; * _ClientData +; ; -; * _Calldata Event +; ; -; * +; ; -; * description: If another click occures in the next two seconds, the +; ; -; * knowledgebase item specified by Widget is copied into +; ; -; * the editor. +; ; -; * +; ; -; * +; ; -; ************************************************************************ +; @@ -1145,49 +1207,51 @@ (firstClauseClick $Widget $ClientData $CallData) ( (xtAddEventHandler $Widget (:: buttonPressMask) False copyClause $_) (xtAddTimeOut 1000 noDoubleClick $Widget $ID))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: copyClause/3 CallbackProcedure +; ; -; * +; ; -; * syntax: copyClause(+Widget,_ClientData,_Calldata) +; ; -; * +; ; -; * args: +Widget calling Widget +; ; -; * _ClientData rules or examples +; ; -; * _Calldata Event +; ; -; * +; ; -; * description: Copies a knowledge base item spezified by Widget to the +; ; -; * editor text. +; ; -; * +; ; -; ************************************************************************ +; @@ -1245,49 +1309,51 @@ (xmStringCreate $LblCP $DCharset $LblS) (xtSetValues $Label (:: (xmNlabelString $LblS)))))))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: noDoubleClick/2 TimeOutProcedure +; ; -; * +; ; -; * syntax: noDoubleClick(+Widget,_IntervallID) +; ; -; * +; ; -; * args: +Widget knowledge label +; ; -; * _IntervallId calling Intervall +; ; -; * +; ; -; * description: Removes event handler for copying a knowledge base item +; ; -; * into the editor. This predicate is avoked if no second +; ; -; * button press has occured within two seconds. +; ; -; * +; ; -; ************************************************************************ +; @@ -1295,52 +1361,54 @@ (noDoubleClick $Widget $IntervallId) (xtRemoveEventHandler $Widget (:: buttonPressMask) False copyClause $_)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: selectAll/3 Callback procedure +; ; -; * +; ; -; * syntax: selectAll(_Widget,+KindOfKnowledge,_CallData) +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * KindOfKnowledge rules or examples +; ; -; * _CallData event +; ; -; * +; ; -; * description: Selects all rules or examples of the knowledge base. The +; ; -; * rules or examples have to satisfy the current display +; ; -; * restricion. +; ; -; * +; ; -; ************************************************************************ +; @@ -1361,6 +1429,8 @@ (recordz current (clause $I $Widget selected) $Ref) (selectAll $Widget rules $CallData))) +; + (= (selectAll $Widget examples $CallData) @@ -1379,55 +1449,59 @@ (recordz current (example $I $Widget selected) $Ref) (selectAll $Widget examples $CallData))) +; + (= (selectAll $_ $_ $_) True) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: unselectAll/3 Callback procedure +; ; -; * +; ; -; * syntax: unselectAll(_Widget,+KindOfKnowledge,_CallData) +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * KindOfKnowledge rules or examples +; ; -; * _CallData event +; ; -; * +; ; -; * description: Unselects all rules or examples of the knowledge base. The +; ; -; * rules or examples have to satisfy the current display +; ; -; * restricion. +; ; -; * +; ; -; ************************************************************************ +; @@ -1448,6 +1522,8 @@ (recordz current (clause $I $Widget notselected) $Ref) (unselectAll $Widget rules $CallData))) +; + (= (unselectAll $Widget examples $CallData) @@ -1466,49 +1542,53 @@ (recordz current (example $I $Widget notselected) $Ref) (unselectAll $Widget examples $CallData))) +; + (= (unselectAll $_ $_ $_) True) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: deleteKnowledge/3 Callback procedure +; ; -; * +; ; -; * syntax: deleteKnowledge(_Widget,+KindOfKnowledge,_CallData) +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * KindOfKnowledge rules or examples +; ; -; * _CallData event +; ; -; * +; ; -; * description: Deletes all selected rules or examples. +; ; -; * +; ; -; ************************************************************************ +; @@ -1537,6 +1617,8 @@ (writeMessage $I) (writelnMessage ).) (deleteKnowledge $Widget rules $CallData))) +; + (= (deleteKnowledge $Widget examples $CallData) @@ -1563,6 +1645,8 @@ (writeMessage $I) (writelnMessage ).) (deleteKnowledge $Widget examples $CallData))) +; + (= (deleteKnowledge $_ $KindOfKnowledge $_) @@ -1570,49 +1654,51 @@ (writeMessage $KindOfKnowledge) (writelnMessage ' deleted.') (updateEvaluationLabel))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: deleteAllKnowledge/3 Callback procedure +; ; -; * +; ; -; * syntax: deleteKnowledge(_Widget,+KindOfKnowledge,_CallData) +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * KindOfKnowledge rules or examples +; ; -; * _CallData event +; ; -; * +; ; -; * description: Deletes all rules or examples within the current display +; ; -; * restriction. +; ; -; * +; ; -; ************************************************************************ +; @@ -1641,6 +1727,8 @@ (writeMessage $I) (writelnMessage ).) (deleteAllKnowledge $Widget rules $CallData))) +; + (= (deleteAllKnowledge $Widget examples $CallData) @@ -1667,52 +1755,56 @@ (writeMessage $I) (writelnMessage ).) (deleteAllKnowledge $Widget examples $CallData))) +; + (= (deleteAllKnowledge $_ $KindOfKnowledge $_) ( (writeMessage '% all ') (writeMessage $KindOfKnowledge) (writelnMessage ' deleted.'))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: saveKnowledgeBegin/3 Callback procedure +; ; -; * +; ; -; * syntax: saveKnowledgeBegin(_Widget,+FileSelectionDialog,_CallData) +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * +FileSelectionDialog FileSelectionDialogWidget +; ; -; * _CallData event +; ; -; * +; ; -; * description: Pops up a fileselection dialog. +; ; -; * +; ; -; ************************************************************************ +; @@ -1721,47 +1813,49 @@ ( (xtManageChild $FileSelectionDialog) (xtAddCallback $FileSelectionDialog xmNokCallback saveKnowledgeEnd $FileSelectionDialog) (xtAddCallback $FileSelectionDialog xmNcancelCallback cancelSaveFileSelect $FileSelectionDialog))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: saveKnowledgeEnd/3 Callback procedure +; ; -; * +; ; -; * syntax: saveKnowledgeEnd(_Widget,+FileSelectionDialog,+CallData) +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * +FileSelectionDialog FileSelectionDialogWidget +; ; -; * +CallData event +; ; -; * +; ; -; * description: Saves the selected file. +; ; -; * +; ; -; ************************************************************************ +; @@ -1792,46 +1886,48 @@ (writeMessage '% file "') (writeMessage $FileName) (writelnMessage " saved.))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: loadKnowledgeBegin/3 Callback procedure +; ; -; * +; ; -; * syntax: loadKnowledgeBegin(_Widget,+FileSelectionDialog,_CallData) +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * +FileSelectionDialog FileSelectionDialogWidget +; ; -; * _CallData event +; ; -; * +; ; -; * description: Pops up a fileselection dialog. +; ; -; * +; ; -; ************************************************************************ +; @@ -1840,46 +1936,48 @@ ( (xtManageChild $FileSelectionDialog) (xtAddCallback $FileSelectionDialog xmNokCallback loadKnowledgeEnd $FileSelectionDialog) (xtAddCallback $FileSelectionDialog xmNcancelCallback cancelLoadFileSelect $FileSelectionDialog))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: loadKnowledgeEnd/3 Callback procedure +; ; -; * +; ; -; * syntax: loadKnowledgeEnd(_Widget,+FileSelectionDialog,+CallData) +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * +FileSelectionDialog FileSelectionDialogWidget +; ; -; * _CallData event +; ; -; * +; ; -; * description: Loads the selected file. +; ; -; * +; ; -; ************************************************************************ +; @@ -1913,46 +2011,48 @@ (refreshKnowledgeList $Widget rules $Calldata) (refreshKnowledgeList $Widget examples $Calldata) (updateEvaluationLabel))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: clearAllKnowledge/3 callback procedure +; ; -; * +; ; -; * syntax: clearAllKnowledge(_Widget,_ClientData,_CallData) +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * _ClientData no client data +; ; -; * _CallData event +; ; -; * +; ; -; * description: deletes all rules and examples +; ; -; * +; ; -; ************************************************************************ +; @@ -1965,48 +2065,50 @@ (writelnMessage '% knowledgebase cleared.') (clear-kb) (updateEvaluationLabel))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: cancelLoadFileSelect/3 callback procedure +; ; -; * +; ; -; * syntax: cancelLoadFileSelect(_Widget,_ClientData,_CallData) +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * _ClientData no client data +; ; -; * _CallData event +; ; -; * +; ; -; * description: Pops down the file selection dialog without loading any +; ; -; * file. +; ; -; * +; ; -; ************************************************************************ +; @@ -2015,49 +2117,51 @@ ( (xtRemoveCallback $FileSelectionDialog xmNokCallback loadKnowledgeEnd $FileSelectionDialog) (xtRemoveCallback $FileSelectionDialog xmNcancelCallback cancelLoadFileSelect $FileSelectionDialog) (xtUnmanageChild $FileSelectionDialog))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: cancelSaveFileSelect/3 callback procedure +; ; -; * +; ; -; * syntax: cancelSaveFileSelect(_Widget,_ClientData,_CallData) +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * _ClientData no client data +; ; -; * _CallData event +; ; -; * +; ; -; * description: Pops down the file selection dialog without saving any +; ; -; * file. +; ; -; * +; ; -; ************************************************************************ +; @@ -2066,46 +2170,48 @@ ( (xtRemoveCallback $FileSelectionDialog xmNokCallback saveKnowledgeEnd $FileSelectionDialog) (xtRemoveCallback $FileSelectionDialog xmNcancelCallback cancelSaveFileSelect $FileSelectionDialog) (xtUnmanageChild $FileSelectionDialog))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createKbButtons/1 +; ; -; * +; ; -; * syntax: createKbButtons(+Parent) +; ; -; * +; ; -; * args: Parent Widget +; ; -; * +; ; -; * description: Creates the push buttons 'Save', 'Load', 'Clear'. These +; ; -; * buttons are effecting the whole knowledge base (rules and +; ; -; * examples). +; ; -; * +; ; -; ************************************************************************ +; @@ -2129,52 +2235,54 @@ (xmCreatePushButton $ButtonRowColumn Clear Nil $Clear) (xtManageChild $Clear) (createYesNoPopup $Clear $YesNoPopup clearAllKnowledge $_))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createKbSubButtons/2 +; ; -; * +; ; -; * syntax: createKbSubButtons(+Parent,+KindOfKnowledge) +; ; -; * +; ; -; * args: +Parent Widget +; ; -; * +KindOfKnowledge examples or rules +; ; -; * +; ; -; * description: Creates the push buttons 'SelectAll', 'Unselect All', +; ; -; * 'Refresh', 'Delete', 'Delete All' and 'Label' or '+', '-' +; ; -; * '?'. These buttons are efecting the KindOfKnowledge +; ; -; * (rules and examples). +; ; -; * +; ; -; ************************************************************************ +; @@ -2213,43 +2321,45 @@ (, (createViewExamplesPopup $View) (createClassChangeButtons $ButtonRowColumn)))))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createLabelChangeButton/1 +; ; -; * +; ; -; * syntax: createLabelChangeButton(+Parent) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: Creates a push button and a editing Dialog for changing +; ; -; * the label of the selected rules. +; ; -; * +; ; -; ************************************************************************ +; @@ -2299,43 +2409,45 @@ (xmCreatePushButton $ButtonRow Cancel Nil $Cancel) (xtManageChild $Cancel) (xtAddCallback $Cancel xmNactivateCallback cancelLabelChange $LabelChangeDialog))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createSelectRulesPopup/1 +; ; -; * +; ; -; * syntax: createSelectRulesPopup(+Parent) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: Creates a push button and a editing Dialog for changing +; ; -; * the label of the selected rules. +; ; -; * +; ; -; ************************************************************************ +; @@ -2386,43 +2498,45 @@ (xmCreatePushButton $ButtonRow Cancel Nil $Cancel) (xtManageChild $Cancel) (xtAddCallback $Cancel xmNactivateCallback yesNoPopdown $SelectRulesDialog))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createExamineRulesPopup/1 +; ; -; * +; ; -; * syntax: createExamineRulesPopup(+Parent) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: Creates a push button and a Dialog for examining +; ; -; * the selected rules. +; ; -; * +; ; -; ************************************************************************ +; @@ -2490,37 +2604,39 @@ (showExaminedRule $_ $_ $_) (xmCreatePushButton $ButtonRow Cancel Nil $Cancel) (xtManageChild $Cancel) - (xtAddCallback $Cancel xmNactivateCallback cancelExamineRules $_))) + (xtAddCallback $Cancel xmNactivateCallback cancelExamineRules $_))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: showExaminedRule/1 +; ; -; * +; ; -; * syntax: showExaminedRule(_Widget,_RuleNoText,_CallData) +; ; -; * +; ; -; * description: Displays Info on the (first) selected rule +; ; -; * +; ; -; ************************************************************************ +; @@ -2600,37 +2716,36 @@ (recordz rules (examineText $Label) $_) (set-det))) -; ;;;;Irene - +; ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createViewRulesPopup/1 +; ; -; * +; ; -; * syntax: createViewRulesPopup(+Parent) +; ; -; * +; ; -; * description: creates Dialog for Viewing Rules +; ; -; * +; ; -; ************************************************************************ +; @@ -2904,39 +3019,41 @@ (xmCreatePushButton $ButtonRow Cancel Nil $Cancel) (xtManageChild $Cancel) (xtAddCallback $Cancel xmNactivateCallback cancelViewRules $_))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createViewExamplesPopup/1 +; ; -; * +; ; -; * syntax: createViewExamplesPopup(+parent) +; ; -; * +; ; -; * description: Creates creates facilities for selecting the viewed +; ; -; * examples. +; ; -; * +; ; -; ************************************************************************ +; @@ -3129,49 +3246,51 @@ (xmCreatePushButton $ButtonRow Cancel Nil $Cancel) (xtManageChild $Cancel) (xtAddCallback $Cancel xmNactivateCallback cancelViewExamples $_))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: changeSelectedLabels/1 callback procedure +; ; -; * +; ; -; * syntax: changeSelectedLabels(_Widget,+[LabelChangeDialog,LabelText],_CallData) +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * +[LabelChangeDialog,LabelText] widgets +; ; -; * _CallData event +; ; -; * +; ; -; * description: Removes the LabelChange Dialog from the display, and +; ; -; * changes the Label of all selected rules. +; ; -; * +; ; -; ************************************************************************ +; @@ -3182,40 +3301,42 @@ (xmTextGetString $LabelText $LabelCP) (proxtCharPtrToString $LabelCP $LabelAS) (setSelectedLabels $LabelAS))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: setSelectedLabels/1 +; ; -; * +; ; -; * syntax: setSelectedLabels(+Label) +; ; -; * +; ; -; * args: +Label new labelname +; ; -; * +; ; -; * description: Sets the label of all selected rules to Label. +; ; -; * +; ; -; ************************************************************************ +; @@ -3232,86 +3353,92 @@ (clause $Id $Widget selected) $_) (addRuleItem $Id $H $B $CL $Label) (updateEvaluationLabel))) +; + (= (setSelectedLabels $_) (set-det)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: cancelLabelChange/3 callback procedure +; ; -; * +; ; -; * syntax: cancelLabelChange(_Widget,+LabelChangeDialog) +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * +LabelChangeDialog widget +; ; -; * _CallData event +; ; -; * +; ; -; * description: Removes the LabelChangeDialog from the display. +; ; -; * +; ; -; ************************************************************************ +; (= (cancelLabelChange $Widget $LabelChangeDialog $CallData) (xtUnmanageChild $LabelChangeDialog)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createClassChangeButtons/1 +; ; -; * +; ; -; * syntax: createClassChangeButtons(+Parent) +; ; -; * +; ; -; * description: Creates three buttons '+', '-', '?' for changing the +; ; -; * class of the selected examples. +; ; -; * +; ; -; ************************************************************************ +; @@ -3334,49 +3461,51 @@ (xmCreatePushButton $ClassChangeRow ? Nil $Quest) (xtManageChild $Quest) (xtAddCallback $Quest xmNactivateCallback classChangeSelected ?))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: classChangeSelected/3 Callback procedure +; ; -; * +; ; -; * syntax: classChangeSelected(_Widget,+Classification,_CallData) +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * +Classification '+' or '-' or '?' +; ; -; * _CallData event +; ; -; * +; ; -; * description: Sets the classification of the selected examples to +; ; -; * Classification. +; ; -; * +; ; -; ************************************************************************ +; @@ -3393,46 +3522,50 @@ (example $Id $Label selected) $_) (addExampleItem $Id $Fact $Classification) (updateEvaluationLabel))) +; + (= (classChangeSelected $_ $_ $_) (set-det)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createArgumentArea/1 +; ; -; * +; ; -; * syntax: createArgumentArea(+Parent) +; ; -; * +; ; -; * description: Creates the argument area with five fields for arguments, +; ; -; * one toggle button for copying rule ids into argument +; ; -; * fields when selecting or deselecting rules or examples, +; ; -; * and a clear push button. +; ; -; * +; ; -; ************************************************************************ +; @@ -3508,49 +3641,53 @@ (xmCreatePushButton $DepthRow > Nil $Raise) (xtManageChild $Raise) (xtAddCallback $Raise xmNactivateCallback raiseDepth $DText))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createArguments/2 +; ; -; * +; ; -; * syntax: createArguments(+Parent,+Count) +; ; -; * +; ; -; * args: +Parent parent widget +; ; -; * +Count number of argument fields to create +; ; -; * +; ; -; * description: Creates Count text widgets for the arguments. +; ; -; * +; ; -; ************************************************************************ +; (= (createArguments $_ 0) (set-det)) +; + (= (createArguments $Parent $Count) ( (is $C1 @@ -3565,51 +3702,55 @@ (xtManageChild $ArgumentText) (recordz state (argumentWidget $Count $ArgumentText) $_))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: clearArguments/3 callback procedure +; ; -; * +; ; -; * syntax: clearArguments(_Widget,+Count,_CallData) +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * Count Number of arguments to clear (5) +; ; -; * _CallData +; ; -; * +; ; -; * description: Clears Count argument text widgets +; ; -; * +; ; -; ************************************************************************ +; (= (clearArguments $Widget 0 $CallData) True) +; + (= (clearArguments $Widget $Count $CallData) ( (is $C1 @@ -3619,52 +3760,54 @@ (argumentWidget $Count $Text) $_) (proxtStringToCharPtr '' $EmptyChrPtr) (xmTextSetString $Text $EmptyChrPtr))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: lowerDepth/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * +DepthText TextWidget of Depth +; ; -; * _CallData +; ; -; * +; ; -; * description: 1 decrements xmDepth. +; ; -; * +; ; -; * see also: raiseDepth +; ; -; * +; ; -; ************************************************************************ +; @@ -3685,52 +3828,54 @@ (atom-chars $NewDepthStr $NewDepthC) (proxtStringToCharPtr $NewDepthStr $NewDepthCP) (xmTextSetString $DepthText $NewDepthCP))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: lowerID/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * +DepthText TextWidget containing ID +; ; -; * _CallData +; ; -; * +; ; -; * description: 1 decrements ID. +; ; -; * +; ; -; * see also: raiseID +; ; -; * +; ; -; ************************************************************************ +; @@ -3751,46 +3896,48 @@ (atom-chars $NewIDStr $NewIDC) (proxtStringToCharPtr $NewIDStr $NewIDCP) (xmTextSetString $IDText $NewIDCP))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: lowerMin/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * +DepthText TextWidget of Depth +; ; -; * _CallData +; ; -; * +; ; -; * description: 1 decrements MinId of viewed rules or examples. +; ; -; * +; ; -; ************************************************************************ +; @@ -3824,46 +3971,48 @@ (atom-chars $NewMinStr $NewMinC) (proxtStringToCharPtr $NewMinStr $NewMinCP) (xmTextSetString $MinText $NewMinCP))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: lowerMax/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * +DepthText TextWidget of Depth +; ; -; * _CallData +; ; -; * +; ; -; * description: 1 decrements MaxId of viewed rules or examples. +; ; -; * +; ; -; ************************************************************************ +; @@ -3897,46 +4046,48 @@ (atom-chars $NewMaxStr $NewMaxC) (proxtStringToCharPtr $NewMaxStr $NewMaxCP) (xmTextSetString $MaxText $NewMaxCP))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: raiseDepth/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * +DepthText TextWidget of Depth +; ; -; * _CallData +; ; -; * +; ; -; * description: 1 inrements xmDepth. +; ; -; * +; ; -; ************************************************************************ +; @@ -3957,46 +4108,48 @@ (atom-chars $NewDepthStr $NewDepthC) (proxtStringToCharPtr $NewDepthStr $NewDepthCP) (xmTextSetString $DepthText $NewDepthCP))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: raiseID/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * +DepthText TextWidget containing ID +; ; -; * _CallData +; ; -; * +; ; -; * description: 1 increments ID. +; ; -; * +; ; -; ************************************************************************ +; @@ -4017,45 +4170,47 @@ (atom-chars $NewIDStr $NewIDC) (proxtStringToCharPtr $NewIDStr $NewIDCP) (xmTextSetString $IDText $NewIDCP))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: raiseMin/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * +DepthText TextWidget of Depth +; ; -; * _CallData +; ; -; * +; ; -; * description: 1 increments MinId of viewed rules or examples. +; ; -; * +; ; -; ************************************************************************ +; @@ -4089,47 +4244,49 @@ (atom-chars $NewMinStr $NewMinC) (proxtStringToCharPtr $NewMinStr $NewMinCP) (xmTextSetString $MinText $NewMinCP))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: raiseMax/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * +DepthText TextWidget of Depth +; ; -; * _CallData +; ; -; * +; ; -; * description: 1 increments MaxId of viewed rules or examples. +; ; -; * +; ; -; ************************************************************************ +; @@ -4163,55 +4320,59 @@ (atom-chars $NewMaxStr $NewMaxC) (proxtStringToCharPtr $NewMaxStr $NewMaxCP) (xmTextSetString $MaxText $NewMaxCP))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: copyId/2 +; ; -; * +; ; -; * syntax: copyId(+Id,+Count) +; ; -; * +; ; -; * args: +Id Id of rule or example to copy +; ; -; * +Count First argument to proove if empty +; ; -; * +; ; -; * +; ; -; * description: Copies the specified rule or example to the textwidget +; ; -; * of the count argument. +; ; -; * +; ; -; ************************************************************************ +; (= (copyId $_ 13) (set-det)) +; + (= (copyId $Id $Count) ( (recorded state @@ -4223,38 +4384,42 @@ (atom-chars $IdStr $IdChars) (proxtStringToCharPtr $IdStr $IdCharPtr) (xmTextSetString $Text $IdCharPtr))) +; + (= (copyId $Id $Count) ( (is $C1 (+ $Count 1)) (copyId $Id $C1))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createCommandArea/1 +; ; -; * +; ; -; * syntax: createCommandArea(+Parent) +; ; -; * +; ; -; * description: Creates the area for direct command input. +; ; -; * +; ; -; ************************************************************************ +; @@ -4320,43 +4485,45 @@ (xtAddCallback $OK xmNactivateCallback doKommando (:: $Ktext $KStatus)) (xtAddCallback $Clear xmNactivateCallback doEmptyKommando $Ktext))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createFunctionArea/1 +; ; -; * +; ; -; * syntax: createFunctionArea(+Parent) +; ; -; * +; ; -; * description: Creates the area for the pulldown menus for calling the +; ; -; * learning functions of miles. +; ; -; * +; ; -; * see also: file: 'xmiles_functions.pl' +; ; -; * +; ; -; ************************************************************************ +; @@ -4390,51 +4557,55 @@ (xtManageChild $FunctionRowColumn) (groups $ListOfGroups) (createFunctionGroups $FunctionRowColumn $ListOfGroups))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createFunctionGroups/2 +; ; -; * +; ; -; * syntax: createFunctionGroups(+Parent,+[Groupname|ListOfGroups]) +; ; -; * +; ; -; * args: +Parent parent widget +; ; -; * +[Groupname|ListOfGroups] list of groupnames +; ; -; * +; ; -; * description: Creates one pull down menu for every group of learning +; ; -; * functions. +; ; -; * +; ; -; ************************************************************************ +; (= (createFunctionGroups $_ ()) True) +; + (= (createFunctionGroups $Parent (Cons $Groupname $ListOfGroups)) @@ -4452,51 +4623,55 @@ (groupdef $Groupname $ListOfButtons) (createFunctionButtons $LearningFunctions $ListOfButtons) (createFunctionGroups $Parent $ListOfGroups))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createFunctionButtons/2 +; ; -; * +; ; -; * syntax: createFunctionButtons(+Parent,+[Button|ListOfButtons]) +; ; -; * +; ; -; * args: +Parent parent widget +; ; -; * +[Button|ListOfButtons] list of buttonnames +; ; -; * +; ; -; * description: Creates one pushbutton for every button name in the second +; ; -; * argument. +; ; -; * +; ; -; ************************************************************************ +; (= (createFunctionButtons $_ ()) True) +; + (= (createFunctionButtons $Parent (Cons $Button $ListOfButtons)) @@ -4504,49 +4679,51 @@ (xtManageChild $ButtonWidget) (xtAddCallback $ButtonWidget xmNactivateCallback callFunction $Button) (createFunctionButtons $Parent $ListOfButtons))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: callFunction/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * +Buttonname determines the function +; ; -; * _CallData event +; ; -; * +; ; -; * description: calls the function defined for the specified button +; ; -; * in the file xmiles_functions.pl +; ; -; * +; ; -; ************************************************************************ +; @@ -4589,58 +4766,62 @@ (det-if-then otherwise (writelnMessage '% Error occured, function not executed!'))) (updateEvaluationLabel))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: replaceXmVars/3 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +[Pat|InOutPattern] List of argument patterns +; ; -; * +InChecks List of checking functions +; ; -; * -Args arguments the learning function is +; ; -; * to be called with +; ; -; * +; ; -; * description: replaces the InOutPattern through constant values for +; ; -; * input arguments and unbound variables for output arguments +; ; -; * +; ; -; ************************************************************************ +; (= (replaceXmVars Nil $_ Nil Nil) ( (set-det) (writelnMessage ).))) +; + (= (replaceXmVars (Cons $Pat $InOutPattern) $InChecks $Args $Fails) @@ -4881,54 +5062,58 @@ (det-if-then otherwise (= $Args (Cons $Value $Values))))))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: outVars/3 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +[Arg1|Args] arguments returned by a learnin f. +; ; -; * +[Pat|InOutPattern] list of InOutPatterns +; ; -; * +XOuts list of output functions +; ; -; * +; ; -; * description: Calls the spezified output functions with the values +; ; -; * returned by a learning function. +; ; -; * +; ; -; ************************************************************************ +; (= (outVars $_ $_ ()) True) +; + (= (outVars (Cons $Arg1 $Args) @@ -4949,99 +5134,105 @@ (= $XOuts $XOs))) (set-det) (outVars $Args $InOutPattern $XOs))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: refresh/1 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +[KindOfKnowledge|R] +; ; -; * +; ; -; * description: Refreshes the visual part of the knowledge base of the +; ; -; * specified kinds of knowledge. +; ; -; * +; ; -; ************************************************************************ +; (= (refresh ()) True) +; + (= (refresh (Cons $KindOfKnowledge $R)) ( (refreshKnowledgeList $_ $KindOfKnowledge $_) (refresh $R))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createYesNoPopup/4 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +Parent parent widget, which is a push button +; ; -; * -YesNoPopup created widget, popupMenu +; ; -; * +YesPred callback procedure for Yes button +; ; -; * +YesArg argument for callback procedure +; ; -; * +; ; -; * description: Creates a popupMenu which is poped up, whenever the +; ; -; * parent button is pressed. This popupMenu consists of two +; ; -; * push buttons 'Yes' and 'No'. +; ; -; * +; ; -; ************************************************************************ +; @@ -5061,46 +5252,48 @@ (xtAddEventHandler $YesNoPopup (:: buttonReleaseMask) False yesNoPopdown $YesNoPopup) (xtManageChildren (:: $Yes $No)))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: popupDialog/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +Widget calling widget +; ; -; * +PopupShell widget, to manage +; ; -; * _CallData event +; ; -; * +; ; -; * description: Manages the specified widget beneath the calling widget. +; ; -; * +; ; -; ************************************************************************ +; @@ -5114,46 +5307,48 @@ (xmNx $X) (xmNy $Y))) (xtManageChild $PopupShell))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: popupViewRules/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +Widget calling widget +; ; -; * _ClientData client data +; ; -; * _CallData event +; ; -; * +; ; -; * description: Manages the specified widget beneath the calling widget +; ; -; * +; ; -; ************************************************************************ +; @@ -5173,48 +5368,50 @@ (fillViewedLabels) (fillExistingClauseHeads) (fillViewedClauseHeads))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: popupExamineRules/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +Widget calling widget +; ; -; * _ClientData client data +; ; -; * _CallData event +; ; -; * +; ; -; * description: Manages the specified widget beneath the calling widget. +; ; -; * +; ; -; ************************************************************************ +; @@ -5231,47 +5428,49 @@ (xmNy $Y))) (showExaminedRule $_ $_ $_) (xtManageChild $ERDialog))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: popupViewExamples/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +Widget calling widget +; ; -; * _ClientData client data +; ; -; * _CallData event +; ; -; * +; ; -; * description: Manages the specified widget beneath the calling widget. +; ; -; * +; ; -; ************************************************************************ +; @@ -5289,40 +5488,42 @@ (xtManageChild $VRDialog) (fillExistingExampleCHs) (fillViewedExampleCHs))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: fillExistingLabels/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: - +; ; -; * +; ; -; * description: Finds all existing Labels. +; ; -; * +; ; -; ************************************************************************ +; @@ -5332,40 +5533,42 @@ (view exLabRC $ExLabRC) $_) (listLabels $LabelList) (createLabelWidgets $ExLabRC $LabelList))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: fillViewedLabels/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: - +; ; -; * +; ; -; * description: Finds all viewed Labels. +; ; -; * +; ; -; ************************************************************************ +; @@ -5376,40 +5579,42 @@ (recorded rules (view labels $LabelList) $_) (createLabelWidgets $ViewLabRC $LabelList))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: fillExistingClauseHeads/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: - +; ; -; * +; ; -; * description: +; ; -; * +; ; -; ************************************************************************ +; @@ -5419,40 +5624,42 @@ (view exCHRC $ExCHRC) $_) (listClauseHeads $LabelList) (createLabelWidgets $ExCHRC $LabelList))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: fillViewedClauseHeads/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: - +; ; -; * +; ; -; * description: Finds all existing Labels +; ; -; * +; ; -; ************************************************************************ +; @@ -5463,40 +5670,42 @@ (recorded rules (view clause-heads $CHList) $_) (createLabelWidgets $ViewCHRC $CHList))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: fillExistingExampleCHs/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: - +; ; -; * +; ; -; * description: Finds all existing Labels. +; ; -; * +; ; -; ************************************************************************ +; @@ -5506,40 +5715,42 @@ (view exCHRC $ExCHRC) $_) (listExampleCHs $LabelList) (createLabelWidgets $ExCHRC $LabelList))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: fillViewedExampleCs/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: - +; ; -; * +; ; -; * description: Finds all existing Clause Heads of examples. +; ; -; * +; ; -; ************************************************************************ +; @@ -5550,43 +5761,45 @@ (recorded examples (view clause-heads $CHList) $_) (createLabelWidgets $ViewCHRC $CHList))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createLabelWidgets/2 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +Parent widget +; ; -; * +NameList atomList +; ; -; * +; ; -; * description: creates a label for each name in NameList. +; ; -; * +; ; -; ************************************************************************ +; @@ -5608,37 +5821,41 @@ (:: buttonReleaseMask) False selectLabel $_) (set-det) (createLabelWidgets $Parent $NameList))) +; + (= (createLabelWidgets $_ Nil) (set-det)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: destroyLabelWidgets/1 +; ; -; * +; ; -; * syntax: destroyLabelWidgets(+Parent) +; ; -; * +; ; -; * description: destroys each sublabel of Parent. +; ; -; * +; ; -; ************************************************************************ +; @@ -5651,6 +5868,8 @@ (erase $Ref) (xtDestroyWidget $L) (destroyLabelWidgets $_))) +; + (= (destroyLabelWidgets $Parent) ( (recorded labels @@ -5659,43 +5878,47 @@ (erase $Ref) (xtDestroyWidget $L) (destroyLabelWidgets $Parent))) +; + (= (destroyLabelWidgets $_) (set-det)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: listLabel/1 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: LabelList atomList +; ; -; * +; ; -; * description: lists each label of rules of knowledgebase. +; ; -; * +; ; -; ************************************************************************ +; @@ -5706,6 +5929,8 @@ (listLabels $ViewedLabels $LL1) (append $LabelList $ViewedLabels $LL1) (set-det))) +; + (= (listLabels $LLin $LLout) ( (get-clause $_ $_ $_ $_ $Label) @@ -5714,43 +5939,47 @@ (= $LLin2 (Cons $Label $LLin)) (listLabels $LLin2 $LLout))) +; + (= (listLabels $A $A) (set-det)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: listClauseHeads/1 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: LabelList atomList +; ; -; * +; ; -; * description: lists each clausehead of rules of knowledgebase. +; ; -; * +; ; -; ************************************************************************ +; @@ -5761,6 +5990,8 @@ (listClauseHeads $ViewedCHs $LL1) (append $LabelList $ViewedCHs $LL1) (set-det))) +; + (= (listClauseHeads $LLin $LLout) ( (get-clause $_ $C $_ $_ $_) @@ -5770,43 +6001,47 @@ (= $LLin2 (Cons $CH $LLin)) (listClauseHeads $LLin2 $LLout))) +; + (= (listClauseHeads $A $A) (set-det)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: listExampleCHs/1 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: LabelList atomList +; ; -; * +; ; -; * description: lists each clausehead of examples of knowledgebase. +; ; -; * +; ; -; ************************************************************************ +; @@ -5817,6 +6052,8 @@ (listExampleCHs $ViewedCHs $LL1) (append $LabelList $ViewedCHs $LL1) (set-det))) +; + (= (listExampleCHs $LLin $LLout) ( (get-example $_ $C $_) @@ -5826,49 +6063,53 @@ (= $LLin2 (Cons $CH $LLin)) (listExampleCHs $LLin2 $LLout))) +; + (= (listExampleCHs $A $A) (set-det)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: selectLabel/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +Widget calling widget +; ; -; * _ClientData client data +; ; -; * _CallData event +; ; -; * +; ; -; * description: Toggles the parent of the calling widget. (exist./view.) +; ; -; * +; ; -; ************************************************************************ +; @@ -5937,6 +6178,8 @@ (xtAddEventHandler $NameLabel (:: buttonReleaseMask) False selectLabel $_) (set-det))) +; + @@ -5968,6 +6211,8 @@ (recorded rules (view dialog $X) $_) (xtUnmanageChild $X))) +; + (= (viewRules $P $List) ( (recorded labels @@ -5980,9 +6225,13 @@ (viewRules $P $L2) (= $List (Cons $Name $L2)))) +; + (= (viewRules $_ Nil) (set-det)) +; + @@ -5998,6 +6247,8 @@ (recorded rules (view dialog $X) $_) (xtUnmanageChild $X))) +; + @@ -6007,6 +6258,8 @@ (recorded rules (view dialog $X) $_) (xtUnmanageChild $X))) +; + @@ -6016,6 +6269,8 @@ (recorded rules (examine dialog $X) $_) (xtUnmanageChild $X))) +; + @@ -6039,6 +6294,8 @@ (recorded examples (view dialog $X) $_) (xtUnmanageChild $X))) +; + (= (viewExamples $P $List) ( (recorded labels @@ -6051,9 +6308,13 @@ (viewExamples $P $L2) (= $List (Cons $Name $L2)))) +; + (= (viewExamples $_ Nil) (set-det)) +; + @@ -6069,6 +6330,8 @@ (recorded examples (view dialog $X) $_) (xtUnmanageChild $X))) +; + @@ -6078,46 +6341,48 @@ (recorded examples (view dialog $X) $_) (xtUnmanageChild $X))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: popupFunctions/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +Widget calling widget +; ; -; * +PopupShell widget, to manage +; ; -; * _CallData event +; ; -; * +; ; -; * description: Manages the specified child of the calling widget. +; ; -; * +; ; -; ************************************************************************ +; @@ -6133,92 +6398,96 @@ (xtManageChild $PopupShell) (recordz learnfuncs (popedup $PopupShell) $_))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: yesNoPopdown/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * +JaNeinPopup widget, to unmanage +; ; -; * _CallData event +; ; -; * +; ; -; * description: Unmanages a popup widget. +; ; -; * +; ; -; ************************************************************************ +; (= (yesNoPopdown $Widget $JaNeinPopup $CallData) (xtUnmanageChild $JaNeinPopup)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: functionsPopdown/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * _ClientData client data +; ; -; * _CallData event +; ; -; * +; ; -; * description: Unmanages a popup widget. +; ; -; * +; ; -; ************************************************************************ +; @@ -6228,46 +6497,48 @@ (popedup $PopupShell) $Ref) (erase $Ref) (xtUnmanageChild $PopupShell))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: doKommando/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: _Widget calling procedure +; ; -; * +[KommandoText,KStatus] widgets +; ; -; * _CallData event +; ; -; * +; ; -; * description: Executes the command given by the user. +; ; -; * +; ; -; ************************************************************************ +; @@ -6301,46 +6572,48 @@ (:: (xmNlabelString $NoXmS))) (writelnMessage '% no')))) (doEmptyKommando $_ $KommandoText $_))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: doEmptyKommando/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * +KommandoText widget +; ; -; * _CallData event +; ; -; * +; ; -; * description: Sets the command text to an empty string. +; ; -; * +; ; -; ************************************************************************ +; @@ -6351,46 +6624,48 @@ (refreshKnowledgeList $Widget rules $Calldata) (refreshKnowledgeList $Widget examples $Calldata) (updateEvaluationLabel))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: beenden/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * _ClientData client data +; ; -; * _CallData event +; ; -; * +; ; -; * description: Quits XMILES, returns to MeTTa toplevel. +; ; -; * +; ; -; ************************************************************************ +; @@ -6402,44 +6677,46 @@ (close $F) (write 'X-MILES korrekt beendet!') (nl) - (remove-atom &self + (remove-symbol &self (my_exit_loop no)) - (add-atom &self + (add-symbol &self (my_exit_loop yes)))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createMessageArea/1 +; ; -; * +; ; -; * syntax: createMessageArea(+Parent) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: Creates the area for the messages from XMILES to the user. +; ; -; * +; ; -; ************************************************************************ +; @@ -6491,46 +6768,48 @@ (open xmProtocol.tmp write $F) (recordz messages (file $F) $_))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: saveMessages/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * _ClientData client data +; ; -; * _CallData event +; ; -; * +; ; -; * description: Saves the scrolled text widet holding the XMILES messages +; ; -; * +; ; -; ************************************************************************ +; @@ -6549,46 +6828,48 @@ (recordz messages (file $Fnew) $_) (writelnMessage '% wrote "xmProtocol.sav"'))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: clearMessages/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * _ClientData client data +; ; -; * _CallData event +; ; -; * +; ; -; * description: Clears the scrolled text widet holding the XMILES messages +; ; -; * +; ; -; ************************************************************************ +; @@ -6605,40 +6886,42 @@ (open xmProtocol.tmp write $Fnew) (recordz messages (file $Fnew) $_))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: writeError/1 +; ; -; * +; ; -; * syntax: writeError(+Message) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: Appends the Message to the ErrorText buffer. +; ; -; * +; ; -; ************************************************************************ +; @@ -6663,40 +6946,42 @@ (= $NewEText $MsgStr))) (recordz error (errorText $NewEText) $_))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: writelnError/1 +; ; -; * +; ; -; * syntax: writelnError(+Message) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: Appends the Message to the ErrorText buffer. +; ; -; * +; ; -; ************************************************************************ +; @@ -6727,40 +7012,42 @@ (= $NewEText $MsgStr))) (recordz error (errorText $NewEText) $_))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: flushErrorBuffer/1 +; ; -; * +; ; -; * syntax: flushErrorBuffer(+Message) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: Appends the ErrorText buffer to the MessageText. +; ; -; * +; ; -; ************************************************************************ +; @@ -6773,40 +7060,42 @@ (, (erase $Ref) (writeMessage $EText))) otherwise)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: writeMessage/1 +; ; -; * +; ; -; * syntax: writeMessage(+Message) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: Appends the Message to the MessageText. +; ; -; * +; ; -; ************************************************************************ +; @@ -6833,40 +7122,42 @@ (recorded messages (file $F) $_) (write $F $Message))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: writelnMessage/1 +; ; -; * +; ; -; * syntax: writelnMessage(+Message) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: Appends the Message to the MessageText. +; ; -; * +; ; -; ************************************************************************ +; @@ -6904,43 +7195,45 @@ (file $F) $_) (write $F $Message) (nl $F))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createEditorArea/1 +; ; -; * +; ; -; * syntax: createEditorArea(+Parent) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: Creates the area for the editior for editing rules and +; ; -; * examples. +; ; -; * +; ; -; ************************************************************************ +; @@ -7000,46 +7293,48 @@ (xtAddCallback $Clear xmNactivateCallback clearEditor $_) (xtAddCallback $AddRule xmNactivateCallback addRule $_) (xtAddCallback $AddExample xmNactivateCallback addExample $_))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: clearEditor/3 callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * _ClientData client data +; ; -; * _CallData event +; ; -; * +; ; -; * description: Clears the scrolled text widget holding the edited object +; ; -; * +; ; -; ************************************************************************ +; @@ -7061,47 +7356,49 @@ (xtSetValues $Label (:: (xmNlabelString $LblS))))) otherwise) (proxtStringToCharPtr '' $EmptyChrPtr) - (xmTextSetString $EditorText $EmptyChrPtr))) + (xmTextSetString $EditorText $EmptyChrPtr))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: addRule/3 Callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * _ClientData +; ; -; * _CallData event +; ; -; * +; ; -; * description: Adds the rule in the editor to the rule list. +; ; -; * +; ; -; ************************************************************************ +; @@ -7124,40 +7421,42 @@ (updateEvaluationLabel) (get-clause $ID $H $B $S $L) (addRuleItem $ID $H $B $S $L))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: resultAddRule/1 result procedure +; ; -; * +; ; -; * syntax: resultAddRule(Id) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: Adds the rule specified by Id to the rule list. +; ; -; * +; ; -; ************************************************************************ +; @@ -7170,43 +7469,45 @@ (atom-chars $IdString $IdChars) (writeMessage $IdString) (writelnMessage ' created.'))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: resultAddNewpreds/1 result procedure +; ; -; * +; ; -; * syntax: resultAddNewpreds(Reflist) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: Displays a window with alternative specialisations +; ; -; * through new predicates, and allows to choose one to add to the kb +; ; -; * +; ; -; ************************************************************************ +; @@ -7273,12 +7574,16 @@ (xtAddCallback $AddRule xmNactivateCallback addselectedRule $_) (xmCreatePushButton $ButtonRow None Nil $None) (xtManageChild $None) - (xtAddCallback $None xmNactivateCallback addnorule $_))) + (xtAddCallback $None xmNactivateCallback addnorule $_))) +; + (= (addnewpredclauses () $_) True) +; + (= (addnewpredclauses (Cons @@ -7297,6 +7602,8 @@ (xtAddEventHandler $Label (:: buttonReleaseMask) False selectnpclause $_) (addnewpredclauses $R $Widget))) +; + @@ -7316,6 +7623,8 @@ (erase $Ref) (recordz newpred (np $Widget $NC $Pos $Neg $TR selected) $_))) +; + (= (selectnpclause $Widget rules $CallData) @@ -7332,6 +7641,8 @@ (erase $Ref) (recordz newpred (np $Widget $NC $Pos $Neg $TR notselected) $_))) +; + (= @@ -7358,6 +7669,8 @@ (:: (xmNbackground $F) (xmNforeground $B))))))))))) $_)) +; + @@ -7372,6 +7685,8 @@ (recorded newpred $X $Ref1) (erase $Ref1))) $_) (xtDestroyWidget $Widget))) +; + (= @@ -7394,7 +7709,7 @@ (, (member $N $Neg) (store-ex $N - $NID))) $_) - (add-atom &self + (add-symbol &self (: kb $TR)) (erase $Ref0) (mysetof $Ref1 @@ -7403,45 +7718,47 @@ (recorded newpred $X $Ref1) (erase $Ref1))) $_) (xtDestroyWidget $Widget) - (refresh (:: rules examples))) True)) + (refresh (:: rules examples))) True)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: resultAddSpec/1 result procedure +; ; -; * +; ; -; * syntax: resultAddNewpreds(Reflist) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: Displays a window with alternative specialisations +; ; -; * through new predicates, and allows to choose one to add to the kb +; ; -; * +; ; -; ************************************************************************ +; @@ -7508,12 +7825,16 @@ (xtAddCallback $AddRule xmNactivateCallback addselectedSpec $_) (xmCreatePushButton $ButtonRow None Nil $None) (xtManageChild $None) - (xtAddCallback $None xmNactivateCallback addnospec $_))) + (xtAddCallback $None xmNactivateCallback addnospec $_))) +; + (= (addspecclauses () $_) True) +; + (= (addspecclauses (Cons $NC $R) $Widget) @@ -7531,6 +7852,8 @@ (xtAddEventHandler $Label (:: buttonReleaseMask) False selectspecclause $_) (addspecclauses $R $Widget))) +; + @@ -7550,6 +7873,8 @@ (erase $Ref) (recordz spec (np $Widget $NC selected) $_))) +; + (= (selectspecclause $Widget rules $CallData) @@ -7566,6 +7891,8 @@ (erase $Ref) (recordz spec (np $Widget $NC notselected) $_))) +; + (= @@ -7589,6 +7916,8 @@ (:: (xmNbackground $F) (xmNforeground $B)))))))) $_)) +; + @@ -7603,6 +7932,8 @@ (recorded spec $X $Ref1) (erase $Ref1))) $_) (xtDestroyWidget $Widget))) +; + (= @@ -7622,83 +7953,89 @@ (recorded spec $X $Ref1) (erase $Ref1))) $_) (xtDestroyWidget $Widget) - (refresh (:: rules))) True)) + (refresh (:: rules))) True)) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: resultAddRuleList/1 result procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +IdList rule ids to add +; ; -; * +; ; -; * description: Adds the rules specified by IdList to the rule list +; ; -; * +; ; -; ************************************************************************ +; (= (resultAddRuleList Nil) (set-det)) +; + (= (resultAddRuleList (Cons $Id $IdList)) ( (resultAddRule $Id) (resultAddRuleList $IdList))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: resultSelectRules/1 result procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +IdList rule ids to select +; ; -; * +; ; -; * description: Selects the rules specified by IdList in the rule list. +; ; -; * +; ; -; ************************************************************************ +; @@ -7707,46 +8044,50 @@ ( (unselectAll $_ rules $_) (set-det) (writelnMessage '% resulting rules selected'))) +; + (= (resultSelectRules (Cons (with_self $Id $_) $IdList)) ( (resultSelectRules $IdList) (recorded current (clause $Id $Widget notselected) $_) (selectClause $Widget rules $_))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: resultSelectExamples/1 result procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +IdList rule ids to select +; ; -; * +; ; -; * description: Selects the examples specified by IdList in the rule list +; ; -; * +; ; -; ************************************************************************ +; @@ -7755,52 +8096,56 @@ ( (unselectAll $_ examples $_) (set-det) (writelnMessage '% resulting examples selected'))) +; + (= (resultSelectExamples (Cons $Id $IdList)) ( (resultSelectExamples $IdList) (recorded current (example $Id $Widget notselected) $_) (selectClause $Widget examples $_))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: changeRule/3 Callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * _ClientData +; ; -; * _CallData event +; ; -; * +; ; -; * description: Changes the rule in the editor to the rule list. +; ; -; * +; ; -; ************************************************************************ +; @@ -7829,49 +8174,51 @@ (get-clause $ID $H $B $S $L) (addRuleItem $ID $H $B $S $L) (updateEvaluationLabel))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: addExample/3 Callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * _ClientData +; ; -; * _CallData event +; ; -; * +; ; -; * +; ; -; * description: Adds the example in the editor to the example list. +; ; -; * +; ; -; ************************************************************************ +; @@ -7894,46 +8241,48 @@ (get-example $ID $F $C) (addExampleItem $ID $F $C) (updateEvaluationLabel))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: changeExample/3 Callback procedure +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: _Widget calling widget +; ; -; * _ClientData +; ; -; * _CallData event +; ; -; * +; ; -; * description: Changes the example in the editor to the example list. +; ; -; * +; ; -; ************************************************************************ +; @@ -7963,46 +8312,48 @@ (get-example $ID $F $C) (addExampleItem $ID $F $C) (updateEvaluationLabel))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: xxmStringToTerm/3 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +S xmCharPtr +; ; -; * Charset xmCharset +; ; -; * +T Term +; ; -; * +; ; -; * description: Conversion of xmCharPtrs and MeTTa Terms. +; ; -; * +; ; -; ************************************************************************ +; @@ -8019,6 +8370,8 @@ (read $T) (seen) (set-det))) +; + (= (xxmStringToTerm $XmS $Charset $T) @@ -8031,46 +8384,48 @@ (xxmStringRead $XmS $Charset) (seen) (set-det))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: xxmStringRead/2 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +S xmString +; ; -; * +Charset xmCharset +; ; -; * +; ; -; * +; ; -; * description: Reads a string from current input. +; ; -; * +; ; -; ************************************************************************ +; @@ -8087,49 +8442,51 @@ (det-if-then otherwise (= $S $XmS))) (set-det))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: xxmStringAppendRead/3 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +S1 xmString, prefix +; ; -; * +S xmString +; ; -; * Charset xmCharset +; ; -; * +; ; -; * description: Reads an xmString from the current input and appends it +; ; -; * to S1. +; ; -; * +; ; -; ************************************************************************ +; @@ -8147,82 +8504,88 @@ (det-if-then otherwise (= $S $XmS1))) (set-det))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: stringRead/2 +; ; -; * +; ; -; * syntax: stringRead(+N,+S) +; ; -; * +; ; -; * description: Reads N characters from the current input. +; ; -; * +; ; -; ************************************************************************ +; (= (stringRead 0 ()) True) +; + (= (stringRead $N $S) ( (get0 $Char) (| (det-if-then (=:= $Char -1) (= $S Nil)) (det-if-then otherwise (, (is $M (- $N 1)) (stringRead $M $S1) (= $S (Cons $Char $S1))))))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: xxmWriteToString/3 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +W writing procedure +; ; -; * +Charset xmCharset +; ; -; * -XmS xmString +; ; -; * +; ; -; * description: Uses the writing procedure W to generate XmS. +; ; -; * +; ; -; ************************************************************************ +; @@ -8235,46 +8598,48 @@ (xxmStringRead $XmS $Charset) (seen) (set-det))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: xxmWriteToCharPtr/3 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +W writing procedure +; ; -; * +Charset xmCharset +; ; -; * -CP xmCharPtr +; ; -; * +; ; -; * description: Uses the writing procedure W to generate CP. +; ; -; * +; ; -; ************************************************************************ +; @@ -8289,40 +8654,42 @@ (atom-chars $AS $S) (proxtStringToCharPtr $AS $CP) (set-det))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: isDepth/1 +; ; -; * +; ; -; * syntax: isDepth(+D) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: Checks if D is within the range of 1-100. +; ; -; * +; ; -; ************************************************************************ +; @@ -8347,40 +8714,42 @@ (writelnError $Message) (set-det) (fail)))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: isExample/1 +; ; -; * +; ; -; * syntax: isExample(+Id) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: checks whether Id specifies an example +; ; -; * +; ; -; ************************************************************************ +; @@ -8402,40 +8771,42 @@ (writelnError $Message) (set-det) (fail)))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: isRule +; ; -; * +; ; -; * syntax: isRule(+Id) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: checks whether Id specifies a rule +; ; -; * +; ; -; ************************************************************************ +; @@ -8457,40 +8828,42 @@ (writelnError $Message) (set-det) (fail)))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: isExOrRule/1 +; ; -; * +; ; -; * syntax: isExOrRule(+Id) +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: checks whether Id specifies a rule or an example +; ; -; * +; ; -; ************************************************************************ +; @@ -8513,98 +8886,110 @@ (atom-chars $Message $M3) (writelnError $Message) (fail))))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: sucheInListe/1 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +Element term +; ; -; * +List list of terms +; ; -; * +; ; -; * description: searches Element in List +; ; -; * +; ; -; ************************************************************************ +; (= (sucheInListe $A (Cons $A $_)) True) +; + (= (sucheInListe $_ ()) True) +; + (= (sucheInListe $A (Cons $_ $Rest)) (sucheInListe $A $Rest)) +; + (= (writeFullstop $X) ( (write $X) (write .))) +; + (= (true $_) True) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: createEvaluationString/1 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: -String list of terms +; ; -; * +; ; -; * description: +; ; -; * +; ; -; ************************************************************************ +; @@ -8614,43 +8999,45 @@ (evaluated no) (= $S '(not evaluated)') (= $S ' (evaluated)'))) +; + ; -; ************************************************************************ +; ; -; * +; ; -; * predicate: updateEvaluationLabel/0 +; ; -; * +; ; -; * syntax: +; ; -; * +; ; -; * args: +; ; -; * +; ; -; * description: updates the label that indicates whether the kb is +; ; -; * evaluated +; ; -; * +; ; -; ************************************************************************ +; @@ -8663,4 +9050,6 @@ (xmStringCreate $ACP $DCharset $AXmS) (xtSetValues $Widget (:: (xmNlabelString $AXmS))))) +; + diff --git a/miles/xmiles_functions.metta b/miles/xmiles_functions.metta index 744b578..c56ef2a 100644 --- a/miles/xmiles_functions.metta +++ b/miles/xmiles_functions.metta @@ -1,211 +1,269 @@ ; -; ****************************************************************************** +; ; -; * +; ; -; * +; ; -; * This file describes the learning operators of miles called by xmiles +; ; -; * when a specific button is pressed +; ; -; * +; ; -; * +; ; -; ****************************************************************************** +; ; -; ****************************************************************************** +; ; -; * +; ; -; * groups(). +; ; -; * +; ; -; ****************************************************************************** +; (= (groups - (preprocess g1 g2 gencon lgg refinement evaluation truncation)) True) + (preprocess g1 g2 gencon lgg refinement evaluation truncation)) True) +; + ; -; ****************************************************************************** +; ; -; * +; ; -; * groupdef(,). +; ; -; * +; ; -; ****************************************************************************** +; (= (groupdef preprocess ('argument types' 'clause heads' 'flatten kb' 'flatten rules' 'unflatten kb')) True) +; + (= (groupdef g1 ('g1 op' 'apply g1' identify absorb 'inv derivate' 'most spec v' saturate 'elem saturate')) True) +; + (= (groupdef g2 ('intraconstruct 1' 'intraconstruct 2' 'g2 op' 'apply g2')) True) +; + (= (groupdef gencon ('learn constrained' 'learn foil' 'learn rul')) True) +; + (= (groupdef lgg ('gen msg' rlgg lgg 'headed lgg' 'nr lgg' gti)) True) +; + (= (groupdef refinement ('unify vars' 'instantiate vars' 'add body lit' 'new predicate')) True) +; + (= (groupdef evaluation ('correct check' 'complete check' 'evaluate examples' fp 'covered examples')) True) +; + (= (groupdef truncation (reduce unconnected redundant 'flat redundant' unconnecting 'negation based' 'flat negation based' facts)) True) +; + ; -; ****************************************************************************** +; ; -; * +; ; -; * operatordef(,,, +; ; -; * ,, +; ; -; * ,). +; ; -; * +; ; -; ****************************************************************************** +; (= (operatordef 'argument types' argument_types () () () (rules)) True) +; + (= (operatordef 'clause heads' clause_heads () () () (rules)) True) +; + (= (operatordef 'flatten kb' flatten_kb () () () (rules)) True) +; + (= (operatordef 'flatten rules' flatten_rules () () () (rules)) True) +; + (= (operatordef 'unflatten kb' unflatten_kb () () () (rules)) True) +; + (= (operatordef 'g1 op' g1_op (xmarg1 xmarg2 xmout1) (isRule isRule) (resultAddRule) ()) True) +; + (= (operatordef 'apply g1' apply_g1 (xmarg1 xmout1) (isRule) (resultAddRuleList) ()) True) +; + (= (operatordef identify identify (xmarg1 xmarg2 xmout1) (isExOrRule true) (resultAddRule) ()) True) +; + (= (operatordef absorb absorb (xmarg1 xmarg2 xmout1) (isExOrRule isExOrRule) (resultAddRule) ()) True) +; + (= (operatordef 'inv derivate' inv_derivate (xmarg1 xmout1) (isExOrRule) (resultAddRule) ()) True) +; + (= (operatordef 'most spec v' most_spec_v (xmarg1 xmarg2 xmout1) (isExOrRule isExOrRule) (resultAddRule) ()) True) +; + (= (operatordef saturate saturate (xmarg1 xmout1 xmoptdepth) (isExOrRule isDepth) (resultAddRule) ()) True) +; + (= (operatordef 'elem saturate' elem_saturate (xmarg1 xmarg2 xmout1) (isExOrRule true) (resultAddRule) ()) True) +; + (= (operatordef 'intraconstruct 1' intra_construct1 (xmarg1 xmarg2 xmout1 xmout2 xmout3) (isRule isRule) (resultAddRule resultAddRule resultAddRule) ()) True) +; + (= (operatordef 'intraconstruct 2' intra_construct2 (xmarg1 xmarg2 xmout1 xmout2 xmout3) (isRule isRule) (resultAddRule resultAddRule resultAddRule) ()) True) +; + (= (operatordef 'g2 op' g2_op (xmarg1 xmarg2 xmout1 xmout2 xmout3) (isRule isRule) (resultAddRule resultAddRule resultAddRule) ()) True) +; + (= (operatordef 'apply g2' apply_g2 (xmarg1 xmarg2 xmout1 xmout2 xmout3) (isRule isRule) (resultAddRule resultAddRule resultAddRule) ()) True) +; + (= (operatordef 'learn constrained' learn_constrained () () () (rules)) True) +; + (= (operatordef 'learn foil' learn_foil () () () (rules)) True) +; + (= (operatordef 'learn rul' learn_rul () () () (rules)) True) +; + (= @@ -213,107 +271,153 @@ (xmarg1 xmarg2 xmout1) (isRule isRule) (resultAddRule) ()) True) +; + (= (operatordef rlgg rlgg (xmarg1 xmarg2 xmout1) (isRule isRule) (resultAddRule) ()) True) +; + (= (operatordef lgg lgg (xmarg1 xmarg2 xmout1) (isRule isRule) (resultAddRule) ()) True) +; + (= (operatordef 'headed lgg' headed_lgg (xmarg1 xmarg2 xmout1) (isRule true) (resultAddRule) ()) True) +; + (= (operatordef 'nr lgg' nr_lgg (xmarg1 xmarg2 xmout1) (isRule isRule) (resultAddRule) ()) True) +; + (= (operatordef gti gti (xmarg1 xmarg2 xmout1) (isRule isRule) (resultAddRule) ()) True) +; + (= (operatordef 'unify vars' refinement_unify_variables (xmarg1 xmout1) (isRule) (resultAddSpec) ()) True) +; + (= (operatordef 'instantiate vars' refinement_instantiate_variables (xmarg1 xmout1) (isRule) (resultAddSpec) ()) True) +; + (= (operatordef 'add body lit' refinement_add_body_literal (xmarg1 xmout1) (isRule) (resultAddSpec) ()) True) +; + (= (operatordef 'new predicate' specialize_with_newpred (xmarg1 xmout1) (isRule) (resultAddNewpreds) ()) True) +; + (= (operatordef 'correct check' correct_chk () () () ()) True) +; + (= (operatordef 'complete check' complete_chk () () () ()) True) +; + (= (operatordef 'evaluate examples' eval_examples () () () ()) True) +; + (= (operatordef fp fp (xmout1) () (resultSelectRules) ()) True) +; + (= (operatordef 'covered examples' all_covered_examples (xmout1) () (resultSelectExamples) ()) True) +; + (= (operatordef reduce reduce_complete (xmarg1) (isRule) () (rules)) True) +; + (= (operatordef unconnected truncate_unconnected (xmarg1) (isRule) () (rules)) True) +; + (= (operatordef redundant truncate_r (xmarg1) (isRule) () (rules)) True) +; + (= (operatordef 'flat redundant' truncate_flat_r (xmarg1) (isRule) () (rules)) True) +; + (= (operatordef unconnecting truncate_unconnecting (xmarg1) (isRule) () (rules)) True) +; + (= (operatordef 'negation based' truncate_neg_based (xmarg1) (isRule) () (rules)) True) +; + (= (operatordef 'flat negation based' truncate_flat_neg_based (xmarg1) (isRule) () (rules)) True) +; + (= (operatordef facts truncate_facts (xmarg1) (isRule) () (rules)) True) +; + diff --git a/multagnt/calls_1.metta b/multagnt/calls_1.metta index 02f57aa..b3644f6 100644 --- a/multagnt/calls_1.metta +++ b/multagnt/calls_1.metta @@ -2,26 +2,36 @@ (= (?- (teacher)) True) +; + (= (?- (learner1)) True) +; + (= (?- (demo (: teacher gilchrist_family) (parent warren david) $L)) True) +; + (= (?- (demo (: teacher gilchrist_family) (parent charles julia) $L)) True) +; + (= (?- (demo (: teacher gilchrist_family) (parent warren (variable a)) $L)) True) +; + (= (?- (demo @@ -29,17 +39,23 @@ (parent (variable parent) (variable child)) $L)) True) +; + (= (?- (demo (: teacher entropy) (entropy_increases kitchen fridge) $L)) True) +; + (= (?- (demo (: teacher entropy) (entropy_increases kitchen living_room) $L)) True) +; + (= (?- (demo @@ -47,6 +63,8 @@ (entropy_increases (variable a) (variable b)) $L)) True) +; + (= (?- @@ -54,24 +72,32 @@ (: teacher t_member) (member a (a b c)) $L)) True) +; + (= (?- (demo (: teacher t_member) (member b (a b c)) $L)) True) +; + (= (?- (demo (: teacher t_member) (member e (q w e r t z t r e w q)) $L)) True) +; + (= (?- (demo (: teacher t_member) (member o (q w e r t z t r e w q)) $L)) True) +; + (= (?- (demo @@ -79,6 +105,8 @@ (member (variable a) (a b c)) $L)) True) +; + (= (?- (demo @@ -86,12 +114,16 @@ (member (variable a) (variable list)) $L)) True) +; + (= (?- (demo (: teacher t_member) (member a (variable list)) $L)) True) +; + (= (?- @@ -100,6 +132,8 @@ (reverse (a b c) (c b a)) $L)) True) +; + (= (?- (demo @@ -107,6 +141,8 @@ (reverse (b a c) (c b a)) $L)) True) +; + (= (?- (demo @@ -114,59 +150,81 @@ (reverse (variable a) (c b a)) $L)) True) +; + (= (?- (can_do $Tl $Tt (parent warren david) $C)) True) +; + (= (?- (can_do $Tl $Tt (parent charles julia) $C)) True) +; + (= (?- (can_do $Tl $Tt (parent (variable parent) (variable child)) $C)) True) +; + (= (?- (demo $Tl $Tt (entropy_increases kitchen fridge) $C)) True) +; + (= (?- (can_do $Tl $Tt (entropy_increases kitchen fridge) $C)) True) +; + (= (?- (can_do $Tl $Tt (entropy_increases (variable a) (variable b)) $C)) True) +; + (= (?- (can_do $Tl $Tt (member a (g f d s a)) $C)) True) +; + (= (?- (can_do $Tl $Tt (member e (q w e r t z t r e w q)) $C)) True) +; + (= (?- (can_do $Tl $Tt (member (variable a) (g f d s a)) $C)) True) +; + (= (?- (can_do $Tl $Tt (member (variable a) (variable list)) $C)) True) +; + (= (?- @@ -174,16 +232,22 @@ (reverse (a b c) (c b a)) $C)) True) +; + (= (?- (can_do $Tl $Tt (reverse (b a c) (c b a)) $C)) True) +; + (= (?- (can_do $Tl $Tt (reverse (variable c) (c b a)) $C)) True) +; + diff --git a/multagnt/calls_2.metta b/multagnt/calls_2.metta index 5238bfe..8db825f 100644 --- a/multagnt/calls_2.metta +++ b/multagnt/calls_2.metta @@ -1,29 +1,41 @@ (= (?- (teacher)) True) +; + (= (?- (learner2)) True) +; + (= (?- (cannot_do $Tl $Tt (parent warren catherine) $C)) True) +; + (= (?- (cannot_do $Tl $Tt (parent warren david) $C)) True) +; + (= (?- (cannot_do $Tl $Tt (parent warren (variable child)) $C)) True) +; + (= (?- (can_do $Tl $Tt (parent (variable parent) (variable child)) $C)) True) +; + (= (?- @@ -31,29 +43,39 @@ (entropy_increases (variable a) (variable b)) $C)) True) +; + (= (?- (cannot_do $Tl $Tt (t_member f (g f d s a)) $C)) True) +; + (= (?- (cannot_do $Tl $Tt (t_member e (q w e r t z t r e w q)) $C)) True) +; + (= (?- (cannot_do $Tl $Tt (t_member (variable a) (g f d s a)) $C)) True) +; + (= (?- (can_do $Tl $Tt (t_member (variable a) (variable list)) $C)) True) +; + (= (?- @@ -61,17 +83,23 @@ (reverse (c b a) (variable c)) $C)) True) +; + (= (?- (cannot_do $Tl $Tt (reverse (a b c) (c b a)) $C)) True) +; + (= (?- (what_cannot_do $Ls $Ts (<- $Q $Ans) () $F)) True) +; + (= (?- (what_cannot_do $Ls $Ts @@ -79,6 +107,8 @@ (qsort (1 2) (variable a)) $Ans) () $F)) True) +; + (= (?- (what_cannot_do $Ls $Ts @@ -86,6 +116,8 @@ (qsort (2 1) (variable a)) $Ans) () $F)) True) +; + (= (?- (what_cannot_do $Ls $Ts @@ -93,6 +125,8 @@ (qsort (2 3 1) (variable a)) $Ans) () $F)) True) +; + (= (?- (what_cannot_do $Ls $Ts @@ -100,4 +134,6 @@ (qsort (3 2 1) (variable a)) $Ans) () $F)) True) +; + diff --git a/multagnt/learner1.metta b/multagnt/learner1.metta index b1270b6..e3c6bed 100644 --- a/multagnt/learner1.metta +++ b/multagnt/learner1.metta @@ -1,9 +1,9 @@ ; -; Right knowledge of a learner about different topics +; ; -; Fact theory +; @@ -11,49 +11,71 @@ (db_entry (: learner gilchrist_family) (parent euan warren) ()) True) +; + (= (db_entry (: learner gilchrist_family) (parent berenice warren) ()) True) +; + (= (db_entry (: learner gilchrist_family) (parent warren catherine) ()) True) +; + (= (db_entry (: learner gilchrist_family) (parent warren charles) ()) True) +; + (= (db_entry (: learner gilchrist_family) (parent warren david) ()) True) +; + (= (db_entry (: learner gilchrist_family) (parent warren julia) ()) True) +; + (= (db_entry (: learner gilchrist_family) (parent kate catherine) ()) True) +; + (= (db_entry (: learner gilchrist_family) (parent kate charles) ()) True) +; + (= (db_entry (: learner gilchrist_family) (parent kate david) ()) True) +; + (= (db_entry (: learner gilchrist_family) (parent kate julia) ()) True) +; + (= (db_entry (: learner gilchrist_family) (parent charles lucinda) ()) True) +; + ; -; Fact and Rule Theory +; @@ -63,51 +85,75 @@ ( (: learner warm) (: learner cold) (: learner door))) True) +; + (= (db_entry (: learner warm) (warm kitchen) ()) True) +; + (= (db_entry (: learner warm) (warm living_room) ()) True) +; + (= (db_entry (: learner cold) (cold fridge) ()) True) +; + (= (db_entry (: learner cold) (cold street) ()) True) +; + (= (db_entry (: learner cold) (cold garden) ()) True) +; + (= (db_entry (: learner door) (door living_room kitchen) ()) True) +; + (= (db_entry (: learner door) (door living_room street) ()) True) +; + (= (db_entry (: learner door) (door living_room garden) ()) True) +; + (= (db_entry (: learner door) (door kitchen garden) ()) True) +; + (= (db_entry (: learner door) (door kitchen fridge) ()) True) +; + (= (db_entry (: learner door) (door street garden) ()) True) +; + (= (db_entry (: learner entropy) @@ -115,6 +161,8 @@ ( (warm $A) (cold $B) (door $A $B))) True) +; + (= (db_entry (: learner entropy) @@ -122,6 +170,8 @@ ( (cold $A) (warm $B) (door $A $B))) True) +; + (= (db_entry (: learner entropy) @@ -129,6 +179,8 @@ ( (warm $A) (cold $B) (door $B $A))) True) +; + (= (db_entry (: learner entropy) @@ -136,9 +188,11 @@ ( (cold $A) (warm $B) (door $B $A))) True) +; + ; -; Recusive Theory +; (= @@ -146,17 +200,23 @@ (: learner t_member) (member $A (Cons $A $_)) ()) True) +; + (= (db_entry (: learner t_member) (member $A (Cons $_ $B)) ( (member $A $B))) True) +; + (= (db_entry (: learner t_append) (append () $List $List) ()) True) +; + (= (db_entry (: learner t_append) @@ -164,34 +224,46 @@ (Cons $First $Rest) $List (Cons $First $TempList)) ( (append $Rest $List $TempList))) True) +; + (= (def_theory (: learner t_reverse) ( (: learner t_append))) True) +; + (= (db_entry (: learner t_reverse) (reverse () ()) ()) True) +; + (= (db_entry (: learner t_reverse) (reverse (Cons $X $Y) $Z) ( (reverse $Y $Y1) (append $Y1 ($X) $Z))) True) +; + (= (def_theory (: learner qsort) ( (: learner partition) (: learner t_append))) True) +; + (= (db_entry (: learner qsort) (qsort () ()) ()) True) +; + (= (db_entry (: learner qsort) @@ -202,11 +274,15 @@ (qsort $L2 $L4) (append $L3 (Cons $X $L4) $L5))) True) +; + (= (db_entry (: learner partition) (partition () $_ () ()) ()) True) +; + (= (db_entry (: learner partition) @@ -214,6 +290,8 @@ (Cons $X $L) $Y (Cons $X $L1) $L2) ( (< $X $Y) (partition $L $Y $L1 $L2))) True) +; + (= (db_entry (: learner partition) @@ -221,4 +299,6 @@ (Cons $X $L) $Y $L1 (Cons $X $L2)) ( (>= $X $Y) (partition $L $Y $L1 $L2))) True) +; + diff --git a/multagnt/learner2.metta b/multagnt/learner2.metta index 4d8708a..b11bd92 100644 --- a/multagnt/learner2.metta +++ b/multagnt/learner2.metta @@ -1,27 +1,31 @@ ; -; Wrong knowledge of a learner about different topics +; ; -; Differences to Learner1 are enclosed in comments +; ; -; Fact theory +; (= (db_entry (: learner gilchrist_family) (parent euan warren) ()) True) +; + (= (db_entry (: learner gilchrist_family) (parent berenice warren) ()) True) +; + ; ; ; -; db_entry(learner:gilchrist_family,parent(warren,catherine),[]). +; ; ; @@ -30,42 +34,56 @@ (db_entry (: learner gilchrist_family) (parent warren charles) ()) True) +; + (= (db_entry (: learner gilchrist_family) (parent warren david) ()) True) +; + (= (db_entry (: learner gilchrist_family) (parent warren julia) ()) True) +; + (= (db_entry (: learner gilchrist_family) (parent kate catherine) ()) True) +; + (= (db_entry (: learner gilchrist_family) (parent kate charles) ()) True) +; + (= (db_entry (: learner gilchrist_family) (parent kate david) ()) True) +; + (= (db_entry (: learner gilchrist_family) (parent kate julia) ()) True) +; + ; ; ; -; db_entry(learner:gilchrist_family,parent(charles,lucinda),[]). +; ; ; ; -; Fact and Rule Theory +; @@ -75,32 +93,44 @@ ( (: learner warm) (: learner cold) (: learner door))) True) +; + (= (db_entry (: learner warm) (warm living_room) ()) True) +; + (= (db_entry (: learner warm) (warm kitchen) ()) True) +; + (= (db_entry (: learner cold) (cold street) ()) True) +; + (= (db_entry (: learner cold) (cold garden) ()) True) +; + (= (db_entry (: learner cold) (cold fridge) ()) True) +; + ; ; ; -; The following entries are incorrect +; ; ; @@ -109,31 +139,43 @@ (db_entry (: learner door) (door a_living_room a_kitchen) ()) True) +; + (= (db_entry (: learner door) (door a_living_room a_street) ()) True) +; + (= (db_entry (: learner door) (door a_living_room a_garden) ()) True) +; + (= (db_entry (: learner door) (door a_kitchen a_garden) ()) True) +; + (= (db_entry (: learner door) (door a_kitchen a_fridge) ()) True) +; + (= (db_entry (: learner door) (door a_street a_garden) ()) True) +; + ; ; ; -; Now the theory continues correctly +; ; ; @@ -145,6 +187,8 @@ ( (warm $A) (cold $B) (door $A $B))) True) +; + (= (db_entry (: learner entropy) @@ -152,6 +196,8 @@ ( (cold $A) (warm $B) (door $A $B))) True) +; + (= (db_entry (: learner entropy) @@ -159,6 +205,8 @@ ( (warm $A) (cold $B) (door $B $A))) True) +; + (= (db_entry (: learner entropy) @@ -166,18 +214,22 @@ ( (cold $A) (warm $B) (door $B $A))) True) +; + ; -; Recusive Theory +; ; -; incorrect t_member +; (= (db_entry (: learner t_member) (member $A ()) ()) True) +; + (= (db_entry (: learner t_member) @@ -185,11 +237,13 @@ (Cons $B $T)) ( (not (= $A $B)) (member $A $T))) True) +; + ; -; | | +; ; -; +--------+ this is a fault ! +; ; ; @@ -199,11 +253,13 @@ (db_entry (: learner t_append) (append () $List ()) ()) True) +; + ; -; || +; ; -; ++ this is a fault ! +; (= (db_entry @@ -212,34 +268,46 @@ (Cons $First $Rest) $List (Cons $First $TempList)) ( (append $Rest $List $TempList))) True) +; + (= (def_theory (: learner t_reverse) ( (: learner t_append))) True) +; + (= (db_entry (: learner t_reverse) (reverse () ()) ()) True) +; + (= (db_entry (: learner t_reverse) (reverse (Cons $X $Y) $Z) ( (reverse $Y $Y1) (append $Y1 ($X) $Z))) True) +; + (= (def_theory (: learner qsort) ( (: learner partition) (: learner t_append1))) True) +; + (= (db_entry (: learner qsort) (qsort () ()) ()) True) +; + (= (db_entry (: learner qsort) @@ -250,6 +318,8 @@ (qsort $L2 $L4) (append1 $L3 (Cons $X $L4) $L5))) True) +; + (= (db_entry @@ -258,9 +328,7 @@ (Cons $X $L) $Y ($L1) $L2) ( (< $X $Y) (partition $L $Y $L1 $L2))) True) -; ; | | -; ; +--+ this is a fault ! - +; (= (db_entry @@ -269,15 +337,21 @@ (Cons $X $L) $Y $L1 (Cons $X $L2)) ( (>= $X $Y) (partition $L $Y $L1 $L2))) True) +; + (= (db_entry (: learner partition) (partition () $_ () ()) ()) True) +; + (= (db_entry (: learner t_append1) (append1 () $List $List) ()) True) +; + (= (db_entry (: learner t_append1) @@ -285,4 +359,6 @@ (Cons $First $Rest) $List (Cons $First $TempList)) ( (append1 $Rest $List $TempList))) True) +; + diff --git a/multagnt/multagnt.metta b/multagnt/multagnt.metta index 0ad9a10..411e0fb 100644 --- a/multagnt/multagnt.metta +++ b/multagnt/multagnt.metta @@ -1,80 +1,24 @@ !(dynamic (/ parent 2)) -; /******************************************************************/ - -; /* MULTAGNT.PRO */ - -; /* Brazdil's Simulation of a tutoring setting between two agents */ - -; /******************************************************************/ - -; /* impl. by : Yiu Cheung HO */ - -; /* Department of Computing */ - -; /* King's College London */ - -; /* 1989 */ - -; /* */ - -; /* Thomas Hoppe */ - -; /* Mommsenstr. 50 */ - -; /* 1000 Berlin 12 */ - -; /* F.R.G. */ - -; /* E-Mail: hoppet@db0tui11.pro */ - -; /* 1990 */ - -; /* */ - -; /* reference : Transfer of Knowledge between Systems, */ - -; /* Brazdil, P., Associacao Portuguesa para a Intel-*/ - -; /* igencia Artificial, Working Paper 87-1, Uni- */ - -; /* versity of Porto, 1987. */ - -; /* */ - -; /* Diagnosis of Misunderstanding, Yiu Cheung HO, */ - -; /* Project Report, Final Year One Unit Project */ - -; /* 88/89, Department of Computing, King's College */ - -; /* London, 1989. */ - -; /* */ - -; /* call : diagnosis */ - -; /* */ - -; /******************************************************************/ - +; !(dynamic (/ db-entry 3)) -; /******************************************************************/ - -; /* YAP-, C- and M-MeTTa specific declaration of dynamical */ - -; /* clauses. */ - -; /******************************************************************/ - +; !(dynamic (/ def-theory 2)) +; + !(dynamic (/ digits-of-next-sym 1)) +; + !(op 999 xfx :) +; + !(op 998 xfx <-) +; + (= @@ -85,12 +29,7 @@ (nl) (get-learner) (locate-error))) -; /******************************************************************/ - -; /* User Interface */ - -; /******************************************************************/ - +; @@ -102,13 +41,21 @@ (multifile (/ def-theory 2)) (dynamic (/ db-entry 3)) (dynamic (/ def-theory 2)))) +; + - !(init) + !(init *) +; - !(:: (teacher)) - !(:: (learner1)) + !(:: (teacher *)) +; + + + !(:: (learner1 *)) +; + (= @@ -116,6 +63,8 @@ ( (repeat) (mode $Mode) (generate-error $Mode))) +; + (= @@ -126,6 +75,8 @@ (exit-manual) (set-det) (exit))) +; + (= (generate-error auto) ( (select-question $Question) @@ -133,9 +84,13 @@ (exit-auto) (set-det) (exit))) +; + (= (generate-error $_) (exit)) +; + (= @@ -145,11 +100,15 @@ (output-error $Ls $Ts (<- $Question $Answer) $FaultyStep) (set-det))) +; + (= (process-question $Question) ( (write ' *** The teacher cannot answer the question: ') (write $Question) (nl))) +; + (= @@ -177,44 +136,62 @@ (out-faulty $FaultyStep) (nl) (set-det))) +; + (= (out-faulty Nil) ( (write 'no faulty step') (nl))) +; + (= (out-faulty $Steps) ( (out-step $Steps) (nl))) +; + (= (out-step Nil) (nl)) +; + (= (out-step (Cons $Step $Steps)) ( (write ) (write $Step) (nl) (write $Steps))) +; + (= (out-answer Nil) ( (write True) (nl))) +; + (= (out-answer $Ans) (out-ans $Ans)) +; + (= (out-ans Nil) (nl)) +; + (= (out-ans (Cons (val $Var $Val) $T)) ( (write (= $Var $Val)) (nl) (write ) (out-ans $T))) +; + (= @@ -222,29 +199,37 @@ ( (generate-question $Question) (yes-no yes confirm $Reply) (= $Reply yes))) +; + (= (select-question $_) ( (write ' no more questions') (nl) (set-det) (fail))) +; + (= (generate-question $Question) ( (db-entry (with_self - (teacher) $_) $Question $_) + (teacher *) $_) $Question $_) (make-ground-term $Question) (nl) (write ' Question generated: ') (write $Question) (nl))) +; + (= (get-question $Question) ( (write ' Input question: ') (read $Question))) +; + (= @@ -255,23 +240,33 @@ (nl) (= $Reply yes) (set-det))) +; + (= (mode manual) True) +; + (= (exit-manual) ( (yes-no no ' Exit manual mode ? ' $Reply) (= $Reply yes))) +; + (= (exit-auto) ( (yes-no no ' Exit auto mode ? ' $Reply) (= $Reply yes))) +; + (= (exit) ( (yes-no no ' Quit ? ' $Reply) (= $Reply yes))) +; + (= @@ -281,26 +276,36 @@ (knowledge-base-list $Reply Nil $Teacher $FileList) (yes-no no ' Do you want to load another teacher KB ? ' $Reply2) (more-knowledge $Reply2 $FileList))) +; + (= (load_knowledge_base no $_) True) +; + (= (load-knowledge-base yes $File) ( (nl) (consult $File) (nl) (set-det))) +; + (= (more_knowledge no (Cons $_ $_)) True) +; + (= (more-knowledge no Nil) ( (write ' *** You have not load any knowledge base yet !') (nl) (more-knowledge yes Nil))) +; + (= (more-knowledge yes $FileList) ( (repeat) @@ -310,19 +315,25 @@ (knowledge-base-list $Load $FileList $File $NewList) (yes-no no ' Do you want to consult more KBs ? ' $Reply) (more-knowledge $Reply $NewList))) +; + (= (not-loaded $File $List no) ( (member $File $List) (set-det))) +; + (= (not_loaded $_ $_ yes) True) +; + ; -; yesno(Question):- yesno(Question,no). +; ; -; yesno(Question, Default):- format('~N~w? (~w): ',[Question,Default]),get_single_char(YN), (YN = 13 -> Default==yes; member(YN, `yY`)). +; @@ -355,16 +366,22 @@ (= $Reply $Default) (reply $In $Reply)))) (set-det))) +; + (= (reply $Reply yes) (member $Reply (:: yes y yes. y. 89 121))) +; + (= (reply $Reply no) (member $Reply (:: no n no. n. 78 110))) +; + (= @@ -374,18 +391,26 @@ (write $Message) (read-in $File) (set-det))) +; + (= (knowledge_base_list yes $List $File (Cons $File $List)) True) +; + (= (knowledge_base_list no $List $_ $List) True) +; + (= (no-knowledge Nil) ( (write ' *** You have not load any knowledge base yet !') (nl))) +; + (= @@ -395,25 +420,20 @@ (knowledge-base-list yes Nil $File $List) (yes-no no ' Do you want to load another KB for the learner ? ' $Reply) (more-knowledge $Reply $List))) +; + (= (can-do (with_self - (learner) $Tl) + (learner *) $Tl) (with_self - (teacher) $Tt) $Question $TeachersAnswer) + (teacher *) $Tt) $Question $TeachersAnswer) ( (demo (with_self - (learner) $Tl) $Question $LearnersAnswer) (can-do-1 (with_self (teacher) $Tt) $Question $TeachersAnswer $LearnersAnswer))) -; /******************************************************************/ - -; /* Brazdil's predicates for evaluating the behavior of "LEARNER" */ - -; /* and "TEACHER". */ - -; /******************************************************************/ - + (learner *) $Tl) $Question $LearnersAnswer) (can-do-1 (with_self (teacher *) $Tt) $Question $TeachersAnswer $LearnersAnswer))) +; @@ -422,31 +442,36 @@ ( (demo $Teacher $Question $TeachersAnswer) (demo $Teacher $LearnersAnswer $TeachersAnswer) (demo $Teacher $TeachersAnswer $LearnersAnswer))) +; + (= (cannot-do (with_self - (learner) $Tl) + (learner *) $Tl) (with_self - (teacher) $Tt) $Question $TeachersAnswer) - ( (not (demo (with_self (learner) $Tl) $Question $LearnersAnswer)) (demo (with_self (teacher) $Tt) $Question $TeachersAnswer))) + (teacher *) $Tt) $Question $TeachersAnswer) + ( (not (demo (with_self (learner *) $Tl) $Question $LearnersAnswer)) (demo (with_self (teacher *) $Tt) $Question $TeachersAnswer))) +; + (= (cannot-do $Learner $Teacher $Question $_) ( (can-do $Learner $Teacher $Question $_) (set-det) (fail))) +; + (= (cannot-do (with_self - (learner) $Tl) + (learner *) $Tl) (with_self - (teacher) $Tt) $Question $TeachersAnswer) + (teacher *) $Tt) $Question $TeachersAnswer) ( (demo (with_self - (learner) $Tl) $Question $_) (demo (with_self (teacher) $Tt) $Question $TeachersAnswer))) -; ; It seems that the condition LearnersAnswer <> TeachersAnswer is missing ! - + (learner *) $Tl) $Question $_) (demo (with_self (teacher *) $Tt) $Question $TeachersAnswer))) +; @@ -459,16 +484,22 @@ (nl) (set-det) (fail))) +; + (= (what-cannot-do $Ls $Ts (<- $Q $A) $FaultyStep $FaultyStep) (can-do $Ls $Ts $Q $A)) +; + (= (what-cannot-do $Ls $Ts (<- $Q $A) $F1 (Cons (<- $Q $A) $F1)) (is-faulty-step $Ls $Ts $Q $A)) +; + (= (what-cannot-do $Ls $Ts (<- $Q $A) $F1 $F2) @@ -476,6 +507,8 @@ (demo-trace2 $Ls $Ts $Q $A $SubSteps) (what-cannot-do-list $Ls $Ts $SubSteps $F1 $F3) (faulty-step $Q $A $F1 $F3 $F2))) +; + (= @@ -483,22 +516,32 @@ ( (cannot-do $Ls $Ts $Q $A) (set-det) (not (demo-trace2 $Ls $Ts $Q $A $_)))) +; + (= (faulty_step $Q $A $F1 $F1 (Cons (<- $Q $A) $F1)) True) +; + (= (faulty_step $Q $A $F1 $F3 $F3) True) +; + (= (what_cannot_do_list $_ $_ () $F $F) True) +; + (= (what-cannot-do-list $Ls $Ts (Cons $Step1 $RestSteps) $F1 $F3) ( (what-cannot-do $Ls $Ts $Step1 $F1 $F2) (what-cannot-do-list $Ls $Ts $RestSteps $F2 $F3))) +; + (= @@ -511,64 +554,7 @@ (show $Theory $Goal2) (link-vals $LVars $LVars2 $Conditions) (make-ground-term $Conditions))) -; /******************************************************************/ - -; /* */ - -; /* call : demo(+Theory,+Goal,Conditions) */ - -; /* */ - -; /* arguments : Theory = ground term denoting a theory */ - -; /* Goal = ground term or list of ground terms*/ - -; /* Conditions = substitutions */ - -; /* */ - -; /* property : backtrackable */ - -; /* */ - -; /******************************************************************/ - -; /* 'demo' is used to prove the Goal in the background of a Theory */ - -; /* delivering a substitution in Conditions. */ - -; /* Bindings of variables and values are explicitly maintained by */ - -; /* this implementation, thus any subterm of the form "variable(S)"*/ - -; /* must actually be of the form "variabl()" where is */ - -; /* the name of a variable in the Goal. */ - -; /* The substitutions in Condition may be either a variable or a */ - -; /* list of terms which all have the form val(variable(X),Y) where */ - -; /* X is the name of a variable (an atom) and Y is any term. */ - -; /* In the case Condition is uninstantiated, demo succeeds iff */ - -; /* Goal can be proven within the Theory. Condition is then instan-*/ - -; /* tiated with the corresponding substitutions in the form */ - -; /* described above. On backtracking it will deliver the next */ - -; /* possible proof with the corresponding substitution, if it */ - -; /* exists. */ - -; /* If Condition is instantiated in the form described above, demo */ - -; /* succeeds, if Goal can be proven with the given substitution. */ - -; /******************************************************************/ - +; (= (demo $Theory $Goal $Conditions) @@ -582,6 +568,8 @@ (no-new-values $LVars3) (not (identified-vars $LVars3)) (set-det))) +; + (= @@ -599,98 +587,88 @@ (show $Ts $Body3) (make-ground-term $Body3) (trace-list $Body3 $Steps))) -; /******************************************************************/ - -; /* Brazdil's predicate for locating erroneous LEARNER's knowledge */ - -; /******************************************************************/ - +; (= (trace_list () ()) True) +; + (= (trace-list (Cons $SubGoal $Rest) (Cons (<- $SubGoal $_) $Steps)) (trace-list $Rest $Steps)) +; + (= (show $_ Nil) (set-det)) -; /******************************************************************/ - -; /* */ - -; /* call : show(+Theory,+Goal) */ - -; /* */ - -; /* arguments : Theory = ground term denoting a theory */ - -; /* Goal = ground term or list of ground terms*/ - -; /* */ - -; /* property : backtrackable */ - -; /* */ - -; /******************************************************************/ - -; /* 'show' is nothing else than an MeTTa meta-interpreter working */ - -; /* in the traditional way, except that substitutions are explicit-*/ - -; /* ly represented through terms in the form 'val(,)'. */ - -; /******************************************************************/ - +; (= (show $Th (not $G)) ( (set-det) (not (show $Th $G)))) +; + (= (show $Th (not $G)) ( (set-det) (not (show $Th $G)))) +; + (= (show $Th (val $X $Y)) ( (set-det) (is-value $X $Y))) +; + (= (show $Th (Cons $G $Gs)) ( (set-det) (show $Th $G) (show $Th $Gs))) +; + (= (show $Th $G) ( (db-entry $Th $G $B) (show $Th $B))) +; + (= (show $Th $G) ( (def-theory $Th $ThList) (member $SubTh $ThList) (show $SubTh $G))) +; + (= (show $_ $G) ( (predicate-property $G built-in) (set-det) (call $G))) +; + (= (show $_ $G) ( (predicate-property $G unknown) (dynamic $G) (fail))) +; + (= (show $_ $G) - ( (not (get-atoms &self (= $G $_))) + ( (not (get-symbols &self (= $G $_))) (call $G) (set-det))) +; + (= @@ -698,19 +676,27 @@ ( (var $X) (var $Y) (set-det))) +; + (= (is-value $X $_) ( (var $X) (set-det) (fail))) +; + (= (is-value $_ $Y) ( (var $Y) (set-det) (fail))) +; + (= (is-value $X $X) ( (atomic $X) (set-det))) +; + (= (is-value (Cons $Head1 $Tail1) @@ -718,6 +704,8 @@ ( (set-det) (is-value $Head1 $Head2) (is-value $Tail1 $Tail2))) +; + (= (is-value $X $Y) ( (not (atomic $X)) @@ -728,6 +716,8 @@ (Cons $F $ArgsY)) (set-det) (is-value $ArgsX $ArgsY))) +; + (= @@ -735,42 +725,13 @@ (variable $G) ($G) $G2 ($G2)) True) -; /******************************************************************/ - -; /* Variable handling procedures */ - -; /******************************************************************/ - -; /* */ - -; /* call : copy_vars(+G,+LVars,-G2,-LVars2) */ - -; /* */ - -; /* arguments : G = ground term */ - -; /* LVars = list of variables in G */ - -; /* G2 = variablelized term */ - -; /* LVars2 = list of variables in G2 */ - -; /* */ - -; /******************************************************************/ - -; /* 'copy_vars' sets G2 to a copy of G with all variables of the */ - -; /* form 'variable()' replaced with uninstantiated MeTTa */ - -; /* variables. */ - -; /******************************************************************/ - +; (= (copy-vars $G Nil $G Nil) (atomic $G)) +; + (= (copy-vars $G $LVars $G2 $LVars2) ( (=.. $G @@ -778,10 +739,14 @@ (copy-vars-list $Args Nil $LVars $Args2 Nil $LVars2) (=.. $G2 (Cons $F $Args2)))) +; + (= (copy_vars_list () $LVars $LVars () $LVars2 $LVars2) True) +; + (= (copy-vars-list (Cons $A $As) $PV $LV @@ -789,15 +754,21 @@ ( (copy-vars $A $AVL $A2 $AVL2) (join-vars $AVL $PV $PVplus $AVL2 $PV2 $PV2plus) (copy-vars-list $As $PVplus $LV $A2s $PV2plus $LV2))) +; + (= (join_vars () $PV $PV () $PV2 $PV2) True) +; + (= (join-vars (Cons $X $AVL) $PVin $PVout (Cons $X2 $AVL2) $PV2in $PV2out) ( (twin-member $X $PVin $X2 $PV2in) (join-vars $AVL $PVin $PVout $AVL2 $PV2in $PV2out))) +; + (= (join-vars (Cons $X $AVL) $PVin $PVout @@ -805,17 +776,23 @@ (join-vars $AVL (Cons $X $PVin) $PVout $AVL2 (Cons $X2 $PV2in) $PV2out)) +; + (= (twin_member $Var (Cons $Var $_) $Val (Cons $Val $_)) True) +; + (= (twin-member $Var (Cons $_ $Tail1) $Val (Cons $_ $Tail2)) (twin-member $Var $Tail1 $Val $Tail2)) +; + (= @@ -826,65 +803,17 @@ (val (variable $X) $X2) $Conditions)) (link-vals $LV $LV2 $Conditions)) -; /******************************************************************/ - -; /* */ - -; /* call : link_vals(+LVars1,+LVars2,-Cond) */ - -; /* */ - -; /* arguments : LVars1 = list of atomic ground terms */ - -; /* LVars2 = list of terms (can be MeTTa variables)*/ - -; /* Cond = combined substitution */ - -; /* */ - -; /******************************************************************/ - -; /* 'link_vals' combines each corresponding varible name in LVars1 */ - -; /* with its value in LVars2, to form a list of substituitions of */ - -; /* the form val(,). */ - -; /******************************************************************/ - +; (= (link_vals () () ()) True) +; + (= (set_vars $Goal () $Goal) True) -; /******************************************************************/ - -; /* */ - -; /* call : set_vars(+Goal1,+Cond,-Goal2) */ - -; /* */ - -; /* arguments : Goal1 = a ground goal */ - -; /* Cond = a substitution */ - -; /* Goal2 = Goal1 with substituted variables */ - -; /* */ - -; /******************************************************************/ - -; /* 'set_vars' substitutes variables depicted by 'variable()'*/ - -; /* in Goal1 by its value in Goal2, according to the substitution */ - -; /* Cond. */ - -; /******************************************************************/ - +; (= (set-vars $Goal @@ -896,13 +825,19 @@ (variable $Var) $Val $Goal2) (set-det) (set-vars $Goal2 $Rest $ResultGoal))) +; + (= (substitute $Var $Var $Val $Val) True) +; + (= (substitute $Goal $_ $_ $Goal) ( (atomic $Goal) (set-det))) +; + (= (substitute (Cons $Arg $Tail) $Var $Val @@ -910,6 +845,8 @@ ( (set-det) (substitute $Arg $Var $Val $NewArg) (substitute $Tail $Var $Val $NewTail))) +; + (= (substitute $Goal $Var $Val $FinalGoal) ( (=.. $Goal @@ -917,6 +854,8 @@ (substitute $Args $Var $Val $NewArgs) (=.. $FinalGoal (Cons $F $NewArgs)))) +; + (= @@ -924,47 +863,26 @@ ( (var $Variable) (set-det) (fail))) -; /******************************************************************/ - -; /* */ - -; /* call : all_ground_term(+Term) */ - -; /* */ - -; /* arguments : Term = a MeTTa term */ - -; /* */ - -; /******************************************************************/ - -; /* 'all_ground_term' succeeds if Term is ground, i.e. all vari- */ - -; /* ables are instantiated. Modification note: In YAP-MeTTa */ - -; /* all_ground_term(Term) :- ground(Term). */ - -; /* and in any other DEC10-MeTTa dialects */ - -; /* all_ground_term(Term) :- numbervars(Term,0,0). */ - -; /* can be used to speed up the system */ - -; /******************************************************************/ - +; (= (all-ground-term $Atomic) ( (atomic $Atomic) (set-det))) +; + (= (all-ground-term (Cons $Head $Tail)) ( (set-det) (all-ground-term $Head) (all-ground-term $Tail))) +; + (= (all-ground-term $Structure) ( (=.. $Structure (Cons $_ $Args)) (all-ground-term $Args))) +; + (= @@ -973,19 +891,27 @@ (write ' *** Only ground terms in goal allowed !') (set-det) (fail))) +; + (= (check-goal $Goal) ( (not (proper-variable $Goal)) (write ' *** of any variable() should be symbolic ground !') (set-det) (fail))) +; + (= (check_goal $_) True) +; + (= (proper-variable $Atom) ( (atomic $Atom) (set-det))) +; + (= (proper-variable (variable $Name)) ( (not (atomic $Name)) @@ -995,15 +921,21 @@ (nl) (set-det) (fail))) +; + (= (proper-variable (Cons $Head $Tail)) ( (set-det) (proper-variable $Head) (proper-variable $Tail))) +; + (= (proper-variable $Structure) ( (=.. $Structure (Cons $_ $Args)) (proper-variable $Args))) +; + (= @@ -1012,6 +944,8 @@ (write ' *** Only ground terms in conditions allowed !') (set-det) (fail))) +; + (= (check-conditions $Cond) ( (not (proper-format $Cond)) @@ -1020,20 +954,30 @@ (write ' or a list of structures, val(variable(),) !') (set-det) (fail))) +; + (= (check_conditions $_) True) +; + (= (proper_format ()) True) +; + (= (proper-format (Cons (val (variable $Atom) $_) $Tail)) ( (atomic $Atom) (proper-format $Tail))) +; + (= (make-ground-term $Body3) (make-ground-term 10 $Body3)) +; + (= (make-ground-term $D $Variable) @@ -1042,9 +986,13 @@ (= $Variable (variable $X)) (set-det))) +; + (= (make-ground-term $D $Atom) ( (atomic $Atom) (set-det))) +; + (= (make-ground-term $D $_) ( (== $D 0) @@ -1052,6 +1000,8 @@ (:: (make-ground-term $D $_))) (set-det) (fail))) +; + (= (make-ground-term $D (Cons $Head $Tail)) @@ -1061,8 +1011,7 @@ (make-ground-term $D2 $Head) (set-det) (make-ground-term $D2 $Tail))) -; ; \+ is_list(Head), - +; (= (make-ground-term $D $Structure) @@ -1073,65 +1022,31 @@ (=.. $Structure (Cons $_ $Args)) (make-ground-term $D2 $Args))) +; + (= (no_new_values ()) True) -; /******************************************************************/ - -; /* */ - -; /* call : no_new_values(+List) */ - -; /* */ - -; /* arguments : List = a MeTTa list */ - -; /* */ - -; /******************************************************************/ - -; /* 'no_new_values' succeeds if List is a list of uninstantiated */ - -; /* variables. */ - -; /******************************************************************/ - +; (= (no-new-values (Cons $X $Xs)) ( (var $X) (no-new-values $Xs))) +; + (= (identified-vars (Cons $X $Xs)) ( (member $Y $Xs) (same-var $X $Y))) -; /******************************************************************/ - -; /* */ - -; /* call : identified_vars(+List) */ - -; /* */ - -; /* arguments : List = a list of variables */ - -; /* */ - -; /******************************************************************/ - -; /* 'identified_vars' succeeds if there exists at least one vari- */ - -; /* able in the List, which has been 'unified' with another vari- */ - -; /* able in the list. */ - -; /******************************************************************/ - +; (= (identified-vars (Cons $_ $T)) (identified-vars $T)) +; + (= @@ -1139,42 +1054,18 @@ ( (var $Y) (set-det) (fail))) -; /******************************************************************/ - -; /* */ - -; /* call : same_var(+Var1,+Var2) */ - -; /* */ - -; /* arguments : Var1 = a MeTTa variable */ - -; /* Var2 = a MeTTa variable */ - -; /* */ - -; /******************************************************************/ - -; /* 'same_var' succeeds if Var1 and Var2 are unified, but uninstan-*/ - -; /* tiated. */ - -; /******************************************************************/ - +; (= (same-var $X $Y) ( (var $X) (var $Y))) +; + (= (digits_of_next_sym "1") True) -; /******************************************************************/ - -; /* Miscelenous predicates */ - -; /******************************************************************/ - +; @@ -1185,10 +1076,12 @@ (append "sym" $RLN $LS) (name $X $LS) (inc-digits $LN $LN2) - (remove-atom &self + (remove-symbol &self (digits_of_next_sym $LN)) - (add-atom &self + (add-symbol &self (digits_of_next_sym $LN2)))) +; + (= @@ -1196,14 +1089,20 @@ (Cons $D1 $LDT) (Cons $D2 $LDT)) ( (< $D1 57) (is $D2 (+ $D1 1)))) +; + (= (inc-digits (Cons $_ $LDT) (Cons 48 $LDT2)) (inc-digits $LDT $LDT2)) +; + (= (inc_digits () (49)) True) +; + (= @@ -1211,8 +1110,12 @@ (Cons $H $T) $V $R) (revzap $T (Cons $H $V) $R)) +; + (= (revzap () $R $R) True) +; + (= @@ -1221,6 +1124,8 @@ (rcl $C $L) (extract-space $L $L1) (convert $W $L1))) +; + (= @@ -1228,34 +1133,48 @@ ( (repeat) (get0 $C) (non-space $C))) +; + (= (rcl 10 ()) True) +; + (= (rcl $C1 (Cons $C1 $P)) ( (proper-char $C1) (get0 $C2) (rcl $C2 $P))) +; + (= (rcl $C1 (Cons $C1 $P)) ( (space $C1) (get0 $C2) (rcl $C2 $P))) +; + (= (rcl $C1 $L) ( (put 7) (get0 $C2) (rcl $C2 $L))) +; + (= (convert () ()) True) +; + (= (convert $W $L) (name $W $L)) +; + (= @@ -1263,28 +1182,42 @@ ( (space $C) (set-det) (fail))) +; + (= (non-space 10) ( (set-det) (fail))) +; + (= (non-space $C) (proper-char $C)) +; + (= (non-space $_) ( (put 7) (set-det) (fail))) +; + (= (space 32) True) +; + (= (space 9) True) +; + (= (proper-char $C) ( (> $C 32) (< $C 128))) +; + (= @@ -1292,21 +1225,31 @@ ( (reverse $L $R) (delete-space $R $R2) (reverse $R2 $L2))) +; + (= (delete-space (Cons $S $T) $L) ( (space $S) (delete-space $T $L))) +; + (= (delete_space $L $L) True) +; + (= (reverse () ()) True) +; + (= (reverse (Cons $X $Y) $Z) ( (reverse $Y $Y1) (append $Y1 (:: $X) $Z))) +; + diff --git a/multagnt/teacher.metta b/multagnt/teacher.metta index 71254d6..c3a9d21 100644 --- a/multagnt/teacher.metta +++ b/multagnt/teacher.metta @@ -1,9 +1,9 @@ ; -; The knowledge of the teacher about different topics +; ; -; Fact theory +; @@ -11,49 +11,71 @@ (db_entry (: teacher gilchrist_family) (parent euan warren) ()) True) +; + (= (db_entry (: teacher gilchrist_family) (parent berenice warren) ()) True) +; + (= (db_entry (: teacher gilchrist_family) (parent warren catherine) ()) True) +; + (= (db_entry (: teacher gilchrist_family) (parent warren charles) ()) True) +; + (= (db_entry (: teacher gilchrist_family) (parent warren david) ()) True) +; + (= (db_entry (: teacher gilchrist_family) (parent warren julia) ()) True) +; + (= (db_entry (: teacher gilchrist_family) (parent kate catherine) ()) True) +; + (= (db_entry (: teacher gilchrist_family) (parent kate charles) ()) True) +; + (= (db_entry (: teacher gilchrist_family) (parent kate david) ()) True) +; + (= (db_entry (: teacher gilchrist_family) (parent kate julia) ()) True) +; + (= (db_entry (: teacher gilchrist_family) (parent charles lucinda) ()) True) +; + ; -; Fact and Rule Theory +; @@ -63,51 +85,75 @@ ( (: teacher warm) (: teacher cold) (: teacher door))) True) +; + (= (db_entry (: teacher warm) (warm kitchen) ()) True) +; + (= (db_entry (: teacher warm) (warm living_room) ()) True) +; + (= (db_entry (: teacher cold) (cold fridge) ()) True) +; + (= (db_entry (: teacher cold) (cold street) ()) True) +; + (= (db_entry (: teacher cold) (cold garden) ()) True) +; + (= (db_entry (: teacher door) (door living_room kitchen) ()) True) +; + (= (db_entry (: teacher door) (door living_room street) ()) True) +; + (= (db_entry (: teacher door) (door living_room garden) ()) True) +; + (= (db_entry (: teacher door) (door kitchen garden) ()) True) +; + (= (db_entry (: teacher door) (door kitchen fridge) ()) True) +; + (= (db_entry (: teacher door) (door street garden) ()) True) +; + (= (db_entry (: teacher entropy) @@ -115,6 +161,8 @@ ( (warm $A) (cold $B) (door $A $B))) True) +; + (= (db_entry (: teacher entropy) @@ -122,6 +170,8 @@ ( (cold $A) (warm $B) (door $A $B))) True) +; + (= (db_entry (: teacher entropy) @@ -129,6 +179,8 @@ ( (warm $A) (cold $B) (door $B $A))) True) +; + (= (db_entry (: teacher entropy) @@ -136,9 +188,11 @@ ( (cold $A) (warm $B) (door $B $A))) True) +; + ; -; Recusive Theory +; (= @@ -146,17 +200,23 @@ (: teacher t_member) (member $A (Cons $A $_)) ()) True) +; + (= (db_entry (: teacher t_member) (member $A (Cons $_ $B)) ( (member $A $B))) True) +; + (= (db_entry (: teacher t_append) (append () $List $List) ()) True) +; + (= (db_entry (: teacher t_append) @@ -164,34 +224,46 @@ (Cons $First $Rest) $List (Cons $First $TempList)) ( (append $Rest $List $TempList))) True) +; + (= (def_theory (: teacher t_reverse) ( (: teacher t_append))) True) +; + (= (db_entry (: teacher t_reverse) (reverse () ()) ()) True) +; + (= (db_entry (: teacher t_reverse) (reverse (Cons $X $Y) $Z) ( (reverse $Y $Y1) (append $Y1 ($X) $Z))) True) +; + (= (def_theory (: teacher qsort) ( (: teacher partition) (: teacher t_append))) True) +; + (= (db_entry (: teacher qsort) (qsort () ()) ()) True) +; + (= (db_entry (: teacher qsort) @@ -202,11 +274,15 @@ (qsort $L2 $L4) (append $L3 (Cons $X $L4) $L5))) True) +; + (= (db_entry (: teacher partition) (partition () $_ () ()) ()) True) +; + (= (db_entry (: teacher partition) @@ -214,6 +290,8 @@ (Cons $X $L) $Y (Cons $X $L1) $L2) ( (< $X $Y) (partition $L $Y $L1 $L2))) True) +; + (= (db_entry (: teacher partition) @@ -221,4 +299,6 @@ (Cons $X $L) $Y $L1 (Cons $X $L2)) ( (>= $X $Y) (partition $L $Y $L1 $L2))) True) +; + diff --git a/nars_lp/nars/agent.metta b/nars_lp/nars/agent.metta index f1289ae..71d64be 100644 --- a/nars_lp/nars/agent.metta +++ b/nars_lp/nars/agent.metta @@ -1,6 +1,8 @@ !(module agent Nil) +; + @@ -8,11 +10,15 @@ (= (rule-set $RuleSet $MaxRuleID) ( (= $MaxRuleID 7) (= $RuleSet (:: (:: 1 def-father-1 (:: (- (:: child $Y $X)) (- (:: male $X)) (+ (:: father $X $Y)))) (:: 2 def-mother-1 (:: (- (:: child $Y $X)) (- (:: female $X)) (+ (:: mother $X $Y)))) (:: 3 def-parent-1 (:: (- (:: father $X $Y)) (+ (:: parent $X $Y)))) (:: 4 def-parent-2 (:: (- (:: mother $X $Y)) (+ (:: parent $X $Y)))) (:: 5 fact-lucy-1 (:: (+ (:: female lucy)))) (:: 6 fact-alice-1 (:: (+ (:: child alice bob)))) (:: 7 fact-bob-1 (:: (+ (:: child bob lucy)))))))) +; + (= (symbol-set $SymbolSet $MaxSymbolID) ( (= $MaxSymbolID 10) (= $SymbolSet (:: (:: 1 vble) (:: 2 father) (:: 3 child) (:: 4 male) (:: 5 female) (:: 6 parent) (:: 7 lucy) (:: 8 alice) (:: 9 bob) (:: 10 mother))))) +; + @@ -35,6 +41,8 @@ (:: -0.2 0.2)) (= $NNet (:: layer1 layer2 layer3 layer4 layer5 layer6)))) +; + (= @@ -77,6 +85,8 @@ (nl) (print-by-line $Path4) (nl))) +; + diff --git a/nars_lp/nars/nal.metta b/nars_lp/nars/nal.metta index 53b0bf6..0379a9f 100644 --- a/nars_lp/nars/nal.metta +++ b/nars_lp/nars/nal.metta @@ -1,27 +1,37 @@ ; -; nal.pl +; ; -; Non-Axiomatic Logic in MeTTa +; ; -; Version: 1.1, September 2012 +; ; -; GNU Lesser General Public License +; ; -; Author: Pei Wang/Pat Hammer/Douglas Miles +; !(module nal Nil) +; + !(set-module (class library)) +; + !(set-module (base system)) +; - !(use-module (library (/ nars nal-reader))) + + !(use-module (library (/ nars nal-reader))) +; + !(ensure-loaded nars) +; + diff --git a/nars_lp/nars/nal_reader.metta b/nars_lp/nars/nal_reader.metta index 722f59d..1a014df 100644 --- a/nars_lp/nars/nal_reader.metta +++ b/nars_lp/nars/nal_reader.metta @@ -1,8 +1,8 @@ ; -; nal_reader.pl +; ; -; Read Non_Axiomatic Logic from MeTTa +; !(module nal-reader (:: @@ -12,20 +12,29 @@ (/ nal-test 1) (/ nal-read-clause 2) (/ nal-call 3))) -; ; nal_test/2, - -; ; nal_call/2, - +; !(set-module (class library)) +; + !(set-module (base system)) +; + !(use-module (library logicmoo-common)) +; + !(use-module (library (/ logicmoo dcg-meta))) +; + !(use-module (library (/ logicmoo dcg-must))) +; + !(use-module (library narsese)) +; + @@ -37,86 +46,7 @@ (, ! (, (nal_task $S) !)))) True) -; /* -; task ::= [budget] sentence (* task to be processed *) -; -; sentence ::= statement"." [tense] [truth] (* judgement to be absorbed into beliefs *) -; | statement"?" [tense] [truth] (* question on thuth-value to be answered *) -; | statement"!" [desire] (* goal to be realized by operations *) -; | statement"@" [desire] (* question on desire-value to be answered *) -; -; statement ::= <"<">term copula term<">"> (* two terms related to each other *) -; | <"(">term copula term<")"> (* two terms related to each other, new notation *) -; | term (* a term can name a statement *) -; | "(^"word {","term} ")" (* an operation to be executed *) -; | word"("term {","term} ")" (* an operation to be executed, new notation *) -; -; copula ::= "-->" (* inheritance *) -; | "<->" (* similarity *) -; | "{--" (* instance *) -; | "--]" (* property *) -; | "{-]" (* instance-property *) -; | "==>" (* implication *) -; | "=/>" (* predictive implication *) -; | "=|>" (* concurrent implication *) -; | "=\\>" (* =\> retrospective implication *) -; | "<=>" (* equivalence *) -; | "" (* predictive equivalence *) -; | "<|>" (* concurrent equivalence *) -; -; term ::= word (* an atomic constant term *) -; | variable (* an atomic variable term *) -; | compound-term (* a term with internal structure *) -; | statement (* a statement can serve as a term *) -; -; compound-term ::= op-ext-set term {"," term} "}" (* extensional set *) -; | op-int-set term {"," term} "]" (* intensional set *) -; | "("op-multi"," term {"," term} ")" (* with prefix operator *) -; | "("op-single"," term "," term ")" (* with prefix operator *) -; | "(" term {op-multi term} ")" (* with infix operator *) -; | "(" term op-single term ")" (* with infix operator *) -; | "(" term {","term} ")" (* product, new notation *) -; | "(" op-ext-image "," term {"," term} ")"(* special case, extensional image *) -; | "(" op-int-image "," term {"," term} ")"(* special case, \ intensional image *) -; | "(" op-negation "," term ")" (* negation *) -; | op-negation term (* negation, new notation *) -; -; op-int-set::= "[" (* intensional set *) -; op-ext-set::= "{" (* extensional set *) -; op-negation::= "--" (* negation *) -; op-int-image::= "\\" (* \ intensional image *) -; op-ext-image::= "/" (* extensional image *) -; op-multi ::= "&&" (* conjunction *) -; | "*" (* product *) -; | "||" (* disjunction *) -; | "&|" (* parallel events *) -; | "&/" (* sequential events *) -; | "|" (* intensional intersection *) -; | "&" (* extensional intersection *) -; op-single ::= "-" (* extensional difference *) -; | "~" (* intensional difference *) -; -; variable ::= "$"word (* independent variable *) -; | "#"word (* dependent variable *) -; | "?"word (* query variable in question *) -; -; tense ::= ":/:" (* future event *) -; | ":|:" (* present event *) -; | ":\\:" (* :\: past event *) -; -; desire ::= truth (* same format, different interpretations *) -; truth ::= <";">frequency[<";">confidence]<";"> (* two numbers in [0,1]x(0,1) *) -; budget ::= <"$">priority[<";">durability][<";">quality]<"$"> (* three numbers in [0,1]x(0,1)x[0,1] *) -; -; word : #"[^\ ]+" (* unicode string *) -; priority : #"([0]?\.[0-9]+|1\.[0]*|1|0)" (* 0 <= x <= 1 *) -; durability : #"[0]?\.[0]*[1-9]{1}[0-9]*" (* 0 < x < 1 *) -; quality : #"([0]?\.[0-9]+|1\.[0]*|1|0)" (* 0 <= x <= 1 *) -; frequency : #"([0]?\.[0-9]+|1\.[0]*|1|0)" (* 0 <= x <= 1 *) -; confidence : #"[0]?\.[0]*[1-9]{1}[0-9]*" (* 0 < x < 1 *) -; occurrenceTime: -; */ - +; (= (--> @@ -129,6 +59,8 @@ { (= $OUT (nal_in $TASK $V3)) }) { (= $OUT $TASK) }))) True) +; + (= (--> @@ -137,8 +69,10 @@ (, (optional $B nal_budget) (, ! - (nal_sentence $X $S $T $O)))) True) ; -; task to be processed + (nal_sentence $X $S $T $O)))) True) +; + ; +; @@ -148,6 +82,8 @@ (, (nal_statement $S) (nal_post_statement $X $T $O))) True) +; + (= (--> @@ -181,26 +117,11 @@ (-> (optional $T nal_tense) (optional $O nal_desire))))))) True) -; /*nal_statement(S),*/ - -; ; judgement to be absorbed into beliefs - -; /*nal_statement(S),*/ - -; ; question on truth_value to be answered - -; /*nal_statement(S),*/ - -; ; goal to be realized by operations - -; /*nal_statement(S),*/ - -; ; question on desire_value to be answered - +; ; -; nal_statement(nal_word(S))--> nal_word(S). +; (= (--> @@ -208,11 +129,15 @@ (, (amw (nal_statement_0 $S)) !)) True) +; + (= (--> (nal_statement_0 $S) (, cwhite (nal_statement_0 $S))) True) +; + (= (--> (nal_statement_0 $S) @@ -265,19 +190,10 @@ (nal_term_1 $X) { (= $S (nal_named_statement $X)) })))))) True) -; ; two terms related to each other - -; ; an operation to be executed - -; ; two terms related to each other, new notation - -; ; an operation to be executed, new notation - -; ; a term can name a statement(S) - +; ; -; nal_statement_0(S)-->nal_rsymbol(S). +; (= @@ -324,10 +240,7 @@ (61 62) $X unknown_implication) (nal_o (124 45) $X prolog_implication))))))))))))))) True) -; ; dmiles added - -; ; dmiles added - +; (= @@ -336,6 +249,8 @@ (, (nal_term_old $O) { (old_to_new $O $N) })) True) +; + (= (--> (nal_term_old $S) @@ -346,14 +261,7 @@ (; (nal_compound_term $S) (nal_statement $S))))) True) -; ; an atomic constant, term, - -; ; an atomic variable, term, - -; ; a term with internal structure - -; ; a statement can serve as a term, - +; @@ -363,6 +271,8 @@ (, (nal_term_0_old $O) { (old_to_new $O $N) })) True) +; + (= (--> (nal_term_0_old $S) @@ -373,14 +283,7 @@ (; (nal_compound_term_0 $S) (nal_statement_0 $S))))) True) -; ; an atomic constant, term, - -; ; an atomic variable, term, - -; ; a, term, with internal structure - -; ; a statement can serve as a, term, - +; (= @@ -390,6 +293,8 @@ (nal_term_1_old $O) (, { (old_to_new $O $N) } !))) True) +; + (= (--> (nal_term_1_old $S) @@ -398,12 +303,7 @@ (; (nal_variable $S) (nal_compound_term $S)))) True) -; ; an atomic constant, term, - -; ; an atomic variable, term, - -; ; a, term, with internal structure - +; @@ -417,6 +317,8 @@ (append $Left (Cons - $Right) $New) (set-det))) +; + (= (old-to-new (rel (Cons $R (Cons (var int $L) $B))) @@ -427,8 +329,12 @@ (append $Left (Cons - $Right) $New) (set-det))) +; + (= (old_to_new $X $X) True) +; + (= (--> @@ -436,6 +342,8 @@ (, (mw (nal_compound_term_0 $X)) !)) True) +; + (= (--> @@ -446,6 +354,8 @@ (, ! (, (nal_term_1 $S) !)))) True) +; + (= (--> (nal_compound_term_0 $S) @@ -456,6 +366,8 @@ (, ! (, (nal_compound_term_1 $S) !)))) True) +; + (= (--> (nal_compound_term_1 $S) @@ -495,14 +407,7 @@ (nal_paren_compound_term $X $L) nal_paren_r)))))) { (=.. $S ($X $L)) })) True) -; ; extensional set - -; ; intensional set - -; ; @TODO notation - -; ; negation, new notation - +; (= @@ -575,48 +480,43 @@ (, { (= $X product) } (nal_term_list_comma $L))))))))))) True) -; ; with prefix operator - -; ; with prefix operator - -; ; special case, extensional image - -; ; special case, \ intensional image - -; ; negation - -; ; with infix operator - -; ; with infix operator - -; ; product, new notation - +; (= (--> nal_op_int_set - (91)) True) ; -; intensional set + (91)) True) +; + ; +; (= (--> nal_op_ext_set - (123)) True) ; -; extensional set + (123)) True) +; + ; +; (= (--> nal_op_negation - (45 45)) True) ; -; negation + (45 45)) True) +; + ; +; (= (--> nal_op_int_image - (92)) True) ; -; \ intensional image + (92)) True) +; + ; +; (= (--> nal_op_ext_image - (47)) True) ; -; / extensional image + (47)) True) +; + ; +; @@ -626,8 +526,10 @@ (locally (b-setval whitespace preserve) (phrase $DCG $S $E))) +; + ; -; nal_no_preserve_whitespace(DCG,S,E) :- phrase(DCG,S,E). +; @@ -658,22 +560,7 @@ (124) $X int_intersection) (nal_o (38) $X ext_intersection))))))))) True) -; ; conjunction - -; ; product - -; ; disjunction - -; ; patham9 "sequence", wasn't really useful for NLP, it was called PART - -; ; parallel events - -; ; sequential events - -; ; intensional intersection - -; ; extensional intersection - +; (= (--> @@ -683,10 +570,7 @@ (45) $X ext_difference) (nal_o (126) $X int_difference))) True) -; ; extensional difference - -; ; intensional difference - +; (= @@ -696,6 +580,8 @@ (nal_variable_0 $V) (, ! (maybe_plus_array2 $V $VA)))) True) +; + (= (--> @@ -725,30 +611,27 @@ (nal_o (92) $X int) (nal_word_0 $W))))))) True) -; ; independent variable - -; ; dependent variable - -; ; query variable in question - -; ; query variable in params - -; ; query variable in .... - +; (= (--> (nal_variable_0 _) (95)) True) +; + (= (--> (nal_variable_0 #) (35)) True) +; + (= (--> (nal_variable_0 $) (36)) True) +; + (= @@ -762,12 +645,7 @@ (58 124 58) $X present) (nal_o (58 92 58) $X past)))) True) -; ; future event - -; ; present event - -; ; :\: past event - +; (= @@ -779,6 +657,8 @@ (, (number $X) (58)))) True) +; + (= (--> (nal_tense @@ -788,16 +668,20 @@ (, (nal_term_1 $X) (58)))) True) +; + ; -; Desire is same format of Truth, but different interpretations +; (= (--> (nal_desire $D) - (nal_truth $D)) True) + (nal_truth $D)) True) +; + ; -; Truth is two numbers in [0,1]x(0,1) +; (= (--> @@ -815,7 +699,9 @@ (nal_confidence $C))) (, (optional - (37)) !)))))) True) + (37)) !)))))) True) +; + (= (--> (nal_truth @@ -836,6 +722,8 @@ { (is_float_0_1 $F) } (, (125) !))))))))) True) +; + (= (--> (nal_truth @@ -843,8 +731,10 @@ (, (84 114 117 116 104 58) (read_nal_expected_truth $F $C))) True) +; + ; -; Budget is three numbers in optional(O,0,1]x(0,1)x[0,1] +; (= (--> @@ -865,18 +755,24 @@ (, (59) (nal_quality $Q))) - (36))))))) True) + (36))))))) True) +; + (= (is-float-0-1 $F) ( (=< 0.0 $F) (=< $F 1.0))) +; + (= (--> (nal_word $E) (amw (nal_word_0 $E))) True) +; + (= (--> @@ -887,24 +783,32 @@ (, (: dcg_basics (integer $E)) !))) True) +; + (= (--> (nal_word_0 $E) (, (: dcg_basics (number $E)) !)) True) +; + (= (--> (nal_word_0 $E) (, (quoted_string $E) !)) True) +; + (= (--> (nal_word_0 $E) (nal_word_str $E)) True) +; + ; -; nal_rsymbol(Chars,E) --> [C], {notrace(nal_sym_char(C))},!, nal_sym_continue(S), {append(Chars,[C|S],AChars),string_to_atom(AChars,E)},!. +; (= @@ -920,6 +824,8 @@ (nal_rsymbol $E) (, ! (maybe_plus_array $E $MaybeArray))))))) True) +; + (= (--> @@ -931,6 +837,8 @@ (, (mw (41)) !))) True) +; + (= (--> (maybe_plus_array2 $E @@ -942,9 +850,13 @@ (nal_term_list_comma $Ar) (, owhite (41)))))) True) +; + (= (--> (maybe_plus_array2 $E $E) ()) True) +; + (= (--> @@ -953,6 +865,8 @@ (\+ (dcg_peek (91))) !)) True) +; + (= (--> (maybe_plus_array $E @@ -964,38 +878,50 @@ (nal_term_list_comma $Ar) (, owhite (93)))))) True) +; + (= (--> (nal_priority $F) - (nal_float_inclusive 0 1 $F)) True) ; -; 0 <= x <= 1 + (nal_float_inclusive 0 1 $F)) True) +; + ; +; (= (--> (nal_durability $F) - (nal_float_exclusive 0 1 $F)) True) ; -; 0 < x < 1 + (nal_float_exclusive 0 1 $F)) True) +; + ; +; (= (--> (nal_quality $F) - (nal_float_inclusive 0 1 $F)) True) ; -; 0 <= x <= 1 + (nal_float_inclusive 0 1 $F)) True) +; + ; +; (= (--> (nal_frequency $F) - (nal_float_inclusive 0 1 $F)) True) ; -; 0 <= x <= 1 + (nal_float_inclusive 0 1 $F)) True) +; + ; +; (= (--> (nal_confidence $F) - (nal_float_exclusive 0 1 $F)) True) ; -; 0 < x < 1 + (nal_float_exclusive 0 1 $F)) True) +; + ; +; (= @@ -1003,10 +929,14 @@ (nal_o $S $X $X) (, owhite (, $S owhite))) True) +; + (= (--> (nal_o $X $X) (nal_o $X $X $X)) True) +; + (= (--> @@ -1019,6 +949,8 @@ (, (=< $L $F) (=< $F $H))) }))) True) +; + (= (--> (nal_float_exclusive $L $H $F) @@ -1030,23 +962,33 @@ (, (< $L $F) (< $F $H))) }))) True) +; + (= (nal-warn-if-strict $G) ( (call $G) (set-det))) +; + (= (nal-warn-if-strict $G) ( (nal-dmsg (nal-warn-if-strict $G)) (set-det))) +; + !(set-dcg-meta-reader-options file-comment-reader nal-comment-expr-unused) +; + (= (--> (nal_comment_expr_unused $_) { (, ! fail) }) True) +; + (= (--> @@ -1054,12 +996,16 @@ (, chspace (, ! (nal_comment_expr $X)))) True) +; + (= (--> (nal_comment_expr ($COMMENT $Expr $I $CP)) (, (nal_comment_expr_3 $Expr $I $CP) !)) True) +; + (= (--> @@ -1078,6 +1024,8 @@ (, ! (, { (text_to_string_safe $S $T) } !)))))))) True) +; + (= (--> (nal_comment_expr_3 $T $N $CharPOS) @@ -1096,6 +1044,8 @@ (, ! (, { (text_to_string_safe $S $T) } !))))))))) True) +; + @@ -1106,6 +1056,8 @@ (\+ (dcg_peek (101 120 112 101 99 116 101 100 58))))) True) +; + (= (nal_cmt_until_eoln (, @@ -1117,9 +1069,13 @@ (dcg_peek (\+ (39 32 65 110 115 119 101 114 32)))))) True) +; + (= (nal_cmt_until_eoln (42 42)) True) +; + @@ -1127,14 +1083,20 @@ (--> nal_comma (amw (44))) True) +; + (= (--> nal_l_paren (amw (40))) True) +; + (= (--> nal_paren_r (amw (41))) True) +; + (= (--> @@ -1148,6 +1110,8 @@ (nal_term_list_white $T $Sep)) (, { (= $T ()) } owhite)))) True) +; + (= (--> (nal_term_list_comma @@ -1158,18 +1122,30 @@ (-> nal_comma (nal_term_list_comma $T)) { (= $T ()) }))) True) +; + (= (builtin_symbol _) True) +; + (= (builtin_symbol --) True) +; + (= (builtin_symbol ~) True) +; + (= (builtin_symbol *) True) +; + (= (builtin_symbol key_101) True) +; + @@ -1181,10 +1157,14 @@ (builtin_symbol $S) (name $S $Str)) } (, $Str !))) True) +; + (= (--> (nal_rsymbol $E) (nal_rsymbol () $E)) True) +; + (= (--> (nal_rsymbol $Chars $E) @@ -1200,11 +1180,15 @@ { (, (append $Chars (Cons $C $S) $AChars) - (string_to_atom $AChars $E)) } !)))))) True) + (string_to_symbol $AChars $E)) } !)))))) True) +; + (= (--> (nal_sym_continue ()) (, nal_peek_symbol_breaker !)) True) +; + (= (--> (nal_sym_continue @@ -1215,14 +1199,20 @@ { (nal_sym_char $H) } (, ! (nal_sym_continue $T))))) True) +; + (= (--> (nal_sym_continue ()) ()) True) +; + (= (--> nal_peek_symbol_breaker (dcg_peek (45 45))) True) +; + (= (--> nal_peek_symbol_breaker (, @@ -1230,9 +1220,13 @@ (45)) (, ! {fail }))) True) +; + (= (--> nal_peek_symbol_breaker (dcg_peek one_blank)) True) +; + (= (--> nal_peek_symbol_breaker (, @@ -1241,6 +1235,8 @@ (, { (\+ (nal_sym_char $C)) } !))) True) +; + (= @@ -1250,41 +1246,53 @@ (char-code $C $D) (set-det) (nal-sym-char $D))) +; + (= (nal-sym-char $C) ( (= (:: $C) (:: 95)) (set-det))) +; + (= (nal-sym-char $C) ( (bx (=< $C 32)) (set-det) (fail))) +; + ; -; nal_sym_char(44). ; allow comma in middle of symbol +; ; -; word is: #"[^\ ]+" ; unicode string +; (= (nal-sym-char $C) ( (nal-never-symbol-char $NeverSymbolList) (memberchk $C $NeverSymbolList) (set-det) - (fail))) ; -; maybe 44 ? nal_comma + (fail))) +; + ; +; ; -; nal_sym_char(C):- nb_current('$maybe_string',t),memberchk(C,`,.:;!;`),!,fail. +; (= (nal-sym-char $_) (set-det)) +; + (= (nal_never_symbol_char (34 59 40 41 126 39 91 93 33 60 62 96 123 125 44 61 46 92 94)) True) +; + @@ -1296,20 +1304,26 @@ (, { (, (append $Prepend $S $AChars) - (string_to_atom $AChars $E)) } !))) True) + (string_to_symbol $AChars $E)) } !))) True) +; + (= (nal-is-test-file $X) ( (filematch - (library ../nal-tests/**/*) $X) (not (nal-non-file $X)))) + (library ../nal-tests/**/*) $X) (not (nal-non-file $X)))) +; + (= (nal-is-test-file $X) ( (filematch (library ../examples/**/*) $X) (atom-contains $X nars) - (not (nal-non-file $X)))) + (not (nal-non-file $X)))) +; + (= (nal-non-file $X) @@ -1317,20 +1331,30 @@ (\== $X $DC) (set-det) (nal-non-file $DC))) +; + (= (nal-non-file $X) (atom-contains readme $X)) +; + (= (nal-non-file $X) (exists-directory $X)) +; + (= (nal-non-file $X) (atom-concat $_ .pl $X)) +; + (= (nal-test-files) ( (make) (catch (forall (nal-is-test-file $X) (, (nal-dmsg (test-file-begin $X)) (ignore (nal-do-test-file $X)) (nal-dmsg (test-file-end $X)))) %aborted True))) +; + (= @@ -1343,15 +1367,19 @@ (filematch $File $Absolute) (set-det) (nal-do-test-file $Absolute))) +; + (= (nal-do-test-file $File) (setup-call-cleanup (open $File read $In) (nal-do-test-stream $In) (close $In))) +; + ; -; Whole Group +; (= @@ -1359,11 +1387,13 @@ ( (nal-read-clauses $In $Expr) (set-det) (nars-exec-ex $Expr))) +; + ; -; One at a time +; ; -; nal_do_test_stream(In):- repeat, nal_read_clause(In,Expr), nars_exec_ex(Expr), Expr==end_of_file. +; @@ -1372,16 +1402,13 @@ ( (is-list $O) (set-det) (in-cmt (maplist print-tree-nl $O)))) -; /* -; must_or_rtrace(nal_call(nal_do_test_file,Expr,OutL)),!, -; flatten([OutL],Out), -; maplist(nal_dmsg,Out),!. -; */ - +; (= (nal-dmsg $O) ( (format ~N) (in-cmt (print-tree-nl $O)))) +; + (= @@ -1390,26 +1417,28 @@ (, cspace (, ! (amw $A)))) True) +; + (= (--> (amw $A) (, $A (more_cspace chspace))) True) +; + ; -; chspace--> `,`,dcg_peek(chspace),!. +; (= (--> chspace cspace) True) +; + (= (--> aspaces (, chspace (more_aspace chspace))) True) -; /* -; chspace--> `,`,!. -; chspace--> [C],{char_type(C,white)}. -; */ - +; (= (--> @@ -1417,9 +1446,13 @@ (, $P (, ! (more_aspace $P)))) True) +; + (= (--> (more_aspace $_) ()) True) +; + (= (--> @@ -1427,12 +1460,16 @@ (, $P (, ! (more_cspace $P)))) True) +; + (= (--> (more_cspace $_) ()) True) +; + ; -; NAL file reader +; (= (--> @@ -1440,23 +1477,31 @@ (, { (retract (: t_l - ($last_comment $CMT))) } !)) True) + (%last_comment $CMT))) } !)) True) +; + (= (--> (nal_file end_of_file) (, file_eof !)) True) +; + (= (--> (nal_file $O) (, eoln (, ! (nal_file $O)))) True) +; + (= (--> (nal_file $O) (, chspace (, ! (nal_file $O)))) True) +; + (= (--> (nal_file ()) @@ -1464,8 +1509,10 @@ (\+ (dcg_peek ($_))) !)) True) +; + ; -; nal_file(O) --> nal_file_element(O), !, owhite. +; (= (--> @@ -1476,8 +1523,10 @@ (phrase (, (nal_file_element $O) owhite) $Str) !) })) True) +; + ; -; fallback to english in a file +; (= (--> @@ -1486,7 +1535,7 @@ (, (read_string_until_no_esc $Str eoln) { (, - (atom_string $Str $TextStr) + (symbol_string $Str $TextStr) (, { (, (format '~N%~~ ') @@ -1494,19 +1543,21 @@ (ansifmt (red) $TextStr) nl)) } (split_string $TextStr "" " \t\r\n" $Text))) })) True) +; + ; -; nal_file(planStepLPG(Name,Expr,Value)) --> owhite,sym_or_num(Name),`:`,owhite, nal(Expr),owhite, `[`,sym_or_num(Value),`]`,owhite. ; 0.0003: (PICK-UP ANDY IBM-R30 CS-LOUNGE) [0.1000] +; ; -; nal_file(Term,Left,Right):- eoln(EOL),append(LLeft,[46,EOL|Right],Left),read_term_from_codes(LLeft,Term,[double_quotes(string),syntax_errors(fail)]),!. +; ; -; nal_file(Term,Left,Right):- append(LLeft,[46|Right],Left), ( \+ member(46,Right)),read_term_from_codes(LLeft,Term,[double_quotes(string),syntax_errors(fail)]),!. +; ; -; non-standard +; (= (--> @@ -1514,6 +1565,8 @@ (, chspace (, ! (nal_file_element $O)))) True) +; + (= (--> (nal_file_element @@ -1524,7 +1577,9 @@ (read_string_until $Str eoln) (, ! { (phrase - (read_nal_expected $O) $Str) })))) True) + (read_nal_expected $O) $Str) })))) True) +; + (= (--> (nal_file_element @@ -1536,8 +1591,10 @@ (nal_file_element $O)) (, (39 41) !)))) True) +; + ; -; nal_file_element(outputMustContain(O)) --> `''outputMustContain('`, !, read_string_until(Str,`')`),`')`,{fmt(Str),phrase(nal_file_element(O),Str,[])}. +; (= (--> @@ -1550,13 +1607,17 @@ (, (123) eoln)) { (phrase - (nal_task $O) $Str ()) }))) True) + (nal_task $O) $Str ()) }))) True) +; + (= (--> (nal_file_element $Comment) (, (nal_comment_expr $Comment) !)) True) +; + (= (--> @@ -1570,6 +1631,8 @@ (amw (61)) (nal_term $V))))) True) +; + (= (--> (nal_file_element @@ -1580,6 +1643,8 @@ (nal_task_0 $H) (optional (nal_three_vals $V3))))) True) +; + (= (--> (nal_file_element @@ -1590,8 +1655,10 @@ (nal_task_0 $H) (optional (nal_three_vals $V3))))) True) +; + ; -; standard +; (= (--> @@ -1600,26 +1667,36 @@ (, (: dcg_basics (number $N)) !)) True) +; + (= (--> (nal_file_element $H) (, (nal_task $H) !)) True) +; + (= (--> (nal_file_element (nal_term $H)) (nal_term $H)) True) +; + ; -; nal_read_clause("'the detective claims that tim lives in graz",A) +; (= (--> ospace (, chspace (, ! ospace))) True) +; + (= (--> ospace ()) True) +; + (= (--> @@ -1627,6 +1704,8 @@ (, chspace (, ! (read_nal_expected $O)))) True) +; + (= (--> (read_nal_expected @@ -1634,17 +1713,23 @@ (, (read_nal_expected_ele $H) (read_nal_expected $T))) True) +; + (= (--> (read_nal_expected ()) ()) True) +; + (= (--> (read_nal_expected_ele $O) (, chspace (, ! (read_nal_expected_ele $O)))) True) +; + ; -; ^say executed with args ({SELF} * bedroom) +; (= (--> @@ -1657,6 +1742,8 @@ (101 120 101 99 117 116 101 100 32 119 105 116 104 32 97 114 103 115) (amw (nal_term $A))))) True) +; + (= (--> (read_nal_expected_ele @@ -1664,6 +1751,8 @@ (, (65 110 115 119 101 114 58) (nal_file_element $O))) True) +; + (= (--> (read_nal_expected_ele @@ -1673,6 +1762,8 @@ (, ospace (: dcg_basics (number $T))))) True) +; + (= (--> (read_nal_expected_ele @@ -1680,6 +1771,8 @@ (, (84 114 117 116 104 58) (read_nal_expected_truth $F $C))) True) +; + (= (--> @@ -1687,11 +1780,15 @@ (, chspace (, ! (read_nal_expected_truth $F $C)))) True) +; + (= (--> (read_nal_expected_truth $_ $_) (, (46) !)) True) +; + (= (--> (read_nal_expected_truth $_ $_) @@ -1699,6 +1796,8 @@ (\+ (dcg_peek ($_))) !)) True) +; + (= (--> (read_nal_expected_truth $F $C) @@ -1706,6 +1805,8 @@ (read_nal_expected_truth_ele $F $C) (, ! (read_nal_expected_truth $F $C)))) True) +; + (= (--> (read_nal_expected_truth_ele $F $C) @@ -1714,6 +1815,8 @@ (44)) (, ! (read_nal_expected_truth_ele $F $C)))) True) +; + (= (--> (read_nal_expected_truth_ele $F $_) @@ -1721,6 +1824,8 @@ (102 114 101 113 117 101 110 99 121 61) (, ospace (nal_frequency $F)))) True) +; + (= (--> (read_nal_expected_truth_ele $_ $C) @@ -1728,9 +1833,11 @@ (99 111 110 102 105 100 101 110 99 101 61) (, ospace (nal_confidence $C)))) True) +; + ; -; {1 : 4;3} +; (= (--> @@ -1744,20 +1851,26 @@ (, { (read_term_from_codes $Str $V3 ( (double_quotes string) (syntax_errors fail))) } !)))) True) +; + ; -; nal_file_with_comments(O,with_text(O,Txt),S,E):- copy_until_tail(S,Copy),text_to_string_safe(Copy,Txt),!. +; - !(thread-local (with_self (t-l) (/ sreader-options 2))) + !(thread-local (with_self (t-l *) (/ sreader-options 2))) +; + (= (nars-tests) ( (nal-tests) (nal-test-files))) +; + @@ -1767,17 +1880,21 @@ (fmt ' NAL TEST') (with_self - (nal-reader) + (nal-reader *) (forall (nal-is-test $_ $Test) (nal-test $Test))))) +; + !(use-module (library (/ dcg basics))) +; + ; -; try_reader_test(Test):- is_stream(Test), !, \+ is_compound(Test), open_string(Test,Stream), try_reader_test(Stream). +; (= @@ -1785,14 +1902,18 @@ NAL TEST') ( (in-cmt (, (fmt "\n-----------------------------\n") (fmt $Test) (fmt "-----------------------------\n"))) (nal-call nal-dmsg $Test $Out) (nal-dmsg $Out))) +; + (= (nal-zave-varname $N $V) ( (debug-var $N $V) (set-det))) +; + ; -; nal_zave_varname(N,V):- V = '$VAR'(N). +; @@ -1800,13 +1921,7 @@ NAL TEST') (nal-read-clauses $Text $Out) ( (findall $Cl (nal-read-clause $Text $Cl) $OutL) (flatten (:: $OutL) $Out))) -; /* -; implode_varnames(Vs):- (var(Vs) ; Vs==[]),!. -; implode_varnames([NV|Vs]) :- implode_varnames(Vs), -; (var(NV) -> ignore((nal_variable_name(NV,Name),nal_zave_varname(Name,NV))); -; ignore((NV=(N=V),nal_zave_varname(N,V)))). -; */ - +; @@ -1815,8 +1930,7 @@ NAL TEST') ( (not (is-stream $NonStream)) (set-det) (must-or-rtrace (, (open-string $NonStream $Stream) (nal-read-clause $Stream $Out))))) -; ; nal_dmsg(NonStream), - +; (= @@ -1828,24 +1942,26 @@ NAL TEST') ($set-typein-module input) (nal-read-clause $Stream $Out) ($set-typein-module $M)))) +; + (= (nal-read-clause $Stream $Out) ( (op 601 xfx (with_self - (input) + (input *) (/))) (op 601 xfx (with_self - (input) + (input *) (\\))) (det-if-then-else (at-end-of-stream $Stream) (= $Out Nil) (, - (remove-all-atoms &self + (remove-all-symbols &self (: t_l - ($last_comment $_))) + (%last_comment $_))) (nal-read-term $Stream $Term) (det-if-then-else (== $Term end-of-file) @@ -1856,12 +1972,14 @@ NAL TEST') !$Exec) (, (with_self - (input) + (input *) (call $Exec)) (= $Out $More)) (= $Out (Cons $Term $More))) (nal-read-clause $Stream $More))))))) +; + (= @@ -1871,24 +1989,32 @@ NAL TEST') (call-cleanup (parse-meta-ascii-nal nal-file $Text $Expr) (append-buffer-codes $In $Codes)))) +; + (= (nal-read-term $Text $Expr) ( (notrace (, (= ascii- $In) (remove-pending-buffer-codes $In $Codes))) (call-cleanup (parse-meta-ascii-nal nal-file $Text $Expr) (append-buffer-codes $In $Codes)))) +; + (= (parse-meta-ascii-nal nal-file $Text $Expr) - ( (parse-meta-ascii nal-file $Text $Expr) (remove-all-atoms &self (: t_l ($last_comment $_))))) + ( (parse-meta-ascii nal-file $Text $Expr) (remove-all-symbols &self (: t_l (%last_comment $_))))) +; + (= (with_self - (nal-reader) + (nal-reader *) {$X }) (call $X)) +; + ; -; Expand Stream or String +; (= @@ -1897,6 +2023,8 @@ NAL TEST') (must-or-rtrace (nal-read-clauses $Stream $List)) (set-det) (nal-call $Ctx $List $Out))) +; + (= (nal-call $Ctx $List $Out) @@ -1905,11 +2033,15 @@ NAL TEST') (maplist (nal-call $Ctx) $List $OutL) (flatten $OutL $Out))) +; + (= (nal-call $Ctx (= $InnerCtx (json $List)) $Out) ( (set-det) (nal-call (Cons $InnerCtx $Ctx) $List $Out))) +; + (= (nal-call $Ctx $List $Out) @@ -1922,14 +2054,15 @@ NAL TEST') (\== $List $NewList) (set-det) (nal-call $Ctx $NewList $Out))) -; ; ignore((NewSub=='$',nal_dmsg(nal_rule_rewrite(_Ctx, Sub, NewSub)))), - +; (= (nal-call $Ctx $List $Out) ( (flatten (:: $List) $Out) (set-det))) +; + @@ -1939,93 +2072,120 @@ NAL TEST') (nal-rule-rewrite $Ctx (json $Replace) $Replace) ( (nonvar $Replace) (set-det))) +; + (= (nal-join-atomics $Sep $List $Joined) (atomics-to-string $List $Sep $Joined)) +; - !(fixup-exports) -; /* -; nal_into_tokenized(Text,TokenizedText):- \+ string(Text),!, -; any_to_string(Text,String), nal_into_tokenized(String,TokenizedText). -; nal_into_tokenized(Text,TokenizedText):- -; split_string(Text, "", "\s\t\r\n", [L]), L\==Text,!, -; nal_into_tokenized(L,M), -; ;string_concat(M,"\n",TokenizedText). -; string_concat(M,"",TokenizedText). -; nal_into_tokenized(Text,TokenizedText):- L=[_S1,_S2|_SS], -; member(Split,["\n'","'\n","'","","\n"]), -; atomic_list_concat(L,Split,Text), -; maplist(nal_into_tokenized,L,LO), -; atomics_to_string(LO,Split, TokenizedText). -; nal_into_tokenized(Text,TokenizedText):- -; split_string(Text, "\n", "\s\t\n\r",StringList), -; maplist(into_text80_atoms,StringList,SentenceList), -; maplist(nal_join_atomics(' '),SentenceList,ListOfStrings), -; nal_join_atomics('\n',ListOfStrings,TokenizedText),!. -; */ + !(fixup-exports *) +; (= (nal_is_test read "'the detective claims that tim lives in graz") True) +; + (= (nal_is_test read "<{tim} --> (/,livingIn,_,{graz})>.") True) +; + (= (nal_is_test read " swimmer>. %0.87;0.91%") True) +; + (= (nal_is_test read "''outputMustContain(' swimmer>. %0.87;0.91%')") True) +; + (= (nal_is_test read "1") True) +; + (= (nal_is_test read "$1") True) +; + (= (nal_is_test read "#1") True) +; + (= (nal_is_test read "?1") True) +; + (= (nal_is_test read "/1") True) +; + (= (nal_is_test read "\\1") True) +; + ; -; to distinguish +; ; -; "eaten by tiger" vs. "eating tiger" +; ; -; before: (/,eat,tiger,_) vs. (/,eat,_,tiger) +; ; -; now: (eat /2 tiger) vs. (eat /1 tiger) +; (= (nal_is_test read "'eating tiger") True) +; + (= (nal_is_test read "(eat /1 tiger)") True) +; + (= (nal_is_test read "(/,eat,_,tiger)") True) +; + (= (nal_is_test read "'eaten by tiger") True) +; + (= (nal_is_test read "(eat /2 tiger)") True) +; + (= (nal_is_test read "(/,eat,tiger,_)") True) +; + (= (nal_is_test read "'intensional eating") True) +; + (= (nal_is_test read "(eat \\1 tiger)") True) +; + (= (nal_is_test read "(\\,eat,_,tiger)") True) +; + (= (nal_is_test read "(eat \\2 tiger)") True) +; + (= (nal_is_test read "(\\,eat,tiger,_)") True) +; + ; @@ -2033,137 +2193,223 @@ NAL TEST') (= (nal_is_test exec "'Revision ------\n\n'Bird is a type of swimmer.\n swimmer>.\n\n'Bird is probably not a type of swimmer.\n swimmer>. %0.10;0.60%\n\n1\n\n'Bird is very likely to be a type of swimmer.\n''outputMustContain(' swimmer>. %0.87;0.91%')") True) +; + (= (nal_is_test exec "\n********** revision\n IN: swimmer>. %1.00;0.90% {0 : 1} \n IN: swimmer>. %0.10;0.60% {0 : 2} \n1\n OUT: swimmer>. %0.87;0.91% {1 : 1;2} \n") True) +; + (= (nal_is_test exec "\n********** abduction\n IN: competition>. %1.00;0.90% {0 : 1} \n IN: competition>. %0.90;0.90% {0 : 2} \n1\n OUT: chess>. %1.00;0.42% {1 : 2;1} \n OUT: sport>. %0.90;0.45% {1 : 2;1} \n OUT: sport>. %0.90;0.45% {1 : 2;1} \n OUT: <(&,chess,sport) --> competition>. %1.00;0.81% {1 : 2;1} \n OUT: <(|,chess,sport) --> competition>. %0.90;0.81% {1 : 2;1} \n OUT: < $1> ==> $1>>. %0.90;0.45% {1 : 2;1} \n OUT: < $1> ==> $1>>. %1.00;0.42% {1 : 2;1} \n OUT: < $1> <=> $1>>. %0.90;0.45% {1 : 2;1} \n OUT: (&&, #1>, #1>). %0.90;0.81% {1 : 2;1} \n") True) +; + (= (nal_is_test exec "\n********* induction\n IN: swimmer>. %0.90;0.90% {0 : 1} \n IN: bird>. %1.00;0.90% {0 : 2} \n1\n OUT: swimmer>. %0.90;0.45% {1 : 2;1} \n OUT: bird>. %1.00;0.42% {1 : 2;1} \n OUT: swimmer>. %0.90;0.45% {1 : 2;1} \n OUT: (|,bird,swimmer)>. %1.00;0.81% {1 : 2;1} \n OUT: (&,bird,swimmer)>. %0.90;0.81% {1 : 2;1} \n OUT: <<$1 --> swimmer> ==> <$1 --> bird>>. %1.00;0.42% {1 : 2;1} \n OUT: <<$1 --> bird> ==> <$1 --> swimmer>>. %0.90;0.45% {1 : 2;1} \n OUT: <<$1 --> bird> <=> <$1 --> swimmer>>. %0.90;0.45% {1 : 2;1} \n OUT: (&&,<#1 --> bird>,<#1 --> swimmer>). %0.90;0.81% {1 : 2;1} \n") True) +; + (= (nal_is_test exec "\n********** exemplification\n IN: bird>. %1.00;0.90% {0 : 1} \n IN: animal>. %1.00;0.90% {0 : 2} \n1\n OUT: animal>. %1.00;0.81% {1 : 2;1} \n OUT: robin>. %1.00;0.45% {1 : 2;1} \n") True) +; + (= (nal_is_test exec "\n********** conversion\n IN: swimmer>. %1.00;0.90% {0 : 1} \n IN: bird>? {0 : 2} \n2\n OUT: bird>. %1.00;0.47% {2 : 1} \n") True) +; + (= (nal_is_test exec "\n********** y/n question\n IN: swimmer>. %1.00;0.90% {0 : 1} \n IN: swimmer>? {0 : 2} \n1\n OUT: swimmer>. %1.00;0.90% {0 : 1} \n") True) +; + (= (nal_is_test exec "\n********** wh-question\n IN: swimmer>. %1.00;0.80% {0 : 1} \n IN: swimmer>? {0 : 2} \n1\n OUT: swimmer>. %1.00;0.80% {0 : 1} \n") True) +; + (= (nal_is_test exec "\n\n'the detective claims that tim lives in graz\n'<{tim} --> (/,livingIn,_,{graz})>.\n'and lawyer claims that this is not the case\n<{tim} --> (/,livingIn,_,{graz})>. %0%\n100\n'the first deponent, a psychologist,\n'claims that people with sunglasses are more aggressive\n<<(*,$1,sunglasses) --> own> ==> <$1 --> [aggressive]>>.\n'the third deponent claims, that he has seen tom with sunglasses on:\n<(*,{tom},sunglasses) --> own>.\n'the teacher claims, that people who are aggressive tend to be murders\n<<$1 --> [aggressive]> ==> <$1 --> murder>>.\n'the second deponent claims, that if the person lives in Graz, he is surely the murder\n<<$1 --> (/,livingIn,_,{graz})> ==> <$1 --> murder>>.\n'who is the murder?\n<{?who} --> murder>?\n''outputMustContain('<{tom} --> murder>. %1.00;0.73%')\n\n") True) +; + (= (nal_is_test read "\n' Custom truth values These are added by appending {0.0 0.9} instead of %0.0;0.9% as we believe this increased the readability.\n\n' Example\n\n********** wh-question\n IN: swimmer>. %1.00;0.80% {0 : 1} \n IN: swimmer>? {0 : 2} \n1\n OUT: swimmer>. %1.00;0.80% {0 : 1} \n\n' can now be\n\n\n********** wh-question\n IN: swimmer>. {1.0 0.80} {0 : 1} \n IN: swimmer>? {0 : 2} \n1\n OUT: swimmer>. {1.0 0.80} {0 : 1} \n\n") True) +; + (= (nal_is_test read "\n'Images\n\n(/,rel,_,b) \n\n' has to be written as\n\n(rel /1 b)\n\n' and image as\n\n(/,rel,a,_) \n\n' as\n\n(rel /2 a)\n\n' same for \\ with \\1 and \\2.\n\n") True) +; + (= (nal_is_test read "\n'Intervals, to measure expected time distances between events, are always learned by ONA and stored as meta-data, they are not part of the Narsese I/O format anymore. Hence a sequence\n\n(&/,a,+5,b)\n\n' becomes\n\n(&/,a,b)\n\n' or\n\n(a &/ b)\n\n' and also the interval for implications is not used anymore.\n\n") True) +; + (= (nal_is_test read "\n'Operators The syntactic sugar\n\n(^op,arg_1,arg_2,arg_3,arg_n)\n\n' is not supported anymore, instead the full notation has to be used which is supported by both systems:\n\n<(*,arg_1,arg_2,arg_3,arg_n) --> ^op>\n\n' though for operations without arguments, the following shortcut can be used:\n\n^op\n\n") True) +; + (= (nal_is_test read "\n'Restrictions\n\n'1. Copulas in ONA are binary, since it's using an array-based heap for terms. \n' While there are ways to encode n-ary relations in a binary heap, the ONA philosophy, following KISS, \n' encourages the use of left-nesting, which is also used by the system itself to compose sequences of events:\n\n((a &/ b) &/ c).\n\n") True) +; + (= (nal_is_test read "\n'2. The parallel temporal copula &| is not implemented, please use &/ for now, again due to KISS. \n' If the order does not matter in some background knowledge we want to give the system, in addition to\n\n<(a &/ b) =/> c>\n\n' also give it\n\n<(b &/ a) =/> c>\n\n' to achieve the same as with &| for now.\n") True) +; + (= (nal_is_test read "\n'Optional syntactic improvements\n' The ONA parser does not require commas, and doesn't distinguish between < and (, also it supports infix format.\n\n<(|,a,b) --> M>. \n\n' can be written as\n\n<(a | b) --> M>. \n\n' or even as\n\n((a | b) --> M).\n\n' Note: Spaces cannot be omitted.\n") True) +; + (= (nal_is_test read "\n'Tim is alive.\n\n<{Tim} --> [alive]>.\n\n'Tim is a human.\n\n<{Tim} --> human>.\n") True) +; + (= (nal_is_test read "\n'Humans are a lifeform.\n\n lifeform>.\n\n'Lifeforms are like machines.\n\n machine>.\n") True) +; + (= (nal_is_test read "\n'Tom eats chocolate.\n\n<(*,{Tom},chocolate) --> eat>.\n\n<{Tom} --> (/,eat,_,chocolate)>.\n\n (/,eat,{Tom},_)>.\n") True) +; + (= (nal_is_test read "\n*volume=0\n*motorbabbling=false\n in>. :|:\n<({SELF} * kitchen) --> ^go>. :|:\n<({cat} * kitchen) --> in>. :|:\n100\n in>. :|:\n<({SELF} * bedroom) --> ^go>. :|:\n<({cat} * bedroom) --> in>. :|:\n100\n in>. :|:\n<({SELF} * livingroom) --> ^go>. :|:\n//no cat this time, it doesn't like the livingroom :)\n100\n in>. :|:\n<({SELF} * bedroom) --> ^go>. :|:\n<({cat} * bedroom) --> in>. :|:\n100\n//Ok you are in corridor now\n in>. :|:\n") True) +; + (= (nal_is_test read "\n*volume=0\nG! :|:\n") True) +; + (= (nal_is_test read "//Jonas has asthma?\n<{jonas} --> [asthma]>?\n//expected: Answer: <{jonas} --> [asthma]>. Truth: frequency=1.000000, confidence=0.801900\n//Angelika has asthma?\n<{angelika} --> [asthma]>?\n//expected: Answer: <{angelika} --> [asthma]>. Truth: frequency=1.000000, confidence=0.810000") True) +; + (= (nal_is_test exec "\n'********** [08 + 09 -> 10]:\n\n'The robot is holding key001. \n<(*,Self,key001) --> hold>. :|: %1.00;0.81% \n\n1\n\n'The robot is holding key001. \n<(*,Self,key001) --> hold>. :|:\n\n5\n\n'The robot is holding key001. \n''outputMustContain('<(*,Self,key001) --> hold>. :!1: %1.00;0.93%') \n") True) +; + (= (nal_is_test exec "\n'********** compound composition, two premises\n\n'Sport is a type of competition. \n competition>. %0.90% \n\n'Chess is a type of competition. \n competition>. %0.80% \n\n16\n\n'If something is either chess or sport, then it is a competition.\n''outputMustContain('<(|,chess,sport) --> competition>. %0.72;0.81%')\n\n'If something is both chess and sport, then it is a competition.\n''outputMustContain('<(&,chess,sport) --> competition>. %0.98;0.81%')\n") True) +; + (= (nal_is_test exec "\n********** [07 + 09 -> 11]:\n IN: <(*,key001) --> ^pick>. :|: %1.00;0.90% {0 : 0 : 1} \n\n1\n\n IN: <(*,Self,key001) --> hold>. :|: %1.00;0.90% {1 : 1 : 2} \n\n1\n\n OUT: <<(*,Self,key001) --> hold> =\\> <(*,key001) --> ^pick>>. :\\: %1.00;0.45% {2 : 1 : 1;2} \n\n OUT: <<(*,key001) --> ^pick> =/> <(*,Self,key001) --> hold>>. :\\: %1.00;0.45% {2 : 1 : 1;2} \n\n OUT: <<(*,key001) --> ^pick> <(*,Self,key001) --> hold>>. :\\: %1.00;0.45% {2 : 1 : 1;2} \n\n OUT: (/,^pick,_)>. :\\: %1.00;0.90% {2 : 0 : 1} \n") True) +; + (= (nal_is_test exec "********** deduction\n IN: animal>. %1.00;0.90% {0 : 1} \n IN: bird>. %1.00;0.90% {0 : 2} \n1\n OUT: animal>. %1.00;0.81% {1 : 2;1} \n OUT: robin>. %1.00;0.45% {1 : 2;1} ") True) +; + (= (nal_is_test exec "********** deduction\n'the detective claims that tim lives in graz\n'<{tim} --> (/,livingIn,_,{graz})>.\n'and lawyer claims that this is not the case\n<{tim} --> (/,livingIn,_,{graz})>. %0%\n100\n'the first deponent, a psychologist,\n'claims that people with sunglasses are more aggressive\n<<(*,$1,sunglasses) --> own> ==> <$1 --> [aggressive]>>.\n'the third deponent claims, that he has seen tom with sunglasses on:\n<(*,{tom},sunglasses) --> own>.\n'the teacher claims, that people who are aggressive tend to be murders\n<<$1 --> [aggressive]> ==> <$1 --> murder>>.\n'the second deponent claims, that if the person lives in Graz, he is surely the murder\n<<$1 --> (/,livingIn,_,{graz})> ==> <$1 --> murder>>.\n'who is the murder?\n<{?who} --> murder>?\n''outputMustContain('<{tom} --> murder>. %1.00;0.73%')") True) +; + (= (nal_is_test read "\n//First: Input diamond:\n// | â\x96\\x88\â\x96\\x88\ |\n// | â\x96\\x88\â\x96\\x88\ â\x96\\x88\â\x96\\x88\ |\n// |â\x96\\x88\â\x96\\x88\ â\x96\\x88\â\x96\\x88\|\n// | â\x96\\x88\â\x96\\x88\ â\x96\\x88\â\x96\\x88\ |\n// | â\x96\\x88\â\x96\\x88\ |:\n<{M1[-1.0,0.0]} --> [BRIGHT]>.\n<{M1[1.0,0.0]} --> [BRIGHT]>.\n<{M1[0.0,1.0]} --> [BRIGHT]>.\n<{M1[0.0,-1.0]} --> [BRIGHT]>.\n<{M1[0.5,0.5]} --> [BRIGHT]>.\n<{M1[-0.5,0.5]} --> [BRIGHT]>.\n<{M1[0.5,-0.5]} --> [BRIGHT]>.\n<{M1[-0.5,-0.5]} --> [BRIGHT]>.\n<{M1} --> (/,called,_,circle)>.\n\n//Re-observe imperfectly\n// |â\x96\\x92\â\x96\\x92\ â\x96\\x88\â\x96\\x88\ |\n// | â\x96\\x88\â\x96\\x88\ â\x96\\x92\â\x96\\x92\ |\n// |â\x96\\x92\â\x96\\x92\ â\x96\\x88\â\x96\\x88\|\n// | â\x96\\x88\â\x96\\x88\ â\x96\\x92\â\x96\\x92\â\x96\\x92\â\x96\\x92\|\n// | |:\n<{M3[-1.0,1.0]} --> [BRIGHT]>. %0.5%\n<{M3[0.0,1.0]} --> [BRIGHT]>.\n<{M3[-0.5,0.5]} --> [BRIGHT]>.\n<{M3[0.5,0.5]} --> [BRIGHT]>. %0.5%\n<{M3[-1.0,0.0]} --> [BRIGHT]>. %0.5%\n<{M3[1.0,0.0]} --> [BRIGHT]>.\n<{M3[-0.5,-0.5]} --> [BRIGHT]>.\n<{M3[0.5,-0.5]} --> [BRIGHT]>. %0.5%\n<{M3[1.0,-0.5]} --> [BRIGHT]>. %0.5%\n\n50000\n//What was observed?\n<{M3} --> (/,called,_,?what)>?\n//A circle\n''outputMustContain('<{M3} --> (/,called,_,circle)>. %0.83;0.36%')") True) +; + (= (nal_is_test exec "\n*volume=0\nburgers are tasty food\nthe stranger eats a burger in the pub\n100\nwho eats tasty food?\n//expected: Answer: (eat /1 ([tasty] & food))>. :|: occurrenceTime=2 Truth: frequency=1.000000, confidence=0.278811\nwho is in the pub?\n//expected: Answer: (in /1 pub)>. :|: occurrenceTime=3 Truth: frequency=1.000000, confidence=0.900000\n") True) +; + (= (nal_is_test exec "\n//NARS, where is the cat?\n//Passive question <({cat} * ?where) --> in>? :|: wouldn't trigger a decision\n//Active question however does:\n<(<({cat} * #where) --> in> &/ <({SELF} * #where) --> ^say>) =/> G>.\nG! :|:\n100\n//expected: ^go executed with args ({SELF} * bedroom)\n") True) +; + (= (nal_is_test read "\n//ok, feedback of NARS going to the bedroom, the cat is there!\n<({cat} * bedroom) --> in>. :|:\nG! :|:\n10\n//expected: ^say executed with args ({SELF} * bedroom)\n") True) +; + (= (nal_is_test exec "\n'********** compound composition, two premises\n\n'Sport is a type of competition. \n competition>. %0.90% \n\n'Chess is a type of competition. \n competition>. %0.80% \n\n16\n\n'If something is either chess or sport, then it is a competition.\n''outputMustContain('<(|,chess,sport) --> competition>. %0.72;0.81%')\n\n'If something is both chess and sport, then it is a competition.\n''outputMustContain('<(&,chess,sport) --> competition>. %0.98;0.81%')\n") True) +; + (= (nal_is_test read " (/,REPRESENT,_,DOG)>. %1.00;0.90% {0 : 2} ") True) +; + (= (nal_is_test read "\n'********** induction on events \n\n'John is opening door_101\n (/,open,_,door_101)>. :|: \n\n6\n\n'John is entering room_101\n (/,enter,_,room_101)>. :|: \n\n20\n\n'If John enter room_101, he should open door_101 before\n''outputMustContain('< (/,enter,_,room_101)> =\\> (&/, (/,open,_,door_101)>,+6)>. :!6: %1.00;0.45%')\n\n'new: variable introduction also in time:\n\n'If someone enter room_101, he should open door_101 before\n''outputMustContain('<<$1 --> (/,enter,_,room_101)> =\\> (&/,<$1 --> (/,open,_,door_101)>,+6)>. :!6: %1.00;0.45%')\n\n'adjusted +2 to +3 in both conditions\n\n10\n") True) +; + (= (nal_is_test read "\n''outputMustContain('< (/,enter,_,room_101)> =\\> (&/, (/,open,_,door_101)>,+6)>. :!6: %1.00;0.45%')") True) +; + (= (nal_is_test read "\n''outputMustContain('<<$1 --> (/,enter,_,room_101)> =\\> (&/,<$1 --> (/,open,_,door_101)>,+6)>. :!6: %1.00;0.45%')") True) +; + (= (nal_is_test read "\n< (/,enter,_,room_101)> =\\> (&/, (/,open,_,door_101)>,+6)>. :!6: %1.00;0.45%") True) +; + (= (nal_is_test read "<<$1 --> (/,enter,_,room_101)> =\\> (&/,<$1 --> (/,open,_,door_101)>,+6)>. :!6: %1.00;0.45%") True) +; + (= (nal_is_test read "****************I am a comment") True) +; + (= (nal_is_test read "****************") True) +; + (= (nal_is_test exec "\n*volume=0\n//When a person picks an object in a place, the picked object is also in that place\n<<#Person --> ((pick /1 $Object) & (in /1 $Place))> ==> <$Object --> (in /1 $Place)>>.\nJohn is in the playground.\nBob is in the office.\nJohn picked up the football.\nBob went to the kitchen.\n50\nThe football is in what?\n//expected: Answer: (in /1 playground)>. :|: occurrenceTime=4 Truth: frequency=1.000000, confidence=0.466560\n") True) +; + (= (nal_is_test exec "\n********** conditional deduction\n IN: <(&&,a,b) ==> c>. %1.00;0.90% {0 : 1} \n IN: a. %1.00;0.90% {0 : 2} \n1\n OUT: c>. %1.00;0.81% {1 : 1;2} \n") True) +; + (= (nal-is-test read $X) ( (atomic-list-concat $List "IN: (&|,<#1() --> (/,at,Self,_)>,<(*,{t002},#1()) --> on>). :\\:\n IN: (&|,<#1() --> (/,at,Self,_)>,<(*,{t002},#1()) --> on>). :\\: %1.00;0.90% {0 : -1 : 1}\n IN: (&|,<#1() --> (/,on,{t002},_)>,<#1() --> (/,at,Self,_)>). :\\:\n IN: (&|,<#1() --> (/,on,{t002},_)>,<#1() --> (/,at,Self,_)>). :\\: %1.00;0.90% {0 : -1 : 1}\n IN: (&|,<(*,{t002},#1()) --> on>,<(*,Self,#1()) --> at>)!\n IN: (&|,<(*,{t002},#1()) --> on>,<(*,Self,#1()) --> at>)! %1.00;0.90% {0 : 2}\n IN: (&|,<(*,{t002},#1()) --> on>,<(*,Self,#1()) --> at>). :|:\n IN: (&|,<(*,{t002},#1()) --> on>,<(*,Self,#1()) --> at>). :|: %1.00;0.90% {0 : 0 : 1}\n IN: <(&|,<(*,#1,#2(#1)) --> on>,<(*,Self,#2(#1)) --> at>) =|> <(*,Self,#1) --> reachable>>.\n IN: <(&|,<(*,#1,#2(#1)) --> on>,<(*,Self,#2(#1)) --> at>) =|> <(*,Self,#1) --> reachable>>. %1.00;0.90% {0 : 1}\n IN: <(&|,<(*,#1,#2(#1)) --> on>,<(*,Self,#2(#1)) --> at>) =|> <(*,Self,#1) --> reachable>>. %1.00;0.90% {0 : 2}\n IN: <(&|,<(*,#1,#2(#1)) --> on>,<(*,Self,#2(#1)) --> at>) =|> <(*,Self,#1) --> reachable>>. \n IN: <(&|,<(*,#1,#2(#1)) --> on>,<(*,Self,#2(#1)) --> at>) =|> <(*,Self,#1) --> reachable>>.\n IN: <(&|,<(*,#1,#2(#1)) --> on>,<(*,Self,#2(#1)) --> at>)=|><(*,Self,#1) --> reachable>>.\n OUT: (&|,<#1() --> (/,at,Self,_)>,<(*,{t002},#1()) --> on>). :\\: %1.00;0.90%\n OUT: (&|,<#1() --> (/,at,Self,_)>,<(*,{t002},#1()) --> on>). :\\: %1.00;0.90% {8 : -1 : 1}\n OUT: (&|,<#1() --> (/,at,Self,_)>,<{t002} --> (/,on,_,#1())>). :\\: %1.00;0.90% {6 : -1 : 1}\n OUT: (&|,<#1() --> (/,on,{t002},_)>,<#1() --> (/,at,Self,_)>). :\\: %1.00;0.81%\n OUT: (&|,<#1() --> (/,on,{t002},_)>,<#1() --> (/,at,Self,_)>). :\\: %1.00;0.81% {2 : -1 : 2;1}\n OUT: (&|,<(*,Self,#1()) --> at>,<{t002} --> (/,on,_,#1())>)! %1.00;0.90% {6 : 2}\n OUT: (&|,<(*,Self,#1()) --> at>,<{t002} --> (/,on,_,#1())>)? :\\: {23 : 1 : 3}\n OUT: (&|,<(*,Self,#1()) --> at>,<{t002} --> (/,on,_,#1())>)? :|: {7 : 7 : 5}\n OUT: (&|,<(*,{t002},#1()) --> on>,<(*,Self,#1()) --> at>)! %1.00;0.81%\n OUT: (&|,<(*,{t002},#1()) --> on>,<(*,Self,#1()) --> at>)! %1.00;0.81% {16 : 2;1}\n OUT: (&|,<(*,{t002},#1()) --> on>,<(*,Self,#1()) --> at>). :\\: %1.00;0.90%\n OUT: (&|,<(*,{t002},#1()) --> on>,<(*,Self,#1()) --> at>). :\\: %1.00;0.90% {4 : -1 : 1}\n OUT: (&|,<(*,{t002},#1()) --> on>,<(*,Self,#1()) --> at>)? :|: {1 : 1 : 3}\n OUT: (&|,<(*,{t002},#1()) --> on>, (/,at,_,#1())>)! %1.00;0.90% {1 : 2}\n OUT: (&|,<(*,{t002},#1()) --> on>, (/,at,_,#1())>). :\\: %1.00;0.90% {3 : -1 : 1}\n OUT: (&|,<(*,{t002},#1()) --> on>, (/,at,_,#1())>)? :\\: {15 : 1 : 3}\n OUT: (&|,<(*,{t002},#1()) --> on>, (/,at,_,#1())>)? :|: {2 : 2 : 4}\n OUT: <(&|,<(*,#1,#2(#1)) --> on>, (/,at,_,#2(#1))>) ==> <(*,Self,#1) --> reachable>>. %1.00;0.90% {4 : 1}") (member $X $List))) +; + @@ -2174,22 +2420,32 @@ NAL TEST') (member $X $List) (\== $X "") (\== $X ''))) +; + (= (nal_is_test exec "'********** conversions between inheritance and similarity\n\n'Swan is a type of bird. \n bird>. \n\n'Bird is not a type of swan. \n swan>. %0.10% \n\n1\n\n'Bird is different from swan. \n''outputMustContain(' swan>.')\n''outputMustContain(' swan>. %0.10')\n''outputMustContain(' swan>. %0.10;0.81%')\n\n") True) +; + (= (nal_is_test read "\n<{a, b} |- (&/,a,b)>.") True) +; + (= (nal_is_test read "\n<{a, b, after(a,b)} |- b>>.") True) +; + (= (nal_is_test read "\n<{ b! , b>} |- a! >") True) +; + ; -; {Event a., Implication b>.} |- Event b. +; diff --git a/nars_lp/nars/nars.metta b/nars_lp/nars/nars.metta index eed2670..1993ade 100644 --- a/nars_lp/nars/nars.metta +++ b/nars_lp/nars/nars.metta @@ -1,84 +1,46 @@ ; -; nal.pl +; ; -; Non-Axiomatic Logic in MeTTa +; ; -; Version: 1.1, September 2012 +; ; -; GNU Lesser General Public License +; ; -; Author: Pei Wang/Pat Hammer/Douglas Miles +; !(module nars (:: (/ nars-main 1) (/ nars-main 0))) -; /* -; User's Guide of NAL -; Input/Output Language -; In this demonstration, NAL implements the following formal language, Narsese. The input and output of the system are Narsese judgments. -; ::= [ [frequency-value, confidence-value]] -; ::= (, ) -; | -; | -; ::= -; | -; | -; | -; ::= -; | (*) -; ::= inheritance -; | similarity -; | implication -; | equivalence -; | instance -; | property -; | inst_prop // instance-property -; ::= negation() -; | conjunction([, +]) -; | disjunction([, +]) -; ::= ext_set([+]) // extensional set -; | int_set([+]) // intensional set -; | ext_intersection([, +]) // extensional intersection -; | int_intersection([, +]) // intensional intersection -; | ext_difference(, ) // extensional difference -; | int_difference(, ) // intensional difference -; | product([, +]) -; | ext_image(, ) // extensional image -; | int_image(, ) // intensional image -; The frequency-value is a real number in [0, 1]; the confidence-value a real number in (0, 1). -; User Interface -; The program can be invoked in the following ways: -; revision(J1, J2, J). -; Judgment J is the result of a revision between judgments J1 and J2. The three judgments all have the same statement in them. -; choice(J1, J2, J). -; Judgment J is the result of a choice between judgments J1 and J2. -; inference(J1, J2, J). -; Judgment J is the conclusion derived from judgments J1 and J2 as premises. -; inference(J1, J). -; Judgment J is the conclusion derived from judgment J1 as single premise. -; -; */ - +; !(set-module (class library)) +; + !(set-module (base system)) +; - !(use-module (library (/ nars nal-reader))) + + !(use-module (library (/ nars nal-reader))) +; + ; -; will change later to what we consider "enough" ground +; (= (narz-ground $G) (ground $G)) +; + (= @@ -86,6 +48,8 @@ (or (atom $Name) (string $Name))) +; + @@ -99,6 +63,8 @@ (= (do-nars-example-tests) (run-nars-example-tests)) +; + (= @@ -110,39 +76,34 @@ (add-history run-nars-example-tests) (forall (with_self - (nal-examples) + (nal-examples *) (nal-example-test $Goal $Results)) (take-nal-example-test $Goal $Results)))) +; + (= (with_self - (baseKB) + (baseKB *) (sanity-test)) (do-nars-example-tests)) +; + (= (with_self - (baseKB) + (baseKB *) (feature-test)) (run-nars-example-tests)) +; + (= (nal-into-prolog) ( (make) (forall (, (nal-is-test $Type $Text) (== $Type into-prolog)) (nal-do-exec-test $Type $Text)))) -; /* -; ```diff -; - text in red -; + text in green -; ! text in orange -; # text in gray -; @@ text in purple (and bold)@@ -; ``` -; */ - -; ;take_nal_example_test(_,_):- make, fail. - +; @@ -150,73 +111,105 @@ (= (nal-do-exec-test $Type $Text) (nal-do-exec-test-text $Text)) +; + (= (nal-do-exec-test-text $Text) ( (nal-read-clauses $Text $Clauses) (nars-exec-ex in $Clauses))) +; + (= (nars-exec-ex $Clauses) (nars-exec-ex in $Clauses)) +; + (= (nars-exec-ex $_ Nil) (set-det)) +; + (= (nars-exec-ex $IO (Cons $C $Clauses)) ( (set-det) (nars-exec-ex $IO $C) (nars-exec-ex $IO $Clauses))) +; + (= (nars-exec-ex $IO $C) ( (nal-to-prolog $IO $C $P) (set-det) (nars-exec-ex1 $IO $P))) +; + (= (nars-exec-ex $IO $C) (nars-exec-ex1 $IO $C)) +; + (= (nars-exec-ex1 $_ Nil) (set-det)) +; + (= (nars-exec-ex1 $IO (Cons $C $Clauses)) ( (set-det) (nars-exec-ex1 $IO $C) (nars-exec-ex1 $IO $Clauses))) +; + (= (nars-exec-ex1 $IO (nop $C)) ( (set-det) (nars-exec-ex1 $IO $C))) +; + (= (nars-exec-ex1 $_ (nal-in $C $V3)) ( (set-det) (nars-exec-ex1 in $C))) +; + (= (nars-exec-ex1 $_ (nal-out $C $V3)) ( (set-det) (nars-exec-ex1 out $C))) +; + (= (nars-exec-ex1 $_ (outputMustContain $C)) ( (set-det) (nars-exec-ex1 out $C))) +; + (= (nars-exec-ex1 $_ (expected $C)) ( (set-det) (nars-exec-ex1 out $C))) +; + (= (nars-exec-ex1 $_ (write $C)) ( (set-det) (nars-exec-ex1 cmt $C))) +; + (= (nars-exec-ex1 $IO $C) ( (dmsg (= $IO $C)) (fail))) +; + (= (nars-exec-ex1 $_ (do-steps $N)) @@ -225,23 +218,31 @@ (between 1 $N $_) (nop (inference-step $_))) (set-det))) +; + ; -; nars_exec_ex1(IO,task(judgement,C,_,TV,_)):- !, nars_exec_ex1(IO,C). +; (= (nars-exec-ex1 in $C) - ( (add-atom &self + ( (add-symbol &self (nars_db $C)) (nop (derive-event $C)) (set-det))) +; + (= (nars_exec_ex1 $_ $_) True) +; + (= (nal-exec-tests) - ( (make) (forall (, (with_self (nal-reader) (nal-is-test $Type $Text)) (\== $Type read)) (nal-do-exec-test $Type $Text)))) + ( (make) (forall (, (with_self (nal-reader *) (nal-is-test $Type $Text)) (\== $Type read)) (nal-do-exec-test $Type $Text)))) +; + @@ -249,10 +250,14 @@ (nal-clauses-to-test $Clauses $Goal (:: $ResultsExpected)) (nal-clauses-to-test $Clauses True $Goal True $ResultsExpected)) +; + (= (nal-clauses-to-test Nil $Goal $Goal $InOut $InOut) (set-det)) +; + (= (nal-clauses-to-test (Cons $C $Cs) $Goal $PGoal $In $Out) @@ -260,18 +265,24 @@ (nal-clauses-to-test $C $Goal $MGoal $In $Mid) (set-det) (nal-clauses-to-test $Cs $MGoal $PGoal $Mid $Out))) +; + (= (nal-clauses-to-test (expected $C) $Goal $Goal $In $Out) ( (set-det) (nal-to-prolog out $C $P) (conjoin-op or $In $P $Out))) +; + (= (nal-clauses-to-test (outputMustContain $C) $Goal $Goal $In $Out) ( (set-det) (nal-to-prolog out $C $P) (conjoin-op or $In $P $Out))) +; + (= (nal-clauses-to-test (nal-out $C $W) $Goal $Goal $In $Out) @@ -279,6 +290,8 @@ (nal-to-prolog out (nal-out $C $W) $P) (conjoin $In $P $Out))) +; + (= (nal-clauses-to-test (nal-in $C $W) $Goal $PGoal $InOut $InOut) @@ -286,6 +299,8 @@ (nal-to-prolog in (nal-in $C $W) $P) (conjoin $Goal $P $PGoal))) +; + (= (nal-clauses-to-test $CMT $Goal $Goal $In $Out) ( (\== $In True) @@ -294,31 +309,41 @@ (set-det) (nal-to-prolog out $CMT $P) (conjoin $In $P $Out))) +; + (= (nal-clauses-to-test $C $Goal $PGoal $InOut $InOut) ( (nal-to-prolog in $C $P) (conjoin $Goal $P $PGoal) (set-det))) +; + ; -; nal_to_MeTTa(IO,'$COMMENT'(C,_,_),writeln(C)):- !. +; ; -; nal_to_MeTTa(IO,'$COMMENT'(_,_,_),true):- !. +; (= (nal-to-prolog $IO ($COMMENT $C $_ $_) $M) ( (set-det) (nal-to-prolog $IO (write $C) $M))) +; + (= (nal-to-prolog $IO (nal-in $C $_) $M) ( (set-det) (nal-to-prolog $IO $C $M))) +; + (= (nal-to-prolog $IO (nal-out $C $_) $M) ( (set-det) (nal-to-prolog $IO $C $M))) +; + (= (nal-to-prolog $IO (task $X $S $T $O $B) $M) @@ -329,6 +354,8 @@ (ignore (= $F 1.0)) (nal-to-prolog $IO (task $X $S $T $O $B) $M))) +; + (= (nal-to-prolog $IO (task $X $S $T $O $B) $M) @@ -336,17 +363,25 @@ (= $T present) (nal-to-prolog $IO (task $X $S $T $O $B) $M))) +; + (= (nal-to-prolog $IO (task judgement $S $_ $FC $_) $O) ( (append-term $S $FC $M) (nal-to-prolog $IO $M $O))) +; + (= (nal_to_prolog in $X (nop $X)) True) +; + (= (nal_to_prolog out $X (nop (expected $X))) True) +; + @@ -361,6 +396,8 @@ (:: red) $S) (ansifmt (:: green) $S)))) +; + (= @@ -371,6 +408,8 @@ (:: $Results) $Failed) (take-nal-example-test-node $Goal (:: $Expected) $Failed))) +; + (= (take-nal-example-test-node $Goal $ResultsExpected $Failed) @@ -383,8 +422,7 @@ (format '~NEXPECTED: `~@`' (:: (print-tree $R)))) $ResultsExpected) (take-nal-example-test-result $Goal $ResultsExpected $Failed))) -; ; term_variables(Goal,Vs), - +; @@ -400,10 +438,12 @@ (set-det) (format '~n~n```prolog ' Nil) (with_self - (mu) + (mu *) (print-tree-nl $ResultsExpected)) (format ```~n~n Nil) (set-det))) +; + @@ -415,6 +455,8 @@ ( (set-det) (nars-call-ex $X) (nars-call-ex $Y))) +; + (= (nars-call-ex (or $X $Y)) (or @@ -422,14 +464,18 @@ (set-det) (nars-call-ex $X)) (nars-call-ex $Y))) +; + ; -; nars_call_ex(X=Y):- !, nars_close_enough(X,Y). ;-> true; (print_tree(failure(X=Y)),!,fail). +; (= (nars-call-ex $L) ( (is-list $L) (set-det) (maplist nars-call-ex $L))) +; + (= (nars-call-ex $X) (or @@ -438,6 +484,8 @@ (, (nop (print-tree-nl (failed-nars-call-ex $X))) (fail)))) +; + @@ -446,6 +494,8 @@ ( (is-list $L) (set-det) (maplist narz-check-results $L))) +; + (= (narz-check-results (or $R1 $R2)) (or @@ -453,11 +503,15 @@ (set-det) (narz-check-results $R1)) (narz-check-results $R2))) +; + (= (narz-check-results (, $R1 $RS)) ( (set-det) (narz-check-results $R1) (narz-check-results $RS))) +; + (= (narz-check-results (= $R $V)) (or @@ -466,6 +520,8 @@ (set-det) (= $R $V)) True) (nars-close-enough $R $V))) +; + (= (narz-check-results $X) (or @@ -475,11 +531,15 @@ (fail) (print-tree (test-failed $X)) (fail)))) +; + (= (nars-close-enough $R $V) ( (=@= $R $V) (set-det))) +; + (= (nars-close-enough $R $V) ( (number $R) @@ -488,6 +548,8 @@ (is $RV (abs (- $R $V))) (< $RV 0.03))) +; + (= (nars-close-enough $R $V) ( (or @@ -495,6 +557,8 @@ (not (compound $V))) (set-det) (== $R $V))) +; + (= (nars-close-enough (Cons $R $RT) @@ -502,12 +566,16 @@ ( (set-det) (nars-close-enough $R $V) (nars-close-enough $RT $VT))) +; + (= (nars-close-enough $R $V) ( (compound-name-arguments $R $F $RA) (compound-name-arguments $V $F $VA) (set-det) (maplist nars-close-enough $RA $VA))) +; + @@ -519,10 +587,10 @@ ; -; like to distinguish "eaten by tiger" from "eating tiger" (/, eat, tiger, _) vs. (/, eat, _, tiger) +; ; -; now: (eat /2 tiger) vs. (eat /1 tiger) +; @@ -531,12 +599,18 @@ ( (is-list $List) (set-det) (maplist use-nars-config-info $List))) +; + (= (use-nars-config-info (element $_ Nil $List)) ( (set-det) (use-nars-config-info $List))) +; + (= (use-nars-config-info (element $_ (:: (= name $Name) (= value $Value)) $_)) ( (set-det) (use-nars-config-info (= $Name $Value)))) +; + (= (use-nars-config-info (= $Name $Value)) ( (nars-string $Name) @@ -544,6 +618,8 @@ (\= $NameD $Name) (set-det) (use-nars-config-info (= $NameD $Value)))) +; + (= (use-nars-config-info (= $Name $Value)) ( (nars-string $Value) @@ -551,114 +627,288 @@ (\= $ValueD $Value) (set-det) (use-nars-config-info (= $Name $ValueD)))) +; + (= (use-nars-config-info (= $Name $Value)) ( (atom $Value) (atom-number $Value $Number) (use-nars-config-info (= $Name $Number)))) +; + ; -; use_nars_config_info(Ignore):- nars_string(Ignore), !. +; ; -; use_nars_config_info(NameValue):- dmsg(use_nars_config_info(NameValue)), fail. +; ; -; use_nars_config_info(Name=Value):- number(Value), !, nb_setval(Name, Value). +; (= (use-nars-config-info (= $Name $Value)) (nb-setval $Name $Value)) +; + (= (use_nars_config_info $_) True) +; + ; -; default gobals +; !(use-nars-config-info (= volume 100)) +; + !(use-nars-config-info (= novelty-horizon 100000)) +; + !(use-nars-config-info (= decision-threshold 0.51)) +; + !(use-nars-config-info (= concept-bag-size 80000)) +; + !(use-nars-config-info (= concept-bag-levels 1000)) +; + !(use-nars-config-info (= duration 5)) +; + !(use-nars-config-info (= horizon 1)) +; + !(use-nars-config-info (= truth-epsilon 0.01)) +; + !(use-nars-config-info (= budget-epsilon 0.0001)) +; + !(use-nars-config-info (= budget-threshold 0.01)) +; + !(use-nars-config-info (= default-confirmation-expectation 0.6)) +; + !(use-nars-config-info (= always-create-concept True)) +; + !(use-nars-config-info (= default-creation-expectation 0.66)) +; + !(use-nars-config-info (= default-creation-expectation-goal 0.6)) +; + !(use-nars-config-info (= default-judgment-confidence 0.9)) +; + !(use-nars-config-info (= default-judgment-priority 0.8)) +; + !(use-nars-config-info (= default-judgment-durability 0.5)) +; + !(use-nars-config-info (= default-question-priority 0.9)) +; + !(use-nars-config-info (= default-question-durability 0.9)) +; + !(use-nars-config-info (= default-goal-confidence 0.9)) +; + !(use-nars-config-info (= default-goal-priority 0.9)) +; + !(use-nars-config-info (= default-goal-durability 0.9)) +; + !(use-nars-config-info (= default-quest-priority 0.9)) +; + !(use-nars-config-info (= default-quest-durability 0.9)) +; + !(use-nars-config-info (= bag-threshold 1.0)) +; + !(use-nars-config-info (= forget-quality-relative 0.3)) +; + !(use-nars-config-info (= revision-max-occurrence-distance 10)) +; + !(use-nars-config-info (= task-link-bag-size 100)) +; + !(use-nars-config-info (= task-link-bag-levels 10)) +; + !(use-nars-config-info (= term-link-bag-size 100)) +; + !(use-nars-config-info (= term-link-bag-levels 10)) +; + !(use-nars-config-info (= term-link-max-matched 10)) +; + !(use-nars-config-info (= novel-task-bag-size 1000)) +; + !(use-nars-config-info (= novel-task-bag-levels 100)) +; + !(use-nars-config-info (= novel-task-bag-selections 100)) +; + !(use-nars-config-info (= sequence-bag-size 30)) +; + !(use-nars-config-info (= sequence-bag-levels 10)) +; + !(use-nars-config-info (= operation-bag-size 10)) +; + !(use-nars-config-info (= operation-bag-levels 10)) +; + !(use-nars-config-info (= operation-samples 6)) +; + !(use-nars-config-info (= projection-decay 0.1)) +; + !(use-nars-config-info (= maximum-evidental-base-length 20000)) +; + !(use-nars-config-info (= termlink-max-reasoned 3)) +; + !(use-nars-config-info (= term-link-record-length 10)) +; + !(use-nars-config-info (= concept-beliefs-max 28)) +; + !(use-nars-config-info (= concept-questions-max 5)) +; + !(use-nars-config-info (= concept-goals-max 7)) +; + !(use-nars-config-info (= reliance 0.9)) +; + !(use-nars-config-info (= discount-rate 0.5)) +; + !(use-nars-config-info (= immediate-eternalization True)) +; + !(use-nars-config-info (= sequence-bag-attempts 10)) +; + !(use-nars-config-info (= condition-bag-attempts 10)) +; + !(use-nars-config-info (= derivation-priority-leak 0.4)) +; + !(use-nars-config-info (= derivation-durability-leak 0.4)) +; + !(use-nars-config-info (= curiosity-desire-confidence-mul 0.1)) +; + !(use-nars-config-info (= curiosity-desire-priority-mul 0.1)) +; + !(use-nars-config-info (= curiosity-desire-durability-mul 0.3)) +; + !(use-nars-config-info (= curiosity-for-operator-only False)) +; + !(use-nars-config-info (= break-nal-hol-boundary False)) +; + !(use-nars-config-info (= question-generation-on-decision-making False)) +; + !(use-nars-config-info (= how-question-generation-on-decision-making False)) +; + !(use-nars-config-info (= anticipation-confidence 0.1)) +; + !(use-nars-config-info (= anticipation-tolerance 100.0)) +; + !(use-nars-config-info (= retrospective-anticipations False)) +; + !(use-nars-config-info (= satisfaction-treshold 0.0)) +; + !(use-nars-config-info (= complexity-unit 1.0)) +; + !(use-nars-config-info (= interval-adapt-speed 4.0)) +; + !(use-nars-config-info (= tasklink-per-content 4)) +; + !(use-nars-config-info (= default-feedback-priority 0.9)) +; + !(use-nars-config-info (= default-feedback-durability 0.5)) +; + !(use-nars-config-info (= concept-forget-durations 2.0)) +; + !(use-nars-config-info (= termlink-forget-durations 10.0)) +; + !(use-nars-config-info (= tasklink-forget-durations 4.0)) +; + !(use-nars-config-info (= event-forget-durations 4.0)) +; + !(use-nars-config-info (= variable-introduction-combinations-max 8)) +; + !(use-nars-config-info (= variable-introduction-confidence-mul 0.9)) +; + !(use-nars-config-info (= anticipations-per-concept-max 8)) +; + !(use-nars-config-info (= motor-babbling-confidence-threshold 0.8)) +; + !(use-nars-config-info (= threads-amount 1)) +; + !(use-nars-config-info (= milliseconds-per-step 0)) +; + !(use-nars-config-info (= steps-clock True)) +; + !(use-nars-config-info (= derivation-durability-leak 0.4)) +; + !(use-nars-config-info (= derivation-priority-leak 0.4)) +; + (= @@ -669,6 +919,8 @@ (absolute-file-name $File $Absolute) (set-det) (use-nars-config $Absolute))) +; + (= (use-nars-config $Absolute) ( (open $Absolute read $In) @@ -687,47 +939,53 @@ (close $In) (use-nars-config-info $Dom) (set-det))) +; + (= (parse-config) (use-nars-config (library ../config/mvpConfig.xml))) +; + ; -; This program covers the inferencerules of upto NAL-6 in +; ; -; "Non-Axiomatic Logic: A Model of Intelligent Reasoning" +; ; -; For the details of syntax, see the "User's Guide of NAL" +; ; -; ;; individual inferencerules +; ; -; There are three types of inferencerules in NAL: +; ; -; (1) "revision" merges its two premises into a conclusion; +; ; -; (2) "choice"nars_selects one of its two premises as a conclusion; +; ; -; (3) "inference" generates a conclusion from one or two premises. +; (= (nars_ctx default) True) +; + ; -; revision/3 +; (= @@ -739,6 +997,8 @@ (:: $S $T1) (:: $S $T2) (:: $S $T))) +; + (= @@ -747,14 +1007,18 @@ (:: $S $T2) (:: $S $T)) (narz-f-rev $T1 $T2 $T)) +; + ; -; NARS choice/3 +; (= (choice $X $Y $Z) (nars-choice $X $Y $Z)) +; + (= @@ -766,6 +1030,8 @@ (:: $S (:: $F1 $C1))) ( (>= $C1 $C2) (set-det))) +; + (= (nars-choice (:: $S @@ -775,6 +1041,8 @@ (:: $S (:: $F2 $C2))) ( (< $C1 $C2) (set-det))) +; + (= (nars-choice (:: $S1 $T1) @@ -785,6 +1053,8 @@ (narz-f-exp $T2 $E2) (>= $E1 $E2) (set-det))) +; + (= (nars-choice (:: $S1 $T1) @@ -795,20 +1065,26 @@ (narz-f-exp $T2 $E2) (< $E1 $E2) (set-det))) +; + ; -; NARS infer-ence/2 (simplified version) +; (= (infer $T1 $T) (nars-infer $T1 $T)) +; + (= (nars-infer $T1 $T) ( (nars-ctx $Ctx) (nars-inference $Ctx (:: $T1 (:: 1 0.9)) $T))) +; + (= (nars-infer @@ -835,6 +1111,8 @@ ( (narz-f-ind (:: 1 0.9) (:: 1 0.9) $V) (set-det))) +; + (= (nars-infer @@ -861,22 +1139,28 @@ ( (narz-f-ind (:: 1 0.9) (:: 1 0.9) $V) (set-det))) +; + (= (nars-infer $T1 $T2 $T) ( (nars-ctx $Ctx) (nars-inference $Ctx (:: $T1 (:: 1 0.9)) (:: $T2 (:: 1 0.9)) $T))) +; + ; -; NARS inference/2 +; (= (inference $T1 $T) ( (nars-ctx $Ctx) (nars-inference $Ctx $T1 $T))) +; + ; -; ; immediate inference +; @@ -887,6 +1171,8 @@ (:: (inheritance $P $S) $T)) (narz-f-cnv $T1 $T)) +; + (= (nars-inference $Ctx (:: @@ -894,6 +1180,8 @@ (:: (implication $P $S) $T)) (narz-f-cnv $T1 $T)) +; + (= (nars-inference $Ctx (:: @@ -903,6 +1191,8 @@ (implication (negation $P) $S) $T)) (narz-f-cnt $T1 $T)) +; + (= (nars-inference $Ctx @@ -910,6 +1200,8 @@ (negation $S) $T1) (:: $S $T)) (narz-f-neg $T1 $T)) +; + (= (nars-inference $Ctx (:: $S @@ -917,9 +1209,11 @@ (:: (negation $S) $T)) ( (< $F1 0.5) (narz-f-neg (:: $F1 $C1) $T))) +; + ; -; ; structural inference +; (= @@ -929,6 +1223,8 @@ ( (narz-reduce $S1 $S) (\== $S1 $S) (set-det))) +; + (= (nars-inference $Ctx (:: $S1 $T) @@ -936,30 +1232,38 @@ (or (nars-equivalence $Ctx $S1 $S) (nars-equivalence $Ctx $S $S1))) +; + (= (nars-inference $Ctx $P $C) ( (nars-inference $Ctx $P (:: $S (:: 1 1)) $C) (call $S))) +; + (= (nars-inference $Ctx $P $C) ( (nars-inference $Ctx (:: $S (:: 1 1)) $P $C) (call $S))) +; + ; -; inference/3 +; (= (inference $X $Y $Z) ( (nars-ctx $Ctx) (nars-inference $Ctx $X $Y $Z))) +; + ; -; ; inheritance-based syllogism +; @@ -972,6 +1276,8 @@ (:: (inheritance $S $P) $T)) ( (\= $S $P) (narz-f-ded $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -981,6 +1287,8 @@ (:: (inheritance $S $P) $T)) ( (\= $S $P) (narz-f-abd $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -990,6 +1298,8 @@ (:: (inheritance $S $P) $T)) ( (\= $S $P) (narz-f-ind $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -999,9 +1309,11 @@ (:: (inheritance $S $P) $T)) ( (\= $S $P) (narz-f-exe $T1 $T2 $T))) +; + ; -; ; similarity from inheritance +; (= @@ -1013,9 +1325,11 @@ (:: (similarity $S $P) $T)) (narz-f-int $T1 $T2 $T)) +; + ; -; ; similarity-based syllogism +; (= @@ -1027,6 +1341,8 @@ (:: (similarity $S $P) $T)) ( (\= $S $P) (narz-f-com $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1036,6 +1352,8 @@ (:: (similarity $S $P) $T)) ( (\= $S $P) (narz-f-com $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1045,6 +1363,8 @@ (:: (inheritance $S $P) $T)) ( (\= $S $P) (narz-f-ana $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1054,6 +1374,8 @@ (:: (inheritance $P $S) $T)) ( (\= $S $P) (narz-f-ana $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1063,9 +1385,11 @@ (:: (similarity $S $P) $T)) ( (\= $S $P) (narz-f-res $T1 $T2 $T))) +; + ; -; ; inheritance-based composition +; (= @@ -1080,6 +1404,8 @@ (narz-reduce (int-intersection (:: $P $S)) $N) (narz-f-int $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1092,6 +1418,8 @@ (narz-reduce (ext-intersection (:: $P $S)) $N) (narz-f-uni $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1104,6 +1432,8 @@ (narz-reduce (int-difference $P $S) $N) (narz-f-dif $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1116,6 +1446,8 @@ (narz-reduce (ext-intersection (:: $P $S)) $N) (narz-f-int $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1128,6 +1460,8 @@ (narz-reduce (int-intersection (:: $P $S)) $N) (narz-f-uni $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1140,9 +1474,11 @@ (narz-reduce (ext-difference $P $S) $N) (narz-f-dif $T1 $T2 $T))) +; + ; -; ; inheirance-based decomposition +; (= @@ -1161,6 +1497,8 @@ (narz-reduce (int-intersection $N) $P) (narz-f-pnn $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1177,6 +1515,8 @@ (narz-reduce (ext-intersection $N) $P) (narz-f-npp $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1189,6 +1529,8 @@ ( (atom $S) (atom $P) (narz-f-pnp $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1201,6 +1543,8 @@ ( (atom $S) (atom $P) (narz-f-nnn $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1217,6 +1561,8 @@ (narz-reduce (ext-intersection $N) $P) (narz-f-pnn $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1233,6 +1579,8 @@ (narz-reduce (int-intersection $N) $P) (narz-f-npp $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1245,6 +1593,8 @@ ( (atom $S) (atom $P) (narz-f-pnp $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1257,9 +1607,11 @@ ( (atom $S) (atom $P) (narz-f-nnn $T1 $T2 $T))) +; + ; -; ; implication-based syllogism +; (= @@ -1271,6 +1623,8 @@ (:: (implication $S $P) $T)) ( (\= $S $P) (narz-f-ded $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1280,6 +1634,8 @@ (:: (implication $S $P) $T)) ( (\= $S $P) (narz-f-abd $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1289,6 +1645,8 @@ (:: (implication $S $P) $T)) ( (\= $S $P) (narz-f-ind $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1298,9 +1656,11 @@ (:: (implication $S $P) $T)) ( (\= $S $P) (narz-f-exe $T1 $T2 $T))) +; + ; -; ; implication to equivalence +; (= @@ -1312,9 +1672,11 @@ (:: (equivalence $S $P) $T)) (narz-f-int $T1 $T2 $T)) +; + ; -; ; equivalence-based syllogism +; (= @@ -1326,6 +1688,8 @@ (:: (equivalence $S $P) $T)) ( (\= $S $P) (narz-f-com $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1335,6 +1699,8 @@ (:: (equivalence $S $P) $T)) ( (\= $S $P) (narz-f-com $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1344,6 +1710,8 @@ (:: (implication $S $P) $T)) ( (\= $S $P) (narz-f-ana $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1353,6 +1721,8 @@ (:: (implication $P $S) $T)) ( (\= $S $P) (narz-f-ana $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1362,9 +1732,11 @@ (:: (equivalence $S $P) $T)) ( (\= $S $P) (narz-f-res $T1 $T2 $T))) +; + ; -; ; implication-based composition +; (= @@ -1379,6 +1751,8 @@ (narz-reduce (disjunction (:: $P $S)) $N) (narz-f-int $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1391,6 +1765,8 @@ (narz-reduce (conjunction (:: $P $S)) $N) (narz-f-uni $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1403,6 +1779,8 @@ (narz-reduce (conjunction (:: $P $S)) $N) (narz-f-int $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1415,9 +1793,11 @@ (narz-reduce (disjunction (:: $P $S)) $N) (narz-f-uni $T1 $T2 $T))) +; + ; -; ; implication-based decomposition +; (= @@ -1436,6 +1816,8 @@ (narz-reduce (disjunction $N) $P) (narz-f-pnn $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1452,6 +1834,8 @@ (narz-reduce (conjunction $N) $P) (narz-f-npp $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1468,6 +1852,8 @@ (narz-reduce (conjunction $N) $P) (narz-f-pnn $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1484,9 +1870,11 @@ (narz-reduce (disjunction $N) $P) (narz-f-npp $T1 $T2 $T))) +; + ; -; ; conditional syllogism +; (= @@ -1496,6 +1884,8 @@ (:: $M $T2) (:: $P $T)) ( (narz-ground $P) (narz-f-ded $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1503,6 +1893,8 @@ (:: $M $T2) (:: $P $T)) ( (narz-ground $P) (narz-f-abd $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: $M $T1) @@ -1510,9 +1902,11 @@ (equivalence $S $M) $T2) (:: $S $T)) ( (narz-ground $S) (narz-f-ana $T1 $T2 $T))) +; + ; -; ; conditional composition +; (= @@ -1522,6 +1916,8 @@ (:: $C $T)) ( (== $C (implication $S $P)) (narz-f-ind $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: $P $T1) @@ -1529,6 +1925,8 @@ (:: $C $T)) ( (== $C (equivalence $S $P)) (narz-f-com $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: $P $T1) @@ -1538,6 +1936,8 @@ (conjunction (:: $P $S)) $N) (== $N $C) (narz-f-int $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: $P $T1) @@ -1547,9 +1947,11 @@ (disjunction (:: $P $S)) $N) (== $N $C) (narz-f-uni $T1 $T2 $T))) +; + ; -; ; propositional decomposition +; (= @@ -1565,6 +1967,8 @@ (narz-reduce (conjunction $N) $P) (narz-f-pnn $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: $S $T1) @@ -1578,9 +1982,11 @@ (narz-reduce (disjunction $N) $P) (narz-f-npp $T1 $T2 $T))) +; + ; -; ; multi-conditional syllogism +; (= @@ -1599,6 +2005,8 @@ (narz-reduce (conjunction $A) $P) (narz-f-ded $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1615,6 +2023,8 @@ (narz-reduce (conjunction $A) $P) (narz-f-abd $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1625,6 +2035,8 @@ ( (== $S (implication (conjunction (Cons $M $L)) $C)) (narz-f-ind $T1 $T2 $T))) +; + (= (nars-inference $Ctx @@ -1640,6 +2052,8 @@ (narz-reduce (conjunction $La) $P) (narz-f-ded $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1653,6 +2067,8 @@ ( (nonvar $Lm) (narz-replace $Lm $M $La $A) (narz-f-abd $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1667,9 +2083,11 @@ (narz-reduce (conjunction $Lm) $P) (narz-f-ind $T1 $T2 $T))) +; + ; -; ; variable introduction +; (= @@ -1683,6 +2101,8 @@ (inheritance $X $S) (inheritance $X $P)) $T)) ( (\= $S $P) (narz-f-ind $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1694,6 +2114,8 @@ (inheritance $P $X) (inheritance $S $X)) $T)) ( (\= $S $P) (narz-f-abd $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1705,6 +2127,8 @@ (inheritance $X $S) (inheritance $X $P)) $T)) ( (\= $S $P) (narz-f-com $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1716,6 +2140,8 @@ (inheritance $P $X) (inheritance $S $X)) $T)) ( (\= $S $P) (narz-f-com $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1725,6 +2151,8 @@ (:: (conjunction (:: (inheritance (var $Y Nil) $S) (inheritance (var $Y Nil) $P))) $T)) ( (\= $S $P) (narz-f-int $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1734,9 +2162,11 @@ (:: (conjunction (:: (inheritance $S (var $Y Nil)) (inheritance $P (var $Y Nil)))) $T)) ( (\= $S $P) (narz-f-int $T1 $T2 $T))) +; + ; -; ; 2nd variable introduction +; (= @@ -1755,6 +2185,8 @@ (\= $A (inheritance $M2 $S)) (narz-f-ind $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1769,6 +2201,8 @@ (\= $A (inheritance $M2 $S)) (narz-f-int $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1786,6 +2220,8 @@ (narz-dependant $P $Y $P2) (narz-dependant $L2 $Y $L3) (narz-f-ind $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1799,6 +2235,8 @@ (\= $L1 $L2) (\= $S $P) (narz-f-int $T1 $T2 $T))) +; + (= (nars-inference $Ctx @@ -1816,6 +2254,8 @@ (\= $A (inheritance $S $M2)) (narz-f-abd $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1830,6 +2270,8 @@ (\= $A (inheritance $S $M2)) (narz-f-int $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1847,6 +2289,8 @@ (narz-dependant $P $Y $P2) (narz-dependant $L2 $Y $L3) (narz-f-abd $T1 $T2 $T))) +; + (= (nars-inference $Ctx (:: @@ -1860,9 +2304,11 @@ (\= $L1 $L2) (\= $S $P) (narz-f-int $T1 $T2 $T))) +; + ; -; ; dependant variable elimination +; @@ -1882,6 +2328,8 @@ (conjunction $L3) $C) (narz-f-cnv $T2 $T0) (narz-f-ana $T1 $T0 $T))) +; + (= (nars-inference $Ctx (:: @@ -1898,10 +2346,14 @@ (conjunction $L3) $C) (narz-f-cnv $T2 $T0) (narz-f-ana $T1 $T0 $T))) +; + (= (replace_var () $_ () $_) True) +; + (= (replace-var (Cons @@ -1909,6 +2361,8 @@ (Cons (inheritance $S2 $P) $T2) $S2) (replace-var $T1 $S1 $T2 $S2)) +; + (= (replace-var (Cons @@ -1916,26 +2370,32 @@ (Cons (inheritance $S $P2) $T2) $P2) (replace-var $T1 $P1 $T2 $P2)) +; + (= (replace-all (Cons $H $T1) $H1 (Cons $H $T2) $H2) (replace-var $T1 $H1 $T2 $H2)) +; + ; -; ;; Theorems in IL: +; ; -; NARS inheritance/2 +; (= (inheritance $X $Y) ( (nars-ctx $Ctx) (nars-inheritance $Ctx $X $Y))) +; + (= @@ -1943,40 +2403,56 @@ (ext-intersection $Ls) $P) (narz-include (:: $P) $Ls)) +; + (= (nars-inheritance $Ctx $S (int-intersection $Lp)) (narz-include (:: $S) $Lp)) +; + (= (nars-inheritance $Ctx (ext-intersection $S) (ext-intersection $P)) ( (narz-include $P $S) (\= $P (:: $_)))) +; + (= (nars-inheritance $Ctx (int-intersection $S) (int-intersection $P)) ( (narz-include $S $P) (\= $S (:: $_)))) +; + (= (nars-inheritance $Ctx (ext-set $S) (ext-set $P)) (narz-include $S $P)) +; + (= (nars-inheritance $Ctx (int-set $S) (int-set $P)) (narz-include $P $S)) +; + (= (nars-inheritance $Ctx (ext-difference $S $P) $S) ( (narz-ground $S) (narz-ground $P))) +; + (= (nars-inheritance $Ctx $S (int-difference $S $P)) ( (narz-ground $S) (narz-ground $P))) +; + (= (nars-inheritance $Ctx @@ -1986,6 +2462,8 @@ (ext-image $R $L2) $L1) (narz-replace $L1 (ext-image $R $L2) $L2))) +; + (= (nars-inheritance $Ctx $R (product $L1)) @@ -1994,14 +2472,18 @@ (int-image $R $L2) $L1) (narz-replace $L1 (int-image $R $L2) $L2))) +; + ; -; NARS similarity/2 +; (= (similarity $X $Y) ( (nars-ctx $Ctx) (nars-similarity $Ctx $X $Y))) +; + (= @@ -2010,54 +2492,74 @@ (narz-reduce $X $Y) (\== $X $Y) (set-det))) +; + (= (nars-similarity $Ctx (ext-intersection $L1) (ext-intersection $L2)) (narz-same-set $L1 $L2)) +; + (= (nars-similarity $Ctx (int-intersection $L1) (int-intersection $L2)) (narz-same-set $L1 $L2)) +; + (= (nars-similarity $Ctx (ext-set $L1) (ext-set $L2)) (narz-same-set $L1 $L2)) +; + (= (nars-similarity $Ctx (int-set $L1) (int-set $L2)) (narz-same-set $L1 $L2)) +; + ; -; NARS implication/2 +; (= (implication $X $Y) ( (nars-ctx $Ctx) (nars-implication $Ctx $X $Y))) +; + (= (nars_implication $Ctx (similarity $S $P) (inheritance $S $P)) True) +; + (= (nars_implication $Ctx (equivalence $S $P) (implication $S $P)) True) +; + (= (nars-implication $Ctx (conjunction $L) $M) ( (narz-ground $L) (member $M $L))) +; + (= (nars-implication $Ctx $M (disjunction $L)) ( (narz-ground $L) (member $M $L))) +; + (= (nars-implication $Ctx @@ -2066,6 +2568,8 @@ ( (narz-ground $L1) (narz-ground $L2) (subset $L2 $L1))) +; + (= (nars-implication $Ctx (disjunction $L1) @@ -2073,6 +2577,8 @@ ( (narz-ground $L1) (narz-ground $L2) (subset $L1 $L2))) +; + (= (nars-implication $Ctx @@ -2084,6 +2590,8 @@ (narz-ground $Lp) (narz-replace $Ls $S $L $P) (narz-same $L $Lp))) +; + (= (nars-implication $Ctx (inheritance $S $P) @@ -2094,6 +2602,8 @@ (narz-ground $Lp) (narz-replace $Ls $S $L $P) (narz-same $L $Lp))) +; + (= (nars-implication $Ctx (similarity $S $P) @@ -2104,6 +2614,8 @@ (narz-ground $Lp) (narz-replace $Ls $S $L $P) (narz-same $L $Lp))) +; + (= (nars-implication $Ctx (similarity $S $P) @@ -2114,6 +2626,8 @@ (narz-ground $Lp) (narz-replace $Ls $S $L $P) (narz-same $L $Lp))) +; + (= (nars-implication $Ctx @@ -2122,6 +2636,8 @@ (ext-difference $S $M) (ext-difference $P $M))) (narz-ground $M)) +; + (= (nars-implication $Ctx (inheritance $S $P) @@ -2129,6 +2645,8 @@ (int-difference $S $M) (int-difference $P $M))) (narz-ground $M)) +; + (= (nars-implication $Ctx (similarity $S $P) @@ -2136,6 +2654,8 @@ (ext-difference $S $M) (ext-difference $P $M))) (narz-ground $M)) +; + (= (nars-implication $Ctx (similarity $S $P) @@ -2143,6 +2663,8 @@ (int-difference $S $M) (int-difference $P $M))) (narz-ground $M)) +; + (= (nars-implication $Ctx (inheritance $S $P) @@ -2150,6 +2672,8 @@ (ext-difference $M $P) (ext-difference $M $S))) (narz-ground $M)) +; + (= (nars-implication $Ctx (inheritance $S $P) @@ -2157,6 +2681,8 @@ (int-difference $M $P) (int-difference $M $S))) (narz-ground $M)) +; + (= (nars-implication $Ctx (similarity $S $P) @@ -2164,6 +2690,8 @@ (ext-difference $M $P) (ext-difference $M $S))) (narz-ground $M)) +; + (= (nars-implication $Ctx (similarity $S $P) @@ -2171,29 +2699,39 @@ (int-difference $M $P) (int-difference $M $S))) (narz-ground $M)) +; + (= (nars-implication $Ctx (inheritance $S $P) (negation (inheritance $S (ext-difference $M $P)))) (narz-ground $M)) +; + (= (nars-implication $Ctx (inheritance $S (ext-difference $M $P)) (negation (inheritance $S $P))) (narz-ground $M)) +; + (= (nars-implication $Ctx (inheritance $S $P) (negation (inheritance (int-difference $M $S) $P))) (narz-ground $M)) +; + (= (nars-implication $Ctx (inheritance (int-difference $M $S) $P) (negation (inheritance $S $P))) (narz-ground $M)) +; + (= (nars-implication $Ctx @@ -2202,6 +2740,8 @@ (ext-image $S $M) (ext-image $P $M))) (narz-ground $M)) +; + (= (nars-implication $Ctx (inheritance $S $P) @@ -2209,6 +2749,8 @@ (int-image $S $M) (int-image $P $M))) (narz-ground $M)) +; + (= (nars-implication $Ctx (inheritance $S $P) @@ -2221,6 +2763,8 @@ (Cons $S $L2) $Ls) (append $L1 (Cons $P $L2) $Lp))) +; + (= (nars-implication $Ctx (inheritance $S $P) @@ -2233,6 +2777,8 @@ (Cons $S $L2) $Ls) (append $L1 (Cons $P $L2) $Lp))) +; + (= (nars-implication $Ctx @@ -2240,12 +2786,16 @@ (negation (conjunction $L))) (narz-include (:: $M) $L)) +; + (= (nars-implication $Ctx (negation (disjunction $L)) (negation $M)) (narz-include (:: $M) $L)) +; + (= (nars-implication $Ctx @@ -2257,6 +2807,8 @@ (narz-ground $Lp) (narz-replace $Ls $S $L $P) (narz-same $L $Lp))) +; + (= (nars-implication $Ctx (implication $S $P) @@ -2267,6 +2819,8 @@ (narz-ground $Lp) (narz-replace $Ls $S $L $P) (narz-same $L $Lp))) +; + (= (nars-implication $Ctx (equivalence $S $P) @@ -2277,6 +2831,8 @@ (narz-ground $Lp) (narz-replace $Ls $S $L $P) (narz-same $L $Lp))) +; + (= (nars-implication $Ctx (equivalence $S $P) @@ -2287,15 +2843,19 @@ (narz-ground $Lp) (narz-replace $Ls $S $L $P) (narz-same $L $Lp))) +; + ; -; NARS equivalence/2 +; (= (equivalence $X $Y) ( (nars-ctx $Ctx) (nars-equivalence $Ctx $X $Y))) +; + (= @@ -2304,11 +2864,15 @@ (narz-reduce $X $Y) (\== $X $Y) (set-det))) +; + (= (nars_equivalence $Ctx (similarity $S $P) (similarity $P $S)) True) +; + (= (nars_equivalence $Ctx @@ -2318,6 +2882,8 @@ (similarity $S (ext_set ($P)))) True) +; + (= (nars_equivalence $Ctx (inheritance @@ -2326,6 +2892,8 @@ (similarity (int_set ($S)) $P)) True) +; + (= (nars-equivalence $Ctx @@ -2335,6 +2903,8 @@ (findall (nars-inheritance $Ctx $S $P) (member $P $Lp) $L)) +; + (= (nars-equivalence $Ctx (inheritance @@ -2343,6 +2913,8 @@ (findall (nars-inheritance $Ctx $S $P) (member $S $Ls) $L)) +; + (= (nars_equivalence $Ctx @@ -2350,12 +2922,16 @@ (ext_difference $P1 $P2)) (conjunction ( (inheritance $S $P1) (negation (inheritance $S $P2))))) True) +; + (= (nars_equivalence $Ctx (inheritance (int_difference $S1 $S2) $P) (conjunction ( (inheritance $S1 $P) (negation (inheritance $S2 $P))))) True) +; + (= (nars-equivalence $Ctx @@ -2364,6 +2940,8 @@ (product $Lp)) (conjunction $L)) (equ-product $Ls $Lp $L)) +; + (= (nars-equivalence $Ctx @@ -2372,6 +2950,8 @@ (product (Cons $P $L))) (inheritance $S $P)) (narz-ground $L)) +; + (= (nars-equivalence $Ctx (inheritance $S $P) @@ -2379,6 +2959,8 @@ (product (Cons $H $Ls)) (product (Cons $H $Lp)))) ( (narz-ground $H) (nars-equivalence $Ctx (inheritance (product $Ls) (product $Lp)) (inheritance $S $P)))) +; + (= (nars-equivalence $Ctx @@ -2387,6 +2969,8 @@ (inheritance $T (ext-image $R $L1))) (narz-replace $L $T $L1)) +; + (= (nars-equivalence $Ctx (inheritance $R @@ -2394,11 +2978,15 @@ (inheritance (int-image $R $L1) $T)) (narz-replace $L $T $L1)) +; + (= (nars_equivalence $Ctx (equivalence $S $P) (equivalence $P $S)) True) +; + (= (nars_equivalence $Ctx @@ -2406,17 +2994,23 @@ (negation $S) $P) (equivalence (negation $P) $S)) True) +; + (= (nars-equivalence $Ctx (conjunction $L1) (conjunction $L2)) (narz-same-set $L1 $L2)) +; + (= (nars-equivalence $Ctx (disjunction $L1) (disjunction $L2)) (narz-same-set $L1 $L2)) +; + (= (nars-equivalence $Ctx @@ -2426,6 +3020,8 @@ (findall (nars-implication $Ctx $S $P) (member $P $Lp) $L)) +; + (= (nars-equivalence $Ctx (implication @@ -2434,6 +3030,8 @@ (findall (nars-implication $Ctx $S $P) (member $S $Ls) $L)) +; + (= (nars-equivalence $Ctx $T1 $T2) @@ -2444,28 +3042,38 @@ (=.. $T1 $L1) (=.. $T2 $L2) (nars-equivalence-list $Ctx $L1 $L2))) +; + (= (nars_equivalence_list $Ctx $L $L) True) +; + (= (nars-equivalence-list $Ctx (Cons $H $L1) (Cons $H $L2)) (nars-equivalence-list $Ctx $L1 $L2)) +; + (= (nars-equivalence-list $Ctx (Cons $H1 $L1) (Cons $H2 $L2)) ( (nars-similarity $Ctx $H1 $H2) (nars-equivalence-list $Ctx $L1 $L2))) +; + (= (nars-equivalence-list $Ctx (Cons $H1 $L1) (Cons $H2 $L2)) ( (nars-equivalence $Ctx $H1 $H2) (nars-equivalence-list $Ctx $L1 $L2))) +; + ; -; compound termnars_structurereduction +; @@ -2476,6 +3084,8 @@ (ext-set (:: $P))) (similarity $S $P)) (set-det)) +; + (= (narz-reduce (similarity @@ -2483,6 +3093,8 @@ (int-set (:: $P))) (similarity $S $P)) (set-det)) +; + (= (narz-reduce @@ -2490,12 +3102,16 @@ (inheritance (ext-set (:: $S)) $P)) (set-det)) +; + (= (narz-reduce (property $S $P) (inheritance $S (int-set (:: $P)))) (set-det)) +; + (= (narz-reduce (inst-prop $S $P) @@ -2503,71 +3119,97 @@ (ext-set (:: $S)) (int-set (:: $P)))) (set-det)) +; + (= (narz-reduce (ext-intersection (:: $T)) $T) (set-det)) +; + (= (narz-reduce (int-intersection (:: $T)) $T) (set-det)) +; + (= (narz-reduce (ext-intersection (:: (ext-intersection $L1) (ext-intersection $L2))) (ext-intersection $L)) ( (nars-union $L1 $L2 $L) (set-det))) +; + (= (narz-reduce (ext-intersection (:: (ext-intersection $L1) $L2)) (ext-intersection $L)) ( (nars-union $L1 (:: $L2) $L) (set-det))) +; + (= (narz-reduce (ext-intersection (:: $L1 (ext-intersection $L2))) (ext-intersection $L)) ( (nars-union (:: $L1) $L2 $L) (set-det))) +; + (= (narz-reduce (ext-intersection (:: (ext-set $L1) (ext-set $L2))) (ext-set $L)) ( (intersection $L1 $L2 $L) (set-det))) +; + (= (narz-reduce (ext-intersection (:: (int-set $L1) (int-set $L2))) (int-set $L)) ( (nars-union $L1 $L2 $L) (set-det))) +; + (= (narz-reduce (int-intersection (:: (int-intersection $L1) (int-intersection $L2))) (int-intersection $L)) ( (nars-union $L1 $L2 $L) (set-det))) +; + (= (narz-reduce (int-intersection (:: (int-intersection $L1) $L2)) (int-intersection $L)) ( (nars-union $L1 (:: $L2) $L) (set-det))) +; + (= (narz-reduce (int-intersection (:: $L1 (int-intersection $L2))) (int-intersection $L)) ( (nars-union (:: $L1) $L2 $L) (set-det))) +; + (= (narz-reduce (int-intersection (:: (int-set $L1) (int-set $L2))) (int-set $L)) ( (intersection $L1 $L2 $L) (set-det))) +; + (= (narz-reduce (int-intersection (:: (ext-set $L1) (ext-set $L2))) (ext-set $L)) ( (nars-union $L1 $L2 $L) (set-det))) +; + (= (narz-reduce @@ -2576,6 +3218,8 @@ (ext-set $L2)) (ext-set $L)) ( (nars-subtract $L1 $L2 $L) (set-det))) +; + (= (narz-reduce (int-difference @@ -2583,6 +3227,8 @@ (int-set $L2)) (int-set $L)) ( (nars-subtract $L1 $L2 $L) (set-det))) +; + (= (narz-reduce @@ -2591,6 +3237,8 @@ (product $L1)) ( (append $L (:: $T) $L1) (set-det))) +; + (= (narz-reduce @@ -2599,6 +3247,8 @@ ( (member $T1 $L1) (narz-replace $L1 $T1 $L2) (set-det))) +; + (= (narz-reduce (int-image @@ -2606,38 +3256,52 @@ ( (member $T1 $L1) (narz-replace $L1 $T1 $L2) (set-det))) +; + (= (narz-reduce (negation (negation $S)) $S) (set-det)) +; + (= (narz-reduce (conjunction (:: $T)) $T) (set-det)) +; + (= (narz-reduce (disjunction (:: $T)) $T) (set-det)) +; + (= (narz-reduce (conjunction (:: (conjunction $L1) (conjunction $L2))) (conjunction $L)) ( (nars-union $L1 $L2 $L) (set-det))) +; + (= (narz-reduce (conjunction (:: (conjunction $L1) $L2)) (conjunction $L)) ( (nars-union $L1 (:: $L2) $L) (set-det))) +; + (= (narz-reduce (conjunction (:: $L1 (conjunction $L2))) (conjunction $L)) ( (nars-union (:: $L1) $L2 $L) (set-det))) +; + (= (narz-reduce @@ -2646,6 +3310,8 @@ (disjunction $L2)) (disjunction $L)) ( (nars-union $L1 $L2 $L) (set-det))) +; + (= (narz-reduce (disjunction @@ -2653,6 +3319,8 @@ (disjunction $L)) ( (nars-union $L1 (:: $L2) $L) (set-det))) +; + (= (narz-reduce (disjunction $L1 @@ -2660,40 +3328,52 @@ (disjunction $L)) ( (nars-union (:: $L1) $L2 $L) (set-det))) +; + (= (narz_reduce $X $X) True) +; + ; -; nars_union(X,Y,Z):- (nonvar(X);nonvar(Z)), catch(union(X,Y,Z),_,fail). +; (= (nars-union $X $Y $Z) (catch (union $X $Y $Z) $_ fail)) +; + ; -; nars_subtract(X,Y,Z):- (nonvar(X);nonvar(Z)), catch(subtract(X,Y,Z),_,fail). +; (= (nars-subtract $X $Y $Z) (catch (subtract $X $Y $Z) $_ fail)) +; + ; -; ;; Argument processing +; (= (equ_product () () ()) True) +; + (= (equ-product (Cons $T $Ls) (Cons $T $Lp) $L) ( (equ-product $Ls $Lp $L) (set-det))) +; + (= (equ-product (Cons $S $Ls) @@ -2701,6 +3381,8 @@ (Cons (inheritance $S $P) $L)) (equ-product $Ls $Lp $L)) +; + (= @@ -2710,10 +3392,14 @@ (:: $_)) (narz-same $L1 $L2) (\== $L1 $L2))) +; + (= (narz_same () ()) True) +; + (= (narz-same $L (Cons $H $T)) @@ -2721,6 +3407,8 @@ (nars-subtract $L (:: $H) $L1) (narz-same $L1 $T))) +; + (= @@ -2729,28 +3417,40 @@ (include1 $L1 $L2) (\== $L1 Nil) (\== $L1 $L2))) +; + (= (include1 () $_) True) +; + (= (include1 (Cons $H $T1) (Cons $H $T2)) (include1 $T1 $T2)) +; + (= (include1 (Cons $H1 $T1) (Cons $H2 $T2)) ( (\== $H2 $H1) (include1 (Cons $H1 $T1) $T2))) +; + (= (narz_not_member $_ ()) True) +; + (= (narz-not-member $C (Cons $C $_)) ( (set-det) (fail))) +; + (= (narz-not-member (:: $S $T) @@ -2759,31 +3459,43 @@ ( (nars-equivalence $Ctx $S $S1) (set-det) (fail))) +; + (= (narz-not-member $C (Cons $_ $L)) (narz-not-member $C $L)) +; + (= (narz_replace (Cons $T $L) $T (Cons nil $L)) True) +; + (= (narz-replace (Cons $H $L) $T (Cons $H $L1)) (narz-replace $L $T $L1)) +; + (= (narz_replace (Cons $H1 $T) $H1 (Cons $H2 $T) $H2) True) +; + (= (narz-replace (Cons $H $T1) $H1 (Cons $H $T2) $H2) (narz-replace $T1 $H1 $T2 $H2)) +; + (= @@ -2792,6 +3504,8 @@ (var $V (Cons $Y $L))) (set-det)) +; + (= (narz-dependant (Cons $H $T) $Y @@ -2799,6 +3513,8 @@ ( (narz-dependant $H $Y $H1) (narz-dependant $T $Y $T1) (set-det))) +; + (= (narz-dependant (inheritance $S $P) $Y @@ -2806,22 +3522,30 @@ ( (narz-dependant $S $Y $S1) (narz-dependant $P $Y $P1) (set-det))) +; + (= (narz-dependant (ext-image $R $A) $Y (ext-image $R $A1)) ( (narz-dependant $A $Y $A1) (set-det))) +; + (= (narz-dependant (int-image $R $A) $Y (int-image $R $A1)) ( (narz-dependant $A $Y $A1) (set-det))) +; + (= (narz_dependant $X $_ $X) True) +; + ; -; ;; Truth-value functions +; @@ -2849,6 +3573,8 @@ (+ $M1 $M2) (+ (+ $M1 $M2) 1))))) +; + (= @@ -2858,6 +3584,8 @@ (+ (* $C (- $F 0.5)) 0.5))) +; + (= @@ -2865,6 +3593,8 @@ (:: $F1 $C1) (:: $F $C1)) (u-not $F1 $F)) +; + (= @@ -2873,6 +3603,8 @@ (:: 1 $C)) ( (u-and (:: $F1 $C1) $W) (u-w2c $W $C))) +; + (= @@ -2883,6 +3615,8 @@ (u-and (:: $F0 $C1) $W) (u-w2c $W $C))) +; + (= @@ -2892,6 +3626,8 @@ (:: $F $C)) ( (u-and (:: $F1 $F2) $F) (u-and (:: $C1 $C2 $F) $C))) +; + (= @@ -2901,6 +3637,8 @@ (:: $F $C)) ( (u-and (:: $F1 $F2) $F) (u-and (:: $C1 $C2 $F2) $C))) +; + (= @@ -2914,6 +3652,8 @@ (:: $F1 $F2) $F0) (u-and (:: $C1 $C2 $F0) $C))) +; + (= @@ -2923,11 +3663,15 @@ (:: $F2 $C)) ( (u-and (:: $F1 $C1 $C2) $W) (u-w2c $W $C))) +; + (= (narz-f-ind $T1 $T2 $T) (narz-f-abd $T2 $T1 $T)) +; + (= @@ -2937,6 +3681,8 @@ (:: 1 $C)) ( (u-and (:: $F1 $C1 $F2 $C2) $W) (u-w2c $W $C))) +; + (= @@ -2944,6 +3690,8 @@ (0 $C1) (0 $C2) (0 0)) True) +; + (= (narz-f-com (:: $F1 $C1) @@ -2958,6 +3706,8 @@ (u-and (:: $F0 $C1 $C2) $W) (u-w2c $W $C))) +; + (= @@ -2967,6 +3717,8 @@ (:: $F $C)) ( (u-and (:: $F1 $F2) $F) (u-and (:: $C1 $C2) $C))) +; + (= @@ -2976,6 +3728,8 @@ (:: $F $C)) ( (u-or (:: $F1 $F2) $F) (u-and (:: $C1 $C2) $C))) +; + (= @@ -2988,6 +3742,8 @@ (:: $F1 $F0) $F) (u-and (:: $C1 $C2) $C))) +; + (= @@ -3001,6 +3757,8 @@ (u-not $Fn $F) (u-and (:: $Fn $C1 $C2) $C))) +; + (= @@ -3013,6 +3771,8 @@ (:: $F1n $F2) $F) (u-and (:: $F $C1 $C2) $C))) +; + (= @@ -3025,6 +3785,8 @@ (:: $F1 $F2n) $F) (u-and (:: $F $C1 $C2) $C))) +; + (= @@ -3039,9 +3801,11 @@ (u-not $Fn $F) (u-and (:: $Fn $C1 $C2) $C))) +; + ; -; Utility functions +; @@ -3049,11 +3813,15 @@ (u-not $N0 $N) ( (is $N (- 1 $N0)) (set-det))) +; + (= (u_and ($N) $N) True) +; + (= (u-and (Cons $N0 $Nt) $N) @@ -3061,11 +3829,15 @@ (is $N (* $N0 $N1)) (set-det))) +; + (= (u_or ($N) $N) True) +; + (= (u-or (Cons $N0 $Nt) $N) @@ -3075,6 +3847,8 @@ (+ $N0 $N1) (* $N0 $N1))) (set-det))) +; + (= @@ -3084,28 +3858,34 @@ (/ $W (+ $W $K))) (set-det))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; memory.pl +; ; -; 11.1.2 State accumulation using engines - https://www.swi-MeTTa.org/pldoc/man?section=engine-state +; !(use-module (library heaps)) +; + (= (create-heap $E) ( (empty-heap $H) (engine-create $_ (update-heap $H) $E))) +; + (= (update-heap $H) @@ -3117,22 +3897,30 @@ (= $Reply False))) (engine-yield $Reply) (update-heap $H1))) +; + (= (update-heap (add $Priority $Key) True $H0 $H) (add-to-heap $H0 $Priority $Key $H)) +; + (= (update-heap (get $Priority $Key) (- $Priority $Key) $H0 $H) (get-from-heap $H0 $Priority $Key $H)) +; + (= (heap-add $Priority $Key $E) (engine-post $E (add $Priority $Key) True)) +; + (= @@ -3140,12 +3928,14 @@ (engine-post $E (get $Priority $Key) (- $Priority $Key))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; control.pl +; @@ -3155,16 +3945,22 @@ (:: $F $C)) $P) ( (narz-f-exp (:: $F $C) $E) (is $P $E))) +; + (= (input-event $Event) (heap-add 1.0 $Event belief-events-queue)) +; + (= (derive-event $Event) ( (priority $Event $P) (heap-add $P $Event belief-events-queue))) +; + (= @@ -3178,60 +3974,73 @@ (derive-event $Conclusion) (write $Conclusion) (nl)) True)) -; ;undo removal of the second premise (TODO) - +; (= (nars-main) ( (create-heap belief-events-queue) (nars-main 1))) +; + (= (nars-main $T) ( (read-nal $X) (or (, (= $X 1) (write "performing 1 inference steps:") (nl) (inference-step $T) (write "done with 1 additional inference steps.") (nl) (nars-main (+ $T 1))) (, (\= $X 1) (write "Input: ") (write $X) (nl) (input-event $X) (nars-main (+ $T 1)))))) +; + ; -; read_nal(X):- read(X). +; (= (read-nal $X) (nal-read-clause current-input $X)) +; + !(if (prolog-load-context reload False)) +; + !(create-heap belief-events-queue) - !(endif) +; + + !(endif *) +; + ; -; test: +; ; -; nars_main. +; ; -; [inheritance(cat,animal), [1.0, 0.9]]. +; ; -; [inheritance(animal,being), [1.0, 0.9]]. +; ; -; 1. +; ; -; output: +; ; -; performing 1 inference steps: +; ; -; [inheritance(cat,being),[1.0,0.81]] +; ; -; done with 1 additional inference steps. +; - !(fixup-exports) + !(fixup-exports *) +; + diff --git a/nars_lp/narsese.metta b/nars_lp/narsese.metta index 0d422b2..89a9214 100644 --- a/nars_lp/narsese.metta +++ b/nars_lp/narsese.metta @@ -1,20 +1,30 @@ ; -; Non-Axiomatic Logic in MeTTa +; ; -; Version: 1.1, September 2012 +; ; -; GNU Lesser General Public License +; !(module narsese Nil) +; + !(set-module (class library)) +; + !(set-module (base system)) +; + !(reexport (library (/ nars nars))) +; + !(reexport (library (/ nars nal-reader))) +; + diff --git a/sldr_dl/example.metta b/sldr_dl/example.metta index 8d28f44..c409a93 100644 --- a/sldr_dl/example.metta +++ b/sldr_dl/example.metta @@ -1,7 +1,9 @@ - !(:: (resolution)) + !(:: (resolution *)) +; + @@ -9,11 +11,15 @@ (= (rule-set $RuleSet $MaxRuleID) ( (= $MaxRuleID 7) (= $RuleSet (:: (:: 1 def-father-1 (:: (- (:: child $Y $X)) (- (:: male $X)) (+ (:: father $X $Y)))) (:: 2 def-mother-1 (:: (- (:: child $Y $X)) (- (:: female $X)) (+ (:: mother $X $Y)))) (:: 3 def-parent-1 (:: (- (:: father $X $Y)) (+ (:: parent $X $Y)))) (:: 4 def-parent-2 (:: (- (:: mother $X $Y)) (+ (:: parent $X $Y)))) (:: 5 fact-lucy-1 (:: (+ (:: female lucy)))) (:: 6 fact-alice-1 (:: (+ (:: child alice bob)))) (:: 7 fact-bob-1 (:: (+ (:: child bob lucy)))))))) +; + (= (symbol-set $SymbolSet $MaxSymbolID) ( (= $MaxSymbolID 10) (= $SymbolSet (:: (:: 1 vble) (:: 2 father) (:: 3 child) (:: 4 male) (:: 5 female) (:: 6 parent) (:: 7 lucy) (:: 8 alice) (:: 9 bob) (:: 10 mother))))) +; + @@ -36,6 +42,8 @@ (:: -0.2 0.2)) (= $NNet (:: layer1 layer2 layer3 layer4 layer5 layer6)))) +; + (= @@ -78,5 +86,7 @@ (nl) (print-by-line $Path4) (nl))) +; + diff --git a/sldr_dl/matrix.metta b/sldr_dl/matrix.metta index 808a7a6..ee976ae 100644 --- a/sldr_dl/matrix.metta +++ b/sldr_dl/matrix.metta @@ -1,8 +1,10 @@ !(use-module (library clpfd)) +; + ; -; Addition +; @@ -10,19 +12,25 @@ (const-add-const $X $Y $Z) ( (is $Z (+ $X $Y)) (set-det))) +; + (= (vec-add-vec $X $Y $R) ( (maplist const-add-const $X $Y $R) (set-det))) +; + (= (mat-add-mat $X $Y $R) ( (maplist vec-add-vec $X $Y $R) (set-det))) +; + ; -; Multiplication +; @@ -30,29 +38,39 @@ (const-mult-const $X $Y $Z) ( (is $Z (* $X $Y)) (set-det))) +; + (= (const-mult-vec $C $V $R) ( (maplist (const-mult-const $C) $V $R) (set-det))) +; + (= (vec-mult-const $V $C $R) ( (maplist (const-mult-const $C) $V $R) (set-det))) +; + (= (vec-mult-vec $X $Y $R) ( (maplist const-mult-const $X $Y $R) (set-det))) +; + (= (mat-mult-const $M $C $R) ( (maplist (const-mult-vec $C) $M $R) (set-det))) +; + (= @@ -61,6 +79,8 @@ (vec-mult-vec $V) $M $T) (maplist sumlist $T $R) (set-det))) +; + (= @@ -69,23 +89,20 @@ (maplist (mat-mult-vec $T) $X $R) (set-det))) +; + (= (mapmat $F $M $R) (maplist (mapmatsub $F) $M $R)) -; /* -; mat_mult_mat(X,Y,R):- -; transpose(Y,T), -; maplist(mat_mult_vec(X),T,S), -; transpose(S,R), -; !. -; */ - +; (= (mapmatsub $F $V $R) ( (maplist $F $V $R) (set-det))) +; + diff --git a/sldr_dl/nnet.metta b/sldr_dl/nnet.metta index df5852e..68d0c51 100644 --- a/sldr_dl/nnet.metta +++ b/sldr_dl/nnet.metta @@ -1,23 +1,29 @@ - !(:: (matrix)) + !(:: (matrix *)) +; + ; -; Randomise. +; ; -; Seed. +; !(set-random (seed 777)) +; + ; -; Vector. +; (= (rand-vector 0 $_ Nil) (set-det)) +; + (= (rand-vector $D (:: $A $B) @@ -32,14 +38,18 @@ (rand-vector $D1 (:: $A $B) $R) (set-det))) +; + ; -; Matrix. +; (= (rand-matrix 0 $_ $_ Nil) (set-det)) +; + (= (rand-matrix $P $Q (:: $A $B) @@ -51,108 +61,154 @@ (rand-matrix $P1 $Q (:: $A $B) $R) (set-det))) +; + ; -; Nnet constructor. +; !(dynamic (/ weight-matrix 2)) +; + !(dynamic (/ bias-vector 2)) +; + !(dynamic (/ activation 2)) +; + !(dynamic (/ layer-input 2)) +; + !(dynamic (/ layer-output 2)) +; + !(dynamic (/ layer-out-diff 2)) +; + !(dynamic (/ layer-in-diff 2)) +; + !(dynamic (/ layer-bias-grad 2)) +; + !(dynamic (/ layer-weight-grad 2)) +; + (= (layer-init $Name $InDim $OutDim $Act (:: $S1 $S2)) - ( (remove-all-atoms &self + ( (remove-all-symbols &self (weight_matrix $Name $_)) - (remove-all-atoms &self + (remove-all-symbols &self (bias_vector $Name $_)) - (remove-all-atoms &self + (remove-all-symbols &self (activation $Name $_)) (rand-matrix $OutDim $InDim (:: $S1 $S2) $W) - (add-atom &self + (add-symbol &self (weight_matrix $Name $W)) (rand-vector $OutDim (:: $S1 $S2) $B) - (add-atom &self + (add-symbol &self (bias_vector $Name $B)) - (add-atom &self + (add-symbol &self (activation $Name $Act)) (print (:: layer $Name has been initialised)) (nl) (set-det))) +; + ; -; Activation Function. +; ; -; ReLU. +; (= (relu $X 0) ( (< $X 0) (set-det))) +; + (= (relu $X 30) ( (> $X 30) (set-det))) +; + (= (relu $X $X) (set-det)) +; + (= (relu-diff $X 0) ( (< $X 0) (set-det))) +; + (= (relu-diff $X 0) ( (> $X 30) (set-det))) +; + (= (relu-diff $_ 1) (set-det)) +; + !(discontiguous (/ vec-act 3)) +; + !(discontiguous (/ vec-act-diff 3)) +; + (= (vec-act relu $V $R) ( (maplist relu $V $R) (set-det))) +; + (= (vec-act-diff relu $V $R) ( (maplist relu-diff $V $R) (set-det))) +; + ; -; Softmax. +; (= (exp $X $Y) ( (is $Y (exp $X)) (set-det))) +; + (= (softmax-sub1 $A $X $Y) ( (is $Y (/ $X $A)) (set-det))) +; + (= (softmax $V $R) @@ -161,33 +217,45 @@ (maplist (softmax-sub1 $S) $P $R) (set-det))) +; + (= (softmax-diff-sub $_ 1) (set-det)) +; + (= (softmax-diff $V $R) ( (maplist softmax-diff-sub $V $R) (set-det))) +; + (= (vec-act softmax $V $R) ( (softmax $V $R) (set-det))) +; + (= (vec-act-diff softmax $V $R) ( (softmax-diff $V $R) (set-det))) +; + ; -; Cross-Entropy Loss. +; (= (ce-sub1 $A $B $S) ( (is $S (- $A $B)) (set-det))) +; + (= (neg-t-ln-y $Y $T $R) @@ -195,34 +263,42 @@ (* (* -1 $T) (log $Y))) (set-det))) +; + (= (ce-error $Y $T $E) ( (maplist neg-t-ln-y $Y $T $P) (sumlist $P $E) (set-det))) +; + (= (ce-diff $Y $T $D) ( (maplist ce-sub1 $T $Y $D) (set-det))) +; + ; -; Forward Computation. +; (= (nnet-forward Nil $In $In) (set-det)) +; + (= (nnet-forward (Cons $Name $LayerList) $In $Out) ( (weight-matrix $Name $W) (bias-vector $Name $B) (activation $Name $Act) - (remove-all-atoms &self + (remove-all-symbols &self (layer_input $Name $_)) - (add-atom &self + (add-symbol &self (layer_input $Name $In)) (transpose $In $InT) (mat-mult-mat $W $InT $X) @@ -231,26 +307,17 @@ (vec-add-vec $B) $XT $ZT) (maplist (vec-act $Act) $ZT $Y) - (remove-all-atoms &self + (remove-all-symbols &self (layer_output $Name $_)) - (add-atom &self + (add-symbol &self (layer_output $Name $Y)) (nnet-forward $LayerList $Y $Out) (set-det))) -; ; Y = Act(W * In + B) - -; ;print(X),nl, - -; ;print(ZT),nl, - -; ;print(Y),nl, - -; ; Go to the next layer - +; ; -; Error Computation. +; (= @@ -265,19 +332,18 @@ (/ $ErrTot $NumData)) (maplist ce-diff $Y $Tgt $Diff) (set-det))) -; ;retractall(layer_out_diff(Name,_)), - -; ;assert(layer_out_diff(Name,Diff)), - +; ; -; Backward Computation. +; (= (nnet-backward Nil $_ $_) (set-det)) +; + (= (nnet-backward $LayerList $Diff $LRate) ( (append $L1 @@ -291,41 +357,40 @@ (maplist vec-mult-vec $Diff $ActDiff $BDiff) (transpose $BDiff $BDT) (maplist sumlist $BDT $BGrad) - (remove-all-atoms &self + (remove-all-symbols &self (layer_bias_grad $Name $_)) - (add-atom &self + (add-symbol &self (layer_bias_grad $Name $BGrad)) (layer-input $Name $In) (mat-mult-mat $BDT $In $WGrad) - (remove-all-atoms &self + (remove-all-symbols &self (layer_weight_grad $Name $_)) - (add-atom &self + (add-symbol &self (layer_weight_grad $Name $WGrad)) (mat-mult-mat $BDiff $W $InDiff) (nnet-backward $L1 $InDiff $LRate) (mat-mult-const $WGrad $LRate $DW) (mat-add-mat $W $DW $WNew) - (remove-all-atoms &self + (remove-all-symbols &self (weight_matrix $Name $_)) - (add-atom &self + (add-symbol &self (weight_matrix $Name $WNew)) (vec-mult-const $BGrad $LRate $DB) (vec-add-vec $B $DB $BNew) - (remove-all-atoms &self + (remove-all-symbols &self (bias_vector $Name $_)) - (add-atom &self + (add-symbol &self (bias_vector $Name $BNew)) (set-det))) -; ; Next Layer. - -; ; Update. - +; (= (nnet-train $_ $_ $_ 0 $_) (set-det)) +; + (= (nnet-train $Nnet $In $Tgt $Iter $LRate) ( (is $I1 @@ -335,6 +400,8 @@ (printerr $Err) (nnet-backward $Nnet $Diff $LRate) (nnet-train $Nnet $In $Tgt $I1 $LRate))) +; + (= @@ -347,6 +414,8 @@ (print $R) (nl) (set-det))) +; + (= @@ -374,5 +443,7 @@ (:: 0 0 0 1 0))) (= $Nnet (:: try1 try2 try3 try4 try5 try6)) - (nnet-train $Nnet $In $Tgt 100 0.01))) + (nnet-train $Nnet $In $Tgt 100 0.01))) +; + diff --git a/sldr_dl/resolution.metta b/sldr_dl/resolution.metta index 86e41ef..9a83dd4 100644 --- a/sldr_dl/resolution.metta +++ b/sldr_dl/resolution.metta @@ -1,5 +1,7 @@ - !(:: (nnet)) + !(:: (nnet *)) +; + @@ -15,6 +17,8 @@ (sort $OVL $OVLS) (reverse $OVLS $Res) (set-det))) +; + @@ -26,6 +30,8 @@ (is $Dim (* $P $NumWord)) (set-det))) +; + @@ -39,11 +45,15 @@ (symlist-to-numlist $PTF $SList $NL) (numlist-to-vec $NL $MaxN $Vec) (set-det))) +; + (= (label-vec Nil $_ Nil) (set-det)) +; + (= (label-vec (Cons $Elem $L) $Num @@ -53,6 +63,8 @@ (+ $Num 1)) (label-vec $L $N1 $LT) (set-det))) +; + @@ -68,6 +80,8 @@ (:: $InVec) (:: $TgtVec) $NumEpoch $LRate) (set-det))) +; + (= @@ -77,6 +91,8 @@ (nl) (copy-n-times 0 $Dim $Vec) (set-det))) +; + (= (axnum-to-vec $AxNum $Dim $Vec) @@ -89,34 +105,46 @@ (append $Vec1 (Cons 1 $Vec2) $Vec) (set-det))) +; + !(dynamic (/ search-time 1)) +; + (= (init-search-time) - ( (remove-all-atoms &self - (search_time $_)) (add-atom &self (search_time 0)))) + ( (remove-all-symbols &self + (search_time $_)) (add-symbol &self (search_time 0)))) +; + (= (add-search-time) ( (search-time $N) - (remove-all-atoms &self + (remove-all-symbols &self (search_time $_)) (is $N1 (+ $N 1)) - (add-atom &self + (add-symbol &self (search_time $N1)) (set-det))) +; + (= (dnn-sl-resolution $A $B $C $D $E $F $G) (dnn-sl-resolution $A $B $C standard $D $E $F $G)) +; + (= (dnn_sl_resolution () $_ $_ $_ $_ $_ $_ ()) True) +; + (= (dnn-sl-resolution $GList (:: $AList $NumA) $SList $StatModName $Nnet $Mtd $Depth $Path) @@ -152,50 +180,63 @@ (dnn-train $Nnet $GTemp $SList $AxNum $Mtd)) (= $Mtd (method reasoning $_ $_))))) -; ;SAL = AList, - -; ;Ax = [+G|GN], - +; (= (print_by_line ()) True) +; + (= (print-by-line (Cons $X $L)) ( (print $X) (nl) (print-by-line $L))) +; + !(dynamic (/ num-vble 1)) - ! (remove-all-atoms &self +; + + ! (remove-all-symbols &self (num_vble $_)) - ! (add-atom &self +; + + ! (add-symbol &self (num_vble 0)) +; + (= (vble-fill $X $X) ( (ground $X) (set-det))) +; + (= (vble-fill $X $X) ( (var $X) (num-vble $N1) (is $N (+ $N1 1)) - (remove-all-atoms &self + (remove-all-symbols &self (num_vble $_)) - (add-atom &self + (add-symbol &self (num_vble $N)) (= $X (vble $N)) (set-det))) +; + (= (vble-fill Nil Nil) (set-det)) +; + (= (vble-fill (Cons $X $L) @@ -203,12 +244,16 @@ ( (vble-fill $X $XT) (vble-fill $L $LT) (set-det))) +; + (= (copy-n-times $_ 0 Nil) (set-det)) +; + (= (copy-n-times $X $N (Cons $X $L)) @@ -217,11 +262,15 @@ (- $N 1)) (copy-n-times $X $N1 $L) (set-det))) +; + (= (produce-empty-tree $_ 0 novalue) (set-det)) +; + (= (produce-empty-tree $B $D (Cons novalue $L)) @@ -231,15 +280,21 @@ (produce-empty-tree $B $D1 $Res1) (copy-n-times $Res1 $B $L) (set-det))) +; + (= (get-partial-tree (Cons $X $_) $_ 0 $X) (set-det)) +; + (= (get-partial-tree $X $_ 0 $X) ( (not (is-list $X)) (set-det))) +; + (= (get-partial-tree (Cons $X $L) $Breadth $Depth @@ -249,6 +304,8 @@ (- $Depth 1)) (get-partial-tree2 $L $Breadth $D1 $LT) (set-det))) +; + (= (get-partial-tree $X $Breadth $Depth (Cons $X $LT)) @@ -258,6 +315,8 @@ (- $Depth 1)) (get-partial-tree2 Nil $Breadth $D1 $LT) (set-det))) +; + (= @@ -280,13 +339,14 @@ (< $N1 0) (get-first-element $Res1 $Breadth $Res))) (set-det))) -; ; Check if the lengths agree. - +; (= (get_first_element $_ 0 ()) True) +; + (= (get-first-element Nil $N (Cons norule $Res1)) @@ -294,6 +354,8 @@ (is $N1 (- $N 1)) (get-first-element Nil $N1 $Res1))) +; + (= (get-first-element (Cons $X $L) $N @@ -302,11 +364,15 @@ (is $N1 (- $N 1)) (get-first-element $L $N1 $Res1))) +; + (= (symlist-to-numlist Nil $_ Nil) (set-det)) +; + (= (symlist-to-numlist (Cons $X $L) $SList @@ -324,11 +390,15 @@ (:: $XT $X) $SList))) (symlist-to-numlist $L $SList $LT) (set-det))) +; + (= (num-to-vec -1 $Dim $Vec) ( (copy-n-times 0 $Dim $Vec) (set-det))) +; + (= (num-to-vec $Num $Dim $Vec) ( (> $Num $Dim) @@ -336,6 +406,8 @@ (nl) (copy-n-times 0 $Dim $Vec) (set-det))) +; + (= (num-to-vec $Num $Dim $Vec) @@ -348,6 +420,8 @@ (append $Vec1 (Cons 1 $Vec2) $Vec) (set-det))) +; + @@ -355,6 +429,8 @@ (= (numlist-to-vec Nil $_ Nil) (set-det)) +; + (= (numlist-to-vec (Cons $X $L) $Dim $Res) @@ -362,21 +438,29 @@ (numlist-to-vec $L $Dim $LT) (append $XT $LT $Res) (set-det))) +; + (= (for $K $P $Q) ( (=< $P $Q) (= $K $P))) +; + (= (for $K $P $Q) ( (< $P $Q) (is $P1 (+ $P 1)) (for $K $P1 $Q))) +; + (= (static_module standard $G $G) True) +; + diff --git a/sldr_dl/yap_compat.metta b/sldr_dl/yap_compat.metta index 4945d5d..f7a810d 100644 --- a/sldr_dl/yap_compat.metta +++ b/sldr_dl/yap_compat.metta @@ -1,24 +1,26 @@ ; -; :- statistics( walltime, [X,Y]), XY is X+Y, srandom(X),!. +; (= (random $X) (is $X random)) +; + !(use-module (library random)) +; + !(use-module (library lists)) +; + (= (round $X $Y) (= $Y (round $X))) -; /*flatten([], []). -; flatten([H|T], M) :- flatten(H, Hf), -; flatten(T, Tf), -; append(Hf, Tf, M).*/ - +; diff --git a/sre_dna/ccs_utils.metta b/sre_dna/ccs_utils.metta index 68732c2..0ea0e44 100644 --- a/sre_dna/ccs_utils.metta +++ b/sre_dna/ccs_utils.metta @@ -2,13 +2,19 @@ (= (trace-append $R $S $T) (tappend $R $S $T)) +; + (= (trace-append $R $S $T) (tappend $S $R $T)) +; + (= (tappend () $X $X) True) +; + (= (tappend (Cons $A $R) @@ -16,6 +22,8 @@ ( (opposite $A $B) (set-det) (trace-append $R $S $T))) +; + (= (tappend (Cons $A $R) @@ -23,14 +31,20 @@ (Cons $A $T)) (trace-append $R (Cons $B $S) $T)) +; + (= (opposite $X (- $X)) True) +; + (= (opposite (- $X) $X) True) +; + @@ -38,6 +52,10 @@ (stripped (- $A) $A) (set-det)) +; + (= (stripped $A $A) True) +; + diff --git a/sre_dna/compile.metta b/sre_dna/compile.metta index f37f4cf..c84429b 100644 --- a/sre_dna/compile.metta +++ b/sre_dna/compile.metta @@ -4,33 +4,51 @@ (?- (use_module (library random))) True) +; + (= (?- (use_module (library system))) True) +; + (= (?- (use_module (library lists))) True) +; + (= (?- (compile dynamics)) True) +; + (= (?- (consult dctg)) True) +; + (= (?- (consult parameters_P)) True) +; + (= (?- (compile operators)) True) +; + (= (?- (consult dctg_pp)) True) +; + (= (?- (compile utils)) True) +; + (= (?- @@ -38,6 +56,8 @@ (dctg_file_P $FileDCTG) (, (grammar $FileDCTG) make_grammar_table))) True) +; + (= (?- (, @@ -48,53 +68,76 @@ ') (, nl (, listing told))))) True) -; ; fast: new - +; (= (?- (compile ccs_utils)) True) +; + (= (?- (compile dctg_gen)) True) +; + (= (?- (compile dctg_reprod)) True) +; + (= (?- (compile dctg_utils)) True) +; + (= (?- (compile generate)) True) +; + (= (?- (compile gp_engine)) True) +; + (= (?- (compile lamarckian)) True) +; + (= (?- (compile evaluation)) True) +; + (= (?- (compile file_stats)) True) +; + ; -; following must follow 'parameters_P' above. +; (= (?- (, (fitness_func_P $File) - (compile $File))) True) + (compile $File))) True) +; + (= (?- (: fast (compile compile_file.pl))) True) +; + (= (?- clean_up) True) +; + diff --git a/sre_dna/compile_file_ex.metta b/sre_dna/compile_file_ex.metta index efbaadf..6e87f99 100644 --- a/sre_dna/compile_file_ex.metta +++ b/sre_dna/compile_file_ex.metta @@ -2,14 +2,26 @@ (?- (use_module (library lists))) True) +; + !(op 650 yfx ^^) +; + !(op 601 xfy :) +; + !(op 1150 xfx ::=) +; + !(op 1175 xfx <:>) +; + !(op 1150 xfx ::-) +; + @@ -18,12 +30,16 @@ (node guardedexpr-a (:: (:: a)) 8) $A $B) (c $A a $B)) +; + (= (guardedexpr-a (node guardedexpr-a (:: (:: a) $A) 9) $B $C) ( (c $B a $D) (expr $A $D $C))) +; + (= @@ -33,78 +49,114 @@ (set-det) (name $B (:: $A)))) +; + (= (c (Cons $A $B) $A $B) True) +; + (= (dctg_rule_info guardedexpr_b 11 (guardedexpr_b (node $_ $_ 11) $_ $_) 3 nonterminal) True) +; + (= (dctg_rule_info guardedexpr_a 9 (guardedexpr_a (node $_ $_ 9) $_ $_) 3 nonterminal) True) +; + (= (dctg_rule_info noniter_expr 5 (noniter_expr (node $_ $_ 5) $_ $_) 3 nonterminal) True) +; + (= (dctg_rule_info expr 0 (expr (node $_ $_ 0) $_ $_) 3 nonterminal) True) +; + (= (dctg_rule_info expr 1 (expr (node $_ $_ 1) $_ $_) 2 nonterminal) True) +; + (= (dctg_rule_info noniter_expr 4 (noniter_expr (node $_ $_ 4) $_ $_) 2 nonterminal) True) +; + (= (dctg_rule_info iter_expr 6 (iter_expr (node $_ $_ 6) $_ $_) 2 nonterminal) True) +; + (= (dctg_rule_info iter_expr 7 (iter_expr (node $_ $_ 7) $_ $_) 2 nonterminal) True) +; + (= (dctg_rule_info probval 13 (probval (node $_ $_ 13) $_ $_) 1 terminal) True) +; + (= (dctg_rule_info intval 12 (intval (node $_ $_ 12) $_ $_) 1 terminal) True) +; + (= (dctg_rule_info guardedexpr_b 10 (guardedexpr_b (node $_ $_ 10) $_ $_) 1 terminal) True) +; + (= (dctg_rule_info guardedexpr_a 8 (guardedexpr_a (node $_ $_ 8) $_ $_) 1 terminal) True) +; + (= (dctg_rule_info noniter_expr 3 (noniter_expr (node $_ $_ 3) $_ $_) 1 terminal) True) +; + (= (dctg_rule_info noniter_expr 2 (noniter_expr (node $_ $_ 2) $_ $_) 1 terminal) True) +; + (= (library_directory 'c:/program files/sicstus prolog/library') True) +; + (= (sre-pp-l (:: $A)) ( (sre-pp $A) (set-det))) +; + (= (sre-pp-l (Cons $A $B)) ( (write [) @@ -113,6 +165,8 @@ (sre-pp-l $B) (write ]) (set-det))) +; + (= @@ -131,6 +185,8 @@ (write 'Leftover = ') (write $D) (nl))) +; + (= @@ -154,6 +210,8 @@ (nl) (writelist $F) (nl))) +; + (= @@ -178,6 +236,8 @@ (nl) (writelist $G) (nl))) +; + (= @@ -187,6 +247,8 @@ (write )*) (write $B) (set-det))) +; + (= (sre-pp (+ $A $B)) ( (write () @@ -194,15 +256,21 @@ (write )+) (write $B) (set-det))) +; + (= (sre-pp (with_self $A $B)) ( (sre-pp $A) (write :) (sre-pp $B) (set-det))) +; + (= (sre-pp (Cons $A $B)) ( (sre-pp-l (Cons $A $B)) (set-det))) +; + (= (sre-pp (, $A $B)) ( (write () @@ -211,56 +279,80 @@ (write $B) (write )) (set-det))) +; + (= (sre-pp $A) (write $A)) +; + (= (select-kth-term (:: $A) $_ $B $B $A) (set-det)) +; + (= (select-kth-term (Cons $A $_) $B $C $C $A) ( (>= $A $B) (set-det))) +; + (= (select-kth-term (Cons $_ $A) $B $C $D $E) ( (is $F (+ $C 1)) (select-kth-term $A $B $F $D $E))) +; + (= (sumlist () () $A $A) True) +; + (= (sumlist (Cons $A $B) (Cons $C $D) $E $F) ( (is $C (+ $E $A)) (sumlist $B $D $C $F))) +; + (= (int_range 0 1000) True) +; + (= (is-a-probability $A) ( (float $A) (set-det))) +; + (= (is-a-probability $A) ( (with_self - (random) + (random *) (random $B)) (is $A (/ (truncate (* $B 100)) 100)))) +; + (= (is-an-integer $A) ( (integer $A) (set-det))) +; + (= (is-an-integer $A) - ( (int-range $B $C) (with_self (random) (random $B $C $A)))) + ( (int-range $B $C) (with_self (random *) (random $B $C $A)))) +; + (= @@ -270,11 +362,15 @@ (* $B (- 1.0 $A))) (check-prob $C))) +; + (= (recognize-loop $_ $A $B $B $C $D) ( (is $D (* $C (- 1.0 $A))) (check-prob $D))) +; + (= (recognize-loop $A $B $C $D $E $F) ( (is $G @@ -285,6 +381,8 @@ (not (= $C $H)) (check-prob $I) (recognize-loop $A $B $H $D $I $F))) +; + (= @@ -295,12 +393,16 @@ (raw-generate $G $E $H)) (raw-gen-loop $A $B $C $I $H $F) (with_self - (lists) + (lists *) (append $G $I $D)) (set-det))) +; + (= (raw-gen-loop $_ $_ $_ Nil $A $A) (set-det)) +; + (= @@ -308,16 +410,20 @@ (node probval (:: (:: $A)) 13) $B $C) ( (c $B $A $C) (is-a-probability $A))) +; + (= (raw-select-term $A $B) ( (sumlist $A $C 0 $D) (with_self - (random) + (random *) (random 0 $D $E)) (select-kth-term $C $E 1 $B $_) (set-det))) +; + (= @@ -325,12 +431,16 @@ (node guardedexpr-b (:: (:: b)) 10) $A $B) (c $A b $B)) +; + (= (guardedexpr-b (node guardedexpr-b (:: (:: b) $A) 11) $B $C) ( (c $B b $D) (expr $A $D $C))) +; + (= @@ -338,6 +448,8 @@ (node intval (:: (:: $A)) 12) $B $C) ( (c $B $A $C) (is-an-integer $A))) +; + (= @@ -345,11 +457,15 @@ (node noniter-expr (:: (:: a)) 2) $A $B) (c $A a $B)) +; + (= (noniter-expr (node noniter-expr (:: (:: b)) 3) $A $B) (c $A b $B)) +; + (= (noniter-expr (node noniter-expr @@ -358,11 +474,15 @@ (intval $B $G $H) (guardedexpr-b $C $H $I) (intval $D $I $F))) +; + (= (noniter-expr (node noniter-expr (:: $A $B) 5) $C $D) ( (expr $A $C $E) (expr $B $E $D))) +; + (= @@ -370,6 +490,8 @@ ( (min-grammar-prob-P $B) (> $A $B) (set-det))) +; + (= @@ -377,15 +499,21 @@ (node iter-expr (:: $A $B) 6) $C $D) ( (noniter-expr $A $C $E) (probval $B $E $D))) +; + (= (iter-expr (node iter-expr (:: $A $B) 7) $C $D) ( (noniter-expr $A $C $E) (probval $B $E $D))) +; + (= (identify_type () () ()) True) +; + (= (identify-type (Cons $A $B) @@ -393,35 +521,47 @@ ( (dctg-rule-info $_ $A $_ $_ terminal) (set-det) (identify-type $B $C $D))) +; + (= (identify-type (Cons $A $B) $C (Cons $A $D)) (identify-type $B $C $D)) +; + (= (get-rule-stuff $A $B) - ( (get-atoms &self + ( (get-symbols &self (= (semantic_rule $B $_ $C $_) $_)) (=.. $C (Cons $A $_)))) +; + (= (make-id-entries Nil) (set-det)) +; + (= (make-id-entries (Cons (, $A $B) $C)) - ( (add-atom &self + ( (add-symbol &self (dctg_id_table $A $B $_ $_)) (make-id-entries $C) (set-det))) +; + (= (make-rule-id-list2 $A $B) ( (bagof $C (get-rule-stuff $A $C) $D) (rem-dups $D $B))) +; + (= @@ -431,16 +571,22 @@ (=.. $B (Cons $C $_)) (set-det))) +; + (= (abstract-member2 $A (Cons $B $_)) (same-goal $A $B)) +; + (= (abstract-member2 $A (Cons $_ $B)) (abstract-member2 $A $B)) +; + (= @@ -454,6 +600,8 @@ (abstract-member2 $F $E) (same-goal $A $F)) (set-det))) +; + (= (goal-type $A $B $C $D $E $F (Cons $A $D) $E $F) @@ -465,13 +613,19 @@ (abstract-member2 $G $D) (abstract-member2 $G $C)) (set-det))) +; + (= (goal-type $A (, $_ $B) $C $D $E $F $G $H $I) ( (set-det) (goal-type $A $B $C $D $E $F $G $H $I))) +; + (= (goal_type $A $_ $_ $B $C $D $B (Cons $A $C) $D) True) +; + (= @@ -481,9 +635,11 @@ (Cons $D $_)) (dctg-override-P $E $_) (with_self - (lists) + (lists *) (member $D $E)) (set-det))) +; + (= (user-override $A $B $C $B (Cons $A $C)) @@ -491,30 +647,40 @@ (Cons $D $_)) (dctg-override-P $_ $E) (with_self - (lists) + (lists *) (member $D $E)) (set-det))) +; + (= (grammar-type-loop Nil $A $B $C $A $B $C) (set-det)) +; + (= (grammar-type-loop (Cons $A $B) $C $D $E $F $G $H) ( (user-override $A $D $E $I $J) (grammar-type-loop $B $C $I $J $F $G $H))) +; + (= (grammar-type-loop (Cons $A $B) $C $D $E $F $G $H) ( (copy-term $A $I) - (get-atoms &self + (get-symbols &self (= $I $J)) (goal-type $A $J $B $C $D $E $K $L $M) (grammar-type-loop $B $K $L $M $F $G $H))) +; + (= (find_minimum_depth $_ () $A $A) True) +; + (= (find-minimum-depth $A (Cons @@ -525,10 +691,14 @@ (min $C $E)) (find-minimum-depth $A $D $G $F) (set-det))) +; + (= (find-minimum-depth $A (Cons $_ $B) $C $D) ( (find-minimum-depth $A $B $C $D) (set-det))) +; + (= @@ -537,10 +707,14 @@ (, $B $_) $_)) (=.. $B (Cons $A $_))) +; + (= (abstract-member $A (Cons $_ $B)) (abstract-member $A $B)) +; + (= @@ -549,10 +723,14 @@ (, $B $C) $_) $C) ( (=.. $A (Cons $B $_)) (set-det))) +; + (= (find-min-depth $A (Cons $_ $B) $C) ( (find-min-depth $A $B $C) (set-det))) +; + (= @@ -561,6 +739,8 @@ (Cons $B $_)) (dctg-id-table $B $_ $_ $_) (set-det))) +; + (= @@ -572,10 +752,14 @@ (is $G (max $F $D)) (find-min-depth-body $B $C $G $E))) +; + (= (find-min-depth-body (, $_ $A) $B $C $D) ( (set-det) (find-min-depth-body $A $B $C $D))) +; + (= (find-min-depth-body $A $B $C $D) ( (is-a-rule-call $A) @@ -583,14 +767,20 @@ (find-min-depth $A $B $E) (is $D (max $E $C)))) +; + (= (find-min-depth-body $_ $_ $A $A) (set-det)) +; + (= (find-rule-mins Nil $A $A) (set-det)) +; + (= (find-rule-mins (Cons @@ -602,20 +792,26 @@ (find-rule-mins $C (Cons (, $F $B) $D) $E))) +; + (= (find-rule-mins (Cons $_ $A) $B $C) (find-rule-mins $A $B $C)) +; + (= (process-rules Nil $A $_ $B $A $B) (set-det)) +; + (= (process-rules (Cons $A $B) $C $D $E $F $G) ( (copy-term $A $H) - (get-atoms &self + (get-symbols &self (= $H $I)) (find-min-depth-body $I $D 0 $J) (set-det) @@ -624,15 +820,21 @@ (process-rules $B (Cons (, $A $K) $C) $D $E $F $G))) +; + (= (process-rules (Cons $A $B) $C $D $E $F $G) ( (set-det) (process-rules $B $C $D (Cons $A $E) $F $G))) +; + (= (set-rule-data Nil $_) (set-det)) +; + (= (set-rule-data (Cons @@ -640,20 +842,22 @@ ( (=.. $A (Cons $E $F)) (with_self - (lists) + (lists *) (append $_ (:: (node $_ $_ $G) $_ $_) $F)) (det-if-then-else (with_self - (lists) + (lists *) (member $A $D)) (= $H terminal) (= $H nonterminal)) - (add-atom &self + (add-symbol &self (dctg_rule_info $E $G $A $B $H)) (set-rule-data $C $D) (set-det))) +; + (= @@ -666,11 +870,15 @@ (= $F $D) (grammar-type-top-loop $E $F $G $D)) (set-det))) +; + (= (grammar-depth-top-loop Nil $A $_ $A) (set-det)) +; + (= (grammar-depth-top-loop $A $B $C $D) ( (process-rules $A $B $C Nil $E $F) @@ -697,77 +905,103 @@ (fail)) (grammar-depth-top-loop $F $E $G $D)) (set-det))) +; + (= (clone-list Nil Nil) (set-det)) +; + (= (clone-list (Cons $_ $A) (Cons $_ $B)) ( (clone-list $A $B) (set-det))) +; + (= (get-rule-name $A) - ( (get-atoms &self + ( (get-symbols &self (= (semantic_rule $B $_ $C $_) $_)) (=.. $C (Cons $D $E)) (clone-list $E $F) (with_self - (lists) + (lists *) (append $F (:: (node $_ $_ $B) $_ $_) $G)) (=.. $A (Cons $D $G)))) +; + (= (dctg_id_table expr (0 1) () (0 1)) True) +; + (= (dctg_id_table guardedexpr_a (8 9) (8) (9)) True) +; + (= (dctg_id_table guardedexpr_b (10 11) (10) (11)) True) +; + (= (dctg_id_table intval (12) (12) ()) True) +; + (= (dctg_id_table iter_expr (6 7) () (6 7)) True) +; + (= (dctg_id_table noniter_expr (2 3 4 5) (2 3) (4 5)) True) +; + (= (dctg_id_table probval (13) (13) ()) True) +; + (= (enhance-rule-id-list) - ( (remove-atom &self + ( (remove-symbol &self (dctg_id_table $A $B $_ $_)) (identify-type $B $C $D) - (add-atom &self + (add-symbol &self (dctg_id_table $A $B $C $D)) (fail))) +; + (= enhance_rule_id_list True) +; + (= @@ -779,6 +1013,8 @@ (grammar-type-top-loop $C Nil Nil $E) (set-rule-data $D $E) (set-det))) +; + (= @@ -788,15 +1024,19 @@ (make-rule-id-list2 $A $B) $C) (make-id-entries $C) (set-det))) +; + (= (cleanup-grammar-data) - ( (remove-all-atoms &self + ( (remove-all-symbols &self (dctg_rule_info $_ $_ $_ $_)) - (remove-all-atoms &self + (remove-all-symbols &self (dctg_id_table $_ $_ $_ $_)) (set-det))) +; + (= @@ -806,54 +1046,80 @@ (generate-rule-data) (enhance-rule-id-list) (set-det))) +; + (= (file-search-path library $A) (library-directory $A)) +; + (= (file-search-path system $A) (prolog-flag host-type $A)) +; + (= (eval_with_ID_P no) True) +; + (= (negsetsize_P 30) True) +; + (= (elite_migrate_P 0 no) True) +; + (= (unique_guards_P no) True) +; + (= (min_skip_prob_P 0.0001) True) +; + (= (min_grammar_prob_P 0.0001) True) +; + (= (gen_set_size_P 1000) True) +; + (= (sre_mintestcnt_P 2) True) +; + (= (mutation_range_P 0.1) True) +; + (= (dctg_override_P () ()) True) +; + (= @@ -861,121 +1127,179 @@ (node expr (:: $A) 0) $B $C) (iter-expr $A $B $C)) +; + (= (expr (node expr (:: $A) 1) $B $C) (noniter-expr $A $B $C)) +; + (= (dctg_root_P expr) True) +; + (= (user_args_P ()) True) +; + (= (reprod_verif_P no) True) +; + (= (evaluator_reset_P generate_testset 100) True) +; + (= (gen_type_P steadystate) True) +; + (= (popn_dump_P no) True) +; + (= (max_string_length_P 20) True) +; + (= (rep_limit_P 2) True) +; + (= (trace_limit_P 0 0) True) +; + (= (unique_population_P yes) True) +; + (= (lamarckian_P 0.0 10 best 0.1) True) +; + (= (tournament_size_P 4 4) True) +; + (= (error_tolerance_P 0) True) +; + (= (max_depth_P 10 17) True) +; + (= (prob_terminal_mutation_P 0.75) True) +; + (= (prob_internal_crossover_P 0.9) True) +; + (= (reprod_P 3) True) +; + (= (prob_crossover_P 0.9) True) +; + (= (prob_grow_P 0.5) True) +; + (= (max_runs_P 1 solution 3) True) +; + (= (cull_method_P elite) True) +; + (= (population_size_P 75 50) True) +; + (= (dctg_file_P sre3.pl) True) +; + (= (fitness_func_P reg_gram_1) True) +; + (= (wd_P c:/research/sre_dna_fastX) True) +; + (= (seed_P random (, $_ (, $_ $_))) True) +; + (= (rule_number 14) True) +; + (= @@ -983,11 +1307,15 @@ (construct $A) expr (:: $B)) ( (set-det) (^^ $B (construct $A)))) +; + (= (semantic-rule 0 (raw-generate $A $B $C) expr (:: $D)) ( (set-det) (^^ $D (raw-generate $A $B $C)))) +; + (= (semantic-rule 0 (recognize $A $B $C $D) expr @@ -996,16 +1324,22 @@ (check-prob $C) (^^ $E (recognize $A $B $C $D)))) +; + (= (semantic-rule 1 (construct $A) expr (:: $B)) ( (set-det) (^^ $B (construct $A)))) +; + (= (semantic-rule 1 (raw-generate $A $B $C) expr (:: $D)) ( (set-det) (^^ $D (raw-generate $A $B $C)))) +; + (= (semantic-rule 1 (recognize $A $B $C $D) expr @@ -1014,40 +1348,54 @@ (check-prob $C) (^^ $E (recognize $A $B $C $D)))) +; + (= (semantic-rule 2 (construct a) noniter-expr (:: (:: a))) (set-det)) +; + (= (semantic-rule 2 (raw-generate (:: a) $A $B) noniter-expr (:: (:: a))) ( (set-det) (is $B (+ $A 1)))) +; + (= (semantic-rule 2 (recognize (Cons a $A) $A $B $B) noniter-expr (:: (:: a))) ( (set-det) (check-prob $B))) +; + (= (semantic-rule 3 (construct b) noniter-expr (:: (:: b))) (set-det)) +; + (= (semantic-rule 3 (raw-generate (:: b) $A $B) noniter-expr (:: (:: b))) ( (set-det) (is $B (+ $A 1)))) +; + (= (semantic-rule 3 (recognize (Cons b $A) $A $B $B) noniter-expr (:: (:: b))) ( (set-det) (check-prob $B))) +; + (= (semantic-rule 4 (construct (:: (, $A $B) (, $C $D))) noniter-expr @@ -1061,6 +1409,8 @@ (construct $C)) (^^ $H (construct $D)))) +; + (= (semantic-rule 4 (raw-generate $A $B $C) noniter-expr @@ -1077,6 +1427,8 @@ (raw-generate $A $B $C)) (^^ $F (raw-generate $A $B $C))))) +; + (= (semantic-rule 4 (recognize $A $B $C $D) noniter-expr @@ -1093,6 +1445,8 @@ (check-prob $J) (^^ $E (recognize $A $B $J $D)))) +; + (= (semantic-rule 4 (recognize $A $B $C $D) noniter-expr @@ -1109,6 +1463,8 @@ (check-prob $J) (^^ $F (recognize $A $B $J $D)))) +; + (= (semantic-rule 5 (construct (with_self $A $B)) noniter-expr @@ -1118,6 +1474,8 @@ (construct $A)) (^^ $D (construct $B)))) +; + (= (semantic-rule 5 (raw-generate $A $B $C) noniter-expr @@ -1128,8 +1486,10 @@ (^^ $E (raw-generate $H $G $C)) (with_self - (lists) + (lists *) (append $F $H $A)))) +; + (= (semantic-rule 5 (recognize $A $B $C $D) noniter-expr @@ -1141,6 +1501,8 @@ (check-prob $H) (^^ $F (recognize $G $B $H $D)))) +; + (= (semantic-rule 6 (construct (* $A $B)) iter-expr @@ -1150,6 +1512,8 @@ (construct $A)) (^^ $D (construct $B)))) +; + (= (semantic-rule 6 (raw-generate $A $B $C) iter-expr @@ -1159,6 +1523,8 @@ (construct $F)) (max-string-length-P $G) (raw-gen-loop $D $F $G $A $B $C))) +; + (= (semantic-rule 6 (recognize $A $B $C $D) iter-expr @@ -1168,6 +1534,8 @@ (^^ $F (construct $G)) (recognize-loop $E $G $A $B $C $D))) +; + (= (semantic-rule 7 (construct (+ $A $B)) iter-expr @@ -1177,6 +1545,8 @@ (construct $A)) (^^ $D (construct $B)))) +; + (= (semantic-rule 7 (raw-generate $A $B $C) iter-expr @@ -1189,9 +1559,11 @@ (max-string-length-P $I) (raw-gen-loop $D $H $I $J $G $C) (with_self - (lists) + (lists *) (append $F $J $A)) (set-det))) +; + (= (semantic-rule 7 (recognize $A $B $C $D) iter-expr @@ -1205,29 +1577,39 @@ (^^ $F (construct $I)) (recognize-loop $E $I $G $B $H $D))) +; + (= (semantic-rule 8 (construct a) guardedexpr-a (:: (:: a))) (set-det)) +; + (= (semantic-rule 8 (raw-generate (:: a) $A $B) guardedexpr-a (:: (:: a))) ( (set-det) (is $B (+ $A 1)))) +; + (= (semantic-rule 8 (recognize (Cons a $A) $A $B $B) guardedexpr-a (:: (:: a))) ( (set-det) (check-prob $B))) +; + (= (semantic-rule 9 - (construct (with_self (a) $A)) guardedexpr-a + (construct (with_self (a *) $A)) guardedexpr-a (:: (:: a) $B)) ( (set-det) (^^ $B (construct $A)))) +; + (= (semantic-rule 9 (raw-generate @@ -1239,6 +1621,8 @@ (raw-generate $A $B $E)) (is $C (+ $E 1)))) +; + (= (semantic-rule 9 (recognize @@ -1249,29 +1633,39 @@ (check-prob $C) (^^ $E (recognize $A $B $C $D)))) +; + (= (semantic-rule 10 (construct b) guardedexpr-b (:: (:: b))) (set-det)) +; + (= (semantic-rule 10 (raw-generate (:: b) $A $B) guardedexpr-b (:: (:: b))) ( (set-det) (is $B (+ $A 1)))) +; + (= (semantic-rule 10 (recognize (Cons b $A) $A $B $B) guardedexpr-b (:: (:: b))) ( (set-det) (check-prob $B))) +; + (= (semantic-rule 11 - (construct (with_self (b) $A)) guardedexpr-b + (construct (with_self (b *) $A)) guardedexpr-b (:: (:: b) $B)) ( (set-det) (^^ $B (construct $A)))) +; + (= (semantic-rule 11 (raw-generate @@ -1283,6 +1677,8 @@ (raw-generate $A $B $E)) (is $C (+ $E 1)))) +; + (= (semantic-rule 11 (recognize @@ -1293,16 +1689,22 @@ (check-prob $C) (^^ $E (recognize $A $B $C $D)))) +; + (= (semantic-rule 12 (construct $A) intval (:: (:: $A))) (set-det)) +; + (= (semantic-rule 13 (construct $A) probval (:: (:: $A))) (set-det)) +; + (= @@ -1314,25 +1716,37 @@ (::= $B $C))) (set-det) (translate-rule $A $D) - (add-atom &self $D) + (add-symbol &self $D) (set-det))) +; + (= (process !$A) ( (set-det) (call $A))) +; + (= (process (= $A $B)) - ( (set-det) (add-atom &self (:- $A $B)))) + ( (set-det) (add-symbol &self (:- $A $B)))) +; + (= (process $A) - (add-atom &self $A)) + (add-symbol &self $A)) +; + (= (check-it $A) ( (= $A end-of-file) (set-det))) +; + (= (check-it $A) ( (process $A) (fail))) +; + (= @@ -1340,6 +1754,8 @@ ( (repeat) (read $A) (check-it $A))) +; + (= @@ -1349,15 +1765,19 @@ (consume) (seen) (see $B))) +; + (= (add-extra-args $A $B $C) ( (=.. $B $D) (with_self - (lists) + (lists *) (append $D $A $E)) (=.. $C $E))) +; + (= @@ -1370,11 +1790,13 @@ (, (= $F $D) (= $G True))) - (add-atom &self + (add-symbol &self (:- (semantic_rule $A $F $B $C) (, ! $G))) (assert-semantic-rule $A $B $C $E))) +; + (= (assert-semantic-rule $A $B $C $D) ( (or @@ -1382,17 +1804,21 @@ (::- $E $F)) (, (= $E $D) - (= $F True))) (add-atom &self (:- (semantic_rule $A $E $B $C) (, ! $F))))) + (= $F True))) (add-symbol &self (:- (semantic_rule $A $E $B $C) (, ! $F))))) +; + (= (prod-number $A) - ( (remove-atom &self + ( (remove-symbol &self (rule_number $A)) (is $B (+ $A 1)) - (add-atom &self + (add-symbol &self (rule_number $B)))) +; + (= @@ -1400,6 +1826,8 @@ (, $A $B $C) $D) (tidy (, $A $B $C) $D)) +; + (= (tidy (, $A $B) @@ -1407,9 +1835,13 @@ ( (set-det) (tidy $A $C) (tidy $B $D))) +; + (= (tidy $A $A) (set-det)) +; + (= @@ -1417,11 +1849,15 @@ (set-det) $A $A $B $B (set-det)) (set-det)) +; + (= (t-rp Nil $A (Cons Nil $A) $B $C (= $B $C)) (set-det)) +; + (= (t-rp (:: $A) $B @@ -1429,6 +1865,8 @@ (:: $C) $B) $D $E (c $D $A $E)) (char $A $C)) +; + (= (t-rp (:: $A) $B @@ -1436,6 +1874,8 @@ (:: $A) $B) $C $D (c $C $A $D)) (set-det)) +; + (= (t-rp (Cons $A $B) $C @@ -1444,6 +1884,8 @@ (, (c $F $A $H) $I)) ( (char $A $D) (t-rp $B $C (Cons $E $C) $H $G $I))) +; + (= (t-rp (Cons $A $B) $C @@ -1452,10 +1894,14 @@ (, (c $D $A $F) $G)) ( (set-det) (t-rp $B $C (Cons $B $C) $F $E $G))) +; + (= (t-rp {$A } $B $B $C $C $A) (set-det)) +; + (= (t-rp (, $A $B) $C $D $E $F @@ -1463,30 +1909,38 @@ ( (set-det) (t-rp $A $C $I $E $J $G) (t-rp $B $I $D $J $F $H))) +; + (= (t-rp (^^ $A $B) $C (Cons $B $C) $D $E $F) (add-extra-args (:: $B $D $E) $A $F)) +; + (= (t-rp $A $B (Cons $C $B) $D $E $F) (add-extra-args (:: $C $D $E) $A $F)) +; + (= (t-lp (, $A $B) $C $D $E $F $G) ( (with_self - (lists) + (lists *) (append $B $E $H)) (prod-number $I) (assert-semantic-rule $I $A $C $F) (add-extra-args (:: (node $A $C $I) $D $H) $A $G))) +; + (= (t-lp $A $B $C $D $E $F) ( (prod-number $G) @@ -1494,6 +1948,8 @@ (add-extra-args (:: (node $A $B $G) $C $D) $A $F))) +; + (= @@ -1501,10 +1957,14 @@ (<:> (::= $A Nil) $B) $C) ( (set-det) (t-lp $A Nil $D $D $B $C))) +; + (= (translate-rule (::= $A Nil) $B) ( (set-det) (t-lp $A Nil $C $C Nil $B))) +; + (= (translate-rule (<:> @@ -1513,10 +1973,12 @@ ( (set-det) (t-rp $B Nil $F $G $H $I) (with_self - (lists) + (lists *) (reverse $F $J)) (t-lp $A $J $G $H $C $D) (tidy $I $E))) +; + (= (translate-rule (::= $A $B) @@ -1525,12 +1987,16 @@ (<:> (::= $A $B) Nil) (= $C $D))) +; + (= (^^ (node $A $B $C) $D) (semantic-rule $C $D $A $B)) +; + (= @@ -1554,5 +2020,7 @@ (write 'Depth = ') (write $F) (nl))) +; + diff --git a/sre_dna/dctg.metta b/sre_dna/dctg.metta index 4a403ca..ec757bd 100644 --- a/sre_dna/dctg.metta +++ b/sre_dna/dctg.metta @@ -1,12 +1,19 @@ !(op 650 yfx ^^) -; /* logic compilation of Definite Clause Translation Grammar rules */ - +; !(op 601 xfy :) +; + !(op 1150 xfx ::=) +; + !(op 1175 xfx <:>) +; + !(op 1150 xfx ::-) +; + @@ -15,19 +22,15 @@ (<:> (::= $LP Nil) $Sem) $H) ( (set-det) (t-lp $LP Nil $S $S $Sem $H))) -; /* -; The form of a rule is: -; -; LP ::= RP <:> Args ::- Sem ; -; */ - (= (translate-rule (::= $LP Nil) $H) ( (set-det) (t-lp $LP Nil $S $S Nil $H))) +; + (= (translate-rule @@ -39,6 +42,8 @@ (reverse $StL $RStL) (t-lp $LP $RStL $S $SR $Sem $H) (tidy $B1 $B))) +; + (= (translate-rule @@ -48,6 +53,8 @@ (<:> (::= $LP $RP) Nil) (= $H $B))) +; + (= @@ -59,6 +66,8 @@ (add-extra-args (:: (node $LP $StL $Number) $S $List2) $LP $H))) +; + (= (t-lp $LP $StL $S $SR $Sem $H) @@ -67,6 +76,8 @@ (add-extra-args (:: (node $LP $StL $Number) $S $SR) $LP $H))) +; + (= @@ -74,12 +85,16 @@ (set-det) $St $St $S $S (set-det)) (set-det)) +; + (= (t-rp Nil $St (Cons Nil $St) $S $S1 (= $S $S1)) (set-det)) +; + (= (t-rp @@ -88,6 +103,8 @@ (:: $NX) $St) $S $SR (c $S $X $SR)) (char $X $NX)) +; + (= (t-rp @@ -96,6 +113,8 @@ (:: $X) $St) $S $SR (c $S $X $SR)) (set-det)) +; + (= (t-rp @@ -105,6 +124,8 @@ (, (c $S $X $SR1) $RB)) ( (char $X $NX) (t-rp $R $St (Cons $NR $St) $SR1 $SR $RB))) +; + (= (t-rp @@ -114,11 +135,15 @@ (, (c $S $X $SR1) $RB)) ( (set-det) (t-rp $R $St (Cons $R $St) $SR1 $SR $RB))) +; + (= (t-rp {$T } $St $St $S $S $T) (set-det)) +; + (= (t-rp @@ -127,6 +152,8 @@ ( (set-det) (t-rp $T $St $St1 $S $SR1 $Tt) (t-rp $R $St1 $StR $SR1 $SR $Rt))) +; + (= (t-rp @@ -134,12 +161,16 @@ (Cons $N $St) $S $SR $Tt) (add-extra-args (:: $N $S $SR) $T $Tt)) +; + (= (t-rp $T $St (Cons $St1 $St) $S $SR $Tt) (add-extra-args (:: $St1 $S $SR) $T $Tt)) +; + (= @@ -147,28 +178,30 @@ ( (=.. $T $Tl) (append $Tl $L $Tl1) (=.. $T1 $Tl1))) +; + ; -; append([],L,L) :- !. +; ; -; append([X|R],L,[X|R1]) :- append(R,L,R1). +; ; -; reverse(X,RX) :- rev1(X,[],RX). +; ; ; ; -; rev1([],R,R) :- !. +; ; ; ; -; rev1([X|Y],Z,R) :- rev1(Y,[X|Z],R). +; @@ -177,6 +210,8 @@ (, $P1 $P2 $P3) $Q) (tidy (, $P1 $P2 $P3) $Q)) +; + (= (tidy @@ -185,10 +220,14 @@ ( (set-det) (tidy $P1 $Q1) (tidy $P2 $Q2))) +; + (= (tidy $A $A) (set-det)) +; + (= @@ -198,11 +237,15 @@ (set-det) (name $NX (:: $X)))) +; + (= (c - (Cons $X $S) $X $S) True) + (Cons $X $S) $X $S) True) +; + (= (grammar $File) ( (seeing $Old) @@ -210,11 +253,7 @@ (consume) (seen) (see $Old))) -; /* defined as a system predicate */ - -; ; :- asserta(( term_expansion(T,E) :- translate_rule(T,E) , ! )). -; ; :- asserta(( term_expansion(T,E) :- process_rule(T,E) , ! )). - +; @@ -223,14 +262,20 @@ ( (repeat) (read $X) (check-it $X))) +; + (= (check-it $X) - ( (= $X end-of-file) (set-det))) + ( (= $X end-of-file) (set-det))) +; + (= (check-it $X) ( (process $X) (fail))) +; + (= @@ -242,28 +287,27 @@ (::= $H $T))) (set-det) (translate-rule $Grammar $Clause) - (add-atom &self $Clause) + (add-symbol &self $Clause) (set-det))) +; + (= (process !$G) ( (set-det) $G)) -; ; Execute a command - +; (= (process (= $P $Q)) - ( (set-det) (add-atom &self (:- $P $Q)))) -; ; Store a normal clause - + ( (set-det) (add-symbol &self (:- $P $Q)))) +; (= (process $P) - (add-atom &self $P)) -; ; Store a unit clause - + (add-symbol &self $P)) +; @@ -271,39 +315,33 @@ (^^ (node $NonTerminal $Trees $Index) $Args) (semantic-rule $Index $Args $NonTerminal $Trees)) -; /* -; process_rule(T,E) :- -; translate_rule(T,E), -; !, -; assert(T). -; */ - +; ; -; fast? +; (= (prod-number $X) - ( (remove-atom &self + ( (remove-symbol &self (rule_number $X)) (is $X1 (+ $X 1)) - (add-atom &self + (add-symbol &self (rule_number $X1)))) -; /* -; get_sem(NonTerminal,Trees,Index,Head) :- -; semantic_rule(Index,NonTerminal,Trees,Head). -; */ - +; !(dynamic (/ rule-number 1)) +; + (= (rule_number 0) True) +; + (= @@ -316,11 +354,13 @@ (, (= $Head $Rule) (= $Body True))) - (add-atom &self + (add-symbol &self (:- (semantic_rule $Number $Head $LP $StL) (, ! $Body))) (assert-semantic-rule $Number $LP $StL $Rules))) +; + (= (assert-semantic-rule $Number $LP $StL $Rule) @@ -329,7 +369,9 @@ (::- $Head $Body)) (, (= $Head $Rule) - (= $Body True))) (add-atom &self (:- (semantic_rule $Number $Head $LP $StL) (, ! $Body))))) + (= $Body True))) (add-symbol &self (:- (semantic_rule $Number $Head $LP $StL) (, ! $Body))))) +; + diff --git a/sre_dna/dctg_gen.metta b/sre_dna/dctg_gen.metta index d2abac7..8692f9b 100644 --- a/sre_dna/dctg_gen.metta +++ b/sre_dna/dctg_gen.metta @@ -1,67 +1,67 @@ ; -; DCTG based tree generation for GP +; ; -; Brian Ross +; ; -; January, 1999 +; ; -; generate_tree(TopGoal, TreeType, MaxDepth, UserArgs, Tree, Expr): +; ; -; TopGoal - name of top of tree to generate +; ; -; TreeType - either grow or full +; ; -; MaxDepth - maximum depth of tree +; ; -; UserArgs - list of user-specified args to use in top of rule +; ; -; Tree - Resulting tree, in DCTG node structure +; ; -; Expr - DCTG expression list equivalent of Tree +; ; ; ; -; Generates a tree of Type and max Depth, with UserArgs used in head of rule. +; ; -; With the node structure of Tree, it should be possible to access all +; ; -; semantic rules. Any embedded MeTTa in DCTG definition of rules is executed +; ; -; as tree is generated; this permits Expr to be constructed. This means +; ; -; that user must ensure embedded MeTTa goals will execute correctly. +; ; -; The node structure inserted into call has it's ID removed, to permit random +; ; -; selection. Any user arg structures in the tree structure are not used +; ; -; afterwards. 'verification' must be called to account for them. +; (= (generate-tree $TopGoal $TreeType $MaxDepth $UserArgs $Tree $Expr) ( (with_self - (fast) + (fast *) (dctg-rule-info $TopGoal $_ $RuleHead $_ $_)) (=.. $RuleHead (Cons $Name $Args)) @@ -76,23 +76,20 @@ (Cons $Name $Args2)) (set-det) (once (gen-tree $RuleHead2 $TreeType $MaxDepth)))) -; ; enforce empty diff list - -; ; new - +; ; -; gen_tree(RuleHead, TreeType, Depth): +; ; -; RuleHead - Head of rule at root of tree +; ; -; TreeType - full or grow +; ; -; Depth - current depth to make tree +; @@ -101,24 +98,23 @@ ( (is $Depth2 (- $Depth 1)) (select-random-rule $TreeType $Depth $RuleHead) - (get-atoms &self + (get-symbols &self (= $RuleHead $Body)) (process-goals $Body $TreeType $Depth2))) -; ; select_random_rule(TreeType, Depth2, RuleHead), - +; ; -; process_goals(Goals, TreeType, Depth): +; ; -; Goals - goals to generate subtrees for +; ; -; TreeType - grow or full +; ; -; Depth - current depth to make tree +; @@ -128,8 +124,10 @@ ( (set-det) (process-goals $A $TreeType $Depth) (process-goals $B $TreeType $Depth))) +; + ; -; !. +; (= (process-goals $A $TreeType $Depth) @@ -137,36 +135,38 @@ (is-a-rule-call $A) (gen-tree $A $TreeType $Depth) (call $A))) +; + ; -; select_random_rule(TreeType, MaxDepth, RuleHead): +; ; -; TreeType - grow or full +; ; -; MaxDepth - maximum depth of resulting tree +; ; -; RuleHead - Head of selected rule +; ; ; ; -; Randomly select a rule for given RuleHead structure, based on type and +; ; -; max depth. The RuleHead args are unified with head of rule to use. +; ; -; On backtracking, new selections are tried. Random selection done by +; ; -; generating a shuffled list of rules to try, and each is tried in succession. +; ; -; Possible for this to fail, depending on MaxDepth value. +; @@ -177,65 +177,63 @@ (shuffle-rule-list $RuleName $TreeType $RuleList) (member $ID $RuleList) (with_self - (fast) + (fast *) (dctg-rule-info $_ $ID $RuleHead $MinDepth $_)) (=< $MinDepth $MaxDepth) (set-det))) -; ; may backtrack to here - -; ; otherwise exceeds Depth; forces backtracking - +; ; -; new: June 11/99 +; ; -; shuffle_rule_list(RuleName, Type, RuleList): +; ; -; RuleName - name of rule to make list for +; ; -; Type - grow or full +; ; -; RuleList - shuffled list of rule ID's +; ; ; ; -; Returns a shuffled list of rule ID's for given rule. +; ; -; Grow tree has terminal and nonterminal rules shuffled together. +; ; -; Full tree has nonterminals shuffled first, followed by terminals. +; ; -; Idea is that rules will be tried one after another from this list. +; (= (shuffle-rule-list $RuleName grow $RuleList) ( (with_self - (fast) + (fast *) (dctg-id-table $RuleName $IDList $_ $_)) (random-permutation $IDList $RuleList) (set-det))) +; + (= (shuffle-rule-list $RuleName full $RuleList) ( (with_self - (fast) + (fast *) (dctg-id-table $RuleName $_ $TermList $NontermList)) (random-permutation $TermList $T1) (random-permutation $NontermList $T2) (append $T2 $T1 $RuleList) (set-det))) -; ; nonterms have precedence - +; diff --git a/sre_dna/dctg_pp.metta b/sre_dna/dctg_pp.metta index b83a9eb..c86d74e 100644 --- a/sre_dna/dctg_pp.metta +++ b/sre_dna/dctg_pp.metta @@ -1,61 +1,61 @@ ; -; Brian Ross +; ; -; Dec 10, 1998 +; ; -; DCTG post-processor: generates relevant tables needed by GP processing. +; ; ; ; -; 1. dctg_rule_info(Name, ID, Call, MinDepth, Type) +; ; -; Name = name of rule +; ; -; ID = DCTG ID label +; ; -; Call = call image for DCTG rule invocation +; ; -; MinDepth = minimum depth to terminal generation +; ; -; Type = terminal, nonterminal +; ; ; ; -; 2. dctg_id_table(Name, IDList, TermList, NontermList) +; ; -; Name = functor name +; ; -; IDList = list of rule ID's for that functor +; ; -; TermList, NontermList = lists of terminals, nonterminals +; ; ; ; -; Some assumptions: +; ; -; - Grammar rules should be uniquely identifiable by functor name. +; ; -; Should not use same functor name for different arity grammar rules! +; @@ -66,30 +66,34 @@ (generate-rule-data) (enhance-rule-id-list) (set-det))) +; + (= (cleanup-grammar-data) - ( (remove-all-atoms &self + ( (remove-all-symbols &self (dctg_rule_info $_ $_ $_ $_)) - (remove-all-atoms &self + (remove-all-symbols &self (dctg_id_table $_ $_ $_ $_)) (set-det))) +; + ; -; get_rule_name constructs a call to a DCTG rule, such that all the args are +; ; -; variable except for the node structure, which has the ID number set. +; ; -; This uniquely identifies a DCTG rule header. +; (= (get-rule-name $Call2) - ( (get-atoms &self + ( (get-symbols &self (= (semantic_rule $ID $_ $Call $_) $_)) (=.. $Call @@ -100,32 +104,38 @@ (node $_ $_ $ID) $_ $_) $AllArgs) (=.. $Call2 (Cons $Name $AllArgs)))) +; + ; -; Given a list, clone_list creates a list of the same size, +; ; -; but with uninst. args +; (= (clone-list Nil Nil) (set-det)) +; + (= (clone-list (Cons $_ $T) (Cons $_ $T2)) ( (clone-list $T $T2) (set-det))) +; + ; -; generate_rule_data gets all the rule headers (Calls) and finds: (i) the +; ; -; minimum depth to terminals for each rule; (ii) whether a rules is a +; ; -; terminal or nonterminal. Result saved in dctg_rule_info/4. +; @@ -138,60 +148,64 @@ (grammar-type-top-loop $Calls2 Nil Nil $Terminal) (set-rule-data $Calls3 $Terminal) (set-det))) +; + ; -; grammar_depth_top_loop(Calls, Known, MinCalls, Known2) +; ; -; Processes rules until all have min depths found, or no changes occurred +; ; -; (which means there's a problem with the rules). +; ; -; Calls - rules to process +; ; -; Known - rules with min depths +; ; -; MinCalls - overall minimum for entire rules, to be used in goal analysis +; ; -; Known - new Known set +; ; ; ; -; Algorithm for depth determination: +; ; -; Repeat until no unknown rules (hopefully! else there's infinite recursion) +; ; -; Process all unknown rules: +; ; -; If all goals have known minimum depths in a rule +; ; -; then find maximum of these and add to Known list +; ; -; Process all Known rules: +; ; -; If a new rule has been added to Known (not in Minimum list) +; ; -; then add it to Minimum list. +; (= (grammar-depth-top-loop Nil $Known $_ $Known) (set-det)) +; + (= (grammar-depth-top-loop $Calls $Known $MinCalls $Known3) ( (process-rules $Calls $Known $MinCalls Nil $Known2 $Unknown) @@ -218,38 +232,39 @@ (fail)) (grammar-depth-top-loop $Unknown $Known2 $MinCalls2 $Known3)) (set-det))) -; ; if no changes... - +; ; -; process_rules(Calls, Known, MinCalls, Unknown, Known2, Unknown2): +; ; -; Calls - to process +; ; -; Known, Unknown - rules with known/unknown minima +; ; -; MinCalls - solved rules (can be used in body analyses of other rules) +; ; -; Known2, Unknown2 - final values of above +; ; -; Find depth of body for rules. If available, add rule to Known, else Unknown. +; (= (process-rules Nil $Known $_ $Unknown $Known $Unknown) (set-det)) +; + (= (process-rules (Cons $Call $Rest) $Known $MinCalls $Unknown $Known2 $Unknown2) ( (copy-term $Call $Call2) - (get-atoms &self + (get-symbols &self (= $Call2 $Body)) (find-min-depth-body $Body $MinCalls 0 $BodyDepth) (set-det) @@ -258,19 +273,23 @@ (process-rules $Rest (Cons (, $Call $MinD) $Known) $MinCalls $Unknown $Known2 $Unknown2))) +; + (= (process-rules (Cons $Call $Rest) $Known $MinCalls $Unknown $Known2 $Unknown2) ( (set-det) (process-rules $Rest $Known $MinCalls (Cons $Call $Unknown) $Known2 $Unknown2))) +; + ; -; find_min_depth_body(Body, MinCalls, MinDSoFar, MinD) +; ; -; Finds the depth value of body (max of all min vals of goals in body). +; ; -; Fails if an goal with unknown depth is found. +; @@ -283,10 +302,14 @@ (is $MinDSoFar2 (max $Val $MinDSoFar)) (find-min-depth-body $Rest $MinCalls $MinDSoFar2 $MinD))) +; + (= (find-min-depth-body (, $_ $Rest) $MinCalls $MinDSoFar $MinD) ( (set-det) (find-min-depth-body $Rest $MinCalls $MinDSoFar $MinD))) +; + (= (find-min-depth-body $Goal $MinCalls $MinDSoFar $MinD) ( (is-a-rule-call $Goal) @@ -294,15 +317,19 @@ (find-min-depth $Goal $MinCalls $Val) (is $MinD (max $Val $MinDSoFar)))) +; + (= (find-min-depth-body $_ $_ $MinD $MinD) (set-det)) +; + ; -; find_min_depth searches for goal name in list, and returns corresp. +; ; -; depth if found. +; @@ -312,13 +339,17 @@ (, $G $M) $_) $M) ( (=.. $Goal (Cons $G $_)) (set-det))) +; + (= (find-min-depth $Goal (Cons $_ $R) $M) ( (find-min-depth $Goal $R $M) (set-det))) +; + ; -; is_a_rule_call checks if a goal refers to a DCTG rule +; @@ -328,24 +359,28 @@ (Cons $Name $_)) (dctg-id-table $Name $_ $_ $_) (set-det))) +; + ; -; find_rule_mins(Calls, MinCalls, MinCalls2): +; ; -; Checks the current Known list for new overall minimum depths. +; ; -; If a goal shows up in Known for the first time (ie. not in MinCalls) +; ; -; then it's depth value must be the minimum for that rule set: add it as such. +; (= (find-rule-mins Nil $MinCalls $MinCalls) (set-det)) +; + (= (find-rule-mins (Cons @@ -357,13 +392,17 @@ (find-rule-mins $Rest (Cons (, $CallName $Depth) $MinCalls) $MinCalls2))) +; + (= (find-rule-mins (Cons $_ $Rest) $MinCalls $MinCalls2) (find-rule-mins $Rest $MinCalls $MinCalls2)) +; + ; -; abstract_member checks if functor names match +; @@ -372,22 +411,28 @@ (Cons (, $First $_) $_)) (=.. $First - (Cons $GoalName $_))) + (Cons $GoalName $_))) +; + (= (abstract-member $GoalName (Cons $_ $Rest)) - (abstract-member $GoalName $Rest)) + (abstract-member $GoalName $Rest)) +; + ; -; find_minimum_depth(Name, Calls, MinSoFar, Min): +; ; -; Finds the minimum depth value for Name in list of Calls. +; (= (find_minimum_depth $_ () $D $D) True) +; + (= (find-minimum-depth $CallName (Cons @@ -398,47 +443,51 @@ (min $D $MinSoFar)) (find-minimum-depth $CallName $Rest $NewMin $MinDepth) (set-det))) +; + (= (find-minimum-depth $CallName (Cons $_ $Rest) $MinSoFar $MinDepth) ( (find-minimum-depth $CallName $Rest $MinSoFar $MinDepth) (set-det))) +; + ; -; grammar_type_top_loop(Calls, Terms, Nonterms, Terms2): +; ; -; Calls - rules to process +; ; -; Terms, Nonterms - terminals and nonterminals so far +; ; -; Terms2 - final results of above +; ; ; ; -; Determine if rules can be classified as terminals. +; ; -; Processing continues until no change in the set of rules that are unknown - +; ; -; these leftovers are classified as 'nonterminals'. +; ; -; First, user-override is checked. If it fail's then analysis done. +; ; -; See 'rule_type' for more details. +; ; -; Note that intermediate nonterminal determination is done as well; +; ; -; this could be deleted in the future to save some processing. +; @@ -452,41 +501,49 @@ (= $Terms3 $Terms2) (grammar-type-top-loop $Unknown $Terms3 $Nonterms3 $Terms2)) (set-det))) +; + (= (grammar-type-loop Nil $Unknown $Term $Nonterm $Unknown $Term $Nonterm) (set-det)) +; + (= (grammar-type-loop (Cons $Call $Rest) $Unknown $Term $Nonterm $Unknown2 $Term2 $Nonterm2) ( (user-override $Call $Term $Nonterm $Term3 $Nonterm3) (grammar-type-loop $Rest $Unknown $Term3 $Nonterm3 $Unknown2 $Term2 $Nonterm2))) +; + (= (grammar-type-loop (Cons $Call $Rest) $Unknown $Term $Nonterm $Unknown2 $Term2 $Nonterm2) ( (copy-term $Call $Call2) - (get-atoms &self + (get-symbols &self (= $Call2 $Body)) (goal-type $Call $Body $Rest $Unknown $Term $Nonterm $Unknown3 $Term3 $Nonterm3) (grammar-type-loop $Rest $Unknown3 $Term3 $Nonterm3 $Unknown2 $Term2 $Nonterm2))) +; + ; -; user_override(Call, Term, Nonterm, Term2, Nonterm2): +; ; -; Call - rule head to process +; ; -; Term, Nonterm - list of rules identified as terms and nonterms +; ; -; Term2, Nonterm2 - final values of Term, Nonterm +; ; -; If the user has Call functor name in dctg_override parameter lists, then +; ; -; add that call to term or nonterm as appropriate. Otherwise, fail. +; @@ -498,6 +555,8 @@ (dctg-override-P $OverTerm $_) (member $Name $OverTerm) (set-det))) +; + (= (user-override $Call $Term $Nonterm $Term (Cons $Call $Nonterm)) @@ -506,55 +565,57 @@ (dctg-override-P $_ $OverNonterm) (member $Name $OverNonterm) (set-det))) +; + ; -; goal_type(Call, Body, Unknown, Term, Nonterm, Unknown2, Term2, Nonterm2) +; ; -; Call - current head of rule being analyzed +; ; -; Body - body of current rule +; ; -; Rest - rules not yet processed +; ; -; Unknown - unknown classifications +; ; -; Term, Nonterm - Rules known to be terminal or nonterminal +; ; -; Unknown2,Term2,Nonterm2 - Final values of results +; ; ; ; -; This performs abstract interp of a single rule body. +; ; -; The order of tests in the following is critical. +; ; -; 1. If goal is a nonterm, then that rule is a nonterm. +; ; -; 2. If goal is same as rule name, then that rule is a nonterm. +; ; -; 3. If a goal is unknown, or not yet processed, +; ; -; then that rule is unknown. +; ; -; 4. Else if the rest of the goals in that clause are term, +; ; -; then that rule is terminal. +; @@ -569,8 +630,7 @@ (abstract-member2 $A $NT) (same-goal $Call $A)) (set-det))) -; ; 1, 2 - +; (= (goal-type $Call $Goals $Rest $U $T $NT @@ -583,22 +643,25 @@ (abstract-member2 $A $U) (abstract-member2 $A $Rest)) (set-det))) -; ; 3 - +; (= (goal-type $Call (, $_ $B) $Rest $U $T $NT $U2 $T2 $NT2) ( (set-det) (goal-type $Call $B $Rest $U $T $NT $U2 $T2 $NT2))) +; + (= (goal_type $Call $_ $_ $U $T $NT $U - (Cons $Call $T) $NT) True) ; -; 4 + (Cons $Call $T) $NT) True) +; + ; +; ; -; abstract_member2 checks if functor names match +; @@ -606,10 +669,14 @@ (abstract-member2 $Goal (Cons $First $_)) (same-goal $Goal $First)) +; + (= (abstract-member2 $Goal (Cons $_ $Rest)) - (abstract-member2 $Goal $Rest)) + (abstract-member2 $Goal $Rest)) +; + (= @@ -619,15 +686,19 @@ (=.. $B (Cons $N $_)) (set-det))) +; + ; -; save depths, term/nonterm in dctg_rule_info assertions +; (= (set-rule-data Nil $_) (set-det)) +; + (= (set-rule-data (Cons @@ -641,19 +712,21 @@ (member $Rule $Terminal) (= $Type terminal) (= $Type nonterminal)) - (add-atom &self + (add-symbol &self (dctg_rule_info $Name $ID $Rule $Depth $Type)) (set-rule-data $Rest $Terminal) (set-det))) +; + ; -; make_rule_id_list makes a table giving rule name and the ID numbers of its +; ; -; associated rules. Last 2 args are placeholders for term and nonterm lists, +; ; -; to be set later. +; @@ -664,52 +737,68 @@ (make-rule-id-list2 $Name $IDs) $RuleIDs) (make-id-entries $RuleIDs) (set-det))) +; + (= (make-rule-id-list2 $Name $RuleIDs2) ( (bagof $ID (get-rule-stuff $Name $ID) $RuleIDs) (rem-dups $RuleIDs $RuleIDs2))) +; + (= (get-rule-stuff $Name $ID) - ( (get-atoms &self + ( (get-symbols &self (= (semantic_rule $ID $_ $Call $_) $_)) (=.. $Call (Cons $Name $_)))) +; + (= (make-id-entries Nil) (set-det)) +; + (= (make-id-entries (Cons (, $Name $IDs) $Rest)) - ( (add-atom &self + ( (add-symbol &self (dctg_id_table $Name $IDs $_ $_)) (make-id-entries $Rest) (set-det))) +; + ; -; enhance each dctg_id_table entry with list of which rules are terminal, +; ; -; and which are nonterminal. +; (= (enhance-rule-id-list) - ( (remove-atom &self + ( (remove-symbol &self (dctg_id_table $Name $IDs $_ $_)) (identify-type $IDs $Terms $Nonterms) - (add-atom &self + (add-symbol &self (dctg_id_table $Name $IDs $Terms $Nonterms)) (fail))) +; + (= enhance_rule_id_list True) +; + (= (identify_type () () ()) True) +; + (= (identify-type (Cons $ID $Rest) @@ -717,10 +806,14 @@ ( (dctg-rule-info $_ $ID $_ $_ terminal) (set-det) (identify-type $Rest $Terms $Nonterms))) +; + (= (identify-type (Cons $ID $Rest) $Terms (Cons $ID $Nonterms)) (identify-type $Rest $Terms $Nonterms)) +; + diff --git a/sre_dna/dctg_reprod.metta b/sre_dna/dctg_reprod.metta index 2050c6e..7f3884e 100644 --- a/sre_dna/dctg_reprod.metta +++ b/sre_dna/dctg_reprod.metta @@ -1,64 +1,64 @@ ; -; DCTG based GP reproduction operators: crossover & mutation +; ; -; Brian Ross +; ; -; January 25, 1999 +; ; -; crossover(Parent1, Parent2, Child1, Child2): +; ; -; Parent1, Parent2 - parent trees to reproduce +; ; -; Child1, Child2 - resulting children +; ; -; Performs grammar tree expression crossover on two parents. +; ; -; If internal crossover probability set, then nodes of the specified type +; ; -; are selected; else all nodes initially counted. +; ; -; The rules for crossover are: +; ; -; - only nodes of same rule name from each parent are crossed +; ; -; - crossover is attempted a max N number of times until successful +; ; -; (user-specified parameter) +; ; -; - an attempt fails if the offspring exceed max depth parameter +; ; -; - if no internal/leaf counting, then counts on all node names done. +; ; -; - if internal/leaf counting to be done (case 1), then it is done only +; ; -; for one parent. (If it fails, then 2nd parent tried; if that fails, +; ; -; then all nodes counted from first parent). Other parent just uses +; ; -; terminal name count (increases odds that a crossover will be +; ; -; possible). +; @@ -84,8 +84,7 @@ (, $P2 $P1)))) (do-crossover $Tries $Parent1 $N1 $Parent2 $C1 $C2) (set-det))) -; ; case 2 - +; (= (crossover $P1 $P2 $C1 $C2) @@ -93,14 +92,15 @@ (once (count-nodes $P1 all $N1)) (do-crossover $Tries $P1 $N1 $P2 $C1 $C2) (set-det))) -; ; case 1 - +; (= (do-crossover 0 $_ $_ $_ $_ $_) ( (set-det) (fail))) +; + (= (do-crossover $_ $Parent1 $N1 $Parent2 $Child1 $Child2) ( (my-random $N1 $K1) @@ -111,10 +111,7 @@ (tree-verification $Child1) (tree-verification $Child2) (set-det))) -; ;writel(['A:rand pick ', K1, ' from ', N1, '.', nl]), - -; ;writel(['B:rand pick ', K2, ' from ', N2, ' ', NodeName, ' nodes.', nl]), - +; (= (do-crossover $Tries $Parent1 $N1 $Parent2 $Child1 $Child2) @@ -122,15 +119,14 @@ (- $Tries 1)) (do-crossover $Tries2 $Parent1 $N1 $Parent2 $Child1 $Child2) (set-det))) -; ;writel(['Try ', Tries2, nl]), - +; ; -; check that a new Tree doesn't fail due to +; ; -; failed embedded code in DCTG rules. +; @@ -141,31 +137,26 @@ (, (user-args-P $Args) (verification $Child $Args $_)) True) (set-det))) -; ;writel(['tree_verif: testing child:',nl]), - -; ;prettyprint(Child), - -; ;writel(['tree_verif: verification succeeded.',nl]) - +; ; -; count_nodes(Tree, NodeName, NumNodes): +; ; -; Tree - DCTG expression structure +; ; -; NodeName - name of node to count (otherwise: all nodes = 'all'; +; ; -; all internal = 'internal'; all leaf = 'leaf') +; ; -; NumNodes - number of nodes in Tree +; ; -; Scans Tree and counts number of nodes. +; @@ -176,48 +167,62 @@ (count-children-nodes $Children all $NumNodes2) (is $NumNodes (+ $NumNodes2 1)))) +; + (= (count-nodes (node $_ $Children $ID) $Type $NumNodes) ( (== $Type internal) (with_self - (fast) + (fast *) (dctg-rule-info $_ $ID $_ $_ nonterminal)) (set-det) (count-children-nodes $Children $Type $NumNodes2) (is $NumNodes (+ $NumNodes2 1)))) +; + (= (count-nodes (node $_ $Children $ID) $Type $NumNodes) ( (== $Type leaf) (with_self - (fast) + (fast *) (dctg-rule-info $_ $ID $_ $_ terminal)) (set-det) (count-children-nodes $Children $Type $NumNodes2) (is $NumNodes (+ $NumNodes2 1)))) +; + (= (count-nodes (node $_ $Children $ID) $NodeName $NumNodes) ( (with_self - (fast) + (fast *) (dctg-rule-info $NodeName $ID $_ $_ $_)) (set-det) (count-children-nodes $Children $NodeName $NumNodes2) (is $NumNodes (+ $NumNodes2 1)))) +; + (= (count-nodes (node $_ $Children $_) $NodeName $NumNodes) ( (set-det) (count-children-nodes $Children $NodeName $NumNodes))) +; + (= (count_nodes $_ $_ 0) True) +; + (= (count_children_nodes () $_ 0) True) +; + (= (count-children-nodes (Cons $Node $Rest) $NodeName $NumNodes) @@ -226,66 +231,68 @@ (is $NumNodes (+ $NumNodes2 $NumNodes3)) (set-det))) +; + ; -; select_subtree(Parent, K, K2, NewParent, SubTree, Hole, NodeName): +; ; -; Parent - parent tree structure +; ; -; K - Kth node to select in Parent; must be < number nodes in Parent. +; ; -; K2 - final K during structure traversal +; ; -; NewParent - Parent structure with variable Hole in place of removed +; ; -; subtree Subtree +; ; -; Subtree - subtree to swap +; ; -; Hole - location of hole in ParentWithHole (variable) +; ; -; NodeName - node name of Subtree to select from; if variable, then +; ; -; select from all nodes +; ; -; Selects a Kth node in tree for crossover of type NodeName (or all, if +; ; -; NodeName not set). Sets up the new tree with Hole placeholder for selected +; ; -; subtree. Hole may be already unified with other parent's subtree. +; ; -; Cases: +; ; -; 1. Count = 0, var name --> use that node +; ; -; 2. Count = 0, name matches given --> use that node +; ; -; 3. Count > 0, var name or name match -> count and continue +; ; -; 4. name doesn't match given --> skip and continue +; ; -; 5. else stop at given count (we've exhausted tree, and we're at +; ; -; non-node component) +; @@ -296,14 +303,13 @@ ( (or (var $NodeName) (with_self - (fast) + (fast *) (dctg-rule-info $NodeName $ID $_ $_ $_))) (set-det) (with_self - (fast) + (fast *) (dctg-rule-info $NodeName $ID $_ $_ $_)))) -; ; cases 1, 2 - +; (= (select-subtree @@ -312,41 +318,45 @@ ( (or (var $NodeName) (with_self - (fast) + (fast *) (dctg-rule-info $NodeName $ID $_ $_ $_))) (set-det) (is $K3 (- $K 1)) (select-subtree-children $Kids $K3 $K2 $Kids2 $Subtree $Hole $NodeName))) -; ; case 3 - +; (= (select-subtree (node $Name $Kids $ID) $K $K2 (node $Name $Kids2 $ID) $Subtree $Hole $NodeName) ( (set-det) (select-subtree-children $Kids $K $K2 $Kids2 $Subtree $Hole $NodeName))) -; ; case 4 - +; (= - (select_subtree $Node $K $K $Node $_ $_ $_) True) ; -; case 5 + (select_subtree $Node $K $K $Node $_ $_ $_) True) +; + ; +; ; -; select_subtree_children applies select_subtree to list of nodes. +; (= (select-subtree-children Nil $K $K Nil $_ $_ $_) (set-det)) +; + (= (select-subtree-children (Cons $Node $T) $K $K2 (Cons $Node2 $T2) $Subtree $Hole $Name) ( (select-subtree $Node $K $K3 $Node2 $Subtree $Hole $Name) (det-if-then-else (== $K3 0) (, (= $T $T2) (= $K3 $K2)) (select-subtree-children $T $K3 $K2 $T2 $Subtree $Hole $Name)))) +; + (= @@ -366,6 +376,8 @@ (prettyprint $C1) (writel (:: Child2... nl)) (prettyprint $C2))) +; + (= @@ -381,40 +393,42 @@ (prettyprint $C1) (writel (:: Child2... nl)) (prettyprint $C2))) +; + ; -; --------------------------- +; ; -; mutation(Parent, Child): +; ; -; Parent - tree to mutate +; ; -; Child - mutated result +; ; -; Performs mutation on a tree. A subtree is randomly selected. Then a +; ; -; new subtree of the same type as selected one is generated using grow +; ; -; generation, and it replaces the selected subtree. If the resulting tree +; ; -; is too deep, then it is repeated a maximum number of user-specified times. +; ; -; If the user is using terminal mutation probability (Case 1) then all nodes +; ; -; of that type (if it succeeds statisticall) are counted. If none exist, then +; ; -; all nodes counted (case 2). +; @@ -423,11 +437,15 @@ ( (reprod-P $Tries) (do-mutation $Tries $Parent $Child) (set-det))) +; + (= (do-mutation 0 $_ $_) ( (set-det) (fail))) +; + (= (do-mutation $_ $Parent $Child) ( (prob-terminal-mutation-P $PT) @@ -445,12 +463,7 @@ (generate-tree $NodeName grow $NewDepth $_ $NewTree $_) (tree-verification $Child) (set-det))) -; ; case 1 - -; ;writel(['rand pick ', K, ' from ', N, '.', nl]), - -; ; a subtree with a node type has depth > 1 - +; (= (do-mutation $_ $Parent $Child) @@ -463,12 +476,7 @@ (generate-tree $NodeName grow $NewDepth $_ $NewTree $_) (tree-verification $Child) (set-det))) -; ; case 2 - -; ;writel(['rand pick ', K, ' from ', N, '.', nl]), - -; ; a subtree with a node type has depth > 1 - +; (= (do-mutation $Tries $Parent $Child) @@ -476,8 +484,7 @@ (- $Tries 1)) (do-mutation $Tries2 $Parent $Child) (set-det))) -; ;writel(['Try countdown... ', Tries2, nl]), - +; @@ -490,47 +497,49 @@ (prettyprint $Parent) (writel (:: Child... nl)) (prettyprint $Child))) +; + ; -; --------------------------- +; ; -; verification(Tree, UserArgs, Expr): +; ; -; Tree - DCTG tree to verify +; ; -; UserArgs - Argument list to pass to DCTG rules +; ; -; Expr - list expression for Tree +; ; -; The DCTG tree is verified by interpreting the MeTTa DCTG rules +; ; -; in concert with the Tree structure. The purpose of this is to +; ; -; execute any embedded MeTTa in the rules, which are +; ; -; not retained in the tree data structure itself. User args as set by user_args +; ; -; parameter are also used (those embedded in MeTTa structure are irrelevant). +; ; -; This routine may cause a tree to fail, in that embedded MeTTa goals or +; ; -; user args fail. +; ; -; verification embeds user args into initial call of tree. +; @@ -538,7 +547,7 @@ (verification (node $Name $Kids $ID) $UserArgs $Expr) ( (with_self - (fast) + (fast *) (dctg-rule-info $_ $ID $Call $_ $_)) (=.. $Call (Cons $Name $Args)) @@ -553,29 +562,24 @@ (set-det) (verify-tree $RuleHead2 (node $Name $Kids $ID)))) -; ; embed user args, empty diff list - +; (= (verify-tree $Call (node $_ $Kids $ID)) - ( (get-atoms &self + ( (get-symbols &self (= $Call $Body)) (same-id $Call $ID) (set-det) (verify-kids $Body $Kids $_))) -; ;writel(['verify_tree: Call=', Call, 'node = ', N, ID, nl]), - -; ;writel(['verify_tree: Body= ', Body, 'Kids=', Kids,nl]), - +; (= (verify-tree $_ $_) ( (set-det) (fail))) -; ;writel(['verify_tree: failed', nl]), - +; @@ -585,6 +589,8 @@ ( (set-det) (verify-kids $A $Kids $Kids2) (verify-kids $B $Kids2 $Kids3))) +; + (= (verify-kids $A (Cons @@ -593,8 +599,7 @@ (set-det) (verify-tree $A (node $_ $Kids $ID)))) -; ;writel(['v_k 2: Call=', A, 'Node name = ', N, ID, nl]), - +; (= (verify-kids @@ -604,12 +609,7 @@ ( (set-det) (= $X $H) (c $A $X $B))) -; ; single constant - -; ; X == H, - -; ;writel(['v_k 3: Call=', c(A,X,B), 'List=', [[H]|T], nl]), - +; (= (verify-kids @@ -620,22 +620,16 @@ ( (set-det) (= $X $H) (c $A $X $B))) -; ; multiple constants - -; ; X == H, - -; ;writel(['v_k 4: Call=', c(A,X,B), 'List=', [[H|T2]|T], nl]), - +; (= (verify-kids $A $Kids $Kids) ( (set-det) (call $A))) -; ;writel(['v_k 5: Call=', A, 'Kids=', Kids, nl]), - +; ; -; Warning: user cannot use node/3 structure in their user arg fields! +; @@ -647,8 +641,7 @@ (node $_ $_ $ID2) $Args) (set-det) (== $ID $ID2))) -; ; append(_, [node(_, _, ID)|_], Args), - +; diff --git a/sre_dna/dctg_utils.metta b/sre_dna/dctg_utils.metta index f172e51..c554b9e 100644 --- a/sre_dna/dctg_utils.metta +++ b/sre_dna/dctg_utils.metta @@ -1,22 +1,24 @@ ; -; Misc DCTG utilities. +; ; -; B. Ross +; ; -; January 1999 +; ; -; Pretty-printer... +; (= (prettyprint $Tree) ( (pretty $Tree 0) (set-det))) +; + (= @@ -30,6 +32,8 @@ (+ $Tab 1)) (prettykids $Kids $Tab2) (set-det))) +; + (= (pretty $Value $Tab) ( (is $T @@ -37,20 +41,26 @@ (tab $T) (writel (:: $Value nl)) (set-det))) +; + (= (prettykids Nil $_) (set-det)) +; + (= (prettykids (Cons $Node $Rest) $Tab) ( (pretty $Node $Tab) (prettykids $Rest $Tab) (set-det))) +; + ; -; DCTG tree depth measurer... +; @@ -61,14 +71,20 @@ (is $D (+ $D2 1)) (set-det))) +; + (= (tree-depth $_ 1) (set-det)) +; + (= (tree-depth-kids Nil 0) (set-det)) +; + (= (tree-depth-kids (Cons $Node $Rest) $D) @@ -77,9 +93,11 @@ (is $D (max $D2 $D3)) (set-det))) +; + ; -; listprint converts tree to list, using DCTG verification +; @@ -90,5 +108,7 @@ (writel2 $List) (nl) (set-det))) +; + diff --git a/sre_dna/dna_proc.metta b/sre_dna/dna_proc.metta index 4d8c0ef..200c5e5 100644 --- a/sre_dna/dna_proc.metta +++ b/sre_dna/dna_proc.metta @@ -1,15 +1,15 @@ ; -; Nov/99 +; ; -; DNA data processing +; ; -; 1. remove duplicates +; ; -; 2. break up upper-case constants to lists of lower-case constants +; @@ -18,12 +18,14 @@ ( (remove-dups $List $List2) (conv-to-lc-atoms $List2 $List3) (make-new-alpha $List3))) +; + ; -; dna_proc2 done by unaligned processing. Pad examples with random +; ; -; alphabet. Don't filter alphabet either, like in dna_proc. +; @@ -37,28 +39,38 @@ (length $S $L) (is $PadSize (integer (/ (- $StrSize $L) 2))) - (pad-randomly $List3 $PadSize $List4))) + (pad-randomly $List3 $PadSize $List4))) +; + (= (remove-dups Nil Nil) (set-det)) +; + (= (remove-dups (Cons $A $R) $S) ( (member $A $R) (set-det) (remove-dups $R $S))) +; + (= (remove-dups (Cons $A $R) (Cons $A $S)) (remove-dups $R $S)) +; + (= (conv-to-lc-atoms Nil Nil) (set-det)) +; + (= (conv-to-lc-atoms (Cons $A $R) @@ -66,11 +78,15 @@ ( (name $A $L) (conv-to-lc-atoms2 $L $B) (conv-to-lc-atoms $R $S))) +; + (= (conv-to-lc-atoms2 Nil Nil) (set-det)) +; + (= (conv-to-lc-atoms2 (Cons $A $R) @@ -80,14 +96,15 @@ (name $B (:: $A2)) (conv-to-lc-atoms2 $R $S))) -; ; upper-case ascii to lower ascii - +; (= (sum-lengths Nil 0) (set-det)) +; + (= (sum-lengths (Cons $A $R) $S) @@ -95,15 +112,19 @@ (length $A $L) (is $S (+ $T $L)))) +; + ; -; makes N random sequences of size =< A. +; (= (make-random-strings $N $_ $_ Nil) ( (=< $N 0) (set-det))) +; + (= (make-random-strings $N $L $Plist (Cons $S $R)) @@ -115,12 +136,16 @@ (not (member $S $R)) (not (member $S $Plist)) (set-det))) +; + (= (make-randstring $N Nil) ( (or (=< $N 0) maybe) (set-det))) +; + (= (make-randstring $N (Cons $A $R)) @@ -129,6 +154,8 @@ (is $M (- $N 1)) (make-randstring $M $R))) +; + @@ -137,27 +164,35 @@ ( (append-all $List Nil $All) (remove-dups $All $All2) (length $All2 $L) - (remove-atom &self + (remove-symbol &self (alphabet_P $_ $_)) - (add-atom &self + (add-symbol &self (alphabet_P $L $All2)) (set-det))) +; + (= (append-all Nil $A $A) (set-det)) +; + (= (append-all (Cons $A $R) $B $C) ( (append $A $B $D) (append-all $R $D $C) (set-det))) +; + (= (pad-randomly Nil $_ Nil) (set-det)) +; + (= (pad-randomly (Cons $S $R) $Size @@ -168,11 +203,15 @@ (append $T $Right $S2) (set-det) (pad-randomly $R $Size $R2))) +; + (= (make-randstring3 $N Nil) ( (=< $N 0) (set-det))) +; + (= (make-randstring3 $N (Cons $A $R)) @@ -181,5 +220,7 @@ (is $M (- $N 1)) (make-randstring3 $M $R))) +; + diff --git a/sre_dna/dynamics.metta b/sre_dna/dynamics.metta index 921d343..85431f9 100644 --- a/sre_dna/dynamics.metta +++ b/sre_dna/dynamics.metta @@ -1,35 +1,59 @@ ; -; ------------------------------------------------ +; ; -; January 1999 +; ; -; Author: Brian Ross +; ; -; Dept. of Computer Science, Brock University +; ; ; ; -; dynamic definitions (make this the first file loaded) +; !(dynamic (/ individual 3)) +; + !(dynamic (/ newindividual 3)) +; + !(dynamic (/ popn-size-P 1)) +; + !(dynamic (/ best-so-far 4)) +; + !(dynamic (/ best-in-run 3)) +; + !(dynamic (/ gp-stats 8)) +; + !(dynamic (/ trace-count 2)) +; + !(dynamic (/ saved-trace 1)) +; + !(dynamic (/ popn-cnt 1)) +; + !(dynamic (/ current-run 1)) +; + !(dynamic (/ temp 1)) - !(dynamic (/ expression-type 1)) +; + + !(dynamic (/ expression-type 1)) +; + diff --git a/sre_dna/evaluation.metta b/sre_dna/evaluation.metta index 1c68bbd..02c597a 100644 --- a/sre_dna/evaluation.metta +++ b/sre_dna/evaluation.metta @@ -1,44 +1,44 @@ ; -; ------------------------------------------------ +; ; -; January 1999 +; ; -; Author: Brian Ross +; ; -; Dept. of Computer Science, Brock University +; ; ; ; -; Fitness evaluation. +; ; ; ; -; Evaluator/2 is user-supplied fitness function. +; ; -; It is then applied to initial population, which +; ; -; are reasserted with their fitness scores. +; ; ; ; -; The problem-specific evaluator should assign individuals a standardized +; ; -; fitness value (lower score is better, 0 is perfect). +; ; -; It's syntax must be: evaluator(Expr, Val) +; @@ -53,15 +53,17 @@ (cull-population $InitPopSize $PopSize) (collect-stats (- 0 culled)) (set-det))) +; + ; -; following only used for initial population... +; (= (evalInitialPopn) - ( (remove-atom &self + ( (remove-symbol &self (individual $ID $Fitness $Expression)) (det-if-then-else (var $Fitness) @@ -69,28 +71,33 @@ (eval-with-ID-P yes) (evaluator $ID $Expression $Fitness) (evaluator $Expression $Fitness)) True) - (add-atom &self + (add-symbol &self (individual $ID $Fitness $Expression)) (write ?) (ttyflush) (fail))) -; ; only reevaluate if not scored - +; (= (evalInitialPopn) (collect-stats (- 0 genesis))) +; + (= (cull-population $PopSize $PopSize) (set-det)) +; + (= (cull-population $InitPopSize $PopSize) ( (< $InitPopSize $PopSize) (set-det) (writel (:: 'Error: init pop size ' $InitPopSize '< pop size' $PopSize nl)) (fail))) +; + (= (cull-population $_ $PopSize) ( (cull-method-P elite) @@ -101,30 +108,34 @@ (, $V $K $E) (individual $K $V $E) $Set) (first-K 0 $PopSize $Set $Set2) - (remove-all-atoms &self + (remove-all-symbols &self (individual $_ $_ $_)) (assert-elite $Set2))) +; + (= (cull-population $CurrPopSize $PopSize) ( (tournament-select worst $CurrPopSize $ID $_) (write x) (ttyflush) - (remove-atom &self + (remove-symbol &self (individual $ID $_ $_)) (det-if-then-else (\== $ID $CurrPopSize) (, - (remove-atom &self + (remove-symbol &self (individual $CurrPopSize $Fit $Expr)) - (add-atom &self + (add-symbol &self (individual $ID $Fit $Expr))) True) (is $NewPopSize (- $CurrPopSize 1)) (set-det) (cull-population $NewPopSize $PopSize))) +; + ; -; save best in run and best so far (session) +; @@ -139,12 +150,16 @@ (< $Min $BestSoFar) (set-det) (individual $_ $Min $Expression) - (remove-atom &self + (remove-symbol &self (best_in_run $_ $_ $_)) - (add-atom &self + (add-symbol &self (best_in_run $Gen $Min $Expression)))) +; + (= (set_best_in_run $_) True) +; + (= @@ -153,25 +168,33 @@ (best-so-far $_ $_ $BV $_) (< $Value $BV) (set-det) - (remove-atom &self + (remove-symbol &self (best_so_far $_ $_ $_ $_)) - (add-atom &self + (add-symbol &self (best_so_far $Run $Gen $Value $Expr)))) +; + (= (set_best_so_far $_) True) +; + ; -; assert_elite asserts individuals into population.... +; (= (assert-elite Nil) (set-det)) +; + (= (assert-elite (Cons (, $V $K $E) $R)) - ( (add-atom &self + ( (add-symbol &self (individual $K $V $E)) (assert-elite $R) (set-det))) +; + diff --git a/sre_dna/file_stats.metta b/sre_dna/file_stats.metta index 89c90ec..22aacc9 100644 --- a/sre_dna/file_stats.metta +++ b/sre_dna/file_stats.metta @@ -1,25 +1,29 @@ ; -; ------------------------------------------------ +; ; -; Jan 1999 +; ; -; Author: Brian Ross +; ; -; Dept. of Computer Science, Brock University +; ; ; ; -; Statistics and I/O +; !(expects-dialect sicstus) +; + !(use-module (library (/ (/ dialect sicstus) system))) +; + (= @@ -35,18 +39,17 @@ (popn-dump-P yes) (dump-population $Gen) True) (set-det))) -; ; should replace with param passing - +; ; -; collect_stats computes some statistics. gp_stats might already be +; ; -; asserted for generation by Lamarckian evol routine, if used. Retract it, +; ; -; but retain it's stat. +; @@ -82,9 +85,9 @@ (since-last-datime total call $HourT $MinuteT $SecT) (since-last-datime generation retract $Hour $Minute $Sec) (or - (remove-atom &self + (remove-symbol &self (gp_stats $Gen $_ $_ $_ $_ $_ $_ $Lamarck)) True) - (add-atom &self + (add-symbol &self (gp_stats $Gen (: $Hour (: $Minute @@ -95,10 +98,7 @@ (worst $Max $SizeW) (avg $Avg) $AvgDepth $Lamarck)) (set-det))) -; ;time_stamp(';h:;02i:;02s;a',T), - -; ; datime(datime(_,_,_,Hour,Minute,Sec)), - +; @@ -110,22 +110,28 @@ (- $Now $Was)) (det-if-then-else (== $SetReset retract) - (add-atom &self + (add-symbol &self (got_time $For $Now)) True) (stamp-date-time $DiffTime (date $Year $Month $Day $Hour $Minute $Sec $_ $_ $_) UTC) (set-det))) +; + !(dynamic (/ got-time 2)) +; + !((get-time $Now) - (add-atom &self + (add-symbol &self (got_time total $Now)) - (add-atom &self + (add-symbol &self (got_time total $Now))) +; + ; -; print run statistics +; (= @@ -144,16 +150,9 @@ (lamarck 0 0 0)) True) (print-stat $Gen $Time $Best $Worst $Avg $AvgDepth $Lamarck) (fail))) -; ; Windows - -; ; Windows - -; ;once(time_stamp('Date: ;W, ;d ;M ;y Time: ;c:;02i;a', DateTime)), - -; ; loops for all - +; ; -; loop driver +; (= (dump-stats $Run) @@ -206,48 +205,12 @@ (told) (tell user) (write-soln "soln" $Run $Expr))) -; ; from gp_parameters file... - -; ;crossover_P(PIC, PTC), - -; ;rep_limit_P(Rep), - -; ; some other stats... - -; ;sre_mutation_P(SREmut), - -; ;mutation_range_P(Mutrange), - -; ; if last generation never reached (soln found before) - -; ;'SRE numeric mutation rate =', SREmut, nl, - -; ;'SRE mutation range = +/-',Mutrange,nl, - -; ;write('Best...'), nl, dna_summary(Expr), ; for DNA only - -; ;write('Best optimized...'), nl, - -; ;mask_optimize(Expr, Fitness, ExprOpt), - -; ;dna_summary(ExprOpt), ; for DNA only - -; /* -; (gp_stats(MaxGen,_, best(MinLast, _, BexprLast), _, _, _, _) -> -; write('Last...'), nl, -; dna_summary(BexprLast), -; mask_optimize(BexprLast, MinLast, LastOpt), ; for DNA only -; write('Last optimized...'), nl, -; dna_summary(LastOpt) -; ; -; true), -; */ - +; ; -; <-- new. +; ; -; write_soln("solnopt", Run, ExprOpt). ; <-- new. +; (= @@ -272,20 +235,7 @@ (append $File4 ".txt" $File5) (name $File $File5) (set-det))) -; /* -; (gp_stats(MaxGen,_, best(MinLast, _, BexprLast), _, _, _, _) -> -; write_soln("last", Run, BexprLast), ; <-- new -; write_soln("lastopt", Run, LastOpt) -; ; -; true). -; */ - -; ; dump_population(Run). - -; ;once(time_stamp('.;d;02n;02y-;02c;02i', Name3)), - -; ;name(Name3, File3), - +; @@ -298,6 +248,8 @@ (set-det) (writel (:: nl nl '---> Generation ' $Gen ( $Time ) nl 'Average fitness:' $Avg nl 'Best count: ' $Bcount nl 'Best example:' $Bexpr nl 'Best fitness = ' $Bfit nl 'Worst count: ' $Wcount nl 'Worst fitness = ' $Wfit nl 'Average Depth:' $AvgD nl 'Lamarckian evolution: off ' nl nl)) (set-det))) +; + (= (print-stat $Gen $Time (best $Bfit $Bcount $Bexpr) @@ -315,9 +267,11 @@ (= $AvgLam 0)) (writel (:: nl nl '---> Generation ' $Gen ( $Time ) nl 'Average fitness:' $Avg nl 'Best count: ' $Bcount nl 'Best example:' $Bexpr nl 'Best fitness = ' $Bfit nl 'Worst count: ' $Wcount nl 'Worst fitness = ' $Wfit nl 'Average Depth:' $AvgD nl 'Lamarckian evolution: ' nl $NumGain ' gains out of ' $N ' tries' nl ' Total gain:' $FitImpr nl ' Max single gain:' $MaxImpr nl ' Avg gain:' $AvgLam nl nl)) (set-det))) +; + ; -; print existing population +; @@ -328,9 +282,13 @@ (individual $ID $V $Expr) (write-individual $ID $V $Expr) (fail))) +; + (= (dump-population $_) ( (told) (tell user))) +; + (= @@ -341,18 +299,20 @@ (sre-pp $E) (nl) (set-det))) +; + ; -; ------------------------------------ +; ; -; solution dump: writes soln expression to a file, for input later. +; ; -; Grammatical expression is written in multiple lines, since the full +; ; -; expression is often larger than MeTTa's builtin "write" can handle. +; @@ -367,6 +327,8 @@ (told) (tell user) (set-det))) +; + (= @@ -379,14 +341,20 @@ (write ],) (write $Y) (write )))) +; + (= (write-term $X) (write $X)) +; + (= (write-tlist Nil) (set-det)) +; + (= (write-tlist (Cons $X (Cons $Y $Z))) ( (set-det) @@ -394,8 +362,12 @@ (write ,) (nl) (write-tlist (Cons $Y $Z)))) +; + (= (write-tlist (:: $X)) (write-term $X)) +; + diff --git a/sre_dna/generate.metta b/sre_dna/generate.metta index d571bad..92a30f1 100644 --- a/sre_dna/generate.metta +++ b/sre_dna/generate.metta @@ -1,77 +1,77 @@ ; -; ------------------------------------------------ +; ; -; Jan 99 +; ; -; Author: Brian Ross +; ; -; Dept. of Computer Science, Brock University +; ; ; ; -; Random generation of CCS expressions. +; ; -; As in Koza, a ramped half-and-half approach used: +; ; ; ; -; If depth = M, then equal spread of trees of approx. depth 2, 3, ..., M. +; ; -; Tree sizes not precise: list terms (restrict, relabel) can vary as much +; ; -; as +4 (or more?), because I'm avoiding backtracking for tree depth size. +; ; -; For each depth category, rougly equal split attempted between full +; ; -; and grow trees. +; ; -; Full tries to get full depth on all branches. +; ; -; Growth trees are irregularly shaped. +; ; -; The generation cycles between them and depth size. Cycling done to +; ; -; reduce duplicates that are common with grow tree generation. +; ; ; ; -; ramped_population: create a population using ramped approach. +; ; -; Equal spread of trees using full and growth generation, and of size +; ; -; 2, 3, ..., MaxDepth. +; ; -; First, old population in individual/3 retracted. +; ; -; All expressions asserted into: individual(ID, Val, Expr). +; (= (ramped-population $PopSize) - ( (remove-all-atoms &self + ( (remove-all-symbols &self (individual $_ $_ $_)) (max-depth-P $MaxDepth $_) (dctg-root-P $Root) @@ -80,32 +80,38 @@ (^ $Y (^ $Z (with_self - (fast) + (fast *) (dctg-rule-info $Root $X $Y $D $Z))))) $L) (max-list $L $MinDepth) (populate $MinDepth $MaxDepth $MinDepth grow 0 $PopSize) (number-population) (set-det))) +; + ; -; populate(D, MaxDepth, MinDepth, Type, CurrPopn, PopSize) loops until PopSize +; ; -; individuals created. Depth D goes between 2 and MaxDepth. Type toggles +; ; -; between grow and full. +; (= (populate $_ $_ $_ $_ $MaxPopn $MaxPopn) (set-det)) +; + (= (populate $D $MaxD $MinD $Type $Popn $MaxPopn) ( (> $D $MaxD) (set-det) (populate $MinD $MaxD $MinD $Type $Popn $MaxPopn))) +; + (= (populate $D $MaxD $MinD grow $Popn $MaxPopn) ( (prob-grow-P $Pgrow) @@ -113,8 +119,7 @@ (make-individual $D grow $Popn $Popn2) (set-det) (populate $D $MaxD $MinD full $Popn2 $MaxPopn))) -; ; new! May/00: only Pgrow; chance of grow tree - +; (= (populate $D $MaxD $MinD $Type $Popn $MaxPopn) @@ -124,51 +129,47 @@ (set-det) (toggle-type $Type $Type2) (populate $D2 $MaxD $MinD $Type2 $Popn2 $MaxPopn))) -; /* -; populate(D, MaxD, MinD, full, Popn, MaxPopn) :- -; make_individual(D, full, Popn, Popn2), -; D2 is D + 1, -; !, -; populate(D2, MaxD, MinD, grow, Popn2, MaxPopn). -; */ - +; (= (populate $D $MaxD $MinD $Type $Popn $MaxPopn) ( (set-det) (populate $D $MaxD $MinD $Type $Popn $MaxPopn))) -; ; new: June 11/99 - +; (= (toggle_type grow full) True) +; + (= (toggle_type full grow) True) +; + ; -; make_individual(Depth, Type, Popn, NewPopn) +; ; -; makes an individual of Type tree of Depth size. +; ; -; current Popn size updated to NewPopn, but might not change +; ; -; if expression rejected (not unique?) +; ; -; Each individual Expr is asserted into: +; ; -; individual(x, _, Expr, Expr2) +; ; -; where Expr is main body, Expr2 is adf expression ('0' if unused). +; ; -; ID and fitness will eventually replace first 2 fields. +; @@ -190,64 +191,71 @@ (== $Type full) (writel f) (writel g)) - (add-atom &self + (add-symbol &self (individual x $_ $Expr)) (is $NewPopn (+ $Popn 1)))) (set-det))) -; ; last arg is list notn. - +; ; -; consecutively numbers all the population with unique ID numbers +; (= (number-population) - ( (add-atom &self + ( (add-symbol &self (popn_cnt 0)) - (remove-atom &self + (remove-symbol &self (individual x $V $E)) - (remove-atom &self + (remove-symbol &self (popn_cnt $K)) (is $K2 (+ $K 1)) - (add-atom &self + (add-symbol &self (popn_cnt $K2)) - (add-atom &self + (add-symbol &self (individual $K2 $V $E)) (fail))) +; + (= (number-population) - ( (remove-atom &self + ( (remove-symbol &self (popn_cnt $_)) (set-det))) +; + ; -; consecutively renumbers all the new population with unique ID numbers +; (= (renumber-population) - ( (add-atom &self + ( (add-symbol &self (popn_cnt 0)) - (remove-atom &self + (remove-symbol &self (newindividual $_ $V $E)) - (remove-atom &self + (remove-symbol &self (popn_cnt $K)) (is $K2 (+ $K 1)) - (add-atom &self + (add-symbol &self (popn_cnt $K2)) - (add-atom &self + (add-symbol &self (individual $K2 $V $E)) (fail))) +; + (= (renumber-population) - ( (remove-atom &self + ( (remove-symbol &self (popn_cnt $_)) (set-det))) +; + diff --git a/sre_dna/go.metta b/sre_dna/go.metta index bd24e02..bcb9e89 100644 --- a/sre_dna/go.metta +++ b/sre_dna/go.metta @@ -1,12 +1,12 @@ ; -; ?- load_files(library(random)). +; ; -; ?- load_files(library(date)). +; ; -; ?- load_files(library(strings)). +; @@ -14,45 +14,63 @@ (?- (use_module (library random))) True) +; + (= (?- (use_module (library system))) True) +; + (= (?- (use_module (library lists))) True) +; + (= (?- (consult (library (/ sre_dna dynamics)))) True) +; + (= (?- (consult (library (/ sre_dna dctg)))) True) +; + (= (?- (consult (library (/ sre_dna parameters_P)))) True) +; + (= (?- (consult (library (/ sre_dna operators)))) True) +; + (= (?- (consult (library (/ sre_dna dctg_pp)))) True) +; + (= (?- (consult (library (/ sre_dna utils)))) True) +; + (= (?- @@ -60,6 +78,8 @@ (dctg_file_P $FileDCTG) (, (grammar $FileDCTG) make_grammar_table))) True) +; + (= (regen) @@ -69,11 +89,12 @@ (nl) (listing) (told))) -; ; fast: new - +; - !(regen) + !(regen *) +; + @@ -83,52 +104,70 @@ (consult (library (/ sre_dna ccs_utils)))) True) +; + (= (?- (consult (library (/ sre_dna dctg_gen)))) True) +; + (= (?- (consult (library (/ sre_dna dctg_reprod)))) True) +; + (= (?- (consult (library (/ sre_dna dctg_utils)))) True) +; + (= (?- (consult (library (/ sre_dna generate)))) True) +; + (= (?- (consult (library (/ sre_dna gp_engine)))) True) +; + (= (?- (consult (library (/ sre_dna lamarckian)))) True) +; + (= (?- (consult (library (/ sre_dna evaluation)))) True) +; + (= (?- (consult (library (/ sre_dna file_stats)))) True) +; + ; -; following must follow 'parameters_P' above. +; ; -; Convenient to put here, as interactive debugging of DCTG-GP is easier. +; (= @@ -136,22 +175,18 @@ (, (fitness_func_P $File) (consult $File))) True) -; /* -; ?- consult(library(sre_dna/sre_mutation3)). -; ?- consult(library(sre_dna/sre_crossover3a)). -; ?- consult(library(sre_dna/dna_proc)). -; ?- consult(library(sre_dna/mask_optimizer)). ; -; ?- dna_file_P(DNA_file), consult(DNA_file). -; */ - (= (?- (: fast (consult compile_file))) True) +; + (= (?- clean_up) True) +; + diff --git a/sre_dna/gp_engine.metta b/sre_dna/gp_engine.metta index e57e357..954dc85 100644 --- a/sre_dna/gp_engine.metta +++ b/sre_dna/gp_engine.metta @@ -1,55 +1,54 @@ ; -; ------------------------------------------------ +; ; -; January 1999 +; ; -; Author: Brian Ross +; ; -; Dept. of Computer Science, Brock University +; ; ; ; -; Genetic Programming engine II. +; ; ; ; -; Tournament, steady state, Lamarckian hill-climbing option. +; ; -; Parameters set in 'gp_defn' file. +; ; -; Fitness: lower scores better, 0 is perfect. +; ; -; Population represented in program database with: +; ; -; individual(ID_number, Fitness, Expression) +; ; -; newindividual(ID_number, Fitness, Expression) (for separate gen) +; (= (gp) ( (clean-up-1) - (add-atom &self + (add-symbol &self (best_so_far $_ $_ 1000 $_)) (max-runs-P $MaxRuns $RunType $_) (set-det) (meta-run-loop 1 $MaxRuns $RunType) (writel (:: '*** END ***' nl nl)))) -; ; from gp_defn file - +; @@ -61,6 +60,8 @@ (writel (:: nl '--> Max run' $MaxRuns ' reached.' nl 'Best found in run ' $Run ' gen ' $Gen : nl ' Expr = ' $Expr nl ' Fitness = ' $Fitness nl nl)) (writel (:: '--> Finished runs <--' nl nl)) (set-det))) +; + (= (meta-run-loop $Run $MaxRuns $RunType) ( (=< $Run $MaxRuns) @@ -83,23 +84,24 @@ (is $Run2 (+ $Run 1)) (meta-run-loop $Run2 $MaxRuns $RunType))))) -; ; gp_parameters - -; ; gp_parameters - +; (= (do-the-run $Gen $MaxGen $_) ( (> $Gen $MaxGen) (set-det))) +; + (= (do-the-run $_ $_ $_) ( (solved-run) (set-det))) +; + (= (do-the-run 0 $MaxGen $PopSize) ( (clean-up-2) - (add-atom &self + (add-symbol &self (best_in_run $_ 1000 $_)) (writel (:: nl '********* Generation ' 0 ********* nl)) (evaluator-reset 0) @@ -109,8 +111,7 @@ (garbage-collect) (set-det) (do-the-run 1 $MaxGen $PopSize))) -; ; dump_population(0), - +; (= (do-the-run $Gen $MaxGen $PopSize) @@ -131,38 +132,39 @@ (garbage-collect) (set-det) (do-the-run $Gen2 $MaxGen $PopSize))) -; ; new: May/00 - -; ; dump_population(Gen), - +; ; -; tournament_loop(NumNew, PopSize) runs until NumNew changes +; ; -; done reaches PopSize OR run found solution. +; ; -; Possible that crossover fails (can't find similar nodes in choices, or +; ; -; children too large), and crossover will fail. +; ; -; Else add each child. +; ; -; Mutation happens if crossover didn't. +; (= (tournament-loop $K $PopSize) ( (> $K $PopSize) (set-det))) +; + (= (tournament-loop $_ $_) ( (solved-run) (set-det))) +; + (= (tournament-loop $K $PopSize) ( (prob-crossover-P $PC) @@ -176,12 +178,7 @@ (add-child c $K2 $K3 $PopSize $NewExpr2)) (= $K $K3)) (tournament-loop $K3 $PopSize))) -; ; do crossover ? - -; ; might be same ID - -; ; in case crossover didn't succeed - +; (= (tournament-loop $K $PopSize) @@ -191,20 +188,17 @@ (add-child m $K $K2 $PopSize $NewExpr) (= $K $K2)) (tournament-loop $K2 $PopSize))) -; ; do mutation - -; ; in case mutation didn't succeed - +; ; -; tournament_select(Type, PopSize, ID, Expression) selects the +; ; -; Type=best/worst Expression from Num randomly selected individuals +; ; -; from population of size PopSize +; @@ -214,24 +208,30 @@ (select-random-IDs 0 $Num $PopSize Nil $IDs) (select best $IDs $ID $Expression) (set-det))) +; + (= (tournament-select worst $PopSize $ID $Expression) ( (tournament-size-P $_ $Num) (select-random-IDs 0 $Num $PopSize Nil $IDs) (select worst $IDs $ID $Expression) (set-det))) +; + ; -; select_random_IDs(N, Size, PopSize, SoFar, Result) selects Size unique +; ; -; individual ID's from 1 to PopSize; N is size of temp answer SoFar. +; (= (select-random-IDs $Size $Size $_ $Result $Result) (set-det)) +; + (= (select-random-IDs $N $Size $PopSize $SoFar $Result) ( (repeat) @@ -241,15 +241,17 @@ (+ $N 1)) (select-random-IDs $N2 $Size $PopSize (Cons $K $SoFar) $Result))) +; + ; -; select the best or worst in tournament +; ; -; If a fair worst selection, then all have a chance to be replaced in +; ; -; proportion to the number of best individuals in the population. +; @@ -257,11 +259,15 @@ (select $Type (Cons $ID1 $Rest) $ID $Expression) ( (individual $ID1 $Fit1 $_) (select2 $Type $Fit1 $ID1 $Rest $ID $Expression))) +; + (= (select2 $_ $_ $ID Nil $ID $Expression) ( (individual $ID $_ $Expression) (set-det))) +; + (= (select2 $Type $Fit1 $_ (Cons $ID2 $Rest) $ID $Expression) @@ -275,16 +281,20 @@ (> $Fit2 $Fit1))) (set-det) (select2 $Type $Fit2 $ID2 $Rest $ID $Expression))) +; + (= (select2 $Type $Fit1 $ID1 (Cons $_ $Rest) $ID $Expression) (select2 $Type $Fit1 $ID1 $Rest $ID $Expression)) +; + ; -; adding to population (replacing a weak member) if legal. +; ; -; Use a reverse tournament selection, finding indiv to replace with child. +; @@ -303,8 +313,7 @@ (writel $T) (is $K2 (+ $K 1)))) (set-det))) -; ; T=first arg of add_child - +; @@ -312,36 +321,40 @@ (add-individual $_ $Fitness $NewExpr) ( (gen-type-P separate) (set-det) - (add-atom &self + (add-symbol &self (newindividual $_ $Fitness $NewExpr)))) +; + (= (add-individual $PopSize $Fitness $NewExpr) ( (tournament-select worst $PopSize $ID $_) - (remove-atom &self + (remove-symbol &self (individual $ID $_ $_)) - (add-atom &self + (add-symbol &self (individual $ID $Fitness $NewExpr)))) +; + ; -; Expression is legal if: +; ; -; 1. If unique population option is on, then if child exists in population, +; ; -; don't add it +; ; -; 2. If size of child exceeds max, don't add. +; ; -; 3. If expression modes set, don't add if expression fails them. +; ; -; Flag set to 'main' if called in main GP loop; else set to 'lamarck' +; ; -; (affects if newindividual exists or not; sloppy). +; @@ -350,22 +363,30 @@ ( (check-unique $Expr $Flag) (check-depth $Expr) (set-det))) +; + (= (check-unique $_ $_) ( (not (unique-population-P yes)) (set-det))) +; + (= (check-unique $Expr main) ( (gen-type-P separate) (set-det) (not (newindividual $_ $_ $Expr)))) +; + (= (check-unique $Expr $_) (not (individual $_ $_ $Expr))) +; + ; -; succeed if Expression depth within limits +; @@ -375,9 +396,11 @@ (tree-depth $Expr $D) (=< $D $MaxDepth) (set-det))) +; + ; -; succeed if solution criteria satisfied +; @@ -387,67 +410,72 @@ (error-tolerance-P $Err) (=< $BFitness $Err) (set-det))) +; + (= (clean-up-1) ( (set-random-number-gen) - (remove-all-atoms &self + (remove-all-symbols &self (start_time $_)) - (remove-all-atoms &self + (remove-all-symbols &self (best_so_far $_ $_ $_ $_)) (garbage-collect) (set-det))) +; + (= (clean-up-2) - ( (remove-all-atoms &self + ( (remove-all-symbols &self (best_in_run $_ $_ $_)) - (remove-all-atoms &self + (remove-all-symbols &self (gp_stats $_ $_ $_ $_ $_ $_ $_)) - (remove-all-atoms &self + (remove-all-symbols &self (individual $_ $_ $_)) - (remove-all-atoms &self + (remove-all-symbols &self (newindividual $_ $_ $_)) - (remove-all-atoms &self + (remove-all-symbols &self (popn_size $_)) - (remove-all-atoms &self + (remove-all-symbols &self (popn_cnt $_)) - (remove-all-atoms &self + (remove-all-symbols &self (temp $_)) (garbage-collect) (set-det))) -; ; retractall(trace_count(_,_)), - -; ; retractall(saved_trace(_)), - +; ; -; for interactive exec... +; (= (clean-up) ( (clean-up-1) (clean-up-2))) +; + ; -; If evaluator_reset_P(Gen) is set to a routine name, then call it before +; ; -; each generation ensues. It is called if it is the Nth generation (1st gen +; ; -; is first one a set is created). +; (= (evaluator-reset $_) ( (evaluator-reset-P $_ no) (set-det))) +; + (= (evaluator-reset $G) ( (evaluator-reset-P $C $N) @@ -455,44 +483,37 @@ (mod $G $N)) (call $C) (set-det))) +; + (= (evaluator_reset $_) True) +; + (= (rename-new-popn) ( (gen-type-P separate) (set-det) - (remove-all-atoms &self + (remove-all-symbols &self (individual $_ $_ $_)) (renumber-population))) -; /* -; evaluator_reset :- -; evaluator_reset_P(no), -; !. -; evaluator_reset :- -; evaluator_reset_P(C), -; call(C), -; !. -; evaluator_reset. -; */ - -; ; If a separate population scheme is being used, then rename the -; ; newindividual's to individuals, and give them ID numbers. - +; (= rename_new_popn True) +; + ; -; If elite migration is on, and gen_type is separate, then migrate the +; ; -; N best individuals into new population. +; ; -; If ReEval = yes, then each has fitness recomputed (assume new generation of +; ; -; testset done beforehand elsewhere). +; @@ -510,16 +531,22 @@ (copy-elite $Elite $ReEval) (is $StartSize (+ $N 1)))) +; + (= (elite-migration $K $K) - (set-det)) ; -; else not done + (set-det)) +; + ; +; (= (copy-elite Nil $_) (set-det)) +; + (= (copy-elite (Cons @@ -534,13 +561,17 @@ (evaluator $E $V2)) (write ?)) (= $V $V2)) - (add-atom &self + (add-symbol &self (newindividual $K $V2 $E)) (set-det) (copy-elite $B $ReEval))) +; + (= (evaluator $K $E $V2) (evaluator $E $V2)) +; + diff --git a/sre_dna/lamarckian.metta b/sre_dna/lamarckian.metta index b963158..747eacb 100644 --- a/sre_dna/lamarckian.metta +++ b/sre_dna/lamarckian.metta @@ -1,51 +1,51 @@ ; -; ------------------------------------------------ +; ; -; January 1999 +; ; -; Author: Brian Ross +; ; -; Dept. of Computer Science, Brock University +; ; ; ; -; Lamarckian evolution: lamarckian_P(P, K, Select, PCross) +; ; -; Performs Lamarckian evolution on P; of population, iterating +; ; -; each K times using hill-climbing. Hill-climber uses mutation; it is +; ; -; recommended that prob_terminal_mutation_P parameter be high, or else +; ; -; internal mutation will not create good search performance. +; ; -; Select can be tournament (best, worst) or random. +; ; -; PCross is prob crossover (prob mutation = 1 - PCross). +; ; -; lamarckian_evolution also asserts gp_stats with improvement gain obtained +; ; -; First clause efficiently processes entire population. +; ; -; Second case is if less than entire population to be used, in which case +; ; -; selection must be performed. +; @@ -57,10 +57,12 @@ (population-size-P $_ $PopSize) (num-list $PopSize $IDs) (lamarck-loop $IDs 0 $FitImpr 0 $MaxImpr 0 $NumGain $K) - (add-atom &self + (add-symbol &self (gp_stats $Gen $_ $_ $_ $_ $_ $_ (lamarck $FitImpr $MaxImpr $NumGain))) (set-det))) +; + (= (lamarckian-evolution $Gen) ( (lamarckian-P $Percent $K $Select $_) @@ -71,22 +73,26 @@ (writel (:: nl 'Lamarckian evolution...' nl)) (get-unique-IDs $Select $N $PopSize Nil $IDs) (lamarck-loop $IDs 0 $FitImpr 0 $MaxImpr 0 $NumGain $K) - (add-atom &self + (add-symbol &self (gp_stats $Gen $_ $_ $_ $_ $_ $_ (lamarck $FitImpr $MaxImpr $NumGain))) (set-det))) +; + ; -; get_unique_IDs retrieves a list of N unique individual ID's, +; ; -; selecting each one via Type (random or best/worst tournament selection). +; (= (get-unique-IDs $_ 0 $_ $IDs $IDs) (set-det)) +; + (= (get-unique-IDs $Type $N $PopSize $SoFar $IDs) ( (repeat) @@ -100,48 +106,49 @@ (get-unique-IDs $Type $M $PopSize (Cons $ID $SoFar) $IDs) (set-det))) -; ; in case number is repeated (member below) - +; ; -; lamark_loop(List, ImprSoFar, FitImpr, MaxSoFar, MaxImpr, +; ; -; NumSoFar, NumGain, Iter) does best-first Lamarckian evolution. +; ; -; List = ordered list of individuals+Fitnesses +; ; -; ImprSoFar, FitImr = Total fitness gain so far / final +; ; -; MaxSoFar, MaxImpr = best fitness gain so far/final +; ; -; NumSoFar, NumGain = number that have been changed so far/final +; ; -; Iter = # iterations to do +; ; ; ; -; Note: even if no overall fitness gain achieved, if an altered expression +; ; -; was found, it is asserted and treated like a gain: will improve genetic +; ; -; diversity in population due to its syntactic variation. +; (= (lamarck-loop Nil $FitImpr $FitImpr $MaxImpr $MaxImpr $NumGain $NumGain $_) (set-det)) +; + (= (lamarck-loop (Cons $ID $Rest) $ImprSoFar $FitImpr $MaxSoFar $MaxImpr $NumSoFar $NumGain $Iter) @@ -159,9 +166,9 @@ (, $NewFitImpr $NewMaxImpr $NumSoFar2) (, $ImprSoFar $MaxSoFar $NumSoFar))) (, - (remove-atom &self + (remove-symbol &self (individual $ID $_ $_)) - (add-atom &self + (add-symbol &self (individual $ID $NewFit $NewExpr)) (is $NewFitImpr (- @@ -174,32 +181,31 @@ (writel +))) (lamarck-loop $Rest $NewFitImpr $FitImpr $NewMaxImpr $MaxImpr $NumSoFar2 $NumGain $Iter) (set-det))) -; ; writel(['L ID=',ID,'* ']), - -; ; don't add - +; ; -; hill_climb(K, BestSoFar, Item) does hill-climbing search for +; ; -; K iterations. BestSoFar contains best expression obtained so far with +; ; -; mutation, and it and Item have (Fitness, Expression, Adf) structure. +; ; -; Note: Failed mutation and repeated mutation is counted as an iteration +; ; -; Also, improved hillclimbing step does not count as an iteration. +; (= (hill-climb $K $Item $Item) ( (=< $K 0) (set-det))) +; + (= (hill-climb $K (, $TopFit $TopExpr) $Soln) @@ -224,8 +230,7 @@ (- $K 2))) (hill-climb $K2 $BestSoFar2 $Soln) (set-det))) -; ; crossover? - +; (= (hill-climb $K @@ -242,10 +247,7 @@ (- $K 1))) (hill-climb $K2 $BestSoFar $Soln) (set-det))) -; ; mutation? - -; ;K2 is K - 1, - +; (= (hill-climb $K $BestSoFar $Soln) @@ -253,9 +255,11 @@ (- $K 1)) (hill-climb $K2 $BestSoFar $Soln) (set-det))) +; + ; -; select best of expression pairs +; @@ -265,17 +269,23 @@ (, $F2 $_) (, $F1 $E1)) ( (=< $F1 $F2) (set-det))) +; + (= (select_best $_ $X $X) True) +; + (= (sre-mutation $I $C) (mutation $I $C)) +; + ; -; some debugging code... +; @@ -289,5 +299,7 @@ (, $NewFit $NewExpr)) (writel (:: 'Initial: ' nl ' Fit = ' $Fit nl ' Expr = ' $Expr nl 'New: ' nl ' Fit = ' $NewFit nl ' Expr = ' $NewExpr nl)) (set-det))) +; + diff --git a/sre_dna/operators.metta b/sre_dna/operators.metta index 57055ef..e86e377 100644 --- a/sre_dna/operators.metta +++ b/sre_dna/operators.metta @@ -1,20 +1,20 @@ ; -; ------------------------------------------------ +; ; -; Feb 1999 +; ; -; Author: Brian Ross +; ; -; Dept. of Computer Science, Brock University +; ; ; ; -; GP dctg operators +; ; ; @@ -24,17 +24,25 @@ (= (?- (op 480 xfy :)) True) +; + (= (?- (op 470 yfx *)) True) +; + (= (?- (op 470 yfx +)) True) +; + (= (sre $E) ( (write $E) (nl))) +; + diff --git a/sre_dna/parameters_P.metta b/sre_dna/parameters_P.metta index b451b0d..0c77d80 100644 --- a/sre_dna/parameters_P.metta +++ b/sre_dna/parameters_P.metta @@ -1,14 +1,14 @@ ; -; ------------------------------------------------ +; ; -; October 2001 +; ; -; Author: Brian Ross +; ; -; Dept. of Computer Science, Brock University +; @@ -16,399 +16,477 @@ (?- (dynamic (/ seed_P 2))) True) +; + (= (?- (dynamic (/ recog_flag 1))) True) +; + ; -; GP Control Parameters +; ; -; --------------------------- +; ; -; fitness_func_P(F) - F is file name containing fitness function. +; ; -; Should have a function called evaluator/2. It sets +; ; -; standardized fitness scores. +; ; -; dctg_file_P(F) - F is file name containing DCTG grammar +; ; -; population_size_P(I,N) - size (initial, final) of GP population +; ; -; - final is culled from initial +; ; -; cull_method_P(T) - T=tournament or elite +; ; -; max_runs_P(R,Type,Gen) - total number R of runs; max generations Gen per run +; ; -; Type = limit: run to R, even if soln found +; ; -; Type = solution: run to R, but stop when soln +; ; -; prob_grow_P - during ramped init population gen, this is +; ; -; probability a 'grow' tree is attempted +; ; -; prob_crossover_P - probability of crossover mating +; ; -; prob mutation = 1 - prob cross +; ; -; reprod_P(T) - # tries for crossover +; ; -; prob_internal_crossover_P - probability that crossover happens on an internal +; ; -; node in 1 parent; set to 'no' otherwise +; ; -; prob_terminal_mutation_P - probability that mutation is on a terminal node; +; ; -; set to 'no' otherwise +; ; -; max_depth_P(I,C) - I = max depth of initial generated indiv's, +; ; -; C = maximum depth permitted in offspring +; ; -; Make sure I is large enough, or else generation will stall. +; ; -; error_tolerance_P - wrt evaluation, tolerance for correct solns. +; ; -; tournament_size_P(S,R) - # entries in tournament selection S and +; ; -; replacement R +; ; -; lamarckian_P(P, K, Select, ProbCross) - do Lamarkian evol on +; ; -; P ; of population, +; ; -; K = # iterations for best-first search +; ; -; Select = {best, worst, random} selection +; ; -; If P=1.0, then Select is irrelevant. +; ; -; ProbCross is prob crossover (vs mutation) +; ; -; unique_population_P(no) - no/yes: children added to popn should be unique +; ; -; (doesn't affect genesis population however) +; ; -; trace_limit_P(U,T) - stops interpretation when this many unique/total +; ; -; traces have been obtained (turn off = (0,0) ) +; ; -; if arg 1 = deterministic, then only 1 soln +; ; -; rep_limit_P(X) - if >0, X is max recursion depth for ! repetition +; ; -; 0 = unlimited repetition +; ; -; simplify_P(yes) - if 'yes', then offspring are simplified +; ; -; before added to population +; ; -; seed_P(X,Y) - if X = default, then default random cycle +; ; -; if X = random, then system timer used to initialize +; ; -; (Y set by program to seeds used, for reinit later) +; ; -; X=manual means Y = (A, B, C) are seed integers 1...30,000 +; !(dynamic (/ debug-set-P 1)) +; + ; -; debug_set_P(yes): for additional debug printing, if implemented +; ; -; popn_dump_P(no) - if yes, then population dumped at end of each gen +; ; -; gen_type_P(T) - generation type: T = steadystate, separate +; ; -; evaluator_reset_P(P, G)- if G=no, ignore; else call P every G-th generation +; ; -; reprod_verif_P(T) - if yes, then each reproduced Tree has its DCTG code +; ; -; executed, to verify it wrt embedded MeTTa code; +; ; -; user_args_P(_) - list of user args for executing dctg calls +; ; -; make sure it has # members of what DCTG expects! +; ; -; dctg_root_P(Root) - root nonterminal of DCTG +; ; -; dctg_override_P(Term, Nonterm). - user override of terminal, nonterminal +; ; -; designation for rules; done for entire nonterm set +; ; -; mutation_range_P(R) - range to mutate SRE numeric values +; ; -; sre_mintestcnt_P(M) - minimum count for test set entries +; ; -; gen_set_size_P(S) - initial size of generated grammar test set +; ; -; min_grammar_prob_P(P) - minimum prob for grammar recognition to continue +; ; -; min_skip_prob_P(P). - min prob for skipping to continue +; ; -; unique_guards_P(yes) - if yes, guards in choice are unique; otherwise not. +; ; -; elite_migrate_P(N, R) - if gen_type=separate, then N best individuals +; ; -; migrate to next generation; if R=yes, then reeval fitness +; ; -; negsetsize_P(S) - number negative examples to generate +; ; -; eval_with_ID_P(T) - T=yes then include expr ID in call to evaluator +; ; -; else don't include +; (= (wd_P /pack/narsese/prolog/sre_dna/) True) +; + (= (fitness_func_P reg_gram_1.pl) True) +; + (= (dctg_file_P sre3.pl) True) +; + (= - (population_size_P 750 500) True) ; -; <-- 750, 500 + (population_size_P 750 500) True) +; + ; +; (= - (cull_method_P elite) True) ; -; <-- tournament + (cull_method_P elite) True) +; + ; +; (= - (max_runs_P 1 solution 50) True) ; -; <-- 5, solution, 35 + (max_runs_P 1 solution 50) True) +; + ; +; (= - (prob_grow_P 0.5) True) ; -; <-- 0.25 + (prob_grow_P 0.5) True) +; + ; +; (= - (prob_crossover_P 0.9) True) ; -; <-- 0.90 + (prob_crossover_P 0.9) True) +; + ; +; (= - (reprod_P 3) True) ; -; <-- 3 + (reprod_P 3) True) +; + ; +; (= - (prob_internal_crossover_P 0.9) True) ; -; <-- 0.90 or no + (prob_internal_crossover_P 0.9) True) +; + ; +; (= - (prob_terminal_mutation_P 0.75) True) ; -; <-- 0.75 or no + (prob_terminal_mutation_P 0.75) True) +; + ; +; (= - (max_depth_P 10 17) True) ; -; <-- 6, 17 + (max_depth_P 10 17) True) +; + ; +; (= - (error_tolerance_P 0) True) ; -; <-- 0.000001 + (error_tolerance_P 0) True) +; + ; +; (= - (tournament_size_P 4 4) True) ; -; <-- 2, 3 + (tournament_size_P 4 4) True) +; + ; +; (= - (lamarckian_P 0.0 10 best 0.1) True) ; -; <-- 0.25, 10, best, 0.20; (0.0,...) = off + (lamarckian_P 0.0 10 best 0.1) True) +; + ; +; ; -; lamarckian_P(0.25, 10, best, 0.20). +; (= - (unique_population_P yes) True) ; -; <-- no + (unique_population_P yes) True) +; + ; +; (= - (trace_limit_P 0 0) True) ; -; <-- (40, 90) + (trace_limit_P 0 0) True) +; + ; +; (= - (rep_limit_P 2) True) ; -; <-- 3 + (rep_limit_P 2) True) +; + ; +; (= - (max_string_length_P 20) True) ; -; <-- 10 + (max_string_length_P 20) True) +; + ; +; (= (seed_P random (, $_ - (, $_ $_))) True) ; -; <-- random, (_,_,_) + (, $_ $_))) True) +; + ; +; (= - (popn_dump_P no) True) ; -; <-- no + (popn_dump_P no) True) +; + ; +; (= - (gen_type_P steadystate) True) ; -; <-- steadystate + (gen_type_P steadystate) True) +; + ; +; (= - (evaluator_reset_P generate_testset 100) True) ; -; <-- no + (evaluator_reset_P generate_testset 100) True) +; + ; +; (= - (reprod_verif_P no) True) ; -; <-- yes + (reprod_verif_P no) True) +; + ; +; (= - (user_args_P ()) True) ; -; <-- eg. [], [_] or [_|_] if arity 0, 1 or 2 + (user_args_P ()) True) +; + ; +; (= - (dctg_root_P expr) True) ; + (dctg_root_P expr) True) +; + ; ; (= - (dctg_override_P () ()) True) ; -; <-- [], [] + (dctg_override_P () ()) True) +; + ; +; (= - (mutation_range_P 0.1) True) ; -; <-- was 0.025 + (mutation_range_P 0.1) True) +; + ; +; (= - (sre_mintestcnt_P 2) True) ; -; <-- 2 + (sre_mintestcnt_P 2) True) +; + ; +; (= - (gen_set_size_P 1000) True) ; -; <-- 250 + (gen_set_size_P 1000) True) +; + ; +; (= - (min_grammar_prob_P 0.0001) True) ; -; <-- 1.0e-4 + (min_grammar_prob_P 0.0001) True) +; + ; +; (= - (min_skip_prob_P 0.0001) True) ; -; <-- 1.0e-4 + (min_skip_prob_P 0.0001) True) +; + ; +; (= - (unique_guards_P no) True) ; -; <-- yes + (unique_guards_P no) True) +; + ; +; (= - (elite_migrate_P 0 no) True) ; -; <-- 10 + (elite_migrate_P 0 no) True) +; + ; +; (= - (negsetsize_P 30) True) ; -; <-- 75 + (negsetsize_P 30) True) +; + ; +; (= - (eval_with_ID_P no) True) ; -; <-- no + (eval_with_ID_P no) True) +; + ; +; diff --git a/sre_dna/reg_gram_1.metta b/sre_dna/reg_gram_1.metta index 57ff151..f638bf2 100644 --- a/sre_dna/reg_gram_1.metta +++ b/sre_dna/reg_gram_1.metta @@ -3,51 +3,53 @@ (?- (dynamic (/ testset 2))) True) +; + ; -; Experiment: evolve a SRE to conform with this stoch. regular grammar +; ; -; (from Carrasco & Forcado 96) +; ; ; ; -; S -> a S (0.2) +; ; -; S -> b A (0.8) +; ; -; A -> a B (0.7) +; ; -; A -> b S (0.3) +; ; -; B -> a A (0.4) +; ; -; B -> b B (0.1) +; ; -; B -> [] (0.5) +; ; ; ; -; Fitness: +; ; -; - Mine expression K times, and compare distribution with test set. +; ; -; - maximum string length enforced +; ; -; - chi-square 2-bin test to compare distributions +; @@ -60,16 +62,15 @@ (tabulate-set $MineSet 0 $_ $MineSet2) (chisquare-b $MineSet2 $TestSet $Size 0.0 $Fitness) (set-det))) -; ;sre_mintestcnt_P(MC), ; new - -; ; chisquare_2bins(MineSet2, TestSet, 0.0, Fitness), - +; (= (mine $_ 0 Nil) (set-det)) +; + (= (mine $Expr $K (Cons $String $Rest)) @@ -79,11 +80,15 @@ (- $K 1)) (mine $Expr $K2 $Rest) (set-det))) +; + (= (normalize $_ Nil Nil) (set-det)) +; + (= (normalize $Size (Cons @@ -94,11 +99,15 @@ (/ $C $Size)) (normalize $Size $R $R2) (set-det))) +; + (= (chisquare-b $_ Nil $_ $Fit $Fit) (set-det)) +; + (= (chisquare-b $MineSet (Cons @@ -115,6 +124,8 @@ (* $T $T) $X))) (chisquare-b $MineSet2 $Rest $Sum $Fit2 $Fitness) (set-det))) +; + (= (chisquare-b $MineSet (Cons @@ -124,22 +135,30 @@ (* $Prob $Sum))) (chisquare-b $MineSet $Rest $Sum $Fit2 $Fitness) (set-det))) +; + (= (member-remove $X (Cons $X $Y) $Y) (set-det)) +; + (= (member-remove $X (Cons $Y $Z) (Cons $Y $W)) (member-remove $X $Z $W)) +; + (= (count-and-remove $_ Nil Nil 0) (set-det)) +; + (= (count-and-remove $A (Cons $A $R) $S $Count) @@ -147,37 +166,42 @@ (count-and-remove $A $R $S $Count2) (is $Count (+ $Count2 1)))) +; + (= (count-and-remove $A (Cons $B $R) (Cons $B $S) $Count) ( (set-det) (count-and-remove $A $R $S $Count))) +; + ; -; This should be called once per GP generation. +; (= (generate-testset) ( (or - (remove-atom &self + (remove-symbol &self (testset $_ $_)) True) (gen-set-size-P $Size) (gen-set $Size $S) (sre-mintestcnt-P $MC) (tabulate-set $S $MC $Sum $T) (normalize $Sum $T $T2) - (add-atom &self + (add-symbol &self (testset $Sum $T2)) (set-det))) -; ; was 250 - +; (= (gen_set 0 ()) True) +; + (= (gen-set $K (Cons $S $R)) @@ -189,48 +213,66 @@ (- $K 1)) (set-det) (gen-set $K2 $R))) +; + (= (gen-string $NonTerm $Len $Max $String) ( (=< $Len $Max) (det-if-then-else (production $NonTerm $Out $NextNonTerm) (, (is $Len2 (+ $Len 1)) (gen-string $NextNonTerm $Len2 $Max $R) (= $String (Cons $Out $R))) (= $String Nil)))) +; + ; -; production(NonTerm, Output, NextNonTerm). +; (= (production s a s) (maybe 0.2)) +; + (= (production s b a) True) +; + (= (production a a b) (maybe 0.7)) +; + (= (production a b s) True) +; + (= (production b a a) (maybe 0.4)) +; + (= (production b b b) (maybe 0.167)) +; + ; -; pre-filter and count test set, rather than repeatedly process +; ; -; it during fitness evaluation of population. User can specify minimum +; ; -; count for processing. +; (= (tabulate_set () $_ 0 ()) True) +; + (= (tabulate-set (Cons $A $R) $Min $Sum @@ -244,14 +286,22 @@ (tabulate-set $R2 $Min $Sum2 $S) (is $Sum (+ $Sum2 $C2)))) +; + (= (tabulate-set (Cons $_ $R) $Min $Sum $S) ( (set-det) (tabulate-set $R $Min $Sum $S))) +; + !(multifile (/ chisquare 4)) +; + !(dynamic (/ chisquare 4)) +; + (= (temp-test $Fitness) @@ -275,20 +325,14 @@ (sre-pp $Expr1) (write 'Expr 2:') (sre-pp $Expr2))) +; + (= (chisquare-2bins Nil Nil $Fit $Fit) (set-det)) -; /* -; test_chi(F) :- -; generate_testset, -; testset(_,A), -; generate_testset, -; testset(_,B), -; chisquare(A,B,0,F). -; */ - +; (= (chisquare-2bins @@ -298,6 +342,8 @@ (+ $FitSoFar $Count)) (chisquare-2bins $Rest Nil $Fit2 $Fit) (set-det))) +; + (= (chisquare-2bins $MineSet (Cons @@ -313,6 +359,8 @@ (+ $Count $Count2)))) (chisquare-2bins $MineSet2 $Rest $Fit2 $Fitness) (set-det))) +; + (= (chisquare-2bins $MineSet (Cons @@ -321,5 +369,7 @@ (+ $FitSoFar $Count)) (chisquare-2bins $MineSet $Rest $Fit2 $Fitness) (set-det))) +; + diff --git a/sre_dna/sre3.metta b/sre_dna/sre3.metta index 5e1b32c..bc03d03 100644 --- a/sre_dna/sre3.metta +++ b/sre_dna/sre3.metta @@ -1,93 +1,93 @@ ; -; DCTG grammar for stochastic regular expressions +; ; -; Feb/99 +; ; ; ; -; Grammar: a | E:F | [a:E1(N1)+b:E2(N2)] | E*(Pr) | E+(Pr) +; ; ; ; -; epsilon e: epsilon (not allowed in constructs; equiv. to [] generation) +; ; -; action: a +; ; -; concatanation: E:F Pr(E:F) = Pr(E)*Pr(F) +; ; -; choice: [E1(N1)+b:E2(N2)] Pr(Ei(Ni)) = Ni / N1+N2 +; ; -; Kleene star: E*(P) Pr(E*) = [epsilon (1-P), (E:E*)(P)] +; ; -; Kleene plus: E+(P) Pr(E+) = Pr(E:(E*(P))) +; ; ; ; -; where: Ni = integers >= 0, P is probability (0 <= P < 1) +; ; ; ; -; Also: (a) no directly nested iteration allowed (star, plus) +; ; -; (b) choice must have at least 2 terms +; ; ; ; -; Semantic rules: +; ; -; construct(E): makes a MeTTa structure equivalent of expression +; ; -; generate(S,SL1,SL2,P): randomly interprets an expression, giving output +; ; -; string S (as list) with associated probability P. +; ; -; Note that repetition (star, plus) are executed according to +; ; -; probability, as well as for a max. generated string length. +; ; -; When length met, then no repetitions possible (max_string_length_P/1) +; ; -; Resulting string may unavoidably exceed this max length. +; ; -; raw_generate(S,SL1,SL2): like generate, but no probability computed. +; ; -; recognize(S,P): finds way of recognizing a string with the +; ; -; expression, resulting in probability P. Will work with backtracking, +; ; -; so that all possibile derivations can be found (no probabilistic +; ; -; execution as with generate/2. +; @@ -112,6 +112,8 @@ (check_prob $PrSoFar) (^^ $A (recognize $S $S2 $PrSoFar $Pr))))))) True) +; + (= (<:> @@ -133,9 +135,11 @@ (check_prob $PrSoFar) (^^ $A (recognize $S $S2 $PrSoFar $Pr))))))) True) +; + ; -; ------------------------------------- +; (= @@ -154,8 +158,7 @@ (recognize (Cons a $T) $T $PrSoFar $PrSoFar) (check_prob $PrSoFar))))) True) -; ; action a - +; (= @@ -174,12 +177,11 @@ (recognize (Cons b $T) $T $PrSoFar $PrSoFar) (check_prob $PrSoFar))))) True) -; ; action b - +; ; -; - - - - +; (= @@ -259,9 +261,11 @@ (check_prob $Pr2) (^^ $A2 (recognize $S $S2 $Pr2 $Pr))))))))))) True) +; + ; -; - - - - +; (= @@ -300,12 +304,11 @@ (check_prob $Pr1) (^^ $B (recognize $S3 $S2 $Pr1 $Pr))))))))) True) -; ; concat - +; ; -; ------------------------------------- +; (= @@ -340,12 +343,11 @@ (^^ $B (construct $Pr1)) (recognize_loop $A $Pr1 $S $S2 $PrSoFar $Pr))))))) True) -; ; star - +; ; -; - - - - +; (= @@ -394,14 +396,11 @@ (^^ $B (construct $Pr2)) (recognize_loop $A $Pr2 $S3 $S2 $Pr1 $Pr)))))))))) True) -; ; plus - -; ; new - +; ; -; ------------------------------------- +; (= @@ -420,8 +419,7 @@ (recognize (Cons a $T) $T $PrSoFar $PrSoFar) (check_prob $PrSoFar))))) True) -; ; action a - +; (= @@ -452,8 +450,7 @@ (check_prob $PrSoFar) (^^ $A (recognize $S $S2 $PrSoFar $Pr))))))) True) -; ; concat - +; (= @@ -472,8 +469,7 @@ (recognize (Cons b $T) $T $PrSoFar $PrSoFar) (check_prob $PrSoFar))))) True) -; ; action b - +; (= @@ -504,13 +500,12 @@ (check_prob $PrSoFar) (^^ $A (recognize $S $S2 $PrSoFar $Pr))))))) True) -; ; concat - +; ; -; ------------------------------------- +; (= @@ -520,6 +515,8 @@ ($N) { (is_an_integer $N) })) (construct $N)) True) +; + (= (<:> @@ -528,83 +525,95 @@ ($R) { (is_a_probability $R) })) (construct $R)) True) +; + ; -; ------------------------------------ +; ; -; MeTTa utilities... +; ; -; ------------------------------------ +; ; -; is_an_integer(N): +; ; -; N - integer value +; ; -; Succeeds if N is an integer. If N is variable, a random integer +; ; -; in desired range is created. +; (= (is-an-integer $N) ( (integer $N) (set-det))) +; + (= (is-an-integer $N) ( (int-range $Low $High) (random $Low $High $N))) +; + (= (int_range 0 1000) True) +; + ; -; ------------------------------------ +; ; -; is_a_probability(R): +; ; -; R - real value 0.0 <= R < 1.0 +; ; -; Succeeds if R is a float, 0.0 <= R < 1.0. +; ; -; If R is variable, a random probability in desired range is created. +; (= (is-a-probability $R) ( (float $R) (set-det))) +; + (= (is-a-probability $R) ( (random $T) (is $R (/ (truncate (* $T 100)) 100)))) +; + ; -; ------------------------------------ +; ; -; raw_select_term(L, K): +; ; -; L - list of probability weights +; ; -; K - kth term selected via prob. weighting (between 1 and length(L)) +; ; -; Pr - calculated probability of selected term +; ; -; Like select_term, but no probability computed. +; @@ -614,100 +623,112 @@ (random 0 $Sum $X) (select-kth-term $SL $X 1 $K $_) (set-det))) +; + ; -; ------------------------------------ +; ; -; sumlist(A, B, L, S): +; ; -; A - list of weights +; ; -; B - summed list of weights (roulette wheel) +; ; -; L - sum so far +; ; -; S - final sum +; ; -; Creates a summed list of prob weights, with final total S. +; (= (sumlist () () $Sum $Sum) True) +; + (= (sumlist (Cons $N $R) (Cons $NewSum $SumList2) $LastSum $Sum) ( (is $NewSum (+ $LastSum $N)) (sumlist $R $SumList2 $NewSum $Sum))) +; + ; -; ------------------------------------ +; ; -; select_kth_term(W, Val, SoFar, K, Val) +; ; -; W - list of summed weights (roulette wheel) +; ; -; Val - random value in wheel to use +; ; -; SoFar - counter +; ; -; K - selected term according to Val on W +; ; -; Val - value of selected term +; (= (select-kth-term (:: $Val) $_ $K $K $Val) - (set-det)) + (set-det)) +; + (= (select-kth-term (Cons $Val $_) $X $K $K $Val) ( (>= $Val $X) (set-det))) +; + (= (select-kth-term (Cons $_ $R) $X $K $K2 $Val) ( (is $K3 (+ $K 1)) (select-kth-term $R $X $K3 $K2 $Val))) +; + ; -; ------------------------------------ +; ; -; raw_gen_loop(Tree, Pr, MaxL, S, SL1, SL2): +; ; -; Tree - grammar tree to process +; ; -; Pr - probability of doing an iteration +; ; -; MaxL - max length of generated string for terminating looping +; ; -; S - final generated string +; ; -; SL1, SL2 - current length and final length of generated string +; ; -; Like gen_loop, but no probabilities computed. +; @@ -720,55 +741,59 @@ (raw-gen-loop $Tree $Pr $MaxL $S2 $SL3 $SL2) (append $S1 $S2 $S) (set-det))) +; + (= (raw-gen-loop $Tree $Pr $_ Nil $SL $SL) (set-det)) +; + ; -; ------------------------------------ +; ; -; recognize_loop(Tree, Pr, S, S2, FinalPr): +; ; -; Tree - grammar tree to process +; ; -; Pr - probability of doing an iteration +; ; -; S, S2 - string to recognize (before, after) +; ; -; FinalPr - final probability of execution +; ; -; recognize_loop performs successive iterations of an iterative expression. +; ; -; Attempts to recognize S, computing probability each time. +; ; -; No limit to number of iterations, other than the ability to consume S. +; ; -; epsilon +; ; -; E +; ; -; E:E +; ; -; E:E:E etc. +; ; -; As soon as an iteration fails to consume (after backtracking as well), +; ; -; then iteration quits. +; @@ -779,14 +804,15 @@ (* $PrSoFar (- 1.0 $Pr))) (check-prob $FinalPr))) -; ; new - +; (= (recognize-loop $T $Pr $S $S $PrSoFar $FinalPr) ( (is $FinalPr (* $PrSoFar (- 1.0 $Pr))) (check-prob $FinalPr))) +; + (= (recognize-loop $Tree $Pr $S $S2 $PrSoFar $FinalPr) ( (is $Pr3 @@ -797,6 +823,8 @@ (not (= $S $S3)) (check-prob $Pr1) (recognize-loop $Tree $Pr $S3 $S2 $Pr1 $FinalPr))) +; + (= @@ -804,12 +832,14 @@ ( (min-grammar-prob-P $E) (> $P $E) (set-det))) +; + ; -; ------------------------------------ +; ; -; for testing... +; @@ -834,6 +864,8 @@ (write 'Depth = ') (write $Depth) (nl))) +; + (= @@ -858,6 +890,8 @@ (nl) (writelist $Rlist) (nl))) +; + (= @@ -881,6 +915,8 @@ (nl) (writelist $Prlist) (nl))) +; + (= @@ -899,12 +935,14 @@ (write 'Leftover = ') (write $Leftover) (nl))) +; + ; -; ------------------------------------ +; ; -; sre pretty printer +; @@ -915,6 +953,8 @@ (write )*) (write $R) (set-det))) +; + (= (sre-pp (+ $E $R)) ( (write () @@ -922,15 +962,21 @@ (write )+) (write $R) (set-det))) +; + (= (sre-pp (with_self $E $F)) ( (sre-pp $E) (write :) (sre-pp $F) (set-det))) +; + (= (sre-pp (Cons $A $T)) ( (sre-pp-l (Cons $A $T)) (set-det))) +; + (= (sre-pp (, $A $B)) ( (write () @@ -939,14 +985,20 @@ (write $B) (write )) (set-det))) +; + (= (sre-pp $X) (write $X)) +; + (= (sre-pp-l (:: $A)) ( (sre-pp $A) (set-det))) +; + (= (sre-pp-l (Cons $A $T)) ( (write [) @@ -955,52 +1007,21 @@ (sre-pp-l $T) (write ]) (set-det))) +; + ; -; ------------------------------------ +; ; -; solution dump: writes soln expression to a file, for input later. +; ; -; Grammatical expression is written in multiple lines, since the full +; ; -; expression is often larger than MeTTa's builtin "write" can handle. +; -; /* -; write_soln(Run, E) :- -; set_file_name("soln", Run, File), -; tell(File), -; write('soln('), -; write_term(E), -; write(').'), -; nl, -; told, -; tell(user), -; !. ; -; write_term(node(X,List,Y)) :- -; !, -; write('node('), -; write(X), -; write(',['), -; write_tlist(List), -; write('],'), -; write(Y), -; write(')'). -; write_term(X) :- write(X). -; -; write_tlist([]) :- !. -; write_tlist([X,Y|Z]) :- -; !, -; write_term(X), -; write(','), -; nl, -; write_tlist([Y|Z]). -; write_tlist([X]) :- -; write_term(X). -; */ - diff --git a/sre_dna/utils.metta b/sre_dna/utils.metta index 58c3adb..80930d3 100644 --- a/sre_dna/utils.metta +++ b/sre_dna/utils.metta @@ -1,29 +1,29 @@ ; -; ------------------------------------------------ +; ; -; January 1999 +; ; -; Author: Brian Ross +; ; -; Dept. of Computer Science, Brock University +; ; ; ; -; Misc MeTTa predicates. +; ; ; ; -; Sicstus: comment out member +; ; -; - add routines for random numbers (seed, maybe, ...) +; @@ -31,46 +31,49 @@ (?- (dynamic (/ been_here 0))) True) +; + ; -; append([], A, A). +; ; -; append([A|X], Y, [A|Z]) :- append(X, Y, Z). +; ; -; member(A, [A|_]). +; ; -; member(A, [_|B]) :- member(A, B). +; (= (memberd $A $L) (once (member $A $L))) +; + ; -; my_random(R, N) finds a random integer N between 1 and R +; ; -; Note: N must be uninstantiated! +; (= (my-random $R $N) ( (random-between 1 $R $N) (set-det))) -; ; S is R + 1, - +; ; -; probability2(P, M) satisfied when random number between 0 and M +; ; -; is less or equal to probability P. +; @@ -81,10 +84,14 @@ (* $X $M)) (=< $Y $P) (set-det))) +; + (= (size_of () 0) True) +; + (= (size-of (Cons $_ $R) $K) @@ -92,15 +99,19 @@ (is $K (+ $L 1)) (set-det))) +; + ; -; once(P) :- P, !. +; (= (writel Nil) ( (set-det) (ttyflush))) +; + (= (writel (Cons $A $R)) ( (var $A) @@ -108,90 +119,83 @@ (write $A) (write ' ') (writel $R))) +; + (= (writel (Cons nl $R)) ( (set-det) (nl) (writel $R))) +; + (= (writel (Cons $A $R)) ( (set-det) (write $A) (write ' ') (writel $R))) +; + (= (writel $A) ( (write $A) (ttyflush) (set-det))) +; + (= (writel2 Nil) ( (set-det) (ttyflush))) +; + (= (writel2 (Cons $A $R)) ( (var $A) (set-det) (write $A) (writel2 $R))) +; + (= (writel2 (Cons nl $R)) ( (set-det) (nl) (writel2 $R))) +; + (= (writel2 (Cons $A $R)) ( (set-det) (write $A) (writel2 $R))) +; + (= (writel2 $A) ( (write $A) (ttyflush) (set-det))) +; + (= (copy-struct $S $T) - ( (add-atom &self + ( (add-symbol &self (temp $S)) - (remove-atom &self + (remove-symbol &self (temp $T)) (set-det))) -; /* -; sum_list([], 0). -; sum_list([A|L], N) :- -; sum_list(L, M), -; N is M + A, -; !. ; -; max_list([A|L], Max) :- -; once(max_list2(A, L, Max)). -; -; max_list2(A, [], A). -; max_list2(A, [B|L], Max) :- -; B > A, -; max_list2(B, L, Max). -; max_list2(A, [_|L], Max) :- -; max_list2(A, L, Max). -; -; min_list([A|L], Min) :- -; once(min_list2(A, L, Min)). -; -; min_list2(A, [], A). -; min_list2(A, [B|L], Min) :- -; B < A, -; min_list2(B, L, Min). -; min_list2(A, [_|L], Min) :- -; min_list2(A, L, Min). -; */ - (= (count $_ () 0) True) +; + (= (count $X (Cons $X $Y) $C) @@ -199,32 +203,44 @@ (count $X $Y $C2) (is $C (+ $C2 1)))) +; + (= (count $X (Cons $_ $Y) $C) (count $X $Y $C)) +; + (= (round $X $Y) ( (is $Y (integer (+ $X 0.5))) (set-det))) +; + (= (set-random-number-gen) ( (been-here) (set-det))) +; + (= (set-random-number-gen) - ( (add-atom &self been_here) + ( (add-symbol &self been_here) (set-det) (seed-P $X $Y) (set-seed $X $Y))) +; + (= (set-seed default $_) (set-det)) +; + (= (set-seed random $_) ( (datime (datime $Year $Month $Day $Hour $Min $Sec)) @@ -254,26 +270,21 @@ (+ (mod $N3 30324) 1)) (setrand (rand $R1 $R2 $R3)) - (remove-atom &self + (remove-symbol &self (seed_P $_ $_)) - (add-atom &self + (add-symbol &self (seed_P random (, $R1 (, $R2 $R3)))) (set-det))) -; ; N is approx number of seconds since Jan 1 1970 - -; ; between 1 and 30000 - -; ; shift right 2 bits - -; ; shift right 4 bits - +; (= (set-seed manual (, $X $Y $Z)) (setrand (rand $X $Y $Z))) +; + @@ -282,44 +293,33 @@ ( (debug-set-P yes) (set-det) (writel $L))) -; /* -; set_seed(default, _) :- !. -; set_seed(random, _) :- -; now(N), -; R1 is mod(N, 30000) + 1, ; between 1 and 30000 -; N2 is abs(N >> 2), ; shift right 2 bits -; R2 is mod(N2, 30000) + 1, -; N3 is abs(N >> 4), ; shift right 4 bits -; R3 is mod(N3, 30000) + 1, -; getrand(random(_,_,_,B)), -; setrand(random(R1,R2,R3,B)), -; retract(seed_P(_,_)), -; assert(seed_P(random, (R1,R2,R3))), -; !. -; set_seed(manual, (X, Y, Z)) :- -; getrand(random(_,_,_,B)), ; use default bit string (could be changed) -; setrand(random(X,Y,Z,B)), -; !. -; */ - +; (= (debug_echo $_) True) +; + (= (rem_dups () ()) True) +; + (= (rem-dups (Cons $A $R) $R2) ( (member $A $R) (set-det) (rem-dups $R $R2))) +; + (= (rem-dups (Cons $A $R) (Cons $A $R2)) ( (rem-dups $R $R2) (set-det))) +; + (= @@ -329,9 +329,11 @@ (is $Avg (/ $Sum $N)) (set-det))) +; + ; -; keep appending B to A until A is at least length K. +; @@ -340,51 +342,73 @@ ( (length $A $K2) (>= $K2 $K) (set-det))) +; + (= (extend-list $A $B $K $A2) ( (append $A $B $A3) (extend-list $A3 $B $K $A2) (set-det))) +; + (= (num-list 0 Nil) (set-det)) +; + (= (num-list $N (Cons $N $R)) ( (is $M (- $N 1)) (num-list $M $R))) +; + (= (remove $_ () ()) True) +; + (= (remove $A (Cons $A $B) $B) True) +; + (= (remove $A (Cons $X $B) (Cons $X $C)) (remove $A $B $C)) +; + (= (remove_all $_ () ()) True) +; + (= (remove-all $A (Cons $A $B) $C) ( (set-det) (remove-all $A $B $C))) +; + (= (remove-all $A (Cons $X $B) (Cons $X $C)) (remove-all $A $B $C)) +; + (= (intersect () $_ ()) True) +; + (= (intersect (Cons $X $Y) $R @@ -392,18 +416,26 @@ ( (member $X $R) (set-det) (intersect $Y $R $Z))) +; + (= (intersect (Cons $_ $Y) $R $Z) (intersect $Y $R $Z)) +; + (= (set-diff Nil $T $T) (set-det)) +; + (= (set-diff $T Nil $T) (set-det)) +; + (= (set-diff (Cons $A $B) $T $Diff) @@ -411,44 +443,60 @@ (set-det) (remove-all $A $T $T2) (set-diff $B $T2 $Diff))) +; + (= (set-diff (Cons $A $B) $T (Cons $A $R)) (set-diff $B $T $R)) +; + (= (remove-list Nil $B $B) (set-det)) +; + (= (remove-list (Cons $A $B) $C $D) ( (remove $A $C $E) (set-det) (remove-list $B $E $D))) +; + (= (writelist Nil) ( (nl) (set-det))) +; + (= (writelist (Cons $A $R)) ( (write $A) (nl) (writelist $R) (set-det))) +; + (= (maybe) ( (maybe 0.5) (set-det))) +; + (= (maybe $X) ( (random $Y) (< $Y $X) (set-det))) +; + (= @@ -456,10 +504,14 @@ ( (length $L $Len) (random-permutation2 $L $Len $Perm) (set-det))) +; + (= (random_permutation2 () $_ ()) True) +; + (= (random-permutation2 $L $Len (Cons $X $Perm)) @@ -469,12 +521,16 @@ (- $Len 1)) (random-permutation2 $L2 $Len2 $Perm) (set-det))) +; + (= (remove-nth 0 (Cons $X $Y) $X $Y) (set-det)) +; + (= (remove-nth $N (Cons $X $Y) $Z @@ -483,6 +539,8 @@ (- $N 1)) (remove-nth $N2 $Y $Z $W) (set-det))) +; + (= @@ -492,19 +550,23 @@ (random 0 $Len $Rand) (remove-nth $Rand $L $R $_) (set-det))) +; + ; -; first_K(M, N, List, Grabbed) counts from M to N, grabbing the first N +; ; -; entries of List, returning them in Grabbed. +; (= (first-K $M $N $_ Nil) ( (>= $M $N) (set-det))) +; + (= (first-K $M $N (Cons $A $R) @@ -513,5 +575,7 @@ (+ $M 1)) (first-K $M2 $N $R $S) (set-det))) +; + diff --git a/sxx_machine/bench/prover.metta b/sxx_machine/bench/prover.metta index c54f141..1f4224c 100644 --- a/sxx_machine/bench/prover.metta +++ b/sxx_machine/bench/prover.metta @@ -96,9 +96,13 @@ ; -; (error -; (syntax_error operator_clash) -; (file tests/features/convertor/sxx_machine/bench/prover.pl 33 24 500)) + (= + (problem 3 + (- a) + (# + (+ to_be) + (- to_be))) True) +; (= @@ -110,9 +114,13 @@ ; -; (error -; (syntax_error operator_clash) -; (file tests/features/convertor/sxx_machine/bench/prover.pl 37 20 558)) + (= + (problem 5 + (- a) + (# + (+ b) + (- a))) True) +; (= @@ -137,19 +145,51 @@ ; -; (error -; (syntax_error operator_clash) -; (file tests/features/convertor/sxx_machine/bench/prover.pl 43 22 653)) + (= + (problem 8 + (# + (- a) + (# + (- b) + (+ c))) + (# + (- b) + (# + (- a) + (+ c)))) True) +; -; (error -; (syntax_error operator_clash) -; (file tests/features/convertor/sxx_machine/bench/prover.pl 45 16 693)) + (= + (problem 9 + (# + (- a) + (+ b)) + (# + (& + (+ b) + (- c)) + (# + (- a) + (+ c)))) True) +; -; (error -; (syntax_error operator_clash) -; (file tests/features/convertor/sxx_machine/bench/prover.pl 47 18 741)) + (= + (problem 10 + (& + (# + (- a) + (+ c)) + (# + (- b) + (+ c))) + (# + (& + (- a) + (- b)) + (+ c))) True) +; ; diff --git a/sxx_machine/sxx_builtins_cafe.metta b/sxx_machine/sxx_builtins_cafe.metta index b3157f2..0986d00 100644 --- a/sxx_machine/sxx_builtins_cafe.metta +++ b/sxx_machine/sxx_builtins_cafe.metta @@ -1,105 +1,154 @@ ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Builtin Predicates of MeTTa Cafe +; ; ; ; -; Mutsunori Banbara (banbara@kobe-u.ac.jp) +; ; -; Naoyuki Tamura (tamura@kobe-u.ac.jp) +; ; -; Kobe University +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(op 1150 fx package) + + !(op 1150 fx package) +; + (= - (package $_) True) + (package $_) True) +; + - !(package TauMachine.builtin) + !(package TauMachine.builtin) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Control constructs +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (, (/ True 0) (/ otherwise 0))) - !(public (, (/ fail 0) (/ False 0))) - !(public (/ (set-det) 0)) - !(public (/ ^ 2)) - !(public (/ , 2)) - !(public (/ or 2)) - !(public (/ -> 2)) - !(public (/ call 1)) + !(public (, (/ True 0) (/ otherwise 0))) +; + + !(public (, (/ fail 0) (/ False 0))) +; + + !(public (/ (set-det) 0)) +; + + !(public (/ ^ 2)) +; + + !(public (/ , 2)) +; + + !(public (/ or 2)) +; + + !(public (/ -> 2)) +; + + !(public (/ call 1)) +; + - (= true True) + (= true True) +; + - (= otherwise True) + (= otherwise True) +; + (= fail - (empty)) + (empty)) +; + (= false - (empty)) + (empty)) +; + - (= ! True) + (= ! True) +; + (= (^ $_ $G) - (call $G)) + (call $G)) +; + (= (, $P $Q) - ( (call $P) (call $Q))) + ( (call $P) (call $Q))) +; + (= (or $P $Q) ( (\= $P - (det-if-then $_ $_)) (call $P))) + (det-if-then $_ $_)) (call $P))) +; + (= (or $P $Q) ( (\= $Q - (det-if-then $_ $_)) (call $Q))) + (det-if-then $_ $_)) (call $Q))) +; + (= (det-if-then $IF $THEN) ( (call $IF) (set-det) - (call $THEN))) + (call $THEN))) +; + (= (det-if-then-else $IF $THEN $ELSE) ( (call $IF) (set-det) - (call $THEN))) + (call $THEN))) +; + (= (det-if-then-else $IF $THEN $ELSE) - (call $ELSE)) + (call $ELSE)) +; + (= (call $Term) - ( ($get-current-B $Cut) ($meta-call $Term user $Cut 0 interpret))) + ( ($get-current-B $Cut) ($meta-call $Term user $Cut 0 interpret))) +; + (= @@ -107,168 +156,246 @@ ( (var $X) (set-det) (illarg var - (call $X) 1))) + (call $X) 1))) +; + (= ($meta-call $X $_ $_ $_ $_) ( (closure $X) (set-det) - ($call-closure $X))) + ($call-closure $X))) +; + (= ($meta-call True $_ $_ $_ $_) - (set-det)) + (set-det)) +; + (= ($meta-call trace $_ $_ $_ $_) - ( (set-det) (trace))) + ( (set-det) (trace))) +; + (= ($meta-call debug $_ $_ $_ $_) - ( (set-det) (debug))) + ( (set-det) (debug))) +; + (= ($meta-call notrace $_ $_ $_ $_) - ( (set-det) (notrace))) + ( (set-det) (notrace))) +; + (= ($meta-call nodebug $_ $_ $_ $_) - ( (set-det) (nodebug))) + ( (set-det) (nodebug))) +; + (= ($meta-call (spy $L) $_ $_ $_ $_) - ( (set-det) (spy $L))) + ( (set-det) (spy $L))) +; + (= ($meta-call (nospy $L) $_ $_ $_ $_) - ( (set-det) (nospy $L))) + ( (set-det) (nospy $L))) +; + (= ($meta-call nospyall $_ $_ $_ $_) - ( (set-det) (nospyall))) + ( (set-det) (nospyall))) +; + (= ($meta-call (leash $L) $_ $_ $_ $_) - ( (set-det) (leash $L))) + ( (set-det) (leash $L))) +; + (= ($meta-call (Cons $X $Xs) $_ $_ $_ $_) - ( (set-det) (consult (Cons $X $Xs)))) + ( (set-det) (consult (Cons $X $Xs)))) +; + (= ($meta-call (^ $_ $X) $P $Cut $Depth $Mode) - ( (set-det) ($meta-call $X $P $Cut $Depth $Mode))) + ( (set-det) ($meta-call $X $P $Cut $Depth $Mode))) +; + (= ($meta-call (with_self $P $X) $_ $Cut $Depth $Mode) - ( (set-det) ($meta-call $X $P $Cut $Depth $Mode))) + ( (set-det) ($meta-call $X $P $Cut $Depth $Mode))) +; + (= ($meta-call (set-det) $_ no $_ $_) - ( (set-det) (illarg (context if cut) (set-det) 0))) + ( (set-det) (illarg (context if cut) (set-det) 0))) +; + (= ($meta-call (set-det) $_ $Cut $_ $_) - ( (set-det) ($cut $Cut))) + ( (set-det) ($cut $Cut))) +; + (= ($meta-call (, $X $Y) $P $Cut $Depth $Mode) ( (set-det) ($meta-call $X $P $Cut $Depth $Mode) - ($meta-call $Y $P $Cut $Depth $Mode))) + ($meta-call $Y $P $Cut $Depth $Mode))) +; + (= ($meta-call (det-if-then-else $X $Y $Z) $P $Cut $Depth $Mode) - ( (set-det) (det-if-then-else ($meta-call $X $P no $Depth $Mode) ($meta-call $Y $P $Cut $Depth $Mode) ($meta-call $Z $P $Cut $Depth $Mode)))) + ( (set-det) (det-if-then-else ($meta-call $X $P no $Depth $Mode) ($meta-call $Y $P $Cut $Depth $Mode) ($meta-call $Z $P $Cut $Depth $Mode)))) +; + (= ($meta-call (det-if-then $X $Y) $P $Cut $Depth $Mode) - ( (set-det) (det-if-then ($meta-call $X $P no $Depth $Mode) ($meta-call $Y $P $Cut $Depth $Mode)))) + ( (set-det) (det-if-then ($meta-call $X $P no $Depth $Mode) ($meta-call $Y $P $Cut $Depth $Mode)))) +; + (= ($meta-call (or $X $Y) $P $Cut $Depth $Mode) - ( (set-det) (or ($meta-call $X $P $Cut $Depth $Mode) ($meta-call $Y $P $Cut $Depth $Mode)))) + ( (set-det) (or ($meta-call $X $P $Cut $Depth $Mode) ($meta-call $Y $P $Cut $Depth $Mode)))) +; + (= ($meta-call (not $X) $P $_ $Depth $Mode) - ( (set-det) (not ($meta-call $X $P no $Depth $Mode)))) + ( (set-det) (not ($meta-call $X $P no $Depth $Mode)))) +; + (= ($meta-call (findall $X $Y $Z) $P $Cut $Depth $Mode) - ( (set-det) (findall $X ($meta-call $Y $P $Cut $Depth $Mode) $Z))) + ( (set-det) (findall $X ($meta-call $Y $P $Cut $Depth $Mode) $Z))) +; + (= ($meta-call (bagof $X $Y $Z) $P $Cut $Depth $Mode) - ( (set-det) (bagof $X ($meta-call $Y $P $Cut $Depth $Mode) $Z))) + ( (set-det) (bagof $X ($meta-call $Y $P $Cut $Depth $Mode) $Z))) +; + (= ($meta-call (setof $X $Y $Z) $P $Cut $Depth $Mode) - ( (set-det) (setof $X ($meta-call $Y $P $Cut $Depth $Mode) $Z))) + ( (set-det) (setof $X ($meta-call $Y $P $Cut $Depth $Mode) $Z))) +; + (= ($meta-call (once $X) $P $Cut $Depth $Mode) - ( (set-det) (once ($meta-call $X $P $Cut $Depth $Mode)))) + ( (set-det) (once ($meta-call $X $P $Cut $Depth $Mode)))) +; + (= ($meta-call (on-exception $X $Y $Z) $P $Cut $Depth $Mode) - ( (set-det) (on-exception $X ($meta-call $Y $P $Cut $Depth $Mode) ($meta-call $Z $P $Cut $Depth $Mode)))) + ( (set-det) (on-exception $X ($meta-call $Y $P $Cut $Depth $Mode) ($meta-call $Z $P $Cut $Depth $Mode)))) +; + (= ($meta-call (catch $X $Y $Z) $P $Cut $Depth $Mode) - ( (set-det) (catch ($meta-call $X $P $Cut $Depth $Mode) $Y ($meta-call $Z $P $Cut $Depth $Mode)))) + ( (set-det) (catch ($meta-call $X $P $Cut $Depth $Mode) $Y ($meta-call $Z $P $Cut $Depth $Mode)))) +; + ; -; '$meta_call'(freeze(X,Y), P, Cut, Depth, Mode) :- !, ??? +; ; -; freeze(X, '$meta_call'(Y, P, Cut, Depth, Mode)). +; (= ($meta-call (synchronized $X $Y) $P $Cut $Depth $Mode) - ( (set-det) (synchronized $X ($meta-call $Y $P $Cut $Depth $Mode)))) + ( (set-det) (synchronized $X ($meta-call $Y $P $Cut $Depth $Mode)))) +; + (= ($meta-call - (get-atoms &self + (get-symbols &self (= $X $Y)) $P $_ $_ $_) - ( (set-det) (get-atoms &self (= (: $P $X) $Y)))) + ( (set-det) (get-symbols &self (= (: $P $X) $Y)))) +; + (= ($meta-call - (add-atom &self $X) $P $_ $_ $_) - ( (set-det) (add-atom &self (: $P $X)))) + (add-symbol &self $X) $P $_ $_ $_) + ( (set-det) (add-symbol &self (: $P $X)))) +; + (= ($meta-call - (add-atom &self $X) $P $_ $_ $_) - ( (set-det) (add-atom &self (: $P $X)))) + (add-symbol &self $X) $P $_ $_ $_) + ( (set-det) (add-symbol &self (: $P $X)))) +; + (= ($meta-call - (add-atom &self $X) $P $_ $_ $_) - ( (set-det) (add-atom &self (: $P $X)))) + (add-symbol &self $X) $P $_ $_ $_) + ( (set-det) (add-symbol &self (: $P $X)))) +; + (= ($meta-call - (remove-atom &self $X) $P $_ $_ $_) - ( (set-det) (remove-atom &self (: $P $X)))) + (remove-symbol &self $X) $P $_ $_ $_) + ( (set-det) (remove-symbol &self (: $P $X)))) +; + (= ($meta-call (abolish $X) $P $_ $_ $_) - ( (set-det) (abolish (with_self $P $X)))) + ( (set-det) (abolish (with_self $P $X)))) +; + (= ($meta-call - (remove-all-atoms &self $X) $P $_ $_ $_) - ( (set-det) (remove-all-atoms &self (: $P $X)))) + (remove-all-symbols &self $X) $P $_ $_ $_) + ( (set-det) (remove-all-symbols &self (: $P $X)))) +; + (= ($meta-call $X $P $_ $Depth $Mode) ( (atom $P) (callable $X) (set-det) - ($meta-call $Mode $Depth $P $X))) + ($meta-call $Mode $Depth $P $X))) +; + (= ($meta-call $X $P $_ $_ $_) (illarg (type callable) - (call (with_self $P $X)) 1)) + (call (with_self $P $X)) 1)) +; + (= ($meta-call trace $Depth $P $X) ( (set-det) (functor $X $F $A) ($trace-goal $X $P - (/ $F $A) $Depth))) + (/ $F $A) $Depth))) +; + (= ($meta-call interpret $Depth $P $X) - ( (functor $X $F $A) ($call-internal $X $P (/ $F $A) $Depth interpret))) + ( (functor $X $F $A) ($call-internal $X $P (/ $F $A) $Depth interpret))) +; + (= @@ -279,40 +406,56 @@ ($get-current-B $Cut) (is $Depth1 (+ $Depth 1)) - (get-atoms &self + (get-symbols &self (= (: $P $X) $Body)) - ($meta-call $Body $P $Cut $Depth1 $Mode))) + ($meta-call $Body $P $Cut $Depth1 $Mode))) +; + (= ($call-internal $X $P $_ $_ $_) - ($call $P $X)) + ($call $P $X)) +; + - !(public (, (/ catch 3) (/ throw 1))) - !(public (/ on-exception 3)) + !(public (, (/ catch 3) (/ throw 1))) +; + + !(public (/ on-exception 3)) +; + (= (catch $Goal $Catch $Recovery) - (on-exception $Catch $Goal $Recovery)) + (on-exception $Catch $Goal $Recovery)) +; + (= (throw $Msg) - (raise-exception $Msg)) + (raise-exception $Msg)) +; + (= (on-exception $Catch $Goal $Recovery) ( (callable $Goal) (set-det) - ($on-exception $Catch $Goal $Recovery))) + ($on-exception $Catch $Goal $Recovery))) +; + (= (on-exception $Catch $Goal $Recovery) (illarg (type callable) - (on-exception $Catch $Goal $Recovery) 2)) + (on-exception $Catch $Goal $Recovery) 2)) +; + (= @@ -320,612 +463,889 @@ ( ($set-exception %none) ($begin-exception $L) (call $Goal) - ($end-exception $L))) + ($end-exception $L))) +; + (= ($on-exception $Catch $Goal $Recovery) ( ($get-exception $Msg) (\== $Msg %none) - ($catch-and-throw $Msg $Catch $Recovery))) + ($catch-and-throw $Msg $Catch $Recovery))) +; + (= ($catch-and-throw $Msg $Msg $Recovery) ( (set-det) ($set-exception %none) - (call $Recovery))) + (call $Recovery))) +; + (= ($catch-and-throw $Msg $_ $_) - (raise-exception $Msg)) + (raise-exception $Msg)) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Term unification +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (, (/ = 2) (/ %unify 2))) - !(public (, (/ \= 2) (/ %not-unifiable 2))) + !(public (, (/ = 2) (/ %unify 2))) +; + + !(public (, (/ \= 2) (/ %not-unifiable 2))) +; + (= (= $X $Y) - (= $X $Y)) + (= $X $Y)) +; + (= ($unify $X $Y) - ($unify $X $Y)) + ($unify $X $Y)) +; + (= (\= $X $Y) - (\= $X $Y)) + (\= $X $Y)) +; + (= ($not-unifiable $X $Y) - ($not-unifiable $X $Y)) + ($not-unifiable $X $Y)) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Type testing +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (, (/ var 1) (/ is-symbol 1) (/ integer 1) (/ long 1) (/ float 1) (/ symbolic 1) (/ compound 1) (/ nonvar 1) (/ number 1))) - !(public (, (/ java 1) (/ java 2) (/ closure 1))) - !(public (, (/ ground 1) (/ callable 1))) + !(public (, (/ var 1) (/ is-symbol 1) (/ integer 1) (/ long 1) (/ float 1) (/ symbolic 1) (/ compound 1) (/ nonvar 1) (/ number 1))) +; + + !(public (, (/ java 1) (/ java 2) (/ closure 1))) +; + + !(public (, (/ ground 1) (/ callable 1))) +; + (= (var $X) - (var $X)) + (var $X)) +; + (= (atom $X) - (atom $X)) + (atom $X)) +; + (= (integer $X) - (integer $X)) + (integer $X)) +; + (= (long $X) - (long $X)) + (long $X)) +; + (= (float $X) - (float $X)) + (float $X)) +; + (= (atomic $X) - (atomic $X)) + (atomic $X)) +; + (= (nonvar $X) - (nonvar $X)) + (nonvar $X)) +; + (= (number $X) - (number $X)) + (number $X)) +; + (= (java $X) - (java $X)) + (java $X)) +; + (= (java $X $Y) - (java $X $Y)) + (java $X $Y)) +; + (= (closure $X) - (closure $X)) + (closure $X)) +; + (= (ground $X) - (ground $X)) + (ground $X)) +; + (= (compound $X) ( (nonvar $X) (functor $X $_ $A) - (> $A 0))) + (> $A 0))) +; + (= (callable $X) - ( (atom $X) (set-det))) + ( (atom $X) (set-det))) +; + (= (callable $X) - ( (compound $X) (set-det))) + ( (compound $X) (set-det))) +; + (= (callable $X) - (closure $X)) + (closure $X)) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Term comparison +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (, (/ == 2) (/ %equality-of-term 2))) - !(public (, (/ \== 2) (/ %inequality-of-term 2))) - !(public (, (/ @< 2) (/ %before 2))) - !(public (, (/ @> 2) (/ %after 2))) - !(public (, (/ @=< 2) (/ %not-after 2))) - !(public (, (/ @>= 2) (/ %not-before 2))) - !(public (, (/ ?= 2) (/ %identical-or-cannot-unify 2))) - !(public (/ compare 3)) + !(public (, (/ == 2) (/ %equality-of-term 2))) +; + + !(public (, (/ \== 2) (/ %inequality-of-term 2))) +; + + !(public (, (/ @< 2) (/ %before 2))) +; + + !(public (, (/ @> 2) (/ %after 2))) +; + + !(public (, (/ @=< 2) (/ %not-after 2))) +; + + !(public (, (/ @>= 2) (/ %not-before 2))) +; + + !(public (, (/ ?= 2) (/ %identical-or-cannot-unify 2))) +; + + !(public (/ compare 3)) +; + ; -; :- public sort/2. witten in Java +; ; -; :- public keysort/2. witten in Java +; ; -; :- public merge/3. +; (= (== $X $Y) - (== $X $Y)) + (== $X $Y)) +; + (= ($equality-of-term $X $Y) - ($equality-of-term $X $Y)) + ($equality-of-term $X $Y)) +; + (= (\== $X $Y) - (\== $X $Y)) + (\== $X $Y)) +; + (= ($inequality-of-term $X $Y) - ($inequality-of-term $X $Y)) + ($inequality-of-term $X $Y)) +; + (= (@< $X $Y) - (@< $X $Y)) + (@< $X $Y)) +; + (= ($before $X $Y) - ($before $X $Y)) + ($before $X $Y)) +; + (= (@> $X $Y) - (@> $X $Y)) + (@> $X $Y)) +; + (= ($after $X $Y) - ($after $X $Y)) + ($after $X $Y)) +; + (= (@=< $X $Y) - (@=< $X $Y)) + (@=< $X $Y)) +; + (= ($not-after $X $Y) - ($not-after $X $Y)) + ($not-after $X $Y)) +; + (= (@>= $X $Y) - (@>= $X $Y)) + (@>= $X $Y)) +; + (= ($not-before $X $Y) - ($not-before $X $Y)) + ($not-before $X $Y)) +; + (= (?= $X $Y) - (?= $X $Y)) + (?= $X $Y)) +; + (= ($identical-or-cannot-unify $X $Y) - ($identical-or-cannot-unify $X $Y)) + ($identical-or-cannot-unify $X $Y)) +; + (= (compare $Op $X $Y) - ( ($compare0 $Op0 $X $Y) ($map-compare-op $Op0 $Op))) + ( ($compare0 $Op0 $X $Y) ($map-compare-op $Op0 $Op))) +; + (= ($map-compare-op $Op0 $Op) ( (=:= $Op0 0) (set-det) - (= $Op =))) + (= $Op =))) +; + (= ($map-compare-op $Op0 $Op) ( (< $Op0 0) (set-det) - (= $Op <))) + (= $Op <))) +; + (= ($map-compare-op $Op0 $Op) ( (> $Op0 0) (set-det) - (= $Op >))) + (= $Op >))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Term creation and decomposition +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; :- public arg/3. --> written in Java +; ; -; :- public functor/3. --> written in Java +; - !(public (/ =.. 2)) - !(public (/ copy-term 2)) + !(public (/ =.. 2)) +; + + !(public (/ copy-term 2)) +; + (= (=.. $Term $List) - (=.. $Term $List)) + (=.. $Term $List)) +; + (= (copy-term $X $Y) - (copy-term $X $Y)) + (copy-term $X $Y)) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Arithmetic evaluation +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (/ is 2)) - !(public (, (/ %abs 2) (/ %asin 2) (/ %acos 2) (/ %atan 2))) - !(public (, (/ %bitwise-conj 3) (/ %bitwise-disj 3) (/ %bitwise-exclusive-or 3) (/ %bitwise-neg 2))) - !(public (, (/ %ceil 2) (/ %cos 2))) - !(public (/ %degrees 2)) - !(public (/ %exp 2)) - !(public (, (/ %float 2) (/ %float-integer-part 2) (/ %float-fractional-part 2) (/ %float-quotient 3) (/ %floor 2))) - !(public (/ %int-quotient 3)) - !(public (/ %log 2)) - !(public (, (/ %max 3) (/ %min 3) (/ %minus 3) (/ %mod 3) (/ %multi 3))) - !(public (, (/ %plus 3) (/ %pow 3))) - !(public (, (/ %radians 2) (/ %rint 2) (/ %round 2))) - !(public (, (/ %shift-left 3) (/ %shift-right 3) (/ %sign 2) (/ %sin 2) (/ %sqrt 2))) - !(public (, (/ %tan 2) (/ %truncate 2))) + !(public (/ is 2)) +; + + !(public (, (/ %abs 2) (/ %asin 2) (/ %acos 2) (/ %atan 2))) +; + + !(public (, (/ %bitwise-conj 3) (/ %bitwise-disj 3) (/ %bitwise-exclusive-or 3) (/ %bitwise-neg 2))) +; + + !(public (, (/ %ceil 2) (/ %cos 2))) +; + + !(public (/ %degrees 2)) +; + + !(public (/ %exp 2)) +; + + !(public (, (/ %float 2) (/ %float-integer-part 2) (/ %float-fractional-part 2) (/ %float-quotient 3) (/ %floor 2))) +; + + !(public (/ %int-quotient 3)) +; + + !(public (/ %log 2)) +; + + !(public (, (/ %max 3) (/ %min 3) (/ %minus 3) (/ %mod 3) (/ %multi 3))) +; + + !(public (, (/ %plus 3) (/ %pow 3))) +; + + !(public (, (/ %radians 2) (/ %rint 2) (/ %round 2))) +; + + !(public (, (/ %shift-left 3) (/ %shift-right 3) (/ %sign 2) (/ %sin 2) (/ %sqrt 2))) +; + + !(public (, (/ %tan 2) (/ %truncate 2))) +; + (= (is $Z $Y) - (is $Z $Y)) + (is $Z $Y)) +; + (= ($abs $X $Y) - ($abs $X $Y)) + ($abs $X $Y)) +; + (= ($asin $X $Y) - ($asin $X $Y)) + ($asin $X $Y)) +; + (= ($acos $X $Y) - ($acos $X $Y)) + ($acos $X $Y)) +; + (= ($atan $X $Y) - ($atan $X $Y)) + ($atan $X $Y)) +; + (= ($bitwise-conj $X $Y $Z) - ($bitwise-conj $X $Y $Z)) + ($bitwise-conj $X $Y $Z)) +; + (= ($bitwise-disj $X $Y $Z) - ($bitwise-disj $X $Y $Z)) + ($bitwise-disj $X $Y $Z)) +; + (= ($bitwise-exclusive-or $X $Y $Z) - ($bitwise-exclusive-or $X $Y $Z)) + ($bitwise-exclusive-or $X $Y $Z)) +; + (= ($bitwise-neg $X $Y) - ($bitwise-neg $X $Y)) + ($bitwise-neg $X $Y)) +; + (= ($ceil $X $Y) - ($ceil $X $Y)) + ($ceil $X $Y)) +; + (= ($cos $X $Y) - ($cos $X $Y)) + ($cos $X $Y)) +; + (= ($degrees $X $Y) - ($degrees $X $Y)) + ($degrees $X $Y)) +; + (= ($exp $X $Y) - ($exp $X $Y)) + ($exp $X $Y)) +; + (= ($float $X $Y) - ($float $X $Y)) + ($float $X $Y)) +; + (= ($float-integer-part $X $Y) - ($float-integer-part $X $Y)) + ($float-integer-part $X $Y)) +; + (= ($float-fractional-part $X $Y) - ($float-fractional-part $X $Y)) + ($float-fractional-part $X $Y)) +; + (= ($float-quotient $X $Y $Z) - ($float-quotient $X $Y $Z)) + ($float-quotient $X $Y $Z)) +; + (= ($floor $X $Y) - ($floor $X $Y)) + ($floor $X $Y)) +; + (= ($int-quotient $X $Y $Z) - ($int-quotient $X $Y $Z)) + ($int-quotient $X $Y $Z)) +; + (= ($log $X $Y) - ($log $X $Y)) + ($log $X $Y)) +; + (= ($max $X $Y $Z) - ($max $X $Y $Z)) + ($max $X $Y $Z)) +; + (= ($min $X $Y $Z) - ($min $X $Y $Z)) + ($min $X $Y $Z)) +; + (= ($minus $X $Y $Z) - ($minus $X $Y $Z)) + ($minus $X $Y $Z)) +; + (= ($mod $X $Y $Z) - ($mod $X $Y $Z)) + ($mod $X $Y $Z)) +; + (= ($multi $X $Y $Z) - ($multi $X $Y $Z)) + ($multi $X $Y $Z)) +; + (= ($plus $X $Y $Z) - ($plus $X $Y $Z)) + ($plus $X $Y $Z)) +; + (= ($pow $X $Y $Z) - ($pow $X $Y $Z)) + ($pow $X $Y $Z)) +; + (= ($radians $X $Y) - ($radians $X $Y)) + ($radians $X $Y)) +; + (= ($rint $X $Y) - ($rint $X $Y)) + ($rint $X $Y)) +; + (= ($round $X $Y) - ($round $X $Y)) + ($round $X $Y)) +; + (= ($shift-left $X $Y $Z) - ($shift-left $X $Y $Z)) + ($shift-left $X $Y $Z)) +; + (= ($shift-right $X $Y $Z) - ($shift-right $X $Y $Z)) + ($shift-right $X $Y $Z)) +; + (= ($sign $X $Y) - ($sign $X $Y)) + ($sign $X $Y)) +; + (= ($sin $X $Y) - ($sin $X $Y)) + ($sin $X $Y)) +; + (= ($sqrt $X $Y) - ($sqrt $X $Y)) + ($sqrt $X $Y)) +; + (= ($tan $X $Y) - ($tan $X $Y)) + ($tan $X $Y)) +; + (= ($truncate $X $Y) - ($truncate $X $Y)) + ($truncate $X $Y)) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Arithmetic comparison +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (, (/ =:= 2) (/ %arith-equal 2))) - !(public (, (/ =\= 2) (/ %arith-not-equal 2))) - !(public (, (/ < 2) (/ %less-than 2))) - !(public (, (/ =< 2) (/ %less-or-equal 2))) - !(public (, (/ > 2) (/ %greater-than 2))) - !(public (, (/ >= 2) (/ %greater-or-equal 2))) + !(public (, (/ =:= 2) (/ %arith-equal 2))) +; + + !(public (, (/ =\= 2) (/ %arith-not-equal 2))) +; + + !(public (, (/ < 2) (/ %less-than 2))) +; + + !(public (, (/ =< 2) (/ %less-or-equal 2))) +; + + !(public (, (/ > 2) (/ %greater-than 2))) +; + + !(public (, (/ >= 2) (/ %greater-or-equal 2))) +; + (= (=:= $X $Y) - (=:= $X $Y)) + (=:= $X $Y)) +; + (= ($arith-equal $X $Y) - ($arith-equal $X $Y)) + ($arith-equal $X $Y)) +; + (= (=\= $X $Y) - (=\= $X $Y)) + (=\= $X $Y)) +; + (= ($arith-not-equal $X $Y) - ($arith-not-equal $X $Y)) + ($arith-not-equal $X $Y)) +; + (= (< $X $Y) - (< $X $Y)) + (< $X $Y)) +; + (= ($less-than $X $Y) - ($less-than $X $Y)) + ($less-than $X $Y)) +; + (= (=< $X $Y) - (=< $X $Y)) + (=< $X $Y)) +; + (= ($less-or-equal $X $Y) - ($less-or-equal $X $Y)) + ($less-or-equal $X $Y)) +; + (= (> $X $Y) - (> $X $Y)) + (> $X $Y)) +; + (= ($greater-than $X $Y) - ($greater-than $X $Y)) + ($greater-than $X $Y)) +; + (= (>= $X $Y) - (>= $X $Y)) + (>= $X $Y)) +; + (= ($greater-or-equal $X $Y) - ($greater-or-equal $X $Y)) + ($greater-or-equal $X $Y)) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Clause retrieval and information +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (/ clause 2)) - !(public (/ initialization 2)) - !(public (/ %new-indexing-hash 3)) + !(public (/ clause 2)) +; + + !(public (/ initialization 2)) +; + + !(public (/ %new-indexing-hash 3)) +; + (= - (get-atoms &self + (get-symbols &self (= $Head $B)) ( ($head-to-term $Head $H (with_self $P $PI) - (get-atoms &self + (get-symbols &self (= $Head $B))) ($new-internal-database $P) ($check-procedure-permission (with_self $P $PI) access private-procedure - (get-atoms &self + (get-symbols &self (= $Head $B))) ($clause-internal $P $PI $H $Cl $_) (copy-term $Cl (= $H $B)))) -; ;(ground(Cl) -> Cl = (H :- B) ; copy_term(Cl, (H :- B))). ??? - +; ; -; head --> term +; (= ($head-to-term $H $T (with_self $Pkg (/ $F $A)) $Goal) - ( ($head-to-term $H $T user $Pkg $Goal) (functor $T $F $A))) + ( ($head-to-term $H $T user $Pkg $Goal) (functor $T $F $A))) +; + (= ($head-to-term $H $_ $_ $_ $Goal) ( (var $H) (set-det) - (illarg var $Goal 1))) + (illarg var $Goal 1))) +; + (= ($head-to-term (with_self $P $H) $T $_ $Pkg $Goal) - ( (set-det) ($head-to-term $H $T $P $Pkg $Goal))) + ( (set-det) ($head-to-term $H $T $P $Pkg $Goal))) +; + (= ($head-to-term $H $H $Pkg $Pkg $_) ( (callable $H) (atom $Pkg) - (set-det))) + (set-det))) +; + (= ($head-to-term $_ $_ $_ $_ $Goal) (illarg - (type callable) $Goal 1)) + (type callable) $Goal 1)) +; + ; -; creates an internal database for A if no exists. +; (= ($new-internal-database $A) ( (atom $A) ($get-hash-manager $HM) - ($new-internal-database $HM $A))) + ($new-internal-database $HM $A))) +; + (= ($new-internal-database $HM $A) - ( (hash-contains-key $HM $A) (set-det))) + ( (hash-contains-key $HM $A) (set-det))) +; + (= ($new-internal-database $_ $A) ( (new-hash $_ - (:: (alias $A))) ($init-internal-database $A))) + (:: (alias $A))) ($init-internal-database $A))) +; + (= @@ -934,22 +1354,28 @@ (findall $_ (with_self $A (%init)) $_) - (set-det))) + (set-det))) +; + (= - ($init_internal_database $_) True) + (%init_internal_database $_) True) +; + ; -; checks if the internal database of A exists. +; (= ($defined-internal-database $A) ( (atom $A) ($get-hash-manager $HM) - (hash-contains-key $HM $A))) + (hash-contains-key $HM $A))) +; + ; -; repeatedly finds dynamic clauses. +; (= @@ -958,28 +1384,27 @@ ($get-indices $P $PI $H $RevRefs) ($get-instances $RevRefs $Cls_Refs) ($clause-internal0 $Cls_Refs $Cl $Ref))) -; ; ??? - -; ;length(Cls_Refs,N), - -; ;'$fast_write'([clause_internal,N,for,P,PI]),nl, - -; ; - +; (= - ($clause_internal0 () $_ $_) - (empty)) + (%clause_internal0 () $_ $_) + (empty)) +; + (= ($clause-internal0 (:: (, $Cl $Ref)) $Cl $Ref) - (set-det)) + (set-det)) +; + (= ($clause-internal0 $L $Cl $Ref) ($builtin-member - (, $Cl $Ref) $L)) + (, $Cl $Ref) $L)) +; + (= @@ -989,17 +1414,21 @@ (det-if-then-else (hash-contains-key $IH $Key) (hash-get $IH $Key $Refs) - (hash-get $IH var $Refs)))) + (hash-get $IH var $Refs)))) +; + ; -; finds the indexing hashtable for P:PI. creates it if no exist. +; (= ($new-indexing-hash $P $PI $IH) ( (hash-contains-key $P $PI) (set-det) - (hash-get $P $PI $IH))) + (hash-get $P $PI $IH))) +; + (= ($new-indexing-hash $P $PI $IH) ( (new-hash $IH) @@ -1007,40 +1436,56 @@ (hash-put $IH var Nil) (hash-put $IH lis Nil) (hash-put $IH str Nil) - (hash-put $P $PI $IH))) + (hash-put $P $PI $IH))) +; + (= ($calc-indexing-key $H all) - ( (atom $H) (set-det))) + ( (atom $H) (set-det))) +; + (= ($calc-indexing-key $H $Key) - ( (arg 1 $H $A1) ($calc-indexing-key0 $A1 $Key))) + ( (arg 1 $H $A1) ($calc-indexing-key0 $A1 $Key))) +; + (= ($calc-indexing-key0 $A1 all) - ( (var $A1) (set-det))) + ( (var $A1) (set-det))) +; + (= ($calc-indexing-key0 $A1 lis) ( (= $A1 - (Cons $_ $_)) (set-det))) + (Cons $_ $_)) (set-det))) +; + (= ($calc-indexing-key0 $A1 str) - ( (compound $A1) (set-det))) + ( (compound $A1) (set-det))) +; + (= ($calc-indexing-key0 $A1 $Key) ( (ground $A1) (set-det) - ($term-hash $A1 $Key))) + ($term-hash $A1 $Key))) +; + (= ($calc-indexing-key0 $A1 $Key) (illarg (type term) - ($calc-indexing-key0 $A1 $Key) 1)) + ($calc-indexing-key0 $A1 $Key) 1)) +; + ; -; checks the permission of predicate P:F/A. +; (= @@ -1048,7 +1493,9 @@ (with_self $P (/ $F $A)) $Operation $ObjType $Goal) ( (hash-contains-key $P - (/ $F $A)) (set-det))) + (/ $F $A)) (set-det))) +; + (= ($check-procedure-permission (with_self $P @@ -1058,83 +1505,107 @@ (illarg (permission $Operation $ObjType (with_self $P - (/ $F $A)) $_) $Goal $_))) + (/ $F $A)) $_) $Goal $_))) +; + (= - ($check_procedure_permission $_ $_ $_ $_) True) + (%check_procedure_permission $_ $_ $_ $_) True) +; + ; -; initialize internal databases of given packages. +; (= (initialization Nil $Goal) - ( (set-det) (once $Goal))) + ( (set-det) (once $Goal))) +; + (= (initialization (Cons $P $Ps) $Goal) - ( ($new-internal-database $P) (initialization $Ps $Goal))) + ( ($new-internal-database $P) (initialization $Ps $Goal))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Clause creation and destruction +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (/ assert 1)) - !(public (/ assertz 1)) - !(public (/ asserta 1)) - !(public (/ retract 1)) - !(public (/ abolish 1)) - !(public (/ retractall 1)) + !(public (/ assert 1)) +; + + !(public (/ assertz 1)) +; + + !(public (/ asserta 1)) +; + + !(public (/ retract 1)) +; + + !(public (/ abolish 1)) +; + + !(public (/ retractall 1)) +; + (= - (add-atom &self $T) - (add-atom &self $T)) + (add-symbol &self $T) + (add-symbol &self $T)) +; + (= - (add-atom &self $T) + (add-symbol &self $T) ( ($term-to-clause $T $Cl (with_self $P $PI) - (add-atom &self $T)) + (add-symbol &self $T)) ($new-internal-database $P) ($check-procedure-permission (with_self $P $PI) modify static-procedure - (add-atom &self $T)) + (add-symbol &self $T)) (copy-term $Cl $NewCl) ($insert $NewCl $Ref) ($update-indexing $P $PI $Cl $Ref z) (fail))) -; ;'$fast_write'([intert,NewCl,Ref]), nl, ;??? - +; (= - (assertz $_) True) + (assertz $_) True) +; + (= - (add-atom &self $T) + (add-symbol &self $T) ( ($term-to-clause $T $Cl (with_self $P $PI) - (add-atom &self $T)) + (add-symbol &self $T)) ($new-internal-database $P) ($check-procedure-permission (with_self $P $PI) modify static-procedure - (add-atom &self $T)) + (add-symbol &self $T)) (copy-term $Cl $NewCl) ($insert $NewCl $Ref) ($update-indexing $P $PI $Cl $Ref a) (fail))) -; ;'$fast_write'([insert,NewCl,Ref]), nl, ;??? - +; (= - (asserta $_) True) + (asserta $_) True) +; + (= @@ -1151,56 +1622,57 @@ ($erase-all $Refs) (hash-remove $P $PI) (fail))) -; ;'$fast_write'([erase_all,Refs]), nl, ;??? - +; (= - (abolish $_) True) + (abolish $_) True) +; + (= - (remove-atom &self $Cl) + (remove-symbol &self $Cl) ( ($clause-to-term $Cl $T (with_self $P $PI) - (remove-atom &self $Cl)) + (remove-symbol &self $Cl)) ($new-internal-database $P) ($check-procedure-permission (with_self $P $PI) access static-procedure - (remove-atom &self $Cl)) + (remove-symbol &self $Cl)) (= $T (= $H $_)) ($clause-internal $P $PI $H $Cl0 $Ref) (copy-term $Cl0 $T) ($erase $Ref) ($rehash-indexing $P $PI $Ref))) -; ;'$fast_write'([erase,Cl0,Ref]), nl, ;??? - +; (= - (remove-all-atoms &self $Head) + (remove-all-symbols &self $Head) ( ($head-to-term $Head $H (with_self $P $PI) - (remove-all-atoms &self $Head)) + (remove-all-symbols &self $Head)) ($new-internal-database $P) ($check-procedure-permission (with_self $P $PI) access static-procedure - (remove-all-atoms &self $Head)) + (remove-all-symbols &self $Head)) ($clause-internal $P $PI $H $Cl $Ref) (copy-term $Cl (= $H $_)) ($erase $Ref) ($rehash-indexing $P $PI $Ref) (fail))) -; ;'$fast_write'([erase,Cl,Ref]), nl, ;??? - +; (= - (retractall $_) True) + (retractall $_) True) +; + ; -; term --> clause (for assert) +; (= @@ -1210,56 +1682,78 @@ ( ($term-to-clause $Cl0 $Cl user $Pkg $Goal) (= $Cl (= $H $_)) - (functor $H $F $A))) + (functor $H $F $A))) +; + (= ($term-to-clause $Cl0 $_ $_ $_ $Goal) ( (var $Cl0) (set-det) - (illarg var $Goal 1))) + (illarg var $Goal 1))) +; + (= ($term-to-clause $_ $_ $Pkg0 $_ $Goal) ( (var $Pkg0) (set-det) - (illarg var $Goal 1))) + (illarg var $Goal 1))) +; + (= ($term-to-clause (with_self $P $Cl0) $Cl $_ $Pkg $Goal) - ( (set-det) ($term-to-clause $Cl0 $Cl $P $Pkg $Goal))) + ( (set-det) ($term-to-clause $Cl0 $Cl $P $Pkg $Goal))) +; + (= ($term-to-clause $_ $_ $Pkg0 $_ $Goal) ( (not (atom $Pkg0)) (set-det) (illarg - (type is-symbol) $Goal 1))) + (type is-symbol) $Goal 1))) +; + (= ($term-to-clause (= $H0 $B0) (= $H $B) $Pkg $Pkg $Goal) ( (set-det) ($term-to-head $H0 $H $Pkg $Goal) - ($term-to-body $B0 $B $Pkg $Goal))) + ($term-to-body $B0 $B $Pkg $Goal))) +; + (= ($term-to-clause $H0 (= $H True) $Pkg $Pkg $Goal) - ($term-to-head $H0 $H $Pkg $Goal)) + ($term-to-head $H0 $H $Pkg $Goal)) +; + (= ($term-to-head $H $H $_ $_) - ( (atom $H) (set-det))) + ( (atom $H) (set-det))) +; + (= ($term-to-head $H $H $_ $_) - ( (compound $H) (set-det))) + ( (compound $H) (set-det))) +; + (= ($term-to-head $_ $_ $_ $Goal) (illarg - (type callable) $Goal 1)) + (type callable) $Goal 1)) +; + (= ($term-to-body $B0 $B $Pkg $_) - ($localize-body $B0 $Pkg $B)) + ($localize-body $B0 $Pkg $B)) +; + (= @@ -1267,32 +1761,42 @@ ( (var $G) (set-det) ($localize-body - (call $G) $P $G1))) + (call $G) $P $G1))) +; + (= ($localize-body (with_self $P $G) $_ $G1) - ( (set-det) ($localize-body $G $P $G1))) + ( (set-det) ($localize-body $G $P $G1))) +; + (= ($localize-body (, $X $Y) $P (, $X1 $Y1)) ( (set-det) ($localize-body $X $P $X1) - ($localize-body $Y $P $Y1))) + ($localize-body $Y $P $Y1))) +; + (= ($localize-body (det-if-then $X $Y) $P (det-if-then $X1 $Y1)) ( (set-det) ($localize-body $X $P $X1) - ($localize-body $Y $P $Y1))) + ($localize-body $Y $P $Y1))) +; + (= ($localize-body (or $X $Y) $P (or $X1 $Y1)) ( (set-det) ($localize-body $X $P $X1) - ($localize-body $Y $P $Y1))) + ($localize-body $Y $P $Y1))) +; + (= ($localize-body $G $P $G1) ( (functor $G $F $A) @@ -1303,27 +1807,36 @@ ($localize-args $M $As $P $As1) (=.. $G1 (Cons $F $As1)))) -; ;??? - +; (= ($localize-body $G $P (call (with_self $P $G))) - ( (var $P) (set-det))) + ( (var $P) (set-det))) +; + (= ($localize-body $G user $G) - (set-det)) + (set-det)) +; + (= ($localize-body $G $_ $G) - ( (system-predicate $G) (set-det))) + ( (system-predicate $G) (set-det))) +; + (= - ($localize_body $G $P - (: $P $G)) True) + (%localize_body $G $P + (: $P $G)) True) +; + (= ($localize-args Nil Nil $_ Nil) - (set-det)) + (set-det)) +; + (= ($localize-args (Cons : $Ms) @@ -1332,54 +1845,80 @@ (with_self $P $A) $As1)) ( (or (var $A) - (with_self - (\= $A $_) $_)) + (\= $A + (with_self $_ $_))) (set-det) - ($localize-args $Ms $As $P $As1))) + ($localize-args $Ms $As $P $As1))) +; + (= ($localize-args (Cons $_ $Ms) (Cons $A $As) $P (Cons $A $As1)) - ($localize-args $Ms $As $P $As1)) + ($localize-args $Ms $As $P $As1)) +; + (= - ($builtin_meta_predicates ^ 2 - (? :)) True) + (%builtin_meta_predicates ^ 2 + (? :)) True) +; + (= - ($builtin_meta_predicates call 1 - (:)) True) + (%builtin_meta_predicates call 1 + (:)) True) +; + (= - ($builtin_meta_predicates once 1 - (:)) True) + (%builtin_meta_predicates once 1 + (:)) True) +; + (= - ($builtin_meta_predicates \+ 1 - (:)) True) + (%builtin_meta_predicates \+ 1 + (:)) True) +; + (= - ($builtin_meta_predicates findall 3 - (? : ?)) True) + (%builtin_meta_predicates findall 3 + (? : ?)) True) +; + (= - ($builtin_meta_predicates setof 3 - (? : ?)) True) + (%builtin_meta_predicates setof 3 + (? : ?)) True) +; + (= - ($builtin_meta_predicates bagof 3 - (? : ?)) True) + (%builtin_meta_predicates bagof 3 + (? : ?)) True) +; + (= - ($builtin_meta_predicates on_exception 3 - (? : :)) True) + (%builtin_meta_predicates on_exception 3 + (? : :)) True) +; + (= - ($builtin_meta_predicates catch 3 - (: ? :)) True) + (%builtin_meta_predicates catch 3 + (: ? :)) True) +; + (= - ($builtin_meta_predicates synchronized 2 - (? :)) True) + (%builtin_meta_predicates synchronized 2 + (? :)) True) +; + (= - ($builtin_meta_predicates freeze 2 - (? :)) True) + (%builtin_meta_predicates freeze 2 + (? :)) True) +; + ; -; clause --> term (for retract) +; (= @@ -1389,87 +1928,117 @@ ( ($clause-to-term $Cl $T user $Pkg $Goal) (= $T (= $H $_)) - (functor $H $F $A))) + (functor $H $F $A))) +; + (= ($clause-to-term $Cl $_ $_ $_ $Goal) ( (var $Cl) (set-det) - (illarg var $Goal 1))) + (illarg var $Goal 1))) +; + (= ($clause-to-term $_ $_ $Pkg $_ $Goal) ( (var $Pkg) (set-det) - (illarg var $Goal 1))) + (illarg var $Goal 1))) +; + (= ($clause-to-term (with_self $P $Cl) $T $_ $Pkg $Goal) - ( (set-det) ($clause-to-term $Cl $T $P $Pkg $Goal))) + ( (set-det) ($clause-to-term $Cl $T $P $Pkg $Goal))) +; + (= ($clause-to-term $_ $_ $Pkg $_ $Goal) ( (not (atom $Pkg)) (set-det) (illarg - (type is-symbol) $Goal 1))) + (type is-symbol) $Goal 1))) +; + (= ($clause-to-term (= $H0 $B) (= $H $B) $Pkg $Pkg $Goal) - ( (set-det) ($head-to-term $H0 $H $_ $Goal))) + ( (set-det) ($head-to-term $H0 $H $_ $Goal))) +; + ; -; '$body_to_term'(B0, B, Goal). +; (= ($clause-to-term $H0 (= $H True) $Pkg $Pkg $Goal) - ($head-to-term $H0 $H $_ $Goal)) + ($head-to-term $H0 $H $_ $Goal)) +; + ; -; term --> predicate indicator (for abolish) +; (= ($term-to-predicateindicator $T (with_self $Pkg $PI) $Goal) - ($term-to-predicateindicator $T $PI user $Pkg $Goal)) + ($term-to-predicateindicator $T $PI user $Pkg $Goal)) +; + (= ($term-to-predicateindicator $T $_ $_ $_ $Goal) ( (var $T) (set-det) - (illarg var $Goal 1))) + (illarg var $Goal 1))) +; + (= ($term-to-predicateindicator $_ $_ $Pkg $_ $Goal) ( (var $Pkg) (set-det) - (illarg var $Goal 1))) + (illarg var $Goal 1))) +; + (= ($term-to-predicateindicator (with_self $P $T) $PI $_ $Pkg $Goal) - ( (set-det) ($term-to-predicateindicator $T $PI $P $Pkg $Goal))) + ( (set-det) ($term-to-predicateindicator $T $PI $P $Pkg $Goal))) +; + (= ($term-to-predicateindicator $T $_ $_ $_ $Goal) ( (\= $T (/ $_ $_)) (set-det) (illarg - (type predicate-indicator) $Goal 1))) + (type predicate-indicator) $Goal 1))) +; + (= ($term-to-predicateindicator (/ $F $_) $_ $_ $_ $Goal) ( (not (atom $F)) (set-det) (illarg - (type is-symbol) $Goal 1))) + (type is-symbol) $Goal 1))) +; + (= ($term-to-predicateindicator (/ $_ $A) $_ $_ $_ $Goal) ( (not (integer $A)) (set-det) (illarg - (type integer) $Goal 1))) + (type integer) $Goal 1))) +; + (= - ($term_to_predicateindicator $T $T $Pkg $Pkg $_) True) + (%term_to_predicateindicator $T $T $Pkg $Pkg $_) True) +; + (= @@ -1477,8 +2046,7 @@ ( ($new-indexing-hash $P $PI $IH) ($gen-indexing-keys $Cl $IH $Keys) ($update-indexing-hash $A_or_Z $Keys $IH $Ref))) -; ;'$fast_write'([update_indexing,P,PI,Cl,Ref,Keys]), nl, ;??? - +; @@ -1486,27 +2054,37 @@ ($gen-indexing-keys (= $H $_) $_ (:: all)) - ( (atom $H) (set-det))) + ( (atom $H) (set-det))) +; + (= ($gen-indexing-keys (= $H $_) $IT $Keys) - ( (arg 1 $H $A1) ($gen-indexing-keys0 $A1 $IT $Keys))) + ( (arg 1 $H $A1) ($gen-indexing-keys0 $A1 $IT $Keys))) +; + (= ($gen-indexing-keys0 $A1 $IT $Keys) ( (var $A1) (set-det) - (hash-keys $IT $Keys))) + (hash-keys $IT $Keys))) +; + (= ($gen-indexing-keys0 $A1 $_ (:: all lis)) ( (= $A1 - (Cons $_ $_)) (set-det))) + (Cons $_ $_)) (set-det))) +; + (= ($gen-indexing-keys0 $A1 $_ (:: all str)) - ( (compound $A1) (set-det))) + ( (compound $A1) (set-det))) +; + (= ($gen-indexing-keys0 $A1 $IT (:: all $Key)) @@ -1518,48 +2096,65 @@ (, (hash-get $IT var $L) (hash-put $IT $Key $L))))) -; ; get the hash code of A1 - +; (= ($gen-indexing-keys0 $A1 $IT $Keys) (illarg (type term) - ($gen-indexing-keys0 $A1 $IT $Keys) 1)) + ($gen-indexing-keys0 $A1 $IT $Keys) 1)) +; + (= ($update-indexing-hash a $Keys $IH $Ref) - ( (set-det) ($hash-addz-all $Keys $IH $Ref))) + ( (set-det) ($hash-addz-all $Keys $IH $Ref))) +; + (= ($update-indexing-hash z $Keys $IH $Ref) - ( (set-det) ($hash-adda-all $Keys $IH $Ref))) + ( (set-det) ($hash-adda-all $Keys $IH $Ref))) +; + (= ($hash-adda-all Nil $_ $_) - (set-det)) + (set-det)) +; + (= ($hash-adda-all (Cons $K $Ks) $H $X) - ( ($hash-adda $H $K $X) ($hash-adda-all $Ks $H $X))) + ( ($hash-adda $H $K $X) ($hash-adda-all $Ks $H $X))) +; + (= ($hash-addz-all Nil $_ $_) - (set-det)) + (set-det)) +; + (= ($hash-addz-all (Cons $K $Ks) $H $X) - ( ($hash-addz $H $K $X) ($hash-addz-all $Ks $H $X))) + ( ($hash-addz $H $K $X) ($hash-addz-all $Ks $H $X))) +; + (= ($erase-all Nil) - (set-det)) + (set-det)) +; + (= ($erase-all (Cons $R $Rs)) - ( ($erase $R) ($erase-all $Rs))) + ( ($erase $R) ($erase-all $Rs))) +; + (= @@ -1567,35 +2162,44 @@ ( ($new-indexing-hash $P $PI $IH) (hash-keys $IH $Keys) ($remove-index-all $Keys $IH $Ref))) -; ;'$fast_write'([rehash_indexing,P,PI,Keys]), nl, ;??? - +; (= ($remove-index-all Nil $_ $_) - (set-det)) + (set-det)) +; + (= ($remove-index-all (Cons $K $Ks) $IH $Ref) - ( ($hash-remove-first $IH $K $Ref) ($remove-index-all $Ks $IH $Ref))) + ( ($hash-remove-first $IH $K $Ref) ($remove-index-all $Ks $IH $Ref))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; All solutions +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (/ findall 3)) - !(public (/ bagof 3)) - !(public (/ setof 3)) + !(public (/ findall 3)) +; + + !(public (/ bagof 3)) +; + + !(public (/ setof 3)) +; + ; -; findall/3 +; (= @@ -1603,12 +2207,16 @@ ( (callable $Goal) (set-det) (new-hash $H) - ($findall $H $Template $Goal $Instances))) + ($findall $H $Template $Goal $Instances))) +; + (= (findall $Template $Goal $Instances) (illarg (type callable) - (findall $Template $Goal $Instances) 2)) + (findall $Template $Goal $Instances) 2)) +; + (= @@ -1616,25 +2224,33 @@ ( (call $Goal) (copy-term $Template $CT) ($hash-addz $H %FINDALL $CT) - (fail))) + (fail))) +; + (= ($findall $H $_ $_ $Instances) - (hash-get $H %FINDALL $Instances)) + (hash-get $H %FINDALL $Instances)) +; + ; -; bagof/3 & setof/3 +; (= (bagof $Template $Goal $Instances) ( (callable $Goal) (set-det) - ($bagof $Template $Goal $Instances))) + ($bagof $Template $Goal $Instances))) +; + (= (bagof $Template $Goal $Instances) (illarg (type callable) - (bagof $Template $Goal $Instances) 2)) + (bagof $Template $Goal $Instances) 2)) +; + (= @@ -1642,12 +2258,16 @@ ( (callable $Goal) (set-det) ($bagof $Template $Goal $Instances0) - (sort $Instances0 $Instances))) + (sort $Instances0 $Instances))) +; + (= (setof $Template $Goal $Instances) (illarg (type callable) - (setof $Template $Goal $Instances) 2)) + (setof $Template $Goal $Instances) 2)) +; + (= @@ -1661,19 +2281,20 @@ (+ $Witness $Template) $Goal $S) ($bagof-instances $S $Witness $Instances0) (= $Instances $Instances0))) -; ;write('Goal = '), write(Goal), nl, - -; ;write('Free variables set = '), write(FV), nl, - +; (= ($bagof $Template $Goal $Instances) - ( (findall $Template $Goal $Instances) (\== $Instances Nil))) + ( (findall $Template $Goal $Instances) (\== $Instances Nil))) +; + (= - ($bagof_instances () $Witness $Instances) - (empty)) + (%bagof_instances () $Witness $Instances) + (empty)) +; + (= ($bagof-instances $S0 $Witness $Instances) ( (= $S0 @@ -1683,20 +2304,28 @@ ($bagof-instances0 $S_next $Witness $Instances (Cons (+ $W $T) $WT_list) - (Cons $T $T_list)))) + (Cons $T $T_list)))) +; + (= ($bagof-instances0 $_ $Witness $Instances $WT_list $T_list) - ( ($unify-witness $WT_list $Witness) (= $Instances $T_list))) + ( ($unify-witness $WT_list $Witness) (= $Instances $T_list))) +; + (= ($bagof-instances0 $S_next $Witness $Instances $_ $_) - ($bagof-instances $S_next $Witness $Instances)) + ($bagof-instances $S_next $Witness $Instances)) +; + (= ($variants-subset Nil $W Nil Nil Nil) - (set-det)) + (set-det)) +; + (= ($variants-subset (Cons @@ -1706,17 +2335,23 @@ (Cons $T0 $T_list) $S_next) ( ($term-variant $W $W0) (set-det) - ($variants-subset $S $W $WT_list $T_list $S_next))) + ($variants-subset $S $W $WT_list $T_list $S_next))) +; + (= ($variants-subset (Cons $WT $S) $W $WT_list $T_list (Cons $WT $S_next)) - ($variants-subset $S $W $WT_list $T_list $S_next)) + ($variants-subset $S $W $WT_list $T_list $S_next)) +; + (= ($term-variant $X $Y) - ( (new-hash $Hash) ($term-variant $X $Y $Hash))) + ( (new-hash $Hash) ($term-variant $X $Y $Hash))) +; + (= ($term-variant $X $Y $Hash) @@ -1729,143 +2364,184 @@ (== $Y $V)) (, (var $Y) - (hash-put $Hash $X $Y))))) + (hash-put $Hash $X $Y))))) +; + (= ($term-variant $X $Y $_) ( (ground $X) (set-det) - (== $X $Y))) + (== $X $Y))) +; + (= ($term-variant $_ $Y $_) ( (var $Y) (set-det) - (fail))) + (fail))) +; + (= ($term-variant (Cons $X $Xs) (Cons $Y $Ys) $Hash) ( (set-det) ($term-variant $X $Y $Hash) - ($term-variant $Xs $Ys $Hash))) + ($term-variant $Xs $Ys $Hash))) +; + (= ($term-variant $X $Y $Hash) ( (=.. $X $Xs) (=.. $Y $Ys) - ($term-variant $Xs $Ys $Hash))) + ($term-variant $Xs $Ys $Hash))) +; + (= ($unify-witness Nil $_) - (set-det)) + (set-det)) +; + (= ($unify-witness (Cons (+ $W $_) $WT_list) $W) - ($unify-witness $WT_list $W)) + ($unify-witness $WT_list $W)) +; + ; -; Variable set of a term +; (= ($variables-set $X $Vs) - ($variables-set $X Nil $Vs)) + ($variables-set $X Nil $Vs)) +; + (= ($variables-set $X $Vs $Vs) ( (var $X) ($builtin-memq $X $Vs) - (set-det))) + (set-det))) +; + (= ($variables-set $X $Vs (Cons $X $Vs)) - ( (var $X) (set-det))) + ( (var $X) (set-det))) +; + (= ($variables-set $X $Vs0 $Vs0) - ( (atomic $X) (set-det))) + ( (atomic $X) (set-det))) +; + (= ($variables-set (Cons $X $Xs) $Vs0 $Vs) ( (set-det) ($variables-set $X $Vs0 $Vs1) - ($variables-set $Xs $Vs1 $Vs))) + ($variables-set $Xs $Vs1 $Vs))) +; + (= ($variables-set $X $Vs0 $Vs) - ( (=.. $X $Xs) ($variables-set $Xs $Vs0 $Vs))) + ( (=.. $X $Xs) ($variables-set $Xs $Vs0 $Vs))) +; + (= ($builtin-memq $X (Cons $Y $_)) - ( (== $X $Y) (set-det))) + ( (== $X $Y) (set-det))) +; + (= ($builtin-memq $X (Cons $_ $Ys)) - ($builtin-memq $X $Ys)) + ($builtin-memq $X $Ys)) +; + ; -; Existential variables set of a term +; (= ($existential-variables-set $X $Vs) - ($existential-variables-set $X Nil $Vs)) + ($existential-variables-set $X Nil $Vs)) +; + (= ($existential-variables-set $X $Vs $Vs) - ( (var $X) (set-det))) + ( (var $X) (set-det))) +; + (= ($existential-variables-set $X $Vs $Vs) - ( (atomic $X) (set-det))) + ( (atomic $X) (set-det))) +; + (= ($existential-variables-set (with_self $_ $X) $Vs0 $Vs) - ( (set-det) ($existential-variables-set $X $Vs0 $Vs))) + ( (set-det) ($existential-variables-set $X $Vs0 $Vs))) +; + ; -; '$existential_variables_set'((X;Y), Vs0, Vs) :- !, +; ; -; '$existential_variables_set'(X, Vs0, Vs1), +; ; -; '$existential_variables_set'(Y, Vs1, Vs). +; ; -; '$existential_variables_set'((X->Y), Vs0, Vs) :- !, +; ; -; '$existential_variables_set'(X, Vs0, Vs1), +; ; -; '$existential_variables_set'(Y, Vs1, Vs). +; ; -; '$existential_variables_set'((X,Y), Vs0, Vs) :- !, +; ; -; '$existential_variables_set'(X, Vs0, Vs1), +; ; -; '$existential_variables_set'(Y, Vs1, Vs). +; (= ($existential-variables-set (^ $V $G) $Vs0 $Vs) ( (set-det) ($variables-set $V $Vs0 $Vs1) - ($existential-variables-set $G $Vs1 $Vs))) + ($existential-variables-set $G $Vs1 $Vs))) +; + (= ($existential-variables-set ($meta-call $G $_ $_ $_ $_) $Vs0 $Vs) ( (set-det) ($existential-variables-set $G $Vs0 $Vs))) -; ;??? - +; (= - ($existential_variables_set $_ $Vs $Vs) True) + (%existential_variables_set $_ $Vs $Vs) True) +; + ; -; Free variables set of a term +; (= @@ -1874,29 +2550,39 @@ ($variables-set $V $VV) ($existential-variables-set $T $VV $BV) ($builtin-set-diff $TV $BV $FV) - (set-det))) + (set-det))) +; + (= ($builtin-set-diff $L1 $L2 $L) ( (sort $L1 $SL1) (sort $L2 $SL2) - ($builtin-set-diff0 $SL1 $SL2 $L))) + ($builtin-set-diff0 $SL1 $SL2 $L))) +; + (= ($builtin-set-diff0 Nil $_ Nil) - (set-det)) + (set-det)) +; + (= ($builtin-set-diff0 $L1 Nil $L1) - (set-det)) + (set-det)) +; + (= ($builtin-set-diff0 (Cons $X $Xs) (Cons $Y $Ys) $L) ( (== $X $Y) (set-det) - ($builtin-set-diff0 $Xs $Ys $L))) + ($builtin-set-diff0 $Xs $Ys $L))) +; + (= ($builtin-set-diff0 (Cons $X $Xs) @@ -1905,7 +2591,9 @@ ( (@< $X $Y) (set-det) ($builtin-set-diff0 $Xs - (Cons $Y $Ys) $L))) + (Cons $Y $Ys) $L))) +; + (= ($builtin-set-diff0 (Cons $X $Xs) @@ -1913,72 +2601,94 @@ (Cons $Y $L)) ($builtin-set-diff0 (Cons $X $Xs) $Ys - (Cons $Y $L))) + (Cons $Y $L))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Stream selection and control +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; :- public current_input/1 (written in Java) +; ; -; :- public current_output/1 (written in Java) +; ; -; :- public set_input/1, set_output/1. (written in Java) +; ; -; :- public open/4 (written in Java) +; - !(public (/ open 3)) + !(public (/ open 3)) +; + ; -; :- public close/2 (written in Java) +; - !(public (/ close 1)) + !(public (/ close 1)) +; + ; -; :- public flush_output/1.(written in Java) +; - !(public (/ flush-output 0)) - !(public (/ stream-property 2)) + !(public (/ flush-output 0)) +; + + !(public (/ stream-property 2)) +; + (= (open $Source_sink $Mode $Stream) - (open $Source_sink $Mode $Stream Nil)) + (open $Source_sink $Mode $Stream Nil)) +; + (= (close $S_or_a) - (close $S_or_a Nil)) + (close $S_or_a Nil)) +; + (= (flush-output) - ( (current-output $S) (flush-output $S))) + ( (current-output $S) (flush-output $S))) +; + (= (stream-property $Stream $Stream_property) ( (var $Stream_property) (set-det) - ($stream-property $Stream $Stream_property))) + ($stream-property $Stream $Stream_property))) +; + (= (stream-property $Stream $Stream_property) ( ($stream-property-specifier $Stream_property) (set-det) - ($stream-property $Stream $Stream_property))) + ($stream-property $Stream $Stream_property))) +; + (= (stream-property $Stream $Stream_property) (illarg (domain term stream-property) - (stream-property $Stream $Stream_property) 2)) + (stream-property $Stream $Stream_property) 2)) +; + (= @@ -1990,352 +2700,464 @@ ($builtin-member (, $Stream $Vs) $Map) (java $Stream) - ($builtin-member $Stream_property $Vs))) + ($builtin-member $Stream_property $Vs))) +; + (= ($stream-property $Stream $Stream_property) ( (java $Stream) (set-det) ($get-stream-manager $SM) (hash-get $SM $Stream $Vs) - ($builtin-member $Stream_property $Vs))) + ($builtin-member $Stream_property $Vs))) +; + (= ($stream-property $Stream $Stream_property) (illarg (domain stream stream) - (stream-property $Stream $Stream_property) 1)) + (stream-property $Stream $Stream_property) 1)) +; + (= - ($stream_property_specifier input) True) + (%stream_property_specifier input) True) +; + (= - ($stream_property_specifier output) True) + (%stream_property_specifier output) True) +; + (= - ($stream_property_specifier - (alias $_)) True) + (%stream_property_specifier + (alias $_)) True) +; + (= - ($stream_property_specifier - (mode $_)) True) + (%stream_property_specifier + (mode $_)) True) +; + (= - ($stream_property_specifier - (type $_)) True) + (%stream_property_specifier + (type $_)) True) +; + (= - ($stream_property_specifier - (file_name $_)) True) + (%stream_property_specifier + (file_name $_)) True) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Character input/output +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; :- public get_char/2, get_code/2. (written in Java) +; ; -; :- public peek_char/2, peek_code/2. (written in Java) +; ; -; :- public put_char/2, put_code/2. (written in Java) +; ; -; :- public nl/0. (written in Java) +; - !(public (, (/ get-char 1) (/ get-code 1))) - !(public (, (/ peek-char 1) (/ peek-code 1))) - !(public (, (/ put-char 1) (/ put-code 1))) - !(public (/ nl 1)) + !(public (, (/ get-char 1) (/ get-code 1))) +; + + !(public (, (/ peek-char 1) (/ peek-code 1))) +; + + !(public (, (/ put-char 1) (/ put-code 1))) +; + + !(public (/ nl 1)) +; + (= (get-char $Char) - ( (current-input $S) (get-char $S $Char))) + ( (current-input $S) (get-char $S $Char))) +; + (= (get-code $Code) - ( (current-input $S) (get-code $S $Code))) + ( (current-input $S) (get-code $S $Code))) +; + (= (peek-char $Char) - ( (current-input $S) (peek-char $S $Char))) + ( (current-input $S) (peek-char $S $Char))) +; + (= (peek-code $Code) - ( (current-input $S) (peek-code $S $Code))) + ( (current-input $S) (peek-code $S $Code))) +; + (= (put-char $Char) - ( (current-output $S) (put-char $S $Char))) + ( (current-output $S) (put-char $S $Char))) +; + (= (put-code $Code) - ( (current-output $S) (put-code $S $Code))) + ( (current-output $S) (put-code $S $Code))) +; + (= (nl $S) (put-char $S -)) +)) +; + - !(public (, (/ get0 1) (/ get0 2))) - !(public (/ get 1)) + !(public (, (/ get0 1) (/ get0 2))) +; + + !(public (/ get 1)) +; + ; -; :- public get/2. (written in Java) +; - !(public (, (/ put 1) (/ put 2))) - !(public (/ tab 1)) + !(public (, (/ put 1) (/ put 2))) +; + + !(public (/ tab 1)) +; + ; -; :- public tab/2. (written in Java) +; - !(public (/ skip 1)) + !(public (/ skip 1)) +; + ; -; :- public skip/2. (written in Java) +; (= (get0 $Code) - ( (current-input $S) (get-code $S $Code))) + ( (current-input $S) (get-code $S $Code))) +; + (= (get0 $S_or_a $Code) - (get-code $S_or_a $Code)) + (get-code $S_or_a $Code)) +; + (= (get $Code) - ( (current-input $S) (get $S $Code))) + ( (current-input $S) (get $S $Code))) +; + (= (put $Exp) - ( (current-output $S) (put $S $Exp))) + ( (current-output $S) (put $S $Exp))) +; + (= (put $S_or_a $Exp) - ( (is $Code $Exp) (put-code $S_or_a $Code))) + ( (is $Code $Exp) (put-code $S_or_a $Code))) +; + (= (tab $N) - ( (current-output $S) (tab $S $N))) + ( (current-output $S) (tab $S $N))) +; + (= (skip $N) - ( (current-input $S) (skip $S $N))) + ( (current-input $S) (skip $S $N))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Byte input/output +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (, (/ get-byte 1) (/ peek-byte 1) (/ put-byte 1))) + !(public (, (/ get-byte 1) (/ peek-byte 1) (/ put-byte 1))) +; + ; -; :- public get_byte/2. ; written in java +; ; -; :- public peek_byte/2. ; written in java +; ; -; :- public put_byte/2. ; written in java +; (= (get-byte $Byte) - ( (current-input $S) (get-byte $S $Byte))) + ( (current-input $S) (get-byte $S $Byte))) +; + (= (peek-byte $Byte) - ( (current-input $S) (peek-byte $S $Byte))) + ( (current-input $S) (peek-byte $S $Byte))) +; + (= (put-byte $Byte) - ( (current-output $S) (put-byte $S $Byte))) + ( (current-output $S) (put-byte $S $Byte))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Term input/output (read) +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (, (/ read 1) (/ read 2))) - !(public (, (/ read-with-variables 2) (/ read-with-variables 3))) - !(public (/ read-line 1)) + !(public (, (/ read 1) (/ read 2))) +; + + !(public (, (/ read-with-variables 2) (/ read-with-variables 3))) +; + + !(public (/ read-line 1)) +; + ; -; :- public read_line/2. (written in Java) +; - !(dynamic (/ %tokens 1)) + !(dynamic (/ %tokens 1)) +; + (= (read $X) - ( (current-input $S) (read $S $X))) + ( (current-input $S) (read $S $X))) +; + (= (read $S_or_a $X) ( (read-tokens $S_or_a $Tokens $_) (parse-tokens $X $Tokens) - (set-det))) + (set-det))) +; + (= (read-with-variables $X $Vs) - ( (current-input $S) (read-with-variables $S $X $Vs))) + ( (current-input $S) (read-with-variables $S $X $Vs))) +; + (= (read-with-variables $S_or_a $X $Vs) ( (read-tokens $S_or_a $Tokens $Vs) (parse-tokens $X $Tokens) - (set-det))) + (set-det))) +; + (= (read-line $X) - ( (current-input $S) (read-line $S $X))) + ( (current-input $S) (read-line $S $X))) +; + ; -; read_token(S_or_a, Token) reads one token from the input, +; ; -; and unifies Token with: +; ; -; error(Atom), +; ; -; end_of_file, +; ; -; '.', ' ', '(', ')', '[', ']', '{', '}', ',', '|', +; ; -; number(Integer_or_Float), +; ; -; atom(Atom), +; ; -; var(Atom), +; ; -; string(CharCodeList) +; ; -; read_token(Token) :- current_input(S), read_token(S, Token). +; (= (read-token $S_or_a $Token) - ( ($read-token0 $S_or_a $Type $Token0) ($read-token1 (:: $Type) $Token0 $Token))) + ( ($read-token0 $S_or_a $Type $Token0) ($read-token1 (:: $Type) $Token0 $Token))) +; + (= ($read-token1 (:: -2) $T (error $T)) - (set-det)) ; -; error('message') + (set-det)) +; + ; +; (= ($read-token1 "I" $T (number $T)) - (set-det)) ; -; number(intvalue) + (set-det)) +; + ; +; (= ($read-token1 "L" $T (number $T)) - (set-det)) ; -; number(longvalue) + (set-det)) +; + ; +; (= ($read-token1 "D" $T (number $T)) - (set-det)) ; -; number(floatvalue) + (set-det)) +; + ; +; (= ($read-token1 "A" $T (atom $T)) - (set-det)) ; -; atom('name') + (set-det)) +; + ; +; (= ($read-token1 "V" $T (var $T)) - (set-det)) ; -; var('name') + (set-det)) +; + ; +; (= ($read-token1 "S" $T (string $T)) - (set-det)) ; -; string("chars") + (set-det)) +; + ; +; (= ($read-token1 $_ $T $T) - (set-det)) ; -; others + (set-det)) +; + ; +; ; -; read_tokens(Tokens, Vs) reads tokens from the input +; ; -; until full-stop-mark ('.') or end_of_file, +; ; -; unifies Tokens with a list of tokens. +; ; -; Token for a variable has a form of var(Name,Variable). +; ; -; Vs is a list of Name=Variable pairs. +; ; -; read_tokens(Tokens, Vs) :- +; ; -; current_input(Stream), +; ; -; '$read_tokens'(Stream, Tokens, Vs, []), +; ; -; !. +; (= (read-tokens $Stream $Tokens $Vs) - ( ($read-tokens $Stream $Tokens $Vs Nil) (set-det))) + ( ($read-tokens $Stream $Tokens $Vs Nil) (set-det))) +; + (= ($read-tokens $Stream $Tokens $Vs $VI) - ( (read-token $Stream $Token) ($read-tokens1 $Stream $Token $Tokens $Vs $VI))) + ( (read-token $Stream $Token) ($read-tokens1 $Stream $Token $Tokens $Vs $VI))) +; + (= @@ -2350,15 +3172,21 @@ (nl user-error) (flush-output user-error) ($read-tokens-until-fullstop $Stream) - (fail))) + (fail))) +; + (= ($read-tokens1 $Stream end-of-file (:: end-of-file .) Nil $_) - (set-det)) + (set-det)) +; + (= ($read-tokens1 $Stream . (:: .) Nil $_) - (set-det)) + (set-det)) +; + (= ($read-tokens1 $Stream (var -) @@ -2366,7 +3194,9 @@ (var - $V) $Tokens) (Cons (= - $V) $Vs) $VI0) - ( (set-det) ($read-tokens $Stream $Tokens $Vs (Cons (= - $V) $VI0)))) + ( (set-det) ($read-tokens $Stream $Tokens $Vs (Cons (= - $V) $VI0)))) +; + (= ($read-tokens1 $Stream (var $Name) @@ -2375,7 +3205,9 @@ ( ($mem-pair (= $Name $V) $VI) (set-det) - ($read-tokens $Stream $Tokens $Vs $VI))) + ($read-tokens $Stream $Tokens $Vs $VI))) +; + (= ($read-tokens1 $Stream (var $Name) @@ -2383,11 +3215,15 @@ (var $Name $V) $Tokens) (Cons (= $Name $V) $Vs) $VI0) - ( (set-det) ($read-tokens $Stream $Tokens $Vs (Cons (= $Name $V) $VI0)))) + ( (set-det) ($read-tokens $Stream $Tokens $Vs (Cons (= $Name $V) $VI0)))) +; + (= ($read-tokens1 $Stream $Token (Cons $Token $Tokens) $Vs $VI) - ($read-tokens $Stream $Tokens $Vs $VI)) + ($read-tokens $Stream $Tokens $Vs $VI)) +; + (= @@ -2397,528 +3233,683 @@ (= $X2 $V2) $_)) ( (== $X1 $X2) (set-det) - (= $V1 $V2))) + (= $V1 $V2))) +; + (= ($mem-pair $X (Cons $_ $L)) - ($mem-pair $X $L)) + ($mem-pair $X $L)) +; + ; -; '$mem_pair'(X, [_|L]) :- member(X, L). +; (= ($read-tokens-until-fullstop $Stream) - ( (read-token $Stream $Token) ($read-tokens-until-fullstop $Stream $Token))) + ( (read-token $Stream $Token) ($read-tokens-until-fullstop $Stream $Token))) +; + (= ($read-tokens-until-fullstop $Stream end-of-file) - (set-det)) + (set-det)) +; + (= ($read-tokens-until-fullstop $Stream .) - (set-det)) + (set-det)) +; + (= ($read-tokens-until-fullstop $Stream $_) - ( (read-token $Stream $Token) ($read-tokens-until-fullstop $Stream $Token))) + ( (read-token $Stream $Token) ($read-tokens-until-fullstop $Stream $Token))) +; + (= (parse-tokens $X $Tokens) - ( (remove-all-atoms &self + ( (remove-all-symbols &self ($tokens $_)) - (add-atom &self + (add-symbol &self ($tokens $Tokens)) ($parse-tokens $X 1201 $Tokens (:: .)) - (remove-atom &self + (remove-symbol &self ($tokens $Tokens)) - (set-det))) + (set-det))) +; + ; -; '$parse_tokens'(X, Prec) parses the input whose precedecence =< Prec. +; (= - (--> - ($parse_tokens $X $Prec0) - (, $parse_tokens_skip_spaces - (, - ($parse_tokens1 $Prec0 $X1 $Prec1) - (, ! - (, $parse_tokens_skip_spaces - (, - ($parse_tokens2 $Prec0 $X1 $Prec1 $X $Prec) !)))))) True) + (, + (--> + (%parse_tokens $X $Prec0) $parse_tokens_skip_spaces) + (, + (%parse_tokens1 $Prec0 $X1 $Prec1) + (, ! + (, $parse_tokens_skip_spaces + (, + (%parse_tokens2 $Prec0 $X1 $Prec1 $X $Prec) !))))) True) +; + (= - (--> - ($parse_tokens1 $Prec0 $X1 $Prec1) + (, + (--> + (%parse_tokens1 $Prec0 $X1 $Prec1) + (%parse_tokens_peep_next $Next)) (, - ($parse_tokens_peep_next $Next) - (, - { ($parse_tokens_is_starter $Next) } - (, ! - ($parse_tokens_before_op $Prec0 $X1 $Prec1))))) True) + { (%parse_tokens_is_starter $Next) } + (, ! + (%parse_tokens_before_op $Prec0 $X1 $Prec1)))) True) +; + (= - (--> - ($parse_tokens1 $_ $_ $_) - (, - ($parse_tokens_peep_next $Next) - ($parse_tokens_error - ($Next cannot start an expression)))) True) + (, + (--> + (%parse_tokens1 $_ $_ $_) + (%parse_tokens_peep_next $Next)) + (%parse_tokens_error + ($Next cannot start an expression))) True) +; + (= - (--> - ($parse_tokens2 $Prec0 $X $Prec $X $Prec) + (, + (--> + (%parse_tokens2 $Prec0 $X $Prec $X $Prec) + (%parse_tokens_peep_next $Next)) (, - ($parse_tokens_peep_next $Next) + { (%parse_tokens_is_terminator $Next) } (, - { ($parse_tokens_is_terminator $Next) } - (, - { (=< $Prec $Prec0) } !)))) True) + { (=< $Prec $Prec0) } !))) True) +; + (= - (--> - ($parse_tokens2 $Prec0 $X1 $Prec1 $X $Prec) + (, + (--> + (%parse_tokens2 $Prec0 $X1 $Prec1 $X $Prec) + (%parse_tokens_peep_next $Next)) (, - ($parse_tokens_peep_next $Next) - (, - { ($parse_tokens_is_post_in_op $Next) } - (, ! - ($parse_tokens_post_in_ops $Prec0 $X1 $Prec1 $X $Prec))))) True) + { (%parse_tokens_is_post_in_op $Next) } + (, ! + (%parse_tokens_post_in_ops $Prec0 $X1 $Prec1 $X $Prec)))) True) +; + + (= (--> - ($parse_tokens2 $_ $_ $_ $_ $_) - ($parse_tokens_error - (operator expected after expression))) True) + (%parse_tokens2 $_ $_ $_ $_ $_) + (%parse_tokens_error + (operator expected after expression))) True) +; + ; -; '$parse_tokens_before_op'(Prec0, X, Prec) +; ; -; parses the input until infix or postfix operator, +; ; -; and returns X and Prec +; + (= - (--> - ($parse_tokens_before_op $Prec0 $X $Prec) + (, + (--> + (%parse_tokens_before_op $Prec0 $X $Prec) + (' ')) + (, ! + (%parse_tokens_before_op $Prec0 $X $Prec))) True) +; + + (= + (, + (--> + (%parse_tokens_before_op $_ end_of_file 0) + (end_of_file)) !) True) +; + + (= + (, + (--> + (%parse_tokens_before_op $_ $N 0) + ( (number $N))) !) True) +; + + (= + (, + (--> + (%parse_tokens_before_op $_ $N 0) + ( (is-symbol -))) (, - (' ') + ( (number $N0)) (, ! - ($parse_tokens_before_op $Prec0 $X $Prec)))) True) + { (is $N + (- $N0)) }))) True) +; + (= - (--> - ($parse_tokens_before_op $_ end_of_file 0) - (, - (end_of_file) !)) True) + (, + (--> + (%parse_tokens_before_op $_ $V 0) + ( (var $_ $V))) !) True) +; + (= - (--> - ($parse_tokens_before_op $_ $N 0) - (, - ( (number $N)) !)) True) + (, + (--> + (%parse_tokens_before_op $_ $S 0) + ( (string $S))) !) True) +; + (= - (--> - ($parse_tokens_before_op $_ $N 0) - (, - ( (atom -)) + (, + (--> + (%parse_tokens_before_op $_ $X 0) + (()) + (, ! (, - ( (number $N0)) - (, ! - { (is $N - (- $N0)) })))) True) + (%parse_tokens $X 1201) + (%parse_tokens_expect ))))) True) +; + (= - (--> - ($parse_tokens_before_op $_ $V 0) - (, - ( (var $_ $V)) !)) True) + (, + (--> + (%parse_tokens_before_op $_ $X 0) + ({)) + (, ! + (, $parse_tokens_skip_spaces + (%parse_tokens_brace $X)))) True) +; + (= - (--> - ($parse_tokens_before_op $_ $S 0) - (, - ( (string $S)) !)) True) + (, + (--> + (%parse_tokens_before_op $_ $X 0) + ([)) + (, ! + (, $parse_tokens_skip_spaces + (%parse_tokens_list $X)))) True) +; + (= - (--> - ($parse_tokens_before_op $_ $X 0) + (, + (--> + (%parse_tokens_before_op $_ $X 0) + ( (is-symbol $F))) (, (() - (, ! - (, - ($parse_tokens $X 1201) - ($parse_tokens_expect )))))) True) - (= - (--> - ($parse_tokens_before_op $_ $X 0) - (, - ({) - (, ! - (, $parse_tokens_skip_spaces - ($parse_tokens_brace $X))))) True) - (= - (--> - ($parse_tokens_before_op $_ $X 0) - (, - ([) (, ! (, $parse_tokens_skip_spaces - ($parse_tokens_list $X))))) True) - (= - (--> - ($parse_tokens_before_op $_ $X 0) - (, - ( (atom $F)) - (, - (() - (, ! - (, $parse_tokens_skip_spaces - (, - ($parse_tokens_args $Args) - { (=.. $X - (Cons $F $Args)) })))))) True) + (, + (%parse_tokens_args $Args) + { (=.. $X + (Cons $F $Args)) }))))) True) +; + (= - (--> - ($parse_tokens_before_op $Prec0 $X $PrecOp) + (, + (--> + (%parse_tokens_before_op $Prec0 $X $PrecOp) + ( (is-symbol $F))) (, - ( (atom $F)) + { (current_op $PrecOp fx $F) } (, - { (current_op $PrecOp fx $F) } - (, - { (=< $PrecOp $Prec0) } - (, $parse_tokens_skip_spaces + { (=< $PrecOp $Prec0) } + (, $parse_tokens_skip_spaces + (, + (%parse_tokens_peep_next $Next) (, - ($parse_tokens_peep_next $Next) + { (%parse_tokens_is_starter $Next) } (, - { ($parse_tokens_is_starter $Next) } - (, - { (\+ - ($parse_tokens_is_post_in_op $Next)) } - (, ! + { (\+ + (%parse_tokens_is_post_in_op $Next)) } + (, ! + (, + { (is $Prec1 + (- $PrecOp 1)) } (, - { (is $Prec1 - (- $PrecOp 1)) } + (%parse_tokens $Arg $Prec1) (, - ($parse_tokens $Arg $Prec1) - (, - { (functor $X $F 1) } - { (arg 1 $X $Arg) })))))))))))) True) + { (functor $X $F 1) } + { (arg 1 $X $Arg) }))))))))))) True) +; + (= - (--> - ($parse_tokens_before_op $Prec0 $X $PrecOp) + (, + (--> + (%parse_tokens_before_op $Prec0 $X $PrecOp) + ( (is-symbol $F))) (, - ( (atom $F)) + { (current_op $PrecOp fy $F) } (, - { (current_op $PrecOp fy $F) } - (, - { (=< $PrecOp $Prec0) } - (, $parse_tokens_skip_spaces + { (=< $PrecOp $Prec0) } + (, $parse_tokens_skip_spaces + (, + (%parse_tokens_peep_next $Next) (, - ($parse_tokens_peep_next $Next) + { (%parse_tokens_is_starter $Next) } (, - { ($parse_tokens_is_starter $Next) } - (, - { (\+ - ($parse_tokens_is_post_in_op $Next)) } - (, ! + { (\+ + (%parse_tokens_is_post_in_op $Next)) } + (, ! + (, + (%parse_tokens $Arg $PrecOp) (, - ($parse_tokens $Arg $PrecOp) - (, - { (functor $X $F 1) } - { (arg 1 $X $Arg) }))))))))))) True) + { (functor $X $F 1) } + { (arg 1 $X $Arg) })))))))))) True) +; + + (= (--> - ($parse_tokens_before_op $_ $A 0) - ( (atom $A))) True) + (%parse_tokens_before_op $_ $A 0) + ( (is-symbol $A))) True) +; + + (= - (--> - ($parse_tokens_brace {}) - (, - (}) !)) True) + (, + (--> + (%parse_tokens_brace {}) + (})) !) True) +; + (= - (--> - ($parse_tokens_brace $X) + (, + (--> + (%parse_tokens_brace $X) + (%parse_tokens $X1 1201)) (, - ($parse_tokens $X1 1201) - (, - ($parse_tokens_expect }) - { (= $X - {$X1 }) }))) True) + (%parse_tokens_expect }) + { (= $X + {$X1 }) })) True) +; + (= - (--> - ($parse_tokens_list []) - (, - (]) !)) True) + (, + (--> + (%parse_tokens_list []) + (])) !) True) +; + (= - (--> - ($parse_tokens_list - (Cons $X $Xs)) - (, - ($parse_tokens $X 999) - (, $parse_tokens_skip_spaces - ($parse_tokens_list_rest $Xs)))) True) + (, + (--> + (%parse_tokens_list + (Cons $X $Xs)) + (%parse_tokens $X 999)) + (, $parse_tokens_skip_spaces + (%parse_tokens_list_rest $Xs))) True) +; + (= - (--> - ($parse_tokens_list_rest $Xs) - (, - (|) - (, ! - (, - ($parse_tokens $Xs 999) - ($parse_tokens_expect ]))))) True) + (, + (--> + (%parse_tokens_list_rest $Xs) + (|)) + (, ! + (, + (%parse_tokens $Xs 999) + (%parse_tokens_expect ])))) True) +; + (= - (--> - ($parse_tokens_list_rest - (Cons $X $Xs)) - (, - (,) - (, ! - (, - ($parse_tokens $X 999) - (, $parse_tokens_skip_spaces - ($parse_tokens_list_rest $Xs)))))) True) + (, + (--> + (%parse_tokens_list_rest + (Cons $X $Xs)) + (,)) + (, ! + (, + (%parse_tokens $X 999) + (, $parse_tokens_skip_spaces + (%parse_tokens_list_rest $Xs))))) True) +; + + (= (--> - ($parse_tokens_list_rest []) - ($parse_tokens_expect ])) True) + (%parse_tokens_list_rest []) + (%parse_tokens_expect ])) True) +; + + (= - (--> - ($parse_tokens_args []) - (, - ()) !)) True) + (, + (--> + (%parse_tokens_args []) + ())) !) True) +; + (= - (--> - ($parse_tokens_args - (Cons $X $Xs)) - (, - ($parse_tokens $X 999) - (, $parse_tokens_skip_spaces - ($parse_tokens_args_rest $Xs)))) True) + (, + (--> + (%parse_tokens_args + (Cons $X $Xs)) + (%parse_tokens $X 999)) + (, $parse_tokens_skip_spaces + (%parse_tokens_args_rest $Xs))) True) +; + (= - (--> - ($parse_tokens_args_rest - (Cons $X $Xs)) - (, - (,) - (, ! - (, - ($parse_tokens $X 999) - (, $parse_tokens_skip_spaces - ($parse_tokens_args_rest $Xs)))))) True) + (, + (--> + (%parse_tokens_args_rest + (Cons $X $Xs)) + (,)) + (, ! + (, + (%parse_tokens $X 999) + (, $parse_tokens_skip_spaces + (%parse_tokens_args_rest $Xs))))) True) +; + + (= (--> - ($parse_tokens_args_rest []) - ($parse_tokens_expect ))) True) + (%parse_tokens_args_rest []) + (%parse_tokens_expect ))) True) +; + ; -; '$parse_tokens_post_in_op'(Prec0, X1, Prec1, X, Prec) +; ; -; parses the input beginning from infix or postfix operator, +; ; -; and returns X and Prec +; + (= - (--> - ($parse_tokens_post_in_ops $Prec0 $X1 $Prec1 $X $Prec) - (, $parse_tokens_skip_spaces + (, + (--> + (%parse_tokens_post_in_ops $Prec0 $X1 $Prec1 $X $Prec) $parse_tokens_skip_spaces) + (, + ($Op) (, - ($Op) - (, - ($parse_tokens_op $Op $Prec0 $X1 $Prec1 $X2 $Prec2) - ($parse_tokens_post_in_ops $Prec0 $X2 $Prec2 $X $Prec))))) True) + (%parse_tokens_op $Op $Prec0 $X1 $Prec1 $X2 $Prec2) + (%parse_tokens_post_in_ops $Prec0 $X2 $Prec2 $X $Prec)))) True) +; + + (= (--> - ($parse_tokens_post_in_ops $Prec0 $X $Prec $X $Prec) - { (=< $Prec $Prec0) }) True) + (%parse_tokens_post_in_ops $Prec0 $X $Prec $X $Prec) + { (=< $Prec $Prec0) }) True) +; + + (= - (--> - ($parse_tokens_op , $Prec0 $X1 $Prec1 $X $PrecOp) - (, ! - ($parse_tokens_op - (atom ,) $Prec0 $X1 $Prec1 $X $PrecOp))) True) + (, + (--> + (%parse_tokens_op , $Prec0 $X1 $Prec1 $X $PrecOp) !) + (%parse_tokens_op + (is-symbol ,) $Prec0 $X1 $Prec1 $X $PrecOp)) True) +; + (= - (--> - ($parse_tokens_op | $Prec0 $X1 $Prec1 $X $PrecOp) - (, ! - ($parse_tokens_op - (atom ;) $Prec0 $X1 $Prec1 $X $PrecOp))) True) + (, + (--> + (%parse_tokens_op | $Prec0 $X1 $Prec1 $X $PrecOp) !) + (%parse_tokens_op + (is-symbol ;) $Prec0 $X1 $Prec1 $X $PrecOp)) True) +; + (= - (--> - ($parse_tokens_op - (atom $Op) $Prec0 $X1 $Prec1 $X $PrecOp) + (, + (--> + (%parse_tokens_op + (is-symbol $Op) $Prec0 $X1 $Prec1 $X $PrecOp) + { (current_op $PrecOp xf $Op) }) (, - { (current_op $PrecOp xf $Op) } + { (=< $PrecOp $Prec0) } (, - { (=< $PrecOp $Prec0) } + { (< $Prec1 $PrecOp) } (, - { (< $Prec1 $PrecOp) } - (, - { (functor $X $Op 1) } - { (arg 1 $X $X1) }))))) True) + { (functor $X $Op 1) } + { (arg 1 $X $X1) })))) True) +; + (= - (--> - ($parse_tokens_op - (atom $Op) $Prec0 $X1 $Prec1 $X $PrecOp) + (, + (--> + (%parse_tokens_op + (is-symbol $Op) $Prec0 $X1 $Prec1 $X $PrecOp) + { (current_op $PrecOp yf $Op) }) (, - { (current_op $PrecOp yf $Op) } + { (=< $PrecOp $Prec0) } (, - { (=< $PrecOp $Prec0) } + { (=< $Prec1 $PrecOp) } (, - { (=< $Prec1 $PrecOp) } - (, - { (functor $X $Op 1) } - { (arg 1 $X $X1) }))))) True) + { (functor $X $Op 1) } + { (arg 1 $X $X1) })))) True) +; + (= - (--> - ($parse_tokens_op - (atom $Op) $Prec0 $X1 $Prec1 $X $PrecOp) + (, + (--> + (%parse_tokens_op + (is-symbol $Op) $Prec0 $X1 $Prec1 $X $PrecOp) + { (current_op $PrecOp xfx $Op) }) (, - { (current_op $PrecOp xfx $Op) } + { (=< $PrecOp $Prec0) } (, - { (=< $PrecOp $Prec0) } + { (< $Prec1 $PrecOp) } (, - { (< $Prec1 $PrecOp) } + { (is $Prec2 + (- $PrecOp 1)) } (, - { (is $Prec2 - (- $PrecOp 1)) } - (, - ($parse_tokens $X2 $Prec2) - (, ! + (%parse_tokens $X2 $Prec2) + (, ! + (, + { (functor $X $Op 2) } (, - { (functor $X $Op 2) } - (, - { (arg 1 $X $X1) } - { (arg 2 $X $X2) }))))))))) True) + { (arg 1 $X $X1) } + { (arg 2 $X $X2) })))))))) True) +; + (= - (--> - ($parse_tokens_op - (atom $Op) $Prec0 $X1 $Prec1 $X $PrecOp) + (, + (--> + (%parse_tokens_op + (is-symbol $Op) $Prec0 $X1 $Prec1 $X $PrecOp) + { (current_op $PrecOp xfy $Op) }) (, - { (current_op $PrecOp xfy $Op) } + { (=< $PrecOp $Prec0) } (, - { (=< $PrecOp $Prec0) } + { (< $Prec1 $PrecOp) } (, - { (< $Prec1 $PrecOp) } + { (is $Prec2 $PrecOp) } (, - { (is $Prec2 $PrecOp) } - (, - ($parse_tokens $X2 $Prec2) - (, ! + (%parse_tokens $X2 $Prec2) + (, ! + (, + { (functor $X $Op 2) } (, - { (functor $X $Op 2) } - (, - { (arg 1 $X $X1) } - { (arg 2 $X $X2) }))))))))) True) + { (arg 1 $X $X1) } + { (arg 2 $X $X2) })))))))) True) +; + (= - (--> - ($parse_tokens_op - (atom $Op) $Prec0 $X1 $Prec1 $X $PrecOp) + (, + (--> + (%parse_tokens_op + (is-symbol $Op) $Prec0 $X1 $Prec1 $X $PrecOp) + { (current_op $PrecOp yfx $Op) }) (, - { (current_op $PrecOp yfx $Op) } + { (=< $PrecOp $Prec0) } (, - { (=< $PrecOp $Prec0) } + { (=< $Prec1 $PrecOp) } (, - { (=< $Prec1 $PrecOp) } + { (is $Prec2 + (- $PrecOp 1)) } (, - { (is $Prec2 - (- $PrecOp 1)) } - (, - ($parse_tokens $X2 $Prec2) - (, ! + (%parse_tokens $X2 $Prec2) + (, ! + (, + { (functor $X $Op 2) } (, - { (functor $X $Op 2) } - (, - { (arg 1 $X $X1) } - { (arg 2 $X $X2) }))))))))) True) + { (arg 1 $X $X1) } + { (arg 2 $X $X2) })))))))) True) +; + (= - ($parse_tokens_is_starter end_of_file) True) + (%parse_tokens_is_starter end_of_file) True) +; + (= - ($parse_tokens_is_starter () True) + (%parse_tokens_is_starter () True) +; + (= - ($parse_tokens_is_starter [) True) + (%parse_tokens_is_starter [) True) +; + (= - ($parse_tokens_is_starter {) True) + (%parse_tokens_is_starter {) True) +; + (= - ($parse_tokens_is_starter - (number $_)) True) + (%parse_tokens_is_starter + (number $_)) True) +; + (= - ($parse_tokens_is_starter - (atom $_)) True) + (%parse_tokens_is_starter + (is-symbol $_)) True) +; + (= - ($parse_tokens_is_starter - (var $_ $_)) True) + (%parse_tokens_is_starter + (var $_ $_)) True) +; + (= - ($parse_tokens_is_starter - (string $_)) True) + (%parse_tokens_is_starter + (string $_)) True) +; + (= - ($parse_tokens_is_terminator )) True) + (%parse_tokens_is_terminator )) True) +; + (= - ($parse_tokens_is_terminator ]) True) + (%parse_tokens_is_terminator ]) True) +; + (= - ($parse_tokens_is_terminator }) True) + (%parse_tokens_is_terminator }) True) +; + (= - ($parse_tokens_is_terminator .) True) + (%parse_tokens_is_terminator .) True) +; + (= ($parse-tokens-is-post-in-op ,) - (set-det)) + (set-det)) +; + (= ($parse-tokens-is-post-in-op |) - (set-det)) + (set-det)) +; + (= ($parse-tokens-is-post-in-op (atom $Op)) ( (current-op $_ $Type $Op) ($parse-tokens-post-in-type $Type) - (set-det))) + (set-det))) +; + (= - ($parse_tokens_post_in_type xfx) True) + (%parse_tokens_post_in_type xfx) True) +; + (= - ($parse_tokens_post_in_type xfy) True) + (%parse_tokens_post_in_type xfy) True) +; + (= - ($parse_tokens_post_in_type yfx) True) + (%parse_tokens_post_in_type yfx) True) +; + (= - ($parse_tokens_post_in_type xf) True) + (%parse_tokens_post_in_type xf) True) +; + (= - ($parse_tokens_post_in_type yf) True) + (%parse_tokens_post_in_type yf) True) +; + (= - (--> - ($parse_tokens_expect $Token) - (, $parse_tokens_skip_spaces - (, - ($Token) !))) True) + (, + (--> + (%parse_tokens_expect $Token) $parse_tokens_skip_spaces) + (, + ($Token) !)) True) +; + + (= (--> - ($parse_tokens_expect $Token) - ($parse_tokens_error - ($Token expected))) True) + (%parse_tokens_expect $Token) + (%parse_tokens_error + ($Token expected))) True) +; + + (= - (--> $parse_tokens_skip_spaces - (, - (' ') - (, ! $parse_tokens_skip_spaces))) True) + (, + (--> $parse_tokens_skip_spaces + (' ')) + (, ! $parse_tokens_skip_spaces)) True) +; + + (= - (--> $parse_tokens_skip_spaces ()) True) + (--> $parse_tokens_skip_spaces ()) True) +; + (= ($parse-tokens-peep-next $Next $S $S) (= $S - (Cons $Next $_))) + (Cons $Next $_))) +; + (= @@ -2930,17 +3921,21 @@ (write user-error **) (nl user-error) ($parse-tokens-error1 Nil $S0) - (get-atoms &self + (get-symbols &self (= ($tokens $Tokens) $_)) ($parse-tokens-error1 $Tokens $S0) (flush-output user-error) - (fail))) + (fail))) +; + (= ($parse-tokens-error1 Nil $_) - (set-det)) + (set-det)) +; + (= ($parse-tokens-error1 $Tokens $S0) ( (== $Tokens $S0) @@ -2949,35 +3944,51 @@ (write user-error '** here **') (nl user-error) ($parse-tokens-error1 $Tokens Nil) - (nl user-error))) + (nl user-error))) +; + (= ($parse-tokens-error1 (Cons $Token $Tokens) $S0) - ( ($parse-tokens-error2 $Token) ($parse-tokens-error1 $Tokens $S0))) + ( ($parse-tokens-error2 $Token) ($parse-tokens-error1 $Tokens $S0))) +; + (= ($parse-tokens-error2 (number $X)) - ( (set-det) (write $X))) + ( (set-det) (write $X))) +; + (= ($parse-tokens-error2 (atom $X)) - ( (set-det) (writeq $X))) + ( (set-det) (writeq $X))) +; + (= ($parse-tokens-error2 (var $X $_)) - ( (set-det) (write $X))) + ( (set-det) (write $X))) +; + (= ($parse-tokens-error2 (string $X)) ( (set-det) (write user-error ") ($parse-tokens-write-string user-error $X) - (write user-error "))) + (write user-error "))) +; + (= ($parse-tokens-error2 $X) - (write user-error $X)) + (write user-error $X)) +; + (= - ($parse_tokens_write_string $_ ()) True) + (%parse_tokens_write_string $_ ()) True) +; + (= ($parse-tokens-write-string $S (Cons $C $Cs)) @@ -2986,86 +3997,122 @@ (set-det) (put-code $S $C) (put-code $S $C) - ($parse-tokens-write-string $S $Cs))) + ($parse-tokens-write-string $S $Cs))) +; + (= ($parse-tokens-write-string $S (Cons $C $Cs)) - ( (put-code $S $C) ($parse-tokens-write-string $S $Cs))) + ( (put-code $S $C) ($parse-tokens-write-string $S $Cs))) +; + (= - ($parse_tokens_write_message $_ ()) True) + (%parse_tokens_write_message $_ ()) True) +; + (= ($parse-tokens-write-message $S (Cons $X $Xs)) ( (write $S $X) (write $S ' ') - ($parse-tokens-write-message $S $Xs))) + ($parse-tokens-write-message $S $Xs))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Term input/output (write) +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (, (/ write 1) (/ write 2))) - !(public (, (/ writeq 1) (/ writeq 2))) - !(public (, (/ write-canonical 1) (/ write-canonical 2))) - !(public (, (/ write-term 2) (/ write-term 3))) + !(public (, (/ write 1) (/ write 2))) +; + + !(public (, (/ writeq 1) (/ writeq 2))) +; + + !(public (, (/ write-canonical 1) (/ write-canonical 2))) +; + + !(public (, (/ write-term 2) (/ write-term 3))) +; + (= (write $Term) - ( (current-output $S) (write-term $S $Term (:: (numbervars True))))) + ( (current-output $S) (write-term $S $Term (:: (numbervars True))))) +; + (= (write $S_or_a $Term) (write-term $S_or_a $Term - (:: (numbervars True)))) + (:: (numbervars True)))) +; + (= (writeq $Term) - ( (current-output $S) (write-term $S $Term (:: (quoted True) (numbervars True))))) + ( (current-output $S) (write-term $S $Term (:: (quoted True) (numbervars True))))) +; + (= (writeq $S_or_a $Term) (write-term $S_or_a $Term (:: (quoted True) - (numbervars True)))) + (numbervars True)))) +; + (= (write-canonical $Term) - ( (current-output $S) (write-term $S $Term (:: (quoted True) (ignore-ops True))))) + ( (current-output $S) (write-term $S $Term (:: (quoted True) (ignore-ops True))))) +; + (= (write-canonical $S_or_a $Term) (write-term $S_or_a $Term (:: (quoted True) - (ignore-ops True)))) + (ignore-ops True)))) +; + (= (write-term $Term $Options) - ( (current-output $S) (write-term $S $Term $Options))) + ( (current-output $S) (write-term $S $Term $Options))) +; + (= (write-term $S_or_a $Term $Options) - ( ($write-term $S_or_a $Term $Options) (fail))) + ( ($write-term $S_or_a $Term $Options) (fail))) +; + (= - (write_term $_ $_ $_) True) + (write_term $_ $_ $_) True) +; + (= ($write-term $S_or_a $Term $Options) - ( ($write-term0 $Term 1200 punct $_ $Options $S_or_a) (set-det))) + ( ($write-term0 $Term 1200 punct $_ $Options $S_or_a) (set-det))) +; + (= @@ -3073,13 +4120,17 @@ ( (var $Term) (set-det) ($write-space-if-needed $Type0 alpha $S_or_a) - ($fast-write $S_or_a $Term))) + ($fast-write $S_or_a $Term))) +; + (= ($write-term0 $Term $Prec $Type0 alpha $_ $S_or_a) ( (java $Term) (set-det) ($write-space-if-needed $Type0 alpha $S_or_a) - ($fast-write $S_or_a $Term))) + ($fast-write $S_or_a $Term))) +; + (= ($write-term0 $Term $Prec $Type0 alpha $Style $S_or_a) ( (= $Term $VN) @@ -3089,61 +4140,71 @@ (numbervars True) $Style) (set-det) ($write-space-if-needed $Type0 alpha $S_or_a) - ($write-VAR $VN $S_or_a))) + ($write-VAR $VN $S_or_a))) +; + (= ($write-term0 $Term $Prec $Type0 alpha $_ $S_or_a) ( (number $Term) (< $Term 0) (set-det) ($write-space-if-needed $Type0 symbol $S_or_a) - ($fast-write $S_or_a $Term))) + ($fast-write $S_or_a $Term))) +; + (= ($write-term0 $Term $Prec $Type0 alpha $_ $S_or_a) ( (number $Term) (set-det) ($write-space-if-needed $Type0 alpha $S_or_a) - ($fast-write $S_or_a $Term))) + ($fast-write $S_or_a $Term))) +; + ; -; '$write_term0'(Term, Prec, Type0, punct, _, S_or_a) :- +; ; -; atom(Term), +; ; -; current_op(PrecOp, OpType, Term), +; ; -; (OpType = fx ; OpType = fy), +; ; -; PrecOp =< Prec, +; ; -; !, +; ; -; '$write_space_if_needed'(Type0, punct, S_or_a), +; ; -; put_char(S_or_a, '('), +; ; -; '$write_atom'(Term, punct, _, _, S_or_a), +; ; -; put_char(S_or_a, ')'). +; (= ($write-term0 $Term $Prec $Type0 $Type $Style $S_or_a) ( (atom $Term) (set-det) - ($write-atom $Term $Type0 $Type $Style $S_or_a))) + ($write-atom $Term $Type0 $Type $Style $S_or_a))) +; + (= ($write-term0 $Term $Prec $Type0 $Type $Style $S_or_a) ( (not ($builtin-member (ignore-ops True) $Style)) ($write-is-operator $Term $Op $Args $OpType) (set-det) - ($write-term-op $Op $OpType $Args $Prec $Type0 $Type $Style $S_or_a))) + ($write-term-op $Op $OpType $Args $Prec $Type0 $Type $Style $S_or_a))) +; + (= ($write-term0 $Term $Prec $Type0 punct $Style $S_or_a) ( (= $Term @@ -3153,7 +4214,9 @@ ($write-space-if-needed $Type0 punct $S_or_a) (put-char $S_or_a [) ($write-term-list-args $Term punct $_ $Style $S_or_a) - (put-char $S_or_a ]))) + (put-char $S_or_a ]))) +; + (= ($write-term0 $Term $Prec $Type0 $Type $Style $S_or_a) ( (= $Term @@ -3163,7 +4226,9 @@ ($write-space-if-needed $Type0 punct $S_or_a) (put-char $S_or_a {) ($write-term0 $Term1 1200 punct $_ $Style $S_or_a) - (put-char $S_or_a }))) + (put-char $S_or_a }))) +; + (= ($write-term0 $Term $Prec $Type0 punct $Style $S_or_a) ( (=.. $Term @@ -3171,20 +4236,30 @@ ($write-atom $F $Type0 $_ $Style $S_or_a) (put-char $S_or_a () ($write-term-args $Args punct $_ $Style $S_or_a) - (put-char $S_or_a )))) + (put-char $S_or_a )))) +; + (= ($write-space-if-needed punct $_ $_) - (set-det)) + (set-det)) +; + (= ($write-space-if-needed $X $X $S_or_a) - ( (set-det) (put-char $S_or_a ' '))) + ( (set-det) (put-char $S_or_a ' '))) +; + (= ($write-space-if-needed other alpha $S_or_a) - ( (set-det) (put-char $S_or_a ' '))) + ( (set-det) (put-char $S_or_a ' '))) +; + (= - ($write_space_if_needed $_ $_ $_) True) + (%write_space_if_needed $_ $_ $_) True) +; + (= @@ -3194,7 +4269,9 @@ (is $Letter (+ (mod $VN 26) "A")) - (put-code $S_or_a $Letter))) + (put-code $S_or_a $Letter))) +; + (= ($write-VAR $VN $S_or_a) ( (is $Letter @@ -3203,7 +4280,9 @@ (put-code $S_or_a $Letter) (is $Rest (// $VN 26)) - ($fast-write $S_or_a $Rest))) + ($fast-write $S_or_a $Rest))) +; + (= @@ -3213,26 +4292,38 @@ (set-det) ($atom-type $Atom $Type) ($write-space-if-needed $Type0 $Type $S_or_a) - ($fast-writeq $S_or_a $Atom))) + ($fast-writeq $S_or_a $Atom))) +; + (= ($write-atom $Atom $Type0 $Type $_ $S_or_a) ( ($atom-type $Atom $Type) ($write-space-if-needed $Type0 $Type $S_or_a) - ($fast-write $S_or_a $Atom))) + ($fast-write $S_or_a $Atom))) +; + (= ($atom-type $X alpha) - ( ($atom-type0 $X 0) (set-det))) + ( ($atom-type0 $X 0) (set-det))) +; + (= ($atom-type $X symbol) - ( ($atom-type0 $X 1) (set-det))) + ( ($atom-type0 $X 1) (set-det))) +; + (= ($atom-type $X punct) - ( ($atom-type0 $X 2) (set-det))) + ( ($atom-type0 $X 2) (set-det))) +; + (= ($atom-type $X other) - ( ($atom-type0 $X 3) (set-det))) + ( ($atom-type0 $X 3) (set-det))) +; + (= @@ -3242,23 +4333,39 @@ (current-op $_ $OpType $Op) (=.. $Term (Cons $_ $Args)) - (set-det))) + (set-det))) +; + (= - ($write_op_type 1 fx) True) + (%write_op_type 1 fx) True) +; + (= - ($write_op_type 1 fy) True) + (%write_op_type 1 fy) True) +; + (= - ($write_op_type 1 xf) True) + (%write_op_type 1 xf) True) +; + (= - ($write_op_type 1 yf) True) + (%write_op_type 1 yf) True) +; + (= - ($write_op_type 2 xfx) True) + (%write_op_type 2 xfx) True) +; + (= - ($write_op_type 2 xfy) True) + (%write_op_type 2 xfy) True) +; + (= - ($write_op_type 2 yfx) True) + (%write_op_type 2 yfx) True) +; + (= @@ -3269,10 +4376,14 @@ ($write-space-if-needed $Type0 punct $S_or_a) (put-char $S_or_a () ($write-term-op1 $Op $OpType $Args $PrecOp punct $_ $Style $S_or_a) - (put-char $S_or_a )))) + (put-char $S_or_a )))) +; + (= ($write-term-op $Op $OpType $Args $Prec $Type0 $Type $Style $S_or_a) - ( (current-op $PrecOp $OpType $Op) ($write-term-op1 $Op $OpType $Args $PrecOp $Type0 $Type $Style $S_or_a))) + ( (current-op $PrecOp $OpType $Op) ($write-term-op1 $Op $OpType $Args $PrecOp $Type0 $Type $Style $S_or_a))) +; + (= @@ -3282,14 +4393,18 @@ ($write-atom $Op $Type0 $Type1 $Style $S_or_a) (is $Prec1 (- $PrecOp 1)) - ($write-term0 $A1 $Prec1 $Type1 $Type $Style $S_or_a))) + ($write-term0 $A1 $Prec1 $Type1 $Type $Style $S_or_a))) +; + (= ($write-term-op1 $Op fy (:: $A1) $PrecOp $Type0 $Type $Style $S_or_a) ( (set-det) ($write-atom $Op $Type0 $Type1 $Style $S_or_a) (is $Prec1 $PrecOp) - ($write-term0 $A1 $Prec1 $Type1 $Type $Style $S_or_a))) + ($write-term0 $A1 $Prec1 $Type1 $Type $Style $S_or_a))) +; + (= ($write-term-op1 $Op xf (:: $A1) $PrecOp $Type0 $Type $Style $S_or_a) @@ -3297,14 +4412,18 @@ (is $Prec1 (- $PrecOp 1)) ($write-term0 $A1 $Prec1 $Type0 $Type1 $Style $S_or_a) - ($write-atom $Op $Type1 $Type $Style $S_or_a))) + ($write-atom $Op $Type1 $Type $Style $S_or_a))) +; + (= ($write-term-op1 $Op yf (:: $A1) $PrecOp $Type0 $Type $Style $S_or_a) ( (set-det) (is $Prec1 $PrecOp) ($write-term0 $A1 $Prec1 $Type0 $Type1 $Style $S_or_a) - ($write-atom $Op $Type1 $Type $Style $S_or_a))) + ($write-atom $Op $Type1 $Type $Style $S_or_a))) +; + (= ($write-term-op1 $Op xfx (:: $A1 $A2) $PrecOp $Type0 $Type $Style $S_or_a) @@ -3315,7 +4434,9 @@ (- $PrecOp 1)) ($write-term0 $A1 $Prec1 $Type0 $Type1 $Style $S_or_a) ($write-term-infix-op $Op $Type1 $Type2 $Style $S_or_a) - ($write-term0 $A2 $Prec2 $Type2 $Type $Style $S_or_a))) + ($write-term0 $A2 $Prec2 $Type2 $Type $Style $S_or_a))) +; + (= ($write-term-op1 $Op xfy (:: $A1 $A2) $PrecOp $Type0 $Type $Style $S_or_a) @@ -3325,7 +4446,9 @@ (is $Prec2 $PrecOp) ($write-term0 $A1 $Prec1 $Type0 $Type1 $Style $S_or_a) ($write-term-infix-op $Op $Type1 $Type2 $Style $S_or_a) - ($write-term0 $A2 $Prec2 $Type2 $Type $Style $S_or_a))) + ($write-term0 $A2 $Prec2 $Type2 $Type $Style $S_or_a))) +; + (= ($write-term-op1 $Op yfx (:: $A1 $A2) $PrecOp $Type0 $Type $Style $S_or_a) @@ -3335,17 +4458,23 @@ (- $PrecOp 1)) ($write-term0 $A1 $Prec1 $Type0 $Type1 $Style $S_or_a) ($write-term-infix-op $Op $Type1 $Type2 $Style $S_or_a) - ($write-term0 $A2 $Prec2 $Type2 $Type $Style $S_or_a))) + ($write-term0 $A2 $Prec2 $Type2 $Type $Style $S_or_a))) +; + (= ($write-term-infix-op , $Type0 punct $_ $S_or_a) ( (set-det) ($write-space-if-needed $Type0 punct $S_or_a) - (put-char $S_or_a ,))) + (put-char $S_or_a ,))) +; + (= ($write-term-infix-op $Op $Type0 $Type $Style $S_or_a) - ($write-atom $Op $Type0 $Type $Style $S_or_a)) + ($write-atom $Op $Type0 $Type $Style $S_or_a)) +; + (= @@ -3358,7 +4487,9 @@ ($write-term0 $A 999 $Type0 $Type1 $Style $S_or_a) ($write-space-if-needed $Type1 punct $S_or_a) (put-char $S_or_a ,) - ($write-term-list-args $As punct $Type $Style $S_or_a))) + ($write-term-list-args $As punct $Type $Style $S_or_a))) +; + (= ($write-term-list-args @@ -3366,7 +4497,9 @@ ( (nonvar $As) (= $As Nil) (set-det) - ($write-term0 $A 999 $Type0 $Type $Style $S_or_a))) + ($write-term0 $A 999 $Type0 $Type $Style $S_or_a))) +; + (= ($write-term-list-args @@ -3374,16 +4507,22 @@ ( ($write-term0 $A 999 $Type0 $Type1 $Style $S_or_a) ($write-space-if-needed $Type1 punct $S_or_a) (put-char $S_or_a |) - ($write-term0 $As 999 punct $Type $Style $S_or_a))) + ($write-term0 $As 999 punct $Type $Style $S_or_a))) +; + (= ($write-term-args Nil $Type $Type $_ $_) - (set-det)) + (set-det)) +; + (= ($write-term-args (:: $A) $Type0 $Type $Style $S_or_a) - ( (set-det) ($write-term0 $A 999 $Type0 $Type $Style $S_or_a))) + ( (set-det) ($write-term0 $A 999 $Type0 $Type $Style $S_or_a))) +; + (= ($write-term-args (Cons $A $As) $Type0 $Type $Style $S_or_a) @@ -3391,21 +4530,29 @@ ($write-term0 $A 999 $Type0 $Type1 $Style $S_or_a) ($write-space-if-needed $Type1 punct $S_or_a) (put-char $S_or_a ,) - ($write-term-args $As punct $Type $Style $S_or_a))) + ($write-term-args $As punct $Type $Style $S_or_a))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Term input/output (others) +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (/ op 3)) - !(public (/ current-op 3)) - !(dynamic (/ %current-operator 3)) + !(public (/ op 3)) +; + + !(public (/ current-op 3)) +; + + !(dynamic (/ %current-operator 3)) +; + (= @@ -3414,13 +4561,17 @@ (=< 0 $Priority) (=< $Priority 1200) (set-det) - ($op1 $Priority $Op_specifier $Operator))) + ($op1 $Priority $Op_specifier $Operator))) +; + (= (op $Priority $Op_specifier $Operator) (illarg (domain integer (- 0 1200)) - (op $Priority $Op_specifier $Operator) 1)) + (op $Priority $Op_specifier $Operator) 1)) +; + (= @@ -3428,11 +4579,15 @@ ( (nonvar $Op_specifier) ($op-specifier $Op_specifier $_) (set-det) - ($op2 $Priority $Op_specifier $Operator))) + ($op2 $Priority $Op_specifier $Operator))) +; + (= ($op1 $Priority $Op_specifier $Operator) ( (findall $X - ($op-specifier $X $_) $Domain) (illarg (domain term $Domain) (op $Priority $Op_specifier $Operator) 2))) + ($op-specifier $X $_) $Domain) (illarg (domain term $Domain) (op $Priority $Op_specifier $Operator) 2))) +; + (= @@ -3440,277 +4595,457 @@ ( (atom $Operator) (set-det) ($add-operators - (:: $Operator) $Priority $Op_specifier))) + (:: $Operator) $Priority $Op_specifier))) +; + (= ($op2 $Priority $Op_specifier $Operator) ( ($op-atom-list $Operator $Atoms) (set-det) - ($add-operators $Atoms $Priority $Op_specifier))) + ($add-operators $Atoms $Priority $Op_specifier))) +; + (= ($op2 $Priority $Op_specifier $Operator) (illarg (type (list is-symbol)) - (op $Priority $Op_specifier $Operator) 3)) + (op $Priority $Op_specifier $Operator) 3)) +; + (= ($add-operators Nil $_ $_) - (set-det)) + (set-det)) +; + (= ($add-operators (Cons $A $As) $Priority $Op_specifier) - ( ($add-op $A $Priority $Op_specifier) ($add-operators $As $Priority $Op_specifier))) + ( ($add-op $A $Priority $Op_specifier) ($add-operators $As $Priority $Op_specifier))) +; + (= ($add-op , $Priority $Op_specifier) - ( (set-det) (illarg (permission modify operator , $_) (op $Priority $Op_specifier ,) 3))) + ( (set-det) (illarg (permission modify operator , $_) (op $Priority $Op_specifier ,) 3))) +; + (= ($add-op $A $_ $Op_specifier) - ( (get-atoms &self + ( (get-symbols &self (= - ($current_operator $_ $Op_specifier0 $A) $_)) + (%current_operator $_ $Op_specifier0 $A) $_)) ($op-specifier $Op_specifier $Class) ($op-specifier $Op_specifier0 $Class0) (= $Class $Class0) - (remove-atom &self - ($current_operator $_ $Op_specifier0 $A)) - (fail))) + (remove-symbol &self + (%current_operator $_ $Op_specifier0 $A)) + (fail))) +; + (= ($add-op $_ 0 $_) - (set-det)) + (set-det)) +; + (= ($add-op $A $Priority $Op_specifier) - (add-atom &self - ($current_operator $Priority $Op_specifier $A))) + (add-symbol &self + (%current_operator $Priority $Op_specifier $A))) +; + (= - ($op_specifier fx prefix) True) + (%op_specifier fx prefix) True) +; + (= - ($op_specifier fy prefix) True) + (%op_specifier fy prefix) True) +; + (= - ($op_specifier xfx infix) True) + (%op_specifier xfx infix) True) +; + (= - ($op_specifier xfy infix) True) + (%op_specifier xfy infix) True) +; + (= - ($op_specifier yfx infix) True) + (%op_specifier yfx infix) True) +; + (= - ($op_specifier xf postfix) True) + (%op_specifier xf postfix) True) +; + (= - ($op_specifier yf postfix) True) + (%op_specifier yf postfix) True) +; + (= ($op-atom-list $X $_) ( (var $X) (set-det) - (fail))) + (fail))) +; + (= ($op-atom-list Nil Nil) - (set-det)) + (set-det)) +; + (= ($op-atom-list (Cons $X $Xs) (Cons $X $As)) ( (atom $X) (set-det) - ($op-atom-list $Xs $As))) + ($op-atom-list $Xs $As))) +; + (= (current-op $Priority $Op_specifier $Operator) - (get-atoms &self + (get-symbols &self (= - ($current_operator $Priority $Op_specifier $Operator) $_))) + (%current_operator $Priority $Op_specifier $Operator) $_))) +; + (= - ($current_operator 1200 xfx :-) True) + (%current_operator 1200 xfx :-) True) +; + (= - ($current_operator 1200 xfx -->) True) + (%current_operator 1200 xfx -->) True) +; + (= - ($current_operator 1200 fx :-) True) + (%current_operator 1200 fx :-) True) +; + (= - ($current_operator 1200 fx ?-) True) + (%current_operator 1200 fx ?-) True) +; + (= - ($current_operator 1150 fx package) True) + (%current_operator 1150 fx package) True) +; + (= - ($current_operator 1150 fx import) True) + (%current_operator 1150 fx import) True) +; + (= - ($current_operator 1150 fx include) True) + (%current_operator 1150 fx include) True) +; + (= - ($current_operator 1150 fx include_resource) True) + (%current_operator 1150 fx include_resource) True) +; + (= - ($current_operator 1150 fx constant) True) + (%current_operator 1150 fx constant) True) +; + (= - ($current_operator 1150 fx public) True) + (%current_operator 1150 fx public) True) +; + (= - ($current_operator 1150 fx dynamic) True) + (%current_operator 1150 fx dynamic) True) +; + (= - ($current_operator 1150 fx meta_predicate) True) + (%current_operator 1150 fx meta_predicate) True) +; + (= - ($current_operator 1150 fx mode) True) + (%current_operator 1150 fx mode) True) +; + (= - ($current_operator 1150 fx multifile) True) + (%current_operator 1150 fx multifile) True) +; + (= - ($current_operator 1150 fx block) True) + (%current_operator 1150 fx block) True) +; + (= - ($current_operator 1150 fx ifdef) True) + (%current_operator 1150 fx ifdef) True) +; + (= - ($current_operator 1150 fx ifndef) True) + (%current_operator 1150 fx ifndef) True) +; + (= - ($current_operator 1150 fx domain) True) + (%current_operator 1150 fx domain) True) +; + (= - ($current_operator 1150 fx database) True) + (%current_operator 1150 fx database) True) +; + (= - ($current_operator 1100 xfy ;) True) + (%current_operator 1100 xfy ;) True) +; + (= - ($current_operator 1050 xfy ->) True) + (%current_operator 1050 xfy ->) True) +; + (= - ($current_operator 1000 xfy ,) True) + (%current_operator 1000 xfy ,) True) +; + (= - ($current_operator 900 fy \+) True) + (%current_operator 900 fy \+) True) +; + (= - ($current_operator 700 xfx =) True) + (%current_operator 700 xfx =) True) +; + (= - ($current_operator 700 xfx \=) True) + (%current_operator 700 xfx \=) True) +; + (= - ($current_operator 700 xfx ==) True) + (%current_operator 700 xfx ==) True) +; + (= - ($current_operator 700 xfx \==) True) + (%current_operator 700 xfx \==) True) +; + (= - ($current_operator 700 xfx @<) True) + (%current_operator 700 xfx @<) True) +; + (= - ($current_operator 700 xfx @>) True) + (%current_operator 700 xfx @>) True) +; + (= - ($current_operator 700 xfx @=<) True) + (%current_operator 700 xfx @=<) True) +; + (= - ($current_operator 700 xfx @>=) True) + (%current_operator 700 xfx @>=) True) +; + (= - ($current_operator 700 xfx =..) True) + (%current_operator 700 xfx =..) True) +; + (= - ($current_operator 700 xfx is) True) + (%current_operator 700 xfx is) True) +; + (= - ($current_operator 700 xfx =:=) True) + (%current_operator 700 xfx =:=) True) +; + (= - ($current_operator 700 xfx =\=) True) + (%current_operator 700 xfx =\=) True) +; + (= - ($current_operator 700 xfx <) True) + (%current_operator 700 xfx <) True) +; + (= - ($current_operator 700 xfx >) True) + (%current_operator 700 xfx >) True) +; + (= - ($current_operator 700 xfx =<) True) + (%current_operator 700 xfx =<) True) +; + (= - ($current_operator 700 xfx >=) True) + (%current_operator 700 xfx >=) True) +; + (= - ($current_operator 550 xfy :) True) + (%current_operator 550 xfy :) True) +; + (= - ($current_operator 500 yfx +) True) + (%current_operator 500 yfx +) True) +; + (= - ($current_operator 500 yfx -) True) + (%current_operator 500 yfx -) True) +; + (= - ($current_operator 500 yfx #) True) + (%current_operator 500 yfx #) True) +; + (= - ($current_operator 500 yfx /\) True) + (%current_operator 500 yfx /\) True) +; + (= - ($current_operator 500 yfx \/) True) + (%current_operator 500 yfx \/) True) +; + (= - ($current_operator 500 fx +) True) + (%current_operator 500 fx +) True) +; + (= - ($current_operator 400 yfx *) True) + (%current_operator 400 yfx *) True) +; + (= - ($current_operator 400 yfx /) True) + (%current_operator 400 yfx /) True) +; + (= - ($current_operator 400 yfx //) True) + (%current_operator 400 yfx //) True) +; + (= - ($current_operator 400 yfx mod) True) + (%current_operator 400 yfx mod) True) +; + (= - ($current_operator 400 yfx rem) True) + (%current_operator 400 yfx rem) True) +; + (= - ($current_operator 400 yfx <<) True) + (%current_operator 400 yfx <<) True) +; + (= - ($current_operator 400 yfx >>) True) + (%current_operator 400 yfx >>) True) +; + (= - ($current_operator 300 xfx ~) True) + (%current_operator 300 xfx ~) True) +; + (= - ($current_operator 200 xfx **) True) + (%current_operator 200 xfx **) True) +; + (= - ($current_operator 200 xfy ^) True) + (%current_operator 200 xfy ^) True) +; + (= - ($current_operator 200 fy \) True) + (%current_operator 200 fy \) True) +; + (= - ($current_operator 200 fy -) True) + (%current_operator 200 fy -) True) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Logic and control +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (/ \+ 1)) - !(public (/ once 1)) - !(public (/ repeat 0)) + !(public (/ \+ 1)) +; + + !(public (/ once 1)) +; + + !(public (/ repeat 0)) +; + (= (not $G) ( (call $G) (set-det) - (fail))) + (fail))) +; + (= - (\+ $_) True) + (\+ $_) True) +; + - (= repeat True) + (= repeat True) +; + (= (repeat) - (repeat)) + (repeat)) +; + (= (once $G) - ( (call $G) (set-det))) + ( (call $G) (set-det))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Atomic term processing +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; :- public atom_length/2. written in Java +; ; -; :- public atom_concat/3. written in Java +; - !(public (/ sub-symbol 5)) + !(public (/ sub-symbol 5)) +; + ; -; :- public atom_chars/2, atom_codes/2. written in Java +; ; -; :- public char_code/2. written in Java +; ; -; :- public number_chars/2, number_codes/2. written in Java +; - !(public (/ name 2)) + !(public (/ name 2)) +; + ; -; :- public regex_compile/2. written in Java +; ; -; :- public regex_match/3. written in Java +; - !(public (/ regex-matches 3)) - !(public (/ regex-matches 2)) + !(public (/ regex-matches 3)) +; + + !(public (/ regex-matches 2)) +; + (= @@ -3719,58 +5054,80 @@ (atom-length $AtomL $Before) (atom-concat $Sub_atom $AtomR $X) (atom-length $Sub_atom $Length) - (atom-length $AtomR $After))) + (atom-length $AtomR $After))) +; + (= (name $Constant $Chars) - ( (nonvar $Constant) (det-if-then-else (number $Constant) (number-codes $Constant $Chars) (det-if-then-else (atomic $Constant) (atom-codes $Constant $Chars) (illarg (type symbolic) (name $Constant $Chars) 1))))) + ( (nonvar $Constant) (det-if-then-else (number $Constant) (number-codes $Constant $Chars) (det-if-then-else (atomic $Constant) (atom-codes $Constant $Chars) (illarg (type symbolic) (name $Constant $Chars) 1))))) +; + (= (name $Constant $Chars) - ( (var $Constant) (det-if-then-else (number-codes $Constant0 $Chars) (= $Constant $Constant0) (det-if-then-else (atom-codes $Constant0 $Chars) (= $Constant $Constant0) (illarg (type (list char)) (name $Constant $Chars) 2))))) + ( (var $Constant) (det-if-then-else (number-codes $Constant0 $Chars) (= $Constant $Constant0) (det-if-then-else (atom-codes $Constant0 $Chars) (= $Constant $Constant0) (illarg (type (list char)) (name $Constant $Chars) 2))))) +; + (= (regex-matches $_ Nil $_) - ( (set-det) (fail))) + ( (set-det) (fail))) +; + (= (regex-matches $Pattern $List $Result) ( (= $List (Cons $_ $_)) (set-det) - (regex-list $Pattern $List $Result))) + (regex-list $Pattern $List $Result))) +; + (= (regex-matches $Pattern $String $Result) ( (atom $String) (regex-compile $Pattern $Matcher) - (regex-match $Matcher $String $Result))) + (regex-match $Matcher $String $Result))) +; + (= (regex-matches $Pattern $String) - (once (regex-matches $Pattern $String $_))) + (once (regex-matches $Pattern $String $_))) +; + (= (regex-list $Pattern (Cons $H $_) $Result) - (regex-matches $Pattern $H $Result)) + (regex-matches $Pattern $H $Result)) +; + (= (regex-list $Pattern (Cons $_ $Ls) $Result) - (regex-list $Pattern $Ls $Result)) + (regex-list $Pattern $Ls $Result)) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Implementation defined hooks +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (/ set-prolog-flag 2)) - !(public (/ current-prolog-flag 2)) + !(public (/ set-prolog-flag 2)) +; + + !(public (/ current-prolog-flag 2)) +; + (= @@ -3778,23 +5135,31 @@ ( (var $Flag) (set-det) (illarg var - (set-prolog-flag $Flag $Value) 1))) + (set-prolog-flag $Flag $Value) 1))) +; + (= (set-prolog-flag $Flag $Value) ( (var $Value) (set-det) (illarg var - (set-prolog-flag $Flag $Value) 2))) + (set-prolog-flag $Flag $Value) 2))) +; + (= (set-prolog-flag $Flag $Value) ( (atom $Flag) (set-det) - ($set-prolog-flag0 $Flag $Value))) + ($set-prolog-flag0 $Flag $Value))) +; + (= (set-prolog-flag $Flag $Value) (illarg (type is-symbol) - (set-prolog-flag $Flag $Value) 1)) + (set-prolog-flag $Flag $Value) 1)) +; + (= @@ -3802,26 +5167,36 @@ ( ($prolog-impl-flag $Flag $Mode (changeable $YN)) (set-det) - ($set-prolog-flag0 $YN $Flag $Value $Mode))) + ($set-prolog-flag0 $YN $Flag $Value $Mode))) +; + (= ($set-prolog-flag0 $Flag $Value) (illarg (domain is-symbol prolog-flag) - (set-prolog-flag $Flag $Value) 1)) + (set-prolog-flag $Flag $Value) 1)) +; + (= ($set-prolog-flag0 no $Flag $Value $_) - ( (set-det) (illarg (permission modify flag $Flag $_) (set-prolog-flag $Flag $Value) $_))) + ( (set-det) (illarg (permission modify flag $Flag $_) (set-prolog-flag $Flag $Value) $_))) +; + (= ($set-prolog-flag0 $_ $Flag $Value $Mode) ( ($builtin-member $Value $Mode) (set-det) - ($set-prolog-impl-flag $Flag $Value))) + ($set-prolog-impl-flag $Flag $Value))) +; + (= ($set-prolog-flag0 $_ $Flag $Value $_) (illarg (domain is-symbol flag-value) - (set-prolog-flag $Flag $Value) 2)) + (set-prolog-flag $Flag $Value) 2)) +; + (= @@ -3829,7 +5204,9 @@ ( (var $Flag) (set-det) ($prolog-impl-flag $Flag $_ $_) - ($get-prolog-impl-flag $Flag $Term))) + ($get-prolog-impl-flag $Flag $Term))) +; + (= (current-prolog-flag $Flag $Term) ( (atom $Flag) @@ -3839,99 +5216,137 @@ ($get-prolog-impl-flag $Flag $Term) (illarg (domain is-symbol prolog-flag) - (current-prolog-flag $Flag $Term) 1)))) + (current-prolog-flag $Flag $Term) 1)))) +; + (= (current-prolog-flag $Flag $Term) (illarg (type is-symbol) - (current-prolog-flag $Flag $Term) 1)) + (current-prolog-flag $Flag $Term) 1)) +; + ; -; '$MeTTa_impl_flag'(bounded, _, changeable(no)). +; (= - ($prolog_impl_flag max_integer $_ - (changeable no)) True) + (%prolog_impl_flag max_integer $_ + (changeable no)) True) +; + (= - ($prolog_impl_flag min_integer $_ - (changeable no)) True) + (%prolog_impl_flag min_integer $_ + (changeable no)) True) +; + ; -; '$MeTTa_impl_flag'(integer_rounding_function, [down,toward_zero], changeable(no)). +; ; -; '$MeTTa_impl_flag'(char_conversion, [on,off], changeable(no)). +; (= - ($prolog_impl_flag debug + (%prolog_impl_flag debug (on off) - (changeable yes)) True) + (changeable yes)) True) +; + (= - ($prolog_impl_flag max_arity $_ - (changeable no)) True) + (%prolog_impl_flag max_arity $_ + (changeable no)) True) +; + (= - ($prolog_impl_flag unknown + (%prolog_impl_flag unknown (error fail warning) - (changeable yes)) True) + (changeable yes)) True) +; + (= - ($prolog_impl_flag double_quotes + (%prolog_impl_flag double_quotes (chars codes atom) - (changeable no)) True) + (changeable no)) True) +; + (= - ($prolog_impl_flag print_stack_trace + (%prolog_impl_flag print_stack_trace (on off) - (changeable yes)) True) + (changeable yes)) True) +; + - !(public (/ halt 0)) - !(public (/ abort 0)) + !(public (/ halt 0)) +; + + !(public (/ abort 0)) +; + (= (halt) - (halt 0)) + (halt 0)) +; + (= (abort) - (raise-exception 'Execution aborted')) + (raise-exception 'Execution aborted')) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; DCG +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (, (/ C 3) (/ expand-term 2))) + !(public (, (/ C 3) (/ expand-term 2))) +; + (= (C - (Cons $X $S) $X $S) True) + (Cons $X $S) $X $S) True) +; + (= (expand-term $Dcg $Cl) ( (var $Dcg) (set-det) - (= $Dcg $Cl))) + (= $Dcg $Cl))) +; + (= (expand-term $Dcg $Cl) ( ($dcg-expansion $Dcg $Cl0) (set-det) - (= $Cl0 $Cl))) + (= $Cl0 $Cl))) +; + (= - (expand_term $Dcg $Dcg) True) + (expand_term $Dcg $Dcg) True) +; + (= ($dcg-expansion $Dcg $Cl) ( (var $Dcg) (set-det) - (= $Dcg $Cl))) + (= $Dcg $Cl))) +; + (= ($dcg-expansion (--> $Head $B) @@ -3945,23 +5360,31 @@ (set-det) ($dcg-translation-atom $H $H1 $S0 $S1) ($dcg-translation $B $G1 $S0 $S) - ($dcg-translation $List $G2 $S1 $S))) + ($dcg-translation $List $G2 $S1 $S))) +; + (= ($dcg-expansion (--> $H $B) (= $H1 $B1)) - ( ($dcg-translation-atom $H $H1 $S0 $S) ($dcg-translation $B $B1 $S0 $S))) + ( ($dcg-translation-atom $H $H1 $S0 $S) ($dcg-translation $B $B1 $S0 $S))) +; + (= ($dcg-translation-atom $X (phrase $X $S0 $S) $S0 $S) - ( (var $X) (set-det))) + ( (var $X) (set-det))) +; + (= ($dcg-translation-atom (with_self $M $X) (with_self $M $X1) $S0 $S) - ( (set-det) ($dcg-translation-atom $X $X1 $S0 $S))) + ( (set-det) ($dcg-translation-atom $X $X1 $S0 $S))) +; + (= ($dcg-translation-atom $X $X1 $S0 $S) ( (=.. $X @@ -3969,192 +5392,264 @@ ($builtin-append $As (:: $S0 $S) $As1) (=.. $X1 - (Cons $F $As1)))) + (Cons $F $As1)))) +; + (= ($dcg-translation $X $Y $S0 $S) - ( ($dcg-trans $X $Y0 $T $S0 $S) ($dcg-trans0 $Y0 $Y $T $S0 $S))) + ( ($dcg-trans $X $Y0 $T $S0 $S) ($dcg-trans0 $Y0 $Y $T $S0 $S))) +; + (= ($dcg-trans0 $Y $Y $T $S0 $T) - ( (\== $T $S0) (set-det))) + ( (\== $T $S0) (set-det))) +; + (= ($dcg-trans0 $Y0 $Y $T $_ $S) ($dcg-concat $Y0 - (= $S $T) $Y)) + (= $S $T) $Y)) +; + (= ($dcg-concat $X $Y $Z) ( (== $X True) (set-det) - (= $Z $Y))) + (= $Z $Y))) +; + (= ($dcg-concat $X $Y $Z) ( (== $Y True) (set-det) - (= $Z $X))) + (= $Z $X))) +; + (= - ($dcg_concat $X $Y - (, $X $Y)) True) + (%dcg_concat $X $Y + (, $X $Y)) True) +; + (= ($dcg-trans $X $X1 $S $S0 $S) ( (var $X) (set-det) - ($dcg-translation-atom $X $X1 $S0 $S))) + ($dcg-translation-atom $X $X1 $S0 $S))) +; + (= ($dcg-trans (with_self $M $X) (with_self $M $Y) $T $S0 $S) - ( (set-det) ($dcg-trans $X $Y $T $S0 $S))) + ( (set-det) ($dcg-trans $X $Y $T $S0 $S))) +; + (= ($dcg-trans Nil True $S0 $S0 $_) - (set-det)) + (set-det)) +; + (= ($dcg-trans (Cons $X $Y) $Z $T $S0 $S) ( (set-det) ($dcg-trans $Y $Y1 $T $S1 $S) ($dcg-concat - (C $S0 $X $S1) $Y1 $Z))) + (C $S0 $X $S1) $Y1 $Z))) +; + (= ($dcg-trans (not $X) (det-if-then-else $X1 fail (= $S $S0)) $S $S0 $S) - ( (set-det) ($dcg-trans $X $X1 $S1 $S0 $S1))) + ( (set-det) ($dcg-trans $X $X1 $S1 $S0 $S1))) +; + (= ($dcg-trans (, $X $Y) $Z $T $S0 $S) ( (set-det) ($dcg-trans $X $X1 $S1 $S0 $S1) ($dcg-trans $Y $Y1 $T $S1 $S) - ($dcg-concat $X1 $Y1 $Z))) + ($dcg-concat $X1 $Y1 $Z))) +; + (= ($dcg-trans (det-if-then $X $Y) (det-if-then $X1 $Y1) $T $S0 $S) ( (set-det) ($dcg-trans $X $X1 $S1 $S0 $S1) - ($dcg-trans $Y $Y1 $T $S1 $S))) + ($dcg-trans $Y $Y1 $T $S1 $S))) +; + (= ($dcg-trans (or $X $Y) (or $X1 $Y1) $S $S0 $S) ( (set-det) ($dcg-translation $X $X1 $S0 $S) - ($dcg-translation $Y $Y1 $S0 $S))) + ($dcg-translation $Y $Y1 $S0 $S))) +; + (= ($dcg-trans (set-det) (set-det) $S0 $S0 $_) - (set-det)) + (set-det)) +; + (= ($dcg-trans {$G } (call $G) $S0 $S0 $_) - ( (var $G) (set-det))) + ( (var $G) (set-det))) +; + (= ($dcg-trans {$G } $G $S0 $S0 $_) - (set-det)) + (set-det)) +; + (= ($dcg-trans $X $X1 $S $S0 $S) - ($dcg-translation-atom $X $X1 $S0 $S)) + ($dcg-translation-atom $X $X1 $S0 $S)) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Hash creation and control +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (/ new-hash 1)) - !(public (/ hash-map 2)) - !(public (/ hash-exists 1)) + !(public (/ new-hash 1)) +; + + !(public (/ hash-map 2)) +; + + !(public (/ hash-exists 1)) +; + (= (new-hash $Hash) - (new-hash $Hash Nil)) + (new-hash $Hash Nil)) +; + (= (hash-map $H_or_a $List) ( (hash-keys $H_or_a $Ks0) (sort $Ks0 $Ks) - (hash-map $Ks $List $H_or_a))) + (hash-map $Ks $List $H_or_a))) +; + (= (hash-map Nil Nil $_) - (set-det)) + (set-det)) +; + (= (hash-map (Cons $K $Ks) (Cons (, $K $V) $Ls) $H_or_a) - ( (hash-get $H_or_a $K $V) (hash-map $Ks $Ls $H_or_a))) + ( (hash-get $H_or_a $K $V) (hash-map $Ks $Ls $H_or_a))) +; + (= (hash-exists $Alias) ( (atom $Alias) ($get-hash-manager $HM) - (hash-contains-key $HM $Alias))) + (hash-contains-key $HM $Alias))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Java interoperation +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; :- public java_constructor0/2. (written in Java) +; ; -; :- public java_declared_constructor0/2. (written in Java) +; ; -; :- public java_method0/3. (written in Java) +; ; -; :- public java_declared_method0/3. (written in Java) +; ; -; :- public java_get_field0/3. (written in Java) +; ; -; :- public java_get_declared_field0/3. (written in Java) +; ; -; :- public java_set_field0/3. (written in Java) +; ; -; :- public java_set_declared_field0/3. (written in Java) +; ; -; :- public java_conversion/2. (written in Java) +; - !(public (/ java-constructor 2)) - !(public (/ java-declared-constructor 2)) - !(public (/ java-method 3)) - !(public (/ java-declared-method 3)) - !(public (/ java-get-field 3)) - !(public (/ java-get-declared-field 3)) - !(public (/ java-set-field 3)) - !(public (/ java-set-declared-field 3)) - !(public (/ synchronized 2)) + !(public (/ java-constructor 2)) +; + + !(public (/ java-declared-constructor 2)) +; + + !(public (/ java-method 3)) +; + + !(public (/ java-declared-method 3)) +; + + !(public (/ java-get-field 3)) +; + + !(public (/ java-get-declared-field 3)) +; + + !(public (/ java-set-field 3)) +; + + !(public (/ java-set-declared-field 3)) +; + + !(public (/ synchronized 2)) +; + (= @@ -4165,7 +5660,9 @@ (=.. $Constr1 (Cons $F $As1)) (java-constructor0 $Constr1 $Instance1) - (= $Instance $Instance1))) + (= $Instance $Instance1))) +; + (= @@ -4176,7 +5673,9 @@ (=.. $Constr1 (Cons $F $As1)) (java-declared-constructor0 $Constr1 $Instance1) - (= $Instance $Instance1))) + (= $Instance $Instance1))) +; + (= @@ -4188,7 +5687,9 @@ (Cons $F $As1)) (java-method0 $Class_or_Instance $Method1 $Value1) (java-conversion $Value2 $Value1) - (= $Value $Value2))) + (= $Value $Value2))) +; + (= @@ -4200,93 +5701,165 @@ (Cons $F $As1)) (java-declared-method0 $Class_or_Instance $Method1 $Value1) (java-conversion $Value2 $Value1) - (= $Value $Value2))) + (= $Value $Value2))) +; + (= (java-get-field $Class_or_Instance $Field $Value) ( (java-get-field0 $Class_or_Instance $Field $Value1) (java-conversion $Value2 $Value1) - (= $Value $Value2))) + (= $Value $Value2))) +; + (= (java-get-declared-field $Class_or_Instance $Field $Value) ( (java-get-declared-field0 $Class_or_Instance $Field $Value1) (java-conversion $Value2 $Value1) - (= $Value $Value2))) + (= $Value $Value2))) +; + (= (java-set-field $Class_or_Instance $Field $Value) - ( (java-conversion $Value $Value1) (java-set-field0 $Class_or_Instance $Field $Value1))) + ( (java-conversion $Value $Value1) (java-set-field0 $Class_or_Instance $Field $Value1))) +; + (= (java-set-declared-field $Class_or_Instance $Field $Value) - ( (java-conversion $Value $Value1) (java-set-declared-field0 $Class_or_Instance $Field $Value1))) + ( (java-conversion $Value $Value1) (java-set-declared-field0 $Class_or_Instance $Field $Value1))) +; + (= (builtin-java-convert-args Nil Nil) - (set-det)) + (set-det)) +; + (= (builtin-java-convert-args (Cons $X $Xs) (Cons $Y $Ys)) - ( (java-conversion $X $Y) (builtin-java-convert-args $Xs $Ys))) + ( (java-conversion $X $Y) (builtin-java-convert-args $Xs $Ys))) +; + (= (synchronized $Object $Goal) ( ($begin-sync $Object $Ref) (call $Goal) - ($end-sync $Ref))) + ($end-sync $Ref))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; MeTTa interpreter +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(op 1170 xfx :-) - !(op 1170 xfx -->) - !(op 1170 fx :-) - !(op 1170 fx ?-) + !(op 1170 xfx :-) +; + + !(op 1170 xfx -->) +; + + !(op 1170 fx :-) +; + + !(op 1170 fx ?-) +; + + + !(op 1150 fx package) +; + + !(op 1150 fx import) +; + + !(op 1150 fx public) +; + + !(op 1150 fx dynamic) +; + + !(op 1150 fx meta-predicate) +; + + !(op 1150 fx mode) +; + + !(op 1150 fx multifile) +; + + !(op 1150 fx block) +; + + + !(public (/ cafeteria 0)) +; + + !(public (/ consult 1)) +; + + !(public (/ consult-stream 1)) +; + + !(public (, (/ trace 0) (/ notrace 0))) +; + + !(public (, (/ debug 0) (/ nodebug 0))) +; + + !(public (/ leash 1)) +; + + !(public (, (/ spy 1) (/ nospy 1) (/ nospyall 0))) +; + + !(public (/ listing 0)) +; - !(op 1150 fx package) - !(op 1150 fx import) - !(op 1150 fx public) - !(op 1150 fx dynamic) - !(op 1150 fx meta-predicate) - !(op 1150 fx mode) - !(op 1150 fx multifile) - !(op 1150 fx block) + !(public (/ listing 1)) +; + + + !(dynamic (/ %current-leash 1)) +; + + !(dynamic (/ %current-spypoint 3)) +; + + !(dynamic (/ %leap-flag 1)) +; - !(public (/ cafeteria 0)) - !(public (/ consult 1)) - !(public (/ consult-stream 1)) - !(public (, (/ trace 0) (/ notrace 0))) - !(public (, (/ debug 0) (/ nodebug 0))) - !(public (/ leash 1)) - !(public (, (/ spy 1) (/ nospy 1) (/ nospyall 0))) - !(public (/ listing 0)) - !(public (/ listing 1)) + !(dynamic (/ %consulted-file 1)) +; + + !(dynamic (/ %consulted-import 2)) +; + + !(dynamic (/ %consulted-package 1)) +; + + !(dynamic (/ %consulted-predicate 3)) +; - !(dynamic (/ %current-leash 1)) - !(dynamic (/ %current-spypoint 3)) - !(dynamic (/ %leap-flag 1)) - !(dynamic (/ %consulted-file 1)) - !(dynamic (/ %consulted-import 2)) - !(dynamic (/ %consulted-package 1)) - !(dynamic (/ %consulted-predicate 3)) ; -; ;; Main +; (= @@ -4301,34 +5874,38 @@ (set-det) (nl) ($fast-write bye) - (nl))) + (nl))) +; + (= (%cafeteria-init) - ( (remove-all-atoms &self - ($leap_flag $_)) - (remove-all-atoms &self - ($current_leash $_)) - (remove-all-atoms &self - ($current_spypoint $_ $_ $_)) - (remove-all-atoms &self - ($consulted_file $_)) - (remove-all-atoms &self - ($consulted_package $_)) - (remove-all-atoms &self - ($consulted_predicate $_ $_ $_)) - (add-atom &self - ($leap_flag no)) - (add-atom &self - ($current_leash call)) - (add-atom &self - ($current_leash exit)) - (add-atom &self - ($current_leash redo)) - (add-atom &self - ($current_leash fail)) - (set-det))) + ( (remove-all-symbols &self + (%leap_flag $_)) + (remove-all-symbols &self + (%current_leash $_)) + (remove-all-symbols &self + (%current_spypoint $_ $_ $_)) + (remove-all-symbols &self + (%consulted_file $_)) + (remove-all-symbols &self + (%consulted_package $_)) + (remove-all-symbols &self + (%consulted_predicate $_ $_ $_)) + (add-symbol &self + (%leap_flag no)) + (add-symbol &self + (%current_leash call)) + (add-symbol &self + (%current_leash exit)) + (add-symbol &self + (%current_leash redo)) + (add-symbol &self + (%current_leash fail)) + (set-det))) +; + (= @@ -4339,12 +5916,16 @@ (print-message info (:: debug))) ($fast-write | ?- ) - (flush-output))) + (flush-output))) +; + (= ($cafeteria $Goal) - ( (read-with-variables $Goal $Vars) ($process-order $Goal $Vars))) + ( (read-with-variables $Goal $Vars) ($process-order $Goal $Vars))) +; + (= @@ -4352,14 +5933,20 @@ ( (var $G) (set-det) (illarg var - (?- $G) 1))) + (?- $G) 1))) +; + (= ($process-order end-of-file $_) - (set-det)) + (set-det)) +; + (= ($process-order (Cons $File $Files) $_) - ( (set-det) (consult (Cons $File $Files)))) + ( (set-det) (consult (Cons $File $Files)))) +; + (= ($process-order $G $Vars) ( (current-prolog-flag debug $Mode) @@ -4372,32 +5959,44 @@ ($give-answers-with-prompt $Vars1) (set-det) ($fast-write yes) - (nl))) + (nl))) +; + (= ($process-order $_ $_) ( (nl) ($fast-write no) - (nl))) + (nl))) +; + (= ($rm-redundant-vars Nil Nil) - (set-det)) + (set-det)) +; + (= ($rm-redundant-vars (Cons (= - $_) $Xs) $Vs) - ( (set-det) ($rm-redundant-vars $Xs $Vs))) + ( (set-det) ($rm-redundant-vars $Xs $Vs))) +; + (= ($rm-redundant-vars (Cons $X $Xs) (Cons $X $Vs)) - ($rm-redundant-vars $Xs $Vs)) + ($rm-redundant-vars $Xs $Vs)) +; + (= ($give-answers-with-prompt Nil) - (set-det)) + (set-det)) +; + (= ($give-answers-with-prompt $Vs) ( ($give-an-answer $Vs) @@ -4405,31 +6004,41 @@ (flush-output) (read-line $Str) (\== $Str ";") - (nl))) + (nl))) +; + (= ($give-an-answer Nil) - ( (set-det) ($fast-write True))) + ( (set-det) ($fast-write True))) +; + (= ($give-an-answer (:: $X)) - ( (set-det) ('$print-an answer' $X))) + ( (set-det) ('$print-an answer' $X))) +; + (= ($give-an-answer (Cons $X $Xs)) ( ('$print-an answer' $X) ($fast-write ,) (nl) - ($give-an-answer $Xs))) + ($give-an-answer $Xs))) +; + (= ('$print-an answer' (= $N $V)) ( (write $N) ($fast-write = ) - (writeq $V))) + (writeq $V))) +; + ; -; ;; Read Program +; (= @@ -4437,20 +6046,28 @@ ( (var $Files) (set-det) (illarg var - (consult $Files) 1))) + (consult $Files) 1))) +; + (= (consult Nil) - (set-det)) + (set-det)) +; + (= (consult (Cons $File $Files)) ( (set-det) (consult $File) - (consult $Files))) + (consult $Files))) +; + (= (consult $File) ( (atom $File) (set-det) - ($consult $File))) + ($consult $File))) +; + (= @@ -4467,7 +6084,9 @@ (:: $_ $T)) (print-message info (:: $File consulted $T msec)) - (close $In))) + (close $In))) +; + (= @@ -4477,108 +6096,154 @@ (read $In $Cl) ($consult-clause $Cl) (== $Cl end-of-file) - (set-det))) + (set-det))) +; + (= ($prolog-file-name $File $File) ( (sub-atom $File $_ $_ $After .) (> $After 0) - (set-det))) + (set-det))) +; + (= ($prolog-file-name $File0 $File) - (atom-concat $File0 .pl $File)) + (atom-concat $File0 .pl $File)) +; + (= ($consult-init $File) - ( (remove-all-atoms &self - ($consulted_file $_)) - (remove-all-atoms &self - ($consulted_package $_)) - (remove-all-atoms &self - ($consulted_import $File $_)) - (remove-atom &self - ($consulted_predicate $P $PI $File)) + ( (remove-all-symbols &self + (%consulted_file $_)) + (remove-all-symbols &self + (%consulted_package $_)) + (remove-all-symbols &self + (%consulted_import $File $_)) + (remove-symbol &self + (%consulted_predicate $P $PI $File)) (abolish (with_self $P $PI)) - (fail))) + (fail))) +; + (= ($consult-init $File) - ( (add-atom &self - ($consulted_file $File)) (add-atom &self ($consulted_package user)))) + ( (add-symbol &self + (%consulted_file $File)) (add-symbol &self (%consulted_package user)))) +; + (= ($consult-clause end-of-file) - (set-det)) + (set-det)) +; + (= ($consult-clause !(module $P $_)) - ( (set-det) ($assert-consulted-package $P))) + ( (set-det) ($assert-consulted-package $P))) +; + (= ($consult-clause !(package $P)) - ( (set-det) ($assert-consulted-package $P))) + ( (set-det) ($assert-consulted-package $P))) +; + (= ($consult-clause !(import $P)) - ( (set-det) ($assert-consulted-import $P))) + ( (set-det) ($assert-consulted-import $P))) +; + (= ($consult-clause !(dynamic $_)) - (set-det)) + (set-det)) +; + (= ($consult-clause !(public $_)) - (set-det)) + (set-det)) +; + (= ($consult-clause !(meta-predicate $_)) - (set-det)) + (set-det)) +; + (= ($consult-clause !(mode $_)) - (set-det)) + (set-det)) +; + (= ($consult-clause !(multifile $_)) - (set-det)) + (set-det)) +; + (= ($consult-clause !(block $_)) - (set-det)) + (set-det)) +; + (= ($consult-clause !$G) ( (set-det) - (get-atoms &self + (get-symbols &self (= - ($consulted_package $P) $_)) - (once (with_self $P $G)))) + (%consulted_package $P) $_)) + (once (with_self $P $G)))) +; + (= ($consult-clause $Clause0) - ( ($consult-preprocess $Clause0 $Clause) ($consult-cls $Clause))) + ( ($consult-preprocess $Clause0 $Clause) ($consult-cls $Clause))) +; + (= ($assert-consulted-package $P) - ( (get-atoms &self + ( (get-symbols &self (= - ($consulted_package $P) $_)) (set-det))) + (%consulted_package $P) $_)) (set-det))) +; + (= ($assert-consulted-package $P) - ( (remove-all-atoms &self - ($consulted_package $_)) (add-atom &self ($consulted_package $P)))) + ( (remove-all-symbols &self + (%consulted_package $_)) (add-symbol &self (%consulted_package $P)))) +; + (= ($assert-consulted-import $P) - ( (get-atoms &self + ( (get-symbols &self (= - ($consulted_file $File) $_)) (add-atom &self ($consulted_import $File $P)))) + (%consulted_file $File) $_)) (add-symbol &self (%consulted_import $File $P)))) +; + (= ($consult-preprocess $Clause0 $Clause) - (expand-term $Clause0 $Clause)) + (expand-term $Clause0 $Clause)) +; + (= ($consult-cls (= $H $G)) - ( (set-det) ($assert-consulted-clause (= $H $G)))) + ( (set-det) ($assert-consulted-clause (= $H $G)))) +; + (= ($consult-cls $H) - ($assert-consulted-clause (= $H True))) + ($assert-consulted-clause (= $H True))) +; + (= @@ -4586,77 +6251,93 @@ ( (= $Clause (= $H $_)) (functor $H $F $A) - (get-atoms &self + (get-symbols &self (= - ($consulted_file $File) $_)) - (get-atoms &self + (%consulted_file $File) $_)) + (get-symbols &self (= - ($consulted_package $P) $_)) - (add-atom &self + (%consulted_package $P) $_)) + (add-symbol &self (: $P $Clause)) - (add-atom &self - ($consulted_predicate $P + (add-symbol &self + (%consulted_predicate $P (/ $F $A) $File)) - (set-det))) + (set-det))) +; + ; -; ;; Trace +; (= (trace) - ( (current-prolog-flag debug on) (set-det))) + ( (current-prolog-flag debug on) (set-det))) +; + (= (trace) ( (set-prolog-flag debug on) (%trace-init) ($fast-write '{Small debugger is switch on}') (nl) - (set-det))) + (set-det))) +; + (= (%trace-init) - ( (remove-all-atoms &self - ($leap_flag $_)) - (remove-all-atoms &self - ($current_leash $_)) - (remove-all-atoms &self - ($current_spypoint $_ $_ $_)) - (add-atom &self - ($leap_flag no)) - (add-atom &self - ($current_leash call)) - (add-atom &self - ($current_leash exit)) - (add-atom &self - ($current_leash redo)) - (add-atom &self - ($current_leash fail)) - (set-det))) + ( (remove-all-symbols &self + (%leap_flag $_)) + (remove-all-symbols &self + (%current_leash $_)) + (remove-all-symbols &self + (%current_spypoint $_ $_ $_)) + (add-symbol &self + (%leap_flag no)) + (add-symbol &self + (%current_leash call)) + (add-symbol &self + (%current_leash exit)) + (add-symbol &self + (%current_leash redo)) + (add-symbol &self + (%current_leash fail)) + (set-det))) +; + (= (notrace) - ( (current-prolog-flag debug off) (set-det))) + ( (current-prolog-flag debug off) (set-det))) +; + (= (notrace) ( (set-prolog-flag debug off) ($fast-write '{Small debugger is switch off}') (nl) - (set-det))) + (set-det))) +; + (= (debug) - (trace)) + (trace)) +; + (= (nodebug) - (notrace)) + (notrace)) +; + ; -; ;; Spy-Points +; (= @@ -4666,38 +6347,46 @@ (trace) ($assert-spypoint $PI) ($set-debug-flag leap yes) - (set-det))) + (set-det))) +; + (= ($assert-spypoint (with_self $P (/ $F $A))) - ( (get-atoms &self + ( (get-symbols &self (= - ($current_spypoint $P $F $A) $_)) + (%current_spypoint $P $F $A) $_)) (print-message info (:: spypoint (with_self $P (/ $F $A)) is already added)) - (set-det))) + (set-det))) +; + (= ($assert-spypoint (with_self $P (/ $F $A))) - ( (get-atoms &self + ( (get-symbols &self (= - ($consulted_predicate $P + (%consulted_predicate $P (/ $F $A) $_) $_)) - (add-atom &self - ($current_spypoint $P $F $A)) + (add-symbol &self + (%current_spypoint $P $F $A)) (print-message info (:: spypoint (with_self $P (/ $F $A)) is added)) - (set-det))) + (set-det))) +; + (= ($assert-spypoint (with_self $P (/ $F $A))) (print-message warning (:: no matching predicate for spy (with_self $P - (/ $F $A))))) + (/ $F $A))))) +; + (= @@ -4706,133 +6395,177 @@ (nospy $T)) ($retract-spypoint $PI) ($set-debug-flag leap no) - (set-det))) + (set-det))) +; + (= ($retract-spypoint (with_self $P (/ $F $A))) - ( (remove-atom &self - ($current_spypoint $P $F $A)) + ( (remove-symbol &self + (%current_spypoint $P $F $A)) (print-message info (:: spypoint (with_self $P (/ $F $A)) is removed)) - (set-det))) + (set-det))) +; + (= - ($retract_spypoint $_) True) + (%retract_spypoint $_) True) +; + (= (nospyall) - ( (remove-all-atoms &self - ($current_spypoint $_ $_ $_)) ($set-debug-flag leap no))) + ( (remove-all-symbols &self + (%current_spypoint $_ $_ $_)) ($set-debug-flag leap no))) +; + ; -; ;; Leash +; (= (leash $L) ( (nonvar $L) ($leash $L) - (set-det))) + (set-det))) +; + (= (leash $L) (illarg (type leash-specifier) - (leash $L) 1)) + (leash $L) 1)) +; + (= ($leash Nil) ( (set-det) - (remove-all-atoms &self - ($current_leash $_)) + (remove-all-symbols &self + (%current_leash $_)) (print-message info - (:: no leashing)))) + (:: no leashing)))) +; + (= ($leash $Ms) - ( (remove-all-atoms &self - ($current_leash $_)) + ( (remove-all-symbols &self + (%current_leash $_)) ($assert-leash $Ms) (print-message info - (:: leashing stopping on $Ms)))) + (:: leashing stopping on $Ms)))) +; + (= ($assert-leash Nil) - (set-det)) + (set-det)) +; + (= ($assert-leash (Cons $X $Xs)) ( ($leash-specifier $X) - (add-atom &self - ($current_leash $X)) - ($assert-leash $Xs))) + (add-symbol &self + (%current_leash $X)) + ($assert-leash $Xs))) +; + (= - ($leash_specifier call) True) + (%leash_specifier call) True) +; + (= - ($leash_specifier exit) True) + (%leash_specifier exit) True) +; + (= - ($leash_specifier redo) True) + (%leash_specifier redo) True) +; + (= - ($leash_specifier fail) True) + (%leash_specifier fail) True) +; + ; -; '$leash_specifier'(exception). +; ; -; ;; Trace a Goal +; (= ($trace-goal $Term) ( ($set-debug-flag leap no) ($get-current-B $Cut) - ($meta-call $Term user $Cut 0 trace))) + ($meta-call $Term user $Cut 0 trace))) +; + (= ($trace-goal $X $P $FA $Depth) ( (print-procedure-box call $X $P $FA $Depth) ($call-internal $X $P $FA $Depth trace) (print-procedure-box exit $X $P $FA $Depth) - (redo-procedure-box $X $P $FA $Depth))) + (redo-procedure-box $X $P $FA $Depth))) +; + (= ($trace-goal $X $P $FA $Depth) - ( (print-procedure-box fail $X $P $FA $Depth) (fail))) + ( (print-procedure-box fail $X $P $FA $Depth) (fail))) +; + (= (print-procedure-box $Mode $G $P (/ $F $A) $Depth) - ( (get-atoms &self + ( (get-symbols &self (= - ($current_spypoint $P $F $A) $_)) + (%current_spypoint $P $F $A) $_)) (set-det) ($builtin-message (:: + $Depth $Mode : (with_self $P $G))) - ($read-blocked (print-procedure-box $Mode $G $P (/ $F $A) $Depth)))) + ($read-blocked (print-procedure-box $Mode $G $P (/ $F $A) $Depth)))) +; + (= (print-procedure-box $Mode $G $P $FA $Depth) - ( (get-atoms &self + ( (get-symbols &self (= - ($leap_flag no) $_)) + (%leap_flag no) $_)) (set-det) ($builtin-message (:: ' ' $Depth $Mode : (with_self $P $G))) (det-if-then-else - (get-atoms &self + (get-symbols &self (= - ($current_leash $Mode) $_)) - ($read-blocked (print-procedure-box $Mode $G $P $FA $Depth)) nl))) + (%current_leash $Mode) $_)) + ($read-blocked (print-procedure-box $Mode $G $P $FA $Depth)) nl))) +; + (= - (print_procedure_box $_ $_ $_ $_ $_) True) + (print_procedure_box $_ $_ $_ $_ $_) True) +; + (= - (redo_procedure_box $_ $_ $_ $_) True) + (redo_procedure_box $_ $_ $_ $_) True) +; + (= (redo-procedure-box $X $P $FA $Depth) - ( (print-procedure-box redo $X $P $FA $Depth) (fail))) + ( (print-procedure-box redo $X $P $FA $Depth) (fail))) +; + (= @@ -4845,25 +6578,33 @@ (= $DOP 99) (= $C (Cons $DOP $_))) - ($debug-option $DOP $G))) + ($debug-option $DOP $G))) +; + (= ($debug-option 97 $_) ( (set-det) (notrace) - (abort))) ; -; a for abort + (abort))) +; + ; +; (= ($debug-option 99 $_) - ( (set-det) ($set-debug-flag leap no))) ; -; c for creep + ( (set-det) ($set-debug-flag leap no))) +; + ; +; (= ($debug-option 108 $_) - ( (set-det) ($set-debug-flag leap yes))) ; -; l for leap + ( (set-det) ($set-debug-flag leap yes))) +; + ; +; (= ($debug-option 43 @@ -4871,8 +6612,7 @@ ( (set-det) (spy (with_self $P $FA)) (call (print-procedure-box $Mode $G $P $FA $Depth)))) -; ; + for spy this - +; (= ($debug-option 45 @@ -4880,21 +6620,26 @@ ( (set-det) (nospy (with_self $P $FA)) (call (print-procedure-box $Mode $G $P $FA $Depth)))) -; ; - for nospy this - +; (= ($debug-option 63 $G) ( (set-det) (%show-debug-option) - (call $G))) + (call $G))) +; + (= ($debug-option 104 $G) ( (set-det) (%show-debug-option) - (call $G))) + (call $G))) +; + (= - ($debug_option $_ $_) True) + (%debug_option $_ $_) True) +; + (= @@ -4925,58 +6670,78 @@ (nl) (tab 4) ($fast-write 'h help') - (nl))) + (nl))) +; + (= ($set-debug-flag leap $Flag) - ( (get-atoms &self + ( (get-symbols &self (= - ($leap_flag $Flag) $_)) (set-det))) + (%leap_flag $Flag) $_)) (set-det))) +; + (= ($set-debug-flag leap $Flag) - ( (remove-all-atoms &self - ($leap_flag $_)) (add-atom &self ($leap_flag $Flag)))) + ( (remove-all-symbols &self + (%leap_flag $_)) (add-symbol &self (%leap_flag $Flag)))) +; + ; -; ;; Listing +; (= (listing) - ($listing $_ user)) + ($listing $_ user)) +; + (= (listing $T) ( (var $T) (set-det) (illarg var - (listing $T) 1))) + (listing $T) 1))) +; + (= (listing $P) ( (atom $P) (set-det) - ($listing $_ $P))) + ($listing $_ $P))) +; + (= (listing (/ $F $A)) - ( (set-det) ($listing (/ $F $A) user))) + ( (set-det) ($listing (/ $F $A) user))) +; + (= (listing (with_self $P $PI)) ( (atom $P) (set-det) - ($listing $PI $P))) + ($listing $PI $P))) +; + (= (listing $T) (illarg (type predicate-indicator) - (listing $T) 1)) + (listing $T) 1)) +; + (= ($listing $PI $P) ( (var $PI) (set-det) - ($listing-dynamic-clause $P $_))) + ($listing-dynamic-clause $P $_))) +; + (= ($listing (/ $F $A) $P) @@ -4984,12 +6749,16 @@ (integer $A) (set-det) ($listing-dynamic-clause $P - (/ $F $A)))) + (/ $F $A)))) +; + (= ($listing $PI $P) (illarg (type predicate-indicator) - (listing (with_self $P $PI)) 1)) + (listing (with_self $P $PI)) 1)) +; + (= @@ -5002,16 +6771,22 @@ (functor $H $F $A) ($clause-internal $P $PI $H $Cl $_) ($write-dynamic-clause $P $Cl) - (fail))) + (fail))) +; + (= - ($listing_dynamic_clause $_ $_) True) + (%listing_dynamic_clause $_ $_) True) +; + (= ($write-dynamic-clause $_ $Cl) ( (var $Cl) (set-det) - (fail))) + (fail))) +; + (= ($write-dynamic-clause $P (= $H True)) @@ -5019,7 +6794,9 @@ (numbervars $H 0 $_) ($write-dynamic-head $P $H) (write .) - (nl))) + (nl))) +; + (= ($write-dynamic-clause $P (= $H $B)) @@ -5031,17 +6808,23 @@ (nl) ($write-dynamic-body $B 8) (write .) - (nl))) + (nl))) +; + (= ($write-dynamic-head user $H) - ( (set-det) (writeq $H))) + ( (set-det) (writeq $H))) +; + (= ($write-dynamic-head $P $H) ( (write $P) (write :) - (writeq $H))) + (writeq $H))) +; + (= @@ -5051,7 +6834,9 @@ ($write-dynamic-body $G1 $N) (write ,) (nl) - ($write-dynamic-body $G2 $N))) + ($write-dynamic-body $G2 $N))) +; + (= ($write-dynamic-body (or $G1 $G2) $N) @@ -5069,7 +6854,9 @@ ($write-dynamic-body $G2 $N1) (nl) (tab $N) - (write )))) + (write )))) +; + (= ($write-dynamic-body (det-if-then $G1 $G2) $N) @@ -5087,34 +6874,46 @@ ($write-dynamic-body $G2 $N1) (nl) (tab $N) - (write )))) + (write )))) +; + (= ($write-dynamic-body $B $N) - ( (tab $N) (writeq $B))) + ( (tab $N) (writeq $B))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Misc +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (/ reverse 2)) - !(public (/ length 2)) - !(public (/ numbervars 3)) - !(public (/ statistics 2)) + !(public (/ reverse 2)) +; + + !(public (/ length 2)) +; + + !(public (/ numbervars 3)) +; + + !(public (/ statistics 2)) +; + ; -; reverse(Xs, Zs) :- reverse(Xs, [], Zs). +; ; -; reverse([], Zs, Zs). +; ; -; reverse([X|Xs], Tmp, Zs) :- reverse(Xs, [X|Tmp], Zs). +; @@ -5122,31 +6921,43 @@ (length $L $N) ( (var $N) (set-det) - ($length $L 0 $N))) + ($length $L 0 $N))) +; + (= (length $L $N) - ($length0 $L 0 $N)) + ($length0 $L 0 $N)) +; + (= - ($length () $I $I) True) + ($length () $I $I) True) +; + (= ($length (Cons $_ $L) $I0 $I) ( (is $I1 - (+ $I0 1)) ($length $L $I1 $I))) + (+ $I0 1)) ($length $L $I1 $I))) +; + (= ($length0 Nil $I $I) - (set-det)) + (set-det)) +; + (= ($length0 (Cons $_ $L) $I0 $I) ( (< $I0 $I) (is $I1 (+ $I0 1)) - ($length0 $L $I1 $I))) + ($length0 $L $I1 $I))) +; + (= @@ -5154,7 +6965,9 @@ ( (integer $VI) (>= $VI 0) (set-det) - ($numbervars $X $VI $VN))) + ($numbervars $X $VI $VN))) +; + (= @@ -5164,32 +6977,41 @@ (= $X $VI) (is $VN (+ $VI 1)))) -; ; This structure is checked in write - +; (= ($numbervars $X $VI $VI) - ( (atomic $X) (set-det))) + ( (atomic $X) (set-det))) +; + (= ($numbervars $X $VI $VI) - ( (java $X) (set-det))) + ( (java $X) (set-det))) +; + (= ($numbervars $X $VI $VN) - ( (functor $X $_ $N) ($numbervars-str 1 $N $X $VI $VN))) + ( (functor $X $_ $N) ($numbervars-str 1 $N $X $VI $VN))) +; + (= ($numbervars-str $I $I $X $VI $VN) ( (set-det) (arg $I $X $A) - ($numbervars $A $VI $VN))) + ($numbervars $A $VI $VN))) +; + (= ($numbervars-str $I $N $X $VI $VN) ( (arg $I $X $A) ($numbervars $A $VI $VN1) (is $I1 (+ $I 1)) - ($numbervars-str $I1 $N $X $VN1 $VN))) + ($numbervars-str $I1 $N $X $VN1 $VN))) +; + (= @@ -5197,19 +7019,29 @@ ( (nonvar $Key) ($statistics-mode $Key) (set-det) - ($statistics $Key $Value))) + ($statistics $Key $Value))) +; + (= (statistics $Key $Value) ( (findall $M - ($statistics-mode $M) $Domain) (illarg (domain is-symbol $Domain) (statistics $Key $Value) 1))) + ($statistics-mode $M) $Domain) (illarg (domain is-symbol $Domain) (statistics $Key $Value) 1))) +; + (= - ($statistics_mode runtime) True) + (%statistics_mode runtime) True) +; + (= - ($statistics_mode trail) True) + (%statistics_mode trail) True) +; + (= - ($statistics_mode choice) True) + (%statistics_mode choice) True) +; + (= @@ -5217,24 +7049,32 @@ ( (var $Type) (set-det) (illarg var - (print-message $Type $Message) 1))) + (print-message $Type $Message) 1))) +; + (= (print-message error $Message) - ( (set-det) ($error-message $Message))) + ( (set-det) ($error-message $Message))) +; + (= (print-message info $Message) ( (set-det) ($fast-write {) ($builtin-message $Message) ($fast-write }) - (nl))) + (nl))) +; + (= (print-message warning $Message) ( (set-det) ($fast-write '{WARNING: ') ($builtin-message $Message) ($fast-write }) - (nl))) + (nl))) +; + (= @@ -5244,7 +7084,9 @@ ($write-goal user-error $Goal) ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (instantiation-error $Goal $ArgNo)) ( (set-det) @@ -5254,7 +7096,9 @@ ($fast-write user-error $ArgNo) ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (type-error $Goal $ArgNo $Type $Culprit)) ( (set-det) @@ -5268,7 +7112,9 @@ (write user-error $Culprit) ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (domain-error $Goal $ArgNo $Domain $Culprit)) ( (set-det) @@ -5282,7 +7128,9 @@ (write user-error $Culprit) ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (existence-error $Goal 0 $ObjType $Culprit $Message)) ( (set-det) @@ -5293,7 +7141,9 @@ ($fast-write user-error ' does not exist') ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (existence-error $Goal $ArgNo $ObjType $Culprit $Message)) ( (set-det) @@ -5308,7 +7158,9 @@ ($fast-write user-error ' does not exist') ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (permission-error $Goal $Operation $ObjType $Culprit $Message)) ( (set-det) @@ -5324,7 +7176,9 @@ ($fast-write user-error $Message) ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (representation-error $Goal $ArgNo $Flag)) ( (set-det) @@ -5337,7 +7191,9 @@ ($fast-write user-error ' is breached') ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (evaluation-error $Goal $ArgNo $Type)) ( (set-det) @@ -5349,7 +7205,9 @@ ($fast-write user-error $Type) ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (syntax-error $Goal $ArgNo $Type $Culprit $Message)) ( (set-det) @@ -5363,7 +7221,9 @@ (write user-error $Culprit) ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (system-error $Message)) ( (set-det) @@ -5371,7 +7231,9 @@ (write user-error $Message) ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (internal-error $Message)) ( (set-det) @@ -5379,7 +7241,9 @@ (write user-error $Message) ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (java-error $Goal $ArgNo $Exception)) ( (set-det) @@ -5392,34 +7256,46 @@ ($fast-write user-error }) (nl user-error) ($print-stack-trace $Exception) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message $Message) ( ($fast-write user-error {) (write user-error $Message) ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($write-goal $S $Goal) ( (java $Goal) (set-det) - ($write-toString $S $Goal))) + ($write-toString $S $Goal))) +; + (= ($write-goal $S $Goal) - (write $S $Goal)) + (write $S $Goal)) +; + (= (illarg $Msg $Goal $ArgNo) ( (var $Msg) (set-det) - (illarg var $Goal $ArgNo))) + (illarg var $Goal $ArgNo))) +; + (= (illarg var $Goal $ArgNo) - (raise-exception (instantiation-error $Goal $ArgNo))) + (raise-exception (instantiation-error $Goal $ArgNo))) +; + (= (illarg (type $Type) $Goal $ArgNo) @@ -5430,7 +7306,9 @@ (type-error $Goal $ArgNo $Type $Arg)) (= $Error (instantiation-error $Goal $ArgNo))) - (raise-exception $Error))) + (raise-exception $Error))) +; + (= (illarg (domain $Type $ExpDomain) $Goal $ArgNo) @@ -5445,142 +7323,206 @@ (type-error $Goal $ArgNo $Type $Arg)) (= $Error (instantiation-error $Goal $ArgNo)))) - (raise-exception $Error))) + (raise-exception $Error))) +; + (= (illarg (existence $ObjType $Culprit $Message) $Goal $ArgNo) - (raise-exception (existence-error $Goal $ArgNo $ObjType $Culprit $Message))) + (raise-exception (existence-error $Goal $ArgNo $ObjType $Culprit $Message))) +; + (= (illarg (permission $Operation $ObjType $Culprit $Message) $Goal $_) - (raise-exception (permission-error $Goal $Operation $ObjType $Culprit $Message))) + (raise-exception (permission-error $Goal $Operation $ObjType $Culprit $Message))) +; + (= (illarg (representation $Flag) $Goal $ArgNo) - (raise-exception (representation-error $Goal $ArgNo $Flag))) + (raise-exception (representation-error $Goal $ArgNo $Flag))) +; + (= (illarg (evaluation $Type) $Goal $ArgNo) - (raise-exception (evaluation-error $Goal $ArgNo $Type))) + (raise-exception (evaluation-error $Goal $ArgNo $Type))) +; + (= (illarg (syntax $Type $Culprit $Message) $Goal $ArgNo) - (raise-exception (syntax-error $Goal $ArgNo $Type $Culprit $Message))) + (raise-exception (syntax-error $Goal $ArgNo $Type $Culprit $Message))) +; + (= (illarg (system $Message) $_ $_) - (raise-exception (system-error $Message))) + (raise-exception (system-error $Message))) +; + (= (illarg (internal $Message) $_ $_) - (raise-exception (internal-error $Message))) + (raise-exception (internal-error $Message))) +; + (= (illarg (java $Exception) $Goal $ArgNo) - (raise-exception (java-error $Goal $ArgNo $Exception))) + (raise-exception (java-error $Goal $ArgNo $Exception))) +; + (= (illarg $Msg $_ $_) - (raise-exception $Msg)) + (raise-exception $Msg)) +; + (= - ($match_type term $_) True) + (%match_type term $_) True) +; + (= ($match-type variable $X) - (var $X)) + (var $X)) +; + (= ($match-type is-symbol $X) - (atom $X)) + (atom $X)) +; + (= ($match-type symbolic $X) - (atomic $X)) + (atomic $X)) +; + (= ($match-type byte $X) ( (integer $X) (=< 0 $X) - (=< $X 255))) + (=< $X 255))) +; + (= ($match-type in-byte $X) ( (integer $X) (=< -1 $X) - (=< $X 255))) + (=< $X 255))) +; + (= ($match-type character $X) - ( (atom $X) (atom-length $X 1))) + ( (atom $X) (atom-length $X 1))) +; + (= ($match-type in-character $X) (or (== $X end-of-file) - ($match-type character $X))) + ($match-type character $X))) +; + (= ($match-type number $X) - (number $X)) + (number $X)) +; + (= ($match-type integer $X) - (integer $X)) + (integer $X)) +; + (= ($match-type long $X) - (long $X)) + (long $X)) +; + (= ($match-type float $X) - (float $X)) + (float $X)) +; + (= ($match-type callable $X) - (callable $X)) + (callable $X)) +; + (= ($match-type compound $X) - (compound $X)) + (compound $X)) +; + (= ($match-type list $X) - ( (nonvar $X) (or (= $X Nil) (= $X (Cons $_ $_))))) + ( (nonvar $X) (or (= $X Nil) (= $X (Cons $_ $_))))) +; + (= ($match-type java $X) - (java $X)) + (java $X)) +; + (= ($match-type stream $X) (or (java $X java.io.PushbackReader) - (java $X java.io.PrintWriter))) + (java $X java.io.PrintWriter))) +; + (= ($match-type stream-or-alias $X) (or (atom $X) - ($match-type stream $X))) + ($match-type stream $X))) +; + (= ($match-type hash $X) - (java $X com.googlecode.prolog-cafe.lang.HashtableOfTerm)) + (java $X com.googlecode.prolog-cafe.lang.HashtableOfTerm)) +; + (= ($match-type hash-or-alias $X) (or (atom $X) - ($match-type hash $X))) + ($match-type hash $X))) +; + (= ($match-type predicate-indicator $X) ( (nonvar $X) - (with_self - (= $X $P) - (/ $F $A)) + (= $X + (with_self $P + (/ $F $A))) (atom $P) (atom $F) - (integer $A))) + (integer $A))) +; + ; -; '$match_type'(evaluable, X). +; ; -; '$match_type'('convertible to java', X). +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; ISO thread synchronization +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (/ with-mutex 2)) + !(public (/ with-mutex 2)) +; + (= @@ -5590,83 +7532,106 @@ (set-det) (illarg (type is-symbol) - (with-mutex $M $G) 1))) + (with-mutex $M $G) 1))) +; + (= (with-mutex $M $G) ( (var $G) (set-det) (illarg var - (with-mutex $M $G) 2))) + (with-mutex $M $G) 2))) +; + (= (with-mutex $M $G) ( (not (callable $G)) (set-det) (illarg (type callable) - (with-mutex $M $G) 2))) + (with-mutex $M $G) 2))) +; + (= (with-mutex $M $G) ( (mutex-lock-bt $M) (call $G) (set-det) (mutex-unlock $M))) -; ; if it fails or throws exception, mutex is unlocked automatically due to mutex_lock_bt - +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Utilities +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; (= - ($builtin_append () $Zs $Zs) True) + (%builtin_append () $Zs $Zs) True) +; + (= ($builtin-append (Cons $X $Xs) $Ys (Cons $X $Zs)) - ($builtin-append $Xs $Ys $Zs)) + ($builtin-append $Xs $Ys $Zs)) +; + (= - ($builtin_member $X - (Cons $X $_)) True) + (%builtin_member $X + (Cons $X $_)) True) +; + (= ($builtin-member $X (Cons $_ $L)) - ($builtin-member $X $L)) + ($builtin-member $X $L)) +; + (= ($builtin-message Nil) - (set-det)) + (set-det)) +; + (= ($builtin-message (:: $M)) - ( (set-det) (write $M))) + ( (set-det) (write $M))) +; + (= ($builtin-message (Cons $M $Ms)) ( (write $M) ($fast-write ' ') - ($builtin-message $Ms))) + ($builtin-message $Ms))) +; + (= ($member-in-reverse $X (Cons $_ $L)) - ($member-in-reverse $X $L)) + ($member-in-reverse $X $L)) +; + (= - ($member_in_reverse $X - (Cons $X $_)) True) + (%member_in_reverse $X + (Cons $X $_)) True) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; END +; diff --git a/sxx_machine/sxx_compiler.metta b/sxx_machine/sxx_compiler.metta index cb68813..4744cd3 100644 --- a/sxx_machine/sxx_compiler.metta +++ b/sxx_machine/sxx_compiler.metta @@ -1,19 +1,27 @@ (= (append () $L $L) True) +; + (= (append (Cons $X $L1) $L2 (Cons $X $L3)) (append $L1 $L2 $L3)) +; + (= (legacy-functor $P . $A) ( (functor $P Cons $A) (set-det))) +; + (= (legacy-functor $P $F $A) ( (functor $P $F $A) (set-det))) +; + (= @@ -30,23 +38,28 @@ (set-det) (gencode $Dir $Prog) (set-det))) -; ; close(File) , - +; (= (gencode $_ ()) True) +; + (= (gencode $Package (Cons $Pred $Preds)) ( (gencodeforpred $Package $Pred) (gencode $Package $Preds))) +; + (= (local-side-efs $_ !$Call) ( (call $Call) (set-det))) +; + (= (local-side-efs $_ $H) ( (\= $H @@ -54,17 +67,25 @@ (set-det) (local-side-efs $_ (= $H True)))) +; + (= (local-side-efs $_ (= $H $_)) ( (or (predicate-property $H static) (predicate-property $H built-in)) (set-det))) +; + (= (local-side-efs $_ $Call) - ( (call (add-atom &self $Call)) (set-det))) + ( (call (add-symbol &self $Call)) (set-det))) +; + (= (local_side_efs $_ $Clause) True) +; + (= (readprogram $BName $In $Out) @@ -77,9 +98,11 @@ (binarize $Clause $BinCl) (addclausetoprogram $BinCl $In $NewIn) (readprogram $BName $NewIn $Out))))) +; + ; -; binarize((Head ::- Body),Cl) :- ! , Cl = (Head :- Body) . +; (= @@ -89,11 +112,15 @@ ( (set-det) (addcont $Head $Continuation $BinHead) (makebinbody $Body $Continuation $BinBody))) +; + (= (binarize $Head (= $BinHead (call $Continuation))) (addcont $Head $Continuation $BinHead)) +; + (= @@ -102,23 +129,33 @@ ( (set-det) (makebinbody $B $C $NewB) (addcont $G $NewB $NewBody))) +; + (= (makebinbody $SpecialGoal $C $NewBody) ( (specialgoal $SpecialGoal $G) (set-det) (addcont $G $C $NewBody))) +; + (= (makebinbody (set-det) $C $NewBody) ( (set-det) (= $NewBody (cut 1 $C)))) +; + (= (makebinbody $G $C $NewBody) ( (set-det) (addcont $G $C $NewBody))) +; + (= (addclausetoprogram $Cl Nil $ProgOut) ( (set-det) (= $ProgOut (:: (:: $Cl))))) +; + (= (addclausetoprogram $Cl (Cons $Pred $Rest) $Out) @@ -127,11 +164,15 @@ (= $Out (Cons (Cons $Cl $Pred) $Rest)))) +; + (= (addclausetoprogram $Cl (Cons $Pred $Rest) (Cons $Pred $NewRest)) (addclausetoprogram $Cl $Rest $NewRest)) +; + @@ -141,6 +182,8 @@ (Cons (= $H2 $_) $_)) ( (legacy-functor $H1 $N $A) (legacy-functor $H2 $N $A))) +; + @@ -151,11 +194,15 @@ (addcont (set-det) $C $FB) ( (set-det) (= $FB (cut 1 $C)))) +; + (= (addcont $S $C $NG) ( (specialgoal $S $NS) (set-det) (addcont $NS $C $NG))) +; + (= (addcont $F $C $FB) ( (=.. $F @@ -164,6 +211,8 @@ (:: $C) $NA) (=.. $FB (Cons $N $NA)))) +; + @@ -172,11 +221,15 @@ ( (== $EOL Nil) (set-det) (= $Out ''))) +; + (= (makename $Atom $Out) ( (atomic $Atom) (set-det) (= $Out $Atom))) +; + (= (makename (Cons $AC $Rest) $OutC) @@ -185,40 +238,58 @@ (name $AC $AL) (append $AL $OL $OutL) (name $OutC $OutL))) +; + (= (writel ()) True) +; + (= (writel (Cons $X $R)) ( (wr $X) (writel $R))) +; + (= (wr (wr nl)) ( (set-det) (nl))) +; + (= (wr $Atom) ( (atomic $Atom) (set-det) (write $Atom))) +; + (= (wr $VAR) ( (legacy-functor $VAR %VAR 2) (set-det) (write $VAR))) +; + (= (wr $Goal) (call $Goal)) +; + (= (wrargs $N $T) (wrargs $N $T $_)) +; + (= (wrargs $N $_ $_) ( (= $N 0) (set-det))) +; + (= (wrargs $N $T $Komma) ( (det-if-then-else @@ -229,12 +300,14 @@ (is $M (- $N 1)) (wrargs $M $T $Komma))) +; + ; -; Pred is a list of clauses for a specific predicate +; ; -; it is binarized and also in reverse order +; @@ -266,20 +339,25 @@ (writel (:: 'class /* Pred */' $ClassName ' extends Code' (wr nl) { (wr nl) (declforeachclause $Pred 1 $ClassName) (declforeachcontinuation $Conts $N $A) (declforeachstring $Strings 0) (declforeachint $AllInts) 'public static Code entry-code = new ' $ClassName (); (wr nl) 'public void Init(Prolog mach)' (wr nl) { (initforeachcontinuation $Conts $N $A) } (wr nl) 'public int Arity() { return ' $AA ; } (wr nl) 'public Code Exec(Prolog mach)' (wr nl) '{ Term aregs[] = {' (aregarray $AA) } ; (wr nl) 'mach.CreateChoicePoint(aregs) ;' (wr nl) 'return cl1.Exec(mach) ;' (wr nl) } (wr nl) } (wr nl) (wr nl))) (genpredcode $Pred last $ClassName $_ $Strings) (told))) -; ;close(FileName) . - +; (= (mysetof $X $Y $Z) ( (setof $X $Y $Z) (set-det))) +; + (= (mysetof $_ $_ ()) True) +; + (= (genpredcode () $_ $_ 0 $_) True) +; + (= (genpredcode (Cons $Clause $Rest) $Last $ClassName $M $Strings) @@ -287,6 +365,8 @@ (is $M (+ $N 1)) (genclausecode $Clause $Last $ClassName $M $Strings))) +; + (= @@ -301,6 +381,8 @@ (arg $Arity $Head ($cont $Arity)) (writel (:: '/* helper */class ' $ClassName -- $N ' extends ' $ClassName (wr nl) { (wr nl) 'public Code Exec(Prolog mach)' (wr nl) { (det-if-then-else (= $Last last) (write 'mach.RemoveChoice() ;') (, (is $M (+ $N 1)) (writel (:: mach.FillAlternative(cl $M ) ;)))) (wr nl) 'Term local-aregs[] = mach.Areg ;' (wr nl) 'Term continuation = local-aregs[' $Amin1 ] ; (wr nl) (decl-deref-args $Amin2) (mynumbervars $Clause 1 $NumbVars) (det-if-then-else (> $NumbVars 1) (declvars $NumbVars) True) (gets $Head $Strings) (puts $Body $Strings) 'mach.CUTB = mach.CurrentChoice ;' (wr nl) (nullifyaregs $Clause) 'return ' (bodycont $Clause $Name $Arity) ; (wr nl) } (wr nl) } (wr nl) (wr nl))))) +; + (= @@ -311,8 +393,12 @@ (- $HA $BA)) (> $Diff 0) (nullify $Diff $HA))) +; + (= (nullifyaregs $_) True) +; + (= @@ -321,6 +407,8 @@ (write 'null ;') (nl) (fail))) +; + (= (nullify $N $K) ( (is $L @@ -329,6 +417,8 @@ (is $M (- $N 1)) (nullify $M $L))) +; + (= @@ -339,27 +429,39 @@ ($VAR $I $_)) (is $O (+ $I 1)))) +; + (= (mynumbervars ($VAR $_ $_) $I $O) ( (set-det) (= $I $O))) +; + (= (mynumbervars $A $I $O) ( (atomic $A) (set-det) (= $I $O))) +; + (= (mynumbervars $Term $I $O) ( (=.. $Term (Cons $_ $Args)) (mynumbervarslist $Args $I $O))) +; + (= (mynumbervarslist () $I $I) True) +; + (= (mynumbervarslist (Cons $T $R) $I $O) ( (mynumbervars $T $I $II) (mynumbervarslist $R $II $O))) +; + @@ -367,12 +469,16 @@ (gets $Head $Strings) ( (=.. $Head (Cons $_ $Args)) (gets $Args 0 $Strings))) +; + (= (gets (:: $_) $_ $_) - (set-det)) ; -; this is the continuation ! + (set-det)) +; + ; +; (= (gets @@ -381,11 +487,15 @@ (+ $N 1)) (getforarg $Arg $N $Strings) (gets $Args $M $Strings))) +; + (= (getforarg $Arg $N $Strings) (writel (:: 'if (!( (areg' $N ).Unify( (constructterm $Arg $Strings) '))) return Prolog.Fail0 ;' (wr nl)))) +; + @@ -395,13 +505,19 @@ ( (set-det) (writel (:: 'mach.DoCut(mach.CUTB) ;' (wr nl))) (putforarg $C 0 $Strings))) +; + (= (puts $Body $Strings) ( (=.. $Body (Cons $_ $Args)) (puts $Args 0 $Strings))) +; + (= (puts () $_ $_) True) +; + (= (puts (Cons $Arg $Args) $N $Strings) @@ -409,30 +525,38 @@ (+ $N 1)) (putforarg $Arg $N $Strings) (puts $Args $M $Strings))) +; + (= (putforarg $Arg $N $Strings) (writel (:: local-aregs[ $N ] = (constructterm $Arg $Strings) ; (wr nl)))) +; + (= (declvars 1) (set-det)) +; + (= (declvars $N) ( (is $M (- $N 1)) (writel (:: 'Term var' $M ' = Term.Var(mach) ;' (wr nl))) (declvars $M))) +; + ; -; variables are replaced with '$VAR'(integer,_) +; ; -; continuation is replaced by '$cont'(arity) +; @@ -440,28 +564,38 @@ (constructterm ($cont $_) $_) ( (set-det) (writel (:: continuation)))) +; + (= (constructterm ($VAR $N $T) $_) ( (set-det) (det-if-then-else (var $T) (, (writel (:: var $N)) (= $T 1)) (writel (:: var $N .Deref()))))) +; + (= (constructterm (cut $_ $C) $Strings) ( (set-det) (getnameindex $Strings cut 0 $I) (writel (:: Term.Compound(string $I ', new HeapChoice(mach.CUTB),' (constructterm $C $Strings) ))))) +; + (= (constructterm $IntegerTerm $_) ( (integer $IntegerTerm) (set-det) (posneg $IntegerTerm))) +; + (= (constructterm $Atom $Strings) ( (atom $Atom) (set-det) (getnameindex $Strings $Atom 0 $I) (writel (:: Const.Intern(string $I ))))) +; + (= (constructterm $Term $Strings) ( (legacy-functor $Term $Name $_) @@ -469,10 +603,14 @@ (Cons $_ $Args)) (getnameindex $Strings $Name 0 $I) (writel (:: Term.Compound(string $I , (newargs $Args 1 $Strings) ))))) +; + (= (newargs () $_ $_) True) +; + (= (newargs (Cons $A $Args) $N $Strings) @@ -483,6 +621,8 @@ (+ $N 1)) (constructterm $A $Strings) (newargs $Args $M $Strings))) +; + @@ -494,75 +634,87 @@ ( (legacy-functor $B $Name $Arity) (set-det) (writel (:: entry-code)))) +; + (= (bodycont (= $_ $B) $_ $_) ( (legacy-functor $B call 1) (set-det) (writel (:: Prolog.Call1)))) +; + (= (bodycont (= $_ $B) $_ $_) ( (legacy-functor $B call 2) (set-det) (writel (:: Prolog.Call2)))) +; + (= (bodycont (= $_ $B) $_ $_) ( (legacy-functor $B cut 2) (set-det) (writel (:: Prolog.Call1)))) +; + (= (bodycont (= $_ $B) $_ $_) ( (legacy-functor $B $Name $Arity) (writel (:: $Name $Arity cont)))) +; + (= (decl-deref-args -1) (set-det)) +; + (= (decl-deref-args $N) ( (writel (:: 'Term areg' $N ' = local-aregs[' $N '].Deref() ;' (wr nl))) (is $M (- $N 1)) (decl-deref-args $M))) +; + (= (initforeachcontinuation () $_ $_) True) +; + (= (initforeachcontinuation (Cons (/ $N $A) $R) $N $A) ( (set-det) (initforeachcontinuation $R $N $A))) -; ; this is entry code ! - +; (= (initforeachcontinuation (Cons (/ call 1) $R) $N $A) ( (set-det) (initforeachcontinuation $R $N $A))) -; ; Call1 - +; (= (initforeachcontinuation (Cons (/ call 2) $R) $N $A) ( (set-det) (initforeachcontinuation $R $N $A))) -; ; Call2 - +; (= (initforeachcontinuation (Cons (/ cut 2) $R) $N $A) ( (set-det) (initforeachcontinuation $R $N $A))) -; ; Cut2 - +; (= (initforeachcontinuation @@ -572,6 +724,8 @@ (- $A 1)) (writel (:: $N $A 'cont = pred-' $N - $B '.entry-code ;' (wr nl))) (initforeachcontinuation $R $Name $Arity))) +; + (= (initforeachcontinuation (Cons @@ -580,15 +734,21 @@ (- $A 1)) (writel (:: $N $A 'cont = mach.LoadPred("' $N ", $B ) ; (wr nl))) (initforeachcontinuation $R $Name $Arity))) +; + (= (aregarray $N) (aregarray 0 $N)) +; + (= (aregarray $N $Max) ( (> $N $Max) (set-det))) +; + (= (aregarray $N $Max) ( (det-if-then-else @@ -597,11 +757,15 @@ (is $M (+ $N 1)) (writel (:: mach.Areg[ $N ])) - (aregarray $M $Max))) + (aregarray $M $Max))) +; + (= (declforeachclause () $_ $_) True) +; + (= (declforeachclause (Cons $_ $R) $N $ClassName) @@ -609,35 +773,49 @@ (is $M (+ $N 1)) (declforeachclause $R $M $ClassName))) +; + (= (declforeachcontinuation () $_ $_) True) +; + (= (declforeachcontinuation (Cons (/ $N $A) $R) $N $A) ( (set-det) (declforeachcontinuation $R $N $A))) +; + (= (declforeachcontinuation (Cons (/ call 1) $R) $N $A) ( (set-det) (declforeachcontinuation $R $N $A))) +; + (= (declforeachcontinuation (Cons (/ call 2) $R) $N $A) ( (set-det) (declforeachcontinuation $R $N $A))) +; + (= (declforeachcontinuation (Cons (/ $N $A) $R) $Name $Arity) ( (writel (:: 'static Code ' $N $A 'cont ;' (wr nl))) (declforeachcontinuation $R $Name $Arity))) +; + (= (declforeachstring () $_) True) +; + (= (declforeachstring (Cons $N $R) $M) @@ -645,13 +823,19 @@ (+ $M 1)) (writel (:: 'static Const string' $M ' = Const.Intern("' $N ") ; (wr nl))) (declforeachstring $R $MM))) +; + (= (declforeachint ()) True) +; + (= (declforeachint (Cons $N $R)) ( (writel (:: 'static Int ' (posneg $N) ' = Term.Number(' $N ) ; (wr nl))) (declforeachint $R))) +; + (= @@ -661,9 +845,13 @@ (is $M (- 0 $N)) (writel (:: negint $M)))) +; + (= (posneg $N) (writel (:: posint $N))) +; + @@ -671,6 +859,8 @@ (getnameindex (Cons $N $_) $N $In $In) (set-det)) +; + (= (getnameindex (Cons $_ $R) $N $In $Out) @@ -678,8 +868,12 @@ (+ $In 1)) (getnameindex $R $N $I $Out) (set-det))) +; + (= (getnameindex $_ $_ $In $In) True) +; + (= @@ -688,20 +882,28 @@ (= $_ $B) $_) (/ $N $A)) (legacy-functor $B $N $A)) +; + (= (continuationof (Cons $_ $R) $F) (continuationof $R $F)) +; + (= (stringof (Cons $Cl $_) $F) (strings1 $Cl $F)) +; + (= (stringof (Cons $_ $R) $F) (stringof $R $F)) +; + (= @@ -709,29 +911,43 @@ ( (var $X) (set-det) (fail))) +; + (= (strings1 (, $A $_) $F) (strings1 $A $F)) +; + (= (strings1 (, $_ $B) $F) ( (set-det) (strings1 $B $F))) +; + (= (strings1 (= $A $_) $F) (strings1 $A $F)) +; + (= (strings1 (= $_ $B) $F) ( (set-det) (strings1 $B $F))) +; + (= (strings1 $T $F) ( (legacy-functor $T $N $_) (= $F $N))) +; + (= (strings1 $T $F) ( (=.. $T (Cons $_ $Args)) (stringsl $Args $F))) +; + (= @@ -739,43 +955,61 @@ ( (var $X) (set-det) (fail))) +; + (= (strings $A $F) ( (atom $A) (set-det) (= $F $A))) +; + (= (strings $A $_) ( (atomic $A) (set-det) (fail))) +; + (= (strings $T $F) ( (legacy-functor $T $N $_) (= $F $N))) +; + (= (strings $T $F) ( (=.. $T (Cons $_ $Args)) (stringsl $Args $F))) +; + (= (stringsl (Cons $T $_) $F) (strings $T $F)) +; + (= (stringsl (Cons $_ $R) $F) (stringsl $R $F)) +; + (= (intof (Cons $Cl $_) $F) (ints $Cl $F)) +; + (= (intof (Cons $_ $R) $F) (intof $R $F)) +; + (= @@ -783,27 +1017,35 @@ ( (var $X) (set-det) (fail))) +; + (= (ints $A $F) ( (integer $A) (set-det) (= $F $A))) +; + (= (ints $A $_) ( (atomic $A) (set-det) (fail))) +; + (= (ints $T $F) ( (=.. $T (Cons $_ $Args)) (intof $Args $F))) +; + ; -; the following are also in someMeTTa at the moment +; @@ -812,79 +1054,111 @@ (< $X $Y) (smallerthan $X $Y)) (set-det)) +; + (= (specialgoal (=< $X $Y) (smallerorequal $X $Y)) (set-det)) +; + (= (specialgoal (> $X $Y) (smallerthan $Y $X)) (set-det)) +; + (= (specialgoal (>= $X $Y) (smallerorequal $Y $X)) (set-det)) +; + (= (specialgoal (=:= $X $Y) (arithequal $Y $X)) (set-det)) +; + (= (specialgoal (= $X $Y) (unify $Y $X)) (set-det)) +; + (= (specialgoal (or $X $Y) (or $X $Y)) (set-det)) +; + (= (specialgoal (@< $X $Y) (termsmallerthan $X $Y)) (set-det)) +; + (= (specialgoal (@> $X $Y) (termgreaterthan $X $Y)) (set-det)) +; + (= (specialgoal (@=< $X $Y) (termsmallerequal $X $Y)) (set-det)) +; + (= (specialgoal (@>= $X $Y) (termgreaterequal $X $Y)) (set-det)) +; + (= (specialgoal (== $X $Y) (termequal $X $Y)) (set-det)) +; + (= (specialgoal (not $X) (not $X)) (set-det)) +; + (= (w-cl (:: $Pred)) ( (set-det) (format ~N~p.~n (:: $Pred)))) +; + (= (w-cl (Cons $Prev $Pred)) ( (set-det) (w-cl $Pred) (w-cl $Prev))) +; + (= (w-cl $Pred) (w-cl (:: $Pred))) +; + (= @@ -896,16 +1170,22 @@ (write */ ))) +; + (= (prelude) ( (write '// Generated code file - by dmiles') (nl) (fail))) +; + (= (prelude) ( (write '// Copyright August 16, 1996,2018 LOGICMOO, KUL and CUM') (nl) (fail))) +; + (= (prelude) ( (write '// Authors: Douglas R. Miles, Bart Demoen and Paul Tarau @@ -913,27 +1193,35 @@ import SxxMachine.*; ') (nl) (nl) (fail))) +; + (= prelude True) +; + ; -; main :- comp('board') , fail . +; ; -; main :- comp('test') , fail . +; ; -; main :- comp('read.pl') , fail . +; ; -; main :- comp('someMeTTa') , fail . +; ; -; main :- comp('chat') , fail . +; ; -; main :- comp('boyer') , fail . +; !(comp sxx-library.pl) +; + !(comp tests/animal.pl) +; + diff --git a/sxx_machine/sxx_compiler_gen_static.metta b/sxx_machine/sxx_compiler_gen_static.metta index 7ba6a92..5fd04ef 100644 --- a/sxx_machine/sxx_compiler_gen_static.metta +++ b/sxx_machine/sxx_compiler_gen_static.metta @@ -1,88 +1,138 @@ (= (append () $L $L) True) +; + (= (append (Cons $X $L1) $L2 (Cons $X $L3)) (append $L1 $L2 $L3)) +; + (= (legacy-functor $P . $A) ( (functor $P Cons $A) (set-det))) +; + (= (legacy-functor $P $F $A) ( (functor $P $F $A) (set-det))) +; + !(dynamic (/ system-predicate 1)) +; + !(multifile (/ system-predicate 1)) +; + ; -; system_predicate('$builtin_member'(_,_)). +; (= (system_predicate ($erase $_)) True) +; + (= (system_predicate - ($fast_write $_)) True) + (%fast_write $_)) True) +; + (= (system_predicate - ($fast_write $_ $_)) True) + (%fast_write $_ $_)) True) +; + (= (system_predicate ($call $_ $_)) True) +; + (= (system_predicate (mutex_lock_bt $_)) True) +; + (= (system_predicate - ($set_exception $_)) True) + (%set_exception $_)) True) +; + (= (system_predicate - ($get_exception $_)) True) + (%get_exception $_)) True) +; + (= (system_predicate - ($get_current_B $_)) True) + (%get_current_B $_)) True) +; + (= (system_predicate ($compare0 $_ $_ $_)) True) +; + (= (system_predicate - ($compiled_predicate $_ $_ $_)) True) + (%compiled_predicate $_ $_ $_)) True) +; + (= (system_predicate - ($compiled_predicate_or_builtin $_ $_ $_)) True) + (%compiled_predicate_or_builtin $_ $_ $_)) True) +; + (= (system_predicate - ($hash_remove_first $_ $_ $_)) True) + (%hash_remove_first $_ $_ $_)) True) +; + (= (system_predicate - ($hash_adda $_ $_ $_)) True) + (%hash_adda $_ $_ $_)) True) +; + (= (system_predicate - ($hash_addz $_ $_ $_)) True) + (%hash_addz $_ $_ $_)) True) +; + (= (system_predicate - ($read_token0 $_ $_ $_)) True) + (%read_token0 $_ $_ $_)) True) +; + (= (system_predicate - ($atom_type0 $_ $_)) True) + (%symbol_type0 $_ $_)) True) +; + (= (system_predicate - ($begin_sync $_ $_)) True) + (%begin_sync $_ $_)) True) +; + !(consult sxx-system) +; + (= (comp $FileSpec) (comp-to $FileSpec ../jsrc/bootlib)) +; + (= @@ -98,11 +148,12 @@ (solutions all))) (exists-file $File)) (comp-to $File $Where)))) +; + (= (comp-to $File $Dir0) ( (must-det-l (, (makename (:: $Dir0 / SxxMachine) $Dir) (set-det) (exists-file $File) (file-base-name $File $Base) (file-name-extension $Stem $_ $Base) (makename (:: $Dir / $Stem .java) $FileName) (set-det) (wdmsg (comp-to $File $Dir $FileName)) (make-directory-path $Dir) (set-det) (nb-setval stem $Stem) (= $InProg Nil) (see $File) (readprogram $Stem $InProg $Prog) (set-det) (seen) (tell $FileName) (gencode-sss $Dir $Stem $Prog) (set-det) (told))) (set-det))) -; ; close(File) , - +; @@ -111,24 +162,38 @@ (= (call-local-side-efs (public $_)) (set-det)) +; + (= (call-local-side-efs (package $V)) (nb-setval package $V)) +; + (= (call-local-side-efs (if $_)) (set-det)) +; + (= (call-local-side-efs (determinate $_)) (set-det)) +; + (= (call-local-side-efs (comp $_)) (set-det)) +; + (= (call-local-side-efs (comp-to $_ $_)) (set-det)) +; + (= (call-local-side-efs $Call) (ignore (call $Call))) +; + (= @@ -139,10 +204,14 @@ (== $Until !(endif)) (set-det))) +; + (= (local-side-efs $_ !$Call) ( (call-local-side-efs $Call) (set-det))) +; + (= (local-side-efs $_ $H) ( (\= $H @@ -150,14 +219,18 @@ (set-det) (local-side-efs $_ (= $H True)))) +; + ; -; local_side_efs(_, (H:-_)):- ( predicate_property(H,static) ; predicate_property(H,built_in) ),!. +; ; -; local_side_efs(_, (Call)):- call(assertz(Call)),!. +; (= (local_side_efs $_ $Clause) True) +; + @@ -172,9 +245,11 @@ (binarize $Clause $BinCl) (addclausetoprogram $BinCl $In $NewIn) (readprogram $Stem $NewIn $Out))))) +; + ; -; binarize((Head ::- Body),Cl) :- ! , Cl = (Head :- Body) . +; @@ -187,6 +262,8 @@ (binarize (= $Pred (write $C)) $Out))) +; + (= (binarize !$C $Out) @@ -195,6 +272,8 @@ (set-det) (binarize (= $Pred $C) $Out))) +; + (= (binarize (= $Head $Body) @@ -202,11 +281,15 @@ ( (set-det) (addcont $Head $Continuation $BinHead) (makebinbody $Body $Continuation $BinBody))) +; + (= (binarize $Head (= $BinHead (call $Continuation))) (addcont $Head $Continuation $BinHead)) +; + (= @@ -215,6 +298,8 @@ (set-det) (makebinbody (call $G) $C $NewBody))) +; + (= (makebinbody @@ -222,23 +307,33 @@ ( (set-det) (makebinbody $B $C $NewB) (addcont $G $NewB $NewBody))) +; + (= (makebinbody $SpecialGoal $C $NewBody) ( (specialgoal $SpecialGoal $G) (set-det) (addcont $G $C $NewBody))) +; + (= (makebinbody (set-det) $C $NewBody) ( (set-det) (= $NewBody (cut 1 $C)))) +; + (= (makebinbody $G $C $NewBody) ( (set-det) (addcont $G $C $NewBody))) +; + (= (addclausetoprogram $Cl Nil $ProgOut) ( (set-det) (= $ProgOut (:: (:: $Cl))))) +; + (= (addclausetoprogram $Cl (Cons $Pred $Rest) $Out) @@ -247,11 +342,15 @@ (= $Out (Cons (Cons $Cl $Pred) $Rest)))) +; + (= (addclausetoprogram $Cl (Cons $Pred $Rest) (Cons $Pred $NewRest)) (addclausetoprogram $Cl $Rest $NewRest)) +; + @@ -261,6 +360,8 @@ (Cons (= $H2 $_) $_)) ( (legacy-functor $H1 $N $A) (legacy-functor $H2 $N $A))) +; + @@ -271,11 +372,15 @@ (addcont (set-det) $C $FB) ( (set-det) (= $FB (cut 1 $C)))) +; + (= (addcont $S $C $NG) ( (specialgoal $S $NS) (set-det) (addcont $NS $C $NG))) +; + (= (addcont $F $C $FB) ( (=.. $F @@ -284,6 +389,8 @@ (:: $C) $NA) (=.. $FB (Cons $N $NA)))) +; + @@ -292,11 +399,15 @@ ( (== $EOL Nil) (set-det) (= $Out ''))) +; + (= (makename $Atom $Out) ( (atomic $Atom) (set-det) (= $Out $Atom))) +; + (= (makename (Cons $AC $Rest) $OutC) @@ -305,43 +416,63 @@ (name $AC $AL) (append $AL $OL $OutL) (name $OutC $OutL))) +; + (= (writel ()) True) +; + (= (writel (Cons $X $R)) ( (wr $X) (writel $R))) +; + (= (wr (getval $Var)) (must (, (nb-current $Var $Value) (write $Value)))) +; + (= (wr (wr nl)) ( (set-det) (nl))) +; + (= (wr $Atom) ( (atomic $Atom) (set-det) (write $Atom))) +; + (= (wr $VAR) ( (legacy-functor $VAR %VAR 2) (set-det) (write $VAR))) +; + (= (wr $Goal) ( (must (call $Goal)) (set-det))) +; + (= (wrargs $N $T) (wrargs $N $T $_)) +; + (= (wrargs $N $_ $_) ( (= $N 0) (set-det))) +; + (= (wrargs $N $T $Komma) ( (det-if-then-else @@ -352,12 +483,14 @@ (is $M (- $N 1)) (wrargs $M $T $Komma))) +; + ; -; Pred is a list of clauses for a specific predicate +; ; -; it is binarized and also in reverse order +; @@ -379,13 +512,19 @@ public class ' $Stem ' /*extends CodeFile*/ { ))))) +; + (= (gencode_sss $_ $_ $_ ()) True) +; + (= (gencode-sss $Strings $Dir $Stem (Cons $Pred $Preds)) ( (gencodeforpred $Strings $Dir $Stem $Pred) (gencode-sss $Strings $Dir $Stem $Preds))) +; + (= @@ -393,11 +532,13 @@ public class ' $Stem ' /*extends CodeFile*/ { ( (= $Pred (:: (= $H $B))) (== $H $B) - (add-atom &self + (add-symbol &self (system_predicate $H)) (set-det) (format '~N/* System pred ~q */~n' (:: $H)))) +; + (= (gencodeforpred $Strings $Dir $Stem $Pred) @@ -410,10 +551,12 @@ public class ' $Stem ' /*extends CodeFile*/ { (make-classname $PN $AA $N $ClassName) (nb-setval classname $ClassName) (gencodeforpred $Strings $Dir $Stem $Pred $H $N $A $AA $ClassName))) +; + ; -; (isSort(X),isSort(Y))-> (all Q hasSort(Q,X) +; @@ -421,60 +564,52 @@ public class ' $Stem ' /*extends CodeFile*/ { (= (symbol-to-name $Atom $Out) ( (symbol-to-name1 $Atom $Out) (set-det))) +; + (= (symbol_to_name $Name $Name) True) +; + (= (symbol-to-name1 or or) (set-det)) -; /* -; symbol_to_name1((':-'),'system_neck'). -; symbol_to_name1(('=..'),'system_univ'). -; symbol_to_name1(('=@='),'system_variant'). -; symbol_to_name1(('\\+'),'system_not'). -; symbol_to_name1(('\\='),'system_notequals'). -; symbol_to_name1(('='),'system_equals'). -; symbol_to_name1(('=='),'strict_eq'). -; symbol_to_name1(('\\=='),'strict_noteq'). -; symbol_to_name1(('-->'),'dcg_arrow'). -; symbol_to_name1(('->'),'if_then_arrow'). -; symbol_to_name1(('*->'),'with_each_arrow'). -; symbol_to_name1((','),'system_comma'). -; symbol_to_name1(('^'),'system_carrot'). -; symbol_to_name1(('|'),'system_bar'). -; symbol_to_name1((':'),'system_colon'). -; -; ; -; -; -; */ - (= (symbol-to-name1 : module-colon) (set-det)) +; + (= (symbol-to-name1 $S $O) ( (functor $P $S 2) (specialgoal $P $PP) (functor $PP $O $_) (set-det))) +; + (= (symbol-to-name1 $S $O) ( (functor $P $S 1) (specialgoal $P $PP) (functor $PP $O $_) (set-det))) +; + (= (symbol-to-name1 $A $B) ( (symbol-to-name2 $A $B) (set-det))) +; + (= (symbol-to-name2 '' '') (set-det)) +; + (= (symbol-to-name2 $Atom $Out) @@ -490,6 +625,8 @@ public class ' $Stem ' /*extends CodeFile*/ { (name $NAtom $Rest) (symbol-to-name2 $NAtom $Mid2) (atom-concat $Mid1 $Mid2 $Out))) +; + (= (symbol-to-name2 $Atom $Out) @@ -504,6 +641,8 @@ public class ' $Stem ' /*extends CodeFile*/ { (name $NAtom $Rest) (symbol-to-name2 $NAtom $Mid2) (atom-concat $Mid1 $Mid2 $Out))) +; + (= (symbol-to-name2 $Atom $Out) @@ -514,6 +653,8 @@ public class ' $Stem ' /*extends CodeFile*/ { (name $NAtom $Rest) (symbol-to-name2 $NAtom $Mid2) (atom-concat $Mid1 $Mid2 $Out))) +; + @@ -525,10 +666,14 @@ public class ' $Stem ' /*extends CodeFile*/ { (\== $Sym $N) (set-det) (make-classname $N $AA $NN $ClassName)))) +; + (= (make-classname $N $AA $N $ClassName) ( (makename (:: pred- $N - $AA) $ClassName) (set-det))) +; + (= @@ -538,14 +683,7 @@ public class ' $Stem ' /*extends CodeFile*/ { ))))) -; ;mysetof(F,Pred^continuationof(Pred,F),Conts) , - -; ; declforeachcontinuation(Conts,N,A), - -; ;declforeachclause(Pred,1,ClassName), - -; ; writel(['static {', initforeachcontinuation(Conts,N,A),'}',wr(nl)]), - +; @@ -554,17 +692,25 @@ public class ' $Stem ' /*extends CodeFile*/ { (= (cont-ref $N) (must-det (writel (:: (getval classname) ::exec- (getval classname) -- $N)))) +; + (= (mysetof $X $Y $Z) ( (setof $X $Y $Z) (set-det))) +; + (= (mysetof $_ $_ ()) True) +; + (= (genpredcode $PreDecl () $_ $_ 0 $_) True) +; + (= (genpredcode $Strings (Cons $Clause $Rest) $Last $ClassName $M $Strings) @@ -572,6 +718,8 @@ public class ' $Stem ' /*extends CodeFile*/ { (is $M (+ $N 1)) (genclausecode $Strings $Clause $Last $ClassName $M $Strings))) +; + (= @@ -580,6 +728,8 @@ public class ' $Stem ' /*extends CodeFile*/ { (= $Head $Body)) (set-det) (must-det-l (, (legacy-functor $Head $Name0 $Arity) (symbol-to-name $Name0 $Name) (is $Amin2 (- $Arity 2)) (is $Amin1 (- $Arity 1)) (arg $Arity $Head ($cont $Arity)) (writel (:: 'public static Operation exec-' $ClassName -- $N '(Prolog mach){ ' (det-if-then-else (= $Last last) (write 'mach.RemoveChoice() ;') (, (is $M (+ $N 1)) (writel (:: mach.FillAlternative( (cont-ref $M) ) ;)))) (wr nl) 'Term local-aregs[] = mach.Areg ;' (wr nl) 'Term continuation = local-aregs[' $Amin1 ] ; (wr nl) (decl-deref-args $Amin2) (mynumbervars $Clause 1 $NumbVars) (det-if-then-else (> $NumbVars 1) (declvars $NumbVars) True) (gets $Head $Strings) (puts $Body $Strings) 'mach.CUTB = mach.CurrentChoice ;' (wr nl) (nullifyaregs $Clause) 'return ' (bodycont $Strings $Clause $Name $Arity) ;} (wr nl))))))) +; + @@ -591,8 +741,12 @@ public class ' $Stem ' /*extends CodeFile*/ { (- $HA $BA)) (> $Diff 0) (nullify $Diff $HA))) +; + (= (nullifyaregs $_) True) +; + (= @@ -601,6 +755,8 @@ public class ' $Stem ' /*extends CodeFile*/ { (write 'null ;') (nl) (fail))) +; + (= (nullify $N $K) ( (is $L @@ -609,6 +765,8 @@ public class ' $Stem ' /*extends CodeFile*/ { (is $M (- $N 1)) (nullify $M $L))) +; + (= @@ -619,27 +777,39 @@ public class ' $Stem ' /*extends CodeFile*/ { ($VAR $I $_)) (is $O (+ $I 1)))) +; + (= (mynumbervars ($VAR $_ $_) $I $O) ( (set-det) (= $I $O))) +; + (= (mynumbervars $A $I $O) ( (atomic $A) (set-det) (= $I $O))) +; + (= (mynumbervars $Term $I $O) ( (=.. $Term (Cons $_ $Args)) (mynumbervarslist $Args $I $O))) +; + (= (mynumbervarslist () $I $I) True) +; + (= (mynumbervarslist (Cons $T $R) $I $O) ( (mynumbervars $T $I $II) (mynumbervarslist $R $II $O))) +; + @@ -647,12 +817,16 @@ public class ' $Stem ' /*extends CodeFile*/ { (gets $Head $Strings) ( (=.. $Head (Cons $_ $Args)) (gets $Args 0 $Strings))) +; + (= (gets (:: $_) $_ $_) - (set-det)) ; -; this is the continuation ! + (set-det)) +; + ; +; (= (gets @@ -661,11 +835,15 @@ public class ' $Stem ' /*extends CodeFile*/ { (+ $N 1)) (getforarg $Arg $N $Strings) (gets $Args $M $Strings))) +; + (= (getforarg $Arg $N $Strings) (writel (:: 'if (!( (areg' $N ).Unify( (constructterm $Arg $Strings) ',mach))) return Prolog.Fail0 ;' (wr nl)))) +; + @@ -675,13 +853,19 @@ public class ' $Stem ' /*extends CodeFile*/ { ( (set-det) (writel (:: 'mach.DoCut(mach.CUTB) ;' (wr nl))) (putforarg $C 0 $Strings))) +; + (= (puts $Body $Strings) ( (=.. $Body (Cons $_ $Args)) (puts $Args 0 $Strings))) +; + (= (puts () $_ $_) True) +; + (= (puts (Cons $Arg $Args) $N $Strings) @@ -689,30 +873,38 @@ public class ' $Stem ' /*extends CodeFile*/ { (+ $N 1)) (putforarg $Arg $N $Strings) (puts $Args $M $Strings))) +; + (= (putforarg $Arg $N $Strings) (writel (:: local-aregs[ $N ] = (constructterm $Arg $Strings) ; (wr nl)))) +; + (= (declvars 1) (set-det)) +; + (= (declvars $N) ( (is $M (- $N 1)) (writel (:: 'Var var' $M ' = Data.V(mach) ;' (wr nl))) (declvars $M))) +; + ; -; variables are replaced with '$VAR'(integer,_) +; ; -; continuation is replaced by '$cont'(arity) +; @@ -720,18 +912,24 @@ public class ' $Stem ' /*extends CodeFile*/ { (constructterm ($cont $_) $_) ( (set-det) (writel (:: continuation)))) +; + (= (constructterm ($VAR $N $T) $_) ( (set-det) (det-if-then-else (var $T) (, (writel (:: var $N)) (= $T 1)) (writel (:: var $N .Deref()))))) +; + ; -; constructterm(cut(_,C),Strings) :- ! , writel(['Data.F("cut",new HeapChoice(mach.CUTB),',constructterm(C,Strings),')']) . +; (= (constructterm (cut $_ $C) $Strings) ( (set-det) (writel (:: mach.HC( (constructterm $C $Strings) ))))) +; + (= (constructterm $Int $_) @@ -739,38 +937,52 @@ public class ' $Stem ' /*extends CodeFile*/ { (set-det) (writel (:: (getval stem) .)) (posneg $Int))) +; + (= (constructterm $Atom $Strings) ( (string $Atom) (set-det) (writeConst $Atom $Strings))) +; + (= (constructterm $Int $_) ( (float $Int) (set-det) (writel (:: Data.Float( $Int ))) (set-det))) +; + (= (constructterm $Atom $Strings) ( (== Nil $Atom) (set-det) (writeConst $Atom $Strings))) +; + (= (constructterm $Atom $Strings) ( (atom $Atom) (set-det) (writeConst $Atom $Strings))) +; + (= (constructterm $Term $Strings) ( (compound $Term) (set-det) (must-det-l (, (legacy-functor $Term $Name $_) (=.. $Term (Cons $_ $Args)) (writel (:: Data.F( (writeConst $Name $Strings) , (newargs $Args 1 $Strings) ))))))) +; + (= (writeConst Nil $Strings) ( (writel (:: Const.Nil)) (set-det))) +; + (= (writeConst $Name $Strings) (det-if-then @@ -782,24 +994,34 @@ public class ' $Stem ' /*extends CodeFile*/ { (set-det) (writel (:: (getval stem) .s- $Name)) (set-det)))) +; + (= (writeConst $Name $Strings) ( (getnameindex $Strings $Name 0 $I) (set-det) (writel (:: (getval stem) .s $I)) (set-det))) +; + (= (writeConst $Name $Strings) ( (must-det-l (, (atom-string $Name $S) (writel (:: Const.Intern( (format ~q (:: $S)) ))))) (set-det))) +; + (= (newargs () $_ $_) True) +; + (= (newargs (Cons $A $Args) $N $Strings) (must-det-l (, (det-if-then-else (> $N 1) (write ,) True) (is $M (+ $N 1)) (constructterm $A $Strings) (newargs $Args $M $Strings)))) +; + @@ -812,26 +1034,34 @@ public class ' $Stem ' /*extends CodeFile*/ { (legacy-functor $B $Name $Arity) (set-det) (writel (:: entry-code)))) +; + (= (bodycont $String (= $_ $B) $_ $_) ( (legacy-functor $B call 1) (set-det) (writel (:: Prolog.Call1)))) +; + (= (bodycont $String (= $_ $B) $_ $_) ( (legacy-functor $B call 2) (set-det) (writel (:: Prolog.Call2)))) +; + (= (bodycont $String (= $_ $B) $_ $_) ( (legacy-functor $B cut 2) (set-det) (writel (:: Prolog.Call1)))) +; + ; -; bodycont(_String,(_ :- B),_,_) :- legacy_functor(B,cut,2) , ! , writel(['MeTTa.Cut2']) . +; (= @@ -844,6 +1074,8 @@ public class ' $Stem ' /*extends CodeFile*/ { (is $MArity (- $Arity 1)) (writel (:: '(Operation) ' (getval stem) .s $I .FindProc( $MArity ))))) +; + (= @@ -856,6 +1088,8 @@ public class ' $Stem ' /*extends CodeFile*/ { (system-predicate $P) (set-det) (writel (:: '(Operation) ' (writeConst $Name $String) .FindProc( $MArity ))))) +; + (= (bodycont $String @@ -865,6 +1099,8 @@ public class ' $Stem ' /*extends CodeFile*/ { (- $Arity 1)) (symbol-to-name $Name0 $Name) (writel (:: (Operation)pred- $Name - $MArity ::exec-static)))) +; + (= @@ -873,63 +1109,73 @@ public class ' $Stem ' /*extends CodeFile*/ { ( (legacy-functor $B $Name0 $Arity) (symbol-to-name $Name0 $Name) (writel (:: $Name $Arity cont)))) +; + (= (decl-deref-args -1) (set-det)) +; + (= (decl-deref-args $N) ( (writel (:: 'Term areg' $N ' = local-aregs[' $N '].Deref() ;' (wr nl))) (is $M (- $N 1)) (decl-deref-args $M))) +; + (= (use_entry_code $F $A) (empty)) +; + (= (use_static_call $F $A) True) +; + (= (use_load_pred $F $A) True) +; + (= (initforeachcontinuation () $_ $_) True) +; + (= (initforeachcontinuation (Cons (/ $N $A) $R) $N $A) ( (set-det) (initforeachcontinuation $R $N $A))) -; ; this is entry code ! - +; (= (initforeachcontinuation (Cons (/ call 1) $R) $N $A) ( (set-det) (initforeachcontinuation $R $N $A))) -; ; Call1 - +; (= (initforeachcontinuation (Cons (/ call 2) $R) $N $A) ( (set-det) (initforeachcontinuation $R $N $A))) -; ; Call2 - +; (= (initforeachcontinuation (Cons (/ cut 2) $R) $N $A) ( (set-det) (initforeachcontinuation $R $N $A))) -; ; Cut2 - +; (= (initforeachcontinuation @@ -940,6 +1186,8 @@ public class ' $Stem ' /*extends CodeFile*/ { (symbol-to-name $N $SN) (writel (:: $N $A 'cont = pred-' $N - $B ::exec-pred- $SN -- $B or (wr nl))) (initforeachcontinuation $R $Name $Arity))) +; + (= (initforeachcontinuation (Cons @@ -950,15 +1198,21 @@ public class ' $Stem ' /*extends CodeFile*/ { (- $A 1)) (writel (:: $N $A 'cont = mach.LoadPred("' $N ", $B ) ; (wr nl))) (initforeachcontinuation $R $Name $Arity))) +; + (= (aregarray $N) (aregarray 0 $N)) +; + (= (aregarray $N $Max) ( (> $N $Max) (set-det))) +; + (= (aregarray $N $Max) ( (det-if-then-else @@ -967,11 +1221,15 @@ public class ' $Stem ' /*extends CodeFile*/ { (is $M (+ $N 1)) (writel (:: mach.Areg[ $N ])) - (aregarray $M $Max))) + (aregarray $M $Max))) +; + (= (declforeachclause () $_ $_) True) +; + (= (declforeachclause (Cons $_ $R) $N $ClassName) @@ -979,31 +1237,43 @@ public class ' $Stem ' /*extends CodeFile*/ { (is $M (+ $N 1)) (declforeachclause $R $M $ClassName))) +; + (= (declforeachcontinuation () $_ $_) True) +; + (= (declforeachcontinuation (Cons (/ $N $A) $R) $N $A) ( (set-det) (declforeachcontinuation $R $N $A))) +; + (= (declforeachcontinuation (Cons (/ call 1) $R) $N $A) ( (set-det) (declforeachcontinuation $R $N $A))) +; + (= (declforeachcontinuation (Cons (/ call 2) $R) $N $A) ( (set-det) (declforeachcontinuation $R $N $A))) +; + (= (declforeachcontinuation (Cons (/ $N $A) $R) $Name $Arity) ( (writel (:: 'static Operation ' $N $A 'cont ;' (wr nl))) (declforeachcontinuation $R $Name $Arity))) +; + (= @@ -1017,13 +1287,19 @@ public class ' $Stem ' /*extends CodeFile*/ { (set-det) (writel (:: s- $N)) (set-det)))) +; + (= (varnamestr $M $_) ( (writel (:: s $M)) (set-det))) +; + (= (declforeachstring () $_) True) +; + (= (declforeachstring (Cons $N $R) $M) @@ -1031,14 +1307,20 @@ public class ' $Stem ' /*extends CodeFile*/ { (+ $M 1)) (declfor1string $N $M) (declforeachstring $R $MM))) +; + (= (declfor1string cut $M) ( (> $M 0) (set-det))) +; + (= (declfor1string $N $M) ( (atom-string $N $S) (writel (:: 'final static Const ' (varnamestr $M $N) ' = Data.Intern(' (writeq $S) ) ; (wr nl))))) +; + @@ -1052,21 +1334,31 @@ public class ' $Stem ' /*extends CodeFile*/ { (> $AInt $X) (set-det) (writel (:: 'Data.BigInt("' $Int "))))) +; + (= (constructnum $Int) ( (integer $Int) (set-det) (writel (:: Data.Number( $Int L))))) +; + (= (constructnum $Int) ( (float $Int) (writel (:: 'Data.BigDec("' $Int "))))) +; + (= (declforeachint ()) True) +; + (= (declforeachint (Cons $N $R)) ( (writel (:: 'final static Int ' (posneg $N) = (constructnum $N) ; (wr nl))) (declforeachint $R))) +; + (= @@ -1076,23 +1368,33 @@ public class ' $Stem ' /*extends CodeFile*/ { (is $M (- 0 $N)) (writel (:: negint $M)))) +; + (= (posneg $N) (writel (:: posint $N))) +; + (= (declforeachpred ()) True) +; + (= (declforeachpred (Cons $P $R)) ( (set-det) (declforeachpred1 $P) (declforeachpred $R))) +; + (= (declforeachpred1 (:: (= $P $A))) (== $P $A)) +; + (= (declforeachpred1 (Cons (= $P $_) $_)) ( (functor $P $F $A) @@ -1103,15 +1405,21 @@ public class ' $Stem ' /*extends CodeFile*/ { (atom-string $F $Str) (writel (:: 'final static Operation reg-' $Name - $AA ' = PredTable.Register(' (writeq $Str) , $AA ', new pred-' $Name - $AA ()); (wr nl))) (set-det))) +; + (= (declforeachpred1 $_) True) +; + (= (getnameindex (Cons $N $_) $N $In $In) (set-det)) +; + (= (getnameindex (Cons $_ $R) $N $In $Out) @@ -1119,8 +1427,10 @@ public class ' $Stem ' /*extends CodeFile*/ { (+ $In 1)) (getnameindex $R $N $I $Out) (set-det))) +; + ; -; getnameindex(_,_,In,In). +; @@ -1131,20 +1441,28 @@ public class ' $Stem ' /*extends CodeFile*/ { (= $_ $B) $_) (/ $N $A)) (legacy-functor $B $N $A)) +; + (= (continuationof (Cons $_ $R) $F) (continuationof $R $F)) +; + (= (stringof (Cons $Cl $_) $F) (strings1 $Cl $F)) +; + (= (stringof (Cons $_ $R) $F) (stringof $R $F)) +; + (= @@ -1152,29 +1470,43 @@ public class ' $Stem ' /*extends CodeFile*/ { ( (var $X) (set-det) (fail))) +; + (= (strings1 (, $A $_) $F) (strings1 $A $F)) +; + (= (strings1 (, $_ $B) $F) ( (set-det) (strings1 $B $F))) +; + (= (strings1 (= $A $_) $F) (strings1 $A $F)) +; + (= (strings1 (= $_ $B) $F) ( (set-det) (strings1 $B $F))) +; + (= (strings1 $T $F) ( (legacy-functor $T $N $_) (= $F $N))) +; + (= (strings1 $T $F) ( (=.. $T (Cons $_ $Args)) (stringsl $Args $F))) +; + (= @@ -1182,43 +1514,61 @@ public class ' $Stem ' /*extends CodeFile*/ { ( (var $X) (set-det) (fail))) +; + (= (strings $A $F) ( (atom $A) (set-det) (= $F $A))) +; + (= (strings $A $_) ( (atomic $A) (set-det) (fail))) +; + (= (strings $T $F) ( (legacy-functor $T $N $_) (= $F $N))) +; + (= (strings $T $F) ( (=.. $T (Cons $_ $Args)) (stringsl $Args $F))) +; + (= (stringsl (Cons $T $_) $F) (strings $T $F)) +; + (= (stringsl (Cons $_ $R) $F) (stringsl $R $F)) +; + (= (intof (Cons $Cl $_) $F) (ints $Cl $F)) +; + (= (intof (Cons $_ $R) $F) (intof $R $F)) +; + (= @@ -1226,20 +1576,28 @@ public class ' $Stem ' /*extends CodeFile*/ { ( (var $X) (set-det) (fail))) +; + (= (ints $A $F) ( (integer $A) (set-det) (= $F $A))) +; + (= (ints $A $_) ( (atomic $A) (set-det) (fail))) +; + (= (ints $T $F) ( (=.. $T (Cons $_ $Args)) (intof $Args $F))) +; + @@ -1247,10 +1605,14 @@ public class ' $Stem ' /*extends CodeFile*/ { (predof (Cons $Cl $_) $F) (preds $Cl $F)) +; + (= (predof (Cons $_ $R) $F) (predof $R $F)) +; + (= @@ -1258,16 +1620,20 @@ public class ' $Stem ' /*extends CodeFile*/ { ( (var $X) (set-det) (fail))) +; + (= (preds $P (/ $F $A)) ( (functor $P $F $A) (set-det))) +; + ; -; the following are also in someMeTTa at the moment +; @@ -1276,79 +1642,111 @@ public class ' $Stem ' /*extends CodeFile*/ { (< $X $Y) (smallerthan $X $Y)) (set-det)) +; + (= (specialgoal (=< $X $Y) (smallerorequal $X $Y)) (set-det)) +; + (= (specialgoal (> $X $Y) (smallerthan $Y $X)) (set-det)) +; + (= (specialgoal (>= $X $Y) (smallerorequal $Y $X)) (set-det)) +; + (= (specialgoal (=:= $X $Y) (arithequal $Y $X)) (set-det)) +; + (= (specialgoal (= $X $Y) (unify $Y $X)) (set-det)) +; + (= (specialgoal (or $X $Y) (or $X $Y)) (set-det)) +; + (= (specialgoal (@< $X $Y) (termsmallerthan $X $Y)) (set-det)) +; + (= (specialgoal (@> $X $Y) (termgreaterthan $X $Y)) (set-det)) +; + (= (specialgoal (@=< $X $Y) (termsmallerequal $X $Y)) (set-det)) +; + (= (specialgoal (@>= $X $Y) (termgreaterequal $X $Y)) (set-det)) +; + (= (specialgoal (== $X $Y) (termequal $X $Y)) (set-det)) +; + (= (specialgoal (not $X) (not $X)) (set-det)) +; + (= (w-cl (:: $Pred)) ( (set-det) (format ~N~p.~n (:: $Pred)))) +; + (= (w-cl (Cons $Prev $Pred)) ( (set-det) (w-cl $Pred) (w-cl $Prev))) +; + (= (w-cl $Pred) (w-cl (:: $Pred))) +; + (= @@ -1361,53 +1759,77 @@ public class ' $Stem ' /*extends CodeFile*/ { */ ))) +; + (= (prelude) ( (write '// Generated code file - by dmiles') (nl) (fail))) +; + (= (prelude) ( (write '// Copyright August 16, 1996,2018 LOGICMOO, KUL and CUM') (nl) (fail))) +; + (= (prelude) ( (write '// Authors: Douglas R. Miles, Bart Demoen and Paul Tarau') (nl) (nl) (fail))) +; + (= prelude True) +; + ; -; main :- comp('board') , fail . +; ; -; main :- comp('test') , fail . +; ; -; main :- comp('read.pl') , fail . +; ; -; main :- comp('someMeTTa') , fail . +; ; -; main :- comp('chat') , fail . +; ; -; main :- comp('boyer') , fail . +; !(comp-to sxx-system ../jsrc/bootlib) +; + !(comp-to sxx-read ../jsrc/bootlib) +; + !(comp-to sxx-library ../jsrc/bootlib) +; + !(comp-to sxx-meta ../jsrc/bootlib) +; + ; -; :- comp_to(sxx_compiler_gen_static,'../jsrc/compiler'). +; !(comp-to sxx-builtins-cafe ../jsrc/library) +; + !(comp-to tests/* ../jsrc/testing) +; + !(comp-to bench/* ../jsrc/benches) +; + diff --git a/sxx_machine/sxx_library.metta b/sxx_machine/sxx_library.metta index 7c930f2..2cc8b8b 100644 --- a/sxx_machine/sxx_library.metta +++ b/sxx_machine/sxx_library.metta @@ -2,9 +2,13 @@ (= (toplevel) ( (top) (fail))) +; + (= (toplevel) (toplevel)) +; + (= @@ -18,10 +22,14 @@ (notmore) (set-det) (fail))) +; + (= (top) (top)) +; + (= @@ -32,26 +40,40 @@ (set-det) (untilend $X) (fail))) +; + (= notmore True) +; + (= (noteq $X $X) ( (set-det) (fail))) +; + (= (noteq $_ $_) True) +; + (= (untilend 10) (set-det)) +; + (= (untilend $_) ( (get0 $X) (untilend $X))) +; + (= (writevars ()) True) +; + (= (writevars (Cons (= $Var $Name) $R)) ( (write $Name) @@ -59,44 +81,64 @@ (write $Var) (nl) (fail))) +; + (= (writevars (Cons $_ $R)) (writevars $R)) +; + (= (nrev Nil Nil) (set-det)) +; + (= (nrev (Cons $A $B) $O) ( (nrev $B $C) (append $C (:: $A) $O))) +; + (= (append () $L $L) True) +; + (= (append (Cons $A $L1) $L2 (Cons $A $L3)) (append $L1 $L2 $L3)) +; + (= (max $A $B $B) (smallerthan $A $B)) +; + (= (max $A $B $A) (smallerthan $B $A)) +; + (= (max $A $A $A) True) +; + (= (sort Nil Nil) (set-det)) +; + (= (sort (Cons $X $R) $Out) @@ -105,11 +147,15 @@ (sort $G $GS) (append $SS (Cons $X $GS) $Out))) +; + (= (split $X Nil Nil Nil) (set-det)) +; + (= (split $X (Cons $A $R) @@ -117,11 +163,15 @@ ( (smallerthan $A $X) (set-det) (split $X $R $S $G))) +; + (= (split $X (Cons $A $R) $S (Cons $A $G)) (split $X $R $S $G)) +; + (= @@ -133,6 +183,8 @@ (- $T2 $T1)) (write $T) (nl))) +; + @@ -141,25 +193,37 @@ ( (var $G) (set-det) (fail))) +; + (= ! (, $G $B) ( (set-det) !$G !$B)) +; + (= ! (det-if-then $If $Then) ( (set-det) (execdisj (det-if-then $If $Then) True))) +; + (= ! (or $B1 $B2) ( (set-det) (execdisj $B1 $B2))) +; + (= !$G ( (specialgoal $G $G1) (set-det) !$G1)) +; + (= !$G (call $G)) +; + (= @@ -168,48 +232,70 @@ ( !$If (set-det) !$Then)) +; + (= (execdisj (det-if-then $If $Then) $Else) ( (set-det) !$Else)) +; + (= (execdisj $B1 $B2) !$B1) +; + (= (execdisj $B1 $B2) !$B2) +; + (= (loop 0) (set-det)) +; + (= (loop $N) ( (is $M (- $N 1)) (loop $M))) +; + (= (or $X $_) !$X) +; + (= (or $_ $Y) !$Y) +; + (= (findall $X $Goal $L) ( (initfindall $Handle) (findall2 $X $Goal $L $Handle))) +; + (= (findall2 $X $Goal $L $Handle) ( !$Goal (addfindall $X $Handle) (fail))) +; + (= (findall2 $X $Goal $L $Handle) (retrievefindall $L $Handle)) +; + (= @@ -217,32 +303,46 @@ (findall $X (= $X $T1) (:: $T2))) +; + (= (var $X) (type-of $X var)) +; + (= (atomic $X) ( (type-of $X $A) (atomic2 $A))) +; + (= (atomic2 is-symbol) (set-det)) +; + (= (atomic2 integer) True) +; + (= (atom $X) (type-of $X is-symbol)) +; + (= (integer $X) (type-of $X integer)) +; + @@ -251,11 +351,15 @@ ( (assume (- $F $Tag)) !$G (= $Tag 1))) +; + (= (assumed $F) ( (allassumed $L) (m1 $F $L))) +; + (= @@ -263,20 +367,26 @@ (Cons (- $X $Tag) $_)) (var $Tag)) +; + (= (m1 $X (Cons $_ $R)) (m1 $X $R)) +; + (= (statistics runtime (:: $T $_)) (cputime $T)) +; + ; -; the following are also needed in the compiler at the moment +; @@ -285,97 +395,139 @@ (< $X $Y) (smallerthan $X $Y)) (set-det)) +; + (= (specialgoal (=< $X $Y) (smallerorequal $X $Y)) (set-det)) +; + (= (specialgoal (> $X $Y) (smallerthan $Y $X)) (set-det)) +; + (= (specialgoal (>= $X $Y) (smallerorequal $Y $X)) (set-det)) +; + (= (specialgoal (=:= $X $Y) (arithequal $Y $X)) (set-det)) +; + (= (specialgoal (= $X $Y) (unify $Y $X)) (set-det)) +; + (= (specialgoal (or $X $Y) (or $X $Y)) (set-det)) +; + (= (specialgoal (@< $X $Y) (termsmallerthan $X $Y)) (set-det)) +; + (= (specialgoal (@> $X $Y) (termgreaterthan $X $Y)) (set-det)) +; + (= (specialgoal (@=< $X $Y) (termsmallerequal $X $Y)) (set-det)) +; + (= (specialgoal (@>= $X $Y) (termgreaterequal $X $Y)) (set-det)) +; + (= (specialgoal (== $X $Y) (termequal $X $Y)) (set-det)) +; + (= (termsmallerthan $X $Y) (compare < $X $Y)) +; + (= (termgreaterthan $X $Y) (compare > $X $Y)) +; + (= (termsmallerequal $X $Y) ( (compare $C $X $Y) (smeq $C))) +; + (= (smeq <) (set-det)) +; + (= (smeq =) True) +; + (= (termgreaterequal $X $Y) ( (compare $C $X $Y) (smgr $C))) +; + (= (smgr >) (set-det)) +; + (= (smgr =) True) +; + (= (termequal $X $Y) (compare = $X $Y)) +; + @@ -384,8 +536,12 @@ ( !$G (set-det) (fail))) +; + (= (not $_) True) +; + @@ -394,15 +550,23 @@ ( (var $X) (set-det) (freeze-internal $X $G))) +; + (= (freeze $X $G) !$G) +; + (= (execpendinggoals Nil) (execcontinuation)) +; + (= (execpendinggoals (Cons $G $R)) ( !$G (execpendinggoals $R))) +; + diff --git a/sxx_machine/sxx_meta.metta b/sxx_machine/sxx_meta.metta index 07f690d..4143dac 100644 --- a/sxx_machine/sxx_meta.metta +++ b/sxx_machine/sxx_meta.metta @@ -1,43 +1,43 @@ ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Builtin Predicates of MeTTa Cafe +; ; ; ; -; Mutsunori Banbara (banbara@kobe-u.ac.jp) +; ; -; Naoyuki Tamura (tamura@kobe-u.ac.jp) +; ; -; Kobe University +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; :- op(1150, fx, (package)). +; ; -; package(X):- nb_setval(package,X). +; ; -; :-package('TauMachine.builtin_tau'). +; ; -; :- public system_predicate/1. +; ; -; :- multifile(system_predicate/1). +; ; -; :- dynamic(system_predicate/1). +; @@ -45,59 +45,42 @@ (= (forall $G1 $G) (not (not (, (call $G1) (not (not (call $G2))))))) -; /* -; system_predicate(nb_setarg(_,_,_)). -; system_predicate(setarg(_,_,_)). -; -; system_predicate(nb_get_attr(_,_,_)). -; system_predicate(nb_put_attr(_,_,_)). ; -; system_predicate(nb_get_attrs(_,_)). -; system_predicate(nb_put_attrs(_,_)). -; */ - -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; ; Control constructs -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; ; :- public undo/1. - -; /* -; '$builtin_meta_predicates'(undo, 1, [:]). -; '$builtin_meta_predicates'(undo1, 1, [:]). -; '$builtin_meta_predicates'(redo_each_call, 3, [:,:,:]). -; '$builtin_meta_predicates'(one_of_or_else, 3, [:,:,:]). -; */ - -; ;(IF -> THEN; _ELSE) :- call(IF), !, call(THEN). -; ;(_IF -> _THEN; ELSE) :- call(ELSE). - (= - (undo $G) $G) + (undo $G) $G) +; + (= (redo-each-call $EachSetup $Call $EachCleanup) - (setup-call-cleanup $EachSetup $Call $EachCleanup)) + (setup-call-cleanup $EachSetup $Call $EachCleanup)) +; + (= (or (if $IF $THEN) $ELSE) ( (= $AtLeastOnce - (dotwo True)) (or (, (call $IF) (nb-setarg 1 $AtLeastOnce fail)) (or (= $AtLeastOnce (dotwo True)) $Else)))) + (dotwo True)) (or (, (call $IF) (nb-setarg 1 $AtLeastOnce fail)) (or (= $AtLeastOnce (dotwo True)) $Else)))) +; + (= (one-of-or-else $If $Then $Else) (or - (if $IF $THEN) $ELSE)) + (if $IF $THEN) $ELSE)) +; + ; -; END +; diff --git a/sxx_machine/sxx_pl2cpp.metta b/sxx_machine/sxx_pl2cpp.metta index 38327fb..e86b3a1 100644 --- a/sxx_machine/sxx_pl2cpp.metta +++ b/sxx_machine/sxx_pl2cpp.metta @@ -1,235 +1,169 @@ !(op 1170 xfx :-) -; /***************************************************************** -; Time-stamp: <2008-10-29 10:41:19 banbara> -; -; NAME -; pl2am: Translating MeTTa into WAM-based Intermediate Code -; -; USAGE -; # sicstus -; ?- [pl2am]. -; ?- pl2am([File1, File2, [Op1,..,OpN]]). -; -; PARAMETERS -; File1 is an input MeTTa file name. -; File2 is an output file name. -; Op ::= ed | ac | ie | rc | idx | clo -; ed : eliminate disjunctions -; ac : arithmetic compilation -; ie : inline expansion -; rc : optimise recursive call -; idx: switch_on_hash (2nd. level indexing) -; clo: generate closure for meta predicates -; pif(folder): folder for writing package init predicates -; -; DESCRIPTION -; This program translates MeTTa program into WAM-based intermediate codes. -; Generated codes can be translated into Java program by using am2j.pl, -; and then compiled and executed by usual java utilities -; with the MeTTa Cafe runtime system. -; -; COPYRIGHT -; pl2am (Translating MeTTa into WAM-based Intermediate Code) -; Copyright (C) 1997-2008 by -; Mutsunori Banbara (banbara@kobe-u.ac.jp) and -; Naoyuki Tamura (tamura@kobe-u.ac.jp) -; -; SEE ALSO -; http://kaminari.istc.kobe-u.ac.jp/MeTTaCafe/ -; *****************************************************************/ - -; /***************************************************************** -; WAM-BASED INTERMEDIATE INSTRUCTIONS -; -; Put Instructions -; ================ -; put_var(X) -; put_int(i, X) -; put_float(f, X) -; put_con(f/n, X) -; put_con(c, X), -; put_list(Xi, Xj, Xk) -; put_str(Xi, Y, Xj) -; put_str_args([Xi,..,Xn], Y) -; put_clo(p:G, X) -; put_cont(p:BinG, C) -; put_cont(BinG, C) -; -; Get Instructions -; ================ -; get_val(Xi, Xj) -; get_int(i, Xi, Xj) -; get_float(f, Xi, Xj) -; get_con(c, Xi, Xj) -; get_ground(g, Xi, Xj) -; get_list(X) -; get_str(f/n, Xi, Xj) -; -; Unify Instructions -; ================== -; unify_var(X) -; unify_val(X) -; unify_int(i, X) -; unify_float(f, X) -; unify_con(c, X) -; unify_ground(g, X) -; unify_void(i) -; -; Choice Instructions -; =================== -; try(Li, Lj) -; retry(Li, Lj) -; trust(L) -; -; Indexing Instructions -; ===================== -; switch_on_term(Lv, Li, Lf, Lc, Ls, Ll) -; switch_on_hash(TAG, i, L, hashtable) -; -; Control Instructions -; ==================== -; execute(p:BinG) -; execute(BinG) -; inline(G) -; -; Other Instructions -; ================== -; (:- G) -; -; comment(Message) -; debug(Message) -; info(Message) -; -; begin_predicate(p, f/n) -; end_predicate(p, f/n) -; -; import_package(p) -; import_package(p, f/n) -; -; main(f/n, public): [Instructions] -; main(f/n, non-public): [Instructions] -; L: [Instructions] -; -; label(L) -; deref(Ri, Rj) -; set(Ri, Rj) -; setB0 -; goto(L) -; -; decl_term_vars([R1,...,Rn]) -; decl_pred_vars([R1,...,Rn]) -; -; new_hash(TAG, i) -; put_hash(X, L, TAG) -; -; static([Instructions]) -; -; Notation -; ******** -; X ::= a(i) | S -; Y ::= y(i) | S -; S ::= s(i) | si(i) | sf(i) -; L ::= f/n | f/n+i | f/n+TAG | f/n+TAG+i | f/n+TAG+i+i -; TAG ::= var | int | flo | con | str | lis | top | sub | nil -; BinG ::= C | f(A1,..,An, C) -; G ::= f(A1,..,An) -; A ::= void | X -; C ::= cont | p(N) -; R ::= cont | econt | a(i) | arg(i) | ea(i) -; -; *****************************************************************/ - -; /***************************************************************** -; Declarations -; *****************************************************************/ - - - !(op 1170 xfx -->) - !(op 1170 fx :-) - !(op 1170 fx ?-) - !(op 500 yfx #) - - !(op 1150 fx constant) ; -; added by Augeo - - !(op 1150 fx dynamic) - !(op 1150 fx meta-predicate) - !(op 1150 fx package) ; -; MeTTa Cafe specific - - !(op 1150 fx public) - !(op 1150 fx import) ; -; MeTTa Cafe specific - - !(op 1150 fx include) ; -; added by Augeo - - !(op 1150 fx mode) - !(op 1150 fx multifile) - !(op 1150 fx block) - !(op 1150 fx ifdef) ; -; added by Augeo - - !(op 1150 fx ifndef) ; -; added by Augeo - - !(op 1150 fx domain) ; -; added by Augeo - - !(op 1150 fx database) ; -; added by Augeo - - !(op 1150 fx include-resource) ; -; added by Augeo - - - !(dynamic (/ internal-clause 2)) - !(dynamic (/ internal-predicates 2)) - !(dynamic (/ dynamic-predicates 3)) - !(dynamic (/ database-call 1)) - !(dynamic (/ compiler-constant 2)) - !(dynamic (/ meta-predicates 3)) - !(dynamic (/ package-name 1)) - !(dynamic (/ public-predicates 2)) - !(dynamic (/ import-package 2)) - !(dynamic (/ internal-declarations 1)) - !(dynamic (/ file-name 1)) - !(dynamic (/ included-file 1)) - !(dynamic (/ dummy-clause-counter 1)) - !(dynamic (/ pl2am-flag 1)) - !(dynamic (/ fail-flag 0)) ; -; used for generating label(fail/0) or not +; + + !(op 1170 xfx -->) +; + + !(op 1170 fx :-) +; + + !(op 1170 fx ?-) +; + + !(op 500 yfx #) +; + + + !(op 1150 fx constant) +; + ; +; + + !(op 1150 fx dynamic) +; + + !(op 1150 fx meta-predicate) +; + + !(op 1150 fx package) +; + ; +; + + !(op 1150 fx public) +; + + !(op 1150 fx import) +; + ; +; + + !(op 1150 fx include) +; + ; +; + + !(op 1150 fx mode) +; + + !(op 1150 fx multifile) +; + + !(op 1150 fx block) +; + + !(op 1150 fx ifdef) +; + ; +; + + !(op 1150 fx ifndef) +; + ; +; + + !(op 1150 fx domain) +; + ; +; + + !(op 1150 fx database) +; + ; +; + + !(op 1150 fx include-resource) +; + ; +; + + + !(dynamic (/ internal-clause 2)) +; + + !(dynamic (/ internal-predicates 2)) +; + + !(dynamic (/ dynamic-predicates 3)) +; + + !(dynamic (/ database-call 1)) +; + + !(dynamic (/ compiler-constant 2)) +; + + !(dynamic (/ meta-predicates 3)) +; + + !(dynamic (/ package-name 1)) +; + + !(dynamic (/ public-predicates 2)) +; + + !(dynamic (/ import-package 2)) +; + + !(dynamic (/ internal-declarations 1)) +; + + !(dynamic (/ file-name 1)) +; + + !(dynamic (/ included-file 1)) +; + + !(dynamic (/ dummy-clause-counter 1)) +; + + !(dynamic (/ pl2am-flag 1)) +; + + !(dynamic (/ fail-flag 0)) +; + ; +; + + !(dynamic (/ skip-code 0)) +; + ; +; - !(dynamic (/ skip-code 0)) ; -; used for conditional compilation - - !(dynamic (/ ifdef-flag 0)) ; -; used for conditional compilation - - !(dynamic (/ domain-definition 2)) - !(dynamic (/ file-base 1)) - !(dynamic (/ file-line 2)) + !(dynamic (/ ifdef-flag 0)) +; + ; +; + + !(dynamic (/ domain-definition 2)) +; + + !(dynamic (/ file-base 1)) +; + + !(dynamic (/ file-line 2)) +; + ; -; :- module('SxxMachine.compiler.pl2am', [main/0,pl2am/1]). +; ; -; package(_). +; ; -; :- package 'SxxMachine.compiler.pl2am'. +; - !(public (, (/ main 0) (/ pl2am 1))) + !(public (, (/ main 0) (/ pl2am 1))) +; + (= (main-pl2am) ( (read $X) (pl2am $X))) -; /***************************************************************** -; Main -; *****************************************************************/ - +; @@ -238,24 +172,23 @@ ( (read-in-program $PrologFile $Opts) (open $AsmFile write $Out) (compile-all-predicates $Out) - (close $Out))) + (close $Out))) +; + ; -; pl2am(_). +; (= (read-in-program $File $Opts) ( (pl2am-preread $File $Opts) - (get-atoms &self + (get-symbols &self (= (file_name $F) $_)) (read-in-file $F) (pl2am-postread))) -; /***************************************************************** -; Read in Program -; *****************************************************************/ - +; @@ -270,171 +203,217 @@ (assert-clause $X) (== $X end-of-file) (set-det) - (remove-all-atoms &self + (remove-all-symbols &self (file_line $_ $_)) - (close $In))) + (close $In))) +; + (= (read-clause- $Stream $Clause) ( (catch (read $Stream $Clause) $_ fail) (set-det))) -; ; catch is necessary only for SWI prolg - +; (= (read-clause- $_ $_) - ( (pl2am-error Nil) (fail))) + ( (pl2am-error Nil) (fail))) +; + ; -; ;; Pre-init +; (= (pl2am-preread $File $Opts) - ( (remove-all-atoms &self + ( (remove-all-symbols &self (internal_clause $_ $_)) - (remove-all-atoms &self + (remove-all-symbols &self (internal_predicates $_ $_)) - (remove-all-atoms &self + (remove-all-symbols &self (dynamic_predicates $_ $_ $_)) - (remove-all-atoms &self + (remove-all-symbols &self (database_call $_)) - (remove-all-atoms &self + (remove-all-symbols &self (compiler_constant $_ $_)) - (remove-all-atoms &self + (remove-all-symbols &self (meta_predicates $_ $_ $_)) - (remove-all-atoms &self + (remove-all-symbols &self (package_name $_)) - (remove-all-atoms &self + (remove-all-symbols &self (public_predicates $_ $_)) - (remove-all-atoms &self + (remove-all-symbols &self (import_package $_ $_)) - (remove-all-atoms &self + (remove-all-symbols &self (internal_declarations $_)) - (remove-all-atoms &self + (remove-all-symbols &self (file_name $_)) - (remove-all-atoms &self + (remove-all-symbols &self (included_file $_)) - (remove-all-atoms &self + (remove-all-symbols &self (dummy_clause_counter $_)) - (remove-all-atoms &self + (remove-all-symbols &self (pl2am_flag $_)) - (remove-all-atoms &self fail_flag) - (remove-all-atoms &self skip_code) - (remove-all-atoms &self ifdef_flag) - (remove-all-atoms &self + (remove-all-symbols &self fail_flag) + (remove-all-symbols &self skip_code) + (remove-all-symbols &self ifdef_flag) + (remove-all-symbols &self (domain_definition $_ $_)) - (add-atom &self + (add-symbol &self (database_call (: SxxMachine.builtin call))) (assert-file-name $File) - (add-atom &self + (add-symbol &self (dummy_clause_counter 0)) (assert-compile-opts $Opts) - (assert-default-decls))) + (assert-default-decls))) +; + (= (assert-file-name (/ $Directory $File)) ( (set-det) - (add-atom &self + (add-symbol &self (file_name $File)) - (add-atom &self - (file_base $Directory)))) + (add-symbol &self + (file_base $Directory)))) +; + (= (assert-file-name $File) - (assert-file-name (/ '' $File))) + (assert-file-name (/ '' $File))) +; + (= (build-file-name $File $File) - ( (get-atoms &self + ( (get-symbols &self (= - (file_base '') $_)) (set-det))) + (file_base '') $_)) (set-det))) +; + (= (build-file-name $File $File) - ( (with_self - (= $File $Package) $ResourceName) (set-det))) + ( (= $File + (with_self $Package $ResourceName)) (set-det))) +; + (= (build-file-name $InFile $OutFile) - ( (get-atoms &self + ( (get-symbols &self (= (file_base $Directory) $_)) (list-to-string (:: $Directory / $InFile) $OutFile) - (set-det))) + (set-det))) +; + (= - (build_file_name $File $File) True) + (build_file_name $File $File) True) +; + (= (assert-file-line $File $Line) - ( (remove-all-atoms &self - (file_line $_ $_)) (add-atom &self (file_line $File $Line)))) -; ;TODO keep stack of included - + ( (remove-all-symbols &self + (file_line $_ $_)) (add-symbol &self (file_line $File $Line)))) +; (= (assert-default-decls) ( (builtin-meta-predicates $Pred $Arity $Mode) - (add-atom &self + (add-symbol &self (meta_predicates $Pred $Arity $Mode)) - (fail))) - (= assert_default_decls True) + (fail))) +; + + (= assert_default_decls True) +; + (= (assert-compile-opts Nil) - (set-det)) + (set-det)) +; + (= (assert-compile-opts (Cons $O $Os)) - ( (assert-copts $O) (assert-compile-opts $Os))) + ( (assert-copts $O) (assert-compile-opts $Os))) +; + (= (assert-copts $O) - ( (get-atoms &self + ( (get-symbols &self (= - (pl2am_flag $O) $_)) (set-det))) + (pl2am_flag $O) $_)) (set-det))) +; + (= (assert-copts $O) ( (copt-expr $O) (set-det) - (add-atom &self - (pl2am_flag $O)))) + (add-symbol &self + (pl2am_flag $O)))) +; + (= (assert-copts $O) - ( (pl2am-error (:: $O is an invalid option for pl2am)) (fail))) + ( (pl2am-error (:: $O is an invalid option for pl2am)) (fail))) +; + (= - (copt_expr ed) True) + (copt_expr ed) True) +; + (= - (copt_expr ac) True) + (copt_expr ac) True) +; + (= - (copt_expr ie) True) + (copt_expr ie) True) +; + (= - (copt_expr rc) True) + (copt_expr rc) True) +; + (= (copt_expr - (rc $_ $_)) True) + (rc $_ $_)) True) +; + (= - (copt_expr idx) True) + (copt_expr idx) True) +; + (= - (copt_expr clo) True) + (copt_expr clo) True) +; + (= (copt_expr - (pif $_)) True) + (pif $_)) True) +; + ; -; ;; Post-init +; (= @@ -442,411 +421,545 @@ ( (assert-import SxxMachine.lang) (assert-import SxxMachine.builtin) (assert-dummy-package) - (assert-dummy-public))) + (assert-dummy-public))) +; + (= (assert-dummy-package) - ( (get-atoms &self + ( (get-symbols &self (= - (package_name $_) $_)) (set-det))) + (package_name $_) $_)) (set-det))) +; + (= (assert-dummy-package) - (add-atom &self - (package_name user))) + (add-symbol &self + (package_name user))) +; + (= (assert-dummy-public) - ( (get-atoms &self + ( (get-symbols &self (= - (public_predicates $_ $_) $_)) (set-det))) + (public_predicates $_ $_) $_)) (set-det))) +; + (= (assert-dummy-public) - (add-atom &self - (public_predicates $_ $_))) + (add-symbol &self + (public_predicates $_ $_))) +; + ; -; ;; Expand constants +; (= (expand-constants $InClause $OutClause) ( (atom $InClause) - (get-atoms &self + (get-symbols &self (= (compiler_constant $InClause $OutClause) $_)) - (set-det))) + (set-det))) +; + (= (expand-constants $InClause $OutClause) ( (compound $InClause) (=.. $InClause $InList) (pl2am-maplist expand-constants $InList $OutList) (=.. $OutClause $OutList) - (set-det))) + (set-det))) +; + (= (expand-constants $Clause $Clause) - (set-det)) + (set-det)) +; + ; -; ;; Assert Clauses +; (= (assert-clause end-of-file) - (set-det)) + (set-det)) +; + (= (assert-clause !(ifdef $C)) - ( (set-det) (assert-ifdef $C))) + ( (set-det) (assert-ifdef $C))) +; + (= (assert-clause !(ifndef $C)) - ( (set-det) (assert-ifndef $C))) + ( (set-det) (assert-ifndef $C))) +; + (= (assert-clause !(elsedef)) - ( (set-det) (assert-elsedef))) + ( (set-det) (assert-elsedef))) +; + (= (assert-clause !(enddef)) - ( (set-det) (assert-enddef))) + ( (set-det) (assert-enddef))) +; + (= (assert-clause $_) - ( (get-atoms &self - (= skip_code $_)) (set-det))) + ( (get-symbols &self + (= skip_code $_)) (set-det))) +; + (= (assert-clause !(constant $C)) - ( (set-det) (assert-constant $C))) + ( (set-det) (assert-constant $C))) +; + (= (assert-clause $C) - ( (expand-constants $C $EC) (assert-clause- $EC))) + ( (expand-constants $C $EC) (assert-clause- $EC))) +; + (= (assert-clause- !(include $F)) - ( (set-det) (assert-include-file $F))) + ( (set-det) (assert-include-file $F))) +; + (= (assert-clause- !(include-resource $F)) - ( (set-det) (assert-include-file $F))) + ( (set-det) (assert-include-file $F))) +; + (= (assert-clause- !(database $D)) - ( (set-det) (assert-database $D))) + ( (set-det) (assert-database $D))) +; + (= (assert-clause- !(dynamic $G)) ( (set-det) (conj-to-list $G $G1) - (assert-dynamic-predicates $G1))) + (assert-dynamic-predicates $G1))) +; + (= (assert-clause- !(domain $D)) - ( (set-det) (assert-domain-definition $D))) + ( (set-det) (assert-domain-definition $D))) +; + (= (assert-clause- !(module $M $PList)) ( (set-det) (assert-package $M) - (assert-public-predicates $PList))) + (assert-public-predicates $PList))) +; + (= (assert-clause- !(meta-predicate $G)) ( (set-det) (conj-to-list $G $G1) - (assert-meta-predicates $G1))) + (assert-meta-predicates $G1))) +; + (= (assert-clause- !(package $G)) - ( (set-det) (assert-package $G))) + ( (set-det) (assert-package $G))) +; + (= (assert-clause- !(public $G)) ( (set-det) (conj-to-list $G $G1) - (assert-public-predicates $G1))) + (assert-public-predicates $G1))) +; + (= (assert-clause- !(import $G)) - ( (set-det) (assert-import $G))) + ( (set-det) (assert-import $G))) +; + (= (assert-clause- !(mode $G)) - ( (set-det) (pl2am-message (:: '*** WARNING' mode declaration is not supported yet)))) + ( (set-det) (pl2am-message (:: '*** WARNING' mode declaration is not supported yet)))) +; + (= (assert-clause- !(multifile $G)) - ( (set-det) (pl2am-message (:: '*** WARNING' multifile declaration is not supported yet)))) + ( (set-det) (pl2am-message (:: '*** WARNING' multifile declaration is not supported yet)))) +; + (= (assert-clause- !(block $G)) - ( (set-det) (pl2am-message (:: '*** WARNING' block declaration is not supported yet)))) + ( (set-det) (pl2am-message (:: '*** WARNING' block declaration is not supported yet)))) +; + (= (assert-clause- !$G) ( (set-det) (call $G) - (assert-declarations $G))) + (assert-declarations $G))) +; + (= (assert-clause- (= (%init) $InitBody)) - ( (get-atoms &self + ( (get-symbols &self (= (pl2am_flag (pif $PackageInitFolder)) $_)) (set-det) - (write-init (= (%init) $InitBody)))) + (write-init (= (%init) $InitBody)))) +; + (= (assert-clause- (= $Head (or $Body1 $Body2))) ( (set-det) (assert-clause- (= $Head $Body1)) - (assert-clause- (= $Head $Body2)))) + (assert-clause- (= $Head $Body2)))) +; + (= (assert-clause- $Clause) - ( (preprocess $Clause $Cl) (assert-cls $Cl))) + ( (preprocess $Clause $Cl) (assert-cls $Cl))) +; + ; -; ;; Constant Declaration +; (= (assert-constant $C) ( (= $C (= $Name $_)) - (get-atoms &self + (get-symbols &self (= (compiler_constant $Name $_) $_)) (set-det) (pl2am-error (:: compiler constant $Name is already defined)) - (fail))) + (fail))) +; + (= (assert-constant $C) ( (= $C (= $Name $Value)) - (add-atom &self + (add-symbol &self (compiler_constant $Name $Value)) - (set-det))) + (set-det))) +; + (= (assert-constant $C) - ( (pl2am-error (:: $C is an invalid constant declaration)) (fail))) + ( (pl2am-error (:: $C is an invalid constant declaration)) (fail))) +; + ; -; ;; Conditional compilation +; (= (assert-ifdef $_) - ( (get-atoms &self + ( (get-symbols &self (= ifdef_flag $_)) (set-det) (pl2am-error (:: nested ifdef are not supported)) - (fail))) + (fail))) +; + (= (assert-ifdef $C) - ( (not (get-atoms &self (= (compiler_constant $C $_) $_))) (add-atom &self skip_code))) + ( (not (get-symbols &self (= (compiler_constant $C $_) $_))) (add-symbol &self skip_code))) +; + (= (assert-ifdef $_) - (add-atom &self ifdef_flag)) + (add-symbol &self ifdef_flag)) +; + (= (assert-ifndef $_) - ( (get-atoms &self + ( (get-symbols &self (= ifdef_flag $_)) (set-det) (pl2am-error (:: nested ifdef are not supported)) - (fail))) + (fail))) +; + (= (assert-ifndef $C) - ( (get-atoms &self + ( (get-symbols &self (= - (compiler_constant $C $_) $_)) (add-atom &self skip_code))) + (compiler_constant $C $_) $_)) (add-symbol &self skip_code))) +; + (= (assert-ifndef $_) - (add-atom &self ifdef_flag)) + (add-symbol &self ifdef_flag)) +; + (= (assert-elsedef) - ( (get-atoms &self + ( (get-symbols &self (= ifdef_flag $_)) - (get-atoms &self + (get-symbols &self (= skip_code $_)) (set-det) - (remove-all-atoms &self skip_code))) + (remove-all-symbols &self skip_code))) +; + (= (assert-elsedef) - ( (get-atoms &self + ( (get-symbols &self (= ifdef_flag $_)) (set-det) - (add-atom &self skip_code))) + (add-symbol &self skip_code))) +; + (= (assert-elsedef) ( (set-det) (pl2am-error (:: elsedef without ifdef)) - (fail))) + (fail))) +; + (= (assert-enddef) - ( (get-atoms &self + ( (get-symbols &self (= ifdef_flag $_)) (set-det) - (remove-all-atoms &self skip_code) - (remove-all-atoms &self ifdef_flag))) + (remove-all-symbols &self skip_code) + (remove-all-symbols &self ifdef_flag))) +; + (= (assert-enddef) ( (set-det) (pl2am-error (:: enddef without ifdef)) - (fail))) + (fail))) +; + ; -; ;; Include files +; (= (assert-include-file $F) - ( (get-atoms &self + ( (get-symbols &self (= (file_name $BaseFile) $_)) (pl2am-resolve-file $BaseFile $F $IncludeFile) - (get-atoms &self + (get-symbols &self (= (included_file $IncludeFile) $_)) - (set-det))) + (set-det))) +; + (= (assert-include-file $F) - ( (get-atoms &self + ( (get-symbols &self (= (file_name $BaseFile) $_)) (pl2am-resolve-file $BaseFile $F $IncludeFile) - (add-atom &self + (add-symbol &self (included_file $IncludeFile)) - (remove-all-atoms &self + (remove-all-symbols &self (file_name $_)) - (add-atom &self + (add-symbol &self (file_name $IncludeFile)) (read-in-file $IncludeFile) - (remove-all-atoms &self + (remove-all-symbols &self (file_name $_)) - (add-atom &self + (add-symbol &self (file_name $BaseFile)) - (set-det))) + (set-det))) +; + (= (assert-include-file $F) - ( (get-atoms &self + ( (get-symbols &self (= (file_name $BaseFile) $_)) (pl2am-error (:: failed to include file $F in $BaseFile)) - (fail))) + (fail))) +; + ; -; ;; Database declaration +; (= (assert-database $D) ( (= $D (= $Name $_)) - (get-atoms &self + (get-symbols &self (= (domain_definition $Name $_) $_)) (set-det) (pl2am-error (:: database $Name is already defined)) - (fail))) + (fail))) +; + (= (assert-database $D) ( (= $D (= $_ $Value)) (assert-domain-definition $D) (assert-database-dynamic $Value) - (set-det))) + (set-det))) +; + (= (assert-database $D) - ( (pl2am-error (:: $D is an invalid database definition)) (fail))) + ( (pl2am-error (:: $D is an invalid database definition)) (fail))) +; + (= (assert-database-dynamic (or $Fact $Tail)) ( (set-det) (assert-database-dynamic $Fact) - (assert-database-dynamic $Tail))) + (assert-database-dynamic $Tail))) +; + (= (assert-database-dynamic $Fact) - ( (functor $Fact $Name $Arity) (assert-dynamic (/ $Name $Arity)))) + ( (functor $Fact $Name $Arity) (assert-dynamic (/ $Name $Arity)))) +; + ; -; ;; Dynamic Declaration +; (= (assert-dynamic-predicates Nil) - (set-det)) + (set-det)) +; + (= (assert-dynamic-predicates (Cons $G $Gs)) - ( (assert-dynamic $G) (assert-dynamic-predicates $Gs))) + ( (assert-dynamic $G) (assert-dynamic-predicates $Gs))) +; + (= (assert-dynamic $G) - ( (not (get-atoms &self (= (package_name SxxMachine.builtin) $_))) + ( (not (get-symbols &self (= (package_name SxxMachine.builtin) $_))) (= $G (/ $F $A)) (functor $Head $F $A) (system-predicate $Head) (set-det) (pl2am-error (:: can not redefine builtin predicate (/ $F $A))) - (fail))) + (fail))) +; + (= (assert-dynamic $G) ( (= $G (/ $F $A)) - (get-atoms &self + (get-symbols &self (= (dynamic_predicates $F $A $_) $_)) - (set-det))) + (set-det))) +; + (= (assert-dynamic $G) ( (= $G (/ $F $A)) - (get-atoms &self + (get-symbols &self (= (database_call $Call) $_)) - (add-atom &self + (add-symbol &self (dynamic_predicates $F $A $Call)) - (set-det))) + (set-det))) +; + (= (assert-dynamic $G) - ( (pl2am-error (:: $G is an invalid dynamic declaration)) (fail))) + ( (pl2am-error (:: $G is an invalid dynamic declaration)) (fail))) +; + ; -; ;; Domain definitions +; (= (assert-domain-definition $D) ( (= $D (= $Name $_)) - (get-atoms &self + (get-symbols &self (= (domain_definition $Name $_) $_)) (set-det) (pl2am-error (:: domain $Name is already defined)) - (fail))) + (fail))) +; + (= (assert-domain-definition $D) ( (= $D (= $Name $Value)) - (add-atom &self + (add-symbol &self (domain_definition $Name $Value)) - (set-det))) + (set-det))) +; + (= (assert-domain-definition $D) - ( (pl2am-error (:: $D is an invalid domain definition)) (fail))) + ( (pl2am-error (:: $D is an invalid domain definition)) (fail))) +; + ; -; ;; Meta Predicates Declaration +; (= (assert-meta-predicates Nil) - (set-det)) + (set-det)) +; + (= (assert-meta-predicates (Cons $G $Gs)) - ( (assert-meta $G) (assert-meta-predicates $Gs))) + ( (assert-meta $G) (assert-meta-predicates $Gs))) +; + (= (assert-meta $G) ( (functor $G $F $A) - (get-atoms &self + (get-symbols &self (= (meta_predicates $F $A $_) $_)) - (set-det))) + (set-det))) +; + (= (assert-meta $G) ( (functor $G $F $A) @@ -854,69 +967,89 @@ (Cons $_ $M)) (mode-expr $M) (set-det) - (add-atom &self - (meta_predicates $F $A $M)))) + (add-symbol &self + (meta_predicates $F $A $M)))) +; + (= (assert-meta $G) - ( (pl2am-error (:: $G is an invalid meta-predicate declaration)) (fail))) + ( (pl2am-error (:: $G is an invalid meta-predicate declaration)) (fail))) +; + ; -; ;; Package Declaration +; (= (assert-package $G) - ( (get-atoms &self + ( (get-symbols &self (= (package_name $G1) $_)) (\== $G $G1) (set-det) (pl2am-error (:: duplicate package declarations : $G1 and $G)) - (fail))) + (fail))) +; + (= (assert-package $G) ( (atom $G) (set-det) - (add-atom &self + (add-symbol &self (package_name $G)) - (remove-all-atoms &self - (import_package $G $_)))) + (remove-all-symbols &self + (import_package $G $_)))) +; + (= (assert-package $G) - ( (pl2am-error (:: $G is invalid package declaration)) (fail))) + ( (pl2am-error (:: $G is invalid package declaration)) (fail))) +; + ; -; ;; Public Declaration +; (= (assert-public-predicates Nil) - (set-det)) + (set-det)) +; + (= (assert-public-predicates (Cons $G $Gs)) - ( (assert-public $G) (assert-public-predicates $Gs))) + ( (assert-public $G) (assert-public-predicates $Gs))) +; + (= (assert-public (/ $F $A)) ( (predspec-expr (/ $F $A)) - (get-atoms &self + (get-symbols &self (= (public_predicates $F $A) $_)) - (set-det))) + (set-det))) +; + (= (assert-public (/ $F $A)) - ( (predspec-expr (/ $F $A)) (add-atom &self (public_predicates $F $A)))) + ( (predspec-expr (/ $F $A)) (add-symbol &self (public_predicates $F $A)))) +; + ; -; ;; Import Declaration +; (= (assert-import $G) ( (atom $G) (set-det) - (assert-impt $G *))) + (assert-impt $G *))) +; + (= (assert-import (with_self $M $P)) ( (atom $M) @@ -924,115 +1057,149 @@ (predspec-expr $P) (atom $P)) (set-det) - (assert-impt $M $P))) + (assert-impt $M $P))) +; + (= (assert-import $G) - ( (pl2am-error (:: $G is invalid import declaration)) (fail))) + ( (pl2am-error (:: $G is invalid import declaration)) (fail))) +; + (= (assert-impt $M $P) - ( (get-atoms &self + ( (get-symbols &self (= - (package_name $M) $_)) (set-det))) + (package_name $M) $_)) (set-det))) +; + (= (assert-impt $M $P) - ( (get-atoms &self + ( (get-symbols &self (= (import_package $M $P0) $_)) (or (== $P0 *) (== $P0 $P)) - (set-det))) + (set-det))) +; + (= (assert-impt $M $P) - (add-atom &self - (import_package $M $P))) + (add-symbol &self + (import_package $M $P))) +; + ; -; ;; Assert Declaration (:- G) +; (= (assert-declarations $G) - ( (get-atoms &self + ( (get-symbols &self (= - (internal_declarations $G) $_)) (set-det))) + (internal_declarations $G) $_)) (set-det))) +; + (= (assert-declarations $G) - (add-atom &self - (internal_declarations $G))) + (add-symbol &self + (internal_declarations $G))) +; + ; -; ;; Assert Cluase +; (= (assert-cls (= $Head $Body)) ( (set-det) (assert-predicate $Head) - (add-atom &self - (internal_clause $Head $Body)))) + (add-symbol &self + (internal_clause $Head $Body)))) +; + (= (assert-cls $Head) ( (set-det) (assert-predicate $Head) - (add-atom &self - (internal_clause $Head true)))) + (add-symbol &self + (internal_clause $Head true)))) +; + (= (assert-predicate $Head) - ( (not (get-atoms &self (= (package_name SxxMachine.builtin) $_))) + ( (not (get-symbols &self (= (package_name SxxMachine.builtin) $_))) (system-predicate $Head) (set-det) (functor $Head $Functor $Arity) (pl2am-error (:: can not redefine builtin predicate (/ $Functor $Arity))) - (fail))) + (fail))) +; + (= (assert-predicate $Head) ( (functor $Head $Functor $Arity) - (get-atoms &self + (get-symbols &self (= (internal_predicates $Functor $Arity) $_)) - (set-det))) + (set-det))) +; + (= (assert-predicate $Head) - ( (functor $Head $Functor $Arity) (add-atom &self (internal_predicates $Functor $Arity)))) + ( (functor $Head $Functor $Arity) (add-symbol &self (internal_predicates $Functor $Arity)))) +; + ; -; ;; Preprocess +; (= (preprocess $Cl0 $Cl) - ( (get-atoms &self + ( (get-symbols &self (= (pl2am_flag ed) $_)) (set-det) (expand-term $Cl0 $Cl1) - (eliminate-disjunction $Cl1 $Cl))) + (eliminate-disjunction $Cl1 $Cl))) +; + (= (preprocess $Cl0 $Cl) - (expand-term $Cl0 $Cl)) + (expand-term $Cl0 $Cl)) +; + (= (eliminate-disjunction $Cl0 $Cl) - ( (eliminate-disj $Cl0 $Cl $DummyCls) (assert-dummy-clauses $DummyCls))) + ( (eliminate-disj $Cl0 $Cl $DummyCls) (assert-dummy-clauses $DummyCls))) +; + (= (assert-dummy-clauses Nil) - (set-det)) + (set-det)) +; + (= (assert-dummy-clauses (Cons $C $Cs)) - ( (assert-clause $C) (assert-dummy-clauses $Cs))) + ( (assert-clause $C) (assert-dummy-clauses $Cs))) +; + (= (compile-all-predicates $Out) - ( (get-atoms &self + ( (get-symbols &self (= (internal_declarations $G) $_)) (writeq $Out @@ -1040,12 +1207,7 @@ (write $Out .) (nl $Out) (fail))) -; /***************************************************************** -; Compile MeTTa Program -; *****************************************************************/ - -; ; output declarations (ex. op/3) - +; (= (compile-all-predicates $_) @@ -1053,42 +1215,48 @@ (/ $Functor $Arity) (dynamic-predicates $Functor $Arity (with_self - (SxxMachine.builtin) + (SxxMachine.builtin *) (call))) $PredSpecs) (assert-init-clauses $PredSpecs) (fail))) -; ; treat dynamic declaration - +; (= (compile-all-predicates $Out) - ( (get-atoms &self + ( (get-symbols &self (= (internal_predicates $Functor $Arity) $_)) (compile-predicate $Functor $Arity $Instructions Nil) (write-asm $Out $Instructions) (nl $Out) (fail))) -; ; compile predicate - +; (= (compile-all-predicates $Out) - (write-domain-definitions $Out)) + (write-domain-definitions $Out)) +; + (= (compile-all-predicates $Out) - (nl $Out)) + (nl $Out)) +; + (= (write-asm $_ Nil) - (set-det)) + (set-det)) +; + (= (write-asm $Out (Cons $Instruction $Instructions)) ( (set-det) (write-asm $Out $Instruction) - (write-asm $Out $Instructions))) + (write-asm $Out $Instructions))) +; + (= (write-asm $Out (begin-predicate $P $FA)) @@ -1096,7 +1264,9 @@ (writeq $Out (begin-predicate $P $FA)) (write $Out .) - (nl $Out))) + (nl $Out))) +; + (= (write-asm $Out (end-predicate $P $FA)) @@ -1104,7 +1274,9 @@ (writeq $Out (end-predicate $P $FA)) (write $Out .) - (nl $Out))) + (nl $Out))) +; + (= (write-asm $Out (comment $Comment0)) @@ -1115,7 +1287,9 @@ (writeq $Out (comment $Comment)) (write $Out .) - (nl $Out))) + (nl $Out))) +; + (= (write-asm $Out (with_self $Label $Instruction)) @@ -1123,60 +1297,74 @@ (writeq $Out $Label) (write $Out :) (nl $Out) - (write-asm $Out $Instruction))) + (write-asm $Out $Instruction))) +; + (= (write-asm $Out $Instruction) ( (tab $Out 8) (writeq $Out $Instruction) (write $Out .) - (nl $Out))) + (nl $Out))) +; + (= (write-domain-definitions $Out) - ( (get-atoms &self + ( (get-symbols &self (= (package_name $PackageName) $_)) - (get-atoms &self + (get-symbols &self (= (domain_definition $Name $Value) $_)) (= $AssertTerm - ! (add-atom &self + ! (add-symbol &self (domain_definition - (: $PackageName - (= $Name $Value))))) + (= + (: $PackageName $Name) $Value)))) (writeq $Out $AssertTerm) (write $Out .) (nl $Out) - (fail))) + (fail))) +; + (= - (write_domain_definitions $_) True) + (write_domain_definitions $_) True) +; + (= (write-init $InitPredicate) - ( (get-atoms &self + ( (get-symbols &self (= (package_name $PackageName) $_)) - (get-atoms &self + (get-symbols &self (= (pl2am_flag (pif $PackageInitFolder)) $_)) (list-to-string (:: $PackageInitFolder / $PackageName .init.pl) $File) (with-mutex $PackageName - (write-init-file $File $PackageName $InitPredicate)))) + (write-init-file $File $PackageName $InitPredicate)))) +; + (= - (write_init $_) True) + (write_init $_) True) +; + (= (write-init-file $File $PackageName $InitPredicate) ( (not (exists-file $File)) (set-det) - (write-init-predicate $File $PackageName $InitPredicate))) + (write-init-predicate $File $PackageName $InitPredicate))) +; + (= (write-init-file $File $PackageName $InitPredicate) @@ -1189,27 +1377,32 @@ (\== $NewBody $InInitBody) (write-init-predicate $File $PackageName (= $InitHead $NewBody)))) -; ;PackageName == InPackageName, - -; ;InitHead == InInitHead, - +; (= - (write_init_file $_ $_ $_) True) + (write_init_file $_ $_ $_) True) +; + (= (conj-member $X $X) - (set-det)) + (set-det)) +; + (= (conj-member $X (, $X $_)) - (set-det)) + (set-det)) +; + (= (conj-member $X (, $_ $Y)) - (conj-member $X $Y)) + (conj-member $X $Y)) +; + (= @@ -1217,19 +1410,27 @@ (, $X $L) $Y $O) ( (conj-member $X $Y) (set-det) - (conj-union $L $Y $O))) + (conj-union $L $Y $O))) +; + (= (conj-union (, $X $L) $Y $O) - ( (set-det) (conj-union $L (, $X $Y) $O))) + ( (set-det) (conj-union $L (, $X $Y) $O))) +; + (= (conj-union $X $Y $Y) - ( (conj-member $X $Y) (set-det))) + ( (conj-member $X $Y) (set-det))) +; + (= (conj_union $X $Y - (, $X $Y)) True) + (, $X $Y)) True) +; + (= @@ -1239,7 +1440,9 @@ (read-clause- $In $InitPredicate) (close $In) (= $Package - !(package $PackageName)))) + !(package $PackageName)))) +; + @@ -1254,68 +1457,79 @@ (writeq $Stream $InitPredicate) (write $Stream .) (nl $Stream) - (close $Stream))) + (close $Stream))) +; + (= (assert-init-clauses Nil) (set-det)) -; /**************************************************************** -; Treat Dynamic Declaration -; ****************************************************************/ - +; (= (assert-init-clauses $PredSpecs) ( (collect-init-cls $PredSpecs $Cls) (assert-init-cls $Cls) - (set-det))) + (set-det))) +; + (= (collect-init-cls Nil Nil) - (set-det)) + (set-det)) +; + (= (collect-init-cls (Cons (/ $F $A) $FAs) (Cons $Cls $Cls1)) - ( (get-atoms &self + ( (get-symbols &self (= (internal_predicates $F $A) $_)) (set-det) (functor $Head $F $A) (findall - (add-atom &self + (add-symbol &self (:- $Head $Body)) (internal-clause $Head $Body) $Cls) - (remove-all-atoms &self + (remove-all-symbols &self (internal_predicates $F $A)) - (remove-all-atoms &self + (remove-all-symbols &self (internal_clause $Head $_)) - (collect-init-cls $FAs $Cls1))) + (collect-init-cls $FAs $Cls1))) +; + ; -; collect_init_cls([FA|FAs], [hash_put(P,FA,[])|Cls]) :- +; (= (collect-init-cls (Cons $FA $FAs) (Cons ($new-indexing-hash $P $FA $_) $Cls)) - ( (get-atoms &self + ( (get-symbols &self (= (package_name $P) $_)) (set-det) - (collect-init-cls $FAs $Cls))) + (collect-init-cls $FAs $Cls))) +; + (= (assert-init-cls Nil) - (set-det)) + (set-det)) +; + (= (assert-init-cls $Cls) - ( (list-to-conj $Cls $Body) (assert-clause (= (%init) $Body)))) + ( (list-to-conj $Cls $Body) (assert-clause (= (%init) $Body)))) +; + (= @@ -1341,19 +1555,18 @@ (/ $Functor $Arity)) ( (end_predicate $P (/ $Functor $Arity))))))))))) True) -; /**************************************************************** -; Compile Predicate -; ****************************************************************/ - +; ; -; ;; Program Code +; (= (--> (compile_pred () $_) - (, () !)) True) + (, () !)) True) +; + (= (--> (compile_pred @@ -1397,18 +1610,7 @@ (generate_var_decl (1 1) ($XN $PN) $DeclLocalVars ())) })))))))))))))) True) -; ; checks public or non-public - -; ; generates put instructions of ground terms - -; ; set B0 register for cut - -; ; generates the declarations of local variables - -; ; set arg(N) to a(N). - -; ; GTI0 = [SN,SAlloc,PutGroundTerm] - +; (= (--> @@ -1480,47 +1682,22 @@ (= $OPT2 (goto (+ $FA top))) - (: - (= $OPT3 - (+ $FA top)) ())))) + (= $OPT3 + (: + (+ $FA top) ()))))) (, (= $OPT1 ()) (, (= $OPT2 ()) (= $OPT3 ())))) })))))))))))))))))))))) True) -; ; checks public or non-public - -; ; generates ground terms - -; ; generates label declarations - -; ; generates new_hash - -; ; generates pub_hash - -; ; - -; ; set arg(N) to engine.areg(N) - -; ; set cont to engine.cont - -; ; set B0 register for cut - -; ; generates control and indexing instructions. - -; ; GTI0 = [SN,SAlloc,PutGroundTerm] - -; ; - -; ; replace the hash key with s(i), si(i), or sf(i) - -; ; generate code for the recursize call optimization - +; (= (--> - (compile_pred2 () $_ $_ $GTI $GTI) !) True) + (compile_pred2 () $_ $_ $GTI $GTI) !) True) +; + (= (--> (compile_pred2 @@ -1557,16 +1734,11 @@ (generate_var_decl (1 1) ($XN $PN) $DeclLocalVars ())) }))))))))))) True) -; ; generates the declarations of local variables - -; ; set engine.areg(N) to a(N). - -; ; set engine.cont to cont - +; ; -; ;; Control and Indexing instructions +; (= (--> @@ -1593,16 +1765,7 @@ (, { (pl2am_append $Ls1 $Ls2 $Label) } { (gen_hash $SWTs $Hash ()) }))))))) True) -; ; generates try, retry, trust, switch_on_term, and switch_on_hash - -; ; generates sub-labels for BP - -; ; generates fail label (fail_flag may be asserted by generate_switch0/4) - -; ; generates labels for clauses - -; ; generates new_hash and put_hash instructions for switch_on_hash - +; (= @@ -1610,10 +1773,12 @@ (generate_switch0 $Clauses $FA) (, { (get_indices $Clauses $FA 1 $Is) } - (generate_switch1 $Is $FA))) True) + (generate_switch1 $Is $FA))) True) +; + ; -; ;; 1st. Indexing +; (= (--> @@ -1622,14 +1787,18 @@ { (= $FA (/ $_ 0)) } (, ! - (generate_tries $Is)))) True) + (generate_tries $Is)))) True) +; + (= (--> (generate_switch1 $Is $_) (, { (all_variable_indices $Is) } (, ! - (generate_tries $Is)))) True) + (generate_tries $Is)))) True) +; + (= (--> (generate_switch1 $Is $FA) @@ -1645,38 +1814,48 @@ (generate_sw $Is $FA con $LC $PIs2 $PIs3) (, (generate_sw $Is $FA str $LS $PIs3 $PIs4) - (generate_sw $Is $FA lis $LL $PIs4 $_)))))))) True) + (generate_sw $Is $FA lis $LL $PIs4 $_)))))))) True) +; + (= (--> (generate_sw $Is $FA $Tag $L $PIs0 $PIs) (, { (select_indices $Is $Tag $Is1) } - (generate_sw1 $Is1 $FA $Tag $L $PIs0 $PIs))) True) + (generate_sw1 $Is1 $FA $Tag $L $PIs0 $PIs))) True) +; + ; -; ;; 2nd. Indexing +; (= (--> (generate_sw1 () $_ $_ (/ fail 0) $PIs $PIs) (, ! - {assert_fail })) True) + {assert_fail })) True) +; + (= (--> (generate_sw1 ($I) $_ $_ $L $PIs $PIs) (, ! { (= $I - (Cons $L $_)) })) True) + (Cons $L $_)) })) True) +; + (= (--> (generate_sw1 $Is $FA $Tag $L $PIs0 $PIs) (, { (no_switch_on_hash $Is $Tag) } (, ! - (generate_sw2 $Is $FA $Tag $L $PIs0 $PIs)))) True) + (generate_sw2 $Is $FA $Tag $L $PIs0 $PIs)))) True) +; + (= (--> (generate_sw1 $Is $FA $Tag @@ -1692,12 +1871,14 @@ (, { (generate_hash_table $Keys $Is $LIs) } (generate_hash_tries $LIs - (+ $FA $Tag) 0 $HT)))))) True) + (+ $FA $Tag) 0 $HT)))))) True) +; + (= (no-switch-on-hash $Is $Tag) - ( (get-atoms &self + ( (get-symbols &self (= (pl2am_flag idx) $_)) (set-det) @@ -1709,9 +1890,13 @@ (= $Tag nil) (, (count-unique-hash $Is $C $_) - (< $C 2))))))) + (< $C 2))))))) +; + (= - (no_switch_on_hash $_ $_) True) + (no_switch_on_hash $_ $_) True) +; + (= @@ -1719,7 +1904,9 @@ (generate_sw2 $Is $_ $_ $L $PIs $PIs) (, { (pl2am_member - (, $L $Is) $PIs) } !)) True) + (, $L $Is) $PIs) } !)) True) +; + (= (--> (generate_sw2 $Is $FA $Tag @@ -1730,11 +1917,15 @@ (, ( (: (+ $FA $Tag) ())) - (generate_tries $Is))) True) + (generate_tries $Is))) True) +; + (= (--> - (generate_hash_tries () $_ $_ ()) !) True) + (generate_hash_tries () $_ $_ ()) !) True) +; + (= (--> (generate_hash_tries @@ -1746,7 +1937,9 @@ (, ! (, {assert_fail } - (generate_hash_tries $LIs $L0 $N $Ls)))) True) + (generate_hash_tries $LIs $L0 $N $Ls)))) True) +; + (= (--> (generate_hash_tries @@ -1759,7 +1952,9 @@ (, { (= $I (Cons $L $_)) } - (generate_hash_tries $LIs $L0 $N $Ls)))) True) + (generate_hash_tries $LIs $L0 $N $Ls)))) True) +; + (= (--> (generate_hash_tries @@ -1776,22 +1971,30 @@ (, { (is $N1 (+ $N 1)) } - (generate_hash_tries $LIs $L0 $N1 $Ls))))) True) + (generate_hash_tries $LIs $L0 $N1 $Ls))))) True) +; + (= (generate-hash-table Nil $_ Nil) - (set-det)) + (set-det)) +; + (= (generate-hash-table (Cons $K $Ks) $Is0 (Cons (with_self $K $Is) $LIs)) - ( (select-hash $Is0 $K $Is) (generate-hash-table $Ks $Is0 $LIs))) + ( (select-hash $Is0 $K $Is) (generate-hash-table $Ks $Is0 $LIs))) +; + (= - (select_hash () $_ ()) True) + (select_hash () $_ ()) True) +; + (= (select-hash (Cons $I $Is0) $K @@ -1802,14 +2005,18 @@ (= $Tag var) (= $K $Hash)) (set-det) - (select-hash $Is0 $K $Is))) + (select-hash $Is0 $K $Is))) +; + (= (select-hash (Cons $_ $Is0) $K $Is) - (select-hash $Is0 $K $Is)) + (select-hash $Is0 $K $Is)) +; + ; -; ;; Choice Point (try, retry, trust) +; (= @@ -1821,7 +2028,9 @@ (Cons $L $_)) } (, ( (try $L)) - (generate_tries1 $Is)))) True) + (generate_tries1 $Is)))) True) +; + (= (--> @@ -1831,7 +2040,9 @@ (, { (= $I (Cons $L $_)) } - ( (trust $L))))) True) + ( (trust $L))))) True) +; + (= (--> (generate_tries1 @@ -1841,11 +2052,15 @@ (Cons $L $_)) } (, ( (retry $L)) - (generate_tries1 $Is)))) True) + (generate_tries1 $Is)))) True) +; + (= - (get_indices () $_ $_ ()) True) + (get_indices () $_ $_ ()) True) +; + (= (get-indices (Cons $_ $Clauses) $FA $N @@ -1856,7 +2071,9 @@ (set-det) (is $N1 (+ $N 1)) - (get-indices $Clauses $FA $N1 $Is))) + (get-indices $Clauses $FA $N1 $Is))) +; + (= (get-indices (Cons $Clause $Clauses) $FA $N @@ -1869,41 +2086,61 @@ (get-hash $A1 $Tag $Hash) (is $N1 (+ $N 1)) - (get-indices $Clauses $FA $N1 $Is))) + (get-indices $Clauses $FA $N1 $Is))) +; + (= (get-hash $X var 0) - ( (var $X) (set-det))) + ( (var $X) (set-det))) +; + (= (get-hash $X int $X) - ( (integer $X) (set-det))) + ( (integer $X) (set-det))) +; + (= (get-hash $X flo $X) - ( (float $X) (set-det))) + ( (float $X) (set-det))) +; + (= (get-hash $X con $X) - ( (atom $X) (set-det))) + ( (atom $X) (set-det))) +; + (= (get-hash $X lis (/ . 2)) ( (= $X - (Cons $_ $_)) (set-det))) + (Cons $_ $_)) (set-det))) +; + (= (get-hash $X str (/ $F $A)) - ( (functor $X $F $A) (set-det))) + ( (functor $X $F $A) (set-det))) +; + (= - (all_variable_indices ()) True) + (all_variable_indices ()) True) +; + (= (all-variable-indices (Cons (:: $_ $_ var $_) $Is)) - (all-variable-indices $Is)) + (all-variable-indices $Is)) +; + (= - (count_unique_hash () 0 ()) True) + (count_unique_hash () 0 ()) True) +; + (= (count-unique-hash (Cons $I $Is) $C $K) @@ -1922,11 +2159,15 @@ (is $C (+ $C0 1)) (= $K - (Cons $Hash $K0)))))) + (Cons $Hash $K0)))))) +; + (= - (select_indices () $_ ()) True) + (select_indices () $_ ()) True) +; + (= (select-indices (Cons $I $Is0) $Tag @@ -1941,31 +2182,41 @@ (= $Tag $T) (= $T var))) (set-det) - (select-indices $Is0 $Tag $Is))) + (select-indices $Is0 $Tag $Is))) +; + (= (select-indices (Cons $_ $Is0) $Tag $Is) - (select-indices $Is0 $Tag $Is)) + (select-indices $Is0 $Tag $Is)) +; + ; -; ;; Assert Fail Flag +; (= (assert-fail) - ( (get-atoms &self - (= fail_flag $_)) (set-det))) + ( (get-symbols &self + (= fail_flag $_)) (set-det))) +; + (= (assert-fail) - (add-atom &self fail_flag)) + (add-symbol &self fail_flag)) +; + ; -; ;; Generate Labels for Backtrack Point +; (= (--> - (generate_bp_label () $_ $_ () ()) !) True) + (generate_bp_label () $_ $_ () ()) !) True) +; + (= (--> (generate_bp_label @@ -1977,7 +2228,9 @@ (, ! (, ($X) - (generate_bp_label $Xs $CL $N $Ls $Hs))))) True) + (generate_bp_label $Xs $CL $N $Ls $Hs))))) True) +; + (= (--> (generate_bp_label @@ -1996,7 +2249,9 @@ (, { (is $N1 (+ $N 1)) } - (generate_bp_label $Xs $CL $N1 $Ls $Hs)))))) True) + (generate_bp_label $Xs $CL $N1 $Ls $Hs)))))) True) +; + (= (--> (generate_bp_label @@ -2015,7 +2270,9 @@ (, { (is $N1 (+ $N 1)) } - (generate_bp_label $Xs $CL $N1 $Ls $Hs)))))) True) + (generate_bp_label $Xs $CL $N1 $Ls $Hs)))))) True) +; + (= (--> (generate_bp_label @@ -2027,33 +2284,43 @@ (, ( (: $L ())) (generate_bp_label - (Cons $X $Xs) $L 1 $Ls $Hs)))) True) + (Cons $X $Xs) $L 1 $Ls $Hs)))) True) +; + (= (--> (generate_bp_label (Cons $X $Xs) $CL $N $Ls $Hs) (, ($X) - (generate_bp_label $Xs $CL $N $Ls $Hs))) True) + (generate_bp_label $Xs $CL $N $Ls $Hs))) True) +; + (= (generate-cl-label $_ $I $N Nil) - ( (> $I $N) (set-det))) + ( (> $I $N) (set-det))) +; + (= (generate-cl-label $FA $I $N (Cons (label (+ $FA $I)) $Ls)) ( (is $I1 - (+ $I 1)) (generate-cl-label $FA $I1 $N $Ls))) + (+ $I 1)) (generate-cl-label $FA $I1 $N $Ls))) +; + ; -; ;; Generate Hash instructions for switch_on_hash +; (= (--> - (gen_hash ()) !) True) + (gen_hash ()) !) True) +; + (= (--> (gen_hash @@ -2064,11 +2331,15 @@ ( (new_hash $T $S)) (, (gen_put_hash $H $T) - (gen_hash $Xs))))) True) + (gen_hash $Xs))))) True) +; + (= (--> - (gen_put_hash () $_) !) True) + (gen_put_hash () $_) !) True) +; + (= (--> (gen_put_hash @@ -2076,12 +2347,16 @@ (: $K $V) $Xs) $T) (, ( (put_hash $K $V $T)) - (gen_put_hash $Xs $T))) True) + (gen_put_hash $Xs $T))) True) +; + (= (replace-hash-keys Nil $_ Nil Nil) - (set-det)) + (set-det)) +; + (= (replace-hash-keys (Cons @@ -2090,12 +2365,16 @@ (put-hash $X $L $H) $PHs)) ( (set-det) (replace-key $K $SA $X) - (replace-hash-keys $Xs $SA $NHs $PHs))) + (replace-hash-keys $Xs $SA $NHs $PHs))) +; + (= (replace-hash-keys (Cons $X $Xs) $SA (Cons $X $NHs) $PHs) - (replace-hash-keys $Xs $SA $NHs $PHs)) + (replace-hash-keys $Xs $SA $NHs $PHs)) +; + (= @@ -2105,7 +2384,9 @@ (with_self $K (int)) (:: $X yes)) - (set-det))) + (set-det))) +; + (= (replace-key $K $Alloc $X) ( (float $K) @@ -2113,7 +2394,9 @@ (with_self $K (flo)) (:: $X yes)) - (set-det))) + (set-det))) +; + (= (replace-key $K $Alloc $X) ( (atom $K) @@ -2121,7 +2404,9 @@ (with_self $K (con)) (:: $X yes)) - (set-det))) + (set-det))) +; + (= (replace-key $K $Alloc $X) ( (nonvar $K) @@ -2133,13 +2418,17 @@ (with_self $K (con)) (:: $X yes)) - (set-det))) + (set-det))) +; + (= (replace-key $K $_ $_) - ( (pl2am-error (:: replacement of hash key $K failed)) (fail))) + ( (pl2am-error (:: replacement of hash key $K failed)) (fail))) +; + ; -; ;; Import Declarations +; (= @@ -2148,11 +2437,15 @@ { (findall (, $P $C) (import_package $P $C) $X) } - (gen_import $X))) True) + (gen_import $X))) True) +; + (= (--> - (gen_import ()) !) True) + (gen_import ()) !) True) +; + (= (--> (gen_import @@ -2161,7 +2454,9 @@ (, ! (, ( (import_package $P)) - (gen_import $Xs)))) True) + (gen_import $Xs)))) True) +; + (= (--> (gen_import @@ -2169,10 +2464,12 @@ (, $P $C) $Xs)) (, ( (import_package $P $C)) - (gen_import $Xs))) True) + (gen_import $Xs))) True) +; + ; -; ;; Information +; (= (--> @@ -2181,33 +2478,43 @@ { (clause (file_name $File) $_) } ( (info - ( (/ $Functor $Arity) $File))))) True) + ( (/ $Functor $Arity) $File))))) True) +; + ; -; ;; Check the Modifier of Predicate F/A. +; (= (check-modifier (/ %init 0) public) - (set-det)) + (set-det)) +; + (= (check-modifier (/ $F $A) public) - ( (get-atoms &self + ( (get-symbols &self (= - (public_predicates $F $A) $_)) (set-det))) + (public_predicates $F $A) $_)) (set-det))) +; + (= (check_modifier $_ - (- non public)) True) + (- non public)) True) +; + ; -; ;; generate a list of registers with given range. +; (= (range-reg $I $N $_ Nil) - ( (> $I $N) (set-det))) + ( (> $I $N) (set-det))) +; + (= (range-reg $I $N $A (Cons $R $Rs)) @@ -2216,15 +2523,19 @@ (+ $I 1)) (=.. $R (:: $A $I)) - (range-reg $I1 $N $A $Rs))) + (range-reg $I1 $N $A $Rs))) +; + ; -; ;; generate set instructions +; (= (--> - (gen_set () ()) !) True) + (gen_set () ()) !) True) +; + (= (--> (gen_set @@ -2232,14 +2543,18 @@ (Cons $Y $Ys)) (, ( (set $X $Y)) - (gen_set $Xs $Ys))) True) + (gen_set $Xs $Ys))) True) +; + ; -; ;; generate deref instructions +; (= (--> - (gen_deref () ()) !) True) + (gen_deref () ()) !) True) +; + (= (--> (gen_deref @@ -2247,10 +2562,12 @@ (Cons $Y $Ys)) (, ( (deref $X $Y)) - (gen_deref $Xs $Ys))) True) + (gen_deref $Xs $Ys))) True) +; + ; -; ;; generate set and deref instructions +; (= (--> @@ -2259,19 +2576,25 @@ { (range_reg $SN $EN $R1 $L1) } (, { (range_reg $SN $EN $R2 $L2) } - (gen_set_arg $Flag $L1 $L2)))) True) + (gen_set_arg $Flag $L1 $L2)))) True) +; + (= (--> (gen_set_arg set $L1 $L2) - (gen_set $L1 $L2)) True) + (gen_set $L1 $L2)) True) +; + (= (--> (gen_set_arg deref $L1 $L2) - (gen_deref $L1 $L2)) True) + (gen_deref $L1 $L2)) True) +; + ; -; ;; generate decl_var instructions +; (= (--> @@ -2290,23 +2613,33 @@ { (range_reg $P0 $P1 p $PL) } (, (gen_decl_term_vars $XL) - (gen_decl_pred_vars $PL)))))) True) + (gen_decl_pred_vars $PL)))))) True) +; + (= (--> - (gen_decl_term_vars ()) !) True) + (gen_decl_term_vars ()) !) True) +; + (= (--> (gen_decl_term_vars $XL) - ( (decl_term_vars $XL))) True) + ( (decl_term_vars $XL))) True) +; + (= (--> - (gen_decl_pred_vars ()) !) True) + (gen_decl_pred_vars ()) !) True) +; + (= (--> (gen_decl_pred_vars $PL) - ( (decl_pred_vars $PL))) True) + ( (decl_pred_vars $PL))) True) +; + (= (--> @@ -2323,18 +2656,7 @@ (:- $Head $Goals))) (, (compile_chunks $Instrs $GTI0 $GTI $LTI) !)))))) True) -; /**************************************************************** -; Compile Clause -; ****************************************************************/ - -; ; cut, rename, compile aith exp. - -; ; add package name for meta predicates - -; ; generate get, put, put_clo, put_cont, inline - -; ; output precompiled clause - +; (= (--> @@ -2342,27 +2664,35 @@ (, { (pl2am_error (compilation of $Clause failed)) } - {fail })) True) + {fail })) True) +; + ; -; ;;;;;;;;; Pretreat Body and Compile Arithmetic Expressions +; (= (pretreat-body $Body $Goals) - ( (pretreat-body0 $Body $Cut $Goals0 Nil) (pretreat-cut $Cut $Goals0 $Goals))) + ( (pretreat-body0 $Body $Cut $Goals0 Nil) (pretreat-cut $Cut $Goals0 $Goals))) +; + (= (pretreat-cut $Cut $Gs $Gs) - ( (var $Cut) (set-det))) + ( (var $Cut) (set-det))) +; + (= (pretreat-cut ($cut $Level) (Cons ($cut $Level) $Gs) (Cons %neck-cut $Gs)) - ( (not (pl2am-member ($cut $Level) $Gs)) (set-det))) + ( (not (pl2am-member ($cut $Level) $Gs)) (set-det))) +; + (= (pretreat-cut ($cut $Level) @@ -2371,12 +2701,16 @@ (Cons ($get-level $Level) (Cons %neck-cut $Gs))) - (set-det)) + (set-det)) +; + (= (pretreat_cut ($cut $Level) $Gs (Cons - ($get_level $Level) $Gs)) True) + (%get_level $Level) $Gs)) True) +; + (= @@ -2385,7 +2719,9 @@ (, { (var $G) } (, ! - ( (call $G))))) True) + ( (call $G))))) True) +; + (= (--> (pretreat_body0 ! $Cut) @@ -2393,33 +2729,47 @@ (, { (= $Cut ($cut $Level)) } - ( ($cut $Level))))) True) + ( ($cut $Level))))) True) +; + (= (--> - (pretreat_body0 otherwise $_) !) True) + (pretreat_body0 otherwise $_) !) True) +; + (= (--> - (pretreat_body0 true $_) !) True) + (pretreat_body0 true $_) !) True) +; + (= (--> (pretreat_body0 fail $_) (, ! - (fail))) True) + (fail))) True) +; + (= (--> (pretreat_body0 false $_) (, ! - (fail))) True) + (fail))) True) +; + (= (--> (pretreat_body0 halt $_) (, ! - (halt))) True) + (halt))) True) +; + (= (--> (pretreat_body0 abort $_) (, ! - (abort))) True) + (abort))) True) +; + (= (--> (pretreat_body0 @@ -2427,12 +2777,16 @@ (, ! (, (pretreat_body0 $G1 $Cut) - (pretreat_body0 $G2 $Cut)))) True) + (pretreat_body0 $G2 $Cut)))) True) +; + (= (--> (pretreat_body0 $G $_) (, - (pretreat_builtin $G) !)) True) + (pretreat_builtin $G) !)) True) +; + (= (--> (pretreat_body0 $G $_) @@ -2446,7 +2800,9 @@ (=.. $CG ($Call $G)))) } (, ! - ($CG)))) True) + ($CG)))) True) +; + (= (--> (pretreat_body0 @@ -2460,11 +2816,11 @@ (clause (dynamic_predicates $F $A $Call) $_) (, - (: - (\== $Call SxxMachine.builtin) call) + (\== $Call + (: SxxMachine.builtin call)) (, - (: - (= $Call $P) $C) + (= $Call + (: $P $C)) (, (clause (package_name $P1) $_) @@ -2473,70 +2829,92 @@ (, ! (pretreat_body0 (findall $X - (: $P $CG) $L) $Z)))) True) + (: $P $CG) $L) $Z)))) True) +; + (= (--> (pretreat_body0 $G $_) - ($G)) True) + ($G)) True) +; + ; -; ;; rename builtins +; (= (--> (pretreat_builtin (= $X $Y)) (, ! - ( ($unify $X $Y)))) True) + ( ($unify $X $Y)))) True) +; + (= (--> (pretreat_builtin (\= $X $Y)) (, ! - ( ($not_unifiable $X $Y)))) True) + ( (%not_unifiable $X $Y)))) True) +; + (= (--> (pretreat_builtin (== $X $Y)) (, ! - ( ($equality_of_term $X $Y)))) True) + ( (%equality_of_term $X $Y)))) True) +; + (= (--> (pretreat_builtin (\== $X $Y)) (, ! - ( ($inequality_of_term $X $Y)))) True) + ( (%inequality_of_term $X $Y)))) True) +; + (= (--> (pretreat_builtin (?= $X $Y)) (, ! - ( ($identical_or_cannot_unify $X $Y)))) True) + ( (%identical_or_cannot_unify $X $Y)))) True) +; + (= (--> (pretreat_builtin (@< $X $Y)) (, ! - ( ($before $X $Y)))) True) + ( ($before $X $Y)))) True) +; + (= (--> (pretreat_builtin (@> $X $Y)) (, ! - ( ($after $X $Y)))) True) + ( ($after $X $Y)))) True) +; + (= (--> (pretreat_builtin (@=< $X $Y)) (, ! - ( ($not_after $X $Y)))) True) + ( (%not_after $X $Y)))) True) +; + (= (--> (pretreat_builtin (@>= $X $Y)) (, ! - ( ($not_before $X $Y)))) True) + ( (%not_before $X $Y)))) True) +; + (= (--> (pretreat_builtin @@ -2544,7 +2922,9 @@ (, { (== $Op =) } (, ! - ( ($equality_of_term $X $Y))))) True) + ( (%equality_of_term $X $Y))))) True) +; + (= (--> (pretreat_builtin @@ -2552,7 +2932,9 @@ (, { (== $Op <) } (, ! - ( ($before $X $Y))))) True) + ( ($before $X $Y))))) True) +; + (= (--> (pretreat_builtin @@ -2560,13 +2942,17 @@ (, { (== $Op >) } (, ! - ( ($after $X $Y))))) True) + ( ($after $X $Y))))) True) +; + (= (--> (pretreat_builtin (=.. $X $Y)) (, ! - ( ($univ $X $Y)))) True) + ( ($univ $X $Y)))) True) +; + (= (--> (pretreat_builtin @@ -2576,7 +2962,9 @@ (pretreat_is $U $X) (, (pretreat_is $V $Y) - ( ($arith_equal $U $V)))))) True) + ( (%arith_equal $U $V)))))) True) +; + (= (--> (pretreat_builtin @@ -2586,7 +2974,9 @@ (pretreat_is $U $X) (, (pretreat_is $V $Y) - ( ($arith_not_equal $U $V)))))) True) + ( (%arith_not_equal $U $V)))))) True) +; + (= (--> (pretreat_builtin @@ -2596,7 +2986,9 @@ (pretreat_is $U $X) (, (pretreat_is $V $Y) - ( ($greater_than $U $V)))))) True) + ( (%greater_than $U $V)))))) True) +; + (= (--> (pretreat_builtin @@ -2606,7 +2998,9 @@ (pretreat_is $U $X) (, (pretreat_is $V $Y) - ( ($greater_or_equal $U $V)))))) True) + ( (%greater_or_equal $U $V)))))) True) +; + (= (--> (pretreat_builtin @@ -2616,7 +3010,9 @@ (pretreat_is $U $X) (, (pretreat_is $V $Y) - ( ($less_than $U $V)))))) True) + ( (%less_than $U $V)))))) True) +; + (= (--> (pretreat_builtin @@ -2626,13 +3022,17 @@ (pretreat_is $U $X) (, (pretreat_is $V $Y) - ( ($less_or_equal $U $V)))))) True) + ( (%less_or_equal $U $V)))))) True) +; + (= (--> (pretreat_builtin (is $Z $X)) (, ! - (pretreat_is0 $Z $X))) True) + (pretreat_is0 $Z $X))) True) +; + (= (--> @@ -2640,11 +3040,15 @@ (, { (var $X) } (, ! - { (= $X $Z) }))) True) + { (= $X $Z) }))) True) +; + (= (--> (pretreat_is $Z $X) - (pretreat_is0 $Z $X)) True) + (pretreat_is0 $Z $X)) True) +; + (= (--> @@ -2653,14 +3057,18 @@ { (clause (pl2am_flag ac) $_) } (, ! - (precompile_is $X $Z)))) True) + (precompile_is $X $Z)))) True) +; + (= (--> (pretreat_is0 $Z $X) - ( (is $Z $X))) True) + ( (is $Z $X))) True) +; + ; -; ;; compile aithmetic expressions +; (= (--> @@ -2668,34 +3076,44 @@ (, { (var $X) } (, ! - ( (is $A $X))))) True) + ( (is $A $X))))) True) +; + (= (--> (precompile_is $X $A) (, { (number $X) } (, ! - { (= $X $A) }))) True) + { (= $X $A) }))) True) +; + (= (--> (precompile_is $X $A) (, { (builtin_arith_constant $X) } (, ! - { (= $X $A) }))) True) + { (= $X $A) }))) True) +; + (= (--> (precompile_is (+ $X) $A) (, ! - (precomp_is $X $A))) True) + (precomp_is $X $A))) True) +; + (= (--> (precompile_is (- $X) $A) (, ! (precompile_is - (* -1 $X) $A))) True) + (* -1 $X) $A))) True) +; + (= (--> (precompile_is @@ -2705,7 +3123,9 @@ (precomp_is $X $U) (, (precomp_is $Y $V) - ( ($plus $U $V $A)))))) True) + ( ($plus $U $V $A)))))) True) +; + (= (--> (precompile_is @@ -2715,7 +3135,9 @@ (precomp_is $X $U) (, (precomp_is $Y $V) - ( ($minus $U $V $A)))))) True) + ( ($minus $U $V $A)))))) True) +; + (= (--> (precompile_is @@ -2725,7 +3147,9 @@ (precomp_is $X $U) (, (precomp_is $Y $V) - ( ($multi $U $V $A)))))) True) + ( ($multi $U $V $A)))))) True) +; + (= (--> (precompile_is @@ -2735,7 +3159,9 @@ (precomp_is $X $U) (, (precomp_is $Y $V) - ( ($float_quotient $U $V $A)))))) True) + ( (%float_quotient $U $V $A)))))) True) +; + (= (--> (precompile_is @@ -2745,7 +3171,9 @@ (precomp_is $X $U) (, (precomp_is $Y $V) - ( ($int_quotient $U $V $A)))))) True) + ( (%int_quotient $U $V $A)))))) True) +; + (= (--> (precompile_is @@ -2755,7 +3183,9 @@ (precomp_is $X $U) (, (precomp_is $Y $V) - ( ($mod $U $V $A)))))) True) + ( ($mod $U $V $A)))))) True) +; + (= (--> (precompile_is @@ -2765,7 +3195,9 @@ (precomp_is $X $U) (, (precomp_is $Y $V) - ( ($mod $U $V $A)))))) True) + ( ($mod $U $V $A)))))) True) +; + (= (--> (precompile_is @@ -2775,7 +3207,9 @@ (precomp_is $X $U) (, (precomp_is $Y $V) - ( ($bitwise_conj $U $V $A)))))) True) + ( (%bitwise_conj $U $V $A)))))) True) +; + (= (--> (precompile_is @@ -2785,7 +3219,9 @@ (precomp_is $X $U) (, (precomp_is $Y $V) - ( ($bitwise_disj $U $V $A)))))) True) + ( (%bitwise_disj $U $V $A)))))) True) +; + (= (--> (precompile_is @@ -2795,7 +3231,9 @@ (precomp_is $X $U) (, (precomp_is $Y $V) - ( ($bitwise_exclusive_or $U $V $A)))))) True) + ( (%bitwise_exclusive_or $U $V $A)))))) True) +; + (= (--> (precompile_is @@ -2803,7 +3241,9 @@ (, ! (, (precomp_is $X $U) - ( ($bitwise_neg $U $A))))) True) + ( (%bitwise_neg $U $A))))) True) +; + (= (--> (precompile_is @@ -2813,7 +3253,9 @@ (precomp_is $X $U) (, (precomp_is $Y $V) - ( ($shift_left $U $V $A)))))) True) + ( (%shift_left $U $V $A)))))) True) +; + (= (--> (precompile_is @@ -2823,13 +3265,17 @@ (precomp_is $X $U) (, (precomp_is $Y $V) - ( ($shift_right $U $V $A)))))) True) + ( (%shift_right $U $V $A)))))) True) +; + (= (--> (precompile_is ($X) $A) (, ! - (precomp_is $X $A))) True) + (precomp_is $X $A))) True) +; + (= (--> (precompile_is @@ -2837,7 +3283,9 @@ (, ! (, (precomp_is $X $U) - ( ($abs $U $A))))) True) + ( ($abs $U $A))))) True) +; + (= (--> (precompile_is @@ -2847,7 +3295,9 @@ (precomp_is $X $U) (, (precomp_is $Y $V) - ( ($min $U $V $A)))))) True) + ( ($min $U $V $A)))))) True) +; + (= (--> (precompile_is @@ -2857,7 +3307,9 @@ (precomp_is $X $U) (, (precomp_is $Y $V) - ( ($max $U $V $A)))))) True) + ( ($max $U $V $A)))))) True) +; + (= (--> (precompile_is @@ -2865,7 +3317,9 @@ (, ! (, (precomp_is $X $U) - ( ($round $U $A))))) True) + ( ($round $U $A))))) True) +; + (= (--> (precompile_is @@ -2873,7 +3327,9 @@ (, ! (, (precomp_is $X $U) - ( ($floor $U $A))))) True) + ( ($floor $U $A))))) True) +; + (= (--> (precompile_is @@ -2881,7 +3337,9 @@ (, ! (, (precomp_is $X $U) - ( ($ceil $U $A))))) True) + ( ($ceil $U $A))))) True) +; + (= (--> (precompile_is @@ -2889,7 +3347,9 @@ (, ! (, (precomp_is $X $U) - ( ($sin $U $A))))) True) + ( ($sin $U $A))))) True) +; + (= (--> (precompile_is @@ -2897,7 +3357,9 @@ (, ! (, (precomp_is $X $U) - ( ($cos $U $A))))) True) + ( ($cos $U $A))))) True) +; + (= (--> (precompile_is @@ -2905,7 +3367,9 @@ (, ! (, (precomp_is $X $U) - ( ($tan $U $A))))) True) + ( ($tan $U $A))))) True) +; + (= (--> (precompile_is @@ -2913,7 +3377,9 @@ (, ! (, (precomp_is $X $U) - ( ($asin $U $A))))) True) + ( ($asin $U $A))))) True) +; + (= (--> (precompile_is @@ -2921,7 +3387,9 @@ (, ! (, (precomp_is $X $U) - ( ($acos $U $A))))) True) + ( ($acos $U $A))))) True) +; + (= (--> (precompile_is @@ -2929,7 +3397,9 @@ (, ! (, (precomp_is $X $U) - ( ($atan $U $A))))) True) + ( ($atan $U $A))))) True) +; + (= (--> (precompile_is @@ -2937,7 +3407,9 @@ (, ! (, (precomp_is $X $U) - ( ($sqrt $U $A))))) True) + ( ($sqrt $U $A))))) True) +; + (= (--> (precompile_is @@ -2945,7 +3417,9 @@ (, ! (, (precomp_is $X $U) - ( ($log $U $A))))) True) + ( ($log $U $A))))) True) +; + (= (--> (precompile_is @@ -2953,7 +3427,9 @@ (, ! (, (precomp_is $X $U) - ( ($exp $U $A))))) True) + ( ($exp $U $A))))) True) +; + (= (--> (precompile_is @@ -2963,7 +3439,9 @@ (precomp_is $X $U) (, (precomp_is $Y $V) - ( ($pow $U $V $A)))))) True) + ( ($pow $U $V $A)))))) True) +; + (= (--> (precompile_is @@ -2971,7 +3449,9 @@ (, ! (, (precomp_is $X $U) - ( ($degrees $U $A))))) True) + ( ($degrees $U $A))))) True) +; + (= (--> (precompile_is @@ -2979,7 +3459,9 @@ (, ! (, (precomp_is $X $U) - ( ($radians $U $A))))) True) + ( ($radians $U $A))))) True) +; + (= (--> (precompile_is @@ -2987,7 +3469,9 @@ (, ! (, (precomp_is $X $U) - ( ($rint $U $A))))) True) + ( ($rint $U $A))))) True) +; + (= (--> (precompile_is @@ -2995,7 +3479,9 @@ (, ! (, (precomp_is $X $U) - ( ($float $U $A))))) True) + ( ($float $U $A))))) True) +; + (= (--> (precompile_is @@ -3003,7 +3489,9 @@ (, ! (, (precomp_is $X $U) - ( ($float_integer_part $U $A))))) True) + ( (%float_integer_part $U $A))))) True) +; + (= (--> (precompile_is @@ -3011,7 +3499,9 @@ (, ! (, (precomp_is $X $U) - ( ($float_fractional_part $U $A))))) True) + ( (%float_fractional_part $U $A))))) True) +; + (= (--> (precompile_is @@ -3019,7 +3509,9 @@ (, ! (, (precomp_is $X $U) - ( ($truncate $U $A))))) True) + ( ($truncate $U $A))))) True) +; + (= (--> (precompile_is @@ -3027,14 +3519,18 @@ (, ! (, (precomp_is $X $U) - ( ($sign $U $A))))) True) + ( ($sign $U $A))))) True) +; + (= (--> (precompile_is $X $_) (, { (pl2am_error (unknown arithemetic expression $X)) } - {fail })) True) + {fail })) True) +; + (= (--> @@ -3044,38 +3540,48 @@ (, { (var $A) } (, ! - { (= $X $A) })))) True) + { (= $X $A) })))) True) +; + (= (--> (precomp_is $X $A) - (precompile_is $X $A)) True) + (precompile_is $X $A)) True) +; + ; -; ;;;;;;;;; Add Pacakge (module) name to meta predicates +; (= (localize-meta $G0 $G) - ( (get-atoms &self + ( (get-symbols &self (= (package_name $P) $_)) (localize-meta $G0 $P $G) - (set-det))) + (set-det))) +; + (= (localize-meta Nil $_ Nil) - (set-det)) + (set-det)) +; + (= (localize-meta (Cons $G $Gs) $P (Cons $G1 $Gs1)) ( (localize-meta-goal $G $P $X) (det-if-then-else - (with_self - (= $X $P) $Y) + (= $X + (with_self $P $Y)) (= $G1 $Y) (= $G1 $X)) - (localize-meta $Gs $P $Gs1))) + (localize-meta $Gs $P $Gs1))) +; + (= @@ -3083,37 +3589,47 @@ ( (var $G) (set-det) (localize-meta-goal - (call $G) $P $G1))) + (call $G) $P $G1))) +; + (= (localize-meta-goal (with_self $P $G) $_ $G1) - ( (set-det) (localize-meta-goal $G $P $G1))) + ( (set-det) (localize-meta-goal $G $P $G1))) +; + (= (localize-meta-goal (, $X $Y) $P (, $X1 $Y1)) ( (set-det) (localize-meta-goal $X $P $X1) - (localize-meta-goal $Y $P $Y1))) + (localize-meta-goal $Y $P $Y1))) +; + (= (localize-meta-goal (det-if-then $X $Y) $P (det-if-then $X1 $Y1)) ( (set-det) (localize-meta-goal $X $P $X1) - (localize-meta-goal $Y $P $Y1))) + (localize-meta-goal $Y $P $Y1))) +; + (= (localize-meta-goal (or $X $Y) $P (or $X1 $Y1)) ( (set-det) (localize-meta-goal $X $P $X1) - (localize-meta-goal $Y $P $Y1))) + (localize-meta-goal $Y $P $Y1))) +; + (= (localize-meta-goal $G $P $G1) ( (functor $G $F $A) (or - (get-atoms &self + (get-symbols &self (= (meta_predicates $F $A $M) $_)) (builtin-local-predicates $F $A $M)) @@ -3122,22 +3638,32 @@ (Cons $F $As)) (localize-meta-args $M $As $P $As1) (=.. $G1 - (Cons $F $As1)))) + (Cons $F $As1)))) +; + (= (localize-meta-goal $G $P (call (with_self $P $G))) - ( (var $P) (set-det))) + ( (var $P) (set-det))) +; + (= (localize-meta-goal $G $_ $G) - ( (system-predicate $G) (set-det))) + ( (system-predicate $G) (set-det))) +; + (= (localize_meta_goal $G $P - (: $P $G)) True) + (: $P $G)) True) +; + (= (localize-meta-args Nil Nil $_ Nil) - (set-det)) + (set-det)) +; + (= (localize-meta-args (Cons : $Ms) @@ -3146,10 +3672,12 @@ (with_self $P $A) $As1)) ( (or (var $A) - (with_self - (\= $A $_) $_)) + (\= $A + (with_self $_ $_))) (set-det) - (localize-meta-args $Ms $As $P $As1))) + (localize-meta-args $Ms $As $P $As1))) +; + (= (localize-meta-args (Cons or $Ms) @@ -3158,29 +3686,35 @@ (with_self $P $A) $As1)) ( (or (var $A) - (with_self - (\= $A $_) $_)) + (\= $A + (with_self $_ $_))) (set-det) - (localize-meta-args $Ms $As $P $As1))) + (localize-meta-args $Ms $As $P $As1))) +; + (= (localize-meta-args (Cons $_ $Ms) (Cons $A $As) $P (Cons $A $As1)) - (localize-meta-args $Ms $As $P $As1)) + (localize-meta-args $Ms $As $P $As1)) +; + ; -; ;;;;;;;;; Precompile Clause and Optimize Recursive Call +; (= (precompile $Head $Goals $Instrs) ( (precompile-head $Head $Instrs0 $Bs) (precompile-body $Goals $Bs Nil) - (optimize-recursive-call $Head $Instrs0 $Instrs))) + (optimize-recursive-call $Head $Instrs0 $Instrs))) +; + ; -; ;; Precompile head (generates get instructions) +; (= @@ -3189,11 +3723,15 @@ (, { (=.. $Head (Cons $_ $Args)) } - (precomp_head $Args 1))) True) + (precomp_head $Args 1))) True) +; + (= (--> - (precomp_head () $_) !) True) + (precomp_head () $_) !) True) +; + (= (--> (precomp_head @@ -3204,13 +3742,15 @@ (, { (is $I1 (+ $I 1)) } - (precomp_head $As $I1)))) True) + (precomp_head $As $I1)))) True) +; + ; -; ;; Precompile body +; ; -; ;; (generates put, put_clo, put_cont, and inline instructions) +; (= (--> @@ -3221,17 +3761,23 @@ (, ! (, { (pickup_inline_goals $Goals $IGs $Gs) } - (precomp_inline $IGs $Gs))))) True) + (precomp_inline $IGs $Gs))))) True) +; + (= (--> (precompile_body $Goals) - (precomp_body $Goals)) True) + (precomp_body $Goals)) True) +; + (= (--> (precomp_body ()) (, ! - ( (execute cont)))) True) + ( (execute cont)))) True) +; + (= (--> (precomp_body @@ -3241,14 +3787,18 @@ (, (binarize_body $G $Cont $G1) ( (execute - (: $M $G1)))))) True) + (: $M $G1)))))) True) +; + (= (--> (precomp_body (Cons $G $Cont)) (, (binarize_body $G $Cont $G1) - ( (execute $G1)))) True) + ( (execute $G1)))) True) +; + (= (--> @@ -3267,22 +3817,14 @@ ($V) $Ws) } { (=.. $G1 (Cons $F $Ws)) })))))) True) -; /*--------------------------------------------------------------- -; Binarization technique was developed by P.Tarau and M.Boyer, -; please see: -; * "Elementary Logic Programs" -; P.Tarau and M.Boyer -; Programming Language Implementation and Logic Programming, -; pp.159--173, LNCS 456, Springer Verlag, 1990 -; ----------------------------------------------------------------*/ - -; ;precomp_call(Args, Us), ; for no closure - +; (= (--> - (precomp_call () ()) !) True) + (precomp_call () ()) !) True) +; + (= (--> (precomp_call @@ -3290,11 +3832,15 @@ (Cons $U $Us)) (, ( (put $A $U)) - (precomp_call $As $Us))) True) + (precomp_call $As $Us))) True) +; + (= (--> - (precomp_cont () cont) !) True) + (precomp_cont () cont) !) True) +; + (= (--> (precomp_cont @@ -3304,26 +3850,34 @@ (, (binarize_body $G $Cont $G1) ( (put_cont - (: $M $G1) $V))))) True) + (: $M $G1) $V))))) True) +; + (= (--> (precomp_cont (Cons $G $Cont) $V) (, (binarize_body $G $Cont $G1) - ( (put_cont $G1 $V)))) True) + ( (put_cont $G1 $V)))) True) +; + (= (--> (precomp_inline () $Gs1) (, ! - (precomp_body $Gs1))) True) + (precomp_body $Gs1))) True) +; + (= (--> (precomp_inline (Cons fail $_) $_) (, ! - ( (inline fail)))) True) + ( (inline fail)))) True) +; + (= (--> (precomp_inline @@ -3341,26 +3895,31 @@ (, ( (inline $G1)) (precomp_inline $Gs $Gs1))))))) True) -; ;precomp_call(Args, Us), - +; (= (pickup-inline-goals Nil Nil Nil) - (set-det)) + (set-det)) +; + (= (pickup-inline-goals (Cons $G $Gs) (Cons $G $IGs) $BGs) ( (builtin-inline-predicates $G) (set-det) - (pickup-inline-goals $Gs $IGs $BGs))) + (pickup-inline-goals $Gs $IGs $BGs))) +; + (= - (pickup_inline_goals $Gs () $Gs) True) + (pickup_inline_goals $Gs () $Gs) True) +; + ; -; ;; Generate Closure +; (= @@ -3376,15 +3935,21 @@ (, { (clause (package_name $P) $_) } - (precomp_closure $Mode $As $P $Us)))))) True) + (precomp_closure $Mode $As $P $Us)))))) True) +; + (= (--> (precomp_call $As $Us $_ $_) - (precomp_call $As $Us)) True) + (precomp_call $As $Us)) True) +; + (= (--> - (precomp_closure () () $_ ()) !) True) + (precomp_closure () () $_ ()) !) True) +; + (= (--> (precomp_closure @@ -3396,7 +3961,9 @@ (, ! (, ( (put_clo $C $U)) - (precomp_closure $Ms $As $P $Us))))) True) + (precomp_closure $Ms $As $P $Us))))) True) +; + (= (--> (precomp_closure @@ -3405,53 +3972,66 @@ (Cons $U $Us)) (, ( (put $A $U)) - (precomp_closure $Ms $As $P $Us))) True) + (precomp_closure $Ms $As $P $Us))) True) +; + (= (get-closure $G $_ $_) ( (var $G) (set-det) - (fail))) + (fail))) +; + (= (get-closure $_ $P $_) ( (var $P) (set-det) - (fail))) + (fail))) +; + (= (get-closure (with_self $P $G) $_ $Clo) - ( (set-det) (get-closure $G $P $Clo))) + ( (set-det) (get-closure $G $P $Clo))) +; + (= (get-closure $G $P (with_self $P $G)) ( (atom $P) (callable $G) (functor $G $F $A) - (not (get-atoms &self (= (dynamic_predicates $F $A $_) $_))) + (not (get-symbols &self (= (dynamic_predicates $F $A $_) $_))) (set-det))) -; ; ??? - +; ; -; ;; Optimize Recursive Call +; (= (optimize-recursive-call $Head $Instrs0 $Instrs) - ( (get-atoms &self + ( (get-symbols &self (= (pl2am_flag rc) $_)) (set-det) - (optimize-rc $Instrs0 $Head $Instrs Nil))) + (optimize-rc $Instrs0 $Head $Instrs Nil))) +; + (= - (optimize_recursive_call $_ $Instrs $Instrs) True) + (optimize_recursive_call $_ $Instrs $Instrs) True) +; + (= (--> - (optimize_rc () $_) !) True) + (optimize_rc () $_) !) True) +; + (= (--> (optimize_rc @@ -3482,17 +4062,21 @@ ( (goto (+ (/ $F $A) top))) - (optimize_rc $Xs $Head)))))))))))) True) + (optimize_rc $Xs $Head)))))))))))) True) +; + (= (--> (optimize_rc (Cons $X $Xs) $Head) (, ($X) - (optimize_rc $Xs $Head))) True) + (optimize_rc $Xs $Head))) True) +; + ; -; ;;;;;;;;; Compile Clause +; (= (--> @@ -3500,13 +4084,14 @@ (, { (alloc_voids $Chunk () $Alloc) } (compile_chunk $Chunk $Alloc $GTI0 $GTI $LTI))) True) -; ; check void variables - +; (= (--> - (compile_chunk () $_ $GTI $GTI ()) !) True) + (compile_chunk () $_ $GTI $GTI ()) !) True) +; + (= (--> (compile_chunk $Chunk $Alloc $GTI0 $GTI $LTI) @@ -3519,11 +4104,15 @@ (, { (= $LTI0 ($XN $YN $PN $Alloc)) } - (comp_chunk $Chunk $LTI0 $LTI $GTI0 $GTI)))) True) + (comp_chunk $Chunk $LTI0 $LTI $GTI0 $GTI)))) True) +; + (= (--> - (comp_chunk () $LTI $LTI $GTI $GTI) !) True) + (comp_chunk () $LTI $LTI $GTI $GTI) !) True) +; + (= (--> (comp_chunk @@ -3532,7 +4121,9 @@ (, ! (, ( (: $L ())) - (comp_chunk $Cs $LTI0 $LTI $GTI0 $GTI)))) True) + (comp_chunk $Cs $LTI0 $LTI $GTI0 $GTI)))) True) +; + (= (--> (comp_chunk @@ -3542,7 +4133,9 @@ (, ( (: $L ())) (comp_chunk - (Cons $C $Cs) $LTI0 $LTI $GTI0 $GTI)))) True) + (Cons $C $Cs) $LTI0 $LTI $GTI0 $GTI)))) True) +; + (= (--> (comp_chunk @@ -3550,14 +4143,18 @@ (, ! (, (comp_instr $C $LTI0 $LTI1 $GTI0 $GTI1) - (comp_chunk $Cs $LTI1 $LTI $GTI1 $GTI)))) True) + (comp_chunk $Cs $LTI1 $LTI $GTI1 $GTI)))) True) +; + ; -; ;; finds an available number A-register +; (= - (free_x_reg () $XN $XN) True) + (free_x_reg () $XN $XN) True) +; + (= (free-x-reg (Cons @@ -3569,7 +4166,9 @@ (is $XN1 (max (+ $N 1) $XN0)) - (free-x-reg $Cs $XN1 $XN))) + (free-x-reg $Cs $XN1 $XN))) +; + (= (free-x-reg (Cons @@ -3581,23 +4180,31 @@ (is $XN1 (max (+ $N 1) $XN0)) - (free-x-reg $Cs $XN1 $XN))) + (free-x-reg $Cs $XN1 $XN))) +; + (= (free-x-reg (Cons $_ $Cs) $XN0 $XN) - (free-x-reg $Cs $XN0 $XN)) + (free-x-reg $Cs $XN0 $XN)) +; + ; -; ;; finds void variables and allocates them in Alloc. +; (= (alloc-voids $Chunks $Alloc0 $Alloc) - ( (variables $Chunks $Vars) (alloc-voids1 $Vars $Chunks $Alloc0 $Alloc))) + ( (variables $Chunks $Vars) (alloc-voids1 $Vars $Chunks $Alloc0 $Alloc))) +; + (= - (alloc_voids1 () $_ $Alloc $Alloc) True) + (alloc_voids1 () $_ $Alloc $Alloc) True) +; + (= (alloc-voids1 (Cons $V $Vars) $Chunks $Alloc0 $Alloc) @@ -3606,14 +4213,18 @@ (= $Alloc1 (Cons (:: $V void $Seen) $Alloc0)) - (alloc-voids1 $Vars $Chunks $Alloc1 $Alloc))) + (alloc-voids1 $Vars $Chunks $Alloc1 $Alloc))) +; + (= (alloc-voids1 (Cons $_ $Vars) $Chunks $Alloc0 $Alloc) - (alloc-voids1 $Vars $Chunks $Alloc0 $Alloc)) + (alloc-voids1 $Vars $Chunks $Alloc0 $Alloc)) +; + ; -; ;;;;;;;;; Compile Precompiled Instructions: get, put, put_clo, and put_cont +; (= @@ -3622,48 +4233,41 @@ (get $X $A) $LTI0 $LTI $GTI0 $GTI) (, ! (gen_get $X $A $LTI0 $LTI $GTI0 $GTI))) True) -; /* -; comp_instr(+Instr, +LTI0, ?LTI, +GTI0, ?GTI) -; Instr : Intermediate instruction -; LTI : [XN, YN, PN, Alloc] -; XN : The register a(XN) is available for "Term". -; YN : The register y(YN) is available for "Term[]". -; PN : The register p(PN) is available for "Predicate". -; Alloc : [[VarTerm, Register, Seen],...] -; GTI : [SN, SAlloc, SInstrs] -; SN : The registers s(SN), si(SN), or sf(SN) are available for static "Term". -; SAlloc : [[NonVarTerm:Type, Register, Seen],...] -; SInstrs : list of instructions for static terms. -; Seen : Unbound variable | yes | void -; Type : int | flo | con | str | lis | arr -; */ - +; (= (--> (comp_instr (put $X $V) $LTI0 $LTI $GTI0 $GTI) (, ! - (gen_put $X $V $LTI0 $LTI $GTI0 $GTI))) True) + (gen_put $X $V $LTI0 $LTI $GTI0 $GTI))) True) +; + (= (--> (comp_instr (put_clo $X $V) $LTI0 $LTI $GTI0 $GTI) (, ! - (gen_put_clo $X $V $LTI0 $LTI $GTI0 $GTI))) True) + (gen_put_clo $X $V $LTI0 $LTI $GTI0 $GTI))) True) +; + (= (--> (comp_instr (put_cont $X $V) $LTI0 $LTI $GTI0 $GTI) (, ! - (gen_put_cont $X $V $LTI0 $LTI $GTI0 $GTI))) True) + (gen_put_cont $X $V $LTI0 $LTI $GTI0 $GTI))) True) +; + (= (--> (comp_instr $Instr $LTI $LTI $GTI $GTI) - ($Instr)) True) + ($Instr)) True) +; + ; -; ;;;;;;;;; put instructions +; (= (--> @@ -3674,7 +4278,9 @@ (, { (pl2am_error ($A should be an unbound variable)) } - {fail })))) True) + {fail })))) True) +; + (= (--> (gen_put $X $A $LTI0 $LTI $GTI $GTI) @@ -3683,7 +4289,9 @@ (, ! (, { (assign_reg $X $R $Seen $LTI0 $LTI) } - (gen_put_var $R $Seen $A))))) True) + (gen_put_var $R $Seen $A))))) True) +; + (= (--> (gen_put $X $A $LTI $LTI $GTI0 $GTI) @@ -3693,7 +4301,9 @@ (, { (assign_sreg (: $X int) $R $Seen $GTI0 $GTI1) } - (gen_put_int $X $R $Seen $A $GTI1 $GTI))))) True) + (gen_put_int $X $R $Seen $A $GTI1 $GTI))))) True) +; + (= (--> (gen_put $X $A $LTI $LTI $GTI0 $GTI) @@ -3703,7 +4313,9 @@ (, { (assign_sreg (: $X long) $R $Seen $GTI0 $GTI1) } - (gen_put_int $X $R $Seen $A $GTI1 $GTI))))) True) + (gen_put_int $X $R $Seen $A $GTI1 $GTI))))) True) +; + (= (--> (gen_put $X $A $LTI $LTI $GTI0 $GTI) @@ -3713,17 +4325,21 @@ (, { (assign_sreg (: $X flo) $R $Seen $GTI0 $GTI1) } - (gen_put_float $X $R $Seen $A $GTI1 $GTI))))) True) + (gen_put_float $X $R $Seen $A $GTI1 $GTI))))) True) +; + (= (--> (gen_put $X $A $LTI $LTI $GTI0 $GTI) (, - { (atom $X) } + { (is-symbol $X) } (, ! (, { (assign_sreg (: $X con) $R $Seen $GTI0 $GTI1) } - (gen_put_con $X $R $Seen $A $GTI1 $GTI))))) True) + (gen_put_con $X $R $Seen $A $GTI1 $GTI))))) True) +; + (= (--> (gen_put $X $A $LTI0 $LTI $GTI0 $GTI) @@ -3741,7 +4357,9 @@ { (assign_sreg (: $X lis) $R $Seen $GTI1 $GTI2) } (gen_put_list - ($R1 $R2) $R $Seen $A $GTI2 $GTI)))))) True) + ($R1 $R2) $R $Seen $A $GTI2 $GTI)))))) True) +; + (= (--> (gen_put $X $A $LTI0 $LTI $GTI0 $GTI) @@ -3771,7 +4389,9 @@ { (assign_sreg (: $X str) $R $Seen $GTI5 $GTI6) } (gen_put_str - ($R0 $R1) $R $Seen $A $GTI6 $GTI)))))))))) True) + ($R0 $R1) $R $Seen $A $GTI6 $GTI)))))))))) True) +; + (= (--> (gen_put $X $A $LTI0 $LTI $GTI0 $GTI) @@ -3789,7 +4409,9 @@ { (, (= $Seen yes) (= $R $A)) } - ( (put_list $R1 $R2 $R)))))))) True) + ( (put_list $R1 $R2 $R)))))))) True) +; + (= (--> (gen_put $X $A $LTI0 $LTI $GTI0 $GTI) @@ -3818,14 +4440,18 @@ (= $R $A)) } (, ( (put_str_args $Regs $R1)) - ( (put_str $R0 $R1 $R)))))))))))) True) + ( (put_str $R0 $R1 $R)))))))))))) True) +; + (= (--> (gen_put_var void $_ $A) (, ! - { (= $A void) })) True) ; -; void is a special constant. + { (= $A void) })) True) +; + ; +; (= (--> @@ -3837,11 +4463,15 @@ { (, (= $Seen yes) (= $R $A)) } - ( (put_var $R)))))) True) + ( (put_var $R)))))) True) +; + (= (--> (gen_put_var $R $_ $A) - { (= $R $A) }) True) + { (= $R $A) }) True) +; + (= (--> @@ -3854,11 +4484,15 @@ (= $Seen yes) (= $R $A)) } { (add_instr - (put_int $X $R) $GTI0 $GTI) })))) True) + (put_int $X $R) $GTI0 $GTI) })))) True) +; + (= (--> (gen_put_int $_ $R $_ $A $GTI $GTI) - { (= $R $A) }) True) + { (= $R $A) }) True) +; + (= (--> @@ -3871,11 +4505,15 @@ (= $Seen yes) (= $R $A)) } { (add_instr - (put_float $X $R) $GTI0 $GTI) })))) True) + (put_float $X $R) $GTI0 $GTI) })))) True) +; + (= (--> (gen_put_float $_ $R $_ $A $GTI $GTI) - { (= $R $A) }) True) + { (= $R $A) }) True) +; + (= (--> @@ -3888,11 +4526,15 @@ (= $Seen yes) (= $R $A)) } { (add_instr - (put_con $X $R) $GTI0 $GTI) })))) True) + (put_con $X $R) $GTI0 $GTI) })))) True) +; + (= (--> (gen_put_con $_ $R $_ $A $GTI $GTI) - { (= $R $A) }) True) + { (= $R $A) }) True) +; + (= (--> @@ -3906,11 +4548,15 @@ (= $Seen yes) (= $R $A)) } { (add_instr - (put_list $R1 $R2 $R) $GTI0 $GTI) })))) True) + (put_list $R1 $R2 $R) $GTI0 $GTI) })))) True) +; + (= (--> (gen_put_list $_ $R $_ $A $GTI $GTI) - { (= $R $A) }) True) + { (= $R $A) }) True) +; + (= (--> @@ -3923,11 +4569,15 @@ (= $Seen yes) (= $R $A)) } { (add_instr - (put_str_args $Regs $R) $GTI0 $GTI) })))) True) + (put_str_args $Regs $R) $GTI0 $GTI) })))) True) +; + (= (--> (gen_put_str_args $_ $R $_ $A $GTI $GTI) - { (= $R $A) }) True) + { (= $R $A) }) True) +; + (= (--> @@ -3941,15 +4591,21 @@ (= $Seen yes) (= $R $A)) } { (add_instr - (put_str $R0 $R1 $R) $GTI0 $GTI) })))) True) + (put_str $R0 $R1 $R) $GTI0 $GTI) })))) True) +; + (= (--> (gen_put_str $_ $R $_ $A $GTI $GTI) - { (= $R $A) }) True) + { (= $R $A) }) True) +; + (= (--> - (gen_put_args () () $LTI $LTI $GTI $GTI) !) True) + (gen_put_args () () $LTI $LTI $GTI $GTI) !) True) +; + (= (--> (gen_put_args @@ -3957,7 +4613,9 @@ (Cons $R $Rs) $LTI0 $LTI $GTI0 $GTI) (, (gen_put $X $R $LTI0 $LTI1 $GTI0 $GTI1) - (gen_put_args $Xs $Rs $LTI1 $LTI $GTI1 $GTI))) True) + (gen_put_args $Xs $Rs $LTI1 $LTI $GTI1 $GTI))) True) +; + (= (--> @@ -3984,22 +4642,28 @@ (clause (package_name $P) $_) (= $CLO $X1)) - (: - (= $CLO $P) $X1)) } - ( (put_clo $CLO $R)))))))))) True) + (= $CLO + (: $P $X1))) } + ( (put_clo $CLO $R)))))))))) True) +; + ; -; ;;;;;;;;; get instructions +; (= (--> (gen_get $X $A $LTI0 $LTI $GTI0 $GTI) (gen_get - ( (= $A $X)) $LTI0 $LTI $GTI0 $GTI)) True) + ( (= $A $X)) $LTI0 $LTI $GTI0 $GTI)) True) +; + (= (--> - (gen_get () $LTI $LTI $GTI $GTI) !) True) + (gen_get () $LTI $LTI $GTI $GTI) !) True) +; + (= (--> (gen_get @@ -4012,7 +4676,9 @@ { (pl2am_error ($A must not be a variable in (get $X $A))) } - {fail })))) True) + {fail })))) True) +; + (= (--> (gen_get @@ -4027,7 +4693,9 @@ (, ! (, (gen_get_var $R $Seen $A) - (gen_get $Instrs $LTI1 $LTI $GTI0 $GTI))))))) True) + (gen_get $Instrs $LTI1 $LTI $GTI0 $GTI))))))) True) +; + (= (--> (gen_get @@ -4039,7 +4707,9 @@ (, { (add_alloc ($X $A yes) $LTI0 $LTI1) } - (gen_get $Instrs $LTI1 $LTI $GTI0 $GTI))))) True) + (gen_get $Instrs $LTI1 $LTI $GTI0 $GTI))))) True) +; + (= (--> (gen_get @@ -4052,7 +4722,9 @@ (gen_put $X $R $LTI0 $LTI1 $GTI0 $GTI1) (, ( (get_int $X $R $A)) - (gen_get $Instrs $LTI1 $LTI $GTI1 $GTI)))))) True) + (gen_get $Instrs $LTI1 $LTI $GTI1 $GTI)))))) True) +; + (= (--> (gen_get @@ -4065,20 +4737,24 @@ (gen_put $X $R $LTI0 $LTI1 $GTI0 $GTI1) (, ( (get_float $X $R $A)) - (gen_get $Instrs $LTI1 $LTI $GTI1 $GTI)))))) True) + (gen_get $Instrs $LTI1 $LTI $GTI1 $GTI)))))) True) +; + (= (--> (gen_get (Cons (= $A $X) $Instrs) $LTI0 $LTI $GTI0 $GTI) (, - { (atom $X) } + { (is-symbol $X) } (, ! (, (gen_put $X $R $LTI0 $LTI1 $GTI0 $GTI1) (, ( (get_con $X $R $A)) - (gen_get $Instrs $LTI1 $LTI $GTI1 $GTI)))))) True) + (gen_get $Instrs $LTI1 $LTI $GTI1 $GTI)))))) True) +; + (= (--> (gen_get @@ -4091,7 +4767,9 @@ (gen_put $X $R $LTI0 $LTI1 $GTI0 $GTI1) (, ( (get_ground $X $R $A)) - (gen_get $Instrs $LTI1 $LTI $GTI1 $GTI)))))) True) + (gen_get $Instrs $LTI1 $LTI $GTI1 $GTI)))))) True) +; + (= (--> (gen_get @@ -4108,7 +4786,9 @@ ($X1 $X2) $Instrs1 $LTI0 $LTI1 $GTI0 $GTI1) (, (gen_get $Instrs1 $LTI1 $LTI2 $GTI1 $GTI2) - (gen_get $Instrs $LTI2 $LTI $GTI2 $GTI))))))) True) + (gen_get $Instrs $LTI2 $LTI $GTI2 $GTI))))))) True) +; + (= (--> (gen_get @@ -4133,22 +4813,30 @@ (gen_unify $Args $Instrs1 $LTI0 $LTI1 $GTI2 $GTI3) (, (gen_get $Instrs1 $LTI1 $LTI2 $GTI3 $GTI4) - (gen_get $Instrs $LTI2 $LTI $GTI4 $GTI)))))))) True) + (gen_get $Instrs $LTI2 $LTI $GTI4 $GTI)))))))) True) +; + (= (--> - (gen_get_var void $_ $_) !) True) + (gen_get_var void $_ $_) !) True) +; + (= (--> (gen_get_var $R $_ $A) - ( (get_val $R $A))) True) + ( (get_val $R $A))) True) +; + ; -; ;;;;;;;;; unify instructions +; (= (--> - (gen_unify () () $LTI $LTI $GTI $GTI) !) True) + (gen_unify () () $LTI $LTI $GTI $GTI) !) True) +; + (= (--> (gen_unify @@ -4160,7 +4848,9 @@ { (assign_reg $X $R $Seen $LTI0 $LTI1) } (, (gen_unify_var $R $Seen) - (gen_unify $Xs $Instrs $LTI1 $LTI $GTI0 $GTI)))))) True) + (gen_unify $Xs $Instrs $LTI1 $LTI $GTI0 $GTI)))))) True) +; + (= (--> (gen_unify @@ -4172,7 +4862,9 @@ (gen_put $X $R $LTI0 $LTI1 $GTI0 $GTI1) (, ( (unify_int $X $R)) - (gen_unify $Xs $Instrs $LTI1 $LTI $GTI1 $GTI)))))) True) + (gen_unify $Xs $Instrs $LTI1 $LTI $GTI1 $GTI)))))) True) +; + (= (--> (gen_unify @@ -4184,19 +4876,23 @@ (gen_put $X $R $LTI0 $LTI1 $GTI0 $GTI1) (, ( (unify_float $X $R)) - (gen_unify $Xs $Instrs $LTI1 $LTI $GTI1 $GTI)))))) True) + (gen_unify $Xs $Instrs $LTI1 $LTI $GTI1 $GTI)))))) True) +; + (= (--> (gen_unify (Cons $X $Xs) $Instrs $LTI0 $LTI $GTI0 $GTI) (, - { (atom $X) } + { (is-symbol $X) } (, ! (, (gen_put $X $R $LTI0 $LTI1 $GTI0 $GTI1) (, ( (unify_con $X $R)) - (gen_unify $Xs $Instrs $LTI1 $LTI $GTI1 $GTI)))))) True) + (gen_unify $Xs $Instrs $LTI1 $LTI $GTI1 $GTI)))))) True) +; + (= (--> (gen_unify @@ -4208,7 +4904,9 @@ (gen_put $X $R $LTI0 $LTI1 $GTI0 $GTI1) (, ( (unify_ground $X $R)) - (gen_unify $Xs $Instrs $LTI1 $LTI $GTI1 $GTI)))))) True) + (gen_unify $Xs $Instrs $LTI1 $LTI $GTI1 $GTI)))))) True) +; + (= (--> (gen_unify @@ -4219,16 +4917,20 @@ { (assign_reg $_ $R $Seen $LTI0 $LTI1) } (, (gen_unify_var $R $Seen) - (gen_unify $Xs $Instrs $LTI1 $LTI $GTI0 $GTI)))) True) + (gen_unify $Xs $Instrs $LTI1 $LTI $GTI0 $GTI)))) True) +; + ; -; ;; unify_void, unify_variable, unify_value +; (= (--> (gen_unify_var void $_) (, ! - ( (unify_void 1)))) True) + ( (unify_void 1)))) True) +; + (= (--> (gen_unify_var $R $Seen) @@ -4237,24 +4939,30 @@ (, ! (, { (= $Seen yes) } - ( (unify_var $R)))))) True) + ( (unify_var $R)))))) True) +; + (= (--> (gen_unify_var $R $_) - ( (unify_val $R))) True) + ( (unify_val $R))) True) +; + ; -; ;;;;;;;;; generate continuation goal +; (= (--> (gen_put_cont $X $R $LTI0 $LTI $GTI $GTI) (, { (inc_PN $R $LTI0 $LTI) } - ( (put_cont $X $R)))) True) + ( (put_cont $X $R)))) True) +; + ; -; ;; A register +; (= @@ -4262,13 +4970,17 @@ ( (nonvar $X) (set-det) (pl2am-error (:: $X must be unbound variable in (assign-reg $X $Reg $Seen $LTI0 $LTI))) - (fail))) + (fail))) +; + (= (assign-reg $X $Reg $Seen (:: $XN $YN $PN $Alloc) (:: $XN $YN $PN $Alloc)) ( (allocated $Alloc $X - (:: $Reg $Seen)) (set-det))) + (:: $Reg $Seen)) (set-det))) +; + (= (assign-reg $X $Reg $Seen (:: $XN $YN $PN $Alloc) @@ -4279,21 +4991,27 @@ (+ $XN 1)) (= $Alloc1 (Cons - (:: $X $Reg $Seen) $Alloc)))) + (:: $X $Reg $Seen) $Alloc)))) +; + (= (allocated (Cons (Cons $V $X) $_) $V0 $X) - ( (== $V $V0) (set-det))) + ( (== $V $V0) (set-det))) +; + (= (allocated (Cons $_ $Alloc) $V0 $X) - (allocated $Alloc $V0 $X)) + (allocated $Alloc $V0 $X)) +; + ; -; ;; S register +; (= @@ -4301,13 +5019,17 @@ ( (not (ground $X)) (set-det) (pl2am-error (:: $X must be ground term in (assign-sreg $X $Reg $Seen $GTI0 $GTI))) - (fail))) + (fail))) +; + (= (assign-sreg $X $Reg $Seen (:: $SN $SAlloc $SInstrs) (:: $SN $SAlloc $SInstrs)) ( (allocated $SAlloc $X - (:: $Reg $Seen)) (set-det))) + (:: $Reg $Seen)) (set-det))) +; + (= (assign-sreg (with_self $X $T) $Reg $Seen @@ -4319,36 +5041,44 @@ (= $SAlloc1 (Cons (:: - (with_self $X $T) $Reg $Seen) $SAlloc)))) + (with_self $X $T) $Reg $Seen) $SAlloc)))) +; + (= (assign-sreg0 int $SN (si $SN)) - (set-det)) + (set-det)) +; + (= (assign-sreg0 flo $SN (sf $SN)) - (set-det)) + (set-det)) +; + (= (assign-sreg0 $_ $SN (s $SN)) - (set-det)) + (set-det)) +; + ; -; assign_sreg0(con, SN, sc(SN)) :- !. +; ; -; assign_sreg0(str, SN, ss(SN)) :- !. +; ; -; assign_sreg0(lis, SN, sl(SN)) :- !. +; ; -; assign_sreg0(arr, SN, sa(SN)) :- !. +; ; -; ;; incriment YN +; (= @@ -4359,10 +5089,12 @@ (Cons $XN (Cons $YN1 $Zs))) (is $YN1 - (+ $YN 1))) + (+ $YN 1))) +; + ; -; ;; incriment PN +; (= @@ -4375,394 +5107,594 @@ (Cons $YN (Cons $PN1 $Zs)))) (is $PN1 - (+ $PN 1))) + (+ $PN 1))) +; + ; -; ;; add an instruction to GTI +; (= (add_instr $Instr ($SN $SAlloc $SInstrs0) ($SN $SAlloc - (Cons $Instr $SInstrs0))) True) + (Cons $Instr $SInstrs0))) True) +; + ; -; ;; add an allocation to LTI +; (= (add_alloc $E ($XN $YN $PN $Alloc0) ($XN $YN $PN - (Cons $E $Alloc0))) True) + (Cons $E $Alloc0))) True) +; + (= (builtin_meta_predicates ^ 2 (? :)) True) -; /***************************************************************** -; Built-in Predicates and Constants -; *****************************************************************/ - +; (= (builtin_meta_predicates call 1 - (:)) True) + (:)) True) +; + (= (builtin_meta_predicates once 1 - (:)) True) + (:)) True) +; + (= (builtin_meta_predicates \+ 1 - (:)) True) + (:)) True) +; + (= (builtin_meta_predicates findall 3 - (? : ?)) True) + (? : ?)) True) +; + (= (builtin_meta_predicates bagof 3 - (? : ?)) True) + (? : ?)) True) +; + (= (builtin_meta_predicates setof 3 - (? : ?)) True) + (? : ?)) True) +; + (= (builtin_meta_predicates on_exception 3 - (? : :)) True) + (? : :)) True) +; + (= (builtin_meta_predicates catch 3 - (: ? :)) True) + (: ? :)) True) +; + (= (builtin_meta_predicates synchronized 2 - (? :)) True) + (? :)) True) +; + (= (builtin_meta_predicates freeze 2 - (? :)) True) + (? :)) True) +; + (= (builtin_local_predicates assert 1 - (:)) True) + (:)) True) +; + (= (builtin_local_predicates asserta 1 - (:)) True) + (:)) True) +; + (= (builtin_local_predicates assertz 1 - (:)) True) + (:)) True) +; + (= (builtin_local_predicates retract 1 - (:)) True) + (:)) True) +; + (= (builtin_local_predicates retractall 1 - (:)) True) + (:)) True) +; + (= (builtin_local_predicates assert 2 - (: ?)) True) + (: ?)) True) +; + (= (builtin_local_predicates asserta 2 - (: ?)) True) + (: ?)) True) +; + (= (builtin_local_predicates assertz 2 - (: ?)) True) + (: ?)) True) +; + (= (builtin_local_predicates retract 2 - (: ?)) True) + (: ?)) True) +; + (= (builtin_local_predicates retractall 2 - (: ?)) True) + (: ?)) True) +; + (= (builtin_local_predicates save 2 - (? :)) True) + (? :)) True) +; + (= (builtin_local_predicates clause 2 - (: ?)) True) + (: ?)) True) +; + (= (builtin_local_predicates abolish 1 - (:)) True) + (:)) True) +; + (= (builtin_local_predicates log_level 1 - (:)) True) + (:)) True) +; + (= (builtin_local_predicates loggable 1 - (:)) True) + (:)) True) +; + (= (builtin_local_predicates log_error 2 - (: ?)) True) + (: ?)) True) +; + (= (builtin_local_predicates log 2 - (: ?)) True) + (: ?)) True) +; + (= (builtin_local_predicates log 3 - (: ? ?)) True) + (: ? ?)) True) +; + (= (builtin_local_predicates log 4 - (: ? ? ?)) True) + (: ? ? ?)) True) +; + (= (builtin_local_predicates log 5 - (: ? ? ? ?)) True) + (: ? ? ? ?)) True) +; + (= (builtin_local_predicates log 6 - (: ? ? ? ? ?)) True) + (: ? ? ? ? ?)) True) +; + (= (builtin_local_predicates log 7 - (: ? ? ? ? ? ?)) True) + (: ? ? ? ? ? ?)) True) +; + (= (builtin_meta_predicates with_mutex 2 - (? :)) True) + (? :)) True) +; + ; -; Control constructs +; (= - (builtin_inline_predicates fail) True) + (builtin_inline_predicates fail) True) +; + (= (builtin_inline_predicates - ($get_level $_)) True) + (%get_level $_)) True) +; + (= - (builtin_inline_predicates $neck_cut) True) + (builtin_inline_predicates $neck_cut) True) +; + (= (builtin_inline_predicates - ($cut $_)) True) + ($cut $_)) True) +; + ; -; Term unification +; (= (builtin_inline_predicates - ($unify $_ $_)) True) + ($unify $_ $_)) True) +; + (= (builtin_inline_predicates - ($not_unifiable $_ $_)) True) + (%not_unifiable $_ $_)) True) +; + ; -; Type testing +; (= (builtin_inline_predicates - (var $_)) True) + (var $_)) True) +; + (= (builtin_inline_predicates - (atom $_)) True) + (is-symbol $_)) True) +; + (= (builtin_inline_predicates - (integer $_)) True) + (integer $_)) True) +; + (= (builtin_inline_predicates - (long $_)) True) + (long $_)) True) +; + (= (builtin_inline_predicates - (float $_)) True) + (float $_)) True) +; + (= (builtin_inline_predicates - (atomic $_)) True) + (atomic $_)) True) +; + (= (builtin_inline_predicates - (nonvar $_)) True) + (nonvar $_)) True) +; + (= (builtin_inline_predicates - (number $_)) True) + (number $_)) True) +; + (= (builtin_inline_predicates - (java $_)) True) + (java $_)) True) +; + (= (builtin_inline_predicates - (java $_ $_)) True) + (java $_ $_)) True) +; + (= (builtin_inline_predicates - (closure $_)) True) + (closure $_)) True) +; + (= (builtin_inline_predicates - (ground $_)) True) + (ground $_)) True) +; + ; -; Term comparison +; (= (builtin_inline_predicates - ($equality_of_term $_ $_)) True) + (%equality_of_term $_ $_)) True) +; + (= (builtin_inline_predicates - ($inequality_of_term $_ $_)) True) + (%inequality_of_term $_ $_)) True) +; + (= (builtin_inline_predicates - ($after $_ $_)) True) + ($after $_ $_)) True) +; + (= (builtin_inline_predicates - ($before $_ $_)) True) + ($before $_ $_)) True) +; + (= (builtin_inline_predicates - ($not_after $_ $_)) True) + (%not_after $_ $_)) True) +; + (= (builtin_inline_predicates - ($not_before $_ $_)) True) + (%not_before $_ $_)) True) +; + (= (builtin_inline_predicates - ($identical_or_cannot_unify $_ $_)) True) + (%identical_or_cannot_unify $_ $_)) True) +; + ; -; Term creation and decomposition +; (= (builtin_inline_predicates - (copy_term $_ $_)) True) + (copy_term $_ $_)) True) +; + ; -; Arithmetic evaluation +; (= (builtin_inline_predicates - (is $_ $_)) True) + (is $_ $_)) True) +; + (= (builtin_inline_predicates - ($abs $_ $_)) True) + ($abs $_ $_)) True) +; + (= (builtin_inline_predicates - ($asin $_ $_)) True) + ($asin $_ $_)) True) +; + (= (builtin_inline_predicates - ($acos $_ $_)) True) + ($acos $_ $_)) True) +; + (= (builtin_inline_predicates - ($atan $_ $_)) True) + ($atan $_ $_)) True) +; + (= (builtin_inline_predicates - ($bitwise_conj $_ $_ $_)) True) + (%bitwise_conj $_ $_ $_)) True) +; + (= (builtin_inline_predicates - ($bitwise_disj $_ $_ $_)) True) + (%bitwise_disj $_ $_ $_)) True) +; + (= (builtin_inline_predicates - ($bitwise_exclusive_or $_ $_ $_)) True) + (%bitwise_exclusive_or $_ $_ $_)) True) +; + (= (builtin_inline_predicates - ($bitwise_neg $_ $_)) True) + (%bitwise_neg $_ $_)) True) +; + (= (builtin_inline_predicates - ($ceil $_ $_)) True) + ($ceil $_ $_)) True) +; + (= (builtin_inline_predicates - ($cos $_ $_)) True) + ($cos $_ $_)) True) +; + (= (builtin_inline_predicates - ($degrees $_ $_)) True) + ($degrees $_ $_)) True) +; + (= (builtin_inline_predicates - ($exp $_ $_)) True) + ($exp $_ $_)) True) +; + (= (builtin_inline_predicates - ($float_quotient $_ $_ $_)) True) + (%float_quotient $_ $_ $_)) True) +; + (= (builtin_inline_predicates - ($floor $_ $_)) True) + ($floor $_ $_)) True) +; + (= (builtin_inline_predicates - ($int_quotient $_ $_ $_)) True) + (%int_quotient $_ $_ $_)) True) +; + (= (builtin_inline_predicates - ($log $_ $_)) True) + ($log $_ $_)) True) +; + (= (builtin_inline_predicates - ($max $_ $_ $_)) True) + ($max $_ $_ $_)) True) +; + (= (builtin_inline_predicates - ($min $_ $_ $_)) True) + ($min $_ $_ $_)) True) +; + (= (builtin_inline_predicates - ($minus $_ $_ $_)) True) + ($minus $_ $_ $_)) True) +; + (= (builtin_inline_predicates - ($mod $_ $_ $_)) True) + ($mod $_ $_ $_)) True) +; + (= (builtin_inline_predicates - ($multi $_ $_ $_)) True) + ($multi $_ $_ $_)) True) +; + (= (builtin_inline_predicates - ($plus $_ $_ $_)) True) + ($plus $_ $_ $_)) True) +; + (= (builtin_inline_predicates - ($pow $_ $_ $_)) True) + ($pow $_ $_ $_)) True) +; + (= (builtin_inline_predicates - ($radians $_ $_)) True) + ($radians $_ $_)) True) +; + (= (builtin_inline_predicates - ($rint $_ $_)) True) + ($rint $_ $_)) True) +; + (= (builtin_inline_predicates - ($round $_ $_)) True) + ($round $_ $_)) True) +; + (= (builtin_inline_predicates - ($shift_left $_ $_ $_)) True) + (%shift_left $_ $_ $_)) True) +; + (= (builtin_inline_predicates - ($shift_right $_ $_ $_)) True) + (%shift_right $_ $_ $_)) True) +; + (= (builtin_inline_predicates - ($sin $_ $_)) True) + ($sin $_ $_)) True) +; + (= (builtin_inline_predicates - ($sqrt $_ $_)) True) + ($sqrt $_ $_)) True) +; + (= (builtin_inline_predicates - ($tan $_ $_)) True) + ($tan $_ $_)) True) +; + (= (builtin_inline_predicates - ($float $_ $_)) True) + ($float $_ $_)) True) +; + (= (builtin_inline_predicates - ($float_integer_part $_ $_)) True) + (%float_integer_part $_ $_)) True) +; + (= (builtin_inline_predicates - ($float_fractional_part $_ $_)) True) + (%float_fractional_part $_ $_)) True) +; + (= (builtin_inline_predicates - ($truncate $_ $_)) True) + ($truncate $_ $_)) True) +; + (= (builtin_inline_predicates - ($sign $_ $_)) True) + ($sign $_ $_)) True) +; + ; -; Arithmetic comparison +; (= (builtin_inline_predicates - ($arith_equal $_ $_)) True) + (%arith_equal $_ $_)) True) +; + (= (builtin_inline_predicates - ($arith_not_equal $_ $_)) True) + (%arith_not_equal $_ $_)) True) +; + (= (builtin_inline_predicates - ($greater_or_equal $_ $_)) True) + (%greater_or_equal $_ $_)) True) +; + (= (builtin_inline_predicates - ($greater_than $_ $_)) True) + (%greater_than $_ $_)) True) +; + (= (builtin_inline_predicates - ($less_or_equal $_ $_)) True) + (%less_or_equal $_ $_)) True) +; + (= (builtin_inline_predicates - ($less_than $_ $_)) True) + (%less_than $_ $_)) True) +; + (= - (builtin_arith_constant random) True) + (builtin_arith_constant random) True) +; + (= - (builtin_arith_constant pi) True) + (builtin_arith_constant pi) True) +; + (= - (builtin_arith_constant e) True) + (builtin_arith_constant e) True) +; + (= (eliminate-disj $Cl $NewCl $DummyCls) ( (extract-disj $Cl $NewCl $Disjs Nil) (treat-disj $Disjs $DummyCls Nil))) -; /***************************************************************** -; Eliminate disjunctions -; *****************************************************************/ - -; ; The clause a :- b;c is converted into a :- b. and a :- c. -; ; In addition, -; ; (C1 -> C2) is converted into ((C1,!,C2) ; fail). -; ; ((C1 -> C2) ; C3) is converted into ((C1,!,C2) ; C3). -; ; not(C) is converted into ((C,!,fail) ; true). -; ; \+(C) is converted into ((C,!,fail) ; true). -; ; And then all of disjunctions are eliminated. -; ; -; ; Note: this is based on flatten.pl in holmer's benchmark. - +; @@ -4770,7 +5702,9 @@ (--> (extract_disj $Cl $Cl) (, - { (var $Cl) } !)) True) + { (var $Cl) } !)) True) +; + (= (--> (extract_disj $Cl @@ -4779,16 +5713,22 @@ { (= $Cl (:- $H $B)) } (, ! - (extract_disj $B $NewB $Cl)))) True) + (extract_disj $B $NewB $Cl)))) True) +; + (= (--> - (extract_disj $Cl $Cl) !) True) + (extract_disj $Cl $Cl) !) True) +; + (= (--> (extract_disj $G $G $_) (, - { (var $G) } !)) True) + { (var $G) } !)) True) +; + (= (--> (extract_disj @@ -4797,7 +5737,9 @@ (, ! (, (extract_disj $G1 $NewG1 $Cl) - (extract_disj $G2 $NewG2 $Cl)))) True) + (extract_disj $G2 $NewG2 $Cl)))) True) +; + (= (--> (extract_disj $G $NewG $Cl) @@ -4813,10 +5755,14 @@ { (is $N1 (+ $N 1)) } { (assert - (dummy_clause_counter $N1)) })))))) True) + (dummy_clause_counter $N1)) })))))) True) +; + (= (--> - (extract_disj $G $G $_) !) True) + (extract_disj $G $G $_) !) True) +; + (= @@ -4825,19 +5771,25 @@ (or (, $C1 (set-det) $C2) fail)) - (set-det)) + (set-det)) +; + (= (is-disj (det-if-then-else $C1 $C2 $C3) (or (, $C1 (set-det) $C2) $C3)) - (set-det)) + (set-det)) +; + (= (is-disj (or $C1 $C2) (or $C1 $C2)) - (set-det)) + (set-det)) +; + (= (is-disj (not $C) @@ -4845,18 +5797,24 @@ (, $C (set-det) (fail)) True)) - (set-det)) + (set-det)) +; + (= (is_disj (\+ $C) (; (, $C - (, ! fail)) true)) True) + (, ! fail)) true)) True) +; + (= (--> - (treat_disj ()) !) True) + (treat_disj ()) !) True) +; + (= (--> (treat_disj @@ -4889,21 +5847,29 @@ ($DummyCla) (, ($DummyClb) - (treat_disj $Disjs)))))))))))) True) + (treat_disj $Disjs)))))))))))) True) +; + (= (intersect-vars $V1 $V2 $Out) ( (sort $V1 $Sorted1) (sort $V2 $Sorted2) - (intersect-sorted-vars $Sorted1 $Sorted2 $Out))) + (intersect-sorted-vars $Sorted1 $Sorted2 $Out))) +; + (= (intersect-sorted-vars Nil $_ Nil) - (set-det)) + (set-det)) +; + (= - (intersect_sorted_vars $_ () ()) True) + (intersect_sorted_vars $_ () ()) True) +; + (= (intersect-sorted-vars (Cons $X $Xs) @@ -4911,7 +5877,9 @@ (Cons $X $Rs)) ( (== $X $Y) (set-det) - (intersect-sorted-vars $Xs $Ys $Rs))) + (intersect-sorted-vars $Xs $Ys $Rs))) +; + (= (intersect-sorted-vars (Cons $X $Xs) @@ -4919,7 +5887,9 @@ ( (@< $X $Y) (set-det) (intersect-sorted-vars $Xs - (Cons $Y $Ys) $Rs))) + (Cons $Y $Ys) $Rs))) +; + (= (intersect-sorted-vars (Cons $X $Xs) @@ -4927,12 +5897,14 @@ ( (@> $X $Y) (set-det) (intersect-sorted-vars - (Cons $X $Xs) $Ys $Rs))) + (Cons $X $Xs) $Ys $Rs))) +; + (= (pl2am-error $M) - ( (get-atoms &self + ( (get-symbols &self (= (file_line $File $Line) $_)) (set-det) @@ -4945,12 +5917,7 @@ (Cons at (Cons $Line (Cons : $M))))))))))) -; /***************************************************************** -; Utilities -; *****************************************************************/ - -; ;;; print - +; (= @@ -4958,89 +5925,123 @@ (pl2am-message user-error (Cons *** (Cons PL2ASM - (Cons ERROR $M))))) + (Cons ERROR $M))))) +; + (= (pl2am-message $M) - (pl2am-message user-output $M)) + (pl2am-message user-output $M)) +; + (= (pl2am-message $Stream Nil) - ( (nl $Stream) (flush-output $Stream))) + ( (nl $Stream) (flush-output $Stream))) +; + (= (pl2am-message $Stream (Cons $M $Ms)) ( (write $Stream $M) (write $Stream ' ') - (pl2am-message $Stream $Ms))) + (pl2am-message $Stream $Ms))) +; + ; -; ;; format +; (= - (mode_expr ()) True) + (mode_expr ()) True) +; + (= (mode-expr (Cons $M $Ms)) ( (nonvar $M) (pl2am-member $M (:: : or + - ?)) (set-det) - (mode-expr $Ms))) + (mode-expr $Ms))) +; + (= (predspec-expr (/ $F $A)) - ( (atom $F) (integer $A))) + ( (atom $F) (integer $A))) +; + ; -; ;; list +; (= - (pl2am_append () $Zs $Zs) True) + (pl2am_append () $Zs $Zs) True) +; + (= (pl2am-append (Cons $X $Xs) $Ys (Cons $X $Zs)) - (pl2am-append $Xs $Ys $Zs)) + (pl2am-append $Xs $Ys $Zs)) +; + (= (pl2am-rev $L $R) - (pl2am-rev $L Nil $R)) + (pl2am-rev $L Nil $R)) +; + (= - (pl2am_rev () $R $R) True) + (pl2am_rev () $R $R) True) +; + (= (pl2am-rev (Cons $X $L) $Y $R) (pl2am-rev $L - (Cons $X $Y) $R)) + (Cons $X $Y) $R)) +; + (= (pl2am_member $X - (Cons $X $_)) True) + (Cons $X $_)) True) +; + (= (pl2am-member $X (Cons $_ $Ys)) - (pl2am-member $X $Ys)) + (pl2am-member $X $Ys)) +; + (= (pl2am-memq $X (Cons $Y $_)) - ( (== $X $Y) (set-det))) + ( (== $X $Y) (set-det))) +; + (= (pl2am-memq $X (Cons $_ $Ys)) - (pl2am-memq $X $Ys)) + (pl2am-memq $X $Ys)) +; + (= (--> - (flatten_list ()) !) True) + (flatten_list ()) !) True) +; + (= (--> (flatten_list @@ -5048,15 +6049,21 @@ (, ! (, (flatten_list $L1) - (flatten_list $L2)))) True) + (flatten_list $L2)))) True) +; + (= (--> (flatten_list $L) - ($L)) True) + ($L)) True) +; + (= (--> - (flatten_code ()) !) True) + (flatten_code ()) !) True) +; + (= (--> (flatten_code @@ -5066,7 +6073,9 @@ (, ( (: $L ())) (flatten_code - (Cons $C $Code))))) True) + (Cons $C $Code))))) True) +; + (= (--> (flatten_code @@ -5074,15 +6083,21 @@ (, ! (, (flatten_code $Code1) - (flatten_code $Code2)))) True) + (flatten_code $Code2)))) True) +; + (= (--> (flatten_code $Code) - ($Code)) True) + ($Code)) True) +; + (= - (pl2am_maplist $_ () ()) True) + (pl2am_maplist $_ () ()) True) +; + (= (pl2am-maplist $Goal (Cons $Elem1 $Tail1) @@ -5090,17 +6105,23 @@ ( (=.. $Term (:: $Goal $Elem1 $Elem2)) (call $Term) - (pl2am-maplist $Goal $Tail1 $Tail2))) + (pl2am-maplist $Goal $Tail1 $Tail2))) +; + (= (pl2am-resolve-file $BaseFile $File $File) - ( (with_self - (= $File $Package) $ResourceName) (set-det))) + ( (= $File + (with_self $Package $ResourceName)) (set-det))) +; + (= (pl2am-resolve-file $BaseFile $File $IncludeFile) - ( (pl2am-file-directory $BaseFile $Directory) (atom-concat $Directory $File $IncludeFile))) + ( (pl2am-file-directory $BaseFile $Directory) (atom-concat $Directory $File $IncludeFile))) +; + (= @@ -5110,50 +6131,70 @@ (pl2am-file-directory- $BaseFileCharsRev $DirectoryCharsRev) (pl2am-add-directory-separator $DirectoryCharsRev $DirectoryCharsRev1) (pl2am-rev $DirectoryCharsRev1 $DirectoryChars) - (atom-chars $Directory $DirectoryChars))) + (atom-chars $Directory $DirectoryChars))) +; + (= (pl2am-file-directory- Nil Nil) - (set-det)) + (set-det)) +; + (= (pl2am-file-directory- (:: \) (:: \)) - (set-det)) + (set-det)) +; + (= (pl2am-file-directory- (:: /) (:: /)) - (set-det)) + (set-det)) +; + (= (pl2am-file-directory- (Cons \ $BaseFileCharsRev) $BaseFileCharsRev) - (set-det)) + (set-det)) +; + (= (pl2am-file-directory- (Cons / $BaseFileCharsRev) $BaseFileCharsRev) - (set-det)) + (set-det)) +; + (= (pl2am-file-directory- (Cons $_ $BaseFileCharsRev) $DirectoryCharsRev) - (pl2am-file-directory- $BaseFileCharsRev $DirectoryCharsRev)) + (pl2am-file-directory- $BaseFileCharsRev $DirectoryCharsRev)) +; + (= (pl2am-add-directory-separator $D $D) ( (= $D - (Cons / $_)) (set-det))) + (Cons / $_)) (set-det))) +; + (= (pl2am-add-directory-separator $D $D) ( (= $D - (Cons \ $_)) (set-det))) + (Cons \ $_)) (set-det))) +; + (= (pl2am_add_directory_separator $D - (Cons / $D)) True) + (Cons / $D)) True) +; + ; -; ;; transform +; (= @@ -5161,31 +6202,43 @@ ( (var $X) (set-det) (pl2am-error (:: variable $X can not be converted to [A|B] expression)) - (fail))) + (fail))) +; + (= (conj-to-list (, $X1 $X2 $Xs) $Y) - ( (set-det) (conj-to-list (, $X1 $X2 $Xs) $Y))) + ( (set-det) (conj-to-list (, $X1 $X2 $Xs) $Y))) +; + (= (conj-to-list (, $X $Xs) (Cons $X $Zs)) - ( (set-det) (conj-to-list $Xs $Zs))) + ( (set-det) (conj-to-list $Xs $Zs))) +; + (= (conj_to_list $X - ($X)) True) + ($X)) True) +; + (= (list-to-string $List $String) ( (list-to-chars $List $Chars0) (flatten-list $Chars0 $Chars Nil) - (atom-codes $String $Chars))) + (atom-codes $String $Chars))) +; + (= (list-to-chars Nil Nil) - (set-det)) + (set-det)) +; + (= (list-to-chars (Cons $L $Ls) @@ -5193,7 +6246,9 @@ ( (atom $L) (set-det) (atom-codes $L $C) - (list-to-chars $Ls $Cs))) + (list-to-chars $Ls $Cs))) +; + (= (list-to-chars (Cons $L $Ls) @@ -5201,12 +6256,16 @@ ( (number $L) (set-det) (number-codes $L $C) - (list-to-chars $Ls $Cs))) + (list-to-chars $Ls $Cs))) +; + (= (list-to-conj $X $Y) - ( (flatten-list $X $L Nil) (list-to-conj0 $L $Y))) + ( (flatten-list $X $L Nil) (list-to-conj0 $L $Y))) +; + (= @@ -5214,56 +6273,80 @@ ( (var $X) (set-det) (pl2am-error (:: variable $X can not be converted to '(A,B)' expression)) - (fail))) + (fail))) +; + (= (list_to_conj0 - ($X) $X) True) + ($X) $X) True) +; + (= (list-to-conj0 (Cons $X $Xs) (, $X $Ys)) - ( (set-det) (list-to-conj0 $Xs $Ys))) + ( (set-det) (list-to-conj0 $Xs $Ys))) +; + ; -; ;; misc +; (= (variables $X $Vs) - (variables $X Nil $Vs)) + (variables $X Nil $Vs)) +; + (= (variables $X $Vs $Vs) ( (var $X) (pl2am-memq $X $Vs) - (set-det))) + (set-det))) +; + (= (variables $X $Vs (Cons $X $Vs)) - ( (var $X) (set-det))) + ( (var $X) (set-det))) +; + (= (variables $X $Vs0 $Vs0) - ( (atomic $X) (set-det))) + ( (atomic $X) (set-det))) +; + (= (variables (Cons $X $Xs) $Vs0 $Vs) ( (set-det) (variables $X $Vs0 $Vs1) - (variables $Xs $Vs1 $Vs))) + (variables $Xs $Vs1 $Vs))) +; + (= (variables $X $Vs0 $Vs) - ( (=.. $X $Xs) (variables $Xs $Vs0 $Vs))) + ( (=.. $X $Xs) (variables $Xs $Vs0 $Vs))) +; + (= (count-variable $V $X 1) - ( (== $V $X) (set-det))) + ( (== $V $X) (set-det))) +; + (= (count-variable $_ $X 0) - ( (var $X) (set-det))) + ( (var $X) (set-det))) +; + (= (count-variable $_ $X 0) - ( (atomic $X) (set-det))) + ( (atomic $X) (set-det))) +; + (= (count-variable $V (Cons $X $Y) $N) @@ -5271,129 +6354,153 @@ (count-variable $V $X $N1) (count-variable $V $Y $N2) (is $N - (+ $N1 $N2)))) + (+ $N1 $N2)))) +; + (= (count-variable $V $X $N) - ( (=.. $X $Xs) (count-variable $V $Xs $N))) + ( (=.. $X $Xs) (count-variable $V $Xs $N))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; END +; ; -; written by SICStus MeTTa 3.12.8 +; + + + !(op 1170 xfx :-) +; + + !(op 1170 xfx -->) +; + + !(op 1170 fx :-) +; + + !(op 1170 fx ?-) +; + + !(op 1150 fx public) +; + !(op 1150 fx package) +; + ; +; + !(op 1170 xfx :-) -; /***************************************************************** -; Time-stamp: <2008-10-29 10:42:42 banbara> -; -; NAME -; am2cpp: Translating WAM-based Intermediate Code into Java -; -; USAGE -; # sicstus -; ?- [am2cpp]. -; ?- am2cpp([File]). -; -; # sicstus -; ?- [am2cpp]. -; ?- am2cpp([File, Dir]). -; -; PARAMETERS -; File is an input WAM-based Intermediate file name. -; -; DESCRIPTION -; This program translates WAM-based intermediate codes into Java. -; For each predicate p/n, the file named "PRED_p_n.java" is generated. -; Generated files can be compiled and executed by usual -; java utilities (ex. javac) with the MeTTa Cafe runtime system. -; -; COPYRIGHT -; am2cpp (Translating WAM-based Intermediate Code into Java) -; Copyright (C) 1997-2008 by -; Mutsunori Banbara (banbara@kobe-u.ac.jp) and -; Naoyuki Tamura (tamura@kobe-u.ac.jp) -; -; SEE ALSO -; http://kaminari.istc.kobe-u.ac.jp/MeTTaCafe/ -; *****************************************************************/ - -; /***************************************************************** -; Declarations -; *****************************************************************/ - - - !(op 1170 xfx -->) - !(op 1170 fx :-) - !(op 1170 fx ?-) - !(op 1150 fx public) - !(op 1150 fx package) ; -; MeTTa Cafe specific - - - !(op 1170 xfx :-) - !(op 1170 xfx -->) - !(op 1170 fx :-) - !(op 1170 fx ?-) - !(op 500 yfx #) - !(op 1150 fx dynamic) - !(op 1150 fx meta-predicate) - !(op 1150 fx package) - !(op 1150 fx public) - !(op 1150 fx import) - !(op 1150 fx mode) - !(op 1150 fx multifile) - !(op 1150 fx block) - - !(dynamic (/ dest-dir 1)) - !(dynamic (/ current-arity 1)) - !(dynamic (/ current-functor 1)) - !(dynamic (/ current-package 1)) - !(dynamic (/ domain-definition 1)) - !(dynamic (/ inlined 2)) +; + + !(op 1170 xfx -->) +; + + !(op 1170 fx :-) +; + + !(op 1170 fx ?-) +; + + !(op 500 yfx #) +; + + !(op 1150 fx dynamic) +; + + !(op 1150 fx meta-predicate) +; + + !(op 1150 fx package) +; + + !(op 1150 fx public) +; + + !(op 1150 fx import) +; + + !(op 1150 fx mode) +; + + !(op 1150 fx multifile) +; + + !(op 1150 fx block) +; + + + !(dynamic (/ dest-dir 1)) +; + + !(dynamic (/ current-arity 1)) +; + + !(dynamic (/ current-functor 1)) +; + + !(dynamic (/ current-package 1)) +; + + !(dynamic (/ domain-definition 1)) +; + + !(dynamic (/ inlined 2)) +; + ; -; :- module('TauMeTTaG.compiler.am2cpp', [main/0,am2cpp/1]). +; (= (package $X) - (nb-setval package $X)) + (nb-setval package $X)) +; + - !(package TauPrologG.compiler.am2cpp) - !(public (, (/ main 0) (/ am2cpp 1))) + !(package TauPrologG.compiler.am2cpp) +; + + !(public (, (/ main 0) (/ am2cpp 1))) +; + (= (main-am2cpp) ( (read $X) (am2cpp $X))) -; /***************************************************************** -; Main -; *****************************************************************/ - +; (= (pl2cpp (:: $File)) - ( (set-det) (pl2cpp (:: $File .)))) + ( (set-det) (pl2cpp (:: $File .)))) +; + (= (pl2cpp (:: $File $Dir)) - (am2cpp (:: $File $Dir))) + (am2cpp (:: $File $Dir))) +; + (= (am2cpp (:: $File)) - ( (set-det) (am2cpp (:: $File .)))) + ( (set-det) (am2cpp (:: $File .)))) +; + (= (am2cpp (:: $File $Dir)) - ( (remove-all-atoms &self + ( (remove-all-symbols &self (dest_dir $_)) - (add-atom &self + (add-symbol &self (dest_dir $Dir)) (open $File read $In) (repeat) @@ -5402,25 +6509,24 @@ (== $X end-of-file) (set-det) (close $In) - (write-domains))) + (write-domains))) +; + (= (write-domains) - ( (get-atoms &self + ( (get-symbols &self (= (dest_dir $Dir) $_)) (findall $D (domain-definition $D) $LD) (catch (with_self - (TauPrologG.builtin) - (call (with_self (TauPrologG.builtin) (write-domain-definitions $Dir $LD)))) $_ + (TauPrologG.builtin *) + (call (with_self (TauPrologG.builtin *) (write-domain-definitions $Dir $LD)))) $_ (am2cpp-message (:: domain definitions are not supported and skipped))))) -; ; on some platforms (like SWI MeTTa) predicate write_domain_definitions might be not available - -; ; so wrap it with catch and produce warning message - +; @@ -5429,34 +6535,40 @@ ( (var $X) (set-det) (am2cpp-error (:: unbound variable is found)) - (fail))) + (fail))) +; + (= (write-java end-of-file $_) - (set-det)) + (set-det)) +; + (= (write-java !$G $_) - ( (set-det) (call $G))) + ( (set-det) (call $G))) +; + (= (write-java (begin-predicate $P (/ $F $A)) $In) - ( (get-atoms &self + ( (get-symbols &self (= (dest_dir $Dir) $_)) - (remove-all-atoms &self + (remove-all-symbols &self (current_package $_)) - (remove-all-atoms &self + (remove-all-symbols &self (current_arity $_)) - (remove-all-atoms &self + (remove-all-symbols &self (current_functor $_)) - (remove-all-atoms &self + (remove-all-symbols &self (inlined $_ $_)) - (add-atom &self + (add-symbol &self (current_package $P)) - (add-atom &self + (add-symbol &self (current_arity $A)) - (add-atom &self + (add-symbol &self (current_functor $F)) (predicate-encoding $F $F1) (package-encoding $P $PDir) @@ -5477,10 +6589,14 @@ (end-predicate $P (/ $F $A))) (close $Out) - (set-det))) + (set-det))) +; + (= (write-java $X $_) - ( (am2cpp-error (:: $X is an invalid argument in (/ write-java 2))) (fail))) + ( (am2cpp-error (:: $X is an invalid argument in (/ write-java 2))) (fail))) +; + (= @@ -5489,20 +6605,21 @@ (set-det) (am2cpp-error (:: unbound variable is found)) (fail))) -; /***************************************************************** -; Write Java -; *****************************************************************/ - +; (= (write-java0 Nil $_ $_) - (set-det)) + (set-det)) +; + (= (write-java0 (Cons $X $Xs) $In $Out) ( (set-det) (write-java0 $X $In $Out) - (write-java0 $Xs $In $Out))) + (write-java0 $Xs $In $Out))) +; + (= (write-java0 (end-predicate $_ $_) $_ $Out) @@ -5511,7 +6628,9 @@ (write $Out }) (nl $Out) (write $Out }) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (comment $Comment) $_ $Out) @@ -5520,7 +6639,9 @@ (tab $Out 4) (write $Out // ) (writeq $Out $Comment) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (debug $Comment) $_ $Out) @@ -5528,7 +6649,9 @@ (numbervars $Comment 0 $_) (write $Out // ) (writeq $Out $Comment) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (info (Cons $FA (Cons $File $_))) $_ $Out) @@ -5545,7 +6668,9 @@ (write $Out ' PLEASE DO NOT EDIT!') (nl $Out) (write $Out */) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (import-package $P) $_ $Out) @@ -5553,7 +6678,9 @@ (write $Out 'import ') (write-package $P $Out) (write $Out .*;) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (import-package $P $FA) $_ $Out) @@ -5567,13 +6694,17 @@ (write-class-name $FA $Out) (write-package $FA $Out)) (write $Out or) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (with_self $Label $Instruction) $In $Out) ( (set-det) (write-label $Label $Out) - (write-java0 $Instruction $In $Out))) + (write-java0 $Instruction $In $Out))) +; + (= (write-java0 (label (/ fail 0)) $_ $Out) @@ -5584,28 +6715,32 @@ (/ fail 0) $Out) (write $Out ' = TauPrologG.Failure.FAIL-0') (write $Out or) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (label $L) $_ $Out) - (set-det)) + (set-det)) +; + ; -; tab(Out, 4), +; ; -; write(Out, 'static final Operation '), +; ; -; write_index(L, Out), +; ; -; write(Out, ' = new '), +; ; -; write_class_name(L, Out), +; ; -; write(Out, '();'), nl(Out). +; (= (write-java0 @@ -5615,17 +6750,23 @@ (write $Out 'return ') (write-index $L $Out) (write $Out (engine);) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 setB0 $_ $Out) ( (set-det) (tab $Out 8) (write $Out engine.setB0();) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (deref $_ void) $_ $_) - (set-det)) + (set-det)) +; + (= (write-java0 (deref $Ri $Rj) $_ $Out) @@ -5635,11 +6776,15 @@ (write $Out = ) (write-reg $Ri $Out) (write $Out .DeRef();) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (set $_ void) $_ $_) - (set-det)) + (set-det)) +; + (= (write-java0 (set $Ri $Rj) $_ $Out) @@ -5649,11 +6794,15 @@ (write $Out = ) (write-reg $Ri $Out) (write $Out or) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (decl-term-vars Nil) $_ $_) - (set-det)) + (set-det)) +; + (= (write-java0 (decl-term-vars $L) $_ $Out) @@ -5662,11 +6811,15 @@ (write $Out 'Term ') (write-reg-args $L $Out) (write $Out or) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (decl-pred-vars Nil) $_ $_) - (set-det)) + (set-det)) +; + (= (write-java0 (decl-pred-vars $L) $_ $Out) @@ -5675,14 +6828,16 @@ (write $Out 'Operation ') (write-reg-args $L $Out) (write $Out or) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (put-cont $BinG $C) $_ $Out) ( (set-det) (det-if-then-else - (with_self - (= $BinG $P) $G) True + (= $BinG + (with_self $P $G)) True (= $BinG $G)) (functor $G $F $A0) (is $A @@ -5702,21 +6857,25 @@ (write $Out () (write-reg-args $Args $Out) (write $Out );) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (execute cont) $_ $Out) ( (set-det) (tab $Out 8) (write $Out 'return cont;') - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (execute $BinG) $_ $Out) ( (set-det) (det-if-then-else - (with_self - (= $BinG $P) $G) True + (= $BinG + (with_self $P $G)) True (= $BinG $G)) (functor $G $F $A0) (is $A @@ -5735,11 +6894,15 @@ (write $Out () (write-reg-args $Args $Out) (write $Out );) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (inline $G) $In $Out) - ( (write-inline $G $In $Out) (set-det))) + ( (write-inline $G $In $Out) (set-det))) +; + (= (write-java0 (new-hash $Tag $I) $_ $Out) @@ -5753,7 +6916,9 @@ (write $Out ' = new java.util.HashMap(') (write $Out $I) (write $Out );) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (put-hash $X $L $Tag) $_ $Out) @@ -5765,7 +6930,7 @@ (write $Out $Tag)) (write $Out .put() (det-if-then-else - (get-atoms &self + (get-symbols &self (= (inlined $X (/ $F $A)) $_)) @@ -5779,7 +6944,9 @@ (write $Out , ) (write-method-ref $L $Out) (write $Out );) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (static $Instrs) $In $Out) @@ -5790,9 +6957,11 @@ (write-java0 $Instrs $In $Out) (tab $Out 4) (write $Out }) - (nl $Out))) + (nl $Out))) +; + ; -; ;; Put Instructions +; (= (write-java0 @@ -5801,7 +6970,9 @@ (tab $Out 8) (write-reg $X $Out) (write $Out ' = new Var(engine);') - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (put-int $I $X) $_ $Out) @@ -5813,7 +6984,9 @@ (write $Out ' = new LongTerm(') (write $Out $I) (write $Out L);) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (put-int $I $X) $_ $Out) @@ -5830,7 +7003,9 @@ (java-integer $I) True (write $Out "))) (write $Out );) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (put-float $F $X) $_ $Out) @@ -5841,12 +7016,16 @@ (write $Out ' = new Float(') (write $Out $F) (write $Out );) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (put-con (/ $F $A) $X) $_ $Out) - ( (set-det) (add-atom &self (inlined $X (/ $F $A))))) + ( (set-det) (add-symbol &self (inlined $X (/ $F $A))))) +; + (= (write-java0 (put-con $C $X) $_ $Out) @@ -5866,7 +7045,9 @@ (, (write-constant $C $Out) (write $Out ");))) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (put-list $Xi $Xj $Xk) $_ $Out) @@ -5884,7 +7065,9 @@ (write $Out , ) (write-reg $Xj $Out) (write $Out );) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (put-str $Xi $Y $Xj) $_ $Out) @@ -5899,7 +7082,7 @@ (write-reg $Xj $Out) (write $Out ' = F(') (det-if-then-else - (get-atoms &self + (get-symbols &self (= (inlined $Xi (/ $F $A)) $_)) @@ -5911,12 +7094,16 @@ (write $Out , ) (write-reg $Y $Out) (write $Out );) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (put-str-args $Xs (s $Y)) $_ $Out) - ( (set-det) (add-atom &self (inlined (s $Y) (str_args $Xs))))) + ( (set-det) (add-symbol &self (inlined (s $Y) (str_args $Xs))))) +; + (= (write-java0 (put-str-args $Xs $Y) $_ $Out) @@ -5933,14 +7120,16 @@ (write $Out = {) (write-reg-args $Xs $Out) (write $Out };) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (put-clo $G0 $X) $_ $Out) ( (set-det) (det-if-then-else - (with_self - (= $G0 $P) $G) True + (= $G0 + (with_self $P $G)) True (= $G0 $G)) (functor $G $F $A) (=.. $G @@ -5960,9 +7149,11 @@ (write $Out () (write-reg-args $Args $Out) (write $Out ));) - (nl $Out))) + (nl $Out))) +; + ; -; ;; Get Instructions +; (= (write-java0 @@ -5977,105 +7168,33 @@ (nl $Out) (tab $Out 12) (write $Out 'return engine.fail();') - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (get-int $_ $Xi $Xj) $In $Out) - ( (set-det) (write-java0 (get-val $Xi $Xj) $In $Out))) + ( (set-det) (write-java0 (get-val $Xi $Xj) $In $Out))) +; + (= (write-java0 (get-float $_ $Xi $Xj) $In $Out) ( (set-det) (write-java0 (get-val $Xi $Xj) $In $Out))) -; /* -; write_java0(get_int(N,Xi,Xj), In, Out) :- !, -; write_java0(deref(Xj,Xj), In, Out), -; ; read mode -; tab(Out, 8), -; write(Out, 'if ('), write_reg(Xj, Out), write(Out, ' .IsInt() || '), write_reg(Xj, Out), write(Out, ' instanceof LongTerm){'), nl(Out), -; tab(Out, 12), -; write(Out, 'if (((NumberTerm) '), write_reg(Xj, Out), write(Out, ').intValue() != '), -; write(Out, N), write(Out, ')'), nl(Out), -; tab(Out, 16), -; write(Out, 'return engine.fail();'), nl(Out), -; ; write mode -; tab(Out, 8), -; write(Out, '} else if ('), write_reg(Xj, Out), write(Out, ' instanceof Var){'), nl(Out), -; tab(Out, 12), -; write(Out, '((Var) '), write_reg(Xj, Out), write(Out, ').bind('), -; write_reg(Xi, Out), write(Out, ', engine.trail);'), nl(Out), -; tab(Out, 8), -; ; otherwise fail -; write(Out, '} else {'), nl(Out), -; tab(Out, 12), -; write(Out, 'return engine.fail();'), nl(Out), -; tab(Out, 8), -; write(Out, '}'), nl(Out). -; */ - +; (= (write-java0 (get-con $_ $Xi $Xj) $In $Out) ( (set-det) (write-java0 (get-val $Xi $Xj) $In $Out))) -; /* -; write_java0(get_float(N,Xi,Xj), In, Out) :- !, -; write_java0(deref(Xj,Xj), In, Out), -; ; read mode -; tab(Out, 8), -; write(Out, 'if ('), write_reg(Xj, Out), write(Out, ' instanceof Float){'), nl(Out), -; tab(Out, 12), -; write(Out, 'if (((Float) '), write_reg(Xj, Out), write(Out, ').doubleValue() != '), -; write(Out, N), write(Out, ')'), nl(Out), -; tab(Out, 16), -; write(Out, 'return engine.fail();'), nl(Out), -; ; write mode -; tab(Out, 8), -; write(Out, '} else if ('), write_reg(Xj, Out), write(Out, ' instanceof Var){'), nl(Out), -; tab(Out, 12), -; write(Out, '((Var) '), write_reg(Xj, Out), write(Out, ').bind('), -; write_reg(Xi, Out), write(Out, ', engine.trail);'), nl(Out), -; tab(Out, 8), -; ; otherwise fail -; write(Out, '} else {'), nl(Out), -; tab(Out, 12), -; write(Out, 'return engine.fail();'), nl(Out), -; tab(Out, 8), -; write(Out, '}'), nl(Out). -; */ - +; (= (write-java0 (get-ground $_ $Xi $Xj) $In $Out) ( (set-det) (write-java0 (get-val $Xi $Xj) $In $Out))) -; /* -; write_java0(get_con(_,Xi,Xj), In, Out) :- !, -; write_java0(deref(Xj,Xj), In, Out), -; ; read mode -; tab(Out, 8), -; write(Out, 'if ('), write_reg(Xj, Out), write(Out, ' .IsConst()){'), nl(Out), -; tab(Out, 12), -; write(Out, 'if (! '), -; write_reg(Xj, Out), write(Out, '.equals('), write_reg(Xi, Out), -; write(Out, '))'), nl(Out), -; tab(Out, 16), -; write(Out, 'return engine.fail();'), nl(Out), -; ; write mode -; tab(Out, 8), -; write(Out, '} else if ('), write_reg(Xj, Out), write(Out, ' instanceof Var){'), nl(Out), -; tab(Out, 12), -; write(Out, '((Var) '), write_reg(Xj, Out), write(Out, ').bind('), -; write_reg(Xi, Out), write(Out, ', engine.trail);'), nl(Out), -; tab(Out, 8), -; ; otherwise fail -; write(Out, '} else {'), nl(Out), -; tab(Out, 12), -; write(Out, 'return engine.fail();'), nl(Out), -; tab(Out, 8), -; write(Out, '}'), nl(Out). -; */ - +; (= (write-java0 @@ -6119,12 +7238,7 @@ (tab $Out 8) (write $Out }) (nl $Out))) -; ; read mode - -; ; write mode - -; ; otherwise fail - +; (= (write-java0 @@ -6150,8 +7264,7 @@ (tab $Out 12) (write $Out }) (nl $Out))) -; ; simple unify - +; @@ -6159,7 +7272,7 @@ (write-java0 (try $Li $Lj) $_ $Out) ( (set-det) - (get-atoms &self + (get-symbols &self (= (current_arity $A) $_)) (tab $Out 8) @@ -6182,39 +7295,7 @@ (write-index $Li $Out) (write $Out (engine);) (nl $Out))) -; /* ; read mode -; tab(Out, 8), -; write(Out, 'if ('), write_reg(Xj, Out), write(Out, ' .IsStruct()){'), nl(Out), ;??? == F -; tab(Out, 12), -; write(Out, 'if (! '), write_reg(Xi, Out), -; write(Out, '.equals(((.Fun)'), write_reg(Xj, Out), -; write(Out, ').functor()))'), nl(Out), -; tab(Out, 16), -; write(Out, 'return engine.fail();'), nl(Out), -; tab(Out, 12), -; write(Out, 'Term[] args = ((.Fun)'), -; write_reg(Xj, Out), write(Out, ').args();'), nl(Out), -; write_unify_read(Us, 0, Out), -; ; write mode -; tab(Out, 8), -; write(Out, '} else if ('), write_reg(Xj, Out), write(Out, ' instanceof Var){'), nl(Out), -; write_unify_write(Us, Rs, Out), -; tab(Out, 12), -; write(Out, 'Term[] args = {'), write_reg_args(Rs, Out), write(Out, '};'), nl(Out), -; tab(Out, 12), -; write(Out, '((Var) '), write_reg(Xj, Out), write(Out, ').bind(F('), -; write_reg(Xi, Out), write(Out, ', args), engine.trail);'), nl(Out), -; ; otherwise fail -; tab(Out, 8), -; write(Out, '} else {'), nl(Out), -; tab(Out, 12), -; write(Out, 'return engine.fail();'), nl(Out), -; tab(Out, 8), -; write(Out, '}'), nl(Out). -; */ - -; ;;; Choice Instructions - +; (= (write-java0 @@ -6229,7 +7310,9 @@ (write $Out 'return ') (write-index $Li $Out) (write $Out (engine);) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (trust $L) $_ $Out) @@ -6241,9 +7324,11 @@ (write $Out 'return ') (write-index $L $Out) (write $Out (engine);) - (nl $Out))) + (nl $Out))) +; + ; -; ;; Indexing Instructions +; (= (write-java0 @@ -6270,7 +7355,9 @@ (tab $Out 8) (write $Out }) (write-inline-end $Out) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 (switch-on-hash $Tag $_ $L $_) $_ $Out) @@ -6284,10 +7371,14 @@ (write $Out , ) (write-method-ref $L $Out) (write $Out ).exec(engine);) - (nl $Out))) + (nl $Out))) +; + (= (write-java0 $Instruction $_ $_) - ( (am2cpp-error (:: $Instruction is an invalid instruction)) (fail))) + ( (am2cpp-error (:: $Instruction is an invalid instruction)) (fail))) +; + (= @@ -6295,7 +7386,7 @@ (main (/ $F $A) $Modifier) $Out) ( (set-det) - (get-atoms &self + (get-symbols &self (= (current_package $P) $_)) (nl $Out) @@ -6310,18 +7401,7 @@ (write-predicate-base-class $A $Out) (write $Out {) (nl $Out))) -; /***************************************************************** -; Write Label -; *****************************************************************/ - -; ; Import class constants within translation unit - -; ; write(Out, 'import static '), write_package(P, Out), write(Out, '.'), -; ; write_class_name(F/A, Out), write(Out, '.*;'), -; ; nl(Out), - -; ; Class definition - +; (= (write-label @@ -6348,14 +7428,7 @@ (tab $Out 4) (write $Out 'public Operation exec(Prolog engine) {') (nl $Out))) -; ; instance variable declaration - -; ; constructor - -; ; toString method - -; ; exec method - +; (= (write-label $L $Out) @@ -6369,12 +7442,13 @@ (write $Out '(Prolog engine) {') (nl $Out) (set-det))) -; ; method for control instructions and clauses - +; (= (write-label $Instruction $_ $_) - ( (am2cpp-error (:: $Instruction is an invalid instruction)) (fail))) + ( (am2cpp-error (:: $Instruction is an invalid instruction)) (fail))) +; + (= @@ -6402,10 +7476,7 @@ (write $Out or) (nl $Out) (fail))) -; /***************************************************************** -; Write Constructor -; *****************************************************************/ - +; (= (write-constructor $_ $Out) @@ -6413,7 +7484,9 @@ (write $Out 'this.cont = cont;') (nl $Out) (tab $Out 4) - (write $Out }))) + (write $Out }))) +; + (= @@ -6427,21 +7500,20 @@ (det-if-then-else (< $I $EN) (write $Out $Delim) True) - (fail))) + (fail))) +; + (= (write-enum $_ $_ $SN $EN $_ $Tail $_ $Out) - ( (=< $SN $EN) (write $Out $Tail))) + ( (=< $SN $EN) (write $Out $Tail))) +; + (= (write-unify-read Nil $_ $_) (set-det)) -; /***************************************************************** -; Write Unify Instructions -; *****************************************************************/ - -; ;;; Read Mode - +; (= (write-unify-read @@ -6450,14 +7522,18 @@ ( (set-det) (is $N1 (+ $N $I)) - (write-unify-read $Xs $N1 $Out))) + (write-unify-read $Xs $N1 $Out))) +; + (= (write-unify-read (Cons $X $Xs) $N $Out) ( (write-unify-r $X $N $Out) (is $N1 (+ $N 1)) - (write-unify-read $Xs $N1 $Out))) + (write-unify-read $Xs $N1 $Out))) +; + (= @@ -6465,7 +7541,9 @@ ( (var $X) (set-det) (am2cpp-error (:: unbound variable is found)) - (fail))) + (fail))) +; + (= (write-unify-r (unify-var $X) $N $Out) @@ -6476,7 +7554,9 @@ (write-reg (args $N) $Out) (write $Out or) - (nl $Out))) + (nl $Out))) +; + (= (write-unify-r (unify-val $X) $N $Out) @@ -6491,48 +7571,55 @@ (nl $Out) (tab $Out 16) (write $Out 'return engine.fail();') - (nl $Out))) + (nl $Out))) +; + (= (write-unify-r (unify-int $_ $X) $N $Out) ( (set-det) (write-unify-r (unify-val $X) $N $Out))) -; ;??? - +; (= (write-unify-r (unify-float $_ $X) $N $Out) ( (set-det) (write-unify-r (unify-val $X) $N $Out))) -; ;??? - +; (= (write-unify-r (unify-con $_ $X) $N $Out) ( (set-det) (write-unify-r (unify-val $X) $N $Out))) -; ;??? - +; (= (write-unify-r (unify-ground $_ $X) $N $Out) - ( (set-det) (write-unify-r (unify-val $X) $N $Out))) + ( (set-det) (write-unify-r (unify-val $X) $N $Out))) +; + (= (write-unify-r $X $_ $_) - ( (am2cpp-error (:: $X is an invalid instruction)) (fail))) + ( (am2cpp-error (:: $X is an invalid instruction)) (fail))) +; + ; -; ;; Write Mode +; (= (write-unify-write Nil Nil $_) - (set-det)) + (set-det)) +; + (= (write-unify-write (Cons (unify-void 0) $Xs) $Rs $Out) - ( (set-det) (write-unify-write $Xs $Rs $Out))) + ( (set-det) (write-unify-write $Xs $Rs $Out))) +; + (= (write-unify-write (Cons @@ -6544,12 +7631,16 @@ (- $I 1)) (write-unify-write (Cons - (unify-void $I1) $Xs) $Rs $Out))) + (unify-void $I1) $Xs) $Rs $Out))) +; + (= (write-unify-write (Cons $X $Xs) (Cons $R $Rs) $Out) - ( (write-unify-w $X $R $Out) (write-unify-write $Xs $Rs $Out))) + ( (write-unify-w $X $R $Out) (write-unify-write $Xs $Rs $Out))) +; + (= @@ -6557,7 +7648,9 @@ ( (var $X) (set-det) (am2cpp-error (:: unbound variable is found)) - (fail))) + (fail))) +; + (= (write-unify-w (unify-var $X) $X $Out) @@ -6565,30 +7658,44 @@ (tab $Out 12) (write-reg $X $Out) (write $Out ' = new Var(engine);') - (nl $Out))) + (nl $Out))) +; + (= (write-unify-w (unify-val $X) $X $_) - (set-det)) + (set-det)) +; + (= (write-unify-w (unify-int $_ $X) $X $_) - (set-det)) + (set-det)) +; + (= (write-unify-w (unify-float $_ $X) $X $_) - (set-det)) + (set-det)) +; + (= (write-unify-w (unify-con $_ $X) $X $_) - (set-det)) + (set-det)) +; + (= (write-unify-w (unify-ground $_ $X) $X $_) - (set-det)) + (set-det)) +; + (= (write-unify-w $X $_ $_) - ( (am2cpp-error (:: $X is an invalid instruction)) (fail))) + ( (am2cpp-error (:: $X is an invalid instruction)) (fail))) +; + (= @@ -6596,10 +7703,7 @@ ( (write-inline-start $X $Out) (write-inline0 $X $In $Out) (write-inline-end $Out))) -; /***************************************************************** -; Write Inline -; *****************************************************************/ - +; @@ -6608,16 +7712,20 @@ ( (tab $Out 8) (write $Out '//START inline expansion of ') (write $Out $Goal) - (nl $Out))) + (nl $Out))) +; + (= (write-inline-end $Out) ( (tab $Out 8) (write $Out '//END inline expansion') - (nl $Out))) + (nl $Out))) +; + ; -; Control constructs +; (= @@ -6625,17 +7733,23 @@ ( (set-det) (tab $Out 8) (write $Out 'return engine.fail();') - (nl $Out))) + (nl $Out))) +; + (= (write-inline0 ($get-level $X) $_ $Out) - ( (set-det) (write-if-fail (op (set-det) (unify $X (# ('new IntegerTerm' engine.B0)))) Nil 8 $Out))) + ( (set-det) (write-if-fail (op (set-det) (unify $X (# ('new IntegerTerm' engine.B0)))) Nil 8 $Out))) +; + (= (write-inline0 %neck-cut $_ $Out) ( (set-det) (tab $Out 8) (write $Out engine.neckCut();) - (nl $Out))) + (nl $Out))) +; + (= (write-inline0 ($cut $X) $_ $Out) @@ -6662,45 +7776,63 @@ (nl $Out) (tab $Out 8) (write $Out }) - (nl $Out))) + (nl $Out))) +; + ; -; Term unification +; (= (write-inline0 ($unify $X $Y) $_ $Out) - ( (set-det) (write-if-fail (op (set-det) (unify $X $Y)) Nil 8 $Out))) + ( (set-det) (write-if-fail (op (set-det) (unify $X $Y)) Nil 8 $Out))) +; + (= (write-inline0 ($not-unifiable $X $Y) $_ $Out) - ( (set-det) (write-if-fail (unify $X $Y) Nil 8 $Out))) + ( (set-det) (write-if-fail (unify $X $Y) Nil 8 $Out))) +; + ; -; Type testing +; (= (write-inline0 (var $X) $_ $Out) - ( (set-det) (write-if-fail (op (set-det) (instanceof $X Var)) (:: $X) 8 $Out))) + ( (set-det) (write-if-fail (op (set-det) (instanceof $X Var)) (:: $X) 8 $Out))) +; + (= (write-inline0 (atom $X) $_ $Out) - ( (set-det) (write-if-fail (op (set-det) (instanceof $X Const)) (:: $X) 8 $Out))) + ( (set-det) (write-if-fail (op (set-det) (instanceof $X Const)) (:: $X) 8 $Out))) +; + (= (write-inline0 (integer $X) $_ $Out) - ( (set-det) (write-if-fail (op (set-det) (instanceof $X IntegerTerm)) (:: $X) 8 $Out))) + ( (set-det) (write-if-fail (op (set-det) (instanceof $X IntegerTerm)) (:: $X) 8 $Out))) +; + (= (write-inline0 (long $X) $_ $Out) - ( (set-det) (write-if-fail (op (set-det) (instanceof $X LongTerm)) (:: $X) 8 $Out))) + ( (set-det) (write-if-fail (op (set-det) (instanceof $X LongTerm)) (:: $X) 8 $Out))) +; + (= (write-inline0 (float $X) $_ $Out) - ( (set-det) (write-if-fail (op (set-det) (instanceof $X Float)) (:: $X) 8 $Out))) + ( (set-det) (write-if-fail (op (set-det) (instanceof $X Float)) (:: $X) 8 $Out))) +; + (= (write-inline0 (nonvar $X) $_ $Out) - ( (set-det) (write-if-fail (instanceof $X Var) (:: $X) 8 $Out))) + ( (set-det) (write-if-fail (instanceof $X Var) (:: $X) 8 $Out))) +; + (= (write-inline0 (number $X) $_ $Out) @@ -6720,15 +7852,21 @@ (write-if-fail (op && (op && $NI $ND) $NL) - (:: $X) 8 $Out))) + (:: $X) 8 $Out))) +; + (= (write-inline0 (java $X) $_ $Out) - ( (set-det) (write-if-fail (op (set-det) (instanceof $X JavaObjectTerm)) (:: $X) 8 $Out))) + ( (set-det) (write-if-fail (op (set-det) (instanceof $X JavaObjectTerm)) (:: $X) 8 $Out))) +; + (= (write-inline0 (closure $X) $_ $Out) - ( (set-det) (write-if-fail (op (set-det) (instanceof $X ClosureTerm)) (:: $X) 8 $Out))) + ( (set-det) (write-if-fail (op (set-det) (instanceof $X ClosureTerm)) (:: $X) 8 $Out))) +; + (= (write-inline0 (atomic $X) $_ $Out) @@ -6753,7 +7891,9 @@ (op && $NL (op && $NS (op && $NI $ND))) - (:: $X) 8 $Out))) + (:: $X) 8 $Out))) +; + (= (write-inline0 (java $X $Y) $_ $Out) @@ -6768,44 +7908,62 @@ (write-if-fail (op (set-det) - (unify $Y $EXP)) Nil 8 $Out))) + (unify $Y $EXP)) Nil 8 $Out))) +; + (= (write-inline0 (ground $X) $_ $Out) - ( (set-det) (write-if-fail (op (set-det) (@ (isGround $X))) (:: $X) 8 $Out))) + ( (set-det) (write-if-fail (op (set-det) (@ (isGround $X))) (:: $X) 8 $Out))) +; + ; -; Term comparison +; (= (write-inline0 ($equality-of-term $X $Y) $_ $Out) - ( (set-det) (write-if-fail (op (set-det) (@ (equals $X $Y))) (:: $X $Y) 8 $Out))) + ( (set-det) (write-if-fail (op (set-det) (@ (equals $X $Y))) (:: $X $Y) 8 $Out))) +; + (= (write-inline0 ($inequality-of-term $X $Y) $_ $Out) - ( (set-det) (write-if-fail (@ (equals $X $Y)) (:: $X $Y) 8 $Out))) + ( (set-det) (write-if-fail (@ (equals $X $Y)) (:: $X $Y) 8 $Out))) +; + (= (write-inline0 ($after $X $Y) $_ $Out) - ( (set-det) (write-if-fail (op <= (@ (compareTo $X $Y)) 0) (:: $X $Y) 8 $Out))) + ( (set-det) (write-if-fail (op <= (@ (compareTo $X $Y)) 0) (:: $X $Y) 8 $Out))) +; + (= (write-inline0 ($before $X $Y) $_ $Out) - ( (set-det) (write-if-fail (op >= (@ (compareTo $X $Y)) 0) (:: $X $Y) 8 $Out))) + ( (set-det) (write-if-fail (op >= (@ (compareTo $X $Y)) 0) (:: $X $Y) 8 $Out))) +; + (= (write-inline0 ($not-after $X $Y) $_ $Out) - ( (set-det) (write-if-fail (op > (@ (compareTo $X $Y)) 0) (:: $X $Y) 8 $Out))) + ( (set-det) (write-if-fail (op > (@ (compareTo $X $Y)) 0) (:: $X $Y) 8 $Out))) +; + (= (write-inline0 ($not-before $X $Y) $_ $Out) - ( (set-det) (write-if-fail (op < (@ (compareTo $X $Y)) 0) (:: $X $Y) 8 $Out))) + ( (set-det) (write-if-fail (op < (@ (compareTo $X $Y)) 0) (:: $X $Y) 8 $Out))) +; + (= (write-inline0 ($identical-or-cannot-unify $X $Y) $_ $Out) - ( (set-det) (write-if-fail (op && (op (set-det) (@ (equals $X $Y))) (unify $X $Y)) (:: $X $Y) 8 $Out))) + ( (set-det) (write-if-fail (op && (op (set-det) (@ (equals $X $Y))) (unify $X $Y)) (:: $X $Y) 8 $Out))) +; + ; -; Term creation and decomposition +; (= (write-inline0 @@ -6818,216 +7976,308 @@ (set-det) (unify $Y (# (engine.copy $X)))) - (:: $X) 8 $Out))) + (:: $X) 8 $Out))) +; + ; -; Arithmetic evaluation +; (= (write-inline0 (is $X $Y) $_ $Out) - ( (set-det) (write-arith $_ $Y $X 8 $Out))) + ( (set-det) (write-arith $_ $Y $X 8 $Out))) +; + (= (write-inline0 ($abs $X $Y) $_ $Out) - ( (set-det) (write-arith abs $X $Y 8 $Out))) + ( (set-det) (write-arith abs $X $Y 8 $Out))) +; + (= (write-inline0 ($asin $X $Y) $_ $Out) - ( (set-det) (write-arith asin $X $Y 8 $Out))) + ( (set-det) (write-arith asin $X $Y 8 $Out))) +; + (= (write-inline0 ($acos $X $Y) $_ $Out) - ( (set-det) (write-arith acos $X $Y 8 $Out))) + ( (set-det) (write-arith acos $X $Y 8 $Out))) +; + (= (write-inline0 ($atan $X $Y) $_ $Out) - ( (set-det) (write-arith atan $X $Y 8 $Out))) + ( (set-det) (write-arith atan $X $Y 8 $Out))) +; + (= (write-inline0 ($bitwise-conj $X $Y $Z) $_ $Out) - ( (set-det) (write-arith and $X $Y $Z 8 $Out))) + ( (set-det) (write-arith and $X $Y $Z 8 $Out))) +; + (= (write-inline0 ($bitwise-disj $X $Y $Z) $_ $Out) - ( (set-det) (write-arith or $X $Y $Z 8 $Out))) + ( (set-det) (write-arith or $X $Y $Z 8 $Out))) +; + (= (write-inline0 ($bitwise-exclusive-or $X $Y $Z) $_ $Out) - ( (set-det) (write-arith xor $X $Y $Z 8 $Out))) + ( (set-det) (write-arith xor $X $Y $Z 8 $Out))) +; + (= (write-inline0 ($bitwise-neg $X $Y) $_ $Out) - ( (set-det) (write-arith not $X $Y 8 $Out))) + ( (set-det) (write-arith not $X $Y 8 $Out))) +; + (= (write-inline0 ($ceil $X $Y) $_ $Out) - ( (set-det) (write-arith ceil $X $Y 8 $Out))) + ( (set-det) (write-arith ceil $X $Y 8 $Out))) +; + (= (write-inline0 ($cos $X $Y) $_ $Out) - ( (set-det) (write-arith cos $X $Y 8 $Out))) + ( (set-det) (write-arith cos $X $Y 8 $Out))) +; + (= (write-inline0 ($degrees $X $Y) $_ $Out) - ( (set-det) (write-arith toDegrees $X $Y 8 $Out))) + ( (set-det) (write-arith toDegrees $X $Y 8 $Out))) +; + (= (write-inline0 ($exp $X $Y) $_ $Out) - ( (set-det) (write-arith exp $X $Y 8 $Out))) + ( (set-det) (write-arith exp $X $Y 8 $Out))) +; + (= (write-inline0 ($float $X $Y) $_ $Out) - ( (set-det) (write-arith toFloat $X $Y 8 $Out))) + ( (set-det) (write-arith toFloat $X $Y 8 $Out))) +; + (= (write-inline0 ($float-integer-part $X $Y) $_ $Out) - ( (set-det) (write-arith floatIntPart $X $Y 8 $Out))) + ( (set-det) (write-arith floatIntPart $X $Y 8 $Out))) +; + (= (write-inline0 ($float-fractional-part $X $Y) $_ $Out) - ( (set-det) (write-arith floatFractPart $X $Y 8 $Out))) + ( (set-det) (write-arith floatFractPart $X $Y 8 $Out))) +; + (= (write-inline0 ($float-quotient $X $Y $Z) $_ $Out) - ( (set-det) (write-arith divide $X $Y $Z 8 $Out))) + ( (set-det) (write-arith divide $X $Y $Z 8 $Out))) +; + (= (write-inline0 ($floor $X $Y) $_ $Out) - ( (set-det) (write-arith floor $X $Y 8 $Out))) + ( (set-det) (write-arith floor $X $Y 8 $Out))) +; + (= (write-inline0 ($int-quotient $X $Y $Z) $_ $Out) - ( (set-det) (write-arith intDivide $X $Y $Z 8 $Out))) + ( (set-det) (write-arith intDivide $X $Y $Z 8 $Out))) +; + (= (write-inline0 ($log $X $Y) $_ $Out) - ( (set-det) (write-arith log $X $Y 8 $Out))) + ( (set-det) (write-arith log $X $Y 8 $Out))) +; + (= (write-inline0 ($max $X $Y $Z) $_ $Out) - ( (set-det) (write-arith max $X $Y $Z 8 $Out))) + ( (set-det) (write-arith max $X $Y $Z 8 $Out))) +; + (= (write-inline0 ($min $X $Y $Z) $_ $Out) - ( (set-det) (write-arith min $X $Y $Z 8 $Out))) + ( (set-det) (write-arith min $X $Y $Z 8 $Out))) +; + (= (write-inline0 ($minus $X $Y $Z) $_ $Out) - ( (set-det) (write-arith subtract $X $Y $Z 8 $Out))) + ( (set-det) (write-arith subtract $X $Y $Z 8 $Out))) +; + (= (write-inline0 ($mod $X $Y $Z) $_ $Out) - ( (set-det) (write-arith mod $X $Y $Z 8 $Out))) + ( (set-det) (write-arith mod $X $Y $Z 8 $Out))) +; + (= (write-inline0 ($multi $X $Y $Z) $_ $Out) - ( (set-det) (write-arith multiply $X $Y $Z 8 $Out))) + ( (set-det) (write-arith multiply $X $Y $Z 8 $Out))) +; + (= (write-inline0 ($plus $X $Y $Z) $_ $Out) - ( (set-det) (write-arith add $X $Y $Z 8 $Out))) + ( (set-det) (write-arith add $X $Y $Z 8 $Out))) +; + (= (write-inline0 ($pow $X $Y $Z) $_ $Out) - ( (set-det) (write-arith pow $X $Y $Z 8 $Out))) + ( (set-det) (write-arith pow $X $Y $Z 8 $Out))) +; + (= (write-inline0 ($radians $X $Y) $_ $Out) - ( (set-det) (write-arith toRadians $X $Y 8 $Out))) + ( (set-det) (write-arith toRadians $X $Y 8 $Out))) +; + (= (write-inline0 ($rint $X $Y) $_ $Out) - ( (set-det) (write-arith rint $X $Y 8 $Out))) + ( (set-det) (write-arith rint $X $Y 8 $Out))) +; + (= (write-inline0 ($round $X $Y) $_ $Out) - ( (set-det) (write-arith round $X $Y 8 $Out))) + ( (set-det) (write-arith round $X $Y 8 $Out))) +; + (= (write-inline0 ($shift-left $X $Y $Z) $_ $Out) - ( (set-det) (write-arith shiftLeft $X $Y $Z 8 $Out))) + ( (set-det) (write-arith shiftLeft $X $Y $Z 8 $Out))) +; + (= (write-inline0 ($shift-right $X $Y $Z) $_ $Out) - ( (set-det) (write-arith shiftRight $X $Y $Z 8 $Out))) + ( (set-det) (write-arith shiftRight $X $Y $Z 8 $Out))) +; + (= (write-inline0 ($sign $X $Y) $_ $Out) - ( (set-det) (write-arith signum $X $Y 8 $Out))) + ( (set-det) (write-arith signum $X $Y 8 $Out))) +; + (= (write-inline0 ($sin $X $Y) $_ $Out) - ( (set-det) (write-arith sin $X $Y 8 $Out))) + ( (set-det) (write-arith sin $X $Y 8 $Out))) +; + (= (write-inline0 ($sqrt $X $Y) $_ $Out) - ( (set-det) (write-arith sqrt $X $Y 8 $Out))) + ( (set-det) (write-arith sqrt $X $Y 8 $Out))) +; + (= (write-inline0 ($tan $X $Y) $_ $Out) - ( (set-det) (write-arith tan $X $Y 8 $Out))) + ( (set-det) (write-arith tan $X $Y 8 $Out))) +; + (= (write-inline0 ($truncate $X $Y) $_ $Out) - ( (set-det) (write-arith truncate $X $Y 8 $Out))) + ( (set-det) (write-arith truncate $X $Y 8 $Out))) +; + ; -; Arithmetic comparison +; (= (write-inline0 ($arith-equal $X $Y) $_ $Out) - ( (set-det) (write-arith-compare != $X $Y 8 $Out))) + ( (set-det) (write-arith-compare != $X $Y 8 $Out))) +; + (= (write-inline0 ($arith-not-equal $X $Y) $_ $Out) - ( (set-det) (write-arith-compare == $X $Y 8 $Out))) + ( (set-det) (write-arith-compare == $X $Y 8 $Out))) +; + (= (write-inline0 ($greater-or-equal $X $Y) $_ $Out) - ( (set-det) (write-arith-compare < $X $Y 8 $Out))) + ( (set-det) (write-arith-compare < $X $Y 8 $Out))) +; + (= (write-inline0 ($greater-than $X $Y) $_ $Out) - ( (set-det) (write-arith-compare <= $X $Y 8 $Out))) + ( (set-det) (write-arith-compare <= $X $Y 8 $Out))) +; + (= (write-inline0 ($less-or-equal $X $Y) $_ $Out) - ( (set-det) (write-arith-compare > $X $Y 8 $Out))) + ( (set-det) (write-arith-compare > $X $Y 8 $Out))) +; + (= (write-inline0 ($less-than $X $Y) $_ $Out) - ( (set-det) (write-arith-compare >= $X $Y 8 $Out))) + ( (set-det) (write-arith-compare >= $X $Y 8 $Out))) +; + (= (write-deref-args Nil $_) - (set-det)) + (set-det)) +; + (= (write-deref-args (Cons (s $_) $Xs) $Out) - ( (set-det) (write-deref-args $Xs $Out))) + ( (set-det) (write-deref-args $Xs $Out))) +; + (= (write-deref-args (Cons (si $_) $Xs) $Out) ( (set-det) (write-deref-args $Xs $Out))) -; ; ??? - +; (= (write-deref-args (Cons (sf $_) $Xs) $Out) ( (set-det) (write-deref-args $Xs $Out))) -; ; ??? - +; (= (write-deref-args (Cons $X $Xs) $Out) ( (write-java0 - (deref $X $X) $_ $Out) (write-deref-args $Xs $Out))) + (deref $X $X) $_ $Out) (write-deref-args $Xs $Out))) +; + (= @@ -7038,29 +8288,39 @@ (= $EXP (if-then $Cond 'return engine.fail()')) (write-deref-args $Args $Out) - (write-inline-java $EXP $Tab $Out))) + (write-inline-java $EXP $Tab $Out))) +; + (= (make-arith-arg $E $_) ( (var $E) (set-det) - (fail))) + (fail))) +; + (= (make-arith-arg $E $E) ( (= $E - (si $_)) (set-det))) + (si $_)) (set-det))) +; + (= (make-arith-arg $E $E) ( (= $E - (sf $_)) (set-det))) + (sf $_)) (set-det))) +; + ; -; make_arith_arg(E, cast('NumberTerm',E)) :- E = a(_), !. ;??? +; (= (make_arith_arg $E (# - (Arithmetic.evaluate $E))) True) + (Arithmetic.evaluate $E))) True) +; + (= @@ -7081,10 +8341,7 @@ (set-det) (unify $V $A)) 'return engine.fail()')) (write-inline-java $EXP $Tab $Out))) -; ;EXP = try_catch(SENT, 'BuiltinException', ['e.goal = this','throw e']), - -; ;write_deref_args([E], Out), - +; (= @@ -7103,10 +8360,7 @@ (set-det) (unify $V $A)) 'return engine.fail()')) (write-inline-java $EXP $Tab $Out))) -; ;EXP = try_catch(SENT, 'BuiltinException', ['e.goal = this','throw e']), - -; ;write_deref_args([E1,E2], Out), - +; @@ -7123,10 +8377,7 @@ (if-then (op $M $A 0) 'return engine.fail()')) (write-inline-java $EXP $Tab $Out))) -; ;EXP = try_catch(SENT, 'BuiltinException', ['e.goal = this','throw e']), - -; ;write_deref_args([E1,E2], Out), - +; @@ -7134,16 +8385,22 @@ (write-inline-java $X $_ $_) ( (var $X) (set-det) - (fail))) + (fail))) +; + (= (write-inline-java Nil $_ $_) - (set-det)) + (set-det)) +; + (= (write-inline-java (Cons $X $Xs) $Tab $Out) ( (set-det) (write-inline-java $X $Tab $Out) - (write-inline-java $Xs $Tab $Out))) + (write-inline-java $Xs $Tab $Out))) +; + (= (write-inline-java (try-catch $TRY $EXCEPT $CATCH) $Tab $Out) @@ -7162,7 +8419,9 @@ (write-inline-java $CATCH $Tab1 $Out) (tab $Out $Tab) (write $Out }) - (nl $Out))) + (nl $Out))) +; + (= (write-inline-java (if-then $IF $THEN) $Tab $Out) @@ -7177,7 +8436,9 @@ (write-inline-java $THEN $Tab1 $Out) (tab $Out $Tab) (write $Out }) - (nl $Out))) + (nl $Out))) +; + (= (write-inline-java (if-then-else $IF $THEN $ELSE) $Tab $Out) @@ -7196,34 +8457,46 @@ (write-inline-java $ELSE $Tab1 $Out) (tab $Out $Tab) (write $Out }) - (nl $Out))) + (nl $Out))) +; + (= (write-inline-java $X $Tab $Out) ( (tab $Out $Tab) (write $Out $X) (write $Out or) - (nl $Out))) + (nl $Out))) +; + (= (write-inline-exp $X $_ $_) ( (var $X) (set-det) - (fail))) + (fail))) +; + (= (write-inline-exp Nil $_ $_) - (set-det)) + (set-det)) +; + (= (write-inline-exp (:: $X) $Tab $Out) - ( (set-det) (write-inline-exp $X $Tab $Out))) + ( (set-det) (write-inline-exp $X $Tab $Out))) +; + (= (write-inline-exp (Cons $X $Xs) $Tab $Out) ( (set-det) (write-inline-exp $X $Tab $Out) (write $Out ,) - (write-inline-exp $Xs 0 $Out))) + (write-inline-exp $Xs 0 $Out))) +; + (= (write-inline-exp (bracket $Exp) $Tab $Out) @@ -7231,7 +8504,9 @@ (tab $Out $Tab) (write $Out () (write-inline-exp $Exp 0 $Out) - (write $Out )))) + (write $Out )))) +; + (= (write-inline-exp (op $Op $Exp) $Tab $Out) @@ -7239,7 +8514,9 @@ (tab $Out $Tab) (write $Out $Op) (write $Out ' ') - (write-inline-exp $Exp 0 $Out))) + (write-inline-exp $Exp 0 $Out))) +; + (= (write-inline-exp (op $Op $Exp1 $Exp2) $Tab $Out) @@ -7249,7 +8526,9 @@ (write $Out ' ') (write $Out $Op) (write $Out ' ') - (write-inline-exp $Exp2 0 $Out))) + (write-inline-exp $Exp2 0 $Out))) +; + (= (write-inline-exp (instanceof $Exp $Class) $Tab $Out) @@ -7259,7 +8538,9 @@ (write-inline-exp $Exp 0 $Out) (write $Out ' instanceof ') (write $Out $Class) - (write $Out )))) + (write $Out )))) +; + (= (write-inline-exp (cast $Class $Exp) $Tab $Out) @@ -7269,7 +8550,9 @@ (write $Out $Class) (write $Out ) ) (write-inline-exp $Exp 0 $Out) - (write $Out )))) + (write $Out )))) +; + (= (write-inline-exp (unify $X $Y) $Tab $Out) @@ -7278,7 +8561,9 @@ (write-inline-exp $X 0 $Out) (write $Out .unify() (write-inline-exp $Y 0 $Out) - (write $Out ', engine.trail)'))) + (write $Out ', engine.trail)'))) +; + (= (write-inline-exp (# $X) $Tab $Out) @@ -7289,21 +8574,27 @@ (write $Out $F) (write $Out () (write-inline-exp $As 0 $Out) - (write $Out )))) + (write $Out )))) +; + (= (write-inline-exp (@ $X) $Tab $Out) ( (set-det) (=.. $X (Cons $F $As)) - (write-inline-method $F $As $Tab $Out))) + (write-inline-method $F $As $Tab $Out))) +; + (= (write-inline-exp $X $Tab $Out) ( (= $X (s $_)) (set-det) (tab $Out $Tab) - (write-reg $X $Out))) + (write-reg $X $Out))) +; + (= (write-inline-exp $X $Tab $Out) ( (= $X @@ -7311,8 +8602,7 @@ (set-det) (tab $Out $Tab) (write-reg $X $Out))) -; ; ??? - +; (= (write-inline-exp $X $Tab $Out) @@ -7321,8 +8611,7 @@ (set-det) (tab $Out $Tab) (write-reg $X $Out))) -; ; ??? - +; (= (write-inline-exp $X $Tab $Out) @@ -7330,31 +8619,38 @@ (a $_)) (set-det) (tab $Out $Tab) - (write-reg $X $Out))) + (write-reg $X $Out))) +; + (= (write-inline-exp $X $Tab $Out) ( (== $X void) (set-det) (tab $Out $Tab) (write-reg $X $Out))) -; ; ??? - +; (= (write-inline-exp $X $Tab $Out) - ( (tab $Out $Tab) (write $Out $X))) + ( (tab $Out $Tab) (write $Out $X))) +; + (= (write-inline-method $F $_ $_ $_) ( (var $F) (set-det) - (fail))) + (fail))) +; + (= (write-inline-method $_ $A $_ $_) ( (var $A) (set-det) - (fail))) + (fail))) +; + (= (write-inline-method $F (:: $A) $Tab $Out) @@ -7363,7 +8659,9 @@ (write-inline-exp $A 0 $Out) (write $Out .) (write $Out $F) - (write $Out ()))) + (write $Out ()))) +; + (= (write-inline-method $F (:: $A $B) $Tab $Out) @@ -7373,7 +8671,9 @@ (write $Out $F) (write $Out () (write-inline-exp $B 0 $Out) - (write $Out )))) + (write $Out )))) +; + @@ -7382,21 +8682,22 @@ ( (var $X) (set-det) (fail))) -; /***************************************************************** -; Write Insert -; *****************************************************************/ - +; (= (write-insert Nil $_ $_) - (set-det)) + (set-det)) +; + (= (write-insert (Cons $X $Xs) $_ $Out) ( (atom $X) (write $Out $X) (nl $Out) - (write-insert $Xs $_ $Out))) + (write-insert $Xs $_ $Out))) +; + (= @@ -7428,22 +8729,14 @@ (tab $Out 4) (write $Out }) (nl $Out))) -; /***************************************************************** -; Write toString(StringBuilder sb) -; *****************************************************************/ - +; (= (mkdirs $Dir) ( (exists-directory $Dir) (set-det))) -; /***************************************************************** -; Auxiliaries -; *****************************************************************/ - -; ; Create a directory if missing - +; (= (mkdirs $Dir) @@ -7451,27 +8744,33 @@ (mkdirs $Parent) (catch (make-directory $Dir) $_ - (exists-directory $Dir)))) ; -; it is ok if we failed to create a directory, because it is already exist + (exists-directory $Dir)))) +; + ; +; ; -; int +; (= (java-integer $X) ( (integer $X) (=< -2147483648 $X) - (=< $X 2147483647))) + (=< $X 2147483647))) +; + ; -; Read Instructions +; (= (read-instructions 0 $_ Nil) - (set-det)) + (set-det)) +; + (= (read-instructions $N $In (Cons $X $Xs)) @@ -7479,70 +8778,92 @@ (read $In $X) (is $N1 (- $N 1)) - (read-instructions $N1 $In $Xs))) + (read-instructions $N1 $In $Xs))) +; + ; -; Write package name +; (= (write-package $P $Out) - ( (set-det) (write $Out $P))) + ( (set-det) (write $Out $P))) +; + ; -; Write class name +; (= (write-class-name $L $Out) - ( (write $Out PRED-) (write-index $L $Out))) + ( (write $Out PRED-) (write-index $L $Out))) +; + ; -; Write out base class name +; (= (write-predicate-base-class 0 $Out) - ( (set-det) (write $Out Predicate))) + ( (set-det) (write $Out Predicate))) +; + (= (write-predicate-base-class 1 $Out) - ( (set-det) (write $Out Predicate.P1))) + ( (set-det) (write $Out Predicate.P1))) +; + (= (write-predicate-base-class 2 $Out) - ( (set-det) (write $Out Predicate.P2))) + ( (set-det) (write $Out Predicate.P2))) +; + (= (write-predicate-base-class 3 $Out) - ( (set-det) (write $Out Predicate.P3))) + ( (set-det) (write $Out Predicate.P3))) +; + (= (write-predicate-base-class 4 $Out) - ( (set-det) (write $Out Predicate.P4))) + ( (set-det) (write $Out Predicate.P4))) +; + (= (write-predicate-base-class $_ $Out) - ( (set-det) (write $Out Predicate.P4))) + ( (set-det) (write $Out Predicate.P4))) +; + ; -; Write method reference +; (= (write-method-ref (/ fail 0) $Out) - ( (set-det) (write-index (/ fail 0) $Out))) + ( (set-det) (write-index (/ fail 0) $Out))) +; + (= (write-method-ref $R $Out) - ( (get-atoms &self + ( (get-symbols &self (= (current_arity $A) $_)) - (get-atoms &self + (get-symbols &self (= (current_functor $F) $_)) (write-class-name (/ $F $A) $Out) (write $Out ::) - (write-index $R $Out))) + (write-index $R $Out))) +; + ; -; Write if method call for switch_on_term +; (= @@ -7559,7 +8880,9 @@ (nl $Out) (tab $Out 12) (write $Out }) - (nl $Out))) + (nl $Out))) +; + (= (write-if-method-call $Cond $Method $Out) @@ -7575,33 +8898,41 @@ (nl $Out) (tab $Out 12) (write $Out }) - (nl $Out))) + (nl $Out))) +; + ; -; Write label +; (= (write-index (/ $F $A) $Out) - ( (set-det) (write-pred-spec (/ $F $A) $Out))) + ( (set-det) (write-pred-spec (/ $F $A) $Out))) +; + (= (write-index (+ $L $I) $Out) ( (write-index $L $Out) (write $Out -) - (write $Out $I))) + (write $Out $I))) +; + ; -; Write constant name +; (= (write-constant $X $Out) - ( (constant-encoding $X $Y) (write $Out $Y))) + ( (constant-encoding $X $Y) (write $Out $Y))) +; + ; -; Write predicate specification +; (= @@ -7610,22 +8941,28 @@ ( (predicate-encoding $F $F1) (write $Out $F1) (write $Out -) - (write $Out $A))) + (write $Out $A))) +; + ; -; Package name as directory +; (= (package-encoding $P $Dir) ( (atom-codes $P $Chs0) (package-encoding $Chs0 $Chs Nil) - (atom-codes $Dir $Chs))) + (atom-codes $Dir $Chs))) +; + (= (--> - (package_encoding ()) !) True) + (package_encoding ()) !) True) +; + (= (--> (package_encoding @@ -7633,7 +8970,9 @@ (, ! (, (47) - (package_encoding $Xs)))) True) + (package_encoding $Xs)))) True) +; + (= (--> (package_encoding @@ -7641,29 +8980,37 @@ (, ! (, ($X) - (package_encoding $Xs)))) True) + (package_encoding $Xs)))) True) +; + ; -; Predicate Encoding +; (= (predicate-encoding $X $Y) ( (atom-codes $X $Chs0) (pred-encoding $Chs0 $Chs Nil) - (atom-codes $Y $Chs))) + (atom-codes $Y $Chs))) +; + (= (--> - (pred_encoding ()) !) True) + (pred_encoding ()) !) True) +; + (= (--> (pred_encoding (Cons $X $Xs)) (, (pred_encoding_char $X) - (pred_encoding $Xs))) True) + (pred_encoding $Xs))) True) +; + (= (--> @@ -7673,8 +9020,10 @@ (=< 97 $X) (=< $X 122)) } (, ! - ($X)))) True) ; -; a..z + ($X)))) True) +; + ; +; (= (--> @@ -7684,8 +9033,10 @@ (=< 65 $X) (=< $X 90)) } (, ! - ($X)))) True) ; -; A..Z + ($X)))) True) +; + ; +; (= (--> @@ -7695,22 +9046,28 @@ (=< 48 $X) (=< $X 57)) } (, ! - ($X)))) True) ; -; 0..9 + ($X)))) True) +; + ; +; (= (--> (pred_encoding_char 95) (, ! - (95))) True) ; -; '_' + (95))) True) +; + ; +; (= (--> (pred_encoding_char 36) (, ! - (36))) True) ; -; '$' ??? + (36))) True) +; + ; +; (= (--> @@ -7723,67 +9080,82 @@ (, (36) (pred_encoding_hex $X))))) True) -; ; '$' - +; (= (--> (pred_encoding_char $X) { (, (am2cpp_error - ($X is an invalid character code)) fail) }) True) + ($X is an invalid character code)) fail) }) True) +; + (= (--> (pred_encoding_hex $X) (, { (int_to_hex $X () $H) } - (pred_encoding_hex_char $H))) True) + (pred_encoding_hex_char $H))) True) +; + (= (--> (pred_encoding_hex_char ()) (, ! - (48 48 48 48))) True) ; -; 0000 + (48 48 48 48))) True) +; + ; +; (= (--> (pred_encoding_hex_char ($X)) (, ! - (48 48 48 $X))) True) ; -; 000X + (48 48 48 $X))) True) +; + ; +; (= (--> (pred_encoding_hex_char ($X $Y)) (, ! - (48 48 $X $Y))) True) ; -; 00XY + (48 48 $X $Y))) True) +; + ; +; (= (--> (pred_encoding_hex_char ($X $Y $Z)) (, ! - (48 $X $Y $Z))) True) ; -; 0XYZ + (48 $X $Y $Z))) True) +; + ; +; (= (--> (pred_encoding_hex_char ($X $Y $Z $W)) (, ! - ($X $Y $Z $W))) True) ; -; XYZW + ($X $Y $Z $W))) True) +; + ; +; (= (int-to-hex 0 $H $H) - (set-det)) + (set-det)) +; + (= (int-to-hex $D $H0 $H) ( (is $R @@ -7792,48 +9164,64 @@ (// $D 16)) (hex-map $R $R1) (int-to-hex $D1 - (Cons $R1 $H0) $H))) + (Cons $R1 $H0) $H))) +; + (= (hex-map 10 65) - (set-det)) ; -; 'A' + (set-det)) +; + ; +; (= (hex-map 11 66) - (set-det)) ; -; 'B' + (set-det)) +; + ; +; (= (hex-map 12 67) - (set-det)) ; -; 'C' + (set-det)) +; + ; +; (= (hex-map 13 68) - (set-det)) ; -; 'D' + (set-det)) +; + ; +; (= (hex-map 14 69) - (set-det)) ; -; 'E' + (set-det)) +; + ; +; (= (hex-map 15 70) - (set-det)) ; -; 'F' + (set-det)) +; + ; +; (= (hex-map $X $Y) ( (=< 0 $X) (=< $X 9) (number-codes $X - (:: $Y)))) + (:: $Y)))) +; + ; -; Constant Encoding (especially, escape sequence) +; (= @@ -7841,102 +9229,125 @@ ( (atom-codes $X $Chs0) (con-encoding $Chs0 $Chs) (atom-codes $Y $Chs))) -; ;??? - +; (= (con-encoding Nil Nil) - (set-det)) + (set-det)) +; + (= (con-encoding (Cons 7 $Xs) (Cons 92 (Cons 97 $Ys))) - ( (set-det) (con-encoding $Xs $Ys))) ; -; \a + ( (set-det) (con-encoding $Xs $Ys))) +; + ; +; (= (con-encoding (Cons 8 $Xs) (Cons 92 (Cons 98 $Ys))) - ( (set-det) (con-encoding $Xs $Ys))) ; -; \b + ( (set-det) (con-encoding $Xs $Ys))) +; + ; +; (= (con-encoding (Cons 9 $Xs) (Cons 92 (Cons 116 $Ys))) - ( (set-det) (con-encoding $Xs $Ys))) ; -; \t + ( (set-det) (con-encoding $Xs $Ys))) +; + ; +; (= (con-encoding (Cons 10 $Xs) (Cons 92 (Cons 110 $Ys))) - ( (set-det) (con-encoding $Xs $Ys))) ; -; \n + ( (set-det) (con-encoding $Xs $Ys))) +; + ; +; (= (con-encoding (Cons 11 $Xs) (Cons 92 (Cons 118 $Ys))) - ( (set-det) (con-encoding $Xs $Ys))) ; -; \v + ( (set-det) (con-encoding $Xs $Ys))) +; + ; +; (= (con-encoding (Cons 12 $Xs) (Cons 92 (Cons 102 $Ys))) - ( (set-det) (con-encoding $Xs $Ys))) ; -; \f + ( (set-det) (con-encoding $Xs $Ys))) +; + ; +; (= (con-encoding (Cons 13 $Xs) (Cons 92 (Cons 114 $Ys))) - ( (set-det) (con-encoding $Xs $Ys))) ; -; \r + ( (set-det) (con-encoding $Xs $Ys))) +; + ; +; (= (con-encoding (Cons 34 $Xs) (Cons 92 (Cons 34 $Ys))) - ( (set-det) (con-encoding $Xs $Ys))) ; -; \" + ( (set-det) (con-encoding $Xs $Ys))) +; + ; +; (= (con-encoding (Cons 39 $Xs) (Cons 92 (Cons 39 $Ys))) - ( (set-det) (con-encoding $Xs $Ys))) ; -; \' + ( (set-det) (con-encoding $Xs $Ys))) +; + ; +; (= (con-encoding (Cons 92 $Xs) (Cons 92 (Cons 92 $Ys))) - ( (set-det) (con-encoding $Xs $Ys))) ; -; \\ + ( (set-det) (con-encoding $Xs $Ys))) +; + ; +; (= (con-encoding (Cons $X $Xs) (Cons $X $Ys)) - (con-encoding $Xs $Ys)) + (con-encoding $Xs $Ys)) +; + ; -; Write Register name +; (= @@ -7944,10 +9355,14 @@ ( (var $X) (set-det) (am2cpp-error (:: register expression must not be unbound variable)) - (fail))) + (fail))) +; + (= (write-reg void $Out) - ( (set-det) (write $Out 'new Var(engine)'))) + ( (set-det) (write $Out 'new Var(engine)'))) +; + (= (write-reg (ea $X) $Out) @@ -7957,37 +9372,33 @@ (- $X 1)) (write $Out $Y) (write $Out ]))) -; /* -; write_reg(ea(1), Out) :- !, write(Out, 'engine.areg1'). -; write_reg(ea(2), Out) :- !, write(Out, 'engine.areg2'). -; write_reg(ea(3), Out) :- !, write(Out, 'engine.areg3'). -; write_reg(ea(4), Out) :- !, write(Out, 'engine.areg4'). -; write_reg(ea(5), Out) :- !, write(Out, 'engine.areg5'). -; write_reg(ea(6), Out) :- !, write(Out, 'engine.areg6'). -; write_reg(ea(7), Out) :- !, write(Out, 'engine.areg7'). -; write_reg(ea(8), Out) :- !, write(Out, 'engine.areg8'). -; */ - +; (= (write-reg econt $Out) - ( (set-det) (write $Out engine.cont))) + ( (set-det) (write $Out engine.cont))) +; + (= (write-reg (arg $X) $Out) ( (set-det) (write $Out arg) - (write $Out $X))) + (write $Out $X))) +; + (= (write-reg (a $X) $Out) ( (set-det) (write $Out a) - (write $Out $X))) + (write $Out $X))) +; + (= (write-reg (s $X) $Out) - ( (get-atoms &self + ( (get-symbols &self (= (inlined (s $X) @@ -7995,59 +9406,77 @@ (set-det) (write $Out ") (write-constant $F $Out) - (write $Out "))) + (write $Out "))) +; + (= (write-reg (s $X) $Out) - ( (get-atoms &self + ( (get-symbols &self (= (inlined (s $X) (str_args $Xs)) $_)) (set-det) - (write-reg-args $Xs $Out))) + (write-reg-args $Xs $Out))) +; + (= (write-reg (s $X) $Out) ( (set-det) (write $Out s) - (write $Out $X))) + (write $Out $X))) +; + (= (write-reg (si $X) $Out) ( (set-det) (write $Out si) - (write $Out $X))) ; -; ??? + (write $Out $X))) +; + ; +; (= (write-reg (sf $X) $Out) ( (set-det) (write $Out sf) - (write $Out $X))) ; -; ??? + (write $Out $X))) +; + ; +; (= (write-reg (y $X) $Out) ( (set-det) (write $Out y) - (write $Out $X))) + (write $Out $X))) +; + (= (write-reg (p $X) $Out) ( (set-det) (write $Out p) - (write $Out $X))) + (write $Out $X))) +; + (= (write-reg cont $Out) - ( (set-det) (write $Out cont))) + ( (set-det) (write $Out cont))) +; + (= (write-reg null $Out) - ( (set-det) (write $Out null))) + ( (set-det) (write $Out null))) +; + ; -; am2cpp only +; (= (write-reg @@ -8055,140 +9484,53 @@ ( (set-det) (write $Out args[) (write $Out $X) - (write $Out ]))) + (write $Out ]))) +; + (= (write-reg $X $_) - ( (am2cpp-error (:: $X is an invalid register expression)) (fail))) + ( (am2cpp-error (:: $X is an invalid register expression)) (fail))) +; + (= (write-reg-args Nil $_) - (set-det)) + (set-det)) +; + (= (write-reg-args (:: $X) $Out) - ( (set-det) (write-reg $X $Out))) + ( (set-det) (write-reg $X $Out))) +; + (= (write-reg-args (Cons $X $Xs) $Out) ( (write-reg $X $Out) (write $Out , ) - (write-reg-args $Xs $Out))) + (write-reg-args $Xs $Out))) +; + (= (for $M $M $N) (=< $M $N)) -; /***************************************************************** -; WAM-BASED INTERMEDIATE INSTRUCTIONS -; -; Put Instructions -; ================ -; + put_var(X) -; + put_int(i, X) -; + put_float(f, X) -; + put_con(f/n, X) -; + put_con(c, X), -; + put_list(Xi, Xj, Xk) -; + put_str(Xi, Y, Xj) -; + put_str_args([Xi,..,Xn], Y) -; + put_clo(p:G, X) -; -; Get Instructions -; ================ -; + get_val(Xi, Xj) -; + get_int(i, Xi, Xj) -; + get_float(f, Xi, Xj) -; + get_con(c, Xi, Xj) -; + get_ground(g, Xi, Xj) -; + get_list(X) -; + get_str(f/n, Xi, Xj) -; -; Unify Instructions -; ================== -; + unify_var(X) -; + unify_val(X) -; + unify_int(i, X) -; + unify_float(f, X) -; + unify_con(c, X) -; + unify_ground(g, X) -; + unify_void(i) -; -; Choice Instructions -; =================== -; + try(Li, Lj) -; + retry(Li, Lj) -; + trust(L) -; -; Indexing Instructions -; ===================== -; + switch_on_term(Lv, Li, Lf, Lc, Ls, Ll) -; + switch_on_hash(TAG, i, L, hashtable) -; -; Other Instructions -; ================== -; + comment(Message) -; + debug(Message) -; -; + begin_predicate(p, f/n) -; + end_predicate(p, f/n) -; -; + import_package(p) -; + import_package(p, f/n) -; -; + main(f/n, public): [Instructions] -; + main(f/n, non-public): [Instructions] -; + L: [Instructions] -; -; + label(L) -; + setB0 -; + goto(L) -; + deref(Ri, Rj) -; + set(Ri, Rj) -; -; + decl_term_vars([R1,...,Rn]) -; + decl_pred_vars([R1,...,Rn]) -; -; + put_cont(p:BinG, C) -; + put_cont(BinG, C) -; + execute(p:BinG) -; + execute(BinG) -; + inline(G) -; -; + new_hash(TAG, i) -; + put_hash(X, L, TAG) -; -; + static([Instructions]) -; -; Notation -; ******** -; X ::= a(i) | S -; Y ::= y(i) | S -; S ::= s(i) | si(i) | sf(i) -; L ::= f/n | f/n+i | f/n+TAG | f/n+TAG+i | f/n+TAG+i+i -; TAG ::= var | int | flo | con | str | lis | top | sub | nil -; BinG ::= C | f(A1,..,An, C) -; G ::= f(A1,..,An) -; A ::= void | X -; C ::= cont | p(N) -; R ::= cont | econt | a(i) | arg(i) | ea(i) -; -; *****************************************************************/ - -; /***************************************************************** -; Utilities -; *****************************************************************/ - +; (= (for $I $M $N) ( (=< $M $N) (is $M1 (+ $M 1)) - (for $I $M1 $N))) + (for $I $M1 $N))) +; + ; -; ;; print +; (= @@ -8196,38 +9538,52 @@ (am2cpp-message user-error (Cons *** (Cons AM2JAVA - (Cons ERROR $M))))) + (Cons ERROR $M))))) +; + (= (am2cpp-message $M) - (am2cpp-message user-output $M)) + (am2cpp-message user-output $M)) +; + (= (am2cpp-message $Stream Nil) - ( (nl $Stream) (flush-output $Stream))) + ( (nl $Stream) (flush-output $Stream))) +; + (= (am2cpp-message (Cons $M $Ms)) ( (write $Stream $M) (write $Stream ' ') - (am2cpp-message $Stream $Ms))) + (am2cpp-message $Stream $Ms))) +; + ; -; ;; list +; (= - (am2cpp_append () $Zs $Zs) True) + (am2cpp_append () $Zs $Zs) True) +; + (= (am2cpp-append (Cons $X $Xs) $Ys (Cons $X $Zs)) - (am2cpp-append $Xs $Ys $Zs)) + (am2cpp-append $Xs $Ys $Zs)) +; + (= (--> - (flatten_list ()) !) True) + (flatten_list ()) !) True) +; + (= (--> (flatten_list @@ -8235,23 +9591,31 @@ (, ! (, (flatten_list $L1) - (flatten_list $L2)))) True) + (flatten_list $L2)))) True) +; + (= (--> (flatten_list $L) - ($L)) True) + ($L)) True) +; + (= (list-to-string $List $String) ( (list-to-chars $List $Chars0) (flatten-list $Chars0 $Chars Nil) - (atom-codes $String $Chars))) + (atom-codes $String $Chars))) +; + (= (list-to-chars Nil Nil) - (set-det)) + (set-det)) +; + (= (list-to-chars (Cons $L $Ls) @@ -8259,7 +9623,9 @@ ( (atom $L) (set-det) (atom-codes $L $C) - (list-to-chars $Ls $Cs))) + (list-to-chars $Ls $Cs))) +; + (= (list-to-chars (Cons $L $Ls) @@ -8267,12 +9633,14 @@ ( (number $L) (set-det) (number-codes $L $C) - (list-to-chars $Ls $Cs))) + (list-to-chars $Ls $Cs))) +; + ; -; END +; ; -; written by SICStus MeTTa 3.12.8 +; diff --git a/sxx_machine/sxx_read.metta b/sxx_machine/sxx_read.metta index 63ea456..ca2884a 100644 --- a/sxx_machine/sxx_read.metta +++ b/sxx_machine/sxx_read.metta @@ -1,5 +1,5 @@ ; -; read/1: from screen - no error recovery - only simple syntax +; @@ -10,6 +10,8 @@ (maketerm $Tokens $Term) (set-det) (collectvars $Tokens Nil $Vars))) +; + (= @@ -18,11 +20,15 @@ (readall $Tok $Tokens) (maketerm $Tokens $Term) (set-det))) +; + (= (collectvars Nil $In $In) (set-det)) +; + (= (collectvars (Cons @@ -33,112 +39,192 @@ (collectvars $R (Cons (= $Var $Name) $In) $Out))) +; + (= (collectvars (Cons $_ $R) $In $Out) (collectvars $R $In $Out)) +; + (= (notvmember $_ Nil) (set-det)) +; + (= (notvmember $Name (Cons (= $_ $Name) $_)) ( (set-det) (fail))) +; + (= (notvmember $Name (Cons $_ $R)) (notvmember $Name $R)) +; + (= (readall end-of-file $Tail) ( (set-det) (halt))) +; + (= (readall end-of-clause $Tail) ( (set-det) (= $Tail Nil))) +; + (= (readall $Token (Cons $Token $Tail)) ( (nexttoken $NewToken) (readall $NewToken $Tail))) +; + (= (infix 1200 xfx :-) True) +; + (= (infix 1000 xfy ,) True) +; + (= (infix 1100 xfy ;) True) +; + (= (infix 1050 xfy ->) True) +; + (= (infix 700 xfx =) True) +; + (= (infix 700 xfx is) True) +; + (= (infix 700 xfx =..) True) +; + (= (infix 700 xfx ==) True) +; + (= (infix 700 xfx @<) True) +; + (= (infix 700 xfx @>) True) +; + (= (infix 700 xfx @=<) True) +; + (= (infix 700 xfx @>=) True) +; + (= (infix 700 xfx =:=) True) +; + (= (infix 700 xfx <) True) +; + (= (infix 700 xfx =<) True) +; + (= (infix 700 xfx >) True) +; + (= (infix 700 xfx >=) True) +; + (= (infix 550 xfy :) True) +; + (= (infix 500 yfx +) True) +; + (= (infix 500 yfx -) True) +; + (= (infix 500 yfx #) True) +; + (= (infix 400 yfx *) True) +; + (= (infix 400 yfx /) True) +; + (= (infix 400 yfx //) True) +; + (= (infix 400 yfx <<) True) +; + (= (infix 400 yfx >>) True) +; + (= (infix 300 xfx mod) True) +; + (= (infix 200 xfy ^) True) +; + (= (prefix 1200 fx :-) True) +; + (= (prefix 1200 fx ?-) True) +; + (= (prefix 500 fx +) True) +; + (= (prefix 500 fx -) True) +; + ; -; maketerm(In,Term) +; ; -; consists of tokens already +; @@ -146,26 +232,36 @@ (maketerm (:: (var $Var $Name $Occ)) $Out $_) ( (= $Out $Var) (set-det))) +; + (= (maketerm (:: (int $Term)) $Out $_) ( (set-det) (= $Out $Term))) +; + (= (maketerm (:: (real $Term)) $Out $_) ( (set-det) (= $Out $Term))) +; + (= (maketerm (:: (const $Term)) $Out $_) ( (set-det) (= $Out $Term))) +; + (= (maketerm (:: (string $Term)) $Out $_) ( (set-det) (= $Out $Term))) +; + (= (maketerm @@ -174,6 +270,8 @@ (Cons (const () $Argswithcomma)) $Out $_) ( (getargs $Argswithcomma $Args) (univ $Out $Name $Args))) +; + (= (maketerm $In $Term $Prec) @@ -187,6 +285,8 @@ (maketerm $In2 $T2 $P2) (univ $Term $Op (:: $T1 $T2)))) +; + (= (maketerm (Cons @@ -197,6 +297,8 @@ (maketerm $In $T1 $P1) (univ $Term $Op (:: $T1)))) +; + (= (maketerm (Cons @@ -209,6 +311,8 @@ (maketerm (Cons (const [) $Rest) $Tail 900))) +; + (= (maketerm (Cons @@ -221,6 +325,8 @@ (:: (const ])) $Rest) (maketerm $ElList $El 900) (maketerm $TailL $Tail 900))) +; + (= (maketerm @@ -230,6 +336,8 @@ (:: (const ))) $L) (set-det) (maketerm $L1 $Term))) +; + (= (maketerm (Cons @@ -237,9 +345,13 @@ (:: $T2) $_) ( (ap $L (:: (const ])) $R) (maketerm $L $T2 900))) +; + (= (maketerm ( (const [) (const ])) () $_) True) +; + (= @@ -249,24 +361,34 @@ (- $P 1)) (is $P2 (- $P 1)))) +; + (= (newprec xfy $P $P1 $P2) ( (set-det) (is $P1 (- $P 1)) (= $P2 $P))) +; + (= (newprec yfx $P $P1 $P2) ( (set-det) (is $P2 (- $P 1)) (= $P1 $P))) +; + (= (newprec fx $P $P1) ( (set-det) (is $P1 (- $P 1)))) +; + (= (newprec fy $P $P) True) +; + (= @@ -276,6 +398,8 @@ (maketerm $I $T 900) (= $Out (:: $T)))) +; + (= (getargs $In $Out) ( (ap $I @@ -285,18 +409,26 @@ (= $Out (Cons $T $RT)) (getargs $RI $RT))) +; + (= (maketerm $X $Y) (maketerm $X $Y 1200)) +; + (= (ap () $L $L) True) +; + (= (ap (Cons $X $L1) $L2 (Cons $X $L3)) (ap $L1 $L2 $L3)) +; + diff --git a/sxx_machine/sxx_system.metta b/sxx_machine/sxx_system.metta index dbcaade..39b4899 100644 --- a/sxx_machine/sxx_system.metta +++ b/sxx_machine/sxx_system.metta @@ -1,788 +1,1280 @@ - !(op 1150 fx package) + !(op 1150 fx package) +; + (= (package $X) - (nb-setval package $X)) + (nb-setval package $X)) +; + - !(package com.googlecode.prolog-cafe.builtin) - !(public (/ system-predicate 1)) - !(multifile (/ system-predicate 1)) - !(dynamic (/ system-predicate 1)) + !(package com.googlecode.prolog-cafe.builtin) +; + + !(public (/ system-predicate 1)) +; + + !(multifile (/ system-predicate 1)) +; + + !(dynamic (/ system-predicate 1)) +; + (= (system_predicate - (system_predicate $_)) True) + (system_predicate $_)) True) +; + ; -; Control constructs +; (= - (system_predicate true) True) + (system_predicate true) True) +; + (= - (system_predicate therwise) True) + (system_predicate therwise) True) +; + (= - (system_predicate fail) True) + (system_predicate fail) True) +; + (= - (system_predicate false) True) + (system_predicate false) True) +; + (= - (system_predicate !) True) + (system_predicate !) True) +; + (= (system_predicate - ($get_level $_)) True) + (%get_level $_)) True) +; + (= - (system_predicate $neck_cut) True) + (system_predicate $neck_cut) True) +; + (= (system_predicate - ($cut $_)) True) + ($cut $_)) True) +; + (= (system_predicate - (^ $_ $_)) True) + (^ $_ $_)) True) +; + (= (system_predicate - (, $_ $_)) True) + (, $_ $_)) True) +; + (= (system_predicate - (; $_ $_)) True) + (; $_ $_)) True) +; + (= (system_predicate - (-> $_ $_)) True) + (-> $_ $_)) True) +; + (= (system_predicate - (call $_)) True) + (call $_)) True) +; + (= (system_predicate - (catch $_ $_ $_)) True) + (catch $_ $_ $_)) True) +; + (= (system_predicate - (throw $_)) True) + (throw $_)) True) +; + (= (system_predicate - (on_exception $_ $_ $_)) True) + (on_exception $_ $_ $_)) True) +; + (= (system_predicate - (raise_exception $_)) True) + (raise_exception $_)) True) +; + ; -; Term unification +; (= (system_predicate - (= $_ $_)) True) + (= $_ $_)) True) +; + (= (system_predicate - ($unify $_ $_)) True) + ($unify $_ $_)) True) +; + (= (system_predicate - (\= $_ $_)) True) + (\= $_ $_)) True) +; + (= (system_predicate - ($not_unifiable $_ $_)) True) + (%not_unifiable $_ $_)) True) +; + ; -; Type testing +; (= (system_predicate - (var $_)) True) + (var $_)) True) +; + (= (system_predicate - (atom $_)) True) + (is-symbol $_)) True) +; + (= (system_predicate - (integer $_)) True) + (integer $_)) True) +; + (= (system_predicate - (long $_)) True) + (long $_)) True) +; + (= (system_predicate - (float $_)) True) + (float $_)) True) +; + (= (system_predicate - (atomic $_)) True) + (atomic $_)) True) +; + (= (system_predicate - (compound $_)) True) + (compound $_)) True) +; + (= (system_predicate - (nonvar $_)) True) + (nonvar $_)) True) +; + (= (system_predicate - (number $_)) True) + (number $_)) True) +; + (= (system_predicate - (java $_)) True) + (java $_)) True) +; + (= (system_predicate - (java $_ $_)) True) + (java $_ $_)) True) +; + (= (system_predicate - (closure $_)) True) + (closure $_)) True) +; + (= (system_predicate - (ground $_)) True) + (ground $_)) True) +; + (= (system_predicate - (callable $_)) True) + (callable $_)) True) +; + ; -; Term comparison +; (= (system_predicate - (== $_ $_)) True) + (== $_ $_)) True) +; + (= (system_predicate - ($equality_of_term $_ $_)) True) + (%equality_of_term $_ $_)) True) +; + (= (system_predicate - (\== $_ $_)) True) + (\== $_ $_)) True) +; + (= (system_predicate - ($inequality_of_term $_ $_)) True) + (%inequality_of_term $_ $_)) True) +; + (= (system_predicate - (@< $_ $_)) True) + (@< $_ $_)) True) +; + (= (system_predicate - ($before $_ $_)) True) + ($before $_ $_)) True) +; + (= (system_predicate - (@> $_ $_)) True) + (@> $_ $_)) True) +; + (= (system_predicate - ($after $_ $_)) True) + ($after $_ $_)) True) +; + (= (system_predicate - (@=< $_ $_)) True) + (@=< $_ $_)) True) +; + (= (system_predicate - ($not_after $_ $_)) True) + (%not_after $_ $_)) True) +; + (= (system_predicate - (@>= $_ $_)) True) + (@>= $_ $_)) True) +; + (= (system_predicate - ($not_before $_ $_)) True) + (%not_before $_ $_)) True) +; + (= (system_predicate - (?= $_ $_)) True) + (?= $_ $_)) True) +; + (= (system_predicate - ($identical_or_cannot_unify $_ $_)) True) + (%identical_or_cannot_unify $_ $_)) True) +; + (= (system_predicate - (compare $_ $_ $_)) True) + (compare $_ $_ $_)) True) +; + (= (system_predicate - (sort $_ $_)) True) + (sort $_ $_)) True) +; + (= (system_predicate - (keysort $_ $_)) True) + (keysort $_ $_)) True) +; + ; -; system_predicate(merge(_,_,_)). +; ; -; Term creation and decomposition +; (= (system_predicate - (arg $_ $_ $_)) True) + (arg $_ $_ $_)) True) +; + (= (system_predicate - (functor $_ $_ $_)) True) + (functor $_ $_ $_)) True) +; + (= (system_predicate - (=.. $_ $_)) True) + (=.. $_ $_)) True) +; + (= (system_predicate - ($univ $_ $_)) True) + ($univ $_ $_)) True) +; + (= (system_predicate - (copy_term $_ $_)) True) + (copy_term $_ $_)) True) +; + ; -; Arithmetic evaluation +; (= (system_predicate - (is $_ $_)) True) + (is $_ $_)) True) +; + (= (system_predicate - ($abs $_ $_)) True) + ($abs $_ $_)) True) +; + (= (system_predicate - ($asin $_ $_)) True) + ($asin $_ $_)) True) +; + (= (system_predicate - ($acos $_ $_)) True) + ($acos $_ $_)) True) +; + (= (system_predicate - ($atan $_ $_)) True) + ($atan $_ $_)) True) +; + (= (system_predicate - ($bitwise_conj $_ $_ $_)) True) + (%bitwise_conj $_ $_ $_)) True) +; + (= (system_predicate - ($bitwise_disj $_ $_ $_)) True) + (%bitwise_disj $_ $_ $_)) True) +; + (= (system_predicate - ($bitwise_exclusive_or $_ $_ $_)) True) + (%bitwise_exclusive_or $_ $_ $_)) True) +; + (= (system_predicate - ($bitwise_neg $_ $_)) True) + (%bitwise_neg $_ $_)) True) +; + (= (system_predicate - ($ceil $_ $_)) True) + ($ceil $_ $_)) True) +; + (= (system_predicate - ($cos $_ $_)) True) + ($cos $_ $_)) True) +; + (= (system_predicate - ($degrees $_ $_)) True) + ($degrees $_ $_)) True) +; + (= (system_predicate - ($exp $_ $_)) True) + ($exp $_ $_)) True) +; + (= (system_predicate - ($float $_ $_)) True) + ($float $_ $_)) True) +; + (= (system_predicate - ($float_integer_part $_ $_)) True) + (%float_integer_part $_ $_)) True) +; + (= (system_predicate - ($float_fractional_part $_ $_)) True) + (%float_fractional_part $_ $_)) True) +; + (= (system_predicate - ($float_quotient $_ $_ $_)) True) + (%float_quotient $_ $_ $_)) True) +; + (= (system_predicate - ($floor $_ $_)) True) + ($floor $_ $_)) True) +; + (= (system_predicate - ($int_quotient $_ $_ $_)) True) + (%int_quotient $_ $_ $_)) True) +; + (= (system_predicate - ($log $_ $_)) True) + ($log $_ $_)) True) +; + (= (system_predicate - ($max $_ $_ $_)) True) + ($max $_ $_ $_)) True) +; + (= (system_predicate - ($min $_ $_ $_)) True) + ($min $_ $_ $_)) True) +; + (= (system_predicate - ($minus $_ $_ $_)) True) + ($minus $_ $_ $_)) True) +; + (= (system_predicate - ($mod $_ $_ $_)) True) + ($mod $_ $_ $_)) True) +; + (= (system_predicate - ($multi $_ $_ $_)) True) + ($multi $_ $_ $_)) True) +; + (= (system_predicate - ($plus $_ $_ $_)) True) + ($plus $_ $_ $_)) True) +; + (= (system_predicate - ($pow $_ $_ $_)) True) + ($pow $_ $_ $_)) True) +; + (= (system_predicate - ($radians $_ $_)) True) + ($radians $_ $_)) True) +; + (= (system_predicate - ($rint $_ $_)) True) + ($rint $_ $_)) True) +; + (= (system_predicate - ($round $_ $_)) True) + ($round $_ $_)) True) +; + (= (system_predicate - ($shift_left $_ $_ $_)) True) + (%shift_left $_ $_ $_)) True) +; + (= (system_predicate - ($shift_right $_ $_ $_)) True) + (%shift_right $_ $_ $_)) True) +; + (= (system_predicate - ($sign $_ $_)) True) + ($sign $_ $_)) True) +; + (= (system_predicate - ($sin $_ $_)) True) + ($sin $_ $_)) True) +; + (= (system_predicate - ($sqrt $_ $_)) True) + ($sqrt $_ $_)) True) +; + (= (system_predicate - ($tan $_ $_)) True) + ($tan $_ $_)) True) +; + (= (system_predicate - ($truncate $_ $_)) True) + ($truncate $_ $_)) True) +; + ; -; Arithmetic comparison +; (= (system_predicate - (=:= $_ $_)) True) + (=:= $_ $_)) True) +; + (= (system_predicate - ($arith_equal $_ $_)) True) + (%arith_equal $_ $_)) True) +; + (= (system_predicate - (=\= $_ $_)) True) + (=\= $_ $_)) True) +; + (= (system_predicate - ($arith_not_equal $_ $_)) True) + (%arith_not_equal $_ $_)) True) +; + (= (system_predicate - (< $_ $_)) True) + (< $_ $_)) True) +; + (= (system_predicate - ($less_than $_ $_)) True) + (%less_than $_ $_)) True) +; + (= (system_predicate - (=< $_ $_)) True) + (=< $_ $_)) True) +; + (= (system_predicate - ($less_or_equal $_ $_)) True) + (%less_or_equal $_ $_)) True) +; + (= (system_predicate - (> $_ $_)) True) + (> $_ $_)) True) +; + (= (system_predicate - ($greater_than $_ $_)) True) + (%greater_than $_ $_)) True) +; + (= (system_predicate - (>= $_ $_)) True) + (>= $_ $_)) True) +; + (= (system_predicate - ($greater_or_equal $_ $_)) True) + (%greater_or_equal $_ $_)) True) +; + ; -; Clause retrieval and information +; (= (system_predicate - (clause $_ $_)) True) + (clause $_ $_)) True) +; + (= (system_predicate - (initialization $_ $_)) True) + (initialization $_ $_)) True) +; + (= (system_predicate - ($new_indexing_hash $_ $_ $_)) True) + (%new_indexing_hash $_ $_ $_)) True) +; + ; -; Clause creation and destruction +; (= (system_predicate - (assert $_)) True) + (assert $_)) True) +; + (= (system_predicate - (assertz $_)) True) + (assertz $_)) True) +; + (= (system_predicate - (asserta $_)) True) + (asserta $_)) True) +; + (= (system_predicate - (retract $_)) True) + (retract $_)) True) +; + (= (system_predicate - (abolish $_)) True) + (abolish $_)) True) +; + (= (system_predicate - (retractall $_)) True) + (retractall $_)) True) +; + ; -; All solutions +; (= (system_predicate - (findall $_ $_ $_)) True) + (findall $_ $_ $_)) True) +; + (= (system_predicate - (bagof $_ $_ $_)) True) + (bagof $_ $_ $_)) True) +; + (= (system_predicate - (setof $_ $_ $_)) True) + (setof $_ $_ $_)) True) +; + ; -; Stream selection and control +; (= (system_predicate - (current_input $_)) True) + (current_input $_)) True) +; + (= (system_predicate - (current_output $_)) True) + (current_output $_)) True) +; + (= (system_predicate - (set_input $_)) True) + (set_input $_)) True) +; + (= (system_predicate - (set_output $_)) True) + (set_output $_)) True) +; + (= (system_predicate - (open $_ $_ $_)) True) + (open $_ $_ $_)) True) +; + (= (system_predicate - (open $_ $_ $_ $_)) True) + (open $_ $_ $_ $_)) True) +; + (= (system_predicate - (close $_)) True) + (close $_)) True) +; + (= (system_predicate - (close $_ $_)) True) + (close $_ $_)) True) +; + (= (system_predicate - (flush_output $_)) True) + (flush_output $_)) True) +; + (= - (system_predicate flush_output) True) + (system_predicate flush_output) True) +; + (= (system_predicate - (stream_property $_ $_)) True) + (stream_property $_ $_)) True) +; + ; -; Character input/output +; (= (system_predicate - (get_char $_)) True) + (get_char $_)) True) +; + (= (system_predicate - (get_char $_ $_)) True) + (get_char $_ $_)) True) +; + (= (system_predicate - (get_code $_)) True) + (get_code $_)) True) +; + (= (system_predicate - (get_code $_ $_)) True) + (get_code $_ $_)) True) +; + (= (system_predicate - (peek_char $_)) True) + (peek_char $_)) True) +; + (= (system_predicate - (peek_char $_ $_)) True) + (peek_char $_ $_)) True) +; + (= (system_predicate - (peek_code $_)) True) + (peek_code $_)) True) +; + (= (system_predicate - (peek_code $_ $_)) True) + (peek_code $_ $_)) True) +; + (= (system_predicate - (put_char $_)) True) + (put_char $_)) True) +; + (= (system_predicate - (put_char $_ $_)) True) + (put_char $_ $_)) True) +; + (= (system_predicate - (put_code $_)) True) + (put_code $_)) True) +; + (= (system_predicate - (put_code $_ $_)) True) + (put_code $_ $_)) True) +; + (= - (system_predicate nl) True) + (system_predicate nl) True) +; + (= (system_predicate - (nl $_)) True) + (nl $_)) True) +; + (= (system_predicate - (get0 $_)) True) + (get0 $_)) True) +; + (= (system_predicate - (get0 $_ $_)) True) + (get0 $_ $_)) True) +; + (= (system_predicate - (get $_)) True) + (get $_)) True) +; + (= (system_predicate - (get $_ $_)) True) + (get $_ $_)) True) +; + (= (system_predicate - (put $_)) True) + (put $_)) True) +; + (= (system_predicate - (put $_ $_)) True) + (put $_ $_)) True) +; + (= (system_predicate - (tab $_)) True) + (tab $_)) True) +; + (= (system_predicate - (tab $_ $_)) True) + (tab $_ $_)) True) +; + (= (system_predicate - (skip $_)) True) + (skip $_)) True) +; + (= (system_predicate - (skip $_ $_)) True) + (skip $_ $_)) True) +; + ; -; Byte input/output +; (= (system_predicate - (get_byte $_)) True) + (get_byte $_)) True) +; + (= (system_predicate - (get_byte $_ $_)) True) + (get_byte $_ $_)) True) +; + (= (system_predicate - (peek_byte $_)) True) + (peek_byte $_)) True) +; + (= (system_predicate - (peek_byte $_ $_)) True) + (peek_byte $_ $_)) True) +; + (= (system_predicate - (put_byte $_)) True) + (put_byte $_)) True) +; + (= (system_predicate - (put_byte $_ $_)) True) + (put_byte $_ $_)) True) +; + ; -; Term input/output +; (= (system_predicate - (read $_)) True) + (read $_)) True) +; + (= (system_predicate - (read $_ $_)) True) + (read $_ $_)) True) +; + (= (system_predicate - (read_with_variables $_ $_)) True) + (read_with_variables $_ $_)) True) +; + (= (system_predicate - (read_with_variables $_ $_ $_)) True) + (read_with_variables $_ $_ $_)) True) +; + (= (system_predicate - (read_line $_)) True) + (read_line $_)) True) +; + (= (system_predicate - (read_line $_ $_)) True) + (read_line $_ $_)) True) +; + (= (system_predicate - (write $_)) True) + (write $_)) True) +; + (= (system_predicate - (write $_ $_)) True) + (write $_ $_)) True) +; + (= (system_predicate - (writeq $_)) True) + (writeq $_)) True) +; + (= (system_predicate - (writeq $_ $_)) True) + (writeq $_ $_)) True) +; + (= (system_predicate - (write_canonical $_)) True) + (write_canonical $_)) True) +; + (= (system_predicate - (write_canonical $_ $_)) True) + (write_canonical $_ $_)) True) +; + (= (system_predicate - (write_term $_ $_)) True) + (write_term $_ $_)) True) +; + (= (system_predicate - (write_term $_ $_ $_)) True) + (write_term $_ $_ $_)) True) +; + (= (system_predicate - (op $_ $_ $_)) True) + (op $_ $_ $_)) True) +; + (= (system_predicate - (current_op $_ $_ $_)) True) + (current_op $_ $_ $_)) True) +; + ; -; Logic and control +; (= (system_predicate - (\+ $_)) True) + (\+ $_)) True) +; + (= (system_predicate - (once $_)) True) + (once $_)) True) +; + (= - (system_predicate repeat) True) + (system_predicate repeat) True) +; + ; -; Atomic term processing +; (= (system_predicate - (atom_length $_ $_)) True) + (symbol_length $_ $_)) True) +; + (= (system_predicate - (atom_concat $_ $_ $_)) True) + (symbol_concat $_ $_ $_)) True) +; + (= (system_predicate - (sub_atom $_ $_ $_ $_ $_)) True) + (sub_symbol $_ $_ $_ $_ $_)) True) +; + (= (system_predicate - (atom_chars $_ $_)) True) + (symbol_chars $_ $_)) True) +; + (= (system_predicate - (atom_codes $_ $_)) True) + (symbol_codes $_ $_)) True) +; + (= (system_predicate - (char_code $_ $_)) True) + (char_code $_ $_)) True) +; + (= (system_predicate - (number_chars $_ $_)) True) + (number_chars $_ $_)) True) +; + (= (system_predicate - (number_codes $_ $_)) True) + (number_codes $_ $_)) True) +; + (= (system_predicate - (name $_ $_)) True) + (name $_ $_)) True) +; + ; -; Implementation defined hooks +; (= (system_predicate - (set_prolog_flag $_ $_)) True) + (set_prolog_flag $_ $_)) True) +; + (= (system_predicate - (current_prolog_flag $_ $_)) True) + (current_prolog_flag $_ $_)) True) +; + (= - (system_predicate halt) True) + (system_predicate halt) True) +; + (= (system_predicate - (halt $_)) True) + (halt $_)) True) +; + (= - (system_predicate abort) True) + (system_predicate abort) True) +; + ; -; DCG +; (= (system_predicate - (C $_ $_ $_)) True) + (C $_ $_ $_)) True) +; + (= (system_predicate - (expand_term $_ $_)) True) + (expand_term $_ $_)) True) +; + ; -; Hash creation and control +; (= (system_predicate - (new_hash $_)) True) + (new_hash $_)) True) +; + (= (system_predicate - (new_hash $_ $_)) True) + (new_hash $_ $_)) True) +; + (= (system_predicate - (hash_clear $_)) True) + (hash_clear $_)) True) +; + (= (system_predicate - (hash_contains_key $_ $_)) True) + (hash_contains_key $_ $_)) True) +; + (= (system_predicate - (hash_get $_ $_ $_)) True) + (hash_get $_ $_ $_)) True) +; + (= (system_predicate - (hash_is_empty $_)) True) + (hash_is_empty $_)) True) +; + (= (system_predicate - (hash_keys $_ $_)) True) + (hash_keys $_ $_)) True) +; + (= (system_predicate - (hash_map $_ $_)) True) + (hash_map $_ $_)) True) +; + (= (system_predicate - (hash_put $_ $_ $_)) True) + (hash_put $_ $_ $_)) True) +; + (= (system_predicate - (hash_remove $_ $_)) True) + (hash_remove $_ $_)) True) +; + (= (system_predicate - (hash_size $_ $_)) True) + (hash_size $_ $_)) True) +; + (= (system_predicate - ($get_hash_manager $_)) True) + (%get_hash_manager $_)) True) +; + ; -; Java interoperation +; (= (system_predicate - (java_constructor0 $_ $_)) True) + (java_constructor0 $_ $_)) True) +; + (= (system_predicate - (java_constructor $_ $_)) True) + (java_constructor $_ $_)) True) +; + (= (system_predicate - (java_declared_constructor0 $_ $_)) True) + (java_declared_constructor0 $_ $_)) True) +; + (= (system_predicate - (java_declared_constructor $_ $_)) True) + (java_declared_constructor $_ $_)) True) +; + (= (system_predicate - (java_method0 $_ $_ $_)) True) + (java_method0 $_ $_ $_)) True) +; + (= (system_predicate - (java_method $_ $_ $_)) True) + (java_method $_ $_ $_)) True) +; + (= (system_predicate - (java_declared_method0 $_ $_ $_)) True) + (java_declared_method0 $_ $_ $_)) True) +; + (= (system_predicate - (java_declared_method $_ $_ $_)) True) + (java_declared_method $_ $_ $_)) True) +; + (= (system_predicate - (java_get_field0 $_ $_ $_)) True) + (java_get_field0 $_ $_ $_)) True) +; + (= (system_predicate - (java_get_field $_ $_ $_)) True) + (java_get_field $_ $_ $_)) True) +; + (= (system_predicate - (java_get_declared_field0 $_ $_ $_)) True) + (java_get_declared_field0 $_ $_ $_)) True) +; + (= (system_predicate - (java_get_declared_field $_ $_ $_)) True) + (java_get_declared_field $_ $_ $_)) True) +; + (= (system_predicate - (java_set_field0 $_ $_ $_)) True) + (java_set_field0 $_ $_ $_)) True) +; + (= (system_predicate - (java_set_field $_ $_ $_)) True) + (java_set_field $_ $_ $_)) True) +; + (= (system_predicate - (java_set_declared_field0 $_ $_ $_)) True) + (java_set_declared_field0 $_ $_ $_)) True) +; + (= (system_predicate - (java_set_declared_field $_ $_ $_)) True) + (java_set_declared_field $_ $_ $_)) True) +; + (= (system_predicate - (synchronized $_ $_)) True) + (synchronized $_ $_)) True) +; + (= (system_predicate - (java_conversion $_ $_)) True) + (java_conversion $_ $_)) True) +; + ; -; MeTTa interpreter +; (= - (system_predicate cafeteria) True) + (system_predicate cafeteria) True) +; + (= (system_predicate - (consult $_)) True) + (consult $_)) True) +; + (= - (system_predicate trace) True) + (system_predicate trace) True) +; + (= - (system_predicate notrace) True) + (system_predicate notrace) True) +; + (= - (system_predicate debug) True) + (system_predicate debug) True) +; + (= - (system_predicate nodebug) True) + (system_predicate nodebug) True) +; + (= (system_predicate - (leash $_)) True) + (leash $_)) True) +; + (= (system_predicate - (spy $_)) True) + (spy $_)) True) +; + (= (system_predicate - (nospy $_)) True) + (nospy $_)) True) +; + (= - (system_predicate nospyall) True) + (system_predicate nospyall) True) +; + (= - (system_predicate listing) True) + (system_predicate listing) True) +; + (= (system_predicate - (listing $_)) True) + (listing $_)) True) +; + ; -; Misc +; (= (system_predicate - (length $_ $_)) True) + (length $_ $_)) True) +; + (= (system_predicate - (numbervars $_ $_ $_)) True) + (numbervars $_ $_ $_)) True) +; + (= (system_predicate - (statistics $_ $_)) True) + (statistics $_ $_)) True) +; + ; -; END +; diff --git a/sxx_machine/tau_builtins.metta b/sxx_machine/tau_builtins.metta index 77938c2..67dca29 100644 --- a/sxx_machine/tau_builtins.metta +++ b/sxx_machine/tau_builtins.metta @@ -1,94 +1,86 @@ ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Builtin Predicates of MeTTa Cafe +; ; ; ; -; Mutsunori Banbara (banbara@kobe-u.ac.jp) +; ; -; Naoyuki Tamura (tamura@kobe-u.ac.jp) +; ; -; Kobe University +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(op 1150 fx package) + !(op 1150 fx package) +; + (= (package $X) - (nb-setval package $X)) + (nb-setval package $X)) +; + - !(package TauMachine.builtin-tau) + !(package TauMachine.builtin-tau) +; + ; -; :- public system_predicate/1. +; ; -; :- multifile(system_predicate/1). +; ; -; :- dynamic(system_predicate/1). +; !(public (/ undo 1)) -; /* -; system_predicate(nb_setarg(_,_,_)). -; system_predicate(setarg(_,_,_)). ; -; system_predicate(nb_get_attr(_,_,_)). -; system_predicate(nb_put_attr(_,_,_)). -; -; system_predicate(nb_get_attrs(_,_)). -; system_predicate(nb_put_attrs(_,_)). -; */ - -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; ; Control constructs -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - (= (undo $G) (undo (call $G))) -; /* -; '$builtin_meta_predicates'(undo, 1, [:]). -; '$builtin_meta_predicates'(undo1, 1, [:]). -; '$builtin_meta_predicates'(redo_each_call, 3, [:,:,:]). -; '$builtin_meta_predicates'(one_of_or_else, 3, [:,:,:]). -; */ - +; (= (undo1 $Term) - ( ($get-current-B $Cut) ($meta-call $Term user $Cut 0 interpret))) + ( ($get-current-B $Cut) ($meta-call $Term user $Cut 0 interpret))) +; + (= (redo-each-call $EachSetup $Call $EachCleanup) - (redo-each-call $EachSetup $Call $EachCleanup)) + (redo-each-call $EachSetup $Call $EachCleanup)) +; + (= (one-of-or-else $If $Then $Else) - (one-of-or-else $If $Then $Else)) + (one-of-or-else $If $Then $Else)) +; + ; -; END +; diff --git a/sxx_machine/tau_builtins_cafe.metta b/sxx_machine/tau_builtins_cafe.metta index 8fa4ca0..93f1926 100644 --- a/sxx_machine/tau_builtins_cafe.metta +++ b/sxx_machine/tau_builtins_cafe.metta @@ -1,106 +1,154 @@ ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Builtin Predicates of MeTTa Cafe +; ; ; ; -; Mutsunori Banbara (banbara@kobe-u.ac.jp) +; ; -; Naoyuki Tamura (tamura@kobe-u.ac.jp) +; ; -; Kobe University +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(op 1150 fx package) + !(op 1150 fx package) +; + (= - (package $_) True) + (package $_) True) +; + - !(package TauMachine.builtin) + !(package TauMachine.builtin) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Control constructs +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (, (/ True 0) (/ otherwise 0))) - !(public (, (/ fail 0) (/ False 0))) - !(public (/ (set-det) 0)) - !(public (/ ^ 2)) - !(public (/ , 2)) - !(public (/ or 2)) - !(public (/ -> 2)) - !(public (/ call 1)) + !(public (, (/ True 0) (/ otherwise 0))) +; + + !(public (, (/ fail 0) (/ False 0))) +; + + !(public (/ (set-det) 0)) +; + + !(public (/ ^ 2)) +; + + !(public (/ , 2)) +; + + !(public (/ or 2)) +; + + !(public (/ -> 2)) +; + + !(public (/ call 1)) +; + - (= true True) + (= true True) +; + - (= otherwise True) + (= otherwise True) +; + (= fail - (empty)) + (empty)) +; + (= false - (empty)) + (empty)) +; + - (= ! True) + (= ! True) +; + (= (^ $_ $G) - (call $G)) + (call $G)) +; + (= (, $P $Q) - ( (call $P) (call $Q))) + ( (call $P) (call $Q))) +; + (= (or $P $Q) ( (\= $P - (det-if-then $_ $_)) (call $P))) + (det-if-then $_ $_)) (call $P))) +; + (= (or $P $Q) ( (\= $Q - (det-if-then $_ $_)) (call $Q))) + (det-if-then $_ $_)) (call $Q))) +; + (= (det-if-then $IF $THEN) ( (call $IF) (set-det) - (call $THEN))) + (call $THEN))) +; + (= (det-if-then-else $IF $THEN $ELSE) ( (call $IF) (set-det) - (call $THEN))) + (call $THEN))) +; + (= (det-if-then-else $IF $THEN $ELSE) - (call $ELSE)) + (call $ELSE)) +; + (= (call $Term) - ( ($get-current-B $Cut) ($meta-call $Term user $Cut 0 interpret))) + ( ($get-current-B $Cut) ($meta-call $Term user $Cut 0 interpret))) +; + (= @@ -108,168 +156,246 @@ ( (var $X) (set-det) (illarg var - (call $X) 1))) + (call $X) 1))) +; + (= ($meta-call $X $_ $_ $_ $_) ( (closure $X) (set-det) - ($call-closure $X))) + ($call-closure $X))) +; + (= ($meta-call True $_ $_ $_ $_) - (set-det)) + (set-det)) +; + (= ($meta-call trace $_ $_ $_ $_) - ( (set-det) (trace))) + ( (set-det) (trace))) +; + (= ($meta-call debug $_ $_ $_ $_) - ( (set-det) (debug))) + ( (set-det) (debug))) +; + (= ($meta-call notrace $_ $_ $_ $_) - ( (set-det) (notrace))) + ( (set-det) (notrace))) +; + (= ($meta-call nodebug $_ $_ $_ $_) - ( (set-det) (nodebug))) + ( (set-det) (nodebug))) +; + (= ($meta-call (spy $L) $_ $_ $_ $_) - ( (set-det) (spy $L))) + ( (set-det) (spy $L))) +; + (= ($meta-call (nospy $L) $_ $_ $_ $_) - ( (set-det) (nospy $L))) + ( (set-det) (nospy $L))) +; + (= ($meta-call nospyall $_ $_ $_ $_) - ( (set-det) (nospyall))) + ( (set-det) (nospyall))) +; + (= ($meta-call (leash $L) $_ $_ $_ $_) - ( (set-det) (leash $L))) + ( (set-det) (leash $L))) +; + (= ($meta-call (Cons $X $Xs) $_ $_ $_ $_) - ( (set-det) (consult (Cons $X $Xs)))) + ( (set-det) (consult (Cons $X $Xs)))) +; + (= ($meta-call (^ $_ $X) $P $Cut $Depth $Mode) - ( (set-det) ($meta-call $X $P $Cut $Depth $Mode))) + ( (set-det) ($meta-call $X $P $Cut $Depth $Mode))) +; + (= ($meta-call (with_self $P $X) $_ $Cut $Depth $Mode) - ( (set-det) ($meta-call $X $P $Cut $Depth $Mode))) + ( (set-det) ($meta-call $X $P $Cut $Depth $Mode))) +; + (= ($meta-call (set-det) $_ no $_ $_) - ( (set-det) (illarg (context if cut) (set-det) 0))) + ( (set-det) (illarg (context if cut) (set-det) 0))) +; + (= ($meta-call (set-det) $_ $Cut $_ $_) - ( (set-det) ($cut $Cut))) + ( (set-det) ($cut $Cut))) +; + (= ($meta-call (, $X $Y) $P $Cut $Depth $Mode) ( (set-det) ($meta-call $X $P $Cut $Depth $Mode) - ($meta-call $Y $P $Cut $Depth $Mode))) + ($meta-call $Y $P $Cut $Depth $Mode))) +; + (= ($meta-call (det-if-then-else $X $Y $Z) $P $Cut $Depth $Mode) - ( (set-det) (det-if-then-else ($meta-call $X $P no $Depth $Mode) ($meta-call $Y $P $Cut $Depth $Mode) ($meta-call $Z $P $Cut $Depth $Mode)))) + ( (set-det) (det-if-then-else ($meta-call $X $P no $Depth $Mode) ($meta-call $Y $P $Cut $Depth $Mode) ($meta-call $Z $P $Cut $Depth $Mode)))) +; + (= ($meta-call (det-if-then $X $Y) $P $Cut $Depth $Mode) - ( (set-det) (det-if-then ($meta-call $X $P no $Depth $Mode) ($meta-call $Y $P $Cut $Depth $Mode)))) + ( (set-det) (det-if-then ($meta-call $X $P no $Depth $Mode) ($meta-call $Y $P $Cut $Depth $Mode)))) +; + (= ($meta-call (or $X $Y) $P $Cut $Depth $Mode) - ( (set-det) (or ($meta-call $X $P $Cut $Depth $Mode) ($meta-call $Y $P $Cut $Depth $Mode)))) + ( (set-det) (or ($meta-call $X $P $Cut $Depth $Mode) ($meta-call $Y $P $Cut $Depth $Mode)))) +; + (= ($meta-call (not $X) $P $_ $Depth $Mode) - ( (set-det) (not ($meta-call $X $P no $Depth $Mode)))) + ( (set-det) (not ($meta-call $X $P no $Depth $Mode)))) +; + (= ($meta-call (findall $X $Y $Z) $P $Cut $Depth $Mode) - ( (set-det) (findall $X ($meta-call $Y $P $Cut $Depth $Mode) $Z))) + ( (set-det) (findall $X ($meta-call $Y $P $Cut $Depth $Mode) $Z))) +; + (= ($meta-call (bagof $X $Y $Z) $P $Cut $Depth $Mode) - ( (set-det) (bagof $X ($meta-call $Y $P $Cut $Depth $Mode) $Z))) + ( (set-det) (bagof $X ($meta-call $Y $P $Cut $Depth $Mode) $Z))) +; + (= ($meta-call (setof $X $Y $Z) $P $Cut $Depth $Mode) - ( (set-det) (setof $X ($meta-call $Y $P $Cut $Depth $Mode) $Z))) + ( (set-det) (setof $X ($meta-call $Y $P $Cut $Depth $Mode) $Z))) +; + (= ($meta-call (once $X) $P $Cut $Depth $Mode) - ( (set-det) (once ($meta-call $X $P $Cut $Depth $Mode)))) + ( (set-det) (once ($meta-call $X $P $Cut $Depth $Mode)))) +; + (= ($meta-call (on-exception $X $Y $Z) $P $Cut $Depth $Mode) - ( (set-det) (on-exception $X ($meta-call $Y $P $Cut $Depth $Mode) ($meta-call $Z $P $Cut $Depth $Mode)))) + ( (set-det) (on-exception $X ($meta-call $Y $P $Cut $Depth $Mode) ($meta-call $Z $P $Cut $Depth $Mode)))) +; + (= ($meta-call (catch $X $Y $Z) $P $Cut $Depth $Mode) - ( (set-det) (catch ($meta-call $X $P $Cut $Depth $Mode) $Y ($meta-call $Z $P $Cut $Depth $Mode)))) + ( (set-det) (catch ($meta-call $X $P $Cut $Depth $Mode) $Y ($meta-call $Z $P $Cut $Depth $Mode)))) +; + ; -; '$meta_call'(freeze(X,Y), P, Cut, Depth, Mode) :- !, ??? +; ; -; freeze(X, '$meta_call'(Y, P, Cut, Depth, Mode)). +; (= ($meta-call (synchronized $X $Y) $P $Cut $Depth $Mode) - ( (set-det) (synchronized $X ($meta-call $Y $P $Cut $Depth $Mode)))) + ( (set-det) (synchronized $X ($meta-call $Y $P $Cut $Depth $Mode)))) +; + (= ($meta-call - (get-atoms &self + (get-symbols &self (= $X $Y)) $P $_ $_ $_) - ( (set-det) (get-atoms &self (= (: $P $X) $Y)))) + ( (set-det) (get-symbols &self (= (: $P $X) $Y)))) +; + (= ($meta-call - (add-atom &self $X) $P $_ $_ $_) - ( (set-det) (add-atom &self (: $P $X)))) + (add-symbol &self $X) $P $_ $_ $_) + ( (set-det) (add-symbol &self (: $P $X)))) +; + (= ($meta-call - (add-atom &self $X) $P $_ $_ $_) - ( (set-det) (add-atom &self (: $P $X)))) + (add-symbol &self $X) $P $_ $_ $_) + ( (set-det) (add-symbol &self (: $P $X)))) +; + (= ($meta-call - (add-atom &self $X) $P $_ $_ $_) - ( (set-det) (add-atom &self (: $P $X)))) + (add-symbol &self $X) $P $_ $_ $_) + ( (set-det) (add-symbol &self (: $P $X)))) +; + (= ($meta-call - (remove-atom &self $X) $P $_ $_ $_) - ( (set-det) (remove-atom &self (: $P $X)))) + (remove-symbol &self $X) $P $_ $_ $_) + ( (set-det) (remove-symbol &self (: $P $X)))) +; + (= ($meta-call (abolish $X) $P $_ $_ $_) - ( (set-det) (abolish (with_self $P $X)))) + ( (set-det) (abolish (with_self $P $X)))) +; + (= ($meta-call - (remove-all-atoms &self $X) $P $_ $_ $_) - ( (set-det) (remove-all-atoms &self (: $P $X)))) + (remove-all-symbols &self $X) $P $_ $_ $_) + ( (set-det) (remove-all-symbols &self (: $P $X)))) +; + (= ($meta-call $X $P $_ $Depth $Mode) ( (atom $P) (callable $X) (set-det) - ($meta-call $Mode $Depth $P $X))) + ($meta-call $Mode $Depth $P $X))) +; + (= ($meta-call $X $P $_ $_ $_) (illarg (type callable) - (call (with_self $P $X)) 1)) + (call (with_self $P $X)) 1)) +; + (= ($meta-call trace $Depth $P $X) ( (set-det) (functor $X $F $A) ($trace-goal $X $P - (/ $F $A) $Depth))) + (/ $F $A) $Depth))) +; + (= ($meta-call interpret $Depth $P $X) - ( (functor $X $F $A) ($call-internal $X $P (/ $F $A) $Depth interpret))) + ( (functor $X $F $A) ($call-internal $X $P (/ $F $A) $Depth interpret))) +; + (= @@ -280,40 +406,56 @@ ($get-current-B $Cut) (is $Depth1 (+ $Depth 1)) - (get-atoms &self + (get-symbols &self (= (: $P $X) $Body)) - ($meta-call $Body $P $Cut $Depth1 $Mode))) + ($meta-call $Body $P $Cut $Depth1 $Mode))) +; + (= ($call-internal $X $P $_ $_ $_) - ($call $P $X)) + ($call $P $X)) +; + - !(public (, (/ catch 3) (/ throw 1))) - !(public (/ on-exception 3)) + !(public (, (/ catch 3) (/ throw 1))) +; + + !(public (/ on-exception 3)) +; + (= (catch $Goal $Catch $Recovery) - (on-exception $Catch $Goal $Recovery)) + (on-exception $Catch $Goal $Recovery)) +; + (= (throw $Msg) - (raise-exception $Msg)) + (raise-exception $Msg)) +; + (= (on-exception $Catch $Goal $Recovery) ( (callable $Goal) (set-det) - ($on-exception $Catch $Goal $Recovery))) + ($on-exception $Catch $Goal $Recovery))) +; + (= (on-exception $Catch $Goal $Recovery) (illarg (type callable) - (on-exception $Catch $Goal $Recovery) 2)) + (on-exception $Catch $Goal $Recovery) 2)) +; + (= @@ -321,612 +463,889 @@ ( ($set-exception %none) ($begin-exception $L) (call $Goal) - ($end-exception $L))) + ($end-exception $L))) +; + (= ($on-exception $Catch $Goal $Recovery) ( ($get-exception $Msg) (\== $Msg %none) - ($catch-and-throw $Msg $Catch $Recovery))) + ($catch-and-throw $Msg $Catch $Recovery))) +; + (= ($catch-and-throw $Msg $Msg $Recovery) ( (set-det) ($set-exception %none) - (call $Recovery))) + (call $Recovery))) +; + (= ($catch-and-throw $Msg $_ $_) - (raise-exception $Msg)) + (raise-exception $Msg)) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Term unification +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (, (/ = 2) (/ %unify 2))) - !(public (, (/ \= 2) (/ %not-unifiable 2))) + !(public (, (/ = 2) (/ %unify 2))) +; + + !(public (, (/ \= 2) (/ %not-unifiable 2))) +; + (= (= $X $Y) - (= $X $Y)) + (= $X $Y)) +; + (= ($unify $X $Y) - ($unify $X $Y)) + ($unify $X $Y)) +; + (= (\= $X $Y) - (\= $X $Y)) + (\= $X $Y)) +; + (= ($not-unifiable $X $Y) - ($not-unifiable $X $Y)) + ($not-unifiable $X $Y)) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Type testing +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (, (/ var 1) (/ is-symbol 1) (/ integer 1) (/ long 1) (/ float 1) (/ symbolic 1) (/ compound 1) (/ nonvar 1) (/ number 1))) - !(public (, (/ java 1) (/ java 2) (/ closure 1))) - !(public (, (/ ground 1) (/ callable 1))) + !(public (, (/ var 1) (/ is-symbol 1) (/ integer 1) (/ long 1) (/ float 1) (/ symbolic 1) (/ compound 1) (/ nonvar 1) (/ number 1))) +; + + !(public (, (/ java 1) (/ java 2) (/ closure 1))) +; + + !(public (, (/ ground 1) (/ callable 1))) +; + (= (var $X) - (var $X)) + (var $X)) +; + (= (atom $X) - (atom $X)) + (atom $X)) +; + (= (integer $X) - (integer $X)) + (integer $X)) +; + (= (long $X) - (long $X)) + (long $X)) +; + (= (float $X) - (float $X)) + (float $X)) +; + (= (atomic $X) - (atomic $X)) + (atomic $X)) +; + (= (nonvar $X) - (nonvar $X)) + (nonvar $X)) +; + (= (number $X) - (number $X)) + (number $X)) +; + (= (java $X) - (java $X)) + (java $X)) +; + (= (java $X $Y) - (java $X $Y)) + (java $X $Y)) +; + (= (closure $X) - (closure $X)) + (closure $X)) +; + (= (ground $X) - (ground $X)) + (ground $X)) +; + (= (compound $X) ( (nonvar $X) (functor $X $_ $A) - (> $A 0))) + (> $A 0))) +; + (= (callable $X) - ( (atom $X) (set-det))) + ( (atom $X) (set-det))) +; + (= (callable $X) - ( (compound $X) (set-det))) + ( (compound $X) (set-det))) +; + (= (callable $X) - (closure $X)) + (closure $X)) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Term comparison +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (, (/ == 2) (/ %equality-of-term 2))) - !(public (, (/ \== 2) (/ %inequality-of-term 2))) - !(public (, (/ @< 2) (/ %before 2))) - !(public (, (/ @> 2) (/ %after 2))) - !(public (, (/ @=< 2) (/ %not-after 2))) - !(public (, (/ @>= 2) (/ %not-before 2))) - !(public (, (/ ?= 2) (/ %identical-or-cannot-unify 2))) - !(public (/ compare 3)) + !(public (, (/ == 2) (/ %equality-of-term 2))) +; + + !(public (, (/ \== 2) (/ %inequality-of-term 2))) +; + + !(public (, (/ @< 2) (/ %before 2))) +; + + !(public (, (/ @> 2) (/ %after 2))) +; + + !(public (, (/ @=< 2) (/ %not-after 2))) +; + + !(public (, (/ @>= 2) (/ %not-before 2))) +; + + !(public (, (/ ?= 2) (/ %identical-or-cannot-unify 2))) +; + + !(public (/ compare 3)) +; + ; -; :- public sort/2. witten in Java +; ; -; :- public keysort/2. witten in Java +; ; -; :- public merge/3. +; (= (== $X $Y) - (== $X $Y)) + (== $X $Y)) +; + (= ($equality-of-term $X $Y) - ($equality-of-term $X $Y)) + ($equality-of-term $X $Y)) +; + (= (\== $X $Y) - (\== $X $Y)) + (\== $X $Y)) +; + (= ($inequality-of-term $X $Y) - ($inequality-of-term $X $Y)) + ($inequality-of-term $X $Y)) +; + (= (@< $X $Y) - (@< $X $Y)) + (@< $X $Y)) +; + (= ($before $X $Y) - ($before $X $Y)) + ($before $X $Y)) +; + (= (@> $X $Y) - (@> $X $Y)) + (@> $X $Y)) +; + (= ($after $X $Y) - ($after $X $Y)) + ($after $X $Y)) +; + (= (@=< $X $Y) - (@=< $X $Y)) + (@=< $X $Y)) +; + (= ($not-after $X $Y) - ($not-after $X $Y)) + ($not-after $X $Y)) +; + (= (@>= $X $Y) - (@>= $X $Y)) + (@>= $X $Y)) +; + (= ($not-before $X $Y) - ($not-before $X $Y)) + ($not-before $X $Y)) +; + (= (?= $X $Y) - (?= $X $Y)) + (?= $X $Y)) +; + (= ($identical-or-cannot-unify $X $Y) - ($identical-or-cannot-unify $X $Y)) + ($identical-or-cannot-unify $X $Y)) +; + (= (compare $Op $X $Y) - ( ($compare0 $Op0 $X $Y) ($map-compare-op $Op0 $Op))) + ( ($compare0 $Op0 $X $Y) ($map-compare-op $Op0 $Op))) +; + (= ($map-compare-op $Op0 $Op) ( (=:= $Op0 0) (set-det) - (= $Op =))) + (= $Op =))) +; + (= ($map-compare-op $Op0 $Op) ( (< $Op0 0) (set-det) - (= $Op <))) + (= $Op <))) +; + (= ($map-compare-op $Op0 $Op) ( (> $Op0 0) (set-det) - (= $Op >))) + (= $Op >))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Term creation and decomposition +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; :- public arg/3. --> written in Java +; ; -; :- public functor/3. --> written in Java +; - !(public (/ =.. 2)) - !(public (/ copy-term 2)) + !(public (/ =.. 2)) +; + + !(public (/ copy-term 2)) +; + (= (=.. $Term $List) - (=.. $Term $List)) + (=.. $Term $List)) +; + (= (copy-term $X $Y) - (copy-term $X $Y)) + (copy-term $X $Y)) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Arithmetic evaluation +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (/ is 2)) - !(public (, (/ %abs 2) (/ %asin 2) (/ %acos 2) (/ %atan 2))) - !(public (, (/ %bitwise-conj 3) (/ %bitwise-disj 3) (/ %bitwise-exclusive-or 3) (/ %bitwise-neg 2))) - !(public (, (/ %ceil 2) (/ %cos 2))) - !(public (/ %degrees 2)) - !(public (/ %exp 2)) - !(public (, (/ %float 2) (/ %float-integer-part 2) (/ %float-fractional-part 2) (/ %float-quotient 3) (/ %floor 2))) - !(public (/ %int-quotient 3)) - !(public (/ %log 2)) - !(public (, (/ %max 3) (/ %min 3) (/ %minus 3) (/ %mod 3) (/ %multi 3))) - !(public (, (/ %plus 3) (/ %pow 3))) - !(public (, (/ %radians 2) (/ %rint 2) (/ %round 2))) - !(public (, (/ %shift-left 3) (/ %shift-right 3) (/ %sign 2) (/ %sin 2) (/ %sqrt 2))) - !(public (, (/ %tan 2) (/ %truncate 2))) + !(public (/ is 2)) +; + + !(public (, (/ %abs 2) (/ %asin 2) (/ %acos 2) (/ %atan 2))) +; + + !(public (, (/ %bitwise-conj 3) (/ %bitwise-disj 3) (/ %bitwise-exclusive-or 3) (/ %bitwise-neg 2))) +; + + !(public (, (/ %ceil 2) (/ %cos 2))) +; + + !(public (/ %degrees 2)) +; + + !(public (/ %exp 2)) +; + + !(public (, (/ %float 2) (/ %float-integer-part 2) (/ %float-fractional-part 2) (/ %float-quotient 3) (/ %floor 2))) +; + + !(public (/ %int-quotient 3)) +; + + !(public (/ %log 2)) +; + + !(public (, (/ %max 3) (/ %min 3) (/ %minus 3) (/ %mod 3) (/ %multi 3))) +; + + !(public (, (/ %plus 3) (/ %pow 3))) +; + + !(public (, (/ %radians 2) (/ %rint 2) (/ %round 2))) +; + + !(public (, (/ %shift-left 3) (/ %shift-right 3) (/ %sign 2) (/ %sin 2) (/ %sqrt 2))) +; + + !(public (, (/ %tan 2) (/ %truncate 2))) +; + (= (is $Z $Y) - (is $Z $Y)) + (is $Z $Y)) +; + (= ($abs $X $Y) - ($abs $X $Y)) + ($abs $X $Y)) +; + (= ($asin $X $Y) - ($asin $X $Y)) + ($asin $X $Y)) +; + (= ($acos $X $Y) - ($acos $X $Y)) + ($acos $X $Y)) +; + (= ($atan $X $Y) - ($atan $X $Y)) + ($atan $X $Y)) +; + (= ($bitwise-conj $X $Y $Z) - ($bitwise-conj $X $Y $Z)) + ($bitwise-conj $X $Y $Z)) +; + (= ($bitwise-disj $X $Y $Z) - ($bitwise-disj $X $Y $Z)) + ($bitwise-disj $X $Y $Z)) +; + (= ($bitwise-exclusive-or $X $Y $Z) - ($bitwise-exclusive-or $X $Y $Z)) + ($bitwise-exclusive-or $X $Y $Z)) +; + (= ($bitwise-neg $X $Y) - ($bitwise-neg $X $Y)) + ($bitwise-neg $X $Y)) +; + (= ($ceil $X $Y) - ($ceil $X $Y)) + ($ceil $X $Y)) +; + (= ($cos $X $Y) - ($cos $X $Y)) + ($cos $X $Y)) +; + (= ($degrees $X $Y) - ($degrees $X $Y)) + ($degrees $X $Y)) +; + (= ($exp $X $Y) - ($exp $X $Y)) + ($exp $X $Y)) +; + (= ($float $X $Y) - ($float $X $Y)) + ($float $X $Y)) +; + (= ($float-integer-part $X $Y) - ($float-integer-part $X $Y)) + ($float-integer-part $X $Y)) +; + (= ($float-fractional-part $X $Y) - ($float-fractional-part $X $Y)) + ($float-fractional-part $X $Y)) +; + (= ($float-quotient $X $Y $Z) - ($float-quotient $X $Y $Z)) + ($float-quotient $X $Y $Z)) +; + (= ($floor $X $Y) - ($floor $X $Y)) + ($floor $X $Y)) +; + (= ($int-quotient $X $Y $Z) - ($int-quotient $X $Y $Z)) + ($int-quotient $X $Y $Z)) +; + (= ($log $X $Y) - ($log $X $Y)) + ($log $X $Y)) +; + (= ($max $X $Y $Z) - ($max $X $Y $Z)) + ($max $X $Y $Z)) +; + (= ($min $X $Y $Z) - ($min $X $Y $Z)) + ($min $X $Y $Z)) +; + (= ($minus $X $Y $Z) - ($minus $X $Y $Z)) + ($minus $X $Y $Z)) +; + (= ($mod $X $Y $Z) - ($mod $X $Y $Z)) + ($mod $X $Y $Z)) +; + (= ($multi $X $Y $Z) - ($multi $X $Y $Z)) + ($multi $X $Y $Z)) +; + (= ($plus $X $Y $Z) - ($plus $X $Y $Z)) + ($plus $X $Y $Z)) +; + (= ($pow $X $Y $Z) - ($pow $X $Y $Z)) + ($pow $X $Y $Z)) +; + (= ($radians $X $Y) - ($radians $X $Y)) + ($radians $X $Y)) +; + (= ($rint $X $Y) - ($rint $X $Y)) + ($rint $X $Y)) +; + (= ($round $X $Y) - ($round $X $Y)) + ($round $X $Y)) +; + (= ($shift-left $X $Y $Z) - ($shift-left $X $Y $Z)) + ($shift-left $X $Y $Z)) +; + (= ($shift-right $X $Y $Z) - ($shift-right $X $Y $Z)) + ($shift-right $X $Y $Z)) +; + (= ($sign $X $Y) - ($sign $X $Y)) + ($sign $X $Y)) +; + (= ($sin $X $Y) - ($sin $X $Y)) + ($sin $X $Y)) +; + (= ($sqrt $X $Y) - ($sqrt $X $Y)) + ($sqrt $X $Y)) +; + (= ($tan $X $Y) - ($tan $X $Y)) + ($tan $X $Y)) +; + (= ($truncate $X $Y) - ($truncate $X $Y)) + ($truncate $X $Y)) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Arithmetic comparison +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (, (/ =:= 2) (/ %arith-equal 2))) - !(public (, (/ =\= 2) (/ %arith-not-equal 2))) - !(public (, (/ < 2) (/ %less-than 2))) - !(public (, (/ =< 2) (/ %less-or-equal 2))) - !(public (, (/ > 2) (/ %greater-than 2))) - !(public (, (/ >= 2) (/ %greater-or-equal 2))) + !(public (, (/ =:= 2) (/ %arith-equal 2))) +; + + !(public (, (/ =\= 2) (/ %arith-not-equal 2))) +; + + !(public (, (/ < 2) (/ %less-than 2))) +; + + !(public (, (/ =< 2) (/ %less-or-equal 2))) +; + + !(public (, (/ > 2) (/ %greater-than 2))) +; + + !(public (, (/ >= 2) (/ %greater-or-equal 2))) +; + (= (=:= $X $Y) - (=:= $X $Y)) + (=:= $X $Y)) +; + (= ($arith-equal $X $Y) - ($arith-equal $X $Y)) + ($arith-equal $X $Y)) +; + (= (=\= $X $Y) - (=\= $X $Y)) + (=\= $X $Y)) +; + (= ($arith-not-equal $X $Y) - ($arith-not-equal $X $Y)) + ($arith-not-equal $X $Y)) +; + (= (< $X $Y) - (< $X $Y)) + (< $X $Y)) +; + (= ($less-than $X $Y) - ($less-than $X $Y)) + ($less-than $X $Y)) +; + (= (=< $X $Y) - (=< $X $Y)) + (=< $X $Y)) +; + (= ($less-or-equal $X $Y) - ($less-or-equal $X $Y)) + ($less-or-equal $X $Y)) +; + (= (> $X $Y) - (> $X $Y)) + (> $X $Y)) +; + (= ($greater-than $X $Y) - ($greater-than $X $Y)) + ($greater-than $X $Y)) +; + (= (>= $X $Y) - (>= $X $Y)) + (>= $X $Y)) +; + (= ($greater-or-equal $X $Y) - ($greater-or-equal $X $Y)) + ($greater-or-equal $X $Y)) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Clause retrieval and information +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (/ clause 2)) - !(public (/ initialization 2)) - !(public (/ %new-indexing-hash 3)) + !(public (/ clause 2)) +; + + !(public (/ initialization 2)) +; + + !(public (/ %new-indexing-hash 3)) +; + (= - (get-atoms &self + (get-symbols &self (= $Head $B)) ( ($head-to-term $Head $H (with_self $P $PI) - (get-atoms &self + (get-symbols &self (= $Head $B))) ($new-internal-database $P) ($check-procedure-permission (with_self $P $PI) access private-procedure - (get-atoms &self + (get-symbols &self (= $Head $B))) ($clause-internal $P $PI $H $Cl $_) (copy-term $Cl (= $H $B)))) -; ;(ground(Cl) -> Cl = (H :- B) ; copy_term(Cl, (H :- B))). ??? - +; ; -; head --> term +; (= ($head-to-term $H $T (with_self $Pkg (/ $F $A)) $Goal) - ( ($head-to-term $H $T user $Pkg $Goal) (functor $T $F $A))) + ( ($head-to-term $H $T user $Pkg $Goal) (functor $T $F $A))) +; + (= ($head-to-term $H $_ $_ $_ $Goal) ( (var $H) (set-det) - (illarg var $Goal 1))) + (illarg var $Goal 1))) +; + (= ($head-to-term (with_self $P $H) $T $_ $Pkg $Goal) - ( (set-det) ($head-to-term $H $T $P $Pkg $Goal))) + ( (set-det) ($head-to-term $H $T $P $Pkg $Goal))) +; + (= ($head-to-term $H $H $Pkg $Pkg $_) ( (callable $H) (atom $Pkg) - (set-det))) + (set-det))) +; + (= ($head-to-term $_ $_ $_ $_ $Goal) (illarg - (type callable) $Goal 1)) + (type callable) $Goal 1)) +; + ; -; creates an internal database for A if no exists. +; (= ($new-internal-database $A) ( (atom $A) ($get-hash-manager $HM) - ($new-internal-database $HM $A))) + ($new-internal-database $HM $A))) +; + (= ($new-internal-database $HM $A) - ( (hash-contains-key $HM $A) (set-det))) + ( (hash-contains-key $HM $A) (set-det))) +; + (= ($new-internal-database $_ $A) ( (new-hash $_ - (:: (alias $A))) ($init-internal-database $A))) + (:: (alias $A))) ($init-internal-database $A))) +; + (= @@ -935,22 +1354,28 @@ (findall $_ (with_self $A (%init)) $_) - (set-det))) + (set-det))) +; + (= - ($init_internal_database $_) True) + (%init_internal_database $_) True) +; + ; -; checks if the internal database of A exists. +; (= ($defined-internal-database $A) ( (atom $A) ($get-hash-manager $HM) - (hash-contains-key $HM $A))) + (hash-contains-key $HM $A))) +; + ; -; repeatedly finds dynamic clauses. +; (= @@ -959,28 +1384,27 @@ ($get-indices $P $PI $H $RevRefs) ($get-instances $RevRefs $Cls_Refs) ($clause-internal0 $Cls_Refs $Cl $Ref))) -; ; ??? - -; ;length(Cls_Refs,N), - -; ;'$fast_write'([clause_internal,N,for,P,PI]),nl, - -; ; - +; (= - ($clause_internal0 () $_ $_) - (empty)) + (%clause_internal0 () $_ $_) + (empty)) +; + (= ($clause-internal0 (:: (, $Cl $Ref)) $Cl $Ref) - (set-det)) + (set-det)) +; + (= ($clause-internal0 $L $Cl $Ref) ($builtin-member - (, $Cl $Ref) $L)) + (, $Cl $Ref) $L)) +; + (= @@ -990,17 +1414,21 @@ (det-if-then-else (hash-contains-key $IH $Key) (hash-get $IH $Key $Refs) - (hash-get $IH var $Refs)))) + (hash-get $IH var $Refs)))) +; + ; -; finds the indexing hashtable for P:PI. creates it if no exist. +; (= ($new-indexing-hash $P $PI $IH) ( (hash-contains-key $P $PI) (set-det) - (hash-get $P $PI $IH))) + (hash-get $P $PI $IH))) +; + (= ($new-indexing-hash $P $PI $IH) ( (new-hash $IH) @@ -1008,40 +1436,56 @@ (hash-put $IH var Nil) (hash-put $IH lis Nil) (hash-put $IH str Nil) - (hash-put $P $PI $IH))) + (hash-put $P $PI $IH))) +; + (= ($calc-indexing-key $H all) - ( (atom $H) (set-det))) + ( (atom $H) (set-det))) +; + (= ($calc-indexing-key $H $Key) - ( (arg 1 $H $A1) ($calc-indexing-key0 $A1 $Key))) + ( (arg 1 $H $A1) ($calc-indexing-key0 $A1 $Key))) +; + (= ($calc-indexing-key0 $A1 all) - ( (var $A1) (set-det))) + ( (var $A1) (set-det))) +; + (= ($calc-indexing-key0 $A1 lis) ( (= $A1 - (Cons $_ $_)) (set-det))) + (Cons $_ $_)) (set-det))) +; + (= ($calc-indexing-key0 $A1 str) - ( (compound $A1) (set-det))) + ( (compound $A1) (set-det))) +; + (= ($calc-indexing-key0 $A1 $Key) ( (ground $A1) (set-det) - ($term-hash $A1 $Key))) + ($term-hash $A1 $Key))) +; + (= ($calc-indexing-key0 $A1 $Key) (illarg (type term) - ($calc-indexing-key0 $A1 $Key) 1)) + ($calc-indexing-key0 $A1 $Key) 1)) +; + ; -; checks the permission of predicate P:F/A. +; (= @@ -1049,7 +1493,9 @@ (with_self $P (/ $F $A)) $Operation $ObjType $Goal) ( (hash-contains-key $P - (/ $F $A)) (set-det))) + (/ $F $A)) (set-det))) +; + (= ($check-procedure-permission (with_self $P @@ -1059,83 +1505,107 @@ (illarg (permission $Operation $ObjType (with_self $P - (/ $F $A)) $_) $Goal $_))) + (/ $F $A)) $_) $Goal $_))) +; + (= - ($check_procedure_permission $_ $_ $_ $_) True) + (%check_procedure_permission $_ $_ $_ $_) True) +; + ; -; initialize internal databases of given packages. +; (= (initialization Nil $Goal) - ( (set-det) (once $Goal))) + ( (set-det) (once $Goal))) +; + (= (initialization (Cons $P $Ps) $Goal) - ( ($new-internal-database $P) (initialization $Ps $Goal))) + ( ($new-internal-database $P) (initialization $Ps $Goal))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Clause creation and destruction +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (/ assert 1)) - !(public (/ assertz 1)) - !(public (/ asserta 1)) - !(public (/ retract 1)) - !(public (/ abolish 1)) - !(public (/ retractall 1)) + !(public (/ assert 1)) +; + + !(public (/ assertz 1)) +; + + !(public (/ asserta 1)) +; + + !(public (/ retract 1)) +; + + !(public (/ abolish 1)) +; + + !(public (/ retractall 1)) +; + (= - (add-atom &self $T) - (add-atom &self $T)) + (add-symbol &self $T) + (add-symbol &self $T)) +; + (= - (add-atom &self $T) + (add-symbol &self $T) ( ($term-to-clause $T $Cl (with_self $P $PI) - (add-atom &self $T)) + (add-symbol &self $T)) ($new-internal-database $P) ($check-procedure-permission (with_self $P $PI) modify static-procedure - (add-atom &self $T)) + (add-symbol &self $T)) (copy-term $Cl $NewCl) ($insert $NewCl $Ref) ($update-indexing $P $PI $Cl $Ref z) (fail))) -; ;'$fast_write'([intert,NewCl,Ref]), nl, ;??? - +; (= - (assertz $_) True) + (assertz $_) True) +; + (= - (add-atom &self $T) + (add-symbol &self $T) ( ($term-to-clause $T $Cl (with_self $P $PI) - (add-atom &self $T)) + (add-symbol &self $T)) ($new-internal-database $P) ($check-procedure-permission (with_self $P $PI) modify static-procedure - (add-atom &self $T)) + (add-symbol &self $T)) (copy-term $Cl $NewCl) ($insert $NewCl $Ref) ($update-indexing $P $PI $Cl $Ref a) (fail))) -; ;'$fast_write'([insert,NewCl,Ref]), nl, ;??? - +; (= - (asserta $_) True) + (asserta $_) True) +; + (= @@ -1152,56 +1622,57 @@ ($erase-all $Refs) (hash-remove $P $PI) (fail))) -; ;'$fast_write'([erase_all,Refs]), nl, ;??? - +; (= - (abolish $_) True) + (abolish $_) True) +; + (= - (remove-atom &self $Cl) + (remove-symbol &self $Cl) ( ($clause-to-term $Cl $T (with_self $P $PI) - (remove-atom &self $Cl)) + (remove-symbol &self $Cl)) ($new-internal-database $P) ($check-procedure-permission (with_self $P $PI) access static-procedure - (remove-atom &self $Cl)) + (remove-symbol &self $Cl)) (= $T (= $H $_)) ($clause-internal $P $PI $H $Cl0 $Ref) (copy-term $Cl0 $T) ($erase $Ref) ($rehash-indexing $P $PI $Ref))) -; ;'$fast_write'([erase,Cl0,Ref]), nl, ;??? - +; (= - (remove-all-atoms &self $Head) + (remove-all-symbols &self $Head) ( ($head-to-term $Head $H (with_self $P $PI) - (remove-all-atoms &self $Head)) + (remove-all-symbols &self $Head)) ($new-internal-database $P) ($check-procedure-permission (with_self $P $PI) access static-procedure - (remove-all-atoms &self $Head)) + (remove-all-symbols &self $Head)) ($clause-internal $P $PI $H $Cl $Ref) (copy-term $Cl (= $H $_)) ($erase $Ref) ($rehash-indexing $P $PI $Ref) (fail))) -; ;'$fast_write'([erase,Cl,Ref]), nl, ;??? - +; (= - (retractall $_) True) + (retractall $_) True) +; + ; -; term --> clause (for assert) +; (= @@ -1211,56 +1682,78 @@ ( ($term-to-clause $Cl0 $Cl user $Pkg $Goal) (= $Cl (= $H $_)) - (functor $H $F $A))) + (functor $H $F $A))) +; + (= ($term-to-clause $Cl0 $_ $_ $_ $Goal) ( (var $Cl0) (set-det) - (illarg var $Goal 1))) + (illarg var $Goal 1))) +; + (= ($term-to-clause $_ $_ $Pkg0 $_ $Goal) ( (var $Pkg0) (set-det) - (illarg var $Goal 1))) + (illarg var $Goal 1))) +; + (= ($term-to-clause (with_self $P $Cl0) $Cl $_ $Pkg $Goal) - ( (set-det) ($term-to-clause $Cl0 $Cl $P $Pkg $Goal))) + ( (set-det) ($term-to-clause $Cl0 $Cl $P $Pkg $Goal))) +; + (= ($term-to-clause $_ $_ $Pkg0 $_ $Goal) ( (not (atom $Pkg0)) (set-det) (illarg - (type is-symbol) $Goal 1))) + (type is-symbol) $Goal 1))) +; + (= ($term-to-clause (= $H0 $B0) (= $H $B) $Pkg $Pkg $Goal) ( (set-det) ($term-to-head $H0 $H $Pkg $Goal) - ($term-to-body $B0 $B $Pkg $Goal))) + ($term-to-body $B0 $B $Pkg $Goal))) +; + (= ($term-to-clause $H0 (= $H True) $Pkg $Pkg $Goal) - ($term-to-head $H0 $H $Pkg $Goal)) + ($term-to-head $H0 $H $Pkg $Goal)) +; + (= ($term-to-head $H $H $_ $_) - ( (atom $H) (set-det))) + ( (atom $H) (set-det))) +; + (= ($term-to-head $H $H $_ $_) - ( (compound $H) (set-det))) + ( (compound $H) (set-det))) +; + (= ($term-to-head $_ $_ $_ $Goal) (illarg - (type callable) $Goal 1)) + (type callable) $Goal 1)) +; + (= ($term-to-body $B0 $B $Pkg $_) - ($localize-body $B0 $Pkg $B)) + ($localize-body $B0 $Pkg $B)) +; + (= @@ -1268,32 +1761,42 @@ ( (var $G) (set-det) ($localize-body - (call $G) $P $G1))) + (call $G) $P $G1))) +; + (= ($localize-body (with_self $P $G) $_ $G1) - ( (set-det) ($localize-body $G $P $G1))) + ( (set-det) ($localize-body $G $P $G1))) +; + (= ($localize-body (, $X $Y) $P (, $X1 $Y1)) ( (set-det) ($localize-body $X $P $X1) - ($localize-body $Y $P $Y1))) + ($localize-body $Y $P $Y1))) +; + (= ($localize-body (det-if-then $X $Y) $P (det-if-then $X1 $Y1)) ( (set-det) ($localize-body $X $P $X1) - ($localize-body $Y $P $Y1))) + ($localize-body $Y $P $Y1))) +; + (= ($localize-body (or $X $Y) $P (or $X1 $Y1)) ( (set-det) ($localize-body $X $P $X1) - ($localize-body $Y $P $Y1))) + ($localize-body $Y $P $Y1))) +; + (= ($localize-body $G $P $G1) ( (functor $G $F $A) @@ -1304,27 +1807,36 @@ ($localize-args $M $As $P $As1) (=.. $G1 (Cons $F $As1)))) -; ;??? - +; (= ($localize-body $G $P (call (with_self $P $G))) - ( (var $P) (set-det))) + ( (var $P) (set-det))) +; + (= ($localize-body $G user $G) - (set-det)) + (set-det)) +; + (= ($localize-body $G $_ $G) - ( (system-predicate $G) (set-det))) + ( (system-predicate $G) (set-det))) +; + (= - ($localize_body $G $P - (: $P $G)) True) + (%localize_body $G $P + (: $P $G)) True) +; + (= ($localize-args Nil Nil $_ Nil) - (set-det)) + (set-det)) +; + (= ($localize-args (Cons : $Ms) @@ -1333,54 +1845,80 @@ (with_self $P $A) $As1)) ( (or (var $A) - (with_self - (\= $A $_) $_)) + (\= $A + (with_self $_ $_))) (set-det) - ($localize-args $Ms $As $P $As1))) + ($localize-args $Ms $As $P $As1))) +; + (= ($localize-args (Cons $_ $Ms) (Cons $A $As) $P (Cons $A $As1)) - ($localize-args $Ms $As $P $As1)) + ($localize-args $Ms $As $P $As1)) +; + (= - ($builtin_meta_predicates ^ 2 - (? :)) True) + (%builtin_meta_predicates ^ 2 + (? :)) True) +; + (= - ($builtin_meta_predicates call 1 - (:)) True) + (%builtin_meta_predicates call 1 + (:)) True) +; + (= - ($builtin_meta_predicates once 1 - (:)) True) + (%builtin_meta_predicates once 1 + (:)) True) +; + (= - ($builtin_meta_predicates \+ 1 - (:)) True) + (%builtin_meta_predicates \+ 1 + (:)) True) +; + (= - ($builtin_meta_predicates findall 3 - (? : ?)) True) + (%builtin_meta_predicates findall 3 + (? : ?)) True) +; + (= - ($builtin_meta_predicates setof 3 - (? : ?)) True) + (%builtin_meta_predicates setof 3 + (? : ?)) True) +; + (= - ($builtin_meta_predicates bagof 3 - (? : ?)) True) + (%builtin_meta_predicates bagof 3 + (? : ?)) True) +; + (= - ($builtin_meta_predicates on_exception 3 - (? : :)) True) + (%builtin_meta_predicates on_exception 3 + (? : :)) True) +; + (= - ($builtin_meta_predicates catch 3 - (: ? :)) True) + (%builtin_meta_predicates catch 3 + (: ? :)) True) +; + (= - ($builtin_meta_predicates synchronized 2 - (? :)) True) + (%builtin_meta_predicates synchronized 2 + (? :)) True) +; + (= - ($builtin_meta_predicates freeze 2 - (? :)) True) + (%builtin_meta_predicates freeze 2 + (? :)) True) +; + ; -; clause --> term (for retract) +; (= @@ -1390,87 +1928,117 @@ ( ($clause-to-term $Cl $T user $Pkg $Goal) (= $T (= $H $_)) - (functor $H $F $A))) + (functor $H $F $A))) +; + (= ($clause-to-term $Cl $_ $_ $_ $Goal) ( (var $Cl) (set-det) - (illarg var $Goal 1))) + (illarg var $Goal 1))) +; + (= ($clause-to-term $_ $_ $Pkg $_ $Goal) ( (var $Pkg) (set-det) - (illarg var $Goal 1))) + (illarg var $Goal 1))) +; + (= ($clause-to-term (with_self $P $Cl) $T $_ $Pkg $Goal) - ( (set-det) ($clause-to-term $Cl $T $P $Pkg $Goal))) + ( (set-det) ($clause-to-term $Cl $T $P $Pkg $Goal))) +; + (= ($clause-to-term $_ $_ $Pkg $_ $Goal) ( (not (atom $Pkg)) (set-det) (illarg - (type is-symbol) $Goal 1))) + (type is-symbol) $Goal 1))) +; + (= ($clause-to-term (= $H0 $B) (= $H $B) $Pkg $Pkg $Goal) - ( (set-det) ($head-to-term $H0 $H $_ $Goal))) + ( (set-det) ($head-to-term $H0 $H $_ $Goal))) +; + ; -; '$body_to_term'(B0, B, Goal). +; (= ($clause-to-term $H0 (= $H True) $Pkg $Pkg $Goal) - ($head-to-term $H0 $H $_ $Goal)) + ($head-to-term $H0 $H $_ $Goal)) +; + ; -; term --> predicate indicator (for abolish) +; (= ($term-to-predicateindicator $T (with_self $Pkg $PI) $Goal) - ($term-to-predicateindicator $T $PI user $Pkg $Goal)) + ($term-to-predicateindicator $T $PI user $Pkg $Goal)) +; + (= ($term-to-predicateindicator $T $_ $_ $_ $Goal) ( (var $T) (set-det) - (illarg var $Goal 1))) + (illarg var $Goal 1))) +; + (= ($term-to-predicateindicator $_ $_ $Pkg $_ $Goal) ( (var $Pkg) (set-det) - (illarg var $Goal 1))) + (illarg var $Goal 1))) +; + (= ($term-to-predicateindicator (with_self $P $T) $PI $_ $Pkg $Goal) - ( (set-det) ($term-to-predicateindicator $T $PI $P $Pkg $Goal))) + ( (set-det) ($term-to-predicateindicator $T $PI $P $Pkg $Goal))) +; + (= ($term-to-predicateindicator $T $_ $_ $_ $Goal) ( (\= $T (/ $_ $_)) (set-det) (illarg - (type predicate-indicator) $Goal 1))) + (type predicate-indicator) $Goal 1))) +; + (= ($term-to-predicateindicator (/ $F $_) $_ $_ $_ $Goal) ( (not (atom $F)) (set-det) (illarg - (type is-symbol) $Goal 1))) + (type is-symbol) $Goal 1))) +; + (= ($term-to-predicateindicator (/ $_ $A) $_ $_ $_ $Goal) ( (not (integer $A)) (set-det) (illarg - (type integer) $Goal 1))) + (type integer) $Goal 1))) +; + (= - ($term_to_predicateindicator $T $T $Pkg $Pkg $_) True) + (%term_to_predicateindicator $T $T $Pkg $Pkg $_) True) +; + (= @@ -1478,8 +2046,7 @@ ( ($new-indexing-hash $P $PI $IH) ($gen-indexing-keys $Cl $IH $Keys) ($update-indexing-hash $A_or_Z $Keys $IH $Ref))) -; ;'$fast_write'([update_indexing,P,PI,Cl,Ref,Keys]), nl, ;??? - +; @@ -1487,27 +2054,37 @@ ($gen-indexing-keys (= $H $_) $_ (:: all)) - ( (atom $H) (set-det))) + ( (atom $H) (set-det))) +; + (= ($gen-indexing-keys (= $H $_) $IT $Keys) - ( (arg 1 $H $A1) ($gen-indexing-keys0 $A1 $IT $Keys))) + ( (arg 1 $H $A1) ($gen-indexing-keys0 $A1 $IT $Keys))) +; + (= ($gen-indexing-keys0 $A1 $IT $Keys) ( (var $A1) (set-det) - (hash-keys $IT $Keys))) + (hash-keys $IT $Keys))) +; + (= ($gen-indexing-keys0 $A1 $_ (:: all lis)) ( (= $A1 - (Cons $_ $_)) (set-det))) + (Cons $_ $_)) (set-det))) +; + (= ($gen-indexing-keys0 $A1 $_ (:: all str)) - ( (compound $A1) (set-det))) + ( (compound $A1) (set-det))) +; + (= ($gen-indexing-keys0 $A1 $IT (:: all $Key)) @@ -1519,48 +2096,65 @@ (, (hash-get $IT var $L) (hash-put $IT $Key $L))))) -; ; get the hash code of A1 - +; (= ($gen-indexing-keys0 $A1 $IT $Keys) (illarg (type term) - ($gen-indexing-keys0 $A1 $IT $Keys) 1)) + ($gen-indexing-keys0 $A1 $IT $Keys) 1)) +; + (= ($update-indexing-hash a $Keys $IH $Ref) - ( (set-det) ($hash-addz-all $Keys $IH $Ref))) + ( (set-det) ($hash-addz-all $Keys $IH $Ref))) +; + (= ($update-indexing-hash z $Keys $IH $Ref) - ( (set-det) ($hash-adda-all $Keys $IH $Ref))) + ( (set-det) ($hash-adda-all $Keys $IH $Ref))) +; + (= ($hash-adda-all Nil $_ $_) - (set-det)) + (set-det)) +; + (= ($hash-adda-all (Cons $K $Ks) $H $X) - ( ($hash-adda $H $K $X) ($hash-adda-all $Ks $H $X))) + ( ($hash-adda $H $K $X) ($hash-adda-all $Ks $H $X))) +; + (= ($hash-addz-all Nil $_ $_) - (set-det)) + (set-det)) +; + (= ($hash-addz-all (Cons $K $Ks) $H $X) - ( ($hash-addz $H $K $X) ($hash-addz-all $Ks $H $X))) + ( ($hash-addz $H $K $X) ($hash-addz-all $Ks $H $X))) +; + (= ($erase-all Nil) - (set-det)) + (set-det)) +; + (= ($erase-all (Cons $R $Rs)) - ( ($erase $R) ($erase-all $Rs))) + ( ($erase $R) ($erase-all $Rs))) +; + (= @@ -1568,35 +2162,44 @@ ( ($new-indexing-hash $P $PI $IH) (hash-keys $IH $Keys) ($remove-index-all $Keys $IH $Ref))) -; ;'$fast_write'([rehash_indexing,P,PI,Keys]), nl, ;??? - +; (= ($remove-index-all Nil $_ $_) - (set-det)) + (set-det)) +; + (= ($remove-index-all (Cons $K $Ks) $IH $Ref) - ( ($hash-remove-first $IH $K $Ref) ($remove-index-all $Ks $IH $Ref))) + ( ($hash-remove-first $IH $K $Ref) ($remove-index-all $Ks $IH $Ref))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; All solutions +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (/ findall 3)) - !(public (/ bagof 3)) - !(public (/ setof 3)) + !(public (/ findall 3)) +; + + !(public (/ bagof 3)) +; + + !(public (/ setof 3)) +; + ; -; findall/3 +; (= @@ -1604,12 +2207,16 @@ ( (callable $Goal) (set-det) (new-hash $H) - ($findall $H $Template $Goal $Instances))) + ($findall $H $Template $Goal $Instances))) +; + (= (findall $Template $Goal $Instances) (illarg (type callable) - (findall $Template $Goal $Instances) 2)) + (findall $Template $Goal $Instances) 2)) +; + (= @@ -1617,25 +2224,33 @@ ( (call $Goal) (copy-term $Template $CT) ($hash-addz $H %FINDALL $CT) - (fail))) + (fail))) +; + (= ($findall $H $_ $_ $Instances) - (hash-get $H %FINDALL $Instances)) + (hash-get $H %FINDALL $Instances)) +; + ; -; bagof/3 & setof/3 +; (= (bagof $Template $Goal $Instances) ( (callable $Goal) (set-det) - ($bagof $Template $Goal $Instances))) + ($bagof $Template $Goal $Instances))) +; + (= (bagof $Template $Goal $Instances) (illarg (type callable) - (bagof $Template $Goal $Instances) 2)) + (bagof $Template $Goal $Instances) 2)) +; + (= @@ -1643,12 +2258,16 @@ ( (callable $Goal) (set-det) ($bagof $Template $Goal $Instances0) - (sort $Instances0 $Instances))) + (sort $Instances0 $Instances))) +; + (= (setof $Template $Goal $Instances) (illarg (type callable) - (setof $Template $Goal $Instances) 2)) + (setof $Template $Goal $Instances) 2)) +; + (= @@ -1662,19 +2281,20 @@ (+ $Witness $Template) $Goal $S) ($bagof-instances $S $Witness $Instances0) (= $Instances $Instances0))) -; ;write('Goal = '), write(Goal), nl, - -; ;write('Free variables set = '), write(FV), nl, - +; (= ($bagof $Template $Goal $Instances) - ( (findall $Template $Goal $Instances) (\== $Instances Nil))) + ( (findall $Template $Goal $Instances) (\== $Instances Nil))) +; + (= - ($bagof_instances () $Witness $Instances) - (empty)) + (%bagof_instances () $Witness $Instances) + (empty)) +; + (= ($bagof-instances $S0 $Witness $Instances) ( (= $S0 @@ -1684,20 +2304,28 @@ ($bagof-instances0 $S_next $Witness $Instances (Cons (+ $W $T) $WT_list) - (Cons $T $T_list)))) + (Cons $T $T_list)))) +; + (= ($bagof-instances0 $_ $Witness $Instances $WT_list $T_list) - ( ($unify-witness $WT_list $Witness) (= $Instances $T_list))) + ( ($unify-witness $WT_list $Witness) (= $Instances $T_list))) +; + (= ($bagof-instances0 $S_next $Witness $Instances $_ $_) - ($bagof-instances $S_next $Witness $Instances)) + ($bagof-instances $S_next $Witness $Instances)) +; + (= ($variants-subset Nil $W Nil Nil Nil) - (set-det)) + (set-det)) +; + (= ($variants-subset (Cons @@ -1707,17 +2335,23 @@ (Cons $T0 $T_list) $S_next) ( ($term-variant $W $W0) (set-det) - ($variants-subset $S $W $WT_list $T_list $S_next))) + ($variants-subset $S $W $WT_list $T_list $S_next))) +; + (= ($variants-subset (Cons $WT $S) $W $WT_list $T_list (Cons $WT $S_next)) - ($variants-subset $S $W $WT_list $T_list $S_next)) + ($variants-subset $S $W $WT_list $T_list $S_next)) +; + (= ($term-variant $X $Y) - ( (new-hash $Hash) ($term-variant $X $Y $Hash))) + ( (new-hash $Hash) ($term-variant $X $Y $Hash))) +; + (= ($term-variant $X $Y $Hash) @@ -1730,143 +2364,184 @@ (== $Y $V)) (, (var $Y) - (hash-put $Hash $X $Y))))) + (hash-put $Hash $X $Y))))) +; + (= ($term-variant $X $Y $_) ( (ground $X) (set-det) - (== $X $Y))) + (== $X $Y))) +; + (= ($term-variant $_ $Y $_) ( (var $Y) (set-det) - (fail))) + (fail))) +; + (= ($term-variant (Cons $X $Xs) (Cons $Y $Ys) $Hash) ( (set-det) ($term-variant $X $Y $Hash) - ($term-variant $Xs $Ys $Hash))) + ($term-variant $Xs $Ys $Hash))) +; + (= ($term-variant $X $Y $Hash) ( (=.. $X $Xs) (=.. $Y $Ys) - ($term-variant $Xs $Ys $Hash))) + ($term-variant $Xs $Ys $Hash))) +; + (= ($unify-witness Nil $_) - (set-det)) + (set-det)) +; + (= ($unify-witness (Cons (+ $W $_) $WT_list) $W) - ($unify-witness $WT_list $W)) + ($unify-witness $WT_list $W)) +; + ; -; Variable set of a term +; (= ($variables-set $X $Vs) - ($variables-set $X Nil $Vs)) + ($variables-set $X Nil $Vs)) +; + (= ($variables-set $X $Vs $Vs) ( (var $X) ($builtin-memq $X $Vs) - (set-det))) + (set-det))) +; + (= ($variables-set $X $Vs (Cons $X $Vs)) - ( (var $X) (set-det))) + ( (var $X) (set-det))) +; + (= ($variables-set $X $Vs0 $Vs0) - ( (atomic $X) (set-det))) + ( (atomic $X) (set-det))) +; + (= ($variables-set (Cons $X $Xs) $Vs0 $Vs) ( (set-det) ($variables-set $X $Vs0 $Vs1) - ($variables-set $Xs $Vs1 $Vs))) + ($variables-set $Xs $Vs1 $Vs))) +; + (= ($variables-set $X $Vs0 $Vs) - ( (=.. $X $Xs) ($variables-set $Xs $Vs0 $Vs))) + ( (=.. $X $Xs) ($variables-set $Xs $Vs0 $Vs))) +; + (= ($builtin-memq $X (Cons $Y $_)) - ( (== $X $Y) (set-det))) + ( (== $X $Y) (set-det))) +; + (= ($builtin-memq $X (Cons $_ $Ys)) - ($builtin-memq $X $Ys)) + ($builtin-memq $X $Ys)) +; + ; -; Existential variables set of a term +; (= ($existential-variables-set $X $Vs) - ($existential-variables-set $X Nil $Vs)) + ($existential-variables-set $X Nil $Vs)) +; + (= ($existential-variables-set $X $Vs $Vs) - ( (var $X) (set-det))) + ( (var $X) (set-det))) +; + (= ($existential-variables-set $X $Vs $Vs) - ( (atomic $X) (set-det))) + ( (atomic $X) (set-det))) +; + (= ($existential-variables-set (with_self $_ $X) $Vs0 $Vs) - ( (set-det) ($existential-variables-set $X $Vs0 $Vs))) + ( (set-det) ($existential-variables-set $X $Vs0 $Vs))) +; + ; -; '$existential_variables_set'((X;Y), Vs0, Vs) :- !, +; ; -; '$existential_variables_set'(X, Vs0, Vs1), +; ; -; '$existential_variables_set'(Y, Vs1, Vs). +; ; -; '$existential_variables_set'((X->Y), Vs0, Vs) :- !, +; ; -; '$existential_variables_set'(X, Vs0, Vs1), +; ; -; '$existential_variables_set'(Y, Vs1, Vs). +; ; -; '$existential_variables_set'((X,Y), Vs0, Vs) :- !, +; ; -; '$existential_variables_set'(X, Vs0, Vs1), +; ; -; '$existential_variables_set'(Y, Vs1, Vs). +; (= ($existential-variables-set (^ $V $G) $Vs0 $Vs) ( (set-det) ($variables-set $V $Vs0 $Vs1) - ($existential-variables-set $G $Vs1 $Vs))) + ($existential-variables-set $G $Vs1 $Vs))) +; + (= ($existential-variables-set ($meta-call $G $_ $_ $_ $_) $Vs0 $Vs) ( (set-det) ($existential-variables-set $G $Vs0 $Vs))) -; ;??? - +; (= - ($existential_variables_set $_ $Vs $Vs) True) + (%existential_variables_set $_ $Vs $Vs) True) +; + ; -; Free variables set of a term +; (= @@ -1875,29 +2550,39 @@ ($variables-set $V $VV) ($existential-variables-set $T $VV $BV) ($builtin-set-diff $TV $BV $FV) - (set-det))) + (set-det))) +; + (= ($builtin-set-diff $L1 $L2 $L) ( (sort $L1 $SL1) (sort $L2 $SL2) - ($builtin-set-diff0 $SL1 $SL2 $L))) + ($builtin-set-diff0 $SL1 $SL2 $L))) +; + (= ($builtin-set-diff0 Nil $_ Nil) - (set-det)) + (set-det)) +; + (= ($builtin-set-diff0 $L1 Nil $L1) - (set-det)) + (set-det)) +; + (= ($builtin-set-diff0 (Cons $X $Xs) (Cons $Y $Ys) $L) ( (== $X $Y) (set-det) - ($builtin-set-diff0 $Xs $Ys $L))) + ($builtin-set-diff0 $Xs $Ys $L))) +; + (= ($builtin-set-diff0 (Cons $X $Xs) @@ -1906,7 +2591,9 @@ ( (@< $X $Y) (set-det) ($builtin-set-diff0 $Xs - (Cons $Y $Ys) $L))) + (Cons $Y $Ys) $L))) +; + (= ($builtin-set-diff0 (Cons $X $Xs) @@ -1914,72 +2601,94 @@ (Cons $Y $L)) ($builtin-set-diff0 (Cons $X $Xs) $Ys - (Cons $Y $L))) + (Cons $Y $L))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Stream selection and control +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; :- public current_input/1 (written in Java) +; ; -; :- public current_output/1 (written in Java) +; ; -; :- public set_input/1, set_output/1. (written in Java) +; ; -; :- public open/4 (written in Java) +; - !(public (/ open 3)) + !(public (/ open 3)) +; + ; -; :- public close/2 (written in Java) +; - !(public (/ close 1)) + !(public (/ close 1)) +; + ; -; :- public flush_output/1.(written in Java) +; - !(public (/ flush-output 0)) - !(public (/ stream-property 2)) + !(public (/ flush-output 0)) +; + + !(public (/ stream-property 2)) +; + (= (open $Source_sink $Mode $Stream) - (open $Source_sink $Mode $Stream Nil)) + (open $Source_sink $Mode $Stream Nil)) +; + (= (close $S_or_a) - (close $S_or_a Nil)) + (close $S_or_a Nil)) +; + (= (flush-output) - ( (current-output $S) (flush-output $S))) + ( (current-output $S) (flush-output $S))) +; + (= (stream-property $Stream $Stream_property) ( (var $Stream_property) (set-det) - ($stream-property $Stream $Stream_property))) + ($stream-property $Stream $Stream_property))) +; + (= (stream-property $Stream $Stream_property) ( ($stream-property-specifier $Stream_property) (set-det) - ($stream-property $Stream $Stream_property))) + ($stream-property $Stream $Stream_property))) +; + (= (stream-property $Stream $Stream_property) (illarg (domain term stream-property) - (stream-property $Stream $Stream_property) 2)) + (stream-property $Stream $Stream_property) 2)) +; + (= @@ -1991,352 +2700,464 @@ ($builtin-member (, $Stream $Vs) $Map) (java $Stream) - ($builtin-member $Stream_property $Vs))) + ($builtin-member $Stream_property $Vs))) +; + (= ($stream-property $Stream $Stream_property) ( (java $Stream) (set-det) ($get-stream-manager $SM) (hash-get $SM $Stream $Vs) - ($builtin-member $Stream_property $Vs))) + ($builtin-member $Stream_property $Vs))) +; + (= ($stream-property $Stream $Stream_property) (illarg (domain stream stream) - (stream-property $Stream $Stream_property) 1)) + (stream-property $Stream $Stream_property) 1)) +; + (= - ($stream_property_specifier input) True) + (%stream_property_specifier input) True) +; + (= - ($stream_property_specifier output) True) + (%stream_property_specifier output) True) +; + (= - ($stream_property_specifier - (alias $_)) True) + (%stream_property_specifier + (alias $_)) True) +; + (= - ($stream_property_specifier - (mode $_)) True) + (%stream_property_specifier + (mode $_)) True) +; + (= - ($stream_property_specifier - (type $_)) True) + (%stream_property_specifier + (type $_)) True) +; + (= - ($stream_property_specifier - (file_name $_)) True) + (%stream_property_specifier + (file_name $_)) True) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Character input/output +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; :- public get_char/2, get_code/2. (written in Java) +; ; -; :- public peek_char/2, peek_code/2. (written in Java) +; ; -; :- public put_char/2, put_code/2. (written in Java) +; ; -; :- public nl/0. (written in Java) +; - !(public (, (/ get-char 1) (/ get-code 1))) - !(public (, (/ peek-char 1) (/ peek-code 1))) - !(public (, (/ put-char 1) (/ put-code 1))) - !(public (/ nl 1)) + !(public (, (/ get-char 1) (/ get-code 1))) +; + + !(public (, (/ peek-char 1) (/ peek-code 1))) +; + + !(public (, (/ put-char 1) (/ put-code 1))) +; + + !(public (/ nl 1)) +; + (= (get-char $Char) - ( (current-input $S) (get-char $S $Char))) + ( (current-input $S) (get-char $S $Char))) +; + (= (get-code $Code) - ( (current-input $S) (get-code $S $Code))) + ( (current-input $S) (get-code $S $Code))) +; + (= (peek-char $Char) - ( (current-input $S) (peek-char $S $Char))) + ( (current-input $S) (peek-char $S $Char))) +; + (= (peek-code $Code) - ( (current-input $S) (peek-code $S $Code))) + ( (current-input $S) (peek-code $S $Code))) +; + (= (put-char $Char) - ( (current-output $S) (put-char $S $Char))) + ( (current-output $S) (put-char $S $Char))) +; + (= (put-code $Code) - ( (current-output $S) (put-code $S $Code))) + ( (current-output $S) (put-code $S $Code))) +; + (= (nl $S) (put-char $S -)) +)) +; + - !(public (, (/ get0 1) (/ get0 2))) - !(public (/ get 1)) + !(public (, (/ get0 1) (/ get0 2))) +; + + !(public (/ get 1)) +; + ; -; :- public get/2. (written in Java) +; - !(public (, (/ put 1) (/ put 2))) - !(public (/ tab 1)) + !(public (, (/ put 1) (/ put 2))) +; + + !(public (/ tab 1)) +; + ; -; :- public tab/2. (written in Java) +; - !(public (/ skip 1)) + !(public (/ skip 1)) +; + ; -; :- public skip/2. (written in Java) +; (= (get0 $Code) - ( (current-input $S) (get-code $S $Code))) + ( (current-input $S) (get-code $S $Code))) +; + (= (get0 $S_or_a $Code) - (get-code $S_or_a $Code)) + (get-code $S_or_a $Code)) +; + (= (get $Code) - ( (current-input $S) (get $S $Code))) + ( (current-input $S) (get $S $Code))) +; + (= (put $Exp) - ( (current-output $S) (put $S $Exp))) + ( (current-output $S) (put $S $Exp))) +; + (= (put $S_or_a $Exp) - ( (is $Code $Exp) (put-code $S_or_a $Code))) + ( (is $Code $Exp) (put-code $S_or_a $Code))) +; + (= (tab $N) - ( (current-output $S) (tab $S $N))) + ( (current-output $S) (tab $S $N))) +; + (= (skip $N) - ( (current-input $S) (skip $S $N))) + ( (current-input $S) (skip $S $N))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Byte input/output +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (, (/ get-byte 1) (/ peek-byte 1) (/ put-byte 1))) + !(public (, (/ get-byte 1) (/ peek-byte 1) (/ put-byte 1))) +; + ; -; :- public get_byte/2. ; written in java +; ; -; :- public peek_byte/2. ; written in java +; ; -; :- public put_byte/2. ; written in java +; (= (get-byte $Byte) - ( (current-input $S) (get-byte $S $Byte))) + ( (current-input $S) (get-byte $S $Byte))) +; + (= (peek-byte $Byte) - ( (current-input $S) (peek-byte $S $Byte))) + ( (current-input $S) (peek-byte $S $Byte))) +; + (= (put-byte $Byte) - ( (current-output $S) (put-byte $S $Byte))) + ( (current-output $S) (put-byte $S $Byte))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Term input/output (read) +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (, (/ read 1) (/ read 2))) - !(public (, (/ read-with-variables 2) (/ read-with-variables 3))) - !(public (/ read-line 1)) + !(public (, (/ read 1) (/ read 2))) +; + + !(public (, (/ read-with-variables 2) (/ read-with-variables 3))) +; + + !(public (/ read-line 1)) +; + ; -; :- public read_line/2. (written in Java) +; - !(dynamic (/ %tokens 1)) + !(dynamic (/ %tokens 1)) +; + (= (read $X) - ( (current-input $S) (read $S $X))) + ( (current-input $S) (read $S $X))) +; + (= (read $S_or_a $X) ( (read-tokens $S_or_a $Tokens $_) (parse-tokens $X $Tokens) - (set-det))) + (set-det))) +; + (= (read-with-variables $X $Vs) - ( (current-input $S) (read-with-variables $S $X $Vs))) + ( (current-input $S) (read-with-variables $S $X $Vs))) +; + (= (read-with-variables $S_or_a $X $Vs) ( (read-tokens $S_or_a $Tokens $Vs) (parse-tokens $X $Tokens) - (set-det))) + (set-det))) +; + (= (read-line $X) - ( (current-input $S) (read-line $S $X))) + ( (current-input $S) (read-line $S $X))) +; + ; -; read_token(S_or_a, Token) reads one token from the input, +; ; -; and unifies Token with: +; ; -; error(Atom), +; ; -; end_of_file, +; ; -; '.', ' ', '(', ')', '[', ']', '{', '}', ',', '|', +; ; -; number(Integer_or_Float), +; ; -; atom(Atom), +; ; -; var(Atom), +; ; -; string(CharCodeList) +; ; -; read_token(Token) :- current_input(S), read_token(S, Token). +; (= (read-token $S_or_a $Token) - ( ($read-token0 $S_or_a $Type $Token0) ($read-token1 (:: $Type) $Token0 $Token))) + ( ($read-token0 $S_or_a $Type $Token0) ($read-token1 (:: $Type) $Token0 $Token))) +; + (= ($read-token1 (:: -2) $T (error $T)) - (set-det)) ; -; error('message') + (set-det)) +; + ; +; (= ($read-token1 "I" $T (number $T)) - (set-det)) ; -; number(intvalue) + (set-det)) +; + ; +; (= ($read-token1 "L" $T (number $T)) - (set-det)) ; -; number(longvalue) + (set-det)) +; + ; +; (= ($read-token1 "D" $T (number $T)) - (set-det)) ; -; number(floatvalue) + (set-det)) +; + ; +; (= ($read-token1 "A" $T (atom $T)) - (set-det)) ; -; atom('name') + (set-det)) +; + ; +; (= ($read-token1 "V" $T (var $T)) - (set-det)) ; -; var('name') + (set-det)) +; + ; +; (= ($read-token1 "S" $T (string $T)) - (set-det)) ; -; string("chars") + (set-det)) +; + ; +; (= ($read-token1 $_ $T $T) - (set-det)) ; -; others + (set-det)) +; + ; +; ; -; read_tokens(Tokens, Vs) reads tokens from the input +; ; -; until full-stop-mark ('.') or end_of_file, +; ; -; unifies Tokens with a list of tokens. +; ; -; Token for a variable has a form of var(Name,Variable). +; ; -; Vs is a list of Name=Variable pairs. +; ; -; read_tokens(Tokens, Vs) :- +; ; -; current_input(Stream), +; ; -; '$read_tokens'(Stream, Tokens, Vs, []), +; ; -; !. +; (= (read-tokens $Stream $Tokens $Vs) - ( ($read-tokens $Stream $Tokens $Vs Nil) (set-det))) + ( ($read-tokens $Stream $Tokens $Vs Nil) (set-det))) +; + (= ($read-tokens $Stream $Tokens $Vs $VI) - ( (read-token $Stream $Token) ($read-tokens1 $Stream $Token $Tokens $Vs $VI))) + ( (read-token $Stream $Token) ($read-tokens1 $Stream $Token $Tokens $Vs $VI))) +; + (= @@ -2351,15 +3172,21 @@ (nl user-error) (flush-output user-error) ($read-tokens-until-fullstop $Stream) - (fail))) + (fail))) +; + (= ($read-tokens1 $Stream end-of-file (:: end-of-file .) Nil $_) - (set-det)) + (set-det)) +; + (= ($read-tokens1 $Stream . (:: .) Nil $_) - (set-det)) + (set-det)) +; + (= ($read-tokens1 $Stream (var -) @@ -2367,7 +3194,9 @@ (var - $V) $Tokens) (Cons (= - $V) $Vs) $VI0) - ( (set-det) ($read-tokens $Stream $Tokens $Vs (Cons (= - $V) $VI0)))) + ( (set-det) ($read-tokens $Stream $Tokens $Vs (Cons (= - $V) $VI0)))) +; + (= ($read-tokens1 $Stream (var $Name) @@ -2376,7 +3205,9 @@ ( ($mem-pair (= $Name $V) $VI) (set-det) - ($read-tokens $Stream $Tokens $Vs $VI))) + ($read-tokens $Stream $Tokens $Vs $VI))) +; + (= ($read-tokens1 $Stream (var $Name) @@ -2384,11 +3215,15 @@ (var $Name $V) $Tokens) (Cons (= $Name $V) $Vs) $VI0) - ( (set-det) ($read-tokens $Stream $Tokens $Vs (Cons (= $Name $V) $VI0)))) + ( (set-det) ($read-tokens $Stream $Tokens $Vs (Cons (= $Name $V) $VI0)))) +; + (= ($read-tokens1 $Stream $Token (Cons $Token $Tokens) $Vs $VI) - ($read-tokens $Stream $Tokens $Vs $VI)) + ($read-tokens $Stream $Tokens $Vs $VI)) +; + (= @@ -2398,360 +3233,442 @@ (= $X2 $V2) $_)) ( (== $X1 $X2) (set-det) - (= $V1 $V2))) + (= $V1 $V2))) +; + (= ($mem-pair $X (Cons $_ $L)) - ($mem-pair $X $L)) + ($mem-pair $X $L)) +; + ; -; '$mem_pair'(X, [_|L]) :- member(X, L). +; (= ($read-tokens-until-fullstop $Stream) - ( (read-token $Stream $Token) ($read-tokens-until-fullstop $Stream $Token))) + ( (read-token $Stream $Token) ($read-tokens-until-fullstop $Stream $Token))) +; + (= ($read-tokens-until-fullstop $Stream end-of-file) - (set-det)) + (set-det)) +; + (= ($read-tokens-until-fullstop $Stream .) - (set-det)) + (set-det)) +; + (= ($read-tokens-until-fullstop $Stream $_) - ( (read-token $Stream $Token) ($read-tokens-until-fullstop $Stream $Token))) + ( (read-token $Stream $Token) ($read-tokens-until-fullstop $Stream $Token))) +; + (= (parse-tokens $X $Tokens) - ( (remove-all-atoms &self + ( (remove-all-symbols &self ($tokens $_)) - (add-atom &self + (add-symbol &self ($tokens $Tokens)) ($parse-tokens $X 1201 $Tokens (:: .)) - (remove-atom &self + (remove-symbol &self ($tokens $Tokens)) - (set-det))) + (set-det))) +; + ; -; '$parse_tokens'(X, Prec) parses the input whose precedecence =< Prec. +; (= (--> - ($parse_tokens $X $Prec0) + (%parse_tokens $X $Prec0) (, $parse_tokens_skip_spaces (, - ($parse_tokens1 $Prec0 $X1 $Prec1) + (%parse_tokens1 $Prec0 $X1 $Prec1) (, ! (, $parse_tokens_skip_spaces (, - ($parse_tokens2 $Prec0 $X1 $Prec1 $X $Prec) !)))))) True) + (%parse_tokens2 $Prec0 $X1 $Prec1 $X $Prec) !)))))) True) +; + (= (--> - ($parse_tokens1 $Prec0 $X1 $Prec1) + (%parse_tokens1 $Prec0 $X1 $Prec1) (, - ($parse_tokens_peep_next $Next) + (%parse_tokens_peep_next $Next) (, - { ($parse_tokens_is_starter $Next) } + { (%parse_tokens_is_starter $Next) } (, ! - ($parse_tokens_before_op $Prec0 $X1 $Prec1))))) True) + (%parse_tokens_before_op $Prec0 $X1 $Prec1))))) True) +; + (= (--> - ($parse_tokens1 $_ $_ $_) + (%parse_tokens1 $_ $_ $_) (, - ($parse_tokens_peep_next $Next) - ($parse_tokens_error - ($Next cannot start an expression)))) True) + (%parse_tokens_peep_next $Next) + (%parse_tokens_error + ($Next cannot start an expression)))) True) +; + (= (--> - ($parse_tokens2 $Prec0 $X $Prec $X $Prec) + (%parse_tokens2 $Prec0 $X $Prec $X $Prec) (, - ($parse_tokens_peep_next $Next) + (%parse_tokens_peep_next $Next) (, - { ($parse_tokens_is_terminator $Next) } + { (%parse_tokens_is_terminator $Next) } (, - { (=< $Prec $Prec0) } !)))) True) + { (=< $Prec $Prec0) } !)))) True) +; + (= (--> - ($parse_tokens2 $Prec0 $X1 $Prec1 $X $Prec) + (%parse_tokens2 $Prec0 $X1 $Prec1 $X $Prec) (, - ($parse_tokens_peep_next $Next) + (%parse_tokens_peep_next $Next) (, - { ($parse_tokens_is_post_in_op $Next) } + { (%parse_tokens_is_post_in_op $Next) } (, ! - ($parse_tokens_post_in_ops $Prec0 $X1 $Prec1 $X $Prec))))) True) + (%parse_tokens_post_in_ops $Prec0 $X1 $Prec1 $X $Prec))))) True) +; + (= (--> - ($parse_tokens2 $_ $_ $_ $_ $_) - ($parse_tokens_error - (operator expected after expression))) True) + (%parse_tokens2 $_ $_ $_ $_ $_) + (%parse_tokens_error + (operator expected after expression))) True) +; + ; -; '$parse_tokens_before_op'(Prec0, X, Prec) +; ; -; parses the input until infix or postfix operator, +; ; -; and returns X and Prec +; (= (--> - ($parse_tokens_before_op $Prec0 $X $Prec) + (%parse_tokens_before_op $Prec0 $X $Prec) (, (' ') (, ! - ($parse_tokens_before_op $Prec0 $X $Prec)))) True) + (%parse_tokens_before_op $Prec0 $X $Prec)))) True) +; + (= (--> - ($parse_tokens_before_op $_ end_of_file 0) + (%parse_tokens_before_op $_ end_of_file 0) (, - (end_of_file) !)) True) + (end_of_file) !)) True) +; + (= (--> - ($parse_tokens_before_op $_ $N 0) + (%parse_tokens_before_op $_ $N 0) (, - ( (number $N)) !)) True) + ( (number $N)) !)) True) +; + (= (--> - ($parse_tokens_before_op $_ $N 0) + (%parse_tokens_before_op $_ $N 0) (, - ( (atom -)) + ( (is-symbol -)) (, ( (number $N0)) (, ! { (is $N - (- $N0)) })))) True) + (- $N0)) })))) True) +; + (= (--> - ($parse_tokens_before_op $_ $V 0) + (%parse_tokens_before_op $_ $V 0) (, - ( (var $_ $V)) !)) True) + ( (var $_ $V)) !)) True) +; + (= (--> - ($parse_tokens_before_op $_ $S 0) + (%parse_tokens_before_op $_ $S 0) (, - ( (string $S)) !)) True) + ( (string $S)) !)) True) +; + (= (--> - ($parse_tokens_before_op $_ $X 0) + (%parse_tokens_before_op $_ $X 0) (, (() (, ! (, - ($parse_tokens $X 1201) - ($parse_tokens_expect )))))) True) + (%parse_tokens $X 1201) + (%parse_tokens_expect )))))) True) +; + (= (--> - ($parse_tokens_before_op $_ $X 0) + (%parse_tokens_before_op $_ $X 0) (, ({) (, ! (, $parse_tokens_skip_spaces - ($parse_tokens_brace $X))))) True) + (%parse_tokens_brace $X))))) True) +; + (= (--> - ($parse_tokens_before_op $_ $X 0) + (%parse_tokens_before_op $_ $X 0) (, ([) (, ! (, $parse_tokens_skip_spaces - ($parse_tokens_list $X))))) True) + (%parse_tokens_list $X))))) True) +; + (= (--> - ($parse_tokens_before_op $_ $X 0) + (%parse_tokens_before_op $_ $X 0) (, - ( (atom $F)) + ( (is-symbol $F)) (, (() (, ! (, $parse_tokens_skip_spaces (, - ($parse_tokens_args $Args) + (%parse_tokens_args $Args) { (=.. $X - (Cons $F $Args)) })))))) True) + (Cons $F $Args)) })))))) True) +; + (= (--> - ($parse_tokens_before_op $Prec0 $X $PrecOp) + (%parse_tokens_before_op $Prec0 $X $PrecOp) (, - ( (atom $F)) + ( (is-symbol $F)) (, { (current_op $PrecOp fx $F) } (, { (=< $PrecOp $Prec0) } (, $parse_tokens_skip_spaces (, - ($parse_tokens_peep_next $Next) + (%parse_tokens_peep_next $Next) (, - { ($parse_tokens_is_starter $Next) } + { (%parse_tokens_is_starter $Next) } (, { (\+ - ($parse_tokens_is_post_in_op $Next)) } + (%parse_tokens_is_post_in_op $Next)) } (, ! (, { (is $Prec1 (- $PrecOp 1)) } (, - ($parse_tokens $Arg $Prec1) + (%parse_tokens $Arg $Prec1) (, { (functor $X $F 1) } - { (arg 1 $X $Arg) })))))))))))) True) + { (arg 1 $X $Arg) })))))))))))) True) +; + (= (--> - ($parse_tokens_before_op $Prec0 $X $PrecOp) + (%parse_tokens_before_op $Prec0 $X $PrecOp) (, - ( (atom $F)) + ( (is-symbol $F)) (, { (current_op $PrecOp fy $F) } (, { (=< $PrecOp $Prec0) } (, $parse_tokens_skip_spaces (, - ($parse_tokens_peep_next $Next) + (%parse_tokens_peep_next $Next) (, - { ($parse_tokens_is_starter $Next) } + { (%parse_tokens_is_starter $Next) } (, { (\+ - ($parse_tokens_is_post_in_op $Next)) } + (%parse_tokens_is_post_in_op $Next)) } (, ! (, - ($parse_tokens $Arg $PrecOp) + (%parse_tokens $Arg $PrecOp) (, { (functor $X $F 1) } - { (arg 1 $X $Arg) }))))))))))) True) + { (arg 1 $X $Arg) }))))))))))) True) +; + (= (--> - ($parse_tokens_before_op $_ $A 0) - ( (atom $A))) True) + (%parse_tokens_before_op $_ $A 0) + ( (is-symbol $A))) True) +; + (= (--> - ($parse_tokens_brace {}) + (%parse_tokens_brace {}) (, - (}) !)) True) + (}) !)) True) +; + (= (--> - ($parse_tokens_brace $X) + (%parse_tokens_brace $X) (, - ($parse_tokens $X1 1201) + (%parse_tokens $X1 1201) (, - ($parse_tokens_expect }) + (%parse_tokens_expect }) { (= $X - {$X1 }) }))) True) + {$X1 }) }))) True) +; + (= (--> - ($parse_tokens_list []) + (%parse_tokens_list []) (, - (]) !)) True) + (]) !)) True) +; + (= (--> - ($parse_tokens_list + (%parse_tokens_list (Cons $X $Xs)) (, - ($parse_tokens $X 999) + (%parse_tokens $X 999) (, $parse_tokens_skip_spaces - ($parse_tokens_list_rest $Xs)))) True) + (%parse_tokens_list_rest $Xs)))) True) +; + (= (--> - ($parse_tokens_list_rest $Xs) + (%parse_tokens_list_rest $Xs) (, (|) (, ! (, - ($parse_tokens $Xs 999) - ($parse_tokens_expect ]))))) True) + (%parse_tokens $Xs 999) + (%parse_tokens_expect ]))))) True) +; + (= (--> - ($parse_tokens_list_rest + (%parse_tokens_list_rest (Cons $X $Xs)) (, (,) (, ! (, - ($parse_tokens $X 999) + (%parse_tokens $X 999) (, $parse_tokens_skip_spaces - ($parse_tokens_list_rest $Xs)))))) True) + (%parse_tokens_list_rest $Xs)))))) True) +; + (= (--> - ($parse_tokens_list_rest []) - ($parse_tokens_expect ])) True) + (%parse_tokens_list_rest []) + (%parse_tokens_expect ])) True) +; + (= (--> - ($parse_tokens_args []) + (%parse_tokens_args []) (, - ()) !)) True) + ()) !)) True) +; + (= (--> - ($parse_tokens_args + (%parse_tokens_args (Cons $X $Xs)) (, - ($parse_tokens $X 999) + (%parse_tokens $X 999) (, $parse_tokens_skip_spaces - ($parse_tokens_args_rest $Xs)))) True) + (%parse_tokens_args_rest $Xs)))) True) +; + (= (--> - ($parse_tokens_args_rest + (%parse_tokens_args_rest (Cons $X $Xs)) (, (,) (, ! (, - ($parse_tokens $X 999) + (%parse_tokens $X 999) (, $parse_tokens_skip_spaces - ($parse_tokens_args_rest $Xs)))))) True) + (%parse_tokens_args_rest $Xs)))))) True) +; + (= (--> - ($parse_tokens_args_rest []) - ($parse_tokens_expect ))) True) + (%parse_tokens_args_rest []) + (%parse_tokens_expect ))) True) +; + ; -; '$parse_tokens_post_in_op'(Prec0, X1, Prec1, X, Prec) +; ; -; parses the input beginning from infix or postfix operator, +; ; -; and returns X and Prec +; (= (--> - ($parse_tokens_post_in_ops $Prec0 $X1 $Prec1 $X $Prec) + (%parse_tokens_post_in_ops $Prec0 $X1 $Prec1 $X $Prec) (, $parse_tokens_skip_spaces (, ($Op) (, - ($parse_tokens_op $Op $Prec0 $X1 $Prec1 $X2 $Prec2) - ($parse_tokens_post_in_ops $Prec0 $X2 $Prec2 $X $Prec))))) True) + (%parse_tokens_op $Op $Prec0 $X1 $Prec1 $X2 $Prec2) + (%parse_tokens_post_in_ops $Prec0 $X2 $Prec2 $X $Prec))))) True) +; + (= (--> - ($parse_tokens_post_in_ops $Prec0 $X $Prec $X $Prec) - { (=< $Prec $Prec0) }) True) + (%parse_tokens_post_in_ops $Prec0 $X $Prec $X $Prec) + { (=< $Prec $Prec0) }) True) +; + (= (--> - ($parse_tokens_op , $Prec0 $X1 $Prec1 $X $PrecOp) + (%parse_tokens_op , $Prec0 $X1 $Prec1 $X $PrecOp) (, ! - ($parse_tokens_op - (atom ,) $Prec0 $X1 $Prec1 $X $PrecOp))) True) + (%parse_tokens_op + (is-symbol ,) $Prec0 $X1 $Prec1 $X $PrecOp))) True) +; + (= (--> - ($parse_tokens_op | $Prec0 $X1 $Prec1 $X $PrecOp) + (%parse_tokens_op | $Prec0 $X1 $Prec1 $X $PrecOp) (, ! - ($parse_tokens_op - (atom ;) $Prec0 $X1 $Prec1 $X $PrecOp))) True) + (%parse_tokens_op + (is-symbol ;) $Prec0 $X1 $Prec1 $X $PrecOp))) True) +; + (= (--> - ($parse_tokens_op - (atom $Op) $Prec0 $X1 $Prec1 $X $PrecOp) + (%parse_tokens_op + (is-symbol $Op) $Prec0 $X1 $Prec1 $X $PrecOp) (, { (current_op $PrecOp xf $Op) } (, @@ -2760,11 +3677,13 @@ { (< $Prec1 $PrecOp) } (, { (functor $X $Op 1) } - { (arg 1 $X $X1) }))))) True) + { (arg 1 $X $X1) }))))) True) +; + (= (--> - ($parse_tokens_op - (atom $Op) $Prec0 $X1 $Prec1 $X $PrecOp) + (%parse_tokens_op + (is-symbol $Op) $Prec0 $X1 $Prec1 $X $PrecOp) (, { (current_op $PrecOp yf $Op) } (, @@ -2773,11 +3692,13 @@ { (=< $Prec1 $PrecOp) } (, { (functor $X $Op 1) } - { (arg 1 $X $X1) }))))) True) + { (arg 1 $X $X1) }))))) True) +; + (= (--> - ($parse_tokens_op - (atom $Op) $Prec0 $X1 $Prec1 $X $PrecOp) + (%parse_tokens_op + (is-symbol $Op) $Prec0 $X1 $Prec1 $X $PrecOp) (, { (current_op $PrecOp xfx $Op) } (, @@ -2788,17 +3709,19 @@ { (is $Prec2 (- $PrecOp 1)) } (, - ($parse_tokens $X2 $Prec2) + (%parse_tokens $X2 $Prec2) (, ! (, { (functor $X $Op 2) } (, { (arg 1 $X $X1) } - { (arg 2 $X $X2) }))))))))) True) + { (arg 2 $X $X2) }))))))))) True) +; + (= (--> - ($parse_tokens_op - (atom $Op) $Prec0 $X1 $Prec1 $X $PrecOp) + (%parse_tokens_op + (is-symbol $Op) $Prec0 $X1 $Prec1 $X $PrecOp) (, { (current_op $PrecOp xfy $Op) } (, @@ -2808,17 +3731,19 @@ (, { (is $Prec2 $PrecOp) } (, - ($parse_tokens $X2 $Prec2) + (%parse_tokens $X2 $Prec2) (, ! (, { (functor $X $Op 2) } (, { (arg 1 $X $X1) } - { (arg 2 $X $X2) }))))))))) True) + { (arg 2 $X $X2) }))))))))) True) +; + (= (--> - ($parse_tokens_op - (atom $Op) $Prec0 $X1 $Prec1 $X $PrecOp) + (%parse_tokens_op + (is-symbol $Op) $Prec0 $X1 $Prec1 $X $PrecOp) (, { (current_op $PrecOp yfx $Op) } (, @@ -2829,97 +3754,149 @@ { (is $Prec2 (- $PrecOp 1)) } (, - ($parse_tokens $X2 $Prec2) + (%parse_tokens $X2 $Prec2) (, ! (, { (functor $X $Op 2) } (, { (arg 1 $X $X1) } - { (arg 2 $X $X2) }))))))))) True) + { (arg 2 $X $X2) }))))))))) True) +; + (= - ($parse_tokens_is_starter end_of_file) True) + (%parse_tokens_is_starter end_of_file) True) +; + (= - ($parse_tokens_is_starter () True) + (%parse_tokens_is_starter () True) +; + (= - ($parse_tokens_is_starter [) True) + (%parse_tokens_is_starter [) True) +; + (= - ($parse_tokens_is_starter {) True) + (%parse_tokens_is_starter {) True) +; + (= - ($parse_tokens_is_starter - (number $_)) True) + (%parse_tokens_is_starter + (number $_)) True) +; + (= - ($parse_tokens_is_starter - (atom $_)) True) + (%parse_tokens_is_starter + (is-symbol $_)) True) +; + (= - ($parse_tokens_is_starter - (var $_ $_)) True) + (%parse_tokens_is_starter + (var $_ $_)) True) +; + (= - ($parse_tokens_is_starter - (string $_)) True) + (%parse_tokens_is_starter + (string $_)) True) +; + (= - ($parse_tokens_is_terminator )) True) + (%parse_tokens_is_terminator )) True) +; + (= - ($parse_tokens_is_terminator ]) True) + (%parse_tokens_is_terminator ]) True) +; + (= - ($parse_tokens_is_terminator }) True) + (%parse_tokens_is_terminator }) True) +; + (= - ($parse_tokens_is_terminator .) True) + (%parse_tokens_is_terminator .) True) +; + (= ($parse-tokens-is-post-in-op ,) - (set-det)) + (set-det)) +; + (= ($parse-tokens-is-post-in-op |) - (set-det)) + (set-det)) +; + (= ($parse-tokens-is-post-in-op (atom $Op)) ( (current-op $_ $Type $Op) ($parse-tokens-post-in-type $Type) - (set-det))) + (set-det))) +; + (= - ($parse_tokens_post_in_type xfx) True) + (%parse_tokens_post_in_type xfx) True) +; + (= - ($parse_tokens_post_in_type xfy) True) + (%parse_tokens_post_in_type xfy) True) +; + (= - ($parse_tokens_post_in_type yfx) True) + (%parse_tokens_post_in_type yfx) True) +; + (= - ($parse_tokens_post_in_type xf) True) + (%parse_tokens_post_in_type xf) True) +; + (= - ($parse_tokens_post_in_type yf) True) + (%parse_tokens_post_in_type yf) True) +; + (= (--> - ($parse_tokens_expect $Token) + (%parse_tokens_expect $Token) (, $parse_tokens_skip_spaces (, - ($Token) !))) True) + ($Token) !))) True) +; + (= (--> - ($parse_tokens_expect $Token) - ($parse_tokens_error - ($Token expected))) True) + (%parse_tokens_expect $Token) + (%parse_tokens_error + ($Token expected))) True) +; + (= (--> $parse_tokens_skip_spaces (, (' ') - (, ! $parse_tokens_skip_spaces))) True) + (, ! $parse_tokens_skip_spaces))) True) +; + (= - (--> $parse_tokens_skip_spaces ()) True) + (--> $parse_tokens_skip_spaces ()) True) +; + (= ($parse-tokens-peep-next $Next $S $S) (= $S - (Cons $Next $_))) + (Cons $Next $_))) +; + (= @@ -2931,17 +3908,21 @@ (write user-error **) (nl user-error) ($parse-tokens-error1 Nil $S0) - (get-atoms &self + (get-symbols &self (= ($tokens $Tokens) $_)) ($parse-tokens-error1 $Tokens $S0) (flush-output user-error) - (fail))) + (fail))) +; + (= ($parse-tokens-error1 Nil $_) - (set-det)) + (set-det)) +; + (= ($parse-tokens-error1 $Tokens $S0) ( (== $Tokens $S0) @@ -2950,35 +3931,51 @@ (write user-error '** here **') (nl user-error) ($parse-tokens-error1 $Tokens Nil) - (nl user-error))) + (nl user-error))) +; + (= ($parse-tokens-error1 (Cons $Token $Tokens) $S0) - ( ($parse-tokens-error2 $Token) ($parse-tokens-error1 $Tokens $S0))) + ( ($parse-tokens-error2 $Token) ($parse-tokens-error1 $Tokens $S0))) +; + (= ($parse-tokens-error2 (number $X)) - ( (set-det) (write $X))) + ( (set-det) (write $X))) +; + (= ($parse-tokens-error2 (atom $X)) - ( (set-det) (writeq $X))) + ( (set-det) (writeq $X))) +; + (= ($parse-tokens-error2 (var $X $_)) - ( (set-det) (write $X))) + ( (set-det) (write $X))) +; + (= ($parse-tokens-error2 (string $X)) ( (set-det) (write user-error ") ($parse-tokens-write-string user-error $X) - (write user-error "))) + (write user-error "))) +; + (= ($parse-tokens-error2 $X) - (write user-error $X)) + (write user-error $X)) +; + (= - ($parse_tokens_write_string $_ ()) True) + (%parse_tokens_write_string $_ ()) True) +; + (= ($parse-tokens-write-string $S (Cons $C $Cs)) @@ -2987,86 +3984,122 @@ (set-det) (put-code $S $C) (put-code $S $C) - ($parse-tokens-write-string $S $Cs))) + ($parse-tokens-write-string $S $Cs))) +; + (= ($parse-tokens-write-string $S (Cons $C $Cs)) - ( (put-code $S $C) ($parse-tokens-write-string $S $Cs))) + ( (put-code $S $C) ($parse-tokens-write-string $S $Cs))) +; + (= - ($parse_tokens_write_message $_ ()) True) + (%parse_tokens_write_message $_ ()) True) +; + (= ($parse-tokens-write-message $S (Cons $X $Xs)) ( (write $S $X) (write $S ' ') - ($parse-tokens-write-message $S $Xs))) + ($parse-tokens-write-message $S $Xs))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Term input/output (write) +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (, (/ write 1) (/ write 2))) - !(public (, (/ writeq 1) (/ writeq 2))) - !(public (, (/ write-canonical 1) (/ write-canonical 2))) - !(public (, (/ write-term 2) (/ write-term 3))) + !(public (, (/ write 1) (/ write 2))) +; + + !(public (, (/ writeq 1) (/ writeq 2))) +; + + !(public (, (/ write-canonical 1) (/ write-canonical 2))) +; + + !(public (, (/ write-term 2) (/ write-term 3))) +; + (= (write $Term) - ( (current-output $S) (write-term $S $Term (:: (numbervars True))))) + ( (current-output $S) (write-term $S $Term (:: (numbervars True))))) +; + (= (write $S_or_a $Term) (write-term $S_or_a $Term - (:: (numbervars True)))) + (:: (numbervars True)))) +; + (= (writeq $Term) - ( (current-output $S) (write-term $S $Term (:: (quoted True) (numbervars True))))) + ( (current-output $S) (write-term $S $Term (:: (quoted True) (numbervars True))))) +; + (= (writeq $S_or_a $Term) (write-term $S_or_a $Term (:: (quoted True) - (numbervars True)))) + (numbervars True)))) +; + (= (write-canonical $Term) - ( (current-output $S) (write-term $S $Term (:: (quoted True) (ignore-ops True))))) + ( (current-output $S) (write-term $S $Term (:: (quoted True) (ignore-ops True))))) +; + (= (write-canonical $S_or_a $Term) (write-term $S_or_a $Term (:: (quoted True) - (ignore-ops True)))) + (ignore-ops True)))) +; + (= (write-term $Term $Options) - ( (current-output $S) (write-term $S $Term $Options))) + ( (current-output $S) (write-term $S $Term $Options))) +; + (= (write-term $S_or_a $Term $Options) - ( ($write-term $S_or_a $Term $Options) (fail))) + ( ($write-term $S_or_a $Term $Options) (fail))) +; + (= - (write_term $_ $_ $_) True) + (write_term $_ $_ $_) True) +; + (= ($write-term $S_or_a $Term $Options) - ( ($write-term0 $Term 1200 punct $_ $Options $S_or_a) (set-det))) + ( ($write-term0 $Term 1200 punct $_ $Options $S_or_a) (set-det))) +; + (= @@ -3074,13 +4107,17 @@ ( (var $Term) (set-det) ($write-space-if-needed $Type0 alpha $S_or_a) - ($fast-write $S_or_a $Term))) + ($fast-write $S_or_a $Term))) +; + (= ($write-term0 $Term $Prec $Type0 alpha $_ $S_or_a) ( (java $Term) (set-det) ($write-space-if-needed $Type0 alpha $S_or_a) - ($fast-write $S_or_a $Term))) + ($fast-write $S_or_a $Term))) +; + (= ($write-term0 $Term $Prec $Type0 alpha $Style $S_or_a) ( (= $Term $VN) @@ -3090,61 +4127,71 @@ (numbervars True) $Style) (set-det) ($write-space-if-needed $Type0 alpha $S_or_a) - ($write-VAR $VN $S_or_a))) + ($write-VAR $VN $S_or_a))) +; + (= ($write-term0 $Term $Prec $Type0 alpha $_ $S_or_a) ( (number $Term) (< $Term 0) (set-det) ($write-space-if-needed $Type0 symbol $S_or_a) - ($fast-write $S_or_a $Term))) + ($fast-write $S_or_a $Term))) +; + (= ($write-term0 $Term $Prec $Type0 alpha $_ $S_or_a) ( (number $Term) (set-det) ($write-space-if-needed $Type0 alpha $S_or_a) - ($fast-write $S_or_a $Term))) + ($fast-write $S_or_a $Term))) +; + ; -; '$write_term0'(Term, Prec, Type0, punct, _, S_or_a) :- +; ; -; atom(Term), +; ; -; current_op(PrecOp, OpType, Term), +; ; -; (OpType = fx ; OpType = fy), +; ; -; PrecOp =< Prec, +; ; -; !, +; ; -; '$write_space_if_needed'(Type0, punct, S_or_a), +; ; -; put_char(S_or_a, '('), +; ; -; '$write_atom'(Term, punct, _, _, S_or_a), +; ; -; put_char(S_or_a, ')'). +; (= ($write-term0 $Term $Prec $Type0 $Type $Style $S_or_a) ( (atom $Term) (set-det) - ($write-atom $Term $Type0 $Type $Style $S_or_a))) + ($write-atom $Term $Type0 $Type $Style $S_or_a))) +; + (= ($write-term0 $Term $Prec $Type0 $Type $Style $S_or_a) ( (not ($builtin-member (ignore-ops True) $Style)) ($write-is-operator $Term $Op $Args $OpType) (set-det) - ($write-term-op $Op $OpType $Args $Prec $Type0 $Type $Style $S_or_a))) + ($write-term-op $Op $OpType $Args $Prec $Type0 $Type $Style $S_or_a))) +; + (= ($write-term0 $Term $Prec $Type0 punct $Style $S_or_a) ( (= $Term @@ -3154,7 +4201,9 @@ ($write-space-if-needed $Type0 punct $S_or_a) (put-char $S_or_a [) ($write-term-list-args $Term punct $_ $Style $S_or_a) - (put-char $S_or_a ]))) + (put-char $S_or_a ]))) +; + (= ($write-term0 $Term $Prec $Type0 $Type $Style $S_or_a) ( (= $Term @@ -3164,7 +4213,9 @@ ($write-space-if-needed $Type0 punct $S_or_a) (put-char $S_or_a {) ($write-term0 $Term1 1200 punct $_ $Style $S_or_a) - (put-char $S_or_a }))) + (put-char $S_or_a }))) +; + (= ($write-term0 $Term $Prec $Type0 punct $Style $S_or_a) ( (=.. $Term @@ -3172,20 +4223,30 @@ ($write-atom $F $Type0 $_ $Style $S_or_a) (put-char $S_or_a () ($write-term-args $Args punct $_ $Style $S_or_a) - (put-char $S_or_a )))) + (put-char $S_or_a )))) +; + (= ($write-space-if-needed punct $_ $_) - (set-det)) + (set-det)) +; + (= ($write-space-if-needed $X $X $S_or_a) - ( (set-det) (put-char $S_or_a ' '))) + ( (set-det) (put-char $S_or_a ' '))) +; + (= ($write-space-if-needed other alpha $S_or_a) - ( (set-det) (put-char $S_or_a ' '))) + ( (set-det) (put-char $S_or_a ' '))) +; + (= - ($write_space_if_needed $_ $_ $_) True) + (%write_space_if_needed $_ $_ $_) True) +; + (= @@ -3195,7 +4256,9 @@ (is $Letter (+ (mod $VN 26) "A")) - (put-code $S_or_a $Letter))) + (put-code $S_or_a $Letter))) +; + (= ($write-VAR $VN $S_or_a) ( (is $Letter @@ -3204,7 +4267,9 @@ (put-code $S_or_a $Letter) (is $Rest (// $VN 26)) - ($fast-write $S_or_a $Rest))) + ($fast-write $S_or_a $Rest))) +; + (= @@ -3214,26 +4279,38 @@ (set-det) ($atom-type $Atom $Type) ($write-space-if-needed $Type0 $Type $S_or_a) - ($fast-writeq $S_or_a $Atom))) + ($fast-writeq $S_or_a $Atom))) +; + (= ($write-atom $Atom $Type0 $Type $_ $S_or_a) ( ($atom-type $Atom $Type) ($write-space-if-needed $Type0 $Type $S_or_a) - ($fast-write $S_or_a $Atom))) + ($fast-write $S_or_a $Atom))) +; + (= ($atom-type $X alpha) - ( ($atom-type0 $X 0) (set-det))) + ( ($atom-type0 $X 0) (set-det))) +; + (= ($atom-type $X symbol) - ( ($atom-type0 $X 1) (set-det))) + ( ($atom-type0 $X 1) (set-det))) +; + (= ($atom-type $X punct) - ( ($atom-type0 $X 2) (set-det))) + ( ($atom-type0 $X 2) (set-det))) +; + (= ($atom-type $X other) - ( ($atom-type0 $X 3) (set-det))) + ( ($atom-type0 $X 3) (set-det))) +; + (= @@ -3243,23 +4320,39 @@ (current-op $_ $OpType $Op) (=.. $Term (Cons $_ $Args)) - (set-det))) + (set-det))) +; + (= - ($write_op_type 1 fx) True) + (%write_op_type 1 fx) True) +; + (= - ($write_op_type 1 fy) True) + (%write_op_type 1 fy) True) +; + (= - ($write_op_type 1 xf) True) + (%write_op_type 1 xf) True) +; + (= - ($write_op_type 1 yf) True) + (%write_op_type 1 yf) True) +; + (= - ($write_op_type 2 xfx) True) + (%write_op_type 2 xfx) True) +; + (= - ($write_op_type 2 xfy) True) + (%write_op_type 2 xfy) True) +; + (= - ($write_op_type 2 yfx) True) + (%write_op_type 2 yfx) True) +; + (= @@ -3270,10 +4363,14 @@ ($write-space-if-needed $Type0 punct $S_or_a) (put-char $S_or_a () ($write-term-op1 $Op $OpType $Args $PrecOp punct $_ $Style $S_or_a) - (put-char $S_or_a )))) + (put-char $S_or_a )))) +; + (= ($write-term-op $Op $OpType $Args $Prec $Type0 $Type $Style $S_or_a) - ( (current-op $PrecOp $OpType $Op) ($write-term-op1 $Op $OpType $Args $PrecOp $Type0 $Type $Style $S_or_a))) + ( (current-op $PrecOp $OpType $Op) ($write-term-op1 $Op $OpType $Args $PrecOp $Type0 $Type $Style $S_or_a))) +; + (= @@ -3283,14 +4380,18 @@ ($write-atom $Op $Type0 $Type1 $Style $S_or_a) (is $Prec1 (- $PrecOp 1)) - ($write-term0 $A1 $Prec1 $Type1 $Type $Style $S_or_a))) + ($write-term0 $A1 $Prec1 $Type1 $Type $Style $S_or_a))) +; + (= ($write-term-op1 $Op fy (:: $A1) $PrecOp $Type0 $Type $Style $S_or_a) ( (set-det) ($write-atom $Op $Type0 $Type1 $Style $S_or_a) (is $Prec1 $PrecOp) - ($write-term0 $A1 $Prec1 $Type1 $Type $Style $S_or_a))) + ($write-term0 $A1 $Prec1 $Type1 $Type $Style $S_or_a))) +; + (= ($write-term-op1 $Op xf (:: $A1) $PrecOp $Type0 $Type $Style $S_or_a) @@ -3298,14 +4399,18 @@ (is $Prec1 (- $PrecOp 1)) ($write-term0 $A1 $Prec1 $Type0 $Type1 $Style $S_or_a) - ($write-atom $Op $Type1 $Type $Style $S_or_a))) + ($write-atom $Op $Type1 $Type $Style $S_or_a))) +; + (= ($write-term-op1 $Op yf (:: $A1) $PrecOp $Type0 $Type $Style $S_or_a) ( (set-det) (is $Prec1 $PrecOp) ($write-term0 $A1 $Prec1 $Type0 $Type1 $Style $S_or_a) - ($write-atom $Op $Type1 $Type $Style $S_or_a))) + ($write-atom $Op $Type1 $Type $Style $S_or_a))) +; + (= ($write-term-op1 $Op xfx (:: $A1 $A2) $PrecOp $Type0 $Type $Style $S_or_a) @@ -3316,7 +4421,9 @@ (- $PrecOp 1)) ($write-term0 $A1 $Prec1 $Type0 $Type1 $Style $S_or_a) ($write-term-infix-op $Op $Type1 $Type2 $Style $S_or_a) - ($write-term0 $A2 $Prec2 $Type2 $Type $Style $S_or_a))) + ($write-term0 $A2 $Prec2 $Type2 $Type $Style $S_or_a))) +; + (= ($write-term-op1 $Op xfy (:: $A1 $A2) $PrecOp $Type0 $Type $Style $S_or_a) @@ -3326,7 +4433,9 @@ (is $Prec2 $PrecOp) ($write-term0 $A1 $Prec1 $Type0 $Type1 $Style $S_or_a) ($write-term-infix-op $Op $Type1 $Type2 $Style $S_or_a) - ($write-term0 $A2 $Prec2 $Type2 $Type $Style $S_or_a))) + ($write-term0 $A2 $Prec2 $Type2 $Type $Style $S_or_a))) +; + (= ($write-term-op1 $Op yfx (:: $A1 $A2) $PrecOp $Type0 $Type $Style $S_or_a) @@ -3336,17 +4445,23 @@ (- $PrecOp 1)) ($write-term0 $A1 $Prec1 $Type0 $Type1 $Style $S_or_a) ($write-term-infix-op $Op $Type1 $Type2 $Style $S_or_a) - ($write-term0 $A2 $Prec2 $Type2 $Type $Style $S_or_a))) + ($write-term0 $A2 $Prec2 $Type2 $Type $Style $S_or_a))) +; + (= ($write-term-infix-op , $Type0 punct $_ $S_or_a) ( (set-det) ($write-space-if-needed $Type0 punct $S_or_a) - (put-char $S_or_a ,))) + (put-char $S_or_a ,))) +; + (= ($write-term-infix-op $Op $Type0 $Type $Style $S_or_a) - ($write-atom $Op $Type0 $Type $Style $S_or_a)) + ($write-atom $Op $Type0 $Type $Style $S_or_a)) +; + (= @@ -3359,7 +4474,9 @@ ($write-term0 $A 999 $Type0 $Type1 $Style $S_or_a) ($write-space-if-needed $Type1 punct $S_or_a) (put-char $S_or_a ,) - ($write-term-list-args $As punct $Type $Style $S_or_a))) + ($write-term-list-args $As punct $Type $Style $S_or_a))) +; + (= ($write-term-list-args @@ -3367,7 +4484,9 @@ ( (nonvar $As) (= $As Nil) (set-det) - ($write-term0 $A 999 $Type0 $Type $Style $S_or_a))) + ($write-term0 $A 999 $Type0 $Type $Style $S_or_a))) +; + (= ($write-term-list-args @@ -3375,16 +4494,22 @@ ( ($write-term0 $A 999 $Type0 $Type1 $Style $S_or_a) ($write-space-if-needed $Type1 punct $S_or_a) (put-char $S_or_a |) - ($write-term0 $As 999 punct $Type $Style $S_or_a))) + ($write-term0 $As 999 punct $Type $Style $S_or_a))) +; + (= ($write-term-args Nil $Type $Type $_ $_) - (set-det)) + (set-det)) +; + (= ($write-term-args (:: $A) $Type0 $Type $Style $S_or_a) - ( (set-det) ($write-term0 $A 999 $Type0 $Type $Style $S_or_a))) + ( (set-det) ($write-term0 $A 999 $Type0 $Type $Style $S_or_a))) +; + (= ($write-term-args (Cons $A $As) $Type0 $Type $Style $S_or_a) @@ -3392,21 +4517,29 @@ ($write-term0 $A 999 $Type0 $Type1 $Style $S_or_a) ($write-space-if-needed $Type1 punct $S_or_a) (put-char $S_or_a ,) - ($write-term-args $As punct $Type $Style $S_or_a))) + ($write-term-args $As punct $Type $Style $S_or_a))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Term input/output (others) +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (/ op 3)) - !(public (/ current-op 3)) - !(dynamic (/ %current-operator 3)) + !(public (/ op 3)) +; + + !(public (/ current-op 3)) +; + + !(dynamic (/ %current-operator 3)) +; + (= @@ -3415,13 +4548,17 @@ (=< 0 $Priority) (=< $Priority 1200) (set-det) - ($op1 $Priority $Op_specifier $Operator))) + ($op1 $Priority $Op_specifier $Operator))) +; + (= (op $Priority $Op_specifier $Operator) (illarg (domain integer (- 0 1200)) - (op $Priority $Op_specifier $Operator) 1)) + (op $Priority $Op_specifier $Operator) 1)) +; + (= @@ -3429,11 +4566,15 @@ ( (nonvar $Op_specifier) ($op-specifier $Op_specifier $_) (set-det) - ($op2 $Priority $Op_specifier $Operator))) + ($op2 $Priority $Op_specifier $Operator))) +; + (= ($op1 $Priority $Op_specifier $Operator) ( (findall $X - ($op-specifier $X $_) $Domain) (illarg (domain term $Domain) (op $Priority $Op_specifier $Operator) 2))) + ($op-specifier $X $_) $Domain) (illarg (domain term $Domain) (op $Priority $Op_specifier $Operator) 2))) +; + (= @@ -3441,277 +4582,457 @@ ( (atom $Operator) (set-det) ($add-operators - (:: $Operator) $Priority $Op_specifier))) + (:: $Operator) $Priority $Op_specifier))) +; + (= ($op2 $Priority $Op_specifier $Operator) ( ($op-atom-list $Operator $Atoms) (set-det) - ($add-operators $Atoms $Priority $Op_specifier))) + ($add-operators $Atoms $Priority $Op_specifier))) +; + (= ($op2 $Priority $Op_specifier $Operator) (illarg (type (list is-symbol)) - (op $Priority $Op_specifier $Operator) 3)) + (op $Priority $Op_specifier $Operator) 3)) +; + (= ($add-operators Nil $_ $_) - (set-det)) + (set-det)) +; + (= ($add-operators (Cons $A $As) $Priority $Op_specifier) - ( ($add-op $A $Priority $Op_specifier) ($add-operators $As $Priority $Op_specifier))) + ( ($add-op $A $Priority $Op_specifier) ($add-operators $As $Priority $Op_specifier))) +; + (= ($add-op , $Priority $Op_specifier) - ( (set-det) (illarg (permission modify operator , $_) (op $Priority $Op_specifier ,) 3))) + ( (set-det) (illarg (permission modify operator , $_) (op $Priority $Op_specifier ,) 3))) +; + (= ($add-op $A $_ $Op_specifier) - ( (get-atoms &self + ( (get-symbols &self (= - ($current_operator $_ $Op_specifier0 $A) $_)) + (%current_operator $_ $Op_specifier0 $A) $_)) ($op-specifier $Op_specifier $Class) ($op-specifier $Op_specifier0 $Class0) (= $Class $Class0) - (remove-atom &self - ($current_operator $_ $Op_specifier0 $A)) - (fail))) + (remove-symbol &self + (%current_operator $_ $Op_specifier0 $A)) + (fail))) +; + (= ($add-op $_ 0 $_) - (set-det)) + (set-det)) +; + (= ($add-op $A $Priority $Op_specifier) - (add-atom &self - ($current_operator $Priority $Op_specifier $A))) + (add-symbol &self + (%current_operator $Priority $Op_specifier $A))) +; + (= - ($op_specifier fx prefix) True) + (%op_specifier fx prefix) True) +; + (= - ($op_specifier fy prefix) True) + (%op_specifier fy prefix) True) +; + (= - ($op_specifier xfx infix) True) + (%op_specifier xfx infix) True) +; + (= - ($op_specifier xfy infix) True) + (%op_specifier xfy infix) True) +; + (= - ($op_specifier yfx infix) True) + (%op_specifier yfx infix) True) +; + (= - ($op_specifier xf postfix) True) + (%op_specifier xf postfix) True) +; + (= - ($op_specifier yf postfix) True) + (%op_specifier yf postfix) True) +; + (= ($op-atom-list $X $_) ( (var $X) (set-det) - (fail))) + (fail))) +; + (= ($op-atom-list Nil Nil) - (set-det)) + (set-det)) +; + (= ($op-atom-list (Cons $X $Xs) (Cons $X $As)) ( (atom $X) (set-det) - ($op-atom-list $Xs $As))) + ($op-atom-list $Xs $As))) +; + (= (current-op $Priority $Op_specifier $Operator) - (get-atoms &self + (get-symbols &self (= - ($current_operator $Priority $Op_specifier $Operator) $_))) + (%current_operator $Priority $Op_specifier $Operator) $_))) +; + (= - ($current_operator 1200 xfx :-) True) + (%current_operator 1200 xfx :-) True) +; + (= - ($current_operator 1200 xfx -->) True) + (%current_operator 1200 xfx -->) True) +; + (= - ($current_operator 1200 fx :-) True) + (%current_operator 1200 fx :-) True) +; + (= - ($current_operator 1200 fx ?-) True) + (%current_operator 1200 fx ?-) True) +; + (= - ($current_operator 1150 fx package) True) + (%current_operator 1150 fx package) True) +; + (= - ($current_operator 1150 fx import) True) + (%current_operator 1150 fx import) True) +; + (= - ($current_operator 1150 fx include) True) + (%current_operator 1150 fx include) True) +; + (= - ($current_operator 1150 fx include_resource) True) + (%current_operator 1150 fx include_resource) True) +; + (= - ($current_operator 1150 fx constant) True) + (%current_operator 1150 fx constant) True) +; + (= - ($current_operator 1150 fx public) True) + (%current_operator 1150 fx public) True) +; + (= - ($current_operator 1150 fx dynamic) True) + (%current_operator 1150 fx dynamic) True) +; + (= - ($current_operator 1150 fx meta_predicate) True) + (%current_operator 1150 fx meta_predicate) True) +; + (= - ($current_operator 1150 fx mode) True) + (%current_operator 1150 fx mode) True) +; + (= - ($current_operator 1150 fx multifile) True) + (%current_operator 1150 fx multifile) True) +; + (= - ($current_operator 1150 fx block) True) + (%current_operator 1150 fx block) True) +; + (= - ($current_operator 1150 fx ifdef) True) + (%current_operator 1150 fx ifdef) True) +; + (= - ($current_operator 1150 fx ifndef) True) + (%current_operator 1150 fx ifndef) True) +; + (= - ($current_operator 1150 fx domain) True) + (%current_operator 1150 fx domain) True) +; + (= - ($current_operator 1150 fx database) True) + (%current_operator 1150 fx database) True) +; + (= - ($current_operator 1100 xfy ;) True) + (%current_operator 1100 xfy ;) True) +; + (= - ($current_operator 1050 xfy ->) True) + (%current_operator 1050 xfy ->) True) +; + (= - ($current_operator 1000 xfy ,) True) + (%current_operator 1000 xfy ,) True) +; + (= - ($current_operator 900 fy \+) True) + (%current_operator 900 fy \+) True) +; + (= - ($current_operator 700 xfx =) True) + (%current_operator 700 xfx =) True) +; + (= - ($current_operator 700 xfx \=) True) + (%current_operator 700 xfx \=) True) +; + (= - ($current_operator 700 xfx ==) True) + (%current_operator 700 xfx ==) True) +; + (= - ($current_operator 700 xfx \==) True) + (%current_operator 700 xfx \==) True) +; + (= - ($current_operator 700 xfx @<) True) + (%current_operator 700 xfx @<) True) +; + (= - ($current_operator 700 xfx @>) True) + (%current_operator 700 xfx @>) True) +; + (= - ($current_operator 700 xfx @=<) True) + (%current_operator 700 xfx @=<) True) +; + (= - ($current_operator 700 xfx @>=) True) + (%current_operator 700 xfx @>=) True) +; + (= - ($current_operator 700 xfx =..) True) + (%current_operator 700 xfx =..) True) +; + (= - ($current_operator 700 xfx is) True) + (%current_operator 700 xfx is) True) +; + (= - ($current_operator 700 xfx =:=) True) + (%current_operator 700 xfx =:=) True) +; + (= - ($current_operator 700 xfx =\=) True) + (%current_operator 700 xfx =\=) True) +; + (= - ($current_operator 700 xfx <) True) + (%current_operator 700 xfx <) True) +; + (= - ($current_operator 700 xfx >) True) + (%current_operator 700 xfx >) True) +; + (= - ($current_operator 700 xfx =<) True) + (%current_operator 700 xfx =<) True) +; + (= - ($current_operator 700 xfx >=) True) + (%current_operator 700 xfx >=) True) +; + (= - ($current_operator 550 xfy :) True) + (%current_operator 550 xfy :) True) +; + (= - ($current_operator 500 yfx +) True) + (%current_operator 500 yfx +) True) +; + (= - ($current_operator 500 yfx -) True) + (%current_operator 500 yfx -) True) +; + (= - ($current_operator 500 yfx #) True) + (%current_operator 500 yfx #) True) +; + (= - ($current_operator 500 yfx /\) True) + (%current_operator 500 yfx /\) True) +; + (= - ($current_operator 500 yfx \/) True) + (%current_operator 500 yfx \/) True) +; + (= - ($current_operator 500 fx +) True) + (%current_operator 500 fx +) True) +; + (= - ($current_operator 400 yfx *) True) + (%current_operator 400 yfx *) True) +; + (= - ($current_operator 400 yfx /) True) + (%current_operator 400 yfx /) True) +; + (= - ($current_operator 400 yfx //) True) + (%current_operator 400 yfx //) True) +; + (= - ($current_operator 400 yfx mod) True) + (%current_operator 400 yfx mod) True) +; + (= - ($current_operator 400 yfx rem) True) + (%current_operator 400 yfx rem) True) +; + (= - ($current_operator 400 yfx <<) True) + (%current_operator 400 yfx <<) True) +; + (= - ($current_operator 400 yfx >>) True) + (%current_operator 400 yfx >>) True) +; + (= - ($current_operator 300 xfx ~) True) + (%current_operator 300 xfx ~) True) +; + (= - ($current_operator 200 xfx **) True) + (%current_operator 200 xfx **) True) +; + (= - ($current_operator 200 xfy ^) True) + (%current_operator 200 xfy ^) True) +; + (= - ($current_operator 200 fy \) True) + (%current_operator 200 fy \) True) +; + (= - ($current_operator 200 fy -) True) + (%current_operator 200 fy -) True) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Logic and control +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (/ \+ 1)) - !(public (/ once 1)) - !(public (/ repeat 0)) + !(public (/ \+ 1)) +; + + !(public (/ once 1)) +; + + !(public (/ repeat 0)) +; + (= (not $G) ( (call $G) (set-det) - (fail))) + (fail))) +; + (= - (\+ $_) True) + (\+ $_) True) +; + - (= repeat True) + (= repeat True) +; + (= (repeat) - (repeat)) + (repeat)) +; + (= (once $G) - ( (call $G) (set-det))) + ( (call $G) (set-det))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Atomic term processing +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; :- public atom_length/2. written in Java +; ; -; :- public atom_concat/3. written in Java +; - !(public (/ sub-symbol 5)) + !(public (/ sub-symbol 5)) +; + ; -; :- public atom_chars/2, atom_codes/2. written in Java +; ; -; :- public char_code/2. written in Java +; ; -; :- public number_chars/2, number_codes/2. written in Java +; - !(public (/ name 2)) + !(public (/ name 2)) +; + ; -; :- public regex_compile/2. written in Java +; ; -; :- public regex_match/3. written in Java +; - !(public (/ regex-matches 3)) - !(public (/ regex-matches 2)) + !(public (/ regex-matches 3)) +; + + !(public (/ regex-matches 2)) +; + (= @@ -3720,58 +5041,80 @@ (atom-length $AtomL $Before) (atom-concat $Sub_atom $AtomR $X) (atom-length $Sub_atom $Length) - (atom-length $AtomR $After))) + (atom-length $AtomR $After))) +; + (= (name $Constant $Chars) - ( (nonvar $Constant) (det-if-then-else (number $Constant) (number-codes $Constant $Chars) (det-if-then-else (atomic $Constant) (atom-codes $Constant $Chars) (illarg (type symbolic) (name $Constant $Chars) 1))))) + ( (nonvar $Constant) (det-if-then-else (number $Constant) (number-codes $Constant $Chars) (det-if-then-else (atomic $Constant) (atom-codes $Constant $Chars) (illarg (type symbolic) (name $Constant $Chars) 1))))) +; + (= (name $Constant $Chars) - ( (var $Constant) (det-if-then-else (number-codes $Constant0 $Chars) (= $Constant $Constant0) (det-if-then-else (atom-codes $Constant0 $Chars) (= $Constant $Constant0) (illarg (type (list char)) (name $Constant $Chars) 2))))) + ( (var $Constant) (det-if-then-else (number-codes $Constant0 $Chars) (= $Constant $Constant0) (det-if-then-else (atom-codes $Constant0 $Chars) (= $Constant $Constant0) (illarg (type (list char)) (name $Constant $Chars) 2))))) +; + (= (regex-matches $_ Nil $_) - ( (set-det) (fail))) + ( (set-det) (fail))) +; + (= (regex-matches $Pattern $List $Result) ( (= $List (Cons $_ $_)) (set-det) - (regex-list $Pattern $List $Result))) + (regex-list $Pattern $List $Result))) +; + (= (regex-matches $Pattern $String $Result) ( (atom $String) (regex-compile $Pattern $Matcher) - (regex-match $Matcher $String $Result))) + (regex-match $Matcher $String $Result))) +; + (= (regex-matches $Pattern $String) - (once (regex-matches $Pattern $String $_))) + (once (regex-matches $Pattern $String $_))) +; + (= (regex-list $Pattern (Cons $H $_) $Result) - (regex-matches $Pattern $H $Result)) + (regex-matches $Pattern $H $Result)) +; + (= (regex-list $Pattern (Cons $_ $Ls) $Result) - (regex-list $Pattern $Ls $Result)) + (regex-list $Pattern $Ls $Result)) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Implementation defined hooks +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (/ set-prolog-flag 2)) - !(public (/ current-prolog-flag 2)) + !(public (/ set-prolog-flag 2)) +; + + !(public (/ current-prolog-flag 2)) +; + (= @@ -3779,23 +5122,31 @@ ( (var $Flag) (set-det) (illarg var - (set-prolog-flag $Flag $Value) 1))) + (set-prolog-flag $Flag $Value) 1))) +; + (= (set-prolog-flag $Flag $Value) ( (var $Value) (set-det) (illarg var - (set-prolog-flag $Flag $Value) 2))) + (set-prolog-flag $Flag $Value) 2))) +; + (= (set-prolog-flag $Flag $Value) ( (atom $Flag) (set-det) - ($set-prolog-flag0 $Flag $Value))) + ($set-prolog-flag0 $Flag $Value))) +; + (= (set-prolog-flag $Flag $Value) (illarg (type is-symbol) - (set-prolog-flag $Flag $Value) 1)) + (set-prolog-flag $Flag $Value) 1)) +; + (= @@ -3803,26 +5154,36 @@ ( ($prolog-impl-flag $Flag $Mode (changeable $YN)) (set-det) - ($set-prolog-flag0 $YN $Flag $Value $Mode))) + ($set-prolog-flag0 $YN $Flag $Value $Mode))) +; + (= ($set-prolog-flag0 $Flag $Value) (illarg (domain is-symbol prolog-flag) - (set-prolog-flag $Flag $Value) 1)) + (set-prolog-flag $Flag $Value) 1)) +; + (= ($set-prolog-flag0 no $Flag $Value $_) - ( (set-det) (illarg (permission modify flag $Flag $_) (set-prolog-flag $Flag $Value) $_))) + ( (set-det) (illarg (permission modify flag $Flag $_) (set-prolog-flag $Flag $Value) $_))) +; + (= ($set-prolog-flag0 $_ $Flag $Value $Mode) ( ($builtin-member $Value $Mode) (set-det) - ($set-prolog-impl-flag $Flag $Value))) + ($set-prolog-impl-flag $Flag $Value))) +; + (= ($set-prolog-flag0 $_ $Flag $Value $_) (illarg (domain is-symbol flag-value) - (set-prolog-flag $Flag $Value) 2)) + (set-prolog-flag $Flag $Value) 2)) +; + (= @@ -3830,7 +5191,9 @@ ( (var $Flag) (set-det) ($prolog-impl-flag $Flag $_ $_) - ($get-prolog-impl-flag $Flag $Term))) + ($get-prolog-impl-flag $Flag $Term))) +; + (= (current-prolog-flag $Flag $Term) ( (atom $Flag) @@ -3840,99 +5203,137 @@ ($get-prolog-impl-flag $Flag $Term) (illarg (domain is-symbol prolog-flag) - (current-prolog-flag $Flag $Term) 1)))) + (current-prolog-flag $Flag $Term) 1)))) +; + (= (current-prolog-flag $Flag $Term) (illarg (type is-symbol) - (current-prolog-flag $Flag $Term) 1)) + (current-prolog-flag $Flag $Term) 1)) +; + ; -; '$MeTTa_impl_flag'(bounded, _, changeable(no)). +; (= - ($prolog_impl_flag max_integer $_ - (changeable no)) True) + (%prolog_impl_flag max_integer $_ + (changeable no)) True) +; + (= - ($prolog_impl_flag min_integer $_ - (changeable no)) True) + (%prolog_impl_flag min_integer $_ + (changeable no)) True) +; + ; -; '$MeTTa_impl_flag'(integer_rounding_function, [down,toward_zero], changeable(no)). +; ; -; '$MeTTa_impl_flag'(char_conversion, [on,off], changeable(no)). +; (= - ($prolog_impl_flag debug + (%prolog_impl_flag debug (on off) - (changeable yes)) True) + (changeable yes)) True) +; + (= - ($prolog_impl_flag max_arity $_ - (changeable no)) True) + (%prolog_impl_flag max_arity $_ + (changeable no)) True) +; + (= - ($prolog_impl_flag unknown + (%prolog_impl_flag unknown (error fail warning) - (changeable yes)) True) + (changeable yes)) True) +; + (= - ($prolog_impl_flag double_quotes + (%prolog_impl_flag double_quotes (chars codes atom) - (changeable no)) True) + (changeable no)) True) +; + (= - ($prolog_impl_flag print_stack_trace + (%prolog_impl_flag print_stack_trace (on off) - (changeable yes)) True) + (changeable yes)) True) +; + - !(public (/ halt 0)) - !(public (/ abort 0)) + !(public (/ halt 0)) +; + + !(public (/ abort 0)) +; + (= (halt) - (halt 0)) + (halt 0)) +; + (= (abort) - (raise-exception 'Execution aborted')) + (raise-exception 'Execution aborted')) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; DCG +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (, (/ C 3) (/ expand-term 2))) + !(public (, (/ C 3) (/ expand-term 2))) +; + (= (C - (Cons $X $S) $X $S) True) + (Cons $X $S) $X $S) True) +; + (= (expand-term $Dcg $Cl) ( (var $Dcg) (set-det) - (= $Dcg $Cl))) + (= $Dcg $Cl))) +; + (= (expand-term $Dcg $Cl) ( ($dcg-expansion $Dcg $Cl0) (set-det) - (= $Cl0 $Cl))) + (= $Cl0 $Cl))) +; + (= - (expand_term $Dcg $Dcg) True) + (expand_term $Dcg $Dcg) True) +; + (= ($dcg-expansion $Dcg $Cl) ( (var $Dcg) (set-det) - (= $Dcg $Cl))) + (= $Dcg $Cl))) +; + (= ($dcg-expansion (--> $Head $B) @@ -3946,23 +5347,31 @@ (set-det) ($dcg-translation-atom $H $H1 $S0 $S1) ($dcg-translation $B $G1 $S0 $S) - ($dcg-translation $List $G2 $S1 $S))) + ($dcg-translation $List $G2 $S1 $S))) +; + (= ($dcg-expansion (--> $H $B) (= $H1 $B1)) - ( ($dcg-translation-atom $H $H1 $S0 $S) ($dcg-translation $B $B1 $S0 $S))) + ( ($dcg-translation-atom $H $H1 $S0 $S) ($dcg-translation $B $B1 $S0 $S))) +; + (= ($dcg-translation-atom $X (phrase $X $S0 $S) $S0 $S) - ( (var $X) (set-det))) + ( (var $X) (set-det))) +; + (= ($dcg-translation-atom (with_self $M $X) (with_self $M $X1) $S0 $S) - ( (set-det) ($dcg-translation-atom $X $X1 $S0 $S))) + ( (set-det) ($dcg-translation-atom $X $X1 $S0 $S))) +; + (= ($dcg-translation-atom $X $X1 $S0 $S) ( (=.. $X @@ -3970,192 +5379,264 @@ ($builtin-append $As (:: $S0 $S) $As1) (=.. $X1 - (Cons $F $As1)))) + (Cons $F $As1)))) +; + (= ($dcg-translation $X $Y $S0 $S) - ( ($dcg-trans $X $Y0 $T $S0 $S) ($dcg-trans0 $Y0 $Y $T $S0 $S))) + ( ($dcg-trans $X $Y0 $T $S0 $S) ($dcg-trans0 $Y0 $Y $T $S0 $S))) +; + (= ($dcg-trans0 $Y $Y $T $S0 $T) - ( (\== $T $S0) (set-det))) + ( (\== $T $S0) (set-det))) +; + (= ($dcg-trans0 $Y0 $Y $T $_ $S) ($dcg-concat $Y0 - (= $S $T) $Y)) + (= $S $T) $Y)) +; + (= ($dcg-concat $X $Y $Z) ( (== $X True) (set-det) - (= $Z $Y))) + (= $Z $Y))) +; + (= ($dcg-concat $X $Y $Z) ( (== $Y True) (set-det) - (= $Z $X))) + (= $Z $X))) +; + (= - ($dcg_concat $X $Y - (, $X $Y)) True) + (%dcg_concat $X $Y + (, $X $Y)) True) +; + (= ($dcg-trans $X $X1 $S $S0 $S) ( (var $X) (set-det) - ($dcg-translation-atom $X $X1 $S0 $S))) + ($dcg-translation-atom $X $X1 $S0 $S))) +; + (= ($dcg-trans (with_self $M $X) (with_self $M $Y) $T $S0 $S) - ( (set-det) ($dcg-trans $X $Y $T $S0 $S))) + ( (set-det) ($dcg-trans $X $Y $T $S0 $S))) +; + (= ($dcg-trans Nil True $S0 $S0 $_) - (set-det)) + (set-det)) +; + (= ($dcg-trans (Cons $X $Y) $Z $T $S0 $S) ( (set-det) ($dcg-trans $Y $Y1 $T $S1 $S) ($dcg-concat - (C $S0 $X $S1) $Y1 $Z))) + (C $S0 $X $S1) $Y1 $Z))) +; + (= ($dcg-trans (not $X) (det-if-then-else $X1 fail (= $S $S0)) $S $S0 $S) - ( (set-det) ($dcg-trans $X $X1 $S1 $S0 $S1))) + ( (set-det) ($dcg-trans $X $X1 $S1 $S0 $S1))) +; + (= ($dcg-trans (, $X $Y) $Z $T $S0 $S) ( (set-det) ($dcg-trans $X $X1 $S1 $S0 $S1) ($dcg-trans $Y $Y1 $T $S1 $S) - ($dcg-concat $X1 $Y1 $Z))) + ($dcg-concat $X1 $Y1 $Z))) +; + (= ($dcg-trans (det-if-then $X $Y) (det-if-then $X1 $Y1) $T $S0 $S) ( (set-det) ($dcg-trans $X $X1 $S1 $S0 $S1) - ($dcg-trans $Y $Y1 $T $S1 $S))) + ($dcg-trans $Y $Y1 $T $S1 $S))) +; + (= ($dcg-trans (or $X $Y) (or $X1 $Y1) $S $S0 $S) ( (set-det) ($dcg-translation $X $X1 $S0 $S) - ($dcg-translation $Y $Y1 $S0 $S))) + ($dcg-translation $Y $Y1 $S0 $S))) +; + (= ($dcg-trans (set-det) (set-det) $S0 $S0 $_) - (set-det)) + (set-det)) +; + (= ($dcg-trans {$G } (call $G) $S0 $S0 $_) - ( (var $G) (set-det))) + ( (var $G) (set-det))) +; + (= ($dcg-trans {$G } $G $S0 $S0 $_) - (set-det)) + (set-det)) +; + (= ($dcg-trans $X $X1 $S $S0 $S) - ($dcg-translation-atom $X $X1 $S0 $S)) + ($dcg-translation-atom $X $X1 $S0 $S)) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Hash creation and control +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (/ new-hash 1)) - !(public (/ hash-map 2)) - !(public (/ hash-exists 1)) + !(public (/ new-hash 1)) +; + + !(public (/ hash-map 2)) +; + + !(public (/ hash-exists 1)) +; + (= (new-hash $Hash) - (new-hash $Hash Nil)) + (new-hash $Hash Nil)) +; + (= (hash-map $H_or_a $List) ( (hash-keys $H_or_a $Ks0) (sort $Ks0 $Ks) - (hash-map $Ks $List $H_or_a))) + (hash-map $Ks $List $H_or_a))) +; + (= (hash-map Nil Nil $_) - (set-det)) + (set-det)) +; + (= (hash-map (Cons $K $Ks) (Cons (, $K $V) $Ls) $H_or_a) - ( (hash-get $H_or_a $K $V) (hash-map $Ks $Ls $H_or_a))) + ( (hash-get $H_or_a $K $V) (hash-map $Ks $Ls $H_or_a))) +; + (= (hash-exists $Alias) ( (atom $Alias) ($get-hash-manager $HM) - (hash-contains-key $HM $Alias))) + (hash-contains-key $HM $Alias))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Java interoperation +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; :- public java_constructor0/2. (written in Java) +; ; -; :- public java_declared_constructor0/2. (written in Java) +; ; -; :- public java_method0/3. (written in Java) +; ; -; :- public java_declared_method0/3. (written in Java) +; ; -; :- public java_get_field0/3. (written in Java) +; ; -; :- public java_get_declared_field0/3. (written in Java) +; ; -; :- public java_set_field0/3. (written in Java) +; ; -; :- public java_set_declared_field0/3. (written in Java) +; ; -; :- public java_conversion/2. (written in Java) +; - !(public (/ java-constructor 2)) - !(public (/ java-declared-constructor 2)) - !(public (/ java-method 3)) - !(public (/ java-declared-method 3)) - !(public (/ java-get-field 3)) - !(public (/ java-get-declared-field 3)) - !(public (/ java-set-field 3)) - !(public (/ java-set-declared-field 3)) - !(public (/ synchronized 2)) + !(public (/ java-constructor 2)) +; + + !(public (/ java-declared-constructor 2)) +; + + !(public (/ java-method 3)) +; + + !(public (/ java-declared-method 3)) +; + + !(public (/ java-get-field 3)) +; + + !(public (/ java-get-declared-field 3)) +; + + !(public (/ java-set-field 3)) +; + + !(public (/ java-set-declared-field 3)) +; + + !(public (/ synchronized 2)) +; + (= @@ -4166,7 +5647,9 @@ (=.. $Constr1 (Cons $F $As1)) (java-constructor0 $Constr1 $Instance1) - (= $Instance $Instance1))) + (= $Instance $Instance1))) +; + (= @@ -4177,7 +5660,9 @@ (=.. $Constr1 (Cons $F $As1)) (java-declared-constructor0 $Constr1 $Instance1) - (= $Instance $Instance1))) + (= $Instance $Instance1))) +; + (= @@ -4189,7 +5674,9 @@ (Cons $F $As1)) (java-method0 $Class_or_Instance $Method1 $Value1) (java-conversion $Value2 $Value1) - (= $Value $Value2))) + (= $Value $Value2))) +; + (= @@ -4201,93 +5688,165 @@ (Cons $F $As1)) (java-declared-method0 $Class_or_Instance $Method1 $Value1) (java-conversion $Value2 $Value1) - (= $Value $Value2))) + (= $Value $Value2))) +; + (= (java-get-field $Class_or_Instance $Field $Value) ( (java-get-field0 $Class_or_Instance $Field $Value1) (java-conversion $Value2 $Value1) - (= $Value $Value2))) + (= $Value $Value2))) +; + (= (java-get-declared-field $Class_or_Instance $Field $Value) ( (java-get-declared-field0 $Class_or_Instance $Field $Value1) (java-conversion $Value2 $Value1) - (= $Value $Value2))) + (= $Value $Value2))) +; + (= (java-set-field $Class_or_Instance $Field $Value) - ( (java-conversion $Value $Value1) (java-set-field0 $Class_or_Instance $Field $Value1))) + ( (java-conversion $Value $Value1) (java-set-field0 $Class_or_Instance $Field $Value1))) +; + (= (java-set-declared-field $Class_or_Instance $Field $Value) - ( (java-conversion $Value $Value1) (java-set-declared-field0 $Class_or_Instance $Field $Value1))) + ( (java-conversion $Value $Value1) (java-set-declared-field0 $Class_or_Instance $Field $Value1))) +; + (= (builtin-java-convert-args Nil Nil) - (set-det)) + (set-det)) +; + (= (builtin-java-convert-args (Cons $X $Xs) (Cons $Y $Ys)) - ( (java-conversion $X $Y) (builtin-java-convert-args $Xs $Ys))) + ( (java-conversion $X $Y) (builtin-java-convert-args $Xs $Ys))) +; + (= (synchronized $Object $Goal) ( ($begin-sync $Object $Ref) (call $Goal) - ($end-sync $Ref))) + ($end-sync $Ref))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; MeTTa interpreter +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(op 1170 xfx :-) - !(op 1170 xfx -->) - !(op 1170 fx :-) - !(op 1170 fx ?-) + !(op 1170 xfx :-) +; + + !(op 1170 xfx -->) +; + + !(op 1170 fx :-) +; + + !(op 1170 fx ?-) +; + + + !(op 1150 fx package) +; + + !(op 1150 fx import) +; + + !(op 1150 fx public) +; + + !(op 1150 fx dynamic) +; + + !(op 1150 fx meta-predicate) +; + + !(op 1150 fx mode) +; + + !(op 1150 fx multifile) +; + + !(op 1150 fx block) +; + + + !(public (/ cafeteria 0)) +; + + !(public (/ consult 1)) +; + + !(public (/ consult-stream 1)) +; + + !(public (, (/ trace 0) (/ notrace 0))) +; + + !(public (, (/ debug 0) (/ nodebug 0))) +; + + !(public (/ leash 1)) +; + + !(public (, (/ spy 1) (/ nospy 1) (/ nospyall 0))) +; - !(op 1150 fx package) - !(op 1150 fx import) - !(op 1150 fx public) - !(op 1150 fx dynamic) - !(op 1150 fx meta-predicate) - !(op 1150 fx mode) - !(op 1150 fx multifile) - !(op 1150 fx block) + !(public (/ listing 0)) +; + + !(public (/ listing 1)) +; + + + !(dynamic (/ %current-leash 1)) +; + + !(dynamic (/ %current-spypoint 3)) +; + + !(dynamic (/ %leap-flag 1)) +; + + !(dynamic (/ %consulted-file 1)) +; + + !(dynamic (/ %consulted-import 2)) +; + + !(dynamic (/ %consulted-package 1)) +; - !(public (/ cafeteria 0)) - !(public (/ consult 1)) - !(public (/ consult-stream 1)) - !(public (, (/ trace 0) (/ notrace 0))) - !(public (, (/ debug 0) (/ nodebug 0))) - !(public (/ leash 1)) - !(public (, (/ spy 1) (/ nospy 1) (/ nospyall 0))) - !(public (/ listing 0)) - !(public (/ listing 1)) + !(dynamic (/ %consulted-predicate 3)) +; - !(dynamic (/ %current-leash 1)) - !(dynamic (/ %current-spypoint 3)) - !(dynamic (/ %leap-flag 1)) - !(dynamic (/ %consulted-file 1)) - !(dynamic (/ %consulted-import 2)) - !(dynamic (/ %consulted-package 1)) - !(dynamic (/ %consulted-predicate 3)) ; -; ;; Main +; (= @@ -4302,34 +5861,38 @@ (set-det) (nl) ($fast-write bye) - (nl))) + (nl))) +; + (= (%cafeteria-init) - ( (remove-all-atoms &self - ($leap_flag $_)) - (remove-all-atoms &self - ($current_leash $_)) - (remove-all-atoms &self - ($current_spypoint $_ $_ $_)) - (remove-all-atoms &self - ($consulted_file $_)) - (remove-all-atoms &self - ($consulted_package $_)) - (remove-all-atoms &self - ($consulted_predicate $_ $_ $_)) - (add-atom &self - ($leap_flag no)) - (add-atom &self - ($current_leash call)) - (add-atom &self - ($current_leash exit)) - (add-atom &self - ($current_leash redo)) - (add-atom &self - ($current_leash fail)) - (set-det))) + ( (remove-all-symbols &self + (%leap_flag $_)) + (remove-all-symbols &self + (%current_leash $_)) + (remove-all-symbols &self + (%current_spypoint $_ $_ $_)) + (remove-all-symbols &self + (%consulted_file $_)) + (remove-all-symbols &self + (%consulted_package $_)) + (remove-all-symbols &self + (%consulted_predicate $_ $_ $_)) + (add-symbol &self + (%leap_flag no)) + (add-symbol &self + (%current_leash call)) + (add-symbol &self + (%current_leash exit)) + (add-symbol &self + (%current_leash redo)) + (add-symbol &self + (%current_leash fail)) + (set-det))) +; + (= @@ -4340,12 +5903,16 @@ (print-message info (:: debug))) ($fast-write | ?- ) - (flush-output))) + (flush-output))) +; + (= ($cafeteria $Goal) - ( (read-with-variables $Goal $Vars) ($process-order $Goal $Vars))) + ( (read-with-variables $Goal $Vars) ($process-order $Goal $Vars))) +; + (= @@ -4353,14 +5920,20 @@ ( (var $G) (set-det) (illarg var - (?- $G) 1))) + (?- $G) 1))) +; + (= ($process-order end-of-file $_) - (set-det)) + (set-det)) +; + (= ($process-order (Cons $File $Files) $_) - ( (set-det) (consult (Cons $File $Files)))) + ( (set-det) (consult (Cons $File $Files)))) +; + (= ($process-order $G $Vars) ( (current-prolog-flag debug $Mode) @@ -4373,32 +5946,44 @@ ($give-answers-with-prompt $Vars1) (set-det) ($fast-write yes) - (nl))) + (nl))) +; + (= ($process-order $_ $_) ( (nl) ($fast-write no) - (nl))) + (nl))) +; + (= ($rm-redundant-vars Nil Nil) - (set-det)) + (set-det)) +; + (= ($rm-redundant-vars (Cons (= - $_) $Xs) $Vs) - ( (set-det) ($rm-redundant-vars $Xs $Vs))) + ( (set-det) ($rm-redundant-vars $Xs $Vs))) +; + (= ($rm-redundant-vars (Cons $X $Xs) (Cons $X $Vs)) - ($rm-redundant-vars $Xs $Vs)) + ($rm-redundant-vars $Xs $Vs)) +; + (= ($give-answers-with-prompt Nil) - (set-det)) + (set-det)) +; + (= ($give-answers-with-prompt $Vs) ( ($give-an-answer $Vs) @@ -4406,31 +5991,41 @@ (flush-output) (read-line $Str) (\== $Str ";") - (nl))) + (nl))) +; + (= ($give-an-answer Nil) - ( (set-det) ($fast-write True))) + ( (set-det) ($fast-write True))) +; + (= ($give-an-answer (:: $X)) - ( (set-det) ('$print-an answer' $X))) + ( (set-det) ('$print-an answer' $X))) +; + (= ($give-an-answer (Cons $X $Xs)) ( ('$print-an answer' $X) ($fast-write ,) (nl) - ($give-an-answer $Xs))) + ($give-an-answer $Xs))) +; + (= ('$print-an answer' (= $N $V)) ( (write $N) ($fast-write = ) - (writeq $V))) + (writeq $V))) +; + ; -; ;; Read Program +; (= @@ -4438,20 +6033,28 @@ ( (var $Files) (set-det) (illarg var - (consult $Files) 1))) + (consult $Files) 1))) +; + (= (consult Nil) - (set-det)) + (set-det)) +; + (= (consult (Cons $File $Files)) ( (set-det) (consult $File) - (consult $Files))) + (consult $Files))) +; + (= (consult $File) ( (atom $File) (set-det) - ($consult $File))) + ($consult $File))) +; + (= @@ -4468,7 +6071,9 @@ (:: $_ $T)) (print-message info (:: $File consulted $T msec)) - (close $In))) + (close $In))) +; + (= @@ -4478,108 +6083,154 @@ (read $In $Cl) ($consult-clause $Cl) (== $Cl end-of-file) - (set-det))) + (set-det))) +; + (= ($prolog-file-name $File $File) ( (sub-atom $File $_ $_ $After .) (> $After 0) - (set-det))) + (set-det))) +; + (= ($prolog-file-name $File0 $File) - (atom-concat $File0 .pl $File)) + (atom-concat $File0 .pl $File)) +; + (= ($consult-init $File) - ( (remove-all-atoms &self - ($consulted_file $_)) - (remove-all-atoms &self - ($consulted_package $_)) - (remove-all-atoms &self - ($consulted_import $File $_)) - (remove-atom &self - ($consulted_predicate $P $PI $File)) + ( (remove-all-symbols &self + (%consulted_file $_)) + (remove-all-symbols &self + (%consulted_package $_)) + (remove-all-symbols &self + (%consulted_import $File $_)) + (remove-symbol &self + (%consulted_predicate $P $PI $File)) (abolish (with_self $P $PI)) - (fail))) + (fail))) +; + (= ($consult-init $File) - ( (add-atom &self - ($consulted_file $File)) (add-atom &self ($consulted_package user)))) + ( (add-symbol &self + (%consulted_file $File)) (add-symbol &self (%consulted_package user)))) +; + (= ($consult-clause end-of-file) - (set-det)) + (set-det)) +; + (= ($consult-clause !(module $P $_)) - ( (set-det) ($assert-consulted-package $P))) + ( (set-det) ($assert-consulted-package $P))) +; + (= ($consult-clause !(package $P)) - ( (set-det) ($assert-consulted-package $P))) + ( (set-det) ($assert-consulted-package $P))) +; + (= ($consult-clause !(import $P)) - ( (set-det) ($assert-consulted-import $P))) + ( (set-det) ($assert-consulted-import $P))) +; + (= ($consult-clause !(dynamic $_)) - (set-det)) + (set-det)) +; + (= ($consult-clause !(public $_)) - (set-det)) + (set-det)) +; + (= ($consult-clause !(meta-predicate $_)) - (set-det)) + (set-det)) +; + (= ($consult-clause !(mode $_)) - (set-det)) + (set-det)) +; + (= ($consult-clause !(multifile $_)) - (set-det)) + (set-det)) +; + (= ($consult-clause !(block $_)) - (set-det)) + (set-det)) +; + (= ($consult-clause !$G) ( (set-det) - (get-atoms &self + (get-symbols &self (= - ($consulted_package $P) $_)) - (once (with_self $P $G)))) + (%consulted_package $P) $_)) + (once (with_self $P $G)))) +; + (= ($consult-clause $Clause0) - ( ($consult-preprocess $Clause0 $Clause) ($consult-cls $Clause))) + ( ($consult-preprocess $Clause0 $Clause) ($consult-cls $Clause))) +; + (= ($assert-consulted-package $P) - ( (get-atoms &self + ( (get-symbols &self (= - ($consulted_package $P) $_)) (set-det))) + (%consulted_package $P) $_)) (set-det))) +; + (= ($assert-consulted-package $P) - ( (remove-all-atoms &self - ($consulted_package $_)) (add-atom &self ($consulted_package $P)))) + ( (remove-all-symbols &self + (%consulted_package $_)) (add-symbol &self (%consulted_package $P)))) +; + (= ($assert-consulted-import $P) - ( (get-atoms &self + ( (get-symbols &self (= - ($consulted_file $File) $_)) (add-atom &self ($consulted_import $File $P)))) + (%consulted_file $File) $_)) (add-symbol &self (%consulted_import $File $P)))) +; + (= ($consult-preprocess $Clause0 $Clause) - (expand-term $Clause0 $Clause)) + (expand-term $Clause0 $Clause)) +; + (= ($consult-cls (= $H $G)) - ( (set-det) ($assert-consulted-clause (= $H $G)))) + ( (set-det) ($assert-consulted-clause (= $H $G)))) +; + (= ($consult-cls $H) - ($assert-consulted-clause (= $H True))) + ($assert-consulted-clause (= $H True))) +; + (= @@ -4587,77 +6238,93 @@ ( (= $Clause (= $H $_)) (functor $H $F $A) - (get-atoms &self + (get-symbols &self (= - ($consulted_file $File) $_)) - (get-atoms &self + (%consulted_file $File) $_)) + (get-symbols &self (= - ($consulted_package $P) $_)) - (add-atom &self + (%consulted_package $P) $_)) + (add-symbol &self (: $P $Clause)) - (add-atom &self - ($consulted_predicate $P + (add-symbol &self + (%consulted_predicate $P (/ $F $A) $File)) - (set-det))) + (set-det))) +; + ; -; ;; Trace +; (= (trace) - ( (current-prolog-flag debug on) (set-det))) + ( (current-prolog-flag debug on) (set-det))) +; + (= (trace) ( (set-prolog-flag debug on) (%trace-init) ($fast-write '{Small debugger is switch on}') (nl) - (set-det))) + (set-det))) +; + (= (%trace-init) - ( (remove-all-atoms &self - ($leap_flag $_)) - (remove-all-atoms &self - ($current_leash $_)) - (remove-all-atoms &self - ($current_spypoint $_ $_ $_)) - (add-atom &self - ($leap_flag no)) - (add-atom &self - ($current_leash call)) - (add-atom &self - ($current_leash exit)) - (add-atom &self - ($current_leash redo)) - (add-atom &self - ($current_leash fail)) - (set-det))) + ( (remove-all-symbols &self + (%leap_flag $_)) + (remove-all-symbols &self + (%current_leash $_)) + (remove-all-symbols &self + (%current_spypoint $_ $_ $_)) + (add-symbol &self + (%leap_flag no)) + (add-symbol &self + (%current_leash call)) + (add-symbol &self + (%current_leash exit)) + (add-symbol &self + (%current_leash redo)) + (add-symbol &self + (%current_leash fail)) + (set-det))) +; + (= (notrace) - ( (current-prolog-flag debug off) (set-det))) + ( (current-prolog-flag debug off) (set-det))) +; + (= (notrace) ( (set-prolog-flag debug off) ($fast-write '{Small debugger is switch off}') (nl) - (set-det))) + (set-det))) +; + (= (debug) - (trace)) + (trace)) +; + (= (nodebug) - (notrace)) + (notrace)) +; + ; -; ;; Spy-Points +; (= @@ -4667,38 +6334,46 @@ (trace) ($assert-spypoint $PI) ($set-debug-flag leap yes) - (set-det))) + (set-det))) +; + (= ($assert-spypoint (with_self $P (/ $F $A))) - ( (get-atoms &self + ( (get-symbols &self (= - ($current_spypoint $P $F $A) $_)) + (%current_spypoint $P $F $A) $_)) (print-message info (:: spypoint (with_self $P (/ $F $A)) is already added)) - (set-det))) + (set-det))) +; + (= ($assert-spypoint (with_self $P (/ $F $A))) - ( (get-atoms &self + ( (get-symbols &self (= - ($consulted_predicate $P + (%consulted_predicate $P (/ $F $A) $_) $_)) - (add-atom &self - ($current_spypoint $P $F $A)) + (add-symbol &self + (%current_spypoint $P $F $A)) (print-message info (:: spypoint (with_self $P (/ $F $A)) is added)) - (set-det))) + (set-det))) +; + (= ($assert-spypoint (with_self $P (/ $F $A))) (print-message warning (:: no matching predicate for spy (with_self $P - (/ $F $A))))) + (/ $F $A))))) +; + (= @@ -4707,133 +6382,177 @@ (nospy $T)) ($retract-spypoint $PI) ($set-debug-flag leap no) - (set-det))) + (set-det))) +; + (= ($retract-spypoint (with_self $P (/ $F $A))) - ( (remove-atom &self - ($current_spypoint $P $F $A)) + ( (remove-symbol &self + (%current_spypoint $P $F $A)) (print-message info (:: spypoint (with_self $P (/ $F $A)) is removed)) - (set-det))) + (set-det))) +; + (= - ($retract_spypoint $_) True) + (%retract_spypoint $_) True) +; + (= (nospyall) - ( (remove-all-atoms &self - ($current_spypoint $_ $_ $_)) ($set-debug-flag leap no))) + ( (remove-all-symbols &self + (%current_spypoint $_ $_ $_)) ($set-debug-flag leap no))) +; + ; -; ;; Leash +; (= (leash $L) ( (nonvar $L) ($leash $L) - (set-det))) + (set-det))) +; + (= (leash $L) (illarg (type leash-specifier) - (leash $L) 1)) + (leash $L) 1)) +; + (= ($leash Nil) ( (set-det) - (remove-all-atoms &self - ($current_leash $_)) + (remove-all-symbols &self + (%current_leash $_)) (print-message info - (:: no leashing)))) + (:: no leashing)))) +; + (= ($leash $Ms) - ( (remove-all-atoms &self - ($current_leash $_)) + ( (remove-all-symbols &self + (%current_leash $_)) ($assert-leash $Ms) (print-message info - (:: leashing stopping on $Ms)))) + (:: leashing stopping on $Ms)))) +; + (= ($assert-leash Nil) - (set-det)) + (set-det)) +; + (= ($assert-leash (Cons $X $Xs)) ( ($leash-specifier $X) - (add-atom &self - ($current_leash $X)) - ($assert-leash $Xs))) + (add-symbol &self + (%current_leash $X)) + ($assert-leash $Xs))) +; + (= - ($leash_specifier call) True) + (%leash_specifier call) True) +; + (= - ($leash_specifier exit) True) + (%leash_specifier exit) True) +; + (= - ($leash_specifier redo) True) + (%leash_specifier redo) True) +; + (= - ($leash_specifier fail) True) + (%leash_specifier fail) True) +; + ; -; '$leash_specifier'(exception). +; ; -; ;; Trace a Goal +; (= ($trace-goal $Term) ( ($set-debug-flag leap no) ($get-current-B $Cut) - ($meta-call $Term user $Cut 0 trace))) + ($meta-call $Term user $Cut 0 trace))) +; + (= ($trace-goal $X $P $FA $Depth) ( (print-procedure-box call $X $P $FA $Depth) ($call-internal $X $P $FA $Depth trace) (print-procedure-box exit $X $P $FA $Depth) - (redo-procedure-box $X $P $FA $Depth))) + (redo-procedure-box $X $P $FA $Depth))) +; + (= ($trace-goal $X $P $FA $Depth) - ( (print-procedure-box fail $X $P $FA $Depth) (fail))) + ( (print-procedure-box fail $X $P $FA $Depth) (fail))) +; + (= (print-procedure-box $Mode $G $P (/ $F $A) $Depth) - ( (get-atoms &self + ( (get-symbols &self (= - ($current_spypoint $P $F $A) $_)) + (%current_spypoint $P $F $A) $_)) (set-det) ($builtin-message (:: + $Depth $Mode : (with_self $P $G))) - ($read-blocked (print-procedure-box $Mode $G $P (/ $F $A) $Depth)))) + ($read-blocked (print-procedure-box $Mode $G $P (/ $F $A) $Depth)))) +; + (= (print-procedure-box $Mode $G $P $FA $Depth) - ( (get-atoms &self + ( (get-symbols &self (= - ($leap_flag no) $_)) + (%leap_flag no) $_)) (set-det) ($builtin-message (:: ' ' $Depth $Mode : (with_self $P $G))) (det-if-then-else - (get-atoms &self + (get-symbols &self (= - ($current_leash $Mode) $_)) - ($read-blocked (print-procedure-box $Mode $G $P $FA $Depth)) nl))) + (%current_leash $Mode) $_)) + ($read-blocked (print-procedure-box $Mode $G $P $FA $Depth)) nl))) +; + (= - (print_procedure_box $_ $_ $_ $_ $_) True) + (print_procedure_box $_ $_ $_ $_ $_) True) +; + (= - (redo_procedure_box $_ $_ $_ $_) True) + (redo_procedure_box $_ $_ $_ $_) True) +; + (= (redo-procedure-box $X $P $FA $Depth) - ( (print-procedure-box redo $X $P $FA $Depth) (fail))) + ( (print-procedure-box redo $X $P $FA $Depth) (fail))) +; + (= @@ -4846,25 +6565,33 @@ (= $DOP 99) (= $C (Cons $DOP $_))) - ($debug-option $DOP $G))) + ($debug-option $DOP $G))) +; + (= ($debug-option 97 $_) ( (set-det) (notrace) - (abort))) ; -; a for abort + (abort))) +; + ; +; (= ($debug-option 99 $_) - ( (set-det) ($set-debug-flag leap no))) ; -; c for creep + ( (set-det) ($set-debug-flag leap no))) +; + ; +; (= ($debug-option 108 $_) - ( (set-det) ($set-debug-flag leap yes))) ; -; l for leap + ( (set-det) ($set-debug-flag leap yes))) +; + ; +; (= ($debug-option 43 @@ -4872,8 +6599,7 @@ ( (set-det) (spy (with_self $P $FA)) (call (print-procedure-box $Mode $G $P $FA $Depth)))) -; ; + for spy this - +; (= ($debug-option 45 @@ -4881,21 +6607,26 @@ ( (set-det) (nospy (with_self $P $FA)) (call (print-procedure-box $Mode $G $P $FA $Depth)))) -; ; - for nospy this - +; (= ($debug-option 63 $G) ( (set-det) (%show-debug-option) - (call $G))) + (call $G))) +; + (= ($debug-option 104 $G) ( (set-det) (%show-debug-option) - (call $G))) + (call $G))) +; + (= - ($debug_option $_ $_) True) + (%debug_option $_ $_) True) +; + (= @@ -4926,58 +6657,78 @@ (nl) (tab 4) ($fast-write 'h help') - (nl))) + (nl))) +; + (= ($set-debug-flag leap $Flag) - ( (get-atoms &self + ( (get-symbols &self (= - ($leap_flag $Flag) $_)) (set-det))) + (%leap_flag $Flag) $_)) (set-det))) +; + (= ($set-debug-flag leap $Flag) - ( (remove-all-atoms &self - ($leap_flag $_)) (add-atom &self ($leap_flag $Flag)))) + ( (remove-all-symbols &self + (%leap_flag $_)) (add-symbol &self (%leap_flag $Flag)))) +; + ; -; ;; Listing +; (= (listing) - ($listing $_ user)) + ($listing $_ user)) +; + (= (listing $T) ( (var $T) (set-det) (illarg var - (listing $T) 1))) + (listing $T) 1))) +; + (= (listing $P) ( (atom $P) (set-det) - ($listing $_ $P))) + ($listing $_ $P))) +; + (= (listing (/ $F $A)) - ( (set-det) ($listing (/ $F $A) user))) + ( (set-det) ($listing (/ $F $A) user))) +; + (= (listing (with_self $P $PI)) ( (atom $P) (set-det) - ($listing $PI $P))) + ($listing $PI $P))) +; + (= (listing $T) (illarg (type predicate-indicator) - (listing $T) 1)) + (listing $T) 1)) +; + (= ($listing $PI $P) ( (var $PI) (set-det) - ($listing-dynamic-clause $P $_))) + ($listing-dynamic-clause $P $_))) +; + (= ($listing (/ $F $A) $P) @@ -4985,12 +6736,16 @@ (integer $A) (set-det) ($listing-dynamic-clause $P - (/ $F $A)))) + (/ $F $A)))) +; + (= ($listing $PI $P) (illarg (type predicate-indicator) - (listing (with_self $P $PI)) 1)) + (listing (with_self $P $PI)) 1)) +; + (= @@ -5003,16 +6758,22 @@ (functor $H $F $A) ($clause-internal $P $PI $H $Cl $_) ($write-dynamic-clause $P $Cl) - (fail))) + (fail))) +; + (= - ($listing_dynamic_clause $_ $_) True) + (%listing_dynamic_clause $_ $_) True) +; + (= ($write-dynamic-clause $_ $Cl) ( (var $Cl) (set-det) - (fail))) + (fail))) +; + (= ($write-dynamic-clause $P (= $H True)) @@ -5020,7 +6781,9 @@ (numbervars $H 0 $_) ($write-dynamic-head $P $H) (write .) - (nl))) + (nl))) +; + (= ($write-dynamic-clause $P (= $H $B)) @@ -5032,17 +6795,23 @@ (nl) ($write-dynamic-body $B 8) (write .) - (nl))) + (nl))) +; + (= ($write-dynamic-head user $H) - ( (set-det) (writeq $H))) + ( (set-det) (writeq $H))) +; + (= ($write-dynamic-head $P $H) ( (write $P) (write :) - (writeq $H))) + (writeq $H))) +; + (= @@ -5052,7 +6821,9 @@ ($write-dynamic-body $G1 $N) (write ,) (nl) - ($write-dynamic-body $G2 $N))) + ($write-dynamic-body $G2 $N))) +; + (= ($write-dynamic-body (or $G1 $G2) $N) @@ -5070,7 +6841,9 @@ ($write-dynamic-body $G2 $N1) (nl) (tab $N) - (write )))) + (write )))) +; + (= ($write-dynamic-body (det-if-then $G1 $G2) $N) @@ -5088,34 +6861,46 @@ ($write-dynamic-body $G2 $N1) (nl) (tab $N) - (write )))) + (write )))) +; + (= ($write-dynamic-body $B $N) - ( (tab $N) (writeq $B))) + ( (tab $N) (writeq $B))) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Misc +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (/ reverse 2)) - !(public (/ length 2)) - !(public (/ numbervars 3)) - !(public (/ statistics 2)) + !(public (/ reverse 2)) +; + + !(public (/ length 2)) +; + + !(public (/ numbervars 3)) +; + + !(public (/ statistics 2)) +; + ; -; reverse(Xs, Zs) :- reverse(Xs, [], Zs). +; ; -; reverse([], Zs, Zs). +; ; -; reverse([X|Xs], Tmp, Zs) :- reverse(Xs, [X|Tmp], Zs). +; @@ -5123,31 +6908,43 @@ (length $L $N) ( (var $N) (set-det) - ($length $L 0 $N))) + ($length $L 0 $N))) +; + (= (length $L $N) - ($length0 $L 0 $N)) + ($length0 $L 0 $N)) +; + (= - ($length () $I $I) True) + ($length () $I $I) True) +; + (= ($length (Cons $_ $L) $I0 $I) ( (is $I1 - (+ $I0 1)) ($length $L $I1 $I))) + (+ $I0 1)) ($length $L $I1 $I))) +; + (= ($length0 Nil $I $I) - (set-det)) + (set-det)) +; + (= ($length0 (Cons $_ $L) $I0 $I) ( (< $I0 $I) (is $I1 (+ $I0 1)) - ($length0 $L $I1 $I))) + ($length0 $L $I1 $I))) +; + (= @@ -5155,7 +6952,9 @@ ( (integer $VI) (>= $VI 0) (set-det) - ($numbervars $X $VI $VN))) + ($numbervars $X $VI $VN))) +; + (= @@ -5165,32 +6964,41 @@ (= $X $VI) (is $VN (+ $VI 1)))) -; ; This structure is checked in write - +; (= ($numbervars $X $VI $VI) - ( (atomic $X) (set-det))) + ( (atomic $X) (set-det))) +; + (= ($numbervars $X $VI $VI) - ( (java $X) (set-det))) + ( (java $X) (set-det))) +; + (= ($numbervars $X $VI $VN) - ( (functor $X $_ $N) ($numbervars-str 1 $N $X $VI $VN))) + ( (functor $X $_ $N) ($numbervars-str 1 $N $X $VI $VN))) +; + (= ($numbervars-str $I $I $X $VI $VN) ( (set-det) (arg $I $X $A) - ($numbervars $A $VI $VN))) + ($numbervars $A $VI $VN))) +; + (= ($numbervars-str $I $N $X $VI $VN) ( (arg $I $X $A) ($numbervars $A $VI $VN1) (is $I1 (+ $I 1)) - ($numbervars-str $I1 $N $X $VN1 $VN))) + ($numbervars-str $I1 $N $X $VN1 $VN))) +; + (= @@ -5198,19 +7006,29 @@ ( (nonvar $Key) ($statistics-mode $Key) (set-det) - ($statistics $Key $Value))) + ($statistics $Key $Value))) +; + (= (statistics $Key $Value) ( (findall $M - ($statistics-mode $M) $Domain) (illarg (domain is-symbol $Domain) (statistics $Key $Value) 1))) + ($statistics-mode $M) $Domain) (illarg (domain is-symbol $Domain) (statistics $Key $Value) 1))) +; + (= - ($statistics_mode runtime) True) + (%statistics_mode runtime) True) +; + (= - ($statistics_mode trail) True) + (%statistics_mode trail) True) +; + (= - ($statistics_mode choice) True) + (%statistics_mode choice) True) +; + (= @@ -5218,24 +7036,32 @@ ( (var $Type) (set-det) (illarg var - (print-message $Type $Message) 1))) + (print-message $Type $Message) 1))) +; + (= (print-message error $Message) - ( (set-det) ($error-message $Message))) + ( (set-det) ($error-message $Message))) +; + (= (print-message info $Message) ( (set-det) ($fast-write {) ($builtin-message $Message) ($fast-write }) - (nl))) + (nl))) +; + (= (print-message warning $Message) ( (set-det) ($fast-write '{WARNING: ') ($builtin-message $Message) ($fast-write }) - (nl))) + (nl))) +; + (= @@ -5245,7 +7071,9 @@ ($write-goal user-error $Goal) ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (instantiation-error $Goal $ArgNo)) ( (set-det) @@ -5255,7 +7083,9 @@ ($fast-write user-error $ArgNo) ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (type-error $Goal $ArgNo $Type $Culprit)) ( (set-det) @@ -5269,7 +7099,9 @@ (write user-error $Culprit) ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (domain-error $Goal $ArgNo $Domain $Culprit)) ( (set-det) @@ -5283,7 +7115,9 @@ (write user-error $Culprit) ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (existence-error $Goal 0 $ObjType $Culprit $Message)) ( (set-det) @@ -5294,7 +7128,9 @@ ($fast-write user-error ' does not exist') ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (existence-error $Goal $ArgNo $ObjType $Culprit $Message)) ( (set-det) @@ -5309,7 +7145,9 @@ ($fast-write user-error ' does not exist') ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (permission-error $Goal $Operation $ObjType $Culprit $Message)) ( (set-det) @@ -5325,7 +7163,9 @@ ($fast-write user-error $Message) ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (representation-error $Goal $ArgNo $Flag)) ( (set-det) @@ -5338,7 +7178,9 @@ ($fast-write user-error ' is breached') ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (evaluation-error $Goal $ArgNo $Type)) ( (set-det) @@ -5350,7 +7192,9 @@ ($fast-write user-error $Type) ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (syntax-error $Goal $ArgNo $Type $Culprit $Message)) ( (set-det) @@ -5364,7 +7208,9 @@ (write user-error $Culprit) ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (system-error $Message)) ( (set-det) @@ -5372,7 +7218,9 @@ (write user-error $Message) ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (internal-error $Message)) ( (set-det) @@ -5380,7 +7228,9 @@ (write user-error $Message) ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message (java-error $Goal $ArgNo $Exception)) ( (set-det) @@ -5393,34 +7243,46 @@ ($fast-write user-error }) (nl user-error) ($print-stack-trace $Exception) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($error-message $Message) ( ($fast-write user-error {) (write user-error $Message) ($fast-write user-error }) (nl user-error) - (flush-output user-error))) + (flush-output user-error))) +; + (= ($write-goal $S $Goal) ( (java $Goal) (set-det) - ($write-toString $S $Goal))) + ($write-toString $S $Goal))) +; + (= ($write-goal $S $Goal) - (write $S $Goal)) + (write $S $Goal)) +; + (= (illarg $Msg $Goal $ArgNo) ( (var $Msg) (set-det) - (illarg var $Goal $ArgNo))) + (illarg var $Goal $ArgNo))) +; + (= (illarg var $Goal $ArgNo) - (raise-exception (instantiation-error $Goal $ArgNo))) + (raise-exception (instantiation-error $Goal $ArgNo))) +; + (= (illarg (type $Type) $Goal $ArgNo) @@ -5431,7 +7293,9 @@ (type-error $Goal $ArgNo $Type $Arg)) (= $Error (instantiation-error $Goal $ArgNo))) - (raise-exception $Error))) + (raise-exception $Error))) +; + (= (illarg (domain $Type $ExpDomain) $Goal $ArgNo) @@ -5446,142 +7310,206 @@ (type-error $Goal $ArgNo $Type $Arg)) (= $Error (instantiation-error $Goal $ArgNo)))) - (raise-exception $Error))) + (raise-exception $Error))) +; + (= (illarg (existence $ObjType $Culprit $Message) $Goal $ArgNo) - (raise-exception (existence-error $Goal $ArgNo $ObjType $Culprit $Message))) + (raise-exception (existence-error $Goal $ArgNo $ObjType $Culprit $Message))) +; + (= (illarg (permission $Operation $ObjType $Culprit $Message) $Goal $_) - (raise-exception (permission-error $Goal $Operation $ObjType $Culprit $Message))) + (raise-exception (permission-error $Goal $Operation $ObjType $Culprit $Message))) +; + (= (illarg (representation $Flag) $Goal $ArgNo) - (raise-exception (representation-error $Goal $ArgNo $Flag))) + (raise-exception (representation-error $Goal $ArgNo $Flag))) +; + (= (illarg (evaluation $Type) $Goal $ArgNo) - (raise-exception (evaluation-error $Goal $ArgNo $Type))) + (raise-exception (evaluation-error $Goal $ArgNo $Type))) +; + (= (illarg (syntax $Type $Culprit $Message) $Goal $ArgNo) - (raise-exception (syntax-error $Goal $ArgNo $Type $Culprit $Message))) + (raise-exception (syntax-error $Goal $ArgNo $Type $Culprit $Message))) +; + (= (illarg (system $Message) $_ $_) - (raise-exception (system-error $Message))) + (raise-exception (system-error $Message))) +; + (= (illarg (internal $Message) $_ $_) - (raise-exception (internal-error $Message))) + (raise-exception (internal-error $Message))) +; + (= (illarg (java $Exception) $Goal $ArgNo) - (raise-exception (java-error $Goal $ArgNo $Exception))) + (raise-exception (java-error $Goal $ArgNo $Exception))) +; + (= (illarg $Msg $_ $_) - (raise-exception $Msg)) + (raise-exception $Msg)) +; + (= - ($match_type term $_) True) + (%match_type term $_) True) +; + (= ($match-type variable $X) - (var $X)) + (var $X)) +; + (= ($match-type is-symbol $X) - (atom $X)) + (atom $X)) +; + (= ($match-type symbolic $X) - (atomic $X)) + (atomic $X)) +; + (= ($match-type byte $X) ( (integer $X) (=< 0 $X) - (=< $X 255))) + (=< $X 255))) +; + (= ($match-type in-byte $X) ( (integer $X) (=< -1 $X) - (=< $X 255))) + (=< $X 255))) +; + (= ($match-type character $X) - ( (atom $X) (atom-length $X 1))) + ( (atom $X) (atom-length $X 1))) +; + (= ($match-type in-character $X) (or (== $X end-of-file) - ($match-type character $X))) + ($match-type character $X))) +; + (= ($match-type number $X) - (number $X)) + (number $X)) +; + (= ($match-type integer $X) - (integer $X)) + (integer $X)) +; + (= ($match-type long $X) - (long $X)) + (long $X)) +; + (= ($match-type float $X) - (float $X)) + (float $X)) +; + (= ($match-type callable $X) - (callable $X)) + (callable $X)) +; + (= ($match-type compound $X) - (compound $X)) + (compound $X)) +; + (= ($match-type list $X) - ( (nonvar $X) (or (= $X Nil) (= $X (Cons $_ $_))))) + ( (nonvar $X) (or (= $X Nil) (= $X (Cons $_ $_))))) +; + (= ($match-type java $X) - (java $X)) + (java $X)) +; + (= ($match-type stream $X) (or (java $X java.io.PushbackReader) - (java $X java.io.PrintWriter))) + (java $X java.io.PrintWriter))) +; + (= ($match-type stream-or-alias $X) (or (atom $X) - ($match-type stream $X))) + ($match-type stream $X))) +; + (= ($match-type hash $X) - (java $X com.googlecode.prolog-cafe.lang.HashtableOfTerm)) + (java $X com.googlecode.prolog-cafe.lang.HashtableOfTerm)) +; + (= ($match-type hash-or-alias $X) (or (atom $X) - ($match-type hash $X))) + ($match-type hash $X))) +; + (= ($match-type predicate-indicator $X) ( (nonvar $X) - (with_self - (= $X $P) - (/ $F $A)) + (= $X + (with_self $P + (/ $F $A))) (atom $P) (atom $F) - (integer $A))) + (integer $A))) +; + ; -; '$match_type'(evaluable, X). +; ; -; '$match_type'('convertible to java', X). +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; ISO thread synchronization +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; - !(public (/ with-mutex 2)) + !(public (/ with-mutex 2)) +; + (= @@ -5591,81 +7519,100 @@ (set-det) (illarg (type is-symbol) - (with-mutex $M $G) 1))) + (with-mutex $M $G) 1))) +; + (= (with-mutex $M $G) ( (var $G) (set-det) (illarg var - (with-mutex $M $G) 2))) + (with-mutex $M $G) 2))) +; + (= (with-mutex $M $G) ( (not (callable $G)) (set-det) (illarg (type callable) - (with-mutex $M $G) 2))) + (with-mutex $M $G) 2))) +; + (= (with-mutex $M $G) ( (mutex-lock-bt $M) (call $G) (set-det) (mutex-unlock $M))) -; ; if it fails or throws exception, mutex is unlocked automatically due to mutex_lock_bt - +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; Utilities +; ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; (= - ($builtin_append () $Zs $Zs) True) + (%builtin_append () $Zs $Zs) True) +; + (= ($builtin-append (Cons $X $Xs) $Ys (Cons $X $Zs)) - ($builtin-append $Xs $Ys $Zs)) + ($builtin-append $Xs $Ys $Zs)) +; + ; -; '$builtin_member'(X, [X|_]). +; ; -; '$builtin_member'(X, [_|L]) :- '$builtin_member'(X, L). +; (= ($builtin-message Nil) - (set-det)) + (set-det)) +; + (= ($builtin-message (:: $M)) - ( (set-det) (write $M))) + ( (set-det) (write $M))) +; + (= ($builtin-message (Cons $M $Ms)) ( (write $M) ($fast-write ' ') - ($builtin-message $Ms))) + ($builtin-message $Ms))) +; + (= ($member-in-reverse $X (Cons $_ $L)) - ($member-in-reverse $X $L)) + ($member-in-reverse $X $L)) +; + (= - ($member_in_reverse $X - (Cons $X $_)) True) + (%member_in_reverse $X + (Cons $X $_)) True) +; + ; -; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ; -; END +; diff --git a/sxx_machine/tau_operators.metta b/sxx_machine/tau_operators.metta index 0c20acb..72a8c85 100644 --- a/sxx_machine/tau_operators.metta +++ b/sxx_machine/tau_operators.metta @@ -1,17 +1,43 @@ - !(op 1170 xfx :-) - !(op 1170 xfx -->) - !(op 1170 fx :-) - !(op 1170 fx ?-) - !(op 500 yfx #) - !(op 1150 fx dynamic) - !(op 1150 fx meta-predicate) - !(op 1150 fx package) - !(op 1150 fx public) - !(op 1150 fx import) - !(op 1150 fx mode) - !(op 1150 fx multifile) - !(op 1150 fx block) + !(op 1170 xfx :-) +; + + !(op 1170 xfx -->) +; + + !(op 1170 fx :-) +; + + !(op 1170 fx ?-) +; + + !(op 500 yfx #) +; + + !(op 1150 fx dynamic) +; + + !(op 1150 fx meta-predicate) +; + + !(op 1150 fx package) +; + + !(op 1150 fx public) +; + + !(op 1150 fx import) +; + + !(op 1150 fx mode) +; + + !(op 1150 fx multifile) +; + + !(op 1150 fx block) +; + diff --git a/sxx_machine/tau_system.metta b/sxx_machine/tau_system.metta index d7c0efd..28e9150 100644 --- a/sxx_machine/tau_system.metta +++ b/sxx_machine/tau_system.metta @@ -1,787 +1,1279 @@ - !(op 1150 fx package) + !(op 1150 fx package) +; + (= (package $X) - (nb-setval package $X)) + (nb-setval package $X)) +; + - !(package com.googlecode.prolog-cafe.builtin) - !(public (/ system-predicate 1)) - !(multifile (/ system-predicate 1)) - !(dynamic (/ system-predicate 1)) + !(package com.googlecode.prolog-cafe.builtin) +; + + !(public (/ system-predicate 1)) +; + + !(multifile (/ system-predicate 1)) +; + + !(dynamic (/ system-predicate 1)) +; + (= (system_predicate - (system_predicate $_)) True) + (system_predicate $_)) True) +; + ; -; Control constructs +; (= - (system_predicate true) True) + (system_predicate true) True) +; + (= - (system_predicate therwise) True) + (system_predicate therwise) True) +; + (= - (system_predicate fail) True) + (system_predicate fail) True) +; + (= - (system_predicate false) True) + (system_predicate false) True) +; + (= - (system_predicate !) True) + (system_predicate !) True) +; + (= (system_predicate - ($get_level $_)) True) + (%get_level $_)) True) +; + (= - (system_predicate $neck_cut) True) + (system_predicate $neck_cut) True) +; + (= (system_predicate - ($cut $_)) True) + ($cut $_)) True) +; + (= (system_predicate - (^ $_ $_)) True) + (^ $_ $_)) True) +; + (= (system_predicate - (, $_ $_)) True) + (, $_ $_)) True) +; + (= (system_predicate - (; $_ $_)) True) + (; $_ $_)) True) +; + (= (system_predicate - (-> $_ $_)) True) + (-> $_ $_)) True) +; + (= (system_predicate - (call $_)) True) + (call $_)) True) +; + (= (system_predicate - (catch $_ $_ $_)) True) + (catch $_ $_ $_)) True) +; + (= (system_predicate - (throw $_)) True) + (throw $_)) True) +; + (= (system_predicate - (on_exception $_ $_ $_)) True) + (on_exception $_ $_ $_)) True) +; + (= (system_predicate - (raise_exception $_)) True) + (raise_exception $_)) True) +; + ; -; Term unification +; (= (system_predicate - (= $_ $_)) True) + (= $_ $_)) True) +; + (= (system_predicate - ($unify $_ $_)) True) + ($unify $_ $_)) True) +; + (= (system_predicate - (\= $_ $_)) True) + (\= $_ $_)) True) +; + (= (system_predicate - ($not_unifiable $_ $_)) True) + (%not_unifiable $_ $_)) True) +; + ; -; Type testing +; (= (system_predicate - (var $_)) True) + (var $_)) True) +; + (= (system_predicate - (atom $_)) True) + (is-symbol $_)) True) +; + (= (system_predicate - (integer $_)) True) + (integer $_)) True) +; + (= (system_predicate - (long $_)) True) + (long $_)) True) +; + (= (system_predicate - (float $_)) True) + (float $_)) True) +; + (= (system_predicate - (atomic $_)) True) + (atomic $_)) True) +; + (= (system_predicate - (compound $_)) True) + (compound $_)) True) +; + (= (system_predicate - (nonvar $_)) True) + (nonvar $_)) True) +; + (= (system_predicate - (number $_)) True) + (number $_)) True) +; + (= (system_predicate - (java $_)) True) + (java $_)) True) +; + (= (system_predicate - (java $_ $_)) True) + (java $_ $_)) True) +; + (= (system_predicate - (closure $_)) True) + (closure $_)) True) +; + (= (system_predicate - (ground $_)) True) + (ground $_)) True) +; + (= (system_predicate - (callable $_)) True) + (callable $_)) True) +; + ; -; Term comparison +; (= (system_predicate - (== $_ $_)) True) + (== $_ $_)) True) +; + (= (system_predicate - ($equality_of_term $_ $_)) True) + (%equality_of_term $_ $_)) True) +; + (= (system_predicate - (\== $_ $_)) True) + (\== $_ $_)) True) +; + (= (system_predicate - ($inequality_of_term $_ $_)) True) + (%inequality_of_term $_ $_)) True) +; + (= (system_predicate - (@< $_ $_)) True) + (@< $_ $_)) True) +; + (= (system_predicate - ($before $_ $_)) True) + ($before $_ $_)) True) +; + (= (system_predicate - (@> $_ $_)) True) + (@> $_ $_)) True) +; + (= (system_predicate - ($after $_ $_)) True) + ($after $_ $_)) True) +; + (= (system_predicate - (@=< $_ $_)) True) + (@=< $_ $_)) True) +; + (= (system_predicate - ($not_after $_ $_)) True) + (%not_after $_ $_)) True) +; + (= (system_predicate - (@>= $_ $_)) True) + (@>= $_ $_)) True) +; + (= (system_predicate - ($not_before $_ $_)) True) + (%not_before $_ $_)) True) +; + (= (system_predicate - (?= $_ $_)) True) + (?= $_ $_)) True) +; + (= (system_predicate - ($identical_or_cannot_unify $_ $_)) True) + (%identical_or_cannot_unify $_ $_)) True) +; + (= (system_predicate - (compare $_ $_ $_)) True) + (compare $_ $_ $_)) True) +; + (= (system_predicate - (sort $_ $_)) True) + (sort $_ $_)) True) +; + (= (system_predicate - (keysort $_ $_)) True) + (keysort $_ $_)) True) +; + ; -; system_predicate(merge(_,_,_)). +; ; -; Term creation and decomposition +; (= (system_predicate - (arg $_ $_ $_)) True) + (arg $_ $_ $_)) True) +; + (= (system_predicate - (functor $_ $_ $_)) True) + (functor $_ $_ $_)) True) +; + (= (system_predicate - (=.. $_ $_)) True) + (=.. $_ $_)) True) +; + (= (system_predicate - ($univ $_ $_)) True) + ($univ $_ $_)) True) +; + (= (system_predicate - (copy_term $_ $_)) True) + (copy_term $_ $_)) True) +; + ; -; Arithmetic evaluation +; (= (system_predicate - (is $_ $_)) True) + (is $_ $_)) True) +; + (= (system_predicate - ($abs $_ $_)) True) + ($abs $_ $_)) True) +; + (= (system_predicate - ($asin $_ $_)) True) + ($asin $_ $_)) True) +; + (= (system_predicate - ($acos $_ $_)) True) + ($acos $_ $_)) True) +; + (= (system_predicate - ($atan $_ $_)) True) + ($atan $_ $_)) True) +; + (= (system_predicate - ($bitwise_conj $_ $_ $_)) True) + (%bitwise_conj $_ $_ $_)) True) +; + (= (system_predicate - ($bitwise_disj $_ $_ $_)) True) + (%bitwise_disj $_ $_ $_)) True) +; + (= (system_predicate - ($bitwise_exclusive_or $_ $_ $_)) True) + (%bitwise_exclusive_or $_ $_ $_)) True) +; + (= (system_predicate - ($bitwise_neg $_ $_)) True) + (%bitwise_neg $_ $_)) True) +; + (= (system_predicate - ($ceil $_ $_)) True) + ($ceil $_ $_)) True) +; + (= (system_predicate - ($cos $_ $_)) True) + ($cos $_ $_)) True) +; + (= (system_predicate - ($degrees $_ $_)) True) + ($degrees $_ $_)) True) +; + (= (system_predicate - ($exp $_ $_)) True) + ($exp $_ $_)) True) +; + (= (system_predicate - ($float $_ $_)) True) + ($float $_ $_)) True) +; + (= (system_predicate - ($float_integer_part $_ $_)) True) + (%float_integer_part $_ $_)) True) +; + (= (system_predicate - ($float_fractional_part $_ $_)) True) + (%float_fractional_part $_ $_)) True) +; + (= (system_predicate - ($float_quotient $_ $_ $_)) True) + (%float_quotient $_ $_ $_)) True) +; + (= (system_predicate - ($floor $_ $_)) True) + ($floor $_ $_)) True) +; + (= (system_predicate - ($int_quotient $_ $_ $_)) True) + (%int_quotient $_ $_ $_)) True) +; + (= (system_predicate - ($log $_ $_)) True) + ($log $_ $_)) True) +; + (= (system_predicate - ($max $_ $_ $_)) True) + ($max $_ $_ $_)) True) +; + (= (system_predicate - ($min $_ $_ $_)) True) + ($min $_ $_ $_)) True) +; + (= (system_predicate - ($minus $_ $_ $_)) True) + ($minus $_ $_ $_)) True) +; + (= (system_predicate - ($mod $_ $_ $_)) True) + ($mod $_ $_ $_)) True) +; + (= (system_predicate - ($multi $_ $_ $_)) True) + ($multi $_ $_ $_)) True) +; + (= (system_predicate - ($plus $_ $_ $_)) True) + ($plus $_ $_ $_)) True) +; + (= (system_predicate - ($pow $_ $_ $_)) True) + ($pow $_ $_ $_)) True) +; + (= (system_predicate - ($radians $_ $_)) True) + ($radians $_ $_)) True) +; + (= (system_predicate - ($rint $_ $_)) True) + ($rint $_ $_)) True) +; + (= (system_predicate - ($round $_ $_)) True) + ($round $_ $_)) True) +; + (= (system_predicate - ($shift_left $_ $_ $_)) True) + (%shift_left $_ $_ $_)) True) +; + (= (system_predicate - ($shift_right $_ $_ $_)) True) + (%shift_right $_ $_ $_)) True) +; + (= (system_predicate - ($sign $_ $_)) True) + ($sign $_ $_)) True) +; + (= (system_predicate - ($sin $_ $_)) True) + ($sin $_ $_)) True) +; + (= (system_predicate - ($sqrt $_ $_)) True) + ($sqrt $_ $_)) True) +; + (= (system_predicate - ($tan $_ $_)) True) + ($tan $_ $_)) True) +; + (= (system_predicate - ($truncate $_ $_)) True) + ($truncate $_ $_)) True) +; + ; -; Arithmetic comparison +; (= (system_predicate - (=:= $_ $_)) True) + (=:= $_ $_)) True) +; + (= (system_predicate - ($arith_equal $_ $_)) True) + (%arith_equal $_ $_)) True) +; + (= (system_predicate - (=\= $_ $_)) True) + (=\= $_ $_)) True) +; + (= (system_predicate - ($arith_not_equal $_ $_)) True) + (%arith_not_equal $_ $_)) True) +; + (= (system_predicate - (< $_ $_)) True) + (< $_ $_)) True) +; + (= (system_predicate - ($less_than $_ $_)) True) + (%less_than $_ $_)) True) +; + (= (system_predicate - (=< $_ $_)) True) + (=< $_ $_)) True) +; + (= (system_predicate - ($less_or_equal $_ $_)) True) + (%less_or_equal $_ $_)) True) +; + (= (system_predicate - (> $_ $_)) True) + (> $_ $_)) True) +; + (= (system_predicate - ($greater_than $_ $_)) True) + (%greater_than $_ $_)) True) +; + (= (system_predicate - (>= $_ $_)) True) + (>= $_ $_)) True) +; + (= (system_predicate - ($greater_or_equal $_ $_)) True) + (%greater_or_equal $_ $_)) True) +; + ; -; Clause retrieval and information +; (= (system_predicate - (clause $_ $_)) True) + (clause $_ $_)) True) +; + (= (system_predicate - (initialization $_ $_)) True) + (initialization $_ $_)) True) +; + (= (system_predicate - ($new_indexing_hash $_ $_ $_)) True) + (%new_indexing_hash $_ $_ $_)) True) +; + ; -; Clause creation and destruction +; (= (system_predicate - (assert $_)) True) + (assert $_)) True) +; + (= (system_predicate - (assertz $_)) True) + (assertz $_)) True) +; + (= (system_predicate - (asserta $_)) True) + (asserta $_)) True) +; + (= (system_predicate - (retract $_)) True) + (retract $_)) True) +; + (= (system_predicate - (abolish $_)) True) + (abolish $_)) True) +; + (= (system_predicate - (retractall $_)) True) + (retractall $_)) True) +; + ; -; All solutions +; (= (system_predicate - (findall $_ $_ $_)) True) + (findall $_ $_ $_)) True) +; + (= (system_predicate - (bagof $_ $_ $_)) True) + (bagof $_ $_ $_)) True) +; + (= (system_predicate - (setof $_ $_ $_)) True) + (setof $_ $_ $_)) True) +; + ; -; Stream selection and control +; (= (system_predicate - (current_input $_)) True) + (current_input $_)) True) +; + (= (system_predicate - (current_output $_)) True) + (current_output $_)) True) +; + (= (system_predicate - (set_input $_)) True) + (set_input $_)) True) +; + (= (system_predicate - (set_output $_)) True) + (set_output $_)) True) +; + (= (system_predicate - (open $_ $_ $_)) True) + (open $_ $_ $_)) True) +; + (= (system_predicate - (open $_ $_ $_ $_)) True) + (open $_ $_ $_ $_)) True) +; + (= (system_predicate - (close $_)) True) + (close $_)) True) +; + (= (system_predicate - (close $_ $_)) True) + (close $_ $_)) True) +; + (= (system_predicate - (flush_output $_)) True) + (flush_output $_)) True) +; + (= - (system_predicate flush_output) True) + (system_predicate flush_output) True) +; + (= (system_predicate - (stream_property $_ $_)) True) + (stream_property $_ $_)) True) +; + ; -; Character input/output +; (= (system_predicate - (get_char $_)) True) + (get_char $_)) True) +; + (= (system_predicate - (get_char $_ $_)) True) + (get_char $_ $_)) True) +; + (= (system_predicate - (get_code $_)) True) + (get_code $_)) True) +; + (= (system_predicate - (get_code $_ $_)) True) + (get_code $_ $_)) True) +; + (= (system_predicate - (peek_char $_)) True) + (peek_char $_)) True) +; + (= (system_predicate - (peek_char $_ $_)) True) + (peek_char $_ $_)) True) +; + (= (system_predicate - (peek_code $_)) True) + (peek_code $_)) True) +; + (= (system_predicate - (peek_code $_ $_)) True) + (peek_code $_ $_)) True) +; + (= (system_predicate - (put_char $_)) True) + (put_char $_)) True) +; + (= (system_predicate - (put_char $_ $_)) True) + (put_char $_ $_)) True) +; + (= (system_predicate - (put_code $_)) True) + (put_code $_)) True) +; + (= (system_predicate - (put_code $_ $_)) True) + (put_code $_ $_)) True) +; + (= - (system_predicate nl) True) + (system_predicate nl) True) +; + (= (system_predicate - (nl $_)) True) + (nl $_)) True) +; + (= (system_predicate - (get0 $_)) True) + (get0 $_)) True) +; + (= (system_predicate - (get0 $_ $_)) True) + (get0 $_ $_)) True) +; + (= (system_predicate - (get $_)) True) + (get $_)) True) +; + (= (system_predicate - (get $_ $_)) True) + (get $_ $_)) True) +; + (= (system_predicate - (put $_)) True) + (put $_)) True) +; + (= (system_predicate - (put $_ $_)) True) + (put $_ $_)) True) +; + (= (system_predicate - (tab $_)) True) + (tab $_)) True) +; + (= (system_predicate - (tab $_ $_)) True) + (tab $_ $_)) True) +; + (= (system_predicate - (skip $_)) True) + (skip $_)) True) +; + (= (system_predicate - (skip $_ $_)) True) + (skip $_ $_)) True) +; + ; -; Byte input/output +; (= (system_predicate - (get_byte $_)) True) + (get_byte $_)) True) +; + (= (system_predicate - (get_byte $_ $_)) True) + (get_byte $_ $_)) True) +; + (= (system_predicate - (peek_byte $_)) True) + (peek_byte $_)) True) +; + (= (system_predicate - (peek_byte $_ $_)) True) + (peek_byte $_ $_)) True) +; + (= (system_predicate - (put_byte $_)) True) + (put_byte $_)) True) +; + (= (system_predicate - (put_byte $_ $_)) True) + (put_byte $_ $_)) True) +; + ; -; Term input/output +; (= (system_predicate - (read $_)) True) + (read $_)) True) +; + (= (system_predicate - (read $_ $_)) True) + (read $_ $_)) True) +; + (= (system_predicate - (read_with_variables $_ $_)) True) + (read_with_variables $_ $_)) True) +; + (= (system_predicate - (read_with_variables $_ $_ $_)) True) + (read_with_variables $_ $_ $_)) True) +; + (= (system_predicate - (read_line $_)) True) + (read_line $_)) True) +; + (= (system_predicate - (read_line $_ $_)) True) + (read_line $_ $_)) True) +; + (= (system_predicate - (write $_)) True) + (write $_)) True) +; + (= (system_predicate - (write $_ $_)) True) + (write $_ $_)) True) +; + (= (system_predicate - (writeq $_)) True) + (writeq $_)) True) +; + (= (system_predicate - (writeq $_ $_)) True) + (writeq $_ $_)) True) +; + (= (system_predicate - (write_canonical $_)) True) + (write_canonical $_)) True) +; + (= (system_predicate - (write_canonical $_ $_)) True) + (write_canonical $_ $_)) True) +; + (= (system_predicate - (write_term $_ $_)) True) + (write_term $_ $_)) True) +; + (= (system_predicate - (write_term $_ $_ $_)) True) + (write_term $_ $_ $_)) True) +; + (= (system_predicate - (op $_ $_ $_)) True) + (op $_ $_ $_)) True) +; + (= (system_predicate - (current_op $_ $_ $_)) True) + (current_op $_ $_ $_)) True) +; + ; -; Logic and control +; (= (system_predicate - (\+ $_)) True) + (\+ $_)) True) +; + (= (system_predicate - (once $_)) True) + (once $_)) True) +; + (= - (system_predicate repeat) True) + (system_predicate repeat) True) +; + ; -; Atomic term processing +; (= (system_predicate - (atom_length $_ $_)) True) + (symbol_length $_ $_)) True) +; + (= (system_predicate - (atom_concat $_ $_ $_)) True) + (symbol_concat $_ $_ $_)) True) +; + (= (system_predicate - (sub_atom $_ $_ $_ $_ $_)) True) + (sub_symbol $_ $_ $_ $_ $_)) True) +; + (= (system_predicate - (atom_chars $_ $_)) True) + (symbol_chars $_ $_)) True) +; + (= (system_predicate - (atom_codes $_ $_)) True) + (symbol_codes $_ $_)) True) +; + (= (system_predicate - (char_code $_ $_)) True) + (char_code $_ $_)) True) +; + (= (system_predicate - (number_chars $_ $_)) True) + (number_chars $_ $_)) True) +; + (= (system_predicate - (number_codes $_ $_)) True) + (number_codes $_ $_)) True) +; + (= (system_predicate - (name $_ $_)) True) + (name $_ $_)) True) +; + ; -; Implementation defined hooks +; (= (system_predicate - (set_prolog_flag $_ $_)) True) + (set_prolog_flag $_ $_)) True) +; + (= (system_predicate - (current_prolog_flag $_ $_)) True) + (current_prolog_flag $_ $_)) True) +; + (= - (system_predicate halt) True) + (system_predicate halt) True) +; + (= (system_predicate - (halt $_)) True) + (halt $_)) True) +; + (= - (system_predicate abort) True) + (system_predicate abort) True) +; + ; -; DCG +; (= (system_predicate - (C $_ $_ $_)) True) + (C $_ $_ $_)) True) +; + (= (system_predicate - (expand_term $_ $_)) True) + (expand_term $_ $_)) True) +; + ; -; Hash creation and control +; (= (system_predicate - (new_hash $_)) True) + (new_hash $_)) True) +; + (= (system_predicate - (new_hash $_ $_)) True) + (new_hash $_ $_)) True) +; + (= (system_predicate - (hash_clear $_)) True) + (hash_clear $_)) True) +; + (= (system_predicate - (hash_contains_key $_ $_)) True) + (hash_contains_key $_ $_)) True) +; + (= (system_predicate - (hash_get $_ $_ $_)) True) + (hash_get $_ $_ $_)) True) +; + (= (system_predicate - (hash_is_empty $_)) True) + (hash_is_empty $_)) True) +; + (= (system_predicate - (hash_keys $_ $_)) True) + (hash_keys $_ $_)) True) +; + (= (system_predicate - (hash_map $_ $_)) True) + (hash_map $_ $_)) True) +; + (= (system_predicate - (hash_put $_ $_ $_)) True) + (hash_put $_ $_ $_)) True) +; + (= (system_predicate - (hash_remove $_ $_)) True) + (hash_remove $_ $_)) True) +; + (= (system_predicate - (hash_size $_ $_)) True) + (hash_size $_ $_)) True) +; + (= (system_predicate - ($get_hash_manager $_)) True) + (%get_hash_manager $_)) True) +; + ; -; Java interoperation +; (= (system_predicate - (java_constructor0 $_ $_)) True) + (java_constructor0 $_ $_)) True) +; + (= (system_predicate - (java_constructor $_ $_)) True) + (java_constructor $_ $_)) True) +; + (= (system_predicate - (java_declared_constructor0 $_ $_)) True) + (java_declared_constructor0 $_ $_)) True) +; + (= (system_predicate - (java_declared_constructor $_ $_)) True) + (java_declared_constructor $_ $_)) True) +; + (= (system_predicate - (java_method0 $_ $_ $_)) True) + (java_method0 $_ $_ $_)) True) +; + (= (system_predicate - (java_method $_ $_ $_)) True) + (java_method $_ $_ $_)) True) +; + (= (system_predicate - (java_declared_method0 $_ $_ $_)) True) + (java_declared_method0 $_ $_ $_)) True) +; + (= (system_predicate - (java_declared_method $_ $_ $_)) True) + (java_declared_method $_ $_ $_)) True) +; + (= (system_predicate - (java_get_field0 $_ $_ $_)) True) + (java_get_field0 $_ $_ $_)) True) +; + (= (system_predicate - (java_get_field $_ $_ $_)) True) + (java_get_field $_ $_ $_)) True) +; + (= (system_predicate - (java_get_declared_field0 $_ $_ $_)) True) + (java_get_declared_field0 $_ $_ $_)) True) +; + (= (system_predicate - (java_get_declared_field $_ $_ $_)) True) + (java_get_declared_field $_ $_ $_)) True) +; + (= (system_predicate - (java_set_field0 $_ $_ $_)) True) + (java_set_field0 $_ $_ $_)) True) +; + (= (system_predicate - (java_set_field $_ $_ $_)) True) + (java_set_field $_ $_ $_)) True) +; + (= (system_predicate - (java_set_declared_field0 $_ $_ $_)) True) + (java_set_declared_field0 $_ $_ $_)) True) +; + (= (system_predicate - (java_set_declared_field $_ $_ $_)) True) + (java_set_declared_field $_ $_ $_)) True) +; + (= (system_predicate - (synchronized $_ $_)) True) + (synchronized $_ $_)) True) +; + (= (system_predicate - (java_conversion $_ $_)) True) + (java_conversion $_ $_)) True) +; + ; -; MeTTa interpreter +; (= - (system_predicate cafeteria) True) + (system_predicate cafeteria) True) +; + (= (system_predicate - (consult $_)) True) + (consult $_)) True) +; + (= - (system_predicate trace) True) + (system_predicate trace) True) +; + (= - (system_predicate notrace) True) + (system_predicate notrace) True) +; + (= - (system_predicate debug) True) + (system_predicate debug) True) +; + (= - (system_predicate nodebug) True) + (system_predicate nodebug) True) +; + (= (system_predicate - (leash $_)) True) + (leash $_)) True) +; + (= (system_predicate - (spy $_)) True) + (spy $_)) True) +; + (= (system_predicate - (nospy $_)) True) + (nospy $_)) True) +; + (= - (system_predicate nospyall) True) + (system_predicate nospyall) True) +; + (= - (system_predicate listing) True) + (system_predicate listing) True) +; + (= (system_predicate - (listing $_)) True) + (listing $_)) True) +; + ; -; Misc +; (= (system_predicate - (length $_ $_)) True) + (length $_ $_)) True) +; + (= (system_predicate - (numbervars $_ $_ $_)) True) + (numbervars $_ $_ $_)) True) +; + (= (system_predicate - (statistics $_ $_)) True) + (statistics $_ $_)) True) +; + ; -; END +; diff --git a/vs/vs.metta b/vs/vs.metta new file mode 100644 index 0000000..492ca52 --- /dev/null +++ b/vs/vs.metta @@ -0,0 +1,428 @@ + + (= + (learn) + ( (writeln 'First positive example ?') + (read $POS_EX) + (nl) + (initialize $POS_EX $G $S) + (versionspace $G $S))) +; + + + + (= + (versionspace Nil $_) + ( (writeln 'There is no consistent concept description in this language !') (set-det))) +; + + (= + (versionspace $_ Nil) + ( (writeln 'There is no consistent concept description in this language !') (set-det))) +; + + (= + (versionspace + (:: $CONCEPT) + (:: $CONCEPT)) + ( (set-det) + (writeln 'The consistent generalization is : ') + (writeln $CONCEPT))) +; + + (= + (versionspace $G $S) + ( (writeln 'The G-set is : ') + (writeln $G) + (writeln 'The S-set is : ') + (writeln $S) + (nl) + (writeln 'Next example :') + (generate-ex $G $S $NEXT_EX) + (set-det) + (writeln $NEXT_EX) + (writeln 'Classification of the example ? [p/n]') + (read $CLASS) + (nl) + (adjust-versionspace $CLASS $NEXT_EX $G $S $NG $NS) + (versionspace $NG $NS))) +; + + (= + (versionspace $G $S) + (writeln 'Impossible to generate relevant examples')) +; + + + + (= + (adjust-versionspace p $EX $G $S $NG $NS) + ( (retain-g $G $NG $EX) + (generalize-s $S $S1 $NG $EX) + (prune-s $S1 $NS))) +; + + (= + (adjust-versionspace n $EX $G $S $NG $NS) + ( (retain-s $S $NS $EX) + (specialize-g $G $G1 $NS $EX) + (prune-g $G1 $NG))) +; + + + + (= + (retain-g Nil Nil $_) + (set-det)) +; + + (= + (retain-g + (Cons $CONCEPT $G) + (Cons $CONCEPT $NG) $EX) + ( (covers $CONCEPT $EX) + (set-det) + (retain-g $G $NG $EX))) +; + + (= + (retain-g + (Cons $CONCEPT $G) $NG $EX) + (retain-g $G $NG $EX)) +; + + + + (= + (retain-s Nil Nil $_) + (set-det)) +; + +; (error +; (syntax_error operator_expected) +; (file vs/vs.pl 164 11 8582)) + + (= + (retain-s + (Cons $CONCEPT $S) $NS $EX) + (retain-s $S $NS $EX)) +; + + + + (= + (generalize-s $S $NS $NG $EX) + (setofnil $NCON + (^ $CON + (, + (member $CON $S) + (valid-least-generalization $CON $EX $NCON $NG))) $NS)) +; + + + + (= + (specialize-g $G $NG $NS $EX) + (setofnil $NCONCEPT + (^ $CONCEPT + (, + (member $CONCEPT $G) + (valid-greatest-specialization $CONCEPT $EX $NCONCEPT $NS))) $NG)) +; + + + + (= + (valid-least-generalization $CONCEPT $EX $NCONCEPT $NG) + ( (least-generalization $CONCEPT $EX $NCONCEPT) + (member $GENERAL $NG) + (more-general $GENERAL $NCONCEPT))) +; + + + + (= + (valid-greatest-specialization $CONCEPT $EX $NCONCEPT $NS) + ( (greatest-specialization $CONCEPT $EX $NCONCEPT) + (member $SPECIFIC $NS) + (more-general $NCONCEPT $SPECIFIC))) +; + + + + (= + (prune-s $S $NS) + (prune-s-acc $S $S $NS)) +; + + + (= + (prune-s-acc Nil $_ Nil) + (set-det)) +; + + (= + (prune-s-acc + (Cons $SPECIFIC $S) $ACC $NS) + ( (member $SPECIFIC1 $ACC) + (not (== $SPECIFIC1 $SPECIFIC)) + (more-general $SPECIFIC $SPECIFIC1) + (set-det) + (prune-s-acc $S $ACC $NS))) +; + + (= + (prune-s-acc + (Cons $SPECIFIC $S) $ACC + (Cons $SPECIFIC $NS)) + (prune-s-acc $S $ACC $NS)) +; + + + + (= + (prune-g $G $NG) + (prune-g-acc $G $G $NG)) +; + + + (= + (prune-g-acc Nil $_ Nil) + (set-det)) +; + + (= + (prune-g-acc + (Cons $GENERAL $G) $ACC $NG) + ( (member $GENERAL1 $ACC) + (not (== $GENERAL $GENERAL1)) + (more-general $GENERAL1 $GENERAL) + (set-det) + (prune-g-acc $G $ACC $NG))) +; + + (= + (prune-g-acc + (Cons $GENERAL $G) $ACC + (Cons $GENERAL $NG)) + (prune-g-acc $G $ACC $NG)) +; + + + + (= + (allcovers Nil $_) + (set-det)) +; + + (= + (allcovers + (Cons $CON $REST) $EX) + ( (covers $CON $EX) (allcovers $REST $EX))) +; + + +; (error +; (syntax_error operator_expected) +; (file vs/vs.pl 334 11 18121)) + + + (= + (generate-ex + (Cons $GENERAL $G) $S $EX) + (generate-ex $G $S $EX)) +; + + + + (= + (find-ex Nil Nil) + (set-det)) +; + + (= + (find-ex + (Cons $GENERAL $G) + (Cons $LEAF $EX)) + ( (isa $LEAF $GENERAL) + (leaf $LEAF) + (find-ex $G $EX))) +; + + + + (= + (initialize $POS_EX + (:: $TOP) + (:: $POS_EX)) + (max $TOP $POS_EX)) +; + + + + (= + (covers () ()) True) +; + + (= + (covers + (Cons $C $CONCEPT) + (Cons $E $EXAMPLE)) + ( (isa $E $C) (covers $CONCEPT $EXAMPLE))) +; + + + + (= + (least_generalization () () ()) True) +; + + (= + (least-generalization + (Cons $CONCEPT $C) + (Cons $EX $E) + (Cons $NCONCEPT $N)) + ( (lge $CONCEPT $EX $NCONCEPT) (least-generalization $C $E $N))) +; + + + + (= + (greatest-specialization + (Cons $CONCEPT $C) + (Cons $EX $E) + (Cons $NCONCEPT $C)) + (gsp $CONCEPT $EX $NCONCEPT)) +; + + (= + (greatest-specialization + (Cons $CONCEPT $C) + (Cons $EX $E) + (Cons $CONCEPT $N)) + (greatest-specialization $C $E $N)) +; + + + + (= + (more-general $CONCEPT1 $CONCEPT2) + (covers $CONCEPT1 $CONCEPT2)) +; + + + + (= + (max Nil Nil) + (set-det)) +; + + (= + (max + (Cons $TOP $T) + (Cons $EX $E)) + ( (top $TOP $EX) (max $T $E))) +; + + +; (error +; (syntax_error operator_expected) +; (file vs/vs.pl 468 11 25683)) + + +; (error +; (syntax_error operator_expected) +; (file vs/vs.pl 480 12 26336)) + + + + (= + (isa $X $X) True) +; + + (= + (isa $X $Y) + ( (son $X $Z) (isa $Z $Y))) +; + + + + (= + (lge $X1 $X2 $X1) + ( (isa $X2 $X1) (set-det))) +; + + + (= + (lge $X1 $X2 $L) + ( (son $X1 $F) (lge $F $X2 $L))) +; + + +; (error +; (syntax_error operator_expected) +; (file vs/vs.pl 530 11 28892)) + + + + (= + (gsp $X1 $X2 $G) + ( (son $S $X1) (gsp $S $X2 $G))) +; + + + + (= + (writeln $X) + ( (display $X) (nl))) +; + + + + (= + (member $X + (Cons $X $Y)) True) +; + + (= + (member $X + (Cons $Y $Z)) + (member $X $Z)) +; + + + + (= + (append () $X $X) True) +; + + (= + (append + (Cons $X $Y) $Z + (Cons $X $W)) + (append $Y $Z $W)) +; + + + + (= + (setofnil $X $Y $Z) + ( (setof $X $Y $Z) (set-det))) +; + + (= + (setofnil $X $Y ()) True) +; + + + + (= + (help) + ( (write ' Start VS with command: learn.') (nl))) +; + + + + !(help *) +; + + diff --git a/vs/vs_1.metta b/vs/vs_1.metta new file mode 100644 index 0000000..a08cb06 --- /dev/null +++ b/vs/vs_1.metta @@ -0,0 +1,82 @@ + + (= + (son mono color) True) +; + + (= + (son poly color) True) +; + + (= + (son red mono) True) +; + + (= + (son blue mono) True) +; + + (= + (son white mono) True) +; + + (= + (son black mono) True) +; + + (= + (son orange poly) True) +; + + (= + (son pink poly) True) +; + + + (= + (son polygon shape) True) +; + + (= + (son oval shape) True) +; + + (= + (son + (- 3 sided) polygon) True) +; + + (= + (son + (- 4 sided) polygon) True) +; + + (= + (son triangle + (- 3 sided)) True) +; + + (= + (son rectangle + (- 4 sided)) True) +; + + (= + (son square + (- 4 sided)) True) +; + + (= + (son trapezoid + (- 4 sided)) True) +; + + (= + (son circle oval) True) +; + + (= + (son ellipse oval) True) +; + + +