2005-07-30 21:37:29 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Author : philippe.billet@noos.fr
|
|
|
|
//
|
|
|
|
// Dirac function dirac(x)
|
|
|
|
// dirac(-x)=dirac(x)
|
|
|
|
// dirac(b-a)=dirac(a-b)
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "defs.h"
|
|
|
|
static void ydirac(void);
|
|
|
|
|
|
|
|
void
|
|
|
|
eval_dirac(void)
|
|
|
|
{
|
|
|
|
push(cadr(p1));
|
|
|
|
eval();
|
|
|
|
dirac();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dirac(void)
|
|
|
|
{
|
|
|
|
save();
|
|
|
|
ydirac();
|
|
|
|
restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
#define X p1
|
|
|
|
|
|
|
|
static void
|
|
|
|
ydirac(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
X = pop();
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-08-06 22:57:37 +02:00
|
|
|
if (isdouble(X)) {
|
2005-07-30 21:37:29 +02:00
|
|
|
if (X->u.d == 0)
|
|
|
|
{push_integer(1);
|
|
|
|
return;}
|
|
|
|
else
|
|
|
|
{push_integer(0);
|
|
|
|
return;}
|
|
|
|
}
|
|
|
|
|
2005-08-06 22:57:37 +02:00
|
|
|
if (isrational(X)) {
|
2005-07-30 21:37:29 +02:00
|
|
|
if (MZERO(mmul(X->u.q.a,X->u.q.b)))
|
|
|
|
{push_integer(1);
|
|
|
|
return;}
|
|
|
|
else
|
|
|
|
{push_integer(0);
|
|
|
|
return;}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (car(X) == symbol(POWER)) {
|
|
|
|
push_symbol(DIRAC);
|
|
|
|
push(cadr(X));
|
|
|
|
list(2);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isnegativeterm(X)) {
|
|
|
|
push_symbol(DIRAC);
|
|
|
|
push(X);
|
|
|
|
negate();
|
|
|
|
list(2);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isnegativeterm(p1) || (car(p1) == symbol(ADD) && isnegativeterm(cadr(p1)))) {
|
|
|
|
push(p1);
|
|
|
|
negate();
|
|
|
|
p1 = pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
push_symbol(DIRAC);
|
|
|
|
push(X);
|
|
|
|
list(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static char *s[] = {
|
|
|
|
|
|
|
|
|
|
|
|
"dirac(-x)",
|
|
|
|
"dirac(x)",
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
test_dirac(void)
|
|
|
|
{
|
|
|
|
test(__FILE__, s, sizeof s / sizeof (char *));
|
|
|
|
}
|