小编Lar*_*ars的帖子

分段函数的积分给出不正确的结果

使用最新版本的sympy(0.7.6),在确定支持[0,y)的函数的积分时,得到以下错误结果:

from sympy import *
a,b,c,x,z = symbols("a,b,c,x,z",real = True)
y = Symbol("y",real=True,positive=True)
inner = Piecewise((0,(x>=y)|(x<0)|(b>c)),(a,True))
I = Integral(inner,(x,0,z))
Eq(I,I.doit())
Run Code Online (Sandbox Code Playgroud)

http://mathurl.com/l8wrjcn.png

这是不正确的,因为实际结果应该交换最后两个案例.这可以通过检查衍生物来确认:

Derivative(I.doit(),z).doit().simplify().subs(z,x)
Run Code Online (Sandbox Code Playgroud)

http://mathurl.com/mg4zpts.png

到处都减少到0.

有趣的是,当(b>c)通过替换inner = Piecewise((0,(x>=y)|(x<0)),(a,True))I得到一个TypeError来删除条件时:

TypeError: cannot determine truth value of
-oo < y
Run Code Online (Sandbox Code Playgroud)

我是否错误地使用了该库,或者这实际上是一个严重的症状错误?

python sympy integral

6
推荐指数
1
解决办法
633
查看次数

使用虚拟继承的地址未对齐

以下显然有效的代码使用UndefinedBehaviorSanitizer sanitiser产生错位的地址运行时错误.

#include <memory>
#include <functional>

struct A{
  std::function<void()> data; // seems to occur only if data is a std::function
} ;

struct B{
  char data; // occurs only if B contains a member variable
};

struct C:public virtual A,public B{

};

struct D:public virtual C{

};

void test(){
  std::make_shared<D>();
}

int main(){
  test();
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

在macbook上编译和执行 clang++ -fsanitize=undefined --std=c++11 ./test.cpp && ./a.out 产生输出 runtime error: constructor call on misaligned address 0x7fe584500028 for type 'C', which requires 16 byte …

c++ memory-alignment virtual-inheritance sanitizer clang++

6
推荐指数
1
解决办法
1137
查看次数