在lisp中给符号赋一个负值

DLR*_*DLR 2 lisp clisp

我是lisp的新手,我正在研究基本语法.我试图将
r1 =( - b + sqrt(b ^ 2 - 4*a*c))/(2*a)
转换为lisp格式.我认为我遇到的唯一问题是我不能让lisp将-b识别为符号b的负值.这是我到目前为止从lisp提示中得到的:

[17]> (setq a 1L0)
1.0L0
[18]> (setq b -1L0)
-1.0L0
[19]> (setq c -1L0)
-1.0L0
[20]> (setq r1 (+ (/ (sqrt (- (power b 2) (* (* 4 a) c))) (* 2 a)) -b))

*** - EVAL: variable -B has no value
The following restarts are available:
USE-VALUE      :R1      You may input a value to be used instead of -B.
STORE-VALUE    :R2      You may input a new value for -B.
ABORT          :R3      Abort main loop
Run Code Online (Sandbox Code Playgroud)

use*_*lpa 8

使用

(- b)
Run Code Online (Sandbox Code Playgroud)

否定b.它相当于

(- 0 b)
Run Code Online (Sandbox Code Playgroud)

  • 试试(/( - (sqrt( - (expt b 2)(*4 ac)))b)(*2 a)) (2认同)