Puzzle
3 minute read

Ponder This Challenge - December 2019 - Approximating absolute value

Approximating absolute value.
Find an expression with no more than 15 operations (+, -, *, /) that approximates the absolute value function on the interval [-1,1] with an MSE (mean squared error) of no more than 0.0001.

For example, (x+1)/2 can be computed with only two operations and has an MSE of 1/6.

Bonus '*' for the best approximation (currently 1.803E-7).

Solution

  • The problem is quite old, as you can see in papers from more than a century ago.

    The best solution we got with 15 operations is 0.3558537121*x*x+0.8756099212-0.342263605/(x*x+0.521238162)-0.0058778217/(x*x+0.03522466135) -0.00006182761867/(x*x+0.00131063), which results in an MSE of ~1.8033e-07.

    The solution with the fewest number of operations (only 7) is 0.497+0.561*x*x-0.0467/(0.1025+x*x), which results in an MSE of ~7.8e-05.

    A nice solution we got from Aviv Nisgav computes the sqrt(x*x) by using the Newton-Raphson method with an initial guess of 0.3 and 3 iterations. After rearranging the terms, we get

    0.1875-0.0135/(0.09+x^2)+x^2(0.4166667+0.6/(0.45+x^2-0.0324/(0.09+x^2))), which results in an MSE of ~3.7e-05.

Solvers

  • *Oleg Vlasii (04/12/2019 02:56 PM IDT)
  • James Dow Allen (04/12/2019 06:22 PM IDT)
  • Guillermo Wildschut (04/12/2019 10:27 PM IDT)
  • Albert Stadler (04/12/2019 11:01 PM IDT)
  • Walter Sebastian Gisler (05/12/2019 04:30 PM IDT)
  • Deane Stewart (05/12/2019 07:52 PM IDT)
  • Benjamin Buhrow (05/12/2019 08:01 PM IDT)
  • *Arthur Vause (05/12/2019 04:01 PM IDT)
  • Daniel Hammack (06/12/2019 01:05 AM IDT)
  • Muralidhar Seshadri (06/12/2019 02:03 AM IDT)
  • Sanandan Swaminathan (06/12/2019 05:28 AM IDT)
  • Michael J. Swart (06/12/2019 04:27 PM IDT)
  • Kurt Foster (06/12/2019 06:38 PM IDT)
  • Hugo Pfoertner (07/12/2019 03:18 AM IDT)
  • Lorenz Reichel (07/12/2019 10:09AM IDT)
  • Janne Junnila (07/12/2019 06:36 PM IDT)
  • Deron Stewart (07/12/2019 06:58 PM IDT)
  • Matthias Baur (08/12/2019 03:03 AM IDT)
  • Eden Saig (08/12/2019 11:48 PM IDT)
  • Michael Liepelt (09/12/2019 04:28 PM IDT)
  • Hannes Planatscher (09/12/2019 06:47 PM IDT)
  • *Alper Halbutogullari (09/12/2019 11:13 PM IDT)
  • Fletcher Dostie (10/12/2019 01:48 AM IDT)
  • *Bertram Felgenhauer (10/12/2019 08:14 AM IDT)
  • John Reid (10/12/2019 11:57 AM IDT)
  • Lorenzo Gianferrari Pini (10/12/2019 02:30 PM IDT)
  • Peter Huggins (11/12/2019 07:48 PM IDT)
  • Thomas Huet (11/12/2019 08:19 PM IDT)
  • *Florian Fischer (12/12/2019 12:55 AM IDT)
  • *Andreas Stiller (12/12/2019 02:27 AM IDT)
  • Marco Bellocchi (13/12/2019 02:46 AM IDT)
  • Maksym Voznyy (13/12/2019 05:17 AM IDT)
  • Vladimir Volevich (13/12/2019 02:34 PM IDT)
  • Latchezar Christov (13/12/2019 04:13 PM IDT)
  • Stefan Wirth (13/12/2019 07:43 PM IDT)
  • Yusuf Attarbashi (14/12/2019 12:34 AM IDT)
  • Harald Bögeholz (14/12/2019 05:43 AM IDT)
  • Jacoby Jaeger (14/12/2019 06:29 AM IDT)
  • Richard Gosiorovsky (14/12/2019 06:06 PM IDT)
  • Andreas Knüpfer (14/12/2019 08:43 PM IDT)
  • David Greer (15/12/2019 01:03 PM IDT)
  • Aviv Nisgav (15/12/2019 10:13 PM IDT)
  • *Bert Dobbelaere (16/12/2019 01:12 AM IDT)
  • Yasodhar Patnaik (16/12/2019 05:45 AM IDT)
  • Rob Pratt (16/12/2019 05:56 AM IDT)
  • Soumitra Agarwal (17/12/2019 02:58 AM IDT)
  • Sebastian Bohm & Martí Bosch (17/12/2019 01:34 PM IDT)
  • David Smalling (18/12/2019 12:39 AM IDT)
  • Victor Chang (19/12/2019 11:15 PM IDT)
  • Todd Will (20/12/2019 06:40 PM IDT)
  • Kang Jin Cho (20/12/2019 08:42 PM IDT)
  • Daniel Bitin (21/12/2019 04:55 PM IDT)
  • Dipto Thakurta (22/12/2019 08:28 AM IDT)
  • Amos Guler (22/12/2019 12:26 PM IDT)
  • Tyler Mullen (23/12/2019 02:34 AM IDT)
  • Daniel Chong Jyh Tar (24/12/2019 10:13 AM IDT)
  • Charles Joscelyne (24/12/2019 06:50 PM IDT)
  • Fabio Michele Negroni (24/12/2019 07:21 PM IDT)
  • Franciraldo Cavalcante (25/12/2019 01:22 AM IDT)
  • Dieter Beckerle (25/12/2019 09:12 PM IDT)
  • Kipp Johnson (25/12/2019 10:34 PM IDT)
  • Hermann Jurksch (28/12/2019 07:57 PM IDT)
  • JJ Rabeyrin (29/12/2019 12:55 AM IDT)
  • Motty Porat (29/12/2019 02:23 AM IDT)
  • Michael Schuresko (29/12/2019 02:41 AM IDT)
  • Shouky Dan & Tamir Ganor (29/12/2019 08:33 AM IDT)
  • Erik Wuenstel (31/12/2019 01:32 AM IDT)
  • Aaron Freedman (31/12/2019 02:35 AM IDT)
  • Stephen Barr (31/12/2019 08:06 AM IDT)
  • *Calvin Pozderac (31/12/2019 07:51 PM IDT)
  • Radu-Alexandru Todor (01/01/2020 02:13 AM IDT)
  • Li Li (01/01/2020 07:54AM IDT)
  • *Oscar Volpatti (01/01/2020 12:37 PM IDT)
  • Gert Schlenker (03/01/2020 11:55 AM IDT)
  • David Keyes (03/01/2020 11:08 PM IDT)
  • Toprak Göke (06/01/2020 11:55 PM IDT)
  • Rogerio Ponce da Silva (10/01/2020 08:15 PM IDT)
  • Inigo Quilez (17/01/2020 11:05 PM IDT)
  • Christopher Dyken (22/01/2020 07:31 PM IDT)
  • Reda Kebbaj (24/01/2020 11:46 PM IDT)

Related posts