
(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 -2.8e+263)
(* y z)
(if (<= y -4.3e+198)
t_0
(if (<= y -2.3e+166)
(* y z)
(if (<= y -1.0)
t_0
(if (<= y 2.4e-124)
x
(if (or (<= y 7e+144) (and (not (<= y 4.2e+176)) (<= y 3e+269)))
(* y z)
t_0))))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -2.8e+263) {
tmp = y * z;
} else if (y <= -4.3e+198) {
tmp = t_0;
} else if (y <= -2.3e+166) {
tmp = y * z;
} else if (y <= -1.0) {
tmp = t_0;
} else if (y <= 2.4e-124) {
tmp = x;
} else if ((y <= 7e+144) || (!(y <= 4.2e+176) && (y <= 3e+269))) {
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 <= (-2.8d+263)) then
tmp = y * z
else if (y <= (-4.3d+198)) then
tmp = t_0
else if (y <= (-2.3d+166)) then
tmp = y * z
else if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 2.4d-124) then
tmp = x
else if ((y <= 7d+144) .or. (.not. (y <= 4.2d+176)) .and. (y <= 3d+269)) 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 <= -2.8e+263) {
tmp = y * z;
} else if (y <= -4.3e+198) {
tmp = t_0;
} else if (y <= -2.3e+166) {
tmp = y * z;
} else if (y <= -1.0) {
tmp = t_0;
} else if (y <= 2.4e-124) {
tmp = x;
} else if ((y <= 7e+144) || (!(y <= 4.2e+176) && (y <= 3e+269))) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -2.8e+263: tmp = y * z elif y <= -4.3e+198: tmp = t_0 elif y <= -2.3e+166: tmp = y * z elif y <= -1.0: tmp = t_0 elif y <= 2.4e-124: tmp = x elif (y <= 7e+144) or (not (y <= 4.2e+176) and (y <= 3e+269)): 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 <= -2.8e+263) tmp = Float64(y * z); elseif (y <= -4.3e+198) tmp = t_0; elseif (y <= -2.3e+166) tmp = Float64(y * z); elseif (y <= -1.0) tmp = t_0; elseif (y <= 2.4e-124) tmp = x; elseif ((y <= 7e+144) || (!(y <= 4.2e+176) && (y <= 3e+269))) 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 <= -2.8e+263) tmp = y * z; elseif (y <= -4.3e+198) tmp = t_0; elseif (y <= -2.3e+166) tmp = y * z; elseif (y <= -1.0) tmp = t_0; elseif (y <= 2.4e-124) tmp = x; elseif ((y <= 7e+144) || (~((y <= 4.2e+176)) && (y <= 3e+269))) 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, -2.8e+263], N[(y * z), $MachinePrecision], If[LessEqual[y, -4.3e+198], t$95$0, If[LessEqual[y, -2.3e+166], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 2.4e-124], x, If[Or[LessEqual[y, 7e+144], And[N[Not[LessEqual[y, 4.2e+176]], $MachinePrecision], LessEqual[y, 3e+269]]], N[(y * z), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -2.8 \cdot 10^{+263}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -4.3 \cdot 10^{+198}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -2.3 \cdot 10^{+166}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{-124}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 7 \cdot 10^{+144} \lor \neg \left(y \leq 4.2 \cdot 10^{+176}\right) \land y \leq 3 \cdot 10^{+269}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -2.7999999999999998e263 or -4.29999999999999982e198 < y < -2.30000000000000008e166 or 2.39999999999999992e-124 < y < 6.9999999999999996e144 or 4.1999999999999998e176 < y < 3.0000000000000001e269Initial program 100.0%
Taylor expanded in z around inf 84.1%
Taylor expanded in x around 0 77.5%
if -2.7999999999999998e263 < y < -4.29999999999999982e198 or -2.30000000000000008e166 < y < -1 or 6.9999999999999996e144 < y < 4.1999999999999998e176 or 3.0000000000000001e269 < y Initial program 100.0%
Taylor expanded in z around 0 67.0%
mul-1-neg67.0%
distribute-lft-neg-out67.0%
*-commutative67.0%
Simplified67.0%
Taylor expanded in y around inf 66.9%
associate-*r*66.9%
mul-1-neg66.9%
Simplified66.9%
if -1 < y < 2.39999999999999992e-124Initial program 100.0%
Taylor expanded in z around inf 99.3%
Taylor expanded in x around inf 80.0%
Final simplification75.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.6e-26) (not (<= z 9500000000.0))) (+ x (* y z)) (- x (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.6e-26) || !(z <= 9500000000.0)) {
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 <= (-4.6d-26)) .or. (.not. (z <= 9500000000.0d0))) 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 <= -4.6e-26) || !(z <= 9500000000.0)) {
tmp = x + (y * z);
} else {
tmp = x - (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.6e-26) or not (z <= 9500000000.0): tmp = x + (y * z) else: tmp = x - (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.6e-26) || !(z <= 9500000000.0)) 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 <= -4.6e-26) || ~((z <= 9500000000.0))) tmp = x + (y * z); else tmp = x - (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.6e-26], N[Not[LessEqual[z, 9500000000.0]], $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 -4.6 \cdot 10^{-26} \lor \neg \left(z \leq 9500000000\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot y\\
\end{array}
\end{array}
if z < -4.60000000000000018e-26 or 9.5e9 < z Initial program 100.0%
Taylor expanded in z around inf 91.9%
if -4.60000000000000018e-26 < z < 9.5e9Initial program 100.0%
Taylor expanded in z around 0 91.4%
mul-1-neg91.4%
distribute-lft-neg-out91.4%
*-commutative91.4%
Simplified91.4%
Taylor expanded in x around 0 91.4%
neg-mul-191.4%
distribute-rgt-in91.4%
*-lft-identity91.4%
cancel-sign-sub-inv91.4%
Simplified91.4%
Final simplification91.7%
(FPCore (x y z) :precision binary64 (if (<= y -1.65e-16) (* y z) (if (<= y 2.3e-124) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.65e-16) {
tmp = y * z;
} else if (y <= 2.3e-124) {
tmp = x;
} else {
tmp = 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 <= (-1.65d-16)) then
tmp = y * z
else if (y <= 2.3d-124) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.65e-16) {
tmp = y * z;
} else if (y <= 2.3e-124) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.65e-16: tmp = y * z elif y <= 2.3e-124: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.65e-16) tmp = Float64(y * z); elseif (y <= 2.3e-124) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.65e-16) tmp = y * z; elseif (y <= 2.3e-124) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.65e-16], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.3e-124], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{-16}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{-124}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -1.64999999999999994e-16 or 2.30000000000000012e-124 < y Initial program 100.0%
Taylor expanded in z around inf 62.3%
Taylor expanded in x around 0 58.4%
if -1.64999999999999994e-16 < y < 2.30000000000000012e-124Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around inf 81.4%
Final simplification66.6%
(FPCore (x y z) :precision binary64 (if (<= x -1e+116) (* y (- x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1e+116) {
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 (x <= (-1d+116)) 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 (x <= -1e+116) {
tmp = y * -x;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1e+116: tmp = y * -x else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1e+116) 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 (x <= -1e+116) tmp = y * -x; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1e+116], N[(y * (-x)), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{+116}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -1.00000000000000002e116Initial program 100.0%
Taylor expanded in z around 0 97.8%
mul-1-neg97.8%
distribute-lft-neg-out97.8%
*-commutative97.8%
Simplified97.8%
Taylor expanded in y around inf 63.1%
associate-*r*63.1%
mul-1-neg63.1%
Simplified63.1%
if -1.00000000000000002e116 < x Initial program 100.0%
Taylor expanded in z around inf 81.9%
Final simplification78.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 75.7%
Taylor expanded in x around inf 33.1%
Final simplification33.1%
herbie shell --seed 2023285
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))