Generated by Cython 0.12.1 on Wed Mar 10 05:39:42 2010
Raw output: _sagenb_sagenb_sage_notebook_sagenb_home_gsever_19_code_sage13_spyx_0.c
1:
2: include "interrupt.pxi" # ctrl-c interrupt block support
3: include "stdsage.pxi" # ctrl-c interrupt block support
4:
5: include "cdefs.pxi"
6: cdef double f2(double x):
static double __pyx_f_69_sagenb_sagenb_sage_notebook_sagenb_home_gsever_19_code_sage13_spyx_0_f2(double __pyx_v_x) {
double __pyx_r;
__Pyx_RefNannySetupContext("f2");
7: return 1/(x**3 + 2*x**2)
__pyx_t_1 = (pow(__pyx_v_x, 3) + (2 * pow(__pyx_v_x, 2)));
if (unlikely(__pyx_t_1 == 0)) {
PyErr_Format(PyExc_ZeroDivisionError, "float division");
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__pyx_r = (1 / __pyx_t_1);
goto __pyx_L0;
__pyx_r = 0;
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_WriteUnraisable("_sagenb_sagenb_sage_notebook_sagenb_home_gsever_19_code_sage13_spyx_0.f2");
__pyx_r = 0;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
8:
9: cpdef double integrate_f2(int a, int b, int N):
static PyObject *__pyx_pf_69_sagenb_sagenb_sage_notebook_sagenb_home_gsever_19_code_sage13_spyx_0_integrate_f2(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); static PyObject *__pyx_pf_69_sagenb_sagenb_sage_notebook_sagenb_home_gsever_19_code_sage13_spyx_0_integrate_f2(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_69_sagenb_sagenb_sage_notebook_sagenb_home_gsever_19_code_sage13_spyx_0_integrate_f2[] = "File: _sagenb_sagenb_sage_notebook_sagenb_home_gsever_19_code_sage13_spyx_0.pyx (starting at line 9)";
static PyObject *__pyx_pf_69_sagenb_sagenb_sage_notebook_sagenb_home_gsever_19_code_sage13_spyx_0_integrate_f2(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
int __pyx_v_a;
int __pyx_v_b;
int __pyx_v_N;
PyObject *__pyx_r = NULL;
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__a,&__pyx_n_s__b,&__pyx_n_s__N,0};
__Pyx_RefNannySetupContext("integrate_f2");
__pyx_self = __pyx_self;
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args = PyDict_Size(__pyx_kwds);
PyObject* values[3] = {0,0,0};
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 0:
values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__a);
if (likely(values[0])) kw_args--;
else goto __pyx_L5_argtuple_error;
case 1:
values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__b);
if (likely(values[1])) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("integrate_f2", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
case 2:
values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__N);
if (likely(values[2])) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("integrate_f2", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "integrate_f2") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
__pyx_v_a = __Pyx_PyInt_AsInt(values[0]); if (unlikely((__pyx_v_a == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_v_b = __Pyx_PyInt_AsInt(values[1]); if (unlikely((__pyx_v_b == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_v_N = __Pyx_PyInt_AsInt(values[2]); if (unlikely((__pyx_v_N == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
} else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
goto __pyx_L5_argtuple_error;
} else {
__pyx_v_a = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 0)); if (unlikely((__pyx_v_a == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_v_b = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 1)); if (unlikely((__pyx_v_b == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_v_N = __Pyx_PyInt_AsInt(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_N == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("integrate_f2", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
__pyx_L3_error:;
__Pyx_AddTraceback("_sagenb_sagenb_sage_notebook_sagenb_home_gsever_19_code_sage13_spyx_0.integrate_f2");
return NULL;
__pyx_L4_argument_unpacking_done:;
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = PyFloat_FromDouble(__pyx_f_69_sagenb_sagenb_sage_notebook_sagenb_home_gsever_19_code_sage13_spyx_0_integrate_f2(__pyx_v_a, __pyx_v_b, __pyx_v_N, 0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("_sagenb_sagenb_sage_notebook_sagenb_home_gsever_19_code_sage13_spyx_0.integrate_f2");
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
10: cdef double s
11: cdef int i
12: s = 0
__pyx_v_s = 0;
13: dx = (b-a) / N
__pyx_t_1 = (__pyx_v_b - __pyx_v_a);
if (unlikely(__pyx_v_N == 0)) {
PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero");
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
else if (sizeof(int) == sizeof(long) && unlikely(__pyx_v_N == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_t_1))) {
PyErr_Format(PyExc_OverflowError, "value too large to perform division");
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
}
__pyx_t_2 = PyInt_FromLong(__Pyx_div_int(__pyx_t_1, __pyx_v_N)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_v_dx);
__pyx_v_dx = __pyx_t_2;
__pyx_t_2 = 0;
14: for i in range(N):
__pyx_t_1 = __pyx_v_N;
for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_1; __pyx_t_3+=1) {
__pyx_v_i = __pyx_t_3;
15: s += f2(a+i*dx)
__pyx_t_2 = PyInt_FromLong(__pyx_v_a); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_4 = PyInt_FromLong(__pyx_v_i); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = PyNumber_Multiply(__pyx_t_4, __pyx_v_dx); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = PyNumber_Add(__pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_v_s += __pyx_f_69_sagenb_sagenb_sage_notebook_sagenb_home_gsever_19_code_sage13_spyx_0_f2(__pyx_t_6);
}
16: return s * dx
__pyx_t_4 = PyFloat_FromDouble(__pyx_v_s); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = PyNumber_Multiply(__pyx_t_4, __pyx_v_dx); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_r = __pyx_t_6;
goto __pyx_L0;
__pyx_r = 0;
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_WriteUnraisable("_sagenb_sagenb_sage_notebook_sagenb_home_gsever_19_code_sage13_spyx_0.integrate_f2");
__pyx_r = 0;
__pyx_L0:;
__Pyx_DECREF(__pyx_v_dx);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}