
(FPCore (x y z) :precision binary64 (+ (* x y) (* z (- 1.0 y))))
double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - y));
}
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 * (1.0d0 - y))
end function
public static double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - y));
}
def code(x, y, z): return (x * y) + (z * (1.0 - y))
function code(x, y, z) return Float64(Float64(x * y) + Float64(z * Float64(1.0 - y))) end
function tmp = code(x, y, z) tmp = (x * y) + (z * (1.0 - y)); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + z \cdot \left(1 - y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* z (- 1.0 y))))
double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - y));
}
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 * (1.0d0 - y))
end function
public static double code(double x, double y, double z) {
return (x * y) + (z * (1.0 - y));
}
def code(x, y, z): return (x * y) + (z * (1.0 - y))
function code(x, y, z) return Float64(Float64(x * y) + Float64(z * Float64(1.0 - y))) end
function tmp = code(x, y, z) tmp = (x * y) + (z * (1.0 - y)); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + z \cdot \left(1 - y\right)
\end{array}
(FPCore (x y z) :precision binary64 (fma y (- x z) z))
double code(double x, double y, double z) {
return fma(y, (x - z), z);
}
function code(x, y, z) return fma(y, Float64(x - z), z) end
code[x_, y_, z_] := N[(y * N[(x - z), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x - z, z\right)
\end{array}
Initial program 98.0%
sub-neg98.0%
+-commutative98.0%
distribute-rgt-in98.0%
*-lft-identity98.0%
associate-+r+98.0%
+-commutative98.0%
distribute-lft-neg-out98.0%
distribute-rgt-neg-out98.0%
*-commutative98.0%
distribute-lft-out100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- z))))
(if (<= y -1.8e+194)
t_0
(if (<= y -9.8e+102)
(* y x)
(if (<= y -1.12e+63)
t_0
(if (or (<= y -8.5e-9) (not (<= y 3.4e-8))) (* y x) z))))))
double code(double x, double y, double z) {
double t_0 = y * -z;
double tmp;
if (y <= -1.8e+194) {
tmp = t_0;
} else if (y <= -9.8e+102) {
tmp = y * x;
} else if (y <= -1.12e+63) {
tmp = t_0;
} else if ((y <= -8.5e-9) || !(y <= 3.4e-8)) {
tmp = y * x;
} else {
tmp = 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) :: t_0
real(8) :: tmp
t_0 = y * -z
if (y <= (-1.8d+194)) then
tmp = t_0
else if (y <= (-9.8d+102)) then
tmp = y * x
else if (y <= (-1.12d+63)) then
tmp = t_0
else if ((y <= (-8.5d-9)) .or. (.not. (y <= 3.4d-8))) then
tmp = y * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * -z;
double tmp;
if (y <= -1.8e+194) {
tmp = t_0;
} else if (y <= -9.8e+102) {
tmp = y * x;
} else if (y <= -1.12e+63) {
tmp = t_0;
} else if ((y <= -8.5e-9) || !(y <= 3.4e-8)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): t_0 = y * -z tmp = 0 if y <= -1.8e+194: tmp = t_0 elif y <= -9.8e+102: tmp = y * x elif y <= -1.12e+63: tmp = t_0 elif (y <= -8.5e-9) or not (y <= 3.4e-8): tmp = y * x else: tmp = z return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-z)) tmp = 0.0 if (y <= -1.8e+194) tmp = t_0; elseif (y <= -9.8e+102) tmp = Float64(y * x); elseif (y <= -1.12e+63) tmp = t_0; elseif ((y <= -8.5e-9) || !(y <= 3.4e-8)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -z; tmp = 0.0; if (y <= -1.8e+194) tmp = t_0; elseif (y <= -9.8e+102) tmp = y * x; elseif (y <= -1.12e+63) tmp = t_0; elseif ((y <= -8.5e-9) || ~((y <= 3.4e-8))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-z)), $MachinePrecision]}, If[LessEqual[y, -1.8e+194], t$95$0, If[LessEqual[y, -9.8e+102], N[(y * x), $MachinePrecision], If[LessEqual[y, -1.12e+63], t$95$0, If[Or[LessEqual[y, -8.5e-9], N[Not[LessEqual[y, 3.4e-8]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-z\right)\\
\mathbf{if}\;y \leq -1.8 \cdot 10^{+194}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -9.8 \cdot 10^{+102}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -1.12 \cdot 10^{+63}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -8.5 \cdot 10^{-9} \lor \neg \left(y \leq 3.4 \cdot 10^{-8}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -1.8e194 or -9.80000000000000089e102 < y < -1.12000000000000006e63Initial program 100.0%
Taylor expanded in y around inf 100.0%
mul-1-neg100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 69.2%
associate-*r*69.2%
neg-mul-169.2%
*-commutative69.2%
Simplified69.2%
if -1.8e194 < y < -9.80000000000000089e102 or -1.12000000000000006e63 < y < -8.5e-9 or 3.4e-8 < y Initial program 95.3%
Taylor expanded in x around inf 56.3%
*-commutative56.3%
Simplified56.3%
if -8.5e-9 < y < 3.4e-8Initial program 100.0%
Taylor expanded in y around 0 77.5%
Final simplification67.6%
(FPCore (x y z)
:precision binary64
(if (or (<= y -3.1e-9)
(and (not (<= y -1.9e-62)) (or (<= y -1.86e-202) (not (<= y 4e-6)))))
(* y (- x z))
z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.1e-9) || (!(y <= -1.9e-62) && ((y <= -1.86e-202) || !(y <= 4e-6)))) {
tmp = y * (x - z);
} else {
tmp = 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 <= (-3.1d-9)) .or. (.not. (y <= (-1.9d-62))) .and. (y <= (-1.86d-202)) .or. (.not. (y <= 4d-6))) then
tmp = y * (x - z)
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.1e-9) || (!(y <= -1.9e-62) && ((y <= -1.86e-202) || !(y <= 4e-6)))) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.1e-9) or (not (y <= -1.9e-62) and ((y <= -1.86e-202) or not (y <= 4e-6))): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.1e-9) || (!(y <= -1.9e-62) && ((y <= -1.86e-202) || !(y <= 4e-6)))) tmp = Float64(y * Float64(x - z)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.1e-9) || (~((y <= -1.9e-62)) && ((y <= -1.86e-202) || ~((y <= 4e-6))))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.1e-9], And[N[Not[LessEqual[y, -1.9e-62]], $MachinePrecision], Or[LessEqual[y, -1.86e-202], N[Not[LessEqual[y, 4e-6]], $MachinePrecision]]]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.1 \cdot 10^{-9} \lor \neg \left(y \leq -1.9 \cdot 10^{-62}\right) \land \left(y \leq -1.86 \cdot 10^{-202} \lor \neg \left(y \leq 4 \cdot 10^{-6}\right)\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -3.10000000000000005e-9 or -1.90000000000000003e-62 < y < -1.85999999999999998e-202 or 3.99999999999999982e-6 < y Initial program 97.0%
Taylor expanded in y around inf 92.8%
mul-1-neg92.8%
sub-neg92.8%
Simplified92.8%
if -3.10000000000000005e-9 < y < -1.90000000000000003e-62 or -1.85999999999999998e-202 < y < 3.99999999999999982e-6Initial program 100.0%
Taylor expanded in y around 0 87.3%
Final simplification90.8%
(FPCore (x y z)
:precision binary64
(if (or (<= y -6.5e-6)
(and (not (<= y -7.2e-65)) (or (<= y -1.86e-202) (not (<= y 0.78)))))
(* y (- x z))
(* z (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.5e-6) || (!(y <= -7.2e-65) && ((y <= -1.86e-202) || !(y <= 0.78)))) {
tmp = y * (x - z);
} else {
tmp = z * (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 ((y <= (-6.5d-6)) .or. (.not. (y <= (-7.2d-65))) .and. (y <= (-1.86d-202)) .or. (.not. (y <= 0.78d0))) then
tmp = y * (x - z)
else
tmp = z * (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -6.5e-6) || (!(y <= -7.2e-65) && ((y <= -1.86e-202) || !(y <= 0.78)))) {
tmp = y * (x - z);
} else {
tmp = z * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.5e-6) or (not (y <= -7.2e-65) and ((y <= -1.86e-202) or not (y <= 0.78))): tmp = y * (x - z) else: tmp = z * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.5e-6) || (!(y <= -7.2e-65) && ((y <= -1.86e-202) || !(y <= 0.78)))) tmp = Float64(y * Float64(x - z)); else tmp = Float64(z * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6.5e-6) || (~((y <= -7.2e-65)) && ((y <= -1.86e-202) || ~((y <= 0.78))))) tmp = y * (x - z); else tmp = z * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.5e-6], And[N[Not[LessEqual[y, -7.2e-65]], $MachinePrecision], Or[LessEqual[y, -1.86e-202], N[Not[LessEqual[y, 0.78]], $MachinePrecision]]]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{-6} \lor \neg \left(y \leq -7.2 \cdot 10^{-65}\right) \land \left(y \leq -1.86 \cdot 10^{-202} \lor \neg \left(y \leq 0.78\right)\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -6.4999999999999996e-6 or -7.1999999999999996e-65 < y < -1.85999999999999998e-202 or 0.78000000000000003 < y Initial program 97.0%
Taylor expanded in y around inf 92.8%
mul-1-neg92.8%
sub-neg92.8%
Simplified92.8%
if -6.4999999999999996e-6 < y < -7.1999999999999996e-65 or -1.85999999999999998e-202 < y < 0.78000000000000003Initial program 100.0%
Taylor expanded in x around 0 88.6%
Final simplification91.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = y * (x - z);
} else {
tmp = z + (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 <= (-1.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = y * (x - z)
else
tmp = z + (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = y * (x - z) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(y * Float64(x - z)); else tmp = Float64(z + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.0))) tmp = y * (x - z); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 96.4%
Taylor expanded in y around inf 98.9%
mul-1-neg98.9%
sub-neg98.9%
Simplified98.9%
if -1 < y < 1Initial program 100.0%
+-commutative100.0%
distribute-lft-out--100.0%
*-rgt-identity100.0%
associate-+l-100.0%
distribute-rgt-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 99.0%
mul-1-neg99.0%
distribute-lft-neg-out99.0%
*-commutative99.0%
Simplified99.0%
sub-neg99.0%
+-commutative99.0%
distribute-rgt-neg-out99.0%
remove-double-neg99.0%
Applied egg-rr99.0%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.5e-7) (not (<= y 0.00045))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.5e-7) || !(y <= 0.00045)) {
tmp = y * x;
} else {
tmp = 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 <= (-7.5d-7)) .or. (.not. (y <= 0.00045d0))) then
tmp = y * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -7.5e-7) || !(y <= 0.00045)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.5e-7) or not (y <= 0.00045): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.5e-7) || !(y <= 0.00045)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -7.5e-7) || ~((y <= 0.00045))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.5e-7], N[Not[LessEqual[y, 0.00045]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{-7} \lor \neg \left(y \leq 0.00045\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -7.5000000000000002e-7 or 4.4999999999999999e-4 < y Initial program 96.4%
Taylor expanded in x around inf 51.0%
*-commutative51.0%
Simplified51.0%
if -7.5000000000000002e-7 < y < 4.4999999999999999e-4Initial program 100.0%
Taylor expanded in y around 0 77.5%
Final simplification63.0%
(FPCore (x y z) :precision binary64 (+ z (* y (- x z))))
double code(double x, double y, double z) {
return z + (y * (x - z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + (y * (x - z))
end function
public static double code(double x, double y, double z) {
return z + (y * (x - z));
}
def code(x, y, z): return z + (y * (x - z))
function code(x, y, z) return Float64(z + Float64(y * Float64(x - z))) end
function tmp = code(x, y, z) tmp = z + (y * (x - z)); end
code[x_, y_, z_] := N[(z + N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + y \cdot \left(x - z\right)
\end{array}
Initial program 98.0%
+-commutative98.0%
distribute-lft-out--98.0%
*-rgt-identity98.0%
associate-+l-98.0%
distribute-rgt-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 98.0%
Taylor expanded in y around 0 36.8%
Final simplification36.8%
(FPCore (x y z) :precision binary64 (- z (* (- z x) y)))
double code(double x, double y, double z) {
return z - ((z - x) * y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z - ((z - x) * y)
end function
public static double code(double x, double y, double z) {
return z - ((z - x) * y);
}
def code(x, y, z): return z - ((z - x) * y)
function code(x, y, z) return Float64(z - Float64(Float64(z - x) * y)) end
function tmp = code(x, y, z) tmp = z - ((z - x) * y); end
code[x_, y_, z_] := N[(z - N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z - \left(z - x\right) \cdot y
\end{array}
herbie shell --seed 2024010
(FPCore (x y z)
:name "Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3"
:precision binary64
:herbie-target
(- z (* (- z x) y))
(+ (* x y) (* z (- 1.0 y))))