?

Average Error: 7.04% → 3.82%
Time: 15.8s
Precision: binary64
Cost: 13897

?

\[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 -5.4 \cdot 10^{+169} \lor \neg \left(y \leq 2.9 \cdot 10^{+180}\right):\\ \;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \cdot \left(z \cdot y\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 (or (<= y -5.4e+169) (not (<= y 2.9e+180)))
   (fma (- t x) z x)
   (+ x (* (- (tanh (/ t y)) (tanh (/ x y))) (* z y)))))
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 <= -5.4e+169) || !(y <= 2.9e+180)) {
		tmp = fma((t - x), z, x);
	} else {
		tmp = x + ((tanh((t / y)) - tanh((x / y))) * (z * y));
	}
	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 <= -5.4e+169) || !(y <= 2.9e+180))
		tmp = fma(Float64(t - x), z, x);
	else
		tmp = Float64(x + Float64(Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))) * Float64(z * y)));
	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[Or[LessEqual[y, -5.4e+169], N[Not[LessEqual[y, 2.9e+180]], $MachinePrecision]], N[(N[(t - x), $MachinePrecision] * z + x), $MachinePrecision], 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]]
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 -5.4 \cdot 10^{+169} \lor \neg \left(y \leq 2.9 \cdot 10^{+180}\right):\\
\;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\

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


\end{array}

Error?

Target

Original7.04%
Target2.87%
Herbie3.82%
\[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 y < -5.39999999999999981e169 or 2.90000000000000007e180 < y

    1. Initial program 27.47

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

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

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

      +-commutative [=>]27.47

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

      *-commutative [=>]27.47

      \[ \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* [=>]9.76

      \[ \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 [=>]9.75

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

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

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

      [Start]9.84

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

      fma-def [=>]9.83

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

    if -5.39999999999999981e169 < y < 2.90000000000000007e180

    1. Initial program 2.48

      \[x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification3.82

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

Alternatives

Alternative 1
Error2.13%
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
Error2.13%
Cost13632
\[x + z \cdot \left(y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right) \]
Alternative 3
Error13.73%
Cost7372
\[\begin{array}{l} t_1 := x + z \cdot \left(y \cdot \tanh \left(\frac{t}{y}\right)\right)\\ \mathbf{if}\;t \leq -7.6 \cdot 10^{-28}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.22 \cdot 10^{-219}:\\ \;\;\;\;x - z \cdot \left(y \cdot \tanh \left(\frac{x}{y}\right)\right)\\ \mathbf{elif}\;t \leq 1.55 \cdot 10^{-117}:\\ \;\;\;\;x + z \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error14.12%
Cost7368
\[\begin{array}{l} t_1 := y \cdot \tanh \left(\frac{t}{y}\right)\\ \mathbf{if}\;y \leq -8.4 \cdot 10^{+127}:\\ \;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{-63}:\\ \;\;\;\;x + z \cdot t_1\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(t_1 - x\right)\\ \end{array} \]
Alternative 5
Error16.63%
Cost7241
\[\begin{array}{l} \mathbf{if}\;t \leq -2.4 \cdot 10^{-48} \lor \neg \left(t \leq 1.9 \cdot 10^{-117}\right):\\ \;\;\;\;x + z \cdot \left(y \cdot \tanh \left(\frac{t}{y}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(t - x\right)\\ \end{array} \]
Alternative 6
Error22.67%
Cost6985
\[\begin{array}{l} \mathbf{if}\;y \leq -1.66 \cdot 10^{+125} \lor \neg \left(y \leq 1.3 \cdot 10^{-32}\right):\\ \;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \frac{y}{\frac{t}{y} \cdot 0.3333333333333333 + \frac{y}{t}}\\ \end{array} \]
Alternative 7
Error22.67%
Cost1225
\[\begin{array}{l} \mathbf{if}\;y \leq -1.12 \cdot 10^{+123} \lor \neg \left(y \leq 1.3 \cdot 10^{-32}\right):\\ \;\;\;\;x + z \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \frac{y}{\frac{t}{y} \cdot 0.3333333333333333 + \frac{y}{t}}\\ \end{array} \]
Alternative 8
Error33.08%
Cost716
\[\begin{array}{l} t_1 := x \cdot \left(1 - z\right)\\ \mathbf{if}\;y \leq -7.3 \cdot 10^{+177}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.2 \cdot 10^{+170}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{-63}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error30.52%
Cost716
\[\begin{array}{l} t_1 := x + z \cdot t\\ \mathbf{if}\;y \leq -1.8 \cdot 10^{+148}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 6 \cdot 10^{-63}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{+112}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error30.47%
Cost716
\[\begin{array}{l} t_1 := x + z \cdot t\\ \mathbf{if}\;y \leq -1.35 \cdot 10^{+140}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{-62}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 9.5 \cdot 10^{+114}:\\ \;\;\;\;x - z \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error24.12%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -2.2 \cdot 10^{+71} \lor \neg \left(y \leq 1.65 \cdot 10^{-34}\right):\\ \;\;\;\;x + z \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error36.97%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.32 \cdot 10^{-138}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.3 \cdot 10^{-301}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Error35.7%
Cost64
\[x \]

Error

Reproduce?

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