
(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 7 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 (fma y (- z x) x))
double code(double x, double y, double z) {
return fma(y, (z - x), x);
}
function code(x, y, z) return fma(y, Float64(z - x), x) end
code[x_, y_, z_] := N[(y * N[(z - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, z - x, x\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= y -6.6e+78)
(* y z)
(if (<= y -4.5e+43)
t_0
(if (<= y -3.7e-15)
(* y z)
(if (<= y 3e-184)
x
(if (<= y 9.2e-156)
(* y z)
(if (<= y 6e-51)
x
(if (or (<= y 3.4e+72)
(and (not (<= y 1.48e+165)) (<= y 4.2e+219)))
(* y z)
t_0)))))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -6.6e+78) {
tmp = y * z;
} else if (y <= -4.5e+43) {
tmp = t_0;
} else if (y <= -3.7e-15) {
tmp = y * z;
} else if (y <= 3e-184) {
tmp = x;
} else if (y <= 9.2e-156) {
tmp = y * z;
} else if (y <= 6e-51) {
tmp = x;
} else if ((y <= 3.4e+72) || (!(y <= 1.48e+165) && (y <= 4.2e+219))) {
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.6d+78)) then
tmp = y * z
else if (y <= (-4.5d+43)) then
tmp = t_0
else if (y <= (-3.7d-15)) then
tmp = y * z
else if (y <= 3d-184) then
tmp = x
else if (y <= 9.2d-156) then
tmp = y * z
else if (y <= 6d-51) then
tmp = x
else if ((y <= 3.4d+72) .or. (.not. (y <= 1.48d+165)) .and. (y <= 4.2d+219)) 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.6e+78) {
tmp = y * z;
} else if (y <= -4.5e+43) {
tmp = t_0;
} else if (y <= -3.7e-15) {
tmp = y * z;
} else if (y <= 3e-184) {
tmp = x;
} else if (y <= 9.2e-156) {
tmp = y * z;
} else if (y <= 6e-51) {
tmp = x;
} else if ((y <= 3.4e+72) || (!(y <= 1.48e+165) && (y <= 4.2e+219))) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -6.6e+78: tmp = y * z elif y <= -4.5e+43: tmp = t_0 elif y <= -3.7e-15: tmp = y * z elif y <= 3e-184: tmp = x elif y <= 9.2e-156: tmp = y * z elif y <= 6e-51: tmp = x elif (y <= 3.4e+72) or (not (y <= 1.48e+165) and (y <= 4.2e+219)): 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.6e+78) tmp = Float64(y * z); elseif (y <= -4.5e+43) tmp = t_0; elseif (y <= -3.7e-15) tmp = Float64(y * z); elseif (y <= 3e-184) tmp = x; elseif (y <= 9.2e-156) tmp = Float64(y * z); elseif (y <= 6e-51) tmp = x; elseif ((y <= 3.4e+72) || (!(y <= 1.48e+165) && (y <= 4.2e+219))) 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.6e+78) tmp = y * z; elseif (y <= -4.5e+43) tmp = t_0; elseif (y <= -3.7e-15) tmp = y * z; elseif (y <= 3e-184) tmp = x; elseif (y <= 9.2e-156) tmp = y * z; elseif (y <= 6e-51) tmp = x; elseif ((y <= 3.4e+72) || (~((y <= 1.48e+165)) && (y <= 4.2e+219))) 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.6e+78], N[(y * z), $MachinePrecision], If[LessEqual[y, -4.5e+43], t$95$0, If[LessEqual[y, -3.7e-15], N[(y * z), $MachinePrecision], If[LessEqual[y, 3e-184], x, If[LessEqual[y, 9.2e-156], N[(y * z), $MachinePrecision], If[LessEqual[y, 6e-51], x, If[Or[LessEqual[y, 3.4e+72], And[N[Not[LessEqual[y, 1.48e+165]], $MachinePrecision], LessEqual[y, 4.2e+219]]], 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.6 \cdot 10^{+78}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -4.5 \cdot 10^{+43}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -3.7 \cdot 10^{-15}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 3 \cdot 10^{-184}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 9.2 \cdot 10^{-156}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 6 \cdot 10^{-51}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 3.4 \cdot 10^{+72} \lor \neg \left(y \leq 1.48 \cdot 10^{+165}\right) \land y \leq 4.2 \cdot 10^{+219}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -6.6e78 or -4.5e43 < y < -3.70000000000000017e-15 or 2.99999999999999991e-184 < y < 9.1999999999999998e-156 or 6.00000000000000005e-51 < y < 3.3999999999999998e72 or 1.48e165 < y < 4.19999999999999976e219Initial program 100.0%
Taylor expanded in z around inf 71.2%
Taylor expanded in x around 0 66.0%
if -6.6e78 < y < -4.5e43 or 3.3999999999999998e72 < y < 1.48e165 or 4.19999999999999976e219 < y Initial program 100.0%
Taylor expanded in x around inf 69.3%
mul-1-neg69.3%
unsub-neg69.3%
Simplified69.3%
Taylor expanded in y around inf 69.3%
associate-*r*69.3%
mul-1-neg69.3%
Simplified69.3%
if -3.70000000000000017e-15 < y < 2.99999999999999991e-184 or 9.1999999999999998e-156 < y < 6.00000000000000005e-51Initial program 100.0%
Taylor expanded in y around 0 80.2%
Final simplification72.5%
(FPCore (x y z)
:precision binary64
(if (or (<= y -2.55e-14)
(and (not (<= y 3e-184)) (or (<= y 9e-156) (not (<= y 3.1e-55)))))
(* y z)
x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.55e-14) || (!(y <= 3e-184) && ((y <= 9e-156) || !(y <= 3.1e-55)))) {
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 <= (-2.55d-14)) .or. (.not. (y <= 3d-184)) .and. (y <= 9d-156) .or. (.not. (y <= 3.1d-55))) 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 <= -2.55e-14) || (!(y <= 3e-184) && ((y <= 9e-156) || !(y <= 3.1e-55)))) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.55e-14) or (not (y <= 3e-184) and ((y <= 9e-156) or not (y <= 3.1e-55))): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.55e-14) || (!(y <= 3e-184) && ((y <= 9e-156) || !(y <= 3.1e-55)))) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.55e-14) || (~((y <= 3e-184)) && ((y <= 9e-156) || ~((y <= 3.1e-55))))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.55e-14], And[N[Not[LessEqual[y, 3e-184]], $MachinePrecision], Or[LessEqual[y, 9e-156], N[Not[LessEqual[y, 3.1e-55]], $MachinePrecision]]]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.55 \cdot 10^{-14} \lor \neg \left(y \leq 3 \cdot 10^{-184}\right) \land \left(y \leq 9 \cdot 10^{-156} \lor \neg \left(y \leq 3.1 \cdot 10^{-55}\right)\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.5499999999999999e-14 or 2.99999999999999991e-184 < y < 8.99999999999999971e-156 or 3.09999999999999997e-55 < y Initial program 100.0%
Taylor expanded in z around inf 61.4%
Taylor expanded in x around 0 57.8%
if -2.5499999999999999e-14 < y < 2.99999999999999991e-184 or 8.99999999999999971e-156 < y < 3.09999999999999997e-55Initial program 100.0%
Taylor expanded in y around 0 80.2%
Final simplification67.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.5e+70) (not (<= z 1e+44))) (* y z) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.5e+70) || !(z <= 1e+44)) {
tmp = y * z;
} else {
tmp = x * (1.0 - 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 <= (-5.5d+70)) .or. (.not. (z <= 1d+44))) then
tmp = y * z
else
tmp = x * (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -5.5e+70) || !(z <= 1e+44)) {
tmp = y * z;
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.5e+70) or not (z <= 1e+44): tmp = y * z else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.5e+70) || !(z <= 1e+44)) tmp = Float64(y * z); else tmp = Float64(x * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5.5e+70) || ~((z <= 1e+44))) tmp = y * z; else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.5e+70], N[Not[LessEqual[z, 1e+44]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.5 \cdot 10^{+70} \lor \neg \left(z \leq 10^{+44}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -5.49999999999999986e70 or 1.0000000000000001e44 < z Initial program 100.0%
Taylor expanded in z around inf 96.1%
Taylor expanded in x around 0 75.4%
if -5.49999999999999986e70 < z < 1.0000000000000001e44Initial program 100.0%
Taylor expanded in x around inf 85.7%
mul-1-neg85.7%
unsub-neg85.7%
Simplified85.7%
Final simplification81.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -8.5e-16) (not (<= z 9.8e+31))) (+ x (* y z)) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8.5e-16) || !(z <= 9.8e+31)) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - 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 <= (-8.5d-16)) .or. (.not. (z <= 9.8d+31))) then
tmp = x + (y * z)
else
tmp = x * (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -8.5e-16) || !(z <= 9.8e+31)) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8.5e-16) or not (z <= 9.8e+31): tmp = x + (y * z) else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8.5e-16) || !(z <= 9.8e+31)) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -8.5e-16) || ~((z <= 9.8e+31))) tmp = x + (y * z); else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8.5e-16], N[Not[LessEqual[z, 9.8e+31]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.5 \cdot 10^{-16} \lor \neg \left(z \leq 9.8 \cdot 10^{+31}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -8.5000000000000001e-16 or 9.79999999999999991e31 < z Initial program 100.0%
Taylor expanded in z around inf 94.7%
if -8.5000000000000001e-16 < z < 9.79999999999999991e31Initial program 100.0%
Taylor expanded in x around inf 91.7%
mul-1-neg91.7%
unsub-neg91.7%
Simplified91.7%
Final simplification93.3%
(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 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 y around 0 37.2%
Final simplification37.2%
herbie shell --seed 2024040
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))