[racket-users] Interpolating Polynomial in Newton Form

2015-11-10 Thread Dave Yrueta
Hi All —

Given a list of constants (a0, a1… an) and a list of x-values (x0, x1,….xn), I 
want to write a function in Racket that produces the function p(x) = a0 + a1(x 
- x0) + a2(x - x0)(x - x1) + a3(x - x0)(x - x1) (x - x2) + ….+ an(x - x0)(x - 
x1)…(x - xn), or the interpolating polynomial in Newton form.   My 
understanding of functions that produce functions is limited to what’s in HtDP, 
and this example (I think) goes beyond that.  Any tips or advice would be much 
appreciated!

Cheers, 
Dave Yrueta

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Interpolating Polynomial in Newton Form

2015-11-07 Thread Dave Yrueta
Yes, I can see at least two significant errors in my description.  The first is 
in the sequence definitions.  They should be

 list of constants (a0, a1… an) and a list of x-values (x0, x1,….x(n-1)) 
Similarly, the def of p(x) should read

p(x) = a0 + a1(x - x0) + a2(x - x0)(x - x1) + a3(x - x0)(x - x1) (x - x2) + ….+ 
an(x - x0)(x - x1)…(x - x(n-1)), not

p(x) = a0 + a1(x - x0) + a2(x - x0)(x - x1) + a3(x - x0)(x - x1) (x - x2) + ….+ 
an(x - x0)(x - x1)…(x - xn).  Thank you for correcting me! 

Here are some examples:

Data Defs:
x is a real number
lox is (listof x)

