Forum: Ruby Integration/Antidifferentiation Program

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
931d5cc3b6fcb9e740ad2846db11a9ba?d=identicon&s=25 SleepJunkie (Guest)
on 2006-04-27 19:30
I'd like to write a program to integrate derivatives to save time on
calc homework and get extra credit in the class. I'm not completely sure
where to start.

I'm just looking for some tips from others who understand what I'm going
to do and any suggestions.

Thanks,
Matt
A402df36168b81b31c17adcbb5ae8cf4?d=identicon&s=25 Pistos Christou (pistos)
on 2006-04-27 19:49
SleepJunkie wrote:
> I'd like to write a program to integrate derivatives to save time on
> calc homework and get extra credit in the class. I'm not completely sure
> where to start.
>
> I'm just looking for some tips from others who understand what I'm going
> to do and any suggestions.
>
> Thanks,
> Matt

Hm... you'll probably strengthen your derivation and integration skills
more if you actually solved the problems yourself.  ;)  If you really
need to have a computer work them out (such as to check your answers),
why not just use one of Mathematica, Maple, Matlab or IDL, which your
school probably has installed somewhere.

Personally, it sounds to me like too much work to write something
yourself whose answers you could be confident about.

Pistos
D4e51fd9554030ab55c379fdc1a34826?d=identicon&s=25 Keith Lancaster (klancaster)
on 2006-04-27 19:58
(Received via mailing list)
On 4/27/06, Pistos Christou <jesusrubsyou.5.pistos@geoshell.com> wrote:
> > Matt
> Pistos
>
> --
> Posted via http://www.ruby-forum.com/.


And just to add to that a bit - doing integration with a computer is
relatively straightforward if you are talking about definate integrals
and
solving them using numerical methods. If you are trying solve them
symbollically, even integrating something as simple as x^2 is not
trivial.
280b41a88665fd8c699e83a9a25ef949?d=identicon&s=25 Stephen Waits (Guest)
on 2006-04-27 20:01
(Received via mailing list)
Pistos Christou wrote:
>
> Hm... you'll probably strengthen your derivation and integration skills
> more if you actually solved the problems yourself.  ;)  If you really

I agree.  Matt didn't say how he wants to solve them, but if he wants to
write something to solve them symbolically, rather than numerically, he
may actually learn more.

But then again, that's not a task I'd want to take on.

--Steve
931d5cc3b6fcb9e740ad2846db11a9ba?d=identicon&s=25 SleepJunkie (Guest)
on 2006-04-27 20:04
I can integrate and derive perfectly fine. It's more of "I just want to
do this" then "Do my homework" program. If I do it, however, I'll get
extra credit, which is always good.

I guess this is going to be harder than I thought. I'll have to program
in the chain rule, quotient rule, product rule, and others..

More suggestions are welcome :)
E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 Logan Capaldo (Guest)
on 2006-04-27 20:46
(Received via mailing list)
On Apr 27, 2006, at 2:04 PM, SleepJunkie wrote:

>
> --
> Posted via http://www.ruby-forum.com/.
>

I think you're going to have to look at the source of some other
computer algebra systems to see and how its done. This isn't a
trivial problem, and it's not just a matter of knowing all the rules,
especially for integrations. (Try writing a program to do integration
by parts, how is it going to decide what u and v should be for
instance?)
784481e009179262d133db1f1eb3bfb1?d=identicon&s=25 Edwin Van leeuwen (blackedder)
on 2006-04-27 20:56
Logan Capaldo wrote:
> I think you're going to have to look at the source of some other
> computer algebra systems to see and how its done. This isn't a
> trivial problem, and it's not just a matter of knowing all the rules,
> especially for integrations. (Try writing a program to do integration
> by parts, how is it going to decide what u and v should be for
> instance?)

Maxima is an open source symbolic solver/integrator, so you could start
by looking how they do it.
08e4fd192c00c7136ca2ee38105213f7?d=identicon&s=25 Stuart Stegall (Guest)
on 2006-04-27 20:59
(Received via mailing list)
Just for normal college/university level calc1&2, you will need
approximately 300 rules to do general integration.  Derivation can be
done with only about 15rules though (though in general the rules are a
bit tougher)
931d5cc3b6fcb9e740ad2846db11a9ba?d=identicon&s=25 SleepJunkie (Guest)
on 2006-04-27 21:46
After hearing all of this and talking to a co-worker (programmer who has
been doing it much longer than I have), I have decided to just go with
making a program for differentiation.

I will look at the Maxima source code, thanks.
I'll see how this goes :)


