?

Average Error: 4.6 → 1.8
Time: 14.4s
Precision: binary64
Cost: 41032

?

\[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 -\infty:\\ \;\;\;\;z \cdot \left(-x\right)\\ \mathbf{elif}\;t_1 \leq 10^{+303}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;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
 (let* ((t_1 (+ x (* (- (tanh (/ t y)) (tanh (/ x y))) (* z y)))))
   (if (<= t_1 (- INFINITY))
     (* z (- x))
     (if (<= t_1 1e+303) t_1 (* 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 t_1 = x + ((tanh((t / y)) - tanh((x / y))) * (z * y));
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = z * -x;
	} else if (t_1 <= 1e+303) {
		tmp = t_1;
	} else {
		tmp = z * (t - x);
	}
	return tmp;
}
public static double code(double x, double y, double z, double t) {
	return x + ((y * z) * (Math.tanh((t / y)) - Math.tanh((x / y))));
}
public static double code(double x, double y, double z, double t) {
	double t_1 = x + ((Math.tanh((t / y)) - Math.tanh((x / y))) * (z * y));
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = z * -x;
	} else if (t_1 <= 1e+303) {
		tmp = t_1;
	} else {
		tmp = z * (t - x);
	}
	return tmp;
}
def code(x, y, z, t):
	return x + ((y * z) * (math.tanh((t / y)) - math.tanh((x / y))))
def code(x, y, z, t):
	t_1 = x + ((math.tanh((t / y)) - math.tanh((x / y))) * (z * y))
	tmp = 0
	if t_1 <= -math.inf:
		tmp = z * -x
	elif t_1 <= 1e+303:
		tmp = t_1
	else:
		tmp = 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)
	t_1 = Float64(x + Float64(Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))) * Float64(z * y)))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(z * Float64(-x));
	elseif (t_1 <= 1e+303)
		tmp = t_1;
	else
		tmp = Float64(z * Float64(t - x));
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = x + ((y * z) * (tanh((t / y)) - tanh((x / y))));
end
function tmp_2 = code(x, y, z, t)
	t_1 = x + ((tanh((t / y)) - tanh((x / y))) * (z * y));
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = z * -x;
	elseif (t_1 <= 1e+303)
		tmp = t_1;
	else
		tmp = z * (t - x);
	end
	tmp_2 = 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, (-Infinity)], N[(z * (-x)), $MachinePrecision], If[LessEqual[t$95$1, 1e+303], t$95$1, N[(z * N[(t - 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}
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 -\infty:\\
\;\;\;\;z \cdot \left(-x\right)\\

\mathbf{elif}\;t_1 \leq 10^{+303}:\\
\;\;\;\;t_1\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original4.6
Target2.1
Herbie1.8
\[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 (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < -inf.0

    1. Initial program 64.0

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

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

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

      +-commutative [=>]64.0

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

      *-commutative [=>]64.0

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(z \cdot x\right)} \]
    6. Simplified30.6

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

      [Start]30.6

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

      mul-1-neg [=>]30.6

      \[ \color{blue}{-z \cdot x} \]

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

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

    if -inf.0 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < 1e303

    1. Initial program 0.6

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

    if 1e303 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y)))))

    1. Initial program 55.9

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

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

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

      +-commutative [=>]55.9

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

      *-commutative [=>]55.9

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

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

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

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

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

    \[\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 -\infty:\\ \;\;\;\;z \cdot \left(-x\right)\\ \mathbf{elif}\;x + \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \cdot \left(z \cdot y\right) \leq 10^{+303}:\\ \;\;\;\;x + \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \cdot \left(z \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;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
Error1.5
Cost13632
\[x + z \cdot \left(y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right) \]
Alternative 3
Error9.0
Cost7369
\[\begin{array}{l} \mathbf{if}\;x \leq -9 \cdot 10^{-147} \lor \neg \left(x \leq 3.7 \cdot 10^{-73}\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 4
Error10.5
Cost7241
\[\begin{array}{l} \mathbf{if}\;t \leq -3.3 \cdot 10^{-192} \lor \neg \left(t \leq 5.1 \cdot 10^{-160}\right):\\ \;\;\;\;x + z \cdot \left(y \cdot \tanh \left(\frac{t}{y}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\ \end{array} \]
Alternative 5
Error9.0
Cost7241
\[\begin{array}{l} \mathbf{if}\;x \leq -2.7 \cdot 10^{-54} \lor \neg \left(x \leq 2.9 \cdot 10^{-73}\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)\right)\\ \end{array} \]
Alternative 6
Error15.5
Cost6852
\[\begin{array}{l} \mathbf{if}\;y \leq -4.3 \cdot 10^{-44}:\\ \;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\ \mathbf{elif}\;y \leq 5 \cdot 10^{-13}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(t - x\right)\\ \end{array} \]
Alternative 7
Error20.5
Cost1113
\[\begin{array}{l} t_1 := x \cdot \left(1 - z\right)\\ t_2 := x + z \cdot t\\ \mathbf{if}\;y \leq -4 \cdot 10^{-44}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{-13}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.3 \cdot 10^{+80}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{+106}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{+108} \lor \neg \left(y \leq 2.2 \cdot 10^{+169}\right):\\ \;\;\;\;z \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error21.8
Cost849
\[\begin{array}{l} t_1 := x \cdot \left(1 - z\right)\\ \mathbf{if}\;y \leq -255000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 6.2 \cdot 10^{-13}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.7 \cdot 10^{+222} \lor \neg \left(y \leq 9.5 \cdot 10^{+276}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot t\\ \end{array} \]
Alternative 9
Error22.0
Cost716
\[\begin{array}{l} t_1 := x \cdot \left(1 - z\right)\\ \mathbf{if}\;y \leq -380000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{-13}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.9 \cdot 10^{+168}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(t - x\right)\\ \end{array} \]
Alternative 10
Error15.5
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -5.5 \cdot 10^{-44} \lor \neg \left(y \leq 1.05 \cdot 10^{-12}\right):\\ \;\;\;\;x + z \cdot \left(t - x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error22.4
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.45 \cdot 10^{-217}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4 \cdot 10^{-179}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error22.8
Cost64
\[x \]

Error

Reproduce?

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