From: David Steuber
Subject: Trying to solve equations in Lisp
Date: 
Message-ID: <87smae5udi.fsf@david-steuber.com>
I'm trying to solve a problem in Lisp and I have gotten stuck.

I have two undefined functions, f(t) & g(t), that double at different
rates.  What I need to find is a way to write g(h) where h is the
result of taking the inverse of f(t).  I need a general solution
because I have to experiment to see how fast g(t) should double
compared to f(t).

In slightly more concrete terms, what I think I need is something like
this:

(let ((m 1707)
      (n 6816)) ; n is 4*m
  (expt x (log m y)) => 512
  (expt x (log n y)) => 1024

I need x & y and the flexibility to change the spacing of m & n to get
the results that I want.  I'm rusty enough on logarithms as it is
without tossing simultaneous equations into the mix.  I'm not even
sure I'm on the right track looking at logs.

Making y 4 and x 2 didn't do it.

I'll keep plugging away at this.  TIA for any help.

-- 
An ideal world is left as an excercise to the reader.
   --- Paul Graham, On Lisp 8.1

From: David Steuber
Subject: Re: Trying to solve equations in Lisp
Date: 
Message-ID: <87r7pye7qg.fsf@david-steuber.com>
David Steuber <·····@david-steuber.com> writes:

> (let ((m 1707)
>       (n 6816)) ; n is 4*m
>   (expt x (log m y)) => 512
>   (expt x (log n y)) => 1024

After some plugging away, I set two sides equal to the other to get
down to one unknown and got stuck at this point:

(expt n (* 9/10 (log 6816 n))) => 1707

If I can get n, then I can go back for x.  I need more grease...

Assuming I didn't make a mistake along the way which is all too possible.

-- 
An ideal world is left as an excercise to the reader.
   --- Paul Graham, On Lisp 8.1
From: David Steuber
Subject: Re: Trying to solve equations in Lisp
Date: 
Message-ID: <87zn4mmm9s.fsf@david-steuber.com>
David Steuber <·····@david-steuber.com> writes:

> David Steuber <·····@david-steuber.com> writes:
> 
> > (let ((m 1707)
> >       (n 6816)) ; n is 4*m
> >   (expt x (log m y)) => 512
> >   (expt x (log n y)) => 1024
> 
> After some plugging away, I set two sides equal to the other to get
> down to one unknown and got stuck at this point:
> 
> (expt n (* 9/10 (log 6816 n))) => 1707
> 
> If I can get n, then I can go back for x.  I need more grease...
> 
> Assuming I didn't make a mistake along the way which is all too possible.

Nuts.  I did:

CL-USER> (expt 2 (* 9/10 (log 6816 2)))
2819.5298
CL-USER> (exp (* 9/10 (log 6816)))
2819.5298

Back to kindergarten.

-- 
An ideal world is left as an excercise to the reader.
   --- Paul Graham, On Lisp 8.1
From: Kalle Olavi Niemitalo
Subject: Re: Trying to solve equations in Lisp
Date: 
Message-ID: <87wtz8a4ah.fsf@Astalo.kon.iki.fi>
David Steuber <·····@david-steuber.com> writes:

> I have two undefined functions, f(t) & g(t), that double at different
> rates.

Do you mean the functions are something like this:

  (defparameter *f-bias* 4)
  (defparameter *f-base* (expt 2 1/10))

  ;; not using T as a parameter name
  (defun f (x) (expt *f-base* (+ x *f-bias*)))

  (f -4)        ; => 1
  (f 0)         ; => 1.3195076
  (f 6)         ; => 1.9999988

> What I need to find is a way to write g(h) where h is the
> result of taking the inverse of f(t).

  (defun h (y) (- (log y *f-base*) *f-bias*))

  (h (f 12))    ; => 11.999997

> (let ((m 1707)
>       (n 6816)) ; n is 4*m
>   (expt x (log m y)) => 512
>   (expt x (log n y)) => 1024

You later wrote this was not correct.  If you want

  (f 1707) =>  512
  (f 6816) => 1024

this can be achieved with:

  (defparameter *f-base* (expt (/ 1024 512) (/ (- 6816 1707))))
  (defparameter *f-bias* (- (log 512 *f-base*) 1707))

  (f 1707)      ; =>  512.00006
  (f 6816)      ; => 1023.89124

I used SINGLE-FLOATs; more accurate results are possible.