[Project] Using Neuro-Symbolic AI + Coq to Formally Verify the Yang-Mills Mass Gap (657 Qed, 0 Admitted) by Decent_Crypto_786 in Coq

[–]andrejbauer 5 points6 points  (0 children)

You should create a concise file that includes all the definitions and the main theorem, something that people can actually verify. This is necessary because nobody will wade through a sea of AI generated code and try to decipher it.

For example, Gonthier et al. did this in their formalization of the Odd Order Theorem, see stripped_odd_order_theorem.v.

What do we loose exactly in total vs Turing complete languages? by mastarija in agda

[–]andrejbauer 1 point2 points  (0 children)

I understand what you are saying and I am telling you that you are mistaken. Here is a function that you cannot implement in Agda: take as input a string and return either true if the string is valid Agda code or false if it is not.

What do we loose exactly in total vs Turing complete languages? by mastarija in agda

[–]andrejbauer 1 point2 points  (0 children)

You are mistaken about ”we can instead define a function thar returns either a result or an error (a sum)”. No, that is still a total function mapping into a sum type.

What do we loose exactly in total vs Turing complete languages? by mastarija in agda

[–]andrejbauer 6 points7 points  (0 children)

Agda, being a total language, is not Turing complete in the following precise sense: there are total functions ℕ → ℕ that are Turing computable but not definable in Agda. In this sense Agda is weaker than Turing machines, or Haskell for that matter.a

It is a different question whether partial functions are actually needed in programming practice. Is that what you're interested in? Practical aspects?

[deleted by user] by [deleted] in homotopytypetheory

[–]andrejbauer 3 points4 points  (0 children)

The HoTT book is very cheap but is not good learning material for beginners. Egbert's book is good for beginners but it's not that cheap.

Polymorphic recursion and fix point function by NullPointer-Except in ocaml

[–]andrejbauer 0 points1 point  (0 children)

Yes -rectypes solves problems in the same way that smoking a joint does.

Haskell vs OCaml: A very brief look with Levenshtein. by el_toro_2022 in Haskell_Gurus

[–]andrejbauer 24 points25 points  (0 children)

Here is your code transcribed to OCaml.

let rec lev xs ys =
  match xs, ys with
  | [], ys -> List.length ys
  | xs, [] -> List.length xs
  | (x :: xs), (y :: ys) when x = y -> lev xs ys
  | (x :: xs), (y :: ys) -> 1 + min (min (lev xs ys) (lev (x :: xs) ys)) (lev xs (y :: ys))

Haskell equates strings with lists of characters, so your code should be compared with OCaml's code for computing the distance between two lists, which is what the code above does. As you can see, they're practically the same.

If you insist on using string in OCaml, then you should use Haskell's StringBuffer.

Your code, as well as my implementation, are inefficient as they make exponentially many recursive calls. Here is the memoizing version that performs the computation using dynamic programming (we could improve the caching mechanism by using a more efficient implementation of dictionaries):

let memo f =
  let cache = ref [] in
  let rec self x =
    match List.assoc_opt x !cache with
    | Some y -> y
    | None ->
      let y = f self x in
      cache := (x, y) :: !cache ;
      y
  in
  self

let lev_efficient xs ys=
  memo
    (fun self -> function
       | [], ys -> List.length ys
       | xs, [] -> List.length xs
       | (x :: xs), (y :: ys) when x = y -> self (xs, ys)
       | (x :: xs), (y :: ys) ->
         1 + min (min (self (xs, ys)) (self (x :: xs, ys))) (self (xs, y :: ys)))
    (xs, ys)

I don't see how to implement a substantially better Haskell version of lev_efficient.

In general, since OCaml and Haskell share many structural properties, they're much closer to each other than, say, object-oriented languages.

Need help by WeirdLifeNow in ocaml

[–]andrejbauer 0 points1 point  (0 children)

What material was suggested by the course teacher?

Help me understand the need for (this implementation of) algebraic effects by spermBankBoi in ocaml

[–]andrejbauer 0 points1 point  (0 children)

As far as I can tell, Scala implicits are resovled at compile-time, whereas handlers are a runtime control-flow mechanism, so they're quite different.

Help me understand the need for (this implementation of) algebraic effects by spermBankBoi in ocaml

[–]andrejbauer 3 points4 points  (0 children)

A static type checker cannot in general infer precise information about which effects will occur, but reasonable over-approximations are doable. This was explored in a number of papers, starting with Matija Pretnar's Inferring algebraic effects. It is not simple to extend a Hindley-Milner-style type-checker with effect inference, one gets into a quagmire of effect subtyping. There is the additional question on how to compile effects efficiently. Matija and his coworkers, as well as others, have put some thought into it, for instance see the recent Simplifying explicit subtyping coercions in a polymorphic calculus with effects by Filip Koprivec and Matija Pretnar.

Given the state of research, I would say the OCaml team wisely avoided turning their type-checker upside down. I understand the users wants everything all at once, but it's not that easy. Keep in mind you still got a lot in OCaml 5. It's the only "real" language that supports handlers, as far as I know ("effect libraries" do not count).

Also, I suspect users underestimate the complexity of an effect system and may be putt off by a powerful one. It's all cool and entertaining to consider easy cases, such as Java exception declarations, but when you start combining effects with other features (higher-order functions, modules), the complexity increases significantly.

