Zulip Chat Archive

Stream: general

Topic: implementation of evaluation of a real-valued logic


Alexandre Rademaker (Dec 17 2020 at 20:50):

I am trying to implement a real-valued logic starting from the definition of the language and a simple eval function. Formulas are propositional logic formulas. Propositions are interpreted into interval of real values.

import data.real.basic

structure interval :=
 mk :: (l : ) (h : )

inductive Expr : Type
  | atom : interval  Expr
  | neg  : Expr  Expr
  | and  : Expr  Expr  Expr
  |  or  : Expr  Expr  Expr

open Expr
variables a b : interval

#check and (or (atom a) (atom b)) (or (atom a) (atom b))

def eval : Expr  interval
 | (atom i) := i
 | (and e1 e2) := interval.mk ((eval e1).h + (eval e2).h) ((eval e1).l + (eval e2).l)
 | _ := interval.mk 0 0

def e1 : Expr := atom (interval.mk 0 1)
#reduce eval (and e1 e1)

But I got a timeout in the reduce! Why?

Alexandre Rademaker (Dec 17 2020 at 20:51):

The eval of and is not final, just testing the ideas.

Kevin Buzzard (Dec 17 2020 at 21:13):

If you try #eval instead of #reduce you'll see why you're getting a timeout!

Kevin Buzzard (Dec 17 2020 at 21:15):

Even #reduce (0 : ℝ) times out.

Alexandre Rademaker (Dec 17 2020 at 21:16):

Hum, so cant I play with reals in Lean?

Kevin Buzzard (Dec 17 2020 at 21:17):

We play with them all the time! We just don't try to evaluate them :-)

Rob Lewis (Dec 17 2020 at 21:30):

Here's how I would do this, using rat and #eval instead of real and #reduce:

import data.rat

structure interval :=
 mk :: (l : ) (h : )

instance : has_repr interval :=
λ i, match i with
| l, h := sformat!"⟨{l}, {h}⟩"
end

inductive Expr : Type
  | atom : interval  Expr
  | neg  : Expr  Expr
  | and  : Expr  Expr  Expr
  |  or  : Expr  Expr  Expr

open Expr
variables a b : interval

#check and (or (atom a) (atom b)) (or (atom a) (atom b))

def eval : Expr  interval
 | (atom i) := i
 | (and e1 e2) := interval.mk ((eval e1).h + (eval e2).h) ((eval e1).l + (eval e2).l)
 | _ := interval.mk 0 0

def e1 : Expr := atom (interval.mk 0 1)

#eval eval (and e1 e1)

Adam Topaz (Dec 17 2020 at 21:34):

Unfortunately, for continuous logic the quantifiers are inf and sup, so one must really use real numbers :)
I should add that I think it would be VERY interesting to formalize stuff around continuous logic!

Alexandre Rademaker (Dec 17 2020 at 23:53):

A stupid question: what is the problema with reals? Why can't we evaluate them? does Lean 4 will solve this limitation?

Reid Barton (Dec 18 2020 at 00:00):

Well they do go on forever


Last updated: Dec 20 2023 at 11:08 UTC