
(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 7 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 (+ 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 99.2%
+-commutative99.2%
+-lft-identity99.2%
cancel-sign-sub99.2%
cancel-sign-sub99.2%
+-lft-identity99.2%
distribute-lft-out--99.2%
*-rgt-identity99.2%
associate-+l-99.2%
distribute-rgt-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -1.85e-21)
(* y x)
(if (<= y 1.42e-64)
z
(if (or (<= y 2.85e+23) (and (not (<= y 2.55e+215)) (<= y 6.9e+286)))
(* y x)
(* z (- y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.85e-21) {
tmp = y * x;
} else if (y <= 1.42e-64) {
tmp = z;
} else if ((y <= 2.85e+23) || (!(y <= 2.55e+215) && (y <= 6.9e+286))) {
tmp = y * x;
} else {
tmp = z * -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 <= (-1.85d-21)) then
tmp = y * x
else if (y <= 1.42d-64) then
tmp = z
else if ((y <= 2.85d+23) .or. (.not. (y <= 2.55d+215)) .and. (y <= 6.9d+286)) then
tmp = y * x
else
tmp = z * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.85e-21) {
tmp = y * x;
} else if (y <= 1.42e-64) {
tmp = z;
} else if ((y <= 2.85e+23) || (!(y <= 2.55e+215) && (y <= 6.9e+286))) {
tmp = y * x;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.85e-21: tmp = y * x elif y <= 1.42e-64: tmp = z elif (y <= 2.85e+23) or (not (y <= 2.55e+215) and (y <= 6.9e+286)): tmp = y * x else: tmp = z * -y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.85e-21) tmp = Float64(y * x); elseif (y <= 1.42e-64) tmp = z; elseif ((y <= 2.85e+23) || (!(y <= 2.55e+215) && (y <= 6.9e+286))) tmp = Float64(y * x); else tmp = Float64(z * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.85e-21) tmp = y * x; elseif (y <= 1.42e-64) tmp = z; elseif ((y <= 2.85e+23) || (~((y <= 2.55e+215)) && (y <= 6.9e+286))) tmp = y * x; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.85e-21], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.42e-64], z, If[Or[LessEqual[y, 2.85e+23], And[N[Not[LessEqual[y, 2.55e+215]], $MachinePrecision], LessEqual[y, 6.9e+286]]], N[(y * x), $MachinePrecision], N[(z * (-y)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.85 \cdot 10^{-21}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.42 \cdot 10^{-64}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 2.85 \cdot 10^{+23} \lor \neg \left(y \leq 2.55 \cdot 10^{+215}\right) \land y \leq 6.9 \cdot 10^{+286}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if y < -1.8500000000000001e-21 or 1.42000000000000006e-64 < y < 2.85e23 or 2.55e215 < y < 6.9000000000000004e286Initial program 97.6%
fma-def98.8%
Simplified98.8%
Taylor expanded in x around inf 70.1%
if -1.8500000000000001e-21 < y < 1.42000000000000006e-64Initial program 100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 75.6%
if 2.85e23 < y < 2.55e215 or 6.9000000000000004e286 < y Initial program 100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 65.6%
mul-1-neg65.6%
distribute-rgt-neg-out65.6%
Simplified65.6%
Final simplification72.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.1e-24) (not (<= y 2.4e-72))) (* y (- x z)) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.1e-24) || !(y <= 2.4e-72)) {
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 <= (-4.1d-24)) .or. (.not. (y <= 2.4d-72))) 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 <= -4.1e-24) || !(y <= 2.4e-72)) {
tmp = y * (x - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.1e-24) or not (y <= 2.4e-72): tmp = y * (x - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.1e-24) || !(y <= 2.4e-72)) 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 <= -4.1e-24) || ~((y <= 2.4e-72))) tmp = y * (x - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.1e-24], N[Not[LessEqual[y, 2.4e-72]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.1 \cdot 10^{-24} \lor \neg \left(y \leq 2.4 \cdot 10^{-72}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -4.10000000000000015e-24 or 2.4e-72 < y Initial program 98.4%
fma-def99.2%
Simplified99.2%
Taylor expanded in y around inf 96.2%
mul-1-neg96.2%
unsub-neg96.2%
Simplified96.2%
if -4.10000000000000015e-24 < y < 2.4e-72Initial program 100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 75.6%
Final simplification85.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.52e-29) (not (<= y 5.5e-67))) (* y (- x z)) (- z (* z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.52e-29) || !(y <= 5.5e-67)) {
tmp = y * (x - z);
} else {
tmp = z - (z * 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 <= (-1.52d-29)) .or. (.not. (y <= 5.5d-67))) then
tmp = y * (x - z)
else
tmp = z - (z * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.52e-29) || !(y <= 5.5e-67)) {
tmp = y * (x - z);
} else {
tmp = z - (z * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.52e-29) or not (y <= 5.5e-67): tmp = y * (x - z) else: tmp = z - (z * y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.52e-29) || !(y <= 5.5e-67)) tmp = Float64(y * Float64(x - z)); else tmp = Float64(z - Float64(z * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.52e-29) || ~((y <= 5.5e-67))) tmp = y * (x - z); else tmp = z - (z * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.52e-29], N[Not[LessEqual[y, 5.5e-67]], $MachinePrecision]], N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision], N[(z - N[(z * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.52 \cdot 10^{-29} \lor \neg \left(y \leq 5.5 \cdot 10^{-67}\right):\\
\;\;\;\;y \cdot \left(x - z\right)\\
\mathbf{else}:\\
\;\;\;\;z - z \cdot y\\
\end{array}
\end{array}
if y < -1.5200000000000001e-29 or 5.5000000000000003e-67 < y Initial program 98.4%
fma-def99.2%
Simplified99.2%
Taylor expanded in y around inf 96.2%
mul-1-neg96.2%
unsub-neg96.2%
Simplified96.2%
if -1.5200000000000001e-29 < y < 5.5000000000000003e-67Initial program 100.0%
+-commutative100.0%
+-lft-identity100.0%
cancel-sign-sub100.0%
cancel-sign-sub100.0%
+-lft-identity100.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 inf 75.6%
Final simplification85.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -31500000000.0) (not (<= y 1.0))) (* y (- x z)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -31500000000.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 <= (-31500000000.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 <= -31500000000.0) || !(y <= 1.0)) {
tmp = y * (x - z);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -31500000000.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 <= -31500000000.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 <= -31500000000.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, -31500000000.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 -31500000000 \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 < -3.15e10 or 1 < y Initial program 98.1%
fma-def99.0%
Simplified99.0%
Taylor expanded in y around inf 100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
if -3.15e10 < y < 1Initial program 100.0%
+-commutative100.0%
+-lft-identity100.0%
cancel-sign-sub100.0%
cancel-sign-sub100.0%
+-lft-identity100.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.2%
mul-1-neg99.2%
distribute-lft-neg-out99.2%
*-commutative99.2%
Simplified99.2%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.45e-30) (not (<= y 5.4e-70))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.45e-30) || !(y <= 5.4e-70)) {
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 <= (-2.45d-30)) .or. (.not. (y <= 5.4d-70))) 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 <= -2.45e-30) || !(y <= 5.4e-70)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.45e-30) or not (y <= 5.4e-70): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.45e-30) || !(y <= 5.4e-70)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.45e-30) || ~((y <= 5.4e-70))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.45e-30], N[Not[LessEqual[y, 5.4e-70]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.45 \cdot 10^{-30} \lor \neg \left(y \leq 5.4 \cdot 10^{-70}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if y < -2.44999999999999985e-30 or 5.4000000000000003e-70 < y Initial program 98.4%
fma-def99.2%
Simplified99.2%
Taylor expanded in x around inf 60.1%
if -2.44999999999999985e-30 < y < 5.4000000000000003e-70Initial program 100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 75.6%
Final simplification68.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 99.2%
fma-def99.6%
Simplified99.6%
Taylor expanded in y around 0 40.8%
Final simplification40.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 2024019
(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))))