;;NewtonPx : (lox lox -> (x -> x)
;; accepts two list of numbers, returns a function equivalent to the 
interpolating polynomial in Netwton form that accepts a number and returns a 
number
(define (NewtonPx lox loa) ….)

Ex #1
(define lox1 ‘(1 2))
(define loa1 (4 5 6))

(NewtonPx lox1 loa1) -> (lambda (x) (+ 4 (* 5(- x 1)) (* 6 (- x 1) (- x 2 
and ( (NewtonPx lox1 loa1) 2) ->  9

Ex. #2
(define lox2 '(4 2 7))
(define loa2 ‘(9 8 6 3))

(NewtonPx lox1 loa1) -> (lambda (x) (+ 9 (* 8 (- x 4)) (* 6 (- x 4) (- x 2)) (* 
3 (- x 4) (- x 2) (- x 7 and  ( (NewtonPx lox2 loa2) 2) -> -7

I realize now that the function I’m after doesn’t require anything as fancy as 
macros — judicious use of loops should do.  Still, I’m wondering if there is a 
macro-based solution that I can use to study as an entry point to this subject. 
 

Cheers, 
DY

 










> On Nov 6, 2015, at 6:43 PM, Matthias Felleisen  wrote:
> 
> 
>> On Nov 6, 2015, at 9:07 PM, dyrueta  wrote:
>> 
>> Hi All --
>> 
>> I'm hoping the answer to the question below will serve as an intro to 
>> macros, a subject I've been interested in for awhile but haven't had time to 
>> look into much.  Here goes, fingers crossed:
>> 
>> Given a list of constants (a0, a1… an) and a list of x-values (x0, x1,….xn), 
>> I want to design a function in Racket that produces an interpolating 
>> polynomial in Newton form, or p(x) = a0 + a1(x - x0) + a2(x - x0)(x - x1) + 
>> a3(x - x0)(x - x1) (x - x2) + ….+ an(x - x0)(x - x1)…(x - xn).   My 
>> understanding of functions that produce functions is limited to what’s in 
>> HtDP, and this example (I think) goes beyond that (and hopefully into 
>> macros).   
>> 
>> Any tips or advice would be much appreciated!
> 
> 
> Let’s assume I don’t know what you’re talking about. But we do know together 
> that HtDP requests examples for problems that you’re not quite familiar with. 
> So we work through 3 instances of this problem: 
> 
> #lang racket
> 
> (require plot)
> 
> (define ((make-p-0 a0 a1) x0 x1)
>  (define (p x)
>(+ a0
>   (* a1 (- x x0
>  p)
> 
> [plot (function ((make-p-0 1 2) 3 4)) #:x-min -10 #:x-max +10]
> 
> (define ((make-p-1 a0 a1 a2) x0 x1 x2)
>  (define (p x)
>(+ a0
>   (* a1 (- x x0))
>   (* a2 (- x x0) (- x x1
>  p)
> 
> [plot (function ((make-p-1 1 2 3) 3 4 5)) #:x-min -10 #:x-max +10]
> 
> (define ((make-p-2 a0 a1 a2 a3) x0 x1 x2 x3)
>  (define (p x)
>(+ a0
>   (* a1 (- x x0))
>   (* a2 (- x x0) (- x x1))
>   (* a3 (- x x0) (- x x1) (- x x2
>  p)
> 
> [plot (function ((make-p-2 1 2 3 4) 3 4 5 6)) #:x-min -10 #:x-max +10]
> 
> I threw in the plots for fun. Now I think one of two things is wrong: 
> 
> — your description (making the a-sequence as long as the x-sequence) 
> — or my understanding of your description. 
> 
> Correct me.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket] Problems with Plot

2013-10-30 Thread Dave Yrueta
Please ignore previous post.  Figured out the problem. My bad. 
On Oct 30, 2013, at 9:47 AM, Dave Yrueta  wrote:

> Hi All --
> 
> I pulled this from the Docs on plot --
> 
> (require plot)
> 
> (plot (function (λ (x) (sin (* 4 x))) -1 1)
>#:x-min -1.5 #:x-max 1.5 #:y-min -1.5 #:y-max 1.5)
> 
> -- ran it in Dr. Racket, and received the following error: "#%datum: keyword 
> used as an expression" with "#:x-min" highlighted in pink.   I've run plot 
> functions before and never had a problem.  Am using Racket version 5.3.6. 
> 
> What am I doing wrong? Apologies in advance if I'm making an obvious mistake. 
> 
> Thanks!
> Dave
> 
> 



  Racket Users list:
  http://lists.racket-lang.org/users


[racket] Problems with Plot

2013-10-30 Thread Dave Yrueta
Hi All --

I pulled this from the Docs on plot --

(require plot)

 (plot (function (λ (x) (sin (* 4 x))) -1 1)
#:x-min -1.5 #:x-max 1.5 #:y-min -1.5 #:y-max 1.5)

-- ran it in Dr. Racket, and received the following error: "#%datum: keyword 
used as an expression" with "#:x-min" highlighted in pink.   I've run plot 
functions before and never had a problem.  Am using Racket version 5.3.6. 

What am I doing wrong? Apologies in advance if I'm making an obvious mistake. 

Thanks!
Dave




  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Scribble and/or Latex?

2013-08-30 Thread Dave Yrueta
I'm a bit pressed for time, so I'll have to postpone learning Scribble for a 
later date.  In the meantime, thanks for the reply!
On Aug 30, 2013, at 10:23 AM, "William J. Bowman"  
wrote:

> Dave,
> 
> Scribble does not have great support for typesetting math. I would love
> to use Scribble for all my typesetting needs. However, I have to
> fall back to Latex whenever I need to typeset math.
> 
> There are ways to insert Latex in Scribble. Others on the list might
> have more information about how to do that. 
> 
> If you have the time, I recommend learning both. Scribble and Latex have
> a lot of similarities, so learning them side-by-side can even be useful. 
> You'll also discover the relative strengths and weaknesses of each.
> 
> William Bowman
> 
> On Fri, Aug 30, 2013 at 09:36:30AM -0700, Dave Yrueta wrote:
>> Hi All --
>> 
>> I'm an apprenticing high school math teacher looking for a documentation 
>> tool for use in preparing lesson plans and class presentations. I've been 
>> advised to use Latex.  But as a former HtDP'er, I've been looking for an 
>> excuse to get back into Racket, and I thought learning Scribble might be a 
>> good route to take.  I've poked through the docs a bit, and can't find any 
>> reference on math typesetting.  Can that be done in Scribble?  Or is 
>> Scribble not the right tool, and should I commit my learning efforts to 
>> Latex?  Or both?
>> 
>> Thanks!
>> Dave Yrueta
>> 
>> 
>> 
>> 
>>  Racket Users list:
>>  http://lists.racket-lang.org/users



  Racket Users list:
  http://lists.racket-lang.org/users


[racket] Scribble and/or Latex?

2013-08-30 Thread Dave Yrueta
Hi All --

I'm an apprenticing high school math teacher looking for a documentation tool 
for use in preparing lesson plans and class presentations. I've been advised to 
use Latex.  But as a former HtDP'er, I've been looking for an excuse to get 
back into Racket, and I thought learning Scribble might be a good route to 
take.  I've poked through the docs a bit, and can't find any reference on math 
typesetting.  Can that be done in Scribble?  Or is Scribble not the right tool, 
and should I commit my learning efforts to Latex?  Or both?

Thanks!
Dave Yrueta




  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] arrangements exercise

2012-07-01 Thread Dave Yrueta
I should have been more explicit:  "ensuring the function design conforms to 
its contract" means testing it in the manner demonstrated by Matthias. 
"Check-expect" is your friend :). 
On Jul 1, 2012, at 4:12 PM, Matthias Felleisen wrote:

> 
> On Jul 1, 2012, at 4:17 PM, Sean Kemplay wrote:
> 
>> Looking back, I am wondering if my solution is a bit of a cheat - 
>> specifically :
>> 
>> (define (insert-everwhere/in-one-word s word)
>> (make-words s word word))
> 
> 
> It's not a cheat, it's wrong. I did you a favor and worked out a failing test 
> case. See below. 
> 
> 
> On Jul 1, 2012, at 6:46 PM, Dave Yrueta wrote:
> 
>> Try working through this exercise by systematically applying the design 
>> recipe.  That is, take the time to make your data definitions explicit, and 
>> begin the definition of each helper function with a contract, purpose 
>> statement, and template.  In my opinion, more than any other exercise in 
>> HtDP, the solution to this exercise relies on paying very close attention to 
>> how the data definitions, function contracts and function templates 
>> interact. If you allow the data definitions to shape the function templates, 
>> and are rigorous about ensuring the function designs conform to their 
>> contracts, the solution should fall into place.  
> 
> 
> The above is the best advice the list can give you. -- Matthias
> 
> 
> 
> 
> ;; World  = [Listof Letter] ;; see chapter IV
> ;; Letter = Symbol 
> 
> ;; Letter Word -> [Listof Word]
> ;; the function says: insert _s_ in all positions in _word_
> 
> (check-expect (insert-everwhere/in-one-word 'a '(w o)) 
>  '((a w o) (w a o) (w o a)))
> (check-expect (insert-everwhere/in-one-word 'a '(w w o)) 
>  '((a w w o) (w a w o) (w w a o) (w w o a)))
> 
> (define (insert-everwhere/in-one-word s word)
> (make-words s word word))
> 
> ;; Letter Word Word -> [Listof Word]
> ;; insert _s_ in all positions in _word2_ using _word1_ as a list of 
> insertion points 
> ;; intended usage: (make-words letter word word) i.e. word1 = word2 initially 
> 
> (check-expect (make-words 'a '(w o) '(w o)) '((a w o) (w a o) (w o a)))
> (check-expect (make-words 'a '(w w o) '(w w o)) '((a w w o) (w a w o) (w w a 
> o) (w w o a)))
> 
> (define (make-words s word1 word2)
> (cond
>   [(empty? word1) (cons (append word2 (cons s empty)) empty)]
>   [else (cons (insert-symbol s (first word1) word2) (make-words s (cdr word1) 
> word2))]))
> 
> 
> ;; Letter Letter Word -> Word 
> ;; add _new_ in front of each occurrence of _old_ in _word_ 
> 
> (check-expect (insert-symbol 'a 'b '(c d e)) '(c d e)) ;; running in BSL with 
> ..
> (check-expect (insert-symbol 'a 'b '(b o b)) '(a b o a b)) 
> 
> (define (insert-symbol new old word)
> (cond
>   [(empty? word) empty]
>   [(symbol=? (first word) old) (cons new (cons old (insert-symbol new old 
> (rest word]
>   [else (cons (first word) (insert-symbol new old (rest word)))]))
> 
> 
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users



  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] arrangements exercise

2012-07-01 Thread Dave Yrueta
Hi Sean --

Don't know if it is a "cheat," but I can tell you from experience your solution 
diverges from the preferred one at the "insert-everywhere/in-one-word" 
function. 

Try working through this exercise by systematically applying the design recipe. 
 That is, take the time to make your data definitions explicit, and begin the 
definition of each helper function with a contract, purpose statement, and 
template.  In my opinion, more than any other exercise in HtDP, the solution to 
this exercise relies on paying very close attention to how the data 
definitions, function contracts and function templates interact.  If you allow 
the data definitions to shape the function templates, and are rigorous about 
ensuring the function designs conform to their contracts, the solution should 
fall into place.  

Good luck!

Dave Yrueta


On Jul 1, 2012, at 1:17 PM, Sean Kemplay wrote:

> Hello,
> 
> I am working through HTDP and have re-visited the arrangements
> exercise from chapter 12.
> 
> Looking back, I am wondering if my solution is a bit of a cheat - 
> specifically :
> 
> (define (insert-everwhere/in-one-word s word)
>  (make-words s word word))
> 
> Here is the entire solution - is there a better way I should be doing this?
> 
> (define (insert-symbol new old word)
>  (cond
>[(empty? word) empty]
>[(symbol=? (first word) old) (cons new (cons old (insert-symbol
> new old (rest word]
>[else (cons (first word) (insert-symbol new old (rest word)))]))
> 
> (define (make-words s word1 word2)
>  (cond
>[(empty? word1) (cons (append word2 (cons s empty)) empty)]
>[else (cons (insert-symbol s (first word1) word2) (make-words s
> (cdr word1) word2))]))
> 
> 
> (define (insert-everwhere/in-one-word s word)
>  (make-words s word word))
> 
> 
> (define (insert-everywhere/in-all-words s low)
>  (cond
>[(empty? low) empty]
>[else (append (insert-everwhere/in-one-word s (first low))
> (insert-everywhere/in-all-words s (rest low)))]))
> 
> 
> (define (arrangements a-word)
>  (cond
>[(empty? a-word) (cons empty empty)]
>[else (insert-everywhere/in-all-words (first a-word)
>(arrangements (rest a-word)))]))
> 
> Any feedback welcome,
> 
> Thanks,
> Sean Kemplay
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users



  Racket Users list:
  http://lists.racket-lang.org/users


[racket] With Best Regards

2011-10-27 Thread Dave Yrueta
 You've no idea how cool is this http://www.40ddd.com/inf.php Enjoy!
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


[racket] Support for MS SQL in Racket?

2011-02-05 Thread Dave Yrueta
Hi All --

I'm an HtDP veteran but otherwise a newbie to the world of commercial
programming.  Recently, I fell into a contract job which consists of moving
data from one MS SQL Server database to another, and using SQL scripts to
"cleanse" the data.  The scripts are brutally repetitive, and seem like they
could benefit from some "cleansing" themselves by, among other things, the
judicious application of the abstraction technique learned in HtDP.  My
question is, and I don't even know if I'm saying this right, is there anyway
to write MS SQL Server scripts in Racket that work in a MS SQL server
environment?

Thanks!
Dave Yrueta
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] HTDP Chapter 4

2011-01-29 Thread Dave Yrueta
Hi Jeremy --

Please post an example of the code which is returning an error.

On Thu, Jan 27, 2011 at 11:12 PM, Jeremy Duenas  wrote:

> I am trying to work on the examples in Chapter 4 of HTDP where they are
> talking about Boolean expressions, and every time I try to create a function
> to do this(i.e. example 4.2.1) I keep getting errors. Even if I input the
> functions given to me in the book I get errors. Is there something that I
> need to do to make Boolean arguments work?!?!? I don't understand why even
> the book examples are giving me errors.
>
> Jeremy D. Duenas
> 714.864.9686
>
>
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users