entities
listlengths
1
9.05k
max_stars_repo_path
stringlengths
5
154
max_stars_repo_name
stringlengths
6
76
max_stars_count
int64
0
38.8k
content
stringlengths
24
1.03M
id
stringlengths
1
5
new_content
stringlengths
17
1.03M
modified
bool
1 class
references
stringlengths
31
1.03M
[ { "context": "#|$ACL2s-Preamble$;\n; Julien Schmaltz\n;; Generic Scheduling Module of GeNoC\n;; Feb 16th", "end": 37, "score": 0.999883234500885, "start": 22, "tag": "NAME", "value": "Julien Schmaltz" }, { "context": ";; Feb 16th 2005\n;; File: GeNoC-scheduling.lisp\n;; Amr HELMY Revised and modified January 24th 2008\n;;edited b", "end": 136, "score": 0.9449099898338318, "start": 127, "tag": "NAME", "value": "Amr HELMY" }, { "context": "Revised and modified January 24th 2008\n;;edited by Amr HELMY, Laurence Pierre august 22nd of august 2007\n\n;;Am", "end": 197, "score": 0.9992311596870422, "start": 188, "tag": "NAME", "value": "Amr HELMY" }, { "context": " modified January 24th 2008\n;;edited by Amr HELMY, Laurence Pierre august 22nd of august 2007\n\n;;Amr helmy\n;;31st oc", "end": 214, "score": 0.9998920559883118, "start": 199, "tag": "NAME", "value": "Laurence Pierre" }, { "context": "MY, Laurence Pierre august 22nd of august 2007\n\n;;Amr helmy\n;;31st october 2007\n\n(begin-book);$ACL2s-Preamble", "end": 254, "score": 0.8781155347824097, "start": 245, "tag": "NAME", "value": "Amr helmy" } ]
books/workshops/2009/verbeek-schmaltz/verbeek/generic-modules/GeNoC-scheduling.lisp
mayankmanj/acl2
305
#|$ACL2s-Preamble$; ; Julien Schmaltz ;; Generic Scheduling Module of GeNoC ;; Feb 16th 2005 ;; File: GeNoC-scheduling.lisp ;; Amr HELMY Revised and modified January 24th 2008 ;;edited by Amr HELMY, Laurence Pierre august 22nd of august 2007 ;;Amr helmy ;;31st october 2007 (begin-book);$ACL2s-Preamble$|# (in-package "ACL2") (include-book "GeNoC-nodeset") (include-book "GeNoC-misc") ;; imports also GeNoC-types (include-book "GeNoC-ntkstate")#|ACL2s-ToDo-Line|# ; ;; Inputs: TrLst = ( ... (Id org frm route) ...), measure, NodeSet, and ;; the current network state ;; outputs: TrLst updated, arrived missives, new state of the network, ;; measure updated (defspec GenericScheduling ;; Function Scheduling represents the scheduling policy of the ;; network. ;; arguments: TrLst measure P ;; outputs: newTrLst Arrived newP newMeasure (((scheduling * * * *) => (mv * * * *)) ((get_next_priority *)=> *) ((scheduling-assumptions * * * *) => *) ((legal-measure * * * * *) => *) ((initial-measure * * * *) => *)) (local (defun get_next_priority (port) port)) (local (defun scheduling-assumptions (TrLst NodeSet ntkstate order) (declare (ignore TrLst NodeSet ntkstate order)) nil)) (local (defun legal-measure (measure trlst nodeset ntkstate order) (declare (ignore measure trlst nodeset ntkstate order)) nil)) (local (defun initial-measure (trlst nodeset ntkstate order) (declare (ignore trlst nodeset ntkstate order)) nil)) (local (defun scheduling (TrLst NodeSet ntkstate order) ;; local witness (mv ;; TrLst updated (if (not (scheduling-assumptions TrLst NodeSet ntkstate order)) (totmissives TrLst) nil) ;; arrived messages ;(if (is-base-measure measure) nil ; TrLst) ;; measure is nil nil ;; ntkstate preserved ntkstate) )) ;; Proof obligations (also named constraints) ;; ----------------------------------------- (defthm scheduled-nil-nil ;; the result of the scheduling function in the case of empty ;; input list is equal to nil (equal (car (scheduling nil nodeset ntkstate order)) nil)) ;; 1/ Types of newTrLst, Arrived and P (state) ;; --------------------------------- ;; The type of newTrLst is a valid traveling missives list (defthm tmissivesp-newTrlst (implies (trlstp TrLst nodeset) (tmissivesp (mv-nth 0 (scheduling TrLst NodeSet ntkstate order)) NodeSet))) ;; so is the list of Arrived (defthm trlstp-Arrived ;; OK (implies (trlstp TrLst nodeset) (trlstp (mv-nth 1 (scheduling TrLst NodeSet ntkstate order)) nodeset))) ;; the state list P is a ValidState (defthm Valid-state-ntkstate (implies (validstate ntkstate) (validstate (mv-nth 3 (scheduling TrLst NodeSet ntkstate order))))) ;; 2/ the measure provided to GeNoC must be decreasing. ;; ------------------------------------------------------ ;; scheduling-assumptions must be a boolean (defthm booleanp-assumptions (booleanp (scheduling-assumptions TrLst NodeSet ntkstate order)) :rule-classes :type-prescription) ;; legal-measure nust be a boolean (defthm booleanp-legal-measure (booleanp (legal-measure measure trlst nodeset ntkstate order)) :rule-classes :type-prescription) ;; the measure must decrease on each call of scheduling (defthm measure-decreases (implies (and (legal-measure measure trlst nodeset ntkstate order) (scheduling-assumptions trlst NodeSet ntkstate order)) (O< (acl2-count (mv-nth 2 (scheduling TrLst NodeSet ntkstate order))) (acl2-count measure)))) ;; 3/ Correctness of the arrived missives ;; ------------------------------------------------------------------ ;; For any arrived missive arr, there exists a unique travel ;; tr in the initial TrLst, such that IdV(arr) = IdV(tr) ;; and FrmV(arr) = FrmV(tr) and RoutesV(arr) is a ;; sublist of RoutesV(tr). ;; In ACL2, the uniqueness of the ids is given by the predicate ;; TrLstp. ;; ------------------------------------------------------------------- ;; First, let us define this correctness (defun s/d-travel-correctness (arr-TrLst TrLst/arr-ids) (if (endp arr-TrLst) (if (endp TrLst/arr-ids) t nil) (let* ((arr-tr (car arr-TrLst)) (tr (car TrLst/arr-ids))) (and (equal (FrmV arr-tr) (FrmV tr)) (equal (IdV arr-tr) (IdV tr)) (equal (OrgV arr-tr) (OrgV tr)) (equal (FlitV arr-tr) (FlitV tr)) (equal (timeV arr-tr) (TimeV tr)) (subsetp (RoutesV arr-tr) (RoutesV tr)) (s/d-travel-correctness (cdr arr-TrLst) (cdr TrLst/arr-ids)))))) (defthm s/d-travel-correctness-unitary (implies (trlstp x nodeset) (s/d-travel-correctness x x))) (defthm arrived-travels-correctness (mv-let (newTrLst Arrived newMeasure newstate ) (scheduling TrLst NodeSet ntkstate order) (declare (ignore newTrLst newMeasure newstate )) (implies (TrLstp TrLst nodeset) (s/d-travel-correctness Arrived (extract-sublst TrLst (V-ids Arrived))))) :hints (("Goal" :in-theory (disable trlstp)))) (defthm subsetp-arrived-newTrLst-ids ;; this should be provable from the two lemmas above ;; but it will always be trivial to prove, and it is ;; useful in subsequent proofs. (mv-let (newTrLst Arrived newMeasure newstate ) (scheduling TrLst NodeSet ntkstate order) (declare (ignore newMeasure newstate )) (implies (TrLstp TrLst nodeset) (and (subsetp (v-ids Arrived) (v-ids Trlst)) (subsetp (Tm-ids newTrLst) (v-ids TrLst)))))) ;; 4. Correctness of the newTrLst travels ;; ------------------------------------- ;; the correctness of the newTrLst travels differs from ;; the correctness of the Arrived travels because, ;; for the Arrived travels we will generally keep only ;; one route, but for the newTrLst travels we will not modify ;; the travels and keep all the routes. In fact, by ;; converting a travel back to a missive we will remove the ;; routes. ;; --------------------------------------------------------- ;; the list newTrLst is equal to filtering the initial ;; TrLst according to the Ids of newTrLst (defthm newTrLst-travel-correctness ;; OK ;; the correctness of newtrlst is the equivalence of the transformation ;;of the newtrlst into missives, and the transformation of the ;;initial trlst (input to the scheduling function) ;;into tmissives and then to missives ;; this rule will cause an infinite number of rewrites that's why ;; it's in rule-classes nil, we have to create an instance to use ;; it (mv-let (newTrLst Arrived newMeasure newstate ) (scheduling TrLst NodeSet ntkstate order) (declare (ignore Arrived newMeasure newstate)) (implies (TrLstp TrLst nodeset) (equal (tomissives newTrLst) (extract-sublst (tomissives(totmissives TrLst)) (Tm-ids newTrLst))))) :rule-classes nil) ;; 6/ if scheduling assumptions are not met, measure is nil (defthm mv-nth-2-scheduling-on-zero-measure ;; OK ;; if the scheduling measure is 0 ;; the new measure is equal to the initial one (implies (and (not (scheduling-assumptions TrLst NodeSet ntkstate order)) (TrLstp trlst nodeset)) (equal (mv-nth 2 (scheduling TrLst NodeSet ntkstate order)) ;; new measure nil))) (defthm mv-nth-0-scheduling-on-zero-measure ;; OK ;; if the scheduling measure is 0 ;; the set of newTrLst s is equal to the initial TrLst (implies (not (scheduling-assumptions TrLst NodeSet ntkstate order)) (equal (mv-nth 0 (scheduling TrLst NodeSet ntkstate order)) (totmissives TrLst)))) ;; 7/ The intersection of the ids of the Arrived travels and those ;; of the newTrLst travels is empty ;; ----------------------------------------------------------------- (defthm not-in-newTrLst-Arrived ;; OK (mv-let (newTrLst Arrived newmeasure newstate ) (scheduling TrLst NodeSet ntkstate order) (declare (ignore newmeasure newstate )) (implies (TrLstp TrLst nodeset) (not-in (Tm-ids newTrLst) (v-ids Arrived))))) ;; some constraints required because we do not have a definition ;; for scheduling (defthm consp-scheduling ;; OK ;; for the mv-nth (consp (scheduling TrLst NodeSet ntkstate order)) :rule-classes :type-prescription) (defthm true-listp-car-scheduling ;; OK (implies (true-listp TrLst) (true-listp (mv-nth 0 (scheduling TrLst NodeSet ntkstate order )))) :rule-classes :type-prescription) (defthm true-listp-mv-nth-1-sched-1 ;; OK (implies (true-listp TrLst) (true-listp (mv-nth 1 (scheduling TrLst NodeSet ntkstate order)))) :rule-classes :type-prescription) (defthm true-listp-mv-nth-1-sched-2 ;; OK (implies (TrLstp TrLst nodeset) (true-listp (mv-nth 1 (scheduling TrLst NodeSet ntkstate order)))) :rule-classes :type-prescription) ) ;; end of scheduling (defthm correctroutesp-s/d-travel-correctness ;; OK ;; correctroutesp between trlst/ids and it's transformation into ;; tmissves, and the s/d-travel-correctness, between trlst/ids and ;; trlst1 ;; implies the correctroutesp between trlst1 and trlst/ids (implies (and (CorrectRoutesp TrLst/ids (ToTMissives TrLst/ids) NodeSet) (s/d-travel-correctness TrLst1 TrLst/ids)) (CorrectRoutesp TrLst1 (ToTMissives TrLst/ids) NodeSet))) (defthm scheduling-preserves-route-correctness ;; OK ;; we prove that sheduling preserve the correctness of the routes ;; after the transformation (mv-let (newTrLst Arrived newmeasure newstate ) (scheduling TrLst NodeSet ntkstate order) (declare (ignore newTrLst newstate newmeasure )) (implies (and (CorrectRoutesp TrLst (ToTMissives TrLst) NodeSet) (TrLstp TrLst nodeset)) (CorrectRoutesp Arrived (ToTMissives (extract-sublst TrLst (V-ids Arrived))) NodeSet))) :otf-flg t :hints (("GOAL" :do-not '(eliminate-destructors generalize) :do-not-induct t :in-theory (disable mv-nth ;; to have my rules used ToTMissives-extract-sublst TrLstp)))) (defthm TMissivesp-mv-nth-0-scheduling ;; OK (let ((NodeSet (NodeSetGenerator Params))) (implies (and (CorrectRoutesp TrLst (ToTMissives TrLst) NodeSet) (ValidParamsp Params) (TrLstp TrLst nodeset)) (TMissivesp (mv-nth 0 (scheduling TrLst NodeSet ntkstate order)) NodeSet))) :hints (("Goal" :use (:instance tmissivesp-newTrlst (nodeset (NodeSetGenerator Params))))))
68194
#|$ACL2s-Preamble$; ; <NAME> ;; Generic Scheduling Module of GeNoC ;; Feb 16th 2005 ;; File: GeNoC-scheduling.lisp ;; <NAME> Revised and modified January 24th 2008 ;;edited by <NAME>, <NAME> august 22nd of august 2007 ;;<NAME> ;;31st october 2007 (begin-book);$ACL2s-Preamble$|# (in-package "ACL2") (include-book "GeNoC-nodeset") (include-book "GeNoC-misc") ;; imports also GeNoC-types (include-book "GeNoC-ntkstate")#|ACL2s-ToDo-Line|# ; ;; Inputs: TrLst = ( ... (Id org frm route) ...), measure, NodeSet, and ;; the current network state ;; outputs: TrLst updated, arrived missives, new state of the network, ;; measure updated (defspec GenericScheduling ;; Function Scheduling represents the scheduling policy of the ;; network. ;; arguments: TrLst measure P ;; outputs: newTrLst Arrived newP newMeasure (((scheduling * * * *) => (mv * * * *)) ((get_next_priority *)=> *) ((scheduling-assumptions * * * *) => *) ((legal-measure * * * * *) => *) ((initial-measure * * * *) => *)) (local (defun get_next_priority (port) port)) (local (defun scheduling-assumptions (TrLst NodeSet ntkstate order) (declare (ignore TrLst NodeSet ntkstate order)) nil)) (local (defun legal-measure (measure trlst nodeset ntkstate order) (declare (ignore measure trlst nodeset ntkstate order)) nil)) (local (defun initial-measure (trlst nodeset ntkstate order) (declare (ignore trlst nodeset ntkstate order)) nil)) (local (defun scheduling (TrLst NodeSet ntkstate order) ;; local witness (mv ;; TrLst updated (if (not (scheduling-assumptions TrLst NodeSet ntkstate order)) (totmissives TrLst) nil) ;; arrived messages ;(if (is-base-measure measure) nil ; TrLst) ;; measure is nil nil ;; ntkstate preserved ntkstate) )) ;; Proof obligations (also named constraints) ;; ----------------------------------------- (defthm scheduled-nil-nil ;; the result of the scheduling function in the case of empty ;; input list is equal to nil (equal (car (scheduling nil nodeset ntkstate order)) nil)) ;; 1/ Types of newTrLst, Arrived and P (state) ;; --------------------------------- ;; The type of newTrLst is a valid traveling missives list (defthm tmissivesp-newTrlst (implies (trlstp TrLst nodeset) (tmissivesp (mv-nth 0 (scheduling TrLst NodeSet ntkstate order)) NodeSet))) ;; so is the list of Arrived (defthm trlstp-Arrived ;; OK (implies (trlstp TrLst nodeset) (trlstp (mv-nth 1 (scheduling TrLst NodeSet ntkstate order)) nodeset))) ;; the state list P is a ValidState (defthm Valid-state-ntkstate (implies (validstate ntkstate) (validstate (mv-nth 3 (scheduling TrLst NodeSet ntkstate order))))) ;; 2/ the measure provided to GeNoC must be decreasing. ;; ------------------------------------------------------ ;; scheduling-assumptions must be a boolean (defthm booleanp-assumptions (booleanp (scheduling-assumptions TrLst NodeSet ntkstate order)) :rule-classes :type-prescription) ;; legal-measure nust be a boolean (defthm booleanp-legal-measure (booleanp (legal-measure measure trlst nodeset ntkstate order)) :rule-classes :type-prescription) ;; the measure must decrease on each call of scheduling (defthm measure-decreases (implies (and (legal-measure measure trlst nodeset ntkstate order) (scheduling-assumptions trlst NodeSet ntkstate order)) (O< (acl2-count (mv-nth 2 (scheduling TrLst NodeSet ntkstate order))) (acl2-count measure)))) ;; 3/ Correctness of the arrived missives ;; ------------------------------------------------------------------ ;; For any arrived missive arr, there exists a unique travel ;; tr in the initial TrLst, such that IdV(arr) = IdV(tr) ;; and FrmV(arr) = FrmV(tr) and RoutesV(arr) is a ;; sublist of RoutesV(tr). ;; In ACL2, the uniqueness of the ids is given by the predicate ;; TrLstp. ;; ------------------------------------------------------------------- ;; First, let us define this correctness (defun s/d-travel-correctness (arr-TrLst TrLst/arr-ids) (if (endp arr-TrLst) (if (endp TrLst/arr-ids) t nil) (let* ((arr-tr (car arr-TrLst)) (tr (car TrLst/arr-ids))) (and (equal (FrmV arr-tr) (FrmV tr)) (equal (IdV arr-tr) (IdV tr)) (equal (OrgV arr-tr) (OrgV tr)) (equal (FlitV arr-tr) (FlitV tr)) (equal (timeV arr-tr) (TimeV tr)) (subsetp (RoutesV arr-tr) (RoutesV tr)) (s/d-travel-correctness (cdr arr-TrLst) (cdr TrLst/arr-ids)))))) (defthm s/d-travel-correctness-unitary (implies (trlstp x nodeset) (s/d-travel-correctness x x))) (defthm arrived-travels-correctness (mv-let (newTrLst Arrived newMeasure newstate ) (scheduling TrLst NodeSet ntkstate order) (declare (ignore newTrLst newMeasure newstate )) (implies (TrLstp TrLst nodeset) (s/d-travel-correctness Arrived (extract-sublst TrLst (V-ids Arrived))))) :hints (("Goal" :in-theory (disable trlstp)))) (defthm subsetp-arrived-newTrLst-ids ;; this should be provable from the two lemmas above ;; but it will always be trivial to prove, and it is ;; useful in subsequent proofs. (mv-let (newTrLst Arrived newMeasure newstate ) (scheduling TrLst NodeSet ntkstate order) (declare (ignore newMeasure newstate )) (implies (TrLstp TrLst nodeset) (and (subsetp (v-ids Arrived) (v-ids Trlst)) (subsetp (Tm-ids newTrLst) (v-ids TrLst)))))) ;; 4. Correctness of the newTrLst travels ;; ------------------------------------- ;; the correctness of the newTrLst travels differs from ;; the correctness of the Arrived travels because, ;; for the Arrived travels we will generally keep only ;; one route, but for the newTrLst travels we will not modify ;; the travels and keep all the routes. In fact, by ;; converting a travel back to a missive we will remove the ;; routes. ;; --------------------------------------------------------- ;; the list newTrLst is equal to filtering the initial ;; TrLst according to the Ids of newTrLst (defthm newTrLst-travel-correctness ;; OK ;; the correctness of newtrlst is the equivalence of the transformation ;;of the newtrlst into missives, and the transformation of the ;;initial trlst (input to the scheduling function) ;;into tmissives and then to missives ;; this rule will cause an infinite number of rewrites that's why ;; it's in rule-classes nil, we have to create an instance to use ;; it (mv-let (newTrLst Arrived newMeasure newstate ) (scheduling TrLst NodeSet ntkstate order) (declare (ignore Arrived newMeasure newstate)) (implies (TrLstp TrLst nodeset) (equal (tomissives newTrLst) (extract-sublst (tomissives(totmissives TrLst)) (Tm-ids newTrLst))))) :rule-classes nil) ;; 6/ if scheduling assumptions are not met, measure is nil (defthm mv-nth-2-scheduling-on-zero-measure ;; OK ;; if the scheduling measure is 0 ;; the new measure is equal to the initial one (implies (and (not (scheduling-assumptions TrLst NodeSet ntkstate order)) (TrLstp trlst nodeset)) (equal (mv-nth 2 (scheduling TrLst NodeSet ntkstate order)) ;; new measure nil))) (defthm mv-nth-0-scheduling-on-zero-measure ;; OK ;; if the scheduling measure is 0 ;; the set of newTrLst s is equal to the initial TrLst (implies (not (scheduling-assumptions TrLst NodeSet ntkstate order)) (equal (mv-nth 0 (scheduling TrLst NodeSet ntkstate order)) (totmissives TrLst)))) ;; 7/ The intersection of the ids of the Arrived travels and those ;; of the newTrLst travels is empty ;; ----------------------------------------------------------------- (defthm not-in-newTrLst-Arrived ;; OK (mv-let (newTrLst Arrived newmeasure newstate ) (scheduling TrLst NodeSet ntkstate order) (declare (ignore newmeasure newstate )) (implies (TrLstp TrLst nodeset) (not-in (Tm-ids newTrLst) (v-ids Arrived))))) ;; some constraints required because we do not have a definition ;; for scheduling (defthm consp-scheduling ;; OK ;; for the mv-nth (consp (scheduling TrLst NodeSet ntkstate order)) :rule-classes :type-prescription) (defthm true-listp-car-scheduling ;; OK (implies (true-listp TrLst) (true-listp (mv-nth 0 (scheduling TrLst NodeSet ntkstate order )))) :rule-classes :type-prescription) (defthm true-listp-mv-nth-1-sched-1 ;; OK (implies (true-listp TrLst) (true-listp (mv-nth 1 (scheduling TrLst NodeSet ntkstate order)))) :rule-classes :type-prescription) (defthm true-listp-mv-nth-1-sched-2 ;; OK (implies (TrLstp TrLst nodeset) (true-listp (mv-nth 1 (scheduling TrLst NodeSet ntkstate order)))) :rule-classes :type-prescription) ) ;; end of scheduling (defthm correctroutesp-s/d-travel-correctness ;; OK ;; correctroutesp between trlst/ids and it's transformation into ;; tmissves, and the s/d-travel-correctness, between trlst/ids and ;; trlst1 ;; implies the correctroutesp between trlst1 and trlst/ids (implies (and (CorrectRoutesp TrLst/ids (ToTMissives TrLst/ids) NodeSet) (s/d-travel-correctness TrLst1 TrLst/ids)) (CorrectRoutesp TrLst1 (ToTMissives TrLst/ids) NodeSet))) (defthm scheduling-preserves-route-correctness ;; OK ;; we prove that sheduling preserve the correctness of the routes ;; after the transformation (mv-let (newTrLst Arrived newmeasure newstate ) (scheduling TrLst NodeSet ntkstate order) (declare (ignore newTrLst newstate newmeasure )) (implies (and (CorrectRoutesp TrLst (ToTMissives TrLst) NodeSet) (TrLstp TrLst nodeset)) (CorrectRoutesp Arrived (ToTMissives (extract-sublst TrLst (V-ids Arrived))) NodeSet))) :otf-flg t :hints (("GOAL" :do-not '(eliminate-destructors generalize) :do-not-induct t :in-theory (disable mv-nth ;; to have my rules used ToTMissives-extract-sublst TrLstp)))) (defthm TMissivesp-mv-nth-0-scheduling ;; OK (let ((NodeSet (NodeSetGenerator Params))) (implies (and (CorrectRoutesp TrLst (ToTMissives TrLst) NodeSet) (ValidParamsp Params) (TrLstp TrLst nodeset)) (TMissivesp (mv-nth 0 (scheduling TrLst NodeSet ntkstate order)) NodeSet))) :hints (("Goal" :use (:instance tmissivesp-newTrlst (nodeset (NodeSetGenerator Params))))))
true
#|$ACL2s-Preamble$; ; PI:NAME:<NAME>END_PI ;; Generic Scheduling Module of GeNoC ;; Feb 16th 2005 ;; File: GeNoC-scheduling.lisp ;; PI:NAME:<NAME>END_PI Revised and modified January 24th 2008 ;;edited by PI:NAME:<NAME>END_PI, PI:NAME:<NAME>END_PI august 22nd of august 2007 ;;PI:NAME:<NAME>END_PI ;;31st october 2007 (begin-book);$ACL2s-Preamble$|# (in-package "ACL2") (include-book "GeNoC-nodeset") (include-book "GeNoC-misc") ;; imports also GeNoC-types (include-book "GeNoC-ntkstate")#|ACL2s-ToDo-Line|# ; ;; Inputs: TrLst = ( ... (Id org frm route) ...), measure, NodeSet, and ;; the current network state ;; outputs: TrLst updated, arrived missives, new state of the network, ;; measure updated (defspec GenericScheduling ;; Function Scheduling represents the scheduling policy of the ;; network. ;; arguments: TrLst measure P ;; outputs: newTrLst Arrived newP newMeasure (((scheduling * * * *) => (mv * * * *)) ((get_next_priority *)=> *) ((scheduling-assumptions * * * *) => *) ((legal-measure * * * * *) => *) ((initial-measure * * * *) => *)) (local (defun get_next_priority (port) port)) (local (defun scheduling-assumptions (TrLst NodeSet ntkstate order) (declare (ignore TrLst NodeSet ntkstate order)) nil)) (local (defun legal-measure (measure trlst nodeset ntkstate order) (declare (ignore measure trlst nodeset ntkstate order)) nil)) (local (defun initial-measure (trlst nodeset ntkstate order) (declare (ignore trlst nodeset ntkstate order)) nil)) (local (defun scheduling (TrLst NodeSet ntkstate order) ;; local witness (mv ;; TrLst updated (if (not (scheduling-assumptions TrLst NodeSet ntkstate order)) (totmissives TrLst) nil) ;; arrived messages ;(if (is-base-measure measure) nil ; TrLst) ;; measure is nil nil ;; ntkstate preserved ntkstate) )) ;; Proof obligations (also named constraints) ;; ----------------------------------------- (defthm scheduled-nil-nil ;; the result of the scheduling function in the case of empty ;; input list is equal to nil (equal (car (scheduling nil nodeset ntkstate order)) nil)) ;; 1/ Types of newTrLst, Arrived and P (state) ;; --------------------------------- ;; The type of newTrLst is a valid traveling missives list (defthm tmissivesp-newTrlst (implies (trlstp TrLst nodeset) (tmissivesp (mv-nth 0 (scheduling TrLst NodeSet ntkstate order)) NodeSet))) ;; so is the list of Arrived (defthm trlstp-Arrived ;; OK (implies (trlstp TrLst nodeset) (trlstp (mv-nth 1 (scheduling TrLst NodeSet ntkstate order)) nodeset))) ;; the state list P is a ValidState (defthm Valid-state-ntkstate (implies (validstate ntkstate) (validstate (mv-nth 3 (scheduling TrLst NodeSet ntkstate order))))) ;; 2/ the measure provided to GeNoC must be decreasing. ;; ------------------------------------------------------ ;; scheduling-assumptions must be a boolean (defthm booleanp-assumptions (booleanp (scheduling-assumptions TrLst NodeSet ntkstate order)) :rule-classes :type-prescription) ;; legal-measure nust be a boolean (defthm booleanp-legal-measure (booleanp (legal-measure measure trlst nodeset ntkstate order)) :rule-classes :type-prescription) ;; the measure must decrease on each call of scheduling (defthm measure-decreases (implies (and (legal-measure measure trlst nodeset ntkstate order) (scheduling-assumptions trlst NodeSet ntkstate order)) (O< (acl2-count (mv-nth 2 (scheduling TrLst NodeSet ntkstate order))) (acl2-count measure)))) ;; 3/ Correctness of the arrived missives ;; ------------------------------------------------------------------ ;; For any arrived missive arr, there exists a unique travel ;; tr in the initial TrLst, such that IdV(arr) = IdV(tr) ;; and FrmV(arr) = FrmV(tr) and RoutesV(arr) is a ;; sublist of RoutesV(tr). ;; In ACL2, the uniqueness of the ids is given by the predicate ;; TrLstp. ;; ------------------------------------------------------------------- ;; First, let us define this correctness (defun s/d-travel-correctness (arr-TrLst TrLst/arr-ids) (if (endp arr-TrLst) (if (endp TrLst/arr-ids) t nil) (let* ((arr-tr (car arr-TrLst)) (tr (car TrLst/arr-ids))) (and (equal (FrmV arr-tr) (FrmV tr)) (equal (IdV arr-tr) (IdV tr)) (equal (OrgV arr-tr) (OrgV tr)) (equal (FlitV arr-tr) (FlitV tr)) (equal (timeV arr-tr) (TimeV tr)) (subsetp (RoutesV arr-tr) (RoutesV tr)) (s/d-travel-correctness (cdr arr-TrLst) (cdr TrLst/arr-ids)))))) (defthm s/d-travel-correctness-unitary (implies (trlstp x nodeset) (s/d-travel-correctness x x))) (defthm arrived-travels-correctness (mv-let (newTrLst Arrived newMeasure newstate ) (scheduling TrLst NodeSet ntkstate order) (declare (ignore newTrLst newMeasure newstate )) (implies (TrLstp TrLst nodeset) (s/d-travel-correctness Arrived (extract-sublst TrLst (V-ids Arrived))))) :hints (("Goal" :in-theory (disable trlstp)))) (defthm subsetp-arrived-newTrLst-ids ;; this should be provable from the two lemmas above ;; but it will always be trivial to prove, and it is ;; useful in subsequent proofs. (mv-let (newTrLst Arrived newMeasure newstate ) (scheduling TrLst NodeSet ntkstate order) (declare (ignore newMeasure newstate )) (implies (TrLstp TrLst nodeset) (and (subsetp (v-ids Arrived) (v-ids Trlst)) (subsetp (Tm-ids newTrLst) (v-ids TrLst)))))) ;; 4. Correctness of the newTrLst travels ;; ------------------------------------- ;; the correctness of the newTrLst travels differs from ;; the correctness of the Arrived travels because, ;; for the Arrived travels we will generally keep only ;; one route, but for the newTrLst travels we will not modify ;; the travels and keep all the routes. In fact, by ;; converting a travel back to a missive we will remove the ;; routes. ;; --------------------------------------------------------- ;; the list newTrLst is equal to filtering the initial ;; TrLst according to the Ids of newTrLst (defthm newTrLst-travel-correctness ;; OK ;; the correctness of newtrlst is the equivalence of the transformation ;;of the newtrlst into missives, and the transformation of the ;;initial trlst (input to the scheduling function) ;;into tmissives and then to missives ;; this rule will cause an infinite number of rewrites that's why ;; it's in rule-classes nil, we have to create an instance to use ;; it (mv-let (newTrLst Arrived newMeasure newstate ) (scheduling TrLst NodeSet ntkstate order) (declare (ignore Arrived newMeasure newstate)) (implies (TrLstp TrLst nodeset) (equal (tomissives newTrLst) (extract-sublst (tomissives(totmissives TrLst)) (Tm-ids newTrLst))))) :rule-classes nil) ;; 6/ if scheduling assumptions are not met, measure is nil (defthm mv-nth-2-scheduling-on-zero-measure ;; OK ;; if the scheduling measure is 0 ;; the new measure is equal to the initial one (implies (and (not (scheduling-assumptions TrLst NodeSet ntkstate order)) (TrLstp trlst nodeset)) (equal (mv-nth 2 (scheduling TrLst NodeSet ntkstate order)) ;; new measure nil))) (defthm mv-nth-0-scheduling-on-zero-measure ;; OK ;; if the scheduling measure is 0 ;; the set of newTrLst s is equal to the initial TrLst (implies (not (scheduling-assumptions TrLst NodeSet ntkstate order)) (equal (mv-nth 0 (scheduling TrLst NodeSet ntkstate order)) (totmissives TrLst)))) ;; 7/ The intersection of the ids of the Arrived travels and those ;; of the newTrLst travels is empty ;; ----------------------------------------------------------------- (defthm not-in-newTrLst-Arrived ;; OK (mv-let (newTrLst Arrived newmeasure newstate ) (scheduling TrLst NodeSet ntkstate order) (declare (ignore newmeasure newstate )) (implies (TrLstp TrLst nodeset) (not-in (Tm-ids newTrLst) (v-ids Arrived))))) ;; some constraints required because we do not have a definition ;; for scheduling (defthm consp-scheduling ;; OK ;; for the mv-nth (consp (scheduling TrLst NodeSet ntkstate order)) :rule-classes :type-prescription) (defthm true-listp-car-scheduling ;; OK (implies (true-listp TrLst) (true-listp (mv-nth 0 (scheduling TrLst NodeSet ntkstate order )))) :rule-classes :type-prescription) (defthm true-listp-mv-nth-1-sched-1 ;; OK (implies (true-listp TrLst) (true-listp (mv-nth 1 (scheduling TrLst NodeSet ntkstate order)))) :rule-classes :type-prescription) (defthm true-listp-mv-nth-1-sched-2 ;; OK (implies (TrLstp TrLst nodeset) (true-listp (mv-nth 1 (scheduling TrLst NodeSet ntkstate order)))) :rule-classes :type-prescription) ) ;; end of scheduling (defthm correctroutesp-s/d-travel-correctness ;; OK ;; correctroutesp between trlst/ids and it's transformation into ;; tmissves, and the s/d-travel-correctness, between trlst/ids and ;; trlst1 ;; implies the correctroutesp between trlst1 and trlst/ids (implies (and (CorrectRoutesp TrLst/ids (ToTMissives TrLst/ids) NodeSet) (s/d-travel-correctness TrLst1 TrLst/ids)) (CorrectRoutesp TrLst1 (ToTMissives TrLst/ids) NodeSet))) (defthm scheduling-preserves-route-correctness ;; OK ;; we prove that sheduling preserve the correctness of the routes ;; after the transformation (mv-let (newTrLst Arrived newmeasure newstate ) (scheduling TrLst NodeSet ntkstate order) (declare (ignore newTrLst newstate newmeasure )) (implies (and (CorrectRoutesp TrLst (ToTMissives TrLst) NodeSet) (TrLstp TrLst nodeset)) (CorrectRoutesp Arrived (ToTMissives (extract-sublst TrLst (V-ids Arrived))) NodeSet))) :otf-flg t :hints (("GOAL" :do-not '(eliminate-destructors generalize) :do-not-induct t :in-theory (disable mv-nth ;; to have my rules used ToTMissives-extract-sublst TrLstp)))) (defthm TMissivesp-mv-nth-0-scheduling ;; OK (let ((NodeSet (NodeSetGenerator Params))) (implies (and (CorrectRoutesp TrLst (ToTMissives TrLst) NodeSet) (ValidParamsp Params) (TrLstp TrLst nodeset)) (TMissivesp (mv-nth 0 (scheduling TrLst NodeSet ntkstate order)) NodeSet))) :hints (("Goal" :use (:instance tmissivesp-newTrlst (nodeset (NodeSetGenerator Params))))))
[ { "context": ";;;; Copyright (c) 2014\n;;;;\n;;;; Robert Strandh ([email protected])\n;;;;\n;;;; all rights r", "end": 52, "score": 0.9998533725738525, "start": 38, "tag": "NAME", "value": "Robert Strandh" }, { "context": " Copyright (c) 2014\n;;;;\n;;;; Robert Strandh ([email protected])\n;;;;\n;;;; all rights reserved.\n;;;;\n;;;; Permiss", "end": 78, "score": 0.9999295473098755, "start": 54, "tag": "EMAIL", "value": "[email protected]" } ]
Code/String/trim.lisp
ebrasca/SICL
1
;;;; Copyright (c) 2014 ;;;; ;;;; Robert Strandh ([email protected]) ;;;; ;;;; all rights reserved. ;;;; ;;;; Permission is hereby granted to use this software for any ;;;; purpose, including using, modifying, and redistributing it. ;;;; ;;;; The software is provided "as-is" with no warranty. The user of ;;;; this software assumes any responsibility of the consequences. ;;;; This file is part of the string module of the SICL project. ;;;; See the file SICL.text for a description of the project. ;;;; See the file string.text for a description of the module. (cl:in-package #:sicl-string) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Utilities. ;;; Check that a list is a proper list of characters. It has already been ;;; checked that the bag is a list. (defun verify-list-bag (bag) (unless (null bag) (loop with slow = bag with fast = bag while (consp fast) unless (characterp (car fast)) do (error 'bag-contains-non-character :datum (car fast) :expected-type 'character) do (setf fast (cdr fast)) while (consp fast) until (eq slow fast) unless (characterp (car fast)) do (error 'bag-contains-non-character :datum (car fast) :expected-type 'character) do (setf fast (cdr fast)) (setf slow (cdr slow)) finally (cond ((eq slow fast) (error 'bag-is-circular-list :datum bag :expected-type 'proper-list)) ((and (atom fast) (not (null fast))) (error 'bag-is-dotted-list :datum bag :expected-type 'proper-list)) (t nil))))) ;;; Check that a vector contains only characters. (defun verify-vector-bag (bag) (loop for element across bag unless (characterp element) do (error 'bag-contains-non-character :datum element :expected-type 'character))) ;;; We assume that the bag has been checked so that it is known to ;;; be a proper list of characters. (defun character-in-list-bag-p (character bag) (declare (type character character) (optimize (speed 3) (safety 0) (debug 0))) (loop for c in bag when (char= character c) return t)) (declaim (inline character-in-list-bag-p)) (defun character-in-simple-string-bag-p (character bag) (declare (type character character) (type simple-string bag) (optimize (speed 3) (safety 0) (debug 0))) (loop for i from 0 below (length bag) when (char= character (schar bag i)) return t)) (declaim (inline character-in-simple-string-bag-p)) (defun character-in-simple-vector-bag-p (character bag) (declare (type character character) (type simple-vector bag) (optimize (speed 3) (safety 0) (debug 0))) (loop for i from 0 below (length bag) when (char= character (svref bag i)) return t)) (declaim (inline character-in-simple-vector-bag-p)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Function STRING-LEFT-TRIM. ;;; A version of STRING-LEFT-TRIM for a character bag represented as a ;;; list, and a string represented as a simple string. (defun string-left-trim-list-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (not (character-in-list-bag-p (schar string 0) character-bag))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum from 0 below length unless (character-in-list-bag-p (schar string i) character-bag) return (extract-interval-simple string i length) finally (return "")))))) ;;; A version of STRING-LEFT-TRIM for a character bag represented as a ;;; simple-string, and a string represented as a simple string. (defun string-left-trim-simple-string-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (not (character-in-simple-string-bag-p (schar string 0) character-bag))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum from 0 below length unless (character-in-simple-string-bag-p (schar string i) character-bag) return (extract-interval-simple string i length) finally (return "")))))) ;;; A version of STRING-LEFT-TRIM for a character bag represented as a ;;; simple vector, and a string represented as a simple string. (defun string-left-trim-simple-vector-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (not (character-in-simple-vector-bag-p (schar string 0) character-bag))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum from 0 below length unless (character-in-simple-vector-bag-p (schar string i) character-bag) return (extract-interval-simple string i length) finally (return "")))))) (defun string-left-trim (character-bag string-designator) (let ((string (string string-designator)) (bag character-bag)) (etypecase bag (list (verify-list-bag bag) (string-left-trim-list-simple-string bag string)) (simple-string (string-left-trim-simple-string-simple-string bag string)) (simple-vector (verify-vector-bag bag) (string-left-trim-simple-vector-simple-string bag string))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Function STRING-RIGHT-TRIM. ;;; A version of STRING-RIGHT-TRIM for a character bag represented as a ;;; list, and a string represented as a simple string. (defun string-right-trim-list-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (not (character-in-list-bag-p (schar string (1- length)) character-bag))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum downfrom (1- length) to 0 unless (character-in-list-bag-p (schar string i) character-bag) return (extract-interval-simple string 0 (1+ i)) finally (return "")))))) ;;; A version of STRING-RIGHT-TRIM for a character bag represented as a ;;; simple-string, and a string represented as a simple string. (defun string-right-trim-simple-string-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (not (character-in-simple-string-bag-p (schar string (1- length)) character-bag))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum downfrom (1- length) to 0 unless (character-in-simple-string-bag-p (schar string i) character-bag) return (extract-interval-simple string 0 (1+ i)) finally (return "")))))) ;;; A version of STRING-RIGHT-TRIM for a character bag represented as a ;;; simple vector, and a string represented as a simple string. (defun string-right-trim-simple-vector-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (not (character-in-simple-vector-bag-p (schar string (1- length)) character-bag))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum downfrom (1- length) to 0 unless (character-in-simple-vector-bag-p (schar string i) character-bag) return (extract-interval-simple string 0 (1+ i)) finally (return "")))))) (defun string-right-trim (character-bag string-designator) (let ((string (string string-designator)) (bag character-bag)) (etypecase bag (list (verify-list-bag bag) (string-right-trim-list-simple-string bag string)) (simple-string (string-right-trim-simple-string-simple-string bag string)) (simple-vector (verify-vector-bag bag) (string-right-trim-simple-vector-simple-string bag string))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Function STRING-TRIM. ;;; A version of STRING-TRIM for a character bag represented as a ;;; list, and a string represented as a simple string. (defun string-trim-list-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (and (not (character-in-list-bag-p (schar string 0) character-bag)) (not (character-in-list-bag-p (schar string (1- length)) character-bag)))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum downfrom (1- length) to 0 unless (character-in-list-bag-p (schar string i) character-bag) return (loop for j from 0 to i unless (character-in-list-bag-p (schar string j) character-bag) return (extract-interval-simple string j (1+ i))) finally (return "")))))) ;;; A version of STRING-TRIM for a character bag represented as a ;;; simple-string, and a string represented as a simple string. (defun string-trim-simple-string-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (and (not (character-in-simple-string-bag-p (schar string 0) character-bag)) (not (character-in-simple-string-bag-p (schar string (1- length)) character-bag)))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum downfrom (1- length) to 0 unless (character-in-simple-string-bag-p (schar string i) character-bag) return (loop for j from 0 to i unless (character-in-simple-string-bag-p (schar string j) character-bag) return (extract-interval-simple string j (1+ i))) finally (return "")))))) ;;; A version of STRING-TRIM for a character bag represented as a ;;; simple vector, and a string represented as a simple string. (defun string-trim-simple-vector-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (and (not (character-in-simple-vector-bag-p (schar string 0) character-bag)) (not (character-in-simple-vector-bag-p (schar string (1- length)) character-bag)))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum downfrom (1- length) to 0 unless (character-in-simple-vector-bag-p (schar string i) character-bag) return (loop for j from 0 to i unless (character-in-simple-vector-bag-p (schar string j) character-bag) return (extract-interval-simple string j (1+ i))) finally (return "")))))) (defun string-trim (character-bag string-designator) (let ((string (string string-designator)) (bag character-bag)) (etypecase bag (list (verify-list-bag bag) (string-trim-list-simple-string bag string)) (simple-string (string-trim-simple-string-simple-string bag string)) (simple-vector (verify-vector-bag bag) (string-trim-simple-vector-simple-string bag string)))))
20973
;;;; Copyright (c) 2014 ;;;; ;;;; <NAME> (<EMAIL>) ;;;; ;;;; all rights reserved. ;;;; ;;;; Permission is hereby granted to use this software for any ;;;; purpose, including using, modifying, and redistributing it. ;;;; ;;;; The software is provided "as-is" with no warranty. The user of ;;;; this software assumes any responsibility of the consequences. ;;;; This file is part of the string module of the SICL project. ;;;; See the file SICL.text for a description of the project. ;;;; See the file string.text for a description of the module. (cl:in-package #:sicl-string) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Utilities. ;;; Check that a list is a proper list of characters. It has already been ;;; checked that the bag is a list. (defun verify-list-bag (bag) (unless (null bag) (loop with slow = bag with fast = bag while (consp fast) unless (characterp (car fast)) do (error 'bag-contains-non-character :datum (car fast) :expected-type 'character) do (setf fast (cdr fast)) while (consp fast) until (eq slow fast) unless (characterp (car fast)) do (error 'bag-contains-non-character :datum (car fast) :expected-type 'character) do (setf fast (cdr fast)) (setf slow (cdr slow)) finally (cond ((eq slow fast) (error 'bag-is-circular-list :datum bag :expected-type 'proper-list)) ((and (atom fast) (not (null fast))) (error 'bag-is-dotted-list :datum bag :expected-type 'proper-list)) (t nil))))) ;;; Check that a vector contains only characters. (defun verify-vector-bag (bag) (loop for element across bag unless (characterp element) do (error 'bag-contains-non-character :datum element :expected-type 'character))) ;;; We assume that the bag has been checked so that it is known to ;;; be a proper list of characters. (defun character-in-list-bag-p (character bag) (declare (type character character) (optimize (speed 3) (safety 0) (debug 0))) (loop for c in bag when (char= character c) return t)) (declaim (inline character-in-list-bag-p)) (defun character-in-simple-string-bag-p (character bag) (declare (type character character) (type simple-string bag) (optimize (speed 3) (safety 0) (debug 0))) (loop for i from 0 below (length bag) when (char= character (schar bag i)) return t)) (declaim (inline character-in-simple-string-bag-p)) (defun character-in-simple-vector-bag-p (character bag) (declare (type character character) (type simple-vector bag) (optimize (speed 3) (safety 0) (debug 0))) (loop for i from 0 below (length bag) when (char= character (svref bag i)) return t)) (declaim (inline character-in-simple-vector-bag-p)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Function STRING-LEFT-TRIM. ;;; A version of STRING-LEFT-TRIM for a character bag represented as a ;;; list, and a string represented as a simple string. (defun string-left-trim-list-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (not (character-in-list-bag-p (schar string 0) character-bag))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum from 0 below length unless (character-in-list-bag-p (schar string i) character-bag) return (extract-interval-simple string i length) finally (return "")))))) ;;; A version of STRING-LEFT-TRIM for a character bag represented as a ;;; simple-string, and a string represented as a simple string. (defun string-left-trim-simple-string-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (not (character-in-simple-string-bag-p (schar string 0) character-bag))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum from 0 below length unless (character-in-simple-string-bag-p (schar string i) character-bag) return (extract-interval-simple string i length) finally (return "")))))) ;;; A version of STRING-LEFT-TRIM for a character bag represented as a ;;; simple vector, and a string represented as a simple string. (defun string-left-trim-simple-vector-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (not (character-in-simple-vector-bag-p (schar string 0) character-bag))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum from 0 below length unless (character-in-simple-vector-bag-p (schar string i) character-bag) return (extract-interval-simple string i length) finally (return "")))))) (defun string-left-trim (character-bag string-designator) (let ((string (string string-designator)) (bag character-bag)) (etypecase bag (list (verify-list-bag bag) (string-left-trim-list-simple-string bag string)) (simple-string (string-left-trim-simple-string-simple-string bag string)) (simple-vector (verify-vector-bag bag) (string-left-trim-simple-vector-simple-string bag string))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Function STRING-RIGHT-TRIM. ;;; A version of STRING-RIGHT-TRIM for a character bag represented as a ;;; list, and a string represented as a simple string. (defun string-right-trim-list-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (not (character-in-list-bag-p (schar string (1- length)) character-bag))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum downfrom (1- length) to 0 unless (character-in-list-bag-p (schar string i) character-bag) return (extract-interval-simple string 0 (1+ i)) finally (return "")))))) ;;; A version of STRING-RIGHT-TRIM for a character bag represented as a ;;; simple-string, and a string represented as a simple string. (defun string-right-trim-simple-string-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (not (character-in-simple-string-bag-p (schar string (1- length)) character-bag))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum downfrom (1- length) to 0 unless (character-in-simple-string-bag-p (schar string i) character-bag) return (extract-interval-simple string 0 (1+ i)) finally (return "")))))) ;;; A version of STRING-RIGHT-TRIM for a character bag represented as a ;;; simple vector, and a string represented as a simple string. (defun string-right-trim-simple-vector-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (not (character-in-simple-vector-bag-p (schar string (1- length)) character-bag))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum downfrom (1- length) to 0 unless (character-in-simple-vector-bag-p (schar string i) character-bag) return (extract-interval-simple string 0 (1+ i)) finally (return "")))))) (defun string-right-trim (character-bag string-designator) (let ((string (string string-designator)) (bag character-bag)) (etypecase bag (list (verify-list-bag bag) (string-right-trim-list-simple-string bag string)) (simple-string (string-right-trim-simple-string-simple-string bag string)) (simple-vector (verify-vector-bag bag) (string-right-trim-simple-vector-simple-string bag string))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Function STRING-TRIM. ;;; A version of STRING-TRIM for a character bag represented as a ;;; list, and a string represented as a simple string. (defun string-trim-list-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (and (not (character-in-list-bag-p (schar string 0) character-bag)) (not (character-in-list-bag-p (schar string (1- length)) character-bag)))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum downfrom (1- length) to 0 unless (character-in-list-bag-p (schar string i) character-bag) return (loop for j from 0 to i unless (character-in-list-bag-p (schar string j) character-bag) return (extract-interval-simple string j (1+ i))) finally (return "")))))) ;;; A version of STRING-TRIM for a character bag represented as a ;;; simple-string, and a string represented as a simple string. (defun string-trim-simple-string-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (and (not (character-in-simple-string-bag-p (schar string 0) character-bag)) (not (character-in-simple-string-bag-p (schar string (1- length)) character-bag)))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum downfrom (1- length) to 0 unless (character-in-simple-string-bag-p (schar string i) character-bag) return (loop for j from 0 to i unless (character-in-simple-string-bag-p (schar string j) character-bag) return (extract-interval-simple string j (1+ i))) finally (return "")))))) ;;; A version of STRING-TRIM for a character bag represented as a ;;; simple vector, and a string represented as a simple string. (defun string-trim-simple-vector-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (and (not (character-in-simple-vector-bag-p (schar string 0) character-bag)) (not (character-in-simple-vector-bag-p (schar string (1- length)) character-bag)))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum downfrom (1- length) to 0 unless (character-in-simple-vector-bag-p (schar string i) character-bag) return (loop for j from 0 to i unless (character-in-simple-vector-bag-p (schar string j) character-bag) return (extract-interval-simple string j (1+ i))) finally (return "")))))) (defun string-trim (character-bag string-designator) (let ((string (string string-designator)) (bag character-bag)) (etypecase bag (list (verify-list-bag bag) (string-trim-list-simple-string bag string)) (simple-string (string-trim-simple-string-simple-string bag string)) (simple-vector (verify-vector-bag bag) (string-trim-simple-vector-simple-string bag string)))))
true
;;;; Copyright (c) 2014 ;;;; ;;;; PI:NAME:<NAME>END_PI (PI:EMAIL:<EMAIL>END_PI) ;;;; ;;;; all rights reserved. ;;;; ;;;; Permission is hereby granted to use this software for any ;;;; purpose, including using, modifying, and redistributing it. ;;;; ;;;; The software is provided "as-is" with no warranty. The user of ;;;; this software assumes any responsibility of the consequences. ;;;; This file is part of the string module of the SICL project. ;;;; See the file SICL.text for a description of the project. ;;;; See the file string.text for a description of the module. (cl:in-package #:sicl-string) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Utilities. ;;; Check that a list is a proper list of characters. It has already been ;;; checked that the bag is a list. (defun verify-list-bag (bag) (unless (null bag) (loop with slow = bag with fast = bag while (consp fast) unless (characterp (car fast)) do (error 'bag-contains-non-character :datum (car fast) :expected-type 'character) do (setf fast (cdr fast)) while (consp fast) until (eq slow fast) unless (characterp (car fast)) do (error 'bag-contains-non-character :datum (car fast) :expected-type 'character) do (setf fast (cdr fast)) (setf slow (cdr slow)) finally (cond ((eq slow fast) (error 'bag-is-circular-list :datum bag :expected-type 'proper-list)) ((and (atom fast) (not (null fast))) (error 'bag-is-dotted-list :datum bag :expected-type 'proper-list)) (t nil))))) ;;; Check that a vector contains only characters. (defun verify-vector-bag (bag) (loop for element across bag unless (characterp element) do (error 'bag-contains-non-character :datum element :expected-type 'character))) ;;; We assume that the bag has been checked so that it is known to ;;; be a proper list of characters. (defun character-in-list-bag-p (character bag) (declare (type character character) (optimize (speed 3) (safety 0) (debug 0))) (loop for c in bag when (char= character c) return t)) (declaim (inline character-in-list-bag-p)) (defun character-in-simple-string-bag-p (character bag) (declare (type character character) (type simple-string bag) (optimize (speed 3) (safety 0) (debug 0))) (loop for i from 0 below (length bag) when (char= character (schar bag i)) return t)) (declaim (inline character-in-simple-string-bag-p)) (defun character-in-simple-vector-bag-p (character bag) (declare (type character character) (type simple-vector bag) (optimize (speed 3) (safety 0) (debug 0))) (loop for i from 0 below (length bag) when (char= character (svref bag i)) return t)) (declaim (inline character-in-simple-vector-bag-p)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Function STRING-LEFT-TRIM. ;;; A version of STRING-LEFT-TRIM for a character bag represented as a ;;; list, and a string represented as a simple string. (defun string-left-trim-list-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (not (character-in-list-bag-p (schar string 0) character-bag))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum from 0 below length unless (character-in-list-bag-p (schar string i) character-bag) return (extract-interval-simple string i length) finally (return "")))))) ;;; A version of STRING-LEFT-TRIM for a character bag represented as a ;;; simple-string, and a string represented as a simple string. (defun string-left-trim-simple-string-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (not (character-in-simple-string-bag-p (schar string 0) character-bag))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum from 0 below length unless (character-in-simple-string-bag-p (schar string i) character-bag) return (extract-interval-simple string i length) finally (return "")))))) ;;; A version of STRING-LEFT-TRIM for a character bag represented as a ;;; simple vector, and a string represented as a simple string. (defun string-left-trim-simple-vector-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (not (character-in-simple-vector-bag-p (schar string 0) character-bag))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum from 0 below length unless (character-in-simple-vector-bag-p (schar string i) character-bag) return (extract-interval-simple string i length) finally (return "")))))) (defun string-left-trim (character-bag string-designator) (let ((string (string string-designator)) (bag character-bag)) (etypecase bag (list (verify-list-bag bag) (string-left-trim-list-simple-string bag string)) (simple-string (string-left-trim-simple-string-simple-string bag string)) (simple-vector (verify-vector-bag bag) (string-left-trim-simple-vector-simple-string bag string))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Function STRING-RIGHT-TRIM. ;;; A version of STRING-RIGHT-TRIM for a character bag represented as a ;;; list, and a string represented as a simple string. (defun string-right-trim-list-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (not (character-in-list-bag-p (schar string (1- length)) character-bag))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum downfrom (1- length) to 0 unless (character-in-list-bag-p (schar string i) character-bag) return (extract-interval-simple string 0 (1+ i)) finally (return "")))))) ;;; A version of STRING-RIGHT-TRIM for a character bag represented as a ;;; simple-string, and a string represented as a simple string. (defun string-right-trim-simple-string-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (not (character-in-simple-string-bag-p (schar string (1- length)) character-bag))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum downfrom (1- length) to 0 unless (character-in-simple-string-bag-p (schar string i) character-bag) return (extract-interval-simple string 0 (1+ i)) finally (return "")))))) ;;; A version of STRING-RIGHT-TRIM for a character bag represented as a ;;; simple vector, and a string represented as a simple string. (defun string-right-trim-simple-vector-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (not (character-in-simple-vector-bag-p (schar string (1- length)) character-bag))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum downfrom (1- length) to 0 unless (character-in-simple-vector-bag-p (schar string i) character-bag) return (extract-interval-simple string 0 (1+ i)) finally (return "")))))) (defun string-right-trim (character-bag string-designator) (let ((string (string string-designator)) (bag character-bag)) (etypecase bag (list (verify-list-bag bag) (string-right-trim-list-simple-string bag string)) (simple-string (string-right-trim-simple-string-simple-string bag string)) (simple-vector (verify-vector-bag bag) (string-right-trim-simple-vector-simple-string bag string))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Function STRING-TRIM. ;;; A version of STRING-TRIM for a character bag represented as a ;;; list, and a string represented as a simple string. (defun string-trim-list-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (and (not (character-in-list-bag-p (schar string 0) character-bag)) (not (character-in-list-bag-p (schar string (1- length)) character-bag)))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum downfrom (1- length) to 0 unless (character-in-list-bag-p (schar string i) character-bag) return (loop for j from 0 to i unless (character-in-list-bag-p (schar string j) character-bag) return (extract-interval-simple string j (1+ i))) finally (return "")))))) ;;; A version of STRING-TRIM for a character bag represented as a ;;; simple-string, and a string represented as a simple string. (defun string-trim-simple-string-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (and (not (character-in-simple-string-bag-p (schar string 0) character-bag)) (not (character-in-simple-string-bag-p (schar string (1- length)) character-bag)))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum downfrom (1- length) to 0 unless (character-in-simple-string-bag-p (schar string i) character-bag) return (loop for j from 0 to i unless (character-in-simple-string-bag-p (schar string j) character-bag) return (extract-interval-simple string j (1+ i))) finally (return "")))))) ;;; A version of STRING-TRIM for a character bag represented as a ;;; simple vector, and a string represented as a simple string. (defun string-trim-simple-vector-simple-string (character-bag string) (declare (type simple-string string)) (let ((length (length string))) (declare (type fixnum length)) (if (or (zerop length) (and (not (character-in-simple-vector-bag-p (schar string 0) character-bag)) (not (character-in-simple-vector-bag-p (schar string (1- length)) character-bag)))) string (locally (declare (optimize (speed 3) (debug 0) (safety 0))) (loop for i of-type fixnum downfrom (1- length) to 0 unless (character-in-simple-vector-bag-p (schar string i) character-bag) return (loop for j from 0 to i unless (character-in-simple-vector-bag-p (schar string j) character-bag) return (extract-interval-simple string j (1+ i))) finally (return "")))))) (defun string-trim (character-bag string-designator) (let ((string (string string-designator)) (bag character-bag)) (etypecase bag (list (verify-list-bag bag) (string-trim-list-simple-string bag string)) (simple-string (string-trim-simple-string-simple-string bag string)) (simple-vector (verify-vector-bag bag) (string-trim-simple-vector-simple-string bag string)))))
[{"context":"lize.lisp\n\n#|\nThe MIT license.\n\nCopyright (c) 2013 Paul L. Krueger\n\nPermission i(...TRUNCATED)
Utilities/objc-initialize.lisp
plkrueger/CocoaInterface
34
";; objc-initialize.lisp\n\n#|\nThe MIT license.\n\nCopyright (c) 2013 Paul L. Krueger\n\nPermission(...TRUNCATED)
59242
";; objc-initialize.lisp\n\n#|\nThe MIT license.\n\nCopyright (c) 2013 <NAME>\n\nPermission is hereb(...TRUNCATED)
true
";; objc-initialize.lisp\n\n#|\nThe MIT license.\n\nCopyright (c) 2013 PI:NAME:<NAME>END_PI\n\nPermi(...TRUNCATED)
[{"context":"ense. See the file books/3BSD-mod.txt.\n;\n; Author: Eric Smith ([email protected](...TRUNCATED)
books/kestrel/utilities/file-existsp.lisp
mayankmanj/acl2
305
"; A tool to tell whether a file exists\n;\n; Copyright (C) 2015-2021 Kestrel Institute\n;\n; Licens(...TRUNCATED)
72837
"; A tool to tell whether a file exists\n;\n; Copyright (C) 2015-2021 Kestrel Institute\n;\n; Licens(...TRUNCATED)
true
"; A tool to tell whether a file exists\n;\n; Copyright (C) 2015-2021 Kestrel Institute\n;\n; Licens(...TRUNCATED)
[{"context":"onway's Game of Life in Common Lisp. \"\n :author \"Andreas Ruscheinski <andreas.rusch(...TRUNCATED)
gol-render-demos.asd
aruscher/gol-render-demos
0
";;;; gol-render-demos.asd\n\n(asdf:defsystem #:gol-render-demos\n :description \"A collection of d(...TRUNCATED)
24606
";;;; gol-render-demos.asd\n\n(asdf:defsystem #:gol-render-demos\n :description \"A collection of d(...TRUNCATED)
true
";;;; gol-render-demos.asd\n\n(asdf:defsystem #:gol-render-demos\n :description \"A collection of d(...TRUNCATED)
[{"context":"he LICENSE file distributed with ACL2.\n;\n; Author: Eric McCarthy ([email protected](...TRUNCATED)
books/kestrel/crypto/ecdsa/deterministic-ecdsa-secp256k1-tests.lisp
mayankmanj/acl2
305
"; Tests of the RFC 6979 Deterministic ECDSA formalization.\n;\n; Copyright (C) 2019 Kestrel Institu(...TRUNCATED)
4281
"; Tests of the RFC 6979 Deterministic ECDSA formalization.\n;\n; Copyright (C) 2019 Kestrel Institu(...TRUNCATED)
true
"; Tests of the RFC 6979 Deterministic ECDSA formalization.\n;\n; Copyright (C) 2019 Kestrel Institu(...TRUNCATED)
[{"context":"sd)\n\n(defsystem t-lack-middleware-csrf\n :author \"Eitaro Fukamachi\"\n :license \"(...TRUNCATED)
bundle-libs/software/lack-20190521-git/t-lack-middleware-csrf.asd
dbym4820/photon
4
"(in-package :cl-user)\n(defpackage t-lack-middleware-csrf-asd\n (:use :cl :asdf))\n(in-package :t-(...TRUNCATED)
16650
"(in-package :cl-user)\n(defpackage t-lack-middleware-csrf-asd\n (:use :cl :asdf))\n(in-package :t-(...TRUNCATED)
true
"(in-package :cl-user)\n(defpackage t-lack-middleware-csrf-asd\n (:use :cl :asdf))\n(in-package :t-(...TRUNCATED)
[{"context":";; Copyright 2010-2018 Ben Lambert\n\n;; Licensed under the Apache License, Version 2."(...TRUNCATED)
src/util.lisp
belambert/lisp-asr
10
";; Copyright 2010-2018 Ben Lambert\n\n;; Licensed under the Apache License, Version 2.0 (the \"Lice(...TRUNCATED)
33852
";; Copyright 2010-2018 <NAME>\n\n;; Licensed under the Apache License, Version 2.0 (the \"License\"(...TRUNCATED)
true
";; Copyright 2010-2018 PI:NAME:<NAME>END_PI\n\n;; Licensed under the Apache License, Version 2.0 (t(...TRUNCATED)
[{"context":"ary for script reading and executing.\"\n :author \"Isoraķatheð Zorethan <isoraqathe(...TRUNCATED)
sclript.asd
isoraqathedh/sclript
5
";;;; sclript.asd\n\n(asdf:defsystem #:sclript\n :description \"Common library for script reading a(...TRUNCATED)
31221
";;;; sclript.asd\n\n(asdf:defsystem #:sclript\n :description \"Common library for script reading a(...TRUNCATED)
true
";;;; sclript.asd\n\n(asdf:defsystem #:sclript\n :description \"Common library for script reading a(...TRUNCATED)
[{"context":"anteau\n :description \"cl-portmanteau\"\n :author \"Sergey Polzunov <sergey@polzunov(...TRUNCATED)
portmanteau.asd
traut/cl-portmanteau
1
"(asdf:defsystem #:portmanteau\n :description \"cl-portmanteau\"\n :author \"Sergey Polzunov <serg(...TRUNCATED)
23062
"(asdf:defsystem #:portmanteau\n :description \"cl-portmanteau\"\n :author \"<NAME> <<EMAIL>>\"\n (...TRUNCATED)
true
"(asdf:defsystem #:portmanteau\n :description \"cl-portmanteau\"\n :author \"PI:NAME:<NAME>END_PI (...TRUNCATED)

Dataset Card for "common-lisp_checks"

More Information needed

Downloads last month
40
Edit dataset card