
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (- (* x (+ z y)) z))
double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (z + y)) - z
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
def code(x, y, z): return (x * (z + y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) - z) end
function tmp = code(x, y, z) tmp = (x * (z + y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) - z
\end{array}
Initial program 98.8%
*-commutative98.8%
sub-neg98.8%
distribute-rgt-in98.8%
metadata-eval98.8%
neg-mul-198.8%
associate-+r+98.8%
unsub-neg98.8%
+-commutative98.8%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.8e-11) (not (<= x 2.45e-42))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.8e-11) || !(x <= 2.45e-42)) {
tmp = x * (z + y);
} 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 ((x <= (-4.8d-11)) .or. (.not. (x <= 2.45d-42))) then
tmp = x * (z + y)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.8e-11) || !(x <= 2.45e-42)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.8e-11) or not (x <= 2.45e-42): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.8e-11) || !(x <= 2.45e-42)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.8e-11) || ~((x <= 2.45e-42))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.8e-11], N[Not[LessEqual[x, 2.45e-42]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{-11} \lor \neg \left(x \leq 2.45 \cdot 10^{-42}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -4.8000000000000002e-11 or 2.45e-42 < x Initial program 97.8%
Taylor expanded in x around inf 95.1%
+-commutative95.1%
Simplified95.1%
if -4.8000000000000002e-11 < x < 2.45e-42Initial program 100.0%
Taylor expanded in x around 0 70.9%
neg-mul-170.9%
Simplified70.9%
Final simplification83.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.02e-53) (not (<= z 6.5e-21))) (* z (+ x -1.0)) (* x (+ z y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.02e-53) || !(z <= 6.5e-21)) {
tmp = z * (x + -1.0);
} else {
tmp = x * (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 ((z <= (-1.02d-53)) .or. (.not. (z <= 6.5d-21))) then
tmp = z * (x + (-1.0d0))
else
tmp = x * (z + y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.02e-53) || !(z <= 6.5e-21)) {
tmp = z * (x + -1.0);
} else {
tmp = x * (z + y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.02e-53) or not (z <= 6.5e-21): tmp = z * (x + -1.0) else: tmp = x * (z + y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.02e-53) || !(z <= 6.5e-21)) tmp = Float64(z * Float64(x + -1.0)); else tmp = Float64(x * Float64(z + y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.02e-53) || ~((z <= 6.5e-21))) tmp = z * (x + -1.0); else tmp = x * (z + y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.02e-53], N[Not[LessEqual[z, 6.5e-21]], $MachinePrecision]], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.02 \cdot 10^{-53} \lor \neg \left(z \leq 6.5 \cdot 10^{-21}\right):\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(z + y\right)\\
\end{array}
\end{array}
if z < -1.02000000000000002e-53 or 6.49999999999999987e-21 < z Initial program 98.1%
Taylor expanded in y around 0 84.7%
if -1.02000000000000002e-53 < z < 6.49999999999999987e-21Initial program 100.0%
Taylor expanded in x around inf 83.9%
+-commutative83.9%
Simplified83.9%
Final simplification84.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.6e-53) (not (<= z 6.5e-21))) (- (* x z) z) (* x (+ z y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.6e-53) || !(z <= 6.5e-21)) {
tmp = (x * z) - z;
} else {
tmp = x * (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 ((z <= (-4.6d-53)) .or. (.not. (z <= 6.5d-21))) then
tmp = (x * z) - z
else
tmp = x * (z + y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -4.6e-53) || !(z <= 6.5e-21)) {
tmp = (x * z) - z;
} else {
tmp = x * (z + y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.6e-53) or not (z <= 6.5e-21): tmp = (x * z) - z else: tmp = x * (z + y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.6e-53) || !(z <= 6.5e-21)) tmp = Float64(Float64(x * z) - z); else tmp = Float64(x * Float64(z + y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4.6e-53) || ~((z <= 6.5e-21))) tmp = (x * z) - z; else tmp = x * (z + y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.6e-53], N[Not[LessEqual[z, 6.5e-21]], $MachinePrecision]], N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.6 \cdot 10^{-53} \lor \neg \left(z \leq 6.5 \cdot 10^{-21}\right):\\
\;\;\;\;x \cdot z - z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(z + y\right)\\
\end{array}
\end{array}
if z < -4.6000000000000003e-53 or 6.49999999999999987e-21 < z Initial program 98.1%
*-commutative98.1%
sub-neg98.1%
distribute-rgt-in98.1%
metadata-eval98.1%
neg-mul-198.1%
associate-+r+98.1%
unsub-neg98.1%
+-commutative98.1%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 84.8%
if -4.6000000000000003e-53 < z < 6.49999999999999987e-21Initial program 100.0%
Taylor expanded in x around inf 83.9%
+-commutative83.9%
Simplified83.9%
Final simplification84.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.5e-10) (not (<= x 2.85e-42))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.5e-10) || !(x <= 2.85e-42)) {
tmp = x * y;
} 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 ((x <= (-4.5d-10)) .or. (.not. (x <= 2.85d-42))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.5e-10) || !(x <= 2.85e-42)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.5e-10) or not (x <= 2.85e-42): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.5e-10) || !(x <= 2.85e-42)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.5e-10) || ~((x <= 2.85e-42))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.5e-10], N[Not[LessEqual[x, 2.85e-42]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{-10} \lor \neg \left(x \leq 2.85 \cdot 10^{-42}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -4.5e-10 or 2.85e-42 < x Initial program 97.8%
Taylor expanded in y around inf 53.7%
if -4.5e-10 < x < 2.85e-42Initial program 100.0%
Taylor expanded in x around 0 70.9%
neg-mul-170.9%
Simplified70.9%
Final simplification61.8%
(FPCore (x y z) :precision binary64 (if (<= x -4e-5) (* x z) (if (<= x 2.85e-42) (- z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4e-5) {
tmp = x * z;
} else if (x <= 2.85e-42) {
tmp = -z;
} else {
tmp = 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 (x <= (-4d-5)) then
tmp = x * z
else if (x <= 2.85d-42) then
tmp = -z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4e-5) {
tmp = x * z;
} else if (x <= 2.85e-42) {
tmp = -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4e-5: tmp = x * z elif x <= 2.85e-42: tmp = -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4e-5) tmp = Float64(x * z); elseif (x <= 2.85e-42) tmp = Float64(-z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4e-5) tmp = x * z; elseif (x <= 2.85e-42) tmp = -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4e-5], N[(x * z), $MachinePrecision], If[LessEqual[x, 2.85e-42], (-z), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-5}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 2.85 \cdot 10^{-42}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -4.00000000000000033e-5Initial program 98.3%
Taylor expanded in y around 0 60.9%
Taylor expanded in x around inf 60.6%
*-commutative60.6%
Simplified60.6%
if -4.00000000000000033e-5 < x < 2.85e-42Initial program 100.0%
Taylor expanded in x around 0 70.4%
neg-mul-170.4%
Simplified70.4%
if 2.85e-42 < x Initial program 97.3%
Taylor expanded in y around inf 59.8%
Final simplification65.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 Float64(-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.8%
Taylor expanded in x around 0 36.7%
neg-mul-136.7%
Simplified36.7%
Final simplification36.7%
herbie shell --seed 2024075
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))