Zulip Chat Archive

Stream: new members

Topic: Function with cases


Tyler Josephson ⚛️ (Jul 23 2024 at 07:32):

How can I split up the domain of a function when the domain is continuous?

The first one works, the second doesn't.

def choices :   
  | 0 => 55.5
  | 1 => 23
  | _ => 0

def ReLU :   
  | x < 0 => 0
  | 0  x => x

Yakov Pechersky (Jul 23 2024 at 07:33):

Use a if-then-else

Tyler Josephson ⚛️ (Jul 23 2024 at 07:34):

I'm specifically trying to use a functional programming style. I'm guessing this style will be easier for writing proofs about this function? Is it even possible to define a function like this in Lane, without using if-then-else?

Tyler Josephson ⚛️ (Jul 23 2024 at 07:35):

This is motivated by a more complicated example:

def truncated_LJ (d sigma epsilon rcut)
  | d  0 => 0
  | 0 < d  rcut => [math expression]
  | rcut < d => 0

Yakov Pechersky (Jul 23 2024 at 07:37):

The match/equation compiler syntax only matches on explicit values and constructors iiuc

Yakov Pechersky (Jul 23 2024 at 07:38):

You could, in such examples, always use min

Yakov Pechersky (Jul 23 2024 at 07:39):

And your math expression probably is already other defns for the attractive and repulsive terms

Yakov Pechersky (Jul 23 2024 at 07:41):

Also, I don't think we have a expression support for 0 <= d < rcut, but you can use Icc if you want

Tyler Josephson ⚛️ (Jul 23 2024 at 07:46):

Yakov Pechersky said:

And your math expression probably is already other defns for the attractive and repulsive terms

Yep, that's the case. We like to prove that the LJ potential is continuous for d > 0, and a proof that the truncated LJ potential is not continuous for d > 0. You think setting up the truncated one with if-then-else would be the best starting point for that case?

Yakov Pechersky (Jul 23 2024 at 07:50):

If then else is a function underneath: docs#ite

Yakov Pechersky (Jul 23 2024 at 07:51):

So I think any way you formulate it is fine. Another approach would be to define the plain LJ, and then define various truncation functions

Yakov Pechersky (Jul 23 2024 at 07:53):

If you'll be defining a softcore potential, for example


Last updated: May 02 2025 at 03:31 UTC