
(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 10 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 (fma (fma (tanh (/ t y)) z (* (tanh (/ x y)) (- z))) y x))
double code(double x, double y, double z, double t) {
return fma(fma(tanh((t / y)), z, (tanh((x / y)) * -z)), y, x);
}
function code(x, y, z, t) return fma(fma(tanh(Float64(t / y)), z, Float64(tanh(Float64(x / y)) * Float64(-z))), y, x) end
code[x_, y_, z_, t_] := N[(N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] * z + N[(N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision] * (-z)), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(\tanh \left(\frac{t}{y}\right), z, \tanh \left(\frac{x}{y}\right) \cdot \left(-z\right)\right), y, x\right)
\end{array}
Initial program 93.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6498.0
Applied rewrites98.0%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
distribute-rgt-inN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-neg.f6498.1
Applied rewrites98.1%
Final simplification98.1%
(FPCore (x y z t) :precision binary64 (fma (* z (- (tanh (/ t y)) (tanh (/ x y)))) y x))
double code(double x, double y, double z, double t) {
return fma((z * (tanh((t / y)) - tanh((x / y)))), y, x);
}
function code(x, y, z, t) return fma(Float64(z * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y)))), y, x) end
code[x_, y_, z_, t_] := N[(N[(z * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), y, x\right)
\end{array}
Initial program 93.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6498.0
Applied rewrites98.0%
(FPCore (x y z t) :precision binary64 (if (<= y 2.4e-129) (/ 1.0 (/ 1.0 x)) (fma (* y (- (tanh (/ t y)) (/ x y))) z x)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 2.4e-129) {
tmp = 1.0 / (1.0 / x);
} else {
tmp = fma((y * (tanh((t / y)) - (x / y))), z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= 2.4e-129) tmp = Float64(1.0 / Float64(1.0 / x)); else tmp = fma(Float64(y * Float64(tanh(Float64(t / y)) - Float64(x / y))), z, x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, 2.4e-129], N[(1.0 / N[(1.0 / x), $MachinePrecision]), $MachinePrecision], N[(N[(y * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.4 \cdot 10^{-129}:\\
\;\;\;\;\frac{1}{\frac{1}{x}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot \left(\tanh \left(\frac{t}{y}\right) - \frac{x}{y}\right), z, x\right)\\
\end{array}
\end{array}
if y < 2.39999999999999989e-129Initial program 94.1%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6455.3
Applied rewrites55.3%
Applied rewrites10.0%
Taylor expanded in z around 0
Applied rewrites64.0%
if 2.39999999999999989e-129 < y Initial program 92.8%
Taylor expanded in x around 0
lower-/.f6481.8
Applied rewrites81.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6485.8
Applied rewrites85.8%
Final simplification72.0%
(FPCore (x y z t) :precision binary64 (if (<= y 1.85e-65) (/ 1.0 (/ 1.0 x)) (fma (* z (- (/ t y) (tanh (/ x y)))) y x)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.85e-65) {
tmp = 1.0 / (1.0 / x);
} else {
tmp = fma((z * ((t / y) - tanh((x / y)))), y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= 1.85e-65) tmp = Float64(1.0 / Float64(1.0 / x)); else tmp = fma(Float64(z * Float64(Float64(t / y) - tanh(Float64(x / y)))), y, x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, 1.85e-65], N[(1.0 / N[(1.0 / x), $MachinePrecision]), $MachinePrecision], N[(N[(z * N[(N[(t / y), $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.85 \cdot 10^{-65}:\\
\;\;\;\;\frac{1}{\frac{1}{x}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot \left(\frac{t}{y} - \tanh \left(\frac{x}{y}\right)\right), y, x\right)\\
\end{array}
\end{array}
if y < 1.85e-65Initial program 94.5%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6455.1
Applied rewrites55.1%
Applied rewrites9.4%
Taylor expanded in z around 0
Applied rewrites63.2%
if 1.85e-65 < y Initial program 91.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6496.3
Applied rewrites96.3%
Taylor expanded in t around 0
lower-/.f6480.0
Applied rewrites80.0%
(FPCore (x y z t) :precision binary64 (if (<= y 2.15e-67) (/ 1.0 (/ 1.0 x)) (fma z (- t x) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 2.15e-67) {
tmp = 1.0 / (1.0 / x);
} else {
tmp = fma(z, (t - x), x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= 2.15e-67) tmp = Float64(1.0 / Float64(1.0 / x)); else tmp = fma(z, Float64(t - x), x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, 2.15e-67], N[(1.0 / N[(1.0 / x), $MachinePrecision]), $MachinePrecision], N[(z * N[(t - x), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.15 \cdot 10^{-67}:\\
\;\;\;\;\frac{1}{\frac{1}{x}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, t - x, x\right)\\
\end{array}
\end{array}
if y < 2.15000000000000013e-67Initial program 94.5%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6454.8
Applied rewrites54.8%
Applied rewrites9.5%
Taylor expanded in z around 0
Applied rewrites63.5%
if 2.15000000000000013e-67 < y Initial program 91.8%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6477.0
Applied rewrites77.0%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* z (- t x)))) (if (<= z -6.2e-11) t_1 (if (<= z 48000.0) (fma z (- x) x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = z * (t - x);
double tmp;
if (z <= -6.2e-11) {
tmp = t_1;
} else if (z <= 48000.0) {
tmp = fma(z, -x, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(z * Float64(t - x)) tmp = 0.0 if (z <= -6.2e-11) tmp = t_1; elseif (z <= 48000.0) tmp = fma(z, Float64(-x), x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(z * N[(t - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -6.2e-11], t$95$1, If[LessEqual[z, 48000.0], N[(z * (-x) + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := z \cdot \left(t - x\right)\\
\mathbf{if}\;z \leq -6.2 \cdot 10^{-11}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 48000:\\
\;\;\;\;\mathsf{fma}\left(z, -x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -6.20000000000000056e-11 or 48000 < z Initial program 88.6%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6446.7
Applied rewrites46.7%
Taylor expanded in z around inf
Applied rewrites46.4%
if -6.20000000000000056e-11 < z < 48000Initial program 99.2%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6478.7
Applied rewrites78.7%
Taylor expanded in t around 0
Applied rewrites86.1%
(FPCore (x y z t) :precision binary64 (if (<= t -7e-155) (* t z) (if (<= t 3.1e-135) (* z (- x)) (* t z))))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -7e-155) {
tmp = t * z;
} else if (t <= 3.1e-135) {
tmp = z * -x;
} else {
tmp = t * z;
}
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 (t <= (-7d-155)) then
tmp = t * z
else if (t <= 3.1d-135) then
tmp = z * -x
else
tmp = t * z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= -7e-155) {
tmp = t * z;
} else if (t <= 3.1e-135) {
tmp = z * -x;
} else {
tmp = t * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -7e-155: tmp = t * z elif t <= 3.1e-135: tmp = z * -x else: tmp = t * z return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -7e-155) tmp = Float64(t * z); elseif (t <= 3.1e-135) tmp = Float64(z * Float64(-x)); else tmp = Float64(t * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -7e-155) tmp = t * z; elseif (t <= 3.1e-135) tmp = z * -x; else tmp = t * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -7e-155], N[(t * z), $MachinePrecision], If[LessEqual[t, 3.1e-135], N[(z * (-x)), $MachinePrecision], N[(t * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -7 \cdot 10^{-155}:\\
\;\;\;\;t \cdot z\\
\mathbf{elif}\;t \leq 3.1 \cdot 10^{-135}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;t \cdot z\\
\end{array}
\end{array}
if t < -7.00000000000000031e-155 or 3.1000000000000001e-135 < t Initial program 95.4%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6453.6
Applied rewrites53.6%
Taylor expanded in t around inf
Applied rewrites23.8%
if -7.00000000000000031e-155 < t < 3.1000000000000001e-135Initial program 89.0%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6484.1
Applied rewrites84.1%
Applied rewrites46.5%
Taylor expanded in z around -inf
Applied rewrites38.3%
Taylor expanded in t around 0
Applied rewrites30.3%
Final simplification25.6%
(FPCore (x y z t) :precision binary64 (if (<= y 1.85e-67) (fma z (- x) x) (fma z (- t x) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.85e-67) {
tmp = fma(z, -x, x);
} else {
tmp = fma(z, (t - x), x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= 1.85e-67) tmp = fma(z, Float64(-x), x); else tmp = fma(z, Float64(t - x), x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, 1.85e-67], N[(z * (-x) + x), $MachinePrecision], N[(z * N[(t - x), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.85 \cdot 10^{-67}:\\
\;\;\;\;\mathsf{fma}\left(z, -x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, t - x, x\right)\\
\end{array}
\end{array}
if y < 1.85e-67Initial program 94.5%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6454.8
Applied rewrites54.8%
Taylor expanded in t around 0
Applied rewrites49.6%
if 1.85e-67 < y Initial program 91.8%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6477.0
Applied rewrites77.0%
(FPCore (x y z t) :precision binary64 (* z (- t x)))
double code(double x, double y, double z, double t) {
return z * (t - 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 = z * (t - x)
end function
public static double code(double x, double y, double z, double t) {
return z * (t - x);
}
def code(x, y, z, t): return z * (t - x)
function code(x, y, z, t) return Float64(z * Float64(t - x)) end
function tmp = code(x, y, z, t) tmp = z * (t - x); end
code[x_, y_, z_, t_] := N[(z * N[(t - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \left(t - x\right)
\end{array}
Initial program 93.6%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6462.0
Applied rewrites62.0%
Taylor expanded in z around inf
Applied rewrites28.7%
(FPCore (x y z t) :precision binary64 (* t z))
double code(double x, double y, double z, double t) {
return t * z;
}
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 = t * z
end function
public static double code(double x, double y, double z, double t) {
return t * z;
}
def code(x, y, z, t): return t * z
function code(x, y, z, t) return Float64(t * z) end
function tmp = code(x, y, z, t) tmp = t * z; end
code[x_, y_, z_, t_] := N[(t * z), $MachinePrecision]
\begin{array}{l}
\\
t \cdot z
\end{array}
Initial program 93.6%
Taylor expanded in y around inf
+-commutativeN/A
lower-fma.f64N/A
lower--.f6462.0
Applied rewrites62.0%
Taylor expanded in t around inf
Applied rewrites20.2%
Final simplification20.2%
(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 2024219
(FPCore (x y z t)
:name "SynthBasics:moogVCF from YampaSynth-0.2"
:precision binary64
:alt
(! :herbie-platform default (+ x (* y (* z (- (tanh (/ t y)) (tanh (/ x y)))))))
(+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))