
(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 -1.2e+228)
t_0
(if (<= y -5.5e+50)
(* y z)
(if (<= y -600000.0)
t_0
(if (<= y -2.45e-18)
(* y z)
(if (<= y -3.2e-64)
x
(if (<= y -6.2e-102)
(* y z)
(if (<= y 2e-53) x (if (<= y 1.35e+61) (* y z) t_0))))))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -1.2e+228) {
tmp = t_0;
} else if (y <= -5.5e+50) {
tmp = y * z;
} else if (y <= -600000.0) {
tmp = t_0;
} else if (y <= -2.45e-18) {
tmp = y * z;
} else if (y <= -3.2e-64) {
tmp = x;
} else if (y <= -6.2e-102) {
tmp = y * z;
} else if (y <= 2e-53) {
tmp = x;
} else if (y <= 1.35e+61) {
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 <= (-1.2d+228)) then
tmp = t_0
else if (y <= (-5.5d+50)) then
tmp = y * z
else if (y <= (-600000.0d0)) then
tmp = t_0
else if (y <= (-2.45d-18)) then
tmp = y * z
else if (y <= (-3.2d-64)) then
tmp = x
else if (y <= (-6.2d-102)) then
tmp = y * z
else if (y <= 2d-53) then
tmp = x
else if (y <= 1.35d+61) 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 <= -1.2e+228) {
tmp = t_0;
} else if (y <= -5.5e+50) {
tmp = y * z;
} else if (y <= -600000.0) {
tmp = t_0;
} else if (y <= -2.45e-18) {
tmp = y * z;
} else if (y <= -3.2e-64) {
tmp = x;
} else if (y <= -6.2e-102) {
tmp = y * z;
} else if (y <= 2e-53) {
tmp = x;
} else if (y <= 1.35e+61) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -1.2e+228: tmp = t_0 elif y <= -5.5e+50: tmp = y * z elif y <= -600000.0: tmp = t_0 elif y <= -2.45e-18: tmp = y * z elif y <= -3.2e-64: tmp = x elif y <= -6.2e-102: tmp = y * z elif y <= 2e-53: tmp = x elif y <= 1.35e+61: 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 <= -1.2e+228) tmp = t_0; elseif (y <= -5.5e+50) tmp = Float64(y * z); elseif (y <= -600000.0) tmp = t_0; elseif (y <= -2.45e-18) tmp = Float64(y * z); elseif (y <= -3.2e-64) tmp = x; elseif (y <= -6.2e-102) tmp = Float64(y * z); elseif (y <= 2e-53) tmp = x; elseif (y <= 1.35e+61) 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 <= -1.2e+228) tmp = t_0; elseif (y <= -5.5e+50) tmp = y * z; elseif (y <= -600000.0) tmp = t_0; elseif (y <= -2.45e-18) tmp = y * z; elseif (y <= -3.2e-64) tmp = x; elseif (y <= -6.2e-102) tmp = y * z; elseif (y <= 2e-53) tmp = x; elseif (y <= 1.35e+61) 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, -1.2e+228], t$95$0, If[LessEqual[y, -5.5e+50], N[(y * z), $MachinePrecision], If[LessEqual[y, -600000.0], t$95$0, If[LessEqual[y, -2.45e-18], N[(y * z), $MachinePrecision], If[LessEqual[y, -3.2e-64], x, If[LessEqual[y, -6.2e-102], N[(y * z), $MachinePrecision], If[LessEqual[y, 2e-53], x, If[LessEqual[y, 1.35e+61], N[(y * z), $MachinePrecision], t$95$0]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -1.2 \cdot 10^{+228}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -5.5 \cdot 10^{+50}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -600000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -2.45 \cdot 10^{-18}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -3.2 \cdot 10^{-64}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq -6.2 \cdot 10^{-102}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-53}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{+61}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.19999999999999994e228 or -5.4999999999999998e50 < y < -6e5 or 1.3500000000000001e61 < y Initial program 99.9%
Taylor expanded in x around inf 71.7%
mul-1-neg71.7%
unsub-neg71.7%
Simplified71.7%
Taylor expanded in y around inf 70.3%
associate-*r*70.3%
mul-1-neg70.3%
Simplified70.3%
if -1.19999999999999994e228 < y < -5.4999999999999998e50 or -6e5 < y < -2.4500000000000001e-18 or -3.19999999999999975e-64 < y < -6.20000000000000026e-102 or 2.00000000000000006e-53 < y < 1.3500000000000001e61Initial program 100.0%
Taylor expanded in x around 0 68.1%
if -2.4500000000000001e-18 < y < -3.19999999999999975e-64 or -6.20000000000000026e-102 < y < 2.00000000000000006e-53Initial program 100.0%
Taylor expanded in y around 0 82.4%
Final simplification75.1%
(FPCore (x y z)
:precision binary64
(if (or (<= y -1.05e-20)
(and (not (<= y -4.8e-66)) (or (<= y -4.3e-102) (not (<= y 8e-43)))))
(* y (- z x))
x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.05e-20) || (!(y <= -4.8e-66) && ((y <= -4.3e-102) || !(y <= 8e-43)))) {
tmp = y * (z - x);
} 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.05d-20)) .or. (.not. (y <= (-4.8d-66))) .and. (y <= (-4.3d-102)) .or. (.not. (y <= 8d-43))) then
tmp = y * (z - x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.05e-20) || (!(y <= -4.8e-66) && ((y <= -4.3e-102) || !(y <= 8e-43)))) {
tmp = y * (z - x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.05e-20) or (not (y <= -4.8e-66) and ((y <= -4.3e-102) or not (y <= 8e-43))): tmp = y * (z - x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.05e-20) || (!(y <= -4.8e-66) && ((y <= -4.3e-102) || !(y <= 8e-43)))) tmp = Float64(y * Float64(z - x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.05e-20) || (~((y <= -4.8e-66)) && ((y <= -4.3e-102) || ~((y <= 8e-43))))) tmp = y * (z - x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.05e-20], And[N[Not[LessEqual[y, -4.8e-66]], $MachinePrecision], Or[LessEqual[y, -4.3e-102], N[Not[LessEqual[y, 8e-43]], $MachinePrecision]]]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.05 \cdot 10^{-20} \lor \neg \left(y \leq -4.8 \cdot 10^{-66}\right) \land \left(y \leq -4.3 \cdot 10^{-102} \lor \neg \left(y \leq 8 \cdot 10^{-43}\right)\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.0499999999999999e-20 or -4.80000000000000052e-66 < y < -4.2999999999999997e-102 or 8.00000000000000062e-43 < y Initial program 99.9%
Taylor expanded in y around inf 94.6%
if -1.0499999999999999e-20 < y < -4.80000000000000052e-66 or -4.2999999999999997e-102 < y < 8.00000000000000062e-43Initial program 100.0%
Taylor expanded in y around 0 81.9%
Final simplification88.8%
(FPCore (x y z)
:precision binary64
(if (or (<= y -1.6e-21)
(not
(or (<= y -7.8e-58) (and (not (<= y -6.2e-102)) (<= y 1.45e-53)))))
(* y z)
x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.6e-21) || !((y <= -7.8e-58) || (!(y <= -6.2e-102) && (y <= 1.45e-53)))) {
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.6d-21)) .or. (.not. (y <= (-7.8d-58)) .or. (.not. (y <= (-6.2d-102))) .and. (y <= 1.45d-53))) 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.6e-21) || !((y <= -7.8e-58) || (!(y <= -6.2e-102) && (y <= 1.45e-53)))) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.6e-21) or not ((y <= -7.8e-58) or (not (y <= -6.2e-102) and (y <= 1.45e-53))): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.6e-21) || !((y <= -7.8e-58) || (!(y <= -6.2e-102) && (y <= 1.45e-53)))) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.6e-21) || ~(((y <= -7.8e-58) || (~((y <= -6.2e-102)) && (y <= 1.45e-53))))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.6e-21], N[Not[Or[LessEqual[y, -7.8e-58], And[N[Not[LessEqual[y, -6.2e-102]], $MachinePrecision], LessEqual[y, 1.45e-53]]]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{-21} \lor \neg \left(y \leq -7.8 \cdot 10^{-58} \lor \neg \left(y \leq -6.2 \cdot 10^{-102}\right) \land y \leq 1.45 \cdot 10^{-53}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.6000000000000001e-21 or -7.79999999999999985e-58 < y < -6.20000000000000026e-102 or 1.4499999999999999e-53 < y Initial program 99.9%
Taylor expanded in x around 0 50.0%
if -1.6000000000000001e-21 < y < -7.79999999999999985e-58 or -6.20000000000000026e-102 < y < 1.4499999999999999e-53Initial program 100.0%
Taylor expanded in y around 0 82.4%
Final simplification64.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -1e+47) (not (<= z 1e+83))) (* y z) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1e+47) || !(z <= 1e+83)) {
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 <= (-1d+47)) .or. (.not. (z <= 1d+83))) 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 <= -1e+47) || !(z <= 1e+83)) {
tmp = y * z;
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1e+47) or not (z <= 1e+83): tmp = y * z else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1e+47) || !(z <= 1e+83)) 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 <= -1e+47) || ~((z <= 1e+83))) tmp = y * z; else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1e+47], N[Not[LessEqual[z, 1e+83]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{+47} \lor \neg \left(z \leq 10^{+83}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -1e47 or 1.00000000000000003e83 < z Initial program 99.9%
Taylor expanded in x around 0 72.0%
if -1e47 < z < 1.00000000000000003e83Initial program 100.0%
Taylor expanded in x around inf 83.7%
mul-1-neg83.7%
unsub-neg83.7%
Simplified83.7%
Final simplification79.6%
(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 40.0%
Final simplification40.0%
herbie shell --seed 2024026
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))