Saturday, 25 February 2017

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

The following lisp program shows implementation of a calculator:

CODE(calculator.lisp):

(write-line "Welcome to a Calculator Program using Concurrent Lisp")     

(defvar num1)     
(defvar num2)
(defvar result)

(defun square(x)
(write-line "SQUARE of first number is:")
(setf result (* x x))
(format t "~D" result ))

(defun cube(x)
(write-line "CUBE of second number is:")
(setf result (* x x x))
(format t "~D" result ))

(defun sine(x)
(write-line "SINE of first number is:")
(setf result (sin x))
(format t "~D" result ))

(defun tangent(x)
(write-line "TANGENT of first number is:")
(setf result (tan x))
(format t "~D" result ))

(defun cosine(x)
(write-line "COSINE of first number is:")
(setf result (cos x))
(format t "~D" result ))

(defun exponential(x)
(write-line "EXPONENTIAL FUNCTION of first number is:")
(setf result (exp x))
(format t "~D" result ))

(defun exponential1(x y)
(write-line "EXPONENTIAL FORM of BASE AND POWER is:")
(setf result (expt x y))
(format t "~D" result ))

(defun logarithm(x)
(write-line "LOGARITHM of first number to base 2 is:")
(setf result (log x 2))
(format t "~D" result ))

(defun logarithm1(x)
(write-line "LOGARITHM of first number to base 10 is:")
(setf result (log x 10))
(format t "~D" result ))

(write-line "Enter two numbers:") 
(setf num1(read)) 
(setf num2(read))
 

(sb-thread:make-thread(lambda()(progn (sleep 0)(setf result(+ num1 num2))
    (print "ADDITION in binary:")
    (format t "~b" result )
    (print "ADDITION in decimal:")
    (format t "~D" result ))))

(sb-thread:make-thread(lambda()(progn (sleep 0)(setf result(- num1 num2))
    (print "SUBTRACTION in binary:")
    (format t "~b" result )
    (print "SUBTRACTION in decimal:")
    (format t "~D" result ))))

(sb-thread:make-thread(lambda()(progn (sleep 0)(setf result(* num1 num2))
    (print "MULTIPLICATION in binary:")
    (format t "~b" result )
    (print "MULTIPLICATION in decimal:")
    (format t "~D" result ))))
   
(sb-thread:make-thread(lambda()(progn (sleep 0)(setf result(/ num1 num2))
    (print "DIVISION in binary:")
    (format t "~b" result )
    (print "DIVISION in decimal:")
    (format t "~D" result ))))

(sb-thread:make-thread(lambda()(progn (sleep 0)(setf result(mod num1 num2))
    (print "MODULUS in binary:")
    (format t "~b" result )
    (print "MODULUS in decimal:")
    (format t "~D" result ))))
   
(sb-thread:make-thread(lambda()(progn (sleep 0)
    (square num1))))
   
(sb-thread:make-thread(lambda()(progn (sleep 0)
    (cube num2))))
   
(sb-thread:make-thread(lambda()(progn (sleep 0)
    (sine num1))))

(sb-thread:make-thread(lambda()(progn (sleep 0)
    (tangent num1))))
   
(sb-thread:make-thread(lambda()(progn (sleep 0)
    (cosine num1))))
   
(sb-thread:make-thread(lambda()(progn (sleep 0)
    (exponential num1))))
   
(sb-thread:make-thread(lambda()(progn (sleep 0)
    (exponential1 num1 num2))))
   
(sb-thread:make-thread(lambda()(progn (sleep 0)
    (logarithm num1))))
   
(sb-thread:make-thread(lambda()(progn (sleep 0)
    (logarithm1 num1))))
   
(print (sb-thread:list-all-threads))
(sleep 30 )      

(exit)




OUTPUT:

pl3@pl3:~$ sbcl
This is SBCL 1.3.1.debian, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
* (load "calculator.lisp")   
Welcome to a Calculator Program using Concurrent Lisp
Enter two numbers:
5
3

"ADDITION in binary:" 1000
"ADDITION in decimal:" 8
"SUBTRACTION in binary:" 10
"SUBTRACTION in decimal:" 2
"MULTIPLICATION in binary:" 1111
"MULTIPLICATION in decimal:" 15
"DIVISION in binary:" 101/11
"DIVISION in decimal:" 5/3
"MODULUS in binary:" 10
"MODULUS in decimal:" 2
SQUARE of first number is:25
CUBE of second number is:27
SINE of first number is:-0.9589243
TANGENT of first number is:-3.380515
COSINE of first number is:0.2836622
EXPONENTIAL FUNCTION of first number is:148.41316
EXPONENTIAL FORM of BASE AND POWER is:125
LOGARITHM of first number to base 2 is:2.321928
LOGARITHM of first number to base 10 is:0.69897

(#<SB-THREAD:THREAD FINISHED values: NIL {1003F13763}>
#<SB-THREAD:THREAD "main thread" RUNNING {100399C4D3}>)

No comments:

Post a Comment