ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 26 Mar 2011 19:45:51 +0100Maxima crashes on relatively simple integralhttps://ask.sagemath.org/question/8028/maxima-crashes-on-relatively-simple-integral/I'm trying to Maxima-fy my Mathematica box options formula
(https://github.com/barrycarter/bcapps/blob/master/box-option-value.m)
but Maxima crashes on a fairly simple integration:
load(distrib);
pdflp(x, p0, v, p1, p2, t1, t2) := pdf_normal(x,log(p0),sqrt(t1)*v);
cdfmaxlp(x, p0, v, p1, p2, t1, t2) := 1-erf(x/(v*sqrt(t2-t1)/sqrt(2)));
upandin(p0, v, p1, p2, t1, t2) :=
integrate(
float(
pdflp(x, p0, v, p1, p2, t1, t2)*
cdfmaxlp(log(p1)-x, p0, v, p1, p2, t1, t2)
),
x, minf, log(p1));
Evaluating upandin w/ certain values crashes:
upandin(1, .15, 1.01, 1.02, 1/365.2425, 2/365.2425);
rat: replaced -.00995033085316809 by -603/60601 = -.00995033085262619
rat: replaced 2.718281828459045 by 23225/8544 = 2.718281835205993
rat: replaced 8116.5 by 16233/2 = 8116.5
rat: replaced 2.718281828459045 by 23225/8544 = 2.718281835205993
rat: replaced -8116.5 by -16233/2 = -8116.5
rat: replaced 1.0 by 1/1 = 1.0
rat: replaced 1.792882852833688 by 4484/2501 = 1.792882846861255
rat: replaced 180.1832400641081 by 126849/704 = 180.1832386363636
rat: replaced 2.718281828459045 by 23225/8544 = 2.718281835205993
rat: replaced -8116.5 by -16233/2 = -8116.5
rat: replaced -1.0 by -1/1 = -1.0
rat: replaced 1.792882852833688 by 4484/2501 = 1.792882846861255
rat: replaced 180.1832400641081 by 126849/704 = 180.1832386363636
rat: replaced 2.718281828459045 by 23225/8544 = 2.718281835205993
rat: replaced -8116.5 by -16233/2 = -8116.5
rat: replaced 1.0 by 1/1 = 1.0
rat: replaced -1.0 by -1/1 = -1.0
Maxima encountered a Lisp error:
The value 16090668801 is not of type FIXNUM.
Without the float() in upandin, Maxima just leaves the integral in
original form.
Can someone help? I thought converting Mathematica to Maxima would be
easy, but now I'm not as sure.
The Mathematica version works fine:
pdflp[x_, p0_, v_, p1_, p2_, t1_, t2_] :=
PDF[NormalDistribution[Log[p0],Sqrt[t1]*v]][x]
cdfmaxlp[x_, p0_, v_, p1_, p2_, t1_, t2_] := 1-Erf[x/(v*Sqrt[t2-t1]/Sqrt[2])];
(* NIntegrate below "equivalent" to Maxima's float(); no closed form *)
upandin[p0_, v_, p1_, p2_, t1_, t2_] :=
NIntegrate[pdflp[x, p0, v, p1, p2, t1, t2]*
cdfmaxlp[Log[p1]-x, p0, v, p1, p2, t1, t2],
{x, -Infinity, Log[p1]}]
upandin[1, .15, 1.01, 1.02, 1/365.2425, 2/365.2425]
0.0998337
Sat, 26 Mar 2011 19:39:04 +0100https://ask.sagemath.org/question/8028/maxima-crashes-on-relatively-simple-integral/Answer by cswiercz for <p>I'm trying to Maxima-fy my Mathematica box options formula
(<a href="https://github.com/barrycarter/bcapps/blob/master/box-option-value.m">https://github.com/barrycarter/bcapps...</a>)
but Maxima crashes on a fairly simple integration: </p>
<pre><code>load(distrib);
pdflp(x, p0, v, p1, p2, t1, t2) := pdf_normal(x,log(p0),sqrt(t1)*v);
cdfmaxlp(x, p0, v, p1, p2, t1, t2) := 1-erf(x/(v*sqrt(t2-t1)/sqrt(2)));
upandin(p0, v, p1, p2, t1, t2) :=
integrate(
float(
pdflp(x, p0, v, p1, p2, t1, t2)*
cdfmaxlp(log(p1)-x, p0, v, p1, p2, t1, t2)
),
x, minf, log(p1));
</code></pre>
<p>Evaluating upandin w/ certain values crashes: </p>
<pre><code>upandin(1, .15, 1.01, 1.02, 1/365.2425, 2/365.2425);
rat: replaced -.00995033085316809 by -603/60601 = -.00995033085262619
rat: replaced 2.718281828459045 by 23225/8544 = 2.718281835205993
rat: replaced 8116.5 by 16233/2 = 8116.5
rat: replaced 2.718281828459045 by 23225/8544 = 2.718281835205993
rat: replaced -8116.5 by -16233/2 = -8116.5
rat: replaced 1.0 by 1/1 = 1.0
rat: replaced 1.792882852833688 by 4484/2501 = 1.792882846861255
rat: replaced 180.1832400641081 by 126849/704 = 180.1832386363636
rat: replaced 2.718281828459045 by 23225/8544 = 2.718281835205993
rat: replaced -8116.5 by -16233/2 = -8116.5
rat: replaced -1.0 by -1/1 = -1.0
rat: replaced 1.792882852833688 by 4484/2501 = 1.792882846861255
rat: replaced 180.1832400641081 by 126849/704 = 180.1832386363636
rat: replaced 2.718281828459045 by 23225/8544 = 2.718281835205993
rat: replaced -8116.5 by -16233/2 = -8116.5
rat: replaced 1.0 by 1/1 = 1.0
rat: replaced -1.0 by -1/1 = -1.0
Maxima encountered a Lisp error:
The value 16090668801 is not of type FIXNUM.
</code></pre>
<p>Without the float() in upandin, Maxima just leaves the integral in
original form. </p>
<p>Can someone help? I thought converting Mathematica to Maxima would be
easy, but now I'm not as sure. </p>
<p>The Mathematica version works fine: </p>
<pre><code>pdflp[x_, p0_, v_, p1_, p2_, t1_, t2_] :=
PDF[NormalDistribution[Log[p0],Sqrt[t1]*v]][x]
cdfmaxlp[x_, p0_, v_, p1_, p2_, t1_, t2_] := 1-Erf[x/(v*Sqrt[t2-t1]/Sqrt[2])];
(* NIntegrate below "equivalent" to Maxima's float(); no closed form *)
upandin[p0_, v_, p1_, p2_, t1_, t2_] :=
NIntegrate[pdflp[x, p0, v, p1, p2, t1, t2]*
cdfmaxlp[Log[p1]-x, p0, v, p1, p2, t1, t2],
{x, -Infinity, Log[p1]}]
upandin[1, .15, 1.01, 1.02, 1/365.2425, 2/365.2425]
0.0998337
</code></pre>
https://ask.sagemath.org/question/8028/maxima-crashes-on-relatively-simple-integral/?answer=12228#post-id-12228Even though Sage includes Maxima (primarily as a backend) I think your question would be better answered in a Maxima forum. Try the [Maxima Wiki](http://maxima-project.org/wiki/index.php?title=Main_Page) or the [Maxima FAQ](http://maxima.sourceforge.net/maximalist.html).Sat, 26 Mar 2011 19:45:51 +0100https://ask.sagemath.org/question/8028/maxima-crashes-on-relatively-simple-integral/?answer=12228#post-id-12228