[fricas-devel] Factor a polynomial in the argument of an exponential

2018-11-08 Thread Marduk
Dear all,

I would like to convert exp(-a^2*x^2 - a^2*y^2) into exp(-a^2*(x^2 + y^2)). 
However,
it seems that exp converts its argument presumably to Expression Integer, 
and 
since FriCAS always expands products the factorization is lost.

For more general expressions, I would like to write a rule that matches 
%c*exp(x/y) 
and rewrites it as %c*exp(factorFraction x/y).

Thank you in advance.

Best regards,
Marduk

-- 
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] Factor a polynomial in the argument of an exponential

2018-11-08 Thread Ralf Hemmecke
Hi Marduk,

> I would like to convert exp(-a^2*x^2 - a^2*y^2) into exp(-a^2*(x^2 +
> y^2)).

I don't know either. Maybe it would be easier to help if you explain the
actual problem you want to solve. Perhaps this factorization is not
really necessary.

It might even be that your rule (whatever it is) does not even apply.

(1) -> E ==> Expression Integer
  Type: Void
(2) -> p:E := a*(x+y)

   (2)  a y + a x
  Type: Expression(Integer)
(8) -> f := factor p

   (8)  a y + a x
 Type: Factored(Expression(Integer))
(9) -> factors factor p

   (9)  []
 Type: List(Record(factor: Expression(Integer),exponent:
NonNegativeInteger))
(10) -> unit f

   (10)  a y + a x
  Type: Expression(Integer)
As you can see, factoring in the domain Expression considers p as an
expression, not as a polynomial.

> However, it seems that exp converts its argument presumably to
> Expression Integer, and since FriCAS always expands products the
> factorization is lost.

Yes. That is another the problem. You must understand that FriCAS is
fundamentally different than other CAS like Maple or Mathematica. They
basically have only an expression tree as their data structure. So for
any transformation there is a function.

FriCAS, however, maintains a whole pool of different data structures,
one for each specific task. Elements of such "domains" are kept
internally in a canonical form (as much as this is possible). That is
why in FriCAS, there is no "simplify".

Well, usually Expression(X) is for manipulating expressions, but (unless
somebody else here on the list comes up with a solution for you) I would
say, Expression(X) doesn't allow what you want to achieve.

Ralf

-- 
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] Simple Gaussian integral fails

2018-11-08 Thread Marduk
Dear all,

I just tried calculating this integral (I defined inf ==> %plusInfinity) 

integrate(exp(-a^2*x^2),x=-inf..inf)

in FriCAS 1.3.4 and it failed. Why?

Best regards,
Marduk

-- 
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] Simple Gaussian integral fails

2018-11-08 Thread Ralf Hemmecke
I suspect, the problem lies in the limit computation.

Ralf

(1) -> i := integrate(exp(-a^2*x^2),x)::Expression(Integer)

+--+
 +---+  | 2
\|%pi erf(x\|a  )
   (1)  -
+--+
| 2
 2 \|a
Type:
Expression(Integer)
(2) -> limit(erf(x),x=%plusInfinity)

   (2)  1
  Type:
Union(OrderedCompletion(Expression(Integer)),...)
(3) -> limit(erf(sqrt(a^2)*x),x=%plusInfinity)

   (3)  "failed"
Type:
Union("failed",...)


On 11/8/18 1:05 PM, Marduk wrote:
> Dear all,
> 
> I just tried calculating this integral (I defined inf ==> %plusInfinity) 
> 
> integrate(exp(-a^2*x^2),x=-inf..inf)
> 
> in FriCAS 1.3.4 and it failed. Why?
> 
> Best regards,
> Marduk
> 

-- 
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: Simple Gaussian integral fails

2018-11-08 Thread Marduk
Interesting. I did some experiments and it seems that limit(erf(M*x), 
x=inf) returns 1
whenever FriCAS can determine that M > 0. In particular M=a^2 and M=exp(a) 
work,
whereas M=a does not. However, M = abs(a) does not work either.

Now I have some questions:

1) Why does not sqrt(a^2) return abs(a)?

2) Why does not FriCAS know that abs(a) > 0?

3) How can one tell FriCAS that a>0 in the Gaussian integral? 
In Maxima this is done with assume. Maybe in FriCAS one could use 
predicates.

-- 
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: Factor a polynomial in the argument of an exponential

2018-11-08 Thread Marduk
Hi Ralf,

Thank you for your prompt reply. I understand that FriCAS works different 
from
other CA systems. To me it is like using Haskell for doing computer 
algebra. 
And I think that is a very interesting approach. 

I am not a computer scientist, but I think it should be possible to do the 
same things
using a type-based and a list-based CA system. In particular, there must be 
a way of
defining a type for an exponential of a factored polynomial.

I am not interested in factorizing the exponential for doing a calculation, 
it is just for 
inserting the resulting expression in TeXmacs.

