
(FPCore (x y z t) :precision binary64 (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))
double code(double x, double y, double z, double t) {
return x + ((y * z) * (tanh((t / y)) - tanh((x / y))));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y * z) * (tanh((t / y)) - tanh((x / y))))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * z) * (Math.tanh((t / y)) - Math.tanh((x / y))));
}
def code(x, y, z, t): return x + ((y * z) * (math.tanh((t / y)) - math.tanh((x / y))))
function code(x, y, z, t) return Float64(x + Float64(Float64(y * z) * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))))) end
function tmp = code(x, y, z, t) tmp = x + ((y * z) * (tanh((t / y)) - tanh((x / y)))); 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]
\begin{array}{l}
\\
x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))
double code(double x, double y, double z, double t) {
return x + ((y * z) * (tanh((t / y)) - tanh((x / y))));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y * z) * (tanh((t / y)) - tanh((x / y))))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * z) * (Math.tanh((t / y)) - Math.tanh((x / y))));
}
def code(x, y, z, t): return x + ((y * z) * (math.tanh((t / y)) - math.tanh((x / y))))
function code(x, y, z, t) return Float64(x + Float64(Float64(y * z) * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))))) end
function tmp = code(x, y, z, t) tmp = x + ((y * z) * (tanh((t / y)) - tanh((x / y)))); 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]
\begin{array}{l}
\\
x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\end{array}
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (+ x (* (- (tanh (/ t y)) (tanh (/ x y))) (* z y)))))
(if (or (<= t_1 (- INFINITY)) (not (<= t_1 2e+302)))
(+ x (* z (- t x)))
t_1)))
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)) || !(t_1 <= 2e+302)) {
tmp = x + (z * (t - x));
} else {
tmp = t_1;
}
return tmp;
}
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) || !(t_1 <= 2e+302)) {
tmp = x + (z * (t - x));
} else {
tmp = t_1;
}
return tmp;
}
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) or not (t_1 <= 2e+302): tmp = x + (z * (t - x)) else: tmp = t_1 return tmp
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)) || !(t_1 <= 2e+302)) tmp = Float64(x + Float64(z * Float64(t - x))); else tmp = t_1; end return tmp 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) || ~((t_1 <= 2e+302))) tmp = x + (z * (t - x)); else tmp = t_1; end tmp_2 = tmp; end
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[Or[LessEqual[t$95$1, (-Infinity)], N[Not[LessEqual[t$95$1, 2e+302]], $MachinePrecision]], N[(x + N[(z * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]
\begin{array}{l}
\\
\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 \lor \neg \left(t\_1 \leq 2 \cdot 10^{+302}\right):\\
\;\;\;\;x + z \cdot \left(t - x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < -inf.0 or 2.0000000000000002e302 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) Initial program 54.2%
Taylor expanded in y around inf 100.0%
if -inf.0 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < 2.0000000000000002e302Initial program 98.4%
Final simplification98.6%
(FPCore (x y z t) :precision binary64 (fma z (* y (- (tanh (/ t y)) (tanh (/ x y)))) x))
double code(double x, double y, double z, double t) {
return fma(z, (y * (tanh((t / y)) - tanh((x / y)))), x);
}
function code(x, y, z, t) return fma(z, Float64(y * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y)))), x) end
code[x_, y_, z_, t_] := N[(z * N[(y * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right)
\end{array}
Initial program 92.7%
+-commutative92.7%
*-commutative92.7%
associate-*l*97.9%
fma-def97.9%
Simplified97.9%
Final simplification97.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (tanh (/ t y)))))
(if (<= y 3.8e-257)
x
(if (<= y 6.6e+24) (+ x (* z t_1)) (+ x (* z (- t_1 x)))))))
double code(double x, double y, double z, double t) {
double t_1 = y * tanh((t / y));
double tmp;
if (y <= 3.8e-257) {
tmp = x;
} else if (y <= 6.6e+24) {
tmp = x + (z * t_1);
} else {
tmp = x + (z * (t_1 - x));
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = y * tanh((t / y))
if (y <= 3.8d-257) then
tmp = x
else if (y <= 6.6d+24) then
tmp = x + (z * t_1)
else
tmp = x + (z * (t_1 - x))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = y * Math.tanh((t / y));
double tmp;
if (y <= 3.8e-257) {
tmp = x;
} else if (y <= 6.6e+24) {
tmp = x + (z * t_1);
} else {
tmp = x + (z * (t_1 - x));
}
return tmp;
}
def code(x, y, z, t): t_1 = y * math.tanh((t / y)) tmp = 0 if y <= 3.8e-257: tmp = x elif y <= 6.6e+24: tmp = x + (z * t_1) else: tmp = x + (z * (t_1 - x)) return tmp
function code(x, y, z, t) t_1 = Float64(y * tanh(Float64(t / y))) tmp = 0.0 if (y <= 3.8e-257) tmp = x; elseif (y <= 6.6e+24) tmp = Float64(x + Float64(z * t_1)); else tmp = Float64(x + Float64(z * Float64(t_1 - x))); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * tanh((t / y)); tmp = 0.0; if (y <= 3.8e-257) tmp = x; elseif (y <= 6.6e+24) tmp = x + (z * t_1); else tmp = x + (z * (t_1 - x)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 3.8e-257], x, If[LessEqual[y, 6.6e+24], N[(x + N[(z * t$95$1), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(t$95$1 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \tanh \left(\frac{t}{y}\right)\\
\mathbf{if}\;y \leq 3.8 \cdot 10^{-257}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 6.6 \cdot 10^{+24}:\\
\;\;\;\;x + z \cdot t\_1\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \left(t\_1 - x\right)\\
\end{array}
\end{array}
if y < 3.8000000000000004e-257Initial program 92.1%
+-commutative92.1%
*-commutative92.1%
associate-*l*97.4%
fma-def97.4%
Simplified97.4%
Taylor expanded in z around 0 59.3%
if 3.8000000000000004e-257 < y < 6.5999999999999998e24Initial program 100.0%
Taylor expanded in x around 0 21.0%
+-commutative21.0%
Simplified70.6%
sub-neg70.6%
distribute-rgt-in70.6%
Applied egg-rr70.6%
Taylor expanded in x around 0 28.6%
associate-*r*28.6%
associate-/l*28.6%
*-commutative28.6%
associate-*r/28.6%
associate-/l*28.6%
associate-*r/28.6%
rec-exp28.6%
rec-exp28.6%
tanh-def-a90.2%
Simplified90.2%
if 6.5999999999999998e24 < y Initial program 87.2%
Taylor expanded in x around 0 44.0%
+-commutative44.0%
Simplified94.6%
Final simplification73.7%
(FPCore (x y z t) :precision binary64 (if (<= y 1.4e-258) x (if (<= y 1.6e+176) (+ x (* z (* y (tanh (/ t y))))) (+ x (* z (- t x))))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.4e-258) {
tmp = x;
} else if (y <= 1.6e+176) {
tmp = x + (z * (y * tanh((t / y))));
} else {
tmp = x + (z * (t - x));
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= 1.4d-258) then
tmp = x
else if (y <= 1.6d+176) then
tmp = x + (z * (y * tanh((t / y))))
else
tmp = x + (z * (t - x))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.4e-258) {
tmp = x;
} else if (y <= 1.6e+176) {
tmp = x + (z * (y * Math.tanh((t / y))));
} else {
tmp = x + (z * (t - x));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 1.4e-258: tmp = x elif y <= 1.6e+176: tmp = x + (z * (y * math.tanh((t / y)))) else: tmp = x + (z * (t - x)) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 1.4e-258) tmp = x; elseif (y <= 1.6e+176) tmp = Float64(x + Float64(z * Float64(y * tanh(Float64(t / y))))); else tmp = Float64(x + Float64(z * Float64(t - x))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 1.4e-258) tmp = x; elseif (y <= 1.6e+176) tmp = x + (z * (y * tanh((t / y)))); else tmp = x + (z * (t - x)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 1.4e-258], x, If[LessEqual[y, 1.6e+176], N[(x + N[(z * N[(y * N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.4 \cdot 10^{-258}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.6 \cdot 10^{+176}:\\
\;\;\;\;x + z \cdot \left(y \cdot \tanh \left(\frac{t}{y}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \left(t - x\right)\\
\end{array}
\end{array}
if y < 1.4000000000000001e-258Initial program 92.1%
+-commutative92.1%
*-commutative92.1%
associate-*l*97.4%
fma-def97.4%
Simplified97.4%
Taylor expanded in z around 0 59.3%
if 1.4000000000000001e-258 < y < 1.5999999999999999e176Initial program 98.3%
Taylor expanded in x around 0 25.7%
+-commutative25.7%
Simplified79.8%
sub-neg79.8%
distribute-rgt-in79.8%
Applied egg-rr79.8%
Taylor expanded in x around 0 26.2%
associate-*r*26.1%
associate-/l*26.1%
*-commutative26.1%
associate-*r/26.2%
associate-/l*26.2%
associate-*r/26.2%
rec-exp26.2%
rec-exp26.2%
tanh-def-a87.5%
Simplified87.5%
if 1.5999999999999999e176 < y Initial program 78.1%
Taylor expanded in y around inf 89.1%
Final simplification71.7%
(FPCore (x y z t) :precision binary64 (if (<= y 7.2e+25) x (+ x (* z (- t x)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 7.2e+25) {
tmp = x;
} else {
tmp = x + (z * (t - x));
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= 7.2d+25) then
tmp = x
else
tmp = x + (z * (t - x))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 7.2e+25) {
tmp = x;
} else {
tmp = x + (z * (t - x));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 7.2e+25: tmp = x else: tmp = x + (z * (t - x)) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 7.2e+25) tmp = x; else tmp = Float64(x + Float64(z * Float64(t - x))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 7.2e+25) tmp = x; else tmp = x + (z * (t - x)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 7.2e+25], x, N[(x + N[(z * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 7.2 \cdot 10^{+25}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \left(t - x\right)\\
\end{array}
\end{array}
if y < 7.20000000000000031e25Initial program 94.3%
+-commutative94.3%
*-commutative94.3%
associate-*l*98.1%
fma-def98.1%
Simplified98.1%
Taylor expanded in z around 0 66.4%
if 7.20000000000000031e25 < y Initial program 87.2%
Taylor expanded in y around inf 77.1%
Final simplification68.8%
(FPCore (x y z t) :precision binary64 (if (<= y 1.9e+26) x (+ x (* z t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.9e+26) {
tmp = x;
} else {
tmp = x + (z * t);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= 1.9d+26) then
tmp = x
else
tmp = x + (z * t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.9e+26) {
tmp = x;
} else {
tmp = x + (z * t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 1.9e+26: tmp = x else: tmp = x + (z * t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 1.9e+26) tmp = x; else tmp = Float64(x + Float64(z * t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 1.9e+26) tmp = x; else tmp = x + (z * t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 1.9e+26], x, N[(x + N[(z * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.9 \cdot 10^{+26}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot t\\
\end{array}
\end{array}
if y < 1.9000000000000001e26Initial program 94.3%
+-commutative94.3%
*-commutative94.3%
associate-*l*98.1%
fma-def98.1%
Simplified98.1%
Taylor expanded in z around 0 66.4%
if 1.9000000000000001e26 < y Initial program 87.2%
Taylor expanded in y around inf 64.3%
Taylor expanded in t around inf 67.1%
Final simplification66.6%
(FPCore (x y z t) :precision binary64 x)
double code(double x, double y, double z, double t) {
return x;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x
end function
public static double code(double x, double y, double z, double t) {
return x;
}
def code(x, y, z, t): return x
function code(x, y, z, t) return x end
function tmp = code(x, y, z, t) tmp = x; end
code[x_, y_, z_, t_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 92.7%
+-commutative92.7%
*-commutative92.7%
associate-*l*97.9%
fma-def97.9%
Simplified97.9%
Taylor expanded in z around 0 59.4%
Final simplification59.4%
(FPCore (x y z t) :precision binary64 (+ x (* y (* z (- (tanh (/ t y)) (tanh (/ x y)))))))
double code(double x, double y, double z, double t) {
return x + (y * (z * (tanh((t / y)) - tanh((x / y)))));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + (y * (z * (tanh((t / y)) - tanh((x / y)))))
end function
public static double code(double x, double y, double z, double t) {
return x + (y * (z * (Math.tanh((t / y)) - Math.tanh((x / y)))));
}
def code(x, y, z, t): return x + (y * (z * (math.tanh((t / y)) - math.tanh((x / y)))))
function code(x, y, z, t) return Float64(x + Float64(y * Float64(z * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y)))))) end
function tmp = code(x, y, z, t) tmp = x + (y * (z * (tanh((t / y)) - tanh((x / y))))); end
code[x_, y_, z_, t_] := N[(x + N[(y * N[(z * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right)
\end{array}
herbie shell --seed 2024041
(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))))))