- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试编写一个小脚本,该脚本将查看表达式的第一项并确定它是正数还是负数,然后打印 +
或 -
相应地,在那个表达之前;但是,我在编写它时遇到了一些麻烦,它可以可靠地提取表达式的第一项。
我一直在试验 part
和 args
.我一直倾向于args
因为我还没有找到任何方法来确定 parts
的“深度”对于任意表达式(即我不确定如何确定是否使用,例如 part(expr,1)
或 part(expr,1,1)
或 part(expr, 1,1,1)
等)。args
的问题就是这样,例如
declare(cos, posfun)$
args(-2*cos(x));
> [2 cos(x)]
即否定被丢弃,大概是由于表达式的 lisp 表示(我们从
part(-2*cos(x),1)
得到相同的结果;此外,
part(-2*cos(x),2)
“从末尾掉下来”——似乎
part
根本看不到
-
)。
args(-2*cos(x)+x);
> [x, -2cos(x) ]
正如预期的那样。
addOp(x) > ["+", x]
addOp(-x) > ["-", x]
addOp(1+2*x+x^2) > ["+", 1+2*x+x^2]
addOp(-2+2*x+x^2) > ["-", 2+2*x+x^2] /* NB: only the first term is scaled by -1, not the entire expression */
addOp(cos(...)) > ["+", cos(...)]
addOp(-2x*cos(...)) > ["-", 2x*cos(x) ]
我也尝试使用
op
与已知数一起运行;然而,负数的内部表示意味着类似
op(1-3*cos(x))
返回
+
.
最佳答案
这是我的第一次尝试。除了 %o11
外,它似乎主要按照您描述的方式工作因为-2
从开始移动到结束。
(%i1) f(e):= if atom(e) then ["+", e]
else if op(e) = "-" then ["-", -e]
elseif op(e) = "+" then [f(first(e)), rest(e)]
else ["+", e];
(%o1) f(e) := if atom(e) then ["+", e] else (if op(e) = "-" then ["-", - e]
elseif op(e) = "+" then [f(first(e)), rest(e)] else ["+", e])
(%i2) f(x);
(%o2) [+, x]
(%i3) f(-x);
(%o3) [-, x]
(%i4) f(-2*x);
(%o4) [-, 2 x]
(%i5) f(-2*cos(x));
(%o5) [-, 2 cos(x)]
(%i6) f(1-2*cos(x));
(%o6) [[+, 1], - 2 cos(x)]
(%i7) f(-1+2*cos(x));
(%o7) [[+, 2 cos(x)], - 1]
(%i8) f(-1-2*cos(x));
(%o8) [[-, 2 cos(x)], - 1]
(%i9) f(a*b+c*d-e*f*g);
(%o9) [[-, e f g], c d + a b]
(%i10) f(1+2*x+x^2);
2
(%o10) [[+, x ], 2 x + 1]
(%i11) f(-2+2*x+x^2);
2
(%o11) [[+, x ], 2 x - 2]
(%i12) f(cos(a*b-c));
(%o12) [+, cos(c - a b)]
(%i13) f(-2*cos(x-y*z));
(%o13) [-, 2 cos(y z - x)]
(%i14) f(-2*x*cos(b-c));
(%o14) [-, 2 cos(c - b) x]
(%i15) -2+2*x+x^2;
2
(%o15) x + 2 x - 2
(%i16) f(-2 + 2*x - x^2);
2
(%o16) [[-, x ], 2 x - 2]
(%i17) -2 + 2*x - x^2;
2
(%o17) (- x ) + 2 x - 2
(%i18) f(a-b);
(%o18) [[+, a], - b]
(%i19) f(b-a);
(%o19) [[+, b], - a]
业务关于
op(e) = "-"
是不是像
-2*cos(x)
这样的东西被重组为
-(2*cos(x))
之前
args
对其进行处理(尽管我认为
inpart
会禁用该行为或对其进行修改)。
atom(-2)
返回
true
,所以 -2 被前面定义中的第一种情况捕获。这是另一个尝试,将负数与其他原子区分开来。
f(e):=
if atom(e)
then (if numberp(e) and e < 0 then ["-", -e] else ["+", e])
else if op(e) = "-" then ["-", -e]
elseif op(e) = "+" then [f(first(e)), rest(e)]
else ["+", e];
我没有尝试这个代码,但也许你可以说它是否有效。
关于arguments - (wx)最大值 : how to get consistent expressions using `args` ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66448172/
我的 Web 应用程序在后端使用 Node.js 和 Express。当违反内容安全策略 (CSP) 时,报告 URI 报告空对象。我的后台代码如下: app.use(bodyParser.urlen
在服务器端提供静态服务的方式在 Express 中似乎非常简单: To serve static files such as images, CSS files, and JavaScript fil
var express = require('express'); var app = express(); 这就是我们创建快速应用程序的方式。但是这个'express()'是什么?它是方法还是构造函
我在尝试安装时收到以下错误 express : npm ERR! code ERR_OSSL_PEM_NO_START_LINE npm ERR! errno ERR_OSSL_PEM_NO_STAR
如 express 所述routing guide和 this answer ,我们可以创建“迷你应用程序”并从主应用程序使用它。但是我看到一段代码,它在模块中使用 app 而不是 router ap
我正在写一个 NestJS应用。现在我想安装 Express中间件 express-openapi-validator . 但是,我无法让它工作。有一个 description for how to
我看过很多类似的帖子,似乎我声明的 var1 似乎需要在其他地方传递,但我似乎无法弄清楚。 public Expression> CreateEqualNameExpression(string ma
Express(或 Connect 的)bodyParser 中间件被标记为已弃用,建议用户改用: app.use(connect.urlencoded()) app.use(connect.json
我只是想知道这种看似尴尬的配置的原因是什么(来自 Getting Started w/ Apollo Server ), const server = new ApolloServer({ //
我正在尝试在表单组中写入表单控件特定的验证错误消息。我在网上找到了几个教程和示例 ( such as this one ),概述了一个看似简单的 *ngIf div,如果在控件上检测到错误,则显示错误
我有一个简单的 Express 应用程序,托管在 AWS 上,使用无服务器框架。 我正在使用 serverless-http 包装 express 应用程序以部署到 AWS lambda 函数,并使用
我最近在 mozilla 教程的帮助下安装了 node 和 express。我正在安装应用程序生成器的下一步,但是当我运行时 npm install express-generator -g 在我的终
我遇到过两种不同的方式来定义 express、use() 中间件,我想知道它们之间是否有任何区别,或者它是否只是语法糖? 一个 const app = express(); app.use(cors(
我试图让我的 Jade 模板编写一个相对于当前 URL 的超链接 ( )。 例如,我的 View 是从 http://localhost/cats 调用的它看起来像这样: extends layou
检查 Express 文档我在下面看到了这种解决方案: app.all('/*', function(req, res) { console.log('Intercepting request
我似乎无法弄清楚如何包含多个模型。 我有三个模型。Tabs, Servers, and PointsTabs hasMany ServerServers belongsTo Tabs and hasM
我已使用Web PI安装IIS Express。在托盘中,没有IIS Express图标。如何在不使用命令行的情况下启动IIS Express?我希望IIS永久运行,因此没有命令行。 最佳答案 参见R
我不想在我的网站上使用 Jade 或 EJS。如何在不默认使用 Jade 模板的情况下创建快速站点?谢谢 最佳答案 如果您想要的是直接为静态 html 文件提供缓存资源的可能性,同时仍然能够点击“/”
Express是否支持HTTP动词“PATCH”,例如: app.patch("/api/resource", function(req, res){ ... }); 我检查了文档,对我来说似乎还不清
我正在快速服务器中运行 vue SPA。问题是当使用历史模式并刷新页面时,我得到一个 404 not found 异常。我尝试使用 connect-history-api-fallback 但不起作用
我是一名优秀的程序员,十分优秀!