
(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 -3.6e+243)
(* y z)
(if (<= y -5.8e+212)
t_0
(if (<= y -2.45e+151)
(* y z)
(if (<= y -1e+43)
t_0
(if (<= y -1.2e-56)
(* y z)
(if (<= y 1.3e-53) x (if (<= y 1.12e+21) (* y z) t_0)))))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -3.6e+243) {
tmp = y * z;
} else if (y <= -5.8e+212) {
tmp = t_0;
} else if (y <= -2.45e+151) {
tmp = y * z;
} else if (y <= -1e+43) {
tmp = t_0;
} else if (y <= -1.2e-56) {
tmp = y * z;
} else if (y <= 1.3e-53) {
tmp = x;
} else if (y <= 1.12e+21) {
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 <= (-3.6d+243)) then
tmp = y * z
else if (y <= (-5.8d+212)) then
tmp = t_0
else if (y <= (-2.45d+151)) then
tmp = y * z
else if (y <= (-1d+43)) then
tmp = t_0
else if (y <= (-1.2d-56)) then
tmp = y * z
else if (y <= 1.3d-53) then
tmp = x
else if (y <= 1.12d+21) 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 <= -3.6e+243) {
tmp = y * z;
} else if (y <= -5.8e+212) {
tmp = t_0;
} else if (y <= -2.45e+151) {
tmp = y * z;
} else if (y <= -1e+43) {
tmp = t_0;
} else if (y <= -1.2e-56) {
tmp = y * z;
} else if (y <= 1.3e-53) {
tmp = x;
} else if (y <= 1.12e+21) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -3.6e+243: tmp = y * z elif y <= -5.8e+212: tmp = t_0 elif y <= -2.45e+151: tmp = y * z elif y <= -1e+43: tmp = t_0 elif y <= -1.2e-56: tmp = y * z elif y <= 1.3e-53: tmp = x elif y <= 1.12e+21: 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 <= -3.6e+243) tmp = Float64(y * z); elseif (y <= -5.8e+212) tmp = t_0; elseif (y <= -2.45e+151) tmp = Float64(y * z); elseif (y <= -1e+43) tmp = t_0; elseif (y <= -1.2e-56) tmp = Float64(y * z); elseif (y <= 1.3e-53) tmp = x; elseif (y <= 1.12e+21) 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 <= -3.6e+243) tmp = y * z; elseif (y <= -5.8e+212) tmp = t_0; elseif (y <= -2.45e+151) tmp = y * z; elseif (y <= -1e+43) tmp = t_0; elseif (y <= -1.2e-56) tmp = y * z; elseif (y <= 1.3e-53) tmp = x; elseif (y <= 1.12e+21) 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, -3.6e+243], N[(y * z), $MachinePrecision], If[LessEqual[y, -5.8e+212], t$95$0, If[LessEqual[y, -2.45e+151], N[(y * z), $MachinePrecision], If[LessEqual[y, -1e+43], t$95$0, If[LessEqual[y, -1.2e-56], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.3e-53], x, If[LessEqual[y, 1.12e+21], N[(y * z), $MachinePrecision], t$95$0]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -3.6 \cdot 10^{+243}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -5.8 \cdot 10^{+212}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -2.45 \cdot 10^{+151}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1 \cdot 10^{+43}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -1.2 \cdot 10^{-56}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{-53}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.12 \cdot 10^{+21}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -3.5999999999999997e243 or -5.7999999999999997e212 < y < -2.45e151 or -1.00000000000000001e43 < y < -1.2e-56 or 1.29999999999999998e-53 < y < 1.12e21Initial program 100.0%
Taylor expanded in z around inf 84.8%
Taylor expanded in x around 0 69.6%
if -3.5999999999999997e243 < y < -5.7999999999999997e212 or -2.45e151 < y < -1.00000000000000001e43 or 1.12e21 < y Initial program 100.0%
Taylor expanded in z around 0 70.9%
mul-1-neg70.9%
distribute-lft-neg-out70.9%
*-commutative70.9%
Simplified70.9%
Taylor expanded in y around inf 70.9%
associate-*r*70.9%
mul-1-neg70.9%
Simplified70.9%
if -1.2e-56 < y < 1.29999999999999998e-53Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around inf 77.4%
Final simplification73.4%
(FPCore (x y z)
:precision binary64
(if (or (<= y -2.1e+243)
(and (not (<= y -7.4e+210))
(or (<= y -2.05e+150)
(and (not (<= y -1.1e+43)) (<= y 8.6e+19)))))
(+ x (* y z))
(* y (- x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.1e+243) || (!(y <= -7.4e+210) && ((y <= -2.05e+150) || (!(y <= -1.1e+43) && (y <= 8.6e+19))))) {
tmp = x + (y * z);
} else {
tmp = y * -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 <= (-2.1d+243)) .or. (.not. (y <= (-7.4d+210))) .and. (y <= (-2.05d+150)) .or. (.not. (y <= (-1.1d+43))) .and. (y <= 8.6d+19)) then
tmp = x + (y * z)
else
tmp = y * -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.1e+243) || (!(y <= -7.4e+210) && ((y <= -2.05e+150) || (!(y <= -1.1e+43) && (y <= 8.6e+19))))) {
tmp = x + (y * z);
} else {
tmp = y * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.1e+243) or (not (y <= -7.4e+210) and ((y <= -2.05e+150) or (not (y <= -1.1e+43) and (y <= 8.6e+19)))): tmp = x + (y * z) else: tmp = y * -x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.1e+243) || (!(y <= -7.4e+210) && ((y <= -2.05e+150) || (!(y <= -1.1e+43) && (y <= 8.6e+19))))) tmp = Float64(x + Float64(y * z)); else tmp = Float64(y * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.1e+243) || (~((y <= -7.4e+210)) && ((y <= -2.05e+150) || (~((y <= -1.1e+43)) && (y <= 8.6e+19))))) tmp = x + (y * z); else tmp = y * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.1e+243], And[N[Not[LessEqual[y, -7.4e+210]], $MachinePrecision], Or[LessEqual[y, -2.05e+150], And[N[Not[LessEqual[y, -1.1e+43]], $MachinePrecision], LessEqual[y, 8.6e+19]]]]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(y * (-x)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.1 \cdot 10^{+243} \lor \neg \left(y \leq -7.4 \cdot 10^{+210}\right) \land \left(y \leq -2.05 \cdot 10^{+150} \lor \neg \left(y \leq -1.1 \cdot 10^{+43}\right) \land y \leq 8.6 \cdot 10^{+19}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\end{array}
\end{array}
if y < -2.0999999999999999e243 or -7.39999999999999996e210 < y < -2.04999999999999997e150 or -1.1e43 < y < 8.6e19Initial program 100.0%
Taylor expanded in z around inf 94.4%
if -2.0999999999999999e243 < y < -7.39999999999999996e210 or -2.04999999999999997e150 < y < -1.1e43 or 8.6e19 < y Initial program 100.0%
Taylor expanded in z around 0 70.9%
mul-1-neg70.9%
distribute-lft-neg-out70.9%
*-commutative70.9%
Simplified70.9%
Taylor expanded in y around inf 70.9%
associate-*r*70.9%
mul-1-neg70.9%
Simplified70.9%
Final simplification86.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.65e-79) (not (<= z 2.2e-35))) (+ x (* y z)) (- x (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.65e-79) || !(z <= 2.2e-35)) {
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 <= (-2.65d-79)) .or. (.not. (z <= 2.2d-35))) 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 <= -2.65e-79) || !(z <= 2.2e-35)) {
tmp = x + (y * z);
} else {
tmp = x - (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.65e-79) or not (z <= 2.2e-35): tmp = x + (y * z) else: tmp = x - (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.65e-79) || !(z <= 2.2e-35)) 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 <= -2.65e-79) || ~((z <= 2.2e-35))) tmp = x + (y * z); else tmp = x - (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.65e-79], N[Not[LessEqual[z, 2.2e-35]], $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 -2.65 \cdot 10^{-79} \lor \neg \left(z \leq 2.2 \cdot 10^{-35}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot y\\
\end{array}
\end{array}
if z < -2.6499999999999999e-79 or 2.19999999999999994e-35 < z Initial program 100.0%
Taylor expanded in z around inf 89.5%
if -2.6499999999999999e-79 < z < 2.19999999999999994e-35Initial program 100.0%
Taylor expanded in z around 0 92.6%
mul-1-neg92.6%
distribute-lft-neg-out92.6%
*-commutative92.6%
Simplified92.6%
*-commutative92.6%
distribute-lft-neg-out92.6%
unsub-neg92.6%
Applied egg-rr92.6%
Final simplification90.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.35e-48) (not (<= y 1.85e-58))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.35e-48) || !(y <= 1.85e-58)) {
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.35d-48)) .or. (.not. (y <= 1.85d-58))) 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.35e-48) || !(y <= 1.85e-58)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.35e-48) or not (y <= 1.85e-58): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.35e-48) || !(y <= 1.85e-58)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.35e-48) || ~((y <= 1.85e-58))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.35e-48], N[Not[LessEqual[y, 1.85e-58]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{-48} \lor \neg \left(y \leq 1.85 \cdot 10^{-58}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.35000000000000006e-48 or 1.8500000000000001e-58 < y Initial program 100.0%
Taylor expanded in z around inf 60.0%
Taylor expanded in x around 0 53.2%
if -1.35000000000000006e-48 < y < 1.8500000000000001e-58Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around inf 77.4%
Final simplification63.6%
(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 77.2%
Taylor expanded in x around inf 38.3%
Final simplification38.3%
herbie shell --seed 2024024
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))