Friday, November 13, 2015

Implement an calculator (64 bit Binary Multiplication) application using concurrent lisp

Program

(defun mul(a b)
(if (string= b "1") a 0)
)
(setf a (read-line))
(setf b (read-line))
(setf b_len (length b))
(setf b1_len (- b_len 1))
(setf an (parse-integer a))
(setf bn (parse-integer b))
(setf c (make-array b_len))
(dotimes (x b_len) (setf (aref c x) (mul (* an (expt 10 x)) (subseq b (- b1_len x) (+ 1 (- b1_len x))))))
(setf c1 0)
(dotimes (x b_len) (setf c1 (+ c1 (aref c x))))
(print c1)
(setf c3 "0")
(setf c2 (concatenate 'string c3 (write-to-string c1)))
(print c2)
(setf c2_len (length c2))
(print c2_len)
(setf c21_len (- c2_len 1))
(print c21_len)
(dotimes (x c21_len)
(setf temp (- c21_len x))
(setf prev (parse-integer (subseq c2 temp (+ temp 1))))
(setf modt (mod (parse-integer (subseq c2 temp (+ temp 1))) 2))
(setf (subseq c2 temp (+ temp 1)) (write-to-string modt))
(setf db2 (- prev modt))
(setf addp (+ (parse-integer (subseq c2 (- temp 1) temp)) (/ db2 2)))
(setf (subseq c2 (- temp 1) temp) (write-to-string addp))
(print temp)
(print modt)
(print addp)
)
(print "loop finished")
(print c2)

Output

* (load "binmul.lisp")

; in: SETF A
;     (SETF A (READ-LINE))
; ==>
;   (SETQ A (READ-LINE))

; caught WARNING:
;   undefined variable: A

; compilation unit finished
;   Undefined variable:
;     A
;   caught 1 WARNING condition
1010

; in: SETF B
;     (SETF B (READ-LINE))
; ==>
;   (SETQ B (READ-LINE))

; caught WARNING:
;   undefined variable: B

; compilation unit finished
;   Undefined variable:
;     B
;   caught 1 WARNING condition
1111

; in: SETF B_LEN
;     (LENGTH B)

; caught WARNING:
;   undefined variable: B

;     (SETF B_LEN (LENGTH B))
; ==>
;   (SETQ B_LEN (LENGTH B))

; caught WARNING:
;   undefined variable: B_LEN

; compilation unit finished
;   Undefined variables:
;     B B_LEN
;   caught 2 WARNING conditions

; in: SETF B1_LEN
;     (SETF B1_LEN (- B_LEN 1))
; ==>
;   (SETQ B1_LEN (- B_LEN 1))

; caught WARNING:
;   undefined variable: B1_LEN

;     (- B_LEN 1)

; caught WARNING:
;   undefined variable: B_LEN

; compilation unit finished
;   Undefined variables:
;     B1_LEN B_LEN
;   caught 2 WARNING conditions

; in: SETF AN
;     (PARSE-INTEGER A)

; caught WARNING:
;   undefined variable: A

;     (SETF AN (PARSE-INTEGER A))
; ==>
;   (SETQ AN (PARSE-INTEGER A))

; caught WARNING:
;   undefined variable: AN

; compilation unit finished
;   Undefined variables:
;     A AN
;   caught 2 WARNING conditions

; in: SETF BN
;     (PARSE-INTEGER B)

; caught WARNING:
;   undefined variable: B

;     (SETF BN (PARSE-INTEGER B))
; ==>
;   (SETQ BN (PARSE-INTEGER B))

; caught WARNING:
;   undefined variable: BN

; compilation unit finished
;   Undefined variables:
;     B BN
;   caught 2 WARNING conditions

; in: SETF C
;     (MAKE-ARRAY B_LEN)
; --> LOCALLY 
; ==>
;   (MAKE-ARRAY B_LEN)

; caught WARNING:
;   undefined variable: B_LEN

;     (SETF C (MAKE-ARRAY B_LEN))
; ==>
;   (SETQ C (MAKE-ARRAY B_LEN))

; caught WARNING:
;   undefined variable: C

; compilation unit finished
;   Undefined variables:
;     B_LEN C
;   caught 2 WARNING conditions

; in: DOTIMES (X B_LEN)
;     (* AN (EXPT 10 X))

; caught WARNING:
;   undefined variable: AN

;     (SUBSEQ B (- B1_LEN X) (+ 1 (- B1_LEN X)))

; caught WARNING:
;   undefined variable: B

;     (- B1_LEN X)

; caught WARNING:
;   undefined variable: B1_LEN

;     (DOTIMES (X B_LEN) (SETF (AREF C X) (MUL (* AN #) (SUBSEQ B # #))))
; --> PROGN BLOCK 
; ==>
;   (LET ((X 0) (#:COUNT886 B_LEN))
;     (DECLARE (TYPE UNSIGNED-BYTE X)
;              (TYPE INTEGER #:COUNT886))
;     (TAGBODY
;       (GO #:G888)
;      #:G887
;       (TAGBODY (SETF # #))
;       (PSETQ X (1+ X))
;      #:G888
;       (UNLESS (>= X #:COUNT886) (GO #:G887))
;       (RETURN-FROM NIL (PROGN NIL))))

; caught WARNING:
;   undefined variable: B_LEN

;     (SETF (AREF C X) (MUL (* AN (EXPT 10 X)) (SUBSEQ B (- B1_LEN X) (+ 1 #))))
; ==>
;   (SB-KERNEL:%ASET C X
;                    (MUL (* AN (EXPT 10 X))
;                         (SUBSEQ B (- B1_LEN X) (+ 1 (- B1_LEN X)))))

; caught WARNING:
;   undefined variable: C

; compilation unit finished
;   Undefined variables:
;     AN B B1_LEN B_LEN C
;   caught 5 WARNING conditions

; in: SETF C1
;     (SETF C1 0)
; ==>
;   (SETQ C1 0)

; caught WARNING:
;   undefined variable: C1

; compilation unit finished
;   Undefined variable:
;     C1
;   caught 1 WARNING condition

; in: DOTIMES (X B_LEN)
;     (DOTIMES (X B_LEN) (SETF C1 (+ C1 (AREF C X))))
; --> PROGN BLOCK 
; ==>
;   (LET ((X 0) (#:COUNT889 B_LEN))
;     (DECLARE (TYPE UNSIGNED-BYTE X)
;              (TYPE INTEGER #:COUNT889))
;     (TAGBODY
;       (GO #:G891)
;      #:G890
;       (TAGBODY (SETF C1 #))
;       (PSETQ X (1+ X))
;      #:G891
;       (UNLESS (>= X #:COUNT889) (GO #:G890))
;       (RETURN-FROM NIL (PROGN NIL))))

; caught WARNING:
;   undefined variable: B_LEN

;     (AREF C X)

; caught WARNING:
;   undefined variable: C

;     (SETF C1 (+ C1 (AREF C X)))
; ==>
;   (SETQ C1 (+ C1 (AREF C X)))

; caught WARNING:
;   undefined variable: C1

; compilation unit finished
;   Undefined variables:
;     B_LEN C C1
;   caught 3 WARNING conditions


; in: SETF C3
;     (SETF C3 "0")
; ==>
;   (SETQ C3 "0")

; caught WARNING:
;   undefined variable: C3

; compilation unit finished
;   Undefined variable:
;     C3
;   caught 1 WARNING condition

; in: SETF C2
;     (WRITE-TO-STRING C1)
; ==>
;   (SB-IMPL::STRINGIFY-OBJECT C1)

; caught WARNING:
;   undefined variable: C1

;     (SETF C2 (CONCATENATE 'STRING C3 (WRITE-TO-STRING C1)))
; ==>
;   (SETQ C2 (CONCATENATE 'STRING C3 (WRITE-TO-STRING C1)))

; caught WARNING:
;   undefined variable: C2

;     (CONCATENATE 'STRING C3 (WRITE-TO-STRING C1))

; caught WARNING:
;   undefined variable: C3

; compilation unit finished
;   Undefined variables:
;     C1 C2 C3
;   caught 3 WARNING conditions
1122110 

; in: SETF C2_LEN
;     (LENGTH C2)

; caught WARNING:
;   undefined variable: C2

;     (SETF C2_LEN (LENGTH C2))
; ==>
;   (SETQ C2_LEN (LENGTH C2))

; caught WARNING:
;   undefined variable: C2_LEN

; compilation unit finished
;   Undefined variables:
;     C2 C2_LEN
;   caught 2 WARNING conditions
"01122110" 

; in: SETF C21_LEN
;     (SETF C21_LEN (- C2_LEN 1))
; ==>
;   (SETQ C21_LEN (- C2_LEN 1))

; caught WARNING:
;   undefined variable: C21_LEN

;     (- C2_LEN 1)

; caught WARNING:
;   undefined variable: C2_LEN

; compilation unit finished
;   Undefined variables:
;     C21_LEN C2_LEN
;   caught 2 WARNING conditions


; in: DOTIMES (X C21_LEN)
;     (SETF ADDP (+ (PARSE-INTEGER (SUBSEQ C2 # TEMP)) (/ DB2 2)))
; ==>
;   (SETQ ADDP (+ (PARSE-INTEGER (SUBSEQ C2 # TEMP)) (/ DB2 2)))

; caught WARNING:
;   undefined variable: ADDP

;     (SUBSEQ C2 TEMP (+ TEMP 1))

; caught WARNING:
;   undefined variable: C2

;     (- C21_LEN X)

; caught WARNING:
;   undefined variable: C21_LEN

;     (SETF DB2 (- PREV MODT))
; ==>
;   (SETQ DB2 (- PREV MODT))

; caught WARNING:
;   undefined variable: DB2

;     (SETF MODT (MOD (PARSE-INTEGER (SUBSEQ C2 TEMP #)) 2))
; ==>
;   (SETQ MODT (MOD (PARSE-INTEGER (SUBSEQ C2 TEMP #)) 2))

; caught WARNING:
;   undefined variable: MODT

;     (SETF PREV (PARSE-INTEGER (SUBSEQ C2 TEMP (+ TEMP 1))))
; ==>
;   (SETQ PREV (PARSE-INTEGER (SUBSEQ C2 TEMP (+ TEMP 1))))

; caught WARNING:
;   undefined variable: PREV

;     (SETF TEMP (- C21_LEN X))
; ==>
;   (SETQ TEMP (- C21_LEN X))

; caught WARNING:
;   undefined variable: TEMP

; compilation unit finished
;   Undefined variables:
;     ADDP C2 C21_LEN DB2 MODT PREV TEMP
;   caught 7 WARNING conditions






















"loop finished" 
"10010110" 
T
* (load "binmul.lisp")

; in: SETF A
;     (SETF A (READ-LINE))
; ==>
;   (SETQ A (READ-LINE))

; caught WARNING:
;   undefined variable: A

; compilation unit finished
;   Undefined variable:
;     A
;   caught 1 WARNING condition
1111

; in: SETF B
;     (SETF B (READ-LINE))
; ==>
;   (SETQ B (READ-LINE))

; caught WARNING:
;   undefined variable: B

; compilation unit finished
;   Undefined variable:
;     B
;   caught 1 WARNING condition
1111

; in: SETF B_LEN
;     (LENGTH B)

; caught WARNING:
;   undefined variable: B

;     (SETF B_LEN (LENGTH B))
; ==>
;   (SETQ B_LEN (LENGTH B))

; caught WARNING:
;   undefined variable: B_LEN

; compilation unit finished
;   Undefined variables:
;     B B_LEN
;   caught 2 WARNING conditions

; in: SETF B1_LEN
;     (SETF B1_LEN (- B_LEN 1))
; ==>
;   (SETQ B1_LEN (- B_LEN 1))

; caught WARNING:
;   undefined variable: B1_LEN

;     (- B_LEN 1)

; caught WARNING:
;   undefined variable: B_LEN

; compilation unit finished
;   Undefined variables:
;     B1_LEN B_LEN
;   caught 2 WARNING conditions

; in: SETF AN
;     (PARSE-INTEGER A)

; caught WARNING:
;   undefined variable: A

;     (SETF AN (PARSE-INTEGER A))
; ==>
;   (SETQ AN (PARSE-INTEGER A))

; caught WARNING:
;   undefined variable: AN

; compilation unit finished
;   Undefined variables:
;     A AN
;   caught 2 WARNING conditions

; in: SETF BN
;     (PARSE-INTEGER B)

; caught WARNING:
;   undefined variable: B

;     (SETF BN (PARSE-INTEGER B))
; ==>
;   (SETQ BN (PARSE-INTEGER B))

; caught WARNING:
;   undefined variable: BN

; compilation unit finished
;   Undefined variables:
;     B BN
;   caught 2 WARNING conditions

; in: SETF C
;     (MAKE-ARRAY B_LEN)
; --> LOCALLY 
; ==>
;   (MAKE-ARRAY B_LEN)

; caught WARNING:
;   undefined variable: B_LEN

;     (SETF C (MAKE-ARRAY B_LEN))
; ==>
;   (SETQ C (MAKE-ARRAY B_LEN))

; caught WARNING:
;   undefined variable: C

; compilation unit finished
;   Undefined variables:
;     B_LEN C
;   caught 2 WARNING conditions

; in: DOTIMES (X B_LEN)
;     (* AN (EXPT 10 X))

; caught WARNING:
;   undefined variable: AN

;     (SUBSEQ B (- B1_LEN X) (+ 1 (- B1_LEN X)))

; caught WARNING:
;   undefined variable: B

;     (- B1_LEN X)

; caught WARNING:
;   undefined variable: B1_LEN

;     (DOTIMES (X B_LEN) (SETF (AREF C X) (MUL (* AN #) (SUBSEQ B # #))))
; --> PROGN BLOCK 
; ==>
;   (LET ((X 0) (#:COUNT895 B_LEN))
;     (DECLARE (TYPE UNSIGNED-BYTE X)
;              (TYPE INTEGER #:COUNT895))
;     (TAGBODY
;       (GO #:G897)
;      #:G896
;       (TAGBODY (SETF # #))
;       (PSETQ X (1+ X))
;      #:G897
;       (UNLESS (>= X #:COUNT895) (GO #:G896))
;       (RETURN-FROM NIL (PROGN NIL))))

; caught WARNING:
;   undefined variable: B_LEN

;     (SETF (AREF C X) (MUL (* AN (EXPT 10 X)) (SUBSEQ B (- B1_LEN X) (+ 1 #))))
; ==>
;   (SB-KERNEL:%ASET C X
;                    (MUL (* AN (EXPT 10 X))
;                         (SUBSEQ B (- B1_LEN X) (+ 1 (- B1_LEN X)))))

; caught WARNING:
;   undefined variable: C

; compilation unit finished
;   Undefined variables:
;     AN B B1_LEN B_LEN C
;   caught 5 WARNING conditions

; in: SETF C1
;     (SETF C1 0)
; ==>
;   (SETQ C1 0)

; caught WARNING:
;   undefined variable: C1

; compilation unit finished
;   Undefined variable:
;     C1
;   caught 1 WARNING condition

; in: DOTIMES (X B_LEN)
;     (DOTIMES (X B_LEN) (SETF C1 (+ C1 (AREF C X))))
; --> PROGN BLOCK 
; ==>
;   (LET ((X 0) (#:COUNT898 B_LEN))
;     (DECLARE (TYPE UNSIGNED-BYTE X)
;              (TYPE INTEGER #:COUNT898))
;     (TAGBODY
;       (GO #:G900)
;      #:G899
;       (TAGBODY (SETF C1 #))
;       (PSETQ X (1+ X))
;      #:G900
;       (UNLESS (>= X #:COUNT898) (GO #:G899))
;       (RETURN-FROM NIL (PROGN NIL))))

; caught WARNING:
;   undefined variable: B_LEN

;     (AREF C X)

; caught WARNING:
;   undefined variable: C

;     (SETF C1 (+ C1 (AREF C X)))
; ==>
;   (SETQ C1 (+ C1 (AREF C X)))

; caught WARNING:
;   undefined variable: C1

; compilation unit finished
;   Undefined variables:
;     B_LEN C C1
;   caught 3 WARNING conditions


; in: SETF C3
;     (SETF C3 "0")
; ==>
;   (SETQ C3 "0")

; caught WARNING:
;   undefined variable: C3

; compilation unit finished
;   Undefined variable:
;     C3
;   caught 1 WARNING condition

; in: SETF C2
;     (WRITE-TO-STRING C1)
; ==>
;   (SB-IMPL::STRINGIFY-OBJECT C1)

; caught WARNING:
;   undefined variable: C1

;     (SETF C2 (CONCATENATE 'STRING C3 (WRITE-TO-STRING C1)))
; ==>
;   (SETQ C2 (CONCATENATE 'STRING C3 (WRITE-TO-STRING C1)))

; caught WARNING:
;   undefined variable: C2

;     (CONCATENATE 'STRING C3 (WRITE-TO-STRING C1))

; caught WARNING:
;   undefined variable: C3

; compilation unit finished
;   Undefined variables:
;     C1 C2 C3
;   caught 3 WARNING conditions
1234321 

; in: SETF C2_LEN
;     (LENGTH C2)

; caught WARNING:
;   undefined variable: C2

;     (SETF C2_LEN (LENGTH C2))
; ==>
;   (SETQ C2_LEN (LENGTH C2))

; caught WARNING:
;   undefined variable: C2_LEN

; compilation unit finished
;   Undefined variables:
;     C2 C2_LEN
;   caught 2 WARNING conditions
"01234321" 

; in: SETF C21_LEN
;     (SETF C21_LEN (- C2_LEN 1))
; ==>
;   (SETQ C21_LEN (- C2_LEN 1))

; caught WARNING:
;   undefined variable: C21_LEN

;     (- C2_LEN 1)

; caught WARNING:
;   undefined variable: C2_LEN

; compilation unit finished
;   Undefined variables:
;     C21_LEN C2_LEN
;   caught 2 WARNING conditions


; in: DOTIMES (X C21_LEN)
;     (SETF ADDP (+ (PARSE-INTEGER (SUBSEQ C2 # TEMP)) (/ DB2 2)))
; ==>
;   (SETQ ADDP (+ (PARSE-INTEGER (SUBSEQ C2 # TEMP)) (/ DB2 2)))

; caught WARNING:
;   undefined variable: ADDP

;     (SUBSEQ C2 TEMP (+ TEMP 1))

; caught WARNING:
;   undefined variable: C2

;     (- C21_LEN X)

; caught WARNING:
;   undefined variable: C21_LEN

;     (SETF DB2 (- PREV MODT))
; ==>
;   (SETQ DB2 (- PREV MODT))

; caught WARNING:
;   undefined variable: DB2

;     (SETF MODT (MOD (PARSE-INTEGER (SUBSEQ C2 TEMP #)) 2))
; ==>
;   (SETQ MODT (MOD (PARSE-INTEGER (SUBSEQ C2 TEMP #)) 2))

; caught WARNING:
;   undefined variable: MODT

;     (SETF PREV (PARSE-INTEGER (SUBSEQ C2 TEMP (+ TEMP 1))))
; ==>
;   (SETQ PREV (PARSE-INTEGER (SUBSEQ C2 TEMP (+ TEMP 1))))

; caught WARNING:
;   undefined variable: PREV

;     (SETF TEMP (- C21_LEN X))
; ==>
;   (SETQ TEMP (- C21_LEN X))

; caught WARNING:
;   undefined variable: TEMP

; compilation unit finished
;   Undefined variables:
;     ADDP C2 C21_LEN DB2 MODT PREV TEMP
;   caught 7 WARNING conditions






















"loop finished" 
"11100001" 
T

No comments:

Post a Comment

Perform a suitable assignment using Xen Hypervisor or equivalent open source to configure it. Give necessary GUI.

 To install kvm on Fedora:  yum install kvm  yum install virt-manager libvirt libvirt-python python-virtinst  su -c "yum install @v...