Also, if you're curious, I'm just doing calculus of a single-variable.
Ce8b03e5750097942c58e12b46724312?d=identicon&s=25 Giles Bowkett (Guest)
on 2006-04-28 00:49
(Received via mailing list)
First of all I'd like to disagree with everybody who told you you'd be
better off doing your homework. I think you'll learn **more** about
integrating derivatives by automating the process than you will doing
it by hand a hundred million times.

Second, if I recall correctly, there's example code for this in
"Higher-Order Perl," although obviously the author of that particular
book didn't use Ruby to do it.

--
Giles Bowkett
http://www.gilesgoatboy.org
931d5cc3b6fcb9e740ad2846db11a9ba?d=identicon&s=25 SleepJunk13 (Guest)
on 2006-04-28 01:01
Giles Bowkett wrote:
> First of all I'd like to disagree with everybody who told you you'd be
> better off doing your homework. I think you'll learn **more** about
> integrating derivatives by automating the process than you will doing
> it by hand a hundred million times.
>
> Second, if I recall correctly, there's example code for this in
> "Higher-Order Perl," although obviously the author of that particular
> book didn't use Ruby to do it.
>
> --
> Giles Bowkett
> http://www.gilesgoatboy.org


Thanks a lot for that book, I'll have to check the book store and read
up on it or run to the library. And I agree too that I'd learn more that
way, but I'm doing great in calc now. I could, however, distribute it to
the morons in the class ;)
931d5cc3b6fcb9e740ad2846db11a9ba?d=identicon&s=25 SleepJunk13 (Guest)
on 2006-04-28 01:29
So.. I have no idea where to start.

I'm starting to think even this is too big for me to do. I've only made
small programs before. I'd really like a place to start, or something to
help get me started. I'm going to have to be able to parse so many
different things.

Maybe I need to learn more Ruby. I'd love to do this, though.
Bbc4b3fca1ae3161257a8636145b424d?d=identicon&s=25 Elliot Temple (Guest)
on 2006-04-28 01:40
(Received via mailing list)
On Apr 27, 2006, at 4:29 PM, SleepJunk13 wrote:

> So.. I have no idea where to start.

Maybe you should figure out a format for storing polynomials, make a
class to deal with this, and then create some basic functions like
multiply or whatever you think you'll need.  or find a library to do
this.

-- Elliot Temple
http://www.curi.us/blog/
3bb23e7770680ea44a2d79e6d10daaed?d=identicon&s=25 M. Edward (Ed) Borasky (Guest)
on 2006-04-29 05:08
(Received via mailing list)
Basic symbolic differentiation is a piece of cake. It's usually done as
an exercise in Lisp programming, but there's no reason on earth you
can't do it in Ruby, or for that matter, any language that supports
recursion. Hell, I've seen it done in Fortran! :)

Symbolic integration is quite a bit more difficult. However, there are
quite a few open-source computer algebra packages you can learn the
algorithms from. There is absolutely no need to spend the money on
Mathematica or Maple -- both quite expensive outside of a university --
just to get some integrals done. Check out Maxima and Axiom.

I think a high-school-level differentiation routine would make an
excellent Ruby quiz, now that I think of it.

SleepJunkie wrote:
> I can integrate and derive perfectly fine. It's more of "I just want to
> do this" then "Do my homework" program. If I do it, however, I'll get
> extra credit, which is always good.
>
> I guess this is going to be harder than I thought. I'll have to program
> in the chain rule, quotient rule, product rule, and others..
>
> More suggestions are welcome :)
>
>

--
M. Edward (Ed) Borasky

http://linuxcapacityplanning.com
3bb23e7770680ea44a2d79e6d10daaed?d=identicon&s=25 M. Edward (Ed) Borasky (Guest)
on 2006-04-29 05:11
(Received via mailing list)
Hmmm ... there's actually a C++ library for writing computer algebra
function -- it's called "ginac". Maybe all you need to do is write Ruby
bindings to ginac and call the ginac functions. I'm not sure what
"high-level" classes it has, like for differentiation, integration or
equation solving.

Elliot Temple wrote:
> -- Elliot Temple
> http://www.curi.us/blog/
>
>
>
>
>

--
M. Edward (Ed) Borasky

http://linuxcapacityplanning.com
08e4fd192c00c7136ca2ee38105213f7?d=identicon&s=25 Stuart Stegall (Guest)
on 2006-04-29 06:27
(Received via mailing list)
As this is a calc student, I would assume he want to write the whole
thing.
7264fb16beeea92b89bb42023738259d?d=identicon&s=25 Christian Neukirchen (Guest)
on 2006-05-03 19:08
(Received via mailing list)
Elliot Temple <curi@curi.us> writes:

