Discussion:
[fricas-devel] Expressing erf as cumulative normal
Slawomir Kolodynski
2018-07-22 12:39:49 UTC
Permalink
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+***@googlegroups.com.
To post to this group, send email to fricas-***@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.
Waldek Hebisch
2018-07-22 12:51:23 UTC
Permalink
Post by Slawomir Kolodynski
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?
1) ':' means type declaration. You need ':=' for assignment
2) You need to declare 'N' befor use

Below is working version:

(1) -> N := operator 'N

(1) N
Type: BasicOperator
(2) -> phirule := rule erf(%x)==2*N(x*sqrt(2))-1

+-+
(2) erf(%x) == 2 N(x\|2 ) - 1
Type: RewriteRule(Integer,Integer,Expression(Integer))
(3) -> (1/(sqrt(2*%pi)))*integrate(exp(-t^2/2),t=%minusInfinity..x)

+-+ x +-+ +---+
(\|2 erf(----) + \|2 )\|%pi
+-+
\|2
(3) ----------------------------
+-----+
2 \|2 %pi
Type: Expression(Integer)
(4) -> phirule(%)

+-+ +-+ +---+
\|2 N(x\|2 )\|%pi
(4) ------------------
+-----+
\|2 %pi
Type: Expression(Integer)


Note that for FriCAS 'N' is an arbitrary functions with unknown
properties. The first line tells FriCAS that 'N' is being
used as function name (operator), otherwise FriCAS would complain
about undefined function.
--
Waldek Hebisch
--
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+***@googlegroups.com.
To post to this group, send email to fricas-***@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.
Riccardo GUIDA
2018-07-25 12:27:42 UTC
Permalink
IIUC there is a misprint in both previous emails: %x in the LHS of the rule should be replaced by x as in the RHS. ric

(1) -> N := operator 'N

(1) N
Type: BasicOperator
(2) -> phirule := rule erf(%x)==2*N(x*sqrt(2))-1 -- BAD

┌─┐
(2) erf(%x) == 2 N(x\│2 ) - 1
Type: RewriteRule(Integer,Integer,Expression(Integer))
(3) -> phirule(erf(y))

┌─┐
(3) 2 N(x\│2 ) - 1
Type: Expression(Integer)
(4) -> phirule := rule erf(x)==2*N(x*sqrt(2))-1 -- OK

┌─┐
(4) erf(x) == 2 N(x\│2 ) - 1
Type: RewriteRule(Integer,Integer,Expression(Integer))
(5) -> phirule(erf(y))

┌─┐
(5) 2 N(y\│2 ) - 1
Type: 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+***@googlegroups.com.
To post to this group, send email to fricas-***@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.
Loading...