-- 
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: Simple Gaussian integral fails

2018-11-08 Thread Ralf Hemmecke
> 1) Why does not sqrt(a^2) return abs(a)?

OK, let's try with a being the imaginary unity.

(4) -> sqrt(%i^2)

   (4)  %i
   Type:
Expression(Complex(Integer))
(5) -> abs(%i)

   (5)  abs(%i)

FriCAS does not simplify abs(%i). So it's left unspecified.
You would probably not agree that abs(%i)=%i

> 2) Why does not FriCAS know that abs(a) > 0?

Because it is just an operator and a can be anything. What would you
want abs("Hello World!") to return?

> 3) How can one tell FriCAS that a>0 in the Gaussian integral? 
> In Maxima this is done with assume. Maybe in FriCAS one could use 
> predicates.

I've no idea.

Ralf

-- 
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: Factor a polynomial in the argument of an exponential

2018-11-08 Thread Ralf Hemmecke
> In particular, there must be a way of defining a type for an
> exponential of a factored polynomial.

Of course, there is. However, I guess, you don't want to program this
just for the following.
> I am not interested in factorizing the exponential for doing a
> calculation, it is just for inserting the resulting expression in
> TeXmacs.

And I cannot even suggest you what to do, because how complicated that
programming will be depends very much on what you want to do with such a
type. If you don't want to compute with such expressions then one can
simply take

Factored Polynomial Integer

as a representation domain and modify the output routine

coerce: % -> OutputForm

in such a way that is displays

exp( ... )

and the factored polynomial where I have put the dots. But I guess, you
don't really want just that.

Ralf

PS: BTW, what does have TeXmacs have to do with this FriCAS question?

-- 
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: Simple Gaussian integral fails

2018-11-08 Thread Marduk

>
> OK, let's try with a being the imaginary unity.
>

I thought that by default FriCAS assumes that variables are real. 
 

> Because it is just an operator and a can be anything. 

 
Fair enough. Then one should be able to specify on which domain an operator 
is acting
and abs(a) | a is real should know that a > 0.

I just found out that the exact same question was asked 7 years ago:
https://groups.google.com/d/topic/fricas-devel/jTeaKzcEJgs/discussion

It is surprising that nothing has been done to correct this problem. But 
reading that thread
explains why. It is not a matter of mathematics or computer science, but a 
matter of sociology.

To us physicists, Juanjo in that thread and myself, a CAS should be a tool 
that helps us save
time by performing the calculations that come up in our work. But to the 
current maintainers of
the big three: Maxima, FriCAS and Reduce, it does not matter that their 
programs cannot calculate
Gaussian integrals (all three have failed my tests). 

In the Axiom/FriCAS wiki it is claimed that this CAS boasts the most 
complete implementation of the
Risch algorithm. And I am sure that it can calculate thousands of 
integrals. But what is the purpose of
having a sophisticated integrator if it cannot calculate the simplest 
integrals? In the thread above 
Waldek replies: do not use it for calculating integrals you already know. 
Seriously?

I must say that it is highly disappointing that to this date there is no 
serious free-software alternative to
Mathematica. The three programs mentioned above have been developed for 
about 40-50 years by very
capable computer scientists and mathematicians. Axiom/FriCAS is IMHO the 
best designed of the three, 
it is thoroughly documented and all that effort is wasted because the 
developers do not care for the needs
of the users. Pretty sad.

Marduk

-- 
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: Factor a polynomial in the argument of an exponential

2018-11-08 Thread Marduk

>
> PS: BTW, what does have TeXmacs have to do with this FriCAS question?
>

I use TeXmacs as a frontend for FriCAS. I would like to be able to use the 
expressions
generated by the CAS directly in my notes, papers, etc. But apparently, it 
takes some
work to get that done.

Thanks anyway for your time and your comments.

Marduk

-- 
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: Simple Gaussian integral fails

2018-11-08 Thread Ralf Hemmecke
> I must say that it is highly disappointing that to this date there
> is no serious free-software alternative to Mathematica.

It all depends on what you want to do.

> The three programs mentioned above have been developed for about
> 40-50 years by very capable computer scientists and mathematicians.
> Axiom/FriCAS is IMHO the best designed of the three, it is thoroughly
> documented and all that effort is wasted because the developers do
> not care for the needs of the users. Pretty sad.

Surely this is sad. But in contrast to Mathematica developers, FriCAS
developers don't see a single cent for their efforts. People do that in
their spare time. It's just natural that solving their own problems
comes first. If that helps other people then fine.

Clearly, we could setup a channel where people would be able to devote
some money to FriCAS developers in order to get a certain problem solved
(implemented).

It's not an excuse, but also open source development costs time and
effort. The sad thing is that FriCAS does not have enough developers,
but a lot of places where it needs improvements.

So everyone is welcome to contribute, even if it is just bug reports.

