Average Error: 4.8 → 1.1
Time: 10.1s
Precision: binary64
Cost: 20036
\[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 \cdot 10^{+229}:\\ \;\;\;\;\mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + z \cdot t\right) - z \cdot x\\ \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 5e+229)
   (fma z (* y (- (tanh (/ t y)) (tanh (/ x y)))) x)
   (- (+ x (* z t)) (* 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 tmp;
	if (y <= 5e+229) {
		tmp = fma(z, (y * (tanh((t / y)) - tanh((x / y)))), x);
	} else {
		tmp = (x + (z * t)) - (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)
	tmp = 0.0
	if (y <= 5e+229)
		tmp = fma(z, Float64(y * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y)))), x);
	else
		tmp = Float64(Float64(x + Float64(z * t)) - Float64(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_] := If[LessEqual[y, 5e+229], N[(z * N[(y * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(N[(x + N[(z * t), $MachinePrecision]), $MachinePrecision] - N[(z * x), $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 \cdot 10^{+229}:\\
\;\;\;\;\mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right)\\

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


\end{array}

Error

Target

Original4.8
Target2.0
Herbie1.1
\[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.0000000000000005e229

    1. Initial program 3.8

      \[x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \]
    2. Applied egg-rr1.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)} \]

    if 5.0000000000000005e229 < y

    1. Initial program 21.9

      \[x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \]
    2. Taylor expanded in y around inf 2.8

      \[\leadsto \color{blue}{x + z \cdot \left(t - x\right)} \]
    3. Applied egg-rr26.6

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

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

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

Alternatives

Alternative 1
Error11.8
Cost14428
\[\begin{array}{l} t_1 := x + \left(y \cdot z\right) \cdot \left(\frac{t}{y} - \tanh \left(\frac{x}{y}\right)\right)\\ t_2 := \tanh \left(\frac{t}{y}\right) - \frac{x}{y}\\ t_3 := \mathsf{fma}\left(z, y \cdot t_2, x\right)\\ \mathbf{if}\;y \leq -4.978469123197317 \cdot 10^{+21}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq -5.265108367908785 \cdot 10^{-30}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -8.954599301357871 \cdot 10^{-32}:\\ \;\;\;\;x + t_2 \cdot \left(y \cdot z\right)\\ \mathbf{elif}\;y \leq 9.801310009497872 \cdot 10^{-102}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 10^{+120}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 10^{+160}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 10^{+218}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;\left(x + z \cdot t\right) - z \cdot x\\ \end{array} \]
Alternative 2
Error1.6
Cost13764
\[\begin{array}{l} \mathbf{if}\;y \leq 5 \cdot 10^{+229}:\\ \;\;\;\;x + y \cdot \left(z \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + z \cdot t\right) - z \cdot x\\ \end{array} \]
Alternative 3
Error12.6
Cost8024
\[\begin{array}{l} t_1 := x + \left(\tanh \left(\frac{t}{y}\right) - \frac{x}{y}\right) \cdot \left(y \cdot z\right)\\ \mathbf{if}\;y \leq -1 \cdot 10^{+169}:\\ \;\;\;\;x + \frac{t - x}{\frac{1}{z}}\\ \mathbf{elif}\;y \leq -4.978469123197317 \cdot 10^{+21}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -5.265108367908785 \cdot 10^{-30}:\\ \;\;\;\;x + \left(y \cdot z\right) \cdot \left(\frac{t}{y} - \tanh \left(\frac{x}{y}\right)\right)\\ \mathbf{elif}\;y \leq -8.954599301357871 \cdot 10^{-32}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 9.801310009497872 \cdot 10^{-102}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4.722799083554523 \cdot 10^{+68}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\left(x + z \cdot t\right) - z \cdot x\\ \end{array} \]
Alternative 4
Error12.5
Cost7760
\[\begin{array}{l} t_1 := x + \left(\tanh \left(\frac{t}{y}\right) - \frac{x}{y}\right) \cdot \left(y \cdot z\right)\\ \mathbf{if}\;y \leq -1 \cdot 10^{+169}:\\ \;\;\;\;x + \frac{t - x}{\frac{1}{z}}\\ \mathbf{elif}\;y \leq -8.954599301357871 \cdot 10^{-32}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 9.801310009497872 \cdot 10^{-102}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 4.722799083554523 \cdot 10^{+68}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\left(x + z \cdot t\right) - z \cdot x\\ \end{array} \]
Alternative 5
Error14.8
Cost840
\[\begin{array}{l} t_1 := x + \frac{t - x}{\frac{1}{z}}\\ \mathbf{if}\;y \leq -4.978469123197317 \cdot 10^{+21}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.600611217249082 \cdot 10^{+64}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error14.8
Cost840
\[\begin{array}{l} \mathbf{if}\;y \leq -4.978469123197317 \cdot 10^{+21}:\\ \;\;\;\;x + \frac{t - x}{\frac{1}{z}}\\ \mathbf{elif}\;y \leq 2.600611217249082 \cdot 10^{+64}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x + \frac{z}{\frac{1}{t - x}}\\ \end{array} \]
Alternative 7
Error14.7
Cost840
\[\begin{array}{l} t_1 := \left(x + z \cdot t\right) - z \cdot x\\ \mathbf{if}\;y \leq -4.978469123197317 \cdot 10^{+21}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.600611217249082 \cdot 10^{+64}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error17.7
Cost584
\[\begin{array}{l} t_1 := x + z \cdot t\\ \mathbf{if}\;y \leq -4.978469123197317 \cdot 10^{+21}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.600611217249082 \cdot 10^{+64}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error22.2
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.70853812750078 \cdot 10^{-238}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.325025159969309 \cdot 10^{-222}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error22.6
Cost64
\[x \]

Error

Reproduce

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