Scala 3, 387 371 bytes
A port of @Ajax1234's Python answer in scala.
Saved 16 bytes thanks to @ceilingcat
Golfed version (371 bytes). Attempt This Online!
def F(v:List[Int])=f(v).contains(0)
def f(v:List[Int]):LazyList[Int]={val k:LazyList[List[Int]]=LazyList(v)++(for{i<-(0 to v.size-1).to(LazyList);j<-(i+1 to v.size).to(LazyList);if j>2&j-i<v.size;t<-f(v.slice(i,j))}yield v.slice(0,i)++List(t)++v.drop(j));k.flatMap{i=>if(i.size==1)LazyList(i(0))else{LazyList(i(0),i(1),i(0)*i(1))++(i.drop(2):+(i(0)+i(1))):+(i(0)-i(1))}}}
Ungolfed version. Attempt This Online!
object Main {
def main(args: Array[String]): Unit = {
println(F(List(1, 1)))
println(F(List(1, 1, 2)))
println(F(List(2, 3, 5)))
//println(F(List(2, 3, 6)))
println(F(List(1, 2, 3, 4)))
println(F(List(1, 1, 3, 4)))
println(F(List(2, 2, 3, 4)))
println(F(List(1, 1, 2, 2, 2)))
println("-" * 20)
println(F(List(1)))
println(F(List(1, 2)))
println(F(List(2, 3, 4)))
//println(F(List(1, 3, 3, 4)))
//println(F(List(2, 2, 2, 2, 2)))
}
def F(v: List[Int]): Boolean = f(v).contains(0)
def f(v: List[Int]): LazyList[Int] = {
val k: LazyList[List[Int]] = LazyList(v) ++ (for {
i <- (0 until v.length).to(LazyList)
j <- (i + 1 to v.length).to(LazyList)
if j - 1 > 1 && j - i < v.length
t <- f(v.slice(i, j))
} yield v.slice(0, i) ++ List(t) ++ v.drop(j))
k.flatMap { i =>
if (i.length == 1) LazyList(i.head)
else {
val V = i.head * i(1)
LazyList(i.head, i(1), V) ++ (i.drop(2) :+ (i.head + i(1))) :+ (i.head - i(1))
}
}
}
}
[1,1,2,2,2]
can be solved with1+1-2+2-2
without parens. A better example might be[1,2,3,9] -> (1+2)*3-9
. \$\endgroup\$