holy crap, dude! You speak portuguese too? you really are an
informatimago... :)
Em 16/09/2015 01:56, "Pascal J. Bourguignon" <[email protected]>
escreveu:

> padovani <[email protected]> writes:
>
> > Oi pessoal,
> >
> > agluma dica de como plotar automaticamente uma s-expression como
> > fórmula matemática? (de preferência simplificando expressões)
> >
> > por exemplo: queria ver essa expressão aqui como função "f(x) = ...":
> >
> > (+ (- 38 -42) (cos (+ (* (* (* x x) (+ 83 (cos (abs (cos (/ (/ x x)
> > 28)))))) (- (abs x) (+ (abs -16) x))) x)))
> >
> > (foi gerada algoritmicamente... não está simplificada)
>
>
>
> Você poderia reescrever a expressão em uma expressão maxima e ter
> maxima exibi-lo.
>
> (defun maxima-sexp (sexp)
>   (cond
>     ((typep sexp 'ratio) `((rat simp) ,(numerator sexp) ,(denominator
> sexp)))
>     ((numberp sexp) sexp)
>     ((symbolp sexp) (intern (concatenate 'string "$" (symbol-name sexp))))
>     ((atom sexp) (error "I don't know how to handle ~S" sexp))
>     ((eq '/ (first sexp))
>      (list '(MTIMES SIMP)
>            (maxima-sexp (second sexp))
>            (list '(MEXPT SIMP) (maxima-sexp (third sexp)) -1)))
>     ((member (first sexp) '(+ - *))
>      (list* (list (cdr (assoc (first sexp) '((+ . mplus)
>                                              (- . mminus)
>                                              (* . mtimes)))) 'simp)
>             (mapcar (function maxima-sexp) (rest sexp))))
>     (t
>      (list* (list (intern (concatenate 'string "%" (symbol-name (first
> sexp)))) 'simp)
>             (mapcar (function maxima-sexp) (rest sexp))))))
>
>
> [pjb@kuiper :0.0 ~]$ maxima
>
> Maxima 5.34.1 http://maxima.sourceforge.net
> using Lisp GNU Common Lisp (GCL) GCL 2.6.12 (a.k.a. GCL)
> Distributed under the GNU Public License. See the file COPYING.
> Dedicated to the memory of William Schelter.
> The function bug_report() provides bug reporting information.
> (%i1) :lisp (defun maxima-sexp (sexp) (cond ((typep sexp 'ratio) `((rat
> simp) ,(numerator sexp) ,(denominator sexp))) ((numberp sexp) sexp)
> ((symbolp sexp) (intern (concatenate 'string "$" (symbol-name sexp))))
> ((atom sexp) (error "I don't know how to handle ~S" sexp)) ((eq '/ (first
> sexp)) (list '(MTIMES SIMP) (maxima-sexp (second sexp)) (list '(MEXPT SIMP)
> (maxima-sexp (third sexp)) -1))) ((member (first sexp) '(+ - *)) (list*
> (list (cdr (assoc (first sexp) '((+ . mplus) (- . mminus) (* . mtimes))))
> 'simp) (mapcar (function maxima-sexp) (rest sexp)))) (t (list* (list
> (intern (concatenate 'string "%" (symbol-name (first sexp)))) 'simp)
> (mapcar (function maxima-sexp) (rest sexp))))))
>
> MAXIMA-SEXP
> (%i1) :lisp (displa (maxima-sexp '(+ (- 38 -42) (cos (+ (* (* (* x x) (+
> 83 (cos (abs (cos (/ (/ x x) 28)))))) (- (abs x) (+ (abs -16) x))) x)))))
>                              x
> cos(x - ((x x) (cos(abs(cos(----))) + 83)) abs(x) (x + abs(- 16))) - 38
>                             x 28
> NIL
> [pjb@kuiper :0.0 ~]$
>
>
> http://maxima.sourceforge.net/
> --
> __Pascal Bourguignon__                 http://www.informatimago.com/
> “The factory of the future will have only two employees, a man and a
> dog. The man will be there to feed the dog. The dog will be there to
> keep the man from touching the equipment.” -- Carl Bass CEO Autodesk
>
> --
> You received this message because you are subscribed to the Google Groups
> "Lisp-br" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/lisp-br.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Lisp-br" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/lisp-br.
For more options, visit https://groups.google.com/d/optout.

Responder a