>> So.. I have no idea where to start.
>
> Maybe you should figure out a format for storing polynomials, make a
> class to deal with this, and then create some basic functions like
> multiply or whatever you think you'll need.  or find a library to do
> this.

http://www.math.kobe-u.ac.jp/~kodama/tips-RubyPoly.html
9eb9840bff908112be8557c9488706ca?d=identicon&s=25 Justin Bangerter (vtphysguy)
on 2006-05-09 04:28
I've been thinking about doing something like this myself, just for
shits and giggles, and I was just wondering if it would be good to use
infinite series expressions to integrate. It seems like it would be a
more standardized way of integration (unless an ln shows up somewhere).
Perhaps once you can write something that will integrate polynomial
expressions, it would be reasonable to use infinite series like this.
However, I haven't really taken the time to mess with it.  I don't know
how much calculus you know, either, so I don't know if you really want
to teach yourself Taylor and Maclauren series just to do this.  If
you're really into it, though, that way seems possible.
3bb23e7770680ea44a2d79e6d10daaed?d=identicon&s=25 M. Edward (Ed) Borasky (Guest)
on 2006-05-09 05:58
(Received via mailing list)
A look at Axiom or Maxima (open source) or Derive (closed source but
very inexpensive, especially to college students) will pretty much show
you what the state of the art in antidifferentiation algorithms is. The
name I remember is Risch, although there may be some others.

Justin Bangerter wrote:
>
>

--
M. Edward (Ed) Borasky

http://linuxcapacityplanning.com
Ce8b03e5750097942c58e12b46724312?d=identicon&s=25 Giles Bowkett (Guest)
on 2006-05-09 06:20
(Received via mailing list)
I know nada about calc, but for what it's worth, it's used as a
teaching exercise in the Perl book I mentioned (and is probably
adapted from the Lisp teaching exercises somebody else mentioned).

Of course it's heavily dependent on recursion, if I recall correctly.

--
Giles Bowkett
http://www.gilesgoatboy.org
71ee1809f53df0a2b4dac0530f630933?d=identicon&s=25 Richard Schneeman (snowmaninthesun)
on 2009-02-05 19:00
Hey, has anyone successfully created a program with Ruby that uses
maxima or any other "reasonably cheap" (or free) math programs?? If so,
can you point me to any resources??

http://www.ruby-forum.com/topic/177704#new
3bb23e7770680ea44a2d79e6d10daaed?d=identicon&s=25 M. Edward (Ed) Borasky (Guest)
on 2009-02-05 21:06
(Received via mailing list)
Richard Schneeman wrote:
> Hey, has anyone successfully created a program with Ruby that uses
> maxima or any other "reasonably cheap" (or free) math programs?? If so,
> can you point me to any resources??
>
> http://www.ruby-forum.com/topic/177704#new

I'm not sure what you mean by Ruby "using" maxima. Maxima is a
stand-alone program, and it has a wxWidgets GUI called "wxMaxima" and an
X-Windows GUI called XMaxima. If you just want to access maxima as a
"server" from Ruby, I'm sure there's a way to start it up using "system"
and pass it input / capture its output via pipes.

What's the application goal / use case / problem you're trying to solve?
Are you trying to use symbolic mathematics as part of a Ruby
application?
--
M. Edward (Ed) Borasky

I've never met a happy clam. In fact, most of them were pretty steamed.
71ee1809f53df0a2b4dac0530f630933?d=identicon&s=25 Richard Schneeman (snowmaninthesun)
on 2009-02-05 21:50
By "using" maxima, I mean accessing maxima via a pipe in Ruby. I am
developing a web based mathematical application that can integrate
symbolically among other things. I don't have to use maxima or even ruby
for that matter but I would like to if possible. I understand the
concept of "system" access but during the execution I've hit two snags

First, If i run this code multiple times:

max = IO.popen("maxima", "w+")
max.puts "1+1;"
8.times {max.gets} #needed to rid of unneeded lines
response = max.gets
max.close

I get a new instances (found via ps -A) of  "ttys000 0:00.00 (sbcl)"
every time i run the code. And i can't kill this "sbcl" via "kill pid".
And after enough runs, I have to restart my computer.

Second, I am unable to just get the last line from maxima without
running "8.times {max.gets}." If i try to execute "max.gets" after
maxima has reached the last line, I get an error (and no return to
ruby). While i can get around this problem, (via 8.times ) it isn't
exactly best practices.

