Average Error: 4.4 → 1.4
Time: 14.5s
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(t - x\right)\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+288}:\\ \;\;\;\;t_1\\ \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
 (let* ((t_1 (+ x (* (- (tanh (/ t y)) (tanh (/ x y))) (* z y)))))
   (if (<= t_1 (- INFINITY))
     (* z (- t x))
     (if (<= t_1 2e+288) t_1 (- (+ 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 t_1 = x + ((tanh((t / y)) - tanh((x / y))) * (z * y));
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = z * (t - x);
	} else if (t_1 <= 2e+288) {
		tmp = t_1;
	} else {
		tmp = (x + (z * t)) - (z * 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 * (t - x);
	} else if (t_1 <= 2e+288) {
		tmp = t_1;
	} else {
		tmp = (x + (z * t)) - (z * 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 * (t - x)
	elif t_1 <= 2e+288:
		tmp = t_1
	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)
	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(t - x));
	elseif (t_1 <= 2e+288)
		tmp = t_1;
	else
		tmp = Float64(Float64(x + Float64(z * t)) - Float64(z * 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 * (t - x);
	elseif (t_1 <= 2e+288)
		tmp = t_1;
	else
		tmp = (x + (z * t)) - (z * 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 * N[(t - x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e+288], t$95$1, 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}
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(t - x\right)\\

\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+288}:\\
\;\;\;\;t_1\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original4.4
Target2.0
Herbie1.4
\[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. Taylor expanded in y around inf 0.0

      \[\leadsto \color{blue}{x + z \cdot \left(t - x\right)} \]
    3. Simplified0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, t - x, x\right)} \]
      Proof
      (fma.f64 z (-.f64 t x) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z (-.f64 t x)) x)): 2 points increase in error, 0 points decrease in error
      (Rewrite=> +-commutative_binary64 (+.f64 x (*.f64 z (-.f64 t x)))): 0 points increase in error, 0 points decrease in error
    4. Taylor expanded in z around inf 0.0

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

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

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

    1. Initial program 43.6

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

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

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

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

    \[\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(t - 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 2 \cdot 10^{+288}:\\ \;\;\;\;x + \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \cdot \left(z \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x + z \cdot t\right) - z \cdot x\\ \end{array} \]

Alternatives

Alternative 1
Error2.0
Cost19904
\[\mathsf{fma}\left(z \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), y, x\right) \]
Alternative 2
Error11.5
Cost13768
\[\begin{array}{l} \mathbf{if}\;x \leq -8.042098222497062 \cdot 10^{-25}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 0.016876214166876444:\\ \;\;\;\;\mathsf{fma}\left(z \cdot \left(\tanh \left(\frac{t}{y}\right) - \frac{x}{y}\right), y, x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error13.0
Cost7496
\[\begin{array}{l} \mathbf{if}\;x \leq -8.042098222497062 \cdot 10^{-25}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 8.1158169123305 \cdot 10^{-79}:\\ \;\;\;\;x + \left(z \cdot y\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \frac{x}{y}\right)\\ \mathbf{elif}\;x \leq 0.016876214166876444:\\ \;\;\;\;x + \frac{t + x}{\frac{t + x}{z} \cdot \frac{1}{t - x}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error15.0
Cost6984
\[\begin{array}{l} \mathbf{if}\;y \leq -1.3701398489509255 \cdot 10^{+32}:\\ \;\;\;\;\left(x + z \cdot t\right) - z \cdot x\\ \mathbf{elif}\;y \leq 2.7855600619364186 \cdot 10^{+72}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, t - x, x\right)\\ \end{array} \]
Alternative 5
Error21.8
Cost716
\[\begin{array}{l} \mathbf{if}\;x \leq -1.8303902661605033 \cdot 10^{-223}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5.509851784189507 \cdot 10^{-253}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;x \leq 0.016876214166876444:\\ \;\;\;\;x - z \cdot x\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error15.0
Cost712
\[\begin{array}{l} t_1 := x + z \cdot \left(t - x\right)\\ \mathbf{if}\;y \leq -1.3701398489509255 \cdot 10^{+32}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.7855600619364186 \cdot 10^{+72}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error15.0
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -1.3701398489509255 \cdot 10^{+32}:\\ \;\;\;\;\left(x + z \cdot t\right) - z \cdot x\\ \mathbf{elif}\;y \leq 2.7855600619364186 \cdot 10^{+72}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(t - x\right)\\ \end{array} \]
Alternative 8
Error17.9
Cost584
\[\begin{array}{l} t_1 := x + z \cdot t\\ \mathbf{if}\;y \leq -4.003371815396493 \cdot 10^{+47}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.383357339322899 \cdot 10^{+56}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error21.9
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.8303902661605033 \cdot 10^{-223}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5.509851784189507 \cdot 10^{-253}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error22.5
Cost64
\[x \]

Error

Reproduce

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