Re: [fricas-devel] erf is left unevaluated in expression

2018-11-21 Thread oldk1331
On Wed, Nov 21, 2018 at 6:22 PM Slawomir Kolodynski  wrote:
>
> 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:

This is not a problem about "referential transparency", this is about a old bug
related with (numeric) evaluation of "erf", e.g. "eval(erf x, x, 1.0)"
returns "erf(1.0)".

https://groups.google.com/forum/#!msg/fricas-devel/Rz5_1iBadAY/B2g9GVibCwAJ


> And another one using the variable which stores that literal
>
> C1(S:F,r:F,T:F,K:F,s:F):F == BS

This usage is wrong, BS is already defined, with a type of Expression,
so this line will never work.

One way can work:
First, use macro '==>' instead of assignment.
Second, use "exp" instead of "%e", so that they are
defined in DFLOAT:

BS1 ==> 
((S*erf(((2*log((S/K))+T*s^2+2*T*r)/(2*s*sqrt(2)*sqrt(T-K*exp((-T*r))*erf(((2*log((S/K))-T*s^2+2*T*r)/(2*s*sqrt(2)*sqrt(T-K*exp((-T*r))+S)/2)
C1(S:F,r:F,T:F,K:F,s:F):F == BS1
C1(10.0,0.05,0.8,11.0,0.05)
   Compiling function C1 with type (DoubleFloat, DoubleFloat,
DoubleFloat, DoubleFloat, DoubleFloat) -> DoubleFloat

   (18)  0.023903294619544546


I think after the bug I mentioned get fixed, using "numeric" will also work.

-- 
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] erf is left unevaluated in expression

2018-11-21 Thread Slawomir Kolodynski
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.


Re: [fricas-devel] erf is left unevaluated in expression

2018-11-10 Thread Ralf Hemmecke
> 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.