?

Average Accuracy: 92.9% → 98.3%
Time: 18.2s
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 := \tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\\ \mathbf{if}\;x + \left(y \cdot z\right) \cdot t_1 \leq 10^{+301}:\\ \;\;\;\;x + z \cdot \left(y \cdot t_1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, -x, z \cdot t\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 (- (tanh (/ t y)) (tanh (/ x y)))))
   (if (<= (+ x (* (* y z) t_1)) 1e+301)
     (+ x (* z (* y t_1)))
     (fma z (- x) (* z t)))))
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 = tanh((t / y)) - tanh((x / y));
	double tmp;
	if ((x + ((y * z) * t_1)) <= 1e+301) {
		tmp = x + (z * (y * t_1));
	} else {
		tmp = fma(z, -x, (z * t));
	}
	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(tanh(Float64(t / y)) - tanh(Float64(x / y)))
	tmp = 0.0
	if (Float64(x + Float64(Float64(y * z) * t_1)) <= 1e+301)
		tmp = Float64(x + Float64(z * Float64(y * t_1)));
	else
		tmp = fma(z, Float64(-x), Float64(z * t));
	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[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x + N[(N[(y * z), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision], 1e+301], N[(x + N[(z * N[(y * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * (-x) + N[(z * t), $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}
t_1 := \tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\\
\mathbf{if}\;x + \left(y \cdot z\right) \cdot t_1 \leq 10^{+301}:\\
\;\;\;\;x + z \cdot \left(y \cdot t_1\right)\\

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


\end{array}

Error?

Target

Original92.9%
Target96.9%
Herbie98.3%
\[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))))) < 1.00000000000000005e301

    1. Initial program 96.7%

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

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

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

      +-commutative [=>]96.7

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

      *-commutative [=>]96.7

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

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

      \[ \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. Applied egg-rr99.1%

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

      [Start]99.1

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

      fma-udef [=>]99.1

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

      *-commutative [=>]99.1

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

    if 1.00000000000000005e301 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y)))))

    1. Initial program 12.4%

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

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

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

      +-commutative [=>]12.4

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

      *-commutative [=>]12.4

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

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

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

      \[\leadsto \color{blue}{\left(t - x\right) \cdot z + x} \]
    4. Taylor expanded in z around inf 81.3%

      \[\leadsto \color{blue}{\left(t - x\right) \cdot z} \]
    5. Taylor expanded in t around 0 81.3%

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

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

      [Start]81.3

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

      +-commutative [=>]81.3

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

      mul-1-neg [=>]81.3

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

      distribute-rgt-neg-out [<=]81.3

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

      fma-def [=>]81.4

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

      *-commutative [=>]81.4

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

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

Alternatives

Alternative 1
Accuracy98.3%
Cost41032
\[\begin{array}{l} t_1 := x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;z \cdot \left(t - x\right)\\ \mathbf{elif}\;t_1 \leq 10^{+301}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, -x, z \cdot t\right)\\ \end{array} \]
Alternative 2
Accuracy87.7%
Cost13576
\[\begin{array}{l} t_1 := \tanh \left(\frac{x}{y}\right)\\ \mathbf{if}\;x \leq -6.2 \cdot 10^{-20}:\\ \;\;\;\;x - z \cdot \left(y \cdot t_1\right)\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{-9}:\\ \;\;\;\;x + z \cdot \left(y \cdot \tanh \left(\frac{t}{y}\right) - x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, z \cdot \left(-t_1\right), x\right)\\ \end{array} \]
Alternative 3
Accuracy74.2%
Cost7636
\[\begin{array}{l} t_1 := x + z \cdot \left(t - x\right)\\ t_2 := x - z \cdot \left(y \cdot \tanh \left(\frac{x}{y}\right)\right)\\ t_3 := \left(y \cdot z\right) \cdot \tanh \left(\frac{t}{y}\right)\\ \mathbf{if}\;x \leq -3.3 \cdot 10^{-23}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -4.2 \cdot 10^{-186}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{-267}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 2.2 \cdot 10^{-195}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{-128}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Accuracy68.5%
Cost7508
\[\begin{array}{l} t_1 := \left(y \cdot z\right) \cdot \tanh \left(\frac{t}{y}\right)\\ t_2 := x + z \cdot \left(t - x\right)\\ \mathbf{if}\;x \leq -8.6 \cdot 10^{+69}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -5.2 \cdot 10^{-187}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{-268}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-198}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{-129}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Accuracy87.7%
Cost7369
\[\begin{array}{l} \mathbf{if}\;x \leq -3.5 \cdot 10^{-20} \lor \neg \left(x \leq 6.6 \cdot 10^{-11}\right):\\ \;\;\;\;x - z \cdot \left(y \cdot \tanh \left(\frac{x}{y}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(y \cdot \tanh \left(\frac{t}{y}\right) - x\right)\\ \end{array} \]
Alternative 6
Accuracy70.5%
Cost980
\[\begin{array}{l} t_1 := x + z \cdot t\\ \mathbf{if}\;y \leq -0.9:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4 \cdot 10^{-33}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 6.2 \cdot 10^{+110}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{+149}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{+263}:\\ \;\;\;\;x - x \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Accuracy75.6%
Cost976
\[\begin{array}{l} t_1 := x + z \cdot \left(t - x\right)\\ \mathbf{if}\;y \leq -3.1 \cdot 10^{-5}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.4 \cdot 10^{-34}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{+111}:\\ \;\;\;\;x + z \cdot t\\ \mathbf{elif}\;y \leq 1.65 \cdot 10^{+146}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Accuracy63.2%
Cost849
\[\begin{array}{l} \mathbf{if}\;x \leq -2.2 \cdot 10^{-42}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 9 \cdot 10^{-259} \lor \neg \left(x \leq 1.06 \cdot 10^{-218}\right) \land x \leq 1.6 \cdot 10^{-176}:\\ \;\;\;\;z \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Accuracy68.3%
Cost584
\[\begin{array}{l} \mathbf{if}\;t \leq -5 \cdot 10^{+37}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 6.6:\\ \;\;\;\;x + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Accuracy65.1%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.1 \cdot 10^{-156}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{-259}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Accuracy65.4%
Cost64
\[x \]

Error

Reproduce?

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