Hello Ralf,

I have not seen this discussion, but I you have Mathamatica or a
WolframKernel jlFricas can easily do this using of course Julia and the
MathLink.jl package:

In the Julia promp:
]
add MathLink

Your Mathematica installation will be used, see
https://github.com/JuliaInterop/MathLink.jl

(1) -> aa:=jWSExpr aa;xx:=jWSExpr xx

   (1)  xx
                                                         Type:
JLWSExpression
(2) -> expr:=sin(xx)^(aa+tan(xx^(-1)))

   (2)

          aa + tan(1/xx)
   sin(xx)
                                                         Type:
JLWSExpression
(3) -> expr2:=sin(x)^(a+tan(x^(-1)))

                  1
              tan(-) + a
                  x
   (3)  sin(x)
                                                    Type:
Expression(Integer)
(4) -> toString jlApply("InputForm",expr)

   (4)  "Sin[xx]^(aa + Tan[xx^(-1)])"
                                                                 Type:
String
(5) -> toString(expr/7,"InputForm")

   (5)  "Sin[xx]^(aa + Tan[xx^(-1)])/7"
                                                                 Type:
String
(6) -> jWSExpr toString(expr/7,"InputForm") -- evaluate directly the string
in Mathematica

   (6)

          aa + tan(1/xx)
   sin(xx)
   ---------------------
             7
                                                         Type:
JLWSExpression
(7) -> %^7

   (7)

          7 aa + 7 tan(1/xx)
   sin(xx)
   -------------------------
            823543
                                                         Type:
JLWSExpression

Here, small support to return the EXPR(INT) version, but beware, this is
interpreted in a new environment the Waldek's function
'interpret_in_new_env':
    strToExprInt(s : String) : Union(Expression(Integer), "failed") ==
      str := concat("0$Expression(Integer)+", s)
      af := parse(str)$InputForm
      av := interpret_in_new_env(af)$InputForm
      retractIfCan(av)$AnyFunctions1(Expression(Integer))

    strToExprFloat(s : String) : Union(Expression(Float), "failed") ==
      str := concat("0$Expression(Float)+", s)
      af := parse(str)$InputForm
      av := interpret_in_new_env(af)$InputForm
      retractIfCan(av)$AnyFunctions1(Expression(Float))

 I use it only to do some comparisons. I do not use the returned value; its
behavior is undefined for me.

(8) -> %::EXPR INT

                      1
               7 tan(--) + 7 aa
                     xx
        sin(xx)
   (8)  -----------------------
                 823543
                                                    Type:
Expression(Integer)


But here, you have direct access to Mathematica inside FriCAS using Wolfram
Symbolic Transport Protocol.
So no need to start Mathematica if you want console-based Mathematica work.
Here is another example with jWSExpr, it should accept all console
compatible Mathematica expression:

(10) -> integrate(1/(x^3 - 1), x)

                                                                     +-+
            +-+     2               +-+                    (2 x + 1)\|3
         - \|3 log(x  + x + 1) + 2 \|3 log(x - 1) - 6 atan(-------------)
                                                                 3
   (10)  ----------------------------------------------------------------
                                         +-+
                                      6 \|3
                                         Type: Union(Expression
(Integer),...)
(11) -> jWSExpr "Integrate[1/(x^3 - 1), x]"

   (11)

            1 + 2 x
     atan(-------)                              2
            sqrt(3)     log(1 - x)   log(1 + x + x )
   -(---------------) + ---------- - ---------------
         sqrt(3)            3               6
                                                         Type:
JLWSExpression
(12) -> factor %

   (12)

                     1 + 2 x                                2
   -2 sqrt(3) atan(-------) + 2 log(1 - x) - log(1 + x + x )
                     sqrt(3)
   -----------------------------------------------------------
                                6
                                                         Type:
JLWSExpression
(13) -> simplify(%%(11))

   (13)

                     1 + 2 x                                2
   -2 sqrt(3) atan(-------) + 2 log(1 - x) - log(1 + x + x )
                     sqrt(3)
   -----------------------------------------------------------
                                6
                                                         Type:
JLWSExpression



The jlFriCAS built with Clozure CL is relatively stable with this package.
With SBCL jlFriCAS can be unstable and falls in the debugger...

- Greg


Le ven. 14 mars 2025 à 00:14, 'Ralf Hemmecke' via FriCAS - computer algebra
system <fricas-devel@googlegroups.com> a écrit :

> I sometimes want to compare FriCAS output with that what Mathematica
> returns and also wanted to be able to cut&paste FriCAS expressions to
> Mathematica without always having the need to change the syntax
> manually. I therefore modified Format1D in such a way that it shows
> Mathematica syntax.
>
> Of course, that cannot be perfect, because OutputForm is an output
> format and does not contain enough information. Nevertheless, the
> attached file produces Mathematica expressions for many common cases.
>
> Please try your favourite expression(s) and let me know where I should
> adapt something.
>
> Use as follows:
>
> )compile fmtmma.spad
> strmma x ==>
> first(lines(format(format(x::OutputForm)$Formatter(FormatMathematica))))
> dispmma x ==> display(x::OutputForm::Formatter(FormatMathematica))
>
> strmma(sin(x)^(a+tan(x^(-1))))
> dispmma(sin(x)^(a+tan(x^(-1))))
> dispmma(sum(sin(k*x),k=1..n))
>
> ===============================
> %%% (33) -> strmma(sin(x)^(a+tan(x^(-1))))
>
>     (33)  "Sin[x]^(Tan[1/x]+a)"
>                                                  Type: String
> %%% (34) -> dispmma(sin(x)^(a+tan(x^(-1))))
> Sin[x]^(Tan[1/x]+a)
>                                                  Type: Void
> %%% (35) -> dispmma(sum(sin(k*x),k=1..n))
>     [OUTPUTFORM = k = 1, SEXPRESSION = (= k 1)]
> Sum[Sin[k*x], {k, 1, n}]
>                                                  Type: Void
>
> 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 view this discussion visit
> https://groups.google.com/d/msgid/fricas-devel/81040453-ba21-463d-aa48-7b871ee676ef%40hemmecke.org
> .
>

-- 
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 view this discussion visit 
https://groups.google.com/d/msgid/fricas-devel/CAHnU2dbK4sZP-MrQ%3Dek5WBWz3Pv0e_SX9c%3D-8QFj58Du0%2B9B3w%40mail.gmail.com.

Reply via email to