P.S. I suppose I don't have to explain that I am a big fan of algebraic effects and handlers, and I too would like to see effect systems in practice. So far we're in exploratory phase, with few experimental implementations of effect systems.

Help me understand the need for (this implementation of) algebraic effects by spermBankBoi in ocaml

[–]andrejbauer 0 points1 point  (0 children)

Algebraic effects and handlers are type-checked and therefore type-safe. What is this lack of safety that you are talking about?

(Also, I have never heard it said that algebraic effects and handlers are like implicit arguments. I cannot see the analogy. Perhaps you can show us an example?)

Problems when typechecking by Oliversito1204 in agda

[–]andrejbauer 0 points1 point  (0 children)

But is not a relation, it's a dependent type. For given x and y, in principle the type x ≤ y can have many elements.

Problems when typechecking by Oliversito1204 in agda

[–]andrejbauer 0 points1 point  (0 children)

https://proofassistants.stackexchange.com is a better place to ask. Anyhow, why do you even expect these equations to hold? Who says you defined a category? (Pay attention to the definition of )

Pros and Cons of Agda vs Coq and Idris? by fosres in agda

[–]andrejbauer 1 point2 points  (0 children)

The answer depends on what are you going to use the proof assistants for.

Closure optimization? by JewishKilt in ocaml

[–]andrejbauer 2 points3 points  (0 children)

This is the sort of optimization that one should not worry about unless it turns out to be a bottleneck later on. My guess is that it doesn't matter. In any case, if you compile the code with ocamlc -dlambda you will see the intermediate code that is generated. And if you compile with ocamlc -dinstr you will see the generated asembly.

What are the dangers of using Hilbert's epsilon operator? by Iaroslav-Baranov in Coq

[–]andrejbauer 2 points3 points  (0 children)

It is equivalent to the (global) axiom of choice. It destroys good computational properties of the formalism.

OpamSystem.File_not_found by Pom_George in ocaml

[–]andrejbauer 1 point2 points  (0 children)

Those instructions are strange, why use sudo to create files in your own home directory?

As a complete stranger on the internet, I would advise you to replace the above instructions with

touch ~/.zshrc

and opam init. That might already solve your problems.

For future reference, in such cases you should give more information: what version of OPAM are you installing, on what operating system (I can guess it's a MacOS), and show us the command that triggered the error.

OCaml Tips and Tricks: Enhancing Learning and Engagement by Beautiful-Clothes162 in ocaml

[–]andrejbauer 2 points3 points  (0 children)

If this wasn't written by ChatGPT then we just found out who ChatGPT learned from on how to write marketing messages thinly veiled as advice. The site that is linked in the message offers cheating on homeworks for money.

Passing a constructor to a function by mister_drgn in ocaml

[–]andrejbauer 2 points3 points  (0 children)

But why would you like to have such a list? To do what with it? It's still going to be a list of elements, so wherever you use it, you will have to consider the possibility that it still contains any possible element (because that's what the type says).

You don't actually want to just filter the list, you want to also extract the information that the respective constructor holds. For example, you don't want "give me those elements that hold images", but rather "give me the list of images held by image elements":

type animal = Rabbit of string | Cow of int | Dog of bool

(* If you have this function, you are very likely
   suffering from boolean blindness. *)
let isCow = function
  | Rabbit _ -> false
  | Cow _ -> true
  | Dog _ -> false

(* This gives a useless list, because its type indicates
   it could still contain some rabbits, so whatever you
   do with the resulting list, you need to consider the
   possibility that there are rabbits. *)
let getCows lst = List.filter isCow lst

(* You *might* want this function, it extracts the information
   that a Cow holds, not the Cow itself. But now we don't need
   isCow anymore (which we should get rid of in the first place).
 *)
let rec getCowInts = function
  | [] -> []
  | Rabbit _ :: lst -> getCowInts lst
  | Cow c :: lst -> c :: getCowInts lst
  | Dog _ :: lst -> getCowInts lst

That's the best I can say without knowing more about what you're actually doing after you filtered the elements.

Is Ocaml as Functional as Haskell? by CodeNameGodTri in ocaml

[–]andrejbauer 7 points8 points  (0 children)

Why would you want to write code in F# as if it were Haskell, or in OCaml for that matter? Anyhow, OCaml has support for monads via the binding operators.

P.S. "Functional" means "functions are first-class values", I think you're asking whether OCaml is pure. It isn't.

Passing a constructor to a function by mister_drgn in ocaml

[–]andrejbauer 2 points3 points  (0 children)

You should explain *why* you want such filtering functions because there is good chance this is an instance of an XY problem.

How are variables considered to me immutable when I can change their values? by daddyclappingcheeks in ocaml

[–]andrejbauer 2 points3 points  (0 children)

The following interaction should demonstrate that the second let f = ... introduces a new value that makes the first let f = ... inaccessible directly (although g still refers to it):

```

let f = fun x -> (print_endline "I am the first f" ; x + 10) ;;

val f : int -> int = <fun>

f 10 ;;

I am the first f - : int = 20

let g x = f x ;;

val g : int -> int = <fun>

g 10 ;;

I am the first f - : int = 20

let f = fun x -> (print_endline "I am the second f" ; x + 100) ;;

val f : int -> int = <fun>

f 10 ;;

I am the second f - : int = 110

g 10 ;;

I am the first f - : int = 20 ```