?

Average Error: 4.5 → 2.2
Time: 13.3s
Precision: binary64
Cost: 27332

?

\[x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \]
\[\begin{array}{l} t_1 := x + \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \cdot \left(z \cdot y\right)\\ \mathbf{if}\;t_1 \leq 5 \cdot 10^{+306}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t - x, z, 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
 (let* ((t_1 (+ x (* (- (tanh (/ t y)) (tanh (/ x y))) (* z y)))))
   (if (<= t_1 5e+306) t_1 (fma (- t x) z 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 t_1 = x + ((tanh((t / y)) - tanh((x / y))) * (z * y));
	double tmp;
	if (t_1 <= 5e+306) {
		tmp = t_1;
	} else {
		tmp = fma((t - x), z, 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)
	t_1 = Float64(x + Float64(Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))) * Float64(z * y)))
	tmp = 0.0
	if (t_1 <= 5e+306)
		tmp = t_1;
	else
		tmp = fma(Float64(t - x), z, 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_] := Block[{t$95$1 = 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]}, If[LessEqual[t$95$1, 5e+306], t$95$1, N[(N[(t - x), $MachinePrecision] * z + x), $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}
t_1 := x + \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \cdot \left(z \cdot y\right)\\
\mathbf{if}\;t_1 \leq 5 \cdot 10^{+306}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\


\end{array}

Error?

Target

Original4.5
Target1.9
Herbie2.2
\[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 2 regimes
  2. if (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < 4.99999999999999993e306

    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 4.99999999999999993e306 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y)))))

    1. Initial program 61.5

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

      \[\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

      [Start]61.5

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

      +-commutative [=>]61.5

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

      *-commutative [=>]61.5

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

      associate-*l* [=>]20.0

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

      fma-def [=>]20.0

      \[ \color{blue}{\mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right)} \]
    3. Taylor expanded in y around inf 5.6

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(t - x, z, x\right)} \]
      Proof

      [Start]5.6

      \[ \left(t - x\right) \cdot z + x \]

      fma-def [=>]5.6

      \[ \color{blue}{\mathsf{fma}\left(t - x, z, x\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification2.2

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

Alternatives

Alternative 1
Error1.4
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.8
Cost7241
\[\begin{array}{l} \mathbf{if}\;y \leq -4.5 \cdot 10^{+95} \lor \neg \left(y \leq 7.2 \cdot 10^{+169}\right):\\ \;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(z \cdot \tanh \left(\frac{t}{y}\right)\right)\\ \end{array} \]
Alternative 3
Error16.0
Cost6985
\[\begin{array}{l} \mathbf{if}\;y \leq -3.7 \cdot 10^{+56} \lor \neg \left(y \leq 3.35 \cdot 10^{+115}\right):\\ \;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error19.6
Cost717
\[\begin{array}{l} \mathbf{if}\;y \leq -2.4 \cdot 10^{+198}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{elif}\;y \leq -2.8 \cdot 10^{-40} \lor \neg \left(y \leq 3.5 \cdot 10^{+111}\right):\\ \;\;\;\;x + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error16.0
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -2.1 \cdot 10^{+57} \lor \neg \left(y \leq 3.35 \cdot 10^{+115}\right):\\ \;\;\;\;x + z \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error21.7
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -4.6 \cdot 10^{+58} \lor \neg \left(y \leq 5.8 \cdot 10^{+172}\right):\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error23.0
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -5.5 \cdot 10^{-190}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{-208}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error23.4
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023027 
(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))))))