Re: [fricas-devel] erf is left unevaluated in expression
It sort of helps in the sense that the hint about specifying the types is useful. I could not apply the solution directly because it lead to another very surprising (to me) quirk of FriCAS: lack of a basic form of referential transparency between variables and literals. Namely if you assign a literal to a variable and later in code use a variable, the result may be different than if you had used the literal instead. For example: Let's assign an expression to a variable: BS := ((S*erf(((2*log((S/K))+T*s^2+2*T*r)/(2*s*sqrt(2)*sqrt(T-K*%e^((-T*r))*erf(((2*log((S/K))-T*s^2+2*T*r)/(2*s*sqrt(2)*sqrt(T-K*%e^((-T*r))+S)/2) define an abbreviation for DoubleFloat F:=DoubleFloat Now define a function using the literal C0(S:F,r:F,T:F,K:F,s:F):F == ((S*erf(((2*log((S/K))+T*s^2+2*T*r)/(2*s*sqrt(2)*sqrt(T-K*%e^((-T*r))*erf(((2*log((S/K))-T*s^2+2*T*r)/(2*s*sqrt(2)*sqrt(T-K*%e^((-T*r))+S)/2) And another one using the variable which stores that literal C1(S:F,r:F,T:F,K:F,s:F):F == BS Now the first function can be evaluated C0(10.0,0.05,0.8,11.0,0.05) 0.023903294619544546 But the second cannot C1(10.0,0.05,0.8,11.0,0.05) Cannot convert the value from type Expression(Integer) to DoubleFloat . It seems the only way to create a function when the expression is stored in a variable is to first declare the function C2:(F,F,F,F,F) -> F Then use the function operation to create the function from the expression function(BS,'C2,['S,'r,'T,'K,'s]) Then such function can be evaluated C2(10.0,0.05,0.8,11.0,0.05) 0.023903294619544546 On Saturday, November 10, 2018 at 12:07:44 PM UTC+1, Ralf Hemmecke wrote: > > Is there a way to force the evaluation of erf so that the function > > s+->C(11.0,s) can be plotted? > > Does the following help? > > The idea is that you specify the type so that the result is not > Expression(Float) (and must later be converted to (Double)Float, but > rather an element of DoubleFloat. > > Ralf > > F ==> DoubleFloat > > C0(S:F,r:F,T:F, > K:F,s:F):F==((S*erf(((2*log((S/K))+T*s^2+2*T*r)/(2*s*sqrt(2)*sqrt(T-K*%e^((-T*r))*erf(((2*log((S/K))-T*s^2+2*T*r)/(2*s*sqrt(2)*sqrt(T-K*%e^((-T*r))+S)/2) > > > > C(K:F, s:F):F==C0(10.0, 0.05, 0.8, K, s) > > CC(s:F):F==C(11.0, s) > > draw(CC, 2.0..3.0) > -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+unsubscr...@googlegroups.com. To post to this group, send email to fricas-devel@googlegroups.com. Visit this group at https://groups.google.com/group/fricas-devel. For more options, visit https://groups.google.com/d/optout.
[fricas-devel] Re: Giving a name to a part of an expression
I had the code based on Bill Page and Waldek Hebisch suggestions that was doing what I wanted but this last hint by Themos simplified it a lot. I will put it here as Marduk seems to be doing a similar exercise in the "Simple Gaussian integral fails thread". The goal is to see if we can make FriCAS compute the integral that gives the Black-Scholes formula for the price of a call option. So, we define C:=exp(-r*T)/(s*sqrt(2*%pi*T)) f(x)==(S*exp(x)-K) g(x) == exp(-(x-T*m)^2/(2*T*s^2)) m := r-s^2/2 The integral integrate(f(x)*g(x),x=log(K/S)..%plusInfinity) fails, but we can do I := C*integrate(f(x)*g(x),x=log(K/S)..y) Now we need to take the limit as y goes to infinity. For that to work we first have to tell FriCAS that the expression sqrt(1/(2*T))/s is positive. We do it by replacing this expression by c^2. withPos:=subst(I,[sqrt(1/(2*T))::Kernel(Expression(Integer))],[c^2*s]) Nowe we can take the limit: lim:=limit(withPos,y=%plusInfinity) and replace c^2 back by sqrt(1/(2*T))/s BS := (rule ('c^2==sqrt(1/(2*T))/s)) (lim::Expression(Integer)) -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+unsubscr...@googlegroups.com. To post to this group, send email to fricas-devel@googlegroups.com. Visit this group at https://groups.google.com/group/fricas-devel. For more options, visit https://groups.google.com/d/optout.
[fricas-devel] erf is left unevaluated in expression
I got a problem trying to plot a function that uses the erf funtion. It seems that the reason was that erf is sometimes left unevaluated by FriCAS even in expressions that only involve erf and numbers. To replicate one can define the expression like Ce:=((S*erf(((2*log((S/K))+T*s^2+2*T*r)/(2*s*sqrt(2)*sqrt(T-K*%e^((-T*r))*erf(((2*log((S/K))-T*s^2+2*T*r)/(2*s*sqrt(2)*sqrt(T-K*%e^((-T*r))+S)/2) This contains variables S,r,T,K,s. I set the first three: S:=10.0,r:=0.05,T:=0.8 Then I create a function C of the remaining K,s variables: function(Ce,'C,'K,'s) But then when I try to evaluate the function C C(11.0,0.05) I get an Expression(Float) 5.2843419153_36519*erf(0.8903421181_7640573378)-5.0*erf(0.8587193415_7472194046)-0.2843419153_365192 I am using TEXmacs interface. Curiously, this expression can be evaluated, sending it back in another field returns 0.0239032946_195444183 Is there a way to force the evaluation of erf so that the function s+->C(11.0,s) can be plotted? Thanks, Slawomir Kolodynski -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+unsubscr...@googlegroups.com. To post to this group, send email to fricas-devel@googlegroups.com. Visit this group at https://groups.google.com/group/fricas-devel. For more options, visit https://groups.google.com/d/optout.
[fricas-devel] Export TeXmacs .tm file to FriCAS .input file
Is there a way to export a TeXmacs file to the FriCAS .input file that can be read by the )read command? What I do now is in TeXmacs I do RightClick --> Session --> Clear All fields, then File->Export/Verbatim, then manually edit the resulting file to remove the FriiCAS session header at start and the )-> characters from every line. This gets tedious as it has to be repeated with every modification. is there a better way? Thanks Slawomir -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+unsubscr...@googlegroups.com. To post to this group, send email to fricas-devel@googlegroups.com. Visit this group at https://groups.google.com/group/fricas-devel. For more options, visit https://groups.google.com/d/optout.
Re: [fricas-devel] Giving a name to a part of an expression
Thank you for looking into this. >Instead, various routines analyze structure of expressions using lower level operations. Could you give some examples of those lower level operations? Pattern matching and rewrite rules seem very useful to me , but I am ok with doing lower level operations if those fail. I know about numerator, denominator and monomials so for example I can do e1 := (y-m)*x/s (monomials numerator e1)(1) to get x*y However when I try to do something similar with e2 := (y-m)*sqrt(x)/s numerator e2 to get (y-m)*sqrt(x), I don't know how then to extract the components of this product. Also, I could not find a way to extract an argument of a function, for example if I have an expression sin(a*x+b) how to get the "a*x+b" part? Thanks, Slawomir -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+unsubscr...@googlegroups.com. To post to this group, send email to fricas-devel@googlegroups.com. Visit this group at https://groups.google.com/group/fricas-devel. For more options, visit https://groups.google.com/d/optout.
[fricas-devel] Giving a name to a part of an expression
Suppose I have an expression like *(y-m)*sqrt(x)/s* . What I would like to do is to give a name *e* to the *sqrt(x)/s* part and do some kind of transformation on this expression so that I get *(y-m)*e *or equivalent as the result*. *To do that I define a rule substE := rule (('y-'m)*sqrt('x)/'s == ('y-'m)*'e) However, when I try to apply this rule to the expression substE (y-m)*sqrt(x)/s I get the *(y-m)*sqrt(x)/s *expression back instead of *(y-m)*e. *It looks like the left hand side of the equality in the rule substE does not pattern match itself. Curiously, without sqrt a similar rule works as expected: substF := rule (('y-'m)*'x/'s == ('y-'m)*'e) substF ((y-m)*x/s) gives e*y - e*m Can you explain what is the difference here and how to approach the goal of substituting a subexpression with a symbol? Thanks, Slawomir -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+unsubscr...@googlegroups.com. To post to this group, send email to fricas-devel@googlegroups.com. Visit this group at https://groups.google.com/group/fricas-devel. For more options, visit https://groups.google.com/d/optout.
[fricas-devel] Re: Defining a rewrite rule when calculation is failing
Thanks for the solution. It works for me. > eval(e1, [name(pos)], [2], [(x : eI) : eI +-> x]) For the interested readers of this thread here is the documentation of the last eval call: eval: (%, List Symbol, List NonNegativeInteger, List % -> %) -> % if R has Ring eval(x, [s1, ..., sm], [n1, ..., nm], [f1, ..., fm]) replaces every si(a)^ni in x by fi(a) for any a. Thanks. Slawomir -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+unsubscr...@googlegroups.com. To post to this group, send email to fricas-devel@googlegroups.com. Visit this group at https://groups.google.com/group/fricas-devel. For more options, visit https://groups.google.com/d/optout.
[fricas-devel] Defining a rewrite rule when calculation is failing
I am trying to figure out a way to tell FriCAS that limit(erf(sqrt(c)*x),x=%plusInfinity) is 1 (say, I know that c>0). To do that I define a rule: limerf := rule limit(erf(sqrt(c)*x),x=%plusInfinity) == 1 However, when I try to apply the rule: limerf(limit(erf(sqrt(c)*x),x=%plusInfinity)) I get Cannot find a definition or applicable library operation named limerf with argument type(s) failed It looks like FriCAS first tries to evaluate the argument of the rule (and gets "failed"), then tries to match the rule pattern to the result. Is there a way to prevent the rule to evaluate its argument before pattern matching? Or I am doing something wrong here? Thanks, Slawomir -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+unsubscr...@googlegroups.com. To post to this group, send email to fricas-devel@googlegroups.com. Visit this group at https://groups.google.com/group/fricas-devel. For more options, visit https://groups.google.com/d/optout.
[fricas-devel] limit of erf at infinity
limit(erf(2*x+b),x=%plusInfinity) works fine, returning 1 as it should. Similarly, limit(erf(-2*x+b),x=%plusInfinity) works. However limit(erf(a*x+b),x=%plusInfinity) returns "failed", perhaps because FriCAS does not know if a is positive or negative. I tried to declare a:PositiveInteger, but that leads to an error " a is declared as being in PositiveInteger but has not been given a value". Is there a way to tell FriCAS that for example a>0 so that the limit can be computed? Slawomir -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+unsubscr...@googlegroups.com. To post to this group, send email to fricas-devel@googlegroups.com. Visit this group at https://groups.google.com/group/fricas-devel. For more options, visit https://groups.google.com/d/optout.
[fricas-devel] Expressing erf as cumulative normal
I am learning FriCAS so please excuse my basic questions and point me to better place to ask them is such exists. FriCAS is able to evaluate some integrals in terms of the Gauss error function (erf). For example (1/(sqrt(2*%pi)))*integrate(exp(-t^2/2),t=%minusInfinity..x) returns an expression involving erf. I would prefer such integrals to be evaluated in terms of cumulative distribution function of the standard normal distribution. To achieve that I tried to define a rewriting rule phirule: rule erf(%x)==2*N(x*sqrt(2))-1 hoping that applying that on the result of integration will express the result in terms of N (the CDF of standard normal). However, I get rule(erf(QUOTE(%x)),2*applyQuote(QUOTE(N),QUOTE(x)*sqrt(2))-1,[ QUOTE(N)]) is not a valid type. when I try to define the rule. What I am doing wrong when defining the rule? Is defining such rule the best way to convert the result of integration so that it is expressed in terms the CDF of standard normal rather than the erf function? Thanks, Slawomir -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+unsubscr...@googlegroups.com. To post to this group, send email to fricas-devel@googlegroups.com. Visit this group at https://groups.google.com/group/fricas-devel. For more options, visit https://groups.google.com/d/optout.
Re: [fricas-devel] Re: TEXmacs as interface
Indeed, installing TEXmacs 1.99.7 fixed the problems. Thank you all for help Slawomir On Monday, July 16, 2018 at 3:59:28 AM UTC+2, oldk1331 wrote: > > Hi Slawomir, > > TeXmacs 1.0.7.18 was released 5 years ago, you should try more recent > version, like 1.99.7. > -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+unsubscr...@googlegroups.com. To post to this group, send email to fricas-devel@googlegroups.com. Visit this group at https://groups.google.com/group/fricas-devel. For more options, visit https://groups.google.com/d/optout.
[fricas-devel] Re: TEXmacs as interface
> Where is the fricas plugin installed? I found it in /usr/share/texmacs/TeXmacs/plugins/fricas $> /usr/share/texmacs/TeXmacs/plugins/fricas $ ls doc progs > 2. Does $ fricas -texmacs work? I am not sure. FriCAS seems to start, the output looks as follows $> fricas -texmacs Checking for foreign routines AXIOM="/usr/local/lib/fricas/target/x86_64-linux-gnu" spad-lib="/usr/local/lib/fricas/target/x86_64-linux-gnu/lib/libspad.so" foreign routines found openServer result -2 FriCAS Computer Algebra System Version: FriCAS 1.3.3 Timestamp: Mon Mar 12 21:48:52 CET 2018 - Issue )copyright to view copyright notices. Issue )summary for a summary of useful system commands. Issue )quit to leave FriCAS and return to shell. - Value = # prompt#(1) -> )quit Does that "openServer result -2" suggest something is not right? My init-fricas.scm was as follows: (define (fricas-initialize) (import-from (utils plugins plugin-convert)) (import-from (utils plugins plugin-cmd)) (import-from (dynamic session-menu)) (import-from (fricas-kbd)) (import-from (fricas-menus)) (lazy-input-converter (fricas-input) fricas)) (plugin-configure fricas (:require (url-exists-in-path? "fricas")) (:initialize (fricas-initialize)) (:launch "fricas -texmacs") (:session "Fricas") (:scripts "Fricas")) I replaced it from by the one from https://github.com/fricas/fricas/blob/master/contrib/texmacs/fricas/progs/init-fricas.scm and now it looks like this: (plugin-configure fricas (:require (url-exists-in-path? "fricas")) (:launch "fricas -texmacs") (:session "FriCAS") (:scripts "FriCAS")) (when (supports-fricas?) (import-from (fricas-kbd)) (import-from (fricas-menus)) (lazy-input-converter (fricas-input) fricas)) This did not fix the problem, Thanks, Slawomir -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+unsubscr...@googlegroups.com. To post to this group, send email to fricas-devel@googlegroups.com. Visit this group at https://groups.google.com/group/fricas-devel. For more options, visit https://groups.google.com/d/optout.
[fricas-devel] TEXmacs as interface
I am trying to use GNU TEXmacs as interface to Fricas. I have installed Fricas 1.3.3 by downloading the tar with binaries and the fricas script is on PATH so I can start fricas from shell by typing "fricas". I also have Texmacs 1.0.7.18 installed from Linux Mint repositories. I assume the Fricas plugin is installed because I can see Fricas as one of the options to select from the Texmacs Insert --> Session menu. However, when I select Fricas there I get "Busy" then "Dead" indication from Texmacs. Does Texmacs 1.0.7.18 work with Fricas 1.3.3? If not, what is a version combination that is known to work? Should I configure Texmacs somehow to point to the location of fricas binaries? How would I do that? Thanks, Slawomir -- You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group. To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+unsubscr...@googlegroups.com. To post to this group, send email to fricas-devel@googlegroups.com. Visit this group at https://groups.google.com/group/fricas-devel. For more options, visit https://groups.google.com/d/optout.