Zulip Chat Archive

Stream: maths

Topic: define polynomials recursively


Michael Nestor (Jan 10 2023 at 21:50):

I know there is a standard polynomial library, but for self-instructive purposes I am trying to define them like so:

def polynomial (f:   ) :
  ( c: , f = λ x: , c)  -- f is constant, or ...
  ( g:   ,  c: , (polynomial g)  f = λ x: , x * g(x) + c)

with error unknown identifier 'polynomial'

Eric Wieser (Jan 10 2023 at 22:30):

Did you mean to write := instead of :?

Eric Wieser (Jan 10 2023 at 22:30):

That says "let polynomial be a proof of the fact that ..."

Eric Wieser (Jan 10 2023 at 22:31):

But I expect you meant def polynomial (f: ℝ → ℝ) : Prop :=, "let polynomial be a proposition, defined as ..."

Michael Nestor (Jan 10 2023 at 22:34):

yes, whoops. but the error persists

Junyan Xu (Jan 10 2023 at 22:55):

You want inductive

import data.real.basic
inductive is_polynomial : (  )  Prop
| const (c : ) : is_polynomial (λ x, c)
| X_mul_add_C (g) (c : ) : is_polynomial g  is_polynomial (λ x, x * g x + c)

Trebor Huang (Jan 11 2023 at 11:29):

Recursive types are different from inductive types, and you mean the latter this time.

Trebor Huang (Jan 11 2023 at 11:31):

And there is a third thing called "types defined by recursion", which is also called recursive types sometimes, which is what your initial definition uses. However, your definition uses arbitrary recursion, which leads to inconsistency. You would have to do recursion on some decreasing argument.

Johan Commelin (Jan 11 2023 at 11:31):

@Michael Nestor There is also a mathematical issue with this definition: you've defined "polynomial function". But a polynomial is not a function. Over finite rings, you only have finitely many polynomial functions, but infinitely many polynomials.


Last updated: Dec 20 2023 at 11:08 UTC