1 Star 0 Fork 0

zhouxs1023/eigenmath_pratt

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
circexp.cpp 2.41 KB
一键复制 编辑 原始数据 按行查看 历史
Calin Barbat 提交于 2018-02-24 10:52 . Initial commit.
// Change circular functions to exponentials
#include "stdafx.h"
#include "defs.h"
void
eval_circexp(void)
{
push(cadr(p1));
eval();
circexp();
// normalize
eval();
}
void
circexp(void)
{
int i, h;
save();
p1 = pop();
if (car(p1) == symbol(COS)) {
push(cadr(p1));
expcos();
restore();
return;
}
if (car(p1) == symbol(SIN)) {
push(cadr(p1));
expsin();
restore();
return;
}
if (car(p1) == symbol(TAN)) {
p1 = cadr(p1);
push(imaginaryunit);
push(p1);
multiply();
exponential();
p2 = pop();
push(imaginaryunit);
push(p1);
multiply();
negate();
exponential();
p3 = pop();
push(p3);
push(p2);
subtract();
push(imaginaryunit);
multiply();
push(p2);
push(p3);
add();
divide();
restore();
return;
}
if (car(p1) == symbol(COSH)) {
p1 = cadr(p1);
push(p1);
exponential();
push(p1);
negate();
exponential();
add();
push_rational(1, 2);
multiply();
restore();
return;
}
if (car(p1) == symbol(SINH)) {
p1 = cadr(p1);
push(p1);
exponential();
push(p1);
negate();
exponential();
subtract();
push_rational(1, 2);
multiply();
restore();
return;
}
if (car(p1) == symbol(TANH)) {
p1 = cadr(p1);
push(p1);
push_integer(2);
multiply();
exponential();
p1 = pop();
push(p1);
push_integer(1);
subtract();
push(p1);
push_integer(1);
add();
divide();
restore();
return;
}
if (iscons(p1)) {
h = tos;
while (iscons(p1)) {
push(car(p1));
circexp();
p1 = cdr(p1);
}
list(tos - h);
restore();
return;
}
if (p1->k == TENSOR) {
push(p1);
copy_tensor();
p1 = pop();
for (i = 0; i < p1->u.tensor->nelem; i++) {
push(p1->u.tensor->elem[i]);
circexp();
p1->u.tensor->elem[i] = pop();
}
push(p1);
restore();
return;
}
push(p1);
restore();
}
#if SELFTEST
static const char *s[] = {
"circexp(cos(x))",
"1/2*exp(-i*x)+1/2*exp(i*x)",
"circexp(sin(x))",
"1/2*i*exp(-i*x)-1/2*i*exp(i*x)",
"circexp(tan(x))",
"i*exp(-i*x)/(exp(-i*x)+exp(i*x))-i*exp(i*x)/(exp(-i*x)+exp(i*x))",
"circexp(cosh(x))",
"1/2*exp(x)+1/2*exp(-x)",
"circexp(sinh(x))",
"1/2*exp(x)-1/2*exp(-x)",
"circexp(tanh(x))",
"-1/(1+exp(2*x))+exp(2*x)/(1+exp(2*x))",
"circexp((cos(x),sin(x)))",
"(1/2*exp(-i*x)+1/2*exp(i*x),1/2*i*exp(-i*x)-1/2*i*exp(i*x))",
"circexp(cos(x)*sin(x))-expcos(x)*expsin(x)",
"0",
};
void
test_circexp(void)
{
test(__FILE__, s, sizeof s / sizeof (char *));
}
#endif
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/zhouxs1023/eigenmath_pratt.git
git@gitee.com:zhouxs1023/eigenmath_pratt.git
zhouxs1023
eigenmath_pratt
eigenmath_pratt
master

搜索帮助