So, any suggestions??
9b905791cbdbb1af35b65e02c3217e23?d=identicon&s=25 Tom Link (Guest)
on 2009-02-05 23:01
(Received via mailing list)
> Second, I am unable to just get the last line from maxima without
> running "8.times {max.gets}." If i try to execute "max.gets" after
> maxima has reached the last line, I get an error (and no return to
> ruby). While i can get around this problem, (via 8.times ) it isn't
> exactly best practices.

AFAIK the maxima gui itself passes the code on to an inferior lisp
process that does the actual work. I don't know how much work that
would be to implement that protocol but maybe looking at the gui's
source code would help to give you an idea of how to communicate with
maxima reliably.
3bb23e7770680ea44a2d79e6d10daaed?d=identicon&s=25 M. Edward (Ed) Borasky (Guest)
on 2009-02-05 23:18
(Received via mailing list)
There are a number of web apps that do this sort of thing -- live math
on the web. It sounds to me like you're re-inventing a wheel here. Of
course, most of said web apps are not in Ruby, because Ruby and Rails
weren't popular when they were designed.

On Thu, Feb 5, 2009 at 12:49 PM, Richard Schneeman
<thedickster@gmail.com> wrote:
> 8.times {max.gets} #needed to rid of unneeded lines
> ruby). While i can get around this problem, (via 8.times ) it isn't
> exactly best practices.
>
> So, any suggestions??
> --
> Posted via http://www.ruby-forum.com/.
>
>



--
M. Edward (Ed) Borasky

I've never met a happy clam. In fact, most of them were pretty steamed.
71ee1809f53df0a2b4dac0530f630933?d=identicon&s=25 Richard Schneeman (snowmaninthesun)
on 2009-02-06 17:31
For reinventing the wheel...the best candidate for copying is WMI (uses
maxima) http://matek.hu/ which is kind enough to give its src code away
for free, unfortunately its PHP and I haven't had anyone who knows
enough about PHP & Ruby to help me figure out what i'm doing wrong:

Here is the PHP: http://pastie.org/380232

Thanks Tom for the Idea, i found an article about converting ruby code
to lisp here: http://onestepback.org/index.cgi/Tech/Ruby/LispInRuby.red
so calling commands naively may be a good work around.

I also discovered Sage an open source math program written in python
http://www.sagemath.org/ I haven't done anything with python before, but
I have some friends who rave django, so it may just be easier to go that
route. Either way I'll let everyone know what ended up meeting my needs.
3bb23e7770680ea44a2d79e6d10daaed?d=identicon&s=25 M. Edward (Ed) Borasky (Guest)
on 2009-02-06 17:56
(Received via mailing list)
Richard Schneeman wrote:

> I also discovered Sage an open source math program written in python
> http://www.sagemath.org/ I haven't done anything with python before, but
> I have some friends who rave django, so it may just be easier to go that
> route. Either way I'll let everyone know what ended up meeting my needs.

Sage is an outstanding project, even though it is written in Python. :)
I'm on their mailing list and I've done a fair amount of testing of it.
In terms of tools for day-to-day use by working mathematicians, I don't
know of anything better in the open source world, and they are closing
in on the expensive proprietary packages like Mathematica and Matlab.

Funny you should mention Sage, since their slogan is, or used to be,
"Building the car, not re-inventing the wheel." :)


--
M. Edward (Ed) Borasky

I've never met a happy clam. In fact, most of them were pretty steamed.
2d3ec3a83b4f8784d6853564fa0d2e77?d=identicon&s=25 Dido Sevilla (Guest)
on 2009-02-07 17:07
(Received via mailing list)
On Fri, Apr 28, 2006 at 1:31 AM, SleepJunkie <SleepJunk13@gmail.com>
wrote:
> I'd like to write a program to integrate derivatives to save time on
> calc homework and get extra credit in the class. I'm not completely sure
> where to start.
>

http://en.wikipedia.org/wiki/Risch_algorithm

There's apparently an algorithm out there that can do symbolic
integration of any elementary function, and returns either its
antiderivative, or that its antiderivative is not expressible in terms
of elementary functions. The only problem that it requires at several
points to determine whether two expressions are equal, and that,
unfortunately, is difficult, and in some cases actually impossible
(undecidable) depending on what functions you allow. See

http://en.wikipedia.org/wiki/Richardson's_theorem

There's also a whole theory built up from this called differential
Galois theory, which extends ideas originally developed by Évariste
Galois for the solvability of polynomial equations into solving
differential equations, which is really what antidifferentiation is
all about:

http://en.wikipedia.org/wiki/Differential_Galois_theory

You're treading in deep water here, brother. Beware.
This topic is locked and can not be replied to.