Success to whatever you want to achieve.

Ralf

-- 
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: Factor a polynomial in the argument of an exponential

2018-11-08 Thread oldk1331
I was also having some thoughs about factoring Expression.

I think it's doable, especially for displaying purpose.

We can use "paren"/"box" to keep the factors.

A quick sketch:

(25) -> exp map(x+->box(x::EXPR INT),factor numer first argument
mainKernel exp(-a^2*x^2 - a^2*y^2))

  2  22
   - a (y  + x )
   (25)  %e


On Thu, Nov 8, 2018 at 10:04 PM Marduk  wrote:
>>
>> PS: BTW, what does have TeXmacs have to do with this FriCAS question?
>
>
> I use TeXmacs as a frontend for FriCAS. I would like to be able to use the 
> expressions
> generated by the CAS directly in my notes, papers, etc. But apparently, it 
> takes some
> work to get that done.
>
> Thanks anyway for your time and your comments.
>
> Marduk
>
> --
> 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.

-- 
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: Factor a polynomial in the argument of an exponential

2018-11-08 Thread Ralf Hemmecke
> We can use "paren"/"box" to keep the factors.

I was thinking about "box", but not in such a sophisticated way as you
did. Comes probably from my dislike of Expression(X). ;-)

Ralf

> (25) -> exp map(x+->box(x::EXPR INT),factor numer first argument
> mainKernel exp(-a^2*x^2 - a^2*y^2))
> 
>   2  22
>- a (y  + x )
>(25)  %e

-- 
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: Re: Simple Gaussian integral fails

2018-11-08 Thread Riccardo GUIDA



On 11/8/18 1:05 PM, Marduk wrote:

3) How can one tell FriCAS that a>0 in the Gaussian integral?


Write a=A^2 :

(1) -> inf ==> %plusInfinity; integrate(exp(-A^4*x^2),x=-inf..inf)

 ┌───┐
\│%pi
   (1)  ──
   2
  A
  Type: Union(f1: OrderedCompletion(Expression(Integer)),...)


another sad physicist...


--
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: Simple Gaussian integral fails

2018-11-08 Thread Riccardo GUIDA

1) Why does not sqrt(a^2) return abs(a)?


IIUC:

When operating on a symbolic expression x in Expression R,
the operator sqrt "represents an arbitrary (but always the same through the code) 
solution y of the algebraic equation y^2=x".
Even when R = Integer, there are still 2 real roots y that satisfy the equation.

Similar semantics for the n-th root nthRoot:
"an arbitrary (but always the same through the code) solution of the algebraic 
equation y^n=x".

Note that sqrt(x) may not be imagined to be a set with two elements
because the (pointwise) product of two sets would be a set including also
non-diagonal products of the elements.
(IE sqrt(4)={+2,-2} ==> sqrt(4)*sqrt(4) = {(+2)*(+2),...} = {+4, -4}).

So, FriCAS deliberately tries not to make a choice of roots
and consequently sqrt has a different semantics (on expressions)
as compared to all other CAS in my knowledge.

As for the (sometimes) weird behavior of abs in FriCAS
this should be related to the fact that using a smart abs one might construct 
zero divisors,
(nonzero  x1,x2 such that x1 * x2 = 0). This would violate the fact that 
Expression Integer
is meant to be a differential field, which is essential for the indefinite 
integration algorithms.
To recover more information I advice you to track the above keywords in the 
past messages:
many of your (present and future) questions have been already asked many times 
in the last 10 years.

riccardo

--
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] Simple Gaussian integral fails

2018-11-08 Thread oldk1331

I think it's doable.

First, by default, "limit" is for real expression (there are
accompanying "complexLimit"), so it knows "sqrt(a)" is positive:

(8) -> limit(sqrt(a)*x,x=%plusInfinity)

   (8)   + infinity

So in theory, it should also compute for "erf(sqrt(a)*x)", but:

(9) -> limit(erf(sqrt(a)*x),x=%plusInfinity)

   (9)  "failed"

This should be very simple to compute, but we still use Gruntz
algorithm to compute and we fail at there.  This may indicate
a bug in Gruntz algorithm, and raise another question: shall
we add a short path to handle simple cases, like "specialLimit"
in limitps.spad?

Another somewhat related problem:

(1) -> limit(sqrt(a^2)*x,x=%plusInfinity)

   (1)  "failed"

This case fails because "mrv_normalize" will destroy the structure
of "sqrt(a^2)", so maybe a "assume" system will still be needed.
But such a system is invasive and not always work in Maxima.

On 11/8/18 8:05 PM, Marduk wrote:

Dear all,

I just tried calculating this integral (I defined inf ==> %plusInfinity)

integrate(exp(-a^2*x^2),x=-inf..inf)

in FriCAS 1.3.4 and it failed. Why?

Best regards,
Marduk

--
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.


--
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.