Maths in Ruby

Hello to everyone!

I have a mathematic problem I need to solve, and it involves finding the values of three consecutive numbers, x, y and z. I need to be able to find every instance of these from negative one million (-1,000,000) up to one million (1,000,000). They must follow the following equations:

x + y + z = 5
x + y - z = 7
(x - y)(x - y)(x - y) + (y - z)(y - z)(y - z) = (x - z)(x - z)(x - z)

I'm completely and utterly stumped. I intend on solving this via Ruby, as doing it on pen and paper might take a while. :wink: If anyone has any suggestions, I'd love to hear them.

Thanks!

···

_________________________________________________________________
Advertisement: Meet Sexy Singles Today @ Lavalife - Click here http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Flavalife9.ninemsn.com.au%2Fclickthru%2Fclickthru.act%3Fid%3Dninemsn%26context%3Dan99%26locale%3Den_AU%26a%3D23769&_t=754951090&_r=endtext_lavalife_dec_meet&_m=EXT

Yannick Grams schrieb:

I have a mathematic problem I need to solve, and it involves finding the values of three consecutive numbers, x, y and z. I need to be able to find every instance of these from negative one million (-1,000,000) up to one million (1,000,000). They must follow the following equations:

x + y + z = 5
x + y - z = 7
(x - y)(x - y)(x - y) + (y - z)(y - z)(y - z) = (x - z)(x - z)(x - z)

I'm completely and utterly stumped. I intend on solving this via Ruby, as doing it on pen and paper might take a while. :wink: If anyone has any suggestions, I'd love to hear them.

Yannick, you don't need Ruby to solve this, just some basic Mathematics.

Regards,
Pit

Hi,

I have a mathematic problem I need to solve, and it involves finding the
values of three consecutive numbers, x, y and z. I need to be able to find
every instance of these from negative one million (-1,000,000) up to one
million (1,000,000). They must follow the following equations:

x + y + z = 5
x + y - z = 7
(x - y)(x - y)(x - y) + (y - z)(y - z)(y - z) = (x - z)(x - z)(x - z)

You can use "algebra" (http://raa.ruby-lang.org/project/algebra/\)

  require "algebra"
  R = MPolynomial(Rational)
  x, y, z = R.vars("xyz")
  f0 = x + y + z - 5
  f1 = x + y - z - 7
  f2 = (x - y)*(x - y)*(x - y) + (y - z)*(y - z)*(y - z) -
          (x - z)*(x - z)*(x - z)
  gs = Groebner.basis([f0, f1, f2])
  gs.each do |f|
    p f.factorize
  end

This shows:
  x + y - 6
  (y - 3)(y - 7)(y + 1)
  z + 1

These mean "z = -1, y = 3, 7, -1, x = -y + 6", And

  p f2.factorize #=> (-3)(x - z)(x - y)(y - z)

This means you can solve this by hand. :slight_smile:

Regards,
Shin-ichiro HARA

···

2007/3/5, Yannick Grams <yannick_grams@hotmail.com>:

Yannick Grams wrote:

Hello to everyone!

I have a mathematic problem I need to solve, and it involves finding the values of three consecutive numbers, x, y and z. I need to be able to find every instance of these from negative one million (-1,000,000) up to one million (1,000,000). They must follow the following equations:

x + y + z = 5
x + y - z = 7
(x - y)(x - y)(x - y) + (y - z)(y - z)(y - z) = (x - z)(x - z)(x - z)

I'm completely and utterly stumped. I intend on solving this via Ruby, as doing it on pen and paper might take a while. :wink: If anyone has any suggestions, I'd love to hear them.

Well, one of the reasons you might be stumped is that the problem as posed does not appear to have a solution. I punched it in to Maxima:

(%o1) z+y+x=5
(%o2) -z+y+x=7
(%o4) (y-z)^3+(x-y)^3=(x-z)^3
(%i5) solve([%o1,%o2,%o4], [x,y,z]);
(%o5) [[x=-1,y=7,z=-1],[x=3,y=3,z=-1],[x=7,y=-1,z=-1]]

Since one of the equations is a cubic, there are three solutions, and they are all smallish integers. But they are *not* consecutive!

Are you sure about the problem statement?

···

--
M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC(P)
http://borasky-research.blogspot.com/

If God had meant for carrots to be eaten cooked, He would have given rabbits fire.

"Yannick Grams" <yannick_grams@hotmail.com> writes:

Hello to everyone!

I have a mathematic problem I need to solve, and it involves finding
the values of three consecutive numbers, x, y and z. I need to be able
to find every instance of these from negative one million (-1,000,000)
up to one million (1,000,000). They must follow the following
equations:

x + y + z = 5
x + y - z = 7
(x - y)(x - y)(x - y) + (y - z)(y - z)(y - z) = (x - z)(x - z)(x - z)

I'm completely and utterly stumped. I intend on solving this via Ruby,
as doing it on pen and paper might take a while. :wink: If anyone has any
suggestions, I'd love to hear them.

This has already been answered by several others, but I'd like to
point out how it could have been solved easily with pencil and paper.

First off, look at the top two equations:

x + y + z = 5
x + y - z = 7

These tell you:

(x+y) + z = 5
(x+y) - z = 7

Although you can add the equations and then divide to get there, it
should be obvious at this point that (x+y) is the average of 5 and 7,
that is that x+y=6. Knowing that, you have that z=-1.

Now, the third equation is:

(x-y)**3 + (y+1)**3 = (x+1)**3

Now, one thing to hold onto is that when you have

   a**n + b**n = c**n

For any integer n > 2, the only way to get a solution with a, b, and c
integers is to have one of a, b, or c be 0. (*) Since a person put
this problem together to be solved, and since pencil-and-paper cubics
are a royal pain in the ass to solve in general if at least one
solution isn't integers, let's see if we can make it work with one of
those three bits we're cubing equal to 0.

First off, see if it'll work with x-y=0 :

  Well, if x-y=0, then x=y and then of course
  (x-y)**3 + (y+1)**3 = (x+1)**3
    0 + (x+1)**3 = (x+1)**3
  So, it'll work if x-y=0.

  Since x+y=6 one solution is then x=3,y=3,z=-1.

Now let's see if it works with y+1=0:

  Well, if y+1=0, then y=-1 and then:
  (x-y)**3 + (y+1)**3 = (x+1)**3
  (x+1)**3 + 0 = (x+1)**3
  So, it'll work if y+1=0.

  Since x+y=6, another solution is x=7,y=-1,z=-1

Now let's see if it works with x+1=0:

  Well, if x+1=0, then x=-1 and then:
  (x-y)**3 + (y+1)**3 = (x+1)**3
  (-1-y)**3 + (y+1)**3 = 0
  So, it'll work if x+1=0.

  Since x+y=6, the final solution is x=-1,y=7,z=-1

Since we're dealing with a cubic and a linear equation once "z" is
solved for with the first two equations, we can only expect to get
at most three solutions, so we're done. The three possible solutions
are:
  x=3, y=3, z=-1
  x=7, y=-1,z=-1
  x=-1,y=7, z=-1

(*) There's not room in this post to prove that here.

···

--
s=%q( Daniel Martin -- martin@snowplow.org
       puts "s=%q(#{s})",s.map{|i|i}[1] )
       puts "s=%q(#{s})",s.map{|i|i}[1]

I'm glad you think so. I, for one, am still not sure exactly what the
requirements are for the proposed problem -- or, more to the point,
exactly what the problem is.

···

On Mon, Mar 05, 2007 at 05:34:25PM +0900, Pit Capitain wrote:

Yannick Grams schrieb:
>I have a mathematic problem I need to solve, and it involves finding the
>values of three consecutive numbers, x, y and z. I need to be able to
>find every instance of these from negative one million (-1,000,000) up
>to one million (1,000,000). They must follow the following equations:
>
>x + y + z = 5
>x + y - z = 7
>(x - y)(x - y)(x - y) + (y - z)(y - z)(y - z) = (x - z)(x - z)(x - z)
>
>I'm completely and utterly stumped. I intend on solving this via Ruby,
>as doing it on pen and paper might take a while. :wink: If anyone has any
>suggestions, I'd love to hear them.

Yannick, you don't need Ruby to solve this, just some basic Mathematics.

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
"The first rule of magic is simple. Don't waste your time waving your
hands and hopping when a rock or a club will do." - McCloctnick the Lucid

Absolutely certain. Unless of course this is a trick question. WHich I doubt. But thanks for everyone's help!

···

From: "M. Edward (Ed) Borasky" <znmeb@cesmail.net>
Reply-To: ruby-talk@ruby-lang.org
To: ruby-talk@ruby-lang.org (ruby-talk ML)
Subject: Re: Maths in Ruby
Date: Mon, 5 Mar 2007 18:08:59 +0900

Yannick Grams wrote:

Hello to everyone!

I have a mathematic problem I need to solve, and it involves finding the values of three consecutive numbers, x, y and z. I need to be able to find every instance of these from negative one million (-1,000,000) up to one million (1,000,000). They must follow the following equations:

x + y + z = 5
x + y - z = 7
(x - y)(x - y)(x - y) + (y - z)(y - z)(y - z) = (x - z)(x - z)(x - z)

I'm completely and utterly stumped. I intend on solving this via Ruby, as doing it on pen and paper might take a while. :wink: If anyone has any suggestions, I'd love to hear them.

Well, one of the reasons you might be stumped is that the problem as posed does not appear to have a solution. I punched it in to Maxima:

(%o1) z+y+x=5
(%o2) -z+y+x=7
(%o4) (y-z)^3+(x-y)^3=(x-z)^3
(%i5) solve([%o1,%o2,%o4], [x,y,z]);
(%o5) [[x=-1,y=7,z=-1],[x=3,y=3,z=-1],[x=7,y=-1,z=-1]]

Since one of the equations is a cubic, there are three solutions, and they are all smallish integers. But they are *not* consecutive!

Are you sure about the problem statement?

--
M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC(P)
http://borasky-research.blogspot.com/

If God had meant for carrots to be eaten cooked, He would have given rabbits fire.

_________________________________________________________________
Advertisement: Amazing holiday rentals? http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fwww.ninemsn.realestate.com.au%2Fcgi-bin%2Frsearch%3Fa%3Dbhp%26t%3Dhol%26cu%3DMSN&_t=758874163&_r=HM_Txt_Link_Holiday_Oct06&_m=EXT

Shin-ichiro HARA schrieb:

You can use "algebra" (http://raa.ruby-lang.org/project/algebra/\)
(...)

Thank you for the link, this looks interesting. In your solution, you forgot:

three consecutive numbers, x, y and z

which makes it even simpler to solve.

Regards,
Pit

Daniel Martin wrote:

Now, one thing to hold onto is that when you have

   a**n + b**n = c**n

For any integer n > 2, the only way to get a solution with a, b, and c
integers is to have one of a, b, or c be 0. (*)
  

[snip]

(*) There's not room in this post to prove that here.
  

I'm not even sure there's room to discuss whether the proof actually exists.

<ducking>

···

--
M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC(P)
http://borasky-research.blogspot.com/

If God had meant for carrots to be eaten cooked, He would have given rabbits fire.

You can tell there's no solution for consecutive X, Y, Z just from
looking at that last equation, each side boils down to a different
constant:

Since the numbers are consecutive
y = x + 1
z = y + 1

Then:
x - y = x - (x+1) = -1
y - z = y - (y+1) = -1
x - z = x - (y+1) = x - (x+1+2) = -2

so:

(x-y)(x-y)(x-y) + (y-z)(y-z)(y-z) =
    (-1)(-1)(-1) + (-1)(-1)(-1) =
   -2

but:

(x - z)(x - z)(x - z) =
(-2)(-2)(-2) = -8

···

On 3/5/07, M. Edward (Ed) Borasky <znmeb@cesmail.net> wrote:

Yannick Grams wrote:
> Hello to everyone!
>
> I have a mathematic problem I need to solve, and it involves finding
> the values of three consecutive numbers, x, y and z. I need to be able
> to find every instance of these from negative one million (-1,000,000)
> up to one million (1,000,000). They must follow the following equations:
>
> x + y + z = 5
> x + y - z = 7
> (x - y)(x - y)(x - y) + (y - z)(y - z)(y - z) = (x - z)(x - z)(x - z)
>
> I'm completely and utterly stumped.

Well, one of the reasons you might be stumped is that the problem as
posed does not appear to have a solution. I punched it in to Maxima:

(%o1) z+y+x=5
(%o2) -z+y+x=7
(%o4) (y-z)^3+(x-y)^3=(x-z)^3
(%i5) solve([%o1,%o2,%o4], [x,y,z]);
(%o5) [[x=-1,y=7,z=-1],[x=3,y=3,z=-1],[x=7,y=-1,z=-1]]

Since one of the equations is a cubic, there are three solutions, and
they are all smallish integers. But they are *not* consecutive!

Are you sure about the problem statement?

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

[ snip simple algebra ]

That's why I wasn't sure I understood the question. The OP seems to be
confirming my initial understanding of what was being asked, despite the
fact that the math doesn't work according to that definition of the
problem.

···

On Tue, Mar 06, 2007 at 02:00:23AM +0900, Rick DeNatale wrote:

You can tell there's no solution for consecutive X, Y, Z just from
looking at that last equation, each side boils down to a different
constant:

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
"A script is what you give the actors. A program
is what you give the audience." - Larry Wall

Rick DeNatale wrote:

···

On 3/5/07, M. Edward (Ed) Borasky <znmeb@cesmail.net> wrote:

Yannick Grams wrote:
> Hello to everyone!
>
> I have a mathematic problem I need to solve, and it involves finding
> the values of three consecutive numbers, x, y and z. I need to be able
> to find every instance of these from negative one million (-1,000,000)
> up to one million (1,000,000). They must follow the following equations:
>
> x + y + z = 5
> x + y - z = 7
> (x - y)(x - y)(x - y) + (y - z)(y - z)(y - z) = (x - z)(x - z)(x - z)
>
> I'm completely and utterly stumped.

Well, one of the reasons you might be stumped is that the problem as
posed does not appear to have a solution. I punched it in to Maxima:

(%o1) z+y+x=5
(%o2) -z+y+x=7
(%o4) (y-z)^3+(x-y)^3=(x-z)^3
(%i5) solve([%o1,%o2,%o4], [x,y,z]);
(%o5) [[x=-1,y=7,z=-1],[x=3,y=3,z=-1],[x=7,y=-1,z=-1]]

Since one of the equations is a cubic, there are three solutions, and
they are all smallish integers. But they are *not* consecutive!

Are you sure about the problem statement?

You can tell there's no solution for consecutive X, Y, Z just from
looking at that last equation, each side boils down to a different
constant:

Since the numbers are consecutive
y = x + 1
z = y + 1

Then:
x - y = x - (x+1) = -1
y - z = y - (y+1) = -1
x - z = x - (y+1) = x - (x+1+2) = -2

so:

(x-y)(x-y)(x-y) + (y-z)(y-z)(y-z) =
   (-1)(-1)(-1) + (-1)(-1)(-1) =
  -2

but:

(x - z)(x - z)(x - z) =
(-2)(-2)(-2) = -8

My way is easier -- punch the equations into an algebraic solver. The batteries are dead on my TI-89, and I don't have a Linux interface to it anyhow, so I brought in the big guns -- Maxima. Yeah, I know -- it's easy to solve in your head. I still want to know where the "consecutive" came from.

--
M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC(P)
http://borasky-research.blogspot.com/

If God had meant for carrots to be eaten cooked, He would have given rabbits fire.

You don't need Ruby to solve this. You need any linear algebra program
which can graph a polynomial equation. That means you can solve it
with a $20 calculator or the Grapher program which ships with OS X,
and probably a number of additional ways as well. Although creating a
general-case polynomial equation grapher would be a pretty interesting
way to solve it, it's also definitely overkill.

···

On 3/5/07, Chad Perrin <perrin@apotheon.com> wrote:

On Tue, Mar 06, 2007 at 02:00:23AM +0900, Rick DeNatale wrote:
>
> You can tell there's no solution for consecutive X, Y, Z just from
> looking at that last equation, each side boils down to a different
> constant:

[ snip simple algebra ]

That's why I wasn't sure I understood the question. The OP seems to be
confirming my initial understanding of what was being asked, despite the
fact that the math doesn't work according to that definition of the
problem.

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
"A script is what you give the actors. A program
is what you give the audience." - Larry Wall

--
Giles Bowkett
http://www.gilesgoatboy.org

http://giles.tumblr.com/

I'm not sure why that was a reply to my email.

···

On Tue, Mar 06, 2007 at 08:01:08AM +0900, Giles Bowkett wrote:

You don't need Ruby to solve this. You need any linear algebra program
which can graph a polynomial equation. That means you can solve it
with a $20 calculator or the Grapher program which ships with OS X,
and probably a number of additional ways as well. Although creating a
general-case polynomial equation grapher would be a pretty interesting
way to solve it, it's also definitely overkill.

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
Leon Festinger: "A man with a conviction is a hard man to change. Tell
him you disagree and he turns away. Show him facts and figures and he
questions your sources. Appeal to logic and he fails to see your point."