
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
double code(double x, double y, double z) {
return x + (y * (z - x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y * (z - x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z - x));
}
def code(x, y, z): return x + (y * (z - x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = x + (y * (z - x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z - x\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
double code(double x, double y, double z) {
return x + (y * (z - x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y * (z - x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z - x));
}
def code(x, y, z): return x + (y * (z - x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = x + (y * (z - x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z - x\right)
\end{array}
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
double code(double x, double y, double z) {
return x + (y * (z - x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y * (z - x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z - x));
}
def code(x, y, z): return x + (y * (z - x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = x + (y * (z - x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z - x\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= y -6.5e+189)
t_0
(if (<= y -1.6e+122)
(* y z)
(if (<= y -1.95e+68)
t_0
(if (<= y -2.8e-18)
(* y z)
(if (<= y 1.35e-16) x (if (<= y 9.8e+188) (* y z) t_0))))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -6.5e+189) {
tmp = t_0;
} else if (y <= -1.6e+122) {
tmp = y * z;
} else if (y <= -1.95e+68) {
tmp = t_0;
} else if (y <= -2.8e-18) {
tmp = y * z;
} else if (y <= 1.35e-16) {
tmp = x;
} else if (y <= 9.8e+188) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = y * -x
if (y <= (-6.5d+189)) then
tmp = t_0
else if (y <= (-1.6d+122)) then
tmp = y * z
else if (y <= (-1.95d+68)) then
tmp = t_0
else if (y <= (-2.8d-18)) then
tmp = y * z
else if (y <= 1.35d-16) then
tmp = x
else if (y <= 9.8d+188) then
tmp = y * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -6.5e+189) {
tmp = t_0;
} else if (y <= -1.6e+122) {
tmp = y * z;
} else if (y <= -1.95e+68) {
tmp = t_0;
} else if (y <= -2.8e-18) {
tmp = y * z;
} else if (y <= 1.35e-16) {
tmp = x;
} else if (y <= 9.8e+188) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -6.5e+189: tmp = t_0 elif y <= -1.6e+122: tmp = y * z elif y <= -1.95e+68: tmp = t_0 elif y <= -2.8e-18: tmp = y * z elif y <= 1.35e-16: tmp = x elif y <= 9.8e+188: tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (y <= -6.5e+189) tmp = t_0; elseif (y <= -1.6e+122) tmp = Float64(y * z); elseif (y <= -1.95e+68) tmp = t_0; elseif (y <= -2.8e-18) tmp = Float64(y * z); elseif (y <= 1.35e-16) tmp = x; elseif (y <= 9.8e+188) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -x; tmp = 0.0; if (y <= -6.5e+189) tmp = t_0; elseif (y <= -1.6e+122) tmp = y * z; elseif (y <= -1.95e+68) tmp = t_0; elseif (y <= -2.8e-18) tmp = y * z; elseif (y <= 1.35e-16) tmp = x; elseif (y <= 9.8e+188) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[y, -6.5e+189], t$95$0, If[LessEqual[y, -1.6e+122], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.95e+68], t$95$0, If[LessEqual[y, -2.8e-18], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.35e-16], x, If[LessEqual[y, 9.8e+188], N[(y * z), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -6.5 \cdot 10^{+189}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -1.6 \cdot 10^{+122}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1.95 \cdot 10^{+68}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -2.8 \cdot 10^{-18}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{-16}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 9.8 \cdot 10^{+188}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -6.50000000000000027e189 or -1.60000000000000006e122 < y < -1.95000000000000009e68 or 9.8e188 < y Initial program 100.0%
Taylor expanded in z around 0 66.1%
mul-1-neg66.1%
distribute-lft-neg-out66.1%
*-commutative66.1%
Simplified66.1%
Taylor expanded in y around inf 66.1%
associate-*r*66.1%
mul-1-neg66.1%
Simplified66.1%
if -6.50000000000000027e189 < y < -1.60000000000000006e122 or -1.95000000000000009e68 < y < -2.80000000000000012e-18 or 1.35e-16 < y < 9.8e188Initial program 100.0%
Taylor expanded in z around inf 72.5%
Taylor expanded in x around 0 71.0%
if -2.80000000000000012e-18 < y < 1.35e-16Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around inf 77.8%
Final simplification72.6%
(FPCore (x y z)
:precision binary64
(if (or (<= y -8.5e+189)
(and (not (<= y -5.6e+122))
(or (<= y -1.9e+70) (not (<= y 5.5e+182)))))
(* y (- x))
(+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8.5e+189) || (!(y <= -5.6e+122) && ((y <= -1.9e+70) || !(y <= 5.5e+182)))) {
tmp = y * -x;
} else {
tmp = x + (y * z);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-8.5d+189)) .or. (.not. (y <= (-5.6d+122))) .and. (y <= (-1.9d+70)) .or. (.not. (y <= 5.5d+182))) then
tmp = y * -x
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -8.5e+189) || (!(y <= -5.6e+122) && ((y <= -1.9e+70) || !(y <= 5.5e+182)))) {
tmp = y * -x;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8.5e+189) or (not (y <= -5.6e+122) and ((y <= -1.9e+70) or not (y <= 5.5e+182))): tmp = y * -x else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8.5e+189) || (!(y <= -5.6e+122) && ((y <= -1.9e+70) || !(y <= 5.5e+182)))) tmp = Float64(y * Float64(-x)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -8.5e+189) || (~((y <= -5.6e+122)) && ((y <= -1.9e+70) || ~((y <= 5.5e+182))))) tmp = y * -x; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8.5e+189], And[N[Not[LessEqual[y, -5.6e+122]], $MachinePrecision], Or[LessEqual[y, -1.9e+70], N[Not[LessEqual[y, 5.5e+182]], $MachinePrecision]]]], N[(y * (-x)), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.5 \cdot 10^{+189} \lor \neg \left(y \leq -5.6 \cdot 10^{+122}\right) \land \left(y \leq -1.9 \cdot 10^{+70} \lor \neg \left(y \leq 5.5 \cdot 10^{+182}\right)\right):\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -8.4999999999999998e189 or -5.5999999999999999e122 < y < -1.8999999999999999e70 or 5.49999999999999977e182 < y Initial program 100.0%
Taylor expanded in z around 0 65.7%
mul-1-neg65.7%
distribute-lft-neg-out65.7%
*-commutative65.7%
Simplified65.7%
Taylor expanded in y around inf 65.7%
associate-*r*65.7%
mul-1-neg65.7%
Simplified65.7%
if -8.4999999999999998e189 < y < -5.5999999999999999e122 or -1.8999999999999999e70 < y < 5.49999999999999977e182Initial program 100.0%
Taylor expanded in z around inf 89.8%
Final simplification82.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.95e-84) (not (<= z 6.5e-20))) (+ x (* y z)) (- x (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.95e-84) || !(z <= 6.5e-20)) {
tmp = x + (y * z);
} else {
tmp = x - (x * y);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-1.95d-84)) .or. (.not. (z <= 6.5d-20))) then
tmp = x + (y * z)
else
tmp = x - (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.95e-84) || !(z <= 6.5e-20)) {
tmp = x + (y * z);
} else {
tmp = x - (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.95e-84) or not (z <= 6.5e-20): tmp = x + (y * z) else: tmp = x - (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.95e-84) || !(z <= 6.5e-20)) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x - Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.95e-84) || ~((z <= 6.5e-20))) tmp = x + (y * z); else tmp = x - (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.95e-84], N[Not[LessEqual[z, 6.5e-20]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.95 \cdot 10^{-84} \lor \neg \left(z \leq 6.5 \cdot 10^{-20}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot y\\
\end{array}
\end{array}
if z < -1.95000000000000011e-84 or 6.50000000000000032e-20 < z Initial program 100.0%
Taylor expanded in z around inf 93.3%
if -1.95000000000000011e-84 < z < 6.50000000000000032e-20Initial program 100.0%
Taylor expanded in z around 0 90.2%
mul-1-neg90.2%
distribute-lft-neg-out90.2%
*-commutative90.2%
Simplified90.2%
*-commutative90.2%
distribute-lft-neg-out90.2%
unsub-neg90.2%
Applied egg-rr90.2%
Final simplification91.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.5e-17) (not (<= y 5e-20))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.5e-17) || !(y <= 5e-20)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-1.5d-17)) .or. (.not. (y <= 5d-20))) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.5e-17) || !(y <= 5e-20)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.5e-17) or not (y <= 5e-20): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.5e-17) || !(y <= 5e-20)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.5e-17) || ~((y <= 5e-20))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.5e-17], N[Not[LessEqual[y, 5e-20]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{-17} \lor \neg \left(y \leq 5 \cdot 10^{-20}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.50000000000000003e-17 or 4.9999999999999999e-20 < y Initial program 100.0%
Taylor expanded in z around inf 56.2%
Taylor expanded in x around 0 55.2%
if -1.50000000000000003e-17 < y < 4.9999999999999999e-20Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around inf 77.8%
Final simplification65.1%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in z around inf 75.4%
Taylor expanded in x around inf 36.0%
Final simplification36.0%
herbie shell --seed 2023306
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))