Average Error: 4.5 → 2.5
Time: 13.9s
Precision: binary64
Cost: 13896
\[x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \]
\[\begin{array}{l} \mathbf{if}\;y \leq -7.8 \cdot 10^{+180}:\\ \;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{+222}:\\ \;\;\;\;x + \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \cdot \left(z \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(t - x\right)\\ \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))
(FPCore (x y z t)
 :precision binary64
 (if (<= y -7.8e+180)
   (fma (- t x) z x)
   (if (<= y 7.5e+222)
     (+ x (* (- (tanh (/ t y)) (tanh (/ x y))) (* z y)))
     (+ x (* z (- t x))))))
double code(double x, double y, double z, double t) {
	return x + ((y * z) * (tanh((t / y)) - tanh((x / y))));
}
double code(double x, double y, double z, double t) {
	double tmp;
	if (y <= -7.8e+180) {
		tmp = fma((t - x), z, x);
	} else if (y <= 7.5e+222) {
		tmp = x + ((tanh((t / y)) - tanh((x / y))) * (z * y));
	} else {
		tmp = x + (z * (t - x));
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(x + Float64(Float64(y * z) * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y)))))
end
function code(x, y, z, t)
	tmp = 0.0
	if (y <= -7.8e+180)
		tmp = fma(Float64(t - x), z, x);
	elseif (y <= 7.5e+222)
		tmp = Float64(x + Float64(Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))) * Float64(z * y)));
	else
		tmp = Float64(x + Float64(z * Float64(t - x)));
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * z), $MachinePrecision] * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[y, -7.8e+180], N[(N[(t - x), $MachinePrecision] * z + x), $MachinePrecision], If[LessEqual[y, 7.5e+222], N[(x + N[(N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\begin{array}{l}
\mathbf{if}\;y \leq -7.8 \cdot 10^{+180}:\\
\;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\

\mathbf{elif}\;y \leq 7.5 \cdot 10^{+222}:\\
\;\;\;\;x + \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \cdot \left(z \cdot y\right)\\

\mathbf{else}:\\
\;\;\;\;x + z \cdot \left(t - x\right)\\


\end{array}

Error

Target

Original4.5
Target2.0
Herbie2.5
\[x + y \cdot \left(z \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right) \]

Derivation

  1. Split input into 3 regimes
  2. if y < -7.8000000000000002e180

    1. Initial program 17.1

      \[x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \]
    2. Simplified6.7

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right)} \]
      Proof
      (fma.f64 z (*.f64 y (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y)))) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z (*.f64 y (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) x)): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 z y) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) x): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (Rewrite<= *-commutative_binary64 (*.f64 y z)) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y)))) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y)))))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in y around inf 6.1

      \[\leadsto \color{blue}{\left(t - x\right) \cdot z + x} \]
    4. Simplified6.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(t - x, z, x\right)} \]
      Proof
      (fma.f64 (-.f64 t x) z x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (-.f64 t x) z) x)): 2 points increase in error, 0 points decrease in error

    if -7.8000000000000002e180 < y < 7.50000000000000003e222

    1. Initial program 2.1

      \[x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \]

    if 7.50000000000000003e222 < y

    1. Initial program 21.0

      \[x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \]
    2. Simplified7.7

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right)} \]
      Proof
      (fma.f64 z (*.f64 y (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y)))) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z (*.f64 y (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) x)): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 z y) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) x): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (Rewrite<= *-commutative_binary64 (*.f64 y z)) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y)))) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y)))))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in y around inf 3.6

      \[\leadsto \color{blue}{\left(t - x\right) \cdot z + x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -7.8 \cdot 10^{+180}:\\ \;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\ \mathbf{elif}\;y \leq 7.5 \cdot 10^{+222}:\\ \;\;\;\;x + \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \cdot \left(z \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(t - x\right)\\ \end{array} \]

Alternatives

Alternative 1
Error1.5
Cost19904
\[\mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right) \]
Alternative 2
Error9.2
Cost13640
\[\begin{array}{l} t_1 := y \cdot \tanh \left(\frac{t}{y}\right)\\ \mathbf{if}\;y \leq -1.45 \cdot 10^{+182}:\\ \;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{+51}:\\ \;\;\;\;\mathsf{fma}\left(z, t_1, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, t_1 - x, x\right)\\ \end{array} \]
Alternative 3
Error9.8
Cost13512
\[\begin{array}{l} \mathbf{if}\;y \leq -1.1 \cdot 10^{+182}:\\ \;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{+76}:\\ \;\;\;\;\mathsf{fma}\left(z, y \cdot \tanh \left(\frac{t}{y}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(t - x\right)\\ \end{array} \]
Alternative 4
Error18.4
Cost7240
\[\begin{array}{l} \mathbf{if}\;x \leq -9.5 \cdot 10^{-201}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-143}:\\ \;\;\;\;z \cdot \left(y \cdot \tanh \left(\frac{t}{y}\right) - x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error9.9
Cost7240
\[\begin{array}{l} \mathbf{if}\;y \leq -9.6 \cdot 10^{+178}:\\ \;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\ \mathbf{elif}\;y \leq 2.9 \cdot 10^{+76}:\\ \;\;\;\;x + y \cdot \left(z \cdot \tanh \left(\frac{t}{y}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(t - x\right)\\ \end{array} \]
Alternative 6
Error15.1
Cost6852
\[\begin{array}{l} \mathbf{if}\;y \leq -7.6 \cdot 10^{+108}:\\ \;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\ \mathbf{elif}\;y \leq 2.15 \cdot 10^{+51}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(t - x\right)\\ \end{array} \]
Alternative 7
Error20.1
Cost848
\[\begin{array}{l} t_1 := x + z \cdot t\\ \mathbf{if}\;x \leq -1.32 \cdot 10^{-158}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{-209}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-160}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{-144}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error15.1
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -7.2 \cdot 10^{+108} \lor \neg \left(y \leq 7.1 \cdot 10^{+50}\right):\\ \;\;\;\;x + z \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error19.9
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -1.1 \cdot 10^{+66} \lor \neg \left(y \leq 3.6 \cdot 10^{+106}\right):\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error21.9
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -5.5 \cdot 10^{-202}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5.4 \cdot 10^{-283}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error22.2
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022343 
(FPCore (x y z t)
  :name "SynthBasics:moogVCF from YampaSynth-0.2"
  :precision binary64

  :herbie-target
  (+ x (* y (* z (- (tanh (/ t y)) (tanh (/ x y))